| @@ -115,8 +115,15 @@ | ||
| 115 | 115 | * put your comment there... |
| 116 | 116 | * |
| 117 | 117 | * @var mixed |
| 118 | 118 | */ |
| 119 | + protected $params = null; | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * put your comment there... | |
| 123 | + * | |
| 124 | + * @var mixed | |
| 125 | + */ | |
| 119 | 126 | protected $request; |
| 120 | 127 | |
| 121 | 128 | /** |
| 122 | 129 | * put your comment there... |
| @@ -134,12 +141,16 @@ | ||
| 134 | 141 | |
| 135 | 142 | /** |
| 136 | 143 | * put your comment there... |
| 137 | 144 | * |
| 145 | + * @param mixed $info | |
| 146 | + * @param mixed $params | |
| 147 | + * @return CJTView | |
| 138 | 148 | */ |
| 139 | - public function __construct($info) { | |
| 149 | + public function __construct($info, $params = null) { | |
| 140 | 150 | // Initialize vars! |
| 141 | 151 | $this->viewInfo = $info; |
| 152 | + $this->params = $params ? $params : array(); | |
| 142 | 153 | // Initialize events engine! |
| 143 | 154 | parent::__construct(); |
| 144 | 155 | // Fire created event! |
| 145 | 156 | $this->oncreated($info); |
| @@ -157,11 +168,12 @@ | ||
| 157 | 168 | /** |
| 158 | 169 | * put your comment there... |
| 159 | 170 | * |
| 160 | 171 | * @param mixed $view |
| 172 | + * @param mixed $params | |
| 161 | 173 | */ |
| 162 | - public static function getInstance($view) { | |
| 163 | - return self::trigger('CJTView.createview', CJTController::getView($view)); | |
| 174 | + public static function getInstance($view, $params = null) { | |
| 175 | + return self::trigger('CJTView.createview', CJTController::getView($view, $params)); | |
| 164 | 176 | } |
| 165 | 177 | |
| 166 | 178 | /** |
| 167 | 179 | * put your comment there... |
| @@ -178,12 +190,21 @@ | ||
| 178 | 190 | |
| 179 | 191 | /** |
| 180 | 192 | * put your comment there... |
| 181 | 193 | * |
| 194 | + * @param mixed $name | |
| 195 | + */ | |
| 196 | + public function getParam($name) { | |
| 197 | + return isset($this->params[$name]) ? $this->params[$name] : null; | |
| 198 | + } | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * put your comment there... | |
| 202 | + * | |
| 182 | 203 | * @param mixed $destination |
| 183 | 204 | */ |
| 184 | 205 | public function getPath($destination) { |
| 185 | - return self::getViewPath($this->viewInfo['name'], $destination); | |
| 206 | + return self::getViewPath($this->viewInfo['name'], $destination, $this->viewInfo['viewsPath']); | |
| 186 | 207 | } |
| 187 | 208 | |
| 188 | 209 | /** |
| 189 | 210 | * put your comment there... |
| @@ -199,9 +220,9 @@ | ||
| 199 | 220 | * @param mixed $name |
| 200 | 221 | * @param mixed $value |
| 201 | 222 | */ |
| 202 | 223 | public function getRequestParameter($name) { |
| 203 | - return $this->request[$name]; | |
| 224 | + return isset($this->request[$name]) ? $this->request[$name] : null; | |
| 204 | 225 | } |
| 205 | 226 | |
| 206 | 227 | /** |
| 207 | 228 | * put your comment there... |
| @@ -214,14 +235,14 @@ | ||
| 214 | 235 | $extension = '.html.tmpl'; |
| 215 | 236 | } |
| 216 | 237 | // filter parameters. |
| 217 | 238 | $params = $this->ontemplateparameters($params, $name, $dir, $extension); |
| 218 | - // Get template content into variable. | |
| 219 | - ob_start(); | |
| 220 | 239 | // Push params into the local scope. |
| 221 | 240 | extract($params); |
| 222 | 241 | // Templates collected under the view/tmpl directory. |
| 223 | 242 | $templateFile = $this->getPath("{$dir}/{$name}{$extension}"); |
| 243 | + // Get template content into variable. | |
| 244 | + ob_start(); | |
| 224 | 245 | require $this->onimporttemplate($templateFile); |
| 225 | 246 | $template = $this->onloadtemplate(ob_get_clean(), $name); |
| 226 | 247 | return $template; |
| 227 | 248 | } |
| @@ -230,9 +251,9 @@ | ||
| 230 | 251 | * put your comment there... |
| 231 | 252 | * |
| 232 | 253 | */ |
| 233 | 254 | public function getURI($destination) { |
| 234 | - return self::getViewURI($this->viewInfo['name'], $destination); | |
| 255 | + return self::getViewURI($this->viewInfo['name'], $destination, $this->viewInfo['viewsUrl']); | |
| 235 | 256 | } |
| 236 | 257 | |
| 237 | 258 | /** |
| 238 | 259 | * put your comment there... |
| @@ -239,10 +260,14 @@ | ||
| 239 | 260 | * |
| 240 | 261 | * @param mixed $view |
| 241 | 262 | * @param mixed $destination |
| 242 | 263 | */ |
| 243 | - public static function getViewPath($view, $destination) { | |
| 244 | - $viewPath = CJTOOLBOX_VIEWS_PATH . "/{$view}"; | |
| 264 | + public static function getViewPath($view, $destination, $overrideViewPath = null) { | |
| 265 | + # Use passed view path or use CJT constants if not passed | |
| 266 | + if (!$overrideViewPath) { | |
| 267 | + $overrideViewPath = CJTOOLBOX_VIEWS_PATH; | |
| 268 | + } | |
| 269 | + $viewPath = $overrideViewPath . DIRECTORY_SEPARATOR . $view; | |
| 245 | 270 | $destination = $destination ? "/{$destination}" : ''; |
| 246 | 271 | return "{$viewPath}{$destination}"; |
| 247 | 272 | } |
| 248 | 273 | |
| @@ -248,12 +273,17 @@ | ||
| 248 | 273 | |
| 249 | 274 | /** |
| 250 | 275 | * put your comment there... |
| 251 | 276 | * |
| 252 | - * @param mixed $file | |
| 277 | + * @param mixed $view | |
| 278 | + * @param mixed $destination | |
| 279 | + * @param mixed $overrideViewUrl | |
| 253 | 280 | */ |
| 254 | - public static function getViewURI($view, $destination) { | |
| 255 | - $viewURI = CJTOOLBOX_VIEWS_URL . "/{$view}/public"; | |
| 281 | + public static function getViewURI($view, $destination, $overrideViewUrl = null) { | |
| 282 | + if (!$overrideViewUrl) { | |
| 283 | + $overrideViewUrl = CJTOOLBOX_VIEWS_URL; | |
| 284 | + } | |
| 285 | + $viewURI = "{$overrideViewUrl}/{$view}/public"; | |
| 256 | 286 | return "{$viewURI}/{$destination}"; |
| 257 | 287 | } |
| 258 | 288 | |
| 259 | 289 | /** |
| @@ -320,8 +350,20 @@ | ||
| 320 | 350 | /** |
| 321 | 351 | * put your comment there... |
| 322 | 352 | * |
| 323 | 353 | */ |
| 354 | + protected function & suppressPrintScriptsHook() { | |
| 355 | + // Access Global. | |
| 356 | + global $wp_actions; | |
| 357 | + // Mark as triggered. | |
| 358 | + $wp_actions['wp_print_scripts'] = true; | |
| 359 | + // Chain. | |
| 360 | + return $this; | |
| 361 | + } | |
| 362 | + /** | |
| 363 | + * put your comment there... | |
| 364 | + * | |
| 365 | + */ | |
| 324 | 366 | protected static function useScripts($className, $scripts = null) { |
| 325 | 367 | wp_enqueue_script('Just Load Default Scripts, this works great!!!!'); |
| 326 | 368 | // Use current class name is $className is not provided! |
| 327 | 369 | if (!$className) { |
| @@ -341,19 +383,22 @@ | ||
| 341 | 383 | // Get script name. |
| 342 | 384 | preg_match($nameExp, $script, $scriptObject); |
| 343 | 385 | // [[2]Prefix], [4] name. Prefix may be not presented. |
| 344 | 386 | $name = "{$scriptObject[2]}{$scriptObject[4]}"; |
| 345 | - if (!$stack[$name]) { | |
| 387 | + $location = isset($scriptObject[7]) ? $scriptObject[7] : null; | |
| 388 | + $scriptParameters = isset($scriptObject[5]) ? $scriptObject[5] : ''; | |
| 389 | + if (!isset($stack[$name])) { | |
| 346 | 390 | // Any JS lib file should named the same as the parent folder with the extension added. |
| 347 | - $libPath = ":{$scriptObject[4]}:{$scriptObject[4]}"; | |
| 391 | + // Except files with _ at the begning | |
| 392 | + $libPath = ':' . ((strpos($scriptObject[4], '_') === 0) ? substr($scriptObject[4], 1) : "{$scriptObject[4]}:{$scriptObject[4]}"); | |
| 348 | 393 | // Pass virtual path to getURI and resolvePath to |
| 349 | 394 | // get JS file URI and localization file path. |
| 350 | 395 | $jsFile = cssJSToolbox::getURI(preg_replace($nameExp, "{$libPath}.js", $script)); |
| 351 | 396 | $localizationFile = cssJSToolbox::resolvePath(preg_replace($nameExp, "{$libPath}.localization.php", $script)); |
| 352 | 397 | // Enqueue script file. |
| 353 | - wp_enqueue_script($name, $jsFile, null, null, $scriptObject[7]); | |
| 398 | + wp_enqueue_script($name, $jsFile, null, null, $location); | |
| 354 | 399 | // Set script parameters. |
| 355 | - if (preg_match_all('/(\w+)=(\w+)/', $scriptObject[5], $params, PREG_SET_ORDER) ) { | |
| 400 | + if (preg_match_all('/(\w+)=(\w+)/', $scriptParameters, $params, PREG_SET_ORDER) ) { | |
| 356 | 401 | // Set parameters. |
| 357 | 402 | foreach ($params as $param) { |
| 358 | 403 | $stack[$name]->cjt[$param[1]] = $param[2]; |
| 359 | 404 | } |
| @@ -361,9 +406,8 @@ | ||
| 361 | 406 | // This object caryy other informations so that the other |
| 362 | 407 | // Plugin parts/components can use it to know how script file work. |
| 363 | 408 | $stack[$name]->cjt = (object) $stack[$name]->cjt; |
| 364 | 409 | } |
| 365 | - | |
| 366 | 410 | // If localization file exists localize JS. |
| 367 | 411 | if (file_exists($localizationFile)) { |
| 368 | 412 | // Get localization text array. |
| 369 | 413 | $localization = require $localizationFile; |
| @@ -375,9 +419,9 @@ | ||
| 375 | 419 | } |
| 376 | 420 | } |
| 377 | 421 | // Enqueue already registered scripts! |
| 378 | 422 | else { |
| 379 | - wp_enqueue_script($name, $jsFile, null, null, $scriptObject[7]); | |
| 423 | + wp_enqueue_script($name, null, null, null, $location); | |
| 380 | 424 | } |
| 381 | 425 | } |
| 382 | 426 | } |
| 383 | 427 | |
| @@ -404,9 +448,9 @@ | ||
| 404 | 448 | // Get script name. |
| 405 | 449 | preg_match($nameExp, $style, $styleObject); |
| 406 | 450 | // [[2]Prefix], [4] name. Prefix may be not presented. |
| 407 | 451 | $name = "{$styleObject[2]}{$styleObject[4]}"; |
| 408 | - if (!$GLOBALS['wp_styles']->registered[$name]) { | |
| 452 | + if (!isset($GLOBALS['wp_styles']->registered[$name])) { | |
| 409 | 453 | // Make all enqueued styles names unique from enqueued scripts. |
| 410 | 454 | // This is useful when merging styles & scripts is required. |
| 411 | 455 | $name = "CSS-{$name}"; |
| 412 | 456 | // Any JS lib file should named the same as the parent folder with the extension added. |
| @@ -417,9 +461,9 @@ | ||
| 417 | 461 | wp_enqueue_style($name, $cssFile); |
| 418 | 462 | } |
| 419 | 463 | else { |
| 420 | 464 | // Enqueue already registered styles. |
| 421 | - wp_enqueue_style($name, $cssFile); | |
| 465 | + wp_enqueue_style($name); | |
| 422 | 466 | } |
| 423 | 467 | } |
| 424 | 468 | } |
| 425 | 469 | |