/**
  * put your comment there...
  * 
  */
 public function getBlocks()
 {
     // Set request view filters used for querying database.
     $this->setRequestFilters();
     // Get blocks order. NOTE: This is all blocks order not only the queried/target blocks.
     $blocksOrder = array();
     $metaBoxesOrder = $this->onblocksorder($this->model->getOrder());
     // Get ORDER-INDEX <TO> BLOCK-ID mapping.
     preg_match_all('/cjtoolbox-(\\d+)/', $metaBoxesOrder['normal'], $blocksOrder, PREG_SET_ORDER);
     /**
      * append more to orders produced by CJTBlocksCouplingController::setRequestFilter().
      * More to orders may allow other blocks to bein the output (e.g metaboxe blocks).
      */
     $blocksOrder = array_merge($blocksOrder, $this->getFilters()->moreToOrder);
     // Prepare request URL to match against Links & Expressions.
     $linksRequestURL = self::getRequestURL();
     $expressionsRequestURL = "{$linksRequestURL}?{$_SERVER['QUERY_STRING']}";
     extract($this->onmatchingurls(compact('linksRequestURL', 'expressionsRequestURL')));
     // Get all blocks including (Links & Expressions Blocks).
     $blocks = $this->ongetblocks($this->model->getPinsBlocks(CJTBlockModel::PINS_LINK_EXPRESSION, $this->getFilters()->pinPoint, $this->getFilters()->customPins, $this->getFilters()));
     if (empty($blocks)) {
         $this->onnoblocks();
         return false;
     }
     // Import related libraries.
     cssJSToolbox::import('framework:php:evaluator:evaluator.inc.php');
     /**
      * Iterator over all blocks by using they order.
      * For each block get code and scripts.
      */
     $this->onprocess();
     foreach ($blocksOrder as $blockOrder) {
         $blockId = (int) $blockOrder[1];
         // As mentioned above. Orders is for all blocks not just those queried from db.
         if (isset($blocks[$blockId])) {
             $block = $this->onprocessblock($blocks[$blockId]);
             /**
              * Process Links & Expressions blocks.
              * For better performace check only those with links and expressions flags.
              */
             if ($block->blocksGroup & CJTBlockModel::PINS_LINK_EXPRESSION) {
                 /**
                  * Initiliaze $matchedLink and $matchedExpression inside IF statment.
                  * Those variables need to refresh state at each block.
                  * If there is no link or expression flags, they will be FALSE.
                  * Otherwise they'll get the correct value inside each statement.
                  */
                 /// Check if there is a matched link.
                 if ($matchedLink = $block->blocksGroup & CJTBlockModel::PINS_LINKS) {
                     $links = explode("\n", trim($block->links));
                     $matchedLink = in_array($linksRequestURL, $links);
                 }
                 /// Check if there is a matched expression.
                 if ($matchedExpression = $block->blocksGroup & CJTBlockModel::PINS_EXPRESSIONS) {
                     $expressions = explode("\n", $block->expressions);
                     foreach ($expressions as $expression) {
                         /// @TODO: Matches may be used later to evaulate variables inside code block.
                         if ($matchedExpression = @preg_match("/{$expression}/", $expressionsRequestURL)) {
                             break;
                         }
                     }
                 }
                 /**
                  * Exclude Links & Expressions Blocks that doesn't has a match.
                  * If there is no matched link or expression then exclude block.
                  */
                 if ($this->oncancelmatching(!($matchedExpression || $matchedLink))) {
                     continue;
                 }
             }
             // Allow extensions to control to prevent block from being in the output
             if ($block = $this->onblockmatched($block)) {
                 // Retrieve block code-files.
                 $block->code = $this->model->getBlockCode($block->id);
                 // Import Executable (PHP and HTML) templates.
                 $block->code = $block->code . $this->model->getExecTemplatesCode($block->id);
                 // For every location store blocks code into single string
                 if (!($evaluatedCode = $this->onevalcodeblock(false, $block))) {
                     $evaluatedCode = CJTPHPCodeEvaluator::getInstance($block)->exec()->getOutput();
                 }
                 /** @todo Include Debuging info only if we're in debuging mode! */
                 if (1) {
                     $evaluatedCode = "\n<!-- Block ({$blockId}) START-->\n{$evaluatedCode}\n<!-- Block ({$blockId}) END -->\n";
                 }
                 $this->blocks['code'][$block->location] .= $this->onappendcode($evaluatedCode);
                 // Store all used Ids in the CORRECT ORDER.
                 $this->addOnActionIds($blockId);
             }
         }
     }
     $templates = $this->onActionIds ? $this->model->getLinkedTemplates($this->onActionIds) : array();
     // Classisfy as we process Scripts and Styles separatly (different hooks!).
     foreach ($this->onlinkedtemplates($templates) as $id => $template) {
         // Filer template!
         extract($this->onlinktemplate(compact('template', 'id')));
         $this->templates[$template->type][$id] = $template;
     }
     return true;
 }
예제 #2
0
 /**
  * put your comment there...
  * 
  */
 public function __toString()
 {
     // Initialize.
     $replacement = '';
     $model = CJTModel::getInstance('coupling');
     // Get shortcode options.
     $this->options = array_merge($this->options, array_intersect_key($this->attributes, $this->options));
     // Get shortcode parameters.
     $this->parameters = array_diff_key($this->attributes, array_flip(array('force', 'tag', 'name', 'id')));
     // Get Block fields to be used to query the block.
     $blockQueryFields = array_intersect_key($this->attributes, array_flip(array('id', 'name')));
     $coupling =& CJTBlocksCouplingController::theInstance();
     // Import dependecies.
     cssJSToolbox::import('framework:db:mysql:xtable.inc.php', 'framework:php:evaluator:evaluator.inc.php');
     // Query block.
     $block = CJTxTable::getInstance('block')->setData($blockQueryFields)->load(array_keys($blockQueryFields));
     // Load using Creteria fields.
     // Get block code if exists and is active block.
     if ($block->get('id')) {
         if ($block->get('state') == 'active') {
             // Get stdCLass copy.
             $block = $block->getData();
             // Output block if 'force="true" or only if it wasn't already in the header/footer!
             if ($this->options['force'] == 'true' || !in_array($block->id, $coupling->getOnActionIds())) {
                 // Id is being used!
                 $coupling->addOnActionIds((int) $block->id);
                 // Retrieve block code-files.
                 $block->code = $model->getBlockCode($block->id);
                 // Import Executable (PHP and HTML) templates.
                 $block->code = $block->code . $model->getExecTemplatesCode($block->id);
                 // CJT Block Standard Parameters object.
                 $spi = new CJT_Framework_Developer_Interface_Block_Shortcode_Shortcode($block, $this->parameters, $this->content);
                 // Get block code, execute it as PHP!
                 $blockCode = CJTPHPCodeEvaluator::getInstance($block)->exec(array('cb' => $spi))->getOutput();
                 // CJT Shortcode markup interface (CSMI)!
                 // CSMI is HTML markup to identify the CJT block Shortcode replacement.
                 $replacement = "<{$this->options['tag']} id='{$spi->containerElementId()}' class='csmi csmi-bid-{$block->id} csmi-{$block->name}'>{$this->content}{$blockCode}</{$this->options['tag']}>";
                 // Get linked templates.
                 $linkedStylesheets = '';
                 $templates = $model->getLinkedTemplates($block->id);
                 $reverseTypes = array_flip(CJTCouplingModel::$templateTypes);
                 // Enqueue all scripts & Direct Output for all Style Sheets!
                 foreach ($templates as $template) {
                     // Get Template type name.
                     $typeName = $reverseTypes[$template->type];
                     /**
                      * @var WP_Dependencies
                      */
                     $queue = $model->getQueueObject($typeName);
                     if (!in_array($template->queueName, $queue->done)) {
                         if (!isset($queue->registered[$template->queueName])) {
                             $queue->add($template->queueName, "/{$template->file}", null, $template->version, 1);
                         }
                         // Enqueue template!
                         $queue->enqueue($template->queueName);
                     }
                 }
                 // Prepend linked Stylesheets to the replacement.
                 if (isset($linkedStylesheets)) {
                     $replacement = "<style type='text/css'>{$linkedStylesheets}</style>{$replacement}";
                 }
             }
         }
     } else {
         // Invalid Shortcode block query!
         $replacement = cssJSToolbox::getText('Could not find block specified! Please check out the Shortcode parameters.');
     }
     // Return shortcode replacement string.
     return $replacement;
 }