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

141 lines 3.7 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 const HANDLE_STYLE_LOGIN_FORM = 'UserAccessManagerLoginForm';
37
38 /**
39 * @var MainConfig
40 */
41 private $mainConfig;
42
43 /**
44 * @var AccessHandler
45 */
46 private $accessHandler;
47
48 /**
49 * FrontendController constructor.
50 * @param Php $php
51 * @param Wordpress $wordpress
52 * @param WordpressConfig $wordpressConfig
53 * @param MainConfig $mainConfig
54 * @param AccessHandler $userHandler
55 */
56 public function __construct(
57 Php $php,
58 Wordpress $wordpress,
59 WordpressConfig $wordpressConfig,
60 MainConfig $mainConfig,
61 AccessHandler $userHandler
62 ) {
63 parent::__construct($php, $wordpress, $wordpressConfig);
64 $this->mainConfig = $mainConfig;
65 $this->accessHandler = $userHandler;
66 }
67
68 /**
69 * Functions for other content.
70 */
71
72 /**
73 * Register all other styles.
74 */
75 private function registerStylesAndScripts()
76 {
77 $urlPath = $this->wordpressConfig->getUrlPath();
78
79 $this->wordpress->registerStyle(
80 self::HANDLE_STYLE_LOGIN_FORM,
81 $urlPath.'assets/css/uamLoginForm.css',
82 [],
83 UserAccessManager::VERSION,
84 'screen'
85 );
86 }
87
88 /**
89 * The function for the wp_enqueue_scripts action.
90 */
91 public function enqueueStylesAndScripts()
92 {
93 $this->registerStylesAndScripts();
94 $this->wordpress->enqueueStyle(self::HANDLE_STYLE_LOGIN_FORM);
95 }
96
97 /**
98 * The function for the get_ancestors filter.
99 * @param array $ancestors
100 * @param int|string $objectId
101 * @param string $objectType
102 * @return array
103 * @throws UserGroupTypeException
104 */
105 public function showAncestors(array $ancestors, $objectId, string $objectType): array
106 {
107 if ($this->mainConfig->lockRecursive() === true
108 && $this->accessHandler->checkObjectAccess($objectType, $objectId) === false
109 ) {
110 return [];
111 }
112
113 foreach ($ancestors as $key => $ancestorId) {
114 if ($this->accessHandler->checkObjectAccess($objectType, $ancestorId) === false) {
115 unset($ancestors[$key]);
116 }
117 }
118
119 return $ancestors;
120 }
121
122
123 /*
124 * Functions for the redirection and files.
125 */
126
127 /**
128 * Filter for Yoast SEO Plugin
129 * Hides the url from the site map if the user has no access
130 * @param string|array $url The url to check
131 * @param string $type The object type
132 * @param object $object The object
133 * @return false|string
134 * @throws UserGroupTypeException
135 */
136 public function getWpSeoUrl($url, string $type, object $object)
137 {
138 return ($this->accessHandler->checkObjectAccess($type, $object->ID) === true) ? $url : false;
139 }
140 }
141