Ticket #31373: 31373.9.patch
File 31373.9.patch, 31.7 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 ) { … … 572 560 $items = $this->_limit_array( $matches[0] ); 573 561 574 562 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] );563 if ( preg_match( '/rel=["\'](canonical|shortlink|icon)["\']/i', $value, $matches_rel ) && preg_match( '/href=[\'"]([^\'" ]+)[\'"]/i', $value, $matches_url ) ) { 564 $rel = $matches_rel[1]; 565 $url = $this->_limit_url( $matches_url[1] ); 578 566 579 if ( ! empty( $url ) && empty( $data['_links'][ $new_matches[2] ] ) ) { 580 $data['_links'][ $new_matches[2] ] = $url; 581 } 567 if ( ! empty( $url ) && empty( $data['_links'][ $rel ] ) ) { 568 $data['_links'][ $rel ] = $url; 582 569 } 583 570 } 584 571 } … … 600 587 $data = array(); 601 588 602 589 // Only instantiate the keys we want. Sanity check and sanitize each one. 603 foreach ( array( 'u', 's', 't', 'v' , '_version') as $key ) {590 foreach ( array( 'u', 's', 't', 'v' ) as $key ) { 604 591 if ( ! empty( $_POST[ $key ] ) ) { 605 592 $value = wp_unslash( $_POST[ $key ] ); 606 593 } else if ( ! empty( $_GET[ $key ] ) ) { … … 635 622 if ( empty( $_POST ) && ! empty( $data['u'] ) ) { 636 623 $data = $this->source_data_fetch_fallback( $data['u'], $data ); 637 624 } else { 638 foreach ( array( '_img', '_embed' , '_meta') as $type ) {625 foreach ( array( '_img', '_embed' ) as $type ) { 639 626 if ( empty( $_POST[ $type ] ) ) { 640 627 continue; 641 628 } … … 642 629 643 630 $data[ $type ] = array(); 644 631 $items = $this->_limit_array( $_POST[ $type ] ); 645 $items = wp_unslash( $items );646 632 647 633 foreach ( $items as $key => $value ) { 648 if ( ! is_numeric( $key ) ) { 649 $key = $this->_limit_string( wp_unslash( $key ) ); 634 if ( $type === '_img' ) { 635 $value = $this->_limit_img( wp_unslash( $value ) ); 636 } else if ( $type === '_embed' ) { 637 $value = $this->_limit_embed( wp_unslash( $value ) ); 638 } 650 639 651 // Sanity check. $key is usually things like 'title', 'description', 'keywords', etc. 652 if ( empty( $key ) || strlen( $key ) > 100 ) { 653 continue; 654 } 640 if ( ! empty( $value ) ) { 641 $data[ $type ][] = $value; 655 642 } 643 } 644 } 656 645 646 foreach ( array( '_meta', '_links' ) as $type ) { 647 if ( empty( $_POST[ $type ] ) ) { 648 continue; 649 } 650 651 $data[ $type ] = array(); 652 $items = $this->_limit_array( $_POST[ $type ] ); 653 654 foreach ( $items as $key => $value ) { 655 // Sanity check. These are associative arrays, $key is usually things like 'title', 'description', 'keywords', etc. 656 if ( empty( $key ) || strlen( $key ) > 100 ) { 657 continue; 658 } 659 657 660 if ( $type === '_meta' ) { 658 $value = $this->_limit_string( $value);661 $value = $this->_limit_string( wp_unslash( $value ) ); 659 662 660 663 if ( ! empty( $value ) ) { 661 664 $data = $this->_process_meta_entry( $key, $value, $data ); 662 665 } 663 } else if ( $type === '_img' ) { 664 $value = $this->_limit_img( $value ); 665 666 if ( ! empty( $value ) ) { 667 $data[ $type ][] = $value; 666 } elseif ( $type === '_links' ) { 667 if ( in_array( $key, array( 'canonical', 'shortlink', 'icon' ) ) ) { 668 $data[ $type ][ $key ] = $this->_limit_url( wp_unslash( $value ) ); 668 669 } 669 } else if ( $type === '_embed' ) {670 $value = $this->_limit_embed( $value );671 672 if ( ! empty( $value ) ) {673 $data[ $type ][] = $value;674 }675 670 } 676 671 } 677 672 } … … 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 if ( empty( $link ) && ! empty( $data['_links']['shortlink'] ) ) { 926 $link = $data['_links']['shortlink']; 927 } 928 929 return $link; 930 } 931 932 /** 933 * Gets the source page's site name, based on passed meta data. 934 * 935 * @param array $data The site's data. 936 * @returns string Discovered site name, or empty 937 */ 938 public function get_source_site_name( $data ) { 939 $name = ''; 940 941 if ( ! empty( $data['_meta'] ) ) { 942 if ( ! empty( $data['_meta']['og:site_name'] ) ) { 943 $name = $data['_meta']['og:site_name']; 944 } else if ( ! empty( $data['_meta']['application-name'] ) ) { 945 $name = $data['_meta']['application-name']; 946 } 947 } 948 949 return $name; 950 } 951 952 /** 953 * Gets the source page's title, based on passed title and meta data. 954 * 955 * @param array $data The site's data. 956 * @returns string Discovered page title, or empty 957 */ 958 public function get_suggested_title( $data ) { 959 $title = ''; 960 961 if ( ! empty( $data['t'] ) ) { 962 $title = $data['t']; 963 } elseif( ! empty( $data['_meta'] ) ) { 964 if ( ! empty( $data['_meta']['twitter:title'] ) ) { 965 $title = $data['_meta']['twitter:title']; 966 } else if ( ! empty( $data['_meta']['og:title'] ) ) { 967 $title = $data['_meta']['og:title']; 968 } else if ( ! empty( $data['_meta']['title'] ) ) { 969 $title = $data['_meta']['title']; 970 } 971 } 972 973 return $title; 974 } 975 976 /** 977 * Gets the source page's suggested content, based on passed data (description, selection, etc). 978 * Features a blockquoted excerpt, as well as content attribution, if any. 979 * 980 * @param array $data The site's data. 981 * @returns string Discovered content, or empty 982 */ 983 public function get_suggested_content( $data ) { 984 $content = $text = ''; 985 986 if ( ! empty( $data['s'] ) ) { 987 $text = $data['s']; 988 } else if ( ! empty( $data['_meta'] ) ) { 989 if ( ! empty( $data['_meta']['twitter:description'] ) ) { 990 $text = $data['_meta']['twitter:description']; 991 } else if ( ! empty( $data['_meta']['og:description'] ) ) { 992 $text = $data['_meta']['og:description']; 993 } else if ( ! empty( $data['_meta']['description'] ) ) { 994 $text = $data['_meta']['description']; 995 } 996 } 997 998 $default_html = array( 999 'quote' => '<blockquote>%1$s</blockquote>', 1000 'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . 1001 ' <em><a href="%1$s">%2$s</a></em></p>', 1002 ); 1003 1004 /** 1005 * Filter the default HTML for the Press This editor. 1006 * 1007 * @since 4.2.0 1008 * 1009 * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description 1010 * or the selected content, and 'link' there %1$s is link href, %2$s is link text. 1011 */ 1012 $default_html = apply_filters( 'press_this_suggested_html', $default_html, $data ); 1013 1014 // Wrap suggested content in the specified HTML. 1015 if ( ! empty( $default_html['quote'] ) ) { 1016 $content = sprintf( $default_html['quote'], $text ); 1017 } 1018 1019 // Add source attribution if there is one available. 1020 if ( ! empty( $default_html['link'] ) ) { 1021 $title = $this->get_suggested_title( $data ); 1022 $url = $this->get_canonical_link( $data ); 1023 1024 if ( ! $title ) { 1025 $title = $this->get_source_site_name( $data ); 1026 } 1027 1028 if ( $url && $title ) { 1029 $content .= sprintf( $default_html['link'], $url, $title ); 1030 } 1031 } 1032 1033 return $content; 1034 } 1035 1036 /** 854 1037 * Serves the app's base HTML, which in turns calls the load script. 855 1038 * 856 1039 * @since 4.2.0 … … 862 1045 // Get data, new (POST) and old (GET). 863 1046 $data = $this->merge_or_fetch_data(); 864 1047 1048 $post_title = $this->get_suggested_title( $data ); 1049 1050 if ( empty( $title ) ) { 1051 $title = __( 'New Post' ); 1052 } 1053 1054 $post_content = $this->get_suggested_content( $data ); 1055 865 1056 // Get site settings array/data. 866 1057 $site_settings = $this->site_settings(); 867 1058 868 // Set the passed data. 869 $data['_version'] = $site_settings['version']; 1059 // Pass the images and embeds 1060 $images = $this->get_images( $data ); 1061 $embeds = $this->get_embeds( $data ); 870 1062 1063 $site_data = array( 1064 'v' => ! empty( $data['v'] ) ? $data['v'] : '', 1065 'hasData' => ! empty( $data ), 1066 ); 1067 1068 if ( ! empty( $images ) ) { 1069 $site_data['_images'] = $images; 1070 } 1071 1072 if ( ! empty( $embeds ) ) { 1073 $site_data['_embeds'] = $embeds; 1074 } 1075 871 1076 // Add press-this-editor.css and remove theme's editor-style.css, if any. 872 1077 remove_editor_styles(); 873 1078 … … 890 1095 <title><?php esc_html_e( 'Press This!' ) ?></title> 891 1096 892 1097 <script> 893 window.wpPressThisData = <?php echo wp_json_encode( $ data )?>;894 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ) ?>;1098 window.wpPressThisData = <?php echo wp_json_encode( $site_data ); ?>; 1099 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ); ?>; 895 1100 </script> 896 1101 897 1102 <script type="text/javascript"> … … 959 1164 $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); 960 1165 $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 961 1166 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 962 1167 963 1168 /** This filter is documented in wp-admin/admin-header.php */ 964 1169 $admin_body_classes = apply_filters( 'admin_body_class', '' ); 965 1170 … … 1007 1212 1008 1213 <div id='app-container' class="editor"> 1009 1214 <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>1215 <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 1216 <div id='featured-media-container' class="featured-container no-media"> 1012 1217 <div id='all-media-widget' class="all-media"> 1013 1218 <div id='all-media-container'></div> … … 1015 1220 </div> 1016 1221 1017 1222 <?php 1018 wp_editor( '', 'pressthis', array(1223 wp_editor( $post_content, 'pressthis', array( 1019 1224 'drag_drop_upload' => true, 1020 1225 'editor_height' => 600, 1021 1226 'media_buttons' => false, … … 1039 1244 </div> 1040 1245 </div> 1041 1246 1042 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1247 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1043 1248 <div class="options-panel is-off-screen is-hidden" tabindex="-1"> 1044 1249 <div class="post-options"> 1045 1250 -
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 ) { … … 117 117 case 'icon': 118 118 case 'shortlink': 119 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 120 } 128 121 } 129 122 } -
src/wp-admin/js/bookmarklet.min.js
1 (function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+= (d.indexOf("?")>-1?"&":"?")+"buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_img[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embed[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}})(window,document,top.location.href,window.pt_url);2 No newline at end of file 1 (function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",z.getAttribute("href"))}}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_img[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embed[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}})(window,document,top.location.href,window.pt_url); 2 No newline at end of file -
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 hasEmptyTitleStr = false,17 suggestedTitleStr = getSuggestedTitle( data ),18 suggestedContentStr = getSuggestedContent( data ),19 14 hasSetFocus = false, 20 15 catsCache = [], 21 16 isOffScreen = 'is-off-screen', … … 75 70 * @returns string Sanitized text. 76 71 */ 77 72 function sanitizeText( text ) { 78 text = stripTags( text ); 79 textarea.innerHTML = text; 73 var _text = stripTags( text ); 80 74 81 return stripTags( textarea.value ); 75 try { 76 textarea.innerHTML = _text; 77 _text = stripTags( textarea.value ); 78 } catch ( er ) {} 79 80 return _text; 82 81 } 83 82 84 83 /** … … 99 98 } 100 99 101 100 /** 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 101 * Show UX spinner 287 102 */ 288 103 function showSpinner() { … … 345 160 renderError( response.data.errorMessage ); 346 161 hideSpinner(); 347 162 } else if ( response.data.redirect ) { 348 if ( window.opener && s iteConfig.redirInParent ) {163 if ( window.opener && settings.redirInParent ) { 349 164 try { 350 165 window.opener.location.href = response.data.redirect; 351 166 } catch( er ) {} … … 456 271 * Hide the form letting users enter a URL to be scanned, if a URL was already passed. 457 272 */ 458 273 function renderToolsVisibility() { 459 if ( data. u && data.u.match( /^https?:/ )) {274 if ( data.hasData ) { 460 275 $( '#scanbar' ).hide(); 461 276 } 462 277 } … … 495 310 } 496 311 497 312 // Prompt user to upgrade their bookmarklet if there is a version mismatch. 498 if ( data.v && data._version && ( data.v + '' ) !== ( data._version + '' ) ) {313 if ( data.v && settings.version && ( data.v + '' ) !== ( settings.version + '' ) ) { 499 314 $( '.should-upgrade-bookmarklet' ).removeClass( 'is-hidden' ); 500 315 } 501 316 } 502 317 503 318 /** 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 319 * Render the detected images and embed for selection, if any 550 320 */ 551 321 function renderDetectedMedia() { … … 555 325 556 326 listContainer.empty(); 557 327 558 if ( interestingEmbeds || interestingImages ) {559 listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' );328 if ( data._embeds || data._images ) { 329 listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' ); 560 330 } 561 331 562 if ( interestingEmbeds ) {563 $.each( interestingEmbeds, function ( i, src ) {332 if ( data._embeds ) { 333 $.each( data._embeds, function ( i, src ) { 564 334 src = checkUrl( src ); 565 335 566 336 var displaySrc = '', … … 601 371 } ); 602 372 } 603 373 604 if ( interestingImages ) {605 $.each( interestingImages, function( i, src ) {374 if ( data._images ) { 375 $.each( data._images, function( i, src ) { 606 376 src = checkUrl( src ); 607 377 608 378 var displaySrc = src.replace(/^(http[^\?]+)(\?.*)?$/, '$1'); … … 716 486 // Reset to options list 717 487 $( '.post-options' ).removeClass( offscreenHidden ); 718 488 $( '.setting-modal').addClass( offscreenHidden ); 719 } 489 }); 720 490 } 721 491 722 492 /** … … 723 493 * Interactive behavior for the post title's field placeholder 724 494 */ 725 495 function monitorPlaceholder() { 726 var $ selector= $( '#title-container'),496 var $titleField = $( '#title-container'), 727 497 $placeholder = $('.post-title-placeholder'); 728 498 729 $ selector.on( 'focus', function() {499 $titleField.on( 'focus', function() { 730 500 $placeholder.addClass('is-hidden'); 731 } ); 732 733 $selector.on( 'blur', function() { 734 if ( ! $( this ).text() ) { 501 }).on( 'blur', function() { 502 if ( ! $titleField.text() ) { 735 503 $placeholder.removeClass('is-hidden'); 736 504 } 737 } ); 505 }); 506 507 if ( $titleField.text() ) { 508 $placeholder.addClass('is-hidden'); 509 } 738 510 } 739 511 740 512 /* *************************************************************** … … 747 519 function render(){ 748 520 // We're on! 749 521 renderToolsVisibility(); 750 renderSuggestedTitle();751 522 renderDetectedMedia(); 752 $( document ).on( 'tinymce-editor-init', renderSuggestedContent );753 523 renderStartupNotices(); 754 524 755 525 if ( window.tagBox ) { … … 761 531 * Set app events and other state monitoring related code. 762 532 */ 763 533 function monitor(){ 534 $( document ).on( 'tinymce-editor-init', function( event, ed ) { 535 editor = ed; 536 537 ed.on( 'focus', function() { 538 hasSetFocus = true; 539 } ); 540 }); 541 764 542 $( '#current-site a').click( function( e ) { 765 543 e.preventDefault(); 766 544 } ); 767 545 768 // Publish and Draft buttons and submit546 // Publish, Draft and Preview buttons 769 547 770 771 548 $( '.post-actions' ).on( 'click.press-this', function( event ) { 772 549 var $target = $( event.target ); 773 550 … … 876 653 refreshCatsCache(); 877 654 }); 878 655 879 // Expose public methods 880 // TODO: which are needed? 656 // Expose public methods? 881 657 return { 882 658 renderNotice: renderNotice, 883 659 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 ) {