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