XPressME Integration Kit

Trac

source: branches/Ver2.4/xpressme_integration_kit/wp-content/plugins/xpressme/include/notify_functions.php @ 823

Last change on this file since 823 was 662, checked in by toemon, 14 years ago

コメント投稿後、ブランクページになるバグ修正 fixes#376

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