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