Example #1
0
 /**
  * 取得帖子的信息
  * @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;
 }