76 | | urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/, |
77 | | selectableTargets = /^(_(?:self|top|parent|blank))$/; |
| 76 | urlRegex = /^(?!javascript)((?:http|https|ftp|news):\/\/)?(.*)$/, |
| 77 | selectableTargets = /^(_(?:self|top|parent|blank))$/, |
| 78 | encodedEmailLinkRegex = /^javascript:void\(location\.href='mailto:'\+String\.fromCharCode\(([^)]+)\)(?:\+'(.*)')?\)$/, |
| 79 | functionCallProtectedEmailLinkRegex = /^javascript:([^(]+)\(([^)]+)\)$/; |
| 100 | else if ( anchorMatch = href.match( anchorRegex ) ) |
| 101 | { |
| 102 | retval.type = 'anchor'; |
| 103 | retval.anchor = {}; |
| 104 | retval.anchor.name = retval.anchor.id = anchorMatch[1]; |
| 105 | } |
| 106 | // Protected email link as encoded string. |
| 107 | else if ( !emailProtection || emailProtection == 'encode' ) |
| 108 | { |
| 109 | if( emailProtection == 'encode' ) |
| 110 | { |
| 111 | href = href.replace( encodedEmailLinkRegex, |
| 112 | function ( match, protectedAddress, rest ) |
| 113 | { |
| 114 | return 'mailto:' + |
| 115 | String.fromCharCode.apply( String, protectedAddress.split( ',' ) ) + |
| 116 | ( rest && unescapeSingleQuote( rest ) ); |
| 117 | } ); |
| 118 | } |
98 | | // Load the link type and URL. |
99 | | if ( emailMatch ) |
100 | | { |
101 | | var subjectMatch = href.match( emailSubjectRegex ), |
102 | | bodyMatch = href.match( emailBodyRegex ); |
103 | | retval.type = 'email'; |
104 | | retval.email = {}; |
105 | | retval.email.address = emailMatch[1]; |
106 | | subjectMatch && ( retval.email.subject = decodeURIComponent( subjectMatch[1] ) ); |
107 | | bodyMatch && ( retval.email.body = decodeURIComponent( bodyMatch[1] ) ); |
108 | | } |
109 | | else if ( anchorMatch ) |
110 | | { |
111 | | retval.type = 'anchor'; |
112 | | retval.anchor = {}; |
113 | | retval.anchor.name = retval.anchor.id = anchorMatch[1]; |
| 120 | emailMatch = href.match( emailRegex ); |
| 121 | |
| 122 | if( emailMatch ) |
| 123 | { |
| 124 | var subjectMatch = href.match( emailSubjectRegex ), |
| 125 | bodyMatch = href.match( emailBodyRegex ); |
| 126 | |
| 127 | retval.type = 'email'; |
| 128 | var email = ( retval.email = {} ); |
| 129 | email.address = emailMatch[ 1 ]; |
| 130 | subjectMatch && ( email.subject = decodeURIComponent( subjectMatch[ 1 ] ) ); |
| 131 | bodyMatch && ( email.body = decodeURIComponent( bodyMatch[ 1 ] ) ); |
| 132 | } |
117 | | retval.type = 'url'; |
118 | | retval.url = {}; |
119 | | retval.url.protocol = urlMatch[1]; |
120 | | retval.url.url = urlMatch[2]; |
121 | | } |
| 137 | href.replace( functionCallProtectedEmailLinkRegex, function( match, funcName, funcArgs ) |
| 138 | { |
| 139 | if( funcName == compiledProtectionFunction.name ) |
| 140 | { |
| 141 | retval.type = 'email'; |
| 142 | var email = retval.email = {}; |
| 143 | |
| 144 | var paramRegex = /[^,\s]+/g, |
| 145 | paramQuoteRegex = /(^')|('$)/g, |
| 146 | paramsMatch = funcArgs.match( paramRegex ), |
| 147 | paramsMatchLength = paramsMatch.length, |
| 148 | paramName, |
| 149 | paramVal; |
| 150 | |
| 151 | for ( var i = 0; i < paramsMatchLength; i++ ) |
| 152 | { |
| 153 | paramVal = decodeURIComponent( unescapeSingleQuote( paramsMatch[ i ].replace( paramQuoteRegex, '' ) ) ); |
| 154 | paramName = compiledProtectionFunction.params[ i ].toLowerCase(); |
| 155 | email[ paramName ] = paramVal; |
| 156 | } |
| 157 | email.address = [ email.name, email.domain ].join( '@' ); |
| 158 | } |
| 159 | } ); |
| 160 | } |
| 287 | function unescapeSingleQuote( str ) |
| 288 | { |
| 289 | return str.replace( /\\'/g, '\'' ); |
| 290 | } |
| 291 | |
| 292 | function escapeSingleQuote( str ) |
| 293 | { |
| 294 | return str.replace( /'/g, '\\$&' ); |
| 295 | } |
| 296 | |
| 297 | var emailProtection = editor.config.emailProtection || ''; |
| 298 | |
| 299 | // Compile the protection function pattern. |
| 300 | if( emailProtection && emailProtection != 'encode' ) |
| 301 | { |
| 302 | var compiledProtectionFunction = {}; |
| 303 | |
| 304 | emailProtection.replace( /^([^(]+)\(([^)]+)\)$/, function( match, funcName, params ) |
| 305 | { |
| 306 | compiledProtectionFunction.name = funcName; |
| 307 | compiledProtectionFunction.params = []; |
| 308 | params.replace( /[^,\s]+/g, function( param ) |
| 309 | { |
| 310 | compiledProtectionFunction.params.push( param ); |
| 311 | } ); |
| 312 | } ); |
| 313 | } |
| 314 | |
| 315 | function protectEmailLinkAsFunction( email ) |
| 316 | { |
| 317 | var retval, |
| 318 | name = compiledProtectionFunction.name, |
| 319 | params = compiledProtectionFunction.params, |
| 320 | paramName, |
| 321 | paramValue; |
| 322 | |
| 323 | retval = [ name, '(' ]; |
| 324 | for ( var i = 0; i < params.length; i++ ) |
| 325 | { |
| 326 | paramName = params[ i ].toLowerCase(); |
| 327 | paramValue = email[ paramName ]; |
| 328 | |
| 329 | i > 0 && retval.push( ',' ); |
| 330 | retval.push( '\'', |
| 331 | paramValue ? |
| 332 | escapeSingleQuote( encodeURIComponent( email[ paramName ] ) ) |
| 333 | : '', |
| 334 | '\''); |
| 335 | } |
| 336 | retval.push( ')' ); |
| 337 | return retval.join( '' ); |
| 338 | } |
| 339 | |
| 340 | function protectEmailAddressAsEncodedString( address ) |
| 341 | { |
| 342 | var charCode, |
| 343 | length = address.length, |
| 344 | encodedChars = []; |
| 345 | for ( var i = 0; i < length; i++ ) |
| 346 | { |
| 347 | charCode = address.charCodeAt( i ); |
| 348 | encodedChars.push( charCode ); |
| 349 | } |
| 350 | return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')'; |
| 351 | } |
| 352 | |
1068 | | var argList = []; |
1069 | | linkList.push( '?' ); |
1070 | | subject && argList.push( 'subject=' + subject ); |
1071 | | body && argList.push( 'body=' + body ); |
1072 | | linkList.push( argList.join( '&' ) ); |
1073 | | } |
1074 | | attributes._cke_saved_href = linkList.join( '' ); |
1075 | | break; |
1076 | | default: |
1077 | | } |
| 1175 | case '' : |
| 1176 | case 'encode' : |
| 1177 | { |
| 1178 | var subject = encodeURIComponent( email.subject || '' ), |
| 1179 | body = encodeURIComponent( email.body || '' ); |
| 1180 | |
| 1181 | // Build the e-mail parameters first. |
| 1182 | var argList = []; |
| 1183 | subject && argList.push( 'subject=' + subject ); |
| 1184 | body && argList.push( 'body=' + body ); |
| 1185 | argList = argList.length ? '?' + argList.join( '&' ) : ''; |
| 1186 | |
| 1187 | if ( emailProtection == 'encode' ) |
| 1188 | { |
| 1189 | linkHref = [ 'javascript:void(location.href=\'mailto:\'+', |
| 1190 | protectEmailAddressAsEncodedString( address ) ]; |
| 1191 | // parameters are optional. |
| 1192 | argList && linkHref.push( '+\'', escapeSingleQuote( argList ), '\'' ); |
| 1193 | |
| 1194 | linkHref.push( ')' ); |
| 1195 | } |
| 1196 | else |
| 1197 | linkHref = [ 'mailto:', address, argList ]; |
| 1198 | |
| 1199 | break; |
| 1200 | } |
| 1201 | default : |
| 1202 | { |
| 1203 | // Separating name and domain. |
| 1204 | var nameAndDomain = address.split( '@', 2 ); |
| 1205 | email.name = nameAndDomain[ 0 ]; |
| 1206 | email.domain = nameAndDomain[ 1 ]; |
| 1207 | |
| 1208 | linkHref = [ 'javascript:', protectEmailLinkAsFunction( email ) ]; |
| 1209 | } |
| 1210 | } |
1221 | | } ); |
| 1358 | } ) |
| 1359 | |
| 1360 | /** |
| 1361 | * The e-mail address anti-spam protection option. |
| 1362 | * @name CKEDITOR.config.emailProtection |
| 1363 | * @type {String} |
| 1364 | * Two forms of protection could be choosed from : |
| 1365 | * 1. The whole address parts ( name, domain with any other query string ) are assembled into a |
| 1366 | * function call pattern which invoke you own provided function, with the specified arguments. |
| 1367 | * 2. Only the e-mail address is obfuscated into unicode code point sequences, replacement are |
| 1368 | * done by a String.fromCharCode() call. |
| 1369 | * Note: Both approaches require JavaScript to be enabled. |
| 1370 | * @default '' |
| 1371 | * @example |
| 1372 | * config.emailProtection = ''; |
| 1373 | * // href="mailto:tester@ckeditor.com?subject=subject&body=body" |
| 1374 | * config.emailProtection = 'encode'; |
| 1375 | * // 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>" |
| 1376 | * config.emailProtection = 'mt(NAME,DOMAIN,SUBJECT,BODY)'; |
| 1377 | * // href="javascript:mt('tester','ckeditor.com','subject','body')" |
| 1378 | */ |