From 7f2aa69f3aa3114e91f7725044dbe5ed0b69c7ce Mon Sep 17 00:00:00 2001 From: conory Date: Wed, 13 Apr 2016 10:34:41 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=84=EC=8B=9C=ED=8C=8C=EC=9D=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B0=9C?= =?UTF-8?q?=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- classes/template/TemplateHandler.class.php | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index ee1dce0c5..7780d1405 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -135,20 +135,25 @@ class TemplateHandler $source_template_mtime = filemtime($this->file); $latest_mtime = $source_template_mtime > $this->handler_mtime ? $source_template_mtime : $this->handler_mtime; - // get cached buff - if(is_readable($this->compiled_file) && filemtime($this->compiled_file) > $latest_mtime && filesize($this->compiled_file)) - { - $buff = Rhymix\Framework\Storage::read($this->compiled_file); - } - - // if not exist cached buff, parse template file - if(empty($buff)) + // make compiled file + if(!file_exists($this->compiled_file) || filemtime($this->compiled_file) < $latest_mtime) { $buff = $this->parse(); - Rhymix\Framework\Storage::write($this->compiled_file, $buff); + if(Rhymix\Framework\Storage::write($this->compiled_file, $buff) === false) + { + $tmpfilename = tempnam(sys_get_temp_dir(), 'rx-compiled'); + Rhymix\Framework\Storage::write($tmpfilename, $buff); + $this->compiled_file = $tmpfilename; + } + } + + $output = $this->_fetch($this->compiled_file); + + // delete tmpfile + if(isset($tmpfilename)) + { + Rhymix\Framework\Storage::delete($tmpfilename); } - - $output = $this->_fetch($buff); if($__templatehandler_root_tpl == $this->file) { @@ -327,10 +332,10 @@ class TemplateHandler /** * fetch using ob_* function - * @param string $buff if buff is not null, eval it instead of including compiled template file + * @param string $filename compiled template file name * @return string */ - private function _fetch($buff) + private function _fetch($filename) { $__Context = Context::getInstance(); $__Context->tpl_path = $this->path; @@ -338,7 +343,7 @@ class TemplateHandler $__ob_level_before_fetch = ob_get_level(); ob_start(); - @eval('?>' . $buff); + include $filename; $contents = ''; while (ob_get_level() > $__ob_level_before_fetch)