[61] | 1 | <?php
|
---|
[95] | 2 |
|
---|
[91] | 3 | function onaction_publish_post_notify($new_status, $old_status, $post)
|
---|
[61] | 4 | {
|
---|
[91] | 5 | if ($new_status == 'publish'){
|
---|
| 6 | do_PostNotifications($post->ID,'newpost');
|
---|
| 7 | }
|
---|
[61] | 8 | }
|
---|
[91] | 9 |
|
---|
[61] | 10 | function onaction_edit_post_notify($post_id)
|
---|
| 11 | {
|
---|
| 12 | do_PostNotifications($post_id,'editpost');
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | function onaction_comment_notify($commentID){
|
---|
| 16 | global $wpdb;
|
---|
| 17 | $status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $commentID");
|
---|
| 18 | $post_id = $wpdb->get_var("SELECT comment_post_ID FROM $wpdb->comments WHERE comment_ID = $commentID");
|
---|
| 19 |
|
---|
| 20 | if ($status ==1){
|
---|
| 21 | do_CommentNotifications($commentID, $post_id);
|
---|
| 22 | } else {
|
---|
[95] | 23 | do_CommentWaiting($commentID, $post_id);
|
---|
[61] | 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | function onaction_comment_apobe_notify($commentID){
|
---|
| 28 | global $wpdb;
|
---|
| 29 | $comment_type = $wpdb->get_var("SELECT comment_type FROM $wpdb->comments WHERE comment_ID = $commentID");
|
---|
| 30 | $status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $commentID");
|
---|
| 31 | if(is_null($status)) return;
|
---|
| 32 | if ($status == 1){
|
---|
| 33 | onaction_comment_notify($commentID);
|
---|
| 34 | }
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[95] | 37 | function Notification_triggerEvent($category, $item_id, $event, $extra_tags=array(), $user_list=array(), $omit_user_id=null)
|
---|
| 38 | {
|
---|
| 39 | global $xoops_db,$xoops_config;
|
---|
| 40 | //When notifying by a private message,
|
---|
| 41 | //it is evaded that the data base becomes read-only as a result of the check on the referrer and the method.
|
---|
[352] | 42 | if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = 'call $notification_handler->triggerEvent');
|
---|
[95] | 43 | if (is_wp_cron_page_call() ){
|
---|
| 44 | $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST] . $_SERVER['PHP_SELF'];
|
---|
| 45 | $_SERVER['REQUEST_METHOD'] = 'POST';
|
---|
[352] | 46 | if (function_exists('xpress_debug')) xpress_debug($title = 'wp_cron_page_call',true);
|
---|
[95] | 47 | }
|
---|
| 48 | if (is_xmlrpc_call() ){
|
---|
| 49 | $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST] . $_SERVER['PHP_SELF'];
|
---|
| 50 | $_SERVER['REQUEST_METHOD'] = 'POST';
|
---|
| 51 | }
|
---|
[96] | 52 | // set_error_handler("xpress_error_handler");
|
---|
[352] | 53 | // if ($xoops_config->is_impress != true){ // impress cms is error
|
---|
| 54 | // if ( !defined("XOOPS_MAINFILE_INCLUDED")) {
|
---|
| 55 | // require_once $xoops_config->xoops_mainfile_path; // load XOOPS System
|
---|
| 56 | // }
|
---|
| 57 | // }
|
---|
[343] | 58 | if ( defined("XOOPS_MAINFILE_INCLUDED")) {
|
---|
[352] | 59 | if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = 'call $notification_handler->triggerEvent');
|
---|
[343] | 60 | $module_id = get_xpress_modid() ;
|
---|
| 61 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 62 | $notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
|
---|
[352] | 63 | } else {
|
---|
| 64 | if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = 'not call $notification_handler->triggerEvent');
|
---|
| 65 | $module_id = get_xpress_modid() ;
|
---|
| 66 | Notification_reserve($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
|
---|
[343] | 67 | }
|
---|
[95] | 68 | }
|
---|
| 69 |
|
---|
| 70 | function do_CommentWaiting($commentID, $comment_post_ID)
|
---|
| 71 | {
|
---|
| 72 | // require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
|
---|
| 73 | // $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 74 | Notification_triggerEvent( 'global' , 0 , 'waiting') ;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | function do_CommentNotifications($commentID, $comment_post_ID)
|
---|
| 79 | {
|
---|
[419] | 80 | global $wpdb, $xoops_config , $xoops_db;
|
---|
[95] | 81 |
|
---|
[419] | 82 | $table_term_relationships = $wpdb->term_relationships;
|
---|
| 83 | $table_term_taxonomy = $wpdb->term_taxonomy;
|
---|
| 84 | $table_terms = $wpdb->terms;
|
---|
| 85 | $table_categories = $wpdb->categories;
|
---|
| 86 | $wp_post = $wpdb->posts;
|
---|
| 87 | $wp_options = $wpdb->options;
|
---|
| 88 | $wp_users = $wpdb->users;
|
---|
| 89 | $wp_comments = $wpdb->comments;
|
---|
| 90 |
|
---|
[95] | 91 | $post_id = $comment_post_ID;
|
---|
| 92 |
|
---|
| 93 | $post_title = get_the_title($post_id);
|
---|
| 94 | $post_url = get_permalink($post_id). '#comment';
|
---|
| 95 | $blog_name = get_bloginfo('name');
|
---|
| 96 |
|
---|
| 97 | // query
|
---|
| 98 | $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$comment_post_ID ";
|
---|
| 99 | $post_author = $xoops_db->get_var($sql);
|
---|
| 100 |
|
---|
| 101 | $sql = "SELECT display_name FROM $wp_users WHERE ID ='$post_author'";
|
---|
| 102 | $user_name = $xoops_db->get_var($sql);
|
---|
| 103 |
|
---|
| 104 | $comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
|
---|
| 105 | Notification_triggerEvent('global' , 0 , 'comment' , $comment_tags , false);
|
---|
| 106 | Notification_triggerEvent('author' , $post_author , 'comment' , $comment_tags , false);
|
---|
| 107 | Notification_triggerEvent('post' , $comment_post_ID , 'comment' , $comment_tags , false);
|
---|
| 108 |
|
---|
| 109 | // categorie notification
|
---|
| 110 | if (get_xpress_db_version() < 6124){
|
---|
| 111 | $sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$comment_post_ID;
|
---|
| 112 | } else {
|
---|
| 113 | $sql2 = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
|
---|
| 114 | $sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
|
---|
| 115 | $sql2 .= "WHERE ($table_term_relationships.object_id =" . $comment_post_ID.") AND ($table_term_taxonomy.taxonomy='category')";
|
---|
| 116 | }
|
---|
[347] | 117 | $categories = $xoops_db->get_results($sql2);
|
---|
[95] | 118 | foreach($categories as $categorie){
|
---|
| 119 | $cat_id = $categorie->cat_ID;
|
---|
| 120 | $cat_name = $categorie->cat_name;
|
---|
| 121 | $comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_CAT_TITLE' => $cat_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
|
---|
| 122 | Notification_triggerEvent('category' , $cat_id , 'comment' , $comment_tags , false);
|
---|
| 123 |
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | function do_PostNotifications($post_id,$not_event)
|
---|
| 128 | {
|
---|
[419] | 129 | global $wpdb, $xoops_config, $xoops_db;
|
---|
[95] | 130 |
|
---|
| 131 | // $not_event: newpost,editpost ; $commentID, $comment_post_ID)
|
---|
[419] | 132 |
|
---|
| 133 | $table_term_relationships = $wpdb->term_relationships;
|
---|
| 134 | $table_term_taxonomy = $wpdb->term_taxonomy;
|
---|
| 135 | $table_terms = $wpdb->terms;
|
---|
| 136 | $table_categories = $wpdb->categories;
|
---|
| 137 | $wp_post = $wpdb->posts;
|
---|
| 138 | $wp_options = $wpdb->options;
|
---|
| 139 | $wp_users = $wpdb->users;
|
---|
| 140 | $wp_comments = $wpdb->comments;
|
---|
[95] | 141 |
|
---|
| 142 | $post_title = get_the_title($post_id);
|
---|
[538] | 143 | $post_url = get_permalink($post_id);
|
---|
[95] | 144 | $blog_name = get_bloginfo('name');
|
---|
| 145 |
|
---|
| 146 | // query
|
---|
| 147 | $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$post_id ";
|
---|
| 148 | $post_author = $xoops_db->get_var($sql);
|
---|
| 149 |
|
---|
| 150 | $sql = "SELECT display_name FROM $wp_users WHERE ID ='$post_author'";
|
---|
| 151 | $user_name = $xoops_db->get_var($sql);
|
---|
| 152 |
|
---|
| 153 | $posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
|
---|
| 154 |
|
---|
| 155 | switch ($not_event) {
|
---|
| 156 | case 'newpost' :
|
---|
| 157 | Notification_triggerEvent('global' , 0 , 'newpost' , $posts_tags , false);
|
---|
| 158 | Notification_triggerEvent('author' , $post_author , 'newpost' , $posts_tags , false);
|
---|
| 159 |
|
---|
| 160 | // categorie notification
|
---|
| 161 | if (get_xpress_db_version() < 6124){
|
---|
| 162 | $sql2 = "SELECT c.cat_ID, c.cat_name FROM ".$table_categories." c, ".$table_post2cat." p2c WHERE c.cat_ID = p2c.category_id AND p2c.post_id=".$post_id;
|
---|
| 163 | } else {
|
---|
| 164 | $sql2 = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
|
---|
| 165 | $sql2 .= "FROM $table_term_relationships INNER JOIN ($table_term_taxonomy INNER JOIN $table_terms ON $table_term_taxonomy.term_id = $table_terms.term_id) ON $table_term_relationships.term_taxonomy_id = $table_term_taxonomy.term_taxonomy_id ";
|
---|
| 166 | $sql2 .= "WHERE ($table_term_relationships.object_id =" . $post_id.") AND ($table_term_taxonomy.taxonomy='category')";
|
---|
| 167 | }
|
---|
[347] | 168 | $categories = $xoops_db->get_results($sql2);
|
---|
[95] | 169 | foreach($categories as $categorie){
|
---|
| 170 | $cat_id = $categorie->cat_ID;
|
---|
| 171 | $cat_name = $categorie->cat_name;
|
---|
| 172 | $posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_CAT_TITLE' => $cat_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
|
---|
| 173 | Notification_triggerEvent('category' , $cat_id , 'newpost' , $posts_tags , false);
|
---|
| 174 | }
|
---|
| 175 | break;
|
---|
| 176 | case 'editpost' :
|
---|
| 177 | Notification_triggerEvent('post' , $post_id , 'editpost' , $posts_tags , false);
|
---|
| 178 | break;
|
---|
| 179 | default :
|
---|
| 180 | }
|
---|
[352] | 181 | }
|
---|
[95] | 182 |
|
---|
[352] | 183 | //When the event cannot notify because the XOOPS system is not loaded, the event is stacked.
|
---|
| 184 | function Notification_reserve($category, $item_id=0, $event, $extra_tags=array(), $user_list=array(), $module_id=0, $omit_user_id=null)
|
---|
| 185 | {
|
---|
| 186 | global $xpress_config,$xoops_db;
|
---|
| 187 |
|
---|
| 188 | $xpress_prefix = get_wp_prefix();
|
---|
| 189 | $notfiy_reserve = $xpress_prefix . 'notify_reserve';
|
---|
| 190 |
|
---|
| 191 | $extra_tags_arry = addslashes(serialize($extra_tags));
|
---|
| 192 | $user_list_arry = addslashes(serialize($user_list));
|
---|
| 193 | // $extra_tags_arry = mysql_real_escape_string(serialize($extra_tags));
|
---|
| 194 | // $user_list_arry = mysql_real_escape_string(serialize($user_list));
|
---|
| 195 |
|
---|
| 196 | $notify_reserve_status = 'reserve';
|
---|
| 197 |
|
---|
| 198 | $sql = "INSERT INTO $notfiy_reserve ";
|
---|
| 199 | $sql .= "(notify_reserve_status , category , item_id , event , extra_tags_arry , user_list_arry , module_id , omit_user_id)";
|
---|
| 200 | $sql .= "VALUES ";
|
---|
| 201 | $sql .= "('$notify_reserve_status' , '$category' , $item_id , '$event' , '$extra_tags_arry' , '$user_list_arry' , $module_id , '$omit_user_id')";
|
---|
| 202 | if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = $sql);
|
---|
| 203 |
|
---|
| 204 | $xoops_db->query($sql);
|
---|
| 205 | }
|
---|
| 206 |
|
---|
| 207 | //It calls when the XOOPS system is loaded, and the stacked event notification processing is done.
|
---|
| 208 | function Notification_reserve_send()
|
---|
| 209 | {
|
---|
| 210 | global $xpress_config,$xoops_db;
|
---|
| 211 | if ( ! defined("XOOPS_MAINFILE_INCLUDED")) return;
|
---|
| 212 |
|
---|
| 213 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 214 |
|
---|
| 215 | $xpress_prefix = get_wp_prefix();
|
---|
| 216 | $notfiy_reserve_db = $xpress_prefix . 'notify_reserve';
|
---|
| 217 |
|
---|
| 218 | $extra_tags_arry = addslashes(serialize($extra_tags));
|
---|
| 219 | $user_list_arry = addslashes(serialize($user_list));
|
---|
| 220 |
|
---|
| 221 | $sql = "SELECT * ";
|
---|
| 222 | $sql .= "FROM $notfiy_reserve_db ";
|
---|
| 223 | $sql .= "WHERE notify_reserve_status = 'reserve'";
|
---|
| 224 |
|
---|
| 225 | $notify_reserves = $xoops_db->get_results($sql);
|
---|
| 226 |
|
---|
| 227 | //So as not to process it by other sessions while processing it, status is changed.
|
---|
| 228 | foreach($notify_reserves as $notify){
|
---|
| 229 | $notify_reserve_id = $notify->notify_reserve_id;
|
---|
| 230 | $sql = "UPDATE $notfiy_reserve_db SET notify_reserve_status = 'sending' WHERE notify_reserve_id = $notify_reserve_id";
|
---|
| 231 | $xoops_db->query($sql);
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | foreach($notify_reserves as $notify){
|
---|
| 235 | $notify_reserve_id = $notify->notify_reserve_id;
|
---|
| 236 | $category = $notify->category;
|
---|
| 237 | $item_id = $notify->item_id;
|
---|
| 238 | $event = $notify->event;
|
---|
| 239 | $extra_tags = unserialize($notify->extra_tags_arry);
|
---|
| 240 | $user_list = unserialize($notify->user_list_arry);
|
---|
| 241 | $module_id = $notify->module_id;
|
---|
| 242 | $omit_user_id = $notify->omit_user_id;
|
---|
| 243 | $notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
|
---|
| 244 | $sql = "DELETE FROM $notfiy_reserve_db WHERE notify_reserve_id = $notify_reserve_id";
|
---|
| 245 | $xoops_db->query($sql);
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 |
|
---|
[61] | 249 | ?> |
---|