PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/index.php

https://github.com/Dratone/EveBB
PHP | 389 lines | 291 code | 60 blank | 38 comment | 83 complexity | 1abdb40132b5d89c6f982a079bfc31a1 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Copyright (C) 2008-2010 FluxBB
  4. * based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
  5. * License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  6. */
  7. define('PUN_ROOT', dirname(__FILE__).'/');
  8. require PUN_ROOT.'include/common.php';
  9. if ($pun_user['g_read_board'] == '0')
  10. message($lang_common['No view']);
  11. // Load the index.php language file
  12. require PUN_ROOT.'lang/'.$pun_user['language'].'/index.php';
  13. // Get list of forums and topics with new posts since last visit
  14. if (!$pun_user['is_guest'])
  15. {
  16. $result = $db->query('SELECT t.forum_id, t.id, t.last_post FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.last_post>'.$pun_user['last_visit'].' AND t.moved_to IS NULL') or error('Unable to fetch new topics', __FILE__, __LINE__, $db->error());
  17. $new_topics = array();
  18. while ($cur_topic = $db->fetch_assoc($result))
  19. $new_topics[$cur_topic['forum_id']][$cur_topic['id']] = $cur_topic['last_post'];
  20. $tracked_topics = get_tracked_topics();
  21. }
  22. if ($pun_config['o_feed_type'] == '1')
  23. $page_head = array('feed' => '<link rel="alternate" type="application/rss+xml" href="extern.php?action=feed&amp;type=rss" title="'.$lang_common['RSS active topics feed'].'" />');
  24. else if ($pun_config['o_feed_type'] == '2')
  25. $page_head = array('feed' => '<link rel="alternate" type="application/atom+xml" href="extern.php?action=feed&amp;type=atom" title="'.$lang_common['Atom active topics feed'].'" />');
  26. $forum_actions = array();
  27. // Display a "mark all as read" link
  28. if (!$pun_user['is_guest'])
  29. $forum_actions[] = '<a href="misc.php?action=markread">'.$lang_common['Mark all as read'].'</a>';
  30. $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']));
  31. define('PUN_ALLOW_INDEX', 1);
  32. define('PUN_ACTIVE_PAGE', 'index');
  33. require PUN_ROOT.'header.php';
  34. # Sub Forum MOD (start) #
  35. if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/sub_forum.php'))
  36. require PUN_ROOT.'lang/'.$pun_user['language'].'/sub_forum.php';
  37. else
  38. require PUN_ROOT.'lang/English/sub_forum.php';
  39. $sfdb = array();
  40. $forums_info = $db->query('SELECT f.num_topics, f.num_posts, f.parent_forum_id, f.last_post_id, f.last_poster, f.last_post, f.id, f.forum_name, t.subject FROM '.$db->prefix.'forums AS f LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND f.parent_forum_id <> 0 ORDER BY disp_position') or error(implode($db->error(),''),__FILE__,__LINE__,$db->error());
  41. while ($current = $db->fetch_assoc($forums_info))
  42. {
  43. if (!isset($sfdb[$current['parent_forum_id']]))
  44. $sfdb[$current['parent_forum_id']] = array();
  45. $sfdb[$current['parent_forum_id']][] = $current;
  46. }
  47. # Sub Forum MOD ( end ) #
  48. //Let's quickly build their group list for the SQL.
  49. $group_list = '';
  50. if (!empty($pun_user['group_ids'])) {
  51. foreach ($pun_user['group_ids'] as $g) {
  52. $group_list .= ' OR fp.group_id='.$g;
  53. } //End foreach().
  54. } //End if.
  55. // Print the categories and forums
  56. if ($pun_user['g_id'] != PUN_ADMIN) {
  57. $sql = 'SELECT DISTINCT f.id AS fid, c.disp_position, c.id AS cid, c.cat_name, 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, f.parent_forum_id, f.disp_position, t.subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id INNER JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND (fp.group_id='.$pun_user['g_id'].' '.$group_list.') AND fp.read_forum=1) LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id WHERE f.parent_forum_id IS NULL OR f.parent_forum_id=0 ORDER BY c.disp_position, c.id, f.disp_position;';
  58. } else {
  59. $sql = '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, f.parent_forum_id, t.subject FROM '.$db->prefix.'categories AS c INNER JOIN '.$db->prefix.'forums AS f ON c.id=f.cat_id LEFT JOIN '.$db->prefix.'topics AS t ON t.last_post_id=f.last_post_id WHERE f.parent_forum_id IS NULL OR f.parent_forum_id=0 ORDER BY c.disp_position, c.id, f.disp_position;';
  60. } //End if - else.
  61. $result = $db->query($sql, true) or error('Unable to fetch category/forum list', __FILE__, __LINE__, $db->error());
  62. $cur_category = 0;
  63. $cat_count = 0;
  64. $forum_count = 0;
  65. while ($cur_forum = $db->fetch_assoc($result))
  66. {
  67. $moderators = '';
  68. if ($cur_forum['cid'] != $cur_category) // A new category since last iteration?
  69. {
  70. if ($cur_category != 0)
  71. echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
  72. ++$cat_count;
  73. $forum_count = 0;
  74. ?>
  75. <div id="idx<?php echo $cat_count ?>" class="blocktable">
  76. <h2><span><?php echo pun_htmlspecialchars($cur_forum['cat_name']) ?></span></h2>
  77. <div class="box">
  78. <div class="inbox">
  79. <table cellspacing="0">
  80. <thead>
  81. <tr>
  82. <th class="tcl" scope="col"><?php echo $lang_common['Forum'] ?></th>
  83. <th class="tc2" scope="col"><?php echo $lang_index['Topics'] ?></th>
  84. <th class="tc3" scope="col"><?php echo $lang_common['Posts'] ?></th>
  85. <th class="tcr" scope="col"><?php echo $lang_common['Last post'] ?></th>
  86. </tr>
  87. </thead>
  88. <tbody>
  89. <?php
  90. $cur_category = $cur_forum['cid'];
  91. }
  92. ++$forum_count;
  93. $item_status = ($forum_count % 2 == 0) ? 'roweven' : 'rowodd';
  94. $forum_field_new = '';
  95. $icon_type = 'icon';
  96. // Are there new posts since our last visit?
  97. if (!$pun_user['is_guest'] && $cur_forum['last_post'] > $pun_user['last_visit'] && (empty($tracked_topics['forums'][$cur_forum['fid']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_forum['fid']]))
  98. {
  99. if (!empty($new_topics[$cur_forum['fid']])) {
  100. // There are new posts in this forum, but have we read all of them already?
  101. foreach ($new_topics[$cur_forum['fid']] as $check_topic_id => $check_last_post)
  102. {
  103. 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))
  104. {
  105. $item_status .= ' inew';
  106. $forum_field_new = '<span class="newtext">[ <a href="search.php?action=show_new&amp;fid='.$cur_forum['fid'].'">'.$lang_common['New posts'].'</a> ]</span>';
  107. $icon_type = 'icon icon-new';
  108. break;
  109. } //End if.
  110. } //End foreach().
  111. } //End if.
  112. } //End if.
  113. // Is this a redirect forum?
  114. if ($cur_forum['redirect_url'] != '')
  115. {
  116. $forum_field = '<h3><span class="redirtext">'.$lang_index['Link to'].'</span> <a href="'.pun_htmlspecialchars($cur_forum['redirect_url']).'" title="'.$lang_index['Link to'].' '.pun_htmlspecialchars($cur_forum['redirect_url']).'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a></h3>';
  117. $num_topics = $num_posts = '-';
  118. $item_status .= ' iredirect';
  119. $icon_type = 'icon';
  120. }
  121. else
  122. {
  123. $forum_field = '<h3><a href="viewforum.php?id='.$cur_forum['fid'].'">'.pun_htmlspecialchars($cur_forum['forum_name']).'</a>'.(!empty($forum_field_new) ? ' '.$forum_field_new : '').'</h3>';
  124. $num_topics = $cur_forum['num_topics'];
  125. $num_posts = $cur_forum['num_posts'];
  126. # Sub Forum MOD (start) #
  127. if (isset($sfdb[$cur_forum['fid']]))
  128. {
  129. foreach ($sfdb[$cur_forum['fid']] as $cur_subforum)
  130. {
  131. $num_topics += $cur_subforum['num_topics'];
  132. $num_posts += $cur_subforum['num_posts'];
  133. if ($cur_forum['last_post'] < $cur_subforum['last_post'])
  134. {
  135. $cur_forum['last_post_id'] = $cur_subforum['last_post_id'];
  136. $cur_forum['last_poster'] = $cur_subforum['last_poster'];
  137. $cur_forum['last_post'] = $cur_subforum['last_post'];
  138. $cur_forum['subject'] = $cur_subforum['subject'];
  139. }
  140. }
  141. }
  142. # Sub Forum MOD ( end ) #
  143. }
  144. if ($cur_forum['forum_desc'] != '')
  145. $forum_field .= "\n\t\t\t\t\t\t\t\t".'<div class="forumdesc">'.$cur_forum['forum_desc'].'</div>';
  146. // If there is a last_post/last_poster
  147. if ($cur_forum['last_post'] != '') {
  148. $char;
  149. $last_post_user = pun_htmlspecialchars($cur_forum['last_poster']);
  150. if ($pun_config['o_eve_use_iga'] == '1') {
  151. $char = fetch_last_forum_poster_character($cur_forum['fid']);
  152. if ($char['character_name'] != null) {
  153. $last_post_user = pun_htmlspecialchars($char['character_name']);
  154. } //End if.
  155. } //End if.
  156. //Lets get some information about the last post.
  157. $last_post = '<a href="viewtopic.php?pid='.$cur_forum['last_post_id'].'#p'.$cur_forum['last_post_id'].'">'.((intval($pun_config['o_use_topic_stamp']) == 1) ? format_time($cur_forum['last_post']) : pun_htmlspecialchars($cur_forum['subject'])).'</a> <span class="byuser">'.$lang_common['by'].' '.$last_post_user.'</span>';
  158. } else if ($cur_forum['redirect_url'] != '') {
  159. $last_post = '- - -';
  160. }else {
  161. $last_post = $lang_common['Never'];
  162. # Sub forums #
  163. // Are there new posts since our last visit?
  164. if (!empty($sfdb) && isset($sfdb[$cur_forum['fid']]))
  165. {
  166. foreach ($sfdb[$cur_forum['fid']] as $cur_subforum)
  167. {
  168. if (!$pun_user['is_guest'] && $cur_subforum['last_post'] > $pun_user['last_visit'] && (empty($tracked_topics['forums'][$cur_subforum['id']]) || $cur_forum['last_post'] > $tracked_topics['forums'][$cur_subforum['id']]))
  169. {
  170. // There are new posts in this forum, but have we read all of them already?
  171. foreach ($new_topics[$cur_subforum['id']] as $check_topic_id => $check_last_post)
  172. {
  173. if ((empty($tracked_topics['topics'][$check_topic_id]) || $tracked_topics['topics'][$check_topic_id] < $check_last_post) && (empty($tracked_topics['forums'][$cur_subforum['id']]) || $tracked_topics['forums'][$cur_subforum['id']] < $check_last_post))
  174. {
  175. $item_status .= ' inew';
  176. $forum_field_new = '<span class="newtext">[ <a href="search.php?action=show_new&amp;fid='.$cur_forum['fid'].'">'.$lang_common['New posts'].'</a> ]</span>';
  177. $icon_type = 'icon icon-new';
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. }
  184. # Sub forums #
  185. } //End if - else block.
  186. if ($cur_forum['moderators'] != '')
  187. {
  188. $mods_array = unserialize($cur_forum['moderators']);
  189. $moderators = array();
  190. foreach ($mods_array as $mod_username => $mod_id)
  191. {
  192. if (!check_numeric($mod_id)) {
  193. continue;
  194. } //End if.
  195. if ($pun_user['g_view_users'] == '1')
  196. $moderators[] = '<a href="profile.php?id='.$mod_id.'">'.pun_htmlspecialchars($mod_username).'</a>';
  197. else
  198. $moderators[] = pun_htmlspecialchars($mod_username);
  199. }
  200. $moderators = "\t\t\t\t\t\t\t\t".'<p class="modlist">(<em>'.$lang_common['Moderated by'].'</em> '.implode(', ', $moderators).')</p>'."\n";
  201. }
  202. ?>
  203. <tr class="<?php echo $item_status ?>">
  204. <td class="tcl">
  205. <div class="<?php echo $icon_type ?>"><div class="nosize"><?php echo forum_number_format($forum_count) ?></div></div>
  206. <div class="tclcon">
  207. <div>
  208. <?php echo $forum_field."\n".$moderators ?>
  209. <?php
  210. $sub_forums_list = array();
  211. if (!empty($sfdb) && isset($sfdb[$cur_forum['fid']]))
  212. {
  213. foreach ($sfdb[$cur_forum['fid']] as $cur_subforum)
  214. $sub_forums_list[] = '<a class="subforum_name" href="viewforum.php?id='.$cur_subforum['id'].'">'.pun_htmlspecialchars($cur_subforum['forum_name']).'</a>';
  215. // EDIT THIS FOR THE DISPLAY STYLE OF THE SUBFORUMS ON MAIN PAGE
  216. if(!empty($sub_forums_list))
  217. {
  218. // Leave one $sub_forums_list commented out to use the other (between the ###..)
  219. ################################
  220. // This is Single Line Wrap Style
  221. $sub_forums_list = "\t\t\t\t\t\t\t\t".'<span class="subforum">'.$lang_sub_forum['Sub forums'].':</span> '.implode(', ', $sub_forums_list)."\n";
  222. // This is List Style
  223. //$sub_forums_list = "\n".'<b><em>'.$lang_sub_forum['Sub forums'].':</em></b><br />&nbsp; -- &nbsp;'.implode('<br />&nbsp; -- &nbsp;', $sub_forums_list)."\n";
  224. ################################
  225. /* if ($cur_forum['forum_desc'] != NULL)
  226. echo "<br />";
  227. */
  228. // TO TURN OFF DISPLAY OF SUBFORUMS ON INDEX PAGE, COMMENT OUT THE FOLLOWING LINE
  229. echo $sub_forums_list;
  230. }
  231. }
  232. ?>
  233. </div>
  234. </div>
  235. </td>
  236. <td class="tc2"><?php echo forum_number_format($num_topics) ?></td>
  237. <td class="tc3"><?php echo forum_number_format($num_posts) ?></td>
  238. <td class="tcr"><?php echo $last_post ?></td>
  239. </tr>
  240. <?php
  241. }
  242. // Did we output any categories and forums?
  243. if ($cur_category > 0)
  244. echo "\t\t\t".'</tbody>'."\n\t\t\t".'</table>'."\n\t\t".'</div>'."\n\t".'</div>'."\n".'</div>'."\n\n";
  245. else
  246. echo '<div id="idx0" class="block"><div class="box"><div class="inbox"><p>'.$lang_index['Empty board'].'</p></div></div></div>';
  247. // Collect some statistics from the database
  248. if (file_exists(FORUM_CACHE_DIR.'cache_users_info.php'))
  249. include FORUM_CACHE_DIR.'cache_users_info.php';
  250. if (!defined('PUN_USERS_INFO_LOADED'))
  251. {
  252. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  253. require PUN_ROOT.'include/cache.php';
  254. generate_users_info_cache();
  255. require FORUM_CACHE_DIR.'cache_users_info.php';
  256. } //End if.
  257. $result = $db->query('SELECT SUM(num_topics), SUM(num_posts) FROM '.$db->prefix.'forums') or error('Unable to fetch topic/post count', __FILE__, __LINE__, $db->error());
  258. list($stats['total_topics'], $stats['total_posts']) = $db->fetch_row($result);
  259. if ($pun_user['g_view_users'] == '1')
  260. $stats['newest_user'] = '<a href="profile.php?id='.$stats['last_user']['id'].'">'.pun_htmlspecialchars($stats['last_user']['username']).'</a>';
  261. else
  262. $stats['newest_user'] = pun_htmlspecialchars($stats['last_user']['username']);
  263. if (!empty($forum_actions))
  264. {
  265. ?>
  266. <div class="linksb">
  267. <div class="inbox crumbsplus">
  268. <p class="subscribelink clearb"><?php echo implode(' - ', $forum_actions); ?></p>
  269. </div>
  270. </div>
  271. <?php
  272. }
  273. ?>
  274. <div id="brdstats" class="block">
  275. <h2><span><?php echo $lang_index['Board info'] ?></span></h2>
  276. <div class="box">
  277. <div class="inbox">
  278. <?php
  279. if ($pun_config['o_hide_stats'] && $pun_user['is_guest']) {
  280. ?>
  281. <dl class="conl">
  282. <dd><span><?php echo sprintf($lang_index['Guests online'], '<strong>'.forum_number_format(1).'</strong>'); ?></span></dd>
  283. <dd><span><em><?php echo $lang_index['stats_disabled']; ?></em></span></dd>
  284. </dl>
  285. <div class="clearer"></div>
  286. <?php
  287. } else {
  288. ?>
  289. <dl class="conr">
  290. <dt><strong><?php echo $lang_index['Board stats'] ?></strong></dt>
  291. <dd><span><?php printf($lang_index['No of users'], '<strong>'.forum_number_format($stats['total_users']).'</strong>') ?></span></dd>
  292. <dd><span><?php printf($lang_index['No of topics'], '<strong>'.forum_number_format($stats['total_topics']).'</strong>') ?></span></dd>
  293. <dd><span><?php printf($lang_index['No of posts'], '<strong>'.forum_number_format($stats['total_posts']).'</strong>') ?></span></dd>
  294. </dl>
  295. <dl class="conl">
  296. <dt><strong><?php echo $lang_index['User info'] ?></strong></dt>
  297. <dd><span><?php printf($lang_index['Newest user'], $stats['newest_user']) ?></span></dd>
  298. <?php
  299. if ($pun_config['o_users_online'] == '1')
  300. {
  301. $reload = false;
  302. //Lets see if there is a cache file!
  303. if (file_exists(FORUM_CACHE_DIR.'online.stamp')) {
  304. $now = time();
  305. $then = file_get_contents(FORUM_CACHE_DIR.'online.stamp');
  306. //You can fine tune how rapidly this is updated by adjusting o_users_online_refresh.
  307. if (($now - $then) > $pun_config['o_users_online_refresh']) {
  308. $reload = true;
  309. } //End if.
  310. } else {
  311. $reload = true;
  312. } //End if - else.
  313. if ($reload) {
  314. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) {
  315. require PUN_ROOT.'include/cache.php';
  316. } //End if.
  317. generate_online_cache();
  318. } //End if.
  319. include(FORUM_CACHE_DIR.'cache_online.php');
  320. }
  321. else
  322. echo "\t\t\t".'</dl>'."\n\t\t\t".'<div class="clearer"></div>'."\n";
  323. } //End if.?>
  324. </div>
  325. </div>
  326. </div>
  327. <?php
  328. $footer_style = 'index';
  329. require PUN_ROOT.'footer.php';