Ticket #4340: 4340.patch

File 4340.patch, 7.5 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/link/plugin.js

     
    122122
    123123        afterInit : function( editor )
    124124        {
     125
     126                var protectFuncRegex = /^([^(]+)\(([^)]+)\)$/,
     127                        functionInfo = {};
     128
     129                editor.config.mailProtection.replace( protectFuncRegex, function( match, funcName, params )
     130                {
     131                        functionInfo.name = funcName;
     132                        functionInfo.params = [];
     133                        params.replace( /[^,]+/g, function( param )
     134                        {
     135                                functionInfo.params.push( param );
     136                        } );
     137                } );
     138
     139                function stringCodes( str )
     140                {
     141                        var char,
     142                                charCode,
     143                                result = [];
     144                        for ( var i = 0; i < str.length; i++ )
     145                        {
     146                                charCode = str.charCodeAt( i );
     147                                result.push( charCode );
     148                        }
     149                        return result;
     150                }
     151
    125152                // Register a filter to displaying placeholders after mode change.
    126153
    127154                var dataProcessor = editor.dataProcessor,
    128                         dataFilter = dataProcessor && dataProcessor.dataFilter;
     155                        dataFilter = dataProcessor && dataProcessor.dataFilter,
     156                        htmlFilter = dataProcessor && dataProcessor.htmlFilter;
    129157
    130158                if ( dataFilter )
    131159                {
     
    141169                                                }
    142170                                        }
    143171                                });
    144                 }
     172
     173                        dataFilter.addRules(
     174                        {
     175                                elements :
     176                                {
     177                                        a : function( element )
     178                                        {
     179                                                var mailProtection = editor.config.mailProtection,
     180                                                        encodeProtection = mailProtection == 'encode',
     181                                                        protectFunction = !encodeProtection,
     182                                                        href = element.attributes.href,
     183                                                        unProtectedHref;
     184
     185                                                if( protectFunction )
     186                                                {
     187                                                        href.replace( /^javascript:([^(]+)\(([^)]+)\)$/, function( match, funcName, args )
     188                                                        {
     189                                                                if( funcName == functionInfo.name )
     190                                                                {
     191                                                                        var mailInSequence = [],
     192                                                                                priority = { name : -2, domain: -1 },
     193                                                                                index = 0,
     194                                                                                paramName;
     195                                                                        unProtectedHref = [ 'mailto:' ];
     196                                                                        args.replace( /[^,]+/g, function( param )
     197                                                                        {
     198                                                                                param = param.replace( /(^')|('$)/g, '' ).replace( /\\'/g, '\'' );
     199                                                                                paramName = functionInfo.params[ index ];
     200                                                                                paramName = paramName && paramName.toLowerCase();
     201                                                                                paramName && mailInSequence.push( [ paramName, param ] );
     202                                                                                index++;
     203                                                                        } );
     204
     205                                                                        mailInSequence.sort( function( a, b )
     206                                                                        {
     207                                                                                return ( priority[ a [ 0 ] ] || a [ 0 ].charCodeAt( 0 ) )
     208                                                                                                > ( priority[ b [ 0 ] ] || b [ 0 ].charCodeAt( 0 ) );
     209                                                                        } );
     210
     211                                                                        for ( var i = 0; i < mailInSequence.length; i++ )
     212                                                                        {
     213                                                                                if( i < 2 )
     214                                                                                {
     215                                                                                        if( i == 1 )
     216                                                                                                unProtectedHref.push( '@' );
     217                                                                                        unProtectedHref.push( mailInSequence[ i ][ 1 ] );
     218                                                                                }
     219                                                                                else
     220                                                                                {
     221                                                                                        if( i == 2 )
     222                                                                                                unProtectedHref.push( '?' );
     223                                                                                        else
     224                                                                                                unProtectedHref.push( '&' );
     225                                                                                        unProtectedHref.push( mailInSequence[ i ][ 0 ], '=', mailInSequence[ i ][ 1 ] );
     226                                                                                }
     227                                                                        }
     228
     229                                                                        unProtectedHref = unProtectedHref.join( '' );
     230                                                                }
     231                                                        } );
     232                                                }
     233                                                else if( encodeProtection )
     234                                                {
     235                                                        href.replace( /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)\+'(.*)'\)$/,
     236                                                                        function ( match, mailAddressCharCodes, rest )
     237                                                                {
     238                                                                        unProtectedHref = 'mailto:'
     239                                                                                        + String.fromCharCode.apply( String, mailAddressCharCodes.split( ',' ) )
     240                                                                                        + rest;
     241                                                                } );
     242                                                }
     243
     244                                                unProtectedHref &&
     245                                                        ( element.attributes[ '_cke_saved_href' ] = element.attributes.href = unProtectedHref );
     246                                        }
     247                                }
     248                        } );
     249
     250                        htmlFilter.addRules(
     251                        {
     252                                elements :
     253                                {
     254                                        a : function( element )
     255                                        {
     256                                                var mailProtection = editor.config.mailProtection,
     257                                                        encodeProtection = mailProtection == 'encode',
     258                                                        protectFunction = !encodeProtection && editor.config.mailProtection,
     259                                                        emailInfo = {},
     260                                                        emailSequence = [],
     261                                                        href = element.attributes[ '_cke_saved_href' ],
     262                                                        protectedHref;
     263
     264                                                href.replace( /&amp;/, '&')
     265                                                        .replace( /^mailto:([^?]+)@([^?]+)(.*)$/,
     266                                                                function ( match, name, domain, rest )
     267                                                                {
     268                                                                        if ( protectFunction )
     269                                                                        {
     270                                                                                emailInfo[ 'name' ] = name;
     271                                                                                emailInfo[ 'domain' ] = domain;
     272                                                                        }
     273                                                                        else
     274                                                                                emailSequence.push( name, domain );
     275
     276                                                                        rest.replace( /([^?&]+)=([^?&]+)/g,
     277                                                                                        function ( match, name, value )
     278                                                                                        {
     279                                                                                                if( protectFunction )
     280                                                                                                    emailInfo[ name ] = value;
     281                                                                                                else
     282                                                                                                        emailSequence.push( match );
     283                                                                                        } );
     284                                                                } );
     285
     286                                                if( protectFunction && !CKEDITOR.tools.isEmpty( emailInfo ) )
     287                                                {
     288                                                        var name = functionInfo.name,
     289                                                                params = functionInfo.params,
     290                                                                paramName;
     291
     292                                                        protectedHref = [ 'javascript:', name, '(' ];
     293
     294                                                        for ( var i = 0; i < params.length; i++ )
     295                                                        {
     296                                                                paramName = params[ i ].toLowerCase();
     297
     298                                                                if ( emailInfo[ paramName ] )
     299                                                                {
     300                                                                        i > 0 && protectedHref.push( ',' );
     301                                                                        protectedHref.push('\'', emailInfo[ paramName ].replace( /'/g, '\\$&' ), '\'');
     302                                                                }
     303                                                        }
     304                                                        protectedHref.push( ')' );
     305                                                }
     306                                                else if( encodeProtection && emailSequence.length )
     307                                                {
     308                                                        protectedHref = ['javascript:void(location.href=\'mailto:\'+'];
     309                                                        for ( i = 0; i < emailSequence.length; i++ )
     310                                                        {
     311                                                                if( i == 1 )
     312                                                                {
     313                                                                        protectedHref.push( 'String.fromCharCode(',
     314                                                                                        stringCodes( emailSequence[ 0 ] + '@' + emailSequence[ 1 ] ).join( ',' ),
     315                                                                                        ')' );
     316                                                                }
     317                                                                else if( i > 1 )
     318                                                                        protectedHref.push( i == 2 ? '+\'?' : '&', emailSequence[ i ] );
     319                                                        }
     320
     321                                                        protectedHref.push( '\')' );
     322                                                }
     323
     324                                                protectedHref && ( element.attributes[ '_cke_saved_href' ] = protectedHref.join( '' ) );
     325                                        }
     326                                }
     327                        } );
     328                }
    145329        },
    146330
    147331        requires : [ 'fakeobjects' ]
  • _source/core/config.js

     
    282282         * @example
    283283         * config.baseFloatZIndex = 2000
    284284         */
    285         baseFloatZIndex : 10000
     285        baseFloatZIndex : 10000,
    286286
     287        /**
     288         * The e-mail address anti-spam protection option.
     289         * @type String
     290         * Two forms of protection could be choosed from :
     291         * 1. The whole address parts ( name, domain with any other query string ) are assembled into a
     292         *   function call pattern which invoke you own provided function, with the specified arguments.
     293         * 2. Only the e-mail address is obfuscated into their corresponding ASC2 values, replacement are
     294         *   done by a String.fromCharCode() call.
     295         * Note: Both approaches require JavaScript to be enabled.
     296         * @default false
     297         * @example
     298         * config.mailProtection = '';
     299         * // href="mailto:tester@ckeditor.com?subject=subject&body=body"
     300         * config.mailProtection = 'encode';
     301         * // href="<a href=\"javascript:void(location.href=\'mailto:\'+String.fromCharCode(116,101,115,116,101,114,64,99,107,101,100,105,116,111,114,46,99,111,109)+\'?subject=subject&body=body\')\">e-mail</a>"
     302         * config.mailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)';
     303         * // href="javascript:mt('tester','ckeditor.com','subject','body')"
     304         */
     305        mailProtection : ''
    287306};
    288307
    289308// PACKAGER_RENAME( CKEDITOR.config )
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy