BoardIndex.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 2014 Simple Machines and individual contributors
  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. {
  32. loadTemplate('BoardIndex');
  33. $context['template_layers'][] = 'boardindex_outer';
  34. }
  35. // Set a canonical URL for this page.
  36. $context['canonical_url'] = $scripturl;
  37. // Do not let search engines index anything if there is a random thing in $_GET.
  38. if (!empty($_GET))
  39. $context['robot_no_index'] = true;
  40. // Retrieve the categories and boards.
  41. require_once($sourcedir . '/Subs-BoardIndex.php');
  42. $boardIndexOptions = array(
  43. 'include_categories' => true,
  44. 'base_level' => 0,
  45. 'parent_id' => 0,
  46. 'set_latest_post' => true,
  47. 'countChildPosts' => !empty($modSettings['countChildPosts']),
  48. );
  49. $context['categories'] = getBoardIndex($boardIndexOptions);
  50. // Now set up for the info center.
  51. $context['info_center'] = array();
  52. // Retrieve the latest posts if the theme settings require it.
  53. if (!empty($settings['number_recent_posts']))
  54. {
  55. if ($settings['number_recent_posts'] > 1)
  56. {
  57. $latestPostOptions = array(
  58. 'number_posts' => $settings['number_recent_posts'],
  59. );
  60. $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));
  61. }
  62. if (!empty($context['latest_posts']) || !empty($context['latest_post']))
  63. $context['info_center'][] = 'recent';
  64. }
  65. // Load the calendar?
  66. if (!empty($modSettings['cal_enabled']) && allowedTo('calendar_view'))
  67. {
  68. // Retrieve the calendar data (events, birthdays, holidays).
  69. $eventOptions = array(
  70. 'include_holidays' => $modSettings['cal_showholidays'] > 1,
  71. 'include_birthdays' => $modSettings['cal_showbdays'] > 1,
  72. 'include_events' => $modSettings['cal_showevents'] > 1,
  73. 'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
  74. );
  75. $context += cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
  76. // Whether one or multiple days are shown on the board index.
  77. $context['calendar_only_today'] = $modSettings['cal_days_for_index'] == 1;
  78. // This is used to show the "how-do-I-edit" help.
  79. $context['calendar_can_edit'] = allowedTo('calendar_edit_any');
  80. if ($context['show_calendar'])
  81. $context['info_center'][] = 'calendar';
  82. }
  83. // And stats.
  84. $context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
  85. if ($settings['show_stats_index'])
  86. $context['info_center'][] = 'stats';
  87. // Now the online stuff
  88. require_once($sourcedir . '/Subs-MembersOnline.php');
  89. $membersOnlineOptions = array(
  90. 'show_hidden' => allowedTo('moderate_forum'),
  91. 'sort' => 'log_time',
  92. 'reverse_sort' => true,
  93. );
  94. $context += getMembersOnlineStats($membersOnlineOptions);
  95. $context['show_buddies'] = !empty($user_info['buddies']);
  96. $context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);
  97. $context['info_center'][] = 'online';
  98. // Track most online statistics? (Subs-MembersOnline.php)
  99. if (!empty($modSettings['trackStats']))
  100. trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
  101. // Are we showing all membergroups on the board index?
  102. if (!empty($settings['show_group_key']))
  103. $context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
  104. // And back to normality.
  105. $context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
  106. // Mark read button
  107. $context['mark_read_button'] = array(
  108. 'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_mark_read'] . '\');"', 'url' => $scripturl . '?action=markasread;sa=all;' . $context['session_var'] . '=' . $context['session_id']),
  109. );
  110. // Allow mods to add additional buttons here
  111. call_integration_hook('integrate_mark_read_button');
  112. loadJavascriptFile('fader.js', array('default_theme' => true, 'defer' => true), 'smf_scripts');
  113. }
  114. /**
  115. * Collapse or expand a category
  116. */
  117. function CollapseCategory()
  118. {
  119. global $user_info, $sourcedir, $context;
  120. // Just in case, no need, no need.
  121. $context['robot_no_index'] = true;
  122. checkSession('request');
  123. if (!isset($_GET['sa']))
  124. fatal_lang_error('no_access', false);
  125. // Check if the input values are correct.
  126. if (in_array($_REQUEST['sa'], array('expand', 'collapse', 'toggle')) && isset($_REQUEST['c']))
  127. {
  128. // And collapse/expand/toggle the category.
  129. require_once($sourcedir . '/Subs-Categories.php');
  130. collapseCategories(array((int) $_REQUEST['c']), $_REQUEST['sa'], array($user_info['id']));
  131. }
  132. // And go back to the board index.
  133. BoardIndex();
  134. }
  135. ?>