PageRenderTime 30ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/jetpack/modules/sharedaddy/sharing-sources.php

https://gitlab.com/juanito.abelo/nlmobile
PHP | 1300 lines | 979 code | 261 blank | 60 comment | 175 complexity | 6ba01dcb6c4b605d66eb9218228af663 MD5 | raw file
  1. <?php
  2. abstract class Sharing_Source {
  3. public $button_style;
  4. public $smart;
  5. protected $open_link_in_new;
  6. protected $id;
  7. public function __construct( $id, array $settings ) {
  8. $this->id = $id;
  9. $this->open_link_in_new = apply_filters( 'jetpack_open_sharing_in_new_window', true );
  10. if ( isset( $settings['button_style'] ) )
  11. $this->button_style = $settings['button_style'];
  12. if ( isset( $settings['smart'] ) )
  13. $this->smart = $settings['smart'];
  14. }
  15. public function http() {
  16. return is_ssl() ? 'https' : 'http';
  17. }
  18. public function get_id() {
  19. return $this->id;
  20. }
  21. public function get_class() {
  22. return $this->id;
  23. }
  24. public function get_share_url( $post_id ) {
  25. return apply_filters( 'sharing_permalink', get_permalink( $post_id ), $post_id, $this->id );
  26. }
  27. public function get_share_title( $post_id ) {
  28. $post = get_post( $post_id );
  29. $title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id );
  30. return html_entity_decode( wp_kses( $title, null ) );
  31. }
  32. public function has_custom_button_style() {
  33. return false;
  34. }
  35. public function get_link( $url, $text, $title, $query = '', $id = false ) {
  36. $args = func_get_args();
  37. $klasses = array( 'share-'.$this->get_class(), 'sd-button' );
  38. if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style )
  39. $klasses[] = 'share-icon';
  40. if ( 'icon' == $this->button_style ) {
  41. $text = $title;
  42. $klasses[] = 'no-text';
  43. if ( true == $this->open_link_in_new )
  44. $text .= __( ' (Opens in new window)', 'jetpack' );
  45. }
  46. $id = apply_filters( 'jetpack_sharing_display_id', $id, $this, $args );
  47. $url = apply_filters( 'sharing_display_link', $url, $this, $id, $args ); // backwards compatibility
  48. $url = apply_filters( 'jetpack_sharing_display_link', $url, $this, $id, $args );
  49. $query = apply_filters( 'jetpack_sharing_display_query', $query, $this, $id, $args );
  50. if ( !empty( $query ) ) {
  51. if ( false === stripos( $url, '?' ) )
  52. $url .= '?'.$query;
  53. else
  54. $url .= '&amp;'.$query;
  55. }
  56. if ( 'text' == $this->button_style )
  57. $klasses[] = 'no-icon';
  58. $klasses = apply_filters( 'jetpack_sharing_display_classes', $klasses, $this, $id, $args );
  59. $title = apply_filters( 'jetpack_sharing_display_title', $title, $this, $id, $args );
  60. $text = apply_filters( 'jetpack_sharing_display_text', $text, $this, $id, $args );
  61. return sprintf(
  62. '<a rel="nofollow" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>',
  63. ( $id ? esc_attr( $id ) : '' ),
  64. implode( ' ', $klasses ),
  65. $url,
  66. ( true == $this->open_link_in_new ) ? ' target="_blank"' : '',
  67. $title,
  68. ( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '',
  69. $text
  70. );
  71. }
  72. abstract public function get_name();
  73. abstract public function get_display( $post );
  74. public function display_header() {
  75. }
  76. public function display_footer() {
  77. }
  78. public function has_advanced_options() {
  79. return false;
  80. }
  81. public function display_preview( $echo = true, $force_smart = false, $button_style = null ) {
  82. $text = '&nbsp;';
  83. $button_style = ( ! empty( $button_style ) ) ? $button_style : $this->button_style;
  84. if ( !$this->smart && ! $force_smart )
  85. if ( $button_style != 'icon' )
  86. $text = $this->get_name();
  87. $klasses = array( 'share-'.$this->get_class(), 'sd-button' );
  88. if ( $button_style == 'icon' || $button_style == 'icon-text' )
  89. $klasses[] = 'share-icon';
  90. if ( $button_style == 'icon' )
  91. $klasses[] = 'no-text';
  92. if ( $button_style == 'text' )
  93. $klasses[] = 'no-icon';
  94. $link = sprintf(
  95. '<a rel="nofollow" class="%s" href="javascript:void(0);return false;" title="%s"><span>%s</span></a>',
  96. implode( ' ', $klasses ),
  97. $this->get_name(),
  98. $text
  99. );
  100. $smart = ( $this->smart || $force_smart ) ? 'on' : 'off';
  101. $return = "<div class='option option-smart-$smart'>$link</div>";
  102. if ( $echo )
  103. echo $return;
  104. return $return;
  105. }
  106. public function get_total( $post = false ) {
  107. global $wpdb, $blog_id;
  108. $name = strtolower( $this->get_id() );
  109. if ( $post == false ) {
  110. // get total number of shares for service
  111. return (int) $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $blog_id, $name ) );
  112. }
  113. // get total shares for a post
  114. 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 ) );
  115. }
  116. public function get_posts_total() {
  117. global $wpdb, $blog_id;
  118. $totals = array();
  119. $name = strtolower( $this->get_id() );
  120. $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 ) );
  121. if ( !empty( $my_data ) )
  122. foreach( $my_data as $row )
  123. $totals[] = new Sharing_Post_Total( $row->id, $row->total );
  124. usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) );
  125. return $totals;
  126. }
  127. public function process_request( $post, array $post_data ) {
  128. do_action( 'sharing_bump_stats', array( 'service' => $this, 'post' => $post ) );
  129. }
  130. public function js_dialog( $name, $params = array() ) {
  131. if ( true !== $this->open_link_in_new )
  132. return;
  133. $defaults = array(
  134. 'menubar' => 1,
  135. 'resizable' => 1,
  136. 'width' => 600,
  137. 'height' => 400,
  138. );
  139. $params = array_merge( $defaults, $params );
  140. $opts = array();
  141. foreach( $params as $key => $val ) {
  142. $opts[] = "$key=$val";
  143. }
  144. $opts = implode( ',', $opts );
  145. ?>
  146. <script type="text/javascript">
  147. var windowOpen;
  148. jQuery(document).on( 'ready post-load', function(){
  149. jQuery( 'a.share-<?php echo $name; ?>' ).on( 'click', function() {
  150. if ( 'undefined' !== typeof windowOpen ){ // If there's another sharing window open, close it.
  151. windowOpen.close();
  152. }
  153. windowOpen = window.open( jQuery(this).attr( 'href' ), 'wpcom<?php echo $name; ?>', '<?php echo $opts; ?>' );
  154. return false;
  155. });
  156. });
  157. </script>
  158. <?php
  159. }
  160. }
  161. abstract class Sharing_Advanced_Source extends Sharing_Source {
  162. public function has_advanced_options() {
  163. return true;
  164. }
  165. abstract public function display_options();
  166. abstract public function update_options( array $data );
  167. abstract public function get_options();
  168. }
  169. class Share_Email extends Sharing_Source {
  170. var $shortname = 'email';
  171. var $genericon = '\f410';
  172. public function __construct( $id, array $settings ) {
  173. parent::__construct( $id, $settings );
  174. if ( 'official' == $this->button_style )
  175. $this->smart = true;
  176. else
  177. $this->smart = false;
  178. }
  179. public function get_name() {
  180. return _x( 'Email', 'as sharing source', 'jetpack' );
  181. }
  182. // Default does nothing
  183. public function process_request( $post, array $post_data ) {
  184. $ajax = false;
  185. if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' )
  186. $ajax = true;
  187. $source_email = $target_email = $source_name = false;
  188. if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) )
  189. $source_email = $post_data['source_email'];
  190. if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) )
  191. $target_email = $post_data['target_email'];
  192. if ( isset( $post_data['source_name'] ) )
  193. $source_name = $post_data['source_name'];
  194. // Test email
  195. $error = 1; // Failure in data
  196. if ( $source_email && $target_email && $source_name ) {
  197. if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) {
  198. $data = array(
  199. 'post' => $post,
  200. 'source' => $source_email,
  201. 'target' => $target_email,
  202. 'name' => $source_name
  203. );
  204. if ( ( $data = apply_filters( 'sharing_email_can_send', $data ) ) !== false ) {
  205. // Record stats
  206. parent::process_request( $data['post'], $post_data );
  207. do_action( 'sharing_email_send_post', $data );
  208. }
  209. // Return a positive regardless of whether the user is subscribed or not
  210. if ( $ajax ) {
  211. ?>
  212. <div class="response">
  213. <div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div>
  214. <div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
  215. <div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
  216. </div>
  217. <?php
  218. }
  219. else
  220. wp_safe_redirect( get_permalink( $post->ID ).'?shared=email' );
  221. die();
  222. }
  223. else
  224. $error = 2; // Email check failed
  225. }
  226. if ( $ajax )
  227. echo $error;
  228. else
  229. wp_safe_redirect( get_permalink( $post->ID ).'?shared=email&msg=fail' );
  230. die();
  231. }
  232. public function get_display( $post ) {
  233. return $this->get_link( get_permalink( $post->ID ), _x( 'Email', 'share to', 'jetpack' ), __( 'Click to email this to a friend', 'jetpack' ), 'share=email' );
  234. }
  235. /**
  236. * Outputs the hidden email dialog
  237. */
  238. public function display_footer() {
  239. global $current_user;
  240. $visible = $status = false;
  241. ?>
  242. <div id="sharing_email" style="display: none;">
  243. <form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post">
  244. <label for="target_email"><?php _e( 'Send to Email Address', 'jetpack' ) ?></label>
  245. <input type="email" name="target_email" id="target_email" value="" />
  246. <?php if ( is_user_logged_in() ) : ?>
  247. <input type="hidden" name="source_name" value="<?php echo esc_attr( $current_user->display_name ); ?>" />
  248. <input type="hidden" name="source_email" value="<?php echo esc_attr( $current_user->user_email ); ?>" />
  249. <?php else : ?>
  250. <label for="source_name"><?php _e( 'Your Name', 'jetpack' ) ?></label>
  251. <input type="text" name="source_name" id="source_name" value="" />
  252. <label for="source_email"><?php _e( 'Your Email Address', 'jetpack' ) ?></label>
  253. <input type="email" name="source_email" id="source_email" value="" />
  254. <?php endif; ?>
  255. <?php do_action( 'sharing_email_dialog', 'jetpack' ); ?>
  256. <img style="float: right; display: none" class="loading" src="<?php
  257. /** This filter is documented in modules/shortcodes/audio.php */
  258. echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" />
  259. <input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" />
  260. <a href="#cancel" class="sharing_cancel"><?php _e( 'Cancel', 'jetpack' ); ?></a>
  261. <div class="errors errors-1" style="display: none;">
  262. <?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?>
  263. </div>
  264. <div class="errors errors-2" style="display: none;">
  265. <?php _e( 'Email check failed, please try again', 'jetpack' ); ?>
  266. </div>
  267. <div class="errors errors-3" style="display: none;">
  268. <?php _e( 'Sorry, your blog cannot share posts by email.', 'jetpack' ); ?>
  269. </div>
  270. </form>
  271. </div>
  272. <?php
  273. }
  274. }
  275. class Share_Twitter extends Sharing_Source {
  276. var $shortname = 'twitter';
  277. var $genericon = '\f202';
  278. // 'https://dev.twitter.com/rest/reference/get/help/configuration' ( 2015/02/06 ) short_url_length is 22, short_url_length_https is 23
  279. var $short_url_length = 24;
  280. public function __construct( $id, array $settings ) {
  281. parent::__construct( $id, $settings );
  282. if ( 'official' == $this->button_style )
  283. $this->smart = true;
  284. else
  285. $this->smart = false;
  286. }
  287. public function get_name() {
  288. return __( 'Twitter', 'jetpack' );
  289. }
  290. function sharing_twitter_via( $post ) {
  291. // Allow themes to customize the via
  292. $twitter_site_tag_value = apply_filters( 'jetpack_twitter_cards_site_tag', '', array() );
  293. /*
  294. * Hack to remove the unwanted behavior of adding 'via @jetpack' which
  295. * was introduced with the adding of the Twitter cards.
  296. * This should be a temporary solution until a better method is setup.
  297. */
  298. if( 'jetpack' == $twitter_site_tag_value ) {
  299. $twitter_site_tag_value = '';
  300. }
  301. $twitter_site_tag_value = apply_filters( 'jetpack_sharing_twitter_via', $twitter_site_tag_value, $post->ID );
  302. // Strip out anything other than a letter, number, or underscore.
  303. // This will prevent the inadvertent inclusion of an extra @, as well as normalizing the handle.
  304. $twitter_site_tag_value = preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value );
  305. return $twitter_site_tag_value;
  306. }
  307. public function get_related_accounts( $post ) {
  308. // Format is 'username' => 'Optional description'
  309. $related_accounts = apply_filters( 'jetpack_sharing_twitter_related', array(), $post->ID );
  310. // Example related string: account1,account2:Account 2 description,account3
  311. $related = array();
  312. foreach ( $related_accounts as $related_account_username => $related_account_description ) {
  313. // Join the description onto the end of the username
  314. if ( $related_account_description )
  315. $related_account_username .= ':' . $related_account_description;
  316. $related[] = $related_account_username;
  317. }
  318. return implode( ',', $related );
  319. }
  320. public function get_display( $post ) {
  321. $via = $this->sharing_twitter_via( $post );
  322. if ( $via ) {
  323. $via = '&via=' . rawurlencode( $via );
  324. } else {
  325. $via = '';
  326. }
  327. $related = $this->get_related_accounts( $post );
  328. if ( ! empty( $related ) && $related !== $via ) {
  329. $via .= '&related=' . rawurlencode( $related );
  330. }
  331. $share_url = $this->get_share_url( $post->ID );
  332. $post_title = $this->get_share_title( $post->ID );
  333. if ( $this->smart ) {
  334. 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( str_replace( 'https://', 'http://', get_permalink( $post->ID ) ) ) . '&count=horizontal&text=' . rawurlencode( $post_title . ':' ) . $via ) . '" style="width:101px; height:20px;"></iframe></div>';
  335. } else {
  336. if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' ) ) {
  337. sharing_register_post_for_share_counts( $post->ID );
  338. }
  339. return $this->get_link( get_permalink( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID );
  340. }
  341. }
  342. public function process_request( $post, array $post_data ) {
  343. $post_title = $this->get_share_title( $post->ID );
  344. $post_link = $this->get_share_url( $post->ID );
  345. if ( function_exists( 'mb_stripos' ) ) {
  346. $strlen = 'mb_strlen';
  347. $substr = 'mb_substr';
  348. } else {
  349. $strlen = 'strlen';
  350. $substr = 'substr';
  351. }
  352. $via = $this->sharing_twitter_via( $post );
  353. $related = $this->get_related_accounts( $post );
  354. if ( $via ) {
  355. $sig = " via @$via";
  356. if ( $related === $via ) {
  357. $related = false;
  358. }
  359. } else {
  360. $via = false;
  361. $sig = '';
  362. }
  363. $suffix_length = $this->short_url_length + $strlen( $sig );
  364. // $sig is handled by twitter in their 'via' argument.
  365. // $post_link is handled by twitter in their 'url' argument.
  366. if ( 140 < $strlen( $post_title ) + $suffix_length ) {
  367. // The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis.
  368. $text = $substr( $post_title, 0, 140 - $suffix_length - 1 ) . "\xE2\x80\xA6";
  369. } else {
  370. $text = $post_title;
  371. }
  372. // Record stats
  373. parent::process_request( $post, $post_data );
  374. $url = $post_link;
  375. $twitter_url = add_query_arg(
  376. urlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
  377. 'https://twitter.com/intent/tweet'
  378. );
  379. // Redirect to Twitter
  380. wp_redirect( $twitter_url );
  381. die();
  382. }
  383. public function has_custom_button_style() {
  384. return $this->smart;
  385. }
  386. public function display_footer() {
  387. $this->js_dialog( $this->shortname, array( 'height' => 350 ) );
  388. }
  389. }
  390. class Share_Stumbleupon extends Sharing_Source {
  391. var $shortname = 'stumbleupon';
  392. var $genericon = '\f223';
  393. public function __construct( $id, array $settings ) {
  394. parent::__construct( $id, $settings );
  395. if ( 'official' == $this->button_style )
  396. $this->smart = true;
  397. else
  398. $this->smart = false;
  399. }
  400. public function get_name() {
  401. return __( 'StumbleUpon', 'jetpack' );
  402. }
  403. public function has_custom_button_style() {
  404. return $this->smart;
  405. }
  406. public function get_display( $post ) {
  407. if ( $this->smart )
  408. return '<div class="stumbleupon_button"><iframe src="http://www.stumbleupon.com/badge/embed/1/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:74px; height: 18px;" allowTransparency="true"></iframe></div>';
  409. else
  410. return $this->get_link( get_permalink( $post->ID ), _x( 'StumbleUpon', 'share to', 'jetpack' ), __( 'Click to share on StumbleUpon', 'jetpack' ), 'share=stumbleupon' );
  411. }
  412. public function process_request( $post, array $post_data ) {
  413. $stumbleupon_url = $this->http() . '://www.stumbleupon.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) );
  414. // Record stats
  415. parent::process_request( $post, $post_data );
  416. // Redirect to Stumbleupon
  417. wp_redirect( $stumbleupon_url );
  418. die();
  419. }
  420. }
  421. class Share_Reddit extends Sharing_Source {
  422. var $shortname = 'reddit';
  423. var $genericon = '\f222';
  424. public function __construct( $id, array $settings ) {
  425. parent::__construct( $id, $settings );
  426. if ( 'official' == $this->button_style )
  427. $this->smart = true;
  428. else
  429. $this->smart = false;
  430. }
  431. public function get_name() {
  432. return __( 'Reddit', 'jetpack' );
  433. }
  434. public function get_display( $post ) {
  435. if ( $this->smart )
  436. return '<div class="reddit_button"><iframe src="' . $this->http() . '://www.reddit.com/static/button/button1.html?width=120&amp;url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>';
  437. else
  438. return $this->get_link( get_permalink( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' );
  439. }
  440. public function process_request( $post, array $post_data ) {
  441. $reddit_url = $this->http() . '://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) );
  442. // Record stats
  443. parent::process_request( $post, $post_data );
  444. // Redirect to Reddit
  445. wp_redirect( $reddit_url );
  446. die();
  447. }
  448. }
  449. class Share_LinkedIn extends Sharing_Source {
  450. var $shortname = 'linkedin';
  451. var $genericon = '\f207';
  452. public function __construct( $id, array $settings ) {
  453. parent::__construct( $id, $settings );
  454. if ( 'official' == $this->button_style )
  455. $this->smart = true;
  456. else
  457. $this->smart = false;
  458. }
  459. public function get_name() {
  460. return __( 'LinkedIn', 'jetpack' );
  461. }
  462. public function has_custom_button_style() {
  463. return $this->smart;
  464. }
  465. public function get_display( $post ) {
  466. $share_url = $this->get_share_url( $post->ID );
  467. $display = '';
  468. if ( $this->smart )
  469. $display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) );
  470. else
  471. $display = $this->get_link( get_permalink( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID );
  472. if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
  473. sharing_register_post_for_share_counts( $post->ID );
  474. }
  475. return $display;
  476. }
  477. public function process_request( $post, array $post_data ) {
  478. $post_link = $this->get_share_url( $post->ID );
  479. // Using the same URL as the official button, which is *not* LinkedIn's documented sharing link
  480. // https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false
  481. $linkedin_url = add_query_arg( array(
  482. 'url' => rawurlencode( $post_link ),
  483. ), 'https://www.linkedin.com/cws/share?token=&isFramed=false' );
  484. // Record stats
  485. parent::process_request( $post, $post_data );
  486. // Redirect to LinkedIn
  487. wp_redirect( $linkedin_url );
  488. die();
  489. }
  490. public function display_footer() {
  491. if ( !$this->smart ) {
  492. $this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) );
  493. } else {
  494. ?><script type="text/javascript">
  495. jQuery( document ).ready( function() {
  496. jQuery.getScript( '//platform.linkedin.com/in.js?async=true', function success() {
  497. IN.init();
  498. });
  499. });
  500. jQuery( document.body ).on( 'post-load', function() {
  501. if ( typeof IN != 'undefined' )
  502. IN.parse();
  503. });
  504. </script><?php
  505. }
  506. }
  507. }
  508. class Share_Facebook extends Sharing_Source {
  509. var $shortname = 'facebook';
  510. var $genericon = '\f204';
  511. private $share_type = 'default';
  512. public function __construct( $id, array $settings ) {
  513. parent::__construct( $id, $settings );
  514. if ( isset( $settings['share_type'] ) )
  515. $this->share_type = $settings['share_type'];
  516. if ( 'official' == $this->button_style )
  517. $this->smart = true;
  518. else
  519. $this->smart = false;
  520. }
  521. public function get_name() {
  522. return __( 'Facebook', 'jetpack' );
  523. }
  524. public function display_header() {
  525. }
  526. function guess_locale_from_lang( $lang ) {
  527. if ( 'en' == $lang || 'en_US' == $lang || !$lang ) {
  528. return 'en_US';
  529. }
  530. if ( !class_exists( 'GP_Locales' ) ) {
  531. if ( !defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || !file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
  532. return false;
  533. }
  534. require JETPACK__GLOTPRESS_LOCALES_PATH;
  535. }
  536. if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
  537. // WP.com: get_locale() returns 'it'
  538. $locale = GP_Locales::by_slug( $lang );
  539. } else {
  540. // Jetpack: get_locale() returns 'it_IT';
  541. $locale = GP_Locales::by_field( 'wp_locale', $lang );
  542. }
  543. if ( !$locale || empty( $locale->facebook_locale ) ) {
  544. return false;
  545. }
  546. return $locale->facebook_locale;
  547. }
  548. public function get_display( $post ) {
  549. $share_url = $this->get_share_url( $post->ID );
  550. if ( $this->smart ) {
  551. $url = $this->http() . '://www.facebook.com/plugins/like.php?href=' . rawurlencode( $share_url ) . '&amp;layout=button_count&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;height=21';
  552. // Default widths to suit English
  553. $inner_w = 90;
  554. // Locale-specific widths/overrides
  555. $widths = array(
  556. 'bg_BG' => 120,
  557. 'bn_IN' => 100,
  558. 'cs_CZ' => 135,
  559. 'de_DE' => 120,
  560. 'da_DK' => 120,
  561. 'es_ES' => 122,
  562. 'es_LA' => 110,
  563. 'fi_FI' => 100,
  564. 'it_IT' => 100,
  565. 'ja_JP' => 100,
  566. 'pl_PL' => 100,
  567. 'nl_NL' => 130,
  568. 'ro_RO' => 100,
  569. 'ru_RU' => 128,
  570. );
  571. $widths = apply_filters( 'sharing_facebook_like_widths', $widths );
  572. $locale = $this->guess_locale_from_lang( get_locale() );
  573. if ( $locale ) {
  574. $url .= '&amp;locale=' . $locale;
  575. if ( isset( $widths[$locale] ) ) {
  576. $inner_w = $widths[$locale];
  577. }
  578. }
  579. $url .= '&amp;width='.$inner_w;
  580. return '<div class="like_button"><iframe src="'.$url.'" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:'.( $inner_w + 6 ).'px; height:21px;" allowTransparency="true"></iframe></div>';
  581. }
  582. if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) {
  583. sharing_register_post_for_share_counts( $post->ID );
  584. }
  585. return $this->get_link( get_permalink( $post->ID ), _x( 'Facebook', 'share to', 'jetpack' ), __( 'Share on Facebook', 'jetpack' ), 'share=facebook', 'sharing-facebook-' . $post->ID );
  586. }
  587. public function process_request( $post, array $post_data ) {
  588. $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 ) );
  589. // Record stats
  590. parent::process_request( $post, $post_data );
  591. // Redirect to Facebook
  592. wp_redirect( $fb_url );
  593. die();
  594. }
  595. public function display_footer() {
  596. $this->js_dialog( $this->shortname );
  597. }
  598. }
  599. class Share_Print extends Sharing_Source {
  600. var $shortname = 'print';
  601. var $genericon = '\f469';
  602. public function __construct( $id, array $settings ) {
  603. parent::__construct( $id, $settings );
  604. if ( 'official' == $this->button_style )
  605. $this->smart = true;
  606. else
  607. $this->smart = false;
  608. }
  609. public function get_name() {
  610. return __( 'Print', 'jetpack' );
  611. }
  612. public function get_display( $post ) {
  613. return $this->get_link( get_permalink( $post->ID ) . ( ( is_single() || is_page() ) ? '#print': '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Click to print', 'jetpack' ) );
  614. }
  615. }
  616. class Share_PressThis extends Sharing_Source {
  617. var $shortname = 'pressthis';
  618. var $genericon = '\f205';
  619. public function __construct( $id, array $settings ) {
  620. parent::__construct( $id, $settings );
  621. if ( 'official' == $this->button_style )
  622. $this->smart = true;
  623. else
  624. $this->smart = false;
  625. }
  626. public function get_name() {
  627. return __( 'Press This', 'jetpack' );
  628. }
  629. public function process_request( $post, array $post_data ) {
  630. global $current_user;
  631. $primary_blog = (int) get_user_meta( $current_user->ID, 'primary_blog', true );
  632. if ( $primary_blog ) {
  633. $primary_blog_details = get_blog_details( $primary_blog );
  634. } else {
  635. $primary_blog_details = false;
  636. }
  637. if ( $primary_blog_details ) {
  638. $blogs = array( $primary_blog_details );
  639. } elseif ( function_exists( 'get_active_blogs_for_user' ) ) {
  640. $blogs = get_active_blogs_for_user();
  641. if ( empty( $blogs ) ) {
  642. $blogs = get_blogs_of_user( $current_user->ID );
  643. }
  644. } else {
  645. $blogs = get_blogs_of_user( $current_user->ID );
  646. }
  647. if ( empty( $blogs ) ) {
  648. wp_safe_redirect( get_permalink( $post->ID ) );
  649. die();
  650. }
  651. $blog = current( $blogs );
  652. $url = $blog->siteurl.'/wp-admin/press-this.php?u='.rawurlencode( $this->get_share_url( $post->ID ) ).'&t='.rawurlencode( $this->get_share_title( $post->ID ) ).'&v=4';
  653. if ( isset( $_GET['sel'] ) )
  654. $url .= '&s='.rawurlencode( $_GET['sel'] );
  655. // Record stats
  656. parent::process_request( $post, $post_data );
  657. // Redirect to Press This
  658. wp_safe_redirect( $url );
  659. die();
  660. }
  661. public function get_display( $post ) {
  662. return $this->get_link( get_permalink( $post->ID ), _x( 'Press This', 'share to', 'jetpack' ), __( 'Click to Press This!', 'jetpack' ), 'share=press-this' );
  663. }
  664. }
  665. class Share_GooglePlus1 extends Sharing_Source {
  666. var $shortname = 'googleplus1';
  667. var $genericon = '\f218';
  668. private $state = false;
  669. public function __construct( $id, array $settings ) {
  670. parent::__construct( $id, $settings );
  671. if ( 'official' == $this->button_style )
  672. $this->smart = true;
  673. else
  674. $this->smart = false;
  675. }
  676. public function get_name() {
  677. return __( 'Google', 'jetpack' );
  678. }
  679. public function has_custom_button_style() {
  680. return $this->smart;
  681. }
  682. public function get_display( $post ) {
  683. $share_url = $this->get_share_url( $post->ID );
  684. if ( $this->smart ) {
  685. return '<div class="googleplus1_button"><div class="g-plus" data-action="share" data-annotation="bubble" data-href="' . esc_url( $share_url ) . '"></div></div>';
  686. } else {
  687. return $this->get_link( get_permalink( $post->ID ), _x( 'Google', 'share to', 'jetpack' ), __( 'Click to share on Google+', 'jetpack' ), 'share=google-plus-1', 'sharing-google-' . $post->ID );
  688. }
  689. }
  690. public function get_state() {
  691. return $this->state;
  692. }
  693. public function process_request( $post, array $post_data ) {
  694. if ( isset( $post_data['state'] ) ) {
  695. $this->state = $post_data['state'];
  696. }
  697. // Record stats
  698. parent::process_request( $post, $post_data );
  699. // Redirect to Google +'s sharing endpoint
  700. $url = 'https://plus.google.com/share?url=' . rawurlencode( $this->get_share_url( $post->ID ) );
  701. wp_redirect( $url );
  702. die();
  703. }
  704. public function display_footer() {
  705. global $post;
  706. if ( $this->smart ) { ?>
  707. <script type="text/javascript">
  708. (function() {
  709. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
  710. po.src = 'https://apis.google.com/js/plusone.js';
  711. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  712. })();
  713. </script>
  714. <?php
  715. } else {
  716. $this->js_dialog( 'google-plus-1', array( 'width' => 480, 'height' => 550 ) );
  717. }
  718. }
  719. public function get_total( $post = false ) {
  720. global $wpdb, $blog_id;
  721. $name = strtolower( $this->get_id() );
  722. if ( $post == false ) {
  723. // get total number of shares for service
  724. return $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $blog_id, $name ) );
  725. }
  726. //get total shares for a post
  727. 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 ) );
  728. }
  729. }
  730. class Share_Custom extends Sharing_Advanced_Source {
  731. private $name;
  732. private $icon;
  733. private $url;
  734. public $smart = true;
  735. var $shortname;
  736. public function get_class() {
  737. return 'custom share-custom-' . sanitize_html_class( strtolower( $this->name ) );
  738. }
  739. public function __construct( $id, array $settings ) {
  740. parent::__construct( $id, $settings );
  741. $opts = $this->get_options();
  742. if ( isset( $settings['name'] ) ) {
  743. $this->name = $settings['name'];
  744. $this->shortname = preg_replace( '/[^a-z0-9]*/', '', $settings['name'] );
  745. }
  746. if ( isset( $settings['icon'] ) ) {
  747. $this->icon = $settings['icon'];
  748. $new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) );
  749. $i = 0;
  750. while ( $new_icon != $this->icon ) {
  751. if ( $i > 5 ) {
  752. $this->icon = false;
  753. break;
  754. } else {
  755. $this->icon = $new_icon;
  756. $new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) );
  757. }
  758. $i++;
  759. }
  760. }
  761. if ( isset( $settings['url'] ) )
  762. $this->url = $settings['url'];
  763. }
  764. public function get_name() {
  765. return $this->name;
  766. }
  767. public function get_display( $post ) {
  768. $str = $this->get_link( get_permalink( $post->ID ), esc_html( $this->name ), sprintf( __( 'Click to share on %s', 'jetpack' ), esc_attr( $this->name ) ), 'share='.$this->id );
  769. return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str );
  770. }
  771. public function process_request( $post, array $post_data ) {
  772. $url = str_replace( '&amp;', '&', $this->url );
  773. $url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
  774. $url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
  775. $url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
  776. if ( strpos( $url, '%post_tags%' ) !== false ) {
  777. $tags = get_the_tags( $post->ID );
  778. $tagged = '';
  779. if ( $tags ) {
  780. foreach ( $tags AS $tag ) {
  781. $tagged[] = rawurlencode( $tag->name );
  782. }
  783. $tagged = implode( ',', $tagged );
  784. }
  785. $url = str_replace( '%post_tags%', $tagged, $url );
  786. }
  787. if ( strpos( $url, '%post_excerpt%' ) !== false ) {
  788. $url_excerpt = $post->post_excerpt;
  789. if ( empty( $url_excerpt ) )
  790. $url_excerpt = $post->post_content;
  791. $url_excerpt = strip_tags( strip_shortcodes( $url_excerpt ) );
  792. $url_excerpt = wp_html_excerpt( $url_excerpt, 100 );
  793. $url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) );
  794. $url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url );
  795. }
  796. // Record stats
  797. parent::process_request( $post, $post_data );
  798. // Redirect
  799. wp_redirect( $url );
  800. die();
  801. }
  802. public function display_options() {
  803. ?>
  804. <div class="input">
  805. <table class="form-table">
  806. <tbody>
  807. <tr>
  808. <th scope="row"><?php _e( 'Label', 'jetpack' ); ?></th>
  809. <td><input type="text" name="name" value="<?php echo esc_attr( $this->name ); ?>" /></td>
  810. </tr>
  811. <tr>
  812. <th scope="row"><?php _e( 'URL', 'jetpack' ); ?></th>
  813. <td><input type="text" name="url" value="<?php echo esc_attr( $this->url ); ?>" /></td>
  814. </tr>
  815. <tr>
  816. <th scope="row"><?php _e( 'Icon', 'jetpack' ); ?></th>
  817. <td><input type="text" name="icon" value="<?php echo esc_attr( $this->icon ); ?>" /></td>
  818. </tr>
  819. <tr>
  820. <th scope="row"></th>
  821. <td>
  822. <input class="button-secondary" type="submit" value="<?php esc_attr_e( 'Save', 'jetpack' ); ?>" />
  823. <a href="#" class="remove"><small><?php _e( 'Remove Service', 'jetpack' ); ?></small></a>
  824. </td>
  825. </tr>
  826. </tbody>
  827. </table>
  828. </div>
  829. <?php
  830. }
  831. public function update_options( array $data ) {
  832. $name = trim( wp_html_excerpt( wp_kses( stripslashes( $data['name'] ), array() ), 30 ) );
  833. $url = trim( esc_url_raw( $data['url'] ) );
  834. $icon = trim( esc_url_raw( $data['icon'] ) );
  835. if ( $name )
  836. $this->name = $name;
  837. if ( $url )
  838. $this->url = $url;
  839. if ( $icon )
  840. $this->icon = $icon;
  841. }
  842. public function get_options() {
  843. return array(
  844. 'name' => $this->name,
  845. 'icon' => $this->icon,
  846. 'url' => $this->url,
  847. );
  848. }
  849. public function display_preview( $echo = true, $force_smart = false, $button_style = null ) {
  850. $opts = $this->get_options();
  851. $text = '&nbsp;';
  852. if ( !$this->smart )
  853. if ( $this->button_style != 'icon' )
  854. $text = $this->get_name();
  855. $klasses = array( 'share-'.$this->shortname );
  856. if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' )
  857. $klasses[] = 'share-icon';
  858. if ( $this->button_style == 'icon' ) {
  859. $text = '';
  860. $klasses[] = 'no-text';
  861. }
  862. if ( $this->button_style == 'text' )
  863. $klasses[] = 'no-icon';
  864. $link = sprintf(
  865. '<a rel="nofollow" class="%s" href="javascript:void(0);return false;" title="%s"><span style="background-image:url(&quot;%s&quot;) !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>',
  866. implode( ' ', $klasses ),
  867. $this->get_name(),
  868. addcslashes( esc_url_raw( $opts['icon'] ), '"' ),
  869. $text
  870. );
  871. ?>
  872. <div class="option option-smart-off">
  873. <?php echo $link ; ?>
  874. </div><?php
  875. }
  876. }
  877. class Share_Tumblr extends Sharing_Source {
  878. var $shortname = 'tumblr';
  879. var $genericon = '\f214';
  880. public function __construct( $id, array $settings ) {
  881. parent::__construct( $id, $settings );
  882. if ( 'official' == $this->button_style )
  883. $this->smart = true;
  884. else
  885. $this->smart = false;
  886. }
  887. public function get_name() {
  888. return __( 'Tumblr', 'jetpack' );
  889. }
  890. public function get_display( $post ) {
  891. if ( $this->smart ) {
  892. $target = '';
  893. if ( true == $this->open_link_in_new )
  894. $target = '_blank';
  895. 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>';
  896. } else {
  897. return $this->get_link( get_permalink( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' );
  898. }
  899. }
  900. public function process_request( $post, array $post_data ) {
  901. // Record stats
  902. parent::process_request( $post, $post_data );
  903. // Redirect to Tumblr's sharing endpoint (a la their bookmarklet)
  904. $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=';
  905. wp_redirect( $url );
  906. die();
  907. }
  908. // http://www.tumblr.com/share?v=3&u=URL&t=TITLE&s=
  909. public function display_footer() {
  910. if ( $this->smart ) {
  911. ?><script type="text/javascript" src="//platform.tumblr.com/v1/share.js"></script><?php
  912. } else {
  913. $this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
  914. }
  915. }
  916. }
  917. class Share_Pinterest extends Sharing_Source {
  918. var $shortname = 'pinterest';
  919. var $genericon = '\f209';
  920. public function __construct( $id, array $settings ) {
  921. parent::__construct( $id, $settings );
  922. if ( 'official' == $this->button_style )
  923. $this->smart = true;
  924. else
  925. $this->smart = false;
  926. }
  927. public function get_name() {
  928. return __( 'Pinterest', 'jetpack' );
  929. }
  930. public function get_display( $post ) {
  931. $share_url = 'http://pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&description=' . rawurlencode( $post->post_title );
  932. $display = '';
  933. if ( $this->smart )
  934. $display .= sprintf( '<div class="pinterest_button"><a href="%s" data-pin-do="buttonBookmark" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>', esc_url( $share_url ) );
  935. else
  936. $display = $this->get_link( get_permalink( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Click to share on Pinterest', 'jetpack' ), 'share=pinterest', 'sharing-pinterest-' . $post->ID );
  937. if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
  938. sharing_register_post_for_share_counts( $post->ID );
  939. }
  940. return $display;
  941. }
  942. public function process_request( $post, array $post_data ) {
  943. // Record stats
  944. parent::process_request( $post, $post_data );
  945. // If we're triggering the multi-select panel, then we don't need to redirect to Pinterest
  946. if ( !isset( $_GET['js_only'] ) ) {
  947. $pinterest_url = esc_url_raw( 'http://pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&description=' . rawurlencode( $this->get_share_title( $post->ID ) ) );
  948. wp_redirect( $pinterest_url );
  949. } else {
  950. echo '// share count bumped';
  951. }
  952. die();
  953. }
  954. public function display_footer() {
  955. ?>
  956. <?php if ( $this->smart ) : ?>
  957. <script type="text/javascript">
  958. // Pinterest shared resources
  959. var s = document.createElement("script");
  960. s.type = "text/javascript";
  961. s.async = true;
  962. s.src = window.location.protocol + "//assets.pinterest.com/js/pinit.js";
  963. var x = document.getElementsByTagName("script")[0];
  964. x.parentNode.insertBefore(s, x);
  965. // if 'Pin it' button has 'counts' make container wider
  966. jQuery(window).load( function(){ jQuery( 'li.share-pinterest a span:visible' ).closest( '.share-pinterest' ).width( '80px' ); } );
  967. </script>
  968. <?php else : ?>
  969. <script type="text/javascript">
  970. jQuery(document).on('ready', function(){
  971. jQuery('body').on('click', 'a.share-pinterest', function(e){
  972. e.preventDefault();
  973. // Load Pinterest Bookmarklet code
  974. var s = document.createElement("script");
  975. s.type = "text/javascript";
  976. s.src = window.location.protocol + "//assets.pinterest.com/js/pinmarklet.js?r=" + ( Math.random() * 99999999 );
  977. var x = document.getElementsByTagName("script")[0];
  978. x.parentNode.insertBefore(s, x);
  979. // Trigger Stats
  980. var s = document.createElement("script");
  981. s.type = "text/javascript";
  982. s.src = this + ( this.toString().indexOf( '?' ) ? '&' : '?' ) + 'js_only=1';
  983. var x = document.getElementsByTagName("script")[0];
  984. x.parentNode.insertBefore(s, x);
  985. });
  986. });
  987. </script>
  988. <?php endif;
  989. }
  990. }
  991. class Share_Pocket extends Sharing_Source {
  992. var $shortname = 'pocket';
  993. var $genericon = '\f224';
  994. public function __construct( $id, array $settings ) {
  995. parent::__construct( $id, $settings );
  996. if ( 'official' == $this->button_style )
  997. $this->smart = true;
  998. else
  999. $this->smart = false;
  1000. }
  1001. public function get_name() {
  1002. return __( 'Pocket', 'jetpack' );
  1003. }
  1004. public function process_request( $post, array $post_data ) {
  1005. // Record stats
  1006. parent::process_request( $post, $post_data );
  1007. $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 ) ) );
  1008. wp_redirect( $pocket_url );
  1009. exit;
  1010. }
  1011. public function get_display( $post ) {
  1012. if ( $this->smart ) {
  1013. $post_count = 'horizontal';
  1014. $button = '';
  1015. $button .= '<div class="pocket_button">';
  1016. $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' ) );
  1017. $button .= '</div>';
  1018. return $button;
  1019. } else {
  1020. return $this->get_link( get_permalink( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' );
  1021. }
  1022. }
  1023. function display_footer() {
  1024. if ( $this->smart ) :
  1025. ?>
  1026. <script>
  1027. // Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS.
  1028. function jetpack_sharing_pocket_init() {
  1029. jQuery.getScript( 'https://widgets.getpocket.com/v1/j/btn.js?v=1' );
  1030. }
  1031. jQuery( document ).on( 'ready', jetpack_sharing_pocket_init );
  1032. jQuery( document.body ).on( 'post-load', jetpack_sharing_pocket_init );
  1033. </script>
  1034. <?php
  1035. else :
  1036. $this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
  1037. endif;
  1038. }
  1039. }