Share_Pocket

The Jetpack by WordPress.com Share Pocket class.

Defined (1)

The class is defined in the following location(s).

/modules/sharedaddy/sharing-sources.php  
  1. class Share_Pocket extends Sharing_Source { 
  2. public $shortname = 'pocket'; 
  3. public $genericon = '\f224'; 
  4.  
  5. public function __construct( $id, array $settings ) { 
  6. parent::__construct( $id, $settings ); 
  7.  
  8. if ( 'official' == $this->button_style ) 
  9. $this->smart = true; 
  10. else 
  11. $this->smart = false; 
  12.  
  13. public function get_name() { 
  14. return __( 'Pocket', 'jetpack' ); 
  15.  
  16. public function process_request( $post, array $post_data ) { 
  17. // Record stats 
  18. parent::process_request( $post, $post_data ); 
  19.  
  20. $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 ) ) ); 
  21. wp_redirect( $pocket_url ); 
  22. exit; 
  23.  
  24. public function get_display( $post ) { 
  25. if ( $this->smart ) { 
  26. $post_count = 'horizontal'; 
  27.  
  28. $button = ''; 
  29. $button .= '<div class="pocket_button">'; 
  30. $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' ) ); 
  31. $button .= '</div>'; 
  32.  
  33. return $button; 
  34. } else { 
  35. return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' ); 
  36.  
  37.  
  38. function display_footer() { 
  39. if ( $this->smart ) : 
  40. ?> 
  41. <script> 
  42. // Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS. 
  43. function jetpack_sharing_pocket_init() { 
  44. jQuery.getScript( 'https://widgets.getpocket.com/v1/j/btn.js?v=1' ); 
  45. jQuery( document ).on( 'ready', jetpack_sharing_pocket_init ); 
  46. jQuery( document.body ).on( 'post-load', jetpack_sharing_pocket_init ); 
  47. </script> 
  48. <?php 
  49. else : 
  50. $this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); 
  51. endif; 
  52.  
  53.