/modules/sharedaddy/sharing-sources.php

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