Feature
8 years ago
View
8 years ago
Widget
8 years ago
phtml
8 years ago
Authorization.php
8 years ago
Feature.php
8 years ago
Filter.php
8 years ago
Manager.php
8 years ago
Subject.php
8 years ago
View.php
8 years ago
View.php
269 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_Menu::register(); |
| 37 | AAM_Backend_Feature_Main_Metabox::register(); |
| 38 | AAM_Backend_Feature_Main_Capability::register(); |
| 39 | AAM_Backend_Feature_Main_Route::register(); |
| 40 | AAM_Backend_Feature_Main_Post::register(); |
| 41 | AAM_Backend_Feature_Main_Redirect::register(); |
| 42 | AAM_Backend_Feature_Main_LoginRedirect::register(); |
| 43 | AAM_Backend_Feature_Main_LogoutRedirect::register(); |
| 44 | AAM_Backend_Feature_Main_404Redirect::register(); |
| 45 | |
| 46 | AAM_Backend_Feature_Settings_Core::register(); |
| 47 | AAM_Backend_Feature_Settings_Content::register(); |
| 48 | AAM_Backend_Feature_Settings_Tools::register(); |
| 49 | AAM_Backend_Feature_Settings_ConfigPress::register(); |
| 50 | |
| 51 | //feature registration hook |
| 52 | do_action('aam-feature-registration-action'); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Run the Manager |
| 57 | * |
| 58 | * @return string |
| 59 | * |
| 60 | * @access public |
| 61 | */ |
| 62 | public function renderPage() { |
| 63 | ob_start(); |
| 64 | require_once(dirname(__FILE__) . '/phtml/index.phtml'); |
| 65 | $content = ob_get_contents(); |
| 66 | ob_end_clean(); |
| 67 | |
| 68 | return $content; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Run the Manager |
| 73 | * |
| 74 | * @return string |
| 75 | * |
| 76 | * @access public |
| 77 | */ |
| 78 | public function renderAccessFrame() { |
| 79 | ob_start(); |
| 80 | require_once(dirname(__FILE__) . '/phtml/metabox/metabox-content.phtml'); |
| 81 | $content = ob_get_contents(); |
| 82 | ob_end_clean(); |
| 83 | |
| 84 | return $content; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * |
| 89 | * @param type $post |
| 90 | * @return type |
| 91 | */ |
| 92 | public function renderPostMetabox($post) { |
| 93 | ob_start(); |
| 94 | require_once(dirname(__FILE__) . '/phtml/metabox/post-metabox.phtml'); |
| 95 | $content = ob_get_contents(); |
| 96 | ob_end_clean(); |
| 97 | |
| 98 | return $content; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * |
| 103 | * @param type $term |
| 104 | * @return type |
| 105 | */ |
| 106 | public function renderTermMetabox($term) { |
| 107 | ob_start(); |
| 108 | require_once(dirname(__FILE__) . '/phtml/metabox/term-metabox.phtml'); |
| 109 | $content = ob_get_contents(); |
| 110 | ob_end_clean(); |
| 111 | |
| 112 | return $content; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Process the ajax call |
| 117 | * |
| 118 | * @return string |
| 119 | * |
| 120 | * @access public |
| 121 | */ |
| 122 | public function processAjax() { |
| 123 | $response = null; |
| 124 | |
| 125 | $action = AAM_Core_Request::request('sub_action'); |
| 126 | $parts = explode('.', $action); |
| 127 | |
| 128 | if (method_exists($this, $parts[0])) { |
| 129 | $response = call_user_func(array($this, $parts[0])); |
| 130 | } elseif (count($parts) == 2) { //cover the Model.method pattern |
| 131 | try { |
| 132 | $classname = 'AAM_Backend_Feature_' . $parts[0]; |
| 133 | if (class_exists($classname)) { |
| 134 | $response = call_user_func(array(new $classname, $parts[1])); |
| 135 | } |
| 136 | } catch (Exception $e) { |
| 137 | $response = $e->getMessage(); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return apply_filters( |
| 142 | 'aam-ajax-filter', |
| 143 | $response, |
| 144 | AAM_Backend_Subject::getInstance()->get(), |
| 145 | $action |
| 146 | ); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Render the Main Control Area |
| 151 | * |
| 152 | * @param string $type |
| 153 | * |
| 154 | * @return void |
| 155 | * |
| 156 | * @access public |
| 157 | */ |
| 158 | public function renderContent($type = 'main') { |
| 159 | $content = apply_filters('aam-ui-content-filter', null, $type); |
| 160 | |
| 161 | if (is_null($content)) { |
| 162 | ob_start(); |
| 163 | if ($type == 'extensions') { |
| 164 | AAM_Backend_Feature_Extension_Manager::getInstance()->render(); |
| 165 | } elseif ($type == 'postform') { |
| 166 | echo AAM_Backend_Feature_Main_Post::renderAccessForm(); |
| 167 | } else { |
| 168 | require_once(dirname(__FILE__) . '/phtml/main-panel.phtml'); |
| 169 | } |
| 170 | $content = ob_get_contents(); |
| 171 | ob_end_clean(); |
| 172 | } |
| 173 | |
| 174 | return $content; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * |
| 179 | * @param type $partial |
| 180 | * @return type |
| 181 | */ |
| 182 | public function loadPartial($partial) { |
| 183 | ob_start(); |
| 184 | require_once(dirname(__FILE__) . '/phtml/partial/' . $partial); |
| 185 | $content = ob_get_contents(); |
| 186 | ob_end_clean(); |
| 187 | |
| 188 | return $content; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Save AAM options |
| 193 | * |
| 194 | * Important notice! This function excepts "value" to be only boolean value |
| 195 | * |
| 196 | * @return string |
| 197 | * |
| 198 | * @access public |
| 199 | */ |
| 200 | public function save() { |
| 201 | $object = trim(AAM_Core_Request::post('object')); |
| 202 | $objectId = intval(AAM_Core_Request::post('objectId', 0)); |
| 203 | |
| 204 | $param = AAM_Core_Request::post('param'); |
| 205 | $value = filter_input(INPUT_POST, 'value'); |
| 206 | |
| 207 | $result = AAM_Backend_Subject::getInstance()->save( |
| 208 | $param, $value, $object, $objectId |
| 209 | ); |
| 210 | |
| 211 | return json_encode(array('status' => ($result ? 'success' : 'failure'))); |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * |
| 216 | * @return type |
| 217 | */ |
| 218 | public function reset() { |
| 219 | return AAM_Backend_Subject::getInstance()->resetObject( |
| 220 | AAM_Core_Request::post('object') |
| 221 | ); |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * |
| 226 | * @return type |
| 227 | */ |
| 228 | public function switchToUser() { |
| 229 | $response = array( |
| 230 | 'status' => 'failure', |
| 231 | 'reason' => 'You are not allowed to switch to this user' |
| 232 | ); |
| 233 | |
| 234 | if (current_user_can('aam_switch_users')) { |
| 235 | $user = new WP_User(AAM_Core_Request::post('user')); |
| 236 | $max = AAM_Core_API::maxLevel(wp_get_current_user()->allcaps); |
| 237 | |
| 238 | if ($max >= AAM_Core_API::maxLevel($user->allcaps)) { |
| 239 | AAM_Core_API::updateOption( |
| 240 | 'aam-user-switch-' . $user->ID, get_current_user_id() |
| 241 | ); |
| 242 | |
| 243 | wp_clear_auth_cookie(); |
| 244 | wp_set_auth_cookie( $user->ID, true ); |
| 245 | wp_set_current_user( $user->ID ); |
| 246 | |
| 247 | $response = array('status' => 'success', 'redirect' => admin_url()); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | return json_encode($response); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Get instance of itself |
| 256 | * |
| 257 | * @return AAM_Backend_View |
| 258 | * |
| 259 | * @access public |
| 260 | */ |
| 261 | public static function getInstance() { |
| 262 | if (is_null(self::$_instance)) { |
| 263 | self::$_instance = new self; |
| 264 | } |
| 265 | |
| 266 | return self::$_instance; |
| 267 | } |
| 268 | |
| 269 | } |