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