XPressME Integration Kit

Trac


Ignore:
Timestamp:
Mar 3, 2009, 8:33:23 PM (16 years ago)
Author:
toemon
Message:

XOOPS mainfile.phpのdefine文を事前に読み取りwp-config.phpのDB接続関係を生成することにより、XOOPSシステムを必要なときだけ呼び出す仕組みを作る。
およびイベント通知関係の修正(まだゲストのアクセス権限がないと駄目)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/plugins/xpressme/include/notify_functions.php

    r91 r95  
    11<?php 
    2          
     2 
    33function onaction_publish_post_notify($new_status, $old_status, $post) 
    44{ 
    55        if ($new_status == 'publish'){ 
    6                 include_once dirname(__FILE__) . '/notification.inc.sub.php'; 
    76                do_PostNotifications($post->ID,'newpost'); 
    87        } 
     
    1110function onaction_edit_post_notify($post_id) 
    1211{ 
    13         include_once ABSPATH . '/include/notification.inc.sub.php'; 
    1412        do_PostNotifications($post_id,'editpost'); 
    1513} 
     
    2119 
    2220        if ($status ==1){ 
    23                 include_once ABSPATH . '/include/notification.inc.sub.php'; 
    2421                do_CommentNotifications($commentID, $post_id); 
    2522        } else { 
    26                 require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ; 
    27                 $notification_handler =& xoops_gethandler( 'notification' ) ; 
    28                 $notification_handler->triggerEvent( 'global' , 0 , 'waiting') ; 
     23                do_CommentWaiting($commentID, $post_id); 
    2924        } 
    3025} 
     
    3530        $status = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID = $commentID"); 
    3631        if(is_null($status)) return; 
    37         //      $status = wp_get_comment_status($commentID); 
    3832        if ($status == 1){ 
    3933                        onaction_comment_notify($commentID); 
     
    4135} 
    4236 
     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         
     51        include_once $xoops_config->xoops_mainfile_path;        // load XOOPS System 
     52        include_once $xoops_config->xoops_root_path . '/include/notification_functions.php' ; 
     53        $module_id = get_xpress_modid() ; 
     54        $notification_handler =& xoops_gethandler( 'notification' ) ; 
     55        $notification_handler->triggerEvent($category, $item_id, $event, $extra_tags, $user_list, $module_id, $omit_user_id); 
     56} 
     57 
     58function do_CommentWaiting($commentID, $comment_post_ID) 
     59{ 
     60//      global $xoops_config; 
     61//      require_once $xoops_config->xoops_mainfile_path; 
     62//      xoops_mainfile_path; 
     63//      require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ; 
     64//      $notification_handler =& xoops_gethandler( 'notification' ) ; 
     65        Notification_triggerEvent( 'global' , 0 , 'waiting') ; 
     66} 
     67 
     68 
     69function do_CommentNotifications($commentID, $comment_post_ID) 
     70{ 
     71        global $xoops_config , $xoops_db; 
     72 
     73        $xpress_prefix = get_wp_prefix() ; 
     74 
     75        $table_term_relationships = $xpress_prefix .'term_relationships'; 
     76        $table_term_taxonomy = $xpress_prefix .'term_taxonomy'; 
     77        $table_terms = $xpress_prefix .'terms'; 
     78        $table_categories = $xpress_prefix .'categories'; 
     79        $wp_post = $xpress_prefix .'posts'; 
     80        $wp_options = $xpress_prefix .'options'; 
     81        $wp_users  = $xpress_prefix .'users'; 
     82        $wp_comments  = $xpress_prefix .'comments'; 
     83        $post_id = $comment_post_ID; 
     84 
     85        $post_title = get_the_title($post_id); 
     86        $post_url = get_permalink($post_id). '#comment'; 
     87        $blog_name = get_bloginfo('name'); 
     88 
     89        // query 
     90        $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$comment_post_ID "; 
     91        $post_author = $xoops_db->get_var($sql); 
     92 
     93        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'"; 
     94        $user_name = $xoops_db->get_var($sql); 
     95 
     96        $comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ; 
     97        Notification_triggerEvent('global' , 0 , 'comment' , $comment_tags , false); 
     98        Notification_triggerEvent('author' , $post_author , 'comment' , $comment_tags , false); 
     99        Notification_triggerEvent('post' , $comment_post_ID , 'comment' , $comment_tags , false); 
     100 
     101        // categorie notification 
     102        if (get_xpress_db_version() < 6124){ 
     103                $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; 
     104        } else { 
     105                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name "; 
     106                $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 "; 
     107                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $comment_post_ID.") AND ($table_term_taxonomy.taxonomy='category')";           
     108        } 
     109        $categories = $xoops_db->get_results($sql); 
     110        foreach($categories as $categorie){ 
     111                $cat_id = $categorie->cat_ID; 
     112                $cat_name = $categorie->cat_name; 
     113                $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 ) ; 
     114                Notification_triggerEvent('category' , $cat_id , 'comment' , $comment_tags , false); 
     115 
     116        } 
     117} 
     118 
     119function do_PostNotifications($post_id,$not_event) 
     120{ 
     121        global $xoops_config, $xoops_db; 
     122        xpress_debug(); 
     123         
     124 
     125 
     126         // $not_event:         newpost,editpost ; $commentID, $comment_post_ID) 
     127          
     128        $xpress_prefix = get_wp_prefix() ; 
     129 
     130        $table_term_relationships = $xpress_prefix .'term_relationships'; 
     131        $table_term_taxonomy = $xpress_prefix .'term_taxonomy'; 
     132        $table_terms = $xpress_prefix .'terms'; 
     133        $table_categories = $xpress_prefix .'categories'; 
     134        $wp_post = $xpress_prefix .'posts'; 
     135        $wp_options = $xpress_prefix .'options'; 
     136        $wp_users  = $xpress_prefix .'users'; 
     137        $wp_comments  = $xpress_prefix .'comments'; 
     138 
     139        $post_title = get_the_title($post_id); 
     140        $post_url = get_permalink($post_id). '#comment'; 
     141        $blog_name = get_bloginfo('name'); 
     142 
     143        // query 
     144        $sql = "SELECT post_author FROM ".$wp_post." WHERE ID=$post_id "; 
     145        $post_author = $xoops_db->get_var($sql); 
     146 
     147        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'"; 
     148        $user_name = $xoops_db->get_var($sql); 
     149 
     150        $posts_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => $post_url ) ; 
     151 
     152        switch ($not_event) { 
     153                case 'newpost' : 
     154                        Notification_triggerEvent('global' , 0 , 'newpost' , $posts_tags , false); 
     155                        Notification_triggerEvent('author' , $post_author , 'newpost' , $posts_tags , false); 
     156 
     157                        // categorie notification 
     158                        if (get_xpress_db_version() < 6124){ 
     159                                $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; 
     160                        } else { 
     161                                $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name "; 
     162                                $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 "; 
     163                                $sql2 .= "WHERE ($table_term_relationships.object_id =" . $post_id.") AND ($table_term_taxonomy.taxonomy='category')";           
     164                        } 
     165                        $categories = $xoops_db->get_results($sql); 
     166                        foreach($categories as $categorie){ 
     167                                $cat_id = $categorie->cat_ID; 
     168                                $cat_name = $categorie->cat_name; 
     169                                $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 ) ; 
     170                                Notification_triggerEvent('category' , $cat_id , 'newpost' , $posts_tags , false); 
     171                        } 
     172                        break; 
     173                case 'editpost' : 
     174                        Notification_triggerEvent('post' , $post_id , 'editpost' , $posts_tags , false); 
     175                        break; 
     176                default : 
     177        } 
     178}                
     179 
    43180?> 
Note: See TracChangeset for help on using the changeset viewer.