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