BoardIndex.php 5.2 KB

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