| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disallow direct access. |
| 7 |
defined('ABSPATH') or die("Access denied"); |
| 8 |
|
| 9 |
/** |
| 10 |
* |
| 11 |
*/ |
| 12 |
class CJT_Framework_Developer_Interface_Block_Shortcode_Shortcode { |
| 13 |
|
| 14 |
/** |
| 15 |
* put your comment there... |
| 16 |
* |
| 17 |
* @var mixed |
| 18 |
*/ |
| 19 |
protected $bcid; |
| 20 |
|
| 21 |
/** |
| 22 |
* put your comment there... |
| 23 |
* |
| 24 |
* @var mixed |
| 25 |
*/ |
| 26 |
protected $block = null; |
| 27 |
|
| 28 |
/** |
| 29 |
* put your comment there... |
| 30 |
* |
| 31 |
* @var mixed |
| 32 |
*/ |
| 33 |
protected $containerElementId = null; |
| 34 |
|
| 35 |
/** |
| 36 |
* put your comment there... |
| 37 |
* |
| 38 |
* @var mixed |
| 39 |
*/ |
| 40 |
protected $content = null; |
| 41 |
|
| 42 |
/** |
| 43 |
* put your comment there... |
| 44 |
* |
| 45 |
* @var mixed |
| 46 |
*/ |
| 47 |
protected $parameters = null; |
| 48 |
|
| 49 |
/** |
| 50 |
* put your comment there... |
| 51 |
* |
| 52 |
* @var CJT_Framework_Developer_Interface_Block_Shortcode_Segments |
| 53 |
*/ |
| 54 |
protected $segments = null; |
| 55 |
|
| 56 |
/** |
| 57 |
* put your comment there... |
| 58 |
* |
| 59 |
* @param mixed $block |
| 60 |
* @param mixed $parameters |
| 61 |
* @param mixed $content |
| 62 |
* @return CJT_Framework_Developer_Interface_Block_Shortcode |
| 63 |
*/ |
| 64 |
public function __construct($block, $parameters, & $content) { |
| 65 |
// Initialize. |
| 66 |
$this->block = $block; |
| 67 |
$this->content =& $content; |
| 68 |
$this->parameters = new CJT_Framework_Developer_Interface_Block_Shortcode_Parameters_Parameters( |
| 69 |
new CJT_Models_Block_Parameters_Parameters($block->id) |
| 70 |
); |
| 71 |
// Load from shortcode parameters. |
| 72 |
$this->parameters->loadString($parameters, $content); |
| 73 |
//$this->segments = new CJT_Framework_Developer_Interface_Block_Shortcode_Segments_Segments($this->cleanContent()); |
| 74 |
// Generate Shortcode block container id. |
| 75 |
$this->bcid = md5(microtime()); |
| 76 |
// Build block container element id. |
| 77 |
$this->containerElementId = "csmi-{$this->bcid}"; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* put your comment there... |
| 82 |
* |
| 83 |
*/ |
| 84 |
public function bcid() { |
| 85 |
return $this->bcid; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* put your comment there... |
| 90 |
* |
| 91 |
*/ |
| 92 |
public function block() { |
| 93 |
return $this->block; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* put your comment there... |
| 98 |
* |
| 99 |
*/ |
| 100 |
public function & cleanContent() { |
| 101 |
// Shortcode content. |
| 102 |
$content = $this->content(); |
| 103 |
// Strip <BR /> tags added by Wordpress. |
| 104 |
$content = str_replace("<br />\n", "\n", $content); |
| 105 |
// Remove first and last. |
| 106 |
$content = preg_replace(array('/^\xA/', '/\xA$/'), '', $content);; |
| 107 |
return $content; |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* put your comment there... |
| 112 |
* |
| 113 |
*/ |
| 114 |
public function containerElementId() { |
| 115 |
return $this->containerElementId; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* put your comment there... |
| 120 |
* |
| 121 |
* @param mixed $new |
| 122 |
*/ |
| 123 |
public function content($value = null) { |
| 124 |
// Return content until its a __setter_. |
| 125 |
$result = $this->content; |
| 126 |
// Set value if apssed. |
| 127 |
if ($value !== null) { |
| 128 |
$this->content = $value; |
| 129 |
$result = $this; |
| 130 |
} |
| 131 |
return $result; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* put your comment there... |
| 136 |
* |
| 137 |
*/ |
| 138 |
public function fw() { |
| 139 |
static $fw = null; |
| 140 |
// Instantiate framework only when used. |
| 141 |
if (!$fw) { |
| 142 |
$fw = new CJT_Framework_Developer_Developer($this->block); |
| 143 |
} |
| 144 |
return $fw; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* put your comment there... |
| 149 |
* |
| 150 |
*/ |
| 151 |
public function params() { |
| 152 |
return $this->parameters; |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* put your comment there... |
| 157 |
* |
| 158 |
*/ |
| 159 |
public function segments() { |
| 160 |
return $this->segments; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* put your comment there... |
| 165 |
* |
| 166 |
* @param mixed $done |
| 167 |
*/ |
| 168 |
public function write($done = null) { |
| 169 |
if ($done) { |
| 170 |
$this->content(ob_get_clean()); |
| 171 |
} |
| 172 |
else { |
| 173 |
ob_start(); |
| 174 |
} |
| 175 |
return $this; |
| 176 |
} |
| 177 |
|
| 178 |
} // End class. |