PluginProbe
User Access Manager / 2.2.13
User Access Manager v2.2.13
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Controller/Backend/SettingsController.php +186 -58 2.3.142.2.13 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * SettingsController.php
4 + *
5 + * The SettingsController class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\Controller\Backend;
@@ -23,33 +36,81 @@
23 36 class SettingsController extends Controller
24 37 {
25 38 use ControllerTabNavigationTrait;
26 39
27 - public const GROUP_POST_TYPES = 'post_types';
28 - public const GROUP_TAXONOMIES = 'taxonomies';
29 - public const GROUP_FILES = 'file';
30 - public const SECTION_FILES = 'file';
31 - public const GROUP_AUTHOR = 'author';
32 - public const SECTION_AUTHOR = 'author';
33 - public const GROUP_CACHE = 'cache';
34 - public const GROUP_OTHER = 'other';
35 - public const SECTION_OTHER = 'other';
40 + const GROUP_POST_TYPES = 'post_types';
41 + const GROUP_TAXONOMIES = 'taxonomies';
42 + const GROUP_FILES = 'file';
43 + const SECTION_FILES = 'file';
44 + const GROUP_AUTHOR = 'author';
45 + const SECTION_AUTHOR = 'author';
46 + const GROUP_CACHE = 'cache';
47 + const GROUP_OTHER = 'other';
48 + const SECTION_OTHER = 'other';
36 49
37 - protected ?string $template = 'AdminSettings.php';
50 + /**
51 + * @var MainConfig
52 + */
53 + private $mainConfig;
38 54
55 + /**
56 + * @var string
57 + */
58 + protected $template = 'AdminSettings.php';
59 +
60 + /**
61 + * @var Cache
62 + */
63 + private $cache;
64 +
65 + /**
66 + * @var FileHandler
67 + */
68 + private $fileHandler;
69 +
70 + /**
71 + * @var FormFactory
72 + */
73 + private $formFactory;
74 +
75 + /**
76 + * @var FormHelper
77 + */
78 + private $formHelper;
79 +
80 + /**
81 + * SettingsController constructor.
82 + * @param Php $php
83 + * @param Wordpress $wordpress
84 + * @param WordpressConfig $wordpressConfig
85 + * @param MainConfig $mainConfig
86 + * @param Cache $cache
87 + * @param FileHandler $fileHandler
88 + * @param FormFactory $formFactory
89 + * @param FormHelper $formHelper
90 + */
39 91 public function __construct(
40 92 Php $php,
41 93 Wordpress $wordpress,
42 94 WordpressConfig $wordpressConfig,
43 - private MainConfig $mainConfig,
44 - private Cache $cache,
45 - private FileHandler $fileHandler,
46 - private FormFactory $formFactory,
47 - private FormHelper $formHelper
95 + MainConfig $mainConfig,
96 + Cache $cache,
97 + FileHandler $fileHandler,
98 + FormFactory $formFactory,
99 + FormHelper $formHelper
48 100 ) {
49 101 parent::__construct($php, $wordpress, $wordpressConfig);
102 + $this->mainConfig = $mainConfig;
103 + $this->cache = $cache;
104 + $this->fileHandler = $fileHandler;
105 + $this->formFactory = $formFactory;
106 + $this->formHelper = $formHelper;
50 107 }
51 108
109 + /**
110 + * Returns the tab groups.
111 + * @return array
112 + */
52 113 public function getTabGroups(): array
53 114 {
54 115 $activeCacheProvider = $this->mainConfig->getActiveCacheProvider();
55 116 $cacheProviderSections = [$activeCacheProvider];
@@ -74,9 +135,12 @@
74 135 self::GROUP_OTHER => [self::SECTION_OTHER]
75 136 ];
76 137 }
77 138
78 -
139 + /**
140 + * Returns the pages.
141 + * @return array
142 + */
79 143 private function getPages(): array
80 144 {
81 145 $pages = $this->wordpress->getPages('sort_column=menu_order');
82 146 return is_array($pages) !== false ? $pages : [];
@@ -82,8 +146,9 @@
82 146 return is_array($pages) !== false ? $pages : [];
83 147 }
84 148
85 149 /**
150 + * Returns the post types as object.
86 151 * @return WP_Post_Type[]
87 152 */
88 153 private function getPostTypes(): array
89 154 {
@@ -90,8 +155,9 @@
90 155 return $this->wordpress->getPostTypes(['public' => true], 'objects');
91 156 }
92 157
93 158 /**
159 + * Returns the taxonomies as objects.
94 160 * @return WP_Taxonomy[]
95 161 */
96 162 private function getTaxonomies(): array
97 163 {
@@ -97,18 +163,31 @@
97 163 {
98 164 return $this->wordpress->getTaxonomies(['public' => true], 'objects');
99 165 }
100 166
101 - public function getText(string $key, bool $description = false): string
167 + /**
168 + * @param string $key
169 + * @param bool $description
170 + * @return string
171 + */
172 + public function getText(string $key, $description = false): string
102 173 {
103 174 return $this->formHelper->getText($key, $description);
104 175 }
105 176
177 + /**
178 + * @param string $key
179 + * @return string
180 + */
106 181 public function getGroupText(string $key): string
107 182 {
108 183 return $this->getText($key);
109 184 }
110 185
186 + /**
187 + * @param string $key
188 + * @return string
189 + */
111 190 public function getGroupSectionText(string $key): string
112 191 {
113 192 return ($key === MainConfig::DEFAULT_TYPE) ?
114 193 TXT_UAM_SETTINGS_GROUP_SECTION_DEFAULT : $this->getObjectName($key);
@@ -113,8 +192,13 @@
113 192 return ($key === MainConfig::DEFAULT_TYPE) ?
114 193 TXT_UAM_SETTINGS_GROUP_SECTION_DEFAULT : $this->getObjectName($key);
115 194 }
116 195
196 + /**
197 + * Returns the object name.
198 + * @param string $objectKey
199 + * @return string
200 + */
117 201 public function getObjectName(string $objectKey): string
118 202 {
119 203 $objects = $this->wordpress->getPostTypes(['public' => true], 'objects')
120 204 + $this->wordpress->getTaxonomies(['public' => true], 'objects');
@@ -122,11 +206,14 @@
122 206 return (isset($objects[$objectKey]) === true) ? $objects[$objectKey]->labels->name : $objectKey;
123 207 }
124 208
125 209 /**
210 + * Returns the post settings form.
211 + * @param string $postType
212 + * @return Form
126 213 * @throws Exception
127 214 */
128 - private function getPostSettingsForm(string $postType = MainConfig::DEFAULT_TYPE): Form
215 + private function getPostSettingsForm($postType = MainConfig::DEFAULT_TYPE): Form
129 216 {
130 217 $textarea = null;
131 218 $configParameters = $this->mainConfig->getConfigParameters();
132 219
@@ -141,9 +228,9 @@
141 228 }
142 229
143 230 $parameters = ($postType !== MainConfig::DEFAULT_TYPE) ? ["{$postType}_use_default"] : [];
144 231 $parameters = array_merge($parameters, [
145 - "hide_$postType",
232 + "hide_{$postType}",
146 233 "hide_{$postType}_title",
147 234 "{$postType}_title",
148 235 $textarea,
149 236 "hide_{$postType}_comment",
@@ -155,27 +242,29 @@
155 242 return $this->formHelper->getSettingsForm($parameters, $postType);
156 243 }
157 244
158 245 /**
246 + * Returns the taxonomy settings form.
247 + * @param string $taxonomy
248 + * @return Form
159 249 * @throws Exception
160 250 */
161 - private function getTaxonomySettingsForm(string $taxonomy = MainConfig::DEFAULT_TYPE): Form
251 + private function getTaxonomySettingsForm($taxonomy = MainConfig::DEFAULT_TYPE): Form
162 252 {
163 253 $parameters = ($taxonomy !== MainConfig::DEFAULT_TYPE) ? ["{$taxonomy}_use_default"] : [];
164 254 $parameters = array_merge($parameters, [
165 - "hide_empty_$taxonomy"
255 + "hide_empty_{$taxonomy}"
166 256 ]);
167 257
168 258 return $this->formHelper->getSettingsForm($parameters, $taxonomy);
169 259 }
170 260
261 + /**
262 + * Checks if x send file is available.
263 + * @return bool
264 + */
171 265 private function isXSendFileAvailable(): bool
172 266 {
173 - // On nginx, X-Accel-Redirect is always available — no HTTP test needed.
174 - if ($this->wordpress->isNginx()) {
175 - return true;
176 - }
177 -
178 267 $content = @file_get_contents($this->wordpress->getSiteUrl() . '?testXSendFile');
179 268 $this->fileHandler->removeXSendFileTestFile();
180 269
181 270 return ($content === 'success');
@@ -180,43 +269,43 @@
180 269
181 270 return ($content === 'success');
182 271 }
183 272
184 - private function configureXSendFileOption(Form $form): void
273 + /**
274 + * Disables the xSendFileOption
275 + * @param Form $form
276 + */
277 + private function disableXSendFileOption(Form $form)
185 278 {
186 279 $formElements = $form->getElements();
187 280
188 - if (isset($formElements['download_type']) === false) {
189 - return;
190 - }
281 + if (isset($formElements['download_type']) === true) {
282 + /** @var ValueSetFormElement $downloadType */
283 + $downloadType = $formElements['download_type'];
284 + $possibleValues = $downloadType->getPossibleValues();
191 285
192 - /** @var ValueSetFormElement $downloadType */
193 - $downloadType = $formElements['download_type'];
194 - $possibleValues = $downloadType->getPossibleValues();
195 -
196 - if (isset($possibleValues['xsendfile']) === false) {
197 - return;
286 + if (isset($possibleValues['xsendfile']) === true) {
287 + $possibleValues['xsendfile']->markDisabled();
288 + }
198 289 }
199 -
200 - if ($this->wordpress->isNginx() === true) {
201 - // X-Accel-Redirect is always available on nginx — just relabel the option.
202 - $possibleValues['xsendfile']->setLabel(TXT_UAM_DOWNLOAD_TYPE_XACCELREDIRECT);
203 - } elseif ($this->isXSendFileAvailable() === false) {
204 - $possibleValues['xsendfile']->markDisabled();
205 - }
206 290 }
207 291
208 - private function addLockFileTypes(array $configParameters, array &$parameters): void
292 + /**
293 + * Adds the lock file types config parameter to the parameters.
294 + * @param array $configParameters
295 + * @param array $parameters
296 + */
297 + private function addLockFileTypes(array $configParameters, array &$parameters)
209 298 {
210 - if (isset($configParameters['lock_file_types']) === true) {
299 + if (isset($configParameters['lock_file_types']) === true
300 + && $this->wordpress->isNginx() === false
301 + ) {
211 302 $parameters['lock_file_types'] = [
212 303 'selected' => 'locked_file_types',
213 304 'not_selected' => 'not_locked_file_types'
214 305 ];
215 306
216 - if ($this->wordpress->isNginx() === false
217 - && $this->wordpress->gotModRewrite() === false
218 - ) {
307 + if ($this->wordpress->gotModRewrite() === false) {
219 308 $parameters[] = 'file_pass_type';
220 309 }
221 310 }
222 311 }
@@ -221,8 +310,10 @@
221 310 }
222 311 }
223 312
224 313 /**
314 + * Returns the files settings form.
315 + * @return Form
225 316 * @throws Exception
226 317 */
227 318 private function getFilesSettingsForm(): Form
228 319 {
@@ -250,14 +341,18 @@
250 341 $this->addLockFileTypes($configParameters, $parameters);
251 342
252 343 $form = $this->formHelper->getSettingsForm($parameters);
253 344
254 - $this->configureXSendFileOption($form);
345 + if ($this->isXSendFileAvailable() === false) {
346 + $this->disableXSendFileOption($form);
347 + }
255 348
256 349 return $form;
257 350 }
258 351
259 352 /**
353 + * Returns the author settings form.
354 + * @return Form
260 355 * @throws Exception
261 356 */
262 357 private function getAuthorSettingsForm(): Form
263 358 {
@@ -269,9 +364,14 @@
269 364
270 365 return $this->formHelper->getSettingsForm($parameters);
271 366 }
272 367
273 - private function addCustomPageRedirectFormElement(array $configParameters, array &$values): void
368 + /**
369 + * Adds the custom page redirect from element.
370 + * @param array $configParameters
371 + * @param array $values
372 + */
373 + private function addCustomPageRedirectFormElement(array $configParameters, array &$values)
274 374 {
275 375 if (isset($configParameters['redirect_custom_page']) === true) {
276 376 $redirectCustomPage = $configParameters['redirect_custom_page'];
277 377 $redirectCustomPageValue = $this->formFactory->createMultipleFormElementValue(
@@ -297,14 +397,17 @@
297 397
298 398 try {
299 399 $redirectCustomPageValue->setSubElement($formElement);
300 400 $values[] = $redirectCustomPageValue;
301 - } catch (Exception) {
401 + } catch (Exception $exception) {
402 + // Do Nothing
302 403 }
303 404 }
304 405 }
305 406
306 407 /**
408 + * Returns the author settings form.
409 + * @return Form
307 410 * @throws Exception
308 411 */
309 412 private function getOtherSettingsForm(): Form
310 413 {
@@ -314,10 +417,9 @@
314 417 if (isset($configParameters['redirect'])) {
315 418 $values = [
316 419 $this->formFactory->createMultipleFormElementValue('false', TXT_UAM_NO),
317 420 $this->formFactory->createMultipleFormElementValue('blog', TXT_UAM_REDIRECT_TO_BLOG),
318 - $this->formFactory->createMultipleFormElementValue('login', TXT_UAM_REDIRECT_TO_LOGIN),
319 - $this->formFactory->createMultipleFormElementValue('origin', TXT_UAM_REDIRECT_TO_ORIGIN)
421 + $this->formFactory->createMultipleFormElementValue('login', TXT_UAM_REDIRECT_TO_LOGIN)
320 422 ];
321 423
322 424 $this->addCustomPageRedirectFormElement($configParameters, $values);
323 425
@@ -327,9 +429,10 @@
327 429 'custom_url',
328 430 TXT_UAM_REDIRECT_TO_URL,
329 431 $configParameters['redirect_custom_url']
330 432 );
331 - } catch (Exception) {
433 + } catch (Exception $exception) {
434 + // Do nothing.
332 435 }
333 436 }
334 437
335 438 $configParameter = $configParameters['redirect'];
@@ -349,15 +452,21 @@
349 452 $redirect,
350 453 'blog_admin_hint',
351 454 'blog_admin_hint_text',
352 455 'show_assigned_groups',
353 - 'hide_edit_link_on_no_access',
354 - 'extra_ip_header'
456 + 'hide_edit_link_on_no_access'
355 457 ];
356 458
357 459 return $this->formHelper->getSettingsForm($parameters);
358 460 }
359 461
462 + /**
463 + * Returns the full settings from.
464 + * @param array $types
465 + * @param array $ignoredTypes
466 + * @param Callable $formFunction
467 + * @return array
468 + */
360 469 private function getFullSettingsFrom(array $types, array $ignoredTypes, callable $formFunction): array
361 470 {
362 471 $groupForms = [];
363 472 $groupForms[MainConfig::DEFAULT_TYPE] = $formFunction();
@@ -373,8 +482,10 @@
373 482 return $groupForms;
374 483 }
375 484
376 485 /**
486 + * Returns the full taxonomy post forms.
487 + * @return array
377 488 * @throws Exception
378 489 */
379 490 private function getFullPostSettingsForm(): array
380 491 {
@@ -387,8 +498,10 @@
387 498 );
388 499 }
389 500
390 501 /**
502 + * Returns the full taxonomy settings forms.
503 + * @return array
391 504 * @throws Exception
392 505 */
393 506 private function getFullTaxonomySettingsForm(): array
394 507 {
@@ -401,8 +514,10 @@
401 514 );
402 515 }
403 516
404 517 /**
518 + * Returns the full cache providers froms.
519 + * @return array
405 520 * @throws Exception
406 521 */
407 522 private function getFullCacheProvidersForm(): array
408 523 {
@@ -419,8 +534,9 @@
419 534 return $groupForms;
420 535 }
421 536
422 537 /**
538 + * Returns the current settings form.
423 539 * @return Form[]
424 540 */
425 541 public function getCurrentGroupForms(): array
426 542 {
@@ -457,9 +573,13 @@
457 573
458 574 return [];
459 575 }
460 576
461 - private function updateFileProtectionFile(array $configParameters): void
577 + /**
578 + * Updates the file handling file.
579 + * @param array $configParameters
580 + */
581 + private function updateFileProtectionFile(array $configParameters)
462 582 {
463 583 $key = 'custom_file_handling_file';
464 584 $customFileHandlingFile = isset($configParameters[$key]) === true ? $configParameters[$key] : null;
465 585 unset($configParameters[$key]);
@@ -477,9 +597,12 @@
477 597 );
478 598 }
479 599 }
480 600
481 - public function updateSettingsAction(): void
601 + /**
602 + * Update settings action.
603 + */
604 + public function updateSettingsAction()
482 605 {
483 606 $this->verifyNonce('uamUpdateSettings');
484 607 $group = $this->getCurrentTabGroup();
485 608 $newConfigParameters = $this->getRequestParameter('config_parameters');
@@ -500,8 +623,13 @@
500 623 $this->wordpress->doAction('uam_update_options', $this->mainConfig);
501 624 $this->setUpdateMessage(TXT_UAM_UPDATE_SETTINGS);
502 625 }
503 626
627 + /**
628 + * Checks if the group is a post type.
629 + * @param string $key
630 + * @return bool
631 + */
504 632 public function isPostTypeGroup(string $key): bool
505 633 {
506 634 $postTypes = $this->getPostTypes();
507 635