XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/plugins/xpressme/include/notify_functions.php @ 347

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

カテゴリーへの投稿イベントが正常に行われないバグを修正 fixes #190

File size: 7.6 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 (is_wp_cron_page_call() ){
43                $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
44                $_SERVER['REQUEST_METHOD'] = 'POST';
45        }
46        if (is_xmlrpc_call() ){
47                $_SERVER['HTTP_REFERER'] = 'http://'. $_SERVER[HTTP_HOST]  . $_SERVER['PHP_SELF'];
48                $_SERVER['REQUEST_METHOD'] = 'POST';
49        }
50//      set_error_handler("xpress_error_handler");
51        if ($xoops_config->is_impress != true){  // impress cms is error
52                if ( !defined("XOOPS_MAINFILE_INCLUDED")) {
53                        require_once $xoops_config->xoops_mainfile_path;        // load XOOPS System
54                }
55        }
56        if ( defined("XOOPS_MAINFILE_INCLUDED")) {
57                $module_id = get_xpress_modid() ;
58                $notification_handler =& xoops_gethandler( 'notification' ) ;
59                $notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id);
60        }
61}
62
63function do_CommentWaiting($commentID, $comment_post_ID)
64{
65//      require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
66//      $notification_handler =& xoops_gethandler( 'notification' ) ;
67        Notification_triggerEvent( 'global' , 0 , 'waiting') ;
68}
69
70
71function do_CommentNotifications($commentID, $comment_post_ID)
72{
73        global $xoops_config , $xoops_db;
74
75        $xpress_prefix = get_wp_prefix() ;
76
77        $table_term_relationships = $xpress_prefix .'term_relationships';
78        $table_term_taxonomy = $xpress_prefix .'term_taxonomy';
79        $table_terms = $xpress_prefix .'terms';
80        $table_categories = $xpress_prefix .'categories';
81        $wp_post = $xpress_prefix .'posts';
82        $wp_options = $xpress_prefix .'options';
83        $wp_users  = $xpress_prefix .'users';
84        $wp_comments  = $xpress_prefix .'comments';
85        $post_id = $comment_post_ID;
86
87        $post_title = get_the_title($post_id);
88        $post_url = get_permalink($post_id). '#comment';
89        $blog_name = get_bloginfo('name');
90
91        // query
92        $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$comment_post_ID ";
93        $post_author = $xoops_db->get_var($sql);
94
95        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
96        $user_name = $xoops_db->get_var($sql);
97
98        $comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
99        Notification_triggerEvent('global' , 0 , 'comment' , $comment_tags , false);
100        Notification_triggerEvent('author' , $post_author , 'comment' , $comment_tags , false);
101        Notification_triggerEvent('post' , $comment_post_ID , 'comment' , $comment_tags , false);
102
103        // categorie notification
104        if (get_xpress_db_version() < 6124){
105                $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;
106        } else {
107                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
108                $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 ";
109                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $comment_post_ID.") AND ($table_term_taxonomy.taxonomy='category')";         
110        }
111        $categories = $xoops_db->get_results($sql2);
112        foreach($categories as $categorie){
113                $cat_id = $categorie->cat_ID;
114                $cat_name = $categorie->cat_name;
115                $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 ) ;
116                Notification_triggerEvent('category' , $cat_id , 'comment' , $comment_tags , false);
117
118        }
119}
120
121function do_PostNotifications($post_id,$not_event)
122{
123        global $xoops_config, $xoops_db;
124       
125
126
127         // $not_event:         newpost,editpost ; $commentID, $comment_post_ID)
128         
129        $xpress_prefix = get_wp_prefix() ;
130
131        $table_term_relationships = $xpress_prefix .'term_relationships';
132        $table_term_taxonomy = $xpress_prefix .'term_taxonomy';
133        $table_terms = $xpress_prefix .'terms';
134        $table_categories = $xpress_prefix .'categories';
135        $wp_post = $xpress_prefix .'posts';
136        $wp_options = $xpress_prefix .'options';
137        $wp_users  = $xpress_prefix .'users';
138        $wp_comments  = $xpress_prefix .'comments';
139
140        $post_title = get_the_title($post_id);
141        $post_url = get_permalink($post_id). '#comment';
142        $blog_name = get_bloginfo('name');
143
144        // query
145        $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$post_id ";
146        $post_author = $xoops_db->get_var($sql);
147
148        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
149        $user_name = $xoops_db->get_var($sql);
150
151        $posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ;
152
153        switch ($not_event) {
154                case 'newpost' :
155                        Notification_triggerEvent('global' , 0 , 'newpost' , $posts_tags , false);
156                        Notification_triggerEvent('author' , $post_author , 'newpost' , $posts_tags , false);
157
158                        // categorie notification
159                        if (get_xpress_db_version() < 6124){
160                                $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;
161                        } else {
162                                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
163                                $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 ";
164                                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $post_id.") AND ($table_term_taxonomy.taxonomy='category')";         
165                        }
166                        $categories = $xoops_db->get_results($sql2);
167                        foreach($categories as $categorie){
168                                $cat_id = $categorie->cat_ID;
169                                $cat_name = $categorie->cat_name;
170                                $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 ) ;
171                                Notification_triggerEvent('category' , $cat_id , 'newpost' , $posts_tags , false);
172                        }
173                        break;
174                case 'editpost' :
175                        Notification_triggerEvent('post' , $post_id , 'editpost' , $posts_tags , false);
176                        break;
177                default :
178        }
179}               
180
181?>
Note: See TracBrowser for help on using the repository browser.