PluginProbe
User Access Manager / 2.1.10
User Access Manager v2.1.10
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
user-access-manager / src / Config / MainConfig.php

MainConfig.php in User Access Manager 2.1.10, at src/Config/MainConfig.php

639 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 */
15 namespace UserAccessManager\Config;
16
17 use UserAccessManager\Cache\Cache;
18 use UserAccessManager\Object\ObjectHandler;
19 use UserAccessManager\Wrapper\Wordpress;
20
21 /**
22 * Class Config
23 *
24 * @package UserAccessManager\Config
25 */
26 class MainConfig extends Config
27 {
28 const MAIN_CONFIG_KEY = 'uamAdminOptions';
29 const DEFAULT_TYPE = 'default';
30 const CACHE_PROVIDER_NONE = 'none';
31
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 /**
48 * MainConfig constructor.
49 *
50 * @param Wordpress $wordpress
51 * @param ObjectHandler $objectHandler
52 * @param Cache $cache
53 * @param ConfigParameterFactory $configParameterFactory
54 */
55 public function __construct(
56 Wordpress $wordpress,
57 ObjectHandler $objectHandler,
58 Cache $cache,
59 ConfigParameterFactory $configParameterFactory
60 ) {
61 $this->objectHandler = $objectHandler;
62 $this->cache = $cache;
63 $this->configParameterFactory = $configParameterFactory;
64
65 parent::__construct($wordpress, self::MAIN_CONFIG_KEY);
66 }
67
68 /**
69 * Adds the default general config parameters to the config parameters.
70 *
71 * @param array $configParameters
72 */
73 private function addDefaultGeneralConfigParameters(array &$configParameters)
74 {
75 $id = 'redirect';
76 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
77 $id,
78 'false',
79 ['false', 'blog', 'login', 'custom_page', 'custom_url']
80 );
81
82 $id = 'redirect_custom_page';
83 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
84
85 $id = 'redirect_custom_url';
86 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
87
88 $id = 'lock_recursive';
89 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
90
91 $id = 'authors_has_access_to_own';
92 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
93
94 $id = 'authors_can_add_posts_to_groups';
95 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
96
97 $id = 'blog_admin_hint';
98 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
99
100 $id = 'blog_admin_hint_text';
101 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, '[L]');
102
103 $id = 'show_assigned_groups';
104 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
105
106 $id = 'hide_edit_link_on_no_access';
107 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
108
109 $id = 'protect_feed';
110 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
111
112 $id = 'full_access_role';
113 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
114 $id,
115 'administrator',
116 ['administrator', 'editor', 'author', 'contributor', 'subscriber']
117 );
118
119 $id = 'active_cache_provider';
120 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
121 $id,
122 self::CACHE_PROVIDER_NONE,
123 array_merge([self::CACHE_PROVIDER_NONE], array_keys($this->cache->getRegisteredCacheProviders()))
124 );
125 }
126
127 /**
128 * Adds the default post config parameters to the config parameters.
129 *
130 * @param array $configParameters
131 */
132 private function addDefaultPostConfigParameters(array &$configParameters)
133 {
134 $postTypes = $this->objectHandler->getPostTypes();
135 array_unshift($postTypes, self::DEFAULT_TYPE);
136
137 foreach ($postTypes as $postType) {
138 if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
139 continue;
140 }
141
142 if ($postType !== self::DEFAULT_TYPE) {
143 $id = "{$postType}_use_default";
144 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
145 }
146
147 $id = "hide_{$postType}";
148 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
149
150 $id = "hide_{$postType}_title";
151 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
152
153 $id = "{$postType}_title";
154 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
155 $id,
156 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS
157 );
158
159 $id = "{$postType}_content";
160 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
161 $id,
162 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_ENTRY
163 );
164
165 $id = "hide_{$postType}_comment";
166 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
167
168 $id = "{$postType}_comment_content";
169 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
170 $id,
171 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_COMMENTS
172 );
173
174 $id = "{$postType}_comments_locked";
175 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
176
177 $id = "show_{$postType}_content_before_more";
178 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
179 }
180 }
181
182 /**
183 * Adds the default taxonomy config parameters to the config parameters.
184 *
185 * @param array $configParameters
186 */
187 private function addDefaultTaxonomyConfigParameters(array &$configParameters)
188 {
189 $taxonomies = $this->objectHandler->getTaxonomies();
190 array_unshift($taxonomies, self::DEFAULT_TYPE);
191
192 foreach ($taxonomies as $taxonomy) {
193 if ($taxonomy !== self::DEFAULT_TYPE) {
194 $id = "{$taxonomy}_use_default";
195 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
196 }
197
198 $id = 'hide_empty_'.$taxonomy;
199 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
200 }
201 }
202
203 /**
204 * Adds the default file config parameters to the config parameters.
205 *
206 * @param array $configParameters
207 */
208 private function addDefaultFileConfigParameters(array &$configParameters)
209 {
210 $id = 'lock_file';
211 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
212
213 $id = 'download_type';
214 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
215 $id,
216 'fopen',
217 ['xsendfile', 'fopen', 'normal']
218 );
219
220 $id = 'inline_files';
221 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, 'pdf');
222
223 $id = 'no_access_image_type';
224 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
225 $id,
226 'default',
227 ['default', 'custom']
228 );
229
230 $id = 'custom_no_access_image';
231 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
232
233 $id = 'use_custom_file_handling_file';
234 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
235
236 $id = 'locked_directory_type';
237 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
238 $id,
239 'wordpress',
240 ['wordpress', 'all', 'custom']
241 );
242
243 $id = 'custom_locked_directories';
244 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
245
246 $id = 'file_pass_type';
247 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
248 $id,
249 'random',
250 ['random', 'user']
251 );
252
253 $id = 'lock_file_types';
254 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
255 $id,
256 'all',
257 ['all', 'selected', 'not_selected']
258 );
259
260 $id = 'locked_file_types';
261 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
262 $id,
263 'zip,rar,tar,gz'
264 );
265
266 $id = 'not_locked_file_types';
267 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
268 $id,
269 'gif,jpg,jpeg,png'
270 );
271 }
272
273 /**
274 * Returns the default config parameters settings
275 *
276 * @return ConfigParameter[]
277 */
278 protected function getDefaultConfigParameters()
279 {
280 if ($this->defaultConfigParameters === []) {
281 /**
282 * @var ConfigParameter[] $configParameters
283 */
284 $configParameters = [];
285
286 $this->addDefaultGeneralConfigParameters($configParameters);
287 $this->addDefaultPostConfigParameters($configParameters);
288 $this->addDefaultTaxonomyConfigParameters($configParameters);
289 $this->addDefaultFileConfigParameters($configParameters);
290
291 $this->defaultConfigParameters = $configParameters;
292 }
293
294 return $this->defaultConfigParameters;
295 }
296
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)
306 {
307 $options = $this->getConfigParameters();
308 $parameterName = sprintf($rawParameterName, $objectType);
309
310 if (isset($options[$parameterName]) === false
311 || isset($options["{$objectType}_use_default"]) === true
312 && $options["{$objectType}_use_default"]->getValue() === true
313 ) {
314 $parameterName = sprintf($rawParameterName, self::DEFAULT_TYPE);
315 }
316
317 return (isset($options[$parameterName]) === true) ? $options[$parameterName] : null;
318 }
319
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)
329 {
330 $parameter = $this->getObjectParameter($objectType, $parameterName);
331 return ($parameter !== null) ? $parameter->getValue() : true;
332 }
333
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)
343 {
344 $parameter = $this->getObjectParameter($objectType, $parameterName);
345 return ($parameter !== null) ? $parameter->getValue() : '';
346 }
347
348 /**
349 * @param string $postType
350 *
351 * @return bool
352 */
353 public function hidePostType($postType)
354 {
355 return $this->hideObject($postType, 'hide_%s');
356 }
357
358 /**
359 * @param string $postType
360 *
361 * @return bool
362 */
363 public function hidePostTypeTitle($postType)
364 {
365 return $this->hideObject($postType, 'hide_%s_title');
366 }
367
368 /**
369 * @param string $postType
370 *
371 * @return bool
372 */
373 public function hidePostTypeComments($postType)
374 {
375 return $this->hideObject($postType, 'hide_%s_comment');
376 }
377
378 /**
379 * @param string $postType
380 *
381 * @return bool
382 */
383 public function lockPostTypeComments($postType)
384 {
385 return $this->hideObject($postType, '%s_comments_locked');
386 }
387
388 /**
389 * @param string $postType
390 *
391 * @return string
392 */
393 public function getPostTypeTitle($postType)
394 {
395 return $this->getObjectContent($postType, '%s_title');
396 }
397
398 /**
399 * @param string $postType
400 *
401 * @return string
402 */
403 public function getPostTypeContent($postType)
404 {
405 return $this->getObjectContent($postType, '%s_content');
406 }
407
408 /**
409 * @param string $postType
410 *
411 * @return string
412 */
413 public function getPostTypeCommentContent($postType)
414 {
415 return $this->getObjectContent($postType, '%s_comment_content');
416 }
417
418 /**
419 * @param string $postType
420 *
421 * @return bool
422 */
423 public function showPostTypeContentBeforeMore($postType)
424 {
425 return $this->getObjectContent($postType, 'show_%s_content_before_more');
426 }
427
428 /**
429 * @return string
430 */
431 public function getRedirect()
432 {
433 return $this->getParameterValue('redirect');
434 }
435
436 /**
437 * @return string
438 */
439 public function getRedirectCustomPage()
440 {
441 return $this->getParameterValue('redirect_custom_page');
442 }
443
444 /**
445 * @return string
446 */
447 public function getRedirectCustomUrl()
448 {
449 return $this->getParameterValue('redirect_custom_url');
450 }
451
452 /**
453 * @return bool
454 */
455 public function lockRecursive()
456 {
457 return $this->getParameterValue('lock_recursive');
458 }
459
460 /**
461 * @return bool
462 */
463 public function authorsHasAccessToOwn()
464 {
465 return $this->getParameterValue('authors_has_access_to_own');
466 }
467
468 /**
469 * @return bool
470 */
471 public function authorsCanAddPostsToGroups()
472 {
473 return $this->getParameterValue('authors_can_add_posts_to_groups');
474 }
475
476 /**
477 * @return bool
478 */
479 public function lockFile()
480 {
481 return $this->getParameterValue('lock_file');
482 }
483
484 /**
485 * @return string
486 */
487 public function getInlineFiles()
488 {
489 return $this->getParameterValue('inline_files');
490 }
491
492 /**
493 * @return string
494 */
495 public function getNoAccessImageType()
496 {
497 return $this->getParameterValue('no_access_image_type');
498 }
499
500 /**
501 * @return string
502 */
503 public function getCustomNoAccessImage()
504 {
505 return $this->getParameterValue('custom_no_access_image');
506 }
507
508 /**
509 * @return bool
510 */
511 public function useCustomFileHandlingFile()
512 {
513 return $this->getParameterValue('use_custom_file_handling_file');
514 }
515
516 /**
517 * @return string
518 */
519 public function getLockedDirectoryType()
520 {
521 return $this->getParameterValue('locked_directory_type');
522 }
523
524 /**
525 * @return string
526 */
527 public function getCustomLockedDirectories()
528 {
529 return $this->getParameterValue('custom_locked_directories');
530 }
531
532 /**
533 * @return string
534 */
535 public function getFilePassType()
536 {
537 return $this->getParameterValue('file_pass_type');
538 }
539
540 /**
541 * @return string
542 */
543 public function getDownloadType()
544 {
545 return $this->getParameterValue('download_type');
546 }
547
548 /**
549 * @return string
550 */
551 public function getLockedFileType()
552 {
553 return $this->getParameterValue('lock_file_types');
554 }
555
556 /**
557 * @return string
558 */
559 public function getLockedFiles()
560 {
561 return $this->getParameterValue('locked_file_types');
562 }
563
564 /**
565 * @return string
566 */
567 public function getNotLockedFiles()
568 {
569 return $this->getParameterValue('not_locked_file_types');
570 }
571
572 /**
573 * @return bool
574 */
575 public function blogAdminHint()
576 {
577 return $this->getParameterValue('blog_admin_hint');
578 }
579
580 /**
581 * @return string
582 */
583 public function getBlogAdminHintText()
584 {
585 return $this->getParameterValue('blog_admin_hint_text');
586 }
587
588 /**
589 * @return bool
590 */
591 public function showAssignedGroups()
592 {
593 return $this->getParameterValue('show_assigned_groups');
594 }
595
596 /**
597 * @return bool
598 */
599 public function hideEditLinkOnNoAccess()
600 {
601 return $this->getParameterValue('hide_edit_link_on_no_access');
602 }
603
604 /**
605 * @param string $taxonomy
606 *
607 * @return bool
608 */
609 public function hideEmptyTaxonomy($taxonomy)
610 {
611 $parameter = $this->getObjectParameter($taxonomy, 'hide_empty_%s');
612 return ($parameter !== null) ? $parameter->getValue() : false;
613 }
614
615 /**
616 * @return bool
617 */
618 public function protectFeed()
619 {
620 return $this->getParameterValue('protect_feed');
621 }
622
623 /**
624 * @return string
625 */
626 public function getFullAccessRole()
627 {
628 return $this->getParameterValue('full_access_role');
629 }
630
631 /**
632 * @return null|string
633 */
634 public function getActiveCacheProvider()
635 {
636 return $this->getParameterValue('active_cache_provider');
637 }
638 }
639