PluginProbe
CSS & JavaScript Toolbox / trunk
CSS & JavaScript Toolbox vtrunk
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
← All changes | controllers/blocks-coupling.php +73 -29 10trunk View file →
@@ -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 ] ) )
@@ -403,22 +429,30 @@
403 429 }
404 430
405 431 /** @todo Include Debuging info only if we're in debuging mode! */
406 432 if ( 1 ) {
407 - // CODE UPDATED BY RBJ -- START
408 - if (trim($evaluatedCode) != ''):
409 - global $post;
410 - $checkMetaBlock = get_post_meta($post->ID, '__CJT-BLOCK-ID', true);
433 + if (trim($evaluatedCode) != ''):
434 + global $post;
435 + // Defensive: $post may be null in some contexts, avoid reading ->ID on null.
436 + $checkMetaBlock = null;
437 + if ( isset($post) && is_object($post) && isset($post->ID) ) {
438 + $checkMetaBlock = get_post_meta($post->ID, '__CJT-BLOCK-ID', true);
439 + }
411 440
412 - if (!empty($checkMetaBlock) && $checkMetaBlock == $blockId):
413 - $evaluatedCode = "\n\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - END -->\n\n";
414 - else:
415 - $evaluatedCode = "\n\n<!-- CJT Global Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Global Block ({$blockId}) - {$block->name} - END -->\n\n";
416 - endif;
417 - endif;
418 - // CODE UPDATED BY RBJ -- END
441 + if (!empty($checkMetaBlock) && $checkMetaBlock == $blockId):
442 + $evaluatedCode = "\n\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Meta Block ({$blockId}) - {$block->name} - END -->\n\n";
443 + else:
444 + $evaluatedCode = "\n\n<!-- CJT Global Block ({$blockId}) - {$block->name} - START -->\n{$evaluatedCode}\n<!-- CJT Global Block ({$blockId}) - {$block->name} - END -->\n\n";
445 + endif;
446 + endif;
419 447 }
420 448
449 + // Initialize block LOCATION array for the first time
450 + if (!isset($this->blocks[ 'code' ][ $block->location ])) {
451 +
452 + $this->blocks[ 'code' ][ $block->location ] = '';
453 + }
454 +
421 455 $this->blocks[ 'code' ][ $block->location ] .= $this->onappendcode( $evaluatedCode );
422 456
423 457 // Store all used Ids in the CORRECT ORDER.
424 458 $this->addOnActionIds( $blockId );
@@ -461,8 +495,16 @@
461 495 public function getFilters() {
462 496 return $this->ongetfilters($this->filters);
463 497 }
464 498
499 + /**
500 + * put your comment there...
501 + *
502 + */
503 + public function & getHooksAttacher() {
504 + return $this->hookAttacher;
505 + }
506 +
465 507 /**
466 508 * put your comment there...
467 509 *
468 510 */
@@ -482,9 +524,11 @@
482 524 $port = ($_SERVER["SERVER_PORT"] != "80") ? ":{$_SERVER["SERVER_PORT"]}" : '';
483 525 // Request URI.
484 526 $requestURI = $_SERVER['REQUEST_URI'];
485 527 // Final URL.
486 - $url = "{$protocol}{$host}{$port}{$requestURI}";
528 + //$url = "{$protocol}{$host}{$port}{$requestURI}";
529 + // Removing port segment from the URL as it is causing bugs.
530 + $url = "{$protocol}{$host}{$requestURI}";
487 531 return $url;
488 532 }
489 533
490 534 /**
@@ -507,19 +551,22 @@
507 551 return;
508 552 }
509 553 // Get current application hook prefix.
510 554 $actionsPrefix = is_admin() ? 'admin' : 'wp';
555 +
511 556 // Get cache or get blocks if not cached.
512 557 // If there is no cache or no blocks for output
513 558 // do nothing.
514 559 if ($this->getCached() || $this->getBlocks()) {
560 +
515 561 // Output blocks on various locations!
516 - add_action("{$actionsPrefix}_head", array(&$this, 'outputBlocks'), 30);
517 - add_action("{$actionsPrefix}_footer", array(&$this, 'outputBlocks'), 30);
562 + $this->hookAttacher->bind();
563 +
518 564 // Links templates & styloes!
519 565 add_action("{$actionsPrefix}_enqueue_scripts", array(&$this, 'linkTemplates'), 30);
520 566 add_action("{$actionsPrefix}_print_styles", array(&$this, 'linkTemplates'), 30);
521 567 }
568 +
522 569 // Link style sheet in footer required custom implementation.
523 570 add_action("{$actionsPrefix}_print_footer_scripts", array(&$this, 'linkFooterStyleSheets'), 9);
524 571 // Make sure this is executed only once.
525 572 // Sometimes wp hook run on backend and sometimes its not.
@@ -596,19 +643,16 @@
596 643 * put your comment there...
597 644 *
598 645 */
599 646 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);
647 +
648 + $hooks = $this->hookAttacher->getHooksByFilterName(current_filter());
649 +
650 + foreach ($hooks as $hook) {
651 +
652 + echo $this->onoutput($this->blocks['code'][$hook['locationName']], $hook['locationName']);
653 + }
654 +
611 655 }
612 656
613 657 /**
614 658 * put your comment there...