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