PluginProbe
CSS & JavaScript Toolbox / 6.0.9
CSS & JavaScript Toolbox v6.0.9
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 +77 -154 trunk6.0.9 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,67 +52,60 @@
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 - * @param mixed $overrideControllerPath
102 - * @param mixed $overrideContollerPrefix
103 101 * @return CJTController
104 102 */
105 - public function __construct($hasView = null,
106 - $request = null,
107 - $overrideControllerPath = null,
108 - $overrideContollerPrefix = null) {
103 + public function __construct($hasView = null, $request = null) {
109 104 // Initialize hookable!
110 105 parent::__construct();
111 106 // Read request parameters.
112 107 $this->request = array_merge(((array) $_REQUEST), ((array) $request));
113 -
114 - $overrideControllerPath = $overrideControllerPath ? null : '';
115 108 // Create default model.
116 109 if (isset($this->controllerInfo['model'])) {
117 110 // E_ALL complain!
118 111 if (!isset($this->controllerInfo['model_file'])) {
@@ -117,25 +110,18 @@
117 110 // E_ALL complain!
118 111 if (!isset($this->controllerInfo['model_file'])) {
119 112 $this->controllerInfo['model_file'] = null;
120 113 }
121 - $this->model = CJTModel::create($this->controllerInfo['model'],
122 - $this->request,
123 - $this->controllerInfo['model_file'],
124 - dirname($overrideControllerPath),
125 - $overrideContollerPrefix);
114 + $this->model = CJTModel::create($this->controllerInfo['model'], array(), $this->controllerInfo['model_file']);
126 115 }
127 116 // Create default view.
128 117 if ($hasView === null) { // Default value for $hasView = true
129 118 // Request/passed parameters has priority over controller default view!
130 - $view = $this->ongetviewname(isset($this->request['view']) ? esc_html($this->request['view']) :
119 + $view = $this->ongetviewname(isset($this->request['view']) ? $this->request['view'] :
131 120 (isset($this->controllerInfo['view']) ? $this->controllerInfo['view'] : null)
132 121 );
133 122 if ($view) {
134 - $this->view = self::getView($view,
135 - null,
136 - dirname($overrideControllerPath),
137 - $overrideContollerPrefix)
123 + $this->view = self::getView($view)
138 124 // Push data into view.
139 125 ->setModel($this->model)
140 126 ->setRequest($this->request);
141 127 }
@@ -140,18 +126,18 @@
140 126 ->setRequest($this->request);
141 127 }
142 128 }
143 129 }
144 -
130 +
145 131 /**
146 132 * put your comment there...
147 - *
133 + *
148 134 */
149 135 public function _doAction() {
150 136 // Force use of internal action untless its empty
151 137 // then look for submitted action or get the default!
152 - $action = $this->action ? $this->action :
153 - (isset($_GET['action']) ? esc_html($_GET['action']) : $this->defaultAction);
138 + $action = $this->action ? $this->action :
139 + (isset($_GET['action']) ? $_GET['action'] : $this->defaultAction);
154 140 // filter action name!
155 141 $action = $this->ongetactionname($action);
156 142 if ($action) {
157 143 $actionHandler = "{$action}Action";
@@ -160,71 +146,31 @@
160 146 // Callback!
161 147 call_user_func($callback);
162 148 }
163 149 }
164 -
150 +
165 151 /**
166 152 * put your comment there...
167 - *
153 + *
154 + * @deprecated Use CJTController::getInstance() instead!
155 + *
168 156 * @param mixed $name
169 - * @param mixed $hasView
170 157 * @param mixed $request
171 - * @param mixed $overrideControllersPath
172 - * @param mixed $overrideControllersPrefix
173 158 */
174 - public static function create($name,
175 - $hasView = null,
176 - $request = null,
177 - $overrideControllersPath = null,
178 - $overrideControllersPrefix = null) {
179 - // Validate controller name to prevent path traversal attacks
180 - if (!self::isValidControllerName($name)) {
181 - throw new Exception('Invalid controller name: ' . esc_html($name));
182 - }
183 -
159 + public static function create($name, $hasView = null, $request = null) {
184 160 // Import controller file.
185 - $pathToControllers = $overrideControllersPath ? $overrideControllersPath : CJTOOLBOX_CONTROLLERS_PATH;
161 + $pathToControllers = CJTOOLBOX_CONTROLLERS_PATH;
186 162 $controllerFile = "{$pathToControllers}/{$name}.php";
187 163 require_once self::trigger('CJTController.loadcontroller', $controllerFile, $name);
188 164 // Get controller class name.
189 - $class = self::getClassName($name, 'Controller', $overrideControllersPrefix);
165 + $class = self::getClassName($name, 'Controller');
190 166 // Instantiate controller class.
191 - return new $class($hasView, $request, $overrideControllersPath, $overrideControllersPrefix);
167 + return new $class($hasView, $request);
192 168 }
193 -
169 +
194 170 /**
195 - * Validate controller name to prevent path traversal attacks
196 - *
197 - * @param string $name Controller name to validate
198 - * @return bool True if valid, false otherwise
199 - */
200 - private static function isValidControllerName($name) {
201 - // Check for null or empty string
202 - if (empty($name) || !is_string($name)) {
203 - return false;
204 - }
205 -
206 - // Check for path traversal attempts
207 - if (strpos($name, '..') !== false) {
208 - return false;
209 - }
210 -
211 - // Check for directory separators
212 - if (strpos($name, '/') !== false || strpos($name, '\\') !== false) {
213 - return false;
214 - }
215 -
216 - // Only allow alphanumeric characters, hyphens, and underscores
217 - if (!preg_match('/^[a-zA-Z0-9_-]+$/', $name)) {
218 - return false;
219 - }
220 -
221 - return true;
222 - }
223 -
224 - /**
225 171 * put your comment there...
226 - *
172 + *
227 173 * @deprecated Use cssJSToolbox::createSecurityToken
228 174 */
229 175 public function createSecurityToken() {
230 176 return wp_create_nonce(self::NONCE_ACTION);
@@ -231,47 +177,38 @@
231 177 }
232 178
233 179 /**
234 180 * put your comment there...
235 - *
181 + *
236 182 */
237 183 protected function displayAction() {
238 184 // Get view layout!
239 - $layout = isset($this->request['layout']) ? esc_html($this->request['layout']) : 'default';
185 + $layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : 'default';
240 186 ob_start();
241 187 $this->view->display($layout);
242 188 $content = ob_get_clean();
243 189 return $content;
244 190 }
245 -
191 +
246 192 /**
247 193 * put your comment there...
248 - *
194 + *
249 195 * @param mixed $name
250 196 * @param mixed $hasView
251 197 * @param mixed $request
252 - * @param mixed $overrideControllersPath
253 198 */
254 - public static function getInstance($name,
255 - $hasView = null,
256 - $request = null,
257 - $overrideControllersPath = null,
258 - $overrideControllersPrefix = null) {
259 - return self::create($name, $hasView, $request, $overrideControllersPath, $overrideControllersPrefix);
199 + public static function getInstance($name, $hasView = null, $request = null) {
200 + return self::create($name, $hasView, $request);
260 201 }
261 -
202 +
262 203 /**
263 204 * Use CJTModel::create instead.
264 - *
205 + *
265 206 * @deprecated No longer used.
266 207 */
267 - public static function getModel($name,
268 - $params = array(),
269 - $file = null,
270 - $overrideModelsPath = null,
271 - $overrideModelsPrefix = null) {
208 + public static function getModel($name, $params = array(), $file = null) {
272 209 $model = null;
273 - $pathToModels = $overrideModelsPath ? ($overrideModelsPath . DIRECTORY_SEPARATOR . 'models') : CJTOOLBOX_MODELS_PATH;
210 + $pathToModels = CJTOOLBOX_MODELS_PATH;
274 211 if (!$file) {
275 212 $file = $name;
276 213 }
277 214 // Import model file.
@@ -277,9 +214,9 @@
277 214 // Import model file.
278 215 $modelFile = "{$pathToModels}/{$file}.php";
279 216 require_once $modelFile;
280 217 // Create model object.
281 - $modelClass = self::getClassName($name, 'Model', $overrideModelsPrefix);
218 + $modelClass = self::getClassName($name, 'Model');
282 219 if (!class_exists($modelClass)) {
283 220 throw new Exception("Model class {$modelClass} doesn't exists!!!");
284 221 }
285 222 $model = new $modelClass($params);
@@ -284,86 +221,72 @@
284 221 }
285 222 $model = new $modelClass($params);
286 223 return $model;
287 224 }
288 -
225 +
289 226 /**
290 227 * @deprecated No longer used.
291 228 */
292 - public static function getClassName($name, $type, $prefix = null) {
293 - // Init vars
229 + public static function getClassName($name, $type) {
294 230 $className = '';
295 - // Getting default prefix
296 - if (!$prefix) {
297 - $prefix = 'CJT';
298 - }
299 231 // Every word start with uppercase character.
300 232 $sanitizedName = ucfirst(str_replace(array('-', '_'), ' ', "{$name} {$type}"));
301 233 // Remove spaces.
302 234 $sanitizedName = str_replace(' ', '', $sanitizedName);
303 235 // Filter.
304 - $className = self::trigger('CJTController.getclassname', "{$prefix}{$sanitizedName}", $name, $type);
236 + $className = self::trigger('CJTController.getclassname', "CJT{$sanitizedName}", $name, $type);
305 237 return $className;
306 238 }
307 -
239 +
308 240 /**
309 241 * put your comment there...
310 - *
242 + *
311 243 * @param mixed $name
312 244 */
313 245 public function getRequestParameter($name) {
314 - return isset($this->request[$name]) ? esc_html($this->request[$name]) : null;
246 + return $this->request;
315 247 }
316 -
248 +
317 249 /**
318 - *
250 + *
319 251 * Use CJTView:create instrad.
320 - *
252 + *
321 253 * @deprecated
322 254 */
323 - public static function getView($path,
324 - $params = null,
325 - $overrideViewsPath = null,
326 - $overrideViewsPrefix = null) {
255 + public static function getView($path) {
327 256 $view = null;
328 257 // Import view file.
329 - $viewInfo = self::getViewInfo($path, $overrideViewsPath, $overrideViewsPrefix);
258 + $viewInfo = self::getViewInfo($path);
330 259 require_once $viewInfo['viewFile'];
331 260 // Create view object.
332 261 $name = str_replace(' ', '', ucwords(str_replace('/', ' ',$path)));
333 - $viewClass = self::getClassName($name, 'view', $overrideViewsPrefix);
334 - $view = new $viewClass($viewInfo, $params);
262 + $viewClass = self::getClassName($name, 'view');
263 + $view = new $viewClass($viewInfo);
335 264 return $view;
336 265 }
337 -
266 +
338 267 /**
339 268 * put your comment there...
340 - *
269 + *
341 270 */
342 - public static function getViewInfo($path, $overrideViewsPath = null, $overrideViewsPrefix = null) {
343 - // Plugin views Url
344 - $viewsUrl = $overrideViewsPath ?
345 - WP_PLUGIN_URL . '/' . basename(dirname($overrideViewsPath)) :
346 - CJTOOLBOX_VIEWS_URL;
271 + public static function getViewInfo($path) {
347 272 // Path to views dir.
348 - $pathToViews = $overrideViewsPath ? ($overrideViewsPath . DIRECTORY_SEPARATOR . 'views') : CJTOOLBOX_VIEWS_PATH;
273 + $pathToViews = CJTOOLBOX_VIEWS_PATH;
349 274 // Get view name.
350 275 $name = basename($path);
351 276 // View info struct.
352 277 $viewInfo = array(
353 278 'name' => $path,
354 - 'url' => "{$viewsUrl}/{$path}",
279 + 'url' => (CJTOOLBOX_VIEWS_URL . "/{$path}"),
355 280 'path' => "{$pathToViews}/{$path}",
356 - 'viewsPath' => $pathToViews,
357 - 'viewsUrl' => $viewsUrl,
358 281 'viewFile' => "{$pathToViews}/{$path}/view.php",
359 282 );
360 283 return $viewInfo;
361 284 }
362 -
285 +
363 286 /**
364 287 * put your comment there...
365 - *
288 + *
366 289 * @param mixed $action
367 290 */
368 291 public function setAction($action) {
369 292 $this->action = $action;
@@ -368,12 +291,12 @@
368 291 public function setAction($action) {
369 292 $this->action = $action;
370 293 return $this;
371 294 }
372 -
295 +
373 296 /**
374 297 * put your comment there...
375 - *
298 + *
376 299 * @param mixed $name
377 300 * @param mixed $value
378 301 */
379 302 public function setRequestParameter($name, $value) {
@@ -379,9 +302,9 @@
379 302 public function setRequestParameter($name, $value) {
380 303 $this->request[$name] = $value;
381 304 return $this;
382 305 }
383 -
306 +
384 307 } // End class.
385 308
386 309 // Hookable!
387 -CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));
310 +CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));