PageRenderTime 54ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/index.php

https://bitbucket.org/gencer/punbb
PHP | 348 lines | 239 code | 82 blank | 27 comment | 53 complexity | af30e5ab3449a595f5bd37fcd4bb6538 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Displays a list of the categories/forums that the current user can see, along with some statistics.
  4. *
  5. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  6. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  7. * @package PunBB
  8. */
  9. if (!defined('FORUM_ROOT'))
  10. define('FORUM_ROOT', './');
  11. require FORUM_ROOT.'include/common.php';
  12. ($hook = get_hook('in_start')) ? eval($hook) : null;
  13. if ($forum_user['g_read_board'] == '0')
  14. message($lang_common['No view']);
  15. // Load the index.php language file
  16. require FORUM_ROOT.'lang/'.$forum_user['language'].'/index.php';
  17. // Get list of forums and topics with new posts since last visit
  18. if (!$forum_user['is_guest'])
  19. {
  20. $query = array(
  21. 'SELECT' => 't.forum_id, t.id, t.last_post',
  22. 'FROM' => 'topics AS t',
  23. 'JOINS' => array(
  24. array(
  25. 'INNER JOIN' => 'forums AS f',
  26. 'ON' => 'f.id=t.forum_id'
  27. ),
  28. array(
  29. 'LEFT JOIN' => 'forum_perms AS fp',
  30. 'ON' => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
  31. )
  32. ),
  33. 'WHERE' => '(fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.$forum_user['last_visit'].' AND t.moved_to IS NULL'
  34. );
  35. ($hook = get_hook('in_qr_get_new_topics')) ? eval($hook) : null;
  36. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  37. $new_topics = array();
  38. while ($cur_topic = $forum_db->fetch_assoc($result))
  39. $new_topics[$cur_topic['forum_id']][$cur_topic['id']] = $cur_topic['last_post'];
  40. $tracked_topics = get_tracked_topics();
  41. }
  42. // Setup main heading
  43. $forum_page['main_title'] = forum_htmlencode($forum_config['o_board_title']);
  44. ($hook = get_hook('in_pre_header_load')) ? eval($hook) : null;
  45. define('FORUM_ALLOW_INDEX', 1);
  46. define('FORUM_PAGE', 'index');
  47. require FORUM_ROOT.'header.php';
  48. // START SUBST - <!-- forum_main -->
  49. ob_start();
  50. ($hook = get_hook('in_main_output_start')) ? eval($hook) : null;
  51. // Print the categories and forums
  52. $query = array(
  53. 'SELECT' => 'c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.forum_desc, f.redirect_url, f.moderators, f.num_topics, f.num_posts, f.last_post, f.last_post_id, f.last_poster',
  54. 'FROM' => 'categories AS c',
  55. 'JOINS' => array(
  56. array(
  57. 'INNER JOIN' => 'forums AS f',
  58. 'ON' => 'c.id=f.cat_id'
  59. ),
  60. array(
  61. 'LEFT JOIN' => 'forum_perms AS fp',
  62. 'ON' => '(fp.forum_id=f.id AND fp.group_id='.$forum_user['g_id'].')'
  63. )
  64. ),
  65. 'WHERE' => 'fp.read_forum IS NULL OR fp.read_forum=1',
  66. 'ORDER BY' => 'c.disp_position, c.id, f.disp_position'
  67. );
  68. ($hook = get_hook('in_qr_get_cats_and_forums')) ? eval($hook) : null;
  69. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  70. $forum_page['cur_category'] = $forum_page['cat_count'] = $forum_page['item_count'] = 0;
  71. while ($cur_forum = $forum_db->fetch_assoc($result))
  72. {
  73. ($hook = get_hook('in_forum_loop_start')) ? eval($hook) : null;
  74. ++$forum_page['item_count'];
  75. if ($cur_forum['cid'] != $forum_page['cur_category']) // A new category since last iteration?
  76. {
  77. if ($forum_page['cur_category'] != 0)
  78. echo "\t".'</div>'."\n";
  79. ++$forum_page['cat_count'];
  80. $forum_page['item_count'] = 1;
  81. $forum_page['item_header'] = array();
  82. $forum_page['item_header']['subject']['title'] = '<strong class="subject-title">'.$lang_index['Forums'].'</strong>';
  83. $forum_page['item_header']['info']['topics'] = '<strong class="info-topics">'.$lang_index['topics'].'</strong>';
  84. $forum_page['item_header']['info']['post'] = '<strong class="info-posts">'.$lang_index['posts'].'</strong>';
  85. $forum_page['item_header']['info']['lastpost'] = '<strong class="info-lastpost">'.$lang_index['last post'].'</strong>';
  86. ($hook = get_hook('in_forum_pre_cat_head')) ? eval($hook) : null;
  87. $forum_page['cur_category'] = $cur_forum['cid'];
  88. ?> <div class="main-head">
  89. <h2 class="hn"><span><?php echo forum_htmlencode($cur_forum['cat_name']) ?></span></h2>
  90. </div>
  91. <div class="main-subhead">
  92. <p class="item-summary"><span><?php printf($lang_index['Category subtitle'], implode(' ', $forum_page['item_header']['subject']), implode(', ', $forum_page['item_header']['info'])) ?></span></p>
  93. </div>
  94. <div id="category<?php echo $forum_page['cat_count'] ?>" class="main-content main-category">
  95. <?php
  96. }
  97. // Reset arrays and globals for each forum
  98. $forum_page['item_status'] = $forum_page['item_subject'] = $forum_page['item_body'] = $forum_page['item_title'] = array();
  99. // Is this a redirect forum?
  100. if ($cur_forum['redirect_url'] != '')
  101. {
  102. $forum_page['item_body']['subject']['title'] = '<h3 class="hn"><a class="external" href="'.forum_htmlencode($cur_forum['redirect_url']).'" title="'.sprintf($lang_index['Link to'], forum_htmlencode($cur_forum['redirect_url'])).'"><span>'.forum_htmlencode($cur_forum['forum_name']).'</span></a></h3>';
  103. $forum_page['item_status']['redirect'] = 'redirect';
  104. if ($cur_forum['forum_desc'] != '')
  105. $forum_page['item_subject']['desc'] = $cur_forum['forum_desc'];
  106. $forum_page['item_subject']['redirect'] = '<span>'.$lang_index['External forum'].'</span>';
  107. ($hook = get_hook('in_redirect_row_pre_item_subject_merge')) ? eval($hook) : null;
  108. if (!empty($forum_page['item_subject']))
  109. $forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
  110. // Forum topic and post count
  111. $forum_page['item_body']['info']['topics'] = '<li class="info-topics"><span class="label">'.$lang_index['No topic info'].'</span></li>';
  112. $forum_page['item_body']['info']['posts'] = '<li class="info-posts"><span class="label">'.$lang_index['No post info'].'</span></li>';
  113. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['No lastpost info'].'</span></li>';
  114. ($hook = get_hook('in_redirect_row_pre_display')) ? eval($hook) : null;
  115. }
  116. else
  117. {
  118. // Setup the title and link to the forum
  119. $forum_page['item_title']['title'] = '<a href="'.forum_link($forum_url['forum'], array($cur_forum['fid'], sef_friendly($cur_forum['forum_name']))).'"><span>'.forum_htmlencode($cur_forum['forum_name']).'</span></a>';
  120. // Are there new posts since our last visit?
  121. if (!$forum_user['is_guest'] && $cur_forum['last_post'] > $forum_user['last_visit'] && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_forum['fid']]))
  122. {
  123. // There are new posts in this forum, but have we read all of them already?
  124. foreach ($new_topics[$cur_forum['fid']] as $check_topic_id => $check_last_post)
  125. {
  126. if ((empty($tracked_topics['topics'][$check_topic_id]) || $tracked_topics['topics'][$check_topic_id] < $check_last_post) && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $tracked_topics['forums'][$cur_forum['fid']] < $check_last_post))
  127. {
  128. $forum_page['item_status']['new'] = 'new';
  129. $forum_page['item_title']['status'] = '<small>'.sprintf($lang_index['Forum has new'], '<a href="'.forum_link($forum_url['search_new_results'], $cur_forum['fid']).'" title="'.$lang_index['New posts title'].'">'.$lang_index['Forum new posts'].'</a>').'</small>';
  130. break;
  131. }
  132. }
  133. }
  134. ($hook = get_hook('in_normal_row_pre_item_title_merge')) ? eval($hook) : null;
  135. $forum_page['item_body']['subject']['title'] = '<h3 class="hn">'.implode(' ', $forum_page['item_title']).'</h3>';
  136. // Setup the forum description and mod list
  137. if ($cur_forum['forum_desc'] != '')
  138. $forum_page['item_subject']['desc'] = $cur_forum['forum_desc'];
  139. if ($forum_config['o_show_moderators'] == '1' && $cur_forum['moderators'] != '')
  140. {
  141. $forum_page['mods_array'] = unserialize($cur_forum['moderators']);
  142. $forum_page['item_mods'] = array();
  143. foreach ($forum_page['mods_array'] as $mod_username => $mod_id)
  144. $forum_page['item_mods'][] = ($forum_user['g_view_users'] == '1') ? '<a href="'.forum_link($forum_url['user'], $mod_id).'">'.forum_htmlencode($mod_username).'</a>' : forum_htmlencode($mod_username);
  145. ($hook = get_hook('in_row_modify_modlist')) ? eval($hook) : null;
  146. $forum_page['item_subject']['modlist'] = '<span class="modlist">'.sprintf($lang_index['Moderated by'], implode(', ', $forum_page['item_mods'])).'</span>';
  147. }
  148. ($hook = get_hook('in_normal_row_pre_item_subject_merge')) ? eval($hook) : null;
  149. if (!empty($forum_page['item_subject']))
  150. $forum_page['item_body']['subject']['desc'] = '<p>'.implode(' ', $forum_page['item_subject']).'</p>';
  151. // Setup forum topics, post count and last post
  152. $forum_page['item_body']['info']['topics'] = '<li class="info-topics"><strong>'.forum_number_format($cur_forum['num_topics']).'</strong> <span class="label">'.(($cur_forum['num_topics'] == 1) ? $lang_index['topic'] : $lang_index['topics']).'</span></li>';
  153. $forum_page['item_body']['info']['posts'] = '<li class="info-posts"><strong>'.forum_number_format($cur_forum['num_posts']).'</strong> <span class="label">'.(($cur_forum['num_posts'] == 1) ? $lang_index['post'] : $lang_index['posts']).'</span></li>';
  154. if ($cur_forum['last_post'] != '')
  155. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><span class="label">'.$lang_index['Last post'].'</span> <strong><a href="'.forum_link($forum_url['post'], $cur_forum['last_post_id']).'">'.format_time($cur_forum['last_post']).'</a></strong> <cite>'.sprintf($lang_index['Last poster'], forum_htmlencode($cur_forum['last_poster'])).'</cite></li>';
  156. else
  157. $forum_page['item_body']['info']['lastpost'] = '<li class="info-lastpost"><strong>'.$lang_common['Never'].'</strong></li>';
  158. ($hook = get_hook('in_normal_row_pre_display')) ? eval($hook) : null;
  159. }
  160. // Generate classes for this forum depending on its status
  161. $forum_page['item_style'] = (($forum_page['item_count'] % 2 != 0) ? ' odd' : ' even').(($forum_page['item_count'] == 1) ? ' main-first-item' : '').((!empty($forum_page['item_status'])) ? ' '.implode(' ', $forum_page['item_status']) : '');
  162. ($hook = get_hook('in_row_pre_display')) ? eval($hook) : null;
  163. ?> <div id="forum<?php echo $cur_forum['fid'] ?>" class="main-item<?php echo $forum_page['item_style'] ?>">
  164. <span class="icon <?php echo implode(' ', $forum_page['item_status']) ?>"><!-- --></span>
  165. <div class="item-subject">
  166. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['subject'])."\n" ?>
  167. </div>
  168. <ul class="item-info">
  169. <?php echo implode("\n\t\t\t\t", $forum_page['item_body']['info'])."\n" ?>
  170. </ul>
  171. </div>
  172. <?php
  173. }
  174. // Did we output any categories and forums?
  175. if ($forum_page['cur_category'] > 0)
  176. {
  177. ?> </div>
  178. <?php
  179. }
  180. else
  181. {
  182. ?> <div class="main-head">
  183. <h2 class="hn"><span><?php echo $lang_common['Forum message']?></span></h2>
  184. </div>
  185. <div class="main-content main-message">
  186. <p><?php echo $lang_index['Empty board'] ?></p>
  187. </div>
  188. <?php
  189. }
  190. ($hook = get_hook('in_end')) ? eval($hook) : null;
  191. $tpl_temp = forum_trim(ob_get_contents());
  192. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  193. ob_end_clean();
  194. // END SUBST - <!-- forum_main -->
  195. // START SUBST - <!-- forum_info -->
  196. ob_start();
  197. ($hook = get_hook('in_info_output_start')) ? eval($hook) : null;
  198. if (file_exists(FORUM_CACHE_DIR.'cache_stats.php'))
  199. include FORUM_CACHE_DIR.'cache_stats.php';
  200. // Regenerate cache only if the cache is more than 30 minutes old
  201. if (!defined('FORUM_STATS_LOADED') || $forum_stats['cached'] < (time() - 1800))
  202. {
  203. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  204. require FORUM_ROOT.'include/cache.php';
  205. generate_stats_cache();
  206. require FORUM_CACHE_DIR.'cache_stats.php';
  207. }
  208. $stats_list['no_of_users'] = '<li class="st-users"><span>'.sprintf($lang_index['No of users'], '<strong>'.forum_number_format($forum_stats['total_users']).'</strong>').'</span></li>';
  209. $stats_list['newest_user'] = '<li class="st-users"><span>'.sprintf($lang_index['Newest user'], '<strong>'.($forum_user['g_view_users'] == '1' ? '<a href="'.forum_link($forum_url['user'], $forum_stats['last_user']['id']).'">'.forum_htmlencode($forum_stats['last_user']['username']).'</a>' : forum_htmlencode($forum_stats['last_user']['username'])).'</strong>').'</span></li>';
  210. $stats_list['no_of_topics'] = '<li class="st-activity"><span>'.sprintf($lang_index['No of topics'], '<strong>'.forum_number_format($forum_stats['total_topics']).'</strong>').'</span></li>';
  211. $stats_list['no_of_posts'] = '<li class="st-activity"><span>'.sprintf($lang_index['No of posts'], '<strong>'.forum_number_format($forum_stats['total_posts']).'</strong>').'</span></li>';
  212. ($hook = get_hook('in_stats_pre_info_output')) ? eval($hook) : null;
  213. ?>
  214. <div id="brd-stats" class="gen-content">
  215. <h2 class="hn"><span><?php echo $lang_index['Statistics'] ?></span></h2>
  216. <ul>
  217. <?php echo implode("\n\t\t", $stats_list)."\n" ?>
  218. </ul>
  219. </div>
  220. <?php
  221. ($hook = get_hook('in_stats_end')) ? eval($hook) : null;
  222. ($hook = get_hook('in_users_online_start')) ? eval($hook) : null;
  223. if ($forum_config['o_users_online'] == '1')
  224. {
  225. // Fetch users online info and generate strings for output
  226. $query = array(
  227. 'SELECT' => 'o.user_id, o.ident',
  228. 'FROM' => 'online AS o',
  229. 'WHERE' => 'o.idle=0',
  230. 'ORDER BY' => 'o.ident'
  231. );
  232. ($hook = get_hook('in_users_online_qr_get_online_info')) ? eval($hook) : null;
  233. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  234. $forum_page['num_guests'] = $forum_page['num_users'] = 0;
  235. $users = array();
  236. while ($forum_user_online = $forum_db->fetch_assoc($result))
  237. {
  238. ($hook = get_hook('in_users_online_add_online_user_loop')) ? eval($hook) : null;
  239. if ($forum_user_online['user_id'] > 1)
  240. {
  241. $users[] = ($forum_user['g_view_users'] == '1') ? '<a href="'.forum_link($forum_url['user'], $forum_user_online['user_id']).'">'.forum_htmlencode($forum_user_online['ident']).'</a>' : forum_htmlencode($forum_user_online['ident']);
  242. ++$forum_page['num_users'];
  243. }
  244. else
  245. ++$forum_page['num_guests'];
  246. }
  247. $forum_page['online_info'] = array();
  248. $forum_page['online_info']['guests'] = ($forum_page['num_guests'] == 0) ? $lang_index['Guests none'] : sprintf((($forum_page['num_guests'] == 1) ? $lang_index['Guests single'] : $lang_index['Guests plural']), forum_number_format($forum_page['num_guests']));
  249. $forum_page['online_info']['users'] = ($forum_page['num_users'] == 0) ? $lang_index['Users none'] : sprintf((($forum_page['num_users'] == 1) ? $lang_index['Users single'] : $lang_index['Users plural']), forum_number_format($forum_page['num_users']));
  250. ($hook = get_hook('in_users_online_pre_online_info_output')) ? eval($hook) : null;
  251. ?>
  252. <div id="brd-online" class="gen-content">
  253. <h3 class="hn"><span><?php printf($lang_index['Currently online'], implode($lang_index['Online stats separator'], $forum_page['online_info'])) ?></span></h3>
  254. <?php if (!empty($users)): ?>
  255. <p><?php echo implode($lang_index['Online list separator'], $users) ?></p>
  256. <?php endif; ($hook = get_hook('in_new_online_data')) ? eval($hook) : null; ?>
  257. </div>
  258. <?php
  259. ($hook = get_hook('in_users_online_end')) ? eval($hook) : null;
  260. }
  261. ($hook = get_hook('in_info_end')) ? eval($hook) : null;
  262. $tpl_temp = forum_trim(ob_get_contents());
  263. $tpl_main = str_replace('<!-- forum_info -->', $tpl_temp, $tpl_main);
  264. ob_end_clean();
  265. // END SUBST - <!-- forum_info -->
  266. require FORUM_ROOT.'footer.php';