function rethestats($cachename = '')
{
    global $DB, $db_prefix;
    if (!$cachename || $cachename == 'settings') {
        settings_recache();
    }
    if (!$cachename || $cachename == 'statistics') {
        // 更新首页显示的文章数
        $article_count = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles WHERE visible = '1'"), 0);
        // 更新首页显示的评论数
        $comment_count = $DB->result($DB->query("SELECT COUNT(commentid) FROM {$db_prefix}comments c LEFT JOIN {$db_prefix}articles a ON (a.articleid=c.articleid) WHERE a.visible='1' AND c.visible='1'"), 0);
        // 更新首页显示的标签(Tags)数
        $tag_count = $DB->result($DB->query("SELECT COUNT(mid) FROM {$db_prefix}metas WHERE type='tag'"), 0);
        $DB->unbuffered_query("UPDATE {$db_prefix}statistics SET article_count='{$article_count}', comment_count='{$comment_count}', tag_count='{$tag_count}'");
        //$DB->unbuffered_query("DELETE FROM {$db_prefix}metas WHERE type='tag' AND count=0");
        // 更新主人发表文章数
        $query = $DB->query("SELECT userid,articles FROM {$db_prefix}users WHERE groupid='1' OR groupid='2'");
        while ($user = $DB->fetch_array($query)) {
            $total = $DB->result($DB->query("SELECT COUNT(articleid) FROM {$db_prefix}articles WHERE visible = '1' AND uid='" . $user['userid'] . "'"), 0);
            if ($user['articles'] != $total) {
                $DB->unbuffered_query("UPDATE {$db_prefix}users SET articles='{$total}' WHERE userid='" . $user['userid'] . "'");
            }
        }
        statistics_recache();
    }
    if (!$cachename || $cachename == 'newarticles') {
        newarticles_recache();
    }
    if (!$cachename || $cachename == 'stick') {
        stick_recache();
    }
    if (!$cachename || $cachename == 'newcomments') {
        newcomments_recache();
    }
    if (!$cachename || $cachename == 'categories') {
        // 更新所有文章的评论数
        $query = $DB->query("SELECT mid,count FROM {$db_prefix}metas");
        while ($meta = $DB->fetch_array($query)) {
            $ctotal = get_meta_article_count($meta['mid']);
            if ($meta['count'] != $ctotal) {
                update_meta_count($meta['mid'], $ctotal);
            }
        }
        categories_recache();
    }
    if (!$cachename || $cachename == 'archives') {
        // 重建文章数据
        $query = $DB->query("SELECT articleid,comments FROM {$db_prefix}articles");
        while ($article = $DB->fetch_array($query)) {
            // 更新所有文章的评论数
            $ctotal = $DB->result($DB->query("SELECT COUNT(commentid) FROM {$db_prefix}comments WHERE articleid='" . $article['articleid'] . "' AND visible='1'"), 0);
            if ($article['comments'] != $ctotal) {
                $DB->unbuffered_query("UPDATE {$db_prefix}articles SET comments='{$ctotal}' WHERE articleid='" . $article['articleid'] . "'");
            }
        }
        archives_recache();
    }
    if (!$cachename || $cachename == 'hottags') {
        hottags_recache();
    }
    if (!$cachename || $cachename == 'links') {
        links_recache();
    }
    if (!$cachename || $cachename == 'stylevars') {
        stylevars_recache();
    }
    if (!$cachename || $cachename == 'allarticleids') {
        allarticleids_recache();
    }
}
}
$settingsmenu = array('all' => '全部', 'basic' => '基本设置', 'display' => '显示设置', 'comment' => '评论设置', 'attach' => '附件设置', 'dateline' => '时间设置', 'seo' => 'SEO设置', 'wap' => 'WAP设置', 'ban' => '安全设置', 'rss' => 'RSS设置', 'permalink' => '伪静态设置');
!$action && ($action = 'basic');
// 更新配置以及配置文件
if ($_POST['action'] == 'updatesetting') {
    //$DB->query("TRUNCATE TABLE {$db_prefix}settings");
    foreach ($_POST['setting'] as $key => $val) {
        $DB->query("REPLACE INTO {$db_prefix}settings VALUES ('" . sax_addslashes($key) . "', '" . sax_addslashes($val) . "')");
    }
    if ($oldaction == 'all' || $oldaction == 'display') {
        newarticles_recache();
        archives_recache();
        hottags_recache();
    }
    if ($oldaction == 'all' || $oldaction == 'comment') {
        newcomments_recache();
    }
    settings_recache();
    $location = getlink('configurate', $oldaction, array('message' => 1));
    header("Location: {$location}");
    exit;
}
//end update
$query = $DB->query("SELECT * FROM {$db_prefix}settings");
while ($setting = $DB->fetch_array($query)) {
    $settings[$setting['title']] = htmlspecialchars($setting['value']);
}
ifchecked($settings['show_calendar'], 'show_calendar');
ifchecked($settings['show_statistics'], 'show_statistics');
ifchecked($settings['show_debug'], 'show_debug');
ifchecked($settings['show_n_p_title'], 'show_n_p_title');
function restats()
{
    allarticleids_recache();
    links_recache();
    newarticles_recache();
    newcomments_recache();
    settings_recache();
    categories_recache();
    statistics_recache();
    archives_recache();
    hottags_recache();
    stylevars_recache();
    stick_recache();
}