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