XPressME Integration Kit

Trac

source: branches/Ver2.1/xpressme_integration_kit/wp-content/plugins/xpressme/include/notify_functions.php

Last change on this file was 374, checked in by toemon, 15 years ago

branches Ver2.1.0

File size: 10.8 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($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.
42        if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = 'call $notification_handler->triggerEvent');
43        if (is_wp_cron_page_call() ){
44                $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
45                $_SERVER['REQUEST_METHOD'] = 'POST';
46                if (function_exists('xpress_debug')) xpress_debug($title = 'wp_cron_page_call',true);
47        }
48        if (is_xmlrpc_call() ){
49                $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
50                $_SERVER['REQUEST_METHOD'] = 'POST';
51        }
52//      set_error_handler("xpress_error_handler");
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//      }
58        if ( defined("XOOPS_MAINFILE_INCLUDED")) {
59                if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = 'call $notification_handler->triggerEvent');
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);
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);
67        }
68}
69
70function 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
78function do_CommentNotifications($commentID, $comment_post_ID)
79{
80        global $xoops_config , $xoops_db;
81
82        $xpress_prefix = get_wp_prefix() ;
83
84        $table_term_relationships = $xpress_prefix .'term_relationships';
85        $table_term_taxonomy = $xpress_prefix .'term_taxonomy';
86        $table_terms = $xpress_prefix .'terms';
87        $table_categories = $xpress_prefix .'categories';
88        $wp_post = $xpress_prefix .'posts';
89        $wp_options = $xpress_prefix .'options';
90        $wp_users  = $xpress_prefix .'users';
91        $wp_comments  = $xpress_prefix .'comments';
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        Notification_triggerEvent('global' , 0 , 'comment' , $comment_tags , false);
107        Notification_triggerEvent('author' , $post_author , 'comment' , $comment_tags , false);
108        Notification_triggerEvent('post' , $comment_post_ID , 'comment' , $comment_tags , false);
109
110        // categorie notification
111        if (get_xpress_db_version() < 6124){
112                $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;
113        } else {
114                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
115                $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 ";
116                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $comment_post_ID.") AND ($table_term_taxonomy.taxonomy='category')";         
117        }
118        $categories = $xoops_db->get_results($sql2);
119        foreach($categories as $categorie){
120                $cat_id = $categorie->cat_ID;
121                $cat_name = $categorie->cat_name;
122                $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 ) ;
123                Notification_triggerEvent('category' , $cat_id , 'comment' , $comment_tags , false);
124
125        }
126}
127
128function do_PostNotifications($post_id,$not_event)
129{
130        global $xoops_config, $xoops_db;
131       
132
133
134         // $not_event:         newpost,editpost ; $commentID, $comment_post_ID)
135         
136        $xpress_prefix = get_wp_prefix() ;
137
138        $table_term_relationships = $xpress_prefix .'term_relationships';
139        $table_term_taxonomy = $xpress_prefix .'term_taxonomy';
140        $table_terms = $xpress_prefix .'terms';
141        $table_categories = $xpress_prefix .'categories';
142        $wp_post = $xpress_prefix .'posts';
143        $wp_options = $xpress_prefix .'options';
144        $wp_users  = $xpress_prefix .'users';
145        $wp_comments  = $xpress_prefix .'comments';
146
147        $post_title = get_the_title($post_id);
148        $post_url = get_permalink($post_id). '#comment';
149        $blog_name = get_bloginfo('name');
150
151        // query
152        $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$post_id ";
153        $post_author = $xoops_db->get_var($sql);
154
155        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
156        $user_name = $xoops_db->get_var($sql);
157
158        $posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
159
160        switch ($not_event) {
161                case 'newpost' :
162                        Notification_triggerEvent('global' , 0 , 'newpost' , $posts_tags , false);
163                        Notification_triggerEvent('author' , $post_author , 'newpost' , $posts_tags , false);
164
165                        // categorie notification
166                        if (get_xpress_db_version() < 6124){
167                                $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;
168                        } else {
169                                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
170                                $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 ";
171                                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $post_id.") AND ($table_term_taxonomy.taxonomy='category')";         
172                        }
173                        $categories = $xoops_db->get_results($sql2);
174                        foreach($categories as $categorie){
175                                $cat_id = $categorie->cat_ID;
176                                $cat_name = $categorie->cat_name;
177                                $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 ) ;
178                                Notification_triggerEvent('category' , $cat_id , 'newpost' , $posts_tags , false);
179                        }
180                        break;
181                case 'editpost' :
182                        Notification_triggerEvent('post' , $post_id , 'editpost' , $posts_tags , false);
183                        break;
184                default :
185        }
186}
187
188//When the event cannot notify because the XOOPS system is not loaded, the event is stacked.
189function Notification_reserve($category, $item_id=0, $event, $extra_tags=array(), $user_list=array(), $module_id=0, $omit_user_id=null)
190{
191        global $xpress_config,$xoops_db;
192       
193        $xpress_prefix = get_wp_prefix();
194        $notfiy_reserve = $xpress_prefix . 'notify_reserve';
195
196        $extra_tags_arry = addslashes(serialize($extra_tags));
197        $user_list_arry = addslashes(serialize($user_list));
198//      $extra_tags_arry = mysql_real_escape_string(serialize($extra_tags));
199//      $user_list_arry = mysql_real_escape_string(serialize($user_list));
200       
201        $notify_reserve_status = 'reserve';
202
203        $sql  = "INSERT INTO $notfiy_reserve ";
204        $sql .=    "(notify_reserve_status , category , item_id , event , extra_tags_arry , user_list_arry , module_id , omit_user_id)";
205        $sql .=  "VALUES ";
206        $sql .=    "('$notify_reserve_status' , '$category' , $item_id , '$event' , '$extra_tags_arry' , '$user_list_arry' , $module_id , '$omit_user_id')";
207        if ( defined("XPRESS_EVENT_DEBUG")) xpress_debug_message($message = $sql);
208
209        $xoops_db->query($sql);
210}
211
212//It calls when the XOOPS system is loaded, and the stacked event notification processing is done.
213function Notification_reserve_send()
214{
215        global $xpress_config,$xoops_db;
216        if ( ! defined("XOOPS_MAINFILE_INCLUDED")) return;
217       
218        $notification_handler =& xoops_gethandler( 'notification' ) ;
219       
220        $xpress_prefix = get_wp_prefix();
221        $notfiy_reserve_db = $xpress_prefix . 'notify_reserve';
222
223        $extra_tags_arry = addslashes(serialize($extra_tags));
224        $user_list_arry = addslashes(serialize($user_list));
225       
226        $sql  = "SELECT * ";
227        $sql .= "FROM $notfiy_reserve_db ";
228        $sql .= "WHERE  notify_reserve_status = 'reserve'";
229
230        $notify_reserves = $xoops_db->get_results($sql);
231
232        //So as not to process it by other sessions while processing it, status is changed.
233        foreach($notify_reserves as $notify){
234                $notify_reserve_id = $notify->notify_reserve_id;
235                $sql  = "UPDATE $notfiy_reserve_db SET  notify_reserve_status = 'sending' WHERE notify_reserve_id = $notify_reserve_id";
236                $xoops_db->query($sql);
237        }
238
239        foreach($notify_reserves as $notify){
240                $notify_reserve_id = $notify->notify_reserve_id;
241                $category = $notify->category;
242                $item_id = $notify->item_id;
243                $event = $notify->event;
244                $extra_tags = unserialize($notify->extra_tags_arry);
245                $user_list = unserialize($notify->user_list_arry);
246                $module_id = $notify->module_id;
247                $omit_user_id = $notify->omit_user_id;
248                $notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
249                $sql  = "DELETE FROM  $notfiy_reserve_db WHERE notify_reserve_id = $notify_reserve_id";
250                $xoops_db->query($sql);
251        }
252}
253
254?>
Note: See TracBrowser for help on using the repository browser.