Advertisement
slek_12000

viewforum.php

Oct 9th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.93 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10.  
  11. /**
  12. * @ignore
  13. */
  14. define('IN_PHPBB', true);
  15. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  16. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  17. include($phpbb_root_path . 'common.' . $phpEx);
  18. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  19.  
  20. // Start session
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23.  
  24. // Start initial var setup
  25. $forum_id = request_var('f', 0);
  26. $mark_read = request_var('mark', '');
  27. $start = request_var('start', 0);
  28.  
  29. $default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
  30. $default_sort_key = (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't';
  31. $default_sort_dir = (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd';
  32.  
  33. $sort_days = request_var('st', $default_sort_days);
  34. $sort_key = request_var('sk', $default_sort_key);
  35. $sort_dir = request_var('sd', $default_sort_dir);
  36.  
  37. // Check if the user has actually sent a forum ID with his/her request
  38. // If not give them a nice error page.
  39. if (!$forum_id)
  40. {
  41. trigger_error('NO_FORUM');
  42. }
  43.  
  44. $sql_from = FORUMS_TABLE . ' f';
  45. $lastread_select = '';
  46.  
  47. // Grab appropriate forum data
  48. if ($config['load_db_lastread'] && $user->data['is_registered'])
  49. {
  50. $sql_from .= ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
  51. AND ft.forum_id = f.forum_id)';
  52. $lastread_select .= ', ft.mark_time';
  53. }
  54.  
  55. if ($user->data['is_registered'])
  56. {
  57. $sql_from .= ' LEFT JOIN ' . FORUMS_WATCH_TABLE . ' fw ON (fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'] . ')';
  58. $lastread_select .= ', fw.notify_status';
  59. }
  60.  
  61. $sql = "SELECT f.* $lastread_select
  62. FROM $sql_from
  63. WHERE f.forum_id = $forum_id";
  64. $result = $db->sql_query($sql);
  65. $forum_data = $db->sql_fetchrow($result);
  66. $db->sql_freeresult($result);
  67.  
  68. if (!$forum_data)
  69. {
  70. trigger_error('NO_FORUM');
  71. }
  72.  
  73.  
  74. // Configure style, language, etc.
  75. $user->setup('viewforum', $forum_data['forum_style']);
  76.  
  77. // Redirect to login upon emailed notification links
  78. if (isset($_GET['e']) && !$user->data['is_registered'])
  79. {
  80. login_box('', $user->lang['LOGIN_NOTIFY_FORUM']);
  81. }
  82.  
  83. // Permissions check
  84. if (!$auth->acl_gets('f_list', 'f_read', $forum_id) || ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'] && !$auth->acl_get('f_read', $forum_id)))
  85. {
  86. if ($user->data['user_id'] != ANONYMOUS)
  87. {
  88. trigger_error('SORRY_AUTH_READ');
  89. }
  90.  
  91. login_box('', $user->lang['LOGIN_VIEWFORUM']);
  92. }
  93.  
  94. // Forum is passworded ... check whether access has been granted to this
  95. // user this session, if not show login box
  96. if ($forum_data['forum_password'])
  97. {
  98. login_forum_box($forum_data);
  99. }
  100.  
  101. // Is this forum a link? ... User got here either because the
  102. // number of clicks is being tracked or they guessed the id
  103. if ($forum_data['forum_type'] == FORUM_LINK && $forum_data['forum_link'])
  104. {
  105. // Does it have click tracking enabled?
  106. if ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK)
  107. {
  108. $sql = 'UPDATE ' . FORUMS_TABLE . '
  109. SET forum_posts = forum_posts + 1
  110. WHERE forum_id = ' . $forum_id;
  111. $db->sql_query($sql);
  112. }
  113.  
  114. // We redirect to the url. The third parameter indicates that external redirects are allowed.
  115. redirect($forum_data['forum_link'], false, true);
  116. return;
  117. }
  118.  
  119. // Build navigation links
  120. generate_forum_nav($forum_data);
  121.  
  122. // Forum Rules
  123. if ($auth->acl_get('f_read', $forum_id))
  124. {
  125. generate_forum_rules($forum_data);
  126. }
  127.  
  128. // Do we have subforums?
  129. $active_forum_ary = $moderators = array();
  130.  
  131. if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
  132. {
  133. list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
  134. }
  135. else
  136. {
  137. $template->assign_var('S_HAS_SUBFORUM', false);
  138. if ($config['load_moderators'])
  139. {
  140. get_moderators($moderators, $forum_id);
  141. }
  142. }
  143.  
  144. // Dump out the page header and load viewforum template
  145. page_header($user->lang['VIEW_FORUM'] . ' - ' . $forum_data['forum_name'], true, $forum_id);
  146.  
  147. $template->set_filenames(array(
  148. 'body' => 'viewforum_body.html')
  149. );
  150.  
  151. make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"), $forum_id);
  152.  
  153. $template->assign_vars(array(
  154. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
  155. ));
  156.  
  157. // Not postable forum or showing active topics?
  158. if (!($forum_data['forum_type'] == FORUM_POST || (($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) && $forum_data['forum_type'] == FORUM_CAT)))
  159. {
  160. page_footer();
  161. }
  162.  
  163. // Ok, if someone has only list-access, we only display the forum list.
  164. // We also make this circumstance available to the template in case we want to display a notice. ;)
  165. if (!$auth->acl_get('f_read', $forum_id))
  166. {
  167. $template->assign_vars(array(
  168. 'S_NO_READ_ACCESS' => true,
  169. ));
  170.  
  171. page_footer();
  172. }
  173.  
  174. // Handle marking posts
  175. if ($mark_read == 'topics')
  176. {
  177. $token = request_var('hash', '');
  178. if (check_link_hash($token, 'global'))
  179. {
  180. // Add 0 to forums array to mark global announcements correctly
  181. markread('topics', array($forum_id, 0));
  182. }
  183. $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
  184. meta_refresh(3, $redirect_url);
  185.  
  186. trigger_error($user->lang['TOPICS_MARKED'] . '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'));
  187. }
  188.  
  189. // Is a forum specific topic count required?
  190. if ($forum_data['forum_topics_per_page'])
  191. {
  192. $config['topics_per_page'] = $forum_data['forum_topics_per_page'];
  193. }
  194.  
  195. // Do the forum Prune thang - cron type job ...
  196. if ($forum_data['prune_next'] < time() && $forum_data['enable_prune'])
  197. {
  198. $template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=prune_forum&amp;f=' . $forum_id) . '" alt="cron" width="1" height="1" />');
  199. }
  200.  
  201. // Forum rules and subscription info
  202. $s_watching_forum = array(
  203. 'link' => '',
  204. 'title' => '',
  205. 'is_watching' => false,
  206. );
  207.  
  208. if (($config['email_enable'] || $config['jab_enable']) && $config['allow_forum_notify'] && $forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_subscribe', $forum_id) || $user->data['user_id'] == ANONYMOUS))
  209. {
  210. $notify_status = (isset($forum_data['notify_status'])) ? $forum_data['notify_status'] : NULL;
  211. watch_topic_forum('forum', $s_watching_forum, $user->data['user_id'], $forum_id, 0, $notify_status, $start, $forum_data['forum_name']);
  212. }
  213.  
  214. $s_forum_rules = '';
  215. gen_forum_auth_level('forum', $forum_id, $forum_data['forum_status']);
  216.  
  217. // Topic ordering options
  218. $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
  219.  
  220. $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
  221. $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
  222.  
  223. $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
  224. gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param, $default_sort_days, $default_sort_key, $default_sort_dir);
  225. //-- mod : quick title edition -------------------------------------------------
  226. //-- add
  227. $sort_attr = request_var('attr_id', 0);
  228. $qte->attr_sort($forum_id, $sort_attr);
  229. //-- fin mod : quick title edition ---------------------------------------------
  230. // Limit topics to certain time frame, obtain correct topic count
  231. // global announcements must not be counted, normal announcements have to
  232. // be counted, as forum_topics(_real) includes them
  233. if ($sort_days)
  234. {
  235. $min_post_time = time() - ($sort_days * 86400);
  236.  
  237. $sql = 'SELECT COUNT(topic_id) AS num_topics
  238. FROM ' . TOPICS_TABLE . "
  239. WHERE forum_id = $forum_id
  240. AND ((topic_type <> " . POST_GLOBAL . " AND topic_last_post_time >= $min_post_time)
  241. OR topic_type = " . POST_ANNOUNCE . ")
  242. " . (($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND topic_approved = 1');
  243. //-- mod : quick title edition -------------------------------------------------
  244. //-- add
  245. if ( $sort_attr )
  246. {
  247. $sql .= 'AND topic_attr_id = ' . (int) $sort_attr;
  248. }
  249. //-- fin mod : quick title edition ---------------------------------------------
  250. $result = $db->sql_query($sql);
  251. $topics_count = (int) $db->sql_fetchfield('num_topics');
  252. $db->sql_freeresult($result);
  253.  
  254. if (isset($_POST['sort']))
  255. {
  256. $start = 0;
  257. }
  258. $sql_limit_time = "AND t.topic_last_post_time >= $min_post_time";
  259.  
  260. // Make sure we have information about day selection ready
  261. $template->assign_var('S_SORT_DAYS', true);
  262. }
  263. //-- mod : quick title edition -------------------------------------------------
  264. //-- add
  265. else if ( $sort_attr )
  266. {
  267. $sql = 'SELECT COUNT(topic_id) AS num_topics
  268. FROM ' . TOPICS_TABLE . '
  269. WHERE forum_id = ' . (int) $forum_id . '
  270. AND ((topic_type <> ' . POST_GLOBAL . ' AND topic_attr_id = ' . (int) $sort_attr . ')
  271. OR topic_type = ' . POST_ANNOUNCE . ')';
  272. if ( !$auth->acl_get('m_approve', $forum_id) )
  273. {
  274. $sql .= 'AND topic_approved = 1';
  275. }
  276. $result = $db->sql_query($sql);
  277. $topics_count = (int) $db->sql_fetchfield('num_topics');
  278. $db->sql_freeresult($result);
  279.  
  280. if ( isset($_POST['sort']) )
  281. {
  282. $start = 0;
  283. }
  284.  
  285. $sql_limit_time = '';
  286. }
  287. //-- fin mod : quick title edition ---------------------------------------------
  288. else
  289. {
  290. $topics_count = ($auth->acl_get('m_approve', $forum_id)) ? $forum_data['forum_topics_real'] : $forum_data['forum_topics'];
  291. $sql_limit_time = '';
  292. }
  293.  
  294. // Make sure $start is set to the last page if it exceeds the amount
  295. if ($start < 0 || $start > $topics_count)
  296. {
  297. $start = ($start < 0) ? 0 : floor(($topics_count - 1) / $config['topics_per_page']) * $config['topics_per_page'];
  298. }
  299.  
  300. // Basic pagewide vars
  301. $post_alt = ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['FORUM_LOCKED'] : $user->lang['POST_NEW_TOPIC'];
  302.  
  303. // Display active topics?
  304. $s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  305.  
  306. $s_search_hidden_fields = array('fid' => array($forum_id));
  307. if ($_SID)
  308. {
  309. $s_search_hidden_fields['sid'] = $_SID;
  310. }
  311.  
  312. if (!empty($_EXTRA_URL))
  313. {
  314. foreach ($_EXTRA_URL as $url_param)
  315. {
  316. $url_param = explode('=', $url_param, 2);
  317. $s_search_hidden_fields[$url_param[0]] = $url_param[1];
  318. }
  319. }
  320.  
  321. $template->assign_vars(array(
  322. 'MODERATORS' => (!empty($moderators[$forum_id])) ? implode(', ', $moderators[$forum_id]) : '',
  323.  
  324. 'POST_IMG' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->img('button_topic_locked', $post_alt) : $user->img('button_topic_new', $post_alt),
  325. 'NEWEST_POST_IMG' => $user->img('icon_topic_newest', 'VIEW_NEWEST_POST'),
  326. 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  327. 'FOLDER_IMG' => $user->img('topic_read', 'NO_UNREAD_POSTS'),
  328. 'FOLDER_UNREAD_IMG' => $user->img('topic_unread', 'UNREAD_POSTS'),
  329. 'FOLDER_HOT_IMG' => $user->img('topic_read_hot', 'NO_UNREAD_POSTS_HOT'),
  330. 'FOLDER_HOT_UNREAD_IMG' => $user->img('topic_unread_hot', 'UNREAD_POSTS_HOT'),
  331. 'FOLDER_LOCKED_IMG' => $user->img('topic_read_locked', 'NO_UNREAD_POSTS_LOCKED'),
  332. 'FOLDER_LOCKED_UNREAD_IMG' => $user->img('topic_unread_locked', 'UNREAD_POSTS_LOCKED'),
  333. 'FOLDER_STICKY_IMG' => $user->img('sticky_read', 'POST_STICKY'),
  334. 'FOLDER_STICKY_UNREAD_IMG' => $user->img('sticky_unread', 'POST_STICKY'),
  335. 'FOLDER_ANNOUNCE_IMG' => $user->img('announce_read', 'POST_ANNOUNCEMENT'),
  336. 'FOLDER_ANNOUNCE_UNREAD_IMG'=> $user->img('announce_unread', 'POST_ANNOUNCEMENT'),
  337. 'FOLDER_MOVED_IMG' => $user->img('topic_moved', 'TOPIC_MOVED'),
  338. 'REPORTED_IMG' => $user->img('icon_topic_reported', 'TOPIC_REPORTED'),
  339. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPIC_UNAPPROVED'),
  340. 'GOTO_PAGE_IMG' => $user->img('icon_post_target', 'GOTO_PAGE'),
  341.  
  342. 'L_NO_TOPICS' => ($forum_data['forum_status'] == ITEM_LOCKED) ? $user->lang['POST_FORUM_LOCKED'] : $user->lang['NO_TOPICS'],
  343.  
  344. 'S_DISPLAY_POST_INFO' => ($forum_data['forum_type'] == FORUM_POST && ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS)) ? true : false,
  345.  
  346. 'S_IS_POSTABLE' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  347. 'S_USER_CAN_POST' => ($auth->acl_get('f_post', $forum_id)) ? true : false,
  348. 'S_DISPLAY_ACTIVE' => $s_display_active,
  349. 'S_SELECT_SORT_DIR' => $s_sort_dir,
  350. 'S_SELECT_SORT_KEY' => $s_sort_key,
  351. 'S_SELECT_SORT_DAYS' => $s_limit_days,
  352. 'S_TOPIC_ICONS' => ($s_display_active && sizeof($active_forum_ary)) ? max($active_forum_ary['enable_icons']) : (($forum_data['enable_icons']) ? true : false),
  353. 'S_WATCH_FORUM_LINK' => $s_watching_forum['link'],
  354. 'S_WATCH_FORUM_TITLE' => $s_watching_forum['title'],
  355. 'S_WATCHING_FORUM' => $s_watching_forum['is_watching'],
  356. 'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . (($start == 0) ? '' : "&amp;start=$start")),
  357. 'S_DISPLAY_SEARCHBOX' => ($auth->acl_get('u_search') && $auth->acl_get('f_search', $forum_id) && $config['load_search']) ? true : false,
  358. 'S_SEARCHBOX_ACTION' => append_sid("{$phpbb_root_path}search.$phpEx"),
  359. 'S_SEARCH_LOCAL_HIDDEN_FIELDS' => build_hidden_fields($s_search_hidden_fields),
  360. 'S_SINGLE_MODERATOR' => (!empty($moderators[$forum_id]) && sizeof($moderators[$forum_id]) > 1) ? false : true,
  361. 'S_IS_LOCKED' => ($forum_data['forum_status'] == ITEM_LOCKED) ? true : false,
  362. 'S_VIEWFORUM' => true,
  363.  
  364. 'U_MCP' => ($auth->acl_get('m_', $forum_id)) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "f=$forum_id&amp;i=main&amp;mode=forum_view", true, $user->session_id) : '',
  365. 'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&amp;f=' . $forum_id) : '',
  366. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '') . (($start == 0) ? '' : "&amp;start=$start")),
  367. 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&amp;f=$forum_id&amp;mark=topics") : '',
  368. ));
  369.  
  370. // Grab icons
  371. $icons = $cache->obtain_icons();
  372.  
  373. // Grab all topic data
  374. $rowset = $announcement_list = $topic_list = $global_announce_list = array();
  375.  
  376. $sql_array = array(
  377. 'SELECT' => 't.*',
  378. 'FROM' => array(
  379. TOPICS_TABLE => 't'
  380. ),
  381. 'LEFT_JOIN' => array(),
  382. );
  383.  
  384. $sql_approved = ($auth->acl_get('m_approve', $forum_id)) ? '' : 'AND t.topic_approved = 1';
  385.  
  386. if ($user->data['is_registered'])
  387. {
  388. if ($config['load_db_track'])
  389. {
  390. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_POSTED_TABLE => 'tp'), 'ON' => 'tp.topic_id = t.topic_id AND tp.user_id = ' . $user->data['user_id']);
  391. $sql_array['SELECT'] .= ', tp.topic_posted';
  392. }
  393.  
  394. if ($config['load_db_lastread'])
  395. {
  396. $sql_array['LEFT_JOIN'][] = array('FROM' => array(TOPICS_TRACK_TABLE => 'tt'), 'ON' => 'tt.topic_id = t.topic_id AND tt.user_id = ' . $user->data['user_id']);
  397. $sql_array['SELECT'] .= ', tt.mark_time';
  398.  
  399. if ($s_display_active && sizeof($active_forum_ary))
  400. {
  401. $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.forum_id = t.forum_id AND ft.user_id = ' . $user->data['user_id']);
  402. $sql_array['SELECT'] .= ', ft.mark_time AS forum_mark_time';
  403. }
  404. }
  405. }
  406.  
  407. if ($forum_data['forum_type'] == FORUM_POST)
  408. {
  409. // Obtain announcements ... removed sort ordering, sort by time in all cases
  410. $sql = $db->sql_build_query('SELECT', array(
  411. 'SELECT' => $sql_array['SELECT'],
  412. 'FROM' => $sql_array['FROM'],
  413. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  414.  
  415. 'WHERE' => 't.forum_id IN (' . $forum_id . ', 0)
  416. AND t.topic_type IN (' . POST_ANNOUNCE . ', ' . POST_GLOBAL . ')',
  417.  
  418. 'ORDER_BY' => 't.topic_time DESC',
  419. ));
  420. $result = $db->sql_query($sql);
  421.  
  422. while ($row = $db->sql_fetchrow($result))
  423. {
  424. if (!$row['topic_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
  425. {
  426. // Do not display announcements that are waiting for approval.
  427. continue;
  428. }
  429.  
  430. $rowset[$row['topic_id']] = $row;
  431. $announcement_list[] = $row['topic_id'];
  432.  
  433. if ($row['topic_type'] == POST_GLOBAL)
  434. {
  435. $global_announce_list[$row['topic_id']] = true;
  436. }
  437. else
  438. {
  439. $topics_count--;
  440. }
  441. }
  442. $db->sql_freeresult($result);
  443. }
  444.  
  445. // If the user is trying to reach late pages, start searching from the end
  446. $store_reverse = false;
  447. $sql_limit = $config['topics_per_page'];
  448. if ($start > $topics_count / 2)
  449. {
  450. $store_reverse = true;
  451.  
  452. if ($start + $config['topics_per_page'] > $topics_count)
  453. {
  454. $sql_limit = min($config['topics_per_page'], max(1, $topics_count - $start));
  455. }
  456.  
  457. // Select the sort order
  458. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'ASC' : 'DESC');
  459. $sql_start = max(0, $topics_count - $sql_limit - $start);
  460. }
  461. else
  462. {
  463. // Select the sort order
  464. $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
  465. $sql_start = $start;
  466. }
  467.  
  468. if ($forum_data['forum_type'] == FORUM_POST || !sizeof($active_forum_ary))
  469. {
  470. $sql_where = 't.forum_id = ' . $forum_id;
  471. }
  472. else if (empty($active_forum_ary['exclude_forum_id']))
  473. {
  474. $sql_where = $db->sql_in_set('t.forum_id', $active_forum_ary['forum_id']);
  475. }
  476. else
  477. {
  478. $get_forum_ids = array_diff($active_forum_ary['forum_id'], $active_forum_ary['exclude_forum_id']);
  479. $sql_where = (sizeof($get_forum_ids)) ? $db->sql_in_set('t.forum_id', $get_forum_ids) : 't.forum_id = ' . $forum_id;
  480. }
  481.  
  482. // Grab just the sorted topic ids
  483. $sql = 'SELECT t.topic_id
  484. FROM ' . TOPICS_TABLE . " t
  485. WHERE $sql_where
  486. AND t.topic_type IN (" . POST_NORMAL . ', ' . POST_STICKY . ")
  487. $sql_approved
  488. $sql_limit_time
  489. ORDER BY t.topic_type " . ((!$store_reverse) ? 'DESC' : 'ASC') . ', ' . $sql_sort_order;
  490. //-- mod : quick title edition -------------------------------------------------
  491. //-- add
  492. if ( $sort_attr )
  493. {
  494. $sql = str_replace($sql_where, $sql_where . ' AND t.topic_attr_id = ' . (int) $sort_attr, $sql);
  495. }
  496. //-- fin mod : quick title edition ---------------------------------------------
  497. $result = $db->sql_query_limit($sql, $sql_limit, $sql_start);
  498.  
  499. while ($row = $db->sql_fetchrow($result))
  500. {
  501. $topic_list[] = (int) $row['topic_id'];
  502. }
  503. $db->sql_freeresult($result);
  504.  
  505. // For storing shadow topics
  506. $shadow_topic_list = array();
  507.  
  508. if (sizeof($topic_list))
  509. {
  510. // SQL array for obtaining topics/stickies
  511. $sql_array = array(
  512. 'SELECT' => $sql_array['SELECT'],
  513. 'FROM' => $sql_array['FROM'],
  514. 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  515.  
  516. 'WHERE' => $db->sql_in_set('t.topic_id', $topic_list),
  517. );
  518.  
  519. // If store_reverse, then first obtain topics, then stickies, else the other way around...
  520. // Funnily enough you typically save one query if going from the last page to the middle (store_reverse) because
  521. // the number of stickies are not known
  522. $sql = $db->sql_build_query('SELECT', $sql_array);
  523. $result = $db->sql_query($sql);
  524.  
  525. while ($row = $db->sql_fetchrow($result))
  526. {
  527. if ($row['topic_status'] == ITEM_MOVED)
  528. {
  529. $shadow_topic_list[$row['topic_moved_id']] = $row['topic_id'];
  530. }
  531.  
  532. $rowset[$row['topic_id']] = $row;
  533. }
  534. $db->sql_freeresult($result);
  535. }
  536.  
  537. // If we have some shadow topics, update the rowset to reflect their topic information
  538. if (sizeof($shadow_topic_list))
  539. {
  540. $sql = 'SELECT *
  541. FROM ' . TOPICS_TABLE . '
  542. WHERE ' . $db->sql_in_set('topic_id', array_keys($shadow_topic_list));
  543. $result = $db->sql_query($sql);
  544.  
  545. while ($row = $db->sql_fetchrow($result))
  546. {
  547. $orig_topic_id = $shadow_topic_list[$row['topic_id']];
  548.  
  549. // If the shadow topic is already listed within the rowset (happens for active topics for example), then do not include it...
  550. if (isset($rowset[$row['topic_id']]))
  551. {
  552. // We need to remove any trace regarding this topic. :)
  553. unset($rowset[$orig_topic_id]);
  554. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  555. $topics_count--;
  556.  
  557. continue;
  558. }
  559.  
  560. // Do not include those topics the user has no permission to access
  561. if (!$auth->acl_get('f_read', $row['forum_id']))
  562. {
  563. // We need to remove any trace regarding this topic. :)
  564. unset($rowset[$orig_topic_id]);
  565. unset($topic_list[array_search($orig_topic_id, $topic_list)]);
  566. $topics_count--;
  567.  
  568. continue;
  569. }
  570.  
  571. // We want to retain some values
  572. $row = array_merge($row, array(
  573. 'topic_moved_id' => $rowset[$orig_topic_id]['topic_moved_id'],
  574. 'topic_status' => $rowset[$orig_topic_id]['topic_status'],
  575. 'topic_type' => $rowset[$orig_topic_id]['topic_type'],
  576. 'topic_title' => $rowset[$orig_topic_id]['topic_title'],
  577. ));
  578.  
  579. // Shadow topics are never reported
  580. $row['topic_reported'] = 0;
  581.  
  582. $rowset[$orig_topic_id] = $row;
  583. }
  584. $db->sql_freeresult($result);
  585. }
  586. unset($shadow_topic_list);
  587.  
  588. // Ok, adjust topics count for active topics list
  589. if ($s_display_active)
  590. {
  591. $topics_count = 1;
  592. }
  593.  
  594. // We need to readd the local announcements to the forums total topic count, otherwise the number is different from the one on the forum list
  595. //-- mod : quick title edition -------------------------------------------------
  596. //-- add
  597. if ( $sort_attr )
  598. {
  599. $u_sort_param .= (strlen($u_sort_param) ? '&amp;' : '') . 'attr_id=' . $sort_attr;
  600. }
  601. //-- fin mod : quick title edition ---------------------------------------------
  602. $total_topic_count = $topics_count + sizeof($announcement_list) - sizeof($global_announce_list);
  603.  
  604. $template->assign_vars(array(
  605. 'PAGINATION' => generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&amp;$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
  606. 'PAGE_NUMBER' => on_page($topics_count, $config['topics_per_page'], $start),
  607. 'TOTAL_TOPICS' => ($s_display_active) ? false : (($total_topic_count == 1) ? $user->lang['VIEW_FORUM_TOPIC'] : sprintf($user->lang['VIEW_FORUM_TOPICS'], $total_topic_count)))
  608. );
  609.  
  610. $topic_list = ($store_reverse) ? array_merge($announcement_list, array_reverse($topic_list)) : array_merge($announcement_list, $topic_list);
  611. $topic_tracking_info = $tracking_topics = array();
  612.  
  613. // Okay, lets dump out the page ...
  614. if (sizeof($topic_list))
  615. {
  616. $mark_forum_read = true;
  617. $mark_time_forum = 0;
  618.  
  619. // Active topics?
  620. if ($s_display_active && sizeof($active_forum_ary))
  621. {
  622. // Generate topic forum list...
  623. $topic_forum_list = array();
  624. foreach ($rowset as $t_id => $row)
  625. {
  626. $topic_forum_list[$row['forum_id']]['forum_mark_time'] = ($config['load_db_lastread'] && $user->data['is_registered'] && isset($row['forum_mark_time'])) ? $row['forum_mark_time'] : 0;
  627. $topic_forum_list[$row['forum_id']]['topics'][] = $t_id;
  628. }
  629.  
  630. if ($config['load_db_lastread'] && $user->data['is_registered'])
  631. {
  632. foreach ($topic_forum_list as $f_id => $topic_row)
  633. {
  634. $topic_tracking_info += get_topic_tracking($f_id, $topic_row['topics'], $rowset, array($f_id => $topic_row['forum_mark_time']), false);
  635. }
  636. }
  637. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  638. {
  639. foreach ($topic_forum_list as $f_id => $topic_row)
  640. {
  641. $topic_tracking_info += get_complete_topic_tracking($f_id, $topic_row['topics'], false);
  642. }
  643. }
  644.  
  645. unset($topic_forum_list);
  646. }
  647. else
  648. {
  649. if ($config['load_db_lastread'] && $user->data['is_registered'])
  650. {
  651. $topic_tracking_info = get_topic_tracking($forum_id, $topic_list, $rowset, array($forum_id => $forum_data['mark_time']), $global_announce_list);
  652. $mark_time_forum = (!empty($forum_data['mark_time'])) ? $forum_data['mark_time'] : $user->data['user_lastmark'];
  653. }
  654. else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  655. {
  656. $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_list, $global_announce_list);
  657.  
  658. if (!$user->data['is_registered'])
  659. {
  660. $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  661. }
  662. $mark_time_forum = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
  663. }
  664. }
  665. //-- mod : quick title edition -------------------------------------------------
  666. //-- add
  667. $qte->get_users_by_topic_id($topic_list);
  668. //-- fin mod : quick title edition ---------------------------------------------
  669. $s_type_switch = 0;
  670. foreach ($topic_list as $topic_id)
  671. {
  672. $row = &$rowset[$topic_id];
  673.  
  674. $topic_forum_id = ($row['forum_id']) ? (int) $row['forum_id'] : $forum_id;
  675.  
  676. // This will allow the style designer to output a different header
  677. // or even separate the list of announcements from sticky and normal topics
  678. $s_type_switch_test = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  679.  
  680. // Replies
  681. $replies = ($auth->acl_get('m_approve', $topic_forum_id)) ? $row['topic_replies_real'] : $row['topic_replies'];
  682.  
  683. if ($row['topic_status'] == ITEM_MOVED)
  684. {
  685. $topic_id = $row['topic_moved_id'];
  686. $unread_topic = false;
  687. }
  688. else
  689. {
  690. $unread_topic = (isset($topic_tracking_info[$topic_id]) && $row['topic_last_post_time'] > $topic_tracking_info[$topic_id]) ? true : false;
  691. }
  692.  
  693. // Get folder img, topic status/type related information
  694. $folder_img = $folder_alt = $topic_type = '';
  695. topic_status($row, $replies, $unread_topic, $folder_img, $folder_alt, $topic_type);
  696.  
  697. // Generate all the URIs ...
  698. $view_topic_url_params = 'f=' . $topic_forum_id . '&amp;t=' . $topic_id;
  699. $view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
  700.  
  701. $topic_unapproved = (!$row['topic_approved'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
  702. $posts_unapproved = ($row['topic_approved'] && $row['topic_replies'] < $row['topic_replies_real'] && $auth->acl_get('m_approve', $topic_forum_id)) ? true : false;
  703. $u_mcp_queue = ($topic_unapproved || $posts_unapproved) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=' . (($topic_unapproved) ? 'approve_details' : 'unapproved_posts') . "&amp;t=$topic_id", true, $user->session_id) : '';
  704.  
  705. // Send vars to template
  706. $template->assign_block_vars('topicrow', array(
  707. 'FORUM_ID' => $topic_forum_id,
  708. 'TOPIC_ID' => $topic_id,
  709. 'TOPIC_AUTHOR' => get_username_string('username', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  710. 'TOPIC_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  711. 'TOPIC_AUTHOR_FULL' => get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  712. 'FIRST_POST_TIME' => $user->format_date($row['topic_time']),
  713. 'LAST_POST_SUBJECT' => censor_text($row['topic_last_post_subject']),
  714. 'LAST_POST_TIME' => $user->format_date($row['topic_last_post_time']),
  715. 'LAST_VIEW_TIME' => $user->format_date($row['topic_last_view_time']),
  716. 'LAST_POST_AUTHOR' => get_username_string('username', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  717. 'LAST_POST_AUTHOR_COLOUR' => get_username_string('colour', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  718. 'LAST_POST_AUTHOR_FULL' => get_username_string('full', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  719.  
  720. 'PAGINATION' => topic_generate_pagination($replies, $view_topic_url),
  721. 'REPLIES' => $replies,
  722. 'VIEWS' => $row['topic_views'],
  723. 'TOPIC_TITLE' => censor_text($row['topic_title']),
  724. 'TOPIC_TYPE' => $topic_type,
  725.  
  726. 'TOPIC_FOLDER_IMG' => $user->img($folder_img, $folder_alt),
  727. 'TOPIC_FOLDER_IMG_SRC' => $user->img($folder_img, $folder_alt, false, '', 'src'),
  728. 'TOPIC_FOLDER_IMG_ALT' => $user->lang[$folder_alt],
  729. 'TOPIC_FOLDER_IMG_WIDTH'=> $user->img($folder_img, '', false, '', 'width'),
  730. 'TOPIC_FOLDER_IMG_HEIGHT' => $user->img($folder_img, '', false, '', 'height'),
  731.  
  732. 'TOPIC_ICON_IMG' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['img'] : '',
  733. 'TOPIC_ICON_IMG_WIDTH' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['width'] : '',
  734. 'TOPIC_ICON_IMG_HEIGHT' => (!empty($icons[$row['icon_id']])) ? $icons[$row['icon_id']]['height'] : '',
  735. 'ATTACH_ICON_IMG' => ($auth->acl_get('u_download') && $auth->acl_get('f_download', $topic_forum_id) && $row['topic_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
  736. 'UNAPPROVED_IMG' => ($topic_unapproved || $posts_unapproved) ? $user->img('icon_topic_unapproved', ($topic_unapproved) ? 'TOPIC_UNAPPROVED' : 'POSTS_UNAPPROVED') : '',
  737.  
  738. 'S_TOPIC_TYPE' => $row['topic_type'],
  739. 'S_USER_POSTED' => (isset($row['topic_posted']) && $row['topic_posted']) ? true : false,
  740. 'S_UNREAD_TOPIC' => $unread_topic,
  741. 'S_TOPIC_REPORTED' => (!empty($row['topic_reported']) && $auth->acl_get('m_report', $topic_forum_id)) ? true : false,
  742. 'S_TOPIC_UNAPPROVED' => $topic_unapproved,
  743. 'S_POSTS_UNAPPROVED' => $posts_unapproved,
  744. 'S_HAS_POLL' => ($row['poll_start']) ? true : false,
  745. 'S_POST_ANNOUNCE' => ($row['topic_type'] == POST_ANNOUNCE) ? true : false,
  746. 'S_POST_GLOBAL' => ($row['topic_type'] == POST_GLOBAL) ? true : false,
  747. 'S_POST_STICKY' => ($row['topic_type'] == POST_STICKY) ? true : false,
  748. 'S_TOPIC_LOCKED' => ($row['topic_status'] == ITEM_LOCKED) ? true : false,
  749. 'S_TOPIC_MOVED' => ($row['topic_status'] == ITEM_MOVED) ? true : false,
  750.  
  751. 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;view=unread') . '#unread',
  752. 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&amp;p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'],
  753. 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']),
  754. 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']),
  755. 'U_VIEW_TOPIC' => $view_topic_url,
  756. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=reports&amp;f=' . $topic_forum_id . '&amp;t=' . $topic_id, true, $user->session_id),
  757. 'U_MCP_QUEUE' => $u_mcp_queue,
  758.  
  759. 'S_TOPIC_TYPE_SWITCH' => ($s_type_switch == $s_type_switch_test) ? -1 : $s_type_switch_test)
  760. );
  761. //-- mod : quick title edition -------------------------------------------------
  762. //-- add
  763. if ( !empty($row['topic_attr_id']) )
  764. {
  765. $template->alter_block_array('topicrow', array(
  766. 'S_TOPIC_ATTR' => true,
  767. 'TOPIC_ATTRIBUTE' => $qte->attr_display($row['topic_attr_id'], $row['topic_attr_user'], $row['topic_attr_time']),
  768. ), true, 'change');
  769. }
  770. //-- fin mod : quick title edition ---------------------------------------------
  771. $s_type_switch = ($row['topic_type'] == POST_ANNOUNCE || $row['topic_type'] == POST_GLOBAL) ? 1 : 0;
  772.  
  773. if ($unread_topic)
  774. {
  775. $mark_forum_read = false;
  776. }
  777.  
  778. unset($rowset[$topic_id]);
  779. }
  780. }
  781.  
  782. // This is rather a fudge but it's the best I can think of without requiring information
  783. // on all topics (as we do in 2.0.x). It looks for unread or new topics, if it doesn't find
  784. // any it updates the forum last read cookie. This requires that the user visit the forum
  785. // after reading a topic
  786. if ($forum_data['forum_type'] == FORUM_POST && sizeof($topic_list) && $mark_forum_read)
  787. {
  788. update_forum_tracking_info($forum_id, $forum_data['forum_last_post_time'], false, $mark_time_forum);
  789. }
  790.  
  791. page_footer();
  792.  
  793. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement