PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 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 All 506 releases
← All changes | extensions/blocks/sharing-button/class-sharing-source-block.php +50 -86 13.3.3 → 16.3-a.7 View file →
@@ -11,9 +11,10 @@
11 11
12 12 namespace Automattic\Jetpack\Extensions\Sharing_Button_Block;
13 13
14 14 use Automattic\Jetpack\Device_Detection\User_Agent_Info;
15 -use Jetpack_PostImages;
15 +use Automattic\Jetpack\Post_Media\Images;
16 +use WP_Post;
16 17
17 18 /**
18 19 * Base class for sharing sources.
19 20 * See individual sharing classes below for the implementation of this class.
@@ -62,14 +63,40 @@
62 63 return $this->id;
63 64 }
64 65
65 66 /**
66 - * Get sharing stats for a specific post or sharing service.
67 + * Get stats for a site, a post, or a sharing service.
68 + * Soon to come to a .org plugin near you!
67 69 *
68 - * @return int This is a placeholder that returns 0 at the moment. We might want to implement this in the future.
70 + * @param WP_Post|bool $post Post object.
71 + *
72 + * @return int
69 73 */
70 - public function get_total() {
71 - return 0;
74 + public function get_total( $post = false ) {
75 + global $wpdb, $blog_id;
76 +
77 + $name = strtolower( (string) $this->get_id() );
78 +
79 + if ( $post === false ) {
80 + // get total number of shares for service
81 + return (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
82 + $wpdb->prepare(
83 + 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s',
84 + $blog_id,
85 + $name
86 + )
87 + );
88 + }
89 +
90 + // get total shares for a post
91 + return (int) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
92 + $wpdb->prepare(
93 + 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s',
94 + $blog_id,
95 + $post->ID,
96 + $name
97 + )
98 + );
72 99 }
73 100
74 101 /**
75 102 * Get a post's permalink to use for sharing.
@@ -112,10 +139,9 @@
112 139 * @param string $post->post_title Post Title.
113 140 * @param int $post_id Post ID.
114 141 * @param int $this->id Sharing ID.
115 142 */
116 - $title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id );
117 -
143 + $title = $post instanceof WP_Post ? apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id ) : '';
118 144 return html_entity_decode( wp_kses( $title, '' ), ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 );
119 145 }
120 146
121 147 /**
@@ -294,8 +320,9 @@
294 320 if ( ! empty( $data_attributes ) ) {
295 321 $encoded_data_attributes = implode(
296 322 ' ',
297 323 array_map(
324 + /** Format attributes */
298 325 function ( $data_key, $data_value ) {
299 326 return sprintf(
300 327 'data-%s="%s"',
301 328 esc_attr( str_replace( array( ' ', '"' ), '', $data_key ) ),
@@ -372,9 +399,9 @@
372 399 wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We allow external redirects here; we define them ourselves.
373 400
374 401 // We set up this custom header to indicate to search engines not to index this page.
375 402 header( 'X-Robots-Tag: noindex, nofollow' );
376 - die();
403 + die( 0 );
377 404 }
378 405 }
379 406
380 407 /**
@@ -403,9 +430,9 @@
403 430 * @param int $post_id The current post id if it is defined.
404 431 * @return string The nonce action name.
405 432 */
406 433 protected function get_email_share_nonce_action( $post_id ) {
407 - if ( ! empty( $post_id ) && 0 !== $post_id ) {
434 + if ( ! empty( $post_id ) ) {
408 435 return 'jetpack-email-share-' . $post_id;
409 436 }
410 437
411 438 return 'jetpack-email-share';
@@ -471,9 +498,9 @@
471 498 *
472 499 * @param WP_Post $post Post object.
473 500 * @param array $post_data Array of information about the post we're sharing.
474 501 *
475 - * @return void
502 + * @return never
476 503 */
477 504 public function process_request( $post, array $post_data ) {
478 505 $is_ajax = false;
479 506 if (
@@ -493,15 +520,14 @@
493 520 parent::process_request( $post, $post_data );
494 521 }
495 522
496 523 if ( $is_ajax ) {
497 - wp_send_json_success();
524 + // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal -- It takes null, but its phpdoc only says int.
525 + wp_send_json_success( null, null, JSON_UNESCAPED_SLASHES );
498 526 } else {
499 527 wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' );
500 - exit;
528 + exit( 0 );
501 529 }
502 -
503 - wp_die();
504 530 }
505 531 }
506 532
507 533 /**
@@ -539,9 +565,10 @@
539 565 *
540 566 * @return void
541 567 */
542 568 public function process_request( $post, array $post_data ) {
543 - $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 ) );
569 + $post_id = $post instanceof WP_Post ? $post->ID : 0;
570 + $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 ) );
544 571
545 572 // Record stats
546 573 parent::process_request( $post, $post_data );
547 574
@@ -657,13 +684,11 @@
657 684 *
658 685 * @return string
659 686 */
660 687 public function get_image( $post ) {
661 - if ( class_exists( 'Jetpack_PostImages' ) ) {
662 - $image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
663 - if ( ! empty( $image ) ) {
664 - return $image['src'];
665 - }
688 + $image = Images::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
689 + if ( ! empty( $image ) ) {
690 + return $image['src'];
666 691 }
667 692
668 693 /**
669 694 * Filters the default image used by the Pinterest Pin It share button.
@@ -684,9 +709,9 @@
684 709 *
685 710 * @return string
686 711 */
687 712 public function get_external_url( $post ) {
688 - $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 );
713 + $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 );
689 714
690 715 /**
691 716 * Filters the Pinterest share URL used in sharing button output.
692 717 *
@@ -735,52 +760,14 @@
735 760 $pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
736 761 parent::redirect_request( $pinterest_url );
737 762 } else {
738 763 echo '// share count bumped';
739 - die();
764 + die( 0 );
740 765 }
741 766 }
742 767 }
743 768
744 769 /**
745 - * Pocket sharing service.
746 - */
747 -class Share_Pocket_Block extends Sharing_Source_Block {
748 - /**
749 - * Service short name.
750 - *
751 - * @var string
752 - */
753 - public $shortname = 'pocket';
754 -
755 - /**
756 - * Service name.
757 - *
758 - * @return string
759 - */
760 - public function get_name() {
761 - return __( 'Pocket', 'jetpack' );
762 - }
763 -
764 - /**
765 - * Process sharing request. Add actions that need to happen when sharing here.
766 - *
767 - * @param WP_Post $post Post object.
768 - * @param array $post_data Array of information about the post we're sharing.
769 - *
770 - * @return void
771 - */
772 - public function process_request( $post, array $post_data ) {
773 - // Record stats
774 - parent::process_request( $post, $post_data );
775 -
776 - $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 ) ) );
777 -
778 - parent::redirect_request( $pocket_url );
779 - }
780 -}
781 -
782 -/**
783 770 * Telegram sharing service.
784 771 */
785 772 class Share_Telegram_Block extends Sharing_Source_Block {
786 773 /**
@@ -1185,9 +1172,9 @@
1185 1172 *
1186 1173 * @return string
1187 1174 */
1188 1175 public function get_name() {
1189 - return __( 'Twitter', 'jetpack' );
1176 + return __( 'X', 'jetpack' );
1190 1177 }
1191 1178
1192 1179 /**
1193 1180 * Determine the Twitter 'via' value for a post.
@@ -1322,9 +1309,9 @@
1322 1309
1323 1310 $url = $post_link;
1324 1311 $twitter_url = add_query_arg(
1325 1312 rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
1326 - 'https://twitter.com/intent/tweet'
1313 + 'https://x.com/intent/tweet'
1327 1314 );
1328 1315
1329 1316 parent::redirect_request( $twitter_url );
1330 1317 }
@@ -1399,15 +1386,13 @@
1399 1386 public function process_request( $post, array $post_data ) {
1400 1387
1401 1388 $post_link = $this->get_share_url( $post->ID );
1402 1389
1403 - // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link
1404 - // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false
1405 1390 $linkedin_url = add_query_arg(
1406 1391 array(
1407 1392 'url' => rawurlencode( $post_link ),
1408 1393 ),
1409 - 'https://www.linkedin.com/cws/share?token=&isFramed=false'
1394 + 'https://www.linkedin.com/sharing/share-offsite/'
1410 1395 );
1411 1396
1412 1397 // Record stats
1413 1398 parent::process_request( $post, $post_data );
@@ -1412,29 +1397,8 @@
1412 1397 // Record stats
1413 1398 parent::process_request( $post, $post_data );
1414 1399
1415 1400 parent::redirect_request( $linkedin_url );
1416 - }
1417 -}
1418 -
1419 -/**
1420 - * Skype sharing service.
1421 - */
1422 -class Share_Skype_Block extends Sharing_Source_Block {
1423 - /**
1424 - * Service short name.
1425 - *
1426 - * @var string
1427 - */
1428 - public $shortname = 'skype';
1429 -
1430 - /**
1431 - * Service name.
1432 - *
1433 - * @return string
1434 - */
1435 - public function get_name() {
1436 - return __( 'Skype', 'jetpack' );
1437 1401 }
1438 1402 }
1439 1403
1440 1404 /**