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