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