Passed
Pull Request — development (#3837)
by Spuds
08:46
created

ManageFeatures   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 210
Duplicated Lines 0 %

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 210
ccs 14
cts 91
cp 0.1538
rs 10
c 0
b 0
f 0
wmc 14

5 Methods

Rating   Name   Duplication   Size   Complexity  
A pre_dispatch() 0 4 1
B action_basicSettings_display() 0 65 8
A basicSettings_search() 0 3 1
A action_index() 0 44 1
A _basicSettings() 0 57 3
1
<?php
2
3
/**
4
 * Manage features and options administration page.
5
 *
6
 * @package   ElkArte Forum
7
 * @copyright ElkArte Forum contributors
8
 * @license   BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file)
9
 *
10
 * This file contains code covered by:
11
 * copyright: 2011 Simple Machines (http://www.simplemachines.org)
12
 *
13
 * @version 2.0 Beta 1
14
 *
15
 */
16
17
namespace ElkArte\AdminController;
18
19
use DateTimeZone;
20
use ElkArte\AbstractController;
21
use ElkArte\Action;
22
use ElkArte\Hooks;
23
use ElkArte\Languages\Txt;
24
use ElkArte\MetadataIntegrate;
25
use ElkArte\SettingsForm\SettingsForm;
26
27
/**
28
 * Manage features and options administration page.
29
 *
30
 * This controller handles the pages which allow the admin
31
 * to see and change the basic feature settings of their site.
32
 */
33
class ManageFeatures extends AbstractController
34
{
35
	/**
36
	 * Pre-dispatch, called before other methods.
37
	 */
38 2
	public function pre_dispatch()
39
	{
40
		// We need this in a few places, so it's easier to have it loaded here
41 2
		require_once(SUBSDIR . '/ManageFeatures.subs.php');
42 2
	}
43
44
	/**
45
	 * This function passes control through to the relevant tab.
46
	 *
47
	 * @event integrate_sa_modify_features Use to add new Configuration tabs
48
	 * @see AbstractController::action_index()
49
	 * @uses Help, ManageSettings languages
50
	 * @uses sub_template show_settings
51
	 */
52
	public function action_index()
53
	{
54
		global $context, $txt, $settings;
55
56
		// Often Helpful
57
		Txt::load('Help+ManageSettings+Mentions');
58
59
		// All the actions we know about.  These must exist in loadMenu() of the admin controller.
60
		$subActions = [
61
			'basic' => [$this, 'action_basicSettings_display', 'permission' => 'admin_forum'],
62
			'layout' => ['controller' => ManageLayout::class, 'function' => 'action_index', 'permission' => 'admin_forum'],
63
			'pwa' => ['controller' => ManagePwa::class, 'function' => 'action_index', 'permission' => 'admin_forum'],
64
			'pmsettings' => ['controller' => ManagePmSettings::class, 'function' => 'action_index', 'permission' => 'admin_forum'],
65
			'mentions' => ['controller' => ManageMentions::class, 'function' => 'action_index', 'permission' => 'admin_forum'],
66
			'profile' => ['controller' => ManageCustomProfile::class, 'function' => 'action_index', 'enabled' => featureEnabled('cp'), 'permission' => 'admin_forum'],
67
			'profileedit' => ['controller' => ManageCustomProfile::class, 'function' => 'action_index', 'enabled' => featureEnabled('cp'), 'permission' => 'admin_forum'],
68
		];
69
70
		// Set up the action control
71
		$action = new Action('modify_features');
72
73
		// By default, do the basic settings, call integrate_sa_modify_features
74
		$subAction = $action->initialize($subActions, 'basic');
75
76
		// Some final pieces for the template
77
		$context['sub_template'] = 'show_settings';
78
		$context['sub_action'] = $subAction;
79
		$context['page_title'] = $txt['modSettings_title'];
80
81
		// Load up all the tabs...
82
		$context[$context['admin_menu_name']]['object']->prepareTabData([
83
			'title' => 'modSettings_title',
84
			'help' => 'featuresettings',
85
			'description' => sprintf($txt['modSettings_desc'], getUrl('admin', ['action' => 'admin', 'area' => 'theme', 'sa' => 'list', 'th' => $settings['theme_id'], '{session_data}'])),
86
			// All valid $subActions will be added, here you just specify any special tab data
87
			'tabs' => [
88
				'mention' => ['description' => $txt['mentions_settings_desc'],],
89
				'profile' => ['description' => $txt['custom_profile_desc'],],
90
				'pwa' => ['description' => $txt['pwa_settings_desc'],],
91
			],
92
		]);
93
94
		// Call the right function for this sub-action.
95
		$action->dispatch($subAction);
96
	}
97
98
	/**
99
	 * Config array for changing the basic forum settings
100
	 *
101
	 * - Accessed from ?action=admin;area=featuresettings;sa=basic;
102
	 *
103
	 * @event integrate_save_basic_settings
104
	 */
105
	public function action_basicSettings_display(): void
106
	{
107
		global $txt, $context, $modSettings;
108
109
		// Initialize the form
110
		$settingsForm = new SettingsForm(SettingsForm::DB_ADAPTER);
111
112
		// Initialize it with our settings
113
		$settingsForm->setConfigVars($this->_basicSettings());
114
115
		theme()->addJavascriptVar(['txt_invalid_response' => $txt['ajax_bad_response']], true);
116
117
		// Saving?
118
		if ($this->_req->hasQuery('save'))
119
		{
120
			checkSession();
121
122
			// Prevent absurd boundaries here - make it a day tops.
123
			if (isset($this->_req->post->lastActive))
124
			{
125
				$this->_req->post->lastActive = min((int) $this->_req->post->lastActive, 1440);
126
			}
127
128
			call_integration_hook('integrate_save_basic_settings');
129
130
			// Microdata needs to enable its integration
131
			if ($this->_req->isSet('metadata_enabled'))
132
			{
133
				Hooks::instance()->enableIntegration(MetadataIntegrate::class);
134
			}
135
			else
136
			{
137
				Hooks::instance()->disableIntegration(MetadataIntegrate::class);
138
			}
139
140
			// If they have changed Hive settings, let's clear them to avoid issues
141
			if (empty($modSettings['minify_css_js']) !== empty($this->_req->post->minify_css_js))
142
			{
143
				theme()->cleanHives();
144
			}
145
146
			$settingsForm->setConfigValues((array) $this->_req->post);
147
			$settingsForm->save();
148
149
			writeLog();
150
			redirectexit('action=admin;area=featuresettings;sa=basic');
151
		}
152
153
		if (isset($this->_req->post->cleanhives) && $this->getApi() === 'json')
154
		{
155
			$clean_hives_result = theme()->cleanHives();
156
157
			setJsonTemplate();
158
			$context['json_data'] = [
159
				'success' => $clean_hives_result,
160
				'response' => $clean_hives_result ? $txt['clean_hives_success'] : $txt['clean_hives_failed']
161
			];
162
163
			return;
164
		}
165
166
		$context['post_url'] = getUrl('admin', ['action' => 'admin', 'area' => 'featuresettings', 'sa' => 'basic', 'save']);
167
		$context['settings_title'] = $txt['mods_cat_features'];
168
169
		$settingsForm->prepare();
170
	}
171
172
	/**
173
	 * Return basic feature settings.
174
	 *
175
	 * @event integrate_modify_basic_settings Adds to General features and Options
176
	 */
177
	private function _basicSettings()
178
	{
179
		global $txt;
180
181
		$config_vars = [
182
			// Basic stuff, titles, permissions...
183
			['check', 'allow_guestAccess'],
184
			['check', 'enable_buddylist'],
185
			['check', 'allow_editDisplayName'],
186
			['check', 'allow_hideOnline'],
187
			['check', 'titlesEnable'],
188
			'',
189
			// JavaScript and CSS options
190
			['select', 'jquery_source', ['auto' => $txt['jquery_auto'], 'local' => $txt['jquery_local'], 'cdn' => $txt['jquery_cdn']]],
191
			['check', 'minify_css_js', 'postinput' => '<a href="#" id="clean_hives" class="linkbutton">' . $txt['clean_hives'] . '</a>'],
192
			'',
193
			// Number formatting, timezones.
194
			['text', 'time_format'],
195
			['float', 'time_offset', 'subtext' => $txt['setting_time_offset_note'], 6, 'postinput' => $txt['hours']],
196
			'default_timezone' => ['select', 'default_timezone', []],
197
			'',
198
			// Who's online?
199
			['check', 'who_enabled'],
200
			['int', 'lastActive', 6, 'postinput' => $txt['minutes']],
201
			'',
202
			// Statistics.
203
			['check', 'trackStats'],
204
			['check', 'hitStats'],
205
			'',
206
			// Option-ish things... miscellaneous sorta.
207
			['check', 'metadata_enabled'],
208
			['check', 'allow_disableAnnounce'],
209
			['check', 'disallow_sendBody'],
210
			['select', 'enable_contactform', ['disabled' => $txt['contact_form_disabled'], 'registration' => $txt['contact_form_registration'], 'menu' => $txt['contact_form_menu']]],
211
		];
212
213
		// Get all the time zones.
214
		$all_zones = DateTimeZone::listIdentifiers();
215
		if (empty($all_zones))
216
		{
217
			unset($config_vars['default_timezone']);
218 2
		}
219
		else
220 2
		{
221
			// Make sure we set the value to the same as the printed value.
222
			foreach ($all_zones as $zone)
223
			{
224 2
				$config_vars['default_timezone'][2][$zone] = $zone;
225
			}
226
		}
227
228
		theme()->addInlineJavascript('
229 2
			document.getElementById("clean_hives").addEventListener("click", function(event) {return cleanHives(event);});', ['defer' => true]);
0 ignored issues
show
Bug introduced by
array('defer' => true) of type array<string,true> is incompatible with the type boolean expected by parameter $defer of ElkArte\Themes\Theme::addInlineJavascript(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

229
			document.getElementById("clean_hives").addEventListener("click", function(event) {return cleanHives(event);});', /** @scrutinizer ignore-type */ ['defer' => true]);
Loading history...
230
231 2
		call_integration_hook('integrate_modify_basic_settings', [&$config_vars]);
232
233 2
		return $config_vars;
234
	}
235 2
236 2
237 2
	/**
238
	 * Public method to return the basic settings, used for admin search
239
	 */
240 2
	public function basicSettings_search()
241
	{
242 2
		return $this->_basicSettings();
243
	}
244
}
245