Posted By

martias21 on 07/08/11


Tagged

cubepoints


Versions (?)

CubePoints Notify Pop-up Redesign: notice.php


 / Published in: PHP
 

The file is located at wp-content\plugins\cubepoints\modules\notice

  1. <?php
  2.  
  3. /** Notify Module */
  4.  
  5. cp_module_register(__('Notify', 'cp') , 'notify' , '1.0', 'CubePoints', 'http://cubepoints.com', 'http://cubepoints.com' , __('After activating this module, a growl-like pop-up will appear to your users each time they earn points.', 'cp'), 1);
  6.  
  7. function cp_module_notify_install(){
  8. global $wpdb;
  9. if($wpdb->get_var("SHOW TABLES LIKE '".CP_DB."_notify'") != CP_DB.'_notify' || (int) get_option('cp_module_notify_db_version') < 1) {
  10. $sql = "CREATE TABLE " . CP_DB . "_notify (
  11. id bigint(20) NOT NULL AUTO_INCREMENT,
  12. uid bigint(20) NOT NULL,
  13. notice text NOT NULL,
  14. UNIQUE KEY id (id)
  15. );";
  16. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  17. dbDelta($sql);
  18. add_option("cp_module_notify_db_version'", "1.0");
  19. add_option("cp_module_notify_header", "CubePoints Notice");
  20. }
  21. }
  22. add_action('cp_module_notify_activate','cp_module_notify_install');
  23.  
  24. function cp_module_notify_uninstall(){
  25. global $wpdb;
  26. $wpdb->query('DROP TABLE `'.CP_DB.'_notify`');
  27. }
  28. add_action('cp_module_notify_deactivate','cp_module_notify_uninstall');
  29.  
  30. if(cp_module_activated('notify')){
  31. /**********************
  32. * Enqueuing Scripts
  33. ***********************/
  34. wp_register_script(
  35. 'jQuery_notice',
  36. WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)). 'jquery.notice.js',
  37. array('jquery'),
  38. '1.0.1'
  39. );
  40. wp_register_style(
  41. 'jQuery_notice',
  42. WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)). 'jquery.notice.css'
  43. );
  44.  
  45. function cp_notify_script(){
  46. wp_enqueue_script('jquery');
  47. wp_enqueue_script('jQuery_notice');
  48. }
  49. function cp_notify_style(){
  50. wp_enqueue_style('jQuery_notice');
  51. }
  52.  
  53. add_action('init', 'cp_notify_script');
  54. add_action('init', 'cp_notify_style');
  55. /************************
  56. * Enqueue End
  57. ************************/
  58.  
  59. /**********************
  60. * Config
  61. ***********************/
  62. function cp_module_notify_config(){
  63. ?>
  64. <br />
  65. <h3><?php _e('Notify','cp'); ?></h3>
  66. <table class="form-table">
  67. <tr valign="top">
  68. <th scope="row"><label for="cp_module_notify_header"><?php _e('Notify Header (leave blank)', 'cp'); ?>:</label></th>
  69. <td valign="middle"><input type="text" id="cp_module_notify_header" name="cp_module_notify_header" value="<?php echo get_option('cp_module_notify_header'); ?>" size="30" /></td>
  70. </tr>
  71. </table>
  72. <?php
  73. }
  74. add_action('cp_config_form','cp_module_notify_config');
  75.  
  76. function cp_module_notify_config_process(){
  77. $cp_module_notify_header = $_POST['cp_module_notify_header'];
  78. update_option('cp_module_notify_header', $cp_module_notify_header);
  79. }
  80. add_action('cp_config_process','cp_module_notify_config_process');
  81. /**********************
  82. * Config End
  83. ***********************/
  84.  
  85.  
  86. add_action('wp_footer', 'cp_module_notify_display_hook', 10, 1);
  87. function cp_module_notify_display($text = ''){
  88. if($text==''){ return; }
  89. $header = get_option('cp_module_notify_header');
  90.  
  91. echo '<script>jQuery.noticeAdd({';
  92. echo ' text: "';
  93. if($header != '') echo '<span class=\'notice-header\'>'.$header.'</span>'; echo $text; echo '",';
  94. echo 'stay: false';
  95. echo '});</script>';
  96. }
  97. function cp_module_notify_hook(){
  98. $notices = apply_filters('cp_module_notify', array());
  99. foreach($notices as $notice){
  100. cp_module_notify_queue($notice);
  101. }
  102. }
  103. function cp_module_notify_queue($notice){
  104. global $wpdb;
  105. $wpdb->insert( CP_DB.'_notify', array( 'uid' => $notice[0], 'notice' => $notice[1] ) );
  106. }
  107. function cp_module_notify_display_hook(){
  108. $notices = apply_filters('cp_module_notify_display_hook', array());
  109. foreach($notices as $notice){
  110. cp_module_notify_display($notice);
  111. }
  112. }
  113. function cp_module_notify_displayNoticesFor($uid){
  114. if($uid==''){return;}
  115. global $wpdb;
  116. $results = $wpdb->get_results('SELECT * FROM `'.CP_DB.'_notify` WHERE `uid`='.$uid.' ORDER BY id DESC');
  117. $wpdb->query('DELETE FROM `'.CP_DB.'_notify` WHERE `uid`='.$uid);
  118. foreach($results as $result){
  119. add_filter('cp_module_notify_display_hook',create_function('$query', '$query[]="'.htmlentities($result->notice).'"; return $query;'));
  120. }
  121. }
  122. add_action('init', 'cp_module_notify_hook',0,2);
  123.  
  124. function cp_module_notify_msg_filter($d){
  125. list($m, $type, $uid, $points, $data) = $d;
  126. $user = get_userdata($uid);
  127. $m = str_replace('%npoints%',abs($points),$m);
  128. $m = str_replace('%points%',cp_formatPoints(abs($points)),$m);
  129. $m = str_replace('%type%',$type,$m);
  130. $m = str_replace('%username%',$user->user_login,$m);
  131. $m = str_replace('%user%',$user->display_name,$m);
  132. return array($m);
  133. }
  134. add_filter('cp_module_notify_msg','cp_module_notify_msg_filter',99999);
  135.  
  136. function cp_module_notify_do(){
  137. cp_module_notify_displayNoticesFor(cp_currentUser());
  138. }
  139. add_action('wp_footer', 'cp_module_notify_do',1);
  140.  
  141. /** hook into cp_points() */
  142. add_action('cp_log','cp_module_notify_logsHook',10,4);
  143. function cp_module_notify_logsHook($type, $uid, $points, $data){
  144. if($points>0){
  145. $m= __('+%npoints%', 'cp');
  146. } else {
  147. $m=__('-%npoints%', 'cp');
  148. }
  149. $m = apply_filters('cp_module_notify_msg',array($m, $type, $uid, $points, $data));
  150. $message = $m[0];
  151. cp_module_notify_queue(array( $uid, $message ));
  152. }
  153.  
  154. /** Messages for common log items */
  155. function cp_module_notify_msg_common($d){
  156. list($m, $type, $uid, $points, $data) = $d;
  157. switch ($type) {
  158. case 'comment':
  159. $m = __('+%npoints%', 'cp');
  160. break;
  161. case 'post':
  162. $m = __('+%npoints%', 'cp');
  163. break;
  164. }
  165. return array($m, $type, $uid, $points, $data);
  166. }
  167. add_filter('cp_module_notify_msg','cp_module_notify_msg_common',1);
  168.  
  169. }
  170. ?>

Report this snippet  

You need to login to post a comment.