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

Sources/Help.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 http://www.simplemachines.org
10
 * @copyright 2017 Simple Machines and individual contributors
11
 * @license http://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 Beta 4
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
 * @uses Help template and Manual language file.
24
 */
25
function ShowHelp()
26
{
27
	loadTemplate('Help');
28
	loadLanguage('Manual');
29
30
	$subActions = array(
31
		'index' => 'HelpIndex',
32
		'rules' => 'HelpRules',
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
 * Displays forum rules
82
 */
83
function HelpRules()
84
{
85
	global $context, $txt, $boarddir, $user_info, $scripturl;
86
87
	// Build the link tree.
88
	$context['linktree'][] = array(
89
		'url' => $scripturl . '?action=help',
90
		'name' => $txt['help'],
91
	);
92
	$context['linktree'][] = array(
93
		'url' => $scripturl . '?action=help;sa=rules',
94
		'name' => $txt['terms_and_rules'],
95
	);
96
97
	// Have we got a localized one?
98 View Code Duplication
	if (file_exists($boarddir . '/agreement.' . $user_info['language'] . '.txt'))
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
		$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.' . $user_info['language'] . '.txt'), true, 'agreement_' . $user_info['language']);
100
	elseif (file_exists($boarddir . '/agreement.txt'))
101
		$context['agreement'] = parse_bbc(file_get_contents($boarddir . '/agreement.txt'), true, 'agreement');
102
	else
103
		$context['agreement'] = '';
104
105
	// Nothing to show, so let's get out of here
106
	if (empty($context['agreement']))
107
	{
108
		// No file found or a blank file! Just leave...
109
		redirectexit();
110
	}
111
112
	$context['canonical_url'] = $scripturl . '?action=help;sa=rules';
113
114
	$context['page_title'] = $txt['terms_and_rules'];
115
	$context['sub_template'] = 'terms';
116
}
117
118
/**
119
 * Show some of the more detailed help to give the admin an idea...
120
 * It shows a popup for administrative or user help.
121
 * It uses the help parameter to decide what string to display and where to get
122
 * the string from. ($helptxt or $txt?)
123
 * It is accessed via ?action=helpadmin;help=?.
124
 * @uses ManagePermissions language file, if the help starts with permissionhelp.
125
 * @uses Help template, popup sub template, no layers.
126
 */
127
function ShowAdminHelp()
128
{
129
	global $txt, $helptxt, $context, $scripturl;
130
131
	if (!isset($_GET['help']) || !is_string($_GET['help']))
132
		fatal_lang_error('no_access', false);
133
134
	if (!isset($helptxt))
135
		$helptxt = array();
136
137
	// Load the admin help language file and template.
138
	loadLanguage('Help');
139
140
	// Permission specific help?
141
	if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp')
142
		loadLanguage('ManagePermissions');
143
144
	loadTemplate('Help');
145
146
	// Allow mods to load their own language file here
147
 	call_integration_hook('integrate_helpadmin');
148
149
	// Set the page title to something relevant.
150
	$context['page_title'] = $context['forum_name'] . ' - ' . $txt['help'];
151
152
	// Don't show any template layers, just the popup sub template.
153
	$context['template_layers'] = array();
154
	$context['sub_template'] = 'popup';
155
156
	// What help string should be used?
157
	if (isset($helptxt[$_GET['help']]))
158
		$context['help_text'] = $helptxt[$_GET['help']];
159
	elseif (isset($txt[$_GET['help']]))
160
		$context['help_text'] = $txt[$_GET['help']];
161
	else
162
		$context['help_text'] = $_GET['help'];
163
164
	// Does this text contain a link that we should fill in?
165
	if (preg_match('~%([0-9]+\$)?s\?~', $context['help_text'], $match))
166
		$context['help_text'] = sprintf($context['help_text'], $scripturl, $context['session_id'], $context['session_var']);
167
}
168
169
?>
0 ignored issues
show
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...