PluginProbe
CSS & JavaScript Toolbox / 8.2
CSS & JavaScript Toolbox v8.2
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 -286 trunk8.2 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,136 +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 - 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 - }
440 -
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;
407 + $evaluatedCode = "\n<!-- Block ({$blockId}) START-->\n{$evaluatedCode}\n<!-- Block ({$blockId}) END -->\n";
447 408 }
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 -
409 +
455 410 $this->blocks[ 'code' ][ $block->location ] .= $this->onappendcode( $evaluatedCode );
456 -
411 +
457 412 // Store all used Ids in the CORRECT ORDER.
458 413 $this->addOnActionIds( $blockId );
459 414 }
460 -
415 +
461 416 }
462 -
417 +
463 418 }
464 -
465 - $templates = $this->onActionIds ?
466 - $this->model->getLinkedTemplates( $this->onActionIds ) :
419 +
420 + $templates = $this->onActionIds ?
421 + $this->model->getLinkedTemplates( $this->onActionIds ) :
467 422 array();
468 -
423 +
469 424 // Classisfy as we process Scripts and Styles separatly (different hooks!).
470 - foreach ( $this->onlinkedtemplates( $templates ) as $id => $template )
425 + foreach ( $this->onlinkedtemplates( $templates ) as $id => $template )
471 426 {
472 427 // Filer template!
473 428 extract( $this->onlinktemplate( compact( 'template', 'id' ) ) );
474 -
429 +
475 430 $this->templates[ $template->type ][ $id ] = $template;
476 431 }
477 -
478 -
432 +
433 +
479 434 return true;
480 435 }
481 -
436 +
482 437 /**
483 438 * put your comment there...
484 - *
439 + *
485 440 */
486 441 public function getCached() {
487 442 // Cache is not implemented yet might be supported by extenal Extensions!
488 443 return $this->ongetcache(false);
489 444 }
490 -
445 +
491 446 /**
492 447 * put your comment there...
493 - *
448 + *
494 449 */
495 450 public function getFilters() {
496 - return $this->ongetfilters($this->filters);
451 + return $this->ongetfilters($this->filters);
497 452 }
498 453
499 - /**
500 - * put your comment there...
501 - *
502 - */
503 - public function & getHooksAttacher() {
504 - return $this->hookAttacher;
505 - }
506 -
507 454 /**
508 455 * put your comment there...
509 - *
456 + *
510 457 */
511 458 public function getOnActionIds() {
512 459 return $this->onActionIds;
513 460 }
@@ -513,9 +460,9 @@
513 460 }
514 461
515 462 /**
516 463 * put your comment there...
517 - *
464 + *
518 465 */
519 466 public static function getRequestURL() {
520 467 // URL Protocol.
521 468 $protocol = 'http' . ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) ? 's' : '') . '://';
@@ -524,25 +471,23 @@
524 471 $port = ($_SERVER["SERVER_PORT"] != "80") ? ":{$_SERVER["SERVER_PORT"]}" : '';
525 472 // Request URI.
526 473 $requestURI = $_SERVER['REQUEST_URI'];
527 474 // 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}";
475 + $url = "{$protocol}{$host}{$port}{$requestURI}";
531 476 return $url;
532 477 }
533 -
478 +
534 479 /**
535 480 * put your comment there...
536 - *
481 + *
537 482 */
538 483 public function hasOnActionIds() {
539 484 return !empty($this->onActionIds);
540 485 }
541 -
486 +
542 487 /**
543 488 * put your comment there...
544 - *
489 + *
545 490 */
546 491 public function initCoupling() {
547 492 // For some reasons wp action is fired twice.
548 493 // The wrong call won't has $wp_query object set,
@@ -551,22 +496,19 @@
551 496 return;
552 497 }
553 498 // Get current application hook prefix.
554 499 $actionsPrefix = is_admin() ? 'admin' : 'wp';
555 -
556 500 // Get cache or get blocks if not cached.
557 501 // If there is no cache or no blocks for output
558 502 // do nothing.
559 503 if ($this->getCached() || $this->getBlocks()) {
560 -
561 504 // Output blocks on various locations!
562 - $this->hookAttacher->bind();
563 -
505 + add_action("{$actionsPrefix}_head", array(&$this, 'outputBlocks'), 30);
506 + add_action("{$actionsPrefix}_footer", array(&$this, 'outputBlocks'), 30);
564 507 // Links templates & styloes!
565 508 add_action("{$actionsPrefix}_enqueue_scripts", array(&$this, 'linkTemplates'), 30);
566 509 add_action("{$actionsPrefix}_print_styles", array(&$this, 'linkTemplates'), 30);
567 510 }
568 -
569 511 // Link style sheet in footer required custom implementation.
570 512 add_action("{$actionsPrefix}_print_footer_scripts", array(&$this, 'linkFooterStyleSheets'), 9);
571 513 // Make sure this is executed only once.
572 514 // Sometimes wp hook run on backend and sometimes its not.
@@ -574,12 +516,12 @@
574 516 // Simply remove all hooks to ensure its run only one time.
575 517 remove_action('wp', array(&$this, 'initCoupling'));
576 518 remove_action('admin_init', array(&$this, 'initCoupling'));
577 519 }
578 -
520 +
579 521 /**
580 522 * put your comment there...
581 - *
523 + *
582 524 */
583 525 public function linkFooterStyleSheets() {
584 526 // Initialize.
585 527 $styles = array();
@@ -603,9 +545,9 @@
603 545 // jQuery is dpendency object required by the loader.
604 546 wp_enqueue_script('jquery');
605 547 // Enqueue footer style sheet loader.
606 548 wp_enqueue_script('cjt-coupling-footer-css-loader', cssJSToolbox::getURI('controllers:coupling:js:footer-stylesheet-loader.js'));
607 - // Output JavaScript array to be filled with the styles!
549 + // Output Javascript array to be filled with the styles!
608 550 $jsStyleSheetsList = json_encode($styles);
609 551 require cssJSToolbox::resolvePath('controllers:coupling:html:load-footer-style.html.php');
610 552 }
611 553 }
@@ -611,9 +553,9 @@
611 553 }
612 554
613 555 /**
614 556 * put your comment there...
615 - *
557 + *
616 558 */
617 559 public function linkTemplates() {
618 560 $currentFilter = current_filter();
619 561 // Derived template Type from Wordpress filter.
@@ -637,83 +579,86 @@
637 579 // Always make sure the template is queued.
638 580 $queue->enqueue($template->queueName);
639 581 }
640 582 }
641 -
583 +
642 584 /**
643 585 * put your comment there...
644 - *
586 + *
645 587 */
646 588 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 -
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);
655 600 }
656 -
601 +
657 602 /**
658 603 * put your comment there...
659 - *
604 + *
660 605 */
661 - protected function setRequestFilters()
606 + protected function setRequestFilters()
662 607 {
663 608 // Get request blocks.
664 609 $filters = $this->ondefaultfilters( ( object ) array
665 610 (
666 -
611 +
667 612 'pinPoint' => 0x00000000,
668 -
613 +
669 614 'customPins' => array(),
670 -
615 +
671 616 'moreToOrder' => array(),
672 -
617 +
673 618 'currentObject' => null,
674 -
619 +
675 620 'currentCustomPin' => 0,
676 -
621 +
677 622 'params' => array(),
678 -
623 +
679 624 ) );
680 -
681 - if ( is_admin() )
625 +
626 + if ( is_admin() )
682 627 {
683 628 // Include all backend blocks.
684 629 $filters->pinPoint |= CJTBlockModel::PINS_BACKEND;
685 630 }
686 - else
631 + else
687 632 {
688 633 $filters->pinPoint |= CJTBlockModel::PINS_FRONTEND;
689 -
634 +
690 635 // Pages.
691 - if ( is_page() )
636 + if ( is_page() )
692 637 {
693 638 // Blocks with ALL PAGES selected.
694 639 $filters->pinPoint |= CJTBlockModel::PINS_PAGES_ALL_PAGES;
695 -
640 +
696 641 $filters->currentObject = $GLOBALS[ 'post' ];
697 - $filters->currentCustomPin = CJTBlockModel::PINS_PAGES_CUSTOM_PAGE;
698 -
642 + $filters->currentCustomPin = CJTBlockModel::PINS_PAGES_CUSTOM_PAGE;
643 +
699 644 // Blocks with PAGE-ID selected.
700 645 $filters->customPins[ ] = array
701 646 (
702 647 'pin' => 'pages',
703 -
648 +
704 649 'pins' => array( $filters->currentObject->ID ),
705 -
650 +
706 651 'flag' => CJTBlockModel::PINS_PAGES_CUSTOM_PAGE,
707 -
652 +
708 653 );
709 -
654 +
710 655 // Blocks with FRONT-PAGE selected.
711 - if ( is_front_page() )
656 + if ( is_front_page() )
712 657 {
713 658 $filters->pinPoint |= CJTBlockModel::PINS_PAGES_FRONT_PAGE;
714 659 }
715 -
660 +
716 661 /**
717 662 * In order for metabox block to get in the output we need
718 663 * to add metabox order for it.
719 664 * @see CJTBlocksCouplingController::getBlocks.
@@ -718,42 +663,42 @@
718 663 * to add metabox order for it.
719 664 * @see CJTBlocksCouplingController::getBlocks.
720 665 */
721 666 $metabox = CJTModel::create( 'metabox', array( $filters->currentObject->ID ) );
722 -
667 +
723 668 $filters->moreToOrder[ ][ 1 ] = $metabox->getMetaboxId();
724 -
669 +
725 670 } // End is_page()
726 -
727 - else if ( is_attachment() )
671 +
672 + else if ( is_attachment() )
728 673 {
729 674 $filters->pinPoint |= CJTBlockModel::PINS_ATTACHMENT;
730 675 }
731 676 // Posts.
732 - else if ( is_single() )
677 + else if ( is_single() )
733 678 {
734 679 // Blocks with ALL POSTS & ALL CATEGORIES selected.
735 680 $filters->pinPoint |= CJTBlockModel::PINS_POSTS_ALL_POSTS | CJTBlockModel::PINS_CATEGORIES_ALL_CATEGORIES;
736 -
681 +
737 682 $filters->currentObject = $GLOBALS[ 'post' ];
738 683 $filters->currentCustomPin = CJTBlockModel::PINS_POSTS_CUSTOM_POST;
739 -
684 +
740 685 // Blocks with POST-ID selected.
741 -
686 +
742 687 $filters->customPins[ ] = array
743 688 (
744 -
689 +
745 690 'pin' => 'posts',
746 -
691 +
747 692 'pins' => array( $filters->currentObject->ID ),
748 -
693 +
749 694 'flag' => CJTBlockModel::PINS_POSTS_CUSTOM_POST,
750 -
695 +
751 696 );
752 -
753 - // Include POST PARENT CATRGORIES blocks.
697 +
698 + // Include POST PARENT CATRGORIES blocks.
754 699 $parentCategoriesIds = wp_get_post_categories( $filters->currentObject->ID, array( 'fields' => 'ids' ) );
755 -
700 +
756 701 /**
757 702 * Custom-Posts just added "ON THE RUN/FLY"
758 703 * Need simple fix by confirming that the post is belong to
759 704 * specific category or not.
@@ -759,27 +704,27 @@
759 704 * specific category or not.
760 705 * Custom posts NOW unlike Posts, it doesn't inherit parent
761 706 * taxonomis Code Blocks!!
762 707 */
763 - if ( ! empty( $parentCategoriesIds ) )
708 + if ( ! empty( $parentCategoriesIds ) )
764 709 {
765 -
710 +
766 711 $filters->params[ 'hasCategories' ] = true;
767 712 $filters->params[ 'parentCategories' ] = $parentCategoriesIds;
768 -
713 +
769 714 $filters->customPins[ ] = array
770 715 (
771 -
716 +
772 717 'pin' => 'categories',
773 -
718 +
774 719 'pins' => $parentCategoriesIds,
775 -
720 +
776 721 'flag' => CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY,
777 -
722 +
778 723 );
779 -
724 +
780 725 }
781 -
726 +
782 727 /**
783 728 * In order for metabox block to get in the output we need
784 729 * to add metabox order for it.
785 730 * @see CJTBlocksCouplingController::getBlocks.
@@ -784,49 +729,49 @@
784 729 * to add metabox order for it.
785 730 * @see CJTBlocksCouplingController::getBlocks.
786 731 */
787 732 $metabox = CJTModel::create( 'metabox', array( $filters->currentObject->ID ) );
788 -
733 +
789 734 $filters->moreToOrder[][ 1 ] = $metabox->getMetaboxId();
790 -
791 - /**
735 +
736 + /**
792 737 * @TODO check for recent posts Based on user configuration.
793 738 * Recent posts should be detcted by comparing
794 739 * user condifguration with post date.
795 740 */
796 741 if ( 0 ) {
797 -
742 +
798 743 }
799 744 } // End is_single()
800 -
745 +
801 746 // Categories.
802 - else if( is_category() )
747 + else if( is_category() )
803 748 {
804 749 // Blocks with ALL CATEGORIES selected.
805 750 $filters->pinPoint |= CJTBlockModel::PINS_CATEGORIES_ALL_CATEGORIES;
806 -
751 +
807 752 $filters->currentObject = get_queried_object();
808 753 $filters->currentCustomPin = CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY;
809 -
754 +
810 755 // Blocks with CATEGORY-ID selected.
811 756 $filters->customPins[] = array
812 757 (
813 758 'pin' => 'categories',
814 -
759 +
815 760 'pins' => array( $filters->currentObject->term_id ),
816 -
761 +
817 762 'flag' => CJTBlockModel::PINS_CATEGORIES_CUSTOM_CATEGORY,
818 -
763 +
819 764 );
820 -
765 +
821 766 } // End is_category()
822 -
767 +
823 768 // Blocks with BLOG-INDEX selected.
824 769 else if ( is_home() )
825 770 {
826 771 $filters->pinPoint |= CJTBlockModel::PINS_POSTS_BLOG_INDEX;
827 772 }
828 - else if ( is_search() )
773 + else if ( is_search() )
829 774 {
830 775 $filters->pinPoint |= CJTBlockModel::PINS_SEARCH;
831 776 }
832 777 else if ( is_tag() )
@@ -832,37 +777,37 @@
832 777 else if ( is_tag() )
833 778 {
834 779 $filters->pinPoint |= CJTBlockModel::PINS_TAG;
835 780 }
836 - else if ( is_author() )
781 + else if ( is_author() )
837 782 {
838 783 $filters->pinPoint |= CJTBlockModel::PINS_AUTHOR;
839 784 }
840 - else if ( is_archive() )
785 + else if ( is_archive() )
841 786 {
842 787 $filters->pinPoint |= CJTBlockModel::PINS_ARCHIVE;
843 788 }
844 - else if ( is_404() )
789 + else if ( is_404() )
845 790 {
846 791 $filters->pinPoint |= CJTBlockModel::PINS_404_ERROR;
847 792 }
848 -
793 +
849 794 }
850 -
795 +
851 796 $this->filters = $this->onsetfilters( $filters );
852 -
797 +
853 798 }
854 -
799 +
855 800 /**
856 801 * Wordpress do shortcode callback for
857 - * CJT Shortcodes ([cjtoolbox ....])!
858 - *
802 + * CJT Shortcodes ([cjtoolbox ....])!
803 + *
859 804 * This method role is to load the shortcode routines
860 805 * in order to handle the request.
861 - *
806 + *
862 807 * It doesn't do anything except deferring the shortcode
863 808 * codes from loaded until shortcode is really used!
864 - *
809 + *
865 810 * @param mixed $attributes
866 811 */
867 812 public function shortcode($attributes, $content) {
868 813 // Instantiate Shortcode handler class.
@@ -870,17 +815,17 @@
870 815 $shortcode = new CJT_Controllers_Coupling_Shortcode($attributes, $content);
871 816 // Return Shortcode replacement!
872 817 return ((string) $shortcode);
873 818 }
874 -
819 +
875 820 /**
876 821 * put your comment there...
877 - *
822 + *
878 823 */
879 824 public static function & theInstance() {
880 825 return self::$instance;
881 826 }
882 -
827 +
883 828 } // End class.
884 829
885 830 // Hookable!
886 831 CJTBlocksCouplingController::define('CJTBlocksCouplingController', array('hookType' => CJTWordpressEvents::HOOK_FILTER));