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