[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 if( ! empty( $this->mod_config['comment_view'] ) ) {
|
---|
| 128 | return $this->mod_config['comment_view'] ;
|
---|
| 129 | } else {
|
---|
| 130 | return 'listposts' ;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 | // get view from $params or config
|
---|
| 136 | // override it if necessary
|
---|
| 137 | function getOrder( $params )
|
---|
| 138 | {
|
---|
| 139 | if( ! empty( $params['order'] ) ) {
|
---|
| 140 | return strtolower( $params['order'] ) ;
|
---|
| 141 | } else if( ! empty( $this->mod_config['comment_order'] ) ) {
|
---|
| 142 | return $this->mod_config['comment_order'] ;
|
---|
| 143 | } else {
|
---|
| 144 | return 'desc' ;
|
---|
| 145 |
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | // get number of posts will be displayed from $params or config
|
---|
| 151 | // override it if necessary
|
---|
| 152 | function getPostsNum( $params )
|
---|
| 153 | {
|
---|
| 154 | if( ! empty( $params['posts_num'] ) ) {
|
---|
| 155 | return $params['posts_num'] ;
|
---|
| 156 | } else if( ! empty( $this->mod_config['comment_posts_num'] ) ) {
|
---|
| 157 | return $this->mod_config['comment_posts_num'] ;
|
---|
| 158 | } else {
|
---|
| 159 | return 10 ;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | function validate_id( $link_id )
|
---|
| 164 | {
|
---|
| 165 | $post_id = intval( $link_id ) ;
|
---|
| 166 | $mydirname = $this->mydirname ;
|
---|
| 167 | $xpress_prefix = $mydirname;
|
---|
| 168 | if ($xpress_prefix == 'wordpress') $xpress_prefix = 'wp';
|
---|
| 169 |
|
---|
| 170 | $db =& Database::getInstance() ;
|
---|
| 171 |
|
---|
| 172 | list( $count ) = $db->fetchRow( $db->query( "SELECT COUNT(*) FROM ".$db->prefix($xpress_prefix."_posts")." WHERE ID=$post_id AND comment_status ='open'" ) ) ;
|
---|
| 173 |
|
---|
| 174 | if( $count <= 0 ) return false ;
|
---|
| 175 | else return $post_id ;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | // callback on newtopic/edit/reply/delete
|
---|
| 179 | // abstract
|
---|
| 180 | function onUpdate( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 )
|
---|
| 181 | {
|
---|
| 182 | global $message;
|
---|
| 183 |
|
---|
| 184 | if ($mode == 'approve'){
|
---|
| 185 | $mode = 'edit';
|
---|
| 186 | }
|
---|
| 187 | return $this->sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id);
|
---|
| 188 |
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | // processing xoops notification for 'comment'
|
---|
| 192 | // override it if necessary
|
---|
| 193 | function processCommentNotifications( $mode , $link_id , $forum_id , $topic_id , $post_id )
|
---|
| 194 | {
|
---|
| 195 | $db =& Database::getInstance() ;
|
---|
| 196 | $myts =& MyTextsanitizer::getInstance() ;
|
---|
| 197 |
|
---|
| 198 | $module_handler =& xoops_gethandler( 'module' ) ;
|
---|
| 199 | $module =& $module_handler->getByDirname( $this->mydirname ) ;
|
---|
| 200 | $config_handler =& xoops_gethandler('config');
|
---|
| 201 | $configs = $config_handler->getConfigList( $module->mid() ) ;
|
---|
| 202 |
|
---|
| 203 | $mydirname = $this->mydirname ;
|
---|
| 204 | if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
|
---|
| 205 |
|
---|
| 206 | $xpress_prefix = $mydirname;
|
---|
| 207 | if ($xpress_prefix == 'wordpress') $xpress_prefix = 'wp';
|
---|
| 208 |
|
---|
| 209 | $table_term_relationships = $db->prefix($xpress_prefix."_term_relationships");
|
---|
| 210 | $table_term_taxonomy = $db->prefix($xpress_prefix."_term_taxonomy");
|
---|
| 211 | $table_terms = $db->prefix($xpress_prefix."_terms");
|
---|
| 212 | $table_categories = $db->prefix($xpress_prefix."_categories");
|
---|
| 213 | $table_post2cat = $db->prefix($xpress_prefix."_post2cat");
|
---|
| 214 | $wp_post = $db->prefix($xpress_prefix."_posts");
|
---|
| 215 | $wp_options = $db->prefix($xpress_prefix."_options");
|
---|
| 216 | $wp_users = $db->prefix($xpress_prefix."_users");
|
---|
| 217 |
|
---|
| 218 | $sql = "SELECT option_value FROM $wp_options WHERE option_name ='blogname'";
|
---|
| 219 | $blog_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
| 220 | if( empty( $blog_row ) ) return false;
|
---|
| 221 | $blog_name = $blog_row['option_value'];
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | // query
|
---|
| 225 | $sql = "SELECT * FROM ".$wp_post." WHERE ID=$link_id ";
|
---|
| 226 | $post_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
| 227 | if( empty( $post_row ) ) return false;
|
---|
| 228 | $post_title = $post_row['post_title'];
|
---|
| 229 | $post_author = $post_row['post_author'];
|
---|
| 230 |
|
---|
| 231 | $sql = "SELECT display_name FROM $wp_users WHERE ID ='$post_author'";
|
---|
| 232 | $blog_row = $db->fetchArray( $db->query( $sql ) ) ;
|
---|
| 233 | if( empty( $blog_row ) ) return false;
|
---|
| 234 | $user_name = $blog_row['display_name'];
|
---|
| 235 |
|
---|
| 236 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
|
---|
| 237 |
|
---|
| 238 | // non-module integration returns false quickly
|
---|
| 239 | if( ! is_object( $this->module ) ) return false ;
|
---|
| 240 |
|
---|
| 241 | $not_module =& $this->module ;
|
---|
| 242 | $not_modid = $this->module->getVar('mid') ;
|
---|
| 243 |
|
---|
| 244 | $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) ) ;
|
---|
| 245 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 246 | $notification_handler->triggerEvent( 'global' , 0 , 'comment' , $comment_tags , false , $not_modid ) ;
|
---|
| 247 | $notification_handler->triggerEvent( 'author' , $post_author , 'comment' , $comment_tags , false , $not_modid ) ;
|
---|
| 248 | $notification_handler->triggerEvent( 'post' , $link_id , 'comment' , $comment_tags , false , $not_modid ) ;
|
---|
| 249 |
|
---|
| 250 | $post_row = $db->fetchArray( $db->query( "SELECT * FROM ".$db->prefix($this->d3forum_dirname."_posts")." WHERE post_id=$post_id" ) ) ;
|
---|
| 251 | if( !empty( $post_row ) ){
|
---|
| 252 | if ( $post_row['approval'] ==0 ){
|
---|
| 253 | $notification_handler->triggerEvent( 'global' , 0 , 'waiting', $comment_tags , false , $not_modid ) ;
|
---|
| 254 | }
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | // categorie notification
|
---|
| 258 | include(XOOPS_ROOT_PATH . '/modules/'.$mydirname . '/wp-includes/version.php');
|
---|
| 259 | if ($wp_db_version < 6124){
|
---|
| 260 | $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;
|
---|
| 261 | } else {
|
---|
| 262 | $sql2 = "SELECT $table_term_relationships.object_id, $table_terms.term_id AS cat_ID, $table_terms.name AS cat_name ";
|
---|
| 263 | $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 ";
|
---|
| 264 | $sql2 .= "WHERE ($table_term_relationships.object_id =" . $link_id.") AND ($table_term_taxonomy.taxonomy='category')";
|
---|
| 265 | }
|
---|
| 266 | $res2 = $db->query($sql2);
|
---|
| 267 | while($row2 = $db->fetchArray($res2)){
|
---|
| 268 | $cat_id = $row2['cat_ID'];
|
---|
| 269 | $cat_name = $row2['cat_name'];
|
---|
| 270 | $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) ) ;
|
---|
| 271 | $notification_handler->triggerEvent( 'category' , $cat_id , 'comment' , $comment_tags , false , $not_modid ) ;
|
---|
| 272 | }
|
---|
| 273 | }
|
---|
| 274 |
|
---|
| 275 | // The content is reflected in the WordPress comment when there is a change in the D3Forum comment.
|
---|
| 276 |
|
---|
| 277 | function sync_to_wp_comment( $mode , $link_id , $forum_id , $topic_id , $post_id = 0 ){
|
---|
| 278 |
|
---|
| 279 | $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 280 | $xpress_prefix = $mydirname;
|
---|
| 281 | if ($xpress_prefix == 'wordpress') $xpress_prefix = 'wp';
|
---|
| 282 | $d3f_forum_dir = $this->d3forum_dirname;
|
---|
| 283 |
|
---|
| 284 | $d3f_prefix = $d3f_forum_dir;
|
---|
| 285 | $myts =& MyTextSanitizer::getInstance();
|
---|
| 286 | $xoopsDB =& Database::getInstance();
|
---|
| 287 |
|
---|
| 288 | $wp_comments = $xoopsDB->prefix($xpress_prefix . '_comments');
|
---|
| 289 | $wp_posts = $xoopsDB->prefix($xpress_prefix . '_posts');
|
---|
| 290 | $wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link');
|
---|
| 291 | $d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts');
|
---|
| 292 | $d3f_topics = $xoopsDB->prefix($d3f_prefix . '_topics');
|
---|
| 293 | $d3f_users2topics = $xoopsDB->prefix($d3f_prefix . '_users2topics ');
|
---|
| 294 | $db_xoops_users = $xoopsDB->prefix('users');
|
---|
| 295 | $d3f_post_votes = $xoopsDB->prefix($d3f_prefix . '_post_votes');
|
---|
| 296 |
|
---|
| 297 | $comment_post_ID = $link_id;
|
---|
| 298 |
|
---|
| 299 | $d3f_sql = "SELECT $d3f_posts.guest_name, ";
|
---|
| 300 | $d3f_sql .= "$d3f_posts.guest_email, $d3f_posts.guest_url, $d3f_posts.poster_ip, $d3f_posts.post_time, ";
|
---|
| 301 | $d3f_sql .= "$d3f_posts.post_text, $d3f_posts.approval, $d3f_posts.uid ,$d3f_posts.pid ";
|
---|
| 302 | $d3f_sql .= "FROM $d3f_posts ";
|
---|
| 303 | $d3f_sql .= "WHERE $d3f_posts.post_id = $post_id";
|
---|
| 304 |
|
---|
| 305 | $d3f_res = $xoopsDB->query($d3f_sql, 0, 0);
|
---|
| 306 | if ($d3f_res === false){
|
---|
| 307 | die('...Err. OPEN D3Forum Data (' . $d3f_sql . ')');
|
---|
| 308 | }else {
|
---|
| 309 | $d3f_row = $xoopsDB->fetchArray($d3f_res);
|
---|
| 310 | $uid = $d3f_row['uid'];
|
---|
| 311 | if (!empty($uid)) {
|
---|
| 312 | $xu_sql = "SELECT uid ,name ,uname ,email , url FROM $db_xoops_users WHERE uid = $uid";
|
---|
| 313 | $xu_res = $xoopsDB->query($xu_sql, 0, 0);
|
---|
| 314 | if ($xu_res === false){
|
---|
| 315 | $user_display_name = '';
|
---|
| 316 | }else {
|
---|
| 317 | $xu_row = $xoopsDB->fetchArray($xu_res);
|
---|
| 318 | if (empty($xu_row['name'])){
|
---|
| 319 | $user_display_name = $xu_row['uname'];
|
---|
| 320 | } else {
|
---|
| 321 | $user_display_name = $xu_row['name'] ;
|
---|
| 322 | }
|
---|
| 323 | $comment_author_email = "'" . $xu_row['email'] . "'";
|
---|
| 324 | $comment_author_url = "'" . $xu_row['url'] . "'";
|
---|
| 325 | }
|
---|
| 326 | $comment_author = "'" . addSlashes($user_display_name) . "'";
|
---|
| 327 | } else {
|
---|
| 328 | $comment_author = "'" . addSlashes($d3f_row['guest_name']) . "'";
|
---|
| 329 | $comment_author_email = "'" . $d3f_row['guest_email'] . "'";
|
---|
| 330 | $comment_author_url = "'" . $d3f_row['guest_url'] . "'";
|
---|
| 331 | }
|
---|
| 332 | $comment_author_IP = "'" . $d3f_row['poster_ip'] . "'";
|
---|
| 333 | $comment_date = "'" . date('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
|
---|
| 334 | $comment_content = "'" . addSlashes($d3f_row['post_text']) . "'";
|
---|
| 335 | $comment_approved = "'" . $d3f_row['approval'] . "'";
|
---|
| 336 | $user_ID = $d3f_row['uid'];
|
---|
| 337 | $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s' , $d3f_row['post_time']) . "'";
|
---|
| 338 | $comment_type = '';
|
---|
| 339 | $d3f_pid = $d3f_row['pid'];
|
---|
| 340 | if ($d3f_pid > 0) {
|
---|
| 341 | $comment_parent = $this->get_wp_comment_ID($d3f_pid);
|
---|
| 342 | } else {
|
---|
| 343 | $comment_parent = 0 ;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | switch($mode){
|
---|
| 347 | case 'reply':
|
---|
| 348 | case 'newtopic' :
|
---|
| 349 | $wp_sql = "INSERT INTO $wp_comments ";
|
---|
| 350 | $wp_sql .= "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , ";
|
---|
| 351 | $wp_sql .= "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) ";
|
---|
| 352 | $wp_sql .= "VALUES ";
|
---|
| 353 | $wp_sql .= "($comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, ";
|
---|
| 354 | $wp_sql .= "$comment_date, $comment_content, $comment_approved, $user_ID, $comment_date_gmt, $comment_parent)";
|
---|
| 355 |
|
---|
| 356 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 357 | if ($wp_res === false){
|
---|
| 358 | die( '...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 359 | } else{
|
---|
| 360 | $comment_ID = $xoopsDB->getInsertId();
|
---|
| 361 |
|
---|
| 362 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count +1 WHERE ID = $comment_post_ID";
|
---|
| 363 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 364 |
|
---|
| 365 | $wp_sql = "INSERT INTO $wp_d3forum_link ";
|
---|
| 366 | $wp_sql .= "(comment_ID , post_id) ";
|
---|
| 367 | $wp_sql .= "VALUES ";
|
---|
| 368 | $wp_sql .= "($comment_ID, $post_id)";
|
---|
| 369 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 |
|
---|
| 373 | if ($comment_approved ==0){
|
---|
| 374 | require_once XOOPS_ROOT_PATH . '/include/notification_functions.php' ;
|
---|
| 375 | $notification_handler =& xoops_gethandler( 'notification' ) ;
|
---|
| 376 | $notification_handler->triggerEvent( 'global' , 0 , 'waiting') ;
|
---|
| 377 | }
|
---|
| 378 |
|
---|
| 379 | break;
|
---|
| 380 | case 'edit':
|
---|
| 381 | $wp_sql = "SELECT comment_ID FROM $wp_d3forum_link WHERE post_id = $post_id";
|
---|
| 382 | $wp_res = $xoopsDB->query($wp_sql, 0, 0);
|
---|
| 383 | if ($wp_res === false){
|
---|
| 384 | die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 385 | } else {
|
---|
| 386 | $wp_row = $xoopsDB->fetchArray($wp_res);
|
---|
| 387 | $comment_ID = $wp_row['comment_ID'];
|
---|
| 388 |
|
---|
| 389 |
|
---|
| 390 | $wp_sql = "UPDATE $wp_comments SET comment_content = $comment_content , comment_date_gmt = $comment_date_gmt WHERE comment_ID = $comment_ID";
|
---|
| 391 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 392 | if ($wp_res === false){
|
---|
| 393 | die( '...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')');
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
| 396 | break;
|
---|
| 397 | case 'delete':
|
---|
| 398 | // wordpress comments delete
|
---|
| 399 | $comment_ID = $this->get_wp_comment_ID($post_id);
|
---|
| 400 | if ($comment_ID > 0){
|
---|
| 401 | $sql= "SELECT comment_type FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
| 402 | $res= $xoopsDB->query( $sql);
|
---|
| 403 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
| 404 | $row = $xoopsDB->fetchArray($res);
|
---|
| 405 | $comment_type = $row['comment_type'];
|
---|
| 406 | if (!empty($comment_type)) break;
|
---|
| 407 | }
|
---|
| 408 | $wp_sql = "DELETE FROM $wp_comments WHERE comment_ID = $comment_ID";
|
---|
| 409 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 410 |
|
---|
| 411 | $wp_sql = "DELETE FROM $wp_d3forum_link WHERE post_id = $post_id";
|
---|
| 412 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 413 |
|
---|
| 414 | $wp_sql = "UPDATE $wp_posts SET comment_count = comment_count -1 WHERE ID = $comment_post_ID";
|
---|
| 415 | $wp_res = $xoopsDB->queryF($wp_sql, 0, 0);
|
---|
| 416 | }
|
---|
| 417 | break;
|
---|
| 418 | default :
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | return true ;
|
---|
| 422 | }
|
---|
| 423 | function get_wp_comment_ID($d3forum_post_ID){
|
---|
| 424 | $xp_prefix = $wpdirname = basename( dirname( dirname( __FILE__ ) ) ) ;
|
---|
| 425 | if ($xp_prefix == 'wordpress'){
|
---|
| 426 | $xp_prefix = 'wp';
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | $xoopsDB =& Database::getInstance();
|
---|
| 430 | $wp_d3forum_link = $xoopsDB->prefix($xp_prefix . '_d3forum_link');
|
---|
| 431 |
|
---|
| 432 | $sql = "SELECT * FROM $wp_d3forum_link WHERE post_id = $d3forum_post_ID";
|
---|
| 433 | $res = $xoopsDB->query($sql, 0, 0);
|
---|
| 434 | $ret = 0;
|
---|
| 435 | if ($xoopsDB->getRowsNum($res) > 0 ){
|
---|
| 436 | $row = $xoopsDB->fetchArray($res);
|
---|
| 437 | $ret = $row['comment_ID'];
|
---|
| 438 | }
|
---|
| 439 | return $ret;
|
---|
| 440 | }
|
---|
| 441 |
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | ?> |
---|