Ticket #3407: 3407_2.patch
File 3407_2.patch, 12.4 KB (added by , 15 years ago) |
---|
-
_source/core/config.js
150 150 * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea'; 151 151 */ 152 152 153 plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,contextmenu,elementspath,enterkey,entities,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,preview,print, removeformat,save,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',153 plugins : 'about,basicstyles,blockquote,button,clipboard,colorbutton,contextmenu,elementspath,enterkey,entities,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,preview,print,protectedsource,removeformat,save,smiley,showblocks,sourcearea,stylescombo,table,tabletools,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc', 154 154 155 155 /** 156 156 * List of additional plugins to be loaded. This is a tool setting which -
_source/core/htmlparser/comment.js
45 45 if ( filter && !( comment = filter.onComment( comment ) ) ) 46 46 return; 47 47 48 writer.comment( comment ); 48 if ( typeof comment == 'string' ) 49 writer.comment( comment ); 50 else 51 { 52 var fragment = new CKEDITOR.htmlParser.fragment(); 53 fragment.add( comment ) 54 fragment.writeHtml( writer, filter ); 55 } 49 56 } 50 57 }; -
_source/core/htmlparser/element.js
124 124 if ( !( element = filter.onElement( element ) ) ) 125 125 return; 126 126 127 if ( element.name == writeName )127 if ( element.name == writeName || element.type == CKEDITOR.NODE_TEXT ) 128 128 break; 129 129 130 130 writeName = element.name; … … 135 135 attributes = element.attributes; 136 136 } 137 137 138 if ( element.type == CKEDITOR.NODE_TEXT ) 139 { 140 writer.text( element.value ); 141 return; 142 } 143 138 144 // Open element tag. 139 145 writer.openTag( writeName, attributes ); 140 146 -
_source/core/htmlparser/filter.js
11 11 { 12 12 this._ = 13 13 { 14 regExp : [], 14 15 elementNames : [], 15 16 attributeNames : [], 16 17 elements : { $length : 0 }, … … 29 30 priority = 10; 30 31 31 32 // Add the elementNames. 33 addItemsToList( this._.regExp, rules.regExp, priority ); 34 35 // Add the elementNames. 32 36 addItemsToList( this._.elementNames, rules.elementNames, priority ); 33 37 34 38 // Add the attributeNames. -
_source/core/htmlparser/text.js
12 12 * @constructor 13 13 * @example 14 14 */ 15 CKEDITOR.htmlParser.text = function( value )15 CKEDITOR.htmlParser.text = function( value, protect ) 16 16 { 17 17 /** 18 18 * The text value. 19 19 * @type String 20 20 * @example 21 21 */ 22 this.value = value.replace( spacesRegex, ' ' );22 this.value = protect ? value : value.replace( spacesRegex, ' ' ); 23 23 24 24 /** @private */ 25 25 this._ = 26 26 { 27 protect : protect, 27 28 isBlockLike : false 28 29 }; 29 30 }; … … 46 47 { 47 48 var text = this.value; 48 49 49 if ( filter && !( text = filter.onText( text ) ) )50 if ( !this._.protect && filter && !( text = filter.onText( text ) ) ) 50 51 return; 51 52 52 53 writer.text( text ); -
_source/plugins/fakeobjects/plugin.js
11 11 { 12 12 $ : function( element ) 13 13 { 14 var realHtml = element.attributes._cke_realelement, 15 realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ), 16 realElement = realFragment && realFragment.children[ 0 ]; 14 var realHtml = element.attributes && element.attributes._cke_realelement; 15 realHtml = realHtml && decodeURIComponent( realHtml ); 17 16 17 if ( realHtml && element.attributes._cke_protect ) 18 return new CKEDITOR.htmlParser.text( realHtml, true ); 19 20 var realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( realHtml ), 21 realElement = realFragment && realFragment.children[ 0 ]; 22 18 23 if ( realElement ) 19 24 { 20 25 // If we have width/height in the element, we must move it into … … 60 65 }); 61 66 })(); 62 67 63 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )68 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable, protectContent ) 64 69 { 65 70 var attributes = 66 71 { 67 72 'class' : className, 68 73 src : CKEDITOR.getUrl( 'images/spacer.gif' ), 69 _cke_realelement : encodeURIComponent( realElement.getOuterHtml() )74 _cke_realelement : encodeURIComponent( ( typeof realElement == 'string' ) ? realElement : realElement.getOuterHtml() ) 70 75 }; 71 76 if ( realElementType ) 72 77 attributes._cke_real_element_type = realElementType; 73 78 if ( isResizable ) 74 79 attributes._cke_resizable = isResizable; 80 if ( protectContent ) 81 { 82 attributes._cke_protect = true; 83 } 75 84 76 return this.document.createElement( 'img', { attributes : attributes } ); 85 var document = this.document || CKEDITOR.document; 86 return document.createElement( 'img', { attributes : attributes } ); 77 87 }; 78 88 79 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )89 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable, protectContent ) 80 90 { 81 91 var writer = new CKEDITOR.htmlParser.basicWriter(); 82 92 … … 91 101 _cke_realelement : encodeURIComponent( html ) 92 102 }; 93 103 104 if ( protectContent ) 105 attributes._cke_protect = true; 106 94 107 if ( realElementType ) 95 108 attributes._cke_real_element_type = realElementType; 96 109 -
_source/plugins/htmldataprocessor/plugin.js
111 111 return html.replace( protectAttributeRegex, '$& _cke_saved_$1' ); 112 112 } 113 113 114 function protectSource( html, filter ) 115 { 116 var rules = filter._.regExp; 117 118 for ( var i = 0 ; i < rules.length ; i++ ) 119 { 120 var rule = rules[ i ]; 121 html = html.replace( rule.regExp, rule.replaceWith ); 122 } 123 return html; 124 } 125 114 126 CKEDITOR.plugins.add( 'htmldataprocessor', 115 127 { 116 128 requires : [ 'htmlwriter' ], … … 140 152 // The source data is already HTML, but we need to clean 141 153 // it up and apply the filter. 142 154 143 // Before anything, we must protect the URL attributes as the 155 // Before anything, we must protect the PHP and ASP content. 156 data = protectSource( data, this.dataFilter ); 157 158 // We must protect the URL attributes as the 144 159 // browser may changing them when setting the innerHTML later in 145 160 // the code. 146 161 data = protectAttributes( data ); -
_source/plugins/protectedsource/plugin.js
1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.plugins.add( 'protectedsource', 7 { 8 requires : [ 'fakeobjects' ], 9 10 afterInit : function( editor ) 11 { 12 var protectedSource = editor.config.protectedSource, 13 dataProcessor = editor.dataProcessor, 14 dataFilter = dataProcessor && dataProcessor.dataFilter, 15 htmlFilter = dataProcessor && dataProcessor.htmlFilter; 16 17 if ( !dataFilter || !htmlFilter ) 18 return; 19 20 21 22 var regExpRules = 23 { 24 regExp : [] 25 }; 26 27 var addCss = false; 28 // Create rules. 29 for ( var i=0; i < protectedSource.length; i++ ) 30 { 31 var rule = protectedSource[ i ]; 32 addCss = addCss || !!rule.editable; 33 regExpRules.regExp.push( 34 (function( rule ) // Remember proper context. 35 { 36 return { 37 regExp : rule.regExp, 38 replaceWith : rule.replaceWith || function ( data ) 39 { 40 data = editor.restoreProtectedElement( data, false ); // Restore inner text to avoid the secont pass scaning. 41 return ( rule.editable ? 42 editor.createFakeElement( data, rule.className || "cke_code", rule.name, false, true ).getOuterHtml() 43 : 44 editor.createProtectedElement( data ).getOuterHtml()); 45 } 46 }; 47 })( rule ) 48 ); 49 } 50 51 // Add rules: Html to Data; 52 dataFilter.addRules( regExpRules ); 53 54 // Add rules: Data to Html. 55 htmlFilter.addRules( 56 { 57 comment : function( content ) 58 { 59 return CKEDITOR.editor.prototype.restoreProtectedElement( content, true ); 60 } 61 } 62 ); 63 if ( addCss ) 64 { 65 editor.addCss( 66 'img.cke_code' + 67 '{' + 68 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/code.gif' ) + ');' + 69 'background-position: center center;' + 70 'background-repeat: no-repeat;' + 71 'border: 1px solid #a9a9a9;' + 72 'width: 32px;' + 73 'height: 32px;' + 74 '}' ); 75 } 76 } 77 }); 78 79 80 CKEDITOR.editor.prototype.createProtectedElement = function( realElement ) 81 { 82 var encodeContent = function( data ) 83 { 84 data = encodeURIComponent( data ); 85 return data.replace( /--/g, "%2D%2D" ); // Protect comments in comment. 86 }; 87 88 var realdata = ( typeof realElement == 'string' ) ? realElement : realElement.getOuterHtml(), 89 content = "cke_protected(" + encodeContent( realdata ) + ")", 90 document = this.document || CKEDITOR.document; 91 92 return document.createElement( document.$.createComment( content ) ); 93 }; 94 95 CKEDITOR.editor.prototype.restoreProtectedElement = function( content, forParser ) 96 { 97 if ( forParser ) 98 { 99 var realData = content.match( /^cke_protected\((.*?)\)$/i ), 100 commentData = content.match( /^cke_comment\((.*?)\)$/i ); 101 102 if ( realData ) 103 { 104 realData = decodeURIComponent( realData[1] ); 105 return new CKEDITOR.htmlParser.text( realData, true ); // true = protect content. 106 } 107 108 return commentData ? decodeURIComponent( commentData[1] ) : content; 109 } 110 else 111 { 112 content = content.replace(/<\!--cke_protected\((.*?)\)-->/g, 113 function( comment ) 114 { 115 // Get the content. 116 return decodeURIComponent( 117 comment.substr( 18, ( comment.length -22 ) ) 118 ); 119 } 120 ); 121 122 content = content.replace( /<\!--cke_comment\((.*?)\)-->/g, 123 function( comment ) 124 { 125 return "<!--" + decodeURIComponent( 126 comment.substr( 16, ( comment.length -20 ) ) 127 ) + "-->"; 128 } 129 ); 130 return content; 131 } 132 }; 133 134 CKEDITOR.config.protectedSource = 135 [ 136 { // Protect existing coments before anything. 137 regExp : /<\!--[\s\S]*?-->/g, 138 replaceWith : function ( data ) 139 { 140 var realContent = data.substr( 4, ( data.length -7 ) ); // Get the content without HTML comment tag. 141 return "<!--cke_comment(" + 142 encodeURIComponent( realContent ) + ")-->"; // Use encodeURIComponent because there is no -- inside. 143 } 144 }, 145 { 146 name : "ASP", 147 regExp : /<%[\s\S]*?%>/g 148 }, 149 { 150 name : "ASP.Net", 151 regExp : /(<asp:[^\>]+>[\s|\S]*?<\/asp:[^\>]+>)|(<asp:[^\>]+\/>)/gi 152 }, 153 { 154 name : "php", 155 regExp : /<\?[\s\S]*?\?>/g 156 }, 157 { 158 name : "style", 159 regExp : /<style[^>]*>(.|\n|\r)*?<\/style[^>]*>/g 160 }, 161 { 162 name : "script", 163 regExp : /<script[^>]*>(.|\n|\r)*?<\/script[^>]*>/g 164 } 165 ]