/** * 判断有无新回复 * @param: &$db, * @param: $id * @return: boolan * @access: public * @static */ public static function haveNewReply(&$db, $id, $user_id) { /*{{{*/ //求用户最后访问的时间 //$user_name = UserUtil::getUserNameById($db, $user_id); $last_time = UserUtil::getUserLastLogoutTime($db, $user_id); $sql = 'select last_access_date from bbs_subject where id=?'; $sth = $db->Prepare($sql); $res = $db->Execute($sth, array($id)); $rows = $res->FetchRow(); $temp_time = $rows['last_access_date']; if ($temp_time >= $last_time) { return TRUE; } else { return FALSE; } }
/** * 显示版面的情况 * @param: NULL * @return: NULL * @access: public */ public function run() { //取得用户的id $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']); $smarty = $this->getSmarty(); //取得站点的公告,并显示在页面上 $is_have_post = false; $post_str = ''; if (PostUtil::haveNotExpirePost($this->getDB())) { $is_have_post = true; $post_array = PostUtil::getPost($this->getDB(), 3); foreach ($post_array as $post_rows) { $post_str .= '<a href=\'index.php?module=post&action=view&id=' . $post_rows['id'] . '\' title=\'' . $post_rows['title'] . '\'>' . utf8_substr($post_rows['title'], 0, 35) . '</a>' . ' '; } } $smarty->assign('have_system_post', $is_have_post); $smarty->assign('post_str', $post_str); //公告显示结束 $q = $this->getParameterFromGET('q'); $encode_q = $q; //取得查询字符串 if (!$q) { //取得用户最后一次的动作时间 $last_time = UserUtil::getUserLastLogoutTime($this->db, $user_id); //生成一个where语句 $q = " where last_access_date >='" . $last_time . "'"; $encode_q = base64_encode($q); } else { $q = base64_decode($q); } $smarty->assign('encode_q', $encode_q); //生成所有的记录数 $sql = 'select count(*) as num from bbs_subject ' . $q; $res = $this->db->Execute($sql); $rows = $res->FetchRow(); $total_number = $rows['num']; //求总公的页面 $total_page = ceil($total_number / $this->page_number); //取得当前的页面 $page = $this->getParameter('page'); if (!$page || $page < 0) { $page = 1; } if ($page > $total_page && $total_page > 0) { $page = $total_page; } $begin_page = 1; $end_page = $total_page; if ($page <= 10 && $total_page >= 10) { $end_page = 10; } else { if ($page > 10) { if ($page % 10 == 0) { //向前翻 $end_page = $page; $begin_page = $end_page - 9; } else { if ($page % 10 == 1) { //向后翻 //确定开始的页数 $begin_page = $page; if ($begin_page > $total_page) { $begin_page = $page - 9; } if ($begin_page + 9 > $total_page) { $end_page = $total_page; } else { $end_page = $begin_page + 9; } } else { $num = $page % 10; $pre_num = floor($page / 10); $begin_page = $pre_num * 10 + 1; $end_page = $begin_page + 9; } } } } if ($end_page > $total_page) { $end_page = $total_page; } $nav_page_array = array(); for ($i = $begin_page; $i <= $end_page; $i++) { array_push($nav_page_array, $i); } //帖子导航栏 $smarty->assign('nav_page', $nav_page_array); //当前的页面 $smarty->assign('now_page', $page); //共有的页面 $smarty->assign('total_page', $total_page); //显示搜索结果 //求出偏移 $offset_number = ($page - 1) * $this->page_number; $subject_array = LayoutUtil::getCacheSubjectInfo($this->db, $this->page_number, $offset_number, $q); if ($total_page > 0) { $smarty->assign('subject', $subject_array); $smarty->assign('have_subject', 1); } $smarty->display('viewnew.tmpl'); }
/** * 判断论坛是否有新帖 * @param: &$db database references * @param: $user_name * @param: $sub_bbs_id 板块及子板块的ID数组 * @return: boolean * @access: public * @static */ public static function haveNewTopic(&$db, $user_name, &$sub_bbs_id) { /*{{{*/ /** * 求出最后时间后,需要我们找出当前子论坛下各个子论坛的id */ $user_id = UserUtil::getUserId($db, $user_name); $last_time = UserUtil::getUserLastLogoutTime($db, $user_id); $sql = 'select count(*) as num from bbs_subject where layout_id in (' . implode(',', $sub_bbs_id) . ') and last_access_date >= ? '; $sth = $db->Prepare($sql); $res = $db->Execute($sth, array($last_time)); $rows = $res->FetchRow(); if ($rows['num']) { return TRUE; } else { return FALSE; } }