Example #1
0
function cron_run($force = 0)
{
    global $conf, $time, $forumlist, $runtime;
    $cron_1_last_date = runtime_get('cron_1_last_date');
    $cron_2_last_date = runtime_get('cron_2_last_date');
    $t = $time - $cron_1_last_date;
    if ($t > 300 || $force) {
        $lock = cache_get('cron_lock_1');
        if ($lock === NULL) {
            cache_set('cron_lock_1', 1, 10);
            // 设置 10 秒超时
            // 清理在线
            online_gc();
            runtime_set('cron_1_last_date', $time);
            cache_delete('cron_lock_1');
        }
    }
    $t = $time - $cron_2_last_date;
    if ($t > 86400 || $force) {
        $lock = cache_get('cron_lock_2');
        // 高并发下, mysql 机制实现的锁锁不住,但是没关系
        if ($lock === NULL) {
            cache_set('cron_lock_2', 1, 10);
            // 设置 10 秒超时
            // 每日统计清 0
            runtime_set('todayposts', 0);
            runtime_set('todaythreads', 0);
            runtime_set('todayusers', 0);
            foreach ($forumlist as $fid => $forum) {
                forum__update($fid, array('todayposts' => 0, 'todaythreads' => 0));
            }
            forum_list_cache_delete();
            // 清理最新发帖,只保留 100 条。
            thread_new_gc();
            thread_lastpid_gc();
            // 清理在线
            online_gc();
            // 清理临时附件
            attach_gc();
            // 清空每日 IP 限制
            ipaccess_truncate();
            // 清理游客喜欢限制
            guest_agree_truncate();
            list($y, $n, $d) = explode(' ', date('Y n j', $time));
            // 0 点
            $today = mktime(0, 0, 0, $n, $d, $y);
            // -8 hours
            runtime_set('cron_2_last_date', $today, TRUE);
            // 加到1天后
            // 每日生成最新的 sitemap
            thread_new_sitemap();
            // 往前推8个小时,尽量保证在前一天
            table_day_cron($time - 8 * 3600);
            cache_delete('cron_lock_2');
        }
    }
}
Example #2
0
function user_delete($uid)
{
    global $conf;
    // 清理用户资源
    $threadlist = mythread_find_by_uid($uid, 1, 1000);
    foreach ($threadlist as $thread) {
        thread_delete($thread['tid']);
    }
    $r = user__delete($uid);
    $conf['cache']['type'] != 'mysql' and cache_delete("user-{$uid}");
    // 全站统计
    runtime_set('users-', 1);
    return $r;
}
Example #3
0
function online_gc()
{
    global $time, $conf;
    $expiry = $time - $conf['online_hold_time'];
    $n = db_exec("DELETE FROM `bbs_online` WHERE last_date<'{$expiry}'");
    // 重新统计在线数, MyISAM count 快,InnoDB 慢。
    runtime_set('onlines', max(1, online_count()));
    // 清理缓存
    online_list_cache_delete();
}
Example #4
0
 public static function set($filename, $content)
 {
     //写入文件时,会将文件的创建时间放在内容的最前面
     return runtime_set($filename, time() . $content);
 }
Example #5
0
include './plugin/xn_qq_login/qq_login.func.php';
$user = user_token_get('', 'bbs');
$user['gid'] != 1 and message(-1, '需要管理员权限才能设置。');
// 检测浏览器
$browser = get__browser();
check_browser($browser);
$runtime = runtime_init();
if ($method == 'GET') {
    $qq = kv_get('qq_login');
    !isset($qq['enable']) && ($qq['enable'] = 0);
    !isset($qq['meta']) && ($qq['meta'] = '');
    !isset($qq['appid']) && ($qq['appid'] = '');
    !isset($qq['appkey']) && ($qq['appkey'] = '');
    $input['enable'] = form_radio_yes_no('enable', $qq['enable']);
    $input['meta'] = form_text('meta', htmlspecialchars($qq['meta']), 600);
    $input['appid'] = form_text('appid', $qq['appid'], 300);
    $input['appkey'] = form_text('appkey', $qq['appkey'], 300);
    $header = array();
    $header['title'] = 'QQ 登陆设置';
    include './plugin/xn_qq_login/setting.htm';
} else {
    $enable = param('enable', 0);
    $meta = param('meta', '', FALSE);
    $appid = param('appid');
    $appkey = param('appkey');
    $arr = array('enable' => $enable, 'meta' => $meta, 'appid' => $appid, 'appkey' => $appkey);
    kv_set('qq_login', $arr);
    // 此处会丢失
    runtime_set('qq_login_enable', $enable, TRUE);
    message(0, '设置成功!');
}
Example #6
0
function post_delete($pid)
{
    global $conf;
    $post = post_read_cache($pid);
    if (empty($post)) {
        return TRUE;
    }
    // 已经不存在了。
    $tid = $post['tid'];
    $uid = $post['uid'];
    $thread = thread_read_cache($tid);
    $fid = $thread['fid'];
    $r = post__delete($pid);
    if ($r === FALSE) {
        return FALSE;
    }
    !$post['isfirst'] and thread__update($tid, array('posts-' => 1));
    !$post['isfirst'] and $uid and user__update($uid, array('posts-' => 1));
    !$post['isfirst'] and runtime_set('posts-', 1);
    // 清理赞同
    $uid and myagree_delete($uid, $pid, $post['isfirst']);
    // 清理缓存
    $post['isfirst'] and post_list_cache_delete($tid);
    $post['images'] || $post['files'] and attach_delete_by_pid($pid);
    return $r;
}
function thread_delete($tid)
{
    global $conf;
    $thread = thread__read($tid);
    if (empty($thread)) {
        return TRUE;
    }
    $fid = $thread['fid'];
    $uid = $thread['uid'];
    $r = thread__delete($tid);
    if ($r === FALSE) {
        return FALSE;
    }
    // 删除所有回帖,同时更新 posts 统计数
    $n = post_delete_by_tid($tid);
    // 删除我的主题
    $uid and mythread_delete($uid, $tid);
    // 删除附件
    // 更新统计
    forum__update($fid, array('threads-' => 1));
    user__update($uid, array('threads-' => 1));
    // 删除 SEO URL
    thread_url_delete($tid);
    // 全站统计
    runtime_set('threads-', 1);
    // 清除相关缓存
    thread_tids_cache_delete($fid);
    forum_list_cache_delete();
    // 最新和置顶也清理
    thread_new_delete($tid);
    thread_top_delete($tid);
    thread_lastpid_delete($tid);
    thread_new_cache_delete();
    thread_top_cache_delete();
    thread_lastpid_cache_delete();
    return $r;
}
function qq_login_create_user($username, $avatar_url_2, $openid)
{
    global $conf, $time, $longip;
    $arr = qq_login_read_user_by_openid($openid);
    if ($arr) {
        return xn_error(-2, '已经注册');
    }
    // 自动产生一个用户名
    $r = user_read_by_username($username);
    if ($r) {
        $username = $username . '_' . $time;
        $r = user_read_by_username($username);
        if ($r) {
            return xn_error(-1, '用户名被占用。');
        }
    }
    // 自动产生一个 Email
    $email = "qq_{$time}@qq.com";
    $r = user_read_by_email($email);
    if ($r) {
        return xn_error(-1, 'Email 被占用');
    }
    // 随机密码
    $password = md5(rand(1000000000, 9999999999) . $time);
    $user = array('username' => $username, 'email' => $email, 'password' => $password, 'gid' => 101, 'salt' => rand(100000, 999999), 'create_date' => $time, 'create_ip' => $longip, 'avatar' => 0, 'logins' => 1, 'login_date' => $time, 'login_ip' => $longip);
    $uid = user_create($user);
    if (empty($uid)) {
        return xn_error(-1, '注册失败');
    }
    $user = user_read($uid);
    $r = db_exec("INSERT INTO bbs_user_open_plat SET uid='{$uid}', platid='1', openid='{$openid}'");
    if (empty($uid)) {
        return xn_error(-1, '注册失败');
    }
    runtime_set('users+', '1');
    runtime_set('todayusers+', '1');
    // 头像不重要,忽略错误。
    if ($avatar_url_2) {
        $filename = "{$uid}.png";
        $dir = substr(sprintf("%09d", $uid), 0, 3) . '/';
        $path = $conf['upload_path'] . 'avatar/' . $dir;
        !is_dir($path) and mkdir($path, 0777, TRUE);
        $data = file_get_contents($avatar_url_2);
        file_put_contents($path . $filename, $data);
        user_update($uid, array('avatar' => $time));
    }
    return $user;
}
Example #9
0
<?php

!defined('DEBUG') and exit('Access Denied.');
$action = param(1);
if ($action == 'clear') {
    if ($method == 'GET') {
        $header['title'] = '清理缓存';
        include "./admin/view/cache_clear.htm";
    } elseif ($method == 'POST') {
        $old = $runtime;
        $clearcache = param('clearcache', 0);
        $clearcache and $r = cache_truncate();
        // 清空缓存会导致今日发帖丢失
        runtime_init();
        runtime_set('todayposts', $old['todayposts']);
        runtime_set('todayusers', $old['todayusers']);
        runtime_set('todaythreads', $old['todaythreads']);
        $rebuildmaxid = param('rebuildmaxid', 0);
        if ($rebuildmaxid) {
            @ignore_user_abort(TRUE);
            @set_time_limit(0);
            table_day_rebuild();
        }
        thread_new_sitemap();
        message(0, '清理成功');
    }
} elseif ($action == 'maxid') {
}