Ticket #3407: 3407_2.patch

File 3407_2.patch, 12.4 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 )
    128128                                                break;
    129129
    130130                                        writeName = element.name;
     
    135135                                attributes = element.attributes;
    136136                        }
    137137
     138                        if ( element.type == CKEDITOR.NODE_TEXT )
     139                        {
     140                                writer.text( element.value );
     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/fakeobjects/plugin.js

     
    1111                {
    1212                        $ : function( element )
    1313                        {
    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 );
    1716
     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
    1823                                if ( realElement )
    1924                                {
    2025                                        // If we have width/height in the element, we must move it into
     
    6065        });
    6166})();
    6267
    63 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
     68CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable, protectContent )
    6469{
    6570        var attributes =
    6671        {
    6772                'class' : className,
    6873                src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    69                 _cke_realelement : encodeURIComponent( realElement.getOuterHtml() )
     74                _cke_realelement : encodeURIComponent( ( typeof realElement == 'string' ) ? realElement : realElement.getOuterHtml() )
    7075        };
    7176        if ( realElementType )
    7277                attributes._cke_real_element_type = realElementType;
    7378        if ( isResizable )
    7479                attributes._cke_resizable = isResizable;
     80        if ( protectContent )
     81        {
     82                attributes._cke_protect = true;
     83        }
    7584
    76         return this.document.createElement( 'img', { attributes : attributes } );
     85        var document = this.document || CKEDITOR.document;
     86        return document.createElement( 'img', { attributes : attributes } );
    7787};
    7888
    79 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
     89CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable, protectContent )
    8090{
    8191        var writer = new CKEDITOR.htmlParser.basicWriter();
    8292
     
    91101                _cke_realelement : encodeURIComponent( html )
    92102        };
    93103
     104        if ( protectContent )
     105                attributes._cke_protect = true;
     106
    94107        if ( realElementType )
    95108                attributes._cke_real_element_type = realElementType;
    96109
  • _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

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6CKEDITOR.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
     80CKEDITOR.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
     95CKEDITOR.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
     134CKEDITOR.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]
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy