/** * strng regexp bbcode killer * * @param string|array $bbcode BBCode as string or matches as array - callback from preg_replace_callback() * * @return string * @throws \chillerlan\bbcode\BBCodeException */ protected function __parse($bbcode) : string { static $callback_count = 0; $callback = false; $preg_error = PREG_NO_ERROR; if (is_array($bbcode) && isset($bbcode['tag'], $bbcode['attributes'], $bbcode['content'])) { $tag = strtolower($bbcode['tag']); $attributes = $this->getAttributes($bbcode['attributes']); $content = $bbcode['content']; $callback = true; $callback_count++; } else { if (is_string($bbcode) && !empty($bbcode)) { $tag = null; $attributes = []; $content = $bbcode; } else { return ''; } } if ($callback_count < (int) $this->parserOptions->nesting_limit && !in_array($tag, $this->noparse_tags)) { $pattern = '#\\[(?<tag>\\w+)(?<attributes>(?:\\s|=)[^]]*)?](?<content>(?:[^[]|\\[(?!/?\\1((?:\\s|=)[^]]*)?])|(?R))*)\\[/\\1]#'; $content = preg_replace_callback($pattern, __METHOD__, $content); $preg_error = preg_last_error(); } $this->throwPregError($preg_error, $tag); if ($callback && isset($this->tagmap[$tag]) && in_array($tag, $this->allowed_tags)) { $this->BBTemp->tag = $tag; $this->BBTemp->attributes = $attributes; $this->BBTemp->content = $content; $this->BBTemp->parserOptions = $this->parserOptions; $this->BBTemp->languageInterface = $this->languageInterface; $this->BBTemp->depth = $callback_count; $this->moduleInterface = $this->modules[$this->tagmap[$tag]]; $this->moduleInterface->setBBTemp($this->BBTemp); $content = $this->moduleInterface->transform(); } $callback_count = 0; return $content; }