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