| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* Handle block Shortcode. |
| 11 |
*/ |
| 12 |
class CJT_Controllers_Coupling_Shortcode_Block extends CJTHookableClass { |
| 13 |
|
| 14 |
/** |
| 15 |
* put your comment there... |
| 16 |
* |
| 17 |
* @var mixed |
| 18 |
*/ |
| 19 |
protected $attributes; |
| 20 |
|
| 21 |
/** |
| 22 |
* put your comment there... |
| 23 |
* |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
protected $content = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* put your comment there... |
| 30 |
* |
| 31 |
* @var mixed |
| 32 |
*/ |
| 33 |
protected $options = array('force' => 'true', 'tag' => 'span'); |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
* @var mixed |
| 39 |
*/ |
| 40 |
protected $parameters = array(); |
| 41 |
|
| 42 |
/** |
| 43 |
* put your comment there... |
| 44 |
* |
| 45 |
* @param mixed $attributes |
| 46 |
* @param mixed $content |
| 47 |
* @return CJT_Controllers_Coupling_Shortcode_Block |
| 48 |
*/ |
| 49 |
public function __construct($attributes, $content) { |
| 50 |
// Hookable initiaization. |
| 51 |
parent::__construct(); |
| 52 |
// Initialize. |
| 53 |
$this->attributes = $attributes; |
| 54 |
$this->content = $content; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* put your comment there... |
| 59 |
* |
| 60 |
*/ |
| 61 |
public function __toString() { |
| 62 |
// Initialize. |
| 63 |
$replacement = ''; |
| 64 |
$model = CJTModel::getInstance('coupling'); |
| 65 |
// Get shortcode options. |
| 66 |
$this->options = array_merge($this->options, array_intersect_key($this->attributes, $this->options)); |
| 67 |
// Get shortcode parameters. |
| 68 |
$this->parameters = array_diff_key($this->attributes, array_flip(array('force', 'tag', 'name', 'id'))); |
| 69 |
// Get Block fields to be used to query the block. |
| 70 |
$blockQueryFields = array_intersect_key($this->attributes, array_flip(array('id', 'name'))); |
| 71 |
$coupling =& CJTBlocksCouplingController::theInstance(); |
| 72 |
// Import dependecies. |
| 73 |
cssJSToolbox::import('framework:db:mysql:xtable.inc.php', 'framework:php:evaluator:evaluator.inc.php'); |
| 74 |
// Query block. |
| 75 |
$block = CJTxTable::getInstance('block') |
| 76 |
->setData($blockQueryFields) // Set Creteria fields! |
| 77 |
->load(array_keys($blockQueryFields)); // Load using Creteria fields. |
| 78 |
// Get block code if exists and is active block. |
| 79 |
if ($block->get('id')) { |
| 80 |
if ($block->get('state') == 'active') { |
| 81 |
// Get stdCLass copy. |
| 82 |
$block = $block->getData(); |
| 83 |
// Output block if 'force="true" or only if it wasn't already in the header/footer! |
| 84 |
if (($this->options['force'] == 'true') || !in_array($block->id, $coupling->getOnActionIds())) { |
| 85 |
// Id is being used! |
| 86 |
$coupling->addOnActionIds((int) $block->id); |
| 87 |
// Retrieve block code-files. |
| 88 |
$block->code = $model->getBlockCode($block->id); |
| 89 |
// Import Executable (PHP and HTML) templates. |
| 90 |
$block->code = $block->code . $model->getExecTemplatesCode($block->id); |
| 91 |
// CJT Block Standard Parameters object. |
| 92 |
$spi = new CJT_Framework_Developer_Interface_Block_Shortcode_Shortcode($block, $this->parameters, $this->content); |
| 93 |
// Get block code, execute it as PHP! |
| 94 |
$blockCode = CJTPHPCodeEvaluator::getInstance($block)->exec(array('cb' => $spi))->getOutput(); |
| 95 |
// CJT Shortcode markup interface (CSMI)! |
| 96 |
// CSMI is HTML markup to identify the CJT block Shortcode replacement. |
| 97 |
|
| 98 |
// CODE UPDATED BY RBJ -- START |
| 99 |
$replacement = "\n\n<!-- CJT Shortcode Block ({$block->id}) - {$block->name} - START -->\n<{$this->options['tag']} id='{$spi->containerElementId()}' class='csmi csmi-bid-{$block->id} csmi-{$block->name}'>{$this->content}{$blockCode}</{$this->options['tag']}>\n<!-- CJT Shortcode Block ({$block->id}) - {$block->name} - END -->\n\n"; |
| 100 |
// CODE UPDATED BY RBJ -- END |
| 101 |
|
| 102 |
// Get linked templates. |
| 103 |
$linkedStylesheets = ''; |
| 104 |
$templates = $model->getLinkedTemplates($block->id); |
| 105 |
$reverseTypes = array_flip(CJTCouplingModel::$templateTypes); |
| 106 |
// Enqueue all scripts & Direct Output for all Style Sheets! |
| 107 |
foreach ($templates as $template) { |
| 108 |
// Get Template type name. |
| 109 |
$typeName = $reverseTypes[$template->type]; |
| 110 |
/** |
| 111 |
* @var WP_Dependencies |
| 112 |
*/ |
| 113 |
$queue = $model->getQueueObject($typeName); |
| 114 |
if (!in_array($template->queueName, $queue->done)) { |
| 115 |
if (!isset($queue->registered[$template->queueName])) { |
| 116 |
$queue->add($template->queueName, "/{$template->file}", null, $template->version, 1); |
| 117 |
} |
| 118 |
// Enqueue template! |
| 119 |
$queue->enqueue($template->queueName); |
| 120 |
} |
| 121 |
} |
| 122 |
// Prepend linked Stylesheets to the replacement. |
| 123 |
if (isset($linkedStylesheets) && !empty($linkedStylesheets)) { |
| 124 |
$replacement = "<style type='text/css'>{$linkedStylesheets}</style>{$replacement}"; |
| 125 |
} |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
else { // Invalid Shortcode block query! |
| 130 |
$replacement = cssJSToolbox::getText('Could not find block specified! Please check out the Shortcode parameters.'); |
| 131 |
} |
| 132 |
// Return shortcode replacement string. |
| 133 |
return $replacement; |
| 134 |
} |
| 135 |
|
| 136 |
} // End class. |
| 137 |
|
| 138 |
// Hookable! |
| 139 |
CJT_Controllers_Coupling_Shortcode_Block::define('CJT_Controllers_Coupling_Shortcode_Block'); |