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