Просмотр файла viewforum.php

Размер файла: 14.93Kb
  1. <?php
  2. /***************************************************************************
  3. * viewforum.php
  4. * -------------------
  5. * Разработка: phpBB Group.
  6. * Оптимизация под WAP: Гутник Игорь ( чел ).
  7. * 2009 год
  8. ***************************************************************************/
  9.  
  10. /***************************************************************************
  11. *
  12. * Эта версия phpBB-WAP является бесплатным
  13. * программным обеспечением и распространяется
  14. * в рамках лицензии GNU General Public License.
  15. * Автор модификации настоятельно не
  16. * рекомендует распрострянять её так, как
  17. * распространялась 5 версия мода.
  18. *
  19. ***************************************************************************/
  20.  
  21. define('IN_PHPBB', true);
  22. $phpbb_root_path = './';
  23. include($phpbb_root_path . 'extension.inc');
  24. include($phpbb_root_path . 'common.'.$phpEx);
  25.  
  26. if ( isset($HTTP_GET_VARS[POST_FORUM_URL]) || isset($HTTP_POST_VARS[POST_FORUM_URL]) )
  27. {
  28. $forum_id = ( isset($HTTP_GET_VARS[POST_FORUM_URL]) ) ? intval($HTTP_GET_VARS[POST_FORUM_URL]) : intval($HTTP_POST_VARS[POST_FORUM_URL]);
  29. }
  30. else if ( isset($HTTP_GET_VARS['forum']))
  31. {
  32. $forum_id = intval($HTTP_GET_VARS['forum']);
  33. }
  34. else
  35. {
  36. $forum_id = '';
  37. }
  38.  
  39. if ( isset($HTTP_GET_VARS['mark']) || isset($HTTP_POST_VARS['mark']) )
  40. {
  41. $mark_read = (isset($HTTP_POST_VARS['mark'])) ? $HTTP_POST_VARS['mark'] : $HTTP_GET_VARS['mark'];
  42. }
  43. else
  44. {
  45. $mark_read = '';
  46. }
  47.  
  48. if ( !empty($forum_id) )
  49. {
  50. $sql = "SELECT *
  51. FROM " . FORUMS_TABLE . "
  52. WHERE forum_id = $forum_id";
  53. if ( !($result = $db->sql_query($sql)) )
  54. {
  55. message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
  56. }
  57. }
  58. else
  59. {
  60. message_die(GENERAL_MESSAGE, 'Раздел, который вы выбрали, не существует');
  61. }
  62.  
  63. if ( !($forum_row = $db->sql_fetchrow($result)) )
  64. {
  65. message_die(GENERAL_MESSAGE, 'Раздел, который вы выбрали, не существует');
  66. }
  67.  
  68. $userdata = session_pagestart($user_ip, $forum_id);
  69. init_userprefs($userdata);
  70.  
  71. if ( isset($HTTP_POST_VARS['start1']) )
  72. {
  73. $start1 = abs(intval($HTTP_POST_VARS['start1']));
  74. $start = (($start1 - 1) * $board_config['topics_per_page']);
  75. } else {
  76. $start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;
  77. $start = ($start < 0) ? 0 : $start;
  78. }
  79.  
  80. $is_auth = array();
  81. $is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row);
  82.  
  83. if ( !$is_auth['auth_read'] || !$is_auth['auth_view'] )
  84. {
  85. if ( !$userdata['session_logged_in'] )
  86. {
  87. $redirect = POST_FORUM_URL . "=$forum_id" . ( ( isset($start) ) ? "&start=$start" : '' );
  88. redirect(append_sid("login.$phpEx?redirect=viewforum.$phpEx&$redirect", true));
  89. }
  90. $message = ( !$is_auth['auth_view'] ) ? $lang['Forum_not_exist'] : sprintf($lang['Sorry_auth_read'], $is_auth['auth_read_type']);
  91.  
  92. message_die(GENERAL_MESSAGE, $message);
  93. }
  94.  
  95. if ( $mark_read == 'topics' )
  96. {
  97. if ( $userdata['session_logged_in'] )
  98. {
  99. $sql = "SELECT MAX(post_time) AS last_post
  100. FROM " . POSTS_TABLE . "
  101. WHERE forum_id = $forum_id";
  102. if ( !($result = $db->sql_query($sql)) )
  103. {
  104. message_die(GENERAL_ERROR, 'Could not obtain forums information', '', __LINE__, __FILE__, $sql);
  105. }
  106.  
  107. if ( $row = $db->sql_fetchrow($result) )
  108. {
  109. $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : array();
  110. $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : array();
  111.  
  112. if ( ( count($tracking_forums) + count($tracking_topics) ) >= 150 && empty($tracking_forums[$forum_id]) )
  113. {
  114. asort($tracking_forums);
  115. unset($tracking_forums[key($tracking_forums)]);
  116. }
  117.  
  118. if ( $row['last_post'] > $userdata['user_lastvisit'] )
  119. {
  120. $tracking_forums[$forum_id] = time();
  121.  
  122. setcookie($board_config['cookie_name'] . '_f', serialize($tracking_forums), 0, $board_config['cookie_path'], $board_config['cookie_domain'], $board_config['cookie_secure']);
  123. }
  124. }
  125.  
  126. $template->assign_vars(array(
  127. 'META' => '<meta http-equiv="refresh" content="3;url=' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">')
  128. );
  129. }
  130.  
  131. $message = $lang['Topics_marked_read'] . '<br /><br />' . sprintf($lang['Click_return_forum'], '<a href="' . append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id") . '">', '</a> ');
  132. message_die(GENERAL_MESSAGE, $message);
  133. }
  134.  
  135. $tracking_topics = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_t']) : '';
  136. $tracking_forums = ( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) ) ? unserialize($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f']) : '';
  137.  
  138. if ( $is_auth['auth_mod'] && $board_config['prune_enable'] )
  139. {
  140. if ( $forum_row['prune_next'] < time() && $forum_row['prune_enable'] )
  141. {
  142. include($phpbb_root_path . 'includes/prune.'.$phpEx);
  143. require($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
  144. auto_prune($forum_id);
  145. }
  146. }
  147.  
  148. $sql = "SELECT u.user_id, u.username
  149. FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g, " . USERS_TABLE . " u
  150. WHERE aa.forum_id = $forum_id
  151. AND aa.auth_mod = " . TRUE . "
  152. AND g.group_single_user = 1
  153. AND ug.group_id = aa.group_id
  154. AND g.group_id = aa.group_id
  155. AND u.user_id = ug.user_id
  156. GROUP BY u.user_id, u.username
  157. ORDER BY u.user_id";
  158. if ( !($result = $db->sql_query($sql)) )
  159. {
  160. message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
  161. }
  162.  
  163. $moderators = array();
  164. while( $row = $db->sql_fetchrow($result) )
  165. {
  166. $moderators[] = '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . "=" . $row['user_id']) . '">' . $row['username'] . '</a>';
  167. }
  168.  
  169. $sql = "SELECT g.group_id, g.group_name
  170. FROM " . AUTH_ACCESS_TABLE . " aa, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
  171. WHERE aa.forum_id = $forum_id
  172. AND aa.auth_mod = " . TRUE . "
  173. AND g.group_single_user = 0
  174. AND g.group_type <> ". GROUP_HIDDEN ."
  175. AND ug.group_id = aa.group_id
  176. AND g.group_id = aa.group_id
  177. GROUP BY g.group_id, g.group_name
  178. ORDER BY g.group_id";
  179. if ( !($result = $db->sql_query($sql)) )
  180. {
  181. message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
  182. }
  183.  
  184. while( $row = $db->sql_fetchrow($result) )
  185. {
  186. $moderators[] = $row['group_name'];
  187. }
  188. $l_moderators = ( count($moderators) == 1 ) ? $lang['Moderator'] : $lang['Moderators'];
  189. $forum_moderators = ( count($moderators) ) ? implode(', ', $moderators) : $lang['None'];
  190. unset($moderators);
  191.  
  192. $previous_days = array(0, 1, 7, 14, 30, 90, 180, 364);
  193. $previous_days_text = array($lang['All_Topics'], $lang['1_Day'], $lang['7_Days'], $lang['2_Weeks'], $lang['1_Month'], $lang['3_Months'], $lang['6_Months'], $lang['1_Year']);
  194.  
  195. if ( !empty($HTTP_POST_VARS['topicdays']) || !empty($HTTP_GET_VARS['topicdays']) )
  196. {
  197. $topic_days = ( !empty($HTTP_POST_VARS['topicdays']) ) ? intval($HTTP_POST_VARS['topicdays']) : intval($HTTP_GET_VARS['topicdays']);
  198. $min_topic_time = time() - ($topic_days * 86400);
  199.  
  200. $sql = "SELECT COUNT(t.topic_id) AS forum_topics
  201. FROM " . TOPICS_TABLE . " t, " . POSTS_TABLE . " p
  202. WHERE t.forum_id = $forum_id
  203. AND p.post_id = t.topic_last_post_id
  204. AND p.post_time >= $min_topic_time";
  205.  
  206. if ( !($result = $db->sql_query($sql)) )
  207. {
  208. message_die(GENERAL_ERROR, 'Could not obtain limited topics count information', '', __LINE__, __FILE__, $sql);
  209. }
  210. $row = $db->sql_fetchrow($result);
  211.  
  212. $topics_count = ( $row['forum_topics'] ) ? $row['forum_topics'] : 1;
  213. $limit_topics_time = "AND p.post_time >= $min_topic_time";
  214.  
  215. if ( !empty($HTTP_POST_VARS['topicdays']) )
  216. {
  217. $start = 0;
  218. }
  219. }
  220. else
  221. {
  222. $topics_count = ( $forum_row['forum_topics'] ) ? $forum_row['forum_topics'] : 1;
  223.  
  224. $limit_topics_time = '';
  225. $topic_days = 0;
  226. }
  227.  
  228. $select_topic_days = '<select name="topicdays">';
  229. for($i = 0; $i < count($previous_days); $i++)
  230. {
  231. $selected = ($topic_days == $previous_days[$i]) ? ' selected="selected"' : '';
  232. $select_topic_days .= '<option value="' . $previous_days[$i] . '"' . $selected . '>' . $previous_days_text[$i] . '</option>';
  233. }
  234. $select_topic_days .= '</select>';
  235.  
  236. $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_time, p.post_username
  237. FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . USERS_TABLE . " u2
  238. WHERE t.forum_id = $forum_id
  239. AND t.topic_poster = u.user_id
  240. AND p.post_id = t.topic_last_post_id
  241. AND p.poster_id = u2.user_id
  242. AND t.topic_type = " . POST_ANNOUNCE . "
  243. ORDER BY t.topic_last_post_id DESC ";
  244. if ( !($result = $db->sql_query($sql)) )
  245. {
  246. message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
  247. }
  248.  
  249. $topic_rowset = array();
  250. $total_announcements = 0;
  251. while( $row = $db->sql_fetchrow($result) )
  252. {
  253. $topic_rowset[] = $row;
  254. $total_announcements++;
  255. }
  256.  
  257. $db->sql_freeresult($result);
  258.  
  259. $sql = "SELECT t.*, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
  260. FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u, " . POSTS_TABLE . " p, " . POSTS_TABLE . " p2, " . USERS_TABLE . " u2
  261. WHERE t.forum_id = $forum_id
  262. AND t.topic_poster = u.user_id
  263. AND p.post_id = t.topic_first_post_id
  264. AND p2.post_id = t.topic_last_post_id
  265. AND u2.user_id = p2.poster_id
  266. AND t.topic_type <> " . POST_ANNOUNCE . "
  267. $limit_topics_time
  268. ORDER BY t.topic_type DESC, t.topic_last_post_id DESC
  269. LIMIT $start, ".$board_config['topics_per_page'];
  270. if ( !($result = $db->sql_query($sql)) )
  271. {
  272. message_die(GENERAL_ERROR, 'Could not obtain topic information', '', __LINE__, __FILE__, $sql);
  273. }
  274.  
  275. $total_topics = 0;
  276. while( $row = $db->sql_fetchrow($result) )
  277. {
  278. $topic_rowset[] = $row;
  279. $total_topics++;
  280. }
  281.  
  282. $db->sql_freeresult($result);
  283.  
  284. $total_topics += $total_announcements;
  285.  
  286. $orig_word = array();
  287. $replacement_word = array();
  288. obtain_word_list($orig_word, $replacement_word);
  289.  
  290. $template->assign_vars(array(
  291. 'U_POST_NEW_TOPIC' => append_sid("posting.$phpEx?mode=newtopic&amp;" . POST_FORUM_URL . "=$forum_id"))
  292. );
  293.  
  294. if ( $is_auth['auth_mod'] )
  295. {
  296. $moder = sprintf($lang['Rules_moderate'], "<a href=\"modcp.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;start=" . $start . "&amp;sid=" . $userdata['session_id'] . '" class="buttom">', '</a><br/>');
  297. }
  298.  
  299. define('SHOW_ONLINE', true);
  300. $page_title = $forum_row['forum_name'];
  301. include($phpbb_root_path . 'includes/page_header.'.$phpEx);
  302.  
  303. $template->set_filenames(array(
  304. 'body' => 'viewforum_body.tpl')
  305. );
  306.  
  307. $template->assign_vars(array(
  308. 'FORUM_ID' => $forum_id,
  309. 'FORUM_NAME' => $forum_row['forum_name'],
  310. 'MODERATORS' => $forum_moderators,
  311. 'MODER' => $moder,
  312. 'L_POST_NEW_TOPIC' => ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['Post_new_topic'],
  313. 'U_VIEW_FORUM' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL ."=$forum_id"))
  314. );
  315.  
  316. if( $total_topics )
  317. {
  318. for($i = 0; $i < $total_topics; $i++)
  319. {
  320. $topic_id = $topic_rowset[$i]['topic_id'];
  321. $topic_title = ( count($orig_word) ) ? str_replace($orig_word, $replacement_word, $topic_rowset[$i]['topic_title']) : $topic_rowset[$i]['topic_title'];
  322. $replies = $topic_rowset[$i]['topic_replies'];
  323. $topic_type = $topic_rowset[$i]['topic_type'];
  324.  
  325. if( $topic_type == POST_ANNOUNCE )
  326. {
  327. $topic_type = '';
  328. }
  329. else if( $topic_type == POST_STICKY )
  330. {
  331. $topic_type = $lang['Topic_Sticky'];
  332. }
  333. else
  334. {
  335. $topic_type = '';
  336. }
  337.  
  338. if( $topic_rowset[$i]['topic_vote'] )
  339. {
  340. $topic_type .= $lang['Topic_Poll'];
  341. }
  342. if( $topic_rowset[$i]['topic_status'] == TOPIC_MOVED )
  343. {
  344. $topic_type = $lang['Topic_Moved'];
  345. $topic_id = $topic_rowset[$i]['topic_moved_id'];
  346. }
  347. else
  348. {
  349. if( $userdata['session_logged_in'] )
  350. {
  351. if( $topic_rowset[$i]['post_time'] > $userdata['user_lastvisit'] )
  352. {
  353. if( !empty($tracking_topics) || !empty($tracking_forums) || isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  354. {
  355. $unread_topics = true;
  356.  
  357. if( !empty($tracking_topics[$topic_id]) )
  358. {
  359. if( $tracking_topics[$topic_id] >= $topic_rowset[$i]['post_time'] )
  360. {
  361. $unread_topics = false;
  362. }
  363. }
  364.  
  365. if( !empty($tracking_forums[$forum_id]) )
  366. {
  367. if( $tracking_forums[$forum_id] >= $topic_rowset[$i]['post_time'] )
  368. {
  369. $unread_topics = false;
  370. }
  371. }
  372.  
  373. if( isset($HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all']) )
  374. {
  375. if( $HTTP_COOKIE_VARS[$board_config['cookie_name'] . '_f_all'] >= $topic_rowset[$i]['post_time'] )
  376. {
  377. $unread_topics = false;
  378. }
  379. }
  380.  
  381. if( $unread_topics )
  382. {
  383. $folder_alt = $lang['New_posts'];
  384. }
  385. else
  386. {
  387. $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED && !$topic_rowset[$i]['topic_type'] ) ? $lang['Topic_locked1'] : '';
  388. }
  389. }
  390. else
  391. {
  392. $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED && !$topic_rowset[$i]['topic_type'] ) ? '<b>' . $lang['Topic_locked1'] . '</b>' : $lang['New_posts'];
  393. }
  394. }
  395. else
  396. {
  397. $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED && !$topic_rowset[$i]['topic_type'] ) ? $lang['Topic_locked1'] : '';
  398. }
  399. }
  400. else
  401. {
  402. $folder_alt = ( $topic_rowset[$i]['topic_status'] == TOPIC_LOCKED && !$topic_rowset[$i]['topic_type'] ) ? $lang['Topic_locked1'] : '';
  403. }
  404. }
  405. $view_topic_url = append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id");
  406. $last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : $topic_rowset[$i]['user2'] ;
  407. $last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?" . POST_POST_URL . '=' . $topic_rowset[$i]['topic_last_post_id']) . '#' . $topic_rowset[$i]['topic_last_post_id'] . '">' . $lang['View_latest_post'] . '</a>';
  408.  
  409. $template->assign_block_vars('topicrow', array(
  410. 'REPLIES' => $replies,
  411. 'TOPIC_ATTACHMENT_IMG' => topic_attachment_image($topic_rowset[$i]['topic_attachment']),
  412. 'TOPIC_TITLE' => $topic_title,
  413. 'TOPIC_TYPE' => $topic_type,
  414. 'REPLIES' => $replies,
  415. 'LAST_POST_AUTHOR' => $last_post_author,
  416. 'LAST_POST_IMG' => $last_post_url,
  417. 'L_TOPIC_FOLDER_ALT' => $folder_alt,
  418. 'U_VIEW_TOPIC' => $view_topic_url)
  419. );
  420. }
  421.  
  422. $topics_count -= $total_announcements;
  423.  
  424. $template->assign_vars(array(
  425. 'PAGINATION' => generate_pagination("viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id&amp;topicdays=$topic_days", $topics_count, $board_config['topics_per_page'], $start),
  426. 'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $topics_count / $board_config['topics_per_page'] )))
  427. );
  428. }
  429. else
  430. {
  431. $no_topics_msg = ( $forum_row['forum_status'] == FORUM_LOCKED ) ? $lang['Forum_locked'] : $lang['No_topics_post_one'];
  432. $template->assign_vars(array(
  433. 'L_NO_TOPICS' => $no_topics_msg)
  434. );
  435.  
  436. $template->assign_block_vars('switch_no_topics', array() );
  437.  
  438. }
  439.  
  440. $template->pparse('body');
  441.  
  442. include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
  443.  
  444. ?>