diff --git a/library/Rain/Tpl/Parser.php b/library/Rain/Tpl/Parser.php index 31b07bb..07f6c0b 100644 --- a/library/Rain/Tpl/Parser.php +++ b/library/Rain/Tpl/Parser.php @@ -123,25 +123,30 @@ public function compileFile( $this->templateInfo['template_filepath'] = $templateFilepath; // read the file - $this->templateInfo['code'] = $code = fread($fp, filesize($templateFilepath)); - - // xml substitution - $code = preg_replace("/<\?xml(.*?)\?>/s", /*config['php_enabled']) - $code = str_replace(array(""), array("<?", "?>"), $code); - - // xml re-substitution - $code = preg_replace_callback("/##XML(.*?)XML##/s", function( $match ) { - return "'; ?>"; - }, $code); - - $parsedCode = $this->compileTemplate($code, $isString = false, $templateBasedir, $templateDirectory, $templateFilepath); - $parsedCode = "" . $parsedCode; - - // fix the php-eating-newline-after-closing-tag-problem - $parsedCode = str_replace("?>\n", "?>\n\n", $parsedCode); + $filesize = filesize($templateFilepath); + $this->templateInfo['code'] = $code = $filesize > 0 ? fread($fp, $filesize) : ''; + + if (!empty($code)) { + // xml substitution + $code = preg_replace("/<\?xml(.*?)\?>/s", /*config['php_enabled']) + $code = str_replace(array(""), array("<?", "?>"), $code); + + // xml re-substitution + $code = preg_replace_callback("/##XML(.*?)XML##/s", function( $match ) { + return "'; ?>"; + }, $code); + + $parsedCode = $this->compileTemplate($code, $isString = false, $templateBasedir, $templateDirectory, $templateFilepath); + $parsedCode = "" . $parsedCode; + + // fix the php-eating-newline-after-closing-tag-problem + $parsedCode = str_replace("?>\n", "?>\n\n", $parsedCode); + } else { + $parsedCode = ''; + } // create directories if (!is_dir($this->config['cache_dir']))