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 attach_delete_by_pid($pid) { global $conf; $attachlist = attach_find_by_pid($pid); foreach ($attachlist as $attach) { $path = $conf['upload_path'] . 'attach/' . $attach['filename']; file_exists($path) and unlink($path); attach__delete($attach['aid']); } return count($attachlist); }
empty($thread) and message(-1, '主题不存在:' . $tid); $fid = $thread['fid']; $forum = forum_read($fid); empty($forum) and message(1, '板块不存在:' . $fid); $isfirst = $post['isfirst']; !forum_access_user($fid, $gid, 'allowpost') and message(-1, '您(' . $user['groupname'] . ')无权限在此版块回帖'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); !$allowupdate and !$post['allowupdate'] and message(-1, '无权编辑该贴'); if ($method == 'GET') { $forumlist_allowthread = forum_list_access_filter($forumlist, $gid, 'allowthread'); $forumarr = xn_json_encode(arrlist_key_values($forumlist_allowthread, 'fid', 'name')); $post['message'] = htmlspecialchars($post['message']); // 将未插入帖子的附件加入到末尾。 $attachlist = $imagelist = $filelist = array(); if ($post['images'] || $post['files']) { $attachlist = attach_find_by_pid($post['pid']); list($imagelist, $filelist) = attach_list_not_in_message($attachlist, $post['message']); $post['message'] .= post_attach_list_add($imagelist, $filelist); } check_standard_browser(); include './flarum/view/post_update.htm'; } elseif ($method == 'POST') { $subject = htmlspecialchars(param('subject', '', FALSE)); $message = param('message', '', FALSE); $seo_url = strtolower(param('seo_url')); empty($message) and message(2, '内容不能为空'); $gid != 1 and $message = xn_html_safe($message); mb_strlen($message, 'UTF-8') > 2048000 and message('内容太长'); $arr = array(); if ($isfirst) { $newfid = param('fid');
//$first['message'] = post_highlight_keyword($first['subject']); } $allowpost = forum_access_user($fid, $gid, 'allowpost') ? 1 : 0; $allowupdate = forum_access_mod($fid, $gid, 'allowupdate') ? 1 : 0; $allowdelete = forum_access_mod($fid, $gid, 'allowdelete') ? 1 : 0; forum_access_user($fid, $gid, 'allowread') or message(-1, '您所在的用户组无权访问该板块。'); // ajax 不需要以下数据 // threadlist $page = 1; $pagesize = $conf['pagesize']; $pages = pages("forum-{$fid}-{page}.htm", $forum['threads'], $page, $pagesize); $threadlist = thread_find(array('fid' => $fid), array('tid' => -1), $page = 1, $pagesize); $seo_url = $thread['seo_url']; // 模板需要 // 升级需要查找附件 $attachlist = $imagelist = $filelist = array(); if ($first['images'] || $first['files']) { $attachlist = attach_find_by_pid($first['pid']); list($imagelist, $filelist) = attach_list_not_in_message($attachlist, $first['message']); } thread_inc_views($tid); // 如果是大站,可以用单独的点击服务,减少 db 压力 $header['navs'][] = "<a href=\"forum-{$fid}.htm\">{$forum['name']}</a>"; $header['navs'][] = "<a href=\"{$thread['url']}\">{$thread['subject']}</a>"; if (!$group['allowviewip']) { unset($thread['userip']); unset($thread['sid']); } include './pc/view/thread.htm'; } }