/**
* Parse a document template
*
* @return HtmlDocument instance of $this to allow chaining
*
* @since 1.7.0
*/
protected function _parseTemplate()
{
$matches = array();
if (preg_match_all('#<jdoc:include\\ type="([^"]+)"(.*)\\/>#iU', $this->_template, $matches)) {
$messages = [];
$template_tags_first = [];
$template_tags_last = [];
// Step through the jdocs in reverse order.
for ($i = \count($matches[0]) - 1; $i >= 0; $i--) {
$type = $matches[1][$i];
$attribs = empty($matches[2][$i]) ? array() : Utility::parseAttributes($matches[2][$i]);
$name = $attribs['name'] ?? null;
// Separate buffers to be executed first and last
if ($type === 'module' || $type === 'modules') {
$template_tags_first[$matches[0][$i]] = ['type' => $type, 'name' => $name, 'attribs' => $attribs];
} elseif ($type === 'message') {
$messages = [$matches[0][$i] => ['type' => $type, 'name' => $name, 'attribs' => $attribs]];
} else {
$template_tags_last[$matches[0][$i]] = ['type' => $type, 'name' => $name, 'attribs' => $attribs];
}
}
$this->_template_tags = $template_tags_first + $messages + array_reverse($template_tags_last);
}
return $this;
}