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