AndreaGooglePlusComments

The WordPress Google Plus Comments AndreaGooglePlusComments class.

Defined (1)

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

/google-plus-comments.php  
  1. class AndreaGooglePlusComments { 
  2. /** 
  3. * Class Constructor 
  4. */ 
  5. function AndreaGooglePlusComments() { 
  6.  
  7.  
  8. /** 
  9. * Enabled the AndreaGooglePlusComments plugin with registering all required hooks 
  10. */ 
  11. function Enable() { 
  12.  
  13. add_action('admin_menu', array("AndreaGooglePlusComments", 'GooglePlusCommentsMenu')); 
  14. //add_action("wp_insert_post", array("AndreaFacebookSend", "SetFacebookSendCode")); 
  15. add_action('wp_head', array("AndreaGooglePlusComments", 'GooglePlusCommentsInit')); 
  16. $options_after = get_option( 'google_plus_comments_after_content' ); 
  17. $options_replace_wp = get_option( 'google_plus_comments_replace_wp' ); 
  18. $options_size = get_option( 'google_plus_comments_size' ); 
  19. if ($options_after) { 
  20. add_filter("the_content", array("AndreaGooglePlusComments", "SetGooglePlusOneCodeFilter")); 
  21. if ($options_replace_wp) { 
  22. //add_action("comments_template", array("AndreaGooglePlusComments", "SetGooglePlusCommentsCode")); 
  23. add_filter("comments_template", array("AndreaGooglePlusComments", "SetGooglePlusCommentsCode")); 
  24. }  
  25.  
  26.  
  27. /** 
  28. * Set the Admin editor to set options 
  29. */ 
  30.  
  31. function SetAdminConfiguration() { 
  32. add_action('admin_menu', array("AndreaGooglePlusComments", 'GooglePlusCommentsMenu')); 
  33. return true; 
  34.  
  35. function GooglePlusCommentsInit() { 
  36. $google_lang = get_option( 'google_plus_comments_lang' ); 
  37. if (is_single()) { 
  38. /**wp_deregister_script('registra_google_plus_comments_js'); 
  39. wp_register_script('registra_google_plus_comments_js', 'http://apis.google.com/js/plusone.js', false, null, true); 
  40. add_action('init', array(&$this, "registra_google_plus_comments_js"));*/ 
  41. echo '<script type="text/javascript" src="http://apis.google.com/js/plusone.js">'; 
  42. if ($google_lang!='') {echo "{lang: '".$google_lang."'}";} 
  43. echo '</script>'; 
  44. echo "<style>div[id^='___comments_'], div[id^='___comments_'] iframe {width: 100% !important;}</style>"; 
  45.  
  46. /**function registra_google_plus_comments_js() { 
  47. wp_enqueue_script('registra_google_plus_comments_js'); 
  48. }*/ 
  49.  
  50. function GooglePlusCommentsMenu() { 
  51. add_options_page('Google Plus Comments Options', 'Google Plus Comments', 'manage_options', 'google-plus-comments-options', array("AndreaGooglePlusComments", 'GooglePlusCommentsOptions')); 
  52.  
  53. function GooglePlusCommentsOptions() { 
  54. if (!current_user_can('manage_options')) { 
  55. wp_die( __('You do not have sufficient permissions to access this page.') ); 
  56.  
  57. // variables for the field and option names  
  58. $google_plus_comments_replace_wp = 'google_plus_comments_replace_wp'; 
  59. $google_plus_comments_after_content = 'google_plus_comments_after_content'; 
  60. $google_plus_comments_size = 'google_plus_comments_size'; 
  61. $google_plus_comments_lang = 'google_plus_comments_lang'; 
  62.  
  63. $hidden_field_name = 'mt_submit_hidden'; 
  64. $data_field_name_replace_wp = 'google_plus_comments_replace_wp'; 
  65. $data_field_name_after = 'google_plus_comments_after_content'; 
  66. $data_field_comments_size = 'google_plus_comments_size'; 
  67. $data_field_comments_lang = 'google_plus_comments_lang'; 
  68.  
  69. // Read in existing option value from database 
  70. $opt_val_replace_wp = get_option( $google_plus_comments_replace_wp ); 
  71. $opt_val_after = get_option( $google_plus_comments_after_content ); 
  72. $opt_val_comments_size = get_option( $google_plus_comments_size ); 
  73. $opt_val_comments_lang = get_option( $google_plus_comments_lang ); 
  74.  
  75. // See if the user has posted us some information 
  76. // If they did, this hidden field will be set to 'Y' 
  77. if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' ) { 
  78. // Read their posted value 
  79. $opt_val_replace_wp = $_POST[ $data_field_name_replace_wp ]; 
  80. $opt_val_after = $_POST[ $data_field_name_after ]; 
  81. $opt_val_comments_size = $_POST[ $data_field_comments_size ]; 
  82. $opt_val_comments_lang = $_POST[ $data_field_comments_lang ]; 
  83.  
  84. // Save the posted value in the database 
  85. update_option( $google_plus_comments_replace_wp, $opt_val_replace_wp ); 
  86. update_option( $google_plus_comments_after_content, $opt_val_after ); 
  87. update_option( $google_plus_comments_size, $opt_val_comments_size ); 
  88. update_option( $google_plus_comments_lang, $opt_val_comments_lang ); 
  89.  
  90. // Put an settings updated message on the screen 
  91.  
  92. ?> 
  93. <div class="updated"><p><strong><?php _e('settings saved.', 'menu-google-plus-comments' ); ?></strong></p></div> 
  94. <?php 
  95.  
  96. // Now display the settings editing screen 
  97. echo '<div class="wrap">'; 
  98. // header 
  99. echo "<h2>" . __( 'Google Plus Comments Options', 'menu-google-plus-comments' ) . "</h2>"; 
  100. // settings form 
  101.  
  102. ?> 
  103.  
  104. <form name="form1" method="post" action=""> 
  105. <input type="hidden" name="<?php echo $hidden_field_name; ?>" value="Y"> 
  106.  
  107. <?php $options_replace_wp = get_option( 'google_plus_comments_replace_wp' ); ?> 
  108. <p><?php _e("Show before Wordpress Comments:", 'menu-google-plus-comments' ); ?>  
  109. <input type="checkbox" name="google_plus_comments_replace_wp" value="1"<?php checked( 1 == $options_replace_wp ); ?> /> 
  110.  
  111. <?php $options_before = get_option( 'google_plus_comments_after_content' ); ?> 
  112. <p><?php _e("Show After Content:", 'menu-google-plus-comments' ); ?>  
  113. <input type="checkbox" name="google_plus_comments_after_content" value="1"<?php checked( 1 == $options_before ); ?> /> <b><span style="color:#ff0000">(use only if replacing comments not working</span></b></p> 
  114.  
  115. <?php $options_size = get_option( 'google_plus_comments_size' ); ?> 
  116. <p><?php _e("Button Size:", 'menu-google-plus-comments' ); ?>  
  117. <input type="text" name="google_plus_comments_size" value="<?php echo $options_size; ?>" /> (put the width in pixel - IE: 600)</p> 
  118.  
  119. <?php $options_lang = get_option( 'google_plus_comments_lang' ); ?> 
  120. <p><?php _e("Language:", 'menu-google-plus-comments' ); ?>  
  121. <input type="text" name="google_plus_comments_lang" value="<?php echo $options_lang; ?>" /> (default blank is en, you can put it for italian.)</p> 
  122.  
  123. <p class="submit"> 
  124. <input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 
  125. </p> 
  126.  
  127. </form> 
  128. <?php echo "<h2>" . __( 'Put Function in Your Theme', 'menu-google-plus-comments' ) . "</h2>"; ?> 
  129. <p>If you want to put the box anywhere in your theme or you have problem showing the box simply use this function:</p> 
  130. <p>if (function_exists('andrea_google_plus_comments')) { andrea_google_plus_comments(); }</p> 
  131. </div> 
  132.  
  133. <?php 
  134.  
  135.  
  136. /** 
  137. * Setup Iframe Buttons for actions 
  138. */ 
  139.  
  140. function SetGooglePlusCommentsCode() { 
  141.  
  142. $google_size = get_option( 'google_plus_comments_size' ); 
  143. $sizer = $google_size; 
  144.  
  145.  
  146. $button = '<div class="g-comments" '; 
  147. $button .= 'data-href="'. get_permalink().'" '; 
  148. $button .= 'data-width="'.$sizer.'" '; 
  149. $button .= 'data-first_party_property="BLOGGER" '; 
  150. $button .= 'data-view_type="FILTERED_POSTMOD">'; 
  151. $button .= '</div>'; 
  152.  
  153. echo $button; 
  154. }  
  155.  
  156. /** 
  157. * Setup Iframe Buttons for Filter 
  158. */ 
  159.  
  160. function SetGooglePlusCommentsCodeFilter($content) { 
  161.  
  162. $google_size = get_option( 'google_plus_comments_size' ); 
  163. $sizer = $google_size; 
  164.  
  165. $button = '<div class="g-comments" '; 
  166. $button .= 'data-href="'. get_permalink().'" '; 
  167. $button .= 'data-width="'.$sizer.'"'; 
  168. $button .= 'data-first_party_property="BLOGGER" '; 
  169. $button .= 'data-view_type="FILTERED_POSTMOD">'; 
  170. $button .= '</div>'; 
  171.  
  172. return $content.$button; 
  173. }  
  174.  
  175. /** 
  176. * Returns the plugin version 
  177. * Uses the WP API to get the meta data from the top of this file (comment) 
  178. * @return string The version like 1.0.0 
  179. */ 
  180. function GetVersion() { 
  181. if(!function_exists('get_plugin_data')) { 
  182. if(file_exists(ABSPATH . 'wp-admin/includes/plugin.php')) require_once(ABSPATH . 'wp-admin/includes/plugin.php'); //2.3+ 
  183. else if(file_exists(ABSPATH . 'wp-admin/admin-functions.php')) require_once(ABSPATH . 'wp-admin/admin-functions.php'); //2.1 
  184. else return "0.ERROR"; 
  185. $data = get_plugin_data(__FILE__); 
  186. return $data['Version']; 
  187.