202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Minor enhancements to the XPages Table Control
Wed, Dec 13th 2017 54
XPages JDBC Configuration via NotesDocuments
Tue, Dec 5th 2017 58
My New Approach for Sharing XPages Controls and Extensions
Fri, Dec 1st 2017 33
Embedded Experiences not rendering after IBM Notes FP9
Wed, Sep 27th 2017 8
BuildXPages Deployment Automation Tools – v1.0.0
Thu, Sep 21st 2017 7
Generating and Downloading Files Using XPages’ Persistence Service
Wed, Sep 13th 2017 9
Bundle Inspector – Diagnosing XPages Plugin Resolution problems
Wed, Aug 2nd 2017 9
Top 10
XPages JDBC Configuration via NotesDocuments
Tue, Dec 5th 2017 58
Minor enhancements to the XPages Table Control
Wed, Dec 13th 2017 54
My New Approach for Sharing XPages Controls and Extensions
Fri, Dec 1st 2017 33
Pasting Images into XPages CKEditor
Sun, Feb 12th 2017 15
Preventing Pasting of Images in CKEditor
Mon, Nov 14th 2016 13
Preventing pasting of remotely hosted images in CKEditor
Mon, Nov 14th 2016 12
Webmail UI – You must learn about MIME
Wed, Apr 20th 2016 11
XPages webmail – Using Mime Inspector to debug Mime
Tue, Feb 14th 2017 11
XPages PhoneNumber Control - Part 2 Upgrades to the Converter
Mon, Feb 23rd 2015 9
Bundle Inspector – Diagnosing XPages Plugin Resolution problems
Wed, Aug 2nd 2017 9


Preventing pasting of remotely hosted images in CKEditor
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
camerongregor    

In the previous post, I showed how to prevent a user from pasting Images from the Clipboard into CKEditor. This post is of a similar nature but is designed to ensure that users don’t paste images with URLs to external / internal applications.

This post is part of my XPages webmail tips series, and addresses a problem where, a user copies and pastes some HTML that includes images, from a webpage and pastes it into CKEditor for a message that is then sent via email. The recipient is then unable to see the image due to the fact they don’t have the same access as the author of the email.

The cause of problem is, when the image is pasted it is pasted as an img tag with a link to the location of the image on a server.
There is no guarantee that the email recipient can access the server that the image is located on. The server is possibly behind a firewall, OR if the HTML was copied from an internal system, then it is possible an external email recipient does not have access to that internal server.

Additionally even for Internal emails, if the html was copied from an XPages application and the copied image is located inside a Notes Document, the URL that is used for that image is only temporarily available by the Xpages Persistence service, and is only available to the user that copied the HTML.

The result of all of this is more complaints of “I can’t see any image”

Another CKEditor Plugin!

The solution is just a modified version of the CKEditor plugin in previous post. The plugin listens for pasted content, and strips out any remotely hosted Images.

CKEDITOR.plugins.add('blockpasteimagelink', {

	init : function(editor) {

		function replaceImgText(html) {

			var replacedSomething = false;

			var ret = html.replace(/<img[^>]*src="http.*?"[^>]*>/gi, function(img) {
				replacedSomething = true;
				return '';
			});

			if (replacedSomething) {
				alert('The Image you have attempted to paste is hosted on a remote server and may not be visible to others. Pasting these images is not currently supported, please upload an image file using the Image button in the toolbar.');
			}

			return ret;
		}

		function chkImg() {

			// don't execute code if the editor is readOnly
			if (editor.readOnly)
				return;

			setTimeout(function() {
				editor.document.$.body.innerHTML = replaceImgText(editor.document.$.body.innerHTML);
			}, 100);
		}

		editor.on('contentDom', function() {
			// For Firefox
			editor.document.on('drop', chkImg);
			// For IE
			editor.document.getBody().on('drop', chkImg);
		});

		editor.on('paste', function(e) {

			var html = e.data.dataValue;
			if (!html) {
				return;
			}

			e.data.dataValue = replaceImgText(html);

		});

	}

});

Save the above javascript as a script library in your nsf, called ‘blockpasteimagelink’

Make sure to include the script library on your XPage, and then tell your InputRichText to use the plugin using the extraPlugins dojoAttribute. Here is a sample XPage:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

	<xp:this.data>
		<xp:dominoDocument var="document1"></xp:dominoDocument>
	</xp:this.data>

	<xp:this.resources>
		<xp:script src="/blockpasteimagelink.js" clientSide="true"></xp:script>
	</xp:this.resources>
	
	<xp:inputRichText id="inputRichText1" value="#{document1.body}">
		<xp:this.dojoAttributes>
			<xp:dojoAttribute name="extraPlugins" value="blockpasteimagelink"></xp:dojoAttribute>
		</xp:this.dojoAttributes>
	</xp:inputRichText>
	
</xp:view>

Now let’s test it out, I would like everyone to know about the mythical Jackalope, so I will copy some info from Wikipedia!

preventpastecopyjackalope

Then I will paste it into my CKEditor, where I will receive a warning…

preventpastewarning

And after clicking ok, I can see that everything except the image has been pasted…

preventpasteafter

Summary

So we have now prevented some more cases whereby the recipient of an email will have trouble viewing images, it can be a little frustating for a user, but probably less frustrating that having to re-send an email, so I call that a win.

I had also intended on looking into the possibility of modifying the plugin so that upon pasting a remote image, the browser would try to download that image and then upload to the XPages server to be attached as an embedded image, however I haven’t looked into that yet!

In our system we have another CKEditor plugin which will allows users to paste image data from the clipboard, this is a nicer solution and I will cover that in the next post.



---------------------
http://camerongregor.com/2016/11/15/preventing-pasting-of-remotely-hosted-images-in-ckeditor/
Nov 14, 2016
13 hits



Recent Blog Posts
54
Minor enhancements to the XPages Table Control
Wed, Dec 13th 2017 10:44a   Cameron Gregor
As mentioned in my previous post, I have started up a fork of the ExtLibX project and have started contributing to it instead of my previous GregorbyteXspLibrary. Last week I shared the JDBC Configuration Provider which uses Notes Documents to store the configuration info,  within this release was another small contribution with 2 minor enhancements for the XPages  table control. The core XPages table control does not provide support for thead, tbody, and tfoot elements. Also there isn’
58
XPages JDBC Configuration via NotesDocuments
Tue, Dec 5th 2017 11:34a   Cameron Gregor
If you have used the Extension Library’s Relational controls, then you are probably familiar with the process of configuring your JDBC Connection details. You have the option of setting up a ‘named’ connection so you can reference a database connection by name. This involves creating an xml file .jdbc in the WebContentWEB-INFjdbc directory. This xml file specifies the driver, url, username, password, and perhaps some information about connection pooling. Alternatively your can
33
My New Approach for Sharing XPages Controls and Extensions
Fri, Dec 1st 2017 12:33p   Cameron Gregor
Over the past few years I have shared a handful of controls and techniques on my blog, and most of these I have made available on github in one way or another. Originally I was creating a separate github project for each one such as EmailValidator, PhoneNumberControl and the Messages Controls. After these few I decided it would be more efficient to create a single project that I could put them all into, so I then began to contribute them via my GregorbyteXspLibrary. From time to time I had a fe
8
Embedded Experiences not rendering after IBM Notes FP9
Wed, Sep 27th 2017 5:36a   Cameron Gregor
Embedded Experiences are no longer rendering after upgrading to FP9. I suspect it is something to do with the changes to Embedded Browser, either removing it or upgrading it or something else. I haven’t had a chance to investigate fully. Perhaps there may be a workaround, or perhaps this is specific to the way we are using embedded experiences. We use embedded experiences quite a bit at our company so we have rolled back for now. If I figure anything out I will post an update but just be a
7
BuildXPages Deployment Automation Tools – v1.0.0
Thu, Sep 21st 2017 12:47p   Cameron Gregor
After quite a bit of work I have finally published the first release of BuildXPages! What is BuildXPages? BuildXPages is a project which is useful if you are interested in Automating tasks that are involved in building XPages. For example you may be interested in automating some of these tasks: Building NSFs from an On-Disk Project Building Plugins and Features Refreshing NSF Designs Setting Template Inheritance of NSFs Start, Stop and Restart Http server Uploading Plugins to an NSF Update
9
Generating and Downloading Files Using XPages’ Persistence Service
Wed, Sep 13th 2017 4:42p   Cameron Gregor
When developing an XPages application you may run into the need to generate files to be downloaded by the user. For example: Generating a PDF Report Exporting Data to Excel Spreadsheet Creating a Zip File of several attachments Achieving these tasks usually raises 2 main problems to solve; What temporary place can I use to generate the files? How do I allow the user to download the generated files? For the temporary place problem, some common solution is to either generate the files to some
9
Bundle Inspector – Diagnosing XPages Plugin Resolution problems
Wed, Aug 2nd 2017 12:26p   Cameron Gregor
A common task with XPages development is to installing some plugins that provide additional functionality. If you do any plugin development of your own, you end up doing this task a lot more as you create new plugins, install new versions etc. It is also common to encounter some problems after installing plugins to your Domino Server! Maybe your expected plugin doesn’t load up at all? maybe the wrong version is loading? The standard method of diagnosing these problems is to use the OSGi c
7
Swiper Official Version 2 Release
Fri, Jul 21st 2017 1:52p   Cameron Gregor
So I have finally posted Swiper version 2 to OpenNTF! (and Github of course) Swiper OpenNTF Project Page Swiper Github Releases The latest version is 2.0.1,  and is the same as 2.0.0beta but with a bug fix for the toolbar buttons. Swiper 2.0.0 beta has been available on the Github project site for a few months, and the core functionality of it works as planned. There was however a bug within the shortcut buttons that I added to the menu bar, and this is a bit of a nasty bug that can cause del
2
Auto-width Bootstrap Column XPages Controls
Tue, Mar 21st 2017 1:13p   Cameron Gregor
I’ve been stuck working with OneUI Version 3 for the past couple of years, due to a regretful decision made at the beginning of my major project. OneUI was better than nothing but very frustrating at times. Finally, I have moved on to my next project and I am now using bootstrap (version 3) A common task when laying out a page using bootstrap is to divide sections up into rows and columns, and use the appropriate css styles to do so. I’m going to assume you are familiar with bo
2
Swiper FP8 Version Beta Release
Thu, Mar 16th 2017 12:50p   Cameron Gregor
Last week I released the ‘alpha’ version of Swiper which was untested on FP8 but presumed to be ok. So far I have only had good reports from the pioneers who have gone ahead and installed FP8 + the alpha version. I have since managed to ugrade my home office setup to FP8 which unfortunately has broken my ability to launch designer from eclipse but I am seeking some advice on fixing this up. In the meantime I have to test the slow way of building plugins, import plugins, restart R




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition