I'm confused why it is commenting them. You've removed it from the protectedSource array right? If so then it should show normally in CKEditor.
I see you're using a filter priority of 2. Have you played with this number? Raising that (Try 10) might give your filter priority over whatever filter is "commenting out" the script (Beware that it might also return it as a data type other than 'comment' then). You can play around in Firebug to see what's actually coming through. Otherwise, there should be no reason that you can't use fakeObjects just like in the flash plugin.
comp615 wrote:I'm confused why it is commenting them. You've removed it from the protectedSource array right? If so then it should show normally in CKEditor.
Afaik, the script tag can't be removed from the protectedSource array, but I can't find the source right now and maybe I'm recalling wrong. Anyway no, I didn't.
EDIT: oh, yeah. Found the source: looking at plugins/htmldataprocessor/plugin.js function protectSource, the script and noscript tags are automatically appended to the protection regexes. I think I filed a bugreport for this, but was marked as non important and thus unknown resolving time. /EDIT
EDIT2 comp615, do you know how to un-protect the script tag? If you do, can you please provide a working example? Thanks for your help anyway /EDIT2
comp615 wrote:I see you're using a filter priority of 2. Have you played with this number? Raising that (Try 10) might give your filter priority over whatever filter is "commenting out" the script (Beware that it might also return it as a data type other than 'comment' then). You can play around in Firebug to see what's actually coming through. Otherwise, there should be no reason that you can't use fakeObjects just like in the flash plugin.
I tested both with low (0-1-2) and high (10-100) priorities, but it doesn't seems to change. Anyway it's a min priority queue, i.e. low priorities are executed first:
Bleh your right. I had it backwards from when I used it (just looked). Anyways, it's jsut a simple stack isn't it? COuldn't you in theory try poping items off the stack?
Alternatively, (And better in terms of figuring out if this is actually your problem) Just edit them out of the htmlprocessor then.
comp615 wrote:Bleh your right. I had it backwards from when I used it (just looked). Anyways, it's jsut a simple stack isn't it? COuldn't you in theory try poping items off the stack?
The problem is that the regexes for protecting script are inserted in the array just before protection occurs, and they are applied BEFORE any regex I may insert:
function protectSource( data, protectRegexes ) {
var regexes =[
( /<script[\s\S]*?<\/script>/gi ),
/<noscript[\s\S]*?<\/noscript>/gi
].concat( protectRegexes );
// blahblah
}
data = protectSource( data, this.editor.config.protectedSource );
comp615 wrote:Alternatively, (And better in terms of figuring out if this is actually your problem) Just edit them out of the htmlprocessor then.
Yes, I thought about this solution... But I don't really like to patch the source (as this could lead to hard-to-find bugs when updating the code, as not everyone reads the documentation). This is why I preferred to work with comments (but well, it's a bad solution as it depends on the source, too, although it's not intrusive).
Anyway, this was the past: the current situation is that I've to work on scripts and insert fake objects, so protection is no longer necessary and those regexes can be placed in the configuration.
I'm trying this approach now, I'll post the results asap.
I follow your instruction and it still does not work for me. There are no javascript errors. Something is going so wrong with dataFilter in afterInit, the alert('script present') is not executed. The text I input is simply '<script> alert('javascript') </script>'. The text is inserted in the ckeditor display successfully. Help is greatly appreciated.
Re: Filtering scripts before protection
Re: Filtering scripts before protection
afterInit: function(editor) { var dataProcessor = editor.dataProcessor; var dataFilter = dataProcessor && dataProcessor.dataFilter; if (dataFilter) { dataFilter.addRules({ comment: function(element) { alert("Found comment: " + element); return element; } }, 2); } }Re: Filtering scripts before protection
I see you're using a filter priority of 2. Have you played with this number? Raising that (Try 10) might give your filter priority over whatever filter is "commenting out" the script (Beware that it might also return it as a data type other than 'comment' then). You can play around in Firebug to see what's actually coming through. Otherwise, there should be no reason that you can't use fakeObjects just like in the flash plugin.
Re: Filtering scripts before protection
Afaik, the script tag can't be removed from the protectedSource array, but I can't find the source right now and maybe I'm recalling wrong. Anyway no, I didn't.
EDIT: oh, yeah. Found the source: looking at plugins/htmldataprocessor/plugin.js function protectSource, the script and noscript tags are automatically appended to the protection regexes. I think I filed a bugreport for this, but was marked as non important and thus unknown resolving time. /EDIT
EDIT2 comp615, do you know how to un-protect the script tag? If you do, can you please provide a working example? Thanks for your help anyway /EDIT2
I tested both with low (0-1-2) and high (10-100) priorities, but it doesn't seems to change. Anyway it's a min priority queue, i.e. low priorities are executed first:
dataFilter.addRules({ comment: function(element) { alert("Found comment 1:" + element); return element; } }, 10); dataFilter.addRules({ comment: function(element) { alert("Found comment 2:" + element); return element; } }, 2);"Found comment 2" happens always before comment 1, Q.E.D.
Re: Filtering scripts before protection
Alternatively, (And better in terms of figuring out if this is actually your problem) Just edit them out of the htmlprocessor then.
Re: Filtering scripts before protection
The problem is that the regexes for protecting script are inserted in the array just before protection occurs, and they are applied BEFORE any regex I may insert:
function protectSource( data, protectRegexes ) { var regexes =[ ( /<script[\s\S]*?<\/script>/gi ), /<noscript[\s\S]*?<\/noscript>/gi ].concat( protectRegexes ); // blahblah } data = protectSource( data, this.editor.config.protectedSource );Yes, I thought about this solution... But I don't really like to patch the source (as this could lead to hard-to-find bugs when updating the code, as not everyone reads the documentation). This is why I preferred to work with comments (but well, it's a bad solution as it depends on the source, too, although it's not intrusive).
Anyway, this was the past: the current situation is that I've to work on scripts and insert fake objects, so protection is no longer necessary and those regexes can be placed in the configuration.
I'm trying this approach now, I'll post the results asap.
Thanks for your help
~Aki
Re: Filtering scripts before protection
.myplug_script { border: 2px solid red; }afterInit: function(editor) { function createFakeElement(realElement) { var fakeElement = editor.createFakeParserElement(realElement, 'myplug_script', 'script', true), fakeStyle = fakeElement.attributes.style || ''; fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:10px;'; fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:10px;'; return fakeElement; } var dataProcessor = editor.dataProcessor; var dataFilter = dataProcessor && dataProcessor.dataFilter; if (dataFilter) { dataFilter.addRules({ elements: { 'script': function(element) { return createFakeElement(element); } } }, 2); // Low priority, it's not really necessary as nothing should touch the script before you } }Re: Filtering scripts before protection
viewtopic.php?f=11&t=19758
Re: Filtering scripts before protection
(function (pluginName) { function createFakeElement(editor, realElement) { var fakeElement = editor.createFakeParserElement(realElement, 'myplugin_script', 'script', false); var fakeStyle = fakeElement.attributes.style || ''; return fakeElement; } CKEDITOR.plugins.add(pluginName, { requires: ['fakeobjects'], init: function(editor) { /* My stuff */ }, afterInit: function(editor) { var dataProcessor = editor.dataProcessor; var dataFilter = dataProcessor && dataProcessor.dataFilter; if (dataFilter) { dataFilter.addRules({ elements: { 'script': function(element) { return createFakeElement(editor, element); } } }, 5); } } }); })('myplugin');Re: Filtering scripts before protection
Re: Filtering scripts before protection
I follow your instruction and it still does not work for me. There are no javascript errors. Something is going so wrong with dataFilter in afterInit, the alert('script present') is not executed. The text I input is simply '<script> alert('javascript') </script>'. The text is inserted in the ckeditor display successfully. Help is greatly appreciated.
/* * @example An iframe-based dialog with custom button handling logics. */ ( function() { CKEDITOR.plugins.add( 'MediaEmbed', { requires: [ 'dialog' ], init: function( editor ) { var me = this; CKEDITOR.dialog.add( 'MediaEmbedDialog', function () { return { title : 'Embed Media Dialog', minWidth : 550, minHeight : 100, contents : [ { id : 'dialog', label : 'Paste Embed Media', expand : true, elements : [ { type : 'textarea', id : 'pageMediaEmbed', label : 'Paste Embed Media', style : 'width:100%' } ] } ], onOk : function() { var content = CKEDITOR.dialog.getCurrent().getValueOf('dialog','pageMediaEmbed'); editor.insertHtml(content); } }; } ); editor.addCommand( 'MediaEmbed', new CKEDITOR.dialogCommand( 'MediaEmbedDialog' ) ); editor.ui.addButton( 'MediaEmbed', { label: 'Insert Embed Media', command: 'MediaEmbed', icon: this.path + 'images/icon.gif' } ); editor.addCss( 'img.cke_phpcode' + '{' + 'background-image: url(' + CKEDITOR.getUrl( this.path + 'placeholder.png' ) + ');' + 'background-position: center center;' + 'background-repeat: no-repeat;' + 'border: 0px;' + 'width: 13px;' + 'height: 13px;' + '}' ); }, afterInit : function( editor ) { var dataProcessor = editor.dataProcessor; var dataFilter = dataProcessor && dataProcessor.dataFilter; if (dataFilter) { dataFilter.addRules({ elements: { 'script': function(element) { alert('script present'); } } }, 10); } }, requires : [ 'fakeobjects' ] } ); } )();Re: Filtering scripts before protection