PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / 5.8.2
Advanced Access Manager – Access Governance for WordPress v5.8.2
6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 6.9.27 6.9.28 6.9.29 6.9.3 6.9.30 6.9.31 6.9.32 6.9.33 6.9.34 6.9.35 6.9.36 6.9.37 6.9.38 6.9.39 6.9.4 6.9.41 6.9.42 6.9.43 6.9.44 6.9.45 6.9.46 6.9.47 6.9.48 6.9.49 6.9.5 6.9.51 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.0-alpha.6 7.0.0-alpha.7 7.0.0-beta.1 7.0.0-rc1 7.0.0-rc2 7.0.0-rc3 7.0.1 7.0.10 7.0.11 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 7.1.0 7.1.1 trunk 3.0 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.6.1 4.6.2 4.7 4.7.1 4.7.2 4.7.5 4.7.6 4.8 4.8.1 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.5.1 4.9.5.2 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1 5.1.1 5.10 5.11 5.2 5.2.1 5.2.5 5.2.6 5.2.7 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.4 5.4.1 5.4.2 5.4.3 5.4.3.1 5.4.3.2 5.5 5.5.1 5.5.2 5.6 5.6.1 5.6.1.1 5.7 5.7.1 5.7.2 5.7.3 5.8 5.8.1 5.8.2 5.8.3 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.3 5.9.4 5.9.5 5.9.6 5.9.6.1 5.9.6.2 5.9.6.3 5.9.7 5.9.7.1 5.9.7.2 5.9.7.3 5.9.8 5.9.8.1 5.9.9 5.9.9.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.2.0 6.2.1 6.2.2 6.3.0 6.3.1 6.3.2 6.3.3 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.6.0 6.6.1 6.6.2 6.6.3 6.6.4 6.7.0 6.7.1 6.7.2 6.7.3 6.7.4 6.7.5 6.7.6 6.7.7 6.7.8 6.7.9 6.8.0 6.8.1 6.8.2 6.8.3
advanced-access-manager / Application / Backend / View.php
advanced-access-manager / Application / Backend Last commit date
Feature 7 years ago View 7 years ago Widget 7 years ago phtml 7 years ago Authorization.php 7 years ago Feature.php 7 years ago Filter.php 7 years ago Manager.php 7 years ago Subject.php 7 years ago View.php 7 years ago
View.php
346 lines
1 <?php
2
3 /**
4 * ======================================================================
5 * LICENSE: This file is subject to the terms and conditions defined in *
6 * file 'license.txt', which is part of this source code package. *
7 * ======================================================================
8 */
9
10 /**
11 * Backend view manager
12 *
13 * @package AAM
14 * @author Vasyl Martyniuk <vasyl@vasyltech.com>
15 */
16 class AAM_Backend_View {
17
18 /**
19 * Instance of itself
20 *
21 * @var AAM_Backend_View
22 *
23 * @access private
24 */
25 private static $_instance = null;
26
27 /**
28 * Construct the view object
29 *
30 * @return void
31 *
32 * @access protected
33 */
34 protected function __construct() {
35 //register default features
36 AAM_Backend_Feature_Main_GetStarted::register();
37 AAM_Backend_Feature_Main_Policy::register();
38 AAM_Backend_Feature_Main_Menu::register();
39 AAM_Backend_Feature_Main_Toolbar::register();
40 AAM_Backend_Feature_Main_Metabox::register();
41 AAM_Backend_Feature_Main_Capability::register();
42 AAM_Backend_Feature_Main_Route::register();
43 AAM_Backend_Feature_Main_Post::register();
44 AAM_Backend_Feature_Main_Redirect::register();
45 AAM_Backend_Feature_Main_LoginRedirect::register();
46 AAM_Backend_Feature_Main_LogoutRedirect::register();
47 AAM_Backend_Feature_Main_404Redirect::register();
48 AAM_Backend_Feature_Main_Uri::register();
49
50 AAM_Backend_Feature_Settings_Core::register();
51 AAM_Backend_Feature_Settings_Content::register();
52 AAM_Backend_Feature_Settings_Security::register();
53 AAM_Backend_Feature_Settings_ConfigPress::register();
54
55 //feature registration hook
56 do_action('aam-feature-registration-action');
57 }
58
59 /**
60 * Clear all AAM settings
61 *
62 * @global wpdb $wpdb
63 *
64 * @return string
65 *
66 * @access public
67 */
68 public function clearSettings() {
69 AAM_Core_API::clearSettings();
70
71 return wp_json_encode(array('status' => 'success'));
72 }
73
74 /**
75 *
76 * @return type
77 */
78 public function clearCache() {
79 AAM_Core_API::clearCache();
80
81 return wp_json_encode(array('status' => 'success'));
82 }
83
84 /**
85 * Run the Manager
86 *
87 * @return string
88 *
89 * @access public
90 */
91 public function renderPage() {
92 ob_start();
93 require_once dirname(__FILE__) . '/phtml/index.phtml';
94 $content = ob_get_contents();
95 ob_end_clean();
96
97 return $content;
98 }
99
100 /**
101 * Run the Manager
102 *
103 * @return string
104 *
105 * @access public
106 */
107 public function renderAccessFrame() {
108 ob_start();
109 require_once dirname(__FILE__) . '/phtml/metabox/metabox-content.phtml';
110 $content = ob_get_contents();
111 ob_end_clean();
112
113 return $content;
114 }
115
116 /**
117 *
118 * @param type $post
119 * @return type
120 */
121 public function renderPostMetabox($post) {
122 ob_start();
123 require_once dirname(__FILE__) . '/phtml/metabox/post-metabox.phtml';
124 $content = ob_get_contents();
125 ob_end_clean();
126
127 return $content;
128 }
129
130 /**
131 *
132 * @param type $post
133 * @return type
134 */
135 public function renderPolicyMetabox($post) {
136 ob_start();
137 require_once dirname(__FILE__) . '/phtml/metabox/policy-metabox.phtml';
138 $content = ob_get_contents();
139 ob_end_clean();
140
141 return $content;
142 }
143
144 /**
145 *
146 * @param type $post
147 * @return type
148 */
149 public function renderPolicyPrincipalMetabox($post) {
150 ob_start();
151 require_once dirname(__FILE__) . '/phtml/metabox/policy-principal-metabox.phtml';
152 $content = ob_get_contents();
153 ob_end_clean();
154
155 return $content;
156 }
157
158 /**
159 *
160 * @param type $term
161 * @return type
162 */
163 public function renderTermMetabox($term) {
164 ob_start();
165 require_once dirname(__FILE__) . '/phtml/metabox/term-metabox.phtml';
166 $content = ob_get_contents();
167 ob_end_clean();
168
169 return $content;
170 }
171
172 /**
173 * Process the ajax call
174 *
175 * @return string
176 *
177 * @access public
178 */
179 public function processAjax() {
180 $response = null;
181
182 $action = AAM_Core_Request::request('sub_action');
183 $parts = explode('.', $action);
184
185 if (method_exists($this, $parts[0])) {
186 $response = call_user_func(array($this, $parts[0]));
187 } elseif (count($parts) === 2) { //cover the Model.method pattern
188 try {
189 $classname = 'AAM_Backend_Feature_' . $parts[0];
190 if (class_exists($classname)) {
191 $response = call_user_func(array(new $classname, $parts[1]));
192 }
193 } catch (Exception $e) {
194 $response = $e->getMessage();
195 }
196 }
197
198 return apply_filters(
199 'aam-ajax-filter',
200 $response,
201 AAM_Backend_Subject::getInstance()->get(),
202 $action
203 );
204 }
205
206 /**
207 * Render the Main Control Area
208 *
209 * @param string $type
210 *
211 * @return void
212 *
213 * @access public
214 */
215 public function renderContent($type = 'main') {
216 $content = apply_filters('aam-ui-content-filter', null, $type);
217
218 if (is_null($content)) {
219 ob_start();
220 if ($type === 'extensions') {
221 AAM_Backend_Feature_Extension_Manager::getInstance()->render();
222 } elseif ($type === 'postform') {
223 echo AAM_Backend_Feature_Main_Post::renderAccessForm();
224 } else {
225 require_once dirname(__FILE__) . '/phtml/main-panel.phtml';
226 }
227 $content = ob_get_contents();
228 ob_end_clean();
229 }
230
231 return $content;
232 }
233
234 /**
235 *
236 * @param type $partial
237 * @return type
238 */
239 public function loadPartial($partial) {
240 ob_start();
241 require_once dirname(__FILE__) . '/phtml/partial/' . $partial;
242 $content = ob_get_contents();
243 ob_end_clean();
244
245 return $content;
246 }
247
248 /**
249 * Save AAM options
250 *
251 * Important notice! This function excepts "value" to be only boolean value
252 *
253 * @return string
254 *
255 * @access public
256 */
257 public function save() {
258 $object = trim(AAM_Core_Request::post('object'));
259 $objectId = intval(AAM_Core_Request::post('objectId', 0));
260
261 $param = AAM_Core_Request::post('param');
262 $value = filter_input(INPUT_POST, 'value');
263
264 $result = AAM_Backend_Subject::getInstance()->save(
265 $param, $value, $object, $objectId
266 );
267
268 return wp_json_encode(array('status' => ($result ? 'success' : 'failure')));
269 }
270
271 /**
272 *
273 * @return type
274 */
275 public function reset() {
276 return AAM_Backend_Subject::getInstance()->resetObject(
277 AAM_Core_Request::post('object')
278 );
279 }
280
281 /**
282 *
283 * @return type
284 */
285 public function switchToUser() {
286 $response = array(
287 'status' => 'failure',
288 'reason' => 'You are not allowed to switch to this user'
289 );
290
291 if (current_user_can('aam_switch_users')) {
292 $user = new WP_User(AAM_Core_Request::post('user'));
293 $max = AAM::getUser()->getMaxLevel();
294
295 if ($max >= AAM_Core_API::maxLevel($user->allcaps)) {
296 AAM_Core_API::updateOption(
297 'aam-user-switch-' . $user->ID, get_current_user_id()
298 );
299
300 // Making sure that user that we are switching too is not logged in
301 // already. Reported by https://github.com/KenAer
302 $sessions = WP_Session_Tokens::get_instance($user->ID);
303 if (count($sessions->get_all()) > 1) {
304 $sessions->destroy_all();
305 }
306
307 // If there is jwt token in cookie, make sure it is deleted otherwise
308 // user technically will never be switched
309 if (AAM_Core_Request::cookie('aam-jwt')) {
310 setcookie(
311 'aam-jwt',
312 '',
313 time() - YEAR_IN_SECONDS,
314 '/',
315 parse_url(get_bloginfo('url'), PHP_URL_HOST),
316 is_ssl()
317 );
318 }
319
320 wp_clear_auth_cookie();
321 wp_set_auth_cookie( $user->ID, true );
322 wp_set_current_user( $user->ID );
323
324 $response = array('status' => 'success', 'redirect' => admin_url());
325 }
326 }
327
328 return wp_json_encode($response);
329 }
330
331 /**
332 * Get instance of itself
333 *
334 * @return AAM_Backend_View
335 *
336 * @access public
337 */
338 public static function getInstance() {
339 if (is_null(self::$_instance)) {
340 self::$_instance = new self;
341 }
342
343 return self::$_instance;
344 }
345
346 }