Ticket #36638: 36638.1.patch
File 36638.1.patch, 7.6 KB (added by , 8 years ago) |
---|
-
src/wp-admin/admin-ajax.php
62 62 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 63 63 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', 64 64 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post', 65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 65 'press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'test_url', 66 66 ); 67 67 68 68 // Deprecated -
src/wp-admin/includes/ajax-actions.php
3333 3333 3334 3334 wp_send_json_success( update_user_meta( get_current_user_id(), 'wporg_favorites', $username ) ); 3335 3335 } 3336 3337 /** 3338 * Ajax handler for testing if an URL exists. Used in the editor. 3339 * 3340 * @since 4.6.0 3341 */ 3342 function wp_ajax_test_url() { 3343 if ( ! current_user_can( 'edit_posts' ) || ! wp_verify_nonce( $_POST['nonce'], 'wp-test-url' ) ) { 3344 wp_send_json_error(); 3345 } 3346 3347 $href = esc_url_raw( $_POST['href'] ); 3348 3349 // Relative URL 3350 if ( strpos( $href, '//' ) !== 0 && in_array( $href[0], array( '/', '#', '?' ), true ) ) { 3351 $href = get_bloginfo( 'url' ) . $href; 3352 } 3353 3354 $response = wp_safe_remote_get( $href, array( 3355 'timeout' => 15, 3356 // Use an explicit user-agent 3357 'user-agent' => 'WordPress URL Test', 3358 ) ); 3359 3360 $message = null; 3361 3362 if ( is_wp_error( $response ) ) { 3363 $error = $response->get_error_message(); 3364 3365 if ( strpos( $message, 'resolve host' ) !== false ) { 3366 $message = array( 'error' => __( 'Invalid host name.' ) ); 3367 } 3368 3369 wp_send_json_error( $message ); 3370 } 3371 3372 if ( wp_remote_retrieve_response_code( $response ) === 404 ) { 3373 wp_send_json_error( array( 'error' => __( 'Not found, HTTP error 404.' ) ) ); 3374 } 3375 3376 wp_send_json_success(); 3377 } -
src/wp-includes/class-wp-editor.php
1063 1063 'Ctrl + letter:' => __( 'Ctrl + letter:' ), 1064 1064 'Letter' => __( 'Letter' ), 1065 1065 'Action' => __( 'Action' ), 1066 'Invalid host name.' => __( 'Invalid host name.' ), 1066 1067 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' => 1067 1068 __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ), 1068 1069 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' => … … 1283 1284 </script> 1284 1285 <?php 1285 1286 1286 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) 1287 $has_wplink = in_array( 'wplink', self::$plugins, true ); 1288 1289 if ( $has_wplink ) { 1290 echo '<input type="hidden" id="_wplink_urltest_nonce" value="' . wp_create_nonce( 'wp-test-url' ) . '" />'; 1291 } 1292 1293 if ( $has_wplink || in_array( 'link', self::$qt_buttons, true ) ) { 1287 1294 self::wp_link_dialog(); 1295 } 1288 1296 1289 1297 /** 1290 1298 * Fires after any core TinyMCE editor instances are created. -
src/wp-includes/css/editor.css
1757 1757 cursor: pointer; 1758 1758 } 1759 1759 1760 div.wp-link-preview a.wplink-url-error { 1761 color: #a00; 1762 } 1763 1764 div.wp-link-preview a.wplink-url-error:hover { 1765 color: #f00; 1766 } 1767 1760 1768 div.wp-link-input { 1761 1769 float: left; 1762 1770 margin: 2px; -
src/wp-includes/js/tinymce/plugins/wplink/plugin.js
93 93 var doingUndoRedo; 94 94 var doingUndoRedoTimer; 95 95 var $ = window.jQuery; 96 var urlErrors = {}; 96 97 97 98 function getSelectedLink() { 98 99 var href, html, … … 131 132 } 132 133 133 134 function removePlaceholderStrings( content, dataAttr ) { 134 if ( dataAttr ) { 135 content = content.replace( / data-wplink-edit="true"/g, '' ); 135 return content.replace( /(<a [^>]+>)([\s\S]*?)<\/a>/g, function( all, tag, text ) { 136 if ( tag.indexOf( ' href="_wp_link_placeholder"' ) > -1 ) { 137 return text; 138 } 139 140 if ( dataAttr ) { 141 tag = tag.replace( / data-wplink-edit="true"/g, '' ); 142 } 143 144 tag = tag.replace( / data-wplink-url-error="true"/g, '' ); 145 146 return tag + text + '</a>'; 147 }); 148 } 149 150 function checkLink( node ) { 151 var $link = editor.$( node ); 152 var href = $link.attr( 'href' ); 153 154 if ( ! href || typeof $ === 'undefined' ) { 155 return; 136 156 } 137 157 138 return content.replace( /<a [^>]*?href="_wp_link_placeholder"[^>]*>([\s\S]+)<\/a>/g, '$1' ); 158 // Early check 159 if ( /^http/i.test( href ) && ! /\.[a-z]{2,63}(\/|$)/i.test( href ) ) { 160 urlErrors[href] = tinymce.translate( 'Invalid host name.' ); 161 } 162 163 if ( urlErrors.hasOwnProperty( href ) ) { 164 $link.attr( 'data-wplink-url-error', 'true' ); 165 return; 166 } else { 167 $link.removeAttr( 'data-wplink-url-error' ); 168 } 169 170 $.post( 171 window.ajaxurl, { 172 action: 'test_url', 173 nonce: $( '#_wplink_urltest_nonce' ).val(), 174 href: href 175 }, 176 'json' 177 ).done( function( response ) { 178 if ( response.success ) { 179 return; 180 } 181 182 if ( response.data && response.data.error ) { 183 urlErrors[href] = response.data.error; 184 $link.attr( 'data-wplink-url-error', 'true' ); 185 186 if ( toolbar && toolbar.visible() ) { 187 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ).attr( 'title', editor.dom.encode( response.data.error ) ); 188 } 189 } 190 }); 139 191 } 140 192 141 193 editor.on( 'preinit', function() { … … 231 283 if ( ! tinymce.trim( linkNode.innerHTML ) ) { 232 284 editor.$( linkNode ).text( text || href ); 233 285 } 286 287 checkLink( linkNode ); 234 288 } 235 289 236 290 inputInstance.reset(); … … 473 527 474 528 editor.on( 'wptoolbar', function( event ) { 475 529 var linkNode = editor.dom.getParent( event.element, 'a' ), 476 $linkNode, href, edit ;530 $linkNode, href, edit, title; 477 531 478 532 if ( typeof window.wpLink !== 'undefined' && window.wpLink.modalOpen ) { 479 533 editToolbar.tempHide = true; … … 498 552 previewInstance.setURL( href ); 499 553 event.element = linkNode; 500 554 event.toolbar = toolbar; 555 title = urlErrors.hasOwnProperty( href ) ? editor.dom.encode( urlErrors[ href ] ) : null; 556 557 if ( $linkNode.attr( 'data-wplink-url-error' ) === 'true' ) { 558 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ).attr( 'title', title ); 559 } else { 560 toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' ).attr( 'title', null ); 561 } 501 562 } 502 563 } 503 564 } ); -
src/wp-includes/js/tinymce/skins/wordpress/wp-content.css
205 205 visibility: hidden; 206 206 } 207 207 208 a[data-wplink-url-error] { 209 color: #fff; 210 outline: 4px solid #b00; 211 background: #b00; 212 } 213 208 214 /** 209 215 * WP Views 210 216 */