PluginProbe
CSS & JavaScript Toolbox / 10
CSS & JavaScript Toolbox v10
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 +29 -73 trunk10 View file →
@@ -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 ] ) )
@@ -429,30 +403,22 @@
429 403 }
430 404
431 405 /** @todo Include Debuging info only if we're in debuging mode! */
432 406 if ( 1 ) {
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 - }
407 + // CODE UPDATED BY RBJ -- START
408 + if (trim($evaluatedCode) != ''):
409 + global $post;
410 + $checkMetaBlock = get_post_meta($post->ID, '__CJT-BLOCK-ID', true);
440 411
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;
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
447 419 }
448 420
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 -
455 421 $this->blocks[ 'code' ][ $block->location ] .= $this->onappendcode( $evaluatedCode );
456 422
457 423 // Store all used Ids in the CORRECT ORDER.
458 424 $this->addOnActionIds( $blockId );
@@ -495,16 +461,8 @@
495 461 public function getFilters() {
496 462 return $this->ongetfilters($this->filters);
497 463 }
498 464
499 - /**
500 - * put your comment there...
501 - *
502 - */
503 - public function & getHooksAttacher() {
504 - return $this->hookAttacher;
505 - }
506 -
507 465 /**
508 466 * put your comment there...
509 467 *
510 468 */
@@ -524,11 +482,9 @@
524 482 $port = ($_SERVER["SERVER_PORT"] != "80") ? ":{$_SERVER["SERVER_PORT"]}" : '';
525 483 // Request URI.
526 484 $requestURI = $_SERVER['REQUEST_URI'];
527 485 // Final URL.
528 - //$url = "{$protocol}{$host}{$port}{$requestURI}";
529 - // Removing port segment from the URL as it is causing bugs.
530 - $url = "{$protocol}{$host}{$requestURI}";
486 + $url = "{$protocol}{$host}{$port}{$requestURI}";
531 487 return $url;
532 488 }
533 489
534 490 /**
@@ -551,22 +507,19 @@
551 507 return;
552 508 }
553 509 // Get current application hook prefix.
554 510 $actionsPrefix = is_admin() ? 'admin' : 'wp';
555 -
556 511 // Get cache or get blocks if not cached.
557 512 // If there is no cache or no blocks for output
558 513 // do nothing.
559 514 if ($this->getCached() || $this->getBlocks()) {
560 -
561 515 // Output blocks on various locations!
562 - $this->hookAttacher->bind();
563 -
516 + add_action("{$actionsPrefix}_head", array(&$this, 'outputBlocks'), 30);
517 + add_action("{$actionsPrefix}_footer", array(&$this, 'outputBlocks'), 30);
564 518 // Links templates & styloes!
565 519 add_action("{$actionsPrefix}_enqueue_scripts", array(&$this, 'linkTemplates'), 30);
566 520 add_action("{$actionsPrefix}_print_styles", array(&$this, 'linkTemplates'), 30);
567 521 }
568 -
569 522 // Link style sheet in footer required custom implementation.
570 523 add_action("{$actionsPrefix}_print_footer_scripts", array(&$this, 'linkFooterStyleSheets'), 9);
571 524 // Make sure this is executed only once.
572 525 // Sometimes wp hook run on backend and sometimes its not.
@@ -643,16 +596,19 @@
643 596 * put your comment there...
644 597 *
645 598 */
646 599 public function outputBlocks() {
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 -
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);
655 611 }
656 612
657 613 /**
658 614 * put your comment there...