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 +140 -259 13.3.316.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,13 +377,21 @@
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(
393 + /** Filter for formatting attributes */
359 394 function ( $data_key, $data_value ) {
360 395 return sprintf(
361 396 'data-%s="%s"',
362 397 esc_attr( str_replace( array( ' ', '"' ), '', $data_key ) ),
@@ -368,19 +403,34 @@
368 403 )
369 404 );
370 405 }
371 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 +
372 412 return sprintf(
373 - '<a rel="nofollow%s" data-shared="%s" class="%s" href="%s"%s title="%s" %s><span%s>%s</span></a>',
374 - ( true === $this->open_link_in_new ) ? ' noopener noreferrer' : '',
375 - ( $id ? esc_attr( $id ) : '' ),
376 - implode( ' ', $klasses ),
377 - $url,
378 - ( true === $this->open_link_in_new ) ? ' target="_blank"' : '',
379 - $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,
380 429 $encoded_data_attributes,
381 - ( 'icon' === $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '',
382 - $text
430 + $id_attr,
431 + esc_html( $accessible_name ),
432 + esc_html( $text )
383 433 );
384 434 }
385 435
386 436 /**
@@ -458,9 +508,9 @@
458 508 protected function build_amp_markup( $attrs = array() ) {
459 509
460 510 $title = sprintf(
461 511 /* translators: placeholder is a service name, such as "Twitter" or "Facebook". */
462 - __( 'Click to share on %s', 'jetpack' ),
512 + __( 'Share on %s', 'jetpack' ),
463 513 $this->get_name()
464 514 );
465 515
466 516 $attrs = array_merge(
@@ -550,9 +600,9 @@
550 600 */
551 601 public function get_total( $post = false ) {
552 602 global $wpdb, $blog_id;
553 603
554 - $name = strtolower( $this->get_id() );
604 + $name = strtolower( (string) $this->get_id() );
555 605
556 606 if ( $post === false ) {
557 607 // get total number of shares for service
558 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 ) );
@@ -570,9 +620,9 @@
570 620 public function get_posts_total() {
571 621 global $wpdb, $blog_id;
572 622
573 623 $totals = array();
574 - $name = strtolower( $this->get_id() );
624 + $name = strtolower( (string) $this->get_id() );
575 625
576 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 ) );
577 627
578 628 if ( ! empty( $my_data ) ) {
@@ -623,14 +673,26 @@
623 673 wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We allow external redirects here; we define them ourselves.
624 674
625 675 // We set up this custom header to indicate to search engines not to index this page.
626 676 header( 'X-Robots-Tag: noindex, nofollow' );
627 - die();
677 + die( 0 );
628 678 }
629 679
630 680 /**
631 - * Add extra JavaScript to a sharing service.
681 + * Register a sharing service's popup window features with the front-end script.
632 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 + *
633 695 * @param string $name Sharing service name.
634 696 * @param array $params Array of sharing options.
635 697 *
636 698 * @return void
@@ -655,41 +717,13 @@
655 717
656 718 // Add JS after sharing-js has been enqueued.
657 719 wp_add_inline_script(
658 720 'sharing-js',
659 - "var windowOpen;
660 - ( function () {
661 - function matches( el, sel ) {
662 - return !! (
663 - el.matches && el.matches( sel ) ||
664 - el.msMatchesSelector && el.msMatchesSelector( sel )
665 - );
666 - }
667 -
668 - document.body.addEventListener( 'click', function ( event ) {
669 - if ( ! event.target ) {
670 - return;
671 - }
672 -
673 - var el;
674 - if ( matches( event.target, 'a.share-$name' ) ) {
675 - el = event.target;
676 - } else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-$name' ) ) {
677 - el = event.target.parentNode;
678 - }
679 -
680 - if ( el ) {
681 - event.preventDefault();
682 -
683 - // If there's another sharing window open, close it.
684 - if ( typeof windowOpen !== 'undefined' ) {
685 - windowOpen.close();
686 - }
687 - windowOpen = window.open( el.getAttribute( 'href' ), 'wpcom$name', '$opts' );
688 - return false;
689 - }
690 - } );
691 - } )();"
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 + )
692 726 );
693 727 }
694 728 }
695 729
@@ -951,9 +985,9 @@
951 985 *
952 986 * @param WP_Post $post Post object.
953 987 * @param array $post_data Array of information about the post we're sharing.
954 988 *
955 - * @return void
989 + * @return never
956 990 */
957 991 public function process_request( $post, array $post_data ) {
958 992 $is_ajax = false;
959 993 if (
@@ -973,15 +1007,14 @@
973 1007 parent::process_request( $post, $post_data );
974 1008 }
975 1009
976 1010 if ( $is_ajax ) {
977 - 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 );
978 1013 } else {
979 1014 wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' );
980 - exit;
1015 + exit( 0 );
981 1016 }
982 -
983 - wp_die();
984 1017 }
985 1018
986 1019 /**
987 1020 * Get the markup of the sharing button.
@@ -1006,8 +1039,9 @@
1006 1039 'jetpack'
1007 1040 ),
1008 1041 'email-share-nonce' => wp_create_nonce( $this->get_email_share_nonce_action( $post ) ),
1009 1042 'email-share-track-url' => $tracking_url,
1043 + 'aria-labelledby' => 'sharing-email-' . $post->ID,
1010 1044 );
1011 1045
1012 1046 $post_title = $this->get_share_title( $post->ID );
1013 1047 $post_url = $this->get_share_url( $post->ID );
@@ -1026,9 +1060,9 @@
1026 1060
1027 1061 return $this->get_link(
1028 1062 'mailto:',
1029 1063 _x( 'Email', 'share to', 'jetpack' ),
1030 - __( 'Click to email a link to a friend', 'jetpack' ),
1064 + __( 'Email a link to a friend', 'jetpack' ),
1031 1065 $mailto_query,
1032 1066 false,
1033 1067 $data_attributes
1034 1068 );
@@ -1049,9 +1083,10 @@
1049 1083 }
1050 1084 }
1051 1085
1052 1086 /**
1053 - * Twitter sharing button.
1087 + * Legacy Twitter sharing button.
1088 + * Share_X is the new Twitter sharing button.
1054 1089 */
1055 1090 class Share_Twitter extends Sharing_Source {
1056 1091 /**
1057 1092 * Service short name.
@@ -1064,9 +1099,9 @@
1064 1099 * Service icon font code.
1065 1100 *
1066 1101 * @var string
1067 1102 */
1068 - public $icon = '\f202';
1103 + public $icon = '\f10e';
1069 1104
1070 1105 /**
1071 1106 * Length of a URL on Twitter.
1072 1107 * 'https://dev.twitter.com/rest/reference/get/help/configuration'
@@ -1097,9 +1132,9 @@
1097 1132 *
1098 1133 * @return string
1099 1134 */
1100 1135 public function get_name() {
1101 - return __( 'Twitter', 'jetpack' );
1136 + return __( 'X', 'jetpack' );
1102 1137 }
1103 1138
1104 1139 /**
1105 1140 * Determine the Twitter 'via' value for a post.
@@ -1236,9 +1271,9 @@
1236 1271 apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' )
1237 1272 ) {
1238 1273 sharing_register_post_for_share_counts( $post->ID );
1239 1274 }
1240 - 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 );
1241 1276 }
1242 1277 }
1243 1278
1244 1279 /**
@@ -1288,9 +1323,9 @@
1288 1323
1289 1324 $url = $post_link;
1290 1325 $twitter_url = add_query_arg(
1291 1326 rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
1292 - 'https://twitter.com/intent/tweet'
1327 + 'https://x.com/intent/tweet'
1293 1328 );
1294 1329
1295 1330 parent::redirect_request( $twitter_url );
1296 1331 }
@@ -1415,9 +1450,9 @@
1415 1450 }
1416 1451 return $this->get_link(
1417 1452 $this->get_process_request_url( $post->ID ),
1418 1453 _x( 'X', 'share to', 'jetpack' ),
1419 - __( 'Click to share on X', 'jetpack' ),
1454 + __( 'Share on X', 'jetpack' ),
1420 1455 'share=x',
1421 1456 'sharing-x-' . $post->ID
1422 1457 );
1423 1458 }
@@ -1596,10 +1631,11 @@
1596 1631 public function get_display( $post ) {
1597 1632 return $this->get_link(
1598 1633 $this->get_process_request_url( $post->ID ),
1599 1634 _x( 'Reddit', 'share to', 'jetpack' ),
1600 - __( 'Click to share on Reddit', 'jetpack' ),
1601 - 'share=reddit'
1635 + __( 'Share on Reddit', 'jetpack' ),
1636 + 'share=reddit',
1637 + 'sharing-reddit-' . $post->ID
1602 1638 );
1603 1639 }
1604 1640
1605 1641 /**
@@ -1698,9 +1734,9 @@
1698 1734 if ( $this->smart ) {
1699 1735 $share_url = $this->get_share_url( $post->ID );
1700 1736 $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) );
1701 1737 } else {
1702 - $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 );
1703 1739 }
1704 1740
1705 1741 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1706 1742 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
@@ -1721,15 +1757,13 @@
1721 1757 public function process_request( $post, array $post_data ) {
1722 1758
1723 1759 $post_link = $this->get_share_url( $post->ID );
1724 1760
1725 - // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link
1726 - // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false
1727 1761 $linkedin_url = add_query_arg(
1728 1762 array(
1729 1763 'url' => rawurlencode( $post_link ),
1730 1764 ),
1731 - 'https://www.linkedin.com/cws/share?token=&isFramed=false'
1765 + 'https://www.linkedin.com/sharing/share-offsite/'
1732 1766 );
1733 1767
1734 1768 // Record stats
1735 1769 parent::process_request( $post, $post_data );
@@ -1925,9 +1959,9 @@
1925 1959 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1926 1960 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) {
1927 1961 sharing_register_post_for_share_counts( $post->ID );
1928 1962 }
1929 - 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 );
1930 1964 }
1931 1965
1932 1966 /**
1933 1967 * AMP display for Facebook.
@@ -1951,9 +1985,9 @@
1951 1985 *
1952 1986 * @return void
1953 1987 */
1954 1988 public function process_request( $post, array $post_data ) {
1955 - $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 ) );
1956 1990
1957 1991 // Record stats
1958 1992 parent::process_request( $post, $post_data );
1959 1993
@@ -2048,9 +2082,9 @@
2048 2082 *
2049 2083 * @return string
2050 2084 */
2051 2085 public function get_display( $post ) {
2052 - 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 );
2053 2087 }
2054 2088
2055 2089 /**
2056 2090 * AMP display for Print.
@@ -2139,9 +2173,9 @@
2139 2173 }
2140 2174
2141 2175 if ( empty( $blogs ) ) {
2142 2176 wp_safe_redirect( get_permalink( $post->ID ) );
2143 - die();
2177 + die( 0 );
2144 2178 }
2145 2179
2146 2180 $blog = current( $blogs );
2147 2181
@@ -2168,9 +2202,9 @@
2168 2202 *
2169 2203 * @return string
2170 2204 */
2171 2205 public function get_display( $post ) {
2172 - 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 );
2173 2207 }
2174 2208
2175 2209 /**
2176 2210 * No AMP display for PressThis.
@@ -2287,14 +2321,18 @@
2287 2321 $this->get_process_request_url( $post->ID ),
2288 2322 esc_html( $this->name ),
2289 2323 sprintf(
2290 2324 /* Translators: placeholder is the name of a social network. */
2291 - __( 'Click to share on %s', 'jetpack' ),
2325 + __( 'Share on %s', 'jetpack' ),
2292 2326 esc_attr( $this->name )
2293 2327 ),
2294 - 'share=' . $this->id
2328 + 'share=' . $this->id,
2329 + 'sharing-custom-' . $post->ID
2295 2330 );
2296 - 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 );
2297 2335 }
2298 2336
2299 2337 /**
2300 2338 * No AMP display for custom elements.
@@ -2314,9 +2352,9 @@
2314 2352 * @return void
2315 2353 */
2316 2354 public function process_request( $post, array $post_data ) {
2317 2355 $url = str_replace( '&amp;', '&', $this->url );
2318 - $url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url );
2356 + $url = str_replace( '%post_id%', rawurlencode( (string) $post->ID ), $url );
2319 2357 $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
2320 2358 $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
2321 2359 $url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
2322 2360 $url = str_replace( '%home_url%', rawurlencode( home_url() ), $url );
@@ -2543,9 +2581,9 @@
2543 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.
2544 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.
2545 2583 */
2546 2584 if ( ! is_single() ) {
2547 - $posttype = 'data-posttype="link"';
2585 + $posttype = ' data-posttype="link"'; // Leading space separates it from the preceding title attribute.
2548 2586 } else {
2549 2587 $posttype = '';
2550 2588 }
2551 2589
@@ -2550,18 +2588,19 @@
2550 2588 }
2551 2589
2552 2590 // Documentation: https://www.tumblr.com/docs/en/share_button
2553 2591 return sprintf(
2554 - '<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>',
2555 2593 $target,
2556 2594 'https://www.tumblr.com/share',
2557 - $this->get_share_title( $post->ID ),
2558 - $this->get_share_url( $post->ID ),
2559 - __( 'Share on Tumblr', 'jetpack' ),
2560 - $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' )
2561 2600 );
2562 2601 } else {
2563 - 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 );
2564 2603 }
2565 2604 }
2566 2605
2567 2606 /**
@@ -2653,13 +2692,11 @@
2653 2692 *
2654 2693 * @return string
2655 2694 */
2656 2695 public function get_image( $post ) {
2657 - if ( class_exists( 'Jetpack_PostImages' ) ) {
2658 - $image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
2659 - if ( ! empty( $image ) ) {
2660 - return $image['src'];
2661 - }
2696 + $image = Images::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
2697 + if ( ! empty( $image ) ) {
2698 + return $image['src'];
2662 2699 }
2663 2700
2664 2701 /**
2665 2702 * Filters the default image used by the Pinterest Pin It share button.
@@ -2680,9 +2717,9 @@
2680 2717 *
2681 2718 * @return string
2682 2719 */
2683 2720 public function get_external_url( $post ) {
2684 - $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 );
2685 2722
2686 2723 /**
2687 2724 * Filters the Pinterest share URL used in sharing button output.
2688 2725 *
@@ -2731,9 +2768,9 @@
2731 2768 esc_url( $this->get_external_url( $post ) ),
2732 2769 esc_attr( $this->get_widget_type() )
2733 2770 );
2734 2771 } else {
2735 - $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 );
2736 2773 }
2737 2774
2738 2775 /** This filter is already documented in modules/sharedaddy/sharing-sources.php */
2739 2776 if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
@@ -2759,9 +2796,9 @@
2759 2796 $pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
2760 2797 parent::redirect_request( $pinterest_url );
2761 2798 } else {
2762 2799 echo '// share count bumped';
2763 - die();
2800 + die( 0 );
2764 2801 }
2765 2802 }
2766 2803
2767 2804 /**
@@ -2855,143 +2892,8 @@
2855 2892 }
2856 2893 }
2857 2894
2858 2895 /**
2859 - * Pocket sharing service.
2860 - */
2861 -class Share_Pocket extends Sharing_Source {
2862 - /**
2863 - * Service short name.
2864 - *
2865 - * @var string
2866 - */
2867 - public $shortname = 'pocket';
2868 -
2869 - /**
2870 - * Service icon font code.
2871 - *
2872 - * @var string
2873 - */
2874 - public $icon = '\f224';
2875 -
2876 - /**
2877 - * Constructor.
2878 - *
2879 - * @param int $id Sharing source ID.
2880 - * @param array $settings Sharing settings.
2881 - */
2882 - public function __construct( $id, array $settings ) {
2883 - parent::__construct( $id, $settings );
2884 -
2885 - if ( 'official' === $this->button_style ) {
2886 - $this->smart = true;
2887 - } else {
2888 - $this->smart = false;
2889 - }
2890 - }
2891 -
2892 - /**
2893 - * Service name.
2894 - *
2895 - * @return string
2896 - */
2897 - public function get_name() {
2898 - return __( 'Pocket', 'jetpack' );
2899 - }
2900 -
2901 - /**
2902 - * Process sharing request. Add actions that need to happen when sharing here.
2903 - *
2904 - * @param WP_Post $post Post object.
2905 - * @param array $post_data Array of information about the post we're sharing.
2906 - *
2907 - * @return void
2908 - */
2909 - public function process_request( $post, array $post_data ) {
2910 - // Record stats
2911 - parent::process_request( $post, $post_data );
2912 -
2913 - $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 ) ) );
2914 -
2915 - parent::redirect_request( $pocket_url );
2916 - }
2917 -
2918 - /**
2919 - * Get the markup of the sharing button.
2920 - *
2921 - * @param WP_Post $post Post object.
2922 - *
2923 - * @return string
2924 - */
2925 - public function get_display( $post ) {
2926 - if ( $this->smart ) {
2927 - $post_count = 'horizontal';
2928 -
2929 - $button = '';
2930 - $button .= '<div class="pocket_button">';
2931 - $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' ) );
2932 - $button .= '</div>';
2933 -
2934 - return $button;
2935 - } else {
2936 - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' );
2937 - }
2938 - }
2939 -
2940 - /**
2941 - * AMP display for Pocket.
2942 - *
2943 - * @param \WP_Post $post The current post being viewed.
2944 - */
2945 - public function get_amp_display( $post ) {
2946 - $attrs = array(
2947 - '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 ) ) ),
2948 - );
2949 -
2950 - return $this->build_amp_markup( $attrs );
2951 - }
2952 -
2953 - /**
2954 - * Add content specific to a service in the footer.
2955 - */
2956 - public function display_footer() {
2957 - if ( $this->smart ) :
2958 - ?>
2959 - <script>
2960 - ( function () {
2961 - var currentScript = document.currentScript;
2962 -
2963 - // Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS.
2964 - function jetpack_sharing_pocket_init() {
2965 - var script = document.createElement( 'script' );
2966 - var prev = currentScript || document.getElementsByTagName( 'script' )[ 0 ];
2967 - script.setAttribute( 'async', true );
2968 - script.setAttribute( 'src', 'https://widgets.getpocket.com/v1/j/btn.js?v=1' );
2969 - prev.parentNode.insertBefore( script, prev );
2970 - }
2971 -
2972 - if ( document.readyState === 'loading' ) {
2973 - document.addEventListener( 'DOMContentLoaded', jetpack_sharing_pocket_init );
2974 - } else {
2975 - jetpack_sharing_pocket_init();
2976 - }
2977 - document.body.addEventListener( 'is.post-load', jetpack_sharing_pocket_init );
2978 - } )();
2979 - </script>
2980 - <?php
2981 - else :
2982 - $this->js_dialog(
2983 - $this->shortname,
2984 - array(
2985 - 'width' => 450,
2986 - 'height' => 450,
2987 - )
2988 - );
2989 - endif;
2990 - }
2991 -}
2992 -
2993 -/**
2994 2896 * Telegram sharing service.
2995 2897 */
2996 2898 class Share_Telegram extends Sharing_Source {
2997 2899 /**
@@ -3044,9 +2946,9 @@
3044 2946 *
3045 2947 * @return string
3046 2948 */
3047 2949 public function get_display( $post ) {
3048 - 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 );
3049 2951 }
3050 2952
3051 2953 /**
3052 2954 * AMP display for Telegram.
@@ -3112,9 +3014,9 @@
3112 3014 *
3113 3015 * @return string
3114 3016 */
3115 3017 public function get_display( $post ) {
3116 - 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 );
3117 3019 }
3118 3020
3119 3021 /**
3120 3022 * AMP display for Whatsapp.
@@ -3154,29 +3056,8 @@
3154 3056 }
3155 3057 }
3156 3058
3157 3059 /**
3158 - * Skype sharing service.
3159 - */
3160 -class Share_Skype extends Deprecated_Sharing_Source {
3161 - /**
3162 - * Service short name.
3163 - *
3164 - * @var string
3165 - */
3166 - public $shortname = 'skype';
3167 -
3168 - /**
3169 - * Service name.
3170 - *
3171 - * @return string
3172 - */
3173 - public function get_name() {
3174 - return __( 'Skype', 'jetpack' );
3175 - }
3176 -}
3177 -
3178 -/**
3179 3060 * Mastodon sharing service.
3180 3061 */
3181 3062 class Share_Mastodon extends Sharing_Source {
3182 3063 /**
@@ -3212,9 +3093,9 @@
3212 3093 public function get_display( $post ) {
3213 3094 return $this->get_link(
3214 3095 $this->get_process_request_url( $post->ID ),
3215 3096 _x( 'Mastodon', 'share to', 'jetpack' ),
3216 - __( 'Click to share on Mastodon', 'jetpack' ),
3097 + __( 'Share on Mastodon', 'jetpack' ),
3217 3098 'share=mastodon',
3218 3099 'sharing-mastodon-' . $post->ID
3219 3100 );
3220 3101 }
@@ -3324,9 +3205,9 @@
3324 3205 public function get_display( $post ) {
3325 3206 return $this->get_link(
3326 3207 $this->get_process_request_url( $post->ID ),
3327 3208 _x( 'Nextdoor', 'share to', 'jetpack' ),
3328 - __( 'Click to share on Nextdoor', 'jetpack' ),
3209 + __( 'Share on Nextdoor', 'jetpack' ),
3329 3210 'share=nextdoor',
3330 3211 'sharing-nextdoor-' . $post->ID
3331 3212 );
3332 3213 }
@@ -3387,9 +3268,9 @@
3387 3268 public function get_display( $post ) {
3388 3269 return $this->get_link(
3389 3270 $this->get_process_request_url( $post->ID ),
3390 3271 _x( 'Threads', 'share to', 'jetpack' ),
3391 - __( 'Click to share on Threads', 'jetpack' ),
3272 + __( 'Share on Threads', 'jetpack' ),
3392 3273 'share=threads',
3393 3274 'sharing-threads-' . $post->ID
3394 3275 );
3395 3276 }
@@ -3457,9 +3338,9 @@
3457 3338 public function get_display( $post ) {
3458 3339 return $this->get_link(
3459 3340 $this->get_process_request_url( $post->ID ),
3460 3341 _x( 'Bluesky', 'share to', 'jetpack' ),
3461 - __( 'Click to share on Bluesky', 'jetpack' ),
3342 + __( 'Share on Bluesky', 'jetpack' ),
3462 3343 'share=bluesky',
3463 3344 'sharing-bluesky-' . $post->ID
3464 3345 );
3465 3346 }