| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version $ Id; blocks-coupling.php 21-03-2012 03:22:10 Ahmed Said $ |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* Applying Code blocks for the curren request. |
| 11 |
* |
| 12 |
* This controller is always loaded. |
| 13 |
* |
| 14 |
* The class resposibility is to output the code blocks |
| 15 |
* tha associated with current request. |
| 16 |
* |
| 17 |
* @author Ahmed Said |
| 18 |
* @version 6 |
| 19 |
*/ |
| 20 |
class CJTBlocksCouplingController extends CJTController { |
| 21 |
|
| 22 |
/** |
| 23 |
* put your comment there... |
| 24 |
* |
| 25 |
* @var mixed |
| 26 |
*/ |
| 27 |
public $blocks = array( |
| 28 |
'code' => array(), |
| 29 |
'scripts' => array(), |
| 30 |
); |
| 31 |
|
| 32 |
/** |
| 33 |
* put your comment there... |
| 34 |
* |
| 35 |
* @var mixed |
| 36 |
*/ |
| 37 |
protected $controllerInfo = array('model' => 'coupling'); |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @var mixed |
| 43 |
*/ |
| 44 |
protected $filters = null; |
| 45 |
|
| 46 |
/** |
| 47 |
* put your comment there... |
| 48 |
* |
| 49 |
* @var mixed |
| 50 |
*/ |
| 51 |
protected $hookAttacher; |
| 52 |
|
| 53 |
/** |
| 54 |
* put your comment there... |
| 55 |
* |
| 56 |
* @var mixed |
| 57 |
*/ |
| 58 |
protected static $instance = null; |
| 59 |
|
| 60 |
/** |
| 61 |
* put your comment there... |
| 62 |
* |
| 63 |
* @var mixed |
| 64 |
*/ |
| 65 |
private $onActionIds = array(); |
| 66 |
|
| 67 |
/** |
| 68 |
* put your comment there... |
| 69 |
* |
| 70 |
* @var mixed |
| 71 |
*/ |
| 72 |
protected $onassigncouplingcallback = array('parameters' => array('callback')); |
| 73 |
|
| 74 |
/** |
| 75 |
* put your comment there... |
| 76 |
* |
| 77 |
* @var mixed |
| 78 |
*/ |
| 79 |
protected $onappendcode = array('parameters' => array('code')); |
| 80 |
|
| 81 |
/** |
| 82 |
* put your comment there... |
| 83 |
* |
| 84 |
* @var mixed |
| 85 |
*/ |
| 86 |
protected $onblockmatched = array('parameters' => array('block')); |
| 87 |
|
| 88 |
/** |
| 89 |
* put your comment there... |
| 90 |
* |
| 91 |
* @var mixed |
| 92 |
*/ |
| 93 |
protected $oncancelmatching = array('parameters' => array('matched')); |
| 94 |
|
| 95 |
/** |
| 96 |
* put your comment there... |
| 97 |
* |
| 98 |
* @var mixed |
| 99 |
*/ |
| 100 |
protected $ondefaultfilters = array('parameters' => array('filters')); |
| 101 |
|
| 102 |
/** |
| 103 |
* put your comment there... |
| 104 |
* |
| 105 |
* @var mixed |
| 106 |
*/ |
| 107 |
protected $ondo = array('parameters' => array('data', 'method', 'condition')); |
| 108 |
|
| 109 |
/** |
| 110 |
* put your comment there... |
| 111 |
* |
| 112 |
* @var mixed |
| 113 |
*/ |
| 114 |
protected $onblocksorder = array('parameters' => array('order')); |
| 115 |
|
| 116 |
/** |
| 117 |
* put your comment there... |
| 118 |
* |
| 119 |
* @var mixed |
| 120 |
*/ |
| 121 |
protected $onevalcodeblock = array( 'parameters' => array( 'keep', 'block' ) ); |
| 122 |
|
| 123 |
/** |
| 124 |
* put your comment there... |
| 125 |
* |
| 126 |
* @var mixed |
| 127 |
*/ |
| 128 |
protected $ongetblocks = array('parameters' => array('blocks')); |
| 129 |
|
| 130 |
/** |
| 131 |
* put your comment there... |
| 132 |
* |
| 133 |
* @var mixed |
| 134 |
*/ |
| 135 |
protected $ongetcache = array('parameters' => array('cache')); |
| 136 |
|
| 137 |
/** |
| 138 |
* put your comment there... |
| 139 |
* |
| 140 |
* @var mixed |
| 141 |
*/ |
| 142 |
protected $ongetfilters = array('parameters' => array('filters')); |
| 143 |
|
| 144 |
/** |
| 145 |
* put your comment there... |
| 146 |
* |
| 147 |
* @var mixed |
| 148 |
*/ |
| 149 |
protected $onlinkedtemplates = array('parameters' => array('templates')); |
| 150 |
|
| 151 |
/** |
| 152 |
* put your comment there... |
| 153 |
* |
| 154 |
* @var mixed |
| 155 |
*/ |
| 156 |
protected $onlinkscripts = array('parameters' => array('templates')); |
| 157 |
|
| 158 |
/** |
| 159 |
* put your comment there... |
| 160 |
* |
| 161 |
* @var mixed |
| 162 |
*/ |
| 163 |
protected $onlinkstyles = array('parameters' => array('templates')); |
| 164 |
|
| 165 |
/** |
| 166 |
* put your comment there... |
| 167 |
* |
| 168 |
* @var mixed |
| 169 |
*/ |
| 170 |
protected $onlinktemplate = array('parameters' => array('template')); |
| 171 |
|
| 172 |
/** |
| 173 |
* put your comment there... |
| 174 |
* |
| 175 |
* @var mixed |
| 176 |
*/ |
| 177 |
protected $onmatchingurls = array('parameters' => array('urls')); |
| 178 |
|
| 179 |
/** |
| 180 |
* put your comment there... |
| 181 |
* |
| 182 |
* @var mixed |
| 183 |
*/ |
| 184 |
protected $onnoblocks = array('hookType' => CJTWordpressEvents::HOOK_ACTION); |
| 185 |
|
| 186 |
/** |
| 187 |
* put your comment there... |
| 188 |
* |
| 189 |
* @var mixed |
| 190 |
*/ |
| 191 |
protected $onoutput = array('parameters' => array('code', 'location')); |
| 192 |
|
| 193 |
/** |
| 194 |
* put your comment there... |
| 195 |
* |
| 196 |
* @var mixed |
| 197 |
*/ |
| 198 |
protected $onprocess = array('hookType' => CJTWordpressEvents::HOOK_ACTION); |
| 199 |
|
| 200 |
/** |
| 201 |
* put your comment there... |
| 202 |
* |
| 203 |
* @var mixed |
| 204 |
*/ |
| 205 |
protected $onprocessblock = array('parameters' => array('block')); |
| 206 |
|
| 207 |
/** |
| 208 |
* put your comment there... |
| 209 |
* |
| 210 |
* @var mixed |
| 211 |
*/ |
| 212 |
protected $onqueuecss = array('parameters' => array('style')); |
| 213 |
|
| 214 |
/** |
| 215 |
* put your comment there... |
| 216 |
* |
| 217 |
* @var mixed |
| 218 |
*/ |
| 219 |
protected $onqueuejavascript = array('parameters' => array('script')); |
| 220 |
|
| 221 |
/** |
| 222 |
* put your comment there... |
| 223 |
* |
| 224 |
* @var mixed |
| 225 |
*/ |
| 226 |
protected $onsetfilters = array('parameters' => array('filters')); |
| 227 |
|
| 228 |
/** |
| 229 |
* put your comment there... |
| 230 |
* |
| 231 |
* @var mixed |
| 232 |
*/ |
| 233 |
protected $templates = array(); |
| 234 |
|
| 235 |
/** |
| 236 |
* Initialize controller object. |
| 237 |
* |
| 238 |
* @see CJTController for more details |
| 239 |
* @return void |
| 240 |
*/ |
| 241 |
public function __construct() { |
| 242 |
|
| 243 |
// Only one instance is allowed. |
| 244 |
if (self::$instance) { |
| 245 |
throw new Exception('Trying to instantiate multiple coupling instances!!'); |
| 246 |
} |
| 247 |
|
| 248 |
// Hold the single instance we've! |
| 249 |
self::$instance = $this; |
| 250 |
$siteHook = cssJSToolbox::$config->core->siteHook; |
| 251 |
|
| 252 |
// Initialize controller. |
| 253 |
parent::__construct(false); |
| 254 |
|
| 255 |
// Import related libraries |
| 256 |
CJTModel::import('block'); |
| 257 |
|
| 258 |
// Not default action needed. |
| 259 |
$this->defaultAction = null; |
| 260 |
$this->hookAttacher = new CJTBlocksCouplingHookAttacher(array(&$this, 'outputBlocks')); |
| 261 |
|
| 262 |
// Initialize Blocks array |
| 263 |
foreach ($this->hookAttacher->getFiltersList() as $hooks) { |
| 264 |
|
| 265 |
foreach ($hooks as $hook) { |
| 266 |
|
| 267 |
$this->blocks['code'][$hook['locationName']] = ''; |
| 268 |
$this->blocks['script'][$hook['locationName']] = ''; |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
// Initialize controller. |
| 273 |
$initCouplingCallback = $this->onassigncouplingcallback(array(&$this, 'initCoupling')); |
| 274 |
add_action('admin_init', $initCouplingCallback); |
| 275 |
add_action($siteHook->tag, $initCouplingCallback, $siteHook->priority); |
| 276 |
|
| 277 |
// Add Shortcode callbacks. |
| 278 |
add_shortcode('cjtoolbox', array(&$this, 'shortcode')); |
| 279 |
} |
| 280 |
|
| 281 |
/** |
| 282 |
* put your comment there... |
| 283 |
* |
| 284 |
* @param mixed $id |
| 285 |
*/ |
| 286 |
public function addOnActionIds($id) { |
| 287 |
// Add ID is not exists. |
| 288 |
if (!in_array($id, $this->onActionIds)) { |
| 289 |
$this->onActionIds[] = $id; |
| 290 |
} |
| 291 |
// Chaining. |
| 292 |
return $this; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* put your comment there... |
| 297 |
* |
| 298 |
*/ |
| 299 |
public function getBlocks() |
| 300 |
{ |
| 301 |
// Set request view filters used for querying database. |
| 302 |
$this->setRequestFilters(); |
| 303 |
|
| 304 |
// Get blocks order. NOTE: This is all blocks order not only the queried/target blocks. |
| 305 |
$blocksOrder = array(); |
| 306 |
$metaBoxesOrder = $this->onblocksorder( $this->model->getOrder() ); |
| 307 |
|
| 308 |
// Get ORDER-INDEX <TO> BLOCK-ID mapping. |
| 309 |
if ( $metaBoxesOrder ) preg_match_all( '/cjtoolbox-(\d+)/', $metaBoxesOrder[ 'normal' ], $blocksOrder, PREG_SET_ORDER ); |
| 310 |
|
| 311 |
/** |
| 312 |
* append more to orders produced by CJTBlocksCouplingController::setRequestFilter(). |
| 313 |
* More to orders may allow other blocks to bein the output (e.g metaboxe blocks). |
| 314 |
*/ |
| 315 |
$blocksOrder = array_merge( $blocksOrder, $this->getFilters()->moreToOrder ); |
| 316 |
|
| 317 |
// Prepare request URL to match against Links & Expressions. |
| 318 |
$linksRequestURL = self::getRequestURL(); |
| 319 |
$expressionsRequestURL = "{$linksRequestURL}?{$_SERVER['QUERY_STRING']}"; |
| 320 |
|
| 321 |
extract( $this->onmatchingurls( compact( 'linksRequestURL', 'expressionsRequestURL' ) ) ); |
| 322 |
|
| 323 |
// Get all blocks including (Links & Expressions Blocks). |
| 324 |
$blocks = $this->ongetblocks( |
| 325 |
|
| 326 |
$this->model->getPinsBlocks( |
| 327 |
|
| 328 |
CJTBlockModel::PINS_LINK_EXPRESSION, |
| 329 |
|
| 330 |
$this->getFilters()->pinPoint, |
| 331 |
|
| 332 |
$this->getFilters()->customPins, |
| 333 |
|
| 334 |
$this->getFilters() |
| 335 |
|
| 336 |
) |
| 337 |
|
| 338 |
); |
| 339 |
|
| 340 |
|
| 341 |
if ( empty( $blocks ) ) |
| 342 |
{ |
| 343 |
$this->onnoblocks(); |
| 344 |
|
| 345 |
return false; |
| 346 |
|
| 347 |
} |
| 348 |
|
| 349 |
// Import related libraries. |
| 350 |
cssJSToolbox::import( 'framework:php:evaluator:evaluator.inc.php' ); |
| 351 |
|
| 352 |
/** |
| 353 |
* Iterator over all blocks by using they order. |
| 354 |
* For each block get code and scripts. |
| 355 |
*/ |
| 356 |
$this->onprocess(); |
| 357 |
|
| 358 |
foreach ( $blocksOrder as $blockOrder ) |
| 359 |
{ |
| 360 |
|
| 361 |
$blockId = (int) $blockOrder[1]; |
| 362 |
|
| 363 |
// As mentioned above. Orders is for all blocks not just those queried from db. |
| 364 |
if ( isset($blocks[ $blockId ] ) ) |
| 365 |
{ |
| 366 |
|
| 367 |
$block = $this->onprocessblock( $blocks[ $blockId ] ); |
| 368 |
|
| 369 |
/** |
| 370 |
* Process Links & Expressions blocks. |
| 371 |
* For better performace check only those with links and expressions flags. |
| 372 |
*/ |
| 373 |
if ( $block->blocksGroup & CJTBlockModel::PINS_LINK_EXPRESSION ) |
| 374 |
{ |
| 375 |
/** |
| 376 |
* Initiliaze $matchedLink and $matchedExpression inside IF statment. |
| 377 |
* Those variables need to refresh state at each block. |
| 378 |
* If there is no link or expression flags, they will be FALSE. |
| 379 |
* Otherwise they'll get the correct value inside each statement. |
| 380 |
*/ |
| 381 |
/// Check if there is a matched link. |
| 382 |
if ( $matchedLink = ( $block->blocksGroup & CJTBlockModel::PINS_LINKS ) ) |
| 383 |
{ |
| 384 |
$links = explode( "\n", trim( $block->links ) ); |
| 385 |
$matchedLink = in_array( $linksRequestURL, $links ); |
| 386 |
} |
| 387 |
|
| 388 |
/// Check if there is a matched expression. |
| 389 |
if ( $matchedExpression = ( $block->blocksGroup & CJTBlockModel::PINS_EXPRESSIONS ) ) |
| 390 |
{ |
| 391 |
$expressions = explode("\n", $block->expressions); |
| 392 |
|
| 393 |
foreach ( $expressions as $expression ) |
| 394 |
{ |
| 395 |
/// @TODO: Matches may be used later to evaulate variables inside code block. |
| 396 |
if( $matchedExpression = @ preg_match( "/{$expression}/", $expressionsRequestURL ) ) |
| 397 |
{ |
| 398 |
break; |
| 399 |
} |
| 400 |
|
| 401 |
} |
| 402 |
|
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Exclude Links & Expressions Blocks that doesn't has a match. |
| 407 |
* If there is no matched link or expression then exclude block. |
| 408 |
*/ |
| 409 |
if ( $this->oncancelmatching( ! ( $matchedExpression || $matchedLink ) ) ) |
| 410 |
{ |
| 411 |
continue; |
| 412 |
} |
| 413 |
|
| 414 |
} |
| 415 |
// Allow extensions to control to prevent block from being in the output |
| 416 |
if ( $block = $this->onblockmatched( $block ) ) |
| 417 |
{ |
| 418 |
// Retrieve block code-files. |
| 419 |
$block->code = $this->model->getBlockCode( $block->id ); |
| 420 |
|
| 421 |
// Import Executable (PHP and HTML) templates. |
| 422 |
$block->code = $block->code . $this->model->getExecTemplatesCode( $block->id ); |
| 423 |
|
| 424 |
// For every location store blocks code into single string |
| 425 |
|
| 426 |
if ( ! $evaluatedCode = $this->onevalcodeblock( false, $block ) ) |
| 427 |
{ |
| 428 |
$evaluatedCode = CJTPHPCodeEvaluator::getInstance( $block )->exec()->getOutput(); |
| 429 |
} |
| 430 |
|
| 431 |
/** @todo Include Debuging info only if we're in debuging mode! */ |
| 432 |
if ( 1 ) { |
| 433 |
// CODE UPDATED BY RBJ -- START |
| 434 |
if (trim($evaluatedCode) != ''): |
| 435 |
global $post; |
| 436 |
$checkMetaBlock = get_post_meta($post->ID, '__CJT-BLOCK-ID', true); |
| 437 |
|
| 438 |
if (!empty($checkMetaBlock) && $checkMetaBlock == $blockId): |
| 439 |
$evaluatedCode = "\n\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - END -->\n\n"; |
| 440 |
else: |
| 441 |
$evaluatedCode = "\n\n<!-- CJT Global Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Global Block ({$blockId}) - {$block->name} - END -->\n\n"; |
| 442 |
endif; |
| 443 |
endif; |
| 444 |
// CODE UPDATED BY RBJ -- END |
| 445 |
} |
| 446 |
|
| 447 |
// Initialize block LOCATION array for the first time |
| 448 |
if (!isset($this->blocks[ 'code' ][ $block->location ])) { |
| 449 |
|
| 450 |
$this->blocks[ 'code' ][ $block->location ] = ''; |
| 451 |
} |
| 452 |
|
| 453 |
$this->blocks[ 'code' ][ $block->location ] .= $this->onappendcode( $evaluatedCode ); |
| 454 |
|
| 455 |
// Store all used Ids in the CORRECT ORDER. |
| 456 |
$this->addOnActionIds( $blockId ); |
| 457 |
} |
| 458 |
|
| 459 |
} |
| 460 |
|
| 461 |
} |
| 462 |
|
| 463 |
$templates = $this->onActionIds ? |
| 464 |
$this->model->getLinkedTemplates( $this->onActionIds ) : |
| 465 |
array(); |
| 466 |
|
| 467 |
// Classisfy as we process Scripts and Styles separatly (different hooks!). |
| 468 |
foreach ( $this->onlinkedtemplates( $templates ) as $id => $template ) |
| 469 |
{ |
| 470 |
// Filer template! |
| 471 |
extract( $this->onlinktemplate( compact( 'template', 'id' ) ) ); |
| 472 |
|
| 473 |
$this->templates[ $template->type ][ $id ] = $template; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
return true; |
| 478 |
} |
| 479 |
|
| 480 |
/** |
| 481 |
* put your comment there... |
| 482 |
* |
| 483 |
*/ |
| 484 |
public function getCached() { |
| 485 |
// Cache is not implemented yet might be supported by extenal Extensions! |
| 486 |
return $this->ongetcache(false); |
| 487 |
} |
| 488 |
|
| 489 |
/** |
| 490 |
* put your comment there... |
| 491 |
* |
| 492 |
*/ |
| 493 |
public function getFilters() { |
| 494 |
return $this->ongetfilters($this->filters); |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* put your comment there... |
| 499 |
* |
| 500 |
*/ |
| 501 |
public function & getHooksAttacher() { |
| 502 |
return $this->hookAttacher; |
| 503 |
} |
| 504 |
|
| 505 |
/** |
| 506 |
* put your comment there... |
| 507 |
* |
| 508 |
*/ |
| 509 |
public function getOnActionIds() { |
| 510 |
return $this->onActionIds; |
| 511 |
} |
| 512 |
|
| 513 |
/** |
| 514 |
* put your comment there... |
| 515 |
* |
| 516 |
*/ |
| 517 |
public static function getRequestURL() { |
| 518 |
// URL Protocol. |
| 519 |
$protocol = 'http' . ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) ? 's' : '') . '://'; |
| 520 |
// Host name & port. |
| 521 |
$host = $_SERVER['HTTP_HOST']; |
| 522 |
$port = ($_SERVER["SERVER_PORT"] != "80") ? ":{$_SERVER["SERVER_PORT"]}" : ''; |
| 523 |
// Request URI. |
| 524 |
$requestURI = $_SERVER['REQUEST_URI']; |
| 525 |
// Final URL. |
| 526 |
$url = "{$protocol}{$host}{$port}{$requestURI}"; |
| 527 |
return $url; |
| 528 |
} |
| 529 |
|
| 530 |
/** |
| 531 |
* put your comment there... |
| 532 |
* |
| 533 |
*/ |
| 534 |
public function hasOnActionIds() { |
| 535 |
return !empty($this->onActionIds); |
| 536 |
} |
| 537 |
|
| 538 |
/** |
| 539 |
* put your comment there... |
| 540 |
* |
| 541 |
*/ |
| 542 |
public function initCoupling() { |
| 543 |
// For some reasons wp action is fired twice. |
| 544 |
// The wrong call won't has $wp_query object set, |
| 545 |
// but this is only valid at Front end. |
| 546 |
if (!is_admin() && !$GLOBALS['wp_query']) { |
| 547 |
return; |
| 548 |
} |
| 549 |
// Get current application hook prefix. |
| 550 |
$actionsPrefix = is_admin() ? 'admin' : 'wp'; |
| 551 |
|
| 552 |
// Get cache or get blocks if not cached. |
| 553 |
// If there is no cache or no blocks for output |
| 554 |
// do nothing. |
| 555 |
if ($this->getCached() || $this->getBlocks()) { |
| 556 |
|
| 557 |
// Output blocks on various locations! |
| 558 |
$this->hookAttacher->bind(); |
| 559 |
|
| 560 |
// Links templates & styloes! |
| 561 |
add_action("{$actionsPrefix}_enqueue_scripts", array(&$this, 'linkTemplates'), 30); |
| 562 |
add_action("{$actionsPrefix}_print_styles", array(&$this, 'linkTemplates'), 30); |
| 563 |
} |
| 564 |
|
| 565 |
// Link style sheet in footer required custom implementation. |
| 566 |
add_action("{$actionsPrefix}_print_footer_scripts", array(&$this, 'linkFooterStyleSheets'), 9); |
| 567 |
// Make sure this is executed only once. |
| 568 |
// Sometimes wp hook run on backend and sometimes its not. |
| 569 |
// This method handle both front and backend requests. |
| 570 |
// Simply remove all hooks to ensure its run only one time. |
| 571 |
remove_action('wp', array(&$this, 'initCoupling')); |
| 572 |
remove_action('admin_init', array(&$this, 'initCoupling')); |
| 573 |
} |
| 574 |
|
| 575 |
/** |
| 576 |
* put your comment there... |
| 577 |
* |
| 578 |
*/ |
| 579 |
public function linkFooterStyleSheets() { |
| 580 |
// Initialize. |
| 581 |
$styles = array(); |
| 582 |
// Get queued style sheets! |
| 583 |
global $wp_styles; |
| 584 |
$queuedStyles =& $wp_styles->queue; |
| 585 |
// Process only 'cjt' templates, |
| 586 |
foreach ($queuedStyles as $index => $styleName) { |
| 587 |
if (strpos($styleName, 'cjt-css-template-') === 0) { |
| 588 |
// Get style name src file, prepend to Wordpress absolute path. |
| 589 |
$style = $wp_styles->registered[$styleName]; |
| 590 |
$styles[] = home_url($style->src); |
| 591 |
// Stop Wordpress from output <link> tag outside head tag |
| 592 |
// as it has no effect. |
| 593 |
unset($queuedStyles[$index]); |
| 594 |
} |
| 595 |
} |
| 596 |
// Enqueue Style Sheet loader javascript if there is any |
| 597 |
// styles need to be loaded. |
| 598 |
if (!empty($styles)) { |
| 599 |
// jQuery is dpendency object required by the loader. |
| 600 |
wp_enqueue_script('jquery'); |
| 601 |
// Enqueue footer style sheet loader. |
| 602 |
wp_enqueue_script('cjt-coupling-footer-css-loader', cssJSToolbox::getURI('controllers:coupling:js:footer-stylesheet-loader.js')); |
| 603 |
// Output JavaScript array to be filled with the styles! |
| 604 |
$jsStyleSheetsList = json_encode($styles); |
| 605 |
require cssJSToolbox::resolvePath('controllers:coupling:html:load-footer-style.html.php'); |
| 606 |
} |
| 607 |
} |
| 608 |
|
| 609 |
/** |
| 610 |
* put your comment there... |
| 611 |
* |
| 612 |
*/ |
| 613 |
public function linkTemplates() { |
| 614 |
$currentFilter = current_filter(); |
| 615 |
// Derived template Type from Wordpress filter. |
| 616 |
$filterFor = explode('_', $currentFilter); $filterFor = array_pop($filterFor); |
| 617 |
$type = CJTCouplingModel::$templateTypes[$filterFor]; |
| 618 |
// Following vars are referenced based on the current type. |
| 619 |
$templates = isset($this->templates[$type]) ? $this->templates[$type] : array(); |
| 620 |
// Filering! |
| 621 |
$templates = $this->{"onlink{$filterFor}"}($templates); |
| 622 |
/** |
| 623 |
* @var WP_Dependencies |
| 624 |
*/ |
| 625 |
$queue = $this->model->getQueueObject($filterFor); |
| 626 |
// Add templates to the queye. |
| 627 |
foreach ($templates as $template) { |
| 628 |
// Registery only if not yet registered. |
| 629 |
$template = $this->{"onqueue{$type}"}($template); |
| 630 |
if (!isset($queue->registered[$template->queueName])) { |
| 631 |
$queue->add($template->queueName, "/{$template->file}", null, $template->version); |
| 632 |
} |
| 633 |
// Always make sure the template is queued. |
| 634 |
$queue->enqueue($template->queueName); |
| 635 |
} |
| 636 |
} |
| 637 |
|
| 638 |
/** |
| 639 |
* put your comment there... |
| 640 |
* |
| 641 |
*/ |
| 642 |
public function outputBlocks() { |
| 643 |
|
| 644 |
$hooks = $this->hookAttacher->getHooksByFilterName(current_filter()); |
| 645 |
|
| 646 |
foreach ($hooks as $hook) { |
| 647 |
|
| 648 |
echo $this->onoutput($this->blocks['code'][$hook['locationName']], $hook['locationName']); |
| 649 |
} |
| 650 |
|
| 651 |
} |
| 652 |
|
| 653 |
/** |
| 654 |
* put your comment there... |
| 655 |
* |
| 656 |
*/ |
| 657 |
protected function setRequestFilters() |
| 658 |
{ |
| 659 |
// Get request blocks. |
| 660 |
$filters = $this->ondefaultfilters( ( object ) array |
| 661 |
( |
| 662 |
|
| 663 |
'pinPoint' => 0x00000000, |
| 664 |
|
| 665 |
'customPins' => array(), |
| 666 |
|
| 667 |
'moreToOrder' => array(), |
| 668 |
|
| 669 |
'currentObject' => null, |
| 670 |
|
| 671 |
'currentCustomPin' => 0, |
| 672 |
|
| 673 |
'params' => array(), |
| 674 |
|
| 675 |
) ); |
| 676 |
|
| 677 |
if ( is_admin() ) |
| 678 |
{ |
| 679 |
// Include all backend blocks. |
| 680 |
$filters->pinPoint |= CJTBlockModel::PINS_BACKEND; |
| 681 |
} |
| 682 |
else |
| 683 |
{ |
| 684 |
$filters->pinPoint |= CJTBlockModel::PINS_FRONTEND; |
| 685 |
|
| 686 |
// Pages. |
| 687 |
if ( is_page() ) |
| 688 |
{ |
| 689 |
// Blocks with ALL PAGES selected. |
| 690 |
$filters->pinPoint |= CJTBlockModel::PINS_PAGES_ALL_PAGES; |
| 691 |
|
| 692 |
$filters->currentObject = $GLOBALS[ 'post' ]; |
| 693 |
$filters->currentCustomPin = CJTBlockModel::PINS_PAGES_CUSTOM_PAGE; |
| 694 |
|
| 695 |
// Blocks with PAGE-ID selected. |
| 696 |
$filters->customPins[ ] = array |
| 697 |
( |
| 698 |
'pin' => 'pages', |
| 699 |
|
| 700 |
'pins' => array( $filters->currentObject->ID ), |
| 701 |
|
| 702 |
'flag' => CJTBlockModel::PINS_PAGES_CUSTOM_PAGE, |
| 703 |
|
| 704 |
); |
| 705 |
|
| 706 |
// Blocks with FRONT-PAGE selected. |
| 707 |
if ( is_front_page() ) |
| 708 |
{ |
| 709 |
$filters->pinPoint |= CJTBlockModel::PINS_PAGES_FRONT_PAGE; |
| 710 |
} |
| 711 |
|
| 712 |
/** |
| 713 |
* In order for metabox block to get in the output we need |
| 714 |
* to add metabox order for it. |
| 715 |
* @see CJTBlocksCouplingController::getBlocks. |
| 716 |
*/ |
| 717 |
$metabox = CJTModel::create( 'metabox', array( $filters->currentObject->ID ) ); |
| 718 |
|
| 719 |
$filters->moreToOrder[ ][ 1 ] = $metabox->getMetaboxId(); |
| 720 |
|
| 721 |
} // End is_page() |
| 722 |
|
| 723 |
else if ( is_attachment() ) |
| 724 |
{ |
| 725 |
$filters->pinPoint |= CJTBlockModel::PINS_ATTACHMENT; |
| 726 |
} |
| 727 |
// Posts. |
| 728 |
else if ( is_single() ) |
| 729 |
{ |
| 730 |
// Blocks with ALL POSTS & ALL CATEGORIES selected. |
| 731 |
$filters->pinPoint |= CJTBlockModel::PINS_POSTS_ALL_POSTS | CJTBlockModel::PINS_CATEGORIES_ALL_CATEGORIES; |
| 732 |
|
| 733 |
$filters->currentObject = $GLOBALS[ 'post' ]; |
| 734 |
$filters->currentCustomPin = CJTBlockModel::PINS_POSTS_CUSTOM_POST; |
| 735 |
|
| 736 |
// Blocks with POST-ID selected. |
| 737 |
|
| 738 |
$filters->customPins[ ] = array |
| 739 |
( |
| 740 |
|
| 741 |
'pin' => 'posts', |
| 742 |
|
| 743 |
'pins' => array( $filters->currentObject->ID ), |
| 744 |
|
| 745 |
'flag' => CJTBlockModel::PINS_POSTS_CUSTOM_POST, |
| 746 |
|
| 747 |
); |
| 748 |
|
| 749 |
// Include POST PARENT CATRGORIES blocks. |
| 750 |
$parentCategoriesIds = wp_get_post_categories( $filters->currentObject->ID, array( 'fields' => 'ids' ) ); |
| 751 |
|
| 752 |
/** |
| 753 |
* Custom-Posts just added "ON THE RUN/FLY" |
| 754 |
* Need simple fix by confirming that the post is belong to |
| 755 |
* specific category or not. |
| 756 |
* Custom posts NOW unlike Posts, it doesn't inherit parent |
| 757 |
* taxonomis Code Blocks!! |
| 758 |
*/ |
| 759 |
if ( ! empty( $parentCategoriesIds ) ) |
| 760 |
{ |
| 761 |
|
| 762 |
$filters->params[ 'hasCategories' ] = true; |
| 763 |
$filters->params[ 'parentCategories' ] = $parentCategoriesIds; |
| 764 |
|
| 765 |
$filters->customPins[ ] = array |
| 766 |
( |
| 767 |
|
| 768 |
'pin' => 'categories', |
| 769 |
|
| 770 |
'pins' => $parentCategoriesIds, |
| 771 |
|
| 772 |
'flag' => CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY, |
| 773 |
|
| 774 |
); |
| 775 |
|
| 776 |
} |
| 777 |
|
| 778 |
/** |
| 779 |
* In order for metabox block to get in the output we need |
| 780 |
* to add metabox order for it. |
| 781 |
* @see CJTBlocksCouplingController::getBlocks. |
| 782 |
*/ |
| 783 |
$metabox = CJTModel::create( 'metabox', array( $filters->currentObject->ID ) ); |
| 784 |
|
| 785 |
$filters->moreToOrder[][ 1 ] = $metabox->getMetaboxId(); |
| 786 |
|
| 787 |
/** |
| 788 |
* @TODO check for recent posts Based on user configuration. |
| 789 |
* Recent posts should be detcted by comparing |
| 790 |
* user condifguration with post date. |
| 791 |
*/ |
| 792 |
if ( 0 ) { |
| 793 |
|
| 794 |
} |
| 795 |
} // End is_single() |
| 796 |
|
| 797 |
// Categories. |
| 798 |
else if( is_category() ) |
| 799 |
{ |
| 800 |
// Blocks with ALL CATEGORIES selected. |
| 801 |
$filters->pinPoint |= CJTBlockModel::PINS_CATEGORIES_ALL_CATEGORIES; |
| 802 |
|
| 803 |
$filters->currentObject = get_queried_object(); |
| 804 |
$filters->currentCustomPin = CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY; |
| 805 |
|
| 806 |
// Blocks with CATEGORY-ID selected. |
| 807 |
$filters->customPins[] = array |
| 808 |
( |
| 809 |
'pin' => 'categories', |
| 810 |
|
| 811 |
'pins' => array( $filters->currentObject->term_id ), |
| 812 |
|
| 813 |
'flag' => CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY, |
| 814 |
|
| 815 |
); |
| 816 |
|
| 817 |
} // End is_category() |
| 818 |
|
| 819 |
// Blocks with BLOG-INDEX selected. |
| 820 |
else if ( is_home() ) |
| 821 |
{ |
| 822 |
$filters->pinPoint |= CJTBlockModel::PINS_POSTS_BLOG_INDEX; |
| 823 |
} |
| 824 |
else if ( is_search() ) |
| 825 |
{ |
| 826 |
$filters->pinPoint |= CJTBlockModel::PINS_SEARCH; |
| 827 |
} |
| 828 |
else if ( is_tag() ) |
| 829 |
{ |
| 830 |
$filters->pinPoint |= CJTBlockModel::PINS_TAG; |
| 831 |
} |
| 832 |
else if ( is_author() ) |
| 833 |
{ |
| 834 |
$filters->pinPoint |= CJTBlockModel::PINS_AUTHOR; |
| 835 |
} |
| 836 |
else if ( is_archive() ) |
| 837 |
{ |
| 838 |
$filters->pinPoint |= CJTBlockModel::PINS_ARCHIVE; |
| 839 |
} |
| 840 |
else if ( is_404() ) |
| 841 |
{ |
| 842 |
$filters->pinPoint |= CJTBlockModel::PINS_404_ERROR; |
| 843 |
} |
| 844 |
|
| 845 |
} |
| 846 |
|
| 847 |
$this->filters = $this->onsetfilters( $filters ); |
| 848 |
|
| 849 |
} |
| 850 |
|
| 851 |
/** |
| 852 |
* Wordpress do shortcode callback for |
| 853 |
* CJT Shortcodes ([cjtoolbox ....])! |
| 854 |
* |
| 855 |
* This method role is to load the shortcode routines |
| 856 |
* in order to handle the request. |
| 857 |
* |
| 858 |
* It doesn't do anything except deferring the shortcode |
| 859 |
* codes from loaded until shortcode is really used! |
| 860 |
* |
| 861 |
* @param mixed $attributes |
| 862 |
*/ |
| 863 |
public function shortcode($attributes, $content) { |
| 864 |
// Instantiate Shortcode handler class. |
| 865 |
cssJSToolbox::import('controllers:coupling:shortcode:shortcode.php'); |
| 866 |
$shortcode = new CJT_Controllers_Coupling_Shortcode($attributes, $content); |
| 867 |
// Return Shortcode replacement! |
| 868 |
return ((string) $shortcode); |
| 869 |
} |
| 870 |
|
| 871 |
/** |
| 872 |
* put your comment there... |
| 873 |
* |
| 874 |
*/ |
| 875 |
public static function & theInstance() { |
| 876 |
return self::$instance; |
| 877 |
} |
| 878 |
|
| 879 |
} // End class. |
| 880 |
|
| 881 |
// Hookable! |
| 882 |
CJTBlocksCouplingController::define('CJTBlocksCouplingController', array('hookType' => CJTWordpressEvents::HOOK_FILTER)); |