PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/sharedaddy/sharing-sources.php +139 -259 13.5.216.3-a.1 View file →
@@ -5,9 +5,14 @@
5 5 * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound
6 6 */
7 7
8 8 use Automattic\Jetpack\Device_Detection\User_Agent_Info;
9 +use Automattic\Jetpack\Post_Media\Images;
9 10
11 +if ( ! defined( 'ABSPATH' ) ) {
12 + exit( 0 );
13 +}
14 +
10 15 /**
11 16 * Base class for sharing sources.
12 17 * See individual sharing classes below for the implementation of this class.
13 18 */
@@ -26,8 +31,15 @@
26 31 */
27 32 public $smart;
28 33
29 34 /**
35 + * Service short name.
36 + *
37 + * @var string
38 + */
39 + public $shortname;
40 +
41 + /**
30 42 * Should the sharing link open in a new tab.
31 43 *
32 44 * @var bool
33 45 */
@@ -147,9 +159,9 @@
147 159 * @param string $post->post_title Post Title.
148 160 * @param int $post_id Post ID.
149 161 * @param int $this->id Sharing ID.
150 162 */
151 - $title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id );
163 + $title = apply_filters( 'sharing_title', $post->post_title ?? '', $post_id, $this->id );
152 164
153 165 return html_entity_decode( wp_kses( $title, '' ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
154 166 }
155 167
@@ -206,9 +218,9 @@
206 218 * Get the HTML markup to display a sharing link.
207 219 *
208 220 * @param string $url Post URL to share.
209 221 * @param string $text Sharing display text.
210 - * @param string $title The title for the link.
222 + * @param string $accessible_name Accessible name for the link.
211 223 * @param string $query Additional query arguments to add to the link. They should be in 'foo=bar&baz=1' format.
212 224 * @param bool|string $id Sharing ID to include in the data-shared attribute.
213 225 * @param array $data_attributes The keys are used as additional attribute names with 'data-' prefix.
214 226 * The values are used as the attribute values.
@@ -214,9 +226,9 @@
214 226 * The values are used as the attribute values.
215 227 *
216 228 * @return string The HTML for the link.
217 229 */
218 - public function get_link( $url, $text, $title, $query = '', $id = false, $data_attributes = array() ) {
230 + public function get_link( $url, $text, $accessible_name = '', $query = '', $id = false, $data_attributes = array() ) {
219 231 $args = func_get_args();
220 232 $klasses = array( 'share-' . $this->get_class(), 'sd-button' );
221 233
222 234 if ( 'icon' === $this->button_style || 'icon-text' === $this->button_style ) {
@@ -223,14 +235,13 @@
223 235 $klasses[] = 'share-icon';
224 236 }
225 237
226 238 if ( 'icon' === $this->button_style ) {
227 - $text = $title;
228 239 $klasses[] = 'no-text';
240 + }
229 241
230 - if ( true === $this->open_link_in_new ) {
231 - $text .= __( ' (Opens in new window)', 'jetpack' );
232 - }
242 + if ( true === $this->open_link_in_new ) {
243 + $accessible_name .= __( ' (Opens in new window)', 'jetpack' );
233 244 }
234 245
235 246 /**
236 247 * Filter the sharing display ID.
@@ -291,8 +302,9 @@
291 302 $url .= '&' . $query;
292 303 }
293 304 }
294 305
306 + // @phan-suppress-next-line PhanSuspiciousValueComparison
295 307 if ( 'text' === $this->button_style ) {
296 308 $klasses[] = 'no-icon';
297 309 }
298 310
@@ -314,8 +326,9 @@
314 326 *
315 327 * @module sharedaddy
316 328 *
317 329 * @since 3.4.0
330 + * @deprecated 14.6 Use jetpack_sharing_accessible_name instead.
318 331 *
319 332 * @param string $title Sharing service title.
320 333 * @param object $this Sharing service properties.
321 334 * @param string|false $id Sharing ID.
@@ -320,10 +333,24 @@
320 333 * @param object $this Sharing service properties.
321 334 * @param string|false $id Sharing ID.
322 335 * @param array $args Array of sharing service options.
323 336 */
324 - $title = apply_filters( 'jetpack_sharing_display_title', $title, $this, $id, $args );
337 + $accessible_name = apply_filters_deprecated( 'jetpack_sharing_display_title', array( $accessible_name, $this, $id, $args ), '14.6', 'jetpack_sharing_accessible_name' );
338 +
325 339 /**
340 + * Filter the sharing accessible name.
341 + *
342 + * @module sharedaddy
343 + *
344 + * @since 14.6
345 + *
346 + * @param string $accessible_name Sharing service accessible name.
347 + * @param object $this Sharing service properties.
348 + * @param string|false $id Sharing ID.
349 + * @param array $args Array of sharing service options.
350 + */
351 + $accessible_name = apply_filters( 'jetpack_sharing_accessible_name', $accessible_name, $this, $id, $args );
352 + /**
326 353 * Filter the sharing display text.
327 354 *
328 355 * @module sharedaddy
329 356 *
@@ -350,10 +377,17 @@
350 377 * @param array $args Array of sharing service options.
351 378 */
352 379 $data_attributes = apply_filters( 'jetpack_sharing_data_attributes', (array) $data_attributes, $this, $id, $args );
353 380
381 + $id_attr = $id ? esc_attr( $id ) : '';
354 382 $encoded_data_attributes = '';
355 383 if ( ! empty( $data_attributes ) ) {
384 + // Check for aria-labelledby first, and separate this out.
385 + if ( isset( $data_attributes['aria-labelledby'] ) ) {
386 + $id_attr = $data_attributes['aria-labelledby'];
387 + unset( $data_attributes['aria-labelledby'] );
388 + }
389 +
356 390 $encoded_data_attributes = implode(
357 391 ' ',
358 392 array_map(
359 393 /** Filter for formatting attributes */
@@ -369,19 +403,34 @@
369 403 )
370 404 );
371 405 }
372 406
407 + $rel_attr = ( true === $this->open_link_in_new ) ? 'noopener noreferrer' : '';
408 + $target_attr = ( true === $this->open_link_in_new ) ? 'target="_blank"' : '';
409 +
410 + $classes = implode( ' ', $klasses );
411 +
373 412 return sprintf(
374 - '<a rel="nofollow%s" data-shared="%s" class="%s" href="%s"%s title="%s" %s><span%s>%s</span></a>',
375 - ( true === $this->open_link_in_new ) ? ' noopener noreferrer' : '',
376 - ( $id ? esc_attr( $id ) : '' ),
377 - implode( ' ', $klasses ),
378 - $url,
379 - ( true === $this->open_link_in_new ) ? ' target="_blank"' : '',
380 - $title,
413 + '<a rel="nofollow %s"
414 + data-shared="%s"
415 + class="%s"
416 + href="%s"
417 + %s
418 + aria-labelledby="%s"
419 + %s>
420 + <span id="%s" hidden>%s</span>
421 + <span>%s</span>
422 + </a>',
423 + $rel_attr,
424 + $id_attr,
425 + esc_attr( $classes ),
426 + esc_url( $url ),
427 + $target_attr,
428 + $id_attr,
381 429 $encoded_data_attributes,
382 - ( 'icon' === $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '',
383 - $text
430 + $id_attr,
431 + esc_html( $accessible_name ),
432 + esc_html( $text )
384 433 );
385 434 }
386 435
387 436 /**
@@ -459,9 +508,9 @@
459 508 protected function build_amp_markup( $attrs = array() ) {
460 509
461 510 $title = sprintf(
462 511 /* translators: placeholder is a service name, such as "Twitter" or "Facebook". */
463 - __( 'Click to share on %s', 'jetpack' ),
512 + __( 'Share on %s', 'jetpack' ),
464 513 $this->get_name()
465 514 );
466 515
467 516 $attrs = array_merge(
@@ -551,9 +600,9 @@
551 600 */
552 601 public function get_total( $post = false ) {
553 602 global $wpdb, $blog_id;
554 603
555 - $name = strtolower( $this->get_id() );
604 + $name = strtolower( (string) $this->get_id() );
556 605
557 606 if ( $post === false ) {
558 607 // get total number of shares for service
559 608 return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) );
@@ -571,9 +620,9 @@
571 620 public function get_posts_total() {
572 621 global $wpdb, $blog_id;
573 622
574 623 $totals = array();
575 - $name = strtolower( $this->get_id() );
624 + $name = strtolower( (string) $this->get_id() );
576 625
577 626 $my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d AND share_service = %s GROUP BY post_id ORDER BY count DESC ', $blog_id, $name ) );
578 627
579 628 if ( ! empty( $my_data ) ) {
@@ -624,14 +673,26 @@
624 673 wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We allow external redirects here; we define them ourselves.
625 674
626 675 // We set up this custom header to indicate to search engines not to index this page.
627 676 header( 'X-Robots-Tag: noindex, nofollow' );
628 - die();
677 + die( 0 );
629 678 }
630 679
631 680 /**
632 - * Add extra JavaScript to a sharing service.
681 + * Register a sharing service's popup window features with the front-end script.
633 682 *
683 + * Services that open their share link in a popup publish the window features
684 + * they need in `window.WPCOM_sharing_popups`. A single delegated click handler
685 + * in sharing.js reads them and opens the popup, so no per-service handler is
686 + * emitted.
687 + *
688 + * $name has to be the same slug that appears in the share link's `share-<name>`
689 + * class, since that class is all the handler has to look the features back up
690 + * with. Every caller passes $this->shortname, which works because get_link()
691 + * builds the class from get_class() and the built-in services register under
692 + * the slug they declare as their shortname. Share_Custom is the exception: its
693 + * class and shortname do not round-trip, but it does not register a popup.
694 + *
634 695 * @param string $name Sharing service name.
635 696 * @param array $params Array of sharing options.
636 697 *
637 698 * @return void
@@ -656,41 +717,13 @@
656 717
657 718 // Add JS after sharing-js has been enqueued.
658 719 wp_add_inline_script(
659 720 'sharing-js',
660 - "var windowOpen;
661 - ( function () {
662 - function matches( el, sel ) {
663 - return !! (
664 - el.matches && el.matches( sel ) ||
665 - el.msMatchesSelector && el.msMatchesSelector( sel )
666 - );
667 - }
668 -
669 - document.body.addEventListener( 'click', function ( event ) {
670 - if ( ! event.target ) {
671 - return;
672 - }
673 -
674 - var el;
675 - if ( matches( event.target, 'a.share-$name' ) ) {
676 - el = event.target;
677 - } else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-$name' ) ) {
678 - el = event.target.parentNode;
679 - }
680 -
681 - if ( el ) {
682 - event.preventDefault();
683 -
684 - // If there's another sharing window open, close it.
685 - if ( typeof windowOpen !== 'undefined' ) {
686 - windowOpen.close();
687 - }
688 - windowOpen = window.open( el.getAttribute( 'href' ), 'wpcom$name', '$opts' );
689 - return false;
690 - }
691 - } );
692 - } )();"
721 + sprintf(
722 + "window.WPCOM_sharing_popups = window.WPCOM_sharing_popups || {};\nwindow.WPCOM_sharing_popups[ %s ] = %s;",
723 + wp_json_encode( (string) $name, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ),
724 + wp_json_encode( $opts, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP )
725 + )
693 726 );
694 727 }
695 728 }
696 729
@@ -952,9 +985,9 @@
952 985 *
953 986 * @param WP_Post $post Post object.
954 987 * @param array $post_data Array of information about the post we're sharing.
955 988 *
956 - * @return void
989 + * @return never
957 990 */
958 991 public function process_request( $post, array $post_data ) {
959 992 $is_ajax = false;
960 993 if (
@@ -974,15 +1007,14 @@
974 1007 parent::process_request( $post, $post_data );
975 1008 }
976 1009
977 1010 if ( $is_ajax ) {
978 - wp_send_json_success();
1011 + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
1012 + wp_send_json_success( null, null, JSON_UNESCAPED_SLASHES );
979 1013 } else {
980 1014 wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' );
981 - exit;
1015 + exit( 0 );
982 1016 }
983 -
984 - wp_die();
985 1017 }
986 1018
987 1019 /**
988 1020 * Get the markup of the sharing button.
@@ -1007,8 +1039,9 @@
1007 1039 'jetpack'
1008 1040 ),
1009 1041 'email-share-nonce' => wp_create_nonce( $this->get_email_share_nonce_action( $post ) ),
1010 1042 'email-share-track-url' => $tracking_url,
1043 + 'aria-labelledby' => 'sharing-email-' . $post->ID,
1011 1044 );
1012 1045
1013 1046 $post_title = $this->get_share_title( $post->ID );
1014 1047 $post_url = $this->get_share_url( $post->ID );
@@ -1027,9 +1060,9 @@
1027 1060
1028 1061 return $this->get_link(
1029 1062 'mailto:',
1030 1063 _x( 'Email', 'share to', 'jetpack' ),
1031 - __( 'Click to email a link to a friend', 'jetpack' ),
1064 + __( 'Email a link to a friend', 'jetpack' ),
1032 1065 $mailto_query,
1033 1066 false,
1034 1067 $data_attributes
1035 1068 );
@@ -1050,9 +1083,10 @@
1050 1083 }
1051 1084 }
1052 1085
1053 1086 /**
1054 - * Twitter sharing button.
1087 + * Legacy Twitter sharing button.
1088 + * Share_X is the new Twitter sharing button.
1055 1089 */
1056 1090 class Share_Twitter extends Sharing_Source {
1057 1091 /**
1058 1092 * Service short name.
@@ -1065,9 +1099,9 @@
1065 1099 * Service icon font code.
1066 1100 *
1067 1101 * @var string
1068 1102 */
1069 - public $icon = '\f202';
1103 + public $icon = '\f10e';
1070 1104
1071 1105 /**
1072 1106 * Length of a URL on Twitter.
1073 1107 * 'https://dev.twitter.com/rest/reference/get/help/configuration'
@@ -1098,9 +1132,9 @@
1098 1132 *
1099 1133 * @return string
1100 1134 */
1101 1135 public function get_name() {
1102 - return __( 'Twitter', 'jetpack' );
1136 + return __( 'X', 'jetpack' );
1103 1137 }
1104 1138
1105 1139 /**
1106 1140 * Determine the Twitter 'via' value for a post.
@@ -1237,9 +1271,9 @@
1237 1271 apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' )
1238 1272 ) {
1239 1273 sharing_register_post_for_share_counts( $post->ID );
1240 1274 }
1241 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID );
1275 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'X', 'share to', 'jetpack' ), __( 'Share on X', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID );
1242 1276 }
1243 1277 }
1244 1278
1245 1279 /**
@@ -1289,9 +1323,9 @@
1289 1323
1290 1324 $url = $post_link;
1291 1325 $twitter_url = add_query_arg(
1292 1326 rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
1293 - 'https://twitter.com/intent/tweet'
1327 + 'https://x.com/intent/tweet'
1294 1328 );
1295 1329
1296 1330 parent::redirect_request( $twitter_url );
1297 1331 }
@@ -1416,9 +1450,9 @@
1416 1450 }
1417 1451 return $this->get_link(
1418 1452 $this->get_process_request_url( $post->ID ),
1419 1453 _x( 'X', 'share to', 'jetpack' ),
1420 - __( 'Click to share on X', 'jetpack' ),
1454 + __( 'Share on X', 'jetpack' ),
1421 1455 'share=x',
1422 1456 'sharing-x-' . $post->ID
1423 1457 );
1424 1458 }
@@ -1597,10 +1631,11 @@
1597 1631 public function get_display( $post ) {
1598 1632 return $this->get_link(
1599 1633 $this->get_process_request_url( $post->ID ),
1600 1634 _x( 'Reddit', 'share to', 'jetpack' ),
1601 - __( 'Click to share on Reddit', 'jetpack' ),
1602 - 'share=reddit'
1635 + __( 'Share on Reddit', 'jetpack' ),
1636 + 'share=reddit',
1637 + 'sharing-reddit-' . $post->ID
1603 1638 );
1604 1639 }
1605 1640
1606 1641 /**
@@ -1699,9 +1734,9 @@
1699 1734 if ( $this->smart ) {
1700 1735 $share_url = $this->get_share_url( $post->ID );
1701 1736 $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) );
1702 1737 } else {
1703 - $display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID );
1738 + $display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID );
1704 1739 }
1705 1740
1706 1741 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1707 1742 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
@@ -1722,15 +1757,13 @@
1722 1757 public function process_request( $post, array $post_data ) {
1723 1758
1724 1759 $post_link = $this->get_share_url( $post->ID );
1725 1760
1726 - // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link
1727 - // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false
1728 1761 $linkedin_url = add_query_arg(
1729 1762 array(
1730 1763 'url' => rawurlencode( $post_link ),
1731 1764 ),
1732 - 'https://www.linkedin.com/cws/share?token=&isFramed=false'
1765 + 'https://www.linkedin.com/sharing/share-offsite/'
1733 1766 );
1734 1767
1735 1768 // Record stats
1736 1769 parent::process_request( $post, $post_data );
@@ -1926,9 +1959,9 @@
1926 1959 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1927 1960 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) {
1928 1961 sharing_register_post_for_share_counts( $post->ID );
1929 1962 }
1930 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Facebook', 'share to', 'jetpack' ), __( 'Click to share on Facebook', 'jetpack' ), 'share=facebook', 'sharing-facebook-' . $post->ID );
1963 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Facebook', 'share to', 'jetpack' ), __( 'Share on Facebook', 'jetpack' ), 'share=facebook', 'sharing-facebook-' . $post->ID );
1931 1964 }
1932 1965
1933 1966 /**
1934 1967 * AMP display for Facebook.
@@ -1952,9 +1985,9 @@
1952 1985 *
1953 1986 * @return void
1954 1987 */
1955 1988 public function process_request( $post, array $post_data ) {
1956 - $fb_url = $this->http() . '://www.facebook.com/sharer.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) );
1989 + $fb_url = 'https://www.facebook.com/sharer/sharer.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) );
1957 1990
1958 1991 // Record stats
1959 1992 parent::process_request( $post, $post_data );
1960 1993
@@ -2049,9 +2082,9 @@
2049 2082 *
2050 2083 * @return string
2051 2084 */
2052 2085 public function get_display( $post ) {
2053 - return $this->get_link( $this->get_process_request_url( $post->ID ) . ( ( is_single() || is_page() ) ? '#print' : '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Click to print', 'jetpack' ) );
2086 + return $this->get_link( $this->get_process_request_url( $post->ID ) . ( ( is_single() || is_page() ) ? '#print' : '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Print', 'jetpack' ), 'share=print', 'sharing-print-' . $post->ID );
2054 2087 }
2055 2088
2056 2089 /**
2057 2090 * AMP display for Print.
@@ -2140,9 +2173,9 @@
2140 2173 }
2141 2174
2142 2175 if ( empty( $blogs ) ) {
2143 2176 wp_safe_redirect( get_permalink( $post->ID ) );
2144 - die();
2177 + die( 0 );
2145 2178 }
2146 2179
2147 2180 $blog = current( $blogs );
2148 2181
@@ -2169,9 +2202,9 @@
2169 2202 *
2170 2203 * @return string
2171 2204 */
2172 2205 public function get_display( $post ) {
2173 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Press This', 'share to', 'jetpack' ), __( 'Click to Press This!', 'jetpack' ), 'share=press-this' );
2206 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Press This', 'share to', 'jetpack' ), __( 'Press This!', 'jetpack' ), 'share=press-this', 'sharing-press-this-' . $post->ID );
2174 2207 }
2175 2208
2176 2209 /**
2177 2210 * No AMP display for PressThis.
@@ -2288,14 +2321,18 @@
2288 2321 $this->get_process_request_url( $post->ID ),
2289 2322 esc_html( $this->name ),
2290 2323 sprintf(
2291 2324 /* Translators: placeholder is the name of a social network. */
2292 - __( 'Click to share on %s', 'jetpack' ),
2325 + __( 'Share on %s', 'jetpack' ),
2293 2326 esc_attr( $this->name )
2294 2327 ),
2295 - 'share=' . $this->id
2328 + 'share=' . $this->id,
2329 + 'sharing-custom-' . $post->ID
2296 2330 );
2297 - return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str );
2331 +
2332 + $style = 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");';
2333 + $class = ( 'icon' === $this->button_style ) ? ' class="custom-sharing-span"' : '';
2334 + return str_replace( '<span>', '<span' . $class . ' style="' . esc_attr( $style ) . '">', $str );
2298 2335 }
2299 2336
2300 2337 /**
2301 2338 * No AMP display for custom elements.
@@ -2315,9 +2352,9 @@
2315 2352 * @return void
2316 2353 */
2317 2354 public function process_request( $post, array $post_data ) {
2318 2355 $url = str_replace( '&amp;', '&', $this->url );
2319 - $url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url );
2356 + $url = str_replace( '%post_id%', rawurlencode( (string) $post->ID ), $url );
2320 2357 $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
2321 2358 $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
2322 2359 $url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
2323 2360 $url = str_replace( '%home_url%', rawurlencode( home_url() ), $url );
@@ -2544,9 +2581,9 @@
2544 2581 * If we are not looking at a single post, content from other posts can appear on the page and Tumblr will pick that up.
2545 2582 * In this case, we want Tumblr to focus on our current post, so we will limit the post type to link, where we can give Tumblr a link to our post.
2546 2583 */
2547 2584 if ( ! is_single() ) {
2548 - $posttype = 'data-posttype="link"';
2585 + $posttype = ' data-posttype="link"'; // Leading space separates it from the preceding title attribute.
2549 2586 } else {
2550 2587 $posttype = '';
2551 2588 }
2552 2589
@@ -2551,18 +2588,19 @@
2551 2588 }
2552 2589
2553 2590 // Documentation: https://www.tumblr.com/docs/en/share_button
2554 2591 return sprintf(
2555 - '<a class="tumblr-share-button" target="%1$s" href="%2$s" data-title="%3$s" data-content="%4$s" title="%5$s"%6$s>%5$s</a>',
2592 + '<a class="tumblr-share-button" target="%1$s" href="%2$s" data-title="%3$s" data-content="%4$s" title="%5$s"%6$s>%7$s</a>',
2556 2593 $target,
2557 2594 'https://www.tumblr.com/share',
2558 - $this->get_share_title( $post->ID ),
2559 - $this->get_share_url( $post->ID ),
2560 - __( 'Share on Tumblr', 'jetpack' ),
2561 - $posttype
2595 + esc_attr( $this->get_share_title( $post->ID ) ),
2596 + esc_url( $this->get_share_url( $post->ID ) ),
2597 + esc_attr__( 'Share on Tumblr', 'jetpack' ),
2598 + $posttype,
2599 + esc_html__( 'Share on Tumblr', 'jetpack' )
2562 2600 );
2563 2601 } else {
2564 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' );
2602 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Share on Tumblr', 'jetpack' ), 'share=tumblr', 'sharing-tumblr-' . $post->ID );
2565 2603 }
2566 2604 }
2567 2605
2568 2606 /**
@@ -2654,13 +2692,11 @@
2654 2692 *
2655 2693 * @return string
2656 2694 */
2657 2695 public function get_image( $post ) {
2658 - if ( class_exists( 'Jetpack_PostImages' ) ) {
2659 - $image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
2660 - if ( ! empty( $image ) ) {
2661 - return $image['src'];
2662 - }
2696 + $image = Images::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
2697 + if ( ! empty( $image ) ) {
2698 + return $image['src'];
2663 2699 }
2664 2700
2665 2701 /**
2666 2702 * Filters the default image used by the Pinterest Pin It share button.
@@ -2681,9 +2717,9 @@
2681 2717 *
2682 2718 * @return string
2683 2719 */
2684 2720 public function get_external_url( $post ) {
2685 - $url = 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&media=' . rawurlencode( $this->get_image( $post ) ) . '&description=' . rawurlencode( $post->post_title );
2721 + $url = 'https://www.pinterest.com/pin/create/link/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&media=' . rawurlencode( $this->get_image( $post ) ) . '&description=' . rawurlencode( $post->post_title );
2686 2722
2687 2723 /**
2688 2724 * Filters the Pinterest share URL used in sharing button output.
2689 2725 *
@@ -2732,9 +2768,9 @@
2732 2768 esc_url( $this->get_external_url( $post ) ),
2733 2769 esc_attr( $this->get_widget_type() )
2734 2770 );
2735 2771 } else {
2736 - $display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Click to share on Pinterest', 'jetpack' ), 'share=pinterest', 'sharing-pinterest-' . $post->ID );
2772 + $display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Share on Pinterest', 'jetpack' ), 'share=pinterest', 'sharing-pinterest-' . $post->ID );
2737 2773 }
2738 2774
2739 2775 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
2740 2776 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
@@ -2760,9 +2796,9 @@
2760 2796 $pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
2761 2797 parent::redirect_request( $pinterest_url );
2762 2798 } else {
2763 2799 echo '// share count bumped';
2764 - die();
2800 + die( 0 );
2765 2801 }
2766 2802 }
2767 2803
2768 2804 /**
@@ -2856,143 +2892,8 @@
2856 2892 }
2857 2893 }
2858 2894
2859 2895 /**
2860 - * Pocket sharing service.
2861 - */
2862 -class Share_Pocket extends Sharing_Source {
2863 - /**
2864 - * Service short name.
2865 - *
2866 - * @var string
2867 - */
2868 - public $shortname = 'pocket';
2869 -
2870 - /**
2871 - * Service icon font code.
2872 - *
2873 - * @var string
2874 - */
2875 - public $icon = '\f224';
2876 -
2877 - /**
2878 - * Constructor.
2879 - *
2880 - * @param int $id Sharing source ID.
2881 - * @param array $settings Sharing settings.
2882 - */
2883 - public function __construct( $id, array $settings ) {
2884 - parent::__construct( $id, $settings );
2885 -
2886 - if ( 'official' === $this->button_style ) {
2887 - $this->smart = true;
2888 - } else {
2889 - $this->smart = false;
2890 - }
2891 - }
2892 -
2893 - /**
2894 - * Service name.
2895 - *
2896 - * @return string
2897 - */
2898 - public function get_name() {
2899 - return __( 'Pocket', 'jetpack' );
2900 - }
2901 -
2902 - /**
2903 - * Process sharing request. Add actions that need to happen when sharing here.
2904 - *
2905 - * @param WP_Post $post Post object.
2906 - * @param array $post_data Array of information about the post we're sharing.
2907 - *
2908 - * @return void
2909 - */
2910 - public function process_request( $post, array $post_data ) {
2911 - // Record stats
2912 - parent::process_request( $post, $post_data );
2913 -
2914 - $pocket_url = esc_url_raw( 'https://getpocket.com/save/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) );
2915 -
2916 - parent::redirect_request( $pocket_url );
2917 - }
2918 -
2919 - /**
2920 - * Get the markup of the sharing button.
2921 - *
2922 - * @param WP_Post $post Post object.
2923 - *
2924 - * @return string
2925 - */
2926 - public function get_display( $post ) {
2927 - if ( $this->smart ) {
2928 - $post_count = 'horizontal';
2929 -
2930 - $button = '';
2931 - $button .= '<div class="pocket_button">';
2932 - $button .= sprintf( '<a href="https://getpocket.com/save" class="pocket-btn" data-lang="%s" data-save-url="%s" data-pocket-count="%s" >%s</a>', 'en', esc_attr( $this->get_share_url( $post->ID ) ), $post_count, esc_attr__( 'Pocket', 'jetpack' ) );
2933 - $button .= '</div>';
2934 -
2935 - return $button;
2936 - } else {
2937 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' );
2938 - }
2939 - }
2940 -
2941 - /**
2942 - * AMP display for Pocket.
2943 - *
2944 - * @param \WP_Post $post The current post being viewed.
2945 - */
2946 - public function get_amp_display( $post ) {
2947 - $attrs = array(
2948 - 'data-share-endpoint' => esc_url_raw( 'https://getpocket.com/save/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) ),
2949 - );
2950 -
2951 - return $this->build_amp_markup( $attrs );
2952 - }
2953 -
2954 - /**
2955 - * Add content specific to a service in the footer.
2956 - */
2957 - public function display_footer() {
2958 - if ( $this->smart ) :
2959 - ?>
2960 - <script>
2961 - ( function () {
2962 - var currentScript = document.currentScript;
2963 -
2964 - // Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS.
2965 - function jetpack_sharing_pocket_init() {
2966 - var script = document.createElement( 'script' );
2967 - var prev = currentScript || document.getElementsByTagName( 'script' )[ 0 ];
2968 - script.setAttribute( 'async', true );
2969 - script.setAttribute( 'src', 'https://widgets.getpocket.com/v1/j/btn.js?v=1' );
2970 - prev.parentNode.insertBefore( script, prev );
2971 - }
2972 -
2973 - if ( document.readyState === 'loading' ) {
2974 - document.addEventListener( 'DOMContentLoaded', jetpack_sharing_pocket_init );
2975 - } else {
2976 - jetpack_sharing_pocket_init();
2977 - }
2978 - document.body.addEventListener( 'is.post-load', jetpack_sharing_pocket_init );
2979 - } )();
2980 - </script>
2981 - <?php
2982 - else :
2983 - $this->js_dialog(
2984 - $this->shortname,
2985 - array(
2986 - 'width' => 450,
2987 - 'height' => 450,
2988 - )
2989 - );
2990 - endif;
2991 - }
2992 -}
2993 -
2994 -/**
2995 2896 * Telegram sharing service.
2996 2897 */
2997 2898 class Share_Telegram extends Sharing_Source {
2998 2899 /**
@@ -3045,9 +2946,9 @@
3045 2946 *
3046 2947 * @return string
3047 2948 */
3048 2949 public function get_display( $post ) {
3049 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' );
2950 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Share on Telegram', 'jetpack' ), 'share=telegram', 'sharing-telegram-' . $post->ID );
3050 2951 }
3051 2952
3052 2953 /**
3053 2954 * AMP display for Telegram.
@@ -3113,9 +3014,9 @@
3113 3014 *
3114 3015 * @return string
3115 3016 */
3116 3017 public function get_display( $post ) {
3117 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Click to share on WhatsApp', 'jetpack' ), 'share=jetpack-whatsapp' );
3018 + return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Share on WhatsApp', 'jetpack' ), 'share=jetpack-whatsapp', 'sharing-whatsapp-' . $post->ID );
3118 3019 }
3119 3020
3120 3021 /**
3121 3022 * AMP display for Whatsapp.
@@ -3155,29 +3056,8 @@
3155 3056 }
3156 3057 }
3157 3058
3158 3059 /**
3159 - * Skype sharing service.
3160 - */
3161 -class Share_Skype extends Deprecated_Sharing_Source {
3162 - /**
3163 - * Service short name.
3164 - *
3165 - * @var string
3166 - */
3167 - public $shortname = 'skype';
3168 -
3169 - /**
3170 - * Service name.
3171 - *
3172 - * @return string
3173 - */
3174 - public function get_name() {
3175 - return __( 'Skype', 'jetpack' );
3176 - }
3177 -}
3178 -
3179 -/**
3180 3060 * Mastodon sharing service.
3181 3061 */
3182 3062 class Share_Mastodon extends Sharing_Source {
3183 3063 /**
@@ -3213,9 +3093,9 @@
3213 3093 public function get_display( $post ) {
3214 3094 return $this->get_link(
3215 3095 $this->get_process_request_url( $post->ID ),
3216 3096 _x( 'Mastodon', 'share to', 'jetpack' ),
3217 - __( 'Click to share on Mastodon', 'jetpack' ),
3097 + __( 'Share on Mastodon', 'jetpack' ),
3218 3098 'share=mastodon',
3219 3099 'sharing-mastodon-' . $post->ID
3220 3100 );
3221 3101 }
@@ -3325,9 +3205,9 @@
3325 3205 public function get_display( $post ) {
3326 3206 return $this->get_link(
3327 3207 $this->get_process_request_url( $post->ID ),
3328 3208 _x( 'Nextdoor', 'share to', 'jetpack' ),
3329 - __( 'Click to share on Nextdoor', 'jetpack' ),
3209 + __( 'Share on Nextdoor', 'jetpack' ),
3330 3210 'share=nextdoor',
3331 3211 'sharing-nextdoor-' . $post->ID
3332 3212 );
3333 3213 }
@@ -3388,9 +3268,9 @@
3388 3268 public function get_display( $post ) {
3389 3269 return $this->get_link(
3390 3270 $this->get_process_request_url( $post->ID ),
3391 3271 _x( 'Threads', 'share to', 'jetpack' ),
3392 - __( 'Click to share on Threads', 'jetpack' ),
3272 + __( 'Share on Threads', 'jetpack' ),
3393 3273 'share=threads',
3394 3274 'sharing-threads-' . $post->ID
3395 3275 );
3396 3276 }
@@ -3458,9 +3338,9 @@
3458 3338 public function get_display( $post ) {
3459 3339 return $this->get_link(
3460 3340 $this->get_process_request_url( $post->ID ),
3461 3341 _x( 'Bluesky', 'share to', 'jetpack' ),
3462 - __( 'Click to share on Bluesky', 'jetpack' ),
3342 + __( 'Share on Bluesky', 'jetpack' ),
3463 3343 'share=bluesky',
3464 3344 'sharing-bluesky-' . $post->ID
3465 3345 );
3466 3346 }