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

468 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Config;
6
7 use Exception;
8 use UserAccessManager\Cache\Cache;
9 use UserAccessManager\Object\ObjectHandler;
10 use UserAccessManager\Wrapper\Wordpress;
11
12 class MainConfig extends Config
13 {
14 public const MAIN_CONFIG_KEY = 'uamAdminOptions';
15 public const DEFAULT_TYPE = 'default';
16 public const CACHE_PROVIDER_NONE = 'none';
17
18 /**
19 * MainConfig constructor.
20 * @param Wordpress $wordpress
21 * @param ObjectHandler $objectHandler
22 * @param Cache $cache
23 * @param ConfigParameterFactory $configParameterFactory
24 */
25 public function __construct(
26 Wordpress $wordpress,
27 private ObjectHandler $objectHandler,
28 private Cache $cache,
29 private ConfigParameterFactory $configParameterFactory
30 ) {
31 parent::__construct($wordpress, self::MAIN_CONFIG_KEY);
32 }
33
34 /**
35 * @throws Exception
36 */
37 private function addDefaultGeneralConfigParameters(array &$configParameters): void
38 {
39 $id = 'redirect';
40 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
41 $id,
42 'false',
43 ['false', 'blog', 'login', 'custom_page', 'custom_url', 'origin']
44 );
45
46 $id = 'redirect_custom_page';
47 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
48
49 $id = 'redirect_custom_url';
50 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
51
52 $id = 'append_redirect_to_parameter';
53 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
54
55 $id = 'lock_recursive';
56 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
57
58 $id = 'authors_has_access_to_own';
59 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
60
61 $id = 'authors_can_add_posts_to_groups';
62 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
63
64 $id = 'blog_admin_hint';
65 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
66
67 $id = 'blog_admin_hint_text';
68 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, '[L]');
69
70 $id = 'show_assigned_groups';
71 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
72
73 $id = 'hide_edit_link_on_no_access';
74 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
75
76 $id = 'extra_ip_header';
77 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, 'HTTP_X_REAL_IP');
78
79 $id = 'protect_feed';
80 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
81
82 $id = 'full_access_role';
83 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
84 $id,
85 'administrator',
86 ['administrator', 'editor', 'author', 'contributor', 'subscriber']
87 );
88
89 $id = 'active_cache_provider';
90 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
91 $id,
92 self::CACHE_PROVIDER_NONE,
93 array_merge([self::CACHE_PROVIDER_NONE], array_keys($this->cache->getRegisteredCacheProviders()))
94 );
95 }
96
97 /**
98 * @throws Exception
99 */
100 private function addDefaultPostConfigParameters(array &$configParameters): void
101 {
102 $postTypes = $this->objectHandler->getPostTypes();
103 array_unshift($postTypes, self::DEFAULT_TYPE);
104
105 foreach ($postTypes as $postType) {
106 if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
107 continue;
108 }
109
110 if ($postType !== self::DEFAULT_TYPE) {
111 $id = "{$postType}_use_default";
112 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
113 }
114
115 $id = "hide_$postType";
116 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
117
118 $id = "hide_{$postType}_title";
119 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
120
121 $id = "{$postType}_title";
122 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
123 $id,
124 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS
125 );
126
127 $id = "{$postType}_content";
128 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
129 $id,
130 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_ENTRY
131 );
132
133 $id = "hide_{$postType}_comment";
134 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
135
136 $id = "{$postType}_comment_content";
137 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
138 $id,
139 TXT_UAM_SETTING_DEFAULT_NO_RIGHTS_FOR_COMMENTS
140 );
141
142 $id = "{$postType}_comments_locked";
143 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
144
145 $id = "show_{$postType}_content_before_more";
146 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
147 }
148 }
149
150 /**
151 * @throws Exception
152 */
153 private function addDefaultTaxonomyConfigParameters(array &$configParameters): void
154 {
155 $taxonomies = $this->objectHandler->getTaxonomies();
156 array_unshift($taxonomies, self::DEFAULT_TYPE);
157
158 foreach ($taxonomies as $taxonomy) {
159 if ($taxonomy !== self::DEFAULT_TYPE) {
160 $id = "{$taxonomy}_use_default";
161 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
162 }
163
164 $id = 'hide_empty_' . $taxonomy;
165 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id, true);
166 }
167 }
168
169 /**
170 * @throws Exception
171 */
172 private function addDefaultFileConfigParameters(array &$configParameters): void
173 {
174 $id = 'lock_file';
175 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
176
177 $id = 'download_type';
178 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
179 $id,
180 'fopen',
181 ['xsendfile', 'fopen', 'normal']
182 );
183
184 $id = 'inline_files';
185 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id, 'pdf');
186
187 $id = 'no_access_image_type';
188 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
189 $id,
190 'default',
191 ['default', 'custom']
192 );
193
194 $id = 'custom_no_access_image';
195 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
196
197 $id = 'use_custom_file_handling_file';
198 $configParameters[$id] = $this->configParameterFactory->createBooleanConfigParameter($id);
199
200 $id = 'locked_directory_type';
201 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
202 $id,
203 'wordpress',
204 ['wordpress', 'all', 'custom']
205 );
206
207 $id = 'custom_locked_directories';
208 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter($id);
209
210 $id = 'file_pass_type';
211 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
212 $id,
213 'random',
214 ['random', 'user']
215 );
216
217 $id = 'lock_file_types';
218 $configParameters[$id] = $this->configParameterFactory->createSelectionConfigParameter(
219 $id,
220 'all',
221 ['all', 'selected', 'not_selected']
222 );
223
224 $id = 'locked_file_types';
225 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
226 $id,
227 'zip,rar,tar,gz'
228 );
229
230 $id = 'not_locked_file_types';
231 $configParameters[$id] = $this->configParameterFactory->createStringConfigParameter(
232 $id,
233 'gif,jpg,jpeg,png'
234 );
235 }
236
237 /**
238 * @return ConfigParameter[]
239 * @throws Exception
240 */
241 protected function getDefaultConfigParameters(): array
242 {
243 if ($this->defaultConfigParameters === []) {
244 /**
245 * @var ConfigParameter[] $configParameters
246 */
247 $configParameters = [];
248
249 $this->addDefaultGeneralConfigParameters($configParameters);
250 $this->addDefaultPostConfigParameters($configParameters);
251 $this->addDefaultTaxonomyConfigParameters($configParameters);
252 $this->addDefaultFileConfigParameters($configParameters);
253
254 $this->defaultConfigParameters = $configParameters;
255 }
256
257 return $this->defaultConfigParameters;
258 }
259
260 private function getObjectParameter(string $objectType, string $rawParameterName): ?ConfigParameter
261 {
262 $options = $this->getConfigParameters();
263 $parameterName = sprintf($rawParameterName, $objectType);
264
265 if (isset($options[$parameterName]) === false
266 || isset($options["{$objectType}_use_default"]) === true
267 && $options["{$objectType}_use_default"]->getValue() === true
268 ) {
269 $parameterName = sprintf($rawParameterName, self::DEFAULT_TYPE);
270 }
271
272 return (isset($options[$parameterName]) === true) ? $options[$parameterName] : null;
273 }
274
275 private function hideObject(string $objectType, string $parameterName): bool
276 {
277 $parameter = $this->getObjectParameter($objectType, $parameterName);
278 return ($parameter !== null) ? $parameter->getValue() : true;
279 }
280
281 private function getObjectContent(string $objectType, string $parameterName): bool|string
282 {
283 $parameter = $this->getObjectParameter($objectType, $parameterName);
284 return ($parameter !== null) ? $parameter->getValue() : '';
285 }
286
287 public function hidePostType(string $postType): bool
288 {
289 return $this->hideObject($postType, 'hide_%s');
290 }
291
292 public function hidePostTypeTitle(string $postType): bool
293 {
294 return $this->hideObject($postType, 'hide_%s_title');
295 }
296
297 public function hidePostTypeComments(string $postType): bool
298 {
299 return $this->hideObject($postType, 'hide_%s_comment');
300 }
301
302 public function lockPostTypeComments(string $postType): bool
303 {
304 return $this->hideObject($postType, '%s_comments_locked');
305 }
306
307 public function getPostTypeTitle(string $postType): string
308 {
309 return $this->getObjectContent($postType, '%s_title');
310 }
311
312 public function getPostTypeContent(string $postType): string
313 {
314 return $this->getObjectContent($postType, '%s_content');
315 }
316
317 public function getPostTypeCommentContent(string $postType): string
318 {
319 return $this->getObjectContent($postType, '%s_comment_content');
320 }
321
322 public function showPostTypeContentBeforeMore(string $postType): bool
323 {
324 return (bool) $this->getObjectContent($postType, 'show_%s_content_before_more');
325 }
326
327 public function getRedirect(): ?string
328 {
329 return $this->getParameterValue('redirect');
330 }
331
332 public function getRedirectCustomPage(): ?string
333 {
334 return $this->getParameterValue('redirect_custom_page');
335 }
336
337 public function getRedirectCustomUrl(): ?string
338 {
339 return $this->getParameterValue('redirect_custom_url');
340 }
341
342 public function appendRedirectToParameter(): bool
343 {
344 return (bool) $this->getParameterValue('append_redirect_to_parameter');
345 }
346
347 public function lockRecursive(): bool
348 {
349 return (bool) $this->getParameterValue('lock_recursive');
350 }
351
352 public function authorsHasAccessToOwn(): bool
353 {
354 return (bool) $this->getParameterValue('authors_has_access_to_own');
355 }
356
357 public function authorsCanAddPostsToGroups(): bool
358 {
359 return (bool) $this->getParameterValue('authors_can_add_posts_to_groups');
360 }
361
362 public function lockFile(): bool
363 {
364 return (bool) $this->getParameterValue('lock_file');
365 }
366
367 public function getInlineFiles(): ?string
368 {
369 return $this->getParameterValue('inline_files');
370 }
371
372 public function getNoAccessImageType(): ?string
373 {
374 return $this->getParameterValue('no_access_image_type');
375 }
376
377 public function getCustomNoAccessImage(): ?string
378 {
379 return $this->getParameterValue('custom_no_access_image');
380 }
381
382 public function useCustomFileHandlingFile(): bool
383 {
384 return (bool) $this->getParameterValue('use_custom_file_handling_file');
385 }
386
387 public function getLockedDirectoryType(): ?string
388 {
389 return $this->getParameterValue('locked_directory_type');
390 }
391
392 public function getCustomLockedDirectories(): ?string
393 {
394 return $this->getParameterValue('custom_locked_directories');
395 }
396
397 public function getFilePassType(): ?string
398 {
399 return $this->getParameterValue('file_pass_type');
400 }
401
402 public function getDownloadType(): ?string
403 {
404 return $this->getParameterValue('download_type');
405 }
406
407 public function getLockedFileType(): ?string
408 {
409 return $this->getParameterValue('lock_file_types');
410 }
411
412 public function getLockedFiles(): ?string
413 {
414 return $this->getParameterValue('locked_file_types');
415 }
416
417 public function getNotLockedFiles(): ?string
418 {
419 return $this->getParameterValue('not_locked_file_types');
420 }
421
422 public function blogAdminHint(): bool
423 {
424 return (bool) $this->getParameterValue('blog_admin_hint');
425 }
426
427 public function getBlogAdminHintText(): ?string
428 {
429 return $this->getParameterValue('blog_admin_hint_text');
430 }
431
432 public function showAssignedGroups(): bool
433 {
434 return (bool) $this->getParameterValue('show_assigned_groups');
435 }
436
437 public function hideEditLinkOnNoAccess(): bool
438 {
439 return (bool) $this->getParameterValue('hide_edit_link_on_no_access');
440 }
441
442 public function hideEmptyTaxonomy(string $taxonomy): bool
443 {
444 $parameter = $this->getObjectParameter($taxonomy, 'hide_empty_%s');
445 return ($parameter !== null) ? $parameter->getValue() : false;
446 }
447
448 public function protectFeed(): bool
449 {
450 return (bool) $this->getParameterValue('protect_feed');
451 }
452
453 public function getFullAccessRole(): ?string
454 {
455 return $this->getParameterValue('full_access_role');
456 }
457
458 public function getActiveCacheProvider(): ?string
459 {
460 return $this->getParameterValue('active_cache_provider');
461 }
462
463 public function getExtraIpHeader(): ?string
464 {
465 return $this->getParameterValue('extra_ip_header');
466 }
467 }
468