XPressME Integration Kit

Trac

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

Last change on this file was 132, checked in by toemon, 16 years ago

ImpressCMSで投稿すると、イベント通知するためにXOOPSをロードしたところで
Fatal error: Call to a member function prefix() on a non-object in C:\xampp\htdocs\impress\kernel\configitem.php on line 331のエラーが、
しょうがないので wp-admin/post.phpの場合は事前にXOOPSをロードするようにしてみた。
予約投稿は問題ないみたいだけれど、もいっかいイベント通知の確認しないと駄目かも

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