PluginProbe
CSS & JavaScript Toolbox / 12
CSS & JavaScript Toolbox v12
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.inc.php +73 -71 1112 View file →
@@ -11,43 +11,43 @@
11 11 /**
12 12 * CJT controller base class.
13 13 */
14 14 abstract class CJTController extends CJTHookableClass {
15 -
15 +
16 16 /** */
17 17 const NONCE_ACTION = 'cjtoolbox';
18 -
18 +
19 19 /**
20 20 * put your comment there...
21 - *
21 + *
22 22 * @var mixed
23 23 */
24 24 protected $action;
25 -
25 +
26 26 /**
27 27 * put your comment there...
28 - *
28 + *
29 29 * @var mixed
30 30 */
31 31 protected $controllerInfo = null;
32 -
32 +
33 33 /**
34 34 * put your comment there...
35 - *
35 + *
36 36 * @var mixed
37 37 */
38 38 protected $defaultAction = 'index';
39 -
39 +
40 40 /**
41 41 * put your comment there...
42 - *
42 + *
43 43 * @var mixed
44 44 */
45 45 protected $request;
46 -
46 +
47 47 /**
48 48 * put your comment there...
49 - *
49 + *
50 50 * @var mixed
51 51 */
52 52 protected $model = null;
53 53
@@ -52,51 +52,51 @@
52 52 protected $model = null;
53 53
54 54 /**
55 55 * put your comment there...
56 - *
56 + *
57 57 * @var mixed
58 58 */
59 59 protected $oncallback = array('parameters' => array('callback', 'action', 'args'));
60 -
60 +
61 61 /**
62 62 * put your comment there...
63 - *
63 + *
64 64 * @var mixed
65 65 */
66 66 protected $ongetactionname = array('parameters' => array('action'));
67 -
67 +
68 68 /**
69 69 * put your comment there...
70 - *
70 + *
71 71 * @var mixed
72 72 */
73 73 protected static $ongetclassname = array('parameters' => array('class', 'name', 'type'));
74 -
74 +
75 75 /**
76 76 * put your comment there...
77 - *
77 + *
78 78 * @var mixed
79 79 */
80 80 protected $ongetviewname = array('parameters' => array('view'));
81 -
81 +
82 82 /**
83 83 * put your comment there...
84 - *
84 + *
85 85 * @var mixed
86 86 */
87 87 protected static $onloadcontroller = array('parameters' => array('file', 'name'));
88 -
88 +
89 89 /**
90 90 * put your comment there...
91 - *
91 + *
92 92 * @var mixed
93 93 */
94 94 protected $view = null;
95 -
95 +
96 96 /**
97 97 * put your comment there...
98 - *
98 + *
99 99 * @param mixed $hasView
100 100 * @param mixed $request
101 101 * @param mixed $overrideControllerPath
102 102 * @param mixed $overrideContollerPrefix
@@ -101,16 +101,18 @@
101 101 * @param mixed $overrideControllerPath
102 102 * @param mixed $overrideContollerPrefix
103 103 * @return CJTController
104 104 */
105 - public function __construct($hasView = null,
106 - $request = null,
107 - $overrideControllerPath = null,
105 + public function __construct($hasView = null,
106 + $request = null,
107 + $overrideControllerPath = '',
108 108 $overrideContollerPrefix = null) {
109 109 // Initialize hookable!
110 110 parent::__construct();
111 111 // Read request parameters.
112 112 $this->request = array_merge(((array) $_REQUEST), ((array) $request));
113 +
114 + $overrideControllerPath = $overrideControllerPath ? null : '';
113 115 // Create default model.
114 116 if (isset($this->controllerInfo['model'])) {
115 117 // E_ALL complain!
116 118 if (!isset($this->controllerInfo['model_file'])) {
@@ -115,10 +117,10 @@
115 117 // E_ALL complain!
116 118 if (!isset($this->controllerInfo['model_file'])) {
117 119 $this->controllerInfo['model_file'] = null;
118 120 }
119 - $this->model = CJTModel::create($this->controllerInfo['model'],
120 - $this->request,
121 + $this->model = CJTModel::create($this->controllerInfo['model'],
122 + $this->request,
121 123 $this->controllerInfo['model_file'],
122 124 dirname($overrideControllerPath),
123 125 $overrideContollerPrefix);
124 126 }
@@ -124,14 +126,14 @@
124 126 }
125 127 // Create default view.
126 128 if ($hasView === null) { // Default value for $hasView = true
127 129 // Request/passed parameters has priority over controller default view!
128 - $view = $this->ongetviewname(isset($this->request['view']) ? $this->request['view'] :
130 + $view = $this->ongetviewname(isset($this->request['view']) ? esc_html($this->request['view']) :
129 131 (isset($this->controllerInfo['view']) ? $this->controllerInfo['view'] : null)
130 132 );
131 133 if ($view) {
132 - $this->view = self::getView($view,
133 - null,
134 + $this->view = self::getView($view,
135 + null,
134 136 dirname($overrideControllerPath),
135 137 $overrideContollerPrefix)
136 138 // Push data into view.
137 139 ->setModel($this->model)
@@ -138,18 +140,18 @@
138 140 ->setRequest($this->request);
139 141 }
140 142 }
141 143 }
142 -
144 +
143 145 /**
144 146 * put your comment there...
145 - *
147 + *
146 148 */
147 149 public function _doAction() {
148 150 // Force use of internal action untless its empty
149 151 // then look for submitted action or get the default!
150 - $action = $this->action ? $this->action :
151 - (isset($_GET['action']) ? $_GET['action'] : $this->defaultAction);
152 + $action = $this->action ? $this->action :
153 + (isset($_GET['action']) ? esc_html($_GET['action']) : $this->defaultAction);
152 154 // filter action name!
153 155 $action = $this->ongetactionname($action);
154 156 if ($action) {
155 157 $actionHandler = "{$action}Action";
@@ -158,12 +160,12 @@
158 160 // Callback!
159 161 call_user_func($callback);
160 162 }
161 163 }
162 -
164 +
163 165 /**
164 166 * put your comment there...
165 - *
167 + *
166 168 * @param mixed $name
167 169 * @param mixed $hasView
168 170 * @param mixed $request
169 171 * @param mixed $overrideControllersPath
@@ -168,11 +170,11 @@
168 170 * @param mixed $request
169 171 * @param mixed $overrideControllersPath
170 172 * @param mixed $overrideControllersPrefix
171 173 */
172 - public static function create($name,
173 - $hasView = null,
174 - $request = null,
174 + public static function create($name,
175 + $hasView = null,
176 + $request = null,
175 177 $overrideControllersPath = null,
176 178 $overrideControllersPrefix = null) {
177 179 // Import controller file.
178 180 $pathToControllers = $overrideControllersPath ? $overrideControllersPath : CJTOOLBOX_CONTROLLERS_PATH;
@@ -182,12 +184,12 @@
182 184 $class = self::getClassName($name, 'Controller', $overrideControllersPrefix);
183 185 // Instantiate controller class.
184 186 return new $class($hasView, $request, $overrideControllersPath, $overrideControllersPrefix);
185 187 }
186 -
188 +
187 189 /**
188 190 * put your comment there...
189 - *
191 + *
190 192 * @deprecated Use cssJSToolbox::createSecurityToken
191 193 */
192 194 public function createSecurityToken() {
193 195 return wp_create_nonce(self::NONCE_ACTION);
@@ -194,13 +196,13 @@
194 196 }
195 197
196 198 /**
197 199 * put your comment there...
198 - *
200 + *
199 201 */
200 202 protected function displayAction() {
201 203 // Get view layout!
202 - $layout = isset($this->request['layout']) ? $this->request['layout'] : 'default';
204 + $layout = isset($this->request['layout']) ? esc_html($this->request['layout']) : 'default';
203 205 ob_start();
204 206 $this->view->display($layout);
205 207 $content = ob_get_clean();
206 208 return $content;
@@ -207,9 +209,9 @@
207 209 }
208 210
209 211 /**
210 212 * put your comment there...
211 - *
213 + *
212 214 * @param mixed $name
213 215 * @param mixed $hasView
214 216 * @param mixed $request
215 217 * @param mixed $overrideControllersPath
@@ -214,22 +216,22 @@
214 216 * @param mixed $request
215 217 * @param mixed $overrideControllersPath
216 218 */
217 219 public static function getInstance($name,
218 - $hasView = null,
219 - $request = null,
220 + $hasView = null,
221 + $request = null,
220 222 $overrideControllersPath = null,
221 223 $overrideControllersPrefix = null) {
222 224 return self::create($name, $hasView, $request, $overrideControllersPath, $overrideControllersPrefix);
223 225 }
224 -
226 +
225 227 /**
226 228 * Use CJTModel::create instead.
227 - *
229 + *
228 230 * @deprecated No longer used.
229 231 */
230 - public static function getModel($name,
231 - $params = array(),
232 + public static function getModel($name,
233 + $params = array(),
232 234 $file = null,
233 235 $overrideModelsPath = null,
234 236 $overrideModelsPrefix = null) {
235 237 $model = null;
@@ -247,9 +249,9 @@
247 249 }
248 250 $model = new $modelClass($params);
249 251 return $model;
250 252 }
251 -
253 +
252 254 /**
253 255 * @deprecated No longer used.
254 256 */
255 257 public static function getClassName($name, $type, $prefix = null) {
@@ -266,27 +268,27 @@
266 268 // Filter.
267 269 $className = self::trigger('CJTController.getclassname', "{$prefix}{$sanitizedName}", $name, $type);
268 270 return $className;
269 271 }
270 -
272 +
271 273 /**
272 274 * put your comment there...
273 - *
275 + *
274 276 * @param mixed $name
275 277 */
276 278 public function getRequestParameter($name) {
277 - return isset($this->request[$name]) ? $this->request[$name] : null;
279 + return isset($this->request[$name]) ? esc_html($this->request[$name]) : null;
278 280 }
279 -
281 +
280 282 /**
281 - *
283 + *
282 284 * Use CJTView:create instrad.
283 - *
285 + *
284 286 * @deprecated
285 287 */
286 - public static function getView($path,
287 - $params = null,
288 - $overrideViewsPath = null,
288 + public static function getView($path,
289 + $params = null,
290 + $overrideViewsPath = null,
289 291 $overrideViewsPrefix = null) {
290 292 $view = null;
291 293 // Import view file.
292 294 $viewInfo = self::getViewInfo($path, $overrideViewsPath, $overrideViewsPrefix);
@@ -296,16 +298,16 @@
296 298 $viewClass = self::getClassName($name, 'view', $overrideViewsPrefix);
297 299 $view = new $viewClass($viewInfo, $params);
298 300 return $view;
299 301 }
300 -
302 +
301 303 /**
302 304 * put your comment there...
303 - *
305 + *
304 306 */
305 307 public static function getViewInfo($path, $overrideViewsPath = null, $overrideViewsPrefix = null) {
306 308 // Plugin views Url
307 - $viewsUrl = $overrideViewsPath ?
309 + $viewsUrl = $overrideViewsPath ?
308 310 WP_PLUGIN_URL . '/' . basename(dirname($overrideViewsPath)) :
309 311 CJTOOLBOX_VIEWS_URL;
310 312 // Path to views dir.
311 313 $pathToViews = $overrideViewsPath ? ($overrideViewsPath . DIRECTORY_SEPARATOR . 'views') : CJTOOLBOX_VIEWS_PATH;
@@ -321,12 +323,12 @@
321 323 'viewFile' => "{$pathToViews}/{$path}/view.php",
322 324 );
323 325 return $viewInfo;
324 326 }
325 -
327 +
326 328 /**
327 329 * put your comment there...
328 - *
330 + *
329 331 * @param mixed $action
330 332 */
331 333 public function setAction($action) {
332 334 $this->action = $action;
@@ -331,12 +333,12 @@
331 333 public function setAction($action) {
332 334 $this->action = $action;
333 335 return $this;
334 336 }
335 -
337 +
336 338 /**
337 339 * put your comment there...
338 - *
340 + *
339 341 * @param mixed $name
340 342 * @param mixed $value
341 343 */
342 344 public function setRequestParameter($name, $value) {
@@ -342,9 +344,9 @@
342 344 public function setRequestParameter($name, $value) {
343 345 $this->request[$name] = $value;
344 346 return $this;
345 347 }
346 -
348 +
347 349 } // End class.
348 350
349 351 // Hookable!
350 -CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));
352 +CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));