| 1 |
<?php |
| 2 |
|
| 3 |
use Automattic\Jetpack\Device_Detection\User_Agent_Info; |
| 4 |
|
| 5 |
abstract class Sharing_Source { |
| 6 |
public $button_style; |
| 7 |
public $smart; |
| 8 |
protected $open_link_in_new; |
| 9 |
protected $id; |
| 10 |
|
| 11 |
public function __construct( $id, array $settings ) { |
| 12 |
$this->id = $id; |
| 13 |
/** |
| 14 |
* Filter the way sharing links open. |
| 15 |
* |
| 16 |
* By default, sharing links open in a new window. |
| 17 |
* |
| 18 |
* @module sharedaddy |
| 19 |
* |
| 20 |
* @since 3.4.0 |
| 21 |
* |
| 22 |
* @param bool true Should Sharing links open in a new window. Default to true. |
| 23 |
*/ |
| 24 |
$this->open_link_in_new = apply_filters( 'jetpack_open_sharing_in_new_window', true ); |
| 25 |
|
| 26 |
if ( isset( $settings['button_style'] ) ) { |
| 27 |
$this->button_style = $settings['button_style']; |
| 28 |
} |
| 29 |
|
| 30 |
if ( isset( $settings['smart'] ) ) { |
| 31 |
$this->smart = $settings['smart']; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
public function is_deprecated() { |
| 36 |
return false; |
| 37 |
} |
| 38 |
|
| 39 |
public function http() { |
| 40 |
return is_ssl() ? 'https' : 'http'; |
| 41 |
} |
| 42 |
|
| 43 |
public function get_id() { |
| 44 |
return $this->id; |
| 45 |
} |
| 46 |
|
| 47 |
public function get_class() { |
| 48 |
return $this->id; |
| 49 |
} |
| 50 |
|
| 51 |
public function get_share_url( $post_id ) { |
| 52 |
/** |
| 53 |
* Filter the sharing permalink. |
| 54 |
* |
| 55 |
* @module sharedaddy |
| 56 |
* |
| 57 |
* @since 1.2.0 |
| 58 |
* |
| 59 |
* @param string get_permalink( $post_id ) Post Permalink. |
| 60 |
* @param int $post_id Post ID. |
| 61 |
* @param int $this->id Sharing ID. |
| 62 |
*/ |
| 63 |
return apply_filters( 'sharing_permalink', get_permalink( $post_id ), $post_id, $this->id ); |
| 64 |
} |
| 65 |
|
| 66 |
public function get_share_title( $post_id ) { |
| 67 |
$post = get_post( $post_id ); |
| 68 |
/** |
| 69 |
* Filter the sharing title. |
| 70 |
* |
| 71 |
* @module sharedaddy |
| 72 |
* |
| 73 |
* @since 2.8.0 |
| 74 |
* |
| 75 |
* @param string $post->post_title Post Title. |
| 76 |
* @param int $post_id Post ID. |
| 77 |
* @param int $this->id Sharing ID. |
| 78 |
*/ |
| 79 |
$title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id ); |
| 80 |
|
| 81 |
return html_entity_decode( wp_kses( $title, null ) ); |
| 82 |
} |
| 83 |
|
| 84 |
public function has_custom_button_style() { |
| 85 |
return false; |
| 86 |
} |
| 87 |
|
| 88 |
public function get_link( $url, $text, $title, $query = '', $id = false ) { |
| 89 |
$args = func_get_args(); |
| 90 |
$klasses = array( 'share-' . $this->get_class(), 'sd-button' ); |
| 91 |
|
| 92 |
if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style ) { |
| 93 |
$klasses[] = 'share-icon'; |
| 94 |
} |
| 95 |
|
| 96 |
if ( 'icon' == $this->button_style ) { |
| 97 |
$text = $title; |
| 98 |
$klasses[] = 'no-text'; |
| 99 |
|
| 100 |
if ( true == $this->open_link_in_new ) { |
| 101 |
$text .= __( ' (Opens in new window)', 'jetpack' ); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* Filter the sharing display ID. |
| 107 |
* |
| 108 |
* @module sharedaddy |
| 109 |
* |
| 110 |
* @since 3.4.0 |
| 111 |
* |
| 112 |
* @param int|false $id Sharing ID. |
| 113 |
* @param object $this Sharing service properties. |
| 114 |
* @param array $args Array of sharing service options. |
| 115 |
*/ |
| 116 |
$id = apply_filters( 'jetpack_sharing_display_id', $id, $this, $args ); |
| 117 |
/** |
| 118 |
* Filter the sharing display link. |
| 119 |
* |
| 120 |
* @module sharedaddy |
| 121 |
* |
| 122 |
* @since 2.8.0 |
| 123 |
* |
| 124 |
* @param string $url Post URL. |
| 125 |
* @param object $this Sharing service properties. |
| 126 |
* @param int|false $id Sharing ID. |
| 127 |
* @param array $args Array of sharing service options. |
| 128 |
*/ |
| 129 |
$url = apply_filters( 'sharing_display_link', $url, $this, $id, $args ); // backwards compatibility |
| 130 |
/** |
| 131 |
* Filter the sharing display link. |
| 132 |
* |
| 133 |
* @module sharedaddy |
| 134 |
* |
| 135 |
* @since 2.8.0 |
| 136 |
* |
| 137 |
* @param string $url Post URL. |
| 138 |
* @param object $this Sharing service properties. |
| 139 |
* @param int|false $id Sharing ID. |
| 140 |
* @param array $args Array of sharing service options. |
| 141 |
*/ |
| 142 |
$url = apply_filters( 'jetpack_sharing_display_link', $url, $this, $id, $args ); |
| 143 |
/** |
| 144 |
* Filter the sharing display query. |
| 145 |
* |
| 146 |
* @module sharedaddy |
| 147 |
* |
| 148 |
* @since 2.8.0 |
| 149 |
* |
| 150 |
* @param string $query Sharing service URL parameter. |
| 151 |
* @param object $this Sharing service properties. |
| 152 |
* @param int|false $id Sharing ID. |
| 153 |
* @param array $args Array of sharing service options. |
| 154 |
*/ |
| 155 |
$query = apply_filters( 'jetpack_sharing_display_query', $query, $this, $id, $args ); |
| 156 |
|
| 157 |
if ( ! empty( $query ) ) { |
| 158 |
if ( false === stripos( $url, '?' ) ) { |
| 159 |
$url .= '?' . $query; |
| 160 |
} else { |
| 161 |
$url .= '&' . $query; |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
if ( 'text' == $this->button_style ) { |
| 166 |
$klasses[] = 'no-icon'; |
| 167 |
} |
| 168 |
|
| 169 |
/** |
| 170 |
* Filter the sharing display classes. |
| 171 |
* |
| 172 |
* @module sharedaddy |
| 173 |
* |
| 174 |
* @since 3.4.0 |
| 175 |
* |
| 176 |
* @param array $klasses Sharing service classes. |
| 177 |
* @param object $this Sharing service properties. |
| 178 |
* @param int|false $id Sharing ID. |
| 179 |
* @param array $args Array of sharing service options. |
| 180 |
*/ |
| 181 |
$klasses = apply_filters( 'jetpack_sharing_display_classes', $klasses, $this, $id, $args ); |
| 182 |
/** |
| 183 |
* Filter the sharing display title. |
| 184 |
* |
| 185 |
* @module sharedaddy |
| 186 |
* |
| 187 |
* @since 3.4.0 |
| 188 |
* |
| 189 |
* @param string $title Sharing service title. |
| 190 |
* @param object $this Sharing service properties. |
| 191 |
* @param int|false $id Sharing ID. |
| 192 |
* @param array $args Array of sharing service options. |
| 193 |
*/ |
| 194 |
$title = apply_filters( 'jetpack_sharing_display_title', $title, $this, $id, $args ); |
| 195 |
/** |
| 196 |
* Filter the sharing display text. |
| 197 |
* |
| 198 |
* @module sharedaddy |
| 199 |
* |
| 200 |
* @since 3.4.0 |
| 201 |
* |
| 202 |
* @param string $text Sharing service text. |
| 203 |
* @param object $this Sharing service properties. |
| 204 |
* @param int|false $id Sharing ID. |
| 205 |
* @param array $args Array of sharing service options. |
| 206 |
*/ |
| 207 |
$text = apply_filters( 'jetpack_sharing_display_text', $text, $this, $id, $args ); |
| 208 |
|
| 209 |
return sprintf( |
| 210 |
'<a rel="nofollow%s" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>', |
| 211 |
( true == $this->open_link_in_new ) ? ' noopener noreferrer' : '', |
| 212 |
( $id ? esc_attr( $id ) : '' ), |
| 213 |
implode( ' ', $klasses ), |
| 214 |
$url, |
| 215 |
( true == $this->open_link_in_new ) ? ' target="_blank"' : '', |
| 216 |
$title, |
| 217 |
( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '', |
| 218 |
$text |
| 219 |
); |
| 220 |
} |
| 221 |
|
| 222 |
/** |
| 223 |
* Get an unfiltered post permalink to use when generating a sharing URL with get_link. |
| 224 |
* Use instead of get_share_url for non-official styles as get_permalink ensures that process_request |
| 225 |
* will be executed more reliably, in the case that the filtered URL uses a service that strips query parameters. |
| 226 |
* |
| 227 |
* @since 3.7.0 |
| 228 |
* @param int $post_id Post ID. |
| 229 |
* @uses get_permalink |
| 230 |
* @return string get_permalink( $post_id ) Post permalink. |
| 231 |
*/ |
| 232 |
public function get_process_request_url( $post_id ) { |
| 233 |
return get_permalink( $post_id ); |
| 234 |
} |
| 235 |
|
| 236 |
abstract public function get_name(); |
| 237 |
abstract public function get_display( $post ); |
| 238 |
|
| 239 |
public function display_header() { |
| 240 |
} |
| 241 |
|
| 242 |
public function display_footer() { |
| 243 |
} |
| 244 |
|
| 245 |
public function has_advanced_options() { |
| 246 |
return false; |
| 247 |
} |
| 248 |
|
| 249 |
/** |
| 250 |
* Get the AMP specific markup for a sharing button. |
| 251 |
* |
| 252 |
* @param \WP_Post $post The current post being viewed. |
| 253 |
*/ |
| 254 |
public function get_amp_display( $post ) { |
| 255 |
// Only display markup if we're on a post. |
| 256 |
if ( empty( $post ) ) { |
| 257 |
return false; |
| 258 |
} |
| 259 |
|
| 260 |
return $this->build_amp_markup(); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* Generates and returns the markup for an AMP sharing button. |
| 265 |
* |
| 266 |
* @param array $attrs Custom attributes for rendering the social icon. |
| 267 |
*/ |
| 268 |
protected function build_amp_markup( $attrs = array() ) { |
| 269 |
|
| 270 |
$title = sprintf( |
| 271 |
/* translators: placeholder is a service name, such as "Twitter" or "Facebook". */ |
| 272 |
__( 'Click to share on %s', 'jetpack' ), |
| 273 |
$this->get_name() |
| 274 |
); |
| 275 |
|
| 276 |
$attrs = array_merge( |
| 277 |
array( |
| 278 |
'type' => $this->get_id(), |
| 279 |
'height' => '32px', |
| 280 |
'width' => '32px', |
| 281 |
'aria-label' => $title, |
| 282 |
'title' => $title, |
| 283 |
), |
| 284 |
$attrs |
| 285 |
); |
| 286 |
$sharing_link = '<amp-social-share'; |
| 287 |
foreach ( $attrs as $key => $value ) { |
| 288 |
$sharing_link .= sprintf( ' %s="%s"', sanitize_key( $key ), esc_attr( $value ) ); |
| 289 |
} |
| 290 |
$sharing_link .= '></amp-social-share>'; |
| 291 |
return $sharing_link; |
| 292 |
} |
| 293 |
|
| 294 |
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
| 295 |
$text = ' '; |
| 296 |
$button_style = ( ! empty( $button_style ) ) ? $button_style : $this->button_style; |
| 297 |
if ( ! $this->smart && ! $force_smart ) { |
| 298 |
if ( $button_style != 'icon' ) { |
| 299 |
$text = $this->get_name(); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
$klasses = array( 'share-' . $this->get_class(), 'sd-button' ); |
| 304 |
|
| 305 |
if ( $button_style == 'icon' || $button_style == 'icon-text' ) { |
| 306 |
$klasses[] = 'share-icon'; |
| 307 |
} |
| 308 |
|
| 309 |
if ( $button_style == 'icon' ) { |
| 310 |
$klasses[] = 'no-text'; |
| 311 |
} |
| 312 |
|
| 313 |
if ( $button_style == 'text' ) { |
| 314 |
$klasses[] = 'no-icon'; |
| 315 |
} |
| 316 |
|
| 317 |
$is_deprecated = $this->is_deprecated(); |
| 318 |
|
| 319 |
$link = sprintf( |
| 320 |
'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span>%s</span></a>', |
| 321 |
implode( ' ', $klasses ), |
| 322 |
esc_attr( |
| 323 |
$is_deprecated |
| 324 |
/* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 325 |
? 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() ) |
| 326 |
: $this->get_name() |
| 327 |
), |
| 328 |
esc_html( |
| 329 |
$is_deprecated |
| 330 |
/* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 331 |
? sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ) |
| 332 |
: $text |
| 333 |
) |
| 334 |
); |
| 335 |
|
| 336 |
$smart = ( $this->smart || $force_smart ) ? 'on' : 'off'; |
| 337 |
$return = "<div class='option option-smart-$smart'>$link</div>"; |
| 338 |
if ( $echo ) { |
| 339 |
echo $return; |
| 340 |
} |
| 341 |
|
| 342 |
return $return; |
| 343 |
} |
| 344 |
|
| 345 |
public function get_total( $post = false ) { |
| 346 |
global $wpdb, $blog_id; |
| 347 |
|
| 348 |
$name = strtolower( $this->get_id() ); |
| 349 |
|
| 350 |
if ( $post == false ) { |
| 351 |
// get total number of shares for service |
| 352 |
return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) ); |
| 353 |
} |
| 354 |
|
| 355 |
// get total shares for a post |
| 356 |
return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $blog_id, $post->ID, $name ) ); |
| 357 |
} |
| 358 |
|
| 359 |
public function get_posts_total() { |
| 360 |
global $wpdb, $blog_id; |
| 361 |
|
| 362 |
$totals = array(); |
| 363 |
$name = strtolower( $this->get_id() ); |
| 364 |
|
| 365 |
$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 ) ); |
| 366 |
|
| 367 |
if ( ! empty( $my_data ) ) { |
| 368 |
foreach ( $my_data as $row ) { |
| 369 |
$totals[] = new Sharing_Post_Total( $row->id, $row->total ); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) ); |
| 374 |
|
| 375 |
return $totals; |
| 376 |
} |
| 377 |
|
| 378 |
public function process_request( $post, array $post_data ) { |
| 379 |
/** |
| 380 |
* Fires when a post is shared via one of the sharing buttons. |
| 381 |
* |
| 382 |
* @module sharedaddy |
| 383 |
* |
| 384 |
* @since 1.1.0 |
| 385 |
* |
| 386 |
* @param array $args Aray of information about the sharing service. |
| 387 |
*/ |
| 388 |
do_action( 'sharing_bump_stats', array( 'service' => $this, 'post' => $post ) ); |
| 389 |
} |
| 390 |
|
| 391 |
public function js_dialog( $name, $params = array() ) { |
| 392 |
if ( true !== $this->open_link_in_new ) { |
| 393 |
return; |
| 394 |
} |
| 395 |
|
| 396 |
$defaults = array( |
| 397 |
'menubar' => 1, |
| 398 |
'resizable' => 1, |
| 399 |
'width' => 600, |
| 400 |
'height' => 400, |
| 401 |
); |
| 402 |
$params = array_merge( $defaults, $params ); |
| 403 |
$opts = array(); |
| 404 |
foreach ( $params as $key => $val ) { |
| 405 |
$opts[] = "$key=$val"; |
| 406 |
} |
| 407 |
$opts = implode( ',', $opts ); |
| 408 |
|
| 409 |
// Add JS after sharing-js has been enqueued. |
| 410 |
wp_add_inline_script( 'sharing-js', |
| 411 |
"var windowOpen; |
| 412 |
( function () { |
| 413 |
function matches( el, sel ) { |
| 414 |
return !! ( |
| 415 |
el.matches && el.matches( sel ) || |
| 416 |
el.msMatchesSelector && el.msMatchesSelector( sel ) |
| 417 |
); |
| 418 |
} |
| 419 |
|
| 420 |
document.body.addEventListener( 'click', function ( event ) { |
| 421 |
if ( ! event.target ) { |
| 422 |
return; |
| 423 |
} |
| 424 |
|
| 425 |
var el; |
| 426 |
if ( matches( event.target, 'a.share-$name' ) ) { |
| 427 |
el = event.target; |
| 428 |
} else if ( event.target.parentNode && matches( event.target.parentNode, 'a.share-$name' ) ) { |
| 429 |
el = event.target.parentNode; |
| 430 |
} |
| 431 |
|
| 432 |
if ( el ) { |
| 433 |
event.preventDefault(); |
| 434 |
|
| 435 |
// If there's another sharing window open, close it. |
| 436 |
if ( typeof windowOpen !== 'undefined' ) { |
| 437 |
windowOpen.close(); |
| 438 |
} |
| 439 |
windowOpen = window.open( el.getAttribute( 'href' ), 'wpcom$name', '$opts' ); |
| 440 |
return false; |
| 441 |
} |
| 442 |
} ); |
| 443 |
} )();" |
| 444 |
); |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
abstract class Deprecated_Sharing_Source extends Sharing_Source { |
| 449 |
public $button_style = 'text'; |
| 450 |
public $smart = false; |
| 451 |
protected $open_link_in_new = false; |
| 452 |
protected $id; |
| 453 |
protected $deprecated = true; |
| 454 |
|
| 455 |
final public function __construct( $id, array $settings ) { |
| 456 |
$this->id = $id; |
| 457 |
|
| 458 |
if ( isset( $settings['button_style'] ) ) { |
| 459 |
$this->button_style = $settings['button_style']; |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
final public function is_deprecated() { |
| 464 |
return true; |
| 465 |
} |
| 466 |
|
| 467 |
final public function get_share_url( $post_id ) { |
| 468 |
return get_permalink( $post_id ); |
| 469 |
} |
| 470 |
|
| 471 |
/** |
| 472 |
* No AMP display for deprecated sources. |
| 473 |
* |
| 474 |
* @param \WP_Post $post The current post being viewed. |
| 475 |
*/ |
| 476 |
final public function get_amp_display( $post ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 477 |
return false; |
| 478 |
} |
| 479 |
|
| 480 |
final public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
| 481 |
return parent::display_preview( $echo, false, $button_style ); |
| 482 |
} |
| 483 |
|
| 484 |
final public function get_total( $post = false ) { |
| 485 |
return 0; |
| 486 |
} |
| 487 |
|
| 488 |
final public function get_posts_total() { |
| 489 |
return 0; |
| 490 |
} |
| 491 |
|
| 492 |
final public function process_request( $post, array $post_data ) { |
| 493 |
parent::process_request( $post, $post_data ); |
| 494 |
} |
| 495 |
|
| 496 |
final public function get_display( $post ) { |
| 497 |
if ( current_user_can( 'manage_options' ) ) { |
| 498 |
return $this->display_deprecated( $post ); |
| 499 |
} |
| 500 |
|
| 501 |
return ''; |
| 502 |
} |
| 503 |
|
| 504 |
public function display_deprecated( $post ) { |
| 505 |
return $this->get_link( |
| 506 |
$this->get_share_url( $post->ID ), |
| 507 |
/* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 508 |
sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ), |
| 509 |
/* translators: %1$s is the name of a deprecated Sharing Service like "Google+" */ |
| 510 |
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() ) |
| 511 |
); |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
abstract class Sharing_Advanced_Source extends Sharing_Source { |
| 516 |
public function has_advanced_options() { |
| 517 |
return true; |
| 518 |
} |
| 519 |
|
| 520 |
abstract public function display_options(); |
| 521 |
abstract public function update_options( array $data ); |
| 522 |
abstract public function get_options(); |
| 523 |
} |
| 524 |
|
| 525 |
class Share_Email extends Sharing_Source { |
| 526 |
public $shortname = 'email'; |
| 527 |
public $icon = '\f410'; |
| 528 |
public function __construct( $id, array $settings ) { |
| 529 |
parent::__construct( $id, $settings ); |
| 530 |
|
| 531 |
if ( 'official' == $this->button_style ) { |
| 532 |
$this->smart = true; |
| 533 |
} else { |
| 534 |
$this->smart = false; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
public function get_name() { |
| 539 |
return _x( 'Email', 'as sharing source', 'jetpack' ); |
| 540 |
} |
| 541 |
|
| 542 |
// Default does nothing |
| 543 |
public function process_request( $post, array $post_data ) { |
| 544 |
$ajax = false; |
| 545 |
if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) { |
| 546 |
$ajax = true; |
| 547 |
} |
| 548 |
|
| 549 |
$source_email = $target_email = $source_name = false; |
| 550 |
|
| 551 |
if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) { |
| 552 |
$source_email = $post_data['source_email']; |
| 553 |
} |
| 554 |
|
| 555 |
if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) { |
| 556 |
$target_email = $post_data['target_email']; |
| 557 |
} |
| 558 |
|
| 559 |
if ( isset( $post_data['source_name'] ) && strlen( $post_data['source_name'] ) < 200 ) { |
| 560 |
$source_name = $post_data['source_name']; |
| 561 |
} elseif ( isset( $post_data['source_name'] ) ) { |
| 562 |
$source_name = substr( $post_data['source_name'], 0, 200 ); |
| 563 |
} else { |
| 564 |
$source_name = ''; |
| 565 |
} |
| 566 |
|
| 567 |
// Test email |
| 568 |
$error = 1; // Failure in data |
| 569 |
if ( empty( $post_data['source_f_name'] ) && $source_email && $target_email && $source_name ) { |
| 570 |
/** |
| 571 |
* Allow plugins to stop the email sharing button from running the shared message through Akismet. |
| 572 |
* |
| 573 |
* @module sharedaddy |
| 574 |
* |
| 575 |
* @since 1.1.0 |
| 576 |
* |
| 577 |
* @param bool true Should we check if the message isn't spam? |
| 578 |
* @param object $post Post information. |
| 579 |
* @param array $post_data Information about the shared message. |
| 580 |
*/ |
| 581 |
if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) { |
| 582 |
$data = array( |
| 583 |
'post' => $post, |
| 584 |
'source' => $source_email, |
| 585 |
'target' => $target_email, |
| 586 |
'name' => $source_name, |
| 587 |
'sharing_source' => $this, |
| 588 |
); |
| 589 |
// todo: implement an error message when email doesn't get sent. |
| 590 |
/** |
| 591 |
* Filter whether an email can be sent from the Email sharing button. |
| 592 |
* |
| 593 |
* @module sharedaddy |
| 594 |
* |
| 595 |
* @since 1.1.0 |
| 596 |
* |
| 597 |
* @param array $data Array of information about the shared message. |
| 598 |
*/ |
| 599 |
if ( ( $data = apply_filters( 'sharing_email_can_send', $data ) ) !== false ) { |
| 600 |
// Record stats |
| 601 |
parent::process_request( $data['post'], $post_data ); |
| 602 |
|
| 603 |
/** |
| 604 |
* Fires when an email is sent via the Email sharing button. |
| 605 |
* |
| 606 |
* @module sharedaddy |
| 607 |
* |
| 608 |
* @since 1.1.0 |
| 609 |
* |
| 610 |
* @param array $data Array of information about the shared message. |
| 611 |
*/ |
| 612 |
do_action( 'sharing_email_send_post', $data ); |
| 613 |
} |
| 614 |
|
| 615 |
// Return a positive regardless of whether the user is subscribed or not |
| 616 |
if ( $ajax ) { |
| 617 |
?> |
| 618 |
<div class="response"> |
| 619 |
<div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div> |
| 620 |
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div> |
| 621 |
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div> |
| 622 |
</div> |
| 623 |
<?php |
| 624 |
} else { |
| 625 |
wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email' ); |
| 626 |
} |
| 627 |
|
| 628 |
die(); |
| 629 |
} else { |
| 630 |
$error = 2; // Email check failed |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
if ( $ajax ) { |
| 635 |
echo $error; |
| 636 |
} else { |
| 637 |
wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' ); |
| 638 |
} |
| 639 |
|
| 640 |
die(); |
| 641 |
} |
| 642 |
|
| 643 |
public function get_display( $post ) { |
| 644 |
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Email', 'share to', 'jetpack' ), __( 'Click to email this to a friend', 'jetpack' ), 'share=email' ); |
| 645 |
} |
| 646 |
|
| 647 |
/** |
| 648 |
* No AMP display for email. |
| 649 |
* |
| 650 |
* @param \WP_Post $post The current post being viewed. |
| 651 |
*/ |
| 652 |
public function get_amp_display( $post ) { // phpcs:ignore |
| 653 |
return false; |
| 654 |
} |
| 655 |
|
| 656 |
/** |
| 657 |
* Outputs the hidden email dialog |
| 658 |
*/ |
| 659 |
public function display_footer() { |
| 660 |
global $current_user; |
| 661 |
|
| 662 |
$visible = $status = false; |
| 663 |
?> |
| 664 |
<div id="sharing_email" style="display: none;"> |
| 665 |
<form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post"> |
| 666 |
<label for="target_email"><?php _e( 'Send to Email Address', 'jetpack' ) ?></label> |
| 667 |
<input type="email" name="target_email" id="target_email" value="" /> |
| 668 |
|
| 669 |
<?php if ( is_user_logged_in() ) : ?> |
| 670 |
<input type="hidden" name="source_name" value="<?php echo esc_attr( $current_user->display_name ); ?>" /> |
| 671 |
<input type="hidden" name="source_email" value="<?php echo esc_attr( $current_user->user_email ); ?>" /> |
| 672 |
<?php else : ?> |
| 673 |
|
| 674 |
<label for="source_name"><?php _e( 'Your Name', 'jetpack' ) ?></label> |
| 675 |
<input type="text" name="source_name" id="source_name" value="" /> |
| 676 |
|
| 677 |
<label for="source_email"><?php _e( 'Your Email Address', 'jetpack' ) ?></label> |
| 678 |
<input type="email" name="source_email" id="source_email" value="" /> |
| 679 |
|
| 680 |
<?php endif; ?> |
| 681 |
<input type="text" id="jetpack-source_f_name" name="source_f_name" class="input" value="" size="25" autocomplete="off" title="<?php esc_attr_e( 'This field is for validation and should not be changed', 'jetpack' ); ?>" /> |
| 682 |
<?php |
| 683 |
/** |
| 684 |
* Fires when the Email sharing dialog is loaded. |
| 685 |
* |
| 686 |
* @module sharedaddy |
| 687 |
* |
| 688 |
* @since 1.1.0 |
| 689 |
* |
| 690 |
* @param string jetpack Eail sharing source. |
| 691 |
*/ |
| 692 |
do_action( 'sharing_email_dialog', 'jetpack' ); |
| 693 |
?> |
| 694 |
|
| 695 |
<img style="float: right; display: none" class="loading" src="<?php |
| 696 |
/** This filter is documented in modules/stats.php */ |
| 697 |
echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" /> |
| 698 |
<input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" /> |
| 699 |
<a rel="nofollow" href="#cancel" class="sharing_cancel" role="button"><?php _e( 'Cancel', 'jetpack' ); ?></a> |
| 700 |
|
| 701 |
<div class="errors errors-1" style="display: none;"> |
| 702 |
<?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?> |
| 703 |
</div> |
| 704 |
|
| 705 |
<div class="errors errors-2" style="display: none;"> |
| 706 |
<?php _e( 'Email check failed, please try again', 'jetpack' ); ?> |
| 707 |
</div> |
| 708 |
|
| 709 |
<div class="errors errors-3" style="display: none;"> |
| 710 |
<?php _e( 'Sorry, your blog cannot share posts by email.', 'jetpack' ); ?> |
| 711 |
</div> |
| 712 |
</form> |
| 713 |
</div> |
| 714 |
<?php |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
class Share_Twitter extends Sharing_Source { |
| 719 |
public $shortname = 'twitter'; |
| 720 |
public $icon = '\f202'; |
| 721 |
// 'https://dev.twitter.com/rest/reference/get/help/configuration' ( 2015/02/06 ) short_url_length is 22, short_url_length_https is 23 |
| 722 |
public $short_url_length = 24; |
| 723 |
|
| 724 |
public function __construct( $id, array $settings ) { |
| 725 |
parent::__construct( $id, $settings ); |
| 726 |
|
| 727 |
if ( 'official' == $this->button_style ) { |
| 728 |
$this->smart = true; |
| 729 |
} else { |
| 730 |
$this->smart = false; |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
public function get_name() { |
| 735 |
return __( 'Twitter', 'jetpack' ); |
| 736 |
} |
| 737 |
|
| 738 |
/** |
| 739 |
* Determine the Twitter 'via' value for a post. |
| 740 |
* |
| 741 |
* @param WP_Post|int $post Post object or post ID. |
| 742 |
* @return string Twitter handle without the preceding @. |
| 743 |
**/ |
| 744 |
public static function sharing_twitter_via( $post ) { |
| 745 |
$post = get_post( $post ); |
| 746 |
/** |
| 747 |
* Allow third-party plugins to customize the Twitter username used as "twitter:site" Twitter Card Meta Tag. |
| 748 |
* |
| 749 |
* @module sharedaddy |
| 750 |
* |
| 751 |
* @since 3.0.0 |
| 752 |
* |
| 753 |
* @param string $string Twitter Username. |
| 754 |
* @param array $args Array of Open Graph Meta Tags and Twitter Cards tags. |
| 755 |
*/ |
| 756 |
$twitter_site_tag_value = apply_filters( |
| 757 |
'jetpack_twitter_cards_site_tag', |
| 758 |
'', |
| 759 |
/** This action is documented in modules/sharedaddy/sharing-sources.php */ |
| 760 |
array( 'twitter:creator' => apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ) ) |
| 761 |
); |
| 762 |
|
| 763 |
/* |
| 764 |
* Hack to remove the unwanted behavior of adding 'via @jetpack' which |
| 765 |
* was introduced with the adding of the Twitter cards. |
| 766 |
* This should be a temporary solution until a better method is setup. |
| 767 |
*/ |
| 768 |
if ( 'jetpack' == $twitter_site_tag_value ) { |
| 769 |
$twitter_site_tag_value = ''; |
| 770 |
} |
| 771 |
|
| 772 |
/** |
| 773 |
* Filters the Twitter username used as "via" in the Twitter sharing button. |
| 774 |
* |
| 775 |
* @module sharedaddy |
| 776 |
* |
| 777 |
* @since 1.7.0 |
| 778 |
* |
| 779 |
* @param string $twitter_site_tag_value Twitter Username. |
| 780 |
* @param int $post->ID Post ID. |
| 781 |
*/ |
| 782 |
$twitter_site_tag_value = apply_filters( 'jetpack_sharing_twitter_via', $twitter_site_tag_value, $post->ID ); |
| 783 |
|
| 784 |
// Strip out anything other than a letter, number, or underscore. |
| 785 |
// This will prevent the inadvertent inclusion of an extra @, as well as normalizing the handle. |
| 786 |
return preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value ); |
| 787 |
} |
| 788 |
|
| 789 |
/** |
| 790 |
* Determine the 'related' Twitter accounts for a post. |
| 791 |
* |
| 792 |
* @param WP_Post|int $post Post object or post ID. |
| 793 |
* @return string Comma-separated list of Twitter handles. |
| 794 |
**/ |
| 795 |
public static function get_related_accounts( $post ) { |
| 796 |
$post = get_post( $post ); |
| 797 |
/** |
| 798 |
* Filter the list of related Twitter accounts added to the Twitter sharing button. |
| 799 |
* |
| 800 |
* @module sharedaddy |
| 801 |
* |
| 802 |
* @since 1.7.0 |
| 803 |
* |
| 804 |
* @param array $args Array of Twitter usernames. Format is 'username' => 'Optional description' |
| 805 |
* @param int $post->ID Post ID. |
| 806 |
*/ |
| 807 |
$related_accounts = apply_filters( 'jetpack_sharing_twitter_related', array(), $post->ID ); |
| 808 |
|
| 809 |
// Example related string: account1,account2:Account 2 description,account3 |
| 810 |
$related = array(); |
| 811 |
|
| 812 |
foreach ( $related_accounts as $related_account_username => $related_account_description ) { |
| 813 |
// Join the description onto the end of the username |
| 814 |
if ( $related_account_description ) { |
| 815 |
$related_account_username .= ':' . $related_account_description; |
| 816 |
} |
| 817 |
|
| 818 |
$related[] = $related_account_username; |
| 819 |
} |
| 820 |
|
| 821 |
return implode( ',', $related ); |
| 822 |
} |
| 823 |
|
| 824 |
public function get_display( $post ) { |
| 825 |
$via = $this->sharing_twitter_via( $post ); |
| 826 |
|
| 827 |
if ( $via ) { |
| 828 |
$via = 'data-via="' . esc_attr( $via ) . '"'; |
| 829 |
} else { |
| 830 |
$via = ''; |
| 831 |
} |
| 832 |
|
| 833 |
$related = $this->get_related_accounts( $post ); |
| 834 |
if ( ! empty( $related ) && $related !== $via ) { |
| 835 |
$related = 'data-related="' . esc_attr( $related ) . '"'; |
| 836 |
} else { |
| 837 |
$related = ''; |
| 838 |
} |
| 839 |
|
| 840 |
if ( $this->smart ) { |
| 841 |
$share_url = $this->get_share_url( $post->ID ); |
| 842 |
$post_title = $this->get_share_title( $post->ID ); |
| 843 |
return sprintf( |
| 844 |
'<a href="https://twitter.com/share" class="twitter-share-button" data-url="%1$s" data-text="%2$s" %3$s %4$s>Tweet</a>', |
| 845 |
esc_url( $share_url ), |
| 846 |
esc_attr( $post_title ), |
| 847 |
$via, |
| 848 |
$related |
| 849 |
); |
| 850 |
} else { |
| 851 |
if ( |
| 852 |
/** |
| 853 |
* Allow plugins to disable sharing counts for specific sharing services. |
| 854 |
* |
| 855 |
* @module sharedaddy |
| 856 |
* |
| 857 |
* @since 3.0.0 |
| 858 |
* |
| 859 |
* @param bool true Should sharing counts be enabled for this specific service. Default to true. |
| 860 |
* @param int $post->ID Post ID. |
| 861 |
* @param string $str Sharing service name. |
| 862 |
*/ |
| 863 |
apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' ) |
| 864 |
) { |
| 865 |
sharing_register_post_for_share_counts( $post->ID ); |
| 866 |
} |
| 867 |
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 ); |
| 868 |
} |
| 869 |
} |
| 870 |
|
| 871 |
public function process_request( $post, array $post_data ) { |
| 872 |
$post_title = $this->get_share_title( $post->ID ); |
| 873 |
$post_link = $this->get_share_url( $post->ID ); |
| 874 |
|
| 875 |
if ( function_exists( 'mb_stripos' ) ) { |
| 876 |
$strlen = 'mb_strlen'; |
| 877 |
$substr = 'mb_substr'; |
| 878 |
} else { |
| 879 |
$strlen = 'strlen'; |
| 880 |
$substr = 'substr'; |
| 881 |
} |
| 882 |
|
| 883 |
$via = $this->sharing_twitter_via( $post ); |
| 884 |
$related = $this->get_related_accounts( $post ); |
| 885 |
if ( $via ) { |
| 886 |
$sig = " via @$via"; |
| 887 |
if ( $related === $via ) { |
| 888 |
$related = false; |
| 889 |
} |
| 890 |
} else { |
| 891 |
$via = false; |
| 892 |
$sig = ''; |
| 893 |
} |
| 894 |
|
| 895 |
$suffix_length = $this->short_url_length + $strlen( $sig ); |
| 896 |
// $sig is handled by twitter in their 'via' argument. |
| 897 |
// $post_link is handled by twitter in their 'url' argument. |
| 898 |
if ( 280 < $strlen( $post_title ) + $suffix_length ) { |
| 899 |
// The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis. |
| 900 |
$text = $substr( $post_title, 0, 280 - $suffix_length - 1 ) . "\xE2\x80\xA6"; |
| 901 |
} else { |
| 902 |
$text = $post_title; |
| 903 |
} |
| 904 |
|
| 905 |
// Record stats |
| 906 |
parent::process_request( $post, $post_data ); |
| 907 |
|
| 908 |
$url = $post_link; |
| 909 |
$twitter_url = add_query_arg( |
| 910 |
rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ), |
| 911 |
'https://twitter.com/intent/tweet' |
| 912 |
); |
| 913 |
|
| 914 |
// Redirect to Twitter |
| 915 |
wp_redirect( $twitter_url ); |
| 916 |
die(); |
| 917 |
} |
| 918 |
|
| 919 |
public function has_custom_button_style() { |
| 920 |
return $this->smart; |
| 921 |
} |
| 922 |
|
| 923 |
public function display_footer() { |
| 924 |
if ( $this->smart ) { |
| 925 |
?> |
| 926 |
<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> |
| 927 |
<?php |
| 928 |
} else { |
| 929 |
$this->js_dialog( $this->shortname, array( 'height' => 350 ) ); |
| 930 |
} |
| 931 |
} |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
class Share_Reddit extends Sharing_Source { |
| 936 |
public $shortname = 'reddit'; |
| 937 |
public $icon = '\f222'; |
| 938 |
public function __construct( $id, array $settings ) { |
| 939 |
parent::__construct( $id, $settings ); |
| 940 |
|
| 941 |
if ( 'official' == $this->button_style ) { |
| 942 |
$this->smart = true; |
| 943 |
} else { |
| 944 |
$this->smart = false; |
| 945 |
} |
| 946 |
} |
| 947 |
|
| 948 |
public function get_name() { |
| 949 |
return __( 'Reddit', 'jetpack' ); |
| 950 |
} |
| 951 |
|
| 952 |
public function get_display( $post ) { |
| 953 |
if ( $this->smart ) { |
| 954 |
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>'; |
| 955 |
} else { |
| 956 |
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' ); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
/** |
| 961 |
* AMP display for Reddit. |
| 962 |
* |
| 963 |
* @param \WP_Post $post The current post being viewed. |
| 964 |
*/ |
| 965 |
public function get_amp_display( $post ) { |
| 966 |
$attrs = array( |
| 967 |
'data-share-endpoint' => esc_url_raw( 'https://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) ), |
| 968 |
); |
| 969 |
|
| 970 |
return $this->build_amp_markup( $attrs ); |
| 971 |
} |
| 972 |
|
| 973 |
public function process_request( $post, array $post_data ) { |
| 974 |
$reddit_url = $this->http() . '://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ); |
| 975 |
|
| 976 |
// Record stats |
| 977 |
parent::process_request( $post, $post_data ); |
| 978 |
|
| 979 |
// Redirect to Reddit |
| 980 |
wp_redirect( $reddit_url ); |
| 981 |
die(); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
class Share_LinkedIn extends Sharing_Source { |
| 986 |
public $shortname = 'linkedin'; |
| 987 |
public $icon = '\f207'; |
| 988 |
public function __construct( $id, array $settings ) { |
| 989 |
parent::__construct( $id, $settings ); |
| 990 |
|
| 991 |
if ( 'official' == $this->button_style ) { |
| 992 |
$this->smart = true; |
| 993 |
} else { |
| 994 |
$this->smart = false; |
| 995 |
} |
| 996 |
} |
| 997 |
|
| 998 |
public function get_name() { |
| 999 |
return __( 'LinkedIn', 'jetpack' ); |
| 1000 |
} |
| 1001 |
|
| 1002 |
public function has_custom_button_style() { |
| 1003 |
return $this->smart; |
| 1004 |
} |
| 1005 |
|
| 1006 |
public function get_display( $post ) { |
| 1007 |
$display = ''; |
| 1008 |
|
| 1009 |
if ( $this->smart ) { |
| 1010 |
$share_url = $this->get_share_url( $post->ID ); |
| 1011 |
$display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) ); |
| 1012 |
} else { |
| 1013 |
$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 ); |
| 1014 |
} |
| 1015 |
|
| 1016 |
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 1017 |
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
| 1018 |
sharing_register_post_for_share_counts( $post->ID ); |
| 1019 |
} |
| 1020 |
|
| 1021 |
return $display; |
| 1022 |
} |
| 1023 |
|
| 1024 |
public function process_request( $post, array $post_data ) { |
| 1025 |
|
| 1026 |
$post_link = $this->get_share_url( $post->ID ); |
| 1027 |
|
| 1028 |
// Using the same URL as the official button, which is *not* LinkedIn's documented sharing link |
| 1029 |
// https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false |
| 1030 |
$linkedin_url = add_query_arg( array( |
| 1031 |
'url' => rawurlencode( $post_link ), |
| 1032 |
), 'https://www.linkedin.com/cws/share?token=&isFramed=false' ); |
| 1033 |
|
| 1034 |
// Record stats |
| 1035 |
parent::process_request( $post, $post_data ); |
| 1036 |
|
| 1037 |
// Redirect to LinkedIn |
| 1038 |
wp_redirect( $linkedin_url ); |
| 1039 |
die(); |
| 1040 |
} |
| 1041 |
|
| 1042 |
public function display_footer() { |
| 1043 |
if ( ! $this->smart ) { |
| 1044 |
$this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) ); |
| 1045 |
} else { |
| 1046 |
?> |
| 1047 |
<script type="text/javascript"> |
| 1048 |
( function () { |
| 1049 |
var currentScript = document.currentScript; |
| 1050 |
|
| 1051 |
// Helper function to load an external script. |
| 1052 |
function loadScript( url, cb ) { |
| 1053 |
var script = document.createElement( 'script' ); |
| 1054 |
var prev = currentScript || document.getElementsByTagName( 'script' )[ 0 ]; |
| 1055 |
script.setAttribute( 'async', true ); |
| 1056 |
script.setAttribute( 'src', url ); |
| 1057 |
prev.parentNode.insertBefore( script, prev ); |
| 1058 |
script.addEventListener( 'load', cb ); |
| 1059 |
} |
| 1060 |
|
| 1061 |
function init() { |
| 1062 |
loadScript( 'https://platform.linkedin.com/in.js?async=true', function () { |
| 1063 |
if ( typeof IN !== 'undefined' ) { |
| 1064 |
IN.init(); |
| 1065 |
} |
| 1066 |
} ); |
| 1067 |
} |
| 1068 |
|
| 1069 |
if ( document.readyState === 'loading' ) { |
| 1070 |
document.addEventListener( 'DOMContentLoaded', init ); |
| 1071 |
} else { |
| 1072 |
init(); |
| 1073 |
} |
| 1074 |
|
| 1075 |
document.body.addEventListener( 'is.post-load', function() { |
| 1076 |
if ( typeof IN !== 'undefined' ) { |
| 1077 |
IN.parse(); |
| 1078 |
} |
| 1079 |
} ); |
| 1080 |
} )(); |
| 1081 |
</script> |
| 1082 |
<?php |
| 1083 |
} |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1087 |
class Share_Facebook extends Sharing_Source { |
| 1088 |
public $shortname = 'facebook'; |
| 1089 |
public $icon = '\f204'; |
| 1090 |
private $share_type = 'default'; |
| 1091 |
|
| 1092 |
public function __construct( $id, array $settings ) { |
| 1093 |
parent::__construct( $id, $settings ); |
| 1094 |
|
| 1095 |
if ( isset( $settings['share_type'] ) ) { |
| 1096 |
$this->share_type = $settings['share_type']; |
| 1097 |
} |
| 1098 |
|
| 1099 |
if ( 'official' == $this->button_style ) { |
| 1100 |
$this->smart = true; |
| 1101 |
} else { |
| 1102 |
$this->smart = false; |
| 1103 |
} |
| 1104 |
} |
| 1105 |
|
| 1106 |
public function get_name() { |
| 1107 |
return __( 'Facebook', 'jetpack' ); |
| 1108 |
} |
| 1109 |
|
| 1110 |
public function display_header() { |
| 1111 |
} |
| 1112 |
|
| 1113 |
function guess_locale_from_lang( $lang ) { |
| 1114 |
if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
| 1115 |
return 'en_US'; |
| 1116 |
} |
| 1117 |
|
| 1118 |
if ( ! class_exists( 'GP_Locales' ) ) { |
| 1119 |
if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
| 1120 |
return false; |
| 1121 |
} |
| 1122 |
|
| 1123 |
require JETPACK__GLOTPRESS_LOCALES_PATH; |
| 1124 |
} |
| 1125 |
|
| 1126 |
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 1127 |
// WP.com: get_locale() returns 'it' |
| 1128 |
$locale = GP_Locales::by_slug( $lang ); |
| 1129 |
} else { |
| 1130 |
// Jetpack: get_locale() returns 'it_IT'; |
| 1131 |
$locale = GP_Locales::by_field( 'wp_locale', $lang ); |
| 1132 |
} |
| 1133 |
|
| 1134 |
if ( ! $locale ) { |
| 1135 |
return false; |
| 1136 |
} |
| 1137 |
|
| 1138 |
if ( empty( $locale->facebook_locale ) ) { |
| 1139 |
if ( empty( $locale->wp_locale ) ) { |
| 1140 |
return false; |
| 1141 |
} else { |
| 1142 |
// Facebook SDK is smart enough to fall back to en_US if a |
| 1143 |
// locale isn't supported. Since supported Facebook locales |
| 1144 |
// can fall out of sync, we'll attempt to use the known |
| 1145 |
// wp_locale value and rely on said fallback. |
| 1146 |
return $locale->wp_locale; |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
return $locale->facebook_locale; |
| 1151 |
} |
| 1152 |
|
| 1153 |
public function get_display( $post ) { |
| 1154 |
if ( $this->smart ) { |
| 1155 |
$share_url = $this->get_share_url( $post->ID ); |
| 1156 |
$fb_share_html = '<div class="fb-share-button" data-href="' . esc_attr( $share_url ) . '" data-layout="button_count"></div>'; |
| 1157 |
/** |
| 1158 |
* Filter the output of the Facebook Sharing button. |
| 1159 |
* |
| 1160 |
* @module sharedaddy |
| 1161 |
* |
| 1162 |
* @since 3.6.0 |
| 1163 |
* |
| 1164 |
* @param string $fb_share_html Facebook Sharing button HTML. |
| 1165 |
* @param string $share_url URL of the post to share. |
| 1166 |
*/ |
| 1167 |
return apply_filters( 'jetpack_sharing_facebook_official_button_output', $fb_share_html, $share_url ); |
| 1168 |
} |
| 1169 |
|
| 1170 |
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 1171 |
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) { |
| 1172 |
sharing_register_post_for_share_counts( $post->ID ); |
| 1173 |
} |
| 1174 |
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 ); |
| 1175 |
} |
| 1176 |
|
| 1177 |
/** |
| 1178 |
* AMP display for Facebook. |
| 1179 |
* |
| 1180 |
* @param \WP_Post $post The current post being viewed. |
| 1181 |
*/ |
| 1182 |
public function get_amp_display( $post ) { |
| 1183 |
$attrs = array( |
| 1184 |
/** This filter is documented in modules/sharedaddy/sharing-sources.php */ |
| 1185 |
'data-param-app_id' => apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ), |
| 1186 |
); |
| 1187 |
|
| 1188 |
return $this->build_amp_markup( $attrs ); |
| 1189 |
} |
| 1190 |
|
| 1191 |
public function process_request( $post, array $post_data ) { |
| 1192 |
$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 ) ); |
| 1193 |
|
| 1194 |
// Record stats |
| 1195 |
parent::process_request( $post, $post_data ); |
| 1196 |
|
| 1197 |
// Redirect to Facebook |
| 1198 |
wp_redirect( $fb_url ); |
| 1199 |
die(); |
| 1200 |
} |
| 1201 |
|
| 1202 |
public function display_footer() { |
| 1203 |
$this->js_dialog( $this->shortname ); |
| 1204 |
if ( $this->smart ) { |
| 1205 |
$locale = $this->guess_locale_from_lang( get_locale() ); |
| 1206 |
if ( ! $locale ) { |
| 1207 |
$locale = 'en_US'; |
| 1208 |
} |
| 1209 |
/** |
| 1210 |
* Filter the App ID used in the official Facebook Share button. |
| 1211 |
* |
| 1212 |
* @since 3.8.0 |
| 1213 |
* |
| 1214 |
* @param int $fb_app_id Facebook App ID. Default to 249643311490 (WordPress.com's App ID). |
| 1215 |
*/ |
| 1216 |
$fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
| 1217 |
if ( is_numeric( $fb_app_id ) ) { |
| 1218 |
$fb_app_id = '&appId=' . $fb_app_id; |
| 1219 |
} else { |
| 1220 |
$fb_app_id = ''; |
| 1221 |
} |
| 1222 |
?><div id="fb-root"></div> |
| 1223 |
<script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = 'https://connect.facebook.net/<?php echo $locale; ?>/sdk.js#xfbml=1<?php echo $fb_app_id; ?>&version=v2.3'; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> |
| 1224 |
<script> |
| 1225 |
document.body.addEventListener( 'is.post-load', function() { |
| 1226 |
if ( 'undefined' !== typeof FB ) { |
| 1227 |
FB.XFBML.parse(); |
| 1228 |
} |
| 1229 |
} ); |
| 1230 |
</script> |
| 1231 |
<?php |
| 1232 |
} |
| 1233 |
} |
| 1234 |
} |
| 1235 |
|
| 1236 |
class Share_Print extends Sharing_Source { |
| 1237 |
public $shortname = 'print'; |
| 1238 |
public $icon = '\f469'; |
| 1239 |
public function __construct( $id, array $settings ) { |
| 1240 |
parent::__construct( $id, $settings ); |
| 1241 |
|
| 1242 |
if ( 'official' == $this->button_style ) { |
| 1243 |
$this->smart = true; |
| 1244 |
} else { |
| 1245 |
$this->smart = false; |
| 1246 |
} |
| 1247 |
} |
| 1248 |
|
| 1249 |
public function get_name() { |
| 1250 |
return __( 'Print', 'jetpack' ); |
| 1251 |
} |
| 1252 |
|
| 1253 |
public function get_display( $post ) { |
| 1254 |
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' ) ); |
| 1255 |
} |
| 1256 |
|
| 1257 |
/** |
| 1258 |
* AMP display for Print. |
| 1259 |
* |
| 1260 |
* @param \WP_Post $post The current post being viewed. |
| 1261 |
*/ |
| 1262 |
public function get_amp_display( $post ) { |
| 1263 |
if ( empty( $post ) ) { |
| 1264 |
return false; |
| 1265 |
} |
| 1266 |
|
| 1267 |
return '<button class="amp-social-share print" on="tap:AMP.print">Print</button>'; |
| 1268 |
} |
| 1269 |
} |
| 1270 |
|
| 1271 |
class Share_PressThis extends Sharing_Source { |
| 1272 |
public $shortname = 'pressthis'; |
| 1273 |
public $icon = '\f205'; |
| 1274 |
public function __construct( $id, array $settings ) { |
| 1275 |
parent::__construct( $id, $settings ); |
| 1276 |
|
| 1277 |
if ( 'official' == $this->button_style ) { |
| 1278 |
$this->smart = true; |
| 1279 |
} else { |
| 1280 |
$this->smart = false; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
public function get_name() { |
| 1285 |
return __( 'Press This', 'jetpack' ); |
| 1286 |
} |
| 1287 |
|
| 1288 |
public function process_request( $post, array $post_data ) { |
| 1289 |
global $current_user; |
| 1290 |
|
| 1291 |
$primary_blog = (int) get_user_meta( $current_user->ID, 'primary_blog', true ); |
| 1292 |
if ( $primary_blog ) { |
| 1293 |
$primary_blog_details = get_blog_details( $primary_blog ); |
| 1294 |
} else { |
| 1295 |
$primary_blog_details = false; |
| 1296 |
} |
| 1297 |
|
| 1298 |
if ( $primary_blog_details ) { |
| 1299 |
$blogs = array( $primary_blog_details ); |
| 1300 |
} elseif ( function_exists( 'get_active_blogs_for_user' ) ) { |
| 1301 |
$blogs = get_active_blogs_for_user(); |
| 1302 |
if ( empty( $blogs ) ) { |
| 1303 |
$blogs = get_blogs_of_user( $current_user->ID ); |
| 1304 |
} |
| 1305 |
} else { |
| 1306 |
$blogs = get_blogs_of_user( $current_user->ID ); |
| 1307 |
} |
| 1308 |
|
| 1309 |
if ( empty( $blogs ) ) { |
| 1310 |
wp_safe_redirect( get_permalink( $post->ID ) ); |
| 1311 |
die(); |
| 1312 |
} |
| 1313 |
|
| 1314 |
$blog = current( $blogs ); |
| 1315 |
|
| 1316 |
$args = array( |
| 1317 |
'u' => rawurlencode( $this->get_share_url( $post->ID ) ), |
| 1318 |
); |
| 1319 |
|
| 1320 |
$args[ 'url-scan-submit' ] = 'Scan'; |
| 1321 |
$args[ '_wpnonce' ] = wp_create_nonce( 'scan-site' ); |
| 1322 |
|
| 1323 |
$url = $blog->siteurl . '/wp-admin/press-this.php'; |
| 1324 |
$url = add_query_arg( $args, $url ); |
| 1325 |
|
| 1326 |
// Record stats |
| 1327 |
parent::process_request( $post, $post_data ); |
| 1328 |
|
| 1329 |
// Redirect to Press This |
| 1330 |
wp_redirect( $url ); |
| 1331 |
die(); |
| 1332 |
} |
| 1333 |
|
| 1334 |
public function get_display( $post ) { |
| 1335 |
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' ); |
| 1336 |
} |
| 1337 |
|
| 1338 |
/** |
| 1339 |
* No AMP display for PressThis. |
| 1340 |
* |
| 1341 |
* @param \WP_Post $post The current post being viewed. |
| 1342 |
*/ |
| 1343 |
public function get_amp_display( $post ) { // phpcs:ignore |
| 1344 |
return false; |
| 1345 |
} |
| 1346 |
} |
| 1347 |
|
| 1348 |
class Share_Custom extends Sharing_Advanced_Source { |
| 1349 |
private $name; |
| 1350 |
private $icon; |
| 1351 |
private $url; |
| 1352 |
public $smart = true; |
| 1353 |
public $shortname; |
| 1354 |
|
| 1355 |
public function get_class() { |
| 1356 |
return 'custom share-custom-' . sanitize_html_class( strtolower( $this->name ) ); |
| 1357 |
} |
| 1358 |
|
| 1359 |
public function __construct( $id, array $settings ) { |
| 1360 |
parent::__construct( $id, $settings ); |
| 1361 |
|
| 1362 |
$opts = $this->get_options(); |
| 1363 |
|
| 1364 |
if ( isset( $settings['name'] ) ) { |
| 1365 |
$this->name = $settings['name']; |
| 1366 |
$this->shortname = preg_replace( '/[^a-z0-9]*/', '', $settings['name'] ); |
| 1367 |
} |
| 1368 |
|
| 1369 |
if ( isset( $settings['icon'] ) ) { |
| 1370 |
$this->icon = $settings['icon']; |
| 1371 |
|
| 1372 |
$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) ); |
| 1373 |
$i = 0; |
| 1374 |
while ( $new_icon != $this->icon ) { |
| 1375 |
if ( $i > 5 ) { |
| 1376 |
$this->icon = false; |
| 1377 |
break; |
| 1378 |
} else { |
| 1379 |
$this->icon = $new_icon; |
| 1380 |
$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) ); |
| 1381 |
} |
| 1382 |
$i++; |
| 1383 |
} |
| 1384 |
} |
| 1385 |
|
| 1386 |
if ( isset( $settings['url'] ) ) { |
| 1387 |
$this->url = $settings['url']; |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
public function get_name() { |
| 1392 |
return $this->name; |
| 1393 |
} |
| 1394 |
|
| 1395 |
public function get_display( $post ) { |
| 1396 |
$str = $this->get_link( $this->get_process_request_url( $post->ID ), esc_html( $this->name ), sprintf( __( 'Click to share on %s', 'jetpack' ), esc_attr( $this->name ) ), 'share=' . $this->id ); |
| 1397 |
return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str ); |
| 1398 |
} |
| 1399 |
|
| 1400 |
/** |
| 1401 |
* No AMP display for custom elements. |
| 1402 |
* |
| 1403 |
* @param \WP_Post $post The current post being viewed. |
| 1404 |
*/ |
| 1405 |
public function get_amp_display( $post ) { // phpcs:ignore |
| 1406 |
return false; |
| 1407 |
} |
| 1408 |
|
| 1409 |
public function process_request( $post, array $post_data ) { |
| 1410 |
$url = str_replace( '&', '&', $this->url ); |
| 1411 |
$url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url ); |
| 1412 |
$url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url ); |
| 1413 |
$url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url ); |
| 1414 |
$url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url ); |
| 1415 |
$url = str_replace( '%home_url%', rawurlencode( home_url() ), $url ); |
| 1416 |
$url = str_replace( '%post_slug%', rawurlencode( $post->post_name ), $url ); |
| 1417 |
|
| 1418 |
if ( strpos( $url, '%post_tags%' ) !== false ) { |
| 1419 |
$tags = get_the_tags( $post->ID ); |
| 1420 |
$tagged = ''; |
| 1421 |
|
| 1422 |
if ( $tags ) { |
| 1423 |
$tagged_raw = array(); |
| 1424 |
foreach ( $tags as $tag ) { |
| 1425 |
$tagged_raw[] = rawurlencode( $tag->name ); |
| 1426 |
} |
| 1427 |
|
| 1428 |
$tagged = implode( ',', $tagged_raw ); |
| 1429 |
} |
| 1430 |
|
| 1431 |
$url = str_replace( '%post_tags%', $tagged, $url ); |
| 1432 |
} |
| 1433 |
|
| 1434 |
if ( strpos( $url, '%post_excerpt%' ) !== false ) { |
| 1435 |
$url_excerpt = $post->post_excerpt; |
| 1436 |
if ( empty( $url_excerpt ) ) { |
| 1437 |
$url_excerpt = $post->post_content; |
| 1438 |
} |
| 1439 |
|
| 1440 |
$url_excerpt = strip_tags( strip_shortcodes( $url_excerpt ) ); |
| 1441 |
$url_excerpt = wp_html_excerpt( $url_excerpt, 100 ); |
| 1442 |
$url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) ); |
| 1443 |
$url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url ); |
| 1444 |
} |
| 1445 |
|
| 1446 |
// Record stats |
| 1447 |
parent::process_request( $post, $post_data ); |
| 1448 |
|
| 1449 |
// Redirect |
| 1450 |
wp_redirect( $url ); |
| 1451 |
die(); |
| 1452 |
} |
| 1453 |
|
| 1454 |
public function display_options() { |
| 1455 |
?> |
| 1456 |
<div class="input"> |
| 1457 |
<table class="form-table"> |
| 1458 |
<tbody> |
| 1459 |
<tr> |
| 1460 |
<th scope="row"><?php _e( 'Label', 'jetpack' ); ?></th> |
| 1461 |
<td><input type="text" name="name" value="<?php echo esc_attr( $this->name ); ?>" /></td> |
| 1462 |
</tr> |
| 1463 |
|
| 1464 |
<tr> |
| 1465 |
<th scope="row"><?php _e( 'URL', 'jetpack' ); ?></th> |
| 1466 |
<td><input type="text" name="url" value="<?php echo esc_attr( $this->url ); ?>" /></td> |
| 1467 |
</tr> |
| 1468 |
|
| 1469 |
<tr> |
| 1470 |
<th scope="row"><?php _e( 'Icon', 'jetpack' ); ?></th> |
| 1471 |
<td><input type="text" name="icon" value="<?php echo esc_attr( $this->icon ); ?>" /></td> |
| 1472 |
</tr> |
| 1473 |
|
| 1474 |
<tr> |
| 1475 |
<th scope="row"></th> |
| 1476 |
<td> |
| 1477 |
<input class="button-secondary" type="submit" value="<?php esc_attr_e( 'Save', 'jetpack' ); ?>" /> |
| 1478 |
<a href="#" class="remove"><small><?php _e( 'Remove Service', 'jetpack' ); ?></small></a> |
| 1479 |
</td> |
| 1480 |
</tr> |
| 1481 |
</tbody> |
| 1482 |
</table> |
| 1483 |
</div> |
| 1484 |
<?php |
| 1485 |
} |
| 1486 |
|
| 1487 |
public function update_options( array $data ) { |
| 1488 |
$name = trim( wp_html_excerpt( wp_kses( stripslashes( $data['name'] ), array() ), 30 ) ); |
| 1489 |
$url = trim( esc_url_raw( $data['url'] ) ); |
| 1490 |
$icon = trim( esc_url_raw( $data['icon'] ) ); |
| 1491 |
|
| 1492 |
if ( $name ) { |
| 1493 |
$this->name = $name; |
| 1494 |
} |
| 1495 |
|
| 1496 |
if ( $url ) { |
| 1497 |
$this->url = $url; |
| 1498 |
} |
| 1499 |
|
| 1500 |
if ( $icon ) { |
| 1501 |
$this->icon = $icon; |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
public function get_options() { |
| 1506 |
return array( |
| 1507 |
'name' => $this->name, |
| 1508 |
'icon' => $this->icon, |
| 1509 |
'url' => $this->url, |
| 1510 |
); |
| 1511 |
} |
| 1512 |
|
| 1513 |
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
| 1514 |
$opts = $this->get_options(); |
| 1515 |
|
| 1516 |
$text = ' '; |
| 1517 |
if ( ! $this->smart ) { |
| 1518 |
if ( $this->button_style != 'icon' ) { |
| 1519 |
$text = $this->get_name(); |
| 1520 |
} |
| 1521 |
} |
| 1522 |
|
| 1523 |
$klasses = array( 'share-' . $this->shortname ); |
| 1524 |
|
| 1525 |
if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' ) { |
| 1526 |
$klasses[] = 'share-icon'; |
| 1527 |
} |
| 1528 |
|
| 1529 |
if ( $this->button_style == 'icon' ) { |
| 1530 |
$text = ''; |
| 1531 |
$klasses[] = 'no-text'; |
| 1532 |
} |
| 1533 |
|
| 1534 |
if ( $this->button_style == 'text' ) { |
| 1535 |
$klasses[] = 'no-icon'; |
| 1536 |
} |
| 1537 |
|
| 1538 |
$link = sprintf( |
| 1539 |
'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span style="background-image:url("%s") !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>', |
| 1540 |
implode( ' ', $klasses ), |
| 1541 |
$this->get_name(), |
| 1542 |
addcslashes( esc_url_raw( $opts['icon'] ), '"' ), |
| 1543 |
$text |
| 1544 |
); |
| 1545 |
?> |
| 1546 |
<div class="option option-smart-off"> |
| 1547 |
<?php echo $link ; ?> |
| 1548 |
</div><?php |
| 1549 |
} |
| 1550 |
} |
| 1551 |
|
| 1552 |
class Share_Tumblr extends Sharing_Source { |
| 1553 |
public $shortname = 'tumblr'; |
| 1554 |
public $icon = '\f214'; |
| 1555 |
public function __construct( $id, array $settings ) { |
| 1556 |
parent::__construct( $id, $settings ); |
| 1557 |
if ( 'official' == $this->button_style ) { |
| 1558 |
$this->smart = true; |
| 1559 |
} else { |
| 1560 |
$this->smart = false; |
| 1561 |
} |
| 1562 |
} |
| 1563 |
|
| 1564 |
public function get_name() { |
| 1565 |
return __( 'Tumblr', 'jetpack' ); |
| 1566 |
} |
| 1567 |
|
| 1568 |
public function get_display( $post ) { |
| 1569 |
if ( $this->smart ) { |
| 1570 |
$target = ''; |
| 1571 |
if ( true == $this->open_link_in_new ) { |
| 1572 |
$target = '_blank'; |
| 1573 |
} |
| 1574 |
|
| 1575 |
/** |
| 1576 |
* If we are looking at a single post, let Tumblr figure out the post type (text, photo, link, quote, chat, or video) |
| 1577 |
* based on the content available on the page. |
| 1578 |
* If we are not looking at a single post, content from other posts can appear on the page and Tumblr will pick that up. |
| 1579 |
* 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. |
| 1580 |
*/ |
| 1581 |
if ( ! is_single() ) { |
| 1582 |
$posttype = 'data-posttype="link"'; |
| 1583 |
} else { |
| 1584 |
$posttype = ''; |
| 1585 |
} |
| 1586 |
|
| 1587 |
// Documentation: https://www.tumblr.com/docs/en/share_button |
| 1588 |
return sprintf( |
| 1589 |
'<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>', |
| 1590 |
$target, |
| 1591 |
'https://www.tumblr.com/share', |
| 1592 |
$this->get_share_title( $post->ID ), |
| 1593 |
$this->get_share_url( $post->ID ), |
| 1594 |
__( 'Share on Tumblr', 'jetpack' ), |
| 1595 |
$posttype |
| 1596 |
); |
| 1597 |
} else { |
| 1598 |
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' ); |
| 1599 |
} |
| 1600 |
} |
| 1601 |
|
| 1602 |
public function process_request( $post, array $post_data ) { |
| 1603 |
// Record stats |
| 1604 |
parent::process_request( $post, $post_data ); |
| 1605 |
|
| 1606 |
// Redirect to Tumblr's sharing endpoint (a la their bookmarklet) |
| 1607 |
$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='; |
| 1608 |
wp_redirect( $url ); |
| 1609 |
die(); |
| 1610 |
} |
| 1611 |
|
| 1612 |
public function display_footer() { |
| 1613 |
if ( $this->smart ) { |
| 1614 |
?><script id="tumblr-js" type="text/javascript" src="https://assets.tumblr.com/share-button.js"></script><?php |
| 1615 |
} else { |
| 1616 |
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
| 1617 |
} |
| 1618 |
} |
| 1619 |
} |
| 1620 |
|
| 1621 |
class Share_Pinterest extends Sharing_Source { |
| 1622 |
public $shortname = 'pinterest'; |
| 1623 |
public $icon = '\f209'; |
| 1624 |
|
| 1625 |
public function __construct( $id, array $settings ) { |
| 1626 |
parent::__construct( $id, $settings ); |
| 1627 |
if ( 'official' == $this->button_style ) { |
| 1628 |
$this->smart = true; |
| 1629 |
} else { |
| 1630 |
$this->smart = false; |
| 1631 |
} |
| 1632 |
} |
| 1633 |
|
| 1634 |
public function get_name() { |
| 1635 |
return __( 'Pinterest', 'jetpack' ); |
| 1636 |
} |
| 1637 |
|
| 1638 |
public function get_image( $post ) { |
| 1639 |
if ( class_exists( 'Jetpack_PostImages' ) ) { |
| 1640 |
$image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) ); |
| 1641 |
if ( ! empty( $image ) ) { |
| 1642 |
return $image['src']; |
| 1643 |
} |
| 1644 |
} |
| 1645 |
|
| 1646 |
/** |
| 1647 |
* Filters the default image used by the Pinterest Pin It share button. |
| 1648 |
* |
| 1649 |
* @module sharedaddy |
| 1650 |
* |
| 1651 |
* @since 3.6.0 |
| 1652 |
* |
| 1653 |
* @param string $url Default image URL. |
| 1654 |
*/ |
| 1655 |
return apply_filters( 'jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg' ); |
| 1656 |
} |
| 1657 |
|
| 1658 |
public function get_external_url( $post ) { |
| 1659 |
$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 ); |
| 1660 |
|
| 1661 |
/** |
| 1662 |
* Filters the Pinterest share URL used in sharing button output. |
| 1663 |
* |
| 1664 |
* @module sharedaddy |
| 1665 |
* |
| 1666 |
* @since 3.6.0 |
| 1667 |
* |
| 1668 |
* @param string $url Pinterest share URL. |
| 1669 |
*/ |
| 1670 |
return apply_filters( 'jetpack_sharing_pinterest_share_url', $url ); |
| 1671 |
} |
| 1672 |
|
| 1673 |
public function get_widget_type() { |
| 1674 |
/** |
| 1675 |
* Filters the Pinterest widget type. |
| 1676 |
* |
| 1677 |
* @see https://business.pinterest.com/en/widget-builder |
| 1678 |
* |
| 1679 |
* @module sharedaddy |
| 1680 |
* |
| 1681 |
* @since 3.6.0 |
| 1682 |
* |
| 1683 |
* @param string $type Pinterest widget type. Default of 'buttonPin' for single-image selection. 'buttonBookmark' for multi-image modal. |
| 1684 |
*/ |
| 1685 |
return apply_filters( 'jetpack_sharing_pinterest_widget_type', 'buttonPin' ); |
| 1686 |
} |
| 1687 |
|
| 1688 |
public function get_display( $post ) { |
| 1689 |
$display = ''; |
| 1690 |
|
| 1691 |
if ( $this->smart ) { |
| 1692 |
$display = sprintf( |
| 1693 |
'<div class="pinterest_button"><a href="%s" data-pin-do="%s" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>', |
| 1694 |
esc_url( $this->get_external_url( $post ) ), |
| 1695 |
esc_attr( $this->get_widget_type() ) |
| 1696 |
); |
| 1697 |
} else { |
| 1698 |
$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 ); |
| 1699 |
} |
| 1700 |
|
| 1701 |
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 1702 |
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
| 1703 |
sharing_register_post_for_share_counts( $post->ID ); |
| 1704 |
} |
| 1705 |
|
| 1706 |
return $display; |
| 1707 |
} |
| 1708 |
|
| 1709 |
public function process_request( $post, array $post_data ) { |
| 1710 |
// Record stats |
| 1711 |
parent::process_request( $post, $post_data ); |
| 1712 |
// If we're triggering the multi-select panel, then we don't need to redirect to Pinterest |
| 1713 |
if ( ! isset( $_GET['js_only'] ) ) { |
| 1714 |
$pinterest_url = esc_url_raw( $this->get_external_url( $post ) ); |
| 1715 |
wp_redirect( $pinterest_url ); |
| 1716 |
} else { |
| 1717 |
echo '// share count bumped'; |
| 1718 |
} |
| 1719 |
die(); |
| 1720 |
} |
| 1721 |
|
| 1722 |
public function display_footer() { |
| 1723 |
/** |
| 1724 |
* Filter the Pin it button appearing when hovering over images when using the official button style. |
| 1725 |
* |
| 1726 |
* @module sharedaddy |
| 1727 |
* |
| 1728 |
* @since 3.6.0 |
| 1729 |
* |
| 1730 |
* @param bool $jetpack_pinit_over True by default, displays the Pin it button when hovering over images. |
| 1731 |
*/ |
| 1732 |
$jetpack_pinit_over = apply_filters( 'jetpack_pinit_over_button', true ); |
| 1733 |
?> |
| 1734 |
<?php if ( $this->smart ) : ?> |
| 1735 |
<script type="text/javascript"> |
| 1736 |
( function () { |
| 1737 |
// Pinterest shared resources |
| 1738 |
var s = document.createElement( 'script' ); |
| 1739 |
s.type = 'text/javascript'; |
| 1740 |
s.async = true; |
| 1741 |
<?php |
| 1742 |
if ( $jetpack_pinit_over ) { |
| 1743 |
echo "s.setAttribute( 'data-pin-hover', true );"; |
| 1744 |
} |
| 1745 |
?> |
| 1746 |
s.src = window.location.protocol + '//assets.pinterest.com/js/pinit.js'; |
| 1747 |
var x = document.getElementsByTagName( 'script' )[ 0 ]; |
| 1748 |
x.parentNode.insertBefore(s, x); |
| 1749 |
// if 'Pin it' button has 'counts' make container wider |
| 1750 |
function init() { |
| 1751 |
var shares = document.querySelectorAll( 'li.share-pinterest' ); |
| 1752 |
for ( var i = 0; i < shares.length; i++ ) { |
| 1753 |
var share = shares[ i ]; |
| 1754 |
if ( share.querySelector( 'a span:visible' ) ) { |
| 1755 |
share.style.width = '80px'; |
| 1756 |
} |
| 1757 |
} |
| 1758 |
} |
| 1759 |
|
| 1760 |
if ( document.readyState !== 'complete' ) { |
| 1761 |
document.addEventListener( 'load', init ); |
| 1762 |
} else { |
| 1763 |
init(); |
| 1764 |
} |
| 1765 |
} )(); |
| 1766 |
</script> |
| 1767 |
<?php elseif ( 'buttonPin' != $this->get_widget_type() ) : ?> |
| 1768 |
<script type="text/javascript"> |
| 1769 |
( function () { |
| 1770 |
function init() { |
| 1771 |
document.body.addEventListener( 'click', function ( e ) { |
| 1772 |
if ( e.target && ( |
| 1773 |
e.target.matches && e.target.matches( 'a.share-pinterest' ) || |
| 1774 |
e.target.msMatchesSelector && e.target.msMatchesSelector( 'a.share-pinterest' ) |
| 1775 |
) ) { |
| 1776 |
e.preventDefault(); |
| 1777 |
// Load Pinterest Bookmarklet code |
| 1778 |
var s = document.createElement( 'script' ); |
| 1779 |
s.type = 'text/javascript'; |
| 1780 |
s.src = window.location.protocol + '//assets.pinterest.com/js/pinmarklet.js?r=' + ( Math.random() * 99999999 ); |
| 1781 |
var x = document.getElementsByTagName( 'script' )[ 0 ]; |
| 1782 |
x.parentNode.insertBefore( s, x ); |
| 1783 |
// Trigger Stats |
| 1784 |
var s = document.createElement( 'script' ); |
| 1785 |
s.type = 'text/javascript'; |
| 1786 |
s.src = e.target.href + ( e.target.href.indexOf( '?' ) ? '&' : '?' ) + 'js_only=1'; |
| 1787 |
var x = document.getElementsByTagName( 'script' )[ '0' ]; |
| 1788 |
x.parentNode.insertBefore( s, x ); |
| 1789 |
} |
| 1790 |
} ); |
| 1791 |
} |
| 1792 |
|
| 1793 |
if ( document.readyState === 'loading' ) { |
| 1794 |
document.addEventListener( 'DOMContentLoaded', init ); |
| 1795 |
} else { |
| 1796 |
init(); |
| 1797 |
} |
| 1798 |
} )(); |
| 1799 |
</script> |
| 1800 |
<?php endif; |
| 1801 |
} |
| 1802 |
} |
| 1803 |
|
| 1804 |
class Share_Pocket extends Sharing_Source { |
| 1805 |
public $shortname = 'pocket'; |
| 1806 |
public $icon = '\f224'; |
| 1807 |
|
| 1808 |
public function __construct( $id, array $settings ) { |
| 1809 |
parent::__construct( $id, $settings ); |
| 1810 |
|
| 1811 |
if ( 'official' == $this->button_style ) { |
| 1812 |
$this->smart = true; |
| 1813 |
} else { |
| 1814 |
$this->smart = false; |
| 1815 |
} |
| 1816 |
} |
| 1817 |
|
| 1818 |
public function get_name() { |
| 1819 |
return __( 'Pocket', 'jetpack' ); |
| 1820 |
} |
| 1821 |
|
| 1822 |
public function process_request( $post, array $post_data ) { |
| 1823 |
// Record stats |
| 1824 |
parent::process_request( $post, $post_data ); |
| 1825 |
|
| 1826 |
$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 ) ) ); |
| 1827 |
wp_redirect( $pocket_url ); |
| 1828 |
exit; |
| 1829 |
} |
| 1830 |
|
| 1831 |
public function get_display( $post ) { |
| 1832 |
if ( $this->smart ) { |
| 1833 |
$post_count = 'horizontal'; |
| 1834 |
|
| 1835 |
$button = ''; |
| 1836 |
$button .= '<div class="pocket_button">'; |
| 1837 |
$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' ) ); |
| 1838 |
$button .= '</div>'; |
| 1839 |
|
| 1840 |
return $button; |
| 1841 |
} else { |
| 1842 |
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' ); |
| 1843 |
} |
| 1844 |
|
| 1845 |
} |
| 1846 |
|
| 1847 |
/** |
| 1848 |
* AMP display for Pocket. |
| 1849 |
* |
| 1850 |
* @param \WP_Post $post The current post being viewed. |
| 1851 |
*/ |
| 1852 |
public function get_amp_display( $post ) { |
| 1853 |
$attrs = array( |
| 1854 |
'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 ) ) ), |
| 1855 |
); |
| 1856 |
|
| 1857 |
return $this->build_amp_markup( $attrs ); |
| 1858 |
} |
| 1859 |
|
| 1860 |
function display_footer() { |
| 1861 |
if ( $this->smart ) : |
| 1862 |
?> |
| 1863 |
<script> |
| 1864 |
( function () { |
| 1865 |
var currentScript = document.currentScript; |
| 1866 |
|
| 1867 |
// Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS. |
| 1868 |
function jetpack_sharing_pocket_init() { |
| 1869 |
var script = document.createElement( 'script' ); |
| 1870 |
var prev = currentScript || document.getElementsByTagName( 'script' )[ 0 ]; |
| 1871 |
script.setAttribute( 'async', true ); |
| 1872 |
script.setAttribute( 'src', 'https://widgets.getpocket.com/v1/j/btn.js?v=1' ); |
| 1873 |
prev.parentNode.insertBefore( script, prev ); |
| 1874 |
} |
| 1875 |
|
| 1876 |
if ( document.readyState === 'loading' ) { |
| 1877 |
document.addEventListener( 'DOMContentLoaded', jetpack_sharing_pocket_init ); |
| 1878 |
} else { |
| 1879 |
jetpack_sharing_pocket_init(); |
| 1880 |
} |
| 1881 |
document.body.addEventListener( 'is.post-load', jetpack_sharing_pocket_init ); |
| 1882 |
} )(); |
| 1883 |
</script> |
| 1884 |
<?php |
| 1885 |
else : |
| 1886 |
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
| 1887 |
endif; |
| 1888 |
|
| 1889 |
} |
| 1890 |
|
| 1891 |
} |
| 1892 |
|
| 1893 |
class Share_Telegram extends Sharing_Source { |
| 1894 |
public $shortname = 'telegram'; |
| 1895 |
|
| 1896 |
public function __construct( $id, array $settings ) { |
| 1897 |
parent::__construct( $id, $settings ); |
| 1898 |
} |
| 1899 |
|
| 1900 |
public function get_name() { |
| 1901 |
return __( 'Telegram', 'jetpack' ); |
| 1902 |
} |
| 1903 |
public function process_request( $post, array $post_data ) { |
| 1904 |
// Record stats |
| 1905 |
parent::process_request( $post, $post_data ); |
| 1906 |
$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 ) ) ); |
| 1907 |
wp_redirect( $telegram_url ); |
| 1908 |
exit; |
| 1909 |
} |
| 1910 |
|
| 1911 |
public function get_display( $post ) { |
| 1912 |
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' ); |
| 1913 |
} |
| 1914 |
|
| 1915 |
/** |
| 1916 |
* AMP display for Telegram. |
| 1917 |
* |
| 1918 |
* @param \WP_Post $post The current post being viewed. |
| 1919 |
*/ |
| 1920 |
public function get_amp_display( $post ) { |
| 1921 |
$attrs = array( |
| 1922 |
'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 ) ) ), |
| 1923 |
); |
| 1924 |
|
| 1925 |
return $this->build_amp_markup( $attrs ); |
| 1926 |
} |
| 1927 |
|
| 1928 |
function display_footer() { |
| 1929 |
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
| 1930 |
} |
| 1931 |
} |
| 1932 |
|
| 1933 |
class Jetpack_Share_WhatsApp extends Sharing_Source { |
| 1934 |
public $shortname = 'jetpack-whatsapp'; |
| 1935 |
|
| 1936 |
public function __construct( $id, array $settings ) { |
| 1937 |
parent::__construct( $id, $settings ); |
| 1938 |
} |
| 1939 |
|
| 1940 |
public function get_name() { |
| 1941 |
return __( 'WhatsApp', 'jetpack' ); |
| 1942 |
} |
| 1943 |
|
| 1944 |
public function get_display( $post ) { |
| 1945 |
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' ); |
| 1946 |
} |
| 1947 |
|
| 1948 |
/** |
| 1949 |
* AMP display for Whatsapp. |
| 1950 |
* |
| 1951 |
* @param \WP_Post $post The current post being viewed. |
| 1952 |
*/ |
| 1953 |
public function get_amp_display( $post ) { |
| 1954 |
$attrs = array( |
| 1955 |
'type' => 'whatsapp', |
| 1956 |
); |
| 1957 |
|
| 1958 |
return $this->build_amp_markup( $attrs ); |
| 1959 |
} |
| 1960 |
|
| 1961 |
public function process_request( $post, array $post_data ) { |
| 1962 |
// Record stats |
| 1963 |
parent::process_request( $post, $post_data ); |
| 1964 |
|
| 1965 |
// Firefox for desktop doesn't handle the "api.whatsapp.com" URL properly, so use "web.whatsapp.com" |
| 1966 |
if ( User_Agent_Info::is_firefox_desktop() ) { |
| 1967 |
$url = 'https://web.whatsapp.com/send?text='; |
| 1968 |
} else { |
| 1969 |
$url = 'https://api.whatsapp.com/send?text='; |
| 1970 |
} |
| 1971 |
|
| 1972 |
$url .= rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ); |
| 1973 |
wp_redirect( $url ); |
| 1974 |
exit; |
| 1975 |
} |
| 1976 |
} |
| 1977 |
|
| 1978 |
class Share_Skype extends Sharing_Source { |
| 1979 |
public $shortname = 'skype'; |
| 1980 |
public $icon = '\f220'; |
| 1981 |
private $share_type = 'default'; |
| 1982 |
|
| 1983 |
public function __construct( $id, array $settings ) { |
| 1984 |
parent::__construct( $id, $settings ); |
| 1985 |
|
| 1986 |
if ( isset( $settings['share_type'] ) ) { |
| 1987 |
$this->share_type = $settings['share_type']; |
| 1988 |
} |
| 1989 |
|
| 1990 |
if ( 'official' == $this->button_style ) { |
| 1991 |
$this->smart = true; |
| 1992 |
} else { |
| 1993 |
$this->smart = false; |
| 1994 |
} |
| 1995 |
|
| 1996 |
} |
| 1997 |
|
| 1998 |
public function get_name() { |
| 1999 |
return __( 'Skype', 'jetpack' ); |
| 2000 |
} |
| 2001 |
|
| 2002 |
public function get_display( $post ) { |
| 2003 |
if ( $this->smart ) { |
| 2004 |
$skype_share_html = sprintf( |
| 2005 |
'<div class="skype-share" data-href="%1$s" data-lang="%2$s" data-style="small" data-source="jetpack" ></div>', |
| 2006 |
esc_attr( $this->get_share_url( $post->ID ) ), |
| 2007 |
'en-US' |
| 2008 |
); |
| 2009 |
return $skype_share_html; |
| 2010 |
} |
| 2011 |
|
| 2012 |
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
| 2013 |
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'skype' ) ) { |
| 2014 |
sharing_register_post_for_share_counts( $post->ID ); |
| 2015 |
} |
| 2016 |
return $this->get_link( |
| 2017 |
$this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Click to share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID ); |
| 2018 |
} |
| 2019 |
|
| 2020 |
/** |
| 2021 |
* AMP display for Skype. |
| 2022 |
* |
| 2023 |
* @param \WP_Post $post The current post being viewed. |
| 2024 |
*/ |
| 2025 |
public function get_amp_display( $post ) { |
| 2026 |
$attrs = array( |
| 2027 |
'data-share-endpoint' => sprintf( |
| 2028 |
'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack', |
| 2029 |
rawurlencode( $this->get_share_url( $post->ID ) ), |
| 2030 |
'en-US' |
| 2031 |
), |
| 2032 |
); |
| 2033 |
|
| 2034 |
return $this->build_amp_markup( $attrs ); |
| 2035 |
} |
| 2036 |
|
| 2037 |
public function process_request( $post, array $post_data ) { |
| 2038 |
$skype_url = sprintf( |
| 2039 |
'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack', |
| 2040 |
rawurlencode( $this->get_share_url( $post->ID ) ), |
| 2041 |
'en-US' |
| 2042 |
); |
| 2043 |
|
| 2044 |
// Record stats |
| 2045 |
parent::process_request( $post, $post_data ); |
| 2046 |
|
| 2047 |
// Redirect to Skype |
| 2048 |
wp_redirect( $skype_url ); |
| 2049 |
die(); |
| 2050 |
} |
| 2051 |
|
| 2052 |
public function display_footer() { |
| 2053 |
if ( $this->smart ) : |
| 2054 |
?> |
| 2055 |
<script> |
| 2056 |
(function(r, d, s) { |
| 2057 |
r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) { |
| 2058 |
var js, sjs = d.getElementsByTagName(s)[0]; |
| 2059 |
if (d.getElementById(p.id)) { return; } |
| 2060 |
js = d.createElement(s); |
| 2061 |
js.id = p.id; |
| 2062 |
js.src = p.scriptToLoad; |
| 2063 |
js.onload = p.callback |
| 2064 |
sjs.parentNode.insertBefore(js, sjs); |
| 2065 |
}; |
| 2066 |
var p = { |
| 2067 |
scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js', |
| 2068 |
id: 'skype_web_sdk' |
| 2069 |
}; |
| 2070 |
r.loadSkypeWebSdkAsync(p); |
| 2071 |
})(window, document, 'script'); |
| 2072 |
</script> |
| 2073 |
<?php |
| 2074 |
else : |
| 2075 |
$this->js_dialog( $this->shortname, array( 'width' => 305, 'height' => 665 ) ); |
| 2076 |
endif; |
| 2077 |
} |
| 2078 |
} |
| 2079 |
|