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