PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/class/bbs/ViewNew.class.php

https://github.com/hylinux/ltebbs
PHP | 196 lines | 97 code | 46 blank | 53 comment | 23 complexity | edfeede52f64202a18c4cff796de1d46 MD5 | raw file
  1. <?php
  2. //vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
  3. /**
  4. * 项目: 5anet(BBS)
  5. * 文件: class/bbs/ViewNew.class.php
  6. *
  7. * 查看最新发表的帖子
  8. *
  9. * PHP Version 5
  10. *
  11. * @package: class.bbs
  12. * @author: Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
  13. * @license: http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  14. * @copyright: http://www.5anet.com
  15. * @version: $Id: ViewNew.class.php,v 1.2 2006-09-24 14:38:08 ghw Exp $
  16. * @date: $Date: 2006-09-24 14:38:08 $
  17. */
  18. include_once CLASS_PATH.'main/BaseAction.class.php';
  19. //包含需要用到的函数
  20. include_once FUNCTION_PATH.'utf8_substr.fun.php';
  21. include_once FUNCTION_PATH.'set_locale_time.fun.php';
  22. //包含需要用到的类
  23. include_once CLASS_PATH.'bbs/LayoutUtil.class.php';
  24. include_once CLASS_PATH.'user/UserUtil.class.php';
  25. class ViewNew extends BaseAction {
  26. /**
  27. * 数据库的连接
  28. */
  29. public $db;
  30. /**
  31. * 每一页显示帖子数
  32. */
  33. private $page_number = 25;
  34. /**
  35. * 构造函数
  36. * @param: NULL
  37. * @return: NULL
  38. * @access: public
  39. */
  40. public function __construct() {
  41. $this->db = $this->getCacheDB();
  42. }
  43. /**
  44. * 显示版面的情况
  45. * @param: NULL
  46. * @return: NULL
  47. * @access: public
  48. */
  49. public function run() {
  50. //取得用户的id
  51. $user_id = UserUtil::getUserId($this->db, $_SESSION['user']['name']);
  52. $smarty = $this->getSmarty();
  53. //取得站点的公告,并显示在页面上
  54. $is_have_post = false;
  55. $post_str = '';
  56. if ( PostUtil::haveNotExpirePost($this->getDB()) ) {
  57. $is_have_post = true;
  58. $post_array = PostUtil::getPost($this->getDB(), 3);
  59. foreach ( $post_array as $post_rows ) {
  60. $post_str .= '<a href=\'index.php?module=post&action=view&id='.
  61. $post_rows['id'].'\' title=\''.$post_rows['title'].'\'>'.
  62. utf8_substr($post_rows['title'], 0, 35).'</a>'.
  63. '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  64. }
  65. }
  66. $smarty->assign('have_system_post', $is_have_post);
  67. $smarty->assign('post_str', $post_str);
  68. //公告显示结束
  69. $q = $this->getParameterFromGET('q');
  70. $encode_q = $q;
  71. //取得查询字符串
  72. if ( !$q ) {
  73. //取得用户最后一次的动作时间
  74. $last_time = UserUtil::getUserLastLogoutTime($this->db, $user_id);
  75. //生成一个where语句
  76. $q = " where last_access_date >='".$last_time."'";
  77. $encode_q = base64_encode($q);
  78. } else {
  79. $q = base64_decode($q);
  80. }
  81. $smarty->assign('encode_q', $encode_q);
  82. //生成所有的记录数
  83. $sql = 'select count(*) as num from bbs_subject '.$q;
  84. $res = $this->db->Execute($sql);
  85. $rows = $res->FetchRow();
  86. $total_number = $rows['num'];
  87. //求总公的页面
  88. $total_page = ceil($total_number / $this->page_number );
  89. //取得当前的页面
  90. $page = $this->getParameter('page');
  91. if ( !$page || $page < 0 ) {
  92. $page = 1;
  93. }
  94. if ( $page > $total_page && $total_page > 0 ) {
  95. $page = $total_page;
  96. }
  97. $begin_page = 1;
  98. $end_page = $total_page;
  99. if ( $page <= 10 && $total_page >=10 ) {
  100. $end_page = 10;
  101. } else if ( $page > 10 ) {
  102. if ( $page % 10 == 0 ) {
  103. //向前翻
  104. $end_page = $page;
  105. $begin_page = $end_page - 9;
  106. } else if ( $page % 10 == 1 ) {
  107. //向后翻
  108. //确定开始的页数
  109. $begin_page = $page;
  110. if ( $begin_page > $total_page ) {
  111. $begin_page = $page - 9;
  112. }
  113. if ( ( $begin_page + 9 ) > $total_page ) {
  114. $end_page = $total_page;
  115. } else {
  116. $end_page = $begin_page + 9;
  117. }
  118. } else {
  119. $num = $page % 10;
  120. $pre_num = floor($page / 10 );
  121. $begin_page = $pre_num * 10 + 1;
  122. $end_page = $begin_page + 9;
  123. }
  124. }
  125. if ( $end_page > $total_page ) {
  126. $end_page = $total_page;
  127. }
  128. $nav_page_array = array();
  129. for( $i = $begin_page; $i<=$end_page; $i++ ) {
  130. array_push($nav_page_array, $i);
  131. }
  132. //帖子导航栏
  133. $smarty->assign('nav_page', $nav_page_array);
  134. //当前的页面
  135. $smarty->assign('now_page', $page);
  136. //共有的页面
  137. $smarty->assign('total_page', $total_page);
  138. //显示搜索结果
  139. //求出偏移
  140. $offset_number = ( $page - 1 ) * $this->page_number;
  141. $subject_array = LayoutUtil::getCacheSubjectInfo($this->db, $this->page_number,
  142. $offset_number, $q);
  143. if ( $total_page > 0 ) {
  144. $smarty->assign('subject', $subject_array);
  145. $smarty->assign('have_subject', 1);
  146. }
  147. $smarty->display('viewnew.tmpl');
  148. }
  149. }
  150. ?>