Preventing Users From Pasting Images
Preventing users form inserting images requires two parts:
- Remove the insert image related items from the configuration file so the insert image dialog is unavailable.
- Prevent users from pasting images into the editor.
The first part is quite simple, just delete the “ImageServer” menu item and toolbar buttons from your configuration file.
The second part however isn’t directly supported by EditLive! Fortunately, we’ve now made a plugin available that automatically strips any images out of pasted content. Like all the plugins on LiveWorks! we don’t offer direct support for the plugin, but the full source code is included and help is generally available on the mailing list. The instructions for using the plugin are on the plugin page - it’s just a simple line of JavaScript.
If you look at the source code for the plugin you’ll find it’s a very simple PasteFilter (see this previous article). The main method simply uses a regular expression to filter out the img tags:
public String filterIn(String source) {
String regex = "<img[^>]*";
if (FILTER_ONLY_LOCAL_IMAGES) {
regex += "src=[\"']file:[^>]*";
}
regex += "/?>";
Pattern pattern = Pattern.compile(regex,
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(source);
return matcher.replaceAll("");
}
FILTER_ONLY_LOCAL_IMAGES is a final variable declared at the top of the file. It’s set to false in the standard version so that all images are removed, but if you change it to true, only local images will be removed and remote images will be pasted normally. This is a great way to prevent users from pasting in local images but still allow them to use images from the repository or other sites. It also shows how simple it is to adapt the regular expression to be more selective about which images to filter out. With a little knowledge of regular expression and this plugin as a starting point you should be able to achieve whatever image filtering policy you need.

