PluginProbe
CSS & JavaScript Toolbox / 8.0.3
CSS & JavaScript Toolbox v8.0.3
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 +75 -28 6.08.0.3 View file →
@@ -97,24 +97,43 @@
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
101 103 * @return CJTController
102 104 */
103 - public function __construct($hasView = null, $request = null) {
105 + public function __construct($hasView = null,
106 + $request = null,
107 + $overrideControllerPath = null,
108 + $overrideContollerPrefix = null) {
104 109 // Initialize hookable!
105 110 parent::__construct();
106 111 // Read request parameters.
107 - $this->request = $request ? $request : $_REQUEST;
112 + $this->request = array_merge(((array) $_REQUEST), ((array) $request));
108 113 // Create default model.
109 114 if (isset($this->controllerInfo['model'])) {
110 - $this->model = CJTModel::create($this->controllerInfo['model'], array(), $this->controllerInfo['model_file']);
115 + // E_ALL complain!
116 + if (!isset($this->controllerInfo['model_file'])) {
117 + $this->controllerInfo['model_file'] = null;
118 + }
119 + $this->model = CJTModel::create($this->controllerInfo['model'],
120 + $this->request,
121 + $this->controllerInfo['model_file'],
122 + dirname($overrideControllerPath),
123 + $overrideContollerPrefix);
111 124 }
112 125 // Create default view.
113 126 if ($hasView === null) { // Default value for $hasView = true
114 - $view = $this->ongetviewname($this->request['view'] ? $this->request['view'] : $this->controllerInfo['view']);
127 + // Request/passed parameters has priority over controller default view!
128 + $view = $this->ongetviewname(isset($this->request['view']) ? $this->request['view'] :
129 + (isset($this->controllerInfo['view']) ? $this->controllerInfo['view'] : null)
130 + );
115 131 if ($view) {
116 - $this->view = self::getView($view)
132 + $this->view = self::getView($view,
133 + null,
134 + dirname($overrideControllerPath),
135 + $overrideContollerPrefix)
117 136 // Push data into view.
118 137 ->setModel($this->model)
119 138 ->setRequest($this->request);
120 139 }
@@ -143,22 +162,27 @@
143 162
144 163 /**
145 164 * put your comment there...
146 165 *
147 - * @deprecated Use CJTController::getInstance() instead!
148 - *
149 166 * @param mixed $name
167 + * @param mixed $hasView
150 168 * @param mixed $request
169 + * @param mixed $overrideControllersPath
170 + * @param mixed $overrideControllersPrefix
151 171 */
152 - public static function create($name, $hasView = null, $request = null) {
172 + public static function create($name,
173 + $hasView = null,
174 + $request = null,
175 + $overrideControllersPath = null,
176 + $overrideControllersPrefix = null) {
153 177 // Import controller file.
154 - $pathToControllers = CJTOOLBOX_CONTROLLERS_PATH;
178 + $pathToControllers = $overrideControllersPath ? $overrideControllersPath : CJTOOLBOX_CONTROLLERS_PATH;
155 179 $controllerFile = "{$pathToControllers}/{$name}.php";
156 180 require_once self::trigger('CJTController.loadcontroller', $controllerFile, $name);
157 181 // Get controller class name.
158 - $class = self::getClassName($name, 'Controller');
182 + $class = self::getClassName($name, 'Controller', $overrideControllersPrefix);
159 183 // Instantiate controller class.
160 - return new $class($hasView, $request);
184 + return new $class($hasView, $request, $overrideControllersPath, $overrideControllersPrefix);
161 185 }
162 186
163 187 /**
164 188 * put your comment there...
@@ -174,15 +198,15 @@
174 198 *
175 199 */
176 200 protected function displayAction() {
177 201 // Get view layout!
178 - $layout = isset($_REQUEST['layout']) ? $_REQUEST['layout'] : 'default';
202 + $layout = isset($this->request['layout']) ? $this->request['layout'] : 'default';
179 203 ob_start();
180 204 $this->view->display($layout);
181 205 $content = ob_get_clean();
182 206 return $content;
183 207 }
184 -
208 +
185 209 /**
186 210 * put your comment there...
187 211 *
188 212 * @param mixed $name
@@ -187,11 +211,16 @@
187 211 *
188 212 * @param mixed $name
189 213 * @param mixed $hasView
190 214 * @param mixed $request
215 + * @param mixed $overrideControllersPath
191 216 */
192 - public static function getInstance($name, $hasView = null, $request = null) {
193 - return self::create($name, $hasView, $request);
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);
194 223 }
195 224
196 225 /**
197 226 * Use CJTModel::create instead.
@@ -197,11 +226,15 @@
197 226 * Use CJTModel::create instead.
198 227 *
199 228 * @deprecated No longer used.
200 229 */
201 - public static function getModel($name, $params = array(), $file = null) {
230 + public static function getModel($name,
231 + $params = array(),
232 + $file = null,
233 + $overrideModelsPath = null,
234 + $overrideModelsPrefix = null) {
202 235 $model = null;
203 - $pathToModels = CJTOOLBOX_MODELS_PATH;
236 + $pathToModels = $overrideModelsPath ? ($overrideModelsPath . DIRECTORY_SEPARATOR . 'models') : CJTOOLBOX_MODELS_PATH;
204 237 if (!$file) {
205 238 $file = $name;
206 239 }
207 240 // Import model file.
@@ -207,9 +240,9 @@
207 240 // Import model file.
208 241 $modelFile = "{$pathToModels}/{$file}.php";
209 242 require_once $modelFile;
210 243 // Create model object.
211 - $modelClass = self::getClassName($name, 'Model');
244 + $modelClass = self::getClassName($name, 'Model', $overrideModelsPrefix);
212 245 if (!class_exists($modelClass)) {
213 246 throw new Exception("Model class {$modelClass} doesn't exists!!!");
214 247 }
215 248 $model = new $modelClass($params);
@@ -218,16 +251,21 @@
218 251
219 252 /**
220 253 * @deprecated No longer used.
221 254 */
222 - public static function getClassName($name, $type) {
255 + public static function getClassName($name, $type, $prefix = null) {
256 + // Init vars
223 257 $className = '';
258 + // Getting default prefix
259 + if (!$prefix) {
260 + $prefix = 'CJT';
261 + }
224 262 // Every word start with uppercase character.
225 263 $sanitizedName = ucfirst(str_replace(array('-', '_'), ' ', "{$name} {$type}"));
226 264 // Remove spaces.
227 265 $sanitizedName = str_replace(' ', '', $sanitizedName);
228 266 // Filter.
229 - $className = self::trigger('CJTController.getclassname', "CJT{$sanitizedName}", $name, $type);
267 + $className = self::trigger('CJTController.getclassname', "{$prefix}{$sanitizedName}", $name, $type);
230 268 return $className;
231 269 }
232 270
233 271 /**
@@ -235,9 +273,9 @@
235 273 *
236 274 * @param mixed $name
237 275 */
238 276 public function getRequestParameter($name) {
239 - return $this->request;
277 + return isset($this->request[$name]) ? $this->request[$name] : null;
240 278 }
241 279
242 280 /**
243 281 *
@@ -244,17 +282,20 @@
244 282 * Use CJTView:create instrad.
245 283 *
246 284 * @deprecated
247 285 */
248 - public static function getView($path) {
286 + public static function getView($path,
287 + $params = null,
288 + $overrideViewsPath = null,
289 + $overrideViewsPrefix = null) {
249 290 $view = null;
250 291 // Import view file.
251 - $viewInfo = self::getViewInfo($path);
292 + $viewInfo = self::getViewInfo($path, $overrideViewsPath, $overrideViewsPrefix);
252 293 require_once $viewInfo['viewFile'];
253 294 // Create view object.
254 295 $name = str_replace(' ', '', ucwords(str_replace('/', ' ',$path)));
255 - $viewClass = self::getClassName($name, 'view');
256 - $view = new $viewClass($viewInfo);
296 + $viewClass = self::getClassName($name, 'view', $overrideViewsPrefix);
297 + $view = new $viewClass($viewInfo, $params);
257 298 return $view;
258 299 }
259 300
260 301 /**
@@ -260,18 +301,24 @@
260 301 /**
261 302 * put your comment there...
262 303 *
263 304 */
264 - public static function getViewInfo($path) {
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;
265 310 // Path to views dir.
266 - $pathToViews = CJTOOLBOX_VIEWS_PATH;
311 + $pathToViews = $overrideViewsPath ? ($overrideViewsPath . DIRECTORY_SEPARATOR . 'views') : CJTOOLBOX_VIEWS_PATH;
267 312 // Get view name.
268 313 $name = basename($path);
269 314 // View info struct.
270 315 $viewInfo = array(
271 316 'name' => $path,
272 - 'url' => (CJTOOLBOX_VIEWS_URL . "/{$path}"),
317 + 'url' => "{$viewsUrl}/{$path}",
273 318 'path' => "{$pathToViews}/{$path}",
319 + 'viewsPath' => $pathToViews,
320 + 'viewsUrl' => $viewsUrl,
274 321 'viewFile' => "{$pathToViews}/{$path}/view.php",
275 322 );
276 323 return $viewInfo;
277 324 }