[104] | 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 | {
|
---|
[144] | 137 | global $xpress_config;
|
---|
[104] | 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' ) ;
|
---|
[257] | 200 |
|
---|
[104] | 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 |
|
---|
[257] | 218 |
|
---|
[104] | 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 |
|
---|
[261] | 274 | $mydirname = $this->mydirname ;
|
---|
[104] | 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'] . "'";
|
---|
[257] | 331 | require_once (XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/include/general_functions.php');
|
---|
[261] | 332 | $user_ID = xoops_uid_to_wp_uid($d3f_row['uid'],$mydirname);
|
---|
[104] | 333 | $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
|
---|
| 334 | $comment_type = '';
|
---|
| 335 | $d3f_pid = $d3f_row['pid'];
|
---|
| 336 | if ($d3f_pid > 0) {
|
---|
| 337 | $comment_parent = $this->get_wp_comment_ID($d3f_pid);
|
---|
| 338 | } else {
|
---|
| 339 | $comment_parent = 0 ;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | switch($mode){
|
---|
| 343 | case 'reply':
|
---|
| 344 | case 'newtopic' :
|
---|
| 345 | $wp_sql = "INSERT INTO $wp_comments ";
|
---|
| 346 | $wp_sql .= "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , ";
|
---|
| 347 | $wp_sql .= "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) ";
|
---|
| 348 | $wp_sql .= "VALUES ";
|
---|
| 349 | $wp_sql .= "($comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, ";
|
---|
| 350 | $wp_sql .= "$comment_date, $comment_content, $comment_approved, $user_ID, $comment_date_gmt, $comment_parent)";
|
---|
| 351 |
|
---|
| 352 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 353 | if ($wp_res === false){
|
---|
| 354 | die( '...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 355 | } else{
|
---|
| 356 | $comment_ID = $xoopsDB->getInsertId();
|
---|
| 357 |
|
---|
| 358 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count +1 WHERE ID = $comment_post_ID";
|
---|
| 359 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 360 |
|
---|
| 361 | $wp_sql = "INSERT INTO $wp_d3forum_link ";
|
---|
| 362 | $wp_sql .= "(comment_ID , post_id) ";
|
---|
| 363 | $wp_sql .= "VALUES ";
|
---|
| 364 | $wp_sql .= "($comment_ID, $post_id)";
|
---|
| 365 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 |
|
---|
| 369 | if ($comment_approved ==0){
|
---|
| 370 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
|
---|
| 371 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 372 | $notification_handler->triggerEvent( 'global' , 0 , 'waiting') ;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | break;
|
---|
| 376 | case 'edit':
|
---|
| 377 | $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id";
|
---|
| 378 | $wp_res = $xoopsDB->query($wp_sql, 0, 0);
|
---|
| 379 | if ($wp_res === false){
|
---|
| 380 | die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 381 | } else {
|
---|
| 382 | $wp_row = $xoopsDB->fetchArray($wp_res);
|
---|
| 383 | $comment_ID = $wp_row['comment_ID'];
|
---|
| 384 |
|
---|
| 385 |
|
---|
| 386 | $wp_sql = "UPDATE $wp_comments SET comment_content = $comment_content , comment_date_gmt = $comment_date_gmt WHERE comment_ID = $comment_ID";
|
---|
| 387 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 388 | if ($wp_res === false){
|
---|
| 389 | die( '...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 | break;
|
---|
| 393 | case 'delete':
|
---|
| 394 | // wordpress comments delete
|
---|
| 395 | $comment_ID = $this->get_wp_comment_ID($post_id);
|
---|
| 396 | if ($comment_ID > 0){
|
---|
| 397 | $sql= "SELECT comment_type FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
| 398 | $res= $xoopsDB->query( $sql);
|
---|
| 399 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
| 400 | $row = $xoopsDB->fetchArray($res);
|
---|
| 401 | $comment_type = $row['comment_type'];
|
---|
| 402 | if (!empty($comment_type)) break;
|
---|
| 403 | }
|
---|
| 404 | $wp_sql = "DELETE FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
| 405 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 406 |
|
---|
| 407 | $wp_sql = "DELETE FROM $wp_d3forum_link WHERE post_id = $post_id";
|
---|
| 408 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 409 |
|
---|
| 410 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count -1 WHERE ID = $comment_post_ID";
|
---|
| 411 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 412 | }
|
---|
| 413 | break;
|
---|
| 414 | default :
|
---|
| 415 | }
|
---|
| 416 | }
|
---|
| 417 | return true ;
|
---|
| 418 | }
|
---|
| 419 | function get_wp_comment_ID($d3forum_post_ID){
|
---|
| 420 | $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 421 | if ($xp_prefix == 'wordpress'){
|
---|
| 422 | $xp_prefix = 'wp';
|
---|
| 423 | }
|
---|
| 424 |
|
---|
| 425 | $xoopsDB =& Database::getInstance();
|
---|
| 426 | $wp_d3forum_link = $xoopsDB->prefix($xp_prefix . '_d3forum_link');
|
---|
| 427 |
|
---|
| 428 | $sql = "SELECT * FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID";
|
---|
| 429 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
| 430 | $ret = 0;
|
---|
| 431 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
| 432 | $row = $xoopsDB->fetchArray($res);
|
---|
| 433 | $ret = $row['comment_ID'];
|
---|
| 434 | }
|
---|
| 435 | return $ret;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | }
|
---|
| 439 | }
|
---|
| 440 | ?> |
---|