PluginProbe
User Access Manager / 2.3.13
User Access Manager v2.3.13
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 2.3.13, at src/Controller/Frontend/FrontendController.php

119 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * FrontendController.php
4 *
5 * The FrontendController 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
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Controller\Frontend;
19
20 use UserAccessManager\Access\AccessHandler;
21 use UserAccessManager\Config\MainConfig;
22 use UserAccessManager\Config\WordpressConfig;
23 use UserAccessManager\Controller\Controller;
24 use UserAccessManager\UserAccessManager;
25 use UserAccessManager\UserGroup\UserGroupTypeException;
26 use UserAccessManager\Wrapper\Php;
27 use UserAccessManager\Wrapper\Wordpress;
28
29 /**
30 * Class FrontendController
31 *
32 * @package UserAccessManager\Controller
33 */
34 class FrontendController extends Controller
35 {
36 public const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm';
37
38 public function __construct(
39 Php $php,
40 Wordpress $wordpress,
41 WordpressConfig $wordpressConfig,
42 private MainConfig $mainConfig,
43 private AccessHandler $accessHandler
44 ) {
45 parent::__construct($php, $wordpress, $wordpressConfig);
46 }
47
48 private function registerStylesAndScripts(): void
49 {
50 $urlPath = $this->wordpressConfig->getUrlPath();
51
52 $this->wordpress->registerStyle(
53 self::HANDLE_STYLE_LOGIN_FORM,
54 $urlPath.'assets/css/uamLoginForm.css',
55 [],
56 UserAccessManager::VERSION,
57 'screen'
58 );
59 }
60
61 public function enqueueStylesAndScripts(): void
62 {
63 $this->registerStylesAndScripts();
64 $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM);
65 }
66
67 /**
68 * @throws UserGroupTypeException
69 */
70 public function showAncestors(array $ancestors, int|string|null $objectId, string $objectType): array
71 {
72 if ($this->mainConfig->lockRecursive() === true
73 && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false
74 ) {
75 return [];
76 }
77
78 foreach ($ancestors as $key => $ancestorId) {
79 if ($this->accessHandler->checkObjectAccess($objectType, $ancestorId) === false) {
80 unset($ancestors[$key]);
81 }
82 }
83
84 return $ancestors;
85 }
86
87
88 /*
89 * Functions for the redirection and files.
90 */
91
92 /**
93 * @throws UserGroupTypeException
94 */
95 public function getWpSeoUrl(array|string $url, string $type, object $object): bool|array|string
96 {
97 return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false;
98 }
99
100 /*
101 * Elementor
102 */
103
104 /**
105 * @throws UserGroupTypeException
106 */
107 public function getElementorContent($content): mixed
108 {
109 $this->wordpress->removeAction('elementor/frontend/the_content', [$this, 'getElementorContent']);
110 $post = $this->wordpress->getCurrentPost();
111
112 if ($this->accessHandler->checkObjectAccess($post->post_type, $post->ID) === false) {
113 $content = htmlspecialchars_decode($this->mainConfig->getPostTypeContent($post->post_type));
114 }
115
116 return $content;
117 }
118 }
119