/** * 取得帖子的信息 * @param: &$db * @param: $id * @param: $pre_page * @param: $offset_page * @return: $topic_array * @access: public * @static */ public static function getTopicInfo(&$db, $id, $pre_page = 10, $offset_page = 0) { /*{{{*/ $topic_array = array(); $topic_status = self::getTopicStatus($db, $id); //如果显示第一页,则必须给出主题 if ($offset_page == 0) { $sql = 'select title, express, author, content, post_date, is_edit, ' . ' edit_user, edit_time, subject_status, is_best, is_top from bbs_subject where id=?'; $sth = $db->Prepare($sql); $res = $db->Execute($sth, array($id)); $rows = $res->FetchRow(); $posttime = set_locale_time($rows['post_date']); $user_name = $rows['author']; $user_id = UserUtil::getUserId($db, $user_name); $user_header = UserUtil::getUserHeader($db, $user_id); $user_info = UserUtil::getUserInfo($db, $user_id); $register_date = $user_info['register_date']; $user_level = $user_info['user_level']; $user_address = $user_info['user_hometown']; $user_topic_number = $user_info['user_topic']; $user_sign = ConvertString($user_info['user_sign'], ROOT_URL, IMAGE_URL . 'express/'); $is_edit = 0; $edit_user = ''; $edit_time = ''; if ($rows['is_edit']) { $is_edit = 1; $edit_user = $rows['edit_user']; $edit_time = $rows['edit_time']; } $user_online = UserUtil::isOnline($db, $user_id); $user_can_be_edit = 0; if (!$_SESSION['user']['name']) { $user_can_be_edit = 0; } else { if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $temp_layout_id = self::getLayoutId($db, $id); $user_can_be_edit = UserUtil::isThisLayoutAdmin($db, $id, $temp_layout_id, $_SESSION['user']['name']); } } } } } //判断是否有附件 //如果有附件,则使用代码替换 $content = ''; if ($topic_status == 2) { $content = TU_TOPIC_WAS_LOCKED; } else { $content = $rows['content'] . self::haveAttach($db, $id); if ($is_edit) { $attach_string = TU_SUB_TITLE . $edit_user . TU_FROM . $edit_time . TU_EDIT; $content .= "\n\n" . $attach_string; } } $title = $rows['title']; $title = htmlspecialchars($title); if ($rows['is_best']) { $title = "<font color=red>[" . BEST_LABEL . "]</font>" . $title; } if ($rows['is_top']) { $title = "<font color=red>[" . TOP_LABEL . "]</font>" . $title; } $topic_array[] = array('id' => $id, 'posttime' => $posttime, 'sort_number' => 1, 'user_name' => $user_name, 'user_id' => $user_id, 'user_header' => $user_header, 'user_sign' => $user_sign, 'register_date' => $register_date, 'user_level' => $user_level, 'user_address' => $user_address, 'user_topic_number' => $user_topic_number, 'title' => $title, 'content' => ConvertString($content, ROOT_URL, IMAGE_URL . 'express/'), 'online' => $user_online, 'can_be_edit' => $user_can_be_edit, 'is_topic' => 1, 'express' => $rows['express']); $pre_page = $pre_page - 1; } else { if ($offset_page >= 1) { $offset_page = $offset_page - 1; } } //再查回复的帖子 $sql = 'select id, title, express,author, content, post_date, is_edit, edit_user, ' . ' edit_time, reply_status from bbs_reply where subject_id=? ' . ' order by id asc'; $res = $db->SelectLimit($sql, $pre_page, $offset_page, array($id)); while ($rows = $res->FetchRow()) { $posttime = set_locale_time($rows['post_date']); $sort_number = $sort_begin; $user_name = $rows['author']; $user_id = UserUtil::getUserId($db, $user_name); $user_header = UserUtil::getUserHeader($db, $user_id); $user_info = UserUtil::getUserInfo($db, $user_id); $register_date = $user_info['register_date']; $user_level = $user_info['user_level']; $user_address = $user_info['user_hometown']; $user_topic_number = $user_info['user_topic']; $user_sign = ConvertString($user_info['user_sign'], ROOT_URL, IMAGE_URL . 'express/'); $is_edit = 0; $edit_user = ''; $edit_time = ''; if ($rows['is_edit']) { $is_edit = 1; $edit_user = $rows['edit_user']; $edit_time = $rows['edit_time']; } $user_online = UserUtil::isOnline($db, $user_id); $user_can_be_edit = 0; if (!$_SESSION['user']['name']) { $user_can_be_edit = 0; } else { if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $temp_layout_id = self::getLayoutId($db, $id); $user_can_be_edit = UserUtil::isThisLayoutAdmin($db, $id, $temp_layout_id, $_SESSION['user']['name']); } } } } } $sort_number = self::getSortNumber($db, $id, $rows['id']); $content = ''; $had_closed = 0; if ($rows['reply_status']) { $had_closed = 1; } if ($rows['reply_status'] || $topic_status == 2) { //如果回帖状态被设定,则表示改帖被关闭或者屏蔽 $content = TU_TOPIC_WAS_LOCKED; } else { $content = $rows['content'] . self::haveReplyAttach($db, $rows['id']); if ($is_edit) { $attach_string = TU_SUB_TITLE . $edit_user . TU_FROM . $edit_time . TU_EDIT; $content .= "\n\n" . $attach_string; } } $title = htmlspecialchars($rows['title']); $topic_array[] = array('id' => $rows['id'], 'posttime' => $posttime, 'sort_number' => $sort_number, 'user_name' => $user_name, 'user_id' => $user_id, 'user_header' => $user_header, 'user_sign' => $user_sign, 'register_date' => $register_date, 'user_level' => $user_level, 'user_address' => $user_address, 'user_topic_number' => $user_topic_number, 'title' => $title, 'content' => ConvertString($content, ROOT_URL, IMAGE_URL . 'express/'), 'online' => $user_online, 'can_be_edit' => $user_can_be_edit, 'is_topic' => 0, 'express' => $rows['express'], 'had_closed' => $had_closed); } return $topic_array; }
/** * 运行本类 */ public function run() { /*{{{*/ $id = $this->getParameterFromGET('id'); $is_topic = $this->getParameterFromGET('topic'); $bbs_id = 0; //判断$id是否存在。 if ($is_topic == 1) { //如果等于1,则为主题 if (!TopicUtil::isExists($this->db, $id)) { $this->AlertAndBack(SE_TOPIC_ID_IS_NOT_EXISTS); return; } else { //如果存在,则判断用户是否有权利修改 $sql = 'select author, layout_id from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $user_name = $rows['author']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($this->db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($this->db, $id, $bbs_id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } } else { //$topic 为其他值,那么就是回帖,而不是主题 $sql = 'select author, subject_id, layout_id from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if (!$rows['author']) { $this->AlertAndBack(SE_TOPIC_ID_IS_NOT_EXISTS); return; } //如果存在, //则判断用户是否有权限 $user_name = $rows['author']; $subject_id = $rows['subject_id']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($this->db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($this->db, $subject_id, $bbs_id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } $smarty = $this->getSmarty(); if ($is_topic) { $smarty->assign('clone_title', SE_EDIT_TOPIC); } else { $smarty->assign('clone_title', SE_EDIT_REPLY); } //更新用户在本版的信息 LayoutUtil::updateOnlineUser($this->db, $bbs_id); //返回论坛上面的导行栏。 $nav_array = LayoutUtil::getParentLayoutInfo($this->db, $bbs_id); //导航栏 $smarty->assign('nav_array', $nav_array); //先删除已经不存在的用户 LayoutUtil::delNotExistsUser($this->db); //用户有权限了。 //则可以开始显示用户帖子的内容 $smarty->assign('id_edit', 1); $smarty->assign('is_topic', $is_topic); $smarty->assign('is_edit', 1); $smarty->assign('bbsid', $id); if ($is_topic == 1) { //如果$is_topic 等于1, 则为主题 $sql = 'select title, content, express from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sql, array($id)); $rows = $res->FetchRow(); $smarty->assign('temp_title', $rows['title']); $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; if (get_magic_quotes_gpc()) { $fck->Value = stripslashes($rows['content']); } else { $fck->Value = $rows['content']; } $smarty->assign('fck', $fck); $smarty->assign('temp_express', $rows['express']); //查询是否有附件 $sql = 'select subject_id, file_type from bbs_subject_attach where subject_id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if ($rows['subject_id']) { $filename = ROOT_URL . 'upload/attach/' . $rows['subject_id'] . $rows['file_type']; $smarty->assign('image_name', $filename); } } else { $sql = 'select title, content, express from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sql, array($id)); $rows = $res->FetchRow(); $smarty->assign('temp_title', $rows['title']); $fck = new FCKeditor("content"); $fck->BasePath = FCKEDITOR_BASEPATH; // $fck->Value = $rows['content']; if (get_magic_quotes_gpc()) { $fck->Value = stripslashes($rows['content']); } else { $fck->Value = $rows['content']; } $smarty->assign('fck', $fck); $smarty->assign('temp_express', $rows['express']); //查询是否有附件 $sql = 'select reply_id, file_type from bbs_reply_attach where reply_id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if ($rows['reply_id']) { $filename = ROOT_URL . 'upload/attach/reply/' . $rows['reply_id'] . $rows['file_type']; $smarty->assign('image_name', $filename); } } $smarty->display('topic.tmpl'); return; }
/** * 保存编辑后的帖子 * @param: NULL * @return: NULL * @access: public */ public function run() { //收集变量 $topic = $this->getParameterFromPOST('topic'); $id = $this->getParameterFromPOST('id'); $title = $this->getParameterFromPOST('title'); $content = $this->getParameterFromPOST('content'); $express = $this->getParameterFromPOST('express'); $delattach = $this->getParameterFromPOST('delattach'); if (!$title || strlen($title) <= 0) { $this->AlertAndBack(SE_TITLE_IS_EMPTY); return; } /* if ( strlen($title) > 140 ) { $this->AlertAndBack(SE_TITLE_TOO_LONG); return; }*/ if (!$content || strlen($content) <= 0) { $this->AlertAndBack(SE_CONTENT_IS_EMPTY); return; } //做出基本的判断/*{{{*/ if (!$id) { $this->AlertandBack(SE_NO_TOPIC_ID); return; } //找出这个帖子所在的版块的id, 作者。 $layout_id = 0; $author = ''; if ($topic) { //如果是主题 $sql = 'select layout_id, author from bbs_subject where id=?'; $sth = $this->db->prepare($sql); $res = $this->db->execute($sth, array($id)); $rows = $res->FetchRow(); $layout_id = $rows['layout_id']; $author = $rows['author']; } else { $sql = 'select layout_id, author from bbs_reply where id=?'; $sth = $this->db->prepare($sql); $res = $this->db->execute($sth, array($id)); $rows = $res->FetchRow(); $layout_id = $rows['layout_id']; $author = $rows['author']; } if (!$layout_id) { //保存的帖子根本不存在。 $this->AlertAndBlack(SE_TOPIC_IS_NOT_EXISTS); return; } //判断用户是否可以编辑 if ($topic) { //如果等于1,则为主题 //如果存在,则判断用户是否有权利修改 $sql = 'select author, layout_id from bbs_subject where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $user_name = $rows['author']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($db, $id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } else { //$topic 为其他值,那么就是回帖,而不是主题 $sql = 'select author, subject_id, layout_id from bbs_reply where id=?'; $sth = $this->db->Prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); if (!$rows['author']) { $this->AlertAndBack(SE_TOPIC_ID_IS_NOT_EXISTS); return; } //如果存在, //则判断用户是否有权限 $user_name = $rows['author']; $subject_id = $rows['subject_id']; $bbs_id = $rows['layout_id']; $user_can_be_edit = 0; if (strtolower($_SESSION['user']['name']) == strtolower($user_name)) { $user_can_be_edit = 1; } else { if (strtolower($_SESSION['user']['name']) != strtolower($user_name)) { //判断用户是否是这个版块的版主。 $dep = UserUtil::getUserDep($db, $_SESSION['user']['name']); if ($dep == 1 || $dep == 2) { $user_can_be_edit = 1; } else { if ($dep == 3) { $user_can_be_edit = UserUtil::isThisLayoutAdmin($db, $subject_id, $_SESSION['user']['name']); } } } } if (!$user_can_be_edit) { $this->AlertAndBack(SE_YOU_HAVE_NO_PRIVIATE); return; } } /*}}}*/ //判断做完了,则可以开始进行更新了。 //求现在的时间 $now = getNoFormateCurrentDate(); if ($topic) { $user_name = $_SESSION['user']['name']; $sql = 'update bbs_subject set title=?, content=?, express=?, is_edit=1, ' . ' edit_user=?, edit_time=? where id=?'; $sth = $this->db->prepare($sql); $this->db->execute($sth, array($title, $content, $express, $user_name, $now, $id)); if ($this->db->ErrorNo()) { $this->AlertAndBack($this->db->ErrorMsg()); return; } if ($delattach) { //删除这个附件 $sql = 'select file_type from bbs_subject_attach where subject_id=?'; $sth = $this->db->prepare($sql); $res = $this->db->execute($sth, array($id)); $rows = $res->FetchRow(); $file_type = $rows['file_type']; $del_sql = 'delete from bbs_subject_attach where subject_id=?'; $sth = $this->db->prepare($del_sql); $this->db->execute($sth, array($id)); //删除文件。 $filename = ROOT_PATH . 'upload/attach/' . $id . $file_type; unlink($filename); } } else { $user_name = $_SESSION['user']['name']; $sql = 'update bbs_reply set title=?, content=?, express=?, is_edit=1, ' . ' edit_user=?, edit_time=? where id=?'; $sth = $this->db->prepare($sql); $this->db->execute($sth, array($title, $content, $express, $user_name, $now, $id)); if ($this->db->ErrorNo()) { $this->AlertAndBack($this->db->ErrorMsg()); return; } if ($delattach) { //删除这个附件 $sql = 'select file_type from bbs_reply_attach where reply_id=?'; $sth = $this->db->prepare($sql); $res = $this->db->execute($sth, array($id)); $rows = $res->FetchRow(); $file_type = $rows['file_type']; $del_sql = 'delete from bbs_reply_attach where reply_id=?'; $sth = $this->db->prepare($del_sql); $this->db->execute($sth, array($id)); //删除文件。 $filename = ROOT_PATH . 'upload/attach/reply/' . $id . $file_type; unlink($filename); } } //编辑成功后,返回当时的页面 if ($topic) { //如果是主页 //则返回第一页 $this->TipsAndForward(SE_SAVE_EDIT_SUCCESS, 'index.php?module=bbs&action=viewtopic&id=' . $id); return; } else { //不是主题 //则是回复 //求这个回帖的位置所在的位置 $sql = 'select subject_id from bbs_reply where id=?'; $sth = $this->db->prepare($sql); $res = $this->db->Execute($sth, array($id)); $rows = $res->FetchRow(); $sort_number = TopicUtil::getSortNumber($this->db, $rows['subject_id'], $id); $page = ceil($sort_number / 10); //这里还有很多的工作需要做 $this->TipsAndForward(SE_SAVE_EDIT_SUCCESS, 'index.php?module=bbs&action=viewtopic&id=' . $rows['subject_id'] . '&page=' . $page . '#topic' . $sort_number); } }