Completed
Push — release-2.1 ( aa21c4...7040ad )
by Mathias
09:20
created

BoardIndex.php ➔ BoardIndex()   F

Complexity

Conditions 18
Paths 8320

Size

Total Lines 119
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 18
eloc 65
nc 8320
nop 0
dl 0
loc 119
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * The single function this file contains is used to display the main
5
 * board index.
6
 *
7
 * Simple Machines Forum (SMF)
8
 *
9
 * @package SMF
10
 * @author Simple Machines http://www.simplemachines.org
11
 * @copyright 2017 Simple Machines and individual contributors
12
 * @license http://www.simplemachines.org/about/smf/license.php BSD
13
 *
14
 * @version 2.1 Beta 4
15
 */
16
17
if (!defined('SMF'))
18
	die('No direct access...');
19
20
/**
21
 * This function shows the board index.
22
 * It uses the BoardIndex template, and main sub template.
23
 * It updates the most online statistics.
24
 * It is accessed by ?action=boardindex.
25
 */
26
function BoardIndex()
27
{
28
	global $txt, $user_info, $sourcedir, $modSettings, $context, $settings, $scripturl;
29
30
	loadTemplate('BoardIndex');
31
	$context['template_layers'][] = 'boardindex_outer';
32
33
	// Set a canonical URL for this page.
34
	$context['canonical_url'] = $scripturl;
35
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
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
51
	// Now set up for the info center.
52
	$context['info_center'] = array();
53
54
	// Retrieve the latest posts if the theme settings require it.
55
	if (!empty($settings['number_recent_posts']))
56
	{
57
		if ($settings['number_recent_posts'] > 1)
58
		{
59
			$latestPostOptions = array(
60
				'number_posts' => $settings['number_recent_posts'],
61
			);
62
			$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));
63
		}
64
65
		if (!empty($context['latest_posts']) || !empty($context['latest_post']))
66
			$context['info_center'][] = array(
67
				'tpl' => 'recent',
68
				'txt' => 'recent_posts',
69
			);
70
	}
71
72
	// Load the calendar?
73
	if (!empty($modSettings['cal_enabled']) && allowedTo('calendar_view'))
74
	{
75
		// Retrieve the calendar data (events, birthdays, holidays).
76
		$eventOptions = array(
77
			'include_holidays' => $modSettings['cal_showholidays'] > 1,
78
			'include_birthdays' => $modSettings['cal_showbdays'] > 1,
79
			'include_events' => $modSettings['cal_showevents'] > 1,
80
			'num_days_shown' => empty($modSettings['cal_days_for_index']) || $modSettings['cal_days_for_index'] < 1 ? 1 : $modSettings['cal_days_for_index'],
81
		);
82
		$context += cache_quick_get('calendar_index_offset_' . ($user_info['time_offset'] + $modSettings['time_offset']), 'Subs-Calendar.php', 'cache_getRecentEvents', array($eventOptions));
83
84
		// Whether one or multiple days are shown on the board index.
85
		$context['calendar_only_today'] = $modSettings['cal_days_for_index'] == 1;
86
87
		// This is used to show the "how-do-I-edit" help.
88
		$context['calendar_can_edit'] = allowedTo('calendar_edit_any');
89
90
		if ($context['show_calendar'])
91
			$context['info_center'][] = array(
92
				'tpl' => 'calendar',
93
				'txt' => $context['calendar_only_today'] ? 'calendar_today' : 'calendar_upcoming',
94
			);
95
	}
96
97
	// And stats.
98
	$context['show_stats'] = allowedTo('view_stats') && !empty($modSettings['trackStats']);
99
	if ($settings['show_stats_index'])
100
		$context['info_center'][] = array(
101
				'tpl' => 'stats',
102
				'txt' => 'forum_stats',
103
			);
104
105
	// Now the online stuff
106
	require_once($sourcedir . '/Subs-MembersOnline.php');
107
	$membersOnlineOptions = array(
108
		'show_hidden' => allowedTo('moderate_forum'),
109
		'sort' => 'log_time',
110
		'reverse_sort' => true,
111
	);
112
	$context += getMembersOnlineStats($membersOnlineOptions);
113
	$context['show_buddies'] = !empty($user_info['buddies']);
114
	$context['show_who'] = allowedTo('who_view') && !empty($modSettings['who_enabled']);
115
	$context['info_center'][] = array(
116
				'tpl' => 'online',
117
				'txt' => 'online_users',
118
			);
119
120
	// Track most online statistics? (Subs-MembersOnline.php)
121
	if (!empty($modSettings['trackStats']))
122
		trackStatsUsersOnline($context['num_guests'] + $context['num_spiders'] + $context['num_users_online']);
123
124
	// Are we showing all membergroups on the board index?
125
	if (!empty($settings['show_group_key']))
126
		$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());
127
128
	// And back to normality.
129
	$context['page_title'] = sprintf($txt['forum_index'], $context['forum_name']);
130
131
	// Mark read button
132
	$context['mark_read_button'] = array(
133
		'markread' => array('text' => 'mark_as_read', 'image' => 'markread.png', 'custom' => 'data-confirm="' . $txt['are_sure_mark_read'] . '"', 'class' => 'you_sure', 'url' => $scripturl . '?action=markasread;sa=all;' . $context['session_var'] . '=' . $context['session_id']),
134
	);
135
136
	// Allow mods to add additional buttons here
137
	call_integration_hook('integrate_mark_read_button');
138
139
	if (!empty($settings['show_newsfader']))
140
	{
141
		loadJavaScriptFile('slippry.min.js', array(), 'smf_jquery_slippry');
142
		loadCSSFile('slider.min.css', array(), 'smf_jquery_slider');
143
	}
144
}
145
146
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...