From 8235bde05b3c0f20e87de53078d63ebe711e74b5 Mon Sep 17 00:00:00 2001 From: zero Date: Thu, 20 Sep 2007 05:06:04 +0000 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EB=B6=80=ED=8E=98=EC=9D=B4=EC=A7=80?= =?UTF-8?q?=EB=AA=A8=EB=93=88(opage)=EC=97=90=EC=84=9C=20=EB=82=B4?= =?UTF-8?q?=EB=B6=80=20php/html=ED=8C=8C=EC=9D=BC=EC=9D=84=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=EC=8B=9C=20=EC=9C=84=EC=A0=AF=EC=9D=B4=EB=82=98=20ZBX?= =?UTF-8?q?E=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=EB=AC=B8=EB=B2=95=EA=B3=BC?= =?UTF-8?q?=20=EB=B3=80=EC=88=98=EB=A5=BC=20=EC=93=B8=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@2632 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/template/TemplateHandler.class.php | 17 ++++- modules/opage/opage.view.php | 77 +++++++++++++++------- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/classes/template/TemplateHandler.class.php b/classes/template/TemplateHandler.class.php index 8858c2f00..87d65803a 100644 --- a/classes/template/TemplateHandler.class.php +++ b/classes/template/TemplateHandler.class.php @@ -64,6 +64,19 @@ return $output; } + /** + * @brief 주어진 파일을 컴파일 후 바로 return + **/ + function compileDirect($tpl_path, $tpl_filename) { + $this->tpl_path = $tpl_path; + $this->tpl_file = $tpl_file; + + $tpl_file = $tpl_path.$tpl_filename; + if(!file_exists($tpl_file)) return; + + return $this->_compileTplFile($tpl_file); + } + /** * @brief tpl_file이 컴파일이 되어 있는 것이 있는지 체크 **/ @@ -78,7 +91,7 @@ /** * @brief tpl_file을 compile **/ - function _compileTplFile($tpl_file, $compiled_tpl_file) { + function _compileTplFile($tpl_file, $compiled_tpl_file = '') { // tpl 파일을 읽음 $buff = FileHandler::readFile($tpl_file); @@ -112,7 +125,7 @@ // $buff = preg_replace('/ +/', ' ', $buff); // 컴파일된 코드를 파일에 저장 - FileHandler::writeFile($compiled_tpl_file, $buff); + if($compiled_tpl_file) FileHandler::writeFile($compiled_tpl_file, $buff); return $buff; } diff --git a/modules/opage/opage.view.php b/modules/opage/opage.view.php index a96617fd0..14dd74fa5 100644 --- a/modules/opage/opage.view.php +++ b/modules/opage/opage.view.php @@ -21,9 +21,6 @@ function dispOpageIndex() { // 권한 체크 if(!$this->grant->view) return $this->stop('msg_not_permitted'); - - // opage controller 생성 - $oOpageController = &getController('opage'); // 외부 페이지 모듈의 정보를 구함 $oOpageModel = &getModel('opage'); @@ -35,7 +32,22 @@ $caching_interval = $module_info->caching_interval; // 캐시 파일 지정 - $cache_file = sprintf("./files/cache/opage/%d.cache", $module_info->module_srl); + $cache_file = sprintf("./files/cache/opage/%d.cache.php", $module_info->module_srl); + + // http 인지 내부 파일인지 점검 + if(eregi("^http:\/\/",$path)) $content = $this->getHtmlPage($path, $caching_interval, $cache_file); + else $content = $this->executeFile($path, $caching_interval, $cache_file); + + Context::set('opage_content', $content); + + // 결과 출력 템플릿 지정 + $this->setTemplateFile('content'); + } + + /** + * @brief 외부 http로 요청되는 파일일 경우 파일을 받아와서 저장 후 return + **/ + function getHtmlPage($path, $caching_interval, $cache_file) { // 캐시 검사 if($caching_interval > 0 && file_exists($cache_file) && filemtime($cache_file) + $caching_interval*60 > time()) { @@ -44,26 +56,16 @@ } else { - // 경로에 http://가 있는 경우와 없는 경우를 비교 - if(eregi("^http:\/\/",$path)) { - FileHandler::getRemoteFile($path, $cache_file); - $content = FileHandler::readFile($cache_file); - - // 서버 내부에 있는 경우 - } elseif(file_exists($path)) { - ob_start(); - @include($path); - $content = ob_get_contents(); - ob_end_clean(); - FileHandler::writeFile($cache_file, $content); - } + FileHandler::getRemoteFile($path, $cache_file); + $content = FileHandler::readFile($cache_file); } + + // opage controller 생성 + $oOpageController = &getController('opage'); // 외부 서버의 페이지 일 경우 이미지, css, javascript등의 url을 변경 - if(eregi("^http:\/\/",$path)) { - $content = $oOpageController->replaceSrc($content, $path); - } + $content = $oOpageController->replaceSrc($content, $path); // 해당 문서를 utf-8로 변경 $buff->content = $content; @@ -82,10 +84,39 @@ $body_script = $oOpageController->getBodyScript($content); if(!$body_script) $body_script = $content; - Context::set('opage_content', $body_script); + return $content; + } - // 결과 출력 템플릿 지정 - $this->setTemplateFile('content'); + /** + * @brief 내부 파일일 경우 include하도록 캐시파일을 만들고 처리 + **/ + function executeFile($path, $caching_interval, $cache_file) { + + // 캐시 검사 + if($caching_interval <1 || !file_exists($cache_file) || filemtime($cache_file) + $caching_interval*60 <= time()) { + if(file_exists($cache_file)) @unlink($cache_file); + + // 경로와 파일이름을 구함 + $tmp_path = explode('/',$path); + $filename = $tmp_path[count($tmp_path)-1]; + $filepath = ereg_replace($filename."$","",$path); + + // 컴파일 시도 + $oTemplate = &TemplateHandler::getInstance(); + $script = $oTemplate->compileDirect($filepath, $filename); + + FileHandler::writeFile($cache_file, $script); + } + + // include후 결과를 return + if(file_exists($cache_file)) { + ob_start(); + @include($cache_file); + $content = ob_get_contents(); + ob_end_clean(); + } + + return $content; } }