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