PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / 4.0
Advanced Access Manager – Access Governance for WordPress v4.0
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 9 years ago View 9 years ago phtml 9 years ago Feature.php 9 years ago Filter.php 9 years ago Manager.php 9 years ago View.php 9 years ago
View.php
261 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 * Current Subject
29 *
30 * @var AAM_Core_Subject
31 *
32 * @access private
33 */
34 private static $_subject = null;
35
36 /**
37 * Construct the view object
38 *
39 * @return void
40 *
41 * @access protected
42 */
43 protected function __construct() {
44 $classname = 'AAM_Core_Subject_' . ucfirst(
45 AAM_Core_Request::request('subject')
46 );
47 if (class_exists($classname)) {
48 $this->setSubject(new $classname(
49 AAM_Core_Request::request('subjectId')
50 ));
51 }
52
53 //register default features
54 AAM_Backend_Feature_Menu::register();
55 AAM_Backend_Feature_Metabox::register();
56 AAM_Backend_Feature_Capability::register();
57 AAM_Backend_Feature_Post::register();
58 AAM_Backend_Feature_Redirect::register();
59 AAM_Backend_Feature_Teaser::register();
60 AAM_Backend_Feature_LoginRedirect::register();
61 AAM_Backend_Feature_Extension::register();
62 AAM_Backend_Feature_Security::register();
63 AAM_Backend_Feature_Utility::register();
64 AAM_Backend_Feature_Contact::register();
65
66 //feature registration hook
67 do_action('aam-feature-registration');
68 }
69
70 /**
71 * Run the Manager
72 *
73 * @return string
74 *
75 * @access public
76 */
77 public function renderPage() {
78 ob_start();
79 require_once(dirname(__FILE__) . '/phtml/index.phtml');
80 $content = ob_get_contents();
81 ob_end_clean();
82
83 return $content;
84 }
85
86 /**
87 * Run the Manager
88 *
89 * @return string
90 *
91 * @access public
92 */
93 public function renderMetabox() {
94 global $post;
95
96 if (is_a($post, 'WP_Post')) {
97 $url = admin_url('admin.php?page=aam&oid=' . $post->ID . '#post');
98
99 ob_start();
100 require_once(dirname(__FILE__) . '/phtml/metabox.phtml');
101 $content = ob_get_contents();
102 ob_end_clean();
103 } else {
104 $content = null;
105 }
106
107 return $content;
108 }
109
110 /**
111 * Process the ajax call
112 *
113 * @return string
114 *
115 * @access public
116 */
117 public function processAjax() {
118 $response = null;
119
120 $action = AAM_Core_Request::request('sub_action');
121 $parts = explode('.', $action);
122
123 if (method_exists($this, $parts[0])) {
124 $response = call_user_func(array($this, $parts[0]));
125 } elseif (count($parts) == 2) { //cover the Model.method pattern
126 try {
127 $classname = 'AAM_Backend_Feature_' . $parts[0];
128 if (class_exists($classname)) {
129 $response = call_user_func(array(new $classname, $parts[1]));
130 }
131 } catch (Exception $e) {
132 $response = $e->getMessage();
133 }
134 }
135
136 return apply_filters(
137 'aam-ajax-filter', $response, $this->getSubject(), $action
138 );
139 }
140
141 /**
142 * Render the Main Control Area
143 *
144 * @return void
145 *
146 * @access public
147 */
148 public function renderContent() {
149 ob_start();
150 require_once(dirname(__FILE__) . '/phtml/main-panel.phtml');
151 $content = ob_get_contents();
152 ob_end_clean();
153
154 return $content;
155 }
156
157 /**
158 *
159 * @param type $partial
160 * @return type
161 */
162 public function loadPartial($partial) {
163 ob_start();
164 require_once(dirname(__FILE__) . '/phtml/partial/' . $partial);
165 $content = ob_get_contents();
166 ob_end_clean();
167
168 return $content;
169 }
170
171 /**
172 * Save AAM options
173 *
174 * Important notice! This function excepts "value" to be only boolean value
175 *
176 * @return string
177 *
178 * @access public
179 */
180 public function save() {
181 $object = trim(AAM_Core_Request::post('object'));
182 $objectId = intval(AAM_Core_Request::post('objectId', 0));
183
184 $param = AAM_Core_Request::post('param');
185 $value = filter_var(
186 AAM_Core_Request::post('value'), FILTER_VALIDATE_BOOLEAN
187 );
188
189 $result = $this->getSubject()->save($param, $value, $object, $objectId);
190
191 return json_encode(array('status' => ($result ? 'success' : 'failure')));
192 }
193
194 /**
195 *
196 * @return type
197 */
198 public function switchToUser() {
199 $user = new WP_User(AAM_Core_Request::post('user'));
200 $max = AAM_Core_API::maxLevel(wp_get_current_user()->allcaps);
201
202 if ($max >= AAM_Core_API::maxLevel($user->allcaps)) {
203 AAM_Core_API::updateOption(
204 'aam-user-switch-' . $user->ID, get_current_user_id()
205 );
206
207 wp_clear_auth_cookie();
208 wp_set_auth_cookie( $user->ID, true );
209 wp_set_current_user( $user->ID );
210
211 $response = array('status' => 'success', 'redirect' => admin_url());
212 } else {
213 $response = array(
214 'status' => 'failure',
215 'reason' => 'You are not allowed to switch to this user'
216 );
217 }
218
219 return json_encode($response);
220 }
221
222 /**
223 * Get Subject
224 *
225 * @return AAM_Core_Subject
226 *
227 * @access public
228 */
229 public static function getSubject() {
230 return self::$_subject;
231 }
232
233 /**
234 * Set Subject
235 *
236 * @param AAM_Core_Subject $subject
237 *
238 * @return void
239 *
240 * @access public
241 */
242 protected function setSubject(AAM_Core_Subject $subject) {
243 self::$_subject = $subject;
244 }
245
246 /**
247 * Get instance of itself
248 *
249 * @return AAM_Backend_View
250 *
251 * @access public
252 */
253 public static function getInstance() {
254 if (is_null(self::$_instance)) {
255 self::$_instance = new self;
256 }
257
258 return self::$_instance;
259 }
260
261 }