Changeset 38126
- Timestamp:
- 07/21/2016 03:41:17 AM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
-
wp-admin/includes/ajax-actions.php (modified) (2 diffs)
-
wp-includes/class-wp-editor.php (modified) (1 diff)
-
wp-includes/js/tinymce/plugins/wplink/plugin.js (modified) (9 diffs)
-
wp-includes/js/wplink.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r38119 r38126 3907 3907 } 3908 3908 3909 // No redirects 3909 3910 $response = wp_safe_remote_get( $href, array( 3910 3911 'timeout' => 15, … … 3913 3914 ) ); 3914 3915 3915 $ message = null;3916 $error = false; 3916 3917 3917 3918 if ( is_wp_error( $response ) ) { 3918 $error = $response->get_error_message(); 3919 3920 if ( strpos( $message, 'resolve host' ) !== false ) { 3921 $message = array( 'error' => __( 'Invalid host name.' ) ); 3922 } 3923 3924 wp_send_json_error( $message ); 3925 } 3926 3927 if ( wp_remote_retrieve_response_code( $response ) === 404 ) { 3928 wp_send_json_error( array( 'error' => __( 'Not found, HTTP error 404.' ) ) ); 3919 if ( strpos( $response->get_error_message(), 'resolve host' ) !== false ) { 3920 $error = true; 3921 } 3922 } elseif ( wp_remote_retrieve_response_code( $response ) === 404 ) { 3923 $error = true; 3924 } 3925 3926 if ( $error ) { 3927 wp_send_json_error( array( 'httpError' => true ) ); 3929 3928 } 3930 3929 -
trunk/src/wp-includes/class-wp-editor.php
r38110 r38126 1066 1066 'Letter' => __( 'Letter' ), 1067 1067 'Action' => __( 'Action' ), 1068 ' Invalid host name.' => __( 'Invalid host name.' ),1068 'Warning: the link has been inserted but the destination cannot be reached.' => __( 'Warning: the link has been inserted but the destination cannot be reached.' ), 1069 1069 '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.' => 1070 1070 __( '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.' ), -
trunk/src/wp-includes/js/tinymce/plugins/wplink/plugin.js
r37927 r38126 95 95 var $ = window.jQuery; 96 96 var urlErrors = {}; 97 var emailRegex = /^(mailto:)?[a-z0-9._%+-]+@[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}$/i; 98 var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {}; 99 var hasLinkError = false; 97 100 98 101 function getSelectedLink() { … … 148 151 } 149 152 153 function setLinkError( $link ) { 154 hasLinkError = true; 155 $link.attr( 'data-wplink-url-error', 'true' ); 156 speak( editor.translate( 'Warning: the link has been inserted but the destination cannot be reached.' ), 'assertive' ); 157 158 if ( toolbar && toolbar.visible() ) { 159 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ); 160 } 161 } 162 150 163 function checkLink( node ) { 151 164 var $link = editor.$( node ); … … 156 169 } 157 170 158 // Early check 159 if ( /^http/i.test( href ) && ! /\.[a-z]{2,63}(\/|$)/i.test( href ) ) { 160 urlErrors[href] = tinymce.translate( 'Invalid host name.' ); 171 hasLinkError = false; 172 173 if ( /^http/i.test( href ) && ! /^https?:\/\/[a-z0-9][a-z0-9.-]*\.[a-z]{2,63}(\/|$)/i.test( href ) ) { 174 urlErrors[href] = true; 161 175 } 162 176 163 177 if ( urlErrors.hasOwnProperty( href ) ) { 164 $link.attr( 'data-wplink-url-error', 'true');178 setLinkError( $link ); 165 179 return; 166 180 } else { … … 180 194 } 181 195 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 } 196 if ( response.data && response.data.httpError ) { 197 urlErrors[href] = true; 198 setLinkError( $link ); 189 199 } 190 200 }); … … 275 285 } 276 286 277 if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) ) {287 if ( ! /^(?:[a-z]+:|#|\?|\.|\/)/.test( href ) && ! emailRegex.test( href ) ) { 278 288 href = 'http://' + href; 279 289 } … … 292 302 293 303 // Audible confirmation message when a link has been inserted in the Editor. 294 if ( typeof window.wp !== 'undefined' && window.wp.a11y && typeof window.wpLinkL10n !== 'undefined') {295 window.wp.a11y.speak( window.wpLinkL10n.linkInserted );304 if ( typeof window.wpLinkL10n !== 'undefined' && ! hasLinkError ) { 305 speak( window.wpLinkL10n.linkInserted ); 296 306 } 297 307 } ); … … 450 460 $( element.firstChild.nextSibling ).val( ui.item.title ); 451 461 452 if ( 9 === event.keyCode && typeof window.wp !== 'undefined' && 453 window.wp.a11y && typeof window.wpLinkL10n !== 'undefined' ) { 462 if ( 9 === event.keyCode && typeof window.wpLinkL10n !== 'undefined' ) { 454 463 // Audible confirmation message when a link has been selected. 455 window.wp.a11y.speak( window.wpLinkL10n.linkSelected );464 speak( window.wpLinkL10n.linkSelected ); 456 465 } 457 466 … … 537 546 editor.on( 'wptoolbar', function( event ) { 538 547 var linkNode = editor.dom.getParent( event.element, 'a' ), 539 $linkNode, href, edit , title;548 $linkNode, href, edit; 540 549 541 550 if ( typeof window.wpLink !== 'undefined' && window.wpLink.modalOpen ) { … … 562 571 event.element = linkNode; 563 572 event.toolbar = toolbar; 564 title = urlErrors.hasOwnProperty( href ) ? editor.dom.encode( urlErrors[ href ] ) : null;565 573 566 574 if ( $linkNode.attr( 'data-wplink-url-error' ) === 'true' ) { 567 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ) .attr( 'title', title );575 toolbar.$el.find( '.wp-link-preview a' ).addClass( 'wplink-url-error' ); 568 576 } else { 569 toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' ).attr( 'title', null ); 577 toolbar.$el.find( '.wp-link-preview a' ).removeClass( 'wplink-url-error' ); 578 hasLinkError = false; 570 579 } 571 580 } -
trunk/src/wp-includes/js/wplink.js
r37741 r38126 3 3 ( function( $, wpLinkL10n, wp ) { 4 4 var editor, searchTimer, River, Query, correctedURL, linkNode, 5 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2, 4}$/i,6 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2, 4}[^ "]*$/i,5 emailRegexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i, 6 urlRegexp = /^(https?|ftp):\/\/[A-Z0-9.-]+\.[A-Z]{2,63}[^ "]*$/i, 7 7 inputs = {}, 8 8 rivers = {},
Note: See TracChangeset
for help on using the changeset viewer.