PluginProbe
User Access Manager / 2.1.7
User Access Manager v2.1.7
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.7, at src/Config/MainConfig.php

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