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