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