Share_GooglePlus1

The Jetpack by WordPress.com Share GooglePlus1 class.

Defined (1)

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

/modules/sharedaddy/sharing-sources.php  
  1. class Share_GooglePlus1 extends Sharing_Source { 
  2. public $shortname = 'googleplus1'; 
  3. public $genericon = '\f218'; 
  4. private $state = false; 
  5.  
  6. public function __construct( $id, array $settings ) { 
  7. parent::__construct( $id, $settings ); 
  8.  
  9. if ( 'official' == $this->button_style ) 
  10. $this->smart = true; 
  11. else 
  12. $this->smart = false; 
  13.  
  14. public function get_name() { 
  15. return __( 'Google', 'jetpack' ); 
  16.  
  17. public function has_custom_button_style() { 
  18. return $this->smart; 
  19.  
  20. public function get_display( $post ) { 
  21.  
  22. if ( $this->smart ) { 
  23. $share_url = $this->get_share_url( $post->ID ); 
  24. return '<div class="googleplus1_button"><div class="g-plus" data-action="share" data-annotation="bubble" data-href="' . esc_url( $share_url ) . '"></div></div>'; 
  25. } else { 
  26. 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 ); 
  27.  
  28. public function get_state() { 
  29. return $this->state; 
  30.  
  31. public function process_request( $post, array $post_data ) { 
  32.  
  33. if ( isset( $post_data['state'] ) ) { 
  34. $this->state = $post_data['state']; 
  35. // Record stats 
  36. parent::process_request( $post, $post_data ); 
  37.  
  38. // Redirect to Google +'s sharing endpoint 
  39. $url = 'https://plus.google.com/share?url=' . rawurlencode( $this->get_share_url( $post->ID ) ); 
  40. wp_redirect( $url ); 
  41. die(); 
  42.  
  43. public function display_footer() { 
  44. global $post; 
  45.  
  46. if ( $this->smart ) { ?> 
  47. <script> 
  48. function renderGooglePlus1() { 
  49. if ( 'undefined' === typeof gapi ) { 
  50. return; 
  51.  
  52. jQuery( '.g-plus' ).each(function() { 
  53. var $button = jQuery( this ); 
  54.  
  55. if ( ! $button.data( 'gplus-rendered' ) ) { 
  56. gapi.plusone.render( this, { 
  57. href: $button.attr( 'data-href' ),  
  58. size: $button.attr( 'data-size' ),  
  59. annotation: $button.attr( 'data-annotation' ) 
  60. }); 
  61.  
  62. $button.data( 'gplus-rendered', true ); 
  63. }); 
  64.  
  65. (function() { 
  66. var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 
  67. po.src = 'https://apis.google.com/js/plusone.js'; 
  68. po.innerHTML = '{"parsetags": "explicit"}'; 
  69. po.onload = renderGooglePlus1; 
  70. var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 
  71. })(); 
  72.  
  73. jQuery( document.body ).on( 'post-load', renderGooglePlus1 ); 
  74. </script> 
  75. <?php 
  76. } else { 
  77. $this->js_dialog( 'google-plus-1', array( 'width' => 480, 'height' => 550 ) ); 
  78.  
  79. public function get_total( $post = false ) { 
  80. global $wpdb, $blog_id; 
  81.  
  82. $name = strtolower( $this->get_id() ); 
  83.  
  84. if ( $post == false ) { 
  85. // get total number of shares for service 
  86. return $wpdb->get_var( $wpdb->prepare( "SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s", $blog_id, $name ) ); 
  87.  
  88. //get total shares for a post 
  89. 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 ) );