PluginProbe
CSS & JavaScript Toolbox / 7.2
CSS & JavaScript Toolbox v7.2
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | framework/mvc/controller-ajax.inc.php +37 -46 117.2 View file →
@@ -1,90 +1,90 @@
1 1 <?php
2 2 /**
3 -*
3 +*
4 4 */
5 5
6 6 /**
7 -*
7 +*
8 8 */
9 9 abstract class CJTAjaxController extends CJTController {
10 -
10 +
11 11 /** */
12 12 const ACTION_PREFIX = 'wp_ajax_cjtoolbox_';
13 -
13 +
14 14 /**
15 15 * put your comment there...
16 - *
16 + *
17 17 * @var mixed
18 18 */
19 19 protected $methodName;
20 -
20 +
21 21 /**
22 22 * put your comment there...
23 - *
23 + *
24 24 * @var mixed
25 25 */
26 26 protected $actionsMap = array();
27 -
27 +
28 28 /**
29 29 * put your comment there...
30 - *
30 + *
31 31 * @var mixed
32 32 */
33 33 protected $defaultCapability = array('administrator');
34 -
34 +
35 35 /**
36 36 * put your comment there...
37 - *
37 + *
38 38 * @var mixed
39 39 */
40 40 protected $impersonated = false;
41 -
41 +
42 42 /**
43 43 * put your comment there...
44 - *
44 + *
45 45 * @var mixed
46 46 */
47 47 public $httpCode = '200 OK';
48 -
48 +
49 49 /**
50 50 * put your comment there...
51 - *
51 + *
52 52 * @var mixed
53 53 */
54 54 public $httpContentType = 'text/plain';
55 -
55 +
56 56 /**
57 57 * put your comment there...
58 - *
58 + *
59 59 * @var mixed
60 60 */
61 61 protected $onauthorize = array('parameters' => array('authorized'));
62 -
62 +
63 63 /**
64 64 * put your comment there...
65 - *
65 + *
66 66 * @var mixed
67 67 */
68 68 protected $onregisteraction = array('parameters' => array('callback', 'action'));
69 -
69 +
70 70 /**
71 71 * put your comment there...
72 - *
72 + *
73 73 * @var mixed
74 74 */
75 75 protected $onresponse = array('hookType' => CJTWordpressEvents::HOOK_ACTION);
76 -
76 +
77 77 /**
78 78 * put your comment there...
79 - *
79 + *
80 80 * @var mixed
81 81 */
82 82 public $response = false;
83 -
83 +
84 84 /**
85 85 * put your comment there...
86 - *
86 + *
87 87 */
88 88 public function _doAction() {
89 89 // Authorize request.
90 90 $authorized = $this->onauthorize(check_ajax_referer(self::NONCE_ACTION, 'security', false));
@@ -91,17 +91,8 @@
91 91 if (!$authorized || !call_user_func_array('current_user_can', $this->defaultCapability)) {
92 92 $this->httpCode = "403 Not Authorized";
93 93 }
94 94 else {
95 - // Clear Wordpress scripts object when using AJAX
96 - // This is to solve conflict caused by other Plugins
97 - // That uses admin_init hook to enqueue their scripts
98 - // Ajax request here is only for CJT no other Plugin
99 - // should involve any scripts with CJT
100 - // Remove all scritps enqueued before CJT Ajax Controller (this) received
101 - // the controller!
102 - global $wp_scripts;
103 - $wp_scripts = new WP_Scripts();
104 95 // Dispatch action.
105 96 $action = current_filter();
106 97 // Get method name from frrom Wordpress action name!
107 98 $method = $this->ongetactionname(str_replace(self::ACTION_PREFIX, '', $action));
@@ -108,9 +99,9 @@
108 99 // Get method name from action name.
109 100 $method = ucfirst(str_replace('_', ' ', $method));
110 101 $method = str_replace(' ', '', $method);
111 102 // Lower case the first character.
112 - $method = strtolower($method[0]) . substr($method, 1);
103 + $method = strtolower($method{0}) . substr($method, 1);
113 104 // Cahe method name for child classes to use!
114 105 $this->methodName = $method;
115 106 // Relying on the trailer "Action" for security.
116 107 // Derivded class should not never use trailer "Action"
@@ -149,9 +140,9 @@
149 140 switch ($this->httpContentType) {
150 141 case 'text/plain':
151 142 echo json_encode($this->response);
152 143 break;
153 -
144 +
154 145 default :
155 146 echo $this->response;
156 147 }
157 148 die();
@@ -158,26 +149,26 @@
158 149 }
159 150
160 151 /**
161 152 * Display templates manager form.
162 - *
153 + *
163 154 */
164 - protected function displayAction() {
155 + protected function displayAction() {
165 156 // Return view.
166 157 $this->httpContentType = 'text/html';
167 158 $this->response = parent::displayAction();
168 159 }
169 -
160 +
170 161 /**
171 162 * Redirect the request to another controller.
172 - *
163 + *
173 164 * Why this method is created anyway is to allow
174 165 * deprecating old controllers and start to create new one
175 166 * a quiet manner!
176 - *
167 + *
177 168 * The idea is to create the new controller, adding new Action there
178 - * and redirect the call through current deprecated controller.
179 - *
169 + * and redirect the call throught current deprecated controller.
170 + *
180 171 * @param mixed $controller
181 172 */
182 173 protected function redirect($controller) {
183 174 // Initialize vars.
@@ -188,12 +179,12 @@
188 179 CJTController::getInstance($controller);
189 180 // Fire the action manually.
190 181 do_action($currentFilter);
191 182 }
192 -
183 +
193 184 /**
194 185 * put your comment there...
195 - *
186 + *
196 187 * @param mixed $action
197 188 * @param mixed $priority
198 189 * @param mixed $paramsCount
199 190 */
@@ -203,9 +194,9 @@
203 194 // Adding action!
204 195 add_action($action, $callback , $priority, $paramsCount);
205 196 return $this;
206 197 }
207 -
198 +
208 199 } // End class.
209 200
210 201 // Hookable!
211 202 CJTAjaxController::define('CJTAjaxController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));