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