PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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/Config/MainConfig.php +260 -81 2.3.13 → 2.1.11 View file →
@@ -1,41 +1,77 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * Config.php
4 + *
5 + * The Config class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\Config;
6 16
7 -use Exception;
8 17 use UserAccessManager\Cache\Cache;
9 18 use UserAccessManager\Object\ObjectHandler;
10 19 use UserAccessManager\Wrapper\Wordpress;
11 20
21 +/**
22 + * Class Config
23 + *
24 + * @package UserAccessManager\Config
25 + */
12 26 class MainConfig extends Config
13 27 {
14 - public const MAIN_CONFIG_KEY = 'uamAdminOptions';
15 - public const DEFAULT_TYPE = 'default';
16 - public const CACHE_PROVIDER_NONE = 'none';
28 + const MAIN_CONFIG_KEY = 'uamAdminOptions';
29 + const DEFAULT_TYPE = 'default';
30 + const CACHE_PROVIDER_NONE = 'none';
17 31
18 32 /**
33 + * @var ObjectHandler
34 + */
35 + private $objectHandler;
36 +
37 + /**
38 + * @var Cache
39 + */
40 + private $cache;
41 +
42 + /**
43 + * @var ConfigParameterFactory
44 + */
45 + protected $configParameterFactory;
46 +
47 + /**
19 48 * MainConfig constructor.
20 - * @param Wordpress $wordpress
21 - * @param ObjectHandler $objectHandler
22 - * @param Cache $cache
49 + *
50 + * @param Wordpress $wordpress
51 + * @param ObjectHandler $objectHandler
52 + * @param Cache $cache
23 53 * @param ConfigParameterFactory $configParameterFactory
24 54 */
25 55 public function __construct(
26 56 Wordpress $wordpress,
27 - private ObjectHandler $objectHandler,
28 - private Cache $cache,
29 - private ConfigParameterFactory $configParameterFactory
57 + ObjectHandler $objectHandler,
58 + Cache $cache,
59 + ConfigParameterFactory $configParameterFactory
30 60 ) {
61 + $this->objectHandler = $objectHandler;
62 + $this->cache = $cache;
63 + $this->configParameterFactory = $configParameterFactory;
64 +
31 65 parent::__construct($wordpress, self::MAIN_CONFIG_KEY);
32 66 }
33 67
34 68 /**
35 - * @throws Exception
69 + * Adds the default general config parameters to the config parameters.
70 + *
71 + * @param array $configParameters
36 72 */
37 - private function addDefaultGeneralConfigParameters(array &$configParameters): void
73 + private function addDefaultGeneralConfigParameters(array &$configParameters)
38 74 {
39 75 $id = 'redirect';
40 76 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
41 77 $id,
@@ -69,11 +105,8 @@
69 105
70 106 $id = 'hide_edit_link_on_no_access';
71 107 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
72 108
73 - $id = 'extra_ip_header';
74 - $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, 'HTTP_X_REAL_IP');
75 -
76 109 $id = 'protect_feed';
77 110 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
78 111
79 112 $id = 'full_access_role';
@@ -91,11 +124,13 @@
91 124 );
92 125 }
93 126
94 127 /**
95 - * @throws Exception
128 + * Adds the default post config parameters to the config parameters.
129 + *
130 + * @param array $configParameters
96 131 */
97 - private function addDefaultPostConfigParameters(array &$configParameters): void
132 + private function addDefaultPostConfigParameters(array &$configParameters)
98 133 {
99 134 $postTypes = $this->objectHandler->getPostTypes();
100 135 array_unshift($postTypes, self::DEFAULT_TYPE);
101 136
@@ -108,9 +143,9 @@
108 143 $id = "{$postType}_use_default";
109 144 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
110 145 }
111 146
112 - $id = "hide_$postType";
147 + $id = "hide_{$postType}";
113 148 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
114 149
115 150 $id = "hide_{$postType}_title";
116 151 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
@@ -144,11 +179,13 @@
144 179 }
145 180 }
146 181
147 182 /**
148 - * @throws Exception
183 + * Adds the default taxonomy config parameters to the config parameters.
184 + *
185 + * @param array $configParameters
149 186 */
150 - private function addDefaultTaxonomyConfigParameters(array &$configParameters): void
187 + private function addDefaultTaxonomyConfigParameters(array &$configParameters)
151 188 {
152 189 $taxonomies = $this->objectHandler->getTaxonomies();
153 190 array_unshift($taxonomies, self::DEFAULT_TYPE);
154 191
@@ -157,17 +194,19 @@
157 194 $id = "{$taxonomy}_use_default";
158 195 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
159 196 }
160 197
161 - $id = 'hide_empty_' . $taxonomy;
198 + $id = 'hide_empty_'.$taxonomy;
162 199 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
163 200 }
164 201 }
165 202
166 203 /**
167 - * @throws Exception
204 + * Adds the default file config parameters to the config parameters.
205 + *
206 + * @param array $configParameters
168 207 */
169 - private function addDefaultFileConfigParameters(array &$configParameters): void
208 + private function addDefaultFileConfigParameters(array &$configParameters)
170 209 {
171 210 $id = 'lock_file';
172 211 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
173 212
@@ -231,12 +270,13 @@
231 270 );
232 271 }
233 272
234 273 /**
274 + * Returns the default config parameters settings
275 + *
235 276 * @return ConfigParameter[]
236 - * @throws Exception
237 277 */
238 - protected function getDefaultConfigParameters(): array
278 + protected function getDefaultConfigParameters()
239 279 {
240 280 if ($this->defaultConfigParameters === []) {
241 281 /**
242 282 * @var ConfigParameter[] $configParameters
@@ -253,9 +293,17 @@
253 293
254 294 return $this->defaultConfigParameters;
255 295 }
256 296
257 - private function getObjectParameter(string $objectType, string $rawParameterName): ?ConfigParameter
297 + /**
298 + * Returns the object parameter name.
299 + *
300 + * @param string $objectType
301 + * @param string $rawParameterName
302 + *
303 + * @return ConfigParameter|null
304 + */
305 + private function getObjectParameter($objectType, $rawParameterName)
258 306 {
259 307 $options = $this->getConfigParameters();
260 308 $parameterName = sprintf($rawParameterName, $objectType);
261 309
@@ -260,9 +308,9 @@
260 308 $parameterName = sprintf($rawParameterName, $objectType);
261 309
262 310 if (isset($options[$parameterName]) === false
263 311 || isset($options["{$objectType}_use_default"]) === true
264 - && $options["{$objectType}_use_default"]->getValue() === true
312 + && $options["{$objectType}_use_default"]->getValue() === true
265 313 ) {
266 314 $parameterName = sprintf($rawParameterName, self::DEFAULT_TYPE);
267 315 }
268 316
@@ -268,192 +316,323 @@
268 316
269 317 return (isset($options[$parameterName]) === true) ? $options[$parameterName] : null;
270 318 }
271 319
272 - private function hideObject(string $objectType, string $parameterName): bool
320 + /**
321 + * Returns the option value if the option exists otherwise true.
322 + *
323 + * @param string $objectType
324 + * @param string $parameterName
325 + *
326 + * @return bool
327 + */
328 + private function hideObject($objectType, $parameterName)
273 329 {
274 330 $parameter = $this->getObjectParameter($objectType, $parameterName);
275 331 return ($parameter !== null) ? $parameter->getValue() : true;
276 332 }
277 333
278 - private function getObjectContent(string $objectType, string $parameterName): bool|string
334 + /**
335 + * Returns the option value if the option exists otherwise an empty string.
336 + *
337 + * @param string $objectType
338 + * @param string $parameterName
339 + *
340 + * @return string
341 + */
342 + private function getObjectContent($objectType, $parameterName)
279 343 {
280 344 $parameter = $this->getObjectParameter($objectType, $parameterName);
281 345 return ($parameter !== null) ? $parameter->getValue() : '';
282 346 }
283 347
284 - public function hidePostType(string $postType): bool
348 + /**
349 + * @param string $postType
350 + *
351 + * @return bool
352 + */
353 + public function hidePostType($postType)
285 354 {
286 355 return $this->hideObject($postType, 'hide_%s');
287 356 }
288 357
289 - public function hidePostTypeTitle(string $postType): bool
358 + /**
359 + * @param string $postType
360 + *
361 + * @return bool
362 + */
363 + public function hidePostTypeTitle($postType)
290 364 {
291 365 return $this->hideObject($postType, 'hide_%s_title');
292 366 }
293 367
294 - public function hidePostTypeComments(string $postType): bool
368 + /**
369 + * @param string $postType
370 + *
371 + * @return bool
372 + */
373 + public function hidePostTypeComments($postType)
295 374 {
296 375 return $this->hideObject($postType, 'hide_%s_comment');
297 376 }
298 377
299 - public function lockPostTypeComments(string $postType): bool
378 + /**
379 + * @param string $postType
380 + *
381 + * @return bool
382 + */
383 + public function lockPostTypeComments($postType)
300 384 {
301 385 return $this->hideObject($postType, '%s_comments_locked');
302 386 }
303 387
304 - public function getPostTypeTitle(string $postType): string
388 + /**
389 + * @param string $postType
390 + *
391 + * @return string
392 + */
393 + public function getPostTypeTitle($postType)
305 394 {
306 395 return $this->getObjectContent($postType, '%s_title');
307 396 }
308 397
309 - public function getPostTypeContent(string $postType): string
398 + /**
399 + * @param string $postType
400 + *
401 + * @return string
402 + */
403 + public function getPostTypeContent($postType)
310 404 {
311 405 return $this->getObjectContent($postType, '%s_content');
312 406 }
313 407
314 - public function getPostTypeCommentContent(string $postType): string
408 + /**
409 + * @param string $postType
410 + *
411 + * @return string
412 + */
413 + public function getPostTypeCommentContent($postType)
315 414 {
316 415 return $this->getObjectContent($postType, '%s_comment_content');
317 416 }
318 417
319 - public function showPostTypeContentBeforeMore(string $postType): bool
418 + /**
419 + * @param string $postType
420 + *
421 + * @return bool
422 + */
423 + public function showPostTypeContentBeforeMore($postType)
320 424 {
321 - return (bool) $this->getObjectContent($postType, 'show_%s_content_before_more');
425 + return $this->getObjectContent($postType, 'show_%s_content_before_more');
322 426 }
323 427
324 - public function getRedirect(): ?string
428 + /**
429 + * @return string
430 + */
431 + public function getRedirect()
325 432 {
326 433 return $this->getParameterValue('redirect');
327 434 }
328 435
329 - public function getRedirectCustomPage(): ?string
436 + /**
437 + * @return string
438 + */
439 + public function getRedirectCustomPage()
330 440 {
331 441 return $this->getParameterValue('redirect_custom_page');
332 442 }
333 443
334 - public function getRedirectCustomUrl(): ?string
444 + /**
445 + * @return string
446 + */
447 + public function getRedirectCustomUrl()
335 448 {
336 449 return $this->getParameterValue('redirect_custom_url');
337 450 }
338 451
339 - public function lockRecursive(): bool
452 + /**
453 + * @return bool
454 + */
455 + public function lockRecursive()
340 456 {
341 - return (bool) $this->getParameterValue('lock_recursive');
457 + return $this->getParameterValue('lock_recursive');
342 458 }
343 459
344 - public function authorsHasAccessToOwn(): bool
460 + /**
461 + * @return bool
462 + */
463 + public function authorsHasAccessToOwn()
345 464 {
346 - return (bool) $this->getParameterValue('authors_has_access_to_own');
465 + return $this->getParameterValue('authors_has_access_to_own');
347 466 }
348 467
349 - public function authorsCanAddPostsToGroups(): bool
468 + /**
469 + * @return bool
470 + */
471 + public function authorsCanAddPostsToGroups()
350 472 {
351 - return (bool) $this->getParameterValue('authors_can_add_posts_to_groups');
473 + return $this->getParameterValue('authors_can_add_posts_to_groups');
352 474 }
353 475
354 - public function lockFile(): bool
476 + /**
477 + * @return bool
478 + */
479 + public function lockFile()
355 480 {
356 - return (bool) $this->getParameterValue('lock_file');
481 + return $this->getParameterValue('lock_file');
357 482 }
358 483
359 - public function getInlineFiles(): ?string
484 + /**
485 + * @return string
486 + */
487 + public function getInlineFiles()
360 488 {
361 489 return $this->getParameterValue('inline_files');
362 490 }
363 491
364 - public function getNoAccessImageType(): ?string
492 + /**
493 + * @return string
494 + */
495 + public function getNoAccessImageType()
365 496 {
366 497 return $this->getParameterValue('no_access_image_type');
367 498 }
368 499
369 - public function getCustomNoAccessImage(): ?string
500 + /**
501 + * @return string
502 + */
503 + public function getCustomNoAccessImage()
370 504 {
371 505 return $this->getParameterValue('custom_no_access_image');
372 506 }
373 507
374 - public function useCustomFileHandlingFile(): bool
508 + /**
509 + * @return bool
510 + */
511 + public function useCustomFileHandlingFile()
375 512 {
376 - return (bool) $this->getParameterValue('use_custom_file_handling_file');
513 + return $this->getParameterValue('use_custom_file_handling_file');
377 514 }
378 515
379 - public function getLockedDirectoryType(): ?string
516 + /**
517 + * @return string
518 + */
519 + public function getLockedDirectoryType()
380 520 {
381 521 return $this->getParameterValue('locked_directory_type');
382 522 }
383 523
384 - public function getCustomLockedDirectories(): ?string
524 + /**
525 + * @return string
526 + */
527 + public function getCustomLockedDirectories()
385 528 {
386 529 return $this->getParameterValue('custom_locked_directories');
387 530 }
388 531
389 - public function getFilePassType(): ?string
532 + /**
533 + * @return string
534 + */
535 + public function getFilePassType()
390 536 {
391 537 return $this->getParameterValue('file_pass_type');
392 538 }
393 539
394 - public function getDownloadType(): ?string
540 + /**
541 + * @return string
542 + */
543 + public function getDownloadType()
395 544 {
396 545 return $this->getParameterValue('download_type');
397 546 }
398 547
399 - public function getLockedFileType(): ?string
548 + /**
549 + * @return string
550 + */
551 + public function getLockedFileType()
400 552 {
401 553 return $this->getParameterValue('lock_file_types');
402 554 }
403 555
404 - public function getLockedFiles(): ?string
556 + /**
557 + * @return string
558 + */
559 + public function getLockedFiles()
405 560 {
406 561 return $this->getParameterValue('locked_file_types');
407 562 }
408 563
409 - public function getNotLockedFiles(): ?string
564 + /**
565 + * @return string
566 + */
567 + public function getNotLockedFiles()
410 568 {
411 569 return $this->getParameterValue('not_locked_file_types');
412 570 }
413 571
414 - public function blogAdminHint(): bool
572 + /**
573 + * @return bool
574 + */
575 + public function blogAdminHint()
415 576 {
416 - return (bool) $this->getParameterValue('blog_admin_hint');
577 + return $this->getParameterValue('blog_admin_hint');
417 578 }
418 579
419 - public function getBlogAdminHintText(): ?string
580 + /**
581 + * @return string
582 + */
583 + public function getBlogAdminHintText()
420 584 {
421 585 return $this->getParameterValue('blog_admin_hint_text');
422 586 }
423 587
424 - public function showAssignedGroups(): bool
588 + /**
589 + * @return bool
590 + */
591 + public function showAssignedGroups()
425 592 {
426 - return (bool) $this->getParameterValue('show_assigned_groups');
593 + return $this->getParameterValue('show_assigned_groups');
427 594 }
428 595
429 - public function hideEditLinkOnNoAccess(): bool
596 + /**
597 + * @return bool
598 + */
599 + public function hideEditLinkOnNoAccess()
430 600 {
431 - return (bool) $this->getParameterValue('hide_edit_link_on_no_access');
601 + return $this->getParameterValue('hide_edit_link_on_no_access');
432 602 }
433 603
434 - public function hideEmptyTaxonomy(string $taxonomy): bool
604 + /**
605 + * @param string $taxonomy
606 + *
607 + * @return bool
608 + */
609 + public function hideEmptyTaxonomy($taxonomy)
435 610 {
436 611 $parameter = $this->getObjectParameter($taxonomy, 'hide_empty_%s');
437 612 return ($parameter !== null) ? $parameter->getValue() : false;
438 613 }
439 614
440 - public function protectFeed(): bool
615 + /**
616 + * @return bool
617 + */
618 + public function protectFeed()
441 619 {
442 - return (bool) $this->getParameterValue('protect_feed');
620 + return $this->getParameterValue('protect_feed');
443 621 }
444 622
445 - public function getFullAccessRole(): ?string
623 + /**
624 + * @return string
625 + */
626 + public function getFullAccessRole()
446 627 {
447 628 return $this->getParameterValue('full_access_role');
448 629 }
449 630
450 - public function getActiveCacheProvider(): ?string
631 + /**
632 + * @return null|string
633 + */
634 + public function getActiveCacheProvider()
451 635 {
452 636 return $this->getParameterValue('active_cache_provider');
453 - }
454 -
455 - public function getExtraIpHeader(): ?string
456 - {
457 - return $this->getParameterValue('extra_ip_header');
458 637 }
459 638 }