XPressME Integration Kit

Trac

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

Last change on this file was 860, checked in by toemon, 8 years ago

PHP7 対応 Fix #431
thx nao-pon

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