Changeset 31693
- Timestamp:
- 03/09/2015 09:48:38 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/css/press-this.css
r31680 r31693 1389 1389 } 1390 1390 1391 /* Make the text inside the editor textarea white. Prevents a "flash" on loading the page */ 1392 #pressthis { 1393 color: #fff; 1394 } 1395 1391 1396 @media (min-width: 901px) { 1392 1397 .editor { -
trunk/src/wp-admin/includes/class-wp-press-this.php
r31655 r31693 15 15 class WP_Press_This { 16 16 17 private $images = array(); 18 19 private $embeds = array(); 20 17 21 /** 18 22 * Constructor. … … 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 /** … … 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 } … … 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 { … … 445 433 $meta_value = $this->_limit_embed( $meta_value ); 446 434 447 if ( ! isset( $data['_embed '] ) ) {448 $data['_embed '] = array();435 if ( ! isset( $data['_embeds'] ) ) { 436 $data['_embeds'] = array(); 449 437 } 450 438 451 if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embed '] ) ) {452 $data['_embed '][] = $meta_value;439 if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embeds'] ) ) { 440 $data['_embeds'][] = $meta_value; 453 441 } 454 442 … … 462 450 $meta_value = $this->_limit_img( $meta_value ); 463 451 464 if ( ! isset( $data['_im g'] ) ) {465 $data['_im g'] = array();452 if ( ! isset( $data['_images'] ) ) { 453 $data['_images'] = array(); 466 454 } 467 455 468 if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_im g'] ) ) {469 $data['_im g'][] = $meta_value;456 if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_images'] ) ) { 457 $data['_images'][] = $meta_value; 470 458 } 471 459 … … 478 466 479 467 /** 480 * Fetches and parses _meta, _im g, and _links data from the source.468 * Fetches and parses _meta, _images, and _links data from the source. 481 469 * 482 470 * @since 4.2.0 … … 522 510 523 511 // Fetch and gather <img> data. 524 if ( empty( $data['_im g'] ) ) {525 $data['_im g'] = array();512 if ( empty( $data['_images'] ) ) { 513 $data['_images'] = array(); 526 514 } 527 515 … … 538 526 if ( preg_match( '/src=(\'|")([^\'"]+)\\1/i', $value, $new_matches ) ) { 539 527 $src = $this->_limit_img( $new_matches[2] ); 540 if ( ! empty( $src ) && ! in_array( $src, $data['_im g'] ) ) {541 $data['_im g'][] = $src;528 if ( ! empty( $src ) && ! in_array( $src, $data['_images'] ) ) { 529 $data['_images'][] = $src; 542 530 } 543 531 } … … 546 534 547 535 // Fetch and gather <iframe> data. 548 if ( empty( $data['_embed '] ) ) {549 $data['_embed '] = array();536 if ( empty( $data['_embeds'] ) ) { 537 $data['_embeds'] = array(); 550 538 } 551 539 … … 557 545 $src = $this->_limit_embed( $new_matches[2] ); 558 546 559 if ( ! empty( $src ) && ! in_array( $src, $data['_embed '] ) ) {560 $data['_embed '][] = $src;547 if ( ! empty( $src ) && ! in_array( $src, $data['_embeds'] ) ) { 548 $data['_embeds'][] = $src; 561 549 } 562 550 } … … 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] ); 578 579 if ( ! empty( $url ) && empty( $data['_links'][ $new_matches[2] ] ) ) { 580 $data['_links'][ $new_matches[2] ] = $url; 581 } 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] ); 566 567 if ( ! empty( $url ) && empty( $data['_links'][ $rel ] ) ) { 568 $data['_links'][ $rel ] = $url; 582 569 } 583 570 } … … 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 ] ); … … 630 617 if ( apply_filters( 'enable_press_this_media_discovery', true ) ) { 631 618 /* 632 * If no title, _im g, _embed, and _meta was passed via $_POST, fetch data from source as fallback,619 * If no title, _images, _embed, and _meta was passed via $_POST, fetch data from source as fallback, 633 620 * making PT fully backward compatible with the older bookmarklet. 634 621 */ … … 636 623 $data = $this->source_data_fetch_fallback( $data['u'], $data ); 637 624 } else { 638 foreach ( array( '_im g', '_embed', '_meta' ) as $type ) {625 foreach ( array( '_images', '_embeds' ) as $type ) { 639 626 if ( empty( $_POST[ $type ] ) ) { 640 627 continue; … … 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 ) ); 650 651 // Sanity check. $key is usually things like 'title', 'description', 'keywords', etc. 652 if ( empty( $key ) || strlen( $key ) > 100 ) { 653 continue; 654 } 634 if ( $type === '_images' ) { 635 $value = $this->_limit_img( wp_unslash( $value ) ); 636 } else { 637 $value = $this->_limit_embed( wp_unslash( $value ) ); 655 638 } 656 639 640 if ( ! empty( $value ) ) { 641 $data[ $type ][] = $value; 642 } 643 } 644 } 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; 668 } 669 } else if ( $type === '_embed' ) { 670 $value = $this->_limit_embed( $value ); 671 672 if ( ! empty( $value ) ) { 673 $data[ $type ][] = $value; 666 } else { 667 if ( in_array( $key, array( 'canonical', 'shortlink', 'icon' ), true ) ) { 668 $data[ $type ][ $key ] = $this->_limit_url( wp_unslash( $value ) ); 674 669 } 675 670 } … … 750 745 <?php 751 746 } 747 752 748 ?> 753 749 </fieldset> … … 852 848 853 849 /** 850 * Get a list of embeds with no duplicates. 851 * 852 * @param array $data The site's data. 853 * @returns array 854 */ 855 public function get_embeds( $data ) { 856 $selected_embeds = array(); 857 858 if ( ! empty( $data['_embeds'] ) ) { 859 foreach( $data['_embeds'] as $src ) { 860 $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 861 862 if ( in_array( $prot_relative_src, $this->embeds ) ) { 863 continue; 864 } 865 866 $selected_embeds[] = $src; 867 $this->embeds[] = $prot_relative_src; 868 } 869 } 870 871 return $selected_embeds; 872 } 873 874 /** 875 * Get a list of images with no duplicates. 876 * 877 * @param array $data The site's data. 878 * @returns array 879 */ 880 public function get_images( $data ) { 881 $selected_images = array(); 882 883 if ( ! empty( $data['_images'] ) ) { 884 foreach( $data['_images'] as $src ) { 885 if ( false !== strpos( $src, 'gravatar.com' ) ) { 886 $src = preg_replace( '%http://[\d]+\.gravatar\.com/%', 'https://secure.gravatar.com/', $src ); 887 } 888 889 $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 890 891 if ( in_array( $prot_relative_src, $this->images ) || 892 ( false !== strpos( $src, 'avatar' ) && count( $this->images ) > 15 ) ) { 893 // Skip: already selected or some type of avatar and we've already gathered more than 15 images. 894 continue; 895 } 896 897 $selected_images[] = $src; 898 $this->images[] = $prot_relative_src; 899 } 900 } 901 902 return $selected_images; 903 } 904 905 /** 906 * Gets the source page's canonical link, based on passed location and meta data. 907 * 908 * @param array $data The site's data. 909 * @returns string Discovered canonical URL, or empty 910 */ 911 public function get_canonical_link( $data ) { 912 $link = ''; 913 914 if ( ! empty( $data['_links']['canonical'] ) ) { 915 $link = $data['_links']['canonical']; 916 } elseif ( ! empty( $data['u'] ) ) { 917 $link = $data['u']; 918 } elseif ( ! empty( $data['_meta'] ) ) { 919 if ( ! empty( $data['_meta']['twitter:url'] ) ) { 920 $link = $data['_meta']['twitter:url']; 921 } else if ( ! empty( $data['_meta']['og:url'] ) ) { 922 $link = $data['_meta']['og:url']; 923 } 924 } 925 926 if ( empty( $link ) && ! empty( $data['_links']['shortlink'] ) ) { 927 $link = $data['_links']['shortlink']; 928 } 929 930 return $link; 931 } 932 933 /** 934 * Gets the source page's site name, based on passed meta data. 935 * 936 * @param array $data The site's data. 937 * @returns string Discovered site name, or empty 938 */ 939 public function get_source_site_name( $data ) { 940 $name = ''; 941 942 if ( ! empty( $data['_meta'] ) ) { 943 if ( ! empty( $data['_meta']['og:site_name'] ) ) { 944 $name = $data['_meta']['og:site_name']; 945 } else if ( ! empty( $data['_meta']['application-name'] ) ) { 946 $name = $data['_meta']['application-name']; 947 } 948 } 949 950 return $name; 951 } 952 953 /** 954 * Gets the source page's title, based on passed title and meta data. 955 * 956 * @param array $data The site's data. 957 * @returns string Discovered page title, or empty 958 */ 959 public function get_suggested_title( $data ) { 960 $title = ''; 961 962 if ( ! empty( $data['t'] ) ) { 963 $title = $data['t']; 964 } elseif( ! empty( $data['_meta'] ) ) { 965 if ( ! empty( $data['_meta']['twitter:title'] ) ) { 966 $title = $data['_meta']['twitter:title']; 967 } else if ( ! empty( $data['_meta']['og:title'] ) ) { 968 $title = $data['_meta']['og:title']; 969 } else if ( ! empty( $data['_meta']['title'] ) ) { 970 $title = $data['_meta']['title']; 971 } 972 } 973 974 return $title; 975 } 976 977 /** 978 * Gets the source page's suggested content, based on passed data (description, selection, etc). 979 * Features a blockquoted excerpt, as well as content attribution, if any. 980 * 981 * @param array $data The site's data. 982 * @returns string Discovered content, or empty 983 */ 984 public function get_suggested_content( $data ) { 985 $content = $text = ''; 986 987 if ( ! empty( $data['s'] ) ) { 988 $text = $data['s']; 989 } else if ( ! empty( $data['_meta'] ) ) { 990 if ( ! empty( $data['_meta']['twitter:description'] ) ) { 991 $text = $data['_meta']['twitter:description']; 992 } else if ( ! empty( $data['_meta']['og:description'] ) ) { 993 $text = $data['_meta']['og:description']; 994 } else if ( ! empty( $data['_meta']['description'] ) ) { 995 $text = $data['_meta']['description']; 996 } 997 } 998 999 $default_html = array( 1000 'quote' => '<blockquote>%1$s</blockquote>', 1001 'link' => '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . 1002 ' <em><a href="%1$s">%2$s</a></em></p>', 1003 ); 1004 1005 /** 1006 * Filter the default HTML for the Press This editor. 1007 * 1008 * @since 4.2.0 1009 * 1010 * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description 1011 * or the selected content, and 'link' there %1$s is link href, %2$s is link text. 1012 */ 1013 $default_html = apply_filters( 'press_this_suggested_html', $default_html, $data ); 1014 1015 // Wrap suggested content in the specified HTML. 1016 if ( ! empty( $default_html['quote'] ) ) { 1017 $content = sprintf( $default_html['quote'], $text ); 1018 } 1019 1020 // Add source attribution if there is one available. 1021 if ( ! empty( $default_html['link'] ) ) { 1022 $title = $this->get_suggested_title( $data ); 1023 $url = $this->get_canonical_link( $data ); 1024 1025 if ( ! $title ) { 1026 $title = $this->get_source_site_name( $data ); 1027 } 1028 1029 if ( $url && $title ) { 1030 $content .= sprintf( $default_html['link'], $url, $title ); 1031 } 1032 } 1033 1034 return $content; 1035 } 1036 1037 /** 854 1038 * Serves the app's base HTML, which in turns calls the load script. 855 1039 * … … 863 1047 $data = $this->merge_or_fetch_data(); 864 1048 1049 $post_title = $this->get_suggested_title( $data ); 1050 1051 if ( empty( $title ) ) { 1052 $title = __( 'New Post' ); 1053 } 1054 1055 $post_content = $this->get_suggested_content( $data ); 1056 865 1057 // Get site settings array/data. 866 1058 $site_settings = $this->site_settings(); 867 1059 868 // Set the passed data. 869 $data['_version'] = $site_settings['version']; 1060 // Pass the images and embeds 1061 $images = $this->get_images( $data ); 1062 $embeds = $this->get_embeds( $data ); 1063 1064 $site_data = array( 1065 'v' => ! empty( $data['v'] ) ? $data['v'] : '', 1066 'hasData' => ! empty( $data ), 1067 ); 1068 1069 if ( ! empty( $images ) ) { 1070 $site_data['_images'] = $images; 1071 } 1072 1073 if ( ! empty( $embeds ) ) { 1074 $site_data['_embeds'] = $embeds; 1075 } 870 1076 871 1077 // Add press-this-editor.css and remove theme's editor-style.css, if any. … … 891 1097 892 1098 <script> 893 window.wpPressThisData = <?php echo wp_json_encode( $ data )?>;894 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ) ?>;1099 window.wpPressThisData = <?php echo wp_json_encode( $site_data ); ?>; 1100 window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ); ?>; 895 1101 </script> 896 1102 … … 960 1166 $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 961 1167 $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 962 1168 963 1169 /** This filter is documented in wp-admin/admin-header.php */ 964 1170 $admin_body_classes = apply_filters( 'admin_body_class', '' ); … … 1008 1214 <div id='app-container' class="editor"> 1009 1215 <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>1216 <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 1217 <div id='featured-media-container' class="featured-container no-media"> 1012 1218 <div id='all-media-widget' class="all-media"> … … 1016 1222 1017 1223 <?php 1018 wp_editor( '', 'pressthis', array(1224 wp_editor( $post_content, 'pressthis', array( 1019 1225 'drag_drop_upload' => true, 1020 1226 'editor_height' => 600, … … 1040 1246 </div> 1041 1247 1042 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1248 <div class="options-panel-back is-hidden" tabindex="-1"></div> 1043 1249 <div class="options-panel is-off-screen is-hidden" tabindex="-1"> 1044 1250 <div class="post-options"> -
trunk/src/wp-admin/js/bookmarklet.js
r31609 r31693 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 ) { … … 69 69 } 70 70 71 if ( href.match( /\/\/www\.youtube\.com\/watch/ ) ) { 72 add( '_embed[]', href ); 73 } else if ( href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ) { 74 add( '_embed[]', href ); 75 } else if ( href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ) { 76 add( '_embed[]', href ); 77 } else if ( href.match( /\/\/soundcloud\.com\/.+$/ ) ) { 78 add( '_embed[]', href ); 79 } else if ( href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) ) { 80 add( '_embed[]', href ); 81 } else if ( href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) { 82 add( '_embed[]', href ); 71 if ( href.match( /\/\/www\.youtube\.com\/watch/ ) || 72 href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) || 73 href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) || 74 href.match( /\/\/soundcloud\.com\/.+$/ ) || 75 href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) || 76 href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) { 77 78 add( '_embeds[]', href ); 83 79 } 84 80 … … 112 108 g_rel = g.getAttribute( 'rel' ); 113 109 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 } 110 if ( g_rel === 'canonical' || g_rel === 'icon' || g_rel === 'shortlink' ) { 111 add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) ); 128 112 } 129 113 } … … 148 132 149 133 if ( img.width >= 256 && img.height >= 128 ) { 150 add( '_im g[]', img.src );134 add( '_images[]', img.src ); 151 135 } 152 136 } … … 159 143 } 160 144 161 add( '_embed []', ifrs[ p ].src );145 add( '_embeds[]', ifrs[ p ].src ); 162 146 } 163 147 -
trunk/src/wp-admin/js/bookmarklet.min.js
r31609 r31693 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);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/)||c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)||c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)||c.match(/\/\/soundcloud\.com\/.+$/)||c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)||c.match(/\/\/vine\.co\/v\/[^\/]+/))&&e("_embeds[]",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");("canonical"===A||"icon"===A||"shortlink"===A)&&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("_images[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embeds[]",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); -
trunk/src/wp-admin/js/press-this.js
r31677 r31693 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 = [], … … 76 71 */ 77 72 function sanitizeText( text ) { 78 text = stripTags( text ); 79 textarea.innerHTML = text; 80 81 return stripTags( textarea.value ); 73 var _text = stripTags( text ); 74 75 try { 76 textarea.innerHTML = _text; 77 _text = stripTags( textarea.value ); 78 } catch ( er ) {} 79 80 return _text; 82 81 } 83 82 … … 97 96 98 97 return ''; 99 }100 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 98 } 284 99 … … 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; … … 457 272 */ 458 273 function renderToolsVisibility() { 459 if ( data. u && data.u.match( /^https?:/ )) {274 if ( data.hasData ) { 460 275 $( '#scanbar' ).hide(); 461 276 } … … 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 }501 }502 503 /**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 315 } 546 316 } … … 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" />' );560 } 561 562 if ( interestingEmbeds ) {563 $.each( interestingEmbeds, function ( i, src ) {328 if ( data._embeds || data._images ) { 329 listContainer.append( '<h2 class="screen-reader-text">' + __( 'allMediaHeading' ) + '</h2><ul class="wppt-all-media-list" />' ); 330 } 331 332 if ( data._embeds ) { 333 $.each( data._embeds, function ( i, src ) { 564 334 src = checkUrl( src ); 565 335 … … 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 … … 717 487 $( '.post-options' ).removeClass( offscreenHidden ); 718 488 $( '.setting-modal').addClass( offscreenHidden ); 719 } 489 }); 720 490 } 721 491 … … 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 … … 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 … … 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 submit 769 546 // Publish, Draft and Preview buttons 770 547 771 548 $( '.post-actions' ).on( 'click.press-this', function( event ) { … … 877 654 }); 878 655 879 // Expose public methods 880 // TODO: which are needed? 656 // Expose public methods? 881 657 return { 882 658 renderNotice: renderNotice, -
trunk/src/wp-includes/link-template.php
r31617 r31693 2601 2601 global $is_IE, $wp_version; 2602 2602 2603 $bookmarklet_version = ' 6';2603 $bookmarklet_version = '7'; 2604 2604 $link = ''; 2605 2605
Note: See TracChangeset
for help on using the changeset viewer.