PluginProbe
User Access Manager / trunk
User Access Manager vtrunk
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 / Controller / Frontend / FrontendController.php

FrontendController.php in User Access Manager trunk, at src/Controller/Frontend/FrontendController.php

85 lines 2.6 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\Controller\Frontend;
6
7 use UserAccessManager\Access\AccessHandler;
8 use UserAccessManager\Config\MainConfig;
9 use UserAccessManager\Config\WordpressConfig;
10 use UserAccessManager\Controller\Controller;
11 use UserAccessManager\UserAccessManager;
12 use UserAccessManager\UserGroup\UserGroupTypeException;
13 use UserAccessManager\Wrapper\Php;
14 use UserAccessManager\Wrapper\Wordpress;
15
16 class FrontendController extends Controller
17 {
18 public const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm';
19
20 public function __construct(
21 Php $php,
22 Wordpress $wordpress,
23 WordpressConfig $wordpressConfig,
24 private MainConfig $mainConfig,
25 private AccessHandler $accessHandler
26 ) {
27 parent::__construct($php, $wordpress, $wordpressConfig);
28 }
29
30 public function enqueueStylesAndScripts(): void
31 {
32 $this->wordpress->registerStyle(
33 self::HANDLE_STYLE_LOGIN_FORM,
34 $this->wordpressConfig->getUrlPath().'assets/css/uamLoginForm.css',
35 [],
36 UserAccessManager::VERSION,
37 'screen'
38 );
39 $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM);
40 }
41
42 /**
43 * @throws UserGroupTypeException
44 */
45 public function showAncestors(array $ancestors, int|string|null $objectId, string $objectType): array
46 {
47 if ($this->mainConfig->lockRecursive() === true
48 && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false
49 ) {
50 return [];
51 }
52
53 foreach ($ancestors as $key => $ancestorId) {
54 if ($this->accessHandler->checkObjectAccess($objectType, $ancestorId) === false) {
55 unset($ancestors[$key]);
56 }
57 }
58
59 return $ancestors;
60 }
61
62 /**
63 * @throws UserGroupTypeException
64 */
65 public function getWpSeoUrl(array|string $url, string $type, object $object): bool|array|string
66 {
67 return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false;
68 }
69
70 /**
71 * @throws UserGroupTypeException
72 */
73 public function getElementorContent(mixed $content): mixed
74 {
75 $this->wordpress->removeAction('elementor/frontend/the_content', [$this, 'getElementorContent']);
76 $post = $this->wordpress->getCurrentPost();
77
78 if ($this->accessHandler->checkObjectAccess($post->post_type, $post->ID) === false) {
79 $content = htmlspecialchars_decode($this->mainConfig->getPostTypeContent($post->post_type));
80 }
81
82 return $content;
83 }
84 }
85