Issues (1027)

Sources/Admin.php (1 issue)

1
<?php
2
3
/**
4
 * This file, unpredictable as this might be, handles basic administration.
5
 *
6
 * Simple Machines Forum (SMF)
7
 *
8
 * @package SMF
9
 * @author Simple Machines http://www.simplemachines.org
10
 * @copyright 2019 Simple Machines and individual contributors
11
 * @license http://www.simplemachines.org/about/smf/license.php BSD
12
 *
13
 * @version 2.1 RC2
14
 */
15
16
if (!defined('SMF'))
17
	die('No direct access...');
18
19
/**
20
 * The main admin handling function.<br>
21
 * It initialises all the basic context required for the admin center.<br>
22
 * It passes execution onto the relevant admin section.<br>
23
 * If the passed section is not found it shows the admin home page.
24
 */
25
function AdminMain()
26
{
27
	global $txt, $context, $scripturl, $modSettings, $settings;
28
	global $smcFunc, $sourcedir, $options, $boarddir;
29
30
	// Load the language and templates....
31
	loadLanguage('Admin');
32
	loadTemplate('Admin');
33
	loadJavaScriptFile('admin.js', array('minimize' => true), 'smf_admin');
34
	loadCSSFile('admin.css', array(), 'smf_admin');
35
36
	// No indexing evil stuff.
37
	$context['robot_no_index'] = true;
38
39
	require_once($sourcedir . '/Subs-Menu.php');
40
41
	// Some preferences.
42
	$context['admin_preferences'] = !empty($options['admin_preferences']) ? $smcFunc['json_decode']($options['admin_preferences'], true) : array();
43
44
	/** @var array $admin_areas Defines the menu structure for the admin center. See {@link Subs-Menu.php Subs-Menu.php} for details! */
45
	$admin_areas = array(
46
		'forum' => array(
47
			'title' => $txt['admin_main'],
48
			'permission' => array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'),
49
			'areas' => array(
50
				'index' => array(
51
					'label' => $txt['admin_center'],
52
					'function' => 'AdminHome',
53
					'icon' => 'administration',
54
				),
55
				'credits' => array(
56
					'label' => $txt['support_credits_title'],
57
					'function' => 'AdminHome',
58
					'icon' => 'support',
59
				),
60
				'news' => array(
61
					'label' => $txt['news_title'],
62
					'file' => 'ManageNews.php',
63
					'function' => 'ManageNews',
64
					'icon' => 'news',
65
					'permission' => array('edit_news', 'send_mail', 'admin_forum'),
66
					'subsections' => array(
67
						'editnews' => array($txt['admin_edit_news'], 'edit_news'),
68
						'mailingmembers' => array($txt['admin_newsletters'], 'send_mail'),
69
						'settings' => array($txt['settings'], 'admin_forum'),
70
					),
71
				),
72
				'packages' => array(
73
					'label' => $txt['package'],
74
					'file' => 'Packages.php',
75
					'function' => 'Packages',
76
					'permission' => array('admin_forum'),
77
					'icon' => 'packages',
78
					'subsections' => array(
79
						'browse' => array($txt['browse_packages']),
80
						'packageget' => array($txt['download_packages'], 'url' => $scripturl . '?action=admin;area=packages;sa=packageget;get'),
81
						'perms' => array($txt['package_file_perms']),
82
						'options' => array($txt['package_settings']),
83
					),
84
				),
85
				'search' => array(
86
					'function' => 'AdminSearch',
87
					'permission' => array('admin_forum'),
88
					'select' => 'index'
89
				),
90
				'adminlogoff' => array(
91
					'label' => $txt['admin_logoff'],
92
					'function' => 'AdminEndSession',
93
					'enabled' => empty($modSettings['securityDisable']),
94
					'icon' => 'exit',
95
				),
96
97
			),
98
		),
99
		'config' => array(
100
			'title' => $txt['admin_config'],
101
			'permission' => array('admin_forum'),
102
			'areas' => array(
103
				'featuresettings' => array(
104
					'label' => $txt['modSettings_title'],
105
					'file' => 'ManageSettings.php',
106
					'function' => 'ModifyFeatureSettings',
107
					'icon' => 'features',
108
					'subsections' => array(
109
						'basic' => array($txt['mods_cat_features']),
110
						'bbc' => array($txt['manageposts_bbc_settings']),
111
						'layout' => array($txt['mods_cat_layout']),
112
						'sig' => array($txt['signature_settings_short']),
113
						'profile' => array($txt['custom_profile_shorttitle']),
114
						'likes' => array($txt['likes']),
115
						'mentions' => array($txt['mentions']),
116
						'alerts' => array($txt['notifications']),
117
					),
118
				),
119
				'antispam' => array(
120
					'label' => $txt['antispam_title'],
121
					'file' => 'ManageSettings.php',
122
					'function' => 'ModifyAntispamSettings',
123
					'icon' => 'security',
124
				),
125
				'languages' => array(
126
					'label' => $txt['language_configuration'],
127
					'file' => 'ManageLanguages.php',
128
					'function' => 'ManageLanguages',
129
					'icon' => 'languages',
130
					'subsections' => array(
131
						'edit' => array($txt['language_edit']),
132
						'add' => array($txt['language_add']),
133
						'settings' => array($txt['language_settings']),
134
					),
135
				),
136
				'current_theme' => array(
137
					'label' => $txt['theme_current_settings'],
138
					'file' => 'Themes.php',
139
					'function' => 'ThemesMain',
140
					'custom_url' => $scripturl . '?action=admin;area=theme;sa=list;th=' . $settings['theme_id'],
141
					'icon' => 'current_theme',
142
				),
143
				'theme' => array(
144
					'label' => $txt['theme_admin'],
145
					'file' => 'Themes.php',
146
					'function' => 'ThemesMain',
147
					'custom_url' => $scripturl . '?action=admin;area=theme',
148
					'icon' => 'themes',
149
					'subsections' => array(
150
						'admin' => array($txt['themeadmin_admin_title']),
151
						'list' => array($txt['themeadmin_list_title']),
152
						'reset' => array($txt['themeadmin_reset_title']),
153
						'edit' => array($txt['themeadmin_edit_title']),
154
					),
155
				),
156
				'modsettings' => array(
157
					'label' => $txt['admin_modifications'],
158
					'file' => 'ManageSettings.php',
159
					'function' => 'ModifyModSettings',
160
					'icon' => 'modifications',
161
					'subsections' => array(
162
						'general' => array($txt['mods_cat_modifications_misc']),
163
						// Mod Authors for a "ADD AFTER" on this line. Ensure you end your change with a comma. For example:
164
						// 'shout' => array($txt['shout']),
165
						// Note the comma!! The setting with automatically appear with the first mod to be added.
166
					),
167
				),
168
			),
169
		),
170
		'layout' => array(
171
			'title' => $txt['layout_controls'],
172
			'permission' => array('manage_boards', 'admin_forum', 'manage_smileys', 'manage_attachments', 'moderate_forum'),
173
			'areas' => array(
174
				'manageboards' => array(
175
					'label' => $txt['admin_boards'],
176
					'file' => 'ManageBoards.php',
177
					'function' => 'ManageBoards',
178
					'icon' => 'boards',
179
					'permission' => array('manage_boards'),
180
					'subsections' => array(
181
						'main' => array($txt['boards_edit']),
182
						'newcat' => array($txt['mboards_new_cat']),
183
						'settings' => array($txt['settings'], 'admin_forum'),
184
					),
185
				),
186
				'postsettings' => array(
187
					'label' => $txt['manageposts'],
188
					'file' => 'ManagePosts.php',
189
					'function' => 'ManagePostSettings',
190
					'permission' => array('admin_forum'),
191
					'icon' => 'posts',
192
					'subsections' => array(
193
						'posts' => array($txt['manageposts_settings']),
194
						'censor' => array($txt['admin_censored_words']),
195
						'topics' => array($txt['manageposts_topic_settings']),
196
						'drafts' => array($txt['manage_drafts']),
197
					),
198
				),
199
				'managecalendar' => array(
200
					'label' => $txt['manage_calendar'],
201
					'file' => 'ManageCalendar.php',
202
					'function' => 'ManageCalendar',
203
					'icon' => 'calendar',
204
					'permission' => array('admin_forum'),
205
					'inactive' => empty($modSettings['cal_enabled']),
206
					'subsections' => empty($modSettings['cal_enabled']) ? array() : array(
207
						'holidays' => array($txt['manage_holidays'], 'admin_forum'),
208
						'settings' => array($txt['calendar_settings'], 'admin_forum'),
209
					),
210
				),
211
				'managesearch' => array(
212
					'label' => $txt['manage_search'],
213
					'file' => 'ManageSearch.php',
214
					'function' => 'ManageSearch',
215
					'icon' => 'search',
216
					'permission' => array('admin_forum'),
217
					'subsections' => array(
218
						'weights' => array($txt['search_weights']),
219
						'method' => array($txt['search_method']),
220
						'settings' => array($txt['settings']),
221
					),
222
				),
223
				'smileys' => array(
224
					'label' => $txt['smileys_manage'],
225
					'file' => 'ManageSmileys.php',
226
					'function' => 'ManageSmileys',
227
					'icon' => 'smiley',
228
					'permission' => array('manage_smileys'),
229
					'subsections' => array(
230
						'editsets' => array($txt['smiley_sets']),
231
						'addsmiley' => array($txt['smileys_add'], 'enabled' => !empty($modSettings['smiley_enable'])),
232
						'editsmileys' => array($txt['smileys_edit'], 'enabled' => !empty($modSettings['smiley_enable'])),
233
						'setorder' => array($txt['smileys_set_order'], 'enabled' => !empty($modSettings['smiley_enable'])),
234
						'editicons' => array($txt['icons_edit_message_icons'], 'enabled' => !empty($modSettings['messageIcons_enable'])),
235
						'settings' => array($txt['settings']),
236
					),
237
				),
238
				'manageattachments' => array(
239
					'label' => $txt['attachments_avatars'],
240
					'file' => 'ManageAttachments.php',
241
					'function' => 'ManageAttachments',
242
					'icon' => 'attachment',
243
					'permission' => array('manage_attachments'),
244
					'subsections' => array(
245
						'browse' => array($txt['attachment_manager_browse']),
246
						'attachments' => array($txt['attachment_manager_settings']),
247
						'avatars' => array($txt['attachment_manager_avatar_settings']),
248
						'attachpaths' => array($txt['attach_directories']),
249
						'maintenance' => array($txt['attachment_manager_maintenance']),
250
					),
251
				),
252
				'sengines' => array(
253
					'label' => $txt['search_engines'],
254
					'inactive' => empty($modSettings['spider_mode']),
255
					'file' => 'ManageSearchEngines.php',
256
					'icon' => 'engines',
257
					'function' => 'SearchEngines',
258
					'permission' => 'admin_forum',
259
					'subsections' => empty($modSettings['spider_mode']) ? array() : array(
260
						'stats' => array($txt['spider_stats']),
261
						'logs' => array($txt['spider_logs']),
262
						'spiders' => array($txt['spiders']),
263
						'settings' => array($txt['settings']),
264
					),
265
				),
266
			),
267
		),
268
		'members' => array(
269
			'title' => $txt['admin_manage_members'],
270
			'permission' => array('moderate_forum', 'manage_membergroups', 'manage_bans', 'manage_permissions', 'admin_forum'),
271
			'areas' => array(
272
				'viewmembers' => array(
273
					'label' => $txt['admin_users'],
274
					'file' => 'ManageMembers.php',
275
					'function' => 'ViewMembers',
276
					'icon' => 'members',
277
					'permission' => array('moderate_forum'),
278
					'subsections' => array(
279
						'all' => array($txt['view_all_members']),
280
						'search' => array($txt['mlist_search']),
281
					),
282
				),
283
				'membergroups' => array(
284
					'label' => $txt['admin_groups'],
285
					'file' => 'ManageMembergroups.php',
286
					'function' => 'ModifyMembergroups',
287
					'icon' => 'membergroups',
288
					'permission' => array('manage_membergroups'),
289
					'subsections' => array(
290
						'index' => array($txt['membergroups_edit_groups'], 'manage_membergroups'),
291
						'add' => array($txt['membergroups_new_group'], 'manage_membergroups'),
292
						'settings' => array($txt['settings'], 'admin_forum'),
293
					),
294
				),
295
				'permissions' => array(
296
					'label' => $txt['edit_permissions'],
297
					'file' => 'ManagePermissions.php',
298
					'function' => 'ModifyPermissions',
299
					'icon' => 'permissions',
300
					'permission' => array('manage_permissions'),
301
					'subsections' => array(
302
						'index' => array($txt['permissions_groups'], 'manage_permissions'),
303
						'board' => array($txt['permissions_boards'], 'manage_permissions'),
304
						'profiles' => array($txt['permissions_profiles'], 'manage_permissions'),
305
						'postmod' => array($txt['permissions_post_moderation'], 'manage_permissions'),
306
						'settings' => array($txt['settings'], 'admin_forum'),
307
					),
308
				),
309
				'regcenter' => array(
310
					'label' => $txt['registration_center'],
311
					'file' => 'ManageRegistration.php',
312
					'function' => 'RegCenter',
313
					'icon' => 'regcenter',
314
					'permission' => array('admin_forum', 'moderate_forum'),
315
					'subsections' => array(
316
						'register' => array($txt['admin_browse_register_new'], 'moderate_forum'),
317
						'agreement' => array($txt['registration_agreement'], 'admin_forum'),
318
						'reservednames' => array($txt['admin_reserved_set'], 'admin_forum'),
319
						'settings' => array($txt['settings'], 'admin_forum'),
320
					),
321
				),
322
				'warnings' => array(
323
					'label' => $txt['warnings'],
324
					'file' => 'ManageSettings.php',
325
					'function' => 'ModifyWarningSettings',
326
					'icon' => 'warning',
327
					'inactive' => $modSettings['warning_settings'][0] == 0,
328
					'permission' => array('admin_forum'),
329
				),
330
				'ban' => array(
331
					'label' => $txt['ban_title'],
332
					'file' => 'ManageBans.php',
333
					'function' => 'Ban',
334
					'icon' => 'ban',
335
					'permission' => 'manage_bans',
336
					'subsections' => array(
337
						'list' => array($txt['ban_edit_list']),
338
						'add' => array($txt['ban_add_new']),
339
						'browse' => array($txt['ban_trigger_browse']),
340
						'log' => array($txt['ban_log']),
341
					),
342
				),
343
				'paidsubscribe' => array(
344
					'label' => $txt['paid_subscriptions'],
345
					'inactive' => empty($modSettings['paid_enabled']),
346
					'file' => 'ManagePaid.php',
347
					'icon' => 'paid',
348
					'function' => 'ManagePaidSubscriptions',
349
					'permission' => 'admin_forum',
350
					'subsections' => empty($modSettings['paid_enabled']) ? array() : array(
351
						'view' => array($txt['paid_subs_view']),
352
						'settings' => array($txt['settings']),
353
					),
354
				),
355
			),
356
		),
357
		'maintenance' => array(
358
			'title' => $txt['admin_maintenance'],
359
			'permission' => array('admin_forum'),
360
			'areas' => array(
361
				'serversettings' => array(
362
					'label' => $txt['admin_server_settings'],
363
					'file' => 'ManageServer.php',
364
					'function' => 'ModifySettings',
365
					'icon' => 'server',
366
					'subsections' => array(
367
						'general' => array($txt['general_settings']),
368
						'database' => array($txt['database_settings']),
369
						'cookie' => array($txt['cookies_sessions_settings']),
370
						'security' => array($txt['security_settings']),
371
						'cache' => array($txt['caching_settings']),
372
						'loads' => array($txt['load_balancing_settings']),
373
						'phpinfo' => array($txt['phpinfo_settings']),
374
					),
375
				),
376
				'maintain' => array(
377
					'label' => $txt['maintain_title'],
378
					'file' => 'ManageMaintenance.php',
379
					'icon' => 'maintain',
380
					'function' => 'ManageMaintenance',
381
					'subsections' => array(
382
						'routine' => array($txt['maintain_sub_routine'], 'admin_forum'),
383
						'database' => array($txt['maintain_sub_database'], 'admin_forum'),
384
						'members' => array($txt['maintain_sub_members'], 'admin_forum'),
385
						'topics' => array($txt['maintain_sub_topics'], 'admin_forum'),
386
						'hooks' => array($txt['hooks_title_list'], 'admin_forum'),
387
					),
388
				),
389
				'scheduledtasks' => array(
390
					'label' => $txt['maintain_tasks'],
391
					'file' => 'ManageScheduledTasks.php',
392
					'icon' => 'scheduled',
393
					'function' => 'ManageScheduledTasks',
394
					'subsections' => array(
395
						'tasks' => array($txt['maintain_tasks'], 'admin_forum'),
396
						'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
397
						'settings' => array($txt['scheduled_tasks_settings'], 'admin_forum'),
398
					),
399
				),
400
				'mailqueue' => array(
401
					'label' => $txt['mailqueue_title'],
402
					'file' => 'ManageMail.php',
403
					'function' => 'ManageMail',
404
					'icon' => 'mail',
405
					'subsections' => array(
406
						'browse' => array($txt['mailqueue_browse'], 'admin_forum'),
407
						'settings' => array($txt['mailqueue_settings'], 'admin_forum'),
408
						'test' => array($txt['mailqueue_test'], 'admin_forum'),
409
					),
410
				),
411
				'reports' => array(
412
					'label' => $txt['generate_reports'],
413
					'file' => 'Reports.php',
414
					'function' => 'ReportsMain',
415
					'icon' => 'reports',
416
				),
417
				'logs' => array(
418
					'label' => $txt['logs'],
419
					'function' => 'AdminLogs',
420
					'icon' => 'logs',
421
					'subsections' => array(
422
						'errorlog' => array($txt['errorlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
423
						'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => !empty($modSettings['adminlog_enabled'])),
424
						'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => !empty($modSettings['modlog_enabled'])),
425
						'banlog' => array($txt['ban_log'], 'manage_bans'),
426
						'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => !empty($modSettings['spider_mode'])),
427
						'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
428
						'settings' => array($txt['log_settings'], 'admin_forum'),
429
					),
430
				),
431
				'repairboards' => array(
432
					'label' => $txt['admin_repair'],
433
					'file' => 'RepairBoards.php',
434
					'function' => 'RepairBoards',
435
					'select' => 'maintain',
436
					'hidden' => true,
437
				),
438
			),
439
		),
440
	);
441
442
	// Any files to include for administration?
443
	if (!empty($modSettings['integrate_admin_include']))
444
	{
445
		$admin_includes = explode(',', $modSettings['integrate_admin_include']);
446
		foreach ($admin_includes as $include)
447
		{
448
			$include = strtr(trim($include), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir']));
449
			if (file_exists($include))
450
				require_once($include);
451
		}
452
	}
453
454
	// Make sure the administrator has a valid session...
455
	validateSession();
456
457
	// Actually create the menu!
458
	$admin_include_data = createMenu($admin_areas, array('do_big_icons' => true));
459
	unset($admin_areas);
460
461
	// Nothing valid?
462
	if ($admin_include_data == false)
463
		fatal_lang_error('no_access', false);
464
465
	// Build the link tree.
466
	$context['linktree'][] = array(
467
		'url' => $scripturl . '?action=admin',
468
		'name' => $txt['admin_center'],
469
	);
470
	if (isset($admin_include_data['current_area']) && $admin_include_data['current_area'] != 'index')
471
		$context['linktree'][] = array(
472
			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';' . $context['session_var'] . '=' . $context['session_id'],
473
			'name' => $admin_include_data['label'],
474
		);
475
	if (!empty($admin_include_data['current_subsection']) && $admin_include_data['subsections'][$admin_include_data['current_subsection']][0] != $admin_include_data['label'])
476
		$context['linktree'][] = array(
477
			'url' => $scripturl . '?action=admin;area=' . $admin_include_data['current_area'] . ';sa=' . $admin_include_data['current_subsection'] . ';' . $context['session_var'] . '=' . $context['session_id'],
478
			'name' => $admin_include_data['subsections'][$admin_include_data['current_subsection']][0],
479
		);
480
481
	// Make a note of the Unique ID for this menu.
482
	$context['admin_menu_id'] = $context['max_menu_id'];
483
	$context['admin_menu_name'] = 'menu_data_' . $context['admin_menu_id'];
484
485
	// Where in the admin are we?
486
	$context['admin_area'] = $admin_include_data['current_area'];
487
488
	// Now - finally - call the right place!
489
	if (isset($admin_include_data['file']))
490
		require_once($sourcedir . '/' . $admin_include_data['file']);
491
492
	// Get the right callable.
493
	$call = call_helper($admin_include_data['function'], true);
494
495
	// Is it valid?
496
	if (!empty($call))
497
		call_user_func($call);
498
}
499
500
/**
501
 * The main administration section.
502
 * It prepares all the data necessary for the administration front page.
503
 * It uses the Admin template along with the admin sub template.
504
 * It requires the moderate_forum, manage_membergroups, manage_bans,
505
 *  admin_forum, manage_permissions, manage_attachments, manage_smileys,
506
 *  manage_boards, edit_news, or send_mail permission.
507
 *  It uses the index administrative area.
508
 *  It can be found by going to ?action=admin.
509
 */
510
function AdminHome()
511
{
512
	global $sourcedir, $txt, $scripturl, $context, $user_info;
513
514
	// You have to be able to do at least one of the below to see this page.
515
	isAllowedTo(array('admin_forum', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_boards', 'manage_smileys', 'manage_attachments'));
516
517
	// Find all of this forum's administrators...
518
	require_once($sourcedir . '/Subs-Membergroups.php');
519
	if (listMembergroupMembers_Href($context['administrators'], 1, 32) && allowedTo('manage_membergroups'))
520
	{
521
		// Add a 'more'-link if there are more than 32.
522
		$context['more_admins_link'] = '<a href="' . $scripturl . '?action=moderate;area=viewgroups;sa=members;group=1">' . $txt['more'] . '</a>';
523
	}
524
525
	// Load the credits stuff.
526
	require_once($sourcedir . '/Who.php');
527
	Credits(true);
528
529
	// This makes it easier to get the latest news with your time format.
530
	$context['time_format'] = urlencode($user_info['time_format']);
531
	$context['forum_version'] = SMF_FULL_VERSION;
532
533
	// Get a list of current server versions.
534
	require_once($sourcedir . '/Subs-Admin.php');
535
	$checkFor = array(
536
		'gd',
537
		'imagemagick',
538
		'db_server',
539
		'phpa',
540
		'apc',
541
		'memcache',
542
		'xcache',
543
		'php',
544
		'server',
545
	);
546
	$context['current_versions'] = getServerVersions($checkFor);
547
548
	$context['can_admin'] = allowedTo('admin_forum');
549
550
	$context['sub_template'] = $context['admin_area'] == 'credits' ? 'credits' : 'admin';
551
	$context['page_title'] = $context['admin_area'] == 'credits' ? $txt['support_credits_title'] : $txt['admin_center'];
552
	if ($context['admin_area'] != 'credits')
553
		$context[$context['admin_menu_name']]['tab_data'] = array(
554
			'title' => $txt['admin_center'],
555
			'help' => '',
556
			'description' => '<strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
557
				' . sprintf($txt['admin_main_welcome'], $txt['admin_center'], $txt['help'], $txt['help']),
558
		);
559
560
	// Lastly, fill in the blanks in the support resources paragraphs.
561
	$txt['support_resources_p1'] = sprintf($txt['support_resources_p1'],
562
		'https://wiki.simplemachines.org/',
563
		'https://wiki.simplemachines.org/smf/features2',
564
		'https://wiki.simplemachines.org/smf/options2',
565
		'https://wiki.simplemachines.org/smf/themes2',
566
		'https://wiki.simplemachines.org/smf/packages2'
567
	);
568
	$txt['support_resources_p2'] = sprintf($txt['support_resources_p2'],
569
		'https://www.simplemachines.org/community/',
570
		'https://www.simplemachines.org/redirect/english_support',
571
		'https://www.simplemachines.org/redirect/international_support_boards',
572
		'https://www.simplemachines.org/redirect/smf_support',
573
		'https://www.simplemachines.org/redirect/customize_support'
574
	);
575
576
	if ($context['admin_area'] == 'admin')
577
		loadJavaScriptFile('admin.js', array('defer' => false, 'minimize' => true), 'smf_admin');
578
}
579
580
/**
581
 * Get one of the admin information files from Simple Machines.
582
 */
583
function DisplayAdminFile()
584
{
585
	global $context, $modSettings, $smcFunc;
586
587
	setMemoryLimit('32M');
588
589
	if (empty($_REQUEST['filename']) || !is_string($_REQUEST['filename']))
590
		fatal_lang_error('no_access', false);
591
592
	// Strip off the forum cache part or we won't find it...
593
	$_REQUEST['filename'] = str_replace($context['browser_cache'], '', $_REQUEST['filename']);
594
595
	$request = $smcFunc['db_query']('', '
596
		SELECT data, filetype
597
		FROM {db_prefix}admin_info_files
598
		WHERE filename = {string:current_filename}
599
		LIMIT 1',
600
		array(
601
			'current_filename' => $_REQUEST['filename'],
602
		)
603
	);
604
605
	if ($smcFunc['db_num_rows']($request) == 0)
606
		fatal_lang_error('admin_file_not_found', true, array($_REQUEST['filename']), 404);
607
608
	list ($file_data, $filetype) = $smcFunc['db_fetch_row']($request);
609
	$smcFunc['db_free_result']($request);
610
611
	// @todo Temp
612
	// Figure out if sesc is still being used.
613
	if (strpos($file_data, ';sesc=') !== false && $filetype == 'text/javascript')
614
		$file_data = '
615
if (!(\'smfForum_sessionvar\' in window))
616
	window.smfForum_sessionvar = \'sesc\';
617
' . strtr($file_data, array(';sesc=' => ';\' + window.smfForum_sessionvar + \'='));
618
619
	$context['template_layers'] = array();
620
	// Lets make sure we aren't going to output anything nasty.
621
	@ob_end_clean();
622
	if (!empty($modSettings['enableCompressedOutput']))
623
		@ob_start('ob_gzhandler');
624
	else
625
		@ob_start();
626
627
	// Make sure they know what type of file we are.
628
	header('content-type: ' . $filetype);
629
	echo $file_data;
630
	obExit(false);
631
}
632
633
/**
634
 * This function allocates out all the search stuff.
635
 */
636
function AdminSearch()
637
{
638
	global $txt, $context, $smcFunc, $sourcedir;
639
640
	isAllowedTo('admin_forum');
641
642
	// What can we search for?
643
	$subActions = array(
644
		'internal' => 'AdminSearchInternal',
645
		'online' => 'AdminSearchOM',
646
		'member' => 'AdminSearchMember',
647
	);
648
649
	$context['search_type'] = !isset($_REQUEST['search_type']) || !isset($subActions[$_REQUEST['search_type']]) ? 'internal' : $_REQUEST['search_type'];
650
	$context['search_term'] = isset($_REQUEST['search_term']) ? $smcFunc['htmlspecialchars']($_REQUEST['search_term'], ENT_QUOTES) : '';
651
652
	$context['sub_template'] = 'admin_search_results';
653
	$context['page_title'] = $txt['admin_search_results'];
654
655
	// Keep track of what the admin wants.
656
	if (empty($context['admin_preferences']['sb']) || $context['admin_preferences']['sb'] != $context['search_type'])
657
	{
658
		$context['admin_preferences']['sb'] = $context['search_type'];
659
660
		// Update the preferences.
661
		require_once($sourcedir . '/Subs-Admin.php');
662
		updateAdminPreferences();
663
	}
664
665
	if (trim($context['search_term']) == '')
666
		$context['search_results'] = array();
667
	else
668
		call_helper($subActions[$context['search_type']]);
669
}
670
671
/**
672
 * A complicated but relatively quick internal search.
673
 */
674
function AdminSearchInternal()
675
{
676
	global $context, $txt, $helptxt, $scripturl, $sourcedir;
677
678
	// Try to get some more memory.
679
	setMemoryLimit('128M');
680
681
	// Load a lot of language files.
682
	$language_files = array(
683
		'Help', 'ManageMail', 'ManageSettings', 'ManageCalendar', 'ManageBoards', 'ManagePaid', 'ManagePermissions', 'Search',
684
		'Login', 'ManageSmileys', 'Drafts',
685
	);
686
687
	// All the files we need to include.
688
	$include_files = array(
689
		'ManageSettings', 'ManageBoards', 'ManageNews', 'ManageAttachments', 'ManageCalendar', 'ManageMail', 'ManagePaid', 'ManagePermissions',
690
		'ManagePosts', 'ManageRegistration', 'ManageSearch', 'ManageSearchEngines', 'ManageServer', 'ManageSmileys', 'ManageLanguages',
691
	);
692
693
	// This is a special array of functions that contain setting data - we query all these to simply pull all setting bits!
694
	$settings_search = array(
695
		array('ModifyBasicSettings', 'area=featuresettings;sa=basic'),
696
		array('ModifyBBCSettings', 'area=featuresettings;sa=bbc'),
697
		array('ModifyLayoutSettings', 'area=featuresettings;sa=layout'),
698
		array('ModifyLikesSettings', 'area=featuresettings;sa=likes'),
699
		array('ModifyMentionsSettings', 'area=featuresettings;sa=mentions'),
700
		array('ModifySignatureSettings', 'area=featuresettings;sa=sig'),
701
		array('ModifyAntispamSettings', 'area=antispam'),
702
		array('ModifyWarningSettings', 'area=warnings'),
703
		array('ModifyGeneralModSettings', 'area=modsettings;sa=general'),
704
		// Mod authors if you want to be "real freaking good" then add any setting pages for your mod BELOW this line!
705
		array('ManageAttachmentSettings', 'area=manageattachments;sa=attachments'),
706
		array('ManageAvatarSettings', 'area=manageattachments;sa=avatars'),
707
		array('ModifyCalendarSettings', 'area=managecalendar;sa=settings'),
708
		array('EditBoardSettings', 'area=manageboards;sa=settings'),
709
		array('ModifyMailSettings', 'area=mailqueue;sa=settings'),
710
		array('ModifyNewsSettings', 'area=news;sa=settings'),
711
		array('GeneralPermissionSettings', 'area=permissions;sa=settings'),
712
		array('ModifyPostSettings', 'area=postsettings;sa=posts'),
713
		array('ModifyTopicSettings', 'area=postsettings;sa=topics'),
714
		array('ModifyDraftSettings', 'area=postsettings;sa=drafts'),
715
		array('EditSearchSettings', 'area=managesearch;sa=settings'),
716
		array('EditSmileySettings', 'area=smileys;sa=settings'),
717
		array('ModifyGeneralSettings', 'area=serversettings;sa=general'),
718
		array('ModifyDatabaseSettings', 'area=serversettings;sa=database'),
719
		array('ModifyCookieSettings', 'area=serversettings;sa=cookie'),
720
		array('ModifyGeneralSecuritySettings', 'area=serversettings;sa=security'),
721
		array('ModifyCacheSettings', 'area=serversettings;sa=cache'),
722
		array('ModifyLanguageSettings', 'area=languages;sa=settings'),
723
		array('ModifyRegistrationSettings', 'area=regcenter;sa=settings'),
724
		array('ManageSearchEngineSettings', 'area=sengines;sa=settings'),
725
		array('ModifySubscriptionSettings', 'area=paidsubscribe;sa=settings'),
726
		array('ModifyLogSettings', 'area=logs;sa=settings'),
727
	);
728
729
	call_integration_hook('integrate_admin_search', array(&$language_files, &$include_files, &$settings_search));
730
731
	loadLanguage(implode('+', $language_files));
732
733
	foreach ($include_files as $file)
734
		require_once($sourcedir . '/' . $file . '.php');
735
736
	/* This is the huge array that defines everything... it's a huge array of items formatted as follows:
737
		0 = Language index (Can be array of indexes) to search through for this setting.
738
		1 = URL for this indexes page.
739
		2 = Help index for help associated with this item (If different from 0)
740
	*/
741
742
	$search_data = array(
743
		// All the major sections of the forum.
744
		'sections' => array(
745
		),
746
		'settings' => array(
747
			array('COPPA', 'area=regcenter;sa=settings'),
748
			array('CAPTCHA', 'area=antispam'),
749
		),
750
	);
751
752
	// Go through the admin menu structure trying to find suitably named areas!
753
	foreach ($context[$context['admin_menu_name']]['sections'] as $section)
754
	{
755
		foreach ($section['areas'] as $menu_key => $menu_item)
756
		{
757
			$search_data['sections'][] = array($menu_item['label'], 'area=' . $menu_key);
758
			if (!empty($menu_item['subsections']))
759
				foreach ($menu_item['subsections'] as $key => $sublabel)
760
				{
761
					if (isset($sublabel['label']))
762
						$search_data['sections'][] = array($sublabel['label'], 'area=' . $menu_key . ';sa=' . $key);
763
				}
764
		}
765
	}
766
767
	foreach ($settings_search as $setting_area)
768
	{
769
		// Get a list of their variables.
770
		$config_vars = call_user_func($setting_area[0], true);
771
772
		foreach ($config_vars as $var)
773
			if (!empty($var[1]) && !in_array($var[0], array('permissions', 'switch', 'desc')))
774
				$search_data['settings'][] = array($var[(isset($var[2]) && in_array($var[2], array('file', 'db'))) ? 0 : 1], $setting_area[1], 'alttxt' => (isset($var[2]) && in_array($var[2], array('file', 'db'))) || isset($var[3]) ? (in_array($var[2], array('file', 'db')) ? $var[1] : $var[3]) : '');
775
	}
776
777
	$context['page_title'] = $txt['admin_search_results'];
778
	$context['search_results'] = array();
779
780
	$search_term = strtolower(un_htmlspecialchars($context['search_term']));
781
	// Go through all the search data trying to find this text!
782
	foreach ($search_data as $section => $data)
783
	{
784
		foreach ($data as $item)
785
		{
786
			$found = false;
787
			if (!is_array($item[0]))
788
				$item[0] = array($item[0]);
789
			foreach ($item[0] as $term)
790
			{
791
				if (stripos($term, $search_term) !== false || (isset($txt[$term]) && stripos($txt[$term], $search_term) !== false) || (isset($txt['setting_' . $term]) && stripos($txt['setting_' . $term], $search_term) !== false))
792
				{
793
					$found = $term;
794
					break;
795
				}
796
			}
797
798
			if ($found)
799
			{
800
				// Format the name - and remove any descriptions the entry may have.
801
				$name = isset($txt[$found]) ? $txt[$found] : (isset($txt['setting_' . $found]) ? $txt['setting_' . $found] : (!empty($item['alttxt']) ? $item['alttxt'] : $found));
802
				$name = preg_replace('~<(?:div|span)\sclass="smalltext">.+?</(?:div|span)>~', '', $name);
803
804
				$context['search_results'][] = array(
805
					'url' => (substr($item[1], 0, 4) == 'area' ? $scripturl . '?action=admin;' . $item[1] : $item[1]) . ';' . $context['session_var'] . '=' . $context['session_id'] . ((substr($item[1], 0, 4) == 'area' && $section == 'settings' ? '#' . $item[0][0] : '')),
806
					'name' => $name,
807
					'type' => $section,
808
					'help' => shorten_subject(isset($item[2]) ? strip_tags($helptxt[$item[2]]) : (isset($helptxt[$found]) ? strip_tags($helptxt[$found]) : ''), 255),
809
				);
810
			}
811
		}
812
	}
813
}
814
815
/**
816
 * All this does is pass through to manage members.
817
 * {@see ViewMembers()}
818
 */
819
function AdminSearchMember()
820
{
821
	global $context, $sourcedir;
822
823
	require_once($sourcedir . '/ManageMembers.php');
824
	$_REQUEST['sa'] = 'query';
825
826
	$_POST['membername'] = un_htmlspecialchars($context['search_term']);
827
	$_POST['types'] = '';
828
829
	ViewMembers();
830
}
831
832
/**
833
 * This file allows the user to search the SM online manual for a little of help.
834
 */
835
function AdminSearchOM()
836
{
837
	global $context, $sourcedir;
838
839
	$context['doc_apiurl'] = 'https://wiki.simplemachines.org/api.php';
840
	$context['doc_scripturl'] = 'https://wiki.simplemachines.org/smf/';
841
842
	// Set all the parameters search might expect.
843
	$postVars = explode(' ', $context['search_term']);
844
845
	// Encode the search data.
846
	foreach ($postVars as $k => $v)
847
		$postVars[$k] = urlencode($v);
848
849
	// This is what we will send.
850
	$postVars = implode('+', $postVars);
851
852
	// Get the results from the doc site.
853
	// Demo URL:
854
	// https://wiki.simplemachines.org/api.php?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=template+eval
855
	$search_results = fetch_web_data($context['doc_apiurl'] . '?action=query&list=search&srprop=timestamp|snippet&format=xml&srwhat=text&srsearch=' . $postVars);
856
857
	// If we didn't get any xml back we are in trouble - perhaps the doc site is overloaded?
858
	if (!$search_results || preg_match('~<' . '\?xml\sversion="\d+\.\d+"\?' . '>\s*(<api\b[^>]*>.+?</api>)~is', $search_results, $matches) != true)
859
		fatal_lang_error('cannot_connect_doc_site');
860
861
	$search_results = $matches[1];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $matches does not seem to be defined for all execution paths leading up to this point.
Loading history...
862
863
	// Otherwise we simply walk through the XML and stick it in context for display.
864
	$context['search_results'] = array();
865
	require_once($sourcedir . '/Class-Package.php');
866
867
	// Get the results loaded into an array for processing!
868
	$results = new xmlArray($search_results, false);
869
870
	// Move through the api layer.
871
	if (!$results->exists('api'))
872
		fatal_lang_error('cannot_connect_doc_site');
873
874
	// Are there actually some results?
875
	if ($results->exists('api/query/search/p'))
876
	{
877
		$relevance = 0;
878
		foreach ($results->set('api/query/search/p') as $result)
879
		{
880
			$context['search_results'][$result->fetch('@title')] = array(
881
				'title' => $result->fetch('@title'),
882
				'relevance' => $relevance++,
883
				'snippet' => str_replace('class=\'searchmatch\'', 'class="highlight"', un_htmlspecialchars($result->fetch('@snippet'))),
884
			);
885
		}
886
	}
887
}
888
889
/**
890
 * This function decides which log to load.
891
 */
892
function AdminLogs()
893
{
894
	global $sourcedir, $context, $txt, $scripturl, $modSettings;
895
896
	// These are the logs they can load.
897
	$log_functions = array(
898
		'errorlog' => array('ManageErrors.php', 'ViewErrorLog'),
899
		'adminlog' => array('Modlog.php', 'ViewModlog', 'disabled' => empty($modSettings['adminlog_enabled'])),
900
		'modlog' => array('Modlog.php', 'ViewModlog', 'disabled' => empty($modSettings['modlog_enabled'])),
901
		'banlog' => array('ManageBans.php', 'BanLog'),
902
		'spiderlog' => array('ManageSearchEngines.php', 'SpiderLogs'),
903
		'tasklog' => array('ManageScheduledTasks.php', 'TaskLog'),
904
		'settings' => array('ManageSettings.php', 'ModifyLogSettings'),
905
	);
906
907
	// If it's not got a sa set it must have come here for first time, pretend error log should be reversed.
908
	if (!isset($_REQUEST['sa']))
909
		$_REQUEST['desc'] = true;
910
911
	// Setup some tab stuff.
912
	$context[$context['admin_menu_name']]['tab_data'] = array(
913
		'title' => $txt['logs'],
914
		'help' => '',
915
		'description' => $txt['maintain_info'],
916
		'tabs' => array(
917
			'errorlog' => array(
918
				'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc',
919
				'description' => sprintf($txt['errorlog_desc'], $txt['remove']),
920
			),
921
			'adminlog' => array(
922
				'description' => $txt['admin_log_desc'],
923
			),
924
			'modlog' => array(
925
				'description' => $txt['moderation_log_desc'],
926
			),
927
			'banlog' => array(
928
				'description' => $txt['ban_log_description'],
929
			),
930
			'spiderlog' => array(
931
				'description' => $txt['spider_log_desc'],
932
			),
933
			'tasklog' => array(
934
				'description' => $txt['scheduled_log_desc'],
935
			),
936
			'settings' => array(
937
				'description' => $txt['log_settings_desc'],
938
			),
939
		),
940
	);
941
942
	call_integration_hook('integrate_manage_logs', array(&$log_functions));
943
944
	$subAction = isset($_REQUEST['sa']) && isset($log_functions[$_REQUEST['sa']]) && empty($log_functions[$_REQUEST['sa']]['disabled']) ? $_REQUEST['sa'] : 'errorlog';
945
946
	require_once($sourcedir . '/' . $log_functions[$subAction][0]);
947
	call_helper($log_functions[$subAction][1]);
948
}
949
950
/**
951
 * This ends a admin session, requiring authentication to access the ACP again.
952
 */
953
function AdminEndSession()
954
{
955
	// This is so easy!
956
	unset($_SESSION['admin_time']);
957
958
	// Clean any admin tokens as well.
959
	foreach ($_SESSION['token'] as $key => $token)
960
		if (strpos($key, '-admin') !== false)
961
			unset($_SESSION['token'][$key]);
962
963
	redirectexit();
964
}
965
966
?>