icon ), '"' ) . '");' ) . '">', $str );
}
public function process_request( $post, array $post_data ) {
$url = str_replace( '&', '&', $this->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 );
if ( strpos( $url, '%post_tags%' ) !== false ) {
$tags = get_the_tags( $post->ID );
$tagged = '';
if ( $tags ) {
foreach ( $tags AS $tag ) {
$tagged[] = rawurlencode( $tag->name );
}
$tagged = implode( ',', $tagged );
}
$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 = strip_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 );
// Redirect
wp_redirect( $url );
die();
}
public function display_options() {
?>
name = $name;
if ( $url )
$this->url = $url;
if ( $icon )
$this->icon = $icon;
}
public function get_options() {
return array(
'name' => $this->name,
'icon' => $this->icon,
'url' => $this->url,
);
}
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) {
$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',
implode( ' ', $klasses ),
$this->get_name(),
addcslashes( esc_url_raw( $opts['icon'] ), '"' ),
$text
);
?>
button_style )
$this->smart = true;
else
$this->smart = false;
}
public function get_name() {
return __( 'Tumblr', 'jetpack' );
}
public function get_display( $post ) {
if ( $this->smart ) {
$target = '';
if ( true == $this->open_link_in_new )
$target = '_blank';
return '' . __( 'Share on Tumblr', 'jetpack' ) . '';
} 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' );
}
}
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 = 'http://www.tumblr.com/share?v=3&u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '&s=';
wp_redirect( $url );
die();
}
// http://www.tumblr.com/share?v=3&u=URL&t=TITLE&s=
public function display_footer() {
if ( $this->smart ) {
?>js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
}
}
}
class Share_Pinterest extends Sharing_Source {
public $shortname = 'pinterest';
public $genericon = '\f209';
public function __construct( $id, array $settings ) {
parent::__construct( $id, $settings );
if ( 'official' == $this->button_style )
$this->smart = true;
else
$this->smart = false;
}
public function get_name() {
return __( 'Pinterest', 'jetpack' );
}
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' );
}
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 );
}
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' );
}
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;
}
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'] ) ) {
$pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
wp_redirect( $pinterest_url );
} else {
echo '// share count bumped';
}
die();
}
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;
}
public function get_name() {
return __( 'Pocket', 'jetpack' );
}
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 ) ) );
wp_redirect( $pocket_url );
exit;
}
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' );
}
}
function display_footer() {
if ( $this->smart ) :
?>
js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
endif;
}
}
class Share_Skype extends Sharing_Source {
public $shortname = 'skype';
public $genericon = '\f220';
private $share_type = 'default';
public function __construct( $id, array $settings ) {
parent::__construct( $id, $settings );
if ( isset( $settings['share_type'] ) ) {
$this->share_type = $settings['share_type'];
}
if ( 'official' == $this->button_style ) {
$this->smart = true;
} else {
$this->smart = false;
}
}
public function get_name() {
return __( 'Skype', 'jetpack' );
}
public function get_display( $post ) {
if ( $this->smart ) {
$skype_share_html = sprintf(
'',
esc_attr( $this->get_share_url( $post->ID ) ),
'en-US'
);
return $skype_share_html;
}
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'skype' ) ) {
sharing_register_post_for_share_counts( $post->ID );
}
return $this->get_link(
$this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID );
}
public function process_request( $post, array $post_data ) {
$skype_url = sprintf(
'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack',
rawurlencode( $this->get_share_url( $post->ID ) ),
'en-US'
);
// Record stats
parent::process_request( $post, $post_data );
// Redirect to Skype
wp_redirect( $skype_url );
die();
}
public function display_footer() {
if ( $this->smart ) :
?>
js_dialog( $this->shortname, array( 'width' => 305, 'height' => 665 ) );
endif;
}
}