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