Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set up TinyMCE so that it won't allow inline data images?

I have a TinyMCE installation on a CMS and the users have been pasting in images which are of the inline data type. This kind of thing:

<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub/
/ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp
V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" 
width="16" height="14" alt="embedded folder icon">

They are pasting in some pretty large images, and the content gets stored in a database. This is making the database grow very quickly in size, and there is already a media upload component available, so how can I simply prevent the editor from accepting this type of image?

like image 275
cwd Avatar asked Sep 27 '11 17:09

cwd


People also ask

Is TinyMCE free for commercial use?

Is TinyMCE free? Yes. The TinyMCE core editor is free to use for commercial and noncommercial purposes.

What is TinyMCE plugin?

TinyMCE is an incredibly powerful, flexible and customizable rich text editor. This section will help configure and extend the editor by using TinyMCE plugins.


1 Answers

This depends on what you want. Due to the fact that you won't be able to disallow this kind of element using valid_elements and child_elements you will have to go other ways.

Case 1: You do not want user to enter this kind of image onPaste.

You will need to use the paste plugin and set the parameter paste_pre

paste_preprocess : function(pl, o) {
    window.console && console.log('Object', o);
    window.console && console.log('Content:', o.content);

    // modify o.content here -> remove images of that kind
    o.content = o.content.substr(...)
}

Case 2: You want the images to be filtered out before they are getting saved into the DB.

You may use the tinymce setup paramter combined with onSave to get rid of them.

From what you describe you seem to be wanting Case 1.

like image 61
Thariama Avatar answered Sep 27 '22 17:09

Thariama