PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / trunk
Advanced Access Manager – Access Governance for WordPress vtrunk
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 1 year ago View 1 year ago Widget 1 year ago tmpl 3 months ago AccessLevel.php 1 year ago Feature.php 1 year ago Manager.php 3 months ago View.php 1 year ago
View.php
454 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 * This class is used to manage all AAM UI templates and interaction of the UI with
14 * AAM backend core
15 *
16 * @package AAM
17 * @version 7.0.0
18 */
19 class AAM_Backend_View
20 {
21
22 /**
23 * Single instance of itself
24 *
25 * @var object
26 * @access private
27 *
28 * @version 7.0.0
29 */
30 private static $_instance = null;
31
32 /**
33 * Constructor
34 *
35 * @return void
36 * @access protected
37 *
38 * @version 7.0.0
39 */
40 protected function __construct()
41 {
42 // Allow other plugins to register new AAM UI tabs/features
43 do_action(
44 'aam_initialize_ui_action',
45 function($feature) { AAM_Backend_Feature::registerFeature($feature); },
46 AAM_Backend_AccessLevel::get_instance()
47 );
48 }
49
50 /**
51 * Replace sprintf string with URLs to aamportal.com
52 *
53 * @param string $str
54 * @param string ...$url
55 *
56 * @return string
57 *
58 * @access public
59 * @static
60 *
61 * @version 7.0.0
62 */
63 public static function replace_aam_urls($str)
64 {
65 $args = array_slice(func_get_args(), 1);
66
67 if (!empty($args)) {
68 // Preparing the array of arguments for the sprintf
69 $replace_args = [$str];
70
71 foreach($args as $relative_url) {
72 array_push($replace_args,
73 '<a href="https://aamportal.com' . $relative_url . '?ref=plugin" target="_blank">',
74 '</a>'
75 );
76 }
77
78 $str = call_user_func_array('sprintf', $replace_args);
79 }
80
81 return $str;
82 }
83
84 /**
85 * Load partial template
86 *
87 * The specified template has to be located inside the ./tmpl/partial folder
88 *
89 * @param string $tmpl
90 * @param array $params
91 *
92 * @return string|null
93 * @access public
94 *
95 * @version 6.0.0
96 */
97 public static function loadPartial($tmpl, $params = array())
98 {
99 if (preg_match('/^[a-z-]+$/i', $tmpl)) {
100 $html = self::loadTemplate(
101 __DIR__ . "/tmpl/partial/{$tmpl}.php",
102 (is_object($params) ? $params : (object) $params)
103 );
104 } else {
105 $html = null;
106 }
107
108 return $html;
109 }
110
111 /**
112 * Load dynamic template
113 *
114 * @param string $file_path
115 * @param object $params
116 *
117 * @return string
118 * @access public
119 *
120 * @version 6.6.0
121 */
122 public static function loadTemplate($file_path, $params = null)
123 {
124 ob_start();
125
126 require $file_path;
127 $content = ob_get_contents();
128
129 ob_end_clean();
130
131 return $content;
132 }
133
134 /**
135 * Process the ajax call
136 *
137 * @return string
138 * @access public
139 *
140 * @version 6.7.9
141 */
142 public function processAjax()
143 {
144 $response = null;
145
146 $action = AAM::api()->misc->get($_POST, 'sub_action');
147 $parts = explode('.', $action);
148 $access_level = AAM_Backend_AccessLevel::get_instance();
149
150 if (count($parts) === 2) {
151 $id = 'AAM_Backend_Feature_' . $parts[0];
152
153 if (AAM_Backend_Feature::isFeatureRegistered($id)) {
154 $response = call_user_func(
155 array(AAM_Backend_Feature::getFeatureView($id), $parts[1])
156 );
157 }
158
159 $response = apply_filters(
160 'aam_ajax_filter',
161 $response,
162 $access_level->get_access_level(),
163 $action
164 );
165 } elseif ($action === 'renderContent') {
166 $partial = AAM::api()->misc->get($_POST, 'partial');
167 $response = $this->renderContent((!empty($partial) ? $partial : 'main'));
168
169 $accept = AAM::api()->misc->get($_SERVER, 'HTTP_ACCEPT_ENCODING');
170 header('Content-Type: text/html; charset=UTF-8');
171
172 $compressed = count(array_intersect(
173 array('zlib output compression', 'ob_gzhandler'),
174 ob_list_handlers()
175 )) > 0;
176
177 if (!empty($accept)) {
178 header('Vary: Accept-Encoding'); // Handle proxies
179
180 if (false !== stripos($accept, 'gzip') && function_exists('gzencode')) {
181 header('Content-Encoding: gzip');
182 $response = ($compressed ? $response : gzencode($response, 3));
183 }
184 }
185 }
186
187 return $response;
188 }
189
190 /**
191 * Render the main AAM page
192 *
193 * This is the landing page for the /wp-admin/admin.php?page=aam
194 *
195 * @return string
196 *
197 * @access public
198 * @version 6.0.0
199 */
200 public function renderPage()
201 {
202 return $this->loadTemplate(dirname(__FILE__) . '/tmpl/index.php');
203 }
204
205 /**
206 * Run AAM iFrame
207 *
208 * @return string
209 * @access public
210 *
211 * @version 6.0.0
212 */
213 public function renderIFrame($type)
214 {
215 $basedir = dirname(__FILE__) . '/tmpl/metabox/';
216
217 if (current_user_can('aam_manager')) {
218 if (($type === 'post') && current_user_can('aam_manage_content')) {
219 echo $this->loadTemplate(
220 $basedir . 'post-iframe.php',
221 (object) array(
222 'objectId' => filter_input(INPUT_GET, 'id'),
223 'objectType' => filter_input(INPUT_GET, 'type'),
224 'postManager' => new AAM_Backend_Feature_Main_Content()
225 )
226 );
227 } elseif ($type === 'user' && current_user_can('aam_manage_users')) {
228 echo $this->loadTemplate(
229 $basedir . 'user-iframe.php',
230 (object) array(
231 'user' => new WP_User(filter_input(INPUT_GET, 'id')),
232 'type' => 'main'
233 )
234 );
235 } elseif ($type === 'main') {
236 echo $this->loadTemplate($basedir . 'main-iframe.php');
237 } else {
238 echo apply_filters('aam_iframe_content_filter', null, $type, $this);
239 }
240 }
241
242 exit;
243 }
244
245 /**
246 * Render Access Manager metabox iFrame element for posts
247 *
248 * @param WP_Post $post
249 *
250 * @return string
251 *
252 * @access public
253 * @version 6.0.0
254 */
255 public static function renderPostMetabox($post)
256 {
257 return static::loadTemplate(
258 dirname(__FILE__) . '/tmpl/metabox/post-metabox.php',
259 (object) array('post' => $post)
260 );
261 }
262
263 /**
264 * Render Access Manager metabox iFrame element for user
265 *
266 * @param WP_User $term
267 *
268 * @return string
269 *
270 * @access public
271 * @version 6.0.0
272 */
273 public static function renderUserMetabox($user)
274 {
275 return static::loadTemplate(
276 dirname(__FILE__) . '/tmpl/metabox/user-metabox.php',
277 (object) array(
278 'user' => $user
279 )
280 );
281 }
282
283 /**
284 * Render Access Policy editor
285 *
286 * @return string
287 *
288 * @access public
289 * @global WP_Post $post
290 *
291 * @version 7.0.0
292 */
293 public function render_policy_metabox()
294 {
295 global $post;
296
297 if (is_a($post, 'WP_Post')) {
298 $content = $this->loadTemplate(
299 dirname(__FILE__) . '/tmpl/metabox/policy-metabox.php',
300 (object) array('post' => $post)
301 );
302 } else {
303 $content = null;
304 }
305
306 return $content;
307 }
308
309 /**
310 * Render policy parent metabox
311 *
312 * @return string
313 * @access public
314 *
315 * @version 7.0.0
316 */
317 public function render_policy_parent_metabox()
318 {
319 global $post;
320
321 if (is_a($post, 'WP_Post')) {
322 $content = $this->loadTemplate(
323 dirname(__FILE__) . '/tmpl/metabox/policy-parent-metabox.php',
324 (object) [ 'post' => $post ]
325 );
326 } else {
327 $content = null;
328 }
329
330 return $content;
331 }
332
333 /**
334 * Render policy principal metabox
335 *
336 * @return string
337 *
338 * @access public
339 * @global WP_Post $post
340 * @version 6.0.0
341 */
342 public static function renderPolicyPrincipalMetabox()
343 {
344 global $post;
345
346 if (is_a($post, 'WP_Post')) {
347 $content = static::loadTemplate(
348 dirname(__FILE__) . '/tmpl/metabox/policy-principal-metabox.php',
349 (object) array('post' => $post)
350 );
351 } else {
352 $content = null;
353 }
354
355 return $content;
356 }
357
358 /**
359 * Render the AAM HTML content
360 *
361 * Depending on the $type of the content, verify correct permissions and load
362 * proper HTML template.
363 *
364 * @param string $type
365 *
366 * @return string
367 *
368 * @access public
369 * @version 6.0.0
370 */
371 public function renderContent($type = 'main')
372 {
373 $basedir = __DIR__ . '/tmpl/page/';
374
375 switch ($type) {
376 case 'main':
377 // No need to do the authorization as this is already done in the
378 // AAM_Backend_Manager class
379 $content = $this->loadTemplate(
380 $basedir . 'main-panel.php',
381 (object) array('type' => 'main')
382 );
383 break;
384
385 case 'settings':
386 if (current_user_can('aam_manage_settings')) {
387 $content = $this->loadTemplate(
388 $basedir . 'main-panel.php',
389 (object) array('type' => 'settings')
390 );
391 }
392 break;
393
394 case 'extensions':
395 if (current_user_can('aam_manage_addons')) {
396 $content = $this->loadTemplate($basedir . 'addon-panel.php');
397 }
398 break;
399
400 case 'content-access-form':
401 $manager = new AAM_Backend_Feature_Main_Content();
402 $content = $manager->render_content_access_form(
403 AAM::api()->misc->get($_POST, 'resource_id'),
404 AAM::api()->misc->get($_POST, 'resource_type')
405 );
406 break;
407
408 case 'audit':
409 if (current_user_can('aam_trigger_audit')) {
410 $content = $this->loadTemplate($basedir . 'security-audit.php');
411 }
412 break;
413
414 default:
415 // Allow other plugins to hook into the AAM template rendering with
416 // with custom HTML
417 $content = apply_filters('aam_ui_content_filter', null, $type);
418 break;
419 }
420
421 return $content;
422 }
423
424 /**
425 * Bootstrap the object
426 *
427 * @return AAM_Backend_View
428 *
429 * @access public
430 * @version 7.0.0
431 */
432 public static function bootstrap()
433 {
434 if (is_null(self::$_instance)) {
435 self::$_instance = new self;
436 }
437
438 return self::$_instance;
439 }
440
441 /**
442 * Get single instance of itself
443 *
444 * @return AAM_Backend_View
445 *
446 * @access public
447 * @version 7.0.0
448 */
449 public static function get_instance()
450 {
451 return self::bootstrap();
452 }
453
454 }