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