/** * Returns instance * @return ctShortcodeHandler */ public static function getInstance() { if (!self::$instance) { self::$instance = new self(); self::$instance->initialize(); } return self::$instance; }
/** * Initialize widget */ protected function initialize() { $name = $this->getShortcodeName(); //find shortcode if (!($this->shortcode = ctShortcodeHandler::getInstance()->getShortcode($name))) { throw new InvalidArgumentException("Cannot find shortcode " . $name); } //maybe child? $this->childShortcode = $this->shortcode->getChildShortcode(); }
/** * Fix shortcode <p> problem. * Cleans ONLY this themes shortcodes * @param $content * @return mixed */ function ct_shortcode_empty_paragraph_fix($content) { $themeShortcodes = ctShortcodeHandler::getInstance()->getShortcodeNames(); // array of custom shortcodes requiring the fix $block = join("|", $themeShortcodes); // opening tag $rep = preg_replace("/(<p>)?\\[({$block})(\\s[^\\]]+)?\\](<\\/p>|<br \\/>)?/", "[\$2\$3]", $content); // closing tag $rep = preg_replace("/(<p>)?\\[\\/({$block})](<\\/p>|<br \\/>)?/", "[/\$2]", $rep); return $rep; }
/** * Returns child shortcode if exists * @return ctShortcode * @throws Exception */ public function getChildShortcode() { //maybe child? $childInfo = $this->getChildShortcodeInfo(); if (isset($childInfo['name']) && $childInfo['name']) { //find shortcode if (!($childShortcode = ctShortcodeHandler::getInstance()->getShortcode($childInfo['name']))) { throw new Exception("Cannot find shortcode " . $childInfo['name']); } return $childShortcode; } return null; }
/** * Init shortcodes */ protected function initShortcodes() { require_once CT_THEME_LIB_DIR . '/shortcodes/ctShortcodeHandler.class.php'; ctShortcodeHandler::getInstance(); //initialize shortcodes }
/** * Wraps shortcode * @param ctShortcode $code * @param string $html * @param array $allowTemplates * @return string */ protected function wrapShortcode($code, $html, $allowTemplates = array()) { if (!self::$rowPatterns) { $row = ctShortcodeHandler::getInstance()->getShortcode('row'); $combs = $this->parseAttributes($row, $row->getAttributesNormalized()); $templates = array('full' => '[full_column]%1$s[/full_column]', 'half' => '[half_column]%1$s[/half_column][half_column]%1$s[/half_column]', 'third' => '[third_column]%1$s[/third_column][two_thirds_column]%1$s[/two_thirds_column]', 'no_row' => '%1$s'); $data = $this->combinations($combs); foreach ($data as $key => $profile) { $params = implode(' ', is_array($profile) ? $profile : array($profile)); foreach ($templates as $name => $template) { $r = ''; if ($name != 'no_row') { $r .= '[' . $row->getShortcodeName() . ' ' . $params . ']' . "\n"; } $r .= $template . "\n"; if ($name != 'no_row') { $r .= '[/' . $row->getShortcodeName() . ']'; } self::$rowPatterns[$key][$name] = $r; } } } $allowTemplates = array_flip($allowTemplates ? $allowTemplates : $this->getShortcodeWrapTemplates($code)); //use only filtered templates $r = ''; if (isset($allowTemplates['no_row'])) { foreach (self::$rowPatterns[0] as $pat) { $r = sprintf($pat, "\n" . $html . "\n") . "\n"; } } else { $r = '[title_row header="Shortcode: ' . $code->getShortcodeName() . '"][/title_row]' . "\n"; foreach (self::$rowPatterns as $patterns) { foreach ($patterns as $type => $pat) { if (array_key_exists($type, $allowTemplates)) { $r .= sprintf($pat, "\n" . $html . "\n") . "\n"; } } } } if ($this->mustCompile($code)) { $r = do_shortcode($r); } return $r . "\n\n"; }