BoardIndex.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * Simple Machines Forum (SMF)
  4. *
  5. * @package SMF
  6. * @author Simple Machines http://www.simplemachines.org
  7. * @copyright 2011 Simple Machines
  8. * @license http://www.simplemachines.org/about/smf/license.php BSD
  9. *
  10. * @version 2.0
  11. */
  12. if (!defined('SMF'))
  13. die('Hacking attempt...');
  14. /* The single function this file contains is used to display the main
  15. board index. It uses just the following functions:
  16. void BoardIndex()
  17. - shows the board index.
  18. - uses the BoardIndex template, and main sub template.
  19. - may use the boardindex subtemplate for wireless support.
  20. - updates the most online statistics.
  21. - is accessed by ?action=boardindex.
  22. void CollapseCategory()
  23. - collapse or expand a category
  24. */
  25. // Show the board index!
  26. function BoardIndex()
  27. {
  28. global $txt, $user_info, $sourcedir, $modSettings, $context, $settings, $scripturl;
  29. // For wireless, we use the Wireless template...
  30. if (WIRELESS)
  31. $context['sub_template'] = WIRELESS_PROTOCOL . '_boardindex';
  32. else
  33. loadTemplate('BoardIndex');
  34. // Set a canonical URL for this page.
  35. $context['canonical_url'] = $scripturl;
  36. // Do not let search engines index anything if there is a random thing in $_GET.
  37. if (!empty($_GET))
  38. $context['robot_no_index'] = true;
  39. // Retrieve the categories and boards.
  40. require_once($sourcedir . '/Subs-BoardIndex.php');
  41. $boardIndexOptions = array(
  42. 'include_categories' => true,
  43. 'base_level' => 0,
  44. 'parent_id' => 0,
  45. 'set_latest_post' => true,
  46. 'countChildPosts' => !empty($modSettings['countChildPosts']),
  47. );
  48. $context['categories'] = getBoardIndex($boardIndexOptions);
  49. // Get the user online list.
  50. require_once($sourcedir . '/Subs-MembersOnline.php');
  51. $membersOnlineOptions = array(
  52. 'show_hidden' => allowedTo('moderate_forum'),
  53. 'sort' => 'log_time',
  54. 'reverse_sort' => true,
  55. );
  56. $context += getMembersOnlineStats($membersOnlineOptions);
  57. $context['show_buddies'] = !empty($user_info['buddies']);
  58. // Are we showing all membergroups on the board index?
  59. if (!empty($settings['show_group_key']))
  60. $context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
  61. // Track most online statistics? (Subs-MembersOnline.php)
  62. if (!empty($modSettings['trackStats']))
  63. trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
  64. // Retrieve the latest posts if the theme settings require it.
  65. if (isset($settings['number_recent_posts']) && $settings['number_recent_posts'] > 1)
  66. {
  67. $latestPostOptions = array(
  68. 'number_posts' => $settings['number_recent_posts'],
  69. );
  70. $context['latest_posts'] = cache_quick_get('boardindex-latest_posts:' . md5($user_info['query_wanna_see_board'] . $user_info['language']), 'Subs-Recent.php', 'cache_getLastPosts', array($latestPostOptions));
  71. }
  72. $settings['display_recent_bar'] = !empty($settings['number_recent_posts']) ? $settings['number_recent_posts'] : 0;
  73. $settings['show_member_bar'] &= allowedTo('view_mlist');
  74. $context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
  75. $context['show_member_list'] = allowedTo('view_mlist');
  76. $context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);
  77. // Load the calendar?
  78. if (!empty($modSettings['cal_enabled']) && allowedTo('calendar_view'))
  79. {
  80. // Retrieve the calendar data (events, birthdays, holidays).
  81. $eventOptions = array(
  82. 'include_holidays' => $modSettings['cal_showholidays'] > 1,
  83. 'include_birthdays' => $modSettings['cal_showbdays'] > 1,
  84. 'include_events' => $modSettings['cal_showevents'] > 1,
  85. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  86. );
  87. $context += cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  88. // Whether one or multiple days are shown on the board index.
  89. $context['calendar_only_today'] = $modSettings['cal_days_for_index'] == 1;
  90. // This is used to show the "how-do-I-edit" help.
  91. $context['calendar_can_edit'] = allowedTo('calendar_edit_any');
  92. }
  93. else
  94. $context['show_calendar'] = false;
  95. $context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
  96. }
  97. // Collapse or expand a category
  98. function CollapseCategory()
  99. {
  100. global $user_info, $sourcedir, $context;
  101. // Just in case, no need, no need.
  102. $context['robot_no_index'] = true;
  103. checkSession('request');
  104. if (!isset($_GET['sa']))
  105. fatal_lang_error('no_access', false);
  106. // Check if the input values are correct.
  107. if (in_array($_REQUEST['sa'], array('expand', 'collapse', 'toggle')) && isset($_REQUEST['c']))
  108. {
  109. // And collapse/expand/toggle the category.
  110. require_once($sourcedir . '/Subs-Categories.php');
  111. collapseCategories(array((int) $_REQUEST['c']), $_REQUEST['sa'], array($user_info['id']));
  112. }
  113. // And go back to the board index.
  114. BoardIndex();
  115. }
  116. ?>