protected function preprocess($input)
{
if ($n = preg_match_all('/<%include(.*?)%>/', $input, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
for ($i = 0; $i < $n; ++$i) {
$filePath = Prado::getPathOfNamespace(trim($matches[$i][1][0]), TTemplateManager::TEMPLATE_FILE_EXT);
if ($filePath !== null && is_file($filePath)) {
$this->_includedFiles[] = $filePath;
} else {
$errorLine = count(explode("\n", substr($input, 0, $matches[$i][0][1] + 1)));
$this->handleException(new TConfigurationException('template_include_invalid', trim($matches[$i][1][0])), $errorLine, $input);
}
}
$base = 0;
for ($i = 0; $i < $n; ++$i) {
$ext = file_get_contents($this->_includedFiles[$i]);
$length = strlen($matches[$i][0][0]);
$offset = $base + $matches[$i][0][1];
$this->_includeAtLine[$i] = count(explode("\n", substr($input, 0, $offset)));
$this->_includeLines[$i] = count(explode("\n", $ext));
$input = substr_replace($input, $ext, $offset, $length);
$base += strlen($ext) - $length;
}
}
return $input;
}