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