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