function sync_to_wp_comment($mode, $link_id, $forum_id, $topic_id, $post_id = 0) { $blog_info = $this->get_comment_blog_info($forum_id); $wp_full_prefix = $blog_info['mb_table_prefix']; $blog_id = $blog_info['blog_id']; $target_db_prefix = $blog_info['mb_table_prefix']; $mydirname = $this->mydirname; $xpress_prefix = preg_replace('/wordpress/', 'wp', $mydirname); $d3f_forum_dir = $this->d3forum_dirname; $d3f_prefix = $d3f_forum_dir; $myts =& MyTextSanitizer::getInstance(); $xoopsDB =& Database::getInstance(); $wp_comments = $wp_full_prefix . 'comments'; $wp_posts = $wp_full_prefix . 'posts'; $wp_d3forum_link = $xoopsDB->prefix($xpress_prefix . '_d3forum_link'); $d3f_posts = $xoopsDB->prefix($d3f_prefix . '_posts'); $d3f_topics = $xoopsDB->prefix($d3f_prefix . '_topics'); $d3f_users2topics = $xoopsDB->prefix($d3f_prefix . '_users2topics '); $db_xoops_users = $xoopsDB->prefix('users'); $d3f_post_votes = $xoopsDB->prefix($d3f_prefix . '_post_votes'); $comment_post_ID = $link_id; $d3f_sql = "SELECT {$d3f_posts}.guest_name, "; $d3f_sql .= "{$d3f_posts}.guest_email, {$d3f_posts}.guest_url, {$d3f_posts}.poster_ip, {$d3f_posts}.post_time, "; $d3f_sql .= "{$d3f_posts}.post_text, {$d3f_posts}.approval, {$d3f_posts}.uid ,{$d3f_posts}.pid "; $d3f_sql .= "FROM {$d3f_posts} "; $d3f_sql .= "WHERE {$d3f_posts}.post_id = {$post_id}"; $d3f_res = $xoopsDB->query($d3f_sql, 0, 0); if ($d3f_res === false) { die('...Err. OPEN D3Forum Data (' . $d3f_sql . ')'); } else { $d3f_row = $xoopsDB->fetchArray($d3f_res); $uid = $d3f_row['uid']; if (!empty($uid)) { $xu_sql = "SELECT uid ,name ,uname ,email , url FROM {$db_xoops_users} WHERE uid = {$uid}"; $xu_res = $xoopsDB->query($xu_sql, 0, 0); if ($xu_res === false) { $user_display_name = ''; } else { $xu_row = $xoopsDB->fetchArray($xu_res); if (empty($xu_row['name'])) { $user_display_name = $xu_row['uname']; } else { $user_display_name = $xu_row['name']; } $comment_author_email = "'" . $xu_row['email'] . "'"; $comment_author_url = "'" . $xu_row['url'] . "'"; } $comment_author = "'" . addSlashes($user_display_name) . "'"; } else { $comment_author = "'" . addSlashes($d3f_row['guest_name']) . "'"; $comment_author_email = "'" . $d3f_row['guest_email'] . "'"; $comment_author_url = "'" . $d3f_row['guest_url'] . "'"; } $comment_author_IP = "'" . $d3f_row['poster_ip'] . "'"; $comment_date = "'" . date('Y-m-d H:i:s', $d3f_row['post_time']) . "'"; $comment_content = "'" . addSlashes($d3f_row['post_text']) . "'"; $comment_approved = "'" . $d3f_row['approval'] . "'"; require_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/general_functions.php'; $user_ID = xoops_uid_to_wp_uid($d3f_row['uid'], $mydirname); $comment_date_gmt = "'" . gmdate('Y-m-d H:i:s', $d3f_row['post_time']) . "'"; $comment_type = ''; $d3f_pid = $d3f_row['pid']; if ($d3f_pid > 0) { $comment_parent = $this->get_wp_comment_ID($d3f_pid); } else { $comment_parent = 0; } switch ($mode) { case 'reply': case 'newtopic': $wp_sql = "INSERT INTO {$wp_comments} "; $wp_sql .= "(comment_post_ID , comment_author , comment_author_email , comment_author_url , comment_author_IP , "; $wp_sql .= "comment_date , comment_content , comment_approved , user_id , comment_date_gmt, comment_parent) "; $wp_sql .= "VALUES "; $wp_sql .= "({$comment_post_ID}, {$comment_author}, {$comment_author_email}, {$comment_author_url}, {$comment_author_IP}, "; $wp_sql .= "{$comment_date}, {$comment_content}, {$comment_approved}, {$user_ID}, {$comment_date_gmt}, {$comment_parent})"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); if ($wp_res === false) { die('...Err. INSERT' . $wp_comments . '(' . $wp_sql . ')'); } else { $comment_ID = $xoopsDB->getInsertId(); $wp_sql = "UPDATE {$wp_posts} SET comment_count = comment_count +1 WHERE ID = {$comment_post_ID}"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); $wp_sql = "INSERT INTO {$wp_d3forum_link} "; $wp_sql .= "(comment_ID , post_id, forum_id,blog_id) "; $wp_sql .= "VALUES "; $wp_sql .= "({$comment_ID}, {$post_id} ,{$forum_id},{$blog_id})"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); } if ($comment_approved == 0) { require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; $notification_handler =& xoops_gethandler('notification'); $notification_handler->triggerEvent('global', 0, 'waiting'); } break; case 'edit': $wp_sql = "SELECT comment_ID FROM {$wp_d3forum_link} WHERE post_id = {$post_id} "; $wp_res = $xoopsDB->query($wp_sql, 0, 0); if ($wp_res === false) { die('...Err. EDIT' . $wp_comments . '(' . $wp_sql . ')'); } else { $wp_row = $xoopsDB->fetchArray($wp_res); $comment_ID = $wp_row['comment_ID']; $wp_sql = "UPDATE {$wp_comments} SET comment_content = {$comment_content} , comment_date_gmt = {$comment_date_gmt} WHERE comment_ID = {$comment_ID}"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); if ($wp_res === false) { die('...Err. UPDATE' . $wp_comments . '(' . $wp_sql . ')'); } } break; case 'delete': // wordpress comments delete $comment_ID = $this->get_wp_comment_ID($post_id); if ($comment_ID > 0) { $sql = "SELECT comment_type FROM {$wp_comments} WHERE comment_ID = {$comment_ID}"; $res = $xoopsDB->query($sql); if ($xoopsDB->getRowsNum($res) > 0) { $row = $xoopsDB->fetchArray($res); $comment_type = $row['comment_type']; if (!empty($comment_type)) { break; } } $wp_sql = "DELETE FROM {$wp_comments} WHERE comment_ID = {$comment_ID}"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); $wp_sql = "DELETE FROM {$wp_d3forum_link} WHERE post_id = {$post_id}"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); $wp_sql = "UPDATE {$wp_posts} SET comment_count = comment_count -1 WHERE ID = {$comment_post_ID}"; $wp_res = $xoopsDB->queryF($wp_sql, 0, 0); } break; default: } } return true; }
function xpress_global_search_base($mydirname, $queryarray, $andor, $limit, $offset, $userid) { global $xoopsDB, $myts; require_once XOOPS_ROOT_PATH . '/modules/' . $mydirname . '/include/general_functions.php'; $myts =& MyTextSanitizer::getInstance(); $xp_prefix = preg_replace('/wordpress/', 'wp', $mydirname); if ($userid) { $wp_uid = xoops_uid_to_wp_uid(intval($userid), $mydirname); } $prefix = XOOPS_DB_PREFIX . '_' . $xp_prefix; $posts_tables = get_table_list($prefix, 'posts'); $i = 0; $ret = array(); foreach ($posts_tables as $views_table) { $mid_prefix = get_multi_mid_prefix($prefix, 'posts', $views_table); $option_table = $prefix . $mid_prefix . 'options'; $time_difference = get_blog_option($option_table, 'gmt_offset'); $blog_url = get_blog_option($option_table, 'siteurl'); $pattern = '/.*' . $mydirname . '/'; $mid_url = preg_replace($pattern, '', $blog_url); $mid_url = preg_replace('/\\//', '', $mid_url); if (!empty($mid_url)) { $mid_url = $mid_url . '/'; } $blog_name = get_blog_option($option_table, 'blogname'); if (empty($mid_url)) { $blog_name = ''; } else { $blog_name = $blog_name . ':: '; } $now = date('Y-m-d H:i:s', time() + $time_difference * 3600); $where = "(post_status = 'publish') AND (post_date <= '" . $now . "') AND (post_type <> 'revision') AND (post_type <> 'nav_menu_item') "; if (is_array($queryarray) && ($count = count($queryarray))) { $str_query = array(); for ($j = 0; $j < $count; $j++) { $str_query[] = "(post_title LIKE '%" . $queryarray[$j] . "%' OR post_content LIKE '%" . $queryarray[$j] . "%')"; } $where .= " AND " . implode(" {$andor} ", $str_query); } if ($userid) { if ($wp_uid) { $where .= " AND (post_author=" . $wp_uid . ")"; } else { $where .= " AND 0 "; } } $request = "SELECT * FROM " . $views_table . " WHERE " . $where; $request .= " ORDER BY post_date DESC"; $result = $xoopsDB->query($request, $limit, $offset); while ($myrow = $xoopsDB->fetchArray($result)) { if ($myrow['post_type'] !== 'revision' && $myrow['post_type'] !== 'nav_menu_item') { switch ($myrow['post_type']) { case 'page': $ret[$i]['link'] = $mid_url . '?page_id=' . $myrow['ID']; break; case 'post': case '': $ret[$i]['link'] = $mid_url . '?p=' . $myrow['ID']; break; default: $ret[$i]['link'] = $mid_url . '?' . $myrow['post_type'] . '=' . $myrow['post_name']; } } $ret[$i]['title'] = $blog_name . $myts->htmlSpecialChars($myrow['post_title']); $date_str = $myrow['post_date']; $yyyy = substr($date_str, 0, 4); $mm = substr($date_str, 5, 2); $dd = substr($date_str, 8, 2); $hh = substr($date_str, 11, 2); $nn = substr($date_str, 14, 2); $ss = substr($date_str, 17, 2); $ret[$i]['time'] = mktime($hh, $nn, $ss, $mm, $dd, $yyyy); $ret[$i]['uid'] = wp_uid_to_xoops_uid($myrow['post_author'], $mydirname); $context = ''; $text = $myrow['post_content']; // get context for module "search" $showcontext = empty($_GET['showcontext']) ? 0 : 1; if (function_exists('search_make_context') && $showcontext) { if (function_exists('easiestml')) { $text = easiestml($text); } $full_context = strip_tags($text); $context = search_make_context($full_context, $queryarray); } $ret[$i]['context'] = $context; $i++; } } return $ret; }