| @@ -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 = '', | |
| 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'], $this->request, $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,36 +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) { | |
| 159 | + public static function create($name, $hasView = null, $request = null) { | |
| 179 | 160 | // Import controller file. |
| 180 | - $pathToControllers = $overrideControllersPath ? $overrideControllersPath : CJTOOLBOX_CONTROLLERS_PATH; | |
| 161 | + $pathToControllers = CJTOOLBOX_CONTROLLERS_PATH; | |
| 181 | 162 | $controllerFile = "{$pathToControllers}/{$name}.php"; |
| 182 | 163 | require_once self::trigger('CJTController.loadcontroller', $controllerFile, $name); |
| 183 | 164 | // Get controller class name. |
| 184 | - $class = self::getClassName($name, 'Controller', $overrideControllersPrefix); | |
| 165 | + $class = self::getClassName($name, 'Controller'); | |
| 185 | 166 | // Instantiate controller class. |
| 186 | - return new $class($hasView, $request, $overrideControllersPath, $overrideControllersPrefix); | |
| 167 | + return new $class($hasView, $request); | |
| 187 | 168 | } |
| 188 | - | |
| 169 | + | |
| 189 | 170 | /** |
| 190 | 171 | * put your comment there... |
| 191 | - * | |
| 172 | + * | |
| 192 | 173 | * @deprecated Use cssJSToolbox::createSecurityToken |
| 193 | 174 | */ |
| 194 | 175 | public function createSecurityToken() { |
| 195 | 176 | return wp_create_nonce(self::NONCE_ACTION); |
| @@ -196,47 +177,38 @@ | ||
| 196 | 177 | } |
| 197 | 178 | |
| 198 | 179 | /** |
| 199 | 180 | * put your comment there... |
| 200 | - * | |
| 181 | + * | |
| 201 | 182 | */ |
| 202 | 183 | protected function displayAction() { |
| 203 | 184 | // Get view layout! |
| 204 | - $layout = isset($this->request['layout']) ? esc_html($this->request['layout']) : 'default'; | |
| 185 | + $layout = isset($this->request['layout']) ? $this->request['layout'] : 'default'; | |
| 205 | 186 | ob_start(); |
| 206 | 187 | $this->view->display($layout); |
| 207 | 188 | $content = ob_get_clean(); |
| 208 | 189 | return $content; |
| 209 | 190 | } |
| 210 | - | |
| 191 | + | |
| 211 | 192 | /** |
| 212 | 193 | * put your comment there... |
| 213 | - * | |
| 194 | + * | |
| 214 | 195 | * @param mixed $name |
| 215 | 196 | * @param mixed $hasView |
| 216 | 197 | * @param mixed $request |
| 217 | - * @param mixed $overrideControllersPath | |
| 218 | 198 | */ |
| 219 | - public static function getInstance($name, | |
| 220 | - $hasView = null, | |
| 221 | - $request = null, | |
| 222 | - $overrideControllersPath = null, | |
| 223 | - $overrideControllersPrefix = null) { | |
| 224 | - 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); | |
| 225 | 201 | } |
| 226 | - | |
| 202 | + | |
| 227 | 203 | /** |
| 228 | 204 | * Use CJTModel::create instead. |
| 229 | - * | |
| 205 | + * | |
| 230 | 206 | * @deprecated No longer used. |
| 231 | 207 | */ |
| 232 | - public static function getModel($name, | |
| 233 | - $params = array(), | |
| 234 | - $file = null, | |
| 235 | - $overrideModelsPath = null, | |
| 236 | - $overrideModelsPrefix = null) { | |
| 208 | + public static function getModel($name, $params = array(), $file = null) { | |
| 237 | 209 | $model = null; |
| 238 | - $pathToModels = $overrideModelsPath ? ($overrideModelsPath . DIRECTORY_SEPARATOR . 'models') : CJTOOLBOX_MODELS_PATH; | |
| 210 | + $pathToModels = CJTOOLBOX_MODELS_PATH; | |
| 239 | 211 | if (!$file) { |
| 240 | 212 | $file = $name; |
| 241 | 213 | } |
| 242 | 214 | // Import model file. |
| @@ -242,9 +214,9 @@ | ||
| 242 | 214 | // Import model file. |
| 243 | 215 | $modelFile = "{$pathToModels}/{$file}.php"; |
| 244 | 216 | require_once $modelFile; |
| 245 | 217 | // Create model object. |
| 246 | - $modelClass = self::getClassName($name, 'Model', $overrideModelsPrefix); | |
| 218 | + $modelClass = self::getClassName($name, 'Model'); | |
| 247 | 219 | if (!class_exists($modelClass)) { |
| 248 | 220 | throw new Exception("Model class {$modelClass} doesn't exists!!!"); |
| 249 | 221 | } |
| 250 | 222 | $model = new $modelClass($params); |
| @@ -249,86 +221,72 @@ | ||
| 249 | 221 | } |
| 250 | 222 | $model = new $modelClass($params); |
| 251 | 223 | return $model; |
| 252 | 224 | } |
| 253 | - | |
| 225 | + | |
| 254 | 226 | /** |
| 255 | 227 | * @deprecated No longer used. |
| 256 | 228 | */ |
| 257 | - public static function getClassName($name, $type, $prefix = null) { | |
| 258 | - // Init vars | |
| 229 | + public static function getClassName($name, $type) { | |
| 259 | 230 | $className = ''; |
| 260 | - // Getting default prefix | |
| 261 | - if (!$prefix) { | |
| 262 | - $prefix = 'CJT'; | |
| 263 | - } | |
| 264 | 231 | // Every word start with uppercase character. |
| 265 | 232 | $sanitizedName = ucfirst(str_replace(array('-', '_'), ' ', "{$name} {$type}")); |
| 266 | 233 | // Remove spaces. |
| 267 | 234 | $sanitizedName = str_replace(' ', '', $sanitizedName); |
| 268 | 235 | // Filter. |
| 269 | - $className = self::trigger('CJTController.getclassname', "{$prefix}{$sanitizedName}", $name, $type); | |
| 236 | + $className = self::trigger('CJTController.getclassname', "CJT{$sanitizedName}", $name, $type); | |
| 270 | 237 | return $className; |
| 271 | 238 | } |
| 272 | - | |
| 239 | + | |
| 273 | 240 | /** |
| 274 | 241 | * put your comment there... |
| 275 | - * | |
| 242 | + * | |
| 276 | 243 | * @param mixed $name |
| 277 | 244 | */ |
| 278 | 245 | public function getRequestParameter($name) { |
| 279 | - return isset($this->request[$name]) ? esc_html($this->request[$name]) : null; | |
| 246 | + return isset($this->request[$name]) ? $this->request[$name] : null; | |
| 280 | 247 | } |
| 281 | - | |
| 248 | + | |
| 282 | 249 | /** |
| 283 | - * | |
| 250 | + * | |
| 284 | 251 | * Use CJTView:create instrad. |
| 285 | - * | |
| 252 | + * | |
| 286 | 253 | * @deprecated |
| 287 | 254 | */ |
| 288 | - public static function getView($path, | |
| 289 | - $params = null, | |
| 290 | - $overrideViewsPath = null, | |
| 291 | - $overrideViewsPrefix = null) { | |
| 255 | + public static function getView($path, $params = null) { | |
| 292 | 256 | $view = null; |
| 293 | 257 | // Import view file. |
| 294 | - $viewInfo = self::getViewInfo($path, $overrideViewsPath, $overrideViewsPrefix); | |
| 258 | + $viewInfo = self::getViewInfo($path); | |
| 295 | 259 | require_once $viewInfo['viewFile']; |
| 296 | 260 | // Create view object. |
| 297 | 261 | $name = str_replace(' ', '', ucwords(str_replace('/', ' ',$path))); |
| 298 | - $viewClass = self::getClassName($name, 'view', $overrideViewsPrefix); | |
| 262 | + $viewClass = self::getClassName($name, 'view'); | |
| 299 | 263 | $view = new $viewClass($viewInfo, $params); |
| 300 | 264 | return $view; |
| 301 | 265 | } |
| 302 | - | |
| 266 | + | |
| 303 | 267 | /** |
| 304 | 268 | * put your comment there... |
| 305 | - * | |
| 269 | + * | |
| 306 | 270 | */ |
| 307 | - public static function getViewInfo($path, $overrideViewsPath = null, $overrideViewsPrefix = null) { | |
| 308 | - // Plugin views Url | |
| 309 | - $viewsUrl = $overrideViewsPath ? | |
| 310 | - WP_PLUGIN_URL . '/' . basename(dirname($overrideViewsPath)) : | |
| 311 | - CJTOOLBOX_VIEWS_URL; | |
| 271 | + public static function getViewInfo($path) { | |
| 312 | 272 | // Path to views dir. |
| 313 | - $pathToViews = $overrideViewsPath ? ($overrideViewsPath . DIRECTORY_SEPARATOR . 'views') : CJTOOLBOX_VIEWS_PATH; | |
| 273 | + $pathToViews = CJTOOLBOX_VIEWS_PATH; | |
| 314 | 274 | // Get view name. |
| 315 | 275 | $name = basename($path); |
| 316 | 276 | // View info struct. |
| 317 | 277 | $viewInfo = array( |
| 318 | 278 | 'name' => $path, |
| 319 | - 'url' => "{$viewsUrl}/{$path}", | |
| 279 | + 'url' => (CJTOOLBOX_VIEWS_URL . "/{$path}"), | |
| 320 | 280 | 'path' => "{$pathToViews}/{$path}", |
| 321 | - 'viewsPath' => $pathToViews, | |
| 322 | - 'viewsUrl' => $viewsUrl, | |
| 323 | 281 | 'viewFile' => "{$pathToViews}/{$path}/view.php", |
| 324 | 282 | ); |
| 325 | 283 | return $viewInfo; |
| 326 | 284 | } |
| 327 | - | |
| 285 | + | |
| 328 | 286 | /** |
| 329 | 287 | * put your comment there... |
| 330 | - * | |
| 288 | + * | |
| 331 | 289 | * @param mixed $action |
| 332 | 290 | */ |
| 333 | 291 | public function setAction($action) { |
| 334 | 292 | $this->action = $action; |
| @@ -333,12 +291,12 @@ | ||
| 333 | 291 | public function setAction($action) { |
| 334 | 292 | $this->action = $action; |
| 335 | 293 | return $this; |
| 336 | 294 | } |
| 337 | - | |
| 295 | + | |
| 338 | 296 | /** |
| 339 | 297 | * put your comment there... |
| 340 | - * | |
| 298 | + * | |
| 341 | 299 | * @param mixed $name |
| 342 | 300 | * @param mixed $value |
| 343 | 301 | */ |
| 344 | 302 | public function setRequestParameter($name, $value) { |
| @@ -344,9 +302,9 @@ | ||
| 344 | 302 | public function setRequestParameter($name, $value) { |
| 345 | 303 | $this->request[$name] = $value; |
| 346 | 304 | return $this; |
| 347 | 305 | } |
| 348 | - | |
| 306 | + | |
| 349 | 307 | } // End class. |
| 350 | 308 | |
| 351 | 309 | // Hookable! |
| 352 | -CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER)); | |
| 310 | +CJTController::define('CJTController', array('hookType' => CJTWordpressEvents::HOOK_FILTER)); | |