/** *Converts a shortcode into an array **/ static function shortcode2array($content, $depth = 1000) { $pattern = empty(ShortcodeHelper::$pattern) ? ShortcodeHelper::build_pattern() : ShortcodeHelper::$pattern; $depth--; preg_match_all("/{$pattern}/s", $content, $matches); $return = array(); foreach ($matches[3] as $key => $match) { $return[$key]['shortcode'] = $matches[2][$key]; $return[$key]['attr'] = shortcode_parse_atts($match); if (preg_match("/{$pattern}/s", $matches[5][$key]) && $depth) { $return[$key]['content'] = self::shortcode2array($matches[5][$key], $depth); } else { $return[$key]['content'] = $matches[5][$key]; } } return $return; }
public function text_to_interface($text = NULL) { global $shortcode_tags; $allowed = false; if (isset($_POST['text'])) { $text = $_POST['text']; } //isset when avia_ajax_text_to_interface is executed (avia_builder.js) if (isset($_POST['params']) && isset($_POST['params']['allowed'])) { $allowed = explode(',', $_POST['params']['allowed']); } //only build pattern with a subset of shortcodes //build the shortcode pattern to check if the text that we want to check uses any of the builder shortcodes ShortcodeHelper::build_pattern($allowed); $text_nodes = preg_split("/" . ShortcodeHelper::$pattern . "/s", $text); foreach ($text_nodes as $node) { if (strlen(trim($node)) == 0 || strlen(trim(strip_tags($node))) == 0) { //$text = preg_replace("/(".preg_quote($node, '/')."(?!\[\/))/", '', $text); } else { $text = preg_replace("/(" . preg_quote($node, '/') . "(?!\\[\\/))/", '[av_textblock]$1[/av_textblock]', $text); } } $text = $this->do_shortcode_backend($text); if (isset($_POST['text'])) { echo $text; exit; } else { return $text; } }