XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/class/xpressD3commentContent.class.php @ 762

Last change on this file since 762 was 757, checked in by toemon, 13 years ago

ConfigFromXoopsクラスを廃止し、modInfoクラスを使用するように変更
WP2.2以下で使用するテンプレートold_templateの廃止

File size: 20.2 KB
RevLine 
[104]1<?php
2if( ! defined( 'XPRESS_D3FORUM_CLASS_INCLUDED' ) ) {
3        define( 'XPRESS_D3FORUM_CLASS_INCLUDED' , 1 ) ;
4
5        // a class for d3forum comment integration
6        class xpressD3commentContent extends D3commentAbstract {
7
8                function fetchSummary( $external_link_id )
9                {
10                //      include_once dirname(dirname(__FILE__)).'/include/common_functions.php' ;
[590]11                        global $forum_id;
[749]12                        global $xoopsDB;
[590]13                       
[104]14                        $myts =& MyTextsanitizer::getInstance() ;
15
16                        $module_handler =& xoops_gethandler( 'module' ) ;
17                        $module =& $module_handler->getByDirname( $this->mydirname ) ;
18                        $config_handler =& xoops_gethandler('config');
19                        $configs = $config_handler->getConfigList( $module->mid() ) ;
20
21                        $post_id = intval( $external_link_id ) ;
22                        $mydirname = $this->mydirname ;
23                        if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
24                       
[583]25                        $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
[590]26                        $blog_info = $this->get_comment_blog_info($forum_id);
[104]27                        // query
[749]28                        $post_row = $xoopsDB->fetchArray( $xoopsDB->query( "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id" ) ) ;
[104]29                        if( empty( $post_row ) ) return '' ;
30
31                        // dare to convert it irregularly
32                        $summary = str_replace( '&amp;' , '&' , htmlspecialchars( xoops_substr( strip_tags( $post_row['post_content'] ) , 0 , 255 ) , ENT_QUOTES ) ) ;
[590]33                        $uri = preg_replace('/\/$/','',$blog_info['home']);
34                        $uri .= '/?p='.$post_row['ID'];
[104]35                        return array(
[590]36                                'dirname' => $mydirname. $blog_info['sub_dir'] ,
37                                'module_name' => $blog_info['blogname'] ,
[104]38                                'subject' => $post_row['post_title'] ,
[590]39                                'uri' => $uri ,
[104]40                                'summary' => $summary ,
41                        ) ;
42                }
43                // public
44                function displayCommentsInline( $params )
45                {
[757]46                        global $modInfo;
[616]47                        if ( function_exists('date_default_timezone_set') )
[757]48                                date_default_timezone_set($modInfo->get_xoops_time_zone());
[104]49                        $new_params = $this->restructParams( $params ) ;
50                        if (!$this->canAddComment($params['id']) ) {
51                                $new_params['no_form'] = true;
52                                echo '<p class="xpress_comment_close">' . __('Sorry, comments are closed for this item.') . '</p>';
53                                ob_start();
54                                        d3forum_render_comments( $this->d3forum_dirname , $new_params['forum_id'] , $new_params , $this->smarty ) ;
55                                        $d3comment=ob_get_contents();
56                                ob_end_clean();
57                                preg_match('/(.*?)<div><a href=(.*?)index.php\?page=newtopic&amp;forum_id=[^>]*?>(.*?)<\/a><\/div>\s?(.*)/s', $d3comment, $elms);
58                                if (! empty($elms[0])) $d3comment = $elms[1] . $elms[4];
59                                echo $d3comment;
60                        } else {
61                                d3forum_render_comments( $this->d3forum_dirname , $new_params['forum_id'] , $new_params , $this->smarty ) ;
62                        }
[616]63                        if ( function_exists('date_default_timezone_set') )
64                                date_default_timezone_set('UTC');
[104]65                }
66
67                //private for XPressME
68                function canAddComment($external_link_id)
69                {
[749]70                        global $xoopsDB;
[590]71                        global $forum_id;
72                        global $post;
73                       
74                        if (is_object($post)){  // in wordpress
75                                if ($post->ID == $external_link_id){
76                                        if($post->comment_status == 'open'){
77                                                return true;
78                                        } else {
79                                                return false;
80                                        }
81                                }
82                        }
[104]83                                        $myts =& MyTextsanitizer::getInstance() ;
84
85                                        $module_handler =& xoops_gethandler( 'module' ) ;
86                                        $module =& $module_handler->getByDirname( $this->mydirname ) ;
87                                        $config_handler =& xoops_gethandler('config');
88                                        $configs = $config_handler->getConfigList( $module->mid() ) ;
89
90                                        $post_id = intval( $external_link_id ) ;
91                                        $mydirname = $this->mydirname ;
92                                        if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
93                                       
[590]94                                        $blog_info = $this->get_comment_blog_info($forum_id);
[583]95                                        $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
[104]96
97                                        // query
[590]98                                        $sql = "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id";
[749]99                                        $post_row = $xoopsDB->fetchArray( $xoopsDB->query( $sql ) ) ;
[104]100                                        if( empty( $post_row ) ) return false ;
101                                        if ($post_row['comment_status'] == 'open')
102                                                return true;
103                                        else
104                                                return false;
105
106                }
107                               
108                // abstract (override it)
109                // set d3forum_dirname from parameter or config
110                function setD3forumDirname( $d3forum_dirname = '' )
111                {
112                        if( ! empty($this->mod_config['d3forum_dir'] ) ) {
113                                $this->d3forum_dirname = $this->mod_config['d3forum_dir'] ;
114                        } else if( $d3forum_dirname ) {
115                                $this->d3forum_dirname = $d3forum_dirname ;
116                        } else if( ! empty( $this->mod_config['comment_dirname'] ) ) {
117                                $this->d3forum_dirname = $this->mod_config['comment_dirname'] ;
118                        } else {
119                                $this->d3forum_dirname = 'd3forum' ;
120                        }
121                }
122                               
123                // get forum_id from $params or config
124                // override it if necessary
125
126                function getForumId( $params )
127                {
128                        if( ! empty( $this->mod_config['d3forum_id'] ) ) {
129                                return $this->mod_config['d3forum_id'] ;
130                        } else if( ! empty( $params['forum_id'] ) ) {
131                                return intval( $params['forum_id'] ) ;
132                        } else if( ! empty( $this->mod_config['comment_forum_id'] ) ) {
133                                return $this->mod_config['comment_forum_id'] ;
134                        } else {
135                                return 1 ;
136                        }
137                }
138
139                // get view from $params or config
140                // override it if necessary
141                function getView( $params )
142                {
143                        if( ! empty( $params['view'] ) ) {
144                                return $params['view'] ;
145                        } else {
146                                return 'listposts' ;
147                        }
148                }
149
150
151                // get view from $params or config
152                // override it if necessary
153                function getOrder( $params )
154                {
[144]155                        global $xpress_config;
[104]156                        if( ! empty( $params['order'] ) ) {
157                                return strtolower( $params['order'] ) ;
158                        } else {
159                                return 'desc' ;
160
161                        }
162                }
163
164
165                // get number of posts will be displayed from $params or config
166                // override it if necessary
167                function getPostsNum( $params )
168                {
169                        if( ! empty( $params['posts_num'] ) ) {
170                                return $params['posts_num'] ;
171                        } else {
172                                return 10 ;
173                        }
174                }
175               
176                function validate_id( $link_id )
177                {
[749]178                        global $xoopsDB;
[590]179                        global $forum_id;
[104]180                        $post_id = intval( $link_id ) ;
181                        $mydirname = $this->mydirname ;
[583]182                        $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
[590]183                        $blog_info = $this->get_comment_blog_info($forum_id);           
[104]184                       
[749]185                        list( $count ) = $xoopsDB->fetchRow( $xoopsDB->query( "SELECT COUNT(*) FROM ".$blog_info['mb_table_prefix'] ."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ;
[104]186
187                        if( $count <= 0 ) return false ;
188                        else return $post_id ;
189                }
190               
191        // callback on newtopic/edit/reply/delete
192        // abstract
193                function onUpdate( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 )
194                {
195                        global $message;
196                       
197                        if ($mode == 'approve'){
198                                $mode = 'edit';
199                        }
200                        return $this->sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id);
201
202                }
203               
204                // processing xoops notification for 'comment'
205                // override it if necessary
206                function processCommentNotifications( $mode , $link_id , $forum_id , $topic_id , $post_id )
207                {
[749]208                        global $xoopsDB;
[590]209                        $blog_info = $this->get_comment_blog_info($forum_id);
210                        $wp_full_prefix = $blog_info['mb_table_prefix'];
211
[104]212                        $myts =& MyTextsanitizer::getInstance() ;
213
214                        $module_handler =& xoops_gethandler( 'module' ) ;
215                        $module =& $module_handler->getByDirname( $this->mydirname ) ;
216                        $config_handler =& xoops_gethandler('config');
217                        $configs = $config_handler->getConfigList( $module->mid() ) ;
218
219                        $mydirname = $this->mydirname ;
220                        if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
[257]221                       
[583]222                        $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
[104]223                       
[590]224                        $table_term_relationships = $wp_full_prefix ."term_relationships";
225                        $table_term_taxonomy = $wp_full_prefix."term_taxonomy";
226                        $table_terms = $wp_full_prefix."terms";
[749]227                        $table_categories = $xoopsDB->prefix($xpress_prefix."_categories");
228                        $table_post2cat = $xoopsDB->prefix($xpress_prefix."_post2cat");
[590]229                        $wp_post = $wp_full_prefix."posts";
230                        $wp_options = $wp_full_prefix."options";
[749]231                        $wp_users  = $xoopsDB->prefix($xpress_prefix."_users");
[104]232                                               
233                        $sql = "SELECT option_value  FROM $wp_options WHERE option_name ='blogname'";
[749]234                        $blog_row = $xoopsDB->fetchArray( $xoopsDB->query( $sql ) ) ;
[104]235                        if( empty( $blog_row ) ) return false;
236                        $blog_name = $blog_row['option_value'];
237                       
[257]238                       
[104]239                        // query
240                        $sql = "SELECT * FROM ".$wp_post." WHERE ID=$link_id ";
[749]241                        $post_row = $xoopsDB->fetchArray( $xoopsDB->query( $sql ) ) ;
[104]242                        if( empty( $post_row ) ) return false;
243                        $post_title = $post_row['post_title'];
244                        $post_author = $post_row['post_author'];
245                       
246                        $sql = "SELECT display_name  FROM $wp_users WHERE ID ='$post_author'";
[749]247                        $blog_row = $xoopsDB->fetchArray( $xoopsDB->query( $sql ) ) ;
[104]248                        if( empty( $blog_row ) ) return false;
249                        $user_name = $blog_row['display_name'];
250
251                        require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
252
253                        // non-module integration returns false quickly
254                        if( ! is_object( $this->module ) ) return false ;
255
256                        $not_module =& $this->module ;
257                        $not_modid = $this->module->getVar('mid') ;
258
259                        $comment_tags = array( 'XPRESS_AUTH_NAME' =>$user_name,'XPRESS_BLOG_NAME' =>$blog_name,'XPRESS_POST_TITLE' => $post_title , 'XPRESS_POST_URL' => XOOPS_URL.'/modules/'.$this->d3forum_dirname.'/index.php?post_id='.intval($post_id) ) ;
260                        $notification_handler =& xoops_gethandler( 'notification' ) ;
261                        $notification_handler->triggerEvent( 'global' , 0 , 'comment' , $comment_tags , false , $not_modid ) ;
262                        $notification_handler->triggerEvent( 'author' , $post_author , 'comment' , $comment_tags , false , $not_modid ) ;
263                        $notification_handler->triggerEvent( 'post' , $link_id , 'comment' , $comment_tags , false , $not_modid ) ;
264                       
[749]265                        $post_row = $xoopsDB->fetchArray( $xoopsDB->query( "SELECT * FROM ".$xoopsDB->prefix($this->d3forum_dirname."_posts")." WHERE post_id=$post_id" ) ) ;
[104]266                        if( !empty( $post_row ) ){
267                                if ( $post_row['approval'] ==0 ){
268                                                        $notification_handler->triggerEvent( 'global' , 0 , 'waiting', $comment_tags , false , $not_modid ) ;
269                                }
270                        }
271                       
272                // categorie notification
273                        include(XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/wp-includes/version.php');
274                        if ($wp_db_version < 6124){
275                                        $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=".$link_id;
276                        } else {
277                                        $sql2  = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
278                                        $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 ";
279                                        $sql2 .= "WHERE ($table_term_relationships.object_id =" . $link_id.") AND ($table_term_taxonomy.taxonomy='category')";         
280                        }
[749]281                        $res2 = $xoopsDB->query($sql2);
282                        while($row2 = $xoopsDB->fetchArray($res2)){
[104]283                                $cat_id = $row2['cat_ID'];
284                                $cat_name = $row2['cat_name'];
285                                $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' => XOOPS_URL.'/modules/'.$this->d3forum_dirname.'/index.php?post_id='.intval($post_id) ) ;
286                                $notification_handler->triggerEvent( 'category' , $cat_id , 'comment' , $comment_tags , false , $not_modid ) ;
287                        }
288                }
289               
290                //  The content is reflected in the WordPress comment when there is a change in the D3Forum comment.
291
292                function sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){
293
[749]294                        global $xoopsDB;
295
[590]296                        $blog_info = $this->get_comment_blog_info($forum_id);
297                        $wp_full_prefix = $blog_info['mb_table_prefix'];
298                        $blog_id = $blog_info['blog_id'];
299                        $target_db_prefix = $blog_info['mb_table_prefix'];
[261]300                        $mydirname = $this->mydirname ;
[583]301                        $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
[104]302                        $d3f_forum_dir  = $this->d3forum_dirname;
303                       
304                        $d3f_prefix = $d3f_forum_dir;
305                        $myts =& MyTextSanitizer::getInstance();
306
[590]307                        $wp_comments = $wp_full_prefix . 'comments';
308                        $wp_posts = $wp_full_prefix . 'posts';
[104]309                        $wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link');
310                        $d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts');
311                        $d3f_topics = $xoopsDB->prefix($d3f_prefix . '_topics');
312                        $d3f_users2topics  = $xoopsDB->prefix($d3f_prefix . '_users2topics ');
313                        $db_xoops_users = $xoopsDB->prefix('users');
314                        $d3f_post_votes = $xoopsDB->prefix($d3f_prefix . '_post_votes');
315                       
316                        $comment_post_ID = $link_id;
317
318                        $d3f_sql  =     "SELECT $d3f_posts.guest_name, ";
319                        $d3f_sql .=     "$d3f_posts.guest_email, $d3f_posts.guest_url, $d3f_posts.poster_ip, $d3f_posts.post_time, ";
320                        $d3f_sql .=     "$d3f_posts.post_text, $d3f_posts.approval, $d3f_posts.uid ,$d3f_posts.pid ";
321                        $d3f_sql .=     "FROM $d3f_posts ";
322                        $d3f_sql .=     "WHERE $d3f_posts.post_id = $post_id";
323
324                        $d3f_res = $xoopsDB->query($d3f_sql, 0, 0);
325                        if ($d3f_res === false){
326                                die('...Err. OPEN D3Forum Data (' .  $d3f_sql . ')');
327                        }else {
328                                $d3f_row = $xoopsDB->fetchArray($d3f_res);
329                                $uid = $d3f_row['uid'];
330                                if (!empty($uid)) {
331                                        $xu_sql  = "SELECT uid ,name ,uname ,email , url FROM $db_xoops_users WHERE uid = $uid";
332                                        $xu_res =  $xoopsDB->query($xu_sql, 0, 0);
333                                        if ($xu_res === false){
334                                                $user_display_name = '';
335                                        }else {
336                                                $xu_row = $xoopsDB->fetchArray($xu_res);
337                                                if (empty($xu_row['name'])){
338                                                        $user_display_name = $xu_row['uname'];
339                                                } else {
340                                                        $user_display_name = $xu_row['name'] ;
341                                                }
342                                                $comment_author_email = "'" . $xu_row['email'] . "'";
343                                                $comment_author_url = "'" . $xu_row['url'] . "'";
344                                        }
345                                        $comment_author = "'" . addSlashes($user_display_name) . "'";
346                                } else {                                               
347                                        $comment_author = "'" . addSlashes($d3f_row['guest_name']) . "'";
348                                        $comment_author_email = "'" . $d3f_row['guest_email'] . "'";
349                                        $comment_author_url = "'" . $d3f_row['guest_url'] . "'";
350                                }
351                                $comment_author_IP = "'" . $d3f_row['poster_ip'] . "'";
352                                $comment_date = "'" . date('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
353                                $comment_content = "'" . addSlashes($d3f_row['post_text']) . "'";
354                                $comment_approved = "'" . $d3f_row['approval'] . "'";
[257]355                                require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
[261]356                                $user_ID = xoops_uid_to_wp_uid($d3f_row['uid'],$mydirname);
[104]357                                $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
358                                $comment_type = '';
359                                $d3f_pid = $d3f_row['pid'];
360                                if ($d3f_pid > 0) {
361                                        $comment_parent = $this->get_wp_comment_ID($d3f_pid);
362                                } else {
363                                        $comment_parent = 0 ;
364                                }
365                               
366                                switch($mode){                         
367                                        case 'reply':
368                                        case 'newtopic' :                               
369                                                $wp_sql  = "INSERT INTO $wp_comments ";
370                                                $wp_sql .=    "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , ";
371                                                $wp_sql .=    "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) ";
372                                                $wp_sql .=  "VALUES ";
373                                                $wp_sql .=    "($comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, ";
374                                                $wp_sql .=    "$comment_date, $comment_content, $comment_approved, $user_ID, $comment_date_gmt, $comment_parent)";
375
376                                                $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
377                                                if ($wp_res === false){
378                                                        die( '...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')');
379                                                } else{
380                                                        $comment_ID = $xoopsDB->getInsertId();
381                                                       
382                                                        $wp_sql  = "UPDATE $wp_posts SET  comment_count = comment_count +1 WHERE ID = $comment_post_ID";
383                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
384                                               
385                                                        $wp_sql  = "INSERT INTO $wp_d3forum_link ";
[590]386                                                        $wp_sql .=    "(comment_ID , post_id, forum_id,blog_id) ";
[104]387                                                        $wp_sql .=  "VALUES ";
[590]388                                                        $wp_sql .=    "($comment_ID, $post_id ,$forum_id,$blog_id)";           
[104]389                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
390                                                }
391                                               
392
393                                                if ($comment_approved ==0){
394                                                        require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
395                                                        $notification_handler =& xoops_gethandler( 'notification' ) ;
396                                                        $notification_handler->triggerEvent( 'global' , 0 , 'waiting') ;
397                                                }                       
398
399                                                break;
400                                        case 'edit':
[590]401                                                $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id ";
[104]402                                                $wp_res = $xoopsDB->query($wp_sql, 0, 0);
403                                                if ($wp_res === false){
404                                                        die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')');
405                                                } else {
406                                                        $wp_row = $xoopsDB->fetchArray($wp_res);
407                                                        $comment_ID = $wp_row['comment_ID'];
408                                               
409                                               
410                                                        $wp_sql  = "UPDATE $wp_comments SET comment_content = $comment_content , comment_date_gmt = $comment_date_gmt WHERE comment_ID = $comment_ID";
411                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
412                                                        if ($wp_res === false){
413                                                                die( '...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')');
414                                                        }
415                                                }
416                                                break;
417                                        case 'delete':
418                                                // wordpress comments delete
419                                                $comment_ID = $this->get_wp_comment_ID($post_id);
420                                                if ($comment_ID > 0){
421                                                        $sql= "SELECT comment_type FROM $wp_comments WHERE comment_ID = $comment_ID";
422                                                        $res= $xoopsDB->query( $sql);
423                                                        if ($xoopsDB->getRowsNum($res) > 0 ){
424                                                                $row = $xoopsDB->fetchArray($res);
425                                                                $comment_type = $row['comment_type'];
426                                                                if (!empty($comment_type)) break;
427                                                        }
428                                                        $wp_sql = "DELETE FROM $wp_comments WHERE comment_ID = $comment_ID";
429                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
430                                                       
431                                                        $wp_sql = "DELETE FROM $wp_d3forum_link WHERE post_id = $post_id";
432                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
433                                                       
434                                                        $wp_sql  = "UPDATE $wp_posts SET  comment_count = comment_count -1 WHERE ID = $comment_post_ID";
435                                                        $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
436                                                }
437                                                break;
438                                        default :
439                                }                               
440                        }               
441                        return true ;
442                }
443                function get_wp_comment_ID($d3forum_post_ID){
[749]444                        global $xoopsDB;
445
[104]446                        $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
[583]447                        $xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix);
[104]448                       
449                        $wp_d3forum_link = $xoopsDB->prefix($xp_prefix . '_d3forum_link');
450                       
451                        $sql  = "SELECT * FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID";
452                        $res = $xoopsDB->query($sql, 0, 0);
453                        $ret = 0;
454                        if ($xoopsDB->getRowsNum($res) > 0 ){
455                                $row = $xoopsDB->fetchArray($res);
456                                $ret = $row['comment_ID'];
457                        }
458                        return $ret;
[590]459                }
[104]460               
[590]461                function get_comment_blog_info($d3forum_forum_id){
[749]462                        global $xoopsDB;
[590]463                        $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
464                        $xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix);
465                        $xp_prefix = $xoopsDB->prefix($xp_prefix);
466                        $table_name = 'options';
467                        $options_array = array();
468
469
470                                $sql = "SHOW TABLES LIKE '" . $xp_prefix  . '%' . $table_name . "'";
471                                if($result = $xoopsDB->queryF($sql)){
472                                        while($row = $xoopsDB->fetchRow($result)){
473                                                $wp_option_table = $row[0];
474                                                $pattern = '/'. $table_name . '/';
475                                                $option['mb_table_prefix'] =  preg_replace($pattern,'',$wp_option_table);
476                                                if (preg_match('/'. $xp_prefix . '_([0-9]*)_/',$option['mb_table_prefix'],$matchs)){
477                                                        $option['blog_id'] = $matchs[1];
478                                                } else {
479                                                        $option['blog_id'] = 1;
480                                                }
481                                               
482                                                $option_sql = "SELECT option_name, option_value FROM $wp_option_table WHERE option_name IN ('home','siteurl','blogname','xpressme_option')";
483                                                if($option_result =  $xoopsDB->query($option_sql, 0, 0)){
484                                                        while($option_row = $xoopsDB->fetchArray($option_result)){
485                                                                $name = $option_row['option_name'];
486                                                                $value = $option_row['option_value'];
487                                                                if ($name == 'xpressme_option'){
488                                                                        $value =  @unserialize( $value );
489                                                                }
490                                                                $option[$name] = $value;
491                                                        }
492                                                        $option['siteurl'] = preg_replace('/\/$/','',$option['siteurl']);
493                                                        $option['home'] = preg_replace('/\/$/','',$option['home']);
494                                                       
495                                                        if ($option['blog_id'] === 1){
496                                                                $option['sub_dir'] = '';
497                                                        } else {
498                                                                $xoops_url = str_replace('/','\\/',XOOPS_URL);
499                                                                if (preg_match('/'. $xoops_url . '.*' . $wpdirname . '(.*)/',$option['home'],$matchs)){
500                                                                        $option['sub_dir'] = $matchs[1];
501                                                                } else {
502                                                                        $option['sub_dir'] = '';
503                                                                }
504                                                        }
505                                                        if ($option['xpressme_option']['d3forum_forum_id'] == $d3forum_forum_id){
506                                                                return $option;
507                                                        }
508                                                }
509                                        }
510                                        return null;
511                                }
512                }
513                function repair_d3forum_link($comment_ID, $post_id ,$forum_id,$blog_id,$target_db_prefix){
514                }
515               
516        } // class
[104]517}
518?>
Note: See TracBrowser for help on using the repository browser.