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