function xpress_state($is_report = false) { global $xoopsModule; include dirname(__FILE__) . '/../wp-includes/version.php'; include_once dirname(__FILE__) . '/../include/general_functions.php'; $xoopsDB =& Database::getInstance(); $xp_prefix = $GLOBALS['xoopsModule']->getInfo('dirname'); $xp_prefix = preg_replace('/wordpress/', 'wp', $xp_prefix); $prefix = $xoopsDB->prefix($xp_prefix . '_'); $posts_tables = get_table_list($prefix, 'posts'); $blogname = array(); $count_article = array(); $count_author = array(); $count_category = array(); $array_index = 0; foreach ($posts_tables as $posts_table) { $sql = "SELECT COUNT(DISTINCT post_author) AS count_author, COUNT(*) AS count_article FROM " . $posts_table . " WHERE post_type = 'post' AND (post_status = 'publish' OR post_status = 'private')"; $result = $xoopsDB->query($sql); if ($myrow = $xoopsDB->fetchArray($result)) { $count_article[$array_index] = $myrow["count_article"]; $count_author[$array_index] = $myrow["count_author"]; } else { $count_article[$array_index] = 0; $count_author[$array_index] = 0; } $mid_prefix = get_multi_mid_prefix($prefix, 'posts', $posts_table); $sql = "SELECT option_value AS blogname FROM " . $prefix . $mid_prefix . "options" . " WHERE option_name = 'blogname'"; $result = $xoopsDB->query($sql); if ($myrow = $xoopsDB->fetchArray($result)) { $blogname[$array_index] = $myrow["blogname"]; } else { $blogname[$array_index] = 'none name'; } if ($wp_db_version < 6124) { $sql = "SELECT COUNT(*) AS count_category FROM " . $prefix . $mid_prefix . "categories"; } else { $sql = "SELECT COUNT(*) AS count_category FROM " . $prefix . $mid_prefix . "term_taxonomy" . " WHERE taxonomy = 'category'"; } $result = $xoopsDB->query($sql); if ($myrow = $xoopsDB->fetchArray($result)) { $count_category[$array_index] = $myrow["count_category"]; } else { $count_category[$array_index] = 0; } $array_index++; } for ($i = 0; $i < $array_index; $i++) { if ($is_report) { echo "******** " . $blogname[$i] . _AM_XP2_STATS . "********" . "<br />\n"; echo _AM_XP2_CATEGORIES . ": " . @$count_category[$i] . "<br />\n"; echo _AM_XP2_ARTICLES . ": " . $count_article[$i] . "<br />\n"; echo _AM_XP2_AUTHORS . ": " . $count_author[$i] . "<br />\n"; } else { echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . $blogname[$i] . _AM_XP2_STATS . "</legend>"; echo "<div style='padding: 8px;'>"; echo "<label>" . _AM_XP2_CATEGORIES . ":</label><text>" . @$count_category[$i]; echo "</text><br />"; echo "<label>" . _AM_XP2_ARTICLES . ":</label><text>" . $count_article[$i]; echo "</text><br />"; echo "<label>" . _AM_XP2_AUTHORS . ":</label><text>" . $count_author[$i]; echo "</text>"; echo "</div>"; echo '</legend>'; echo "</fieldset>"; } } }
function repair_user_meta_prefix() { global $xoops_db; // repair usermeta db $db_xpress_usermeta = get_wp_prefix() . 'usermeta'; $wp_prefix_only = get_wp_prefix_only(); $user_meta_prefix = get_wp_prefix(); $sql = "SELECT * FROM {$db_xpress_usermeta} WHERE meta_key LIKE '%_" . $wp_prefix_only . "%'"; $user_metas = $xoops_db->get_results($sql); if (!empty($user_metas)) { foreach ($user_metas as $user_meta) { if (strpos($user_meta->meta_key, $user_meta_prefix) === false) { $new_meta_key = ''; if (strpos($user_meta->meta_key, $wp_prefix_only . 'user_level')) { $new_meta_key = $user_meta_prefix . 'user_level'; } if (strpos($user_meta->meta_key, $wp_prefix_only . 'capabilities')) { $new_meta_key = $user_meta_prefix . 'capabilities'; } if (strpos($user_meta->meta_key, $wp_prefix_only . 'autosave_draft_ids')) { $new_meta_key = $user_meta_prefix . 'autosave_draft_ids'; } if (strpos($user_meta->meta_key, $wp_prefix_only . 'usersettings')) { if (strpos($user_meta->meta_key, $wp_prefix_only . 'usersettingstime')) { $new_meta_key = $user_meta_prefix . 'usersettingstime'; } else { $new_meta_key = $user_meta_prefix . 'usersettings'; } } if (!empty($new_meta_key)) { $repair_sql = "UPDATE {$db_xpress_usermeta} "; $repair_sql .= 'SET '; $repair_sql .= "meta_key = '{$new_meta_key}' "; $repair_sql .= "WHERE (umeta_id = {$user_meta->umeta_id} )"; $xoops_db->query($repair_sql); } } } } // repair option db user_roles include_once ABSPATH . '/include/general_functions.php'; $prefix = get_wp_prefix(); $option_tables = get_table_list($prefix, 'options'); if (!empty($option_tables)) { foreach ($option_tables as $option_table) { $mid_prefix = get_multi_mid_prefix($prefix, 'options', $option_table); $new_option_name = $prefix . $mid_prefix . 'user_roles'; $sql = "SELECT option_id , option_name FROM {$option_table} WHERE option_name LIKE '%_user_roles'"; $option = $xoops_db->get_row($sql); if ($option->option_name != $new_option_name) { $repair_sql = "UPDATE {$db_wp_option} "; $repair_sql .= 'SET '; $repair_sql .= "option_name = '{$new_option_name}' "; $repair_sql .= "WHERE (option_id = {$option->option_id} )"; $xoops_db->query($repair_sql); } } } }
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; }