1 | <?php
|
---|
2 | if( ! 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 | global $forum_id;
|
---|
12 |
|
---|
13 | $db =& XoopsDatabaseFactory::getDatabaseConnection() ;
|
---|
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 |
|
---|
25 | $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
26 | $blog_info = $this->get_comment_blog_info($forum_id);
|
---|
27 | // query
|
---|
28 | $post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id" ) ) ;
|
---|
29 | if( empty( $post_row ) ) return '' ;
|
---|
30 |
|
---|
31 | // dare to convert it irregularly
|
---|
32 | $summary = str_replace( '&' , '&' , htmlspecialchars( xoops_substr( strip_tags( $post_row['post_content'] ) , 0 , 255 ) , ENT_QUOTES ) ) ;
|
---|
33 | $uri = preg_replace('/\/$/','',$blog_info['home']);
|
---|
34 | $uri .= '/?p='.$post_row['ID'];
|
---|
35 | return array(
|
---|
36 | 'dirname' => $mydirname. $blog_info['sub_dir'] ,
|
---|
37 | 'module_name' => $blog_info['blogname'] ,
|
---|
38 | 'subject' => $post_row['post_title'] ,
|
---|
39 | 'uri' => $uri ,
|
---|
40 | 'summary' => $summary ,
|
---|
41 | ) ;
|
---|
42 | }
|
---|
43 | // public
|
---|
44 | function displayCommentsInline( $params )
|
---|
45 | {
|
---|
46 | global $xoops_config;
|
---|
47 | if ( function_exists('date_default_timezone_set') )
|
---|
48 | date_default_timezone_set($xoops_config->xoops_time_zone);
|
---|
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&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 | }
|
---|
63 | if ( function_exists('date_default_timezone_set') )
|
---|
64 | date_default_timezone_set('UTC');
|
---|
65 | }
|
---|
66 |
|
---|
67 | //private for XPressME
|
---|
68 | function canAddComment($external_link_id)
|
---|
69 | {
|
---|
70 | global $forum_id;
|
---|
71 | global $post;
|
---|
72 |
|
---|
73 | if (is_object($post)){ // in wordpress
|
---|
74 | if ($post->ID == $external_link_id){
|
---|
75 | if($post->comment_status == 'open'){
|
---|
76 | return true;
|
---|
77 | } else {
|
---|
78 | return false;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 | $db =& XoopsDatabaseFactory::getDatabaseConnection() ;
|
---|
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 |
|
---|
94 | $blog_info = $this->get_comment_blog_info($forum_id);
|
---|
95 | $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
96 |
|
---|
97 | // query
|
---|
98 | $sql = "SELECT * FROM ".$blog_info['mb_table_prefix']."posts WHERE ID=$post_id";
|
---|
99 | $post_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
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 | {
|
---|
155 | global $xpress_config;
|
---|
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 | {
|
---|
178 | global $forum_id;
|
---|
179 | $post_id = intval( $link_id ) ;
|
---|
180 | $mydirname = $this->mydirname ;
|
---|
181 | $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
182 | $blog_info = $this->get_comment_blog_info($forum_id);
|
---|
183 | $db =& XoopsDatabaseFactory::getDatabaseConnection() ;
|
---|
184 |
|
---|
185 | list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$blog_info['mb_table_prefix'] ."posts WHERE ID=$post_id AND comment_status ='open'" ) ) ;
|
---|
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 | {
|
---|
208 | $blog_info = $this->get_comment_blog_info($forum_id);
|
---|
209 | $wp_full_prefix = $blog_info['mb_table_prefix'];
|
---|
210 |
|
---|
211 | $db =& XoopsDatabaseFactory::getDatabaseConnection() ;
|
---|
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' ) ;
|
---|
221 |
|
---|
222 | $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
223 |
|
---|
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";
|
---|
227 | $table_categories = $db->prefix($xpress_prefix."_categories");
|
---|
228 | $table_post2cat = $db->prefix($xpress_prefix."_post2cat");
|
---|
229 | $wp_post = $wp_full_prefix."posts";
|
---|
230 | $wp_options = $wp_full_prefix."options";
|
---|
231 | $wp_users = $db->prefix($xpress_prefix."_users");
|
---|
232 |
|
---|
233 | $sql = "SELECT option_value FROM $wp_options WHERE option_name ='blogname'";
|
---|
234 | $blog_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
235 | if( empty( $blog_row ) ) return false;
|
---|
236 | $blog_name = $blog_row['option_value'];
|
---|
237 |
|
---|
238 |
|
---|
239 | // query
|
---|
240 | $sql = "SELECT * FROM ".$wp_post." WHERE ID=$link_id ";
|
---|
241 | $post_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
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'";
|
---|
247 | $blog_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
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 |
|
---|
265 | $post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$db->prefix($this->d3forum_dirname."_posts")." WHERE post_id=$post_id" ) ) ;
|
---|
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 | }
|
---|
281 | $res2 = $db->query($sql2);
|
---|
282 | while($row2 = $db->fetchArray($res2)){
|
---|
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 |
|
---|
294 | $blog_info = $this->get_comment_blog_info($forum_id);
|
---|
295 | $wp_full_prefix = $blog_info['mb_table_prefix'];
|
---|
296 | $blog_id = $blog_info['blog_id'];
|
---|
297 | $target_db_prefix = $blog_info['mb_table_prefix'];
|
---|
298 | $mydirname = $this->mydirname ;
|
---|
299 | $xpress_prefix = preg_replace('/wordpress/','wp',$mydirname);
|
---|
300 | $d3f_forum_dir = $this->d3forum_dirname;
|
---|
301 |
|
---|
302 | $d3f_prefix = $d3f_forum_dir;
|
---|
303 | $myts =& MyTextSanitizer::getInstance();
|
---|
304 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
305 |
|
---|
306 | $wp_comments = $wp_full_prefix . 'comments';
|
---|
307 | $wp_posts = $wp_full_prefix . 'posts';
|
---|
308 | $wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link');
|
---|
309 | $d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts');
|
---|
310 | $d3f_topics = $xoopsDB->prefix($d3f_prefix . '_topics');
|
---|
311 | $d3f_users2topics = $xoopsDB->prefix($d3f_prefix . '_users2topics ');
|
---|
312 | $db_xoops_users = $xoopsDB->prefix('users');
|
---|
313 | $d3f_post_votes = $xoopsDB->prefix($d3f_prefix . '_post_votes');
|
---|
314 |
|
---|
315 | $comment_post_ID = $link_id;
|
---|
316 |
|
---|
317 | $d3f_sql = "SELECT $d3f_posts.guest_name, ";
|
---|
318 | $d3f_sql .= "$d3f_posts.guest_email, $d3f_posts.guest_url, $d3f_posts.poster_ip, $d3f_posts.post_time, ";
|
---|
319 | $d3f_sql .= "$d3f_posts.post_text, $d3f_posts.approval, $d3f_posts.uid ,$d3f_posts.pid ";
|
---|
320 | $d3f_sql .= "FROM $d3f_posts ";
|
---|
321 | $d3f_sql .= "WHERE $d3f_posts.post_id = $post_id";
|
---|
322 |
|
---|
323 | $d3f_res = $xoopsDB->query($d3f_sql, 0, 0);
|
---|
324 | if ($d3f_res === false){
|
---|
325 | die('...Err. OPEN D3Forum Data (' . $d3f_sql . ')');
|
---|
326 | }else {
|
---|
327 | $d3f_row = $xoopsDB->fetchArray($d3f_res);
|
---|
328 | $uid = $d3f_row['uid'];
|
---|
329 | if (!empty($uid)) {
|
---|
330 | $xu_sql = "SELECT uid ,name ,uname ,email , url FROM $db_xoops_users WHERE uid = $uid";
|
---|
331 | $xu_res = $xoopsDB->query($xu_sql, 0, 0);
|
---|
332 | if ($xu_res === false){
|
---|
333 | $user_display_name = '';
|
---|
334 | }else {
|
---|
335 | $xu_row = $xoopsDB->fetchArray($xu_res);
|
---|
336 | if (empty($xu_row['name'])){
|
---|
337 | $user_display_name = $xu_row['uname'];
|
---|
338 | } else {
|
---|
339 | $user_display_name = $xu_row['name'] ;
|
---|
340 | }
|
---|
341 | $comment_author_email = "'" . $xu_row['email'] . "'";
|
---|
342 | $comment_author_url = "'" . $xu_row['url'] . "'";
|
---|
343 | }
|
---|
344 | $comment_author = "'" . addSlashes($user_display_name) . "'";
|
---|
345 | } else {
|
---|
346 | $comment_author = "'" . addSlashes($d3f_row['guest_name']) . "'";
|
---|
347 | $comment_author_email = "'" . $d3f_row['guest_email'] . "'";
|
---|
348 | $comment_author_url = "'" . $d3f_row['guest_url'] . "'";
|
---|
349 | }
|
---|
350 | $comment_author_IP = "'" . $d3f_row['poster_ip'] . "'";
|
---|
351 | $comment_date = "'" . date('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
|
---|
352 | $comment_content = "'" . addSlashes($d3f_row['post_text']) . "'";
|
---|
353 | $comment_approved = "'" . $d3f_row['approval'] . "'";
|
---|
354 | require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
|
---|
355 | $user_ID = xoops_uid_to_wp_uid($d3f_row['uid'],$mydirname);
|
---|
356 | $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
|
---|
357 | $comment_type = '';
|
---|
358 | $d3f_pid = $d3f_row['pid'];
|
---|
359 | if ($d3f_pid > 0) {
|
---|
360 | $comment_parent = $this->get_wp_comment_ID($d3f_pid);
|
---|
361 | } else {
|
---|
362 | $comment_parent = 0 ;
|
---|
363 | }
|
---|
364 |
|
---|
365 | switch($mode){
|
---|
366 | case 'reply':
|
---|
367 | case 'newtopic' :
|
---|
368 | $wp_sql = "INSERT INTO $wp_comments ";
|
---|
369 | $wp_sql .= "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , ";
|
---|
370 | $wp_sql .= "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) ";
|
---|
371 | $wp_sql .= "VALUES ";
|
---|
372 | $wp_sql .= "($comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, ";
|
---|
373 | $wp_sql .= "$comment_date, $comment_content, $comment_approved, $user_ID, $comment_date_gmt, $comment_parent)";
|
---|
374 |
|
---|
375 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
376 | if ($wp_res === false){
|
---|
377 | die( '...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
378 | } else{
|
---|
379 | $comment_ID = $xoopsDB->getInsertId();
|
---|
380 |
|
---|
381 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count +1 WHERE ID = $comment_post_ID";
|
---|
382 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
383 |
|
---|
384 | $wp_sql = "INSERT INTO $wp_d3forum_link ";
|
---|
385 | $wp_sql .= "(comment_ID , post_id, forum_id,blog_id) ";
|
---|
386 | $wp_sql .= "VALUES ";
|
---|
387 | $wp_sql .= "($comment_ID, $post_id ,$forum_id,$blog_id)";
|
---|
388 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | if ($comment_approved ==0){
|
---|
393 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
|
---|
394 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
395 | $notification_handler->triggerEvent( 'global' , 0 , 'waiting') ;
|
---|
396 | }
|
---|
397 |
|
---|
398 | break;
|
---|
399 | case 'edit':
|
---|
400 | $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id ";
|
---|
401 | $wp_res = $xoopsDB->query($wp_sql, 0, 0);
|
---|
402 | if ($wp_res === false){
|
---|
403 | die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
404 | } else {
|
---|
405 | $wp_row = $xoopsDB->fetchArray($wp_res);
|
---|
406 | $comment_ID = $wp_row['comment_ID'];
|
---|
407 |
|
---|
408 |
|
---|
409 | $wp_sql = "UPDATE $wp_comments SET comment_content = $comment_content , comment_date_gmt = $comment_date_gmt WHERE comment_ID = $comment_ID";
|
---|
410 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
411 | if ($wp_res === false){
|
---|
412 | die( '...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')');
|
---|
413 | }
|
---|
414 | }
|
---|
415 | break;
|
---|
416 | case 'delete':
|
---|
417 | // wordpress comments delete
|
---|
418 | $comment_ID = $this->get_wp_comment_ID($post_id);
|
---|
419 | if ($comment_ID > 0){
|
---|
420 | $sql= "SELECT comment_type FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
421 | $res= $xoopsDB->query( $sql);
|
---|
422 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
423 | $row = $xoopsDB->fetchArray($res);
|
---|
424 | $comment_type = $row['comment_type'];
|
---|
425 | if (!empty($comment_type)) break;
|
---|
426 | }
|
---|
427 | $wp_sql = "DELETE FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
428 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
429 |
|
---|
430 | $wp_sql = "DELETE FROM $wp_d3forum_link WHERE post_id = $post_id";
|
---|
431 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
432 |
|
---|
433 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count -1 WHERE ID = $comment_post_ID";
|
---|
434 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
435 | }
|
---|
436 | break;
|
---|
437 | default :
|
---|
438 | }
|
---|
439 | }
|
---|
440 | return true ;
|
---|
441 | }
|
---|
442 | function get_wp_comment_ID($d3forum_post_ID){
|
---|
443 | $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
444 | $xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix);
|
---|
445 |
|
---|
446 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
447 | $wp_d3forum_link = $xoopsDB->prefix($xp_prefix . '_d3forum_link');
|
---|
448 |
|
---|
449 | $sql = "SELECT * FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID";
|
---|
450 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
451 | $ret = 0;
|
---|
452 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
453 | $row = $xoopsDB->fetchArray($res);
|
---|
454 | $ret = $row['comment_ID'];
|
---|
455 | }
|
---|
456 | return $ret;
|
---|
457 | }
|
---|
458 |
|
---|
459 | function get_comment_blog_info($d3forum_forum_id){
|
---|
460 | $xoopsDB =& XoopsDatabaseFactory::getDatabaseConnection();
|
---|
461 | $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
462 | $xp_prefix = preg_replace('/wordpress/','wp',$xp_prefix);
|
---|
463 | $xp_prefix = $xoopsDB->prefix($xp_prefix);
|
---|
464 | $table_name = 'options';
|
---|
465 | $options_array = array();
|
---|
466 |
|
---|
467 |
|
---|
468 | $sql = "SHOW TABLES LIKE '" . $xp_prefix . '%' . $table_name . "'";
|
---|
469 | if($result = $xoopsDB->queryF($sql)){
|
---|
470 | while($row = $xoopsDB->fetchRow($result)){
|
---|
471 | $wp_option_table = $row[0];
|
---|
472 | $pattern = '/'. $table_name . '/';
|
---|
473 | $option['mb_table_prefix'] = preg_replace($pattern,'',$wp_option_table);
|
---|
474 | if (preg_match('/'. $xp_prefix . '_([0-9]*)_/',$option['mb_table_prefix'],$matchs)){
|
---|
475 | $option['blog_id'] = $matchs[1];
|
---|
476 | } else {
|
---|
477 | $option['blog_id'] = 1;
|
---|
478 | }
|
---|
479 |
|
---|
480 | $option_sql = "SELECT option_name, option_value FROM $wp_option_table WHERE option_name IN ('home','siteurl','blogname','xpressme_option')";
|
---|
481 | if($option_result = $xoopsDB->query($option_sql, 0, 0)){
|
---|
482 | while($option_row = $xoopsDB->fetchArray($option_result)){
|
---|
483 | $name = $option_row['option_name'];
|
---|
484 | $value = $option_row['option_value'];
|
---|
485 | if ($name == 'xpressme_option'){
|
---|
486 | $value = @unserialize( $value );
|
---|
487 | }
|
---|
488 | $option[$name] = $value;
|
---|
489 | }
|
---|
490 | $option['siteurl'] = preg_replace('/\/$/','',$option['siteurl']);
|
---|
491 | $option['home'] = preg_replace('/\/$/','',$option['home']);
|
---|
492 |
|
---|
493 | if ($option['blog_id'] === 1){
|
---|
494 | $option['sub_dir'] = '';
|
---|
495 | } else {
|
---|
496 | $xoops_url = str_replace('/','\\/',XOOPS_URL);
|
---|
497 | if (preg_match('/'. $xoops_url . '.*' . $wpdirname . '(.*)/',$option['home'],$matchs)){
|
---|
498 | $option['sub_dir'] = $matchs[1];
|
---|
499 | } else {
|
---|
500 | $option['sub_dir'] = '';
|
---|
501 | }
|
---|
502 | }
|
---|
503 | if ($option['xpressme_option']['d3forum_forum_id'] == $d3forum_forum_id){
|
---|
504 | return $option;
|
---|
505 | }
|
---|
506 | }
|
---|
507 | }
|
---|
508 | return null;
|
---|
509 | }
|
---|
510 | }
|
---|
511 | function repair_d3forum_link($comment_ID, $post_id ,$forum_id,$blog_id,$target_db_prefix){
|
---|
512 | }
|
---|
513 |
|
---|
514 | } // class
|
---|
515 | }
|
---|
516 | ?> |
---|