示例#1
0
function post_update($pid, $arr, $tid = 0)
{
    global $conf;
    $post = post__read($pid);
    if (empty($post)) {
        return FALSE;
    }
    $tid = $post['tid'];
    $uid = $post['uid'];
    $isfirst = $post['isfirst'];
    $r = post__update($pid, $arr);
    post_list_cache_delete($tid);
    // 如果 message 发生了变化。
    if (isset($arr['message']) and $arr['message'] != $post['message']) {
        // 更新附件数
        $oldlist = attach_find_by_pid($pid);
        $newlist = attach_find_just_upload($uid);
        $attachlist = array_merge($oldlist, $newlist);
        foreach ($attachlist as $k => $attach) {
            $url = $conf['upload_url'] . 'attach/' . $attach['filename'];
            $file = $conf['upload_path'] . 'attach/' . $attach['filename'];
            if (strpos($arr['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));
            }
        }
        list($images, $files) = attach_images_files($attachlist);
        post__update($pid, array('images' => $images, 'files' => $files));
        thread__update($tid, array('images' => $images, 'files' => $files));
    }
    return $r;
}
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;
}