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