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