function thread_new_gc()
{
    if (thread_new_count() > 100) {
        $threadlist = thread_new_find();
        thread_new_truncate();
        foreach ($threadlist as $v) {
            thread_new_create($v['tid']);
        }
    }
}
예제 #2
0
function thread_create($arr, &$pid)
{
    global $conf;
    $fid = $arr['fid'];
    $uid = $arr['uid'];
    $subject = $arr['subject'];
    $message = $arr['message'];
    $time = $arr['time'];
    $longip = $arr['longip'];
    $sid = empty($arr['sid']) ? '' : $arr['sid'];
    # 论坛帖子数据,一页显示,不分页。
    $post = array('tid' => 0, 'isfirst' => 1, 'uid' => $uid, 'create_date' => $time, 'userip' => $longip, 'sid' => $sid, 'message' => $message);
    $pid = post__create($post);
    if ($pid === FALSE) {
        return FALSE;
    }
    // empty($pid) AND message(1, '创建帖子失败');
    // 创建主题
    $thread = array('fid' => $fid, 'subject' => $subject, 'uid' => $uid, 'create_date' => $time, 'last_date' => $time, 'firstpid' => $pid, 'lastpid' => $pid, 'userip' => $longip);
    $tid = thread__create($thread);
    if ($tid === FALSE) {
        post__delete($pid);
        return FALSE;
    }
    // 板块总数+1, 用户发帖+1
    // 更新统计数据
    $uid and user__update($uid, array('threads+' => 1));
    forum__update($fid, array('threads+' => 1, 'todaythreads+' => 1));
    // 反过来关联
    post__update($pid, array('tid' => $tid), $tid);
    // 最新发帖
    thread_new_create($tid);
    // 我参与的发帖
    $uid and mythread_create($uid, $tid);
    // 更新附件
    $attachlist = attach_find_just_upload($uid);
    foreach ($attachlist as $k => $attach) {
        // 判断是否存在于内容中,不存在,则删除
        $url = $conf['upload_url'] . 'attach/' . $attach['filename'];
        $file = $conf['upload_path'] . 'attach/' . $attach['filename'];
        if (strpos($message, $url) === FALSE) {
            attach__delete($attach['aid']);
            is_file($file) and unlink($file);
            unset($attachlist[$k]);
        } else {
            attach__update($attach['aid'], array('tid' => $tid, 'pid' => $pid));
        }
    }
    $images = $files = 0;
    list($images, $files) = attach_images_files($attachlist);
    $images || $files and thread__update($tid, array('images' => $images, 'files' => $files));
    $images || $files and post__update($pid, array('images' => $images, 'files' => $files));
    // SEO URL
    isset($arr['seo_url']) and thread_url_create($tid, $arr['seo_url']);
    // 全站发帖数
    runtime_set('threads+', 1);
    runtime_set('todaythreads+', 1);
    // 清理缓存
    thread_tids_cache_delete($fid);
    thread_new_cache_delete();
    thread_lastpid_create($tid, $pid);
    thread_lastpid_cache_delete();
    // 更新板块信息。
    forum_list_cache_delete();
    return $tid;
}