icon ), '"' ) . '");' ) . '">', $str );
}
/**
* No AMP display for custom elements.
*
* @param \WP_Post $post The current post being viewed.
*/
public function get_amp_display( $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
return false;
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
$url = str_replace( '&', '&', $this->url );
$url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url );
$url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
$url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
$url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
$url = str_replace( '%home_url%', rawurlencode( home_url() ), $url );
$url = str_replace( '%post_slug%', rawurlencode( $post->post_name ), $url );
if ( strpos( $url, '%post_tags%' ) !== false ) {
$tags = get_the_tags( $post->ID );
$tagged = '';
if ( $tags ) {
$tagged_raw = array();
foreach ( $tags as $tag ) {
$tagged_raw[] = rawurlencode( $tag->name );
}
$tagged = implode( ',', $tagged_raw );
}
$url = str_replace( '%post_tags%', $tagged, $url );
}
if ( strpos( $url, '%post_excerpt%' ) !== false ) {
$url_excerpt = $post->post_excerpt;
if ( empty( $url_excerpt ) ) {
$url_excerpt = $post->post_content;
}
$url_excerpt = wp_strip_all_tags( strip_shortcodes( $url_excerpt ) );
$url_excerpt = wp_html_excerpt( $url_excerpt, 100 );
$url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) );
$url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url );
}
// Record stats
parent::process_request( $post, $post_data );
parent::redirect_request( $url );
}
/**
* Display options for our sharing buttons.
*
* @return void
*/
public function display_options() {
?>
name = $name;
}
if ( $url ) {
$this->url = $url;
}
if ( $icon ) {
$this->icon = $icon;
}
}
/**
* Get array of information about the service.
*
* @return array
*/
public function get_options() {
return array(
'name' => $this->name,
'icon' => $this->icon,
'url' => $this->url,
);
}
/**
* Display a preview of the sharing button.
*
* @param bool $echo Whether to echo the output or return it.
* @param bool $force_smart Whether to force the smart (official) services to be shown.
* @param null|string $button_style Button style.
*
* @return void
*/
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$opts = $this->get_options();
$text = ' ';
if ( ! $this->smart ) {
if ( $this->button_style !== 'icon' ) {
$text = $this->get_name();
}
}
$klasses = array( 'share-' . $this->shortname );
if ( $this->button_style === 'icon' || $this->button_style === 'icon-text' ) {
$klasses[] = 'share-icon';
}
if ( $this->button_style === 'icon' ) {
$text = '';
$klasses[] = 'no-text';
}
if ( $this->button_style === 'text' ) {
$klasses[] = 'no-icon';
}
$link = sprintf(
'%s',
esc_attr( implode( ' ', $klasses ) ),
esc_attr( $this->get_name() ),
addcslashes( esc_url_raw( $opts['icon'] ), '"' ),
esc_html( $text )
);
?>
button_style ) {
$this->smart = true;
} else {
$this->smart = false;
}
}
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Tumblr', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
if ( $this->smart ) {
$target = '';
if ( true === $this->open_link_in_new ) {
$target = '_blank';
}
/**
* If we are looking at a single post, let Tumblr figure out the post type (text, photo, link, quote, chat, or video)
* based on the content available on the page.
* If we are not looking at a single post, content from other posts can appear on the page and Tumblr will pick that up.
* 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.
*/
if ( ! is_single() ) {
$posttype = 'data-posttype="link"';
} else {
$posttype = '';
}
// Documentation: https://www.tumblr.com/docs/en/share_button
return sprintf(
'%5$s',
$target,
'https://www.tumblr.com/share',
$this->get_share_title( $post->ID ),
$this->get_share_url( $post->ID ),
__( 'Share on Tumblr', 'jetpack' ),
$posttype
);
} else {
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' );
}
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
// Redirect to Tumblr's sharing endpoint (a la their bookmarklet)
$url = 'https://www.tumblr.com/share?v=3&u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '&s=';
parent::redirect_request( $url );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
if ( $this->smart ) {
// phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript
?>
js_dialog(
$this->shortname,
array(
'width' => 450,
'height' => 450,
)
);
}
}
}
/**
* Pinterest sharing service.
*/
class Share_Pinterest extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'pinterest';
/**
* Service icon font code.
*
* @var string
*/
public $icon = '\f209';
/**
* Constructor.
*
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
*/
public function __construct( $id, array $settings ) {
parent::__construct( $id, $settings );
if ( 'official' === $this->button_style ) {
$this->smart = true;
} else {
$this->smart = false;
}
}
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Pinterest', 'jetpack' );
}
/**
* Get image representative of the post to pass on to Pinterest.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_image( $post ) {
if ( class_exists( 'Jetpack_PostImages' ) ) {
$image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
if ( ! empty( $image ) ) {
return $image['src'];
}
}
/**
* Filters the default image used by the Pinterest Pin It share button.
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param string $url Default image URL.
*/
return apply_filters( 'jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg' );
}
/**
* Get Pinterest external sharing URL.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_external_url( $post ) {
$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 );
/**
* Filters the Pinterest share URL used in sharing button output.
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param string $url Pinterest share URL.
*/
return apply_filters( 'jetpack_sharing_pinterest_share_url', $url );
}
/**
* Get Pinterest widget type.
*
* @return string
*/
public function get_widget_type() {
/**
* Filters the Pinterest widget type.
*
* @see https://business.pinterest.com/en/widget-builder
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param string $type Pinterest widget type. Default of 'buttonPin' for single-image selection. 'buttonBookmark' for multi-image modal.
*/
return apply_filters( 'jetpack_sharing_pinterest_widget_type', 'buttonPin' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
$display = '';
if ( $this->smart ) {
$display = sprintf(
'',
esc_url( $this->get_external_url( $post ) ),
esc_attr( $this->get_widget_type() )
);
} else {
$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 );
}
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
sharing_register_post_for_share_counts( $post->ID );
}
return $display;
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
// If we're triggering the multi-select panel, then we don't need to redirect to Pinterest
if ( ! isset( $_GET['js_only'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
parent::redirect_request( $pinterest_url );
} else {
echo '// share count bumped';
die();
}
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
/**
* Filter the Pin it button appearing when hovering over images when using the official button style.
*
* @module sharedaddy
*
* @since 3.6.0
*
* @param bool $jetpack_pinit_over True by default, displays the Pin it button when hovering over images.
*/
$jetpack_pinit_over = apply_filters( 'jetpack_pinit_over_button', true );
?>
smart ) : ?>
get_widget_type() ) : ?>
button_style ) {
$this->smart = true;
} else {
$this->smart = false;
}
}
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Pocket', 'jetpack' );
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$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 ) ) );
parent::redirect_request( $pocket_url );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
if ( $this->smart ) {
$post_count = 'horizontal';
$button = '';
$button .= '';
return $button;
} else {
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' );
}
}
/**
* AMP display for Pocket.
*
* @param \WP_Post $post The current post being viewed.
*/
public function get_amp_display( $post ) {
$attrs = array(
'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 ) ) ),
);
return $this->build_amp_markup( $attrs );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
if ( $this->smart ) :
?>
js_dialog(
$this->shortname,
array(
'width' => 450,
'height' => 450,
)
);
endif;
}
}
/**
* Telegram sharing service.
*/
class Share_Telegram extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'telegram';
/**
* Constructor.
*
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
*/
public function __construct( $id, array $settings ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
parent::__construct( $id, $settings );
}
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Telegram', 'jetpack' );
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$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 ) ) );
parent::redirect_request( $telegram_url );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' );
}
/**
* AMP display for Telegram.
*
* @param \WP_Post $post The current post being viewed.
*/
public function get_amp_display( $post ) {
$attrs = array(
'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 ) ) ),
);
return $this->build_amp_markup( $attrs );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
$this->js_dialog(
$this->shortname,
array(
'width' => 450,
'height' => 450,
)
);
}
}
/**
* WhatsApp sharing service.
*/
class Jetpack_Share_WhatsApp extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'jetpack-whatsapp';
/**
* Constructor.
*
* @param int $id Sharing source ID.
* @param array $settings Sharing settings.
*/
public function __construct( $id, array $settings ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
parent::__construct( $id, $settings );
}
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'WhatsApp', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
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' );
}
/**
* AMP display for Whatsapp.
*
* @param \WP_Post $post The current post being viewed.
*/
public function get_amp_display( $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$attrs = array(
'type' => 'whatsapp',
);
return $this->build_amp_markup( $attrs );
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
// Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com"
if ( User_Agent_Info::is_firefox_desktop() ) {
$url = 'https://web.whatsapp.com/send?text=';
} else {
$url = 'https://api.whatsapp.com/send?text=';
}
$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );
parent::redirect_request( $url );
}
}
/**
* Skype sharing service.
*/
class Share_Skype extends Deprecated_Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'skype';
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Skype', 'jetpack' );
}
}
/**
* Mastodon sharing service.
*/
class Share_Mastodon extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'mastodon';
/**
* Service icon font code.
*
* @var string
*/
public $icon = '\f10a';
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Mastodon', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
return $this->get_link(
$this->get_process_request_url( $post->ID ),
_x( 'Mastodon', 'share to', 'jetpack' ),
__( 'Click to share on Mastodon', 'jetpack' ),
'share=mastodon',
'sharing-mastodon-' . $post->ID
);
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
if ( empty( $_POST['jetpack-mastodon-instance'] ) ) {
require_once WP_SHARING_PLUGIN_DIR . 'services/class-jetpack-mastodon-modal.php';
add_action( 'template_redirect', array( 'Jetpack_Mastodon_Modal', 'modal' ) );
return;
}
check_admin_referer( 'jetpack_share_mastodon_instance' );
$mastodon_instance = isset( $_POST['jetpack-mastodon-instance'] )
? trailingslashit( sanitize_text_field( wp_unslash( $_POST['jetpack-mastodon-instance'] ) ) )
: null;
$post_title = $this->get_share_title( $post->ID );
$post_link = $this->get_share_url( $post->ID );
$post_tags = $this->get_share_tags( $post->ID );
/**
* Allow filtering the default message that gets posted to Mastodon.
*
* @module sharedaddy
* @since 11.9
*
* @param string $share_url The default message that gets posted to Mastodon.
* @param WP_Post $post The post object.
* @param array $post_data Array of information about the post we're sharing.
*/
$shared_message = apply_filters(
'jetpack_sharing_mastodon_default_message',
$post_title . ' ' . $post_link . ' ' . $post_tags,
$post,
$post_data
);
$share_url = sprintf(
'%1$sshare?text=%2$s',
$mastodon_instance,
rawurlencode( $shared_message )
);
// Record stats
parent::process_request( $post, $post_data );
parent::redirect_request( $share_url );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
$this->js_dialog(
$this->shortname,
array(
'width' => 460,
'height' => 400,
)
);
}
}
/**
* Nextdoor sharing service.
*/
class Share_Nextdoor extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'nextdoor';
/**
* Service icon font code.
*
* @var string
*/
public $icon = '\f10c';
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Nextdoor', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
return $this->get_link(
$this->get_process_request_url( $post->ID ),
_x( 'Nextdoor', 'share to', 'jetpack' ),
__( 'Click to share on Nextdoor', 'jetpack' ),
'share=nextdoor',
'sharing-nextdoor-' . $post->ID
);
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$url = 'https://nextdoor.com/sharekit/?source=jetpack&body=';
$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );
parent::redirect_request( $url );
}
}
/**
* Threads sharing service.
*/
class Share_Threads extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'threads';
/**
* Service icon font code.
*
* @var string
*/
public $icon = '\f10d';
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Threads', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
return $this->get_link(
$this->get_process_request_url( $post->ID ),
_x( 'Threads', 'share to', 'jetpack' ),
__( 'Click to share on Threads', 'jetpack' ),
'share=threads',
'sharing-threads-' . $post->ID
);
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$url = 'https://threads.net/intent/post?text=';
$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );
parent::redirect_request( $url );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
$this->js_dialog( $this->shortname );
}
}
/**
* Bluesky sharing service.
*/
class Share_Bluesky extends Sharing_Source {
/**
* Service short name.
*
* @var string
*/
public $shortname = 'bluesky';
/**
* Service icon font code.
*
* @var string
*/
public $icon = '\f10f';
/**
* Service name.
*
* @return string
*/
public function get_name() {
return __( 'Bluesky', 'jetpack' );
}
/**
* Get the markup of the sharing button.
*
* @param WP_Post $post Post object.
*
* @return string
*/
public function get_display( $post ) {
return $this->get_link(
$this->get_process_request_url( $post->ID ),
_x( 'Bluesky', 'share to', 'jetpack' ),
__( 'Click to share on Bluesky', 'jetpack' ),
'share=bluesky',
'sharing-bluesky-' . $post->ID
);
}
/**
* Process sharing request. Add actions that need to happen when sharing here.
*
* @param WP_Post $post Post object.
* @param array $post_data Array of information about the post we're sharing.
*
* @return void
*/
public function process_request( $post, array $post_data ) {
// Record stats
parent::process_request( $post, $post_data );
$url = 'https://bsky.app/intent/compose?text=';
$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) );
parent::redirect_request( $url );
}
/**
* Add content specific to a service in the footer.
*/
public function display_footer() {
$this->js_dialog( $this->shortname );
}
}