Ticket #3407: 3407_3.patch

File 3407_3.patch, 9.5 KB (added by Artur Formella, 15 years ago)
  • _source/core/config.js

     
    150150         * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea';
    151151         */
    152152
    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',
    154154
    155155        /**
    156156         * List of additional plugins to be loaded. This is a tool setting which
  • _source/core/htmlparser/comment.js

     
    4545                if ( filter && !( comment = filter.onComment( comment ) ) )
    4646                        return;
    4747
    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                }
    4956        }
    5057};
  • _source/core/htmlparser/element.js

     
    124124                                        if ( !( element = filter.onElement( element ) ) )
    125125                                                return;
    126126
    127                                         if ( element.name == writeName )
     127                                        if ( element.name == writeName || element.type == CKEDITOR.NODE_TEXT || element.type == CKEDITOR.NODE_COMMENT )
    128128                                                break;
    129129
    130130                                        writeName = element.name;
     
    135135                                attributes = element.attributes;
    136136                        }
    137137
     138                        if ( element.type == CKEDITOR.NODE_COMMENT || element.type == CKEDITOR.NODE_TEXT )
     139                        {
     140                                element.writeHtml( writer );
     141                                return;
     142                        }
     143
    138144                        // Open element tag.
    139145                        writer.openTag( writeName, attributes );
    140146
  • _source/core/htmlparser/filter.js

     
    1111                {
    1212                        this._ =
    1313                        {
     14                                regExp : [],
    1415                                elementNames : [],
    1516                                attributeNames : [],
    1617                                elements : { $length : 0 },
     
    2930                                        priority = 10;
    3031
    3132                                // Add the elementNames.
     33                                addItemsToList( this._.regExp, rules.regExp, priority );
     34
     35                                // Add the elementNames.
    3236                                addItemsToList( this._.elementNames, rules.elementNames, priority );
    3337
    3438                                // Add the attributeNames.
  • _source/core/htmlparser/text.js

     
    1212         * @constructor
    1313         * @example
    1414         */
    15         CKEDITOR.htmlParser.text = function( value )
     15        CKEDITOR.htmlParser.text = function( value, protect )
    1616        {
    1717                /**
    1818                 * The text value.
    1919                 * @type String
    2020                 * @example
    2121                 */
    22                 this.value = value.replace( spacesRegex, ' ' );
     22                this.value = protect ? value : value.replace( spacesRegex, ' ' );
    2323
    2424                /** @private */
    2525                this._ =
    2626                {
     27                        protect : protect,
    2728                        isBlockLike : false
    2829                };
    2930        };
     
    4647                {
    4748                        var text = this.value;
    4849
    49                         if ( filter && !( text = filter.onText( text ) ) )
     50                        if ( !this._.protect && filter && !( text = filter.onText( text ) ) )
    5051                                return;
    5152
    5253                        writer.text( text );
  • _source/plugins/htmldataprocessor/plugin.js

     
    111111                return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );
    112112        }
    113113
     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
    114126        CKEDITOR.plugins.add( 'htmldataprocessor',
    115127        {
    116128                requires : [ 'htmlwriter' ],
     
    140152                        // The source data is already HTML, but we need to clean
    141153                        // it up and apply the filter.
    142154
    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
    144159                        // browser may changing them when setting the innerHTML later in
    145160                        // the code.
    146161                        data = protectAttributes( data );
  • _source/plugins/protectedsource/plugin.js

    Property changes on: _source\plugins\protectedsource
    ___________________________________________________________________
    Added: bugtraq:label
       + Ticket
    Added: bugtraq:url
       + http://dev.fckeditor.net/ticket/%BUGID%
    Added: webviewer:pathrevision
       + http://dev.fckeditor.net/browser/%PATH%?rev=%REVISION% 
    Added: webviewer:revision
       + http://dev.fckeditor.net/changeset/%REVISION%
    Added: bugtraq:logregex
       + (?:ticket: *|#)(\d+) *(?:, *(\d+))*
    
    
     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6(function()
     7{
     8        var encodeContent = function( data )
     9        {
     10                return encodeURIComponent( data ).replace( /--/g, "%2D%2D" );           // Protect comments in comment.
     11        };
     12
     13        var createProtectedElement = function( realElement )
     14        {
     15                var realdata = ( typeof realElement == 'string' ) ? realElement : realElement.getOuterHtml(),
     16                        realdata = restoreProtectedElement( realdata, false ),                                  // Restore inner text to avoid the second pass.
     17                        content = "cke_protected(" + encodeContent( realdata ) + ")",
     18                        doc = CKEDITOR.document;
     19                       
     20                return doc.createElement( doc.$.createComment( content ) );
     21        };
     22
     23        var createProtectedParserElement = function( element )
     24        {
     25                var writer = new CKEDITOR.htmlParser.basicWriter();
     26                element.writeHtml( writer );
     27
     28                var content = restoreProtectedElement( writer.getHtml(), false );                       // Restore inner text to avoid the second pass.
     29                content = "cke_protected(" + encodeContent( content ) + ")";
     30                return new CKEDITOR.htmlParser.comment( content );
     31        };
     32
     33        var restoreProtectedElement = function( content, forParser )
     34        {
     35                if ( forParser )
     36                {
     37                        var realData = content.match( /^cke_protected\((.*?)\)$/i );
     38                        if ( realData )
     39                        {
     40                                realData = decodeURIComponent( realData[1] );
     41                                return new CKEDITOR.htmlParser.text( realData, true );  // true = protect content.
     42                        }
     43                        return content;
     44                }
     45                else
     46                {
     47                        content = content.replace(/<\!--cke_protected\((.*?)\)-->/g,
     48                                function( comment )
     49                                        {
     50                                                return decodeURIComponent(
     51                                                                comment.substr( 18, ( comment.length -22 ) )                                    // Get the content.
     52                                                        );
     53                                        }
     54                        );
     55                        return content;
     56                }
     57        };
     58       
     59        CKEDITOR.plugins.add( 'protectedsource',
     60        {
     61                afterInit : function( editor )
     62                {
     63                        var protectedSource = editor.config.protectedSource,
     64                                dataProcessor = editor.dataProcessor,
     65                                dataFilter = dataProcessor && dataProcessor.dataFilter,
     66                                htmlFilter = dataProcessor && dataProcessor.htmlFilter;
     67
     68                        if ( !dataFilter || !htmlFilter )
     69                                return;
     70
     71                        var rules =
     72                        {
     73                                regExp : [],
     74                                elements : []
     75                        };
     76
     77                        // Create rules.
     78                        for ( var i=0; i < protectedSource.length; i++ )
     79                        {
     80                                var rule = protectedSource[ i ];
     81                                if ( rule.regExp )
     82                                {
     83                                        rules.regExp.push(
     84                                                {
     85                                                        regExp : rule.regExp,
     86                                                        replaceWith : rule.replaceWith || function ( data )
     87                                                        {
     88                                                                return createProtectedElement( data ).getOuterHtml();
     89                                                        }
     90                                                }
     91                                        );
     92                                }
     93                                else if ( rule.element )
     94                                        rules.elements[ rule.element ] = createProtectedParserElement;
     95                        }
     96
     97                        // Add rules: Html to Data;
     98                        dataFilter.addRules( rules );
     99                               
     100                        // Add rules: Data to Html.
     101                        htmlFilter.addRules(
     102                                {
     103                                        comment : function( content )
     104                                        {
     105                                                return restoreProtectedElement( content, true );
     106                                        }
     107                                }
     108                        );
     109
     110                }
     111        });
     112})();
     113
     114CKEDITOR.config.protectedSource =
     115[
     116        {       // Protect existing coments before anything.
     117                regExp : /<\!--[\s\S]*?-->/g
     118        },
     119        {
     120                name : 'ASP',
     121                regExp : /<%[\s\S]*?%>/g
     122        },
     123        {
     124                name : 'ASP.Net',
     125                regExp : /(<asp:[^\>]+>[\s|\S]*?<\/asp:[^\>]+>)|(<asp:[^\>]+\/>)/gi
     126        },
     127        {
     128                name : 'php',
     129                regExp : /<\?[\s\S]*?\?>/g
     130        },
     131        {
     132                name : 'style',
     133                regExp : /<style[^>]*>(.|\n|\r)*?<\/style[^>]*>/g
     134        },
     135        {
     136                name : 'script',
     137                element : 'script'
     138        }
     139]
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy