ShowAdminHelp()   F
last analyzed

Complexity

Conditions 17
Paths 240

Size

Total Lines 55
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 34
c 0
b 0
f 0
nc 240
nop 0
dl 0
loc 55
rs 3.8833

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
 * This file has the important job of taking care of help messages and the help center.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines https://www.simplemachines.org
10
 * @copyright 2022 Simple Machines and individual contributors
11
 * @license https://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1.3
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
/**
20
 * Redirect to the user help ;).
21
 * It loads information needed for the help section.
22
 * It is accessed by ?action=help.
23
 *
24
 * Uses Help template and Manual language file.
25
 */
26
function ShowHelp()
27
{
28
	loadTemplate('Help');
29
	loadLanguage('Manual');
30
31
	$subActions = array(
32
		'index' => 'HelpIndex',
33
	);
34
35
	// CRUD $subActions as needed.
36
	call_integration_hook('integrate_manage_help', array(&$subActions));
37
38
	$sa = isset($_GET['sa'], $subActions[$_GET['sa']]) ? $_GET['sa'] : 'index';
39
	call_helper($subActions[$sa]);
40
}
41
42
/**
43
 * The main page for the Help section
44
 */
45
function HelpIndex()
46
{
47
	global $scripturl, $context, $txt;
48
49
	// We need to know where our wiki is.
50
	$context['wiki_url'] = 'https://wiki.simplemachines.org/smf';
51
	$context['wiki_prefix'] = 'SMF2.1:';
52
53
	$context['canonical_url'] = $scripturl . '?action=help';
54
55
	// Sections were are going to link...
56
	$context['manual_sections'] = array(
57
		'registering' => 'Registering',
58
		'logging_in' => 'Logging_In',
59
		'profile' => 'Profile',
60
		'search' => 'Search',
61
		'posting' => 'Posting',
62
		'bbc' => 'Bulletin_board_code',
63
		'personal_messages' => 'Personal_messages',
64
		'memberlist' => 'Memberlist',
65
		'calendar' => 'Calendar',
66
		'features' => 'Features',
67
	);
68
69
	// Build the link tree.
70
	$context['linktree'][] = array(
71
		'url' => $scripturl . '?action=help',
72
		'name' => $txt['help'],
73
	);
74
75
	// Lastly, some minor template stuff.
76
	$context['page_title'] = $txt['manual_smf_user_help'];
77
	$context['sub_template'] = 'manual';
78
}
79
80
/**
81
 * Show some of the more detailed help to give the admin an idea...
82
 * It shows a popup for administrative or user help.
83
 * It uses the help parameter to decide what string to display and where to get
84
 * the string from. ($helptxt or $txt?)
85
 * It is accessed via ?action=helpadmin;help=?.
86
 *
87
 * Uses ManagePermissions language file, if the help starts with permissionhelp.
88
 * @uses template_popup() with no layers.
89
 */
90
function ShowAdminHelp()
91
{
92
	global $txt, $helptxt, $context, $scripturl, $boarddir, $boardurl;
93
94
	if (!isset($_GET['help']) || !is_string($_GET['help']))
95
		fatal_lang_error('no_access', false);
96
97
	if (!isset($helptxt))
98
		$helptxt = array();
99
100
	// Load the admin help language file and template.
101
	loadLanguage('Help');
102
103
	// Permission specific help?
104
	if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp')
105
		loadLanguage('ManagePermissions');
106
107
	loadTemplate('Help');
108
109
	// Allow mods to load their own language file here
110
	call_integration_hook('integrate_helpadmin');
111
112
	// What help string should be used?
113
	if (isset($helptxt[$_GET['help']]))
114
		$context['help_text'] = $helptxt[$_GET['help']];
115
	elseif (isset($txt[$_GET['help']]))
116
		$context['help_text'] = $txt[$_GET['help']];
117
	else
118
		fatal_lang_error('not_found', false, array(), 404);
119
120
	switch ($_GET['help']) {
121
		case 'cal_short_months':
122
			$context['help_text'] = sprintf($context['help_text'], $txt['months_short'][1], $txt['months_titles'][1]);
123
			break;
124
		case 'cal_short_days':
125
			$context['help_text'] = sprintf($context['help_text'], $txt['days_short'][1], $txt['days'][1]);
126
			break;
127
		case 'cron_is_real_cron':
128
			$context['help_text'] = sprintf($context['help_text'], allowedTo('admin_forum') ? $boarddir : '[' . $txt['hidden'] . ']', $boardurl);
129
			break;
130
		case 'queryless_urls':
131
			$context['help_text'] = sprintf($context['help_text'], (isset($_SERVER['SERVER_SOFTWARE']) && (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') !== false) ? $helptxt['queryless_urls_supported'] : $helptxt['queryless_urls_unsupported']));
132
			break;
133
	}
134
135
	// Does this text contain a link that we should fill in?
136
	if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match))
137
		$context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']);
138
139
	// Set the page title to something relevant.
140
	$context['page_title'] = $context['forum_name'] . ' - ' . $txt['help'];
141
142
	// Don't show any template layers, just the popup sub template.
143
	$context['template_layers'] = array();
144
	$context['sub_template'] = 'popup';
145
}
146
147
?>