| @@ -23,11 +23,11 @@ | ||
| 23 | 23 | * put your comment there... |
| 24 | 24 | * |
| 25 | 25 | * @var mixed |
| 26 | 26 | */ |
| 27 | - protected $blocks = array( | |
| 28 | - 'code' => array('header' => '', 'footer' => ''), | |
| 29 | - 'scripts' => array('header' => array(), 'footer' => array()), | |
| 27 | + public $blocks = array( | |
| 28 | + 'code' => array(), | |
| 29 | + 'scripts' => array(), | |
| 30 | 30 | ); |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * put your comment there... |
| @@ -42,8 +42,15 @@ | ||
| 42 | 42 | * @var mixed |
| 43 | 43 | */ |
| 44 | 44 | protected $filters = null; |
| 45 | 45 | |
| 46 | + /** | |
| 47 | + * put your comment there... | |
| 48 | + * | |
| 49 | + * @var mixed | |
| 50 | + */ | |
| 51 | + protected $hookAttacher; | |
| 52 | + | |
| 46 | 53 | /** |
| 47 | 54 | * put your comment there... |
| 48 | 55 | * |
| 49 | 56 | * @var mixed |
| @@ -231,25 +238,43 @@ | ||
| 231 | 238 | * @see CJTController for more details |
| 232 | 239 | * @return void |
| 233 | 240 | */ |
| 234 | 241 | public function __construct() { |
| 242 | + | |
| 235 | 243 | // Only one instance is allowed. |
| 236 | 244 | if (self::$instance) { |
| 237 | 245 | throw new Exception('Trying to instantiate multiple coupling instances!!'); |
| 238 | 246 | } |
| 247 | + | |
| 239 | 248 | // Hold the single instance we've! |
| 240 | 249 | self::$instance = $this; |
| 241 | 250 | $siteHook = cssJSToolbox::$config->core->siteHook; |
| 251 | + | |
| 242 | 252 | // Initialize controller. |
| 243 | 253 | parent::__construct(false); |
| 254 | + | |
| 244 | 255 | // Import related libraries |
| 245 | 256 | CJTModel::import('block'); |
| 257 | + | |
| 246 | 258 | // Not default action needed. |
| 247 | 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 | + | |
| 248 | 272 | // Initialize controller. |
| 249 | 273 | $initCouplingCallback = $this->onassigncouplingcallback(array(&$this, 'initCoupling')); |
| 250 | 274 | add_action('admin_init', $initCouplingCallback); |
| 251 | 275 | add_action($siteHook->tag, $initCouplingCallback, $siteHook->priority); |
| 276 | + | |
| 252 | 277 | // Add Shortcode callbacks. |
| 253 | 278 | add_shortcode('cjtoolbox', array(&$this, 'shortcode')); |
| 254 | 279 | } |
| 255 | 280 | |
| @@ -280,9 +305,9 @@ | ||
| 280 | 305 | $blocksOrder = array(); |
| 281 | 306 | $metaBoxesOrder = $this->onblocksorder( $this->model->getOrder() ); |
| 282 | 307 | |
| 283 | 308 | // Get ORDER-INDEX <TO> BLOCK-ID mapping. |
| 284 | - preg_match_all( '/cjtoolbox-(\d+)/', $metaBoxesOrder[ 'normal' ], $blocksOrder, PREG_SET_ORDER ); | |
| 309 | + if ( $metaBoxesOrder ) preg_match_all( '/cjtoolbox-(\d+)/', $metaBoxesOrder[ 'normal' ], $blocksOrder, PREG_SET_ORDER ); | |
| 285 | 310 | |
| 286 | 311 | /** |
| 287 | 312 | * append more to orders produced by CJTBlocksCouplingController::setRequestFilter(). |
| 288 | 313 | * More to orders may allow other blocks to bein the output (e.g metaboxe blocks). |
| @@ -331,8 +356,9 @@ | ||
| 331 | 356 | $this->onprocess(); |
| 332 | 357 | |
| 333 | 358 | foreach ( $blocksOrder as $blockOrder ) |
| 334 | 359 | { |
| 360 | + | |
| 335 | 361 | $blockId = (int) $blockOrder[1]; |
| 336 | 362 | |
| 337 | 363 | // As mentioned above. Orders is for all blocks not just those queried from db. |
| 338 | 364 | if ( isset($blocks[ $blockId ] ) ) |
| @@ -417,8 +443,14 @@ | ||
| 417 | 443 | endif; |
| 418 | 444 | // CODE UPDATED BY RBJ -- END |
| 419 | 445 | } |
| 420 | 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 | + | |
| 421 | 453 | $this->blocks[ 'code' ][ $block->location ] .= $this->onappendcode( $evaluatedCode ); |
| 422 | 454 | |
| 423 | 455 | // Store all used Ids in the CORRECT ORDER. |
| 424 | 456 | $this->addOnActionIds( $blockId ); |
| @@ -461,8 +493,16 @@ | ||
| 461 | 493 | public function getFilters() { |
| 462 | 494 | return $this->ongetfilters($this->filters); |
| 463 | 495 | } |
| 464 | 496 | |
| 497 | + /** | |
| 498 | + * put your comment there... | |
| 499 | + * | |
| 500 | + */ | |
| 501 | + public function & getHooksAttacher() { | |
| 502 | + return $this->hookAttacher; | |
| 503 | + } | |
| 504 | + | |
| 465 | 505 | /** |
| 466 | 506 | * put your comment there... |
| 467 | 507 | * |
| 468 | 508 | */ |
| @@ -507,19 +547,22 @@ | ||
| 507 | 547 | return; |
| 508 | 548 | } |
| 509 | 549 | // Get current application hook prefix. |
| 510 | 550 | $actionsPrefix = is_admin() ? 'admin' : 'wp'; |
| 551 | + | |
| 511 | 552 | // Get cache or get blocks if not cached. |
| 512 | 553 | // If there is no cache or no blocks for output |
| 513 | 554 | // do nothing. |
| 514 | 555 | if ($this->getCached() || $this->getBlocks()) { |
| 556 | + | |
| 515 | 557 | // Output blocks on various locations! |
| 516 | - add_action("{$actionsPrefix}_head", array(&$this, 'outputBlocks'), 30); | |
| 517 | - add_action("{$actionsPrefix}_footer", array(&$this, 'outputBlocks'), 30); | |
| 558 | + $this->hookAttacher->bind(); | |
| 559 | + | |
| 518 | 560 | // Links templates & styloes! |
| 519 | 561 | add_action("{$actionsPrefix}_enqueue_scripts", array(&$this, 'linkTemplates'), 30); |
| 520 | 562 | add_action("{$actionsPrefix}_print_styles", array(&$this, 'linkTemplates'), 30); |
| 521 | 563 | } |
| 564 | + | |
| 522 | 565 | // Link style sheet in footer required custom implementation. |
| 523 | 566 | add_action("{$actionsPrefix}_print_footer_scripts", array(&$this, 'linkFooterStyleSheets'), 9); |
| 524 | 567 | // Make sure this is executed only once. |
| 525 | 568 | // Sometimes wp hook run on backend and sometimes its not. |
| @@ -596,19 +639,16 @@ | ||
| 596 | 639 | * put your comment there... |
| 597 | 640 | * |
| 598 | 641 | */ |
| 599 | 642 | public function outputBlocks() { |
| 600 | - // Derived location name from wordpress filter name. | |
| 601 | - $currentFilter = current_filter(); | |
| 602 | - // Map "wp hook location" to "block hook location". | |
| 603 | - $locationsMap = array('head' => 'header', 'footer' => 'footer'); | |
| 604 | - // This hook is used across both ends, front and back ends. | |
| 605 | - // Remove application prefix (wp_ or admin_). | |
| 606 | - // Remining is head or footer. | |
| 607 | - $location = str_replace(array('wp_', 'admin_'), '', $currentFilter); | |
| 608 | - // Map to block location. | |
| 609 | - $location = $locationsMap[$location]; | |
| 610 | - echo $this->onoutput($this->blocks['code'][$location], $location); | |
| 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 | + | |
| 611 | 651 | } |
| 612 | 652 | |
| 613 | 653 | /** |
| 614 | 654 | * put your comment there... |