| @@ -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( |
| @@ -520,15 +570,15 @@ | ||
| 520 | 570 | implode( ' ', $klasses ), |
| 521 | 571 | esc_attr( |
| 522 | 572 | $is_deprecated |
| 523 | 573 | /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 524 | - ? sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) | |
| 574 | + ? sprintf( __( 'The %1$s sharing service has shut down or discontinued support for sharing buttons. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) | |
| 525 | 575 | : $this->get_name() |
| 526 | 576 | ), |
| 527 | 577 | esc_html( |
| 528 | 578 | $is_deprecated |
| 529 | 579 | /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 530 | - ? sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ) | |
| 580 | + ? sprintf( __( '%1$s is no longer supported', 'jetpack' ), $this->get_name() ) | |
| 531 | 581 | : $text |
| 532 | 582 | ) |
| 533 | 583 | ); |
| 534 | 584 | |
| @@ -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 ) ) { |
| @@ -616,8 +666,9 @@ | ||
| 616 | 666 | /** |
| 617 | 667 | * Redirect to an external social network site to finish sharing. |
| 618 | 668 | * |
| 619 | 669 | * @param string $url Sharing URL for a given service. |
| 670 | + * @return never | |
| 620 | 671 | */ |
| 621 | 672 | public function redirect_request( $url ) { |
| 622 | 673 | wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We allow external redirects here; we define them ourselves. |
| 623 | 674 | |
| @@ -622,14 +673,26 @@ | ||
| 622 | 673 | wp_redirect( $url ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- We allow external redirects here; we define them ourselves. |
| 623 | 674 | |
| 624 | 675 | // We set up this custom header to indicate to search engines not to index this page. |
| 625 | 676 | header( 'X-Robots-Tag: noindex, nofollow' ); |
| 626 | - die(); | |
| 677 | + die( 0 ); | |
| 627 | 678 | } |
| 628 | 679 | |
| 629 | 680 | /** |
| 630 | - * Add extra JavaScript to a sharing service. | |
| 681 | + * Register a sharing service's popup window features with the front-end script. | |
| 631 | 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 | + * | |
| 632 | 695 | * @param string $name Sharing service name. |
| 633 | 696 | * @param array $params Array of sharing options. |
| 634 | 697 | * |
| 635 | 698 | * @return void |
| @@ -654,41 +717,13 @@ | ||
| 654 | 717 | |
| 655 | 718 | // Add JS after sharing-js has been enqueued. |
| 656 | 719 | wp_add_inline_script( |
| 657 | 720 | 'sharing-js', |
| 658 | - "var windowOpen; | |
| 659 | - ( function () { | |
| 660 | - function matches( el, sel ) { | |
| 661 | - return !! ( | |
| 662 | - el.matches && el.matches( sel ) || | |
| 663 | - el.msMatchesSelector && el.msMatchesSelector( sel ) | |
| 664 | - ); | |
| 665 | - } | |
| 666 | - | |
| 667 | - document.body.addEventListener( 'click', function ( event ) { | |
| 668 | - if ( ! event.target ) { | |
| 669 | - return; | |
| 670 | - } | |
| 671 | - | |
| 672 | - var el; | |
| 673 | - if ( matches( event.target, 'a.share-$name' ) ) { | |
| 674 | - el = event.target; | |
| 675 | - } else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-$name' ) ) { | |
| 676 | - el = event.target.parentNode; | |
| 677 | - } | |
| 678 | - | |
| 679 | - if ( el ) { | |
| 680 | - event.preventDefault(); | |
| 681 | - | |
| 682 | - // If there's another sharing window open, close it. | |
| 683 | - if ( typeof windowOpen !== 'undefined' ) { | |
| 684 | - windowOpen.close(); | |
| 685 | - } | |
| 686 | - windowOpen = window.open( el.getAttribute( 'href' ), 'wpcom$name', '$opts' ); | |
| 687 | - return false; | |
| 688 | - } | |
| 689 | - } ); | |
| 690 | - } )();" | |
| 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 | + ) | |
| 691 | 726 | ); |
| 692 | 727 | } |
| 693 | 728 | } |
| 694 | 729 | |
| @@ -844,11 +879,11 @@ | ||
| 844 | 879 | public function display_deprecated( $post ) { |
| 845 | 880 | return $this->get_link( |
| 846 | 881 | $this->get_share_url( $post->ID ), |
| 847 | 882 | /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 848 | - sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ), | |
| 883 | + sprintf( __( '%1$s is no longer supported', 'jetpack' ), $this->get_name() ), | |
| 849 | 884 | /* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 850 | - sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) | |
| 885 | + sprintf( __( 'The %1$s sharing service has shut down or discontinued support for sharing buttons. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) | |
| 851 | 886 | ); |
| 852 | 887 | } |
| 853 | 888 | } |
| 854 | 889 | |
| @@ -950,9 +985,9 @@ | ||
| 950 | 985 | * |
| 951 | 986 | * @param WP_Post $post Post object. |
| 952 | 987 | * @param array $post_data Array of information about the post we're sharing. |
| 953 | 988 | * |
| 954 | - * @return void | |
| 989 | + * @return never | |
| 955 | 990 | */ |
| 956 | 991 | public function process_request( $post, array $post_data ) { |
| 957 | 992 | $is_ajax = false; |
| 958 | 993 | if ( |
| @@ -972,15 +1007,14 @@ | ||
| 972 | 1007 | parent::process_request( $post, $post_data ); |
| 973 | 1008 | } |
| 974 | 1009 | |
| 975 | 1010 | if ( $is_ajax ) { |
| 976 | - 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 ); | |
| 977 | 1013 | } else { |
| 978 | 1014 | wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' ); |
| 979 | - exit; | |
| 1015 | + exit( 0 ); | |
| 980 | 1016 | } |
| 981 | - | |
| 982 | - wp_die(); | |
| 983 | 1017 | } |
| 984 | 1018 | |
| 985 | 1019 | /** |
| 986 | 1020 | * Get the markup of the sharing button. |
| @@ -1005,8 +1039,9 @@ | ||
| 1005 | 1039 | 'jetpack' |
| 1006 | 1040 | ), |
| 1007 | 1041 | 'email-share-nonce' => wp_create_nonce( $this->get_email_share_nonce_action( $post ) ), |
| 1008 | 1042 | 'email-share-track-url' => $tracking_url, |
| 1043 | + 'aria-labelledby' => 'sharing-email-' . $post->ID, | |
| 1009 | 1044 | ); |
| 1010 | 1045 | |
| 1011 | 1046 | $post_title = $this->get_share_title( $post->ID ); |
| 1012 | 1047 | $post_url = $this->get_share_url( $post->ID ); |
| @@ -1025,9 +1060,9 @@ | ||
| 1025 | 1060 | |
| 1026 | 1061 | return $this->get_link( |
| 1027 | 1062 | 'mailto:', |
| 1028 | 1063 | _x( 'Email', 'share to', 'jetpack' ), |
| 1029 | - __( 'Click to email a link to a friend', 'jetpack' ), | |
| 1064 | + __( 'Email a link to a friend', 'jetpack' ), | |
| 1030 | 1065 | $mailto_query, |
| 1031 | 1066 | false, |
| 1032 | 1067 | $data_attributes |
| 1033 | 1068 | ); |
| @@ -1048,9 +1083,10 @@ | ||
| 1048 | 1083 | } |
| 1049 | 1084 | } |
| 1050 | 1085 | |
| 1051 | 1086 | /** |
| 1052 | - * Twitter sharing button. | |
| 1087 | + * Legacy Twitter sharing button. | |
| 1088 | + * Share_X is the new Twitter sharing button. | |
| 1053 | 1089 | */ |
| 1054 | 1090 | class Share_Twitter extends Sharing_Source { |
| 1055 | 1091 | /** |
| 1056 | 1092 | * Service short name. |
| @@ -1063,9 +1099,9 @@ | ||
| 1063 | 1099 | * Service icon font code. |
| 1064 | 1100 | * |
| 1065 | 1101 | * @var string |
| 1066 | 1102 | */ |
| 1067 | - public $icon = '\f202'; | |
| 1103 | + public $icon = '\f10e'; | |
| 1068 | 1104 | |
| 1069 | 1105 | /** |
| 1070 | 1106 | * Length of a URL on Twitter. |
| 1071 | 1107 | * 'https://dev.twitter.com/rest/reference/get/help/configuration' |
| @@ -1096,9 +1132,9 @@ | ||
| 1096 | 1132 | * |
| 1097 | 1133 | * @return string |
| 1098 | 1134 | */ |
| 1099 | 1135 | public function get_name() { |
| 1100 | - return __( 'Twitter', 'jetpack' ); | |
| 1136 | + return __( 'X', 'jetpack' ); | |
| 1101 | 1137 | } |
| 1102 | 1138 | |
| 1103 | 1139 | /** |
| 1104 | 1140 | * Determine the Twitter 'via' value for a post. |
| @@ -1235,9 +1271,9 @@ | ||
| 1235 | 1271 | apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' ) |
| 1236 | 1272 | ) { |
| 1237 | 1273 | sharing_register_post_for_share_counts( $post->ID ); |
| 1238 | 1274 | } |
| 1239 | - 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 ); | |
| 1240 | 1276 | } |
| 1241 | 1277 | } |
| 1242 | 1278 | |
| 1243 | 1279 | /** |
| @@ -1287,9 +1323,9 @@ | ||
| 1287 | 1323 | |
| 1288 | 1324 | $url = $post_link; |
| 1289 | 1325 | $twitter_url = add_query_arg( |
| 1290 | 1326 | rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ), |
| 1291 | - 'https://twitter.com/intent/tweet' | |
| 1327 | + 'https://x.com/intent/tweet' | |
| 1292 | 1328 | ); |
| 1293 | 1329 | |
| 1294 | 1330 | parent::redirect_request( $twitter_url ); |
| 1295 | 1331 | } |
| @@ -1317,17 +1353,20 @@ | ||
| 1317 | 1353 | } |
| 1318 | 1354 | } |
| 1319 | 1355 | |
| 1320 | 1356 | /** |
| 1321 | - * Reddit sharing button. | |
| 1357 | + * X sharing button. | |
| 1358 | + * | |
| 1359 | + * While the old Twitter button had an official button, | |
| 1360 | + * this new X button does not, since there is no official X button yet. | |
| 1322 | 1361 | */ |
| 1323 | -class Share_Reddit extends Sharing_Source { | |
| 1362 | +class Share_X extends Sharing_Source { | |
| 1324 | 1363 | /** |
| 1325 | 1364 | * Service short name. |
| 1326 | 1365 | * |
| 1327 | 1366 | * @var string |
| 1328 | 1367 | */ |
| 1329 | - public $shortname = 'reddit'; | |
| 1368 | + public $shortname = 'x'; | |
| 1330 | 1369 | |
| 1331 | 1370 | /** |
| 1332 | 1371 | * Service icon font code. |
| 1333 | 1372 | * |
| @@ -1332,11 +1371,19 @@ | ||
| 1332 | 1371 | * Service icon font code. |
| 1333 | 1372 | * |
| 1334 | 1373 | * @var string |
| 1335 | 1374 | */ |
| 1336 | - public $icon = '\f222'; | |
| 1375 | + public $icon = '\f10e'; | |
| 1337 | 1376 | |
| 1338 | 1377 | /** |
| 1378 | + * Length of a URL on X. | |
| 1379 | + * https://developer.twitter.com/en/docs/tco | |
| 1380 | + * | |
| 1381 | + * @var int | |
| 1382 | + */ | |
| 1383 | + public $short_url_length = 24; | |
| 1384 | + | |
| 1385 | + /** | |
| 1339 | 1386 | * Constructor. |
| 1340 | 1387 | * |
| 1341 | 1388 | * @param int $id Sharing source ID. |
| 1342 | 1389 | * @param array $settings Sharing settings. |
| @@ -1356,9 +1403,9 @@ | ||
| 1356 | 1403 | * |
| 1357 | 1404 | * @return string |
| 1358 | 1405 | */ |
| 1359 | 1406 | public function get_name() { |
| 1360 | - return __( 'Reddit', 'jetpack' ); | |
| 1407 | + return __( 'X', 'jetpack' ); | |
| 1361 | 1408 | } |
| 1362 | 1409 | |
| 1363 | 1410 | /** |
| 1364 | 1411 | * Get the markup of the sharing button. |
| @@ -1367,16 +1414,232 @@ | ||
| 1367 | 1414 | * |
| 1368 | 1415 | * @return string |
| 1369 | 1416 | */ |
| 1370 | 1417 | public function get_display( $post ) { |
| 1418 | + $via = static::sharing_x_via( $post ); | |
| 1419 | + | |
| 1420 | + if ( $via ) { | |
| 1421 | + $via = 'data-via="' . esc_attr( $via ) . '"'; | |
| 1422 | + } else { | |
| 1423 | + $via = ''; | |
| 1424 | + } | |
| 1425 | + | |
| 1426 | + $related = static::get_related_accounts( $post ); | |
| 1427 | + if ( ! empty( $related ) && $related !== $via ) { | |
| 1428 | + $related = 'data-related="' . esc_attr( $related ) . '"'; | |
| 1429 | + } else { | |
| 1430 | + $related = ''; | |
| 1431 | + } | |
| 1432 | + | |
| 1371 | 1433 | if ( $this->smart ) { |
| 1372 | - return '<div class="reddit_button"><iframe src="' . $this->http() . '://www.reddit.com/static/button/button1.html?newwindow=true&width=120&url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>'; | |
| 1434 | + $share_url = $this->get_share_url( $post->ID ); | |
| 1435 | + $post_title = $this->get_share_title( $post->ID ); | |
| 1436 | + return sprintf( | |
| 1437 | + '<a href="https://x.com/share" class="twitter-share-button" data-url="%1$s" data-text="%2$s" %3$s %4$s>%5$s</a>', | |
| 1438 | + esc_url( $share_url ), | |
| 1439 | + esc_attr( $post_title ), | |
| 1440 | + $via, | |
| 1441 | + $related, | |
| 1442 | + esc_html__( 'Post', 'jetpack' ) | |
| 1443 | + ); | |
| 1373 | 1444 | } else { |
| 1374 | - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' ); | |
| 1445 | + if ( | |
| 1446 | + /** This filter is documented in modules/sharedaddy/sharing-sources.php */ | |
| 1447 | + apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'x' ) | |
| 1448 | + ) { | |
| 1449 | + sharing_register_post_for_share_counts( $post->ID ); | |
| 1450 | + } | |
| 1451 | + return $this->get_link( | |
| 1452 | + $this->get_process_request_url( $post->ID ), | |
| 1453 | + _x( 'X', 'share to', 'jetpack' ), | |
| 1454 | + __( 'Share on X', 'jetpack' ), | |
| 1455 | + 'share=x', | |
| 1456 | + 'sharing-x-' . $post->ID | |
| 1457 | + ); | |
| 1375 | 1458 | } |
| 1376 | 1459 | } |
| 1377 | 1460 | |
| 1378 | 1461 | /** |
| 1462 | + * Determine the X 'via' value for a post. | |
| 1463 | + * | |
| 1464 | + * @param WP_Post|int $post Post object or post ID. | |
| 1465 | + * @return string X handle without the preceding @. | |
| 1466 | + **/ | |
| 1467 | + public static function sharing_x_via( $post ) { | |
| 1468 | + $post = get_post( $post ); | |
| 1469 | + /** This filter is documented in modules/sharedaddy/sharing-sources.php */ | |
| 1470 | + $twitter_site_tag_value = apply_filters( | |
| 1471 | + 'jetpack_twitter_cards_site_tag', | |
| 1472 | + '', | |
| 1473 | + /** This action is documented in modules/sharedaddy/sharing-sources.php */ | |
| 1474 | + array( 'twitter:creator' => apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ) ) | |
| 1475 | + ); | |
| 1476 | + | |
| 1477 | + /* | |
| 1478 | + * Hack to remove the unwanted behavior of adding 'via @jetpack' which | |
| 1479 | + * was introduced with the adding of the Twitter cards. | |
| 1480 | + * This should be a temporary solution until a better method is setup. | |
| 1481 | + */ | |
| 1482 | + if ( 'jetpack' === $twitter_site_tag_value ) { | |
| 1483 | + $twitter_site_tag_value = ''; | |
| 1484 | + } | |
| 1485 | + | |
| 1486 | + /** This filter is documented in modules/sharedaddy/sharing-sources.php */ | |
| 1487 | + $twitter_site_tag_value = apply_filters( 'jetpack_sharing_twitter_via', $twitter_site_tag_value, $post->ID ); | |
| 1488 | + | |
| 1489 | + // Strip out anything other than a letter, number, or underscore. | |
| 1490 | + // This will prevent the inadvertent inclusion of an extra @, as well as normalizing the handle. | |
| 1491 | + return preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value ); | |
| 1492 | + } | |
| 1493 | + | |
| 1494 | + /** | |
| 1495 | + * Determine the 'related' X accounts for a post. | |
| 1496 | + * | |
| 1497 | + * @param WP_Post|int $post Post object or post ID. | |
| 1498 | + * @return string Comma-separated list of X handles. | |
| 1499 | + **/ | |
| 1500 | + public static function get_related_accounts( $post ) { | |
| 1501 | + $post = get_post( $post ); | |
| 1502 | + /** This filter is documented in modules/sharedaddy/sharing-sources.php */ | |
| 1503 | + $related_accounts = apply_filters( 'jetpack_sharing_twitter_related', array(), $post->ID ); | |
| 1504 | + | |
| 1505 | + // Example related string: account1,account2:Account 2 description,account3 | |
| 1506 | + $related = array(); | |
| 1507 | + | |
| 1508 | + foreach ( $related_accounts as $related_account_username => $related_account_description ) { | |
| 1509 | + // Join the description onto the end of the username | |
| 1510 | + if ( $related_account_description ) { | |
| 1511 | + $related_account_username .= ':' . $related_account_description; | |
| 1512 | + } | |
| 1513 | + | |
| 1514 | + $related[] = $related_account_username; | |
| 1515 | + } | |
| 1516 | + | |
| 1517 | + return implode( ',', $related ); | |
| 1518 | + } | |
| 1519 | + | |
| 1520 | + /** | |
| 1521 | + * Add content specific to a service in the footer. | |
| 1522 | + */ | |
| 1523 | + public function display_footer() { | |
| 1524 | + if ( $this->smart ) { | |
| 1525 | + ?> | |
| 1526 | + <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script> | |
| 1527 | + <?php | |
| 1528 | + } else { | |
| 1529 | + $this->js_dialog( $this->shortname, array( 'height' => 350 ) ); | |
| 1530 | + } | |
| 1531 | + } | |
| 1532 | + | |
| 1533 | + /** | |
| 1534 | + * Process sharing request. Add actions that need to happen when sharing here. | |
| 1535 | + * | |
| 1536 | + * @param WP_Post $post Post object. | |
| 1537 | + * @param array $post_data Array of information about the post we're sharing. | |
| 1538 | + * | |
| 1539 | + * @return void | |
| 1540 | + */ | |
| 1541 | + public function process_request( $post, array $post_data ) { | |
| 1542 | + $post_title = $this->get_share_title( $post->ID ); | |
| 1543 | + $post_link = $this->get_share_url( $post->ID ); | |
| 1544 | + | |
| 1545 | + if ( function_exists( 'mb_stripos' ) ) { | |
| 1546 | + $strlen = 'mb_strlen'; | |
| 1547 | + $substr = 'mb_substr'; | |
| 1548 | + } else { | |
| 1549 | + $strlen = 'strlen'; | |
| 1550 | + $substr = 'substr'; | |
| 1551 | + } | |
| 1552 | + | |
| 1553 | + $via = static::sharing_x_via( $post ); | |
| 1554 | + $related = static::get_related_accounts( $post ); | |
| 1555 | + if ( $via ) { | |
| 1556 | + $sig = " via @$via"; | |
| 1557 | + if ( $related === $via ) { | |
| 1558 | + $related = false; | |
| 1559 | + } | |
| 1560 | + } else { | |
| 1561 | + $via = false; | |
| 1562 | + $sig = ''; | |
| 1563 | + } | |
| 1564 | + | |
| 1565 | + $suffix_length = $this->short_url_length + $strlen( $sig ); | |
| 1566 | + // $sig is handled by twitter in their 'via' argument. | |
| 1567 | + // $post_link is handled by twitter in their 'url' argument. | |
| 1568 | + if ( 280 < $strlen( $post_title ) + $suffix_length ) { | |
| 1569 | + // The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis. | |
| 1570 | + $text = $substr( $post_title, 0, 280 - $suffix_length - 1 ) . "\xE2\x80\xA6"; | |
| 1571 | + } else { | |
| 1572 | + $text = $post_title; | |
| 1573 | + } | |
| 1574 | + | |
| 1575 | + // Record stats | |
| 1576 | + parent::process_request( $post, $post_data ); | |
| 1577 | + | |
| 1578 | + $url = $post_link; | |
| 1579 | + $twitter_url = add_query_arg( | |
| 1580 | + rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ), | |
| 1581 | + 'https://x.com/intent/tweet' | |
| 1582 | + ); | |
| 1583 | + | |
| 1584 | + parent::redirect_request( $twitter_url ); | |
| 1585 | + } | |
| 1586 | + | |
| 1587 | + /** | |
| 1588 | + * Does this sharing source have a custom style. | |
| 1589 | + * | |
| 1590 | + * @return bool | |
| 1591 | + */ | |
| 1592 | + public function has_custom_button_style() { | |
| 1593 | + return $this->smart; | |
| 1594 | + } | |
| 1595 | +} | |
| 1596 | + | |
| 1597 | +/** | |
| 1598 | + * Reddit sharing button. | |
| 1599 | + */ | |
| 1600 | +class Share_Reddit extends Sharing_Source { | |
| 1601 | + /** | |
| 1602 | + * Service short name. | |
| 1603 | + * | |
| 1604 | + * @var string | |
| 1605 | + */ | |
| 1606 | + public $shortname = 'reddit'; | |
| 1607 | + | |
| 1608 | + /** | |
| 1609 | + * Service icon font code. | |
| 1610 | + * | |
| 1611 | + * @var string | |
| 1612 | + */ | |
| 1613 | + public $icon = '\f222'; | |
| 1614 | + | |
| 1615 | + /** | |
| 1616 | + * Service name. | |
| 1617 | + * | |
| 1618 | + * @return string | |
| 1619 | + */ | |
| 1620 | + public function get_name() { | |
| 1621 | + return __( 'Reddit', 'jetpack' ); | |
| 1622 | + } | |
| 1623 | + | |
| 1624 | + /** | |
| 1625 | + * Get the markup of the sharing button. | |
| 1626 | + * | |
| 1627 | + * @param WP_Post $post Post object. | |
| 1628 | + * | |
| 1629 | + * @return string | |
| 1630 | + */ | |
| 1631 | + public function get_display( $post ) { | |
| 1632 | + return $this->get_link( | |
| 1633 | + $this->get_process_request_url( $post->ID ), | |
| 1634 | + _x( 'Reddit', 'share to', 'jetpack' ), | |
| 1635 | + __( 'Share on Reddit', 'jetpack' ), | |
| 1636 | + 'share=reddit', | |
| 1637 | + 'sharing-reddit-' . $post->ID | |
| 1638 | + ); | |
| 1639 | + } | |
| 1640 | + | |
| 1641 | + /** | |
| 1379 | 1642 | * AMP display for Reddit. |
| 1380 | 1643 | * |
| 1381 | 1644 | * @param \WP_Post $post The current post being viewed. |
| 1382 | 1645 | */ |
| @@ -1471,9 +1734,9 @@ | ||
| 1471 | 1734 | if ( $this->smart ) { |
| 1472 | 1735 | $share_url = $this->get_share_url( $post->ID ); |
| 1473 | 1736 | $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) ); |
| 1474 | 1737 | } else { |
| 1475 | - $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 ); | |
| 1476 | 1739 | } |
| 1477 | 1740 | |
| 1478 | 1741 | /** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 1479 | 1742 | if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
| @@ -1494,15 +1757,13 @@ | ||
| 1494 | 1757 | public function process_request( $post, array $post_data ) { |
| 1495 | 1758 | |
| 1496 | 1759 | $post_link = $this->get_share_url( $post->ID ); |
| 1497 | 1760 | |
| 1498 | - // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link | |
| 1499 | - // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false | |
| 1500 | 1761 | $linkedin_url = add_query_arg( |
| 1501 | 1762 | array( |
| 1502 | 1763 | 'url' => rawurlencode( $post_link ), |
| 1503 | 1764 | ), |
| 1504 | - 'https://www.linkedin.com/cws/share?token=&isFramed=false' | |
| 1765 | + 'https://www.linkedin.com/sharing/share-offsite/' | |
| 1505 | 1766 | ); |
| 1506 | 1767 | |
| 1507 | 1768 | // Record stats |
| 1508 | 1769 | parent::process_request( $post, $post_data ); |
| @@ -1698,9 +1959,9 @@ | ||
| 1698 | 1959 | /** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 1699 | 1960 | if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) { |
| 1700 | 1961 | sharing_register_post_for_share_counts( $post->ID ); |
| 1701 | 1962 | } |
| 1702 | - 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 ); | |
| 1703 | 1964 | } |
| 1704 | 1965 | |
| 1705 | 1966 | /** |
| 1706 | 1967 | * AMP display for Facebook. |
| @@ -1724,9 +1985,9 @@ | ||
| 1724 | 1985 | * |
| 1725 | 1986 | * @return void |
| 1726 | 1987 | */ |
| 1727 | 1988 | public function process_request( $post, array $post_data ) { |
| 1728 | - $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 ) ); | |
| 1729 | 1990 | |
| 1730 | 1991 | // Record stats |
| 1731 | 1992 | parent::process_request( $post, $post_data ); |
| 1732 | 1993 | |
| @@ -1821,9 +2082,9 @@ | ||
| 1821 | 2082 | * |
| 1822 | 2083 | * @return string |
| 1823 | 2084 | */ |
| 1824 | 2085 | public function get_display( $post ) { |
| 1825 | - 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 ); | |
| 1826 | 2087 | } |
| 1827 | 2088 | |
| 1828 | 2089 | /** |
| 1829 | 2090 | * AMP display for Print. |
| @@ -1912,9 +2173,9 @@ | ||
| 1912 | 2173 | } |
| 1913 | 2174 | |
| 1914 | 2175 | if ( empty( $blogs ) ) { |
| 1915 | 2176 | wp_safe_redirect( get_permalink( $post->ID ) ); |
| 1916 | - die(); | |
| 2177 | + die( 0 ); | |
| 1917 | 2178 | } |
| 1918 | 2179 | |
| 1919 | 2180 | $blog = current( $blogs ); |
| 1920 | 2181 | |
| @@ -1941,9 +2202,9 @@ | ||
| 1941 | 2202 | * |
| 1942 | 2203 | * @return string |
| 1943 | 2204 | */ |
| 1944 | 2205 | public function get_display( $post ) { |
| 1945 | - 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 ); | |
| 1946 | 2207 | } |
| 1947 | 2208 | |
| 1948 | 2209 | /** |
| 1949 | 2210 | * No AMP display for PressThis. |
| @@ -2060,14 +2321,18 @@ | ||
| 2060 | 2321 | $this->get_process_request_url( $post->ID ), |
| 2061 | 2322 | esc_html( $this->name ), |
| 2062 | 2323 | sprintf( |
| 2063 | 2324 | /* Translators: placeholder is the name of a social network. */ |
| 2064 | - __( 'Click to share on %s', 'jetpack' ), | |
| 2325 | + __( 'Share on %s', 'jetpack' ), | |
| 2065 | 2326 | esc_attr( $this->name ) |
| 2066 | 2327 | ), |
| 2067 | - 'share=' . $this->id | |
| 2328 | + 'share=' . $this->id, | |
| 2329 | + 'sharing-custom-' . $post->ID | |
| 2068 | 2330 | ); |
| 2069 | - 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 ); | |
| 2070 | 2335 | } |
| 2071 | 2336 | |
| 2072 | 2337 | /** |
| 2073 | 2338 | * No AMP display for custom elements. |
| @@ -2087,9 +2352,9 @@ | ||
| 2087 | 2352 | * @return void |
| 2088 | 2353 | */ |
| 2089 | 2354 | public function process_request( $post, array $post_data ) { |
| 2090 | 2355 | $url = str_replace( '&', '&', $this->url ); |
| 2091 | - $url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url ); | |
| 2356 | + $url = str_replace( '%post_id%', rawurlencode( (string) $post->ID ), $url ); | |
| 2092 | 2357 | $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url ); |
| 2093 | 2358 | $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url ); |
| 2094 | 2359 | $url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url ); |
| 2095 | 2360 | $url = str_replace( '%home_url%', rawurlencode( home_url() ), $url ); |
| @@ -2316,9 +2581,9 @@ | ||
| 2316 | 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. |
| 2317 | 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. |
| 2318 | 2583 | */ |
| 2319 | 2584 | if ( ! is_single() ) { |
| 2320 | - $posttype = 'data-posttype="link"'; | |
| 2585 | + $posttype = ' data-posttype="link"'; // Leading space separates it from the preceding title attribute. | |
| 2321 | 2586 | } else { |
| 2322 | 2587 | $posttype = ''; |
| 2323 | 2588 | } |
| 2324 | 2589 | |
| @@ -2323,18 +2588,19 @@ | ||
| 2323 | 2588 | } |
| 2324 | 2589 | |
| 2325 | 2590 | // Documentation: https://www.tumblr.com/docs/en/share_button |
| 2326 | 2591 | return sprintf( |
| 2327 | - '<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>', | |
| 2328 | 2593 | $target, |
| 2329 | 2594 | 'https://www.tumblr.com/share', |
| 2330 | - $this->get_share_title( $post->ID ), | |
| 2331 | - $this->get_share_url( $post->ID ), | |
| 2332 | - __( 'Share on Tumblr', 'jetpack' ), | |
| 2333 | - $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' ) | |
| 2334 | 2600 | ); |
| 2335 | 2601 | } else { |
| 2336 | - 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 ); | |
| 2337 | 2603 | } |
| 2338 | 2604 | } |
| 2339 | 2605 | |
| 2340 | 2606 | /** |
| @@ -2426,13 +2692,11 @@ | ||
| 2426 | 2692 | * |
| 2427 | 2693 | * @return string |
| 2428 | 2694 | */ |
| 2429 | 2695 | public function get_image( $post ) { |
| 2430 | - if ( class_exists( 'Jetpack_PostImages' ) ) { | |
| 2431 | - $image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) ); | |
| 2432 | - if ( ! empty( $image ) ) { | |
| 2433 | - return $image['src']; | |
| 2434 | - } | |
| 2696 | + $image = Images::get_image( $post->ID, array( 'fallback_to_avatars' => true ) ); | |
| 2697 | + if ( ! empty( $image ) ) { | |
| 2698 | + return $image['src']; | |
| 2435 | 2699 | } |
| 2436 | 2700 | |
| 2437 | 2701 | /** |
| 2438 | 2702 | * Filters the default image used by the Pinterest Pin It share button. |
| @@ -2453,9 +2717,9 @@ | ||
| 2453 | 2717 | * |
| 2454 | 2718 | * @return string |
| 2455 | 2719 | */ |
| 2456 | 2720 | public function get_external_url( $post ) { |
| 2457 | - $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 ); | |
| 2458 | 2722 | |
| 2459 | 2723 | /** |
| 2460 | 2724 | * Filters the Pinterest share URL used in sharing button output. |
| 2461 | 2725 | * |
| @@ -2504,9 +2768,9 @@ | ||
| 2504 | 2768 | esc_url( $this->get_external_url( $post ) ), |
| 2505 | 2769 | esc_attr( $this->get_widget_type() ) |
| 2506 | 2770 | ); |
| 2507 | 2771 | } else { |
| 2508 | - $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 ); | |
| 2509 | 2773 | } |
| 2510 | 2774 | |
| 2511 | 2775 | /** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 2512 | 2776 | if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
| @@ -2532,9 +2796,9 @@ | ||
| 2532 | 2796 | $pinterest_url = esc_url_raw( $this->get_external_url( $post ) ); |
| 2533 | 2797 | parent::redirect_request( $pinterest_url ); |
| 2534 | 2798 | } else { |
| 2535 | 2799 | echo '// share count bumped'; |
| 2536 | - die(); | |
| 2800 | + die( 0 ); | |
| 2537 | 2801 | } |
| 2538 | 2802 | } |
| 2539 | 2803 | |
| 2540 | 2804 | /** |
| @@ -2628,39 +2892,26 @@ | ||
| 2628 | 2892 | } |
| 2629 | 2893 | } |
| 2630 | 2894 | |
| 2631 | 2895 | /** |
| 2632 | - * Pocket sharing service. | |
| 2896 | + * Telegram sharing service. | |
| 2633 | 2897 | */ |
| 2634 | -class Share_Pocket extends Sharing_Source { | |
| 2898 | +class Share_Telegram extends Sharing_Source { | |
| 2635 | 2899 | /** |
| 2636 | 2900 | * Service short name. |
| 2637 | 2901 | * |
| 2638 | 2902 | * @var string |
| 2639 | 2903 | */ |
| 2640 | - public $shortname = 'pocket'; | |
| 2904 | + public $shortname = 'telegram'; | |
| 2641 | 2905 | |
| 2642 | 2906 | /** |
| 2643 | - * Service icon font code. | |
| 2644 | - * | |
| 2645 | - * @var string | |
| 2646 | - */ | |
| 2647 | - public $icon = '\f224'; | |
| 2648 | - | |
| 2649 | - /** | |
| 2650 | 2907 | * Constructor. |
| 2651 | 2908 | * |
| 2652 | 2909 | * @param int $id Sharing source ID. |
| 2653 | 2910 | * @param array $settings Sharing settings. |
| 2654 | 2911 | */ |
| 2655 | - public function __construct( $id, array $settings ) { | |
| 2912 | + public function __construct( $id, array $settings ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found | |
| 2656 | 2913 | parent::__construct( $id, $settings ); |
| 2657 | - | |
| 2658 | - if ( 'official' === $this->button_style ) { | |
| 2659 | - $this->smart = true; | |
| 2660 | - } else { | |
| 2661 | - $this->smart = false; | |
| 2662 | - } | |
| 2663 | 2914 | } |
| 2664 | 2915 | |
| 2665 | 2916 | /** |
| 2666 | 2917 | * Service name. |
| @@ -2667,9 +2918,9 @@ | ||
| 2667 | 2918 | * |
| 2668 | 2919 | * @return string |
| 2669 | 2920 | */ |
| 2670 | 2921 | public function get_name() { |
| 2671 | - return __( 'Pocket', 'jetpack' ); | |
| 2922 | + return __( 'Telegram', 'jetpack' ); | |
| 2672 | 2923 | } |
| 2673 | 2924 | |
| 2674 | 2925 | /** |
| 2675 | 2926 | * Process sharing request. Add actions that need to happen when sharing here. |
| @@ -2682,11 +2933,11 @@ | ||
| 2682 | 2933 | public function process_request( $post, array $post_data ) { |
| 2683 | 2934 | // Record stats |
| 2684 | 2935 | parent::process_request( $post, $post_data ); |
| 2685 | 2936 | |
| 2686 | - $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 ) ) ); | |
| 2937 | + $telegram_url = esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) ); | |
| 2687 | 2938 | |
| 2688 | - parent::redirect_request( $pocket_url ); | |
| 2939 | + parent::redirect_request( $telegram_url ); | |
| 2689 | 2940 | } |
| 2690 | 2941 | |
| 2691 | 2942 | /** |
| 2692 | 2943 | * Get the markup of the sharing button. |
| @@ -2695,30 +2946,19 @@ | ||
| 2695 | 2946 | * |
| 2696 | 2947 | * @return string |
| 2697 | 2948 | */ |
| 2698 | 2949 | public function get_display( $post ) { |
| 2699 | - if ( $this->smart ) { | |
| 2700 | - $post_count = 'horizontal'; | |
| 2701 | - | |
| 2702 | - $button = ''; | |
| 2703 | - $button .= '<div class="pocket_button">'; | |
| 2704 | - $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' ) ); | |
| 2705 | - $button .= '</div>'; | |
| 2706 | - | |
| 2707 | - return $button; | |
| 2708 | - } else { | |
| 2709 | - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' ); | |
| 2710 | - } | |
| 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 ); | |
| 2711 | 2951 | } |
| 2712 | 2952 | |
| 2713 | 2953 | /** |
| 2714 | - * AMP display for Pocket. | |
| 2954 | + * AMP display for Telegram. | |
| 2715 | 2955 | * |
| 2716 | 2956 | * @param \WP_Post $post The current post being viewed. |
| 2717 | 2957 | */ |
| 2718 | 2958 | public function get_amp_display( $post ) { |
| 2719 | 2959 | $attrs = array( |
| 2720 | - '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 ) ) ), | |
| 2960 | + 'data-share-endpoint' => esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) ), | |
| 2721 | 2961 | ); |
| 2722 | 2962 | |
| 2723 | 2963 | return $this->build_amp_markup( $attrs ); |
| 2724 | 2964 | } |
| @@ -2726,55 +2966,28 @@ | ||
| 2726 | 2966 | /** |
| 2727 | 2967 | * Add content specific to a service in the footer. |
| 2728 | 2968 | */ |
| 2729 | 2969 | public function display_footer() { |
| 2730 | - if ( $this->smart ) : | |
| 2731 | - ?> | |
| 2732 | - <script> | |
| 2733 | - ( function () { | |
| 2734 | - var currentScript = document.currentScript; | |
| 2735 | - | |
| 2736 | - // Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS. | |
| 2737 | - function jetpack_sharing_pocket_init() { | |
| 2738 | - var script = document.createElement( 'script' ); | |
| 2739 | - var prev = currentScript || document.getElementsByTagName( 'script' )[ 0 ]; | |
| 2740 | - script.setAttribute( 'async', true ); | |
| 2741 | - script.setAttribute( 'src', 'https://widgets.getpocket.com/v1/j/btn.js?v=1' ); | |
| 2742 | - prev.parentNode.insertBefore( script, prev ); | |
| 2743 | - } | |
| 2744 | - | |
| 2745 | - if ( document.readyState === 'loading' ) { | |
| 2746 | - document.addEventListener( 'DOMContentLoaded', jetpack_sharing_pocket_init ); | |
| 2747 | - } else { | |
| 2748 | - jetpack_sharing_pocket_init(); | |
| 2749 | - } | |
| 2750 | - document.body.addEventListener( 'is.post-load', jetpack_sharing_pocket_init ); | |
| 2751 | - } )(); | |
| 2752 | - </script> | |
| 2753 | - <?php | |
| 2754 | - else : | |
| 2755 | - $this->js_dialog( | |
| 2756 | - $this->shortname, | |
| 2757 | - array( | |
| 2758 | - 'width' => 450, | |
| 2759 | - 'height' => 450, | |
| 2760 | - ) | |
| 2761 | - ); | |
| 2762 | - endif; | |
| 2970 | + $this->js_dialog( | |
| 2971 | + $this->shortname, | |
| 2972 | + array( | |
| 2973 | + 'width' => 450, | |
| 2974 | + 'height' => 450, | |
| 2975 | + ) | |
| 2976 | + ); | |
| 2763 | 2977 | } |
| 2764 | - | |
| 2765 | 2978 | } |
| 2766 | 2979 | |
| 2767 | 2980 | /** |
| 2768 | - * Telegram sharing service. | |
| 2981 | + * WhatsApp sharing service. | |
| 2769 | 2982 | */ |
| 2770 | -class Share_Telegram extends Sharing_Source { | |
| 2983 | +class Jetpack_Share_WhatsApp extends Sharing_Source { | |
| 2771 | 2984 | /** |
| 2772 | 2985 | * Service short name. |
| 2773 | 2986 | * |
| 2774 | 2987 | * @var string |
| 2775 | 2988 | */ |
| 2776 | - public $shortname = 'telegram'; | |
| 2989 | + public $shortname = 'jetpack-whatsapp'; | |
| 2777 | 2990 | |
| 2778 | 2991 | /** |
| 2779 | 2992 | * Constructor. |
| 2780 | 2993 | * |
| @@ -2790,12 +3003,36 @@ | ||
| 2790 | 3003 | * |
| 2791 | 3004 | * @return string |
| 2792 | 3005 | */ |
| 2793 | 3006 | public function get_name() { |
| 2794 | - return __( 'Telegram', 'jetpack' ); | |
| 3007 | + return __( 'WhatsApp', 'jetpack' ); | |
| 2795 | 3008 | } |
| 2796 | 3009 | |
| 2797 | 3010 | /** |
| 3011 | + * Get the markup of the sharing button. | |
| 3012 | + * | |
| 3013 | + * @param WP_Post $post Post object. | |
| 3014 | + * | |
| 3015 | + * @return string | |
| 3016 | + */ | |
| 3017 | + public function get_display( $post ) { | |
| 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 ); | |
| 3019 | + } | |
| 3020 | + | |
| 3021 | + /** | |
| 3022 | + * AMP display for Whatsapp. | |
| 3023 | + * | |
| 3024 | + * @param \WP_Post $post The current post being viewed. | |
| 3025 | + */ | |
| 3026 | + public function get_amp_display( $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 3027 | + $attrs = array( | |
| 3028 | + 'type' => 'whatsapp', | |
| 3029 | + ); | |
| 3030 | + | |
| 3031 | + return $this->build_amp_markup( $attrs ); | |
| 3032 | + } | |
| 3033 | + | |
| 3034 | + /** | |
| 2798 | 3035 | * Process sharing request. Add actions that need to happen when sharing here. |
| 2799 | 3036 | * |
| 2800 | 3037 | * @param WP_Post $post Post object. |
| 2801 | 3038 | * @param array $post_data Array of information about the post we're sharing. |
| @@ -2805,14 +3042,49 @@ | ||
| 2805 | 3042 | public function process_request( $post, array $post_data ) { |
| 2806 | 3043 | // Record stats |
| 2807 | 3044 | parent::process_request( $post, $post_data ); |
| 2808 | 3045 | |
| 2809 | - $telegram_url = esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) ); | |
| 3046 | + // Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com" | |
| 3047 | + if ( User_Agent_Info::is_firefox_desktop() ) { | |
| 3048 | + $url = 'https://web.whatsapp.com/send?text='; | |
| 3049 | + } else { | |
| 3050 | + $url = 'https://api.whatsapp.com/send?text='; | |
| 3051 | + } | |
| 2810 | 3052 | |
| 2811 | - parent::redirect_request( $telegram_url ); | |
| 3053 | + $url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); | |
| 3054 | + | |
| 3055 | + parent::redirect_request( $url ); | |
| 2812 | 3056 | } |
| 3057 | +} | |
| 2813 | 3058 | |
| 3059 | +/** | |
| 3060 | + * Mastodon sharing service. | |
| 3061 | + */ | |
| 3062 | +class Share_Mastodon extends Sharing_Source { | |
| 2814 | 3063 | /** |
| 3064 | + * Service short name. | |
| 3065 | + * | |
| 3066 | + * @var string | |
| 3067 | + */ | |
| 3068 | + public $shortname = 'mastodon'; | |
| 3069 | + | |
| 3070 | + /** | |
| 3071 | + * Service icon font code. | |
| 3072 | + * | |
| 3073 | + * @var string | |
| 3074 | + */ | |
| 3075 | + public $icon = '\f10a'; | |
| 3076 | + | |
| 3077 | + /** | |
| 3078 | + * Service name. | |
| 3079 | + * | |
| 3080 | + * @return string | |
| 3081 | + */ | |
| 3082 | + public function get_name() { | |
| 3083 | + return __( 'Mastodon', 'jetpack' ); | |
| 3084 | + } | |
| 3085 | + | |
| 3086 | + /** | |
| 2815 | 3087 | * Get the markup of the sharing button. |
| 2816 | 3088 | * |
| 2817 | 3089 | * @param WP_Post $post Post object. |
| 2818 | 3090 | * |
| @@ -2818,22 +3090,69 @@ | ||
| 2818 | 3090 | * |
| 2819 | 3091 | * @return string |
| 2820 | 3092 | */ |
| 2821 | 3093 | public function get_display( $post ) { |
| 2822 | - return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' ); | |
| 3094 | + return $this->get_link( | |
| 3095 | + $this->get_process_request_url( $post->ID ), | |
| 3096 | + _x( 'Mastodon', 'share to', 'jetpack' ), | |
| 3097 | + __( 'Share on Mastodon', 'jetpack' ), | |
| 3098 | + 'share=mastodon', | |
| 3099 | + 'sharing-mastodon-' . $post->ID | |
| 3100 | + ); | |
| 2823 | 3101 | } |
| 2824 | 3102 | |
| 2825 | 3103 | /** |
| 2826 | - * AMP display for Telegram. | |
| 3104 | + * Process sharing request. Add actions that need to happen when sharing here. | |
| 2827 | 3105 | * |
| 2828 | - * @param \WP_Post $post The current post being viewed. | |
| 3106 | + * @param WP_Post $post Post object. | |
| 3107 | + * @param array $post_data Array of information about the post we're sharing. | |
| 3108 | + * | |
| 3109 | + * @return void | |
| 2829 | 3110 | */ |
| 2830 | - public function get_amp_display( $post ) { | |
| 2831 | - $attrs = array( | |
| 2832 | - 'data-share-endpoint' => esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) ), | |
| 3111 | + public function process_request( $post, array $post_data ) { | |
| 3112 | + if ( empty( $_POST['jetpack-mastodon-instance'] ) ) { | |
| 3113 | + require_once WP_SHARING_PLUGIN_DIR . 'services/class-jetpack-mastodon-modal.php'; | |
| 3114 | + add_action( 'template_redirect', array( 'Jetpack_Mastodon_Modal', 'modal' ) ); | |
| 3115 | + return; | |
| 3116 | + } | |
| 3117 | + | |
| 3118 | + check_admin_referer( 'jetpack_share_mastodon_instance' ); | |
| 3119 | + | |
| 3120 | + $mastodon_instance = isset( $_POST['jetpack-mastodon-instance'] ) | |
| 3121 | + ? trailingslashit( sanitize_text_field( wp_unslash( $_POST['jetpack-mastodon-instance'] ) ) ) | |
| 3122 | + : null; | |
| 3123 | + | |
| 3124 | + $post_title = $this->get_share_title( $post->ID ); | |
| 3125 | + $post_link = $this->get_share_url( $post->ID ); | |
| 3126 | + $post_tags = $this->get_share_tags( $post->ID ); | |
| 3127 | + | |
| 3128 | + /** | |
| 3129 | + * Allow filtering the default message that gets posted to Mastodon. | |
| 3130 | + * | |
| 3131 | + * @module sharedaddy | |
| 3132 | + * @since 11.9 | |
| 3133 | + * | |
| 3134 | + * @param string $share_url The default message that gets posted to Mastodon. | |
| 3135 | + * @param WP_Post $post The post object. | |
| 3136 | + * @param array $post_data Array of information about the post we're sharing. | |
| 3137 | + */ | |
| 3138 | + $shared_message = apply_filters( | |
| 3139 | + 'jetpack_sharing_mastodon_default_message', | |
| 3140 | + $post_title . ' ' . $post_link . ' ' . $post_tags, | |
| 3141 | + $post, | |
| 3142 | + $post_data | |
| 2833 | 3143 | ); |
| 2834 | 3144 | |
| 2835 | - return $this->build_amp_markup( $attrs ); | |
| 3145 | + $share_url = sprintf( | |
| 3146 | + '%1$sshare?text=%2$s', | |
| 3147 | + $mastodon_instance, | |
| 3148 | + rawurlencode( $shared_message ) | |
| 3149 | + ); | |
| 3150 | + | |
| 3151 | + // Record stats | |
| 3152 | + parent::process_request( $post, $post_data ); | |
| 3153 | + | |
| 3154 | + parent::redirect_request( $share_url ); | |
| 2836 | 3155 | } |
| 2837 | 3156 | |
| 2838 | 3157 | /** |
| 2839 | 3158 | * Add content specific to a service in the footer. |
| @@ -2841,10 +3160,10 @@ | ||
| 2841 | 3160 | public function display_footer() { |
| 2842 | 3161 | $this->js_dialog( |
| 2843 | 3162 | $this->shortname, |
| 2844 | 3163 | array( |
| 2845 | - 'width' => 450, | |
| 2846 | - 'height' => 450, | |
| 3164 | + 'width' => 460, | |
| 3165 | + 'height' => 400, | |
| 2847 | 3166 | ) |
| 2848 | 3167 | ); |
| 2849 | 3168 | } |
| 2850 | 3169 | } |
| @@ -2849,27 +3168,24 @@ | ||
| 2849 | 3168 | } |
| 2850 | 3169 | } |
| 2851 | 3170 | |
| 2852 | 3171 | /** |
| 2853 | - * WhatsApp sharing service. | |
| 3172 | + * Nextdoor sharing service. | |
| 2854 | 3173 | */ |
| 2855 | -class Jetpack_Share_WhatsApp extends Sharing_Source { | |
| 3174 | +class Share_Nextdoor extends Sharing_Source { | |
| 2856 | 3175 | /** |
| 2857 | 3176 | * Service short name. |
| 2858 | 3177 | * |
| 2859 | 3178 | * @var string |
| 2860 | 3179 | */ |
| 2861 | - public $shortname = 'jetpack-whatsapp'; | |
| 3180 | + public $shortname = 'nextdoor'; | |
| 2862 | 3181 | |
| 2863 | 3182 | /** |
| 2864 | - * Constructor. | |
| 3183 | + * Service icon font code. | |
| 2865 | 3184 | * |
| 2866 | - * @param int $id Sharing source ID. | |
| 2867 | - * @param array $settings Sharing settings. | |
| 3185 | + * @var string | |
| 2868 | 3186 | */ |
| 2869 | - public function __construct( $id, array $settings ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found | |
| 2870 | - parent::__construct( $id, $settings ); | |
| 2871 | - } | |
| 3187 | + public $icon = '\f10c'; | |
| 2872 | 3188 | |
| 2873 | 3189 | /** |
| 2874 | 3190 | * Service name. |
| 2875 | 3191 | * |
| @@ -2875,9 +3191,9 @@ | ||
| 2875 | 3191 | * |
| 2876 | 3192 | * @return string |
| 2877 | 3193 | */ |
| 2878 | 3194 | public function get_name() { |
| 2879 | - return __( 'WhatsApp', 'jetpack' ); | |
| 3195 | + return __( 'Nextdoor', 'jetpack' ); | |
| 2880 | 3196 | } |
| 2881 | 3197 | |
| 2882 | 3198 | /** |
| 2883 | 3199 | * Get the markup of the sharing button. |
| @@ -2886,22 +3202,15 @@ | ||
| 2886 | 3202 | * |
| 2887 | 3203 | * @return string |
| 2888 | 3204 | */ |
| 2889 | 3205 | public function get_display( $post ) { |
| 2890 | - 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' ); | |
| 2891 | - } | |
| 2892 | - | |
| 2893 | - /** | |
| 2894 | - * AMP display for Whatsapp. | |
| 2895 | - * | |
| 2896 | - * @param \WP_Post $post The current post being viewed. | |
| 2897 | - */ | |
| 2898 | - public function get_amp_display( $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 2899 | - $attrs = array( | |
| 2900 | - 'type' => 'whatsapp', | |
| 3206 | + return $this->get_link( | |
| 3207 | + $this->get_process_request_url( $post->ID ), | |
| 3208 | + _x( 'Nextdoor', 'share to', 'jetpack' ), | |
| 3209 | + __( 'Share on Nextdoor', 'jetpack' ), | |
| 3210 | + 'share=nextdoor', | |
| 3211 | + 'sharing-nextdoor-' . $post->ID | |
| 2901 | 3212 | ); |
| 2902 | - | |
| 2903 | - return $this->build_amp_markup( $attrs ); | |
| 2904 | 3213 | } |
| 2905 | 3214 | |
| 2906 | 3215 | /** |
| 2907 | 3216 | * Process sharing request. Add actions that need to happen when sharing here. |
| @@ -2914,15 +3223,9 @@ | ||
| 2914 | 3223 | public function process_request( $post, array $post_data ) { |
| 2915 | 3224 | // Record stats |
| 2916 | 3225 | parent::process_request( $post, $post_data ); |
| 2917 | 3226 | |
| 2918 | - // Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com" | |
| 2919 | - if ( User_Agent_Info::is_firefox_desktop() ) { | |
| 2920 | - $url = 'https://web.whatsapp.com/send?text='; | |
| 2921 | - } else { | |
| 2922 | - $url = 'https://api.whatsapp.com/send?text='; | |
| 2923 | - } | |
| 2924 | - | |
| 3227 | + $url = 'https://nextdoor.com/sharekit/?source=jetpack&body='; | |
| 2925 | 3228 | $url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); |
| 2926 | 3229 | |
| 2927 | 3230 | parent::redirect_request( $url ); |
| 2928 | 3231 | } |
| @@ -2928,17 +3231,17 @@ | ||
| 2928 | 3231 | } |
| 2929 | 3232 | } |
| 2930 | 3233 | |
| 2931 | 3234 | /** |
| 2932 | - * Skype sharing service. | |
| 3235 | + * Threads sharing service. | |
| 2933 | 3236 | */ |
| 2934 | -class Share_Skype extends Sharing_Source { | |
| 3237 | +class Share_Threads extends Sharing_Source { | |
| 2935 | 3238 | /** |
| 2936 | 3239 | * Service short name. |
| 2937 | 3240 | * |
| 2938 | 3241 | * @var string |
| 2939 | 3242 | */ |
| 2940 | - public $shortname = 'skype'; | |
| 3243 | + public $shortname = 'threads'; | |
| 2941 | 3244 | |
| 2942 | 3245 | /** |
| 2943 | 3246 | * Service icon font code. |
| 2944 | 3247 | * |
| @@ -2943,44 +3246,17 @@ | ||
| 2943 | 3246 | * Service icon font code. |
| 2944 | 3247 | * |
| 2945 | 3248 | * @var string |
| 2946 | 3249 | */ |
| 2947 | - public $icon = '\f220'; | |
| 3250 | + public $icon = '\f10d'; | |
| 2948 | 3251 | |
| 2949 | 3252 | /** |
| 2950 | - * Sharing type. | |
| 2951 | - * | |
| 2952 | - * @var string | |
| 2953 | - */ | |
| 2954 | - private $share_type = 'default'; | |
| 2955 | - | |
| 2956 | - /** | |
| 2957 | - * Constructor. | |
| 2958 | - * | |
| 2959 | - * @param int $id Sharing source ID. | |
| 2960 | - * @param array $settings Sharing settings. | |
| 2961 | - */ | |
| 2962 | - public function __construct( $id, array $settings ) { | |
| 2963 | - parent::__construct( $id, $settings ); | |
| 2964 | - | |
| 2965 | - if ( isset( $settings['share_type'] ) ) { | |
| 2966 | - $this->share_type = $settings['share_type']; | |
| 2967 | - } | |
| 2968 | - | |
| 2969 | - if ( 'official' === $this->button_style ) { | |
| 2970 | - $this->smart = true; | |
| 2971 | - } else { | |
| 2972 | - $this->smart = false; | |
| 2973 | - } | |
| 2974 | - } | |
| 2975 | - | |
| 2976 | - /** | |
| 2977 | 3253 | * Service name. |
| 2978 | 3254 | * |
| 2979 | 3255 | * @return string |
| 2980 | 3256 | */ |
| 2981 | 3257 | public function get_name() { |
| 2982 | - return __( 'Skype', 'jetpack' ); | |
| 3258 | + return __( 'Threads', 'jetpack' ); | |
| 2983 | 3259 | } |
| 2984 | 3260 | |
| 2985 | 3261 | /** |
| 2986 | 3262 | * Get the markup of the sharing button. |
| @@ -2989,48 +3265,18 @@ | ||
| 2989 | 3265 | * |
| 2990 | 3266 | * @return string |
| 2991 | 3267 | */ |
| 2992 | 3268 | public function get_display( $post ) { |
| 2993 | - if ( $this->smart ) { | |
| 2994 | - $skype_share_html = sprintf( | |
| 2995 | - '<div class="skype-share" data-href="%1$s" data-lang="%2$s" data-style="small" data-source="jetpack" ></div>', | |
| 2996 | - esc_attr( $this->get_share_url( $post->ID ) ), | |
| 2997 | - 'en-US' | |
| 2998 | - ); | |
| 2999 | - return $skype_share_html; | |
| 3000 | - } | |
| 3001 | - | |
| 3002 | - /** This filter is already documented in modules/sharedaddy/sharing-sources.php */ | |
| 3003 | - if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'skype' ) ) { | |
| 3004 | - sharing_register_post_for_share_counts( $post->ID ); | |
| 3005 | - } | |
| 3006 | 3269 | return $this->get_link( |
| 3007 | 3270 | $this->get_process_request_url( $post->ID ), |
| 3008 | - _x( 'Skype', 'share to', 'jetpack' ), | |
| 3009 | - __( 'Click to share on Skype', 'jetpack' ), | |
| 3010 | - 'share=skype', | |
| 3011 | - 'sharing-skype-' . $post->ID | |
| 3271 | + _x( 'Threads', 'share to', 'jetpack' ), | |
| 3272 | + __( 'Share on Threads', 'jetpack' ), | |
| 3273 | + 'share=threads', | |
| 3274 | + 'sharing-threads-' . $post->ID | |
| 3012 | 3275 | ); |
| 3013 | 3276 | } |
| 3014 | 3277 | |
| 3015 | 3278 | /** |
| 3016 | - * AMP display for Skype. | |
| 3017 | - * | |
| 3018 | - * @param \WP_Post $post The current post being viewed. | |
| 3019 | - */ | |
| 3020 | - public function get_amp_display( $post ) { | |
| 3021 | - $attrs = array( | |
| 3022 | - 'data-share-endpoint' => sprintf( | |
| 3023 | - 'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack', | |
| 3024 | - rawurlencode( $this->get_share_url( $post->ID ) ), | |
| 3025 | - 'en-US' | |
| 3026 | - ), | |
| 3027 | - ); | |
| 3028 | - | |
| 3029 | - return $this->build_amp_markup( $attrs ); | |
| 3030 | - } | |
| 3031 | - | |
| 3032 | - /** | |
| 3033 | 3279 | * Process sharing request. Add actions that need to happen when sharing here. |
| 3034 | 3280 | * |
| 3035 | 3281 | * @param WP_Post $post Post object. |
| 3036 | 3282 | * @param array $post_data Array of information about the post we're sharing. |
| @@ -3037,18 +3283,15 @@ | ||
| 3037 | 3283 | * |
| 3038 | 3284 | * @return void |
| 3039 | 3285 | */ |
| 3040 | 3286 | public function process_request( $post, array $post_data ) { |
| 3041 | - $skype_url = sprintf( | |
| 3042 | - 'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack', | |
| 3043 | - rawurlencode( $this->get_share_url( $post->ID ) ), | |
| 3044 | - 'en-US' | |
| 3045 | - ); | |
| 3046 | - | |
| 3047 | 3287 | // Record stats |
| 3048 | 3288 | parent::process_request( $post, $post_data ); |
| 3049 | 3289 | |
| 3050 | - parent::redirect_request( $skype_url ); | |
| 3290 | + $url = 'https://threads.net/intent/post?text='; | |
| 3291 | + $url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); | |
| 3292 | + | |
| 3293 | + parent::redirect_request( $url ); | |
| 3051 | 3294 | } |
| 3052 | 3295 | |
| 3053 | 3296 | /** |
| 3054 | 3297 | * Add content specific to a service in the footer. |
| @@ -3053,51 +3296,22 @@ | ||
| 3053 | 3296 | /** |
| 3054 | 3297 | * Add content specific to a service in the footer. |
| 3055 | 3298 | */ |
| 3056 | 3299 | public function display_footer() { |
| 3057 | - if ( $this->smart ) : | |
| 3058 | - ?> | |
| 3059 | - <script> | |
| 3060 | - (function(r, d, s) { | |
| 3061 | - r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) { | |
| 3062 | - var js, sjs = d.getElementsByTagName(s)[0]; | |
| 3063 | - if (d.getElementById(p.id)) { return; } | |
| 3064 | - js = d.createElement(s); | |
| 3065 | - js.id = p.id; | |
| 3066 | - js.src = p.scriptToLoad; | |
| 3067 | - js.onload = p.callback | |
| 3068 | - sjs.parentNode.insertBefore(js, sjs); | |
| 3069 | - }; | |
| 3070 | - var p = { | |
| 3071 | - scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js', | |
| 3072 | - id: 'skype_web_sdk' | |
| 3073 | - }; | |
| 3074 | - r.loadSkypeWebSdkAsync(p); | |
| 3075 | - })(window, document, 'script'); | |
| 3076 | - </script> | |
| 3077 | - <?php | |
| 3078 | - else : | |
| 3079 | - $this->js_dialog( | |
| 3080 | - $this->shortname, | |
| 3081 | - array( | |
| 3082 | - 'width' => 305, | |
| 3083 | - 'height' => 665, | |
| 3084 | - ) | |
| 3085 | - ); | |
| 3086 | - endif; | |
| 3300 | + $this->js_dialog( $this->shortname ); | |
| 3087 | 3301 | } |
| 3088 | 3302 | } |
| 3089 | 3303 | |
| 3090 | 3304 | /** |
| 3091 | - * Mastodon sharing service. | |
| 3305 | + * Bluesky sharing service. | |
| 3092 | 3306 | */ |
| 3093 | -class Share_Mastodon extends Sharing_Source { | |
| 3307 | +class Share_Bluesky extends Sharing_Source { | |
| 3094 | 3308 | /** |
| 3095 | 3309 | * Service short name. |
| 3096 | 3310 | * |
| 3097 | 3311 | * @var string |
| 3098 | 3312 | */ |
| 3099 | - public $shortname = 'mastodon'; | |
| 3313 | + public $shortname = 'bluesky'; | |
| 3100 | 3314 | |
| 3101 | 3315 | /** |
| 3102 | 3316 | * Service icon font code. |
| 3103 | 3317 | * |
| @@ -3102,9 +3316,9 @@ | ||
| 3102 | 3316 | * Service icon font code. |
| 3103 | 3317 | * |
| 3104 | 3318 | * @var string |
| 3105 | 3319 | */ |
| 3106 | - public $icon = '\f10a'; | |
| 3320 | + public $icon = '\f10f'; | |
| 3107 | 3321 | |
| 3108 | 3322 | /** |
| 3109 | 3323 | * Service name. |
| 3110 | 3324 | * |
| @@ -3110,9 +3324,9 @@ | ||
| 3110 | 3324 | * |
| 3111 | 3325 | * @return string |
| 3112 | 3326 | */ |
| 3113 | 3327 | public function get_name() { |
| 3114 | - return __( 'Mastodon', 'jetpack' ); | |
| 3328 | + return __( 'Bluesky', 'jetpack' ); | |
| 3115 | 3329 | } |
| 3116 | 3330 | |
| 3117 | 3331 | /** |
| 3118 | 3332 | * Get the markup of the sharing button. |
| @@ -3123,12 +3337,12 @@ | ||
| 3123 | 3337 | */ |
| 3124 | 3338 | public function get_display( $post ) { |
| 3125 | 3339 | return $this->get_link( |
| 3126 | 3340 | $this->get_process_request_url( $post->ID ), |
| 3127 | - _x( 'Mastodon', 'share to', 'jetpack' ), | |
| 3128 | - __( 'Click to share on Mastodon', 'jetpack' ), | |
| 3129 | - 'share=mastodon', | |
| 3130 | - 'sharing-mastodon-' . $post->ID | |
| 3341 | + _x( 'Bluesky', 'share to', 'jetpack' ), | |
| 3342 | + __( 'Share on Bluesky', 'jetpack' ), | |
| 3343 | + 'share=bluesky', | |
| 3344 | + 'sharing-bluesky-' . $post->ID | |
| 3131 | 3345 | ); |
| 3132 | 3346 | } |
| 3133 | 3347 | |
| 3134 | 3348 | /** |
| @@ -3139,51 +3353,15 @@ | ||
| 3139 | 3353 | * |
| 3140 | 3354 | * @return void |
| 3141 | 3355 | */ |
| 3142 | 3356 | public function process_request( $post, array $post_data ) { |
| 3143 | - if ( empty( $_POST['jetpack-mastodon-instance'] ) ) { | |
| 3144 | - require_once WP_SHARING_PLUGIN_DIR . 'services/class-jetpack-mastodon-modal.php'; | |
| 3145 | - add_action( 'template_redirect', array( 'Jetpack_Mastodon_Modal', 'modal' ) ); | |
| 3146 | - return; | |
| 3147 | - } | |
| 3357 | + // Record stats | |
| 3358 | + parent::process_request( $post, $post_data ); | |
| 3148 | 3359 | |
| 3149 | - check_admin_referer( 'jetpack_share_mastodon_instance' ); | |
| 3360 | + $url = 'https://bsky.app/intent/compose?text='; | |
| 3361 | + $url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); | |
| 3150 | 3362 | |
| 3151 | - $mastodon_instance = isset( $_POST['jetpack-mastodon-instance'] ) | |
| 3152 | - ? trailingslashit( sanitize_text_field( wp_unslash( $_POST['jetpack-mastodon-instance'] ) ) ) | |
| 3153 | - : null; | |
| 3154 | - | |
| 3155 | - $post_title = $this->get_share_title( $post->ID ); | |
| 3156 | - $post_link = $this->get_share_url( $post->ID ); | |
| 3157 | - $post_tags = $this->get_share_tags( $post->ID ); | |
| 3158 | - | |
| 3159 | - /** | |
| 3160 | - * Allow filtering the default message that gets posted to Mastodon. | |
| 3161 | - * | |
| 3162 | - * @module sharedaddy | |
| 3163 | - * @since 11.9 | |
| 3164 | - * | |
| 3165 | - * @param string $share_url The default message that gets posted to Mastodon. | |
| 3166 | - * @param WP_Post $post The post object. | |
| 3167 | - * @param array $post_data Array of information about the post we're sharing. | |
| 3168 | - */ | |
| 3169 | - $shared_message = apply_filters( | |
| 3170 | - 'jetpack_sharing_mastodon_default_message', | |
| 3171 | - $post_title . ' ' . $post_link . ' ' . $post_tags, | |
| 3172 | - $post, | |
| 3173 | - $post_data | |
| 3174 | - ); | |
| 3175 | - | |
| 3176 | - $share_url = sprintf( | |
| 3177 | - '%1$sshare?text=%2$s', | |
| 3178 | - $mastodon_instance, | |
| 3179 | - rawurlencode( $shared_message ) | |
| 3180 | - ); | |
| 3181 | - | |
| 3182 | - // Record stats | |
| 3183 | - parent::process_request( $post, $post_data ); | |
| 3184 | - | |
| 3185 | - parent::redirect_request( $share_url ); | |
| 3363 | + parent::redirect_request( $url ); | |
| 3186 | 3364 | } |
| 3187 | 3365 | |
| 3188 | 3366 | /** |
| 3189 | 3367 | * Add content specific to a service in the footer. |
| @@ -3188,13 +3366,7 @@ | ||
| 3188 | 3366 | /** |
| 3189 | 3367 | * Add content specific to a service in the footer. |
| 3190 | 3368 | */ |
| 3191 | 3369 | public function display_footer() { |
| 3192 | - $this->js_dialog( | |
| 3193 | - $this->shortname, | |
| 3194 | - array( | |
| 3195 | - 'width' => 460, | |
| 3196 | - 'height' => 400, | |
| 3197 | - ) | |
| 3198 | - ); | |
| 3370 | + $this->js_dialog( $this->shortname ); | |
| 3199 | 3371 | } |
| 3200 | 3372 | } |