Ticket #31373: 31373.8.patch
File 31373.8.patch, 27.2 KB (added by , 10 years ago) |
---|
-
src/wp-admin/includes/class-wp-press-this.php
14 14 */ 15 15 class WP_Press_This { 16 16 17 private $images = array(); 18 19 private $embeds = array(); 20 17 21 /** 18 22 * Constructor. 19 23 * … … 31 35 * @return array Site settings. 32 36 */ 33 37 public function site_settings() { 34 $default_html = array(35 'quote' => '<blockquote>%1$s</blockquote>',36 'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) .37 ' <em><a href="%1$s">%2$s</a></em></p>',38 );39 40 38 return array( 41 39 // Used to trigger the bookmarklet update notice. 42 40 // Needs to be set here and in get_shortcut_link() in wp-includes/link-template.php. 43 'version' => ' 6',41 'version' => '7', 44 42 45 43 /** 46 44 * Filter whether or not Press This should redirect the user in the parent window upon save. … … 50 48 * @param bool false Whether to redirect in parent window or not. Default false. 51 49 */ 52 50 'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ), 53 54 /**55 * Filter the default HTML for the Press This editor.56 *57 * @since 4.2.058 *59 * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description60 * or the selected content, and 'link' there %1$s is link href, %2$s is link text.61 */62 'html' => apply_filters( 'press_this_suggested_html', $default_html ),63 51 ); 64 52 } 65 53 … … 435 423 } 436 424 437 425 private function _process_meta_entry( $meta_name, $meta_value, $data ) { 438 if ( preg_match( '/:?(title|description|keywords )$/', $meta_name ) ) {426 if ( preg_match( '/:?(title|description|keywords|site_name)$/', $meta_name ) ) { 439 427 $data['_meta'][ $meta_name ] = $meta_value; 440 428 } else { 441 429 switch ( $meta_name ) { … … 452 440 $data['_embed'][] = $meta_value; 453 441 } 454 442 443 // Add it back to _meta so we can use it as URL if needed 444 $data['_meta'][ $meta_name ] = $meta_value; 445 455 446 break; 456 447 case 'og:image': 457 448 case 'og:image:secure_url': … … 572 563 $items = $this->_limit_array( $matches[0] ); 573 564 574 565 foreach ( $items as $value ) { 575 if ( preg_match( '/(rel|itemprop)="([^"]+)"[^>]+href="([^"]+)"/', $value, $new_matches ) ) { 576 if ( 'alternate' === $new_matches[2] || 'thumbnailUrl' === $new_matches[2] || 'url' === $new_matches[2] ) { 577 $url = $this->_limit_url( $new_matches[3] ); 566 if ( ( false !== strpos( $value, 'rel="canonical"' ) || false !== strpos( $value, "rel='canonical'" ) ) && preg_match( '/href=[\'"]([^\'" ]+)[\'"]/', $value, $new_matches ) ) { 567 $url = $this->_limit_url( $new_matches[1] ); 578 568 579 if ( ! empty( $url ) && empty( $data['_links'][ $new_matches[2] ] ) ) { 580 $data['_links'][ $new_matches[2] ] = $url; 581 } 569 if ( ! empty( $url ) && empty( $data['_links']['canonical'] ) ) { 570 $data['_links']['canonical'] = $url; 582 571 } 583 572 } 584 573 } … … 600 589 $data = array(); 601 590 602 591 // Only instantiate the keys we want. Sanity check and sanitize each one. 603 foreach ( array( 'u', 's', 't', 'v' , '_version') as $key ) {592 foreach ( array( 'u', 's', 't', 'v' ) as $key ) { 604 593 if ( ! empty( $_POST[ $key ] ) ) { 605 594 $value = wp_unslash( $_POST[ $key ] ); 606 595 } else if ( ! empty( $_GET[ $key ] ) ) { … … 635 624 if ( empty( $_POST ) && ! empty( $data['u'] ) ) { 636 625 $data = $this->source_data_fetch_fallback( $data['u'], $data ); 637 626 } else { 638 foreach ( array( '_img', '_embed' , '_meta') as $type ) {627 foreach ( array( '_img', '_embed' ) as $type ) { 639 628 if ( empty( $_POST[ $type ] ) ) { 640 629 continue; 641 630 } … … 642 631 643 632 $data[ $type ] = array(); 644 633 $items = $this->_limit_array( $_POST[ $type ] ); 645 $items = wp_unslash( $items );646 634 647 635 foreach ( $items as $key => $value ) { 648 if ( ! is_numeric( $key ) ) { 649 $key = $this->_limit_string( wp_unslash( $key ) ); 636 if ( $type === '_img' ) { 637 $value = $this->_limit_img( wp_unslash( $value ) ); 638 } else if ( $type === '_embed' ) { 639 $value = $this->_limit_embed( wp_unslash( $value ) ); 640 } 650 641 651 // Sanity check. $key is usually things like 'title', 'description', 'keywords', etc. 652 if ( empty( $key ) || strlen( $key ) > 100 ) { 653 continue; 654 } 642 if ( ! empty( $value ) ) { 643 $data[ $type ][] = $value; 655 644 } 645 } 646 } 656 647 657 if ( $type === '_meta' ) { 658 $value = $this->_limit_string( $value ); 648 if ( ! empty( $_POST['_meta'] ) && is_array( $_POST['_meta'] ) ) { 649 $data['_meta'] = array(); 650 $items = $this->_limit_array( $_POST['_meta'] ); 659 651 660 if ( ! empty( $value )) {661 $data = $this->_process_meta_entry( $key, $value, $data );662 }663 } else if ( $type === '_img' ) {664 $value = $this->_limit_img( $value );652 foreach ( $items as $key => $value ) { 653 // Sanity check. These are associative arrays, $key is usually things like 'title', 'description', 'keywords', etc. 654 if ( empty( $key ) || strlen( $key ) > 100 ) { 655 continue; 656 } 665 657 666 if ( ! empty( $value ) ) { 667 $data[ $type ][] = $value; 668 } 669 } else if ( $type === '_embed' ) { 670 $value = $this->_limit_embed( $value ); 658 $value = $this->_limit_string( wp_unslash( $value ) ); 671 659 672 if ( ! empty( $value ) ) { 673 $data[ $type ][] = $value; 674 } 660 if ( ! empty( $value ) ) { 661 $data = $this->_process_meta_entry( $key, $value, $data ); 675 662 } 676 663 } 677 664 } 665 666 if ( ! empty( $_POST['canonical'] ) ) { 667 $value = _limit_url( $_POST['canonical'] ); 668 669 if ( $value ) { 670 $data['_links']['canonical'] = $value; 671 } 672 } 678 673 } 679 674 } 680 675 … … 851 846 } 852 847 853 848 /** 849 * Get a list of embeds with no duplicates. 850 * 851 * @param array $data The site's data. 852 * @returns array 853 */ 854 public function get_embeds( $data ) { 855 $selected_embeds = array(); 856 857 if ( ! empty( $data['_embeds'] ) ) { 858 foreach( $data['_embeds'] as $src ) { 859 $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 860 861 if ( in_array( $prot_relative_src, $this->embeds ) ) { 862 continue; 863 } 864 865 $selected_embeds[] = $src; 866 $this->embeds[] = $prot_relative_src; 867 } 868 } 869 870 return $selected_embeds; 871 } 872 873 /** 874 * Get a list of images with no duplicates. 875 * 876 * @param array $data The site's data. 877 * @returns array 878 */ 879 public function get_images( $data ) { 880 $selected_images = array(); 881 882 if ( ! empty( $data['_img'] ) ) { 883 foreach( $data['_img'] as $src ) { 884 if ( false !== strpos( $src, 'gravatar.com' ) ) { 885 $src = preg_replace( '%http://[\d]+\.gravatar\.com/%', 'https://secure.gravatar.com/', $src ); 886 } 887 888 $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 889 890 if ( in_array( $prot_relative_src, $this->images ) || 891 ( false !== strpos( $src, 'avatar' ) && count( $this->images ) > 15 ) ) { 892 // Skip: already selected or some type of avatar and we've already gathered more than 15 images. 893 continue; 894 } 895 896 $selected_images[] = $src; 897 $this->images[] = $prot_relative_src; 898 } 899 } 900 901 return $selected_images; 902 } 903 904 /** 905 * Gets the source page's canonical link, based on passed location and meta data. 906 * 907 * @param array $data The site's data. 908 * @returns string Discovered canonical URL, or empty 909 */ 910 public function get_canonical_link( $data ) { 911 $link = ''; 912 913 if ( ! empty( $data['_links']['canonical'] ) ) { 914 $link = $data['_links']['canonical']; 915 } elseif ( ! empty( $data['u'] ) ) { 916 $link = $data['u']; 917 } elseif ( ! empty( $data['_meta'] ) ) { 918 if ( ! empty( $data['_meta']['twitter:url'] ) ) { 919 $link = $data['_meta']['twitter:url']; 920 } else if ( ! empty( $data['_meta']['og:url'] ) ) { 921 $link = $data['_meta']['og:url']; 922 } 923 } 924 925 return $link; 926 } 927 928 /** 929 * Gets the source page's site name, based on passed meta data. 930 * 931 * @param array $data The site's data. 932 * @returns string Discovered site name, or empty 933 */ 934 public function get_source_site_name( $data ) { 935 $name = ''; 936 937 if ( ! empty( $data['_meta'] ) ) { 938 if ( ! empty( $data['_meta']['og:site_name'] ) ) { 939 $name = $data['_meta']['og:site_name']; 940 } else if ( ! empty( $data['_meta']['application-name'] ) ) { 941 $name = $data['_meta']['application-name']; 942 } 943 } 944 945 return $name; 946 } 947 948 /** 949 * Gets the source page's title, based on passed title and meta data. 950 * 951 * @param array $data The site's data. 952 * @returns string Discovered page title, or empty 953 */ 954 public function get_suggested_title( $data ) { 955 $title = ''; 956 957 if ( ! empty( $data['t'] ) ) { 958 $title = $data['t']; 959 } elseif( ! empty( $data['_meta'] ) ) { 960 if ( ! empty( $data['_meta']['twitter:title'] ) ) { 961 $title = $data['_meta']['twitter:title']; 962 } else if ( ! empty( $data['_meta']['og:title'] ) ) { 963 $title = $data['_meta']['og:title']; 964 } else if ( ! empty( $data['_meta']['title'] ) ) { 965 $title = $data['_meta']['title']; 966 } 967 } 968 969 return $title; 970 } 971 972 /** 973 * Gets the source page's suggested content, based on passed data (description, selection, etc). 974 * Features a blockquoted excerpt, as well as content attribution, if any. 975 * 976 * @param array $data The site's data. 977 * @returns string Discovered content, or empty 978 */ 979 public function get_suggested_content( $data ) { 980 $content = $text = ''; 981 982 if ( ! empty( $data['s'] ) ) { 983 $text = $data['s']; 984 } else if ( ! empty( $data['_meta'] ) ) { 985 if ( ! empty( $data['_meta']['twitter:description'] ) ) { 986 $text = $data['_meta']['twitter:description']; 987 } else if ( ! empty( $data['_meta']['og:description'] ) ) { 988 $text = $data['_meta']['og:description']; 989 } else if ( ! empty( $data['_meta']['description'] ) ) { 990 $text = $data['_meta']['description']; 991 } 992 } 993 994 $default_html = array( 995 'quote' => '<blockquote>%1$s</blockquote>', 996 'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . 997 ' <em><a href="%1$s">%2$s</a></em></p>', 998 ); 999 1000 /** 1001 * Filter the default HTML for the Press This editor. 1002 * 1003 * @since 4.2.0 1004 * 1005 * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description 1006 * or the selected content, and 'link' there %1$s is link href, %2$s is link text. 1007 */ 1008 $default_html = apply_filters( 'press_this_suggested_html', $default_html, $data ); 1009 1010 // Wrap suggested content in the specified HTML. 1011 if ( ! empty( $default_html['quote'] ) ) { 1012 $content = sprintf( $default_html['quote'], $text ); 1013 } 1014 1015 // Add source attribution if there is one available. 1016 if ( ! empty( $default_html['link'] ) ) { 1017 $title = $this->get_suggested_title( $data ); 1018 $url = $this->get_canonical_link( $data ); 1019 1020 if ( ! $title ) { 1021 $title = $this->get_source_site_name( $data ); 1022 } 1023 1024 if ( $url && $title ) { 1025 $content .= sprintf( $default_html['link'], $url, $title ); 1026 } 1027 } 1028 1029 return $content; 1030 } 1031 1032 /** 854 1033 * Serves the app's base HTML, which in turns calls the load script. 855 1034 * 856 1035 * @since 4.2.0 … … 862 1041 // Get data, new (POST) and old (GET). 863 1042 $data = $this->merge_or_fetch_data(); 864 1043 1044 $post_title = $this->get_suggested_title( $data ); 1045 1046 if ( empty( $title ) ) { 1047 $title = __( 'New Post' ); 1048 } 1049 1050 $post_content = $this->get_suggested_content( $data ); 1051 865 1052 // Get site settings array/data. 866 1053 $site_settings = $this->site_settings(); 867 1054 868 // Set the passed data. 869 $data['_version'] = $site_settings['version']; 1055 // Pass the images and embeds 1056 $images = $this->get_images( $data ); 1057 $embeds = $this->get_embeds( $data ); 870 1058 1059 $site_data = array( 1060 'v' => ! empty( $data['v'] ) ? $data['v'] : '', 1061 'hasData' => ! empty( $data ), 1062 ); 1063 1064 if ( ! empty( $images ) ) { 1065 $site_data['_images'] = $images; 1066 } 1067 1068 if ( ! empty( $embeds ) ) { 1069 $site_data['_embeds'] = $embeds; 1070 } 1071 871 1072 // Add press-this-editor.css and remove theme's editor-style.css, if any. 872 1073 remove_editor_styles(); 873 1074 … … 890 1091 <title><?php esc_html_e( 'Press This!' ) ?></title> 891 1092 892 1093 <script> 893 window.wpPressThisData = <?php echo wp_json_encode( $ data )?>;894 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ) ?>;1094 window.wpPressThisData = <?php echo wp_json_encode( $site_data ); ?>; 1095 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ); ?>; 895 1096 </script> 896 1097 897 1098 <script type="text/javascript"> … … 959 1160 $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); 960 1161 $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 961 1162 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 962 1163 963 1164 /** This filter is documented in wp-admin/admin-header.php */ 964 1165 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 965 1166 … … 1007 1208 1008 1209 <div id='app-container' class="editor"> 1009 1210 <span id="title-container-label" class="post-title-placeholder" aria-hidden="true"><?php _e( 'Post title' ); ?></span> 1010 <h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0">< /h2>1211 <h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0"><?php echo esc_html( $post_title ); ?></h2> 1011 1212 <div id='featured-media-container' class="featured-container no-media"> 1012 1213 <div id='all-media-widget' class="all-media"> 1013 1214 <div id='all-media-container'></div> … … 1015 1216 </div> 1016 1217 1017 1218 <?php 1018 wp_editor( '', 'pressthis', array(1219 wp_editor( $post_content, 'pressthis', array( 1019 1220 'drag_drop_upload' => true, 1020 1221 'editor_height' => 600, 1021 1222 'media_buttons' => false, … … 1039 1240 </div> 1040 1241 </div> 1041 1242 1042 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1243 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1043 1244 <div class="options-panel is-off-screen is-hidden" tabindex="-1"> 1044 1245 <div class="post-options"> 1045 1246 -
src/wp-admin/js/bookmarklet.js
31 31 selection = document.selection.createRange().text || ''; 32 32 } 33 33 34 pt_url += ( pt_url.indexOf( '?' ) > -1 ? '&' : '?' ) + 'buster=' + ( new Date().getTime() );34 pt_url += '&buster=' + ( new Date().getTime() ); 35 35 36 36 if ( ! canPost ) { 37 37 if ( document.title ) { … … 108 108 break; 109 109 } 110 110 111 var g = links[ y ], 112 g_rel = g.getAttribute( 'rel' ); 111 var g = links[y]; 113 112 114 if ( g_rel ) { 115 switch ( g_rel ) { 116 case 'canonical': 117 case 'icon': 118 case 'shortlink': 119 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) ); 120 break; 121 case 'alternate': 122 if ( 'application/json+oembed' === g.getAttribute( 'type' ) ) { 123 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) ); 124 } else if ( 'handheld' === g.getAttribute( 'media' ) ) { 125 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) ); 126 } 127 } 113 if ( 'canonical' === g.getAttribute( 'rel' ) ) { 114 add( 'canonical', g.getAttribute( 'href' ) ); 128 115 } 129 116 } 130 117 -
src/wp-admin/js/press-this.js
8 8 saveAlert = false, 9 9 textarea = document.createElement( 'textarea' ), 10 10 sidebarIsOpen = false, 11 s iteConfig= window.wpPressThisConfig || {},11 settings = window.wpPressThisConfig || {}, 12 12 data = window.wpPressThisData || {}, 13 13 smallestWidth = 128, 14 interestingImages = getInterestingImages( data ) || [],15 interestingEmbeds = getInterestingEmbeds( data ) || [],16 14 hasEmptyTitleStr = false, 17 suggestedTitleStr = getSuggestedTitle( data ),18 suggestedContentStr = getSuggestedContent( data ),19 15 hasSetFocus = false, 20 16 catsCache = [], 21 17 isOffScreen = 'is-off-screen', … … 75 71 * @returns string Sanitized text. 76 72 */ 77 73 function sanitizeText( text ) { 78 text = stripTags( text ); 79 textarea.innerHTML = text; 74 var _text = stripTags( text ); 80 75 81 return stripTags( textarea.value ); 76 try { 77 textarea.innerHTML = _text; 78 _text = stripTags( textarea.value ); 79 } catch ( er ) {} 80 81 return _text; 82 82 } 83 83 84 84 /** … … 99 99 } 100 100 101 101 /** 102 * Gets the source page's canonical link, based on passed location and meta data.103 *104 * @returns string Discovered canonical URL, or empty105 */106 function getCanonicalLink() {107 var link = '';108 109 if ( data._links && data._links.canonical ) {110 link = data._links.canonical;111 }112 113 if ( ! link && data.u ) {114 link = data.u;115 }116 117 if ( ! link && data._meta ) {118 if ( data._meta['twitter:url'] ) {119 link = data._meta['twitter:url'];120 } else if ( data._meta['og:url'] ) {121 link = data._meta['og:url'];122 }123 }124 125 return checkUrl( decodeURI( link ) );126 }127 128 /**129 * Gets the source page's site name, based on passed meta data.130 *131 * @returns string Discovered site name, or empty132 */133 function getSourceSiteName() {134 var name = '';135 136 if ( data._meta ) {137 if ( data._meta['og:site_name'] ) {138 name = data._meta['og:site_name'];139 } else if ( data._meta['application-name'] ) {140 name = data._meta['application-name'];141 }142 }143 144 return sanitizeText( name );145 }146 147 /**148 * Gets the source page's title, based on passed title and meta data.149 *150 * @returns string Discovered page title, or empty151 */152 function getSuggestedTitle() {153 var title = '';154 155 if ( data.t ) {156 title = data.t;157 }158 159 if ( ! title && data._meta ) {160 if ( data._meta['twitter:title'] ) {161 title = data._meta['twitter:title'];162 } else if ( data._meta['og:title'] ) {163 title = data._meta['og:title'];164 } else if ( data._meta.title ) {165 title = data._meta.title;166 }167 }168 169 if ( ! title ) {170 title = __( 'newPost' );171 hasEmptyTitleStr = true;172 }173 174 return sanitizeText( title );175 }176 177 /**178 * Gets the source page's suggested content, based on passed data (description, selection, etc).179 * Features a blockquoted excerpt, as well as content attribution, if any.180 *181 * @returns string Discovered content, or empty182 */183 function getSuggestedContent() {184 var content = '',185 text = '',186 title = getSuggestedTitle(),187 url = getCanonicalLink(),188 siteName = getSourceSiteName();189 190 if ( data.s ) {191 text = data.s;192 } else if ( data._meta ) {193 if ( data._meta['twitter:description'] ) {194 text = data._meta['twitter:description'];195 } else if ( data._meta['og:description'] ) {196 text = data._meta['og:description'];197 } else if ( data._meta.description ) {198 text = data._meta.description;199 }200 }201 202 if ( text && siteConfig.html.quote ) {203 // Wrap suggested content in specified HTML.204 content = siteConfig.html.quote.replace( /%1\$s/g, sanitizeText( text ) );205 }206 207 // Add a source attribution if there is one available.208 if ( url && siteConfig.html.link && ( ( title && __( 'newPost' ) !== title ) || siteName ) ) {209 content += siteConfig.html.link.replace( /%1\$s/g, encodeURI( url ) ).replace( /%2\$s/g, ( title || siteName ) );210 }211 212 return content || '';213 }214 215 /**216 * Get a list of valid embeds from what was passed via WpPressThis_App.data._embed on page load.217 *218 * @returns array219 */220 function getInterestingEmbeds() {221 var embeds = data._embed || [],222 interestingEmbeds = [],223 alreadySelected = [];224 225 if ( embeds.length ) {226 $.each( embeds, function ( i, src ) {227 if ( ! src ) {228 // Skip: no src value229 return;230 }231 232 var schemelessSrc = src.replace( /^https?:/, '' );233 234 if ( $.inArray( schemelessSrc, alreadySelected ) > -1 ) {235 // Skip: already shown236 return;237 }238 239 interestingEmbeds.push( src );240 alreadySelected.push( schemelessSrc );241 } );242 }243 244 return interestingEmbeds;245 }246 247 /**248 * Get a list of valid images from what was passed via WpPressThis_App.data._img and WpPressThis_App.data._meta on page load.249 *250 * @returns array251 */252 function getInterestingImages( data ) {253 var imgs = data._img || [],254 interestingImgs = [],255 alreadySelected = [];256 257 if ( imgs.length ) {258 $.each( imgs, function ( i, src ) {259 src = src.replace( /http:\/\/[\d]+\.gravatar\.com\//, 'https://secure.gravatar.com/' );260 src = checkUrl( src );261 262 if ( ! src ) {263 // Skip: no src value264 return;265 }266 267 var schemelessSrc = src.replace( /^https?:/, '' );268 269 if ( Array.prototype.indexOf && alreadySelected.indexOf( schemelessSrc ) > -1 ) {270 // Skip: already shown271 return;272 } else if ( src.indexOf( 'avatar' ) > -1 && interestingImgs.length >= 15 ) {273 // Skip: some type of avatar and we've already gathered more than 23 diff images to show274 return;275 }276 277 interestingImgs.push( src );278 alreadySelected.push( schemelessSrc );279 } );280 }281 282 return interestingImgs;283 }284 285 /**286 102 * Show UX spinner 287 103 */ 288 104 function showSpinner() { … … 304 120 305 121 /** 306 122 * Prepare the form data for saving. 307 */ 123 */ 308 124 function prepareFormData() { 309 125 editor && editor.save(); 310 126 … … 345 161 renderError( response.data.errorMessage ); 346 162 hideSpinner(); 347 163 } else if ( response.data.redirect ) { 348 if ( window.opener && s iteConfig.redirInParent ) {164 if ( window.opener && settings.redirInParent ) { 349 165 try { 350 166 window.opener.location.href = response.data.redirect; 351 167 } catch( er ) {} … … 456 272 * Hide the form letting users enter a URL to be scanned, if a URL was already passed. 457 273 */ 458 274 function renderToolsVisibility() { 459 if ( data. u && data.u.match( /^https?:/ )) {275 if ( data.hasData ) { 460 276 $( '#scanbar' ).hide(); 461 277 } 462 278 } … … 495 311 } 496 312 497 313 // Prompt user to upgrade their bookmarklet if there is a version mismatch. 498 if ( data.v && data._version && ( data.v + '' ) !== ( data._version + '' ) ) {314 if ( data.v && settings.version && ( data.v + '' ) !== ( settings.version + '' ) ) { 499 315 $( '.should-upgrade-bookmarklet' ).removeClass( 'is-hidden' ); 500 316 } 501 317 } 502 318 503 319 /** 504 * Render the suggested title, if any505 */506 function renderSuggestedTitle() {507 var suggestedTitle = suggestedTitleStr || '',508 $title = $( '#title-container' );509 510 if ( ! hasEmptyTitleStr ) {511 $( '#post_title' ).val( suggestedTitle );512 $title.text( suggestedTitle );513 $( '.post-title-placeholder' ).addClass( 'is-hidden' );514 }515 516 $title.on( 'keyup', function() {517 saveAlert = true;518 }).on( 'paste', function() {519 saveAlert = true;520 521 setTimeout( function() {522 $title.text( $title.text() );523 }, 100 );524 } );525 526 }527 528 /**529 * Render the suggested content, if any530 */531 function renderSuggestedContent() {532 if ( ! suggestedContentStr ) {533 return;534 }535 536 if ( ! editor ) {537 editor = window.tinymce.get( 'pressthis' );538 }539 540 if ( editor ) {541 editor.setContent( suggestedContentStr );542 editor.on( 'focus', function() {543 hasSetFocus = true;544 } );545 }546 }547 548 /**549 320 * Render the detected images and embed for selection, if any 550 321 */ 551 322 function renderDetectedMedia() { … … 555 326 556 327 listContainer.empty(); 557 328 558 if ( interestingEmbeds || interestingImages ) {559 listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' );329 if ( data._embeds || data._images ) { 330 listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' ); 560 331 } 561 332 562 if ( interestingEmbeds ) {563 $.each( interestingEmbeds, function ( i, src ) {333 if ( data._embeds ) { 334 $.each( data._embeds, function ( i, src ) { 564 335 src = checkUrl( src ); 565 336 566 337 var displaySrc = '', … … 601 372 } ); 602 373 } 603 374 604 if ( interestingImages ) {605 $.each( interestingImages, function( i, src ) {375 if ( data._images ) { 376 $.each( data._images, function( i, src ) { 606 377 src = checkUrl( src ); 607 378 608 379 var displaySrc = src.replace(/^(http[^\?]+)(\?.*)?$/, '$1'); … … 703 474 $( '.post-option:first' ).focus(); 704 475 } ); 705 476 } 706 477 707 478 function closeSidebar() { 708 479 sidebarIsOpen = false; 709 480 … … 716 487 // Reset to options list 717 488 $( '.post-options' ).removeClass( offscreenHidden ); 718 489 $( '.setting-modal').addClass( offscreenHidden ); 719 } 490 }); 720 491 } 721 492 722 493 /** … … 723 494 * Interactive behavior for the post title's field placeholder 724 495 */ 725 496 function monitorPlaceholder() { 726 var $ selector= $( '#title-container'),497 var $titleField = $( '#title-container'), 727 498 $placeholder = $('.post-title-placeholder'); 728 499 729 $ selector.on( 'focus', function() {500 $titleField.on( 'focus', function() { 730 501 $placeholder.addClass('is-hidden'); 731 } ); 732 733 $selector.on( 'blur', function() { 734 if ( ! $( this ).text() ) { 502 }).on( 'blur', function() { 503 if ( ! $titleField.text() ) { 735 504 $placeholder.removeClass('is-hidden'); 736 505 } 737 } ); 506 }); 507 508 if ( $titleField.text() ) { 509 $placeholder.addClass('is-hidden'); 510 } 738 511 } 739 512 740 513 /* *************************************************************** … … 747 520 function render(){ 748 521 // We're on! 749 522 renderToolsVisibility(); 750 renderSuggestedTitle();751 523 renderDetectedMedia(); 752 $( document ).on( 'tinymce-editor-init', renderSuggestedContent );753 524 renderStartupNotices(); 754 525 } 755 526 … … 757 528 * Set app events and other state monitoring related code. 758 529 */ 759 530 function monitor(){ 531 $( document ).on( 'tinymce-editor-init', function( ed ) { 532 editor = ed; 533 534 ed.on( 'focus', function() { 535 hasSetFocus = true; 536 } ); 537 }); 538 760 539 $( '#current-site a').click( function( e ) { 761 540 e.preventDefault(); 762 541 } ); 763 542 764 // Publish and Draft buttons and submit 765 766 543 // Publish, Draft and Preview buttons 767 544 $( '.post-actions' ).on( 'click.press-this', function( event ) { 768 545 var $target = $( event.target ); 769 546 … … 872 649 refreshCatsCache(); 873 650 }); 874 651 875 // Expose public methods 876 // TODO: which are needed? 652 // Expose public methods? 877 653 return { 878 654 renderNotice: renderNotice, 879 655 renderError: renderError -
src/wp-includes/link-template.php
2600 2600 function get_shortcut_link() { 2601 2601 global $is_IE, $wp_version; 2602 2602 2603 $bookmarklet_version = ' 6';2603 $bookmarklet_version = '7'; 2604 2604 $link = ''; 2605 2605 2606 2606 if ( $is_IE ) {