- Timestamp:
- 06/16/2008 02:37:05 PM (3 months ago)
- Location:
- sandbox
- Files:
-
- 3 modified
-
classes/widget/WidgetHandler.class.php (modified) (4 diffs)
-
modules/page/page.admin.controller.php (modified) (1 diff)
-
modules/widget/widget.controller.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
sandbox/classes/widget/WidgetHandler.class.php
r3794 r4283 13 13 * @brief 위젯 캐시 처리 14 14 **/ 15 function getCache($widget, $args) { 15 function getCache($widget, $args, $lang_type = null, $ignore_cache = false) { 16 // 지정된 언어가 없으면 현재 언어 지정 17 if(!$lang_type) $lang_type = Context::getLangType(); 16 18 17 19 // widget, 캐시 번호와 캐시값이 설정되어 있는지 확인 … … 22 24 * 캐시 번호와 캐시 값이 아예 없으면 바로 데이터를 추출해서 리턴 23 25 **/ 24 if(!$ widget_cache || !$widget_sequence) {26 if(!$ignore_cache && (!$widget_cache || !$widget_sequence)) { 25 27 $oWidget = WidgetHandler::getObject($widget); 26 28 if(!$oWidget) return; … … 38 40 39 41 // 캐시파일명을 구함 40 $cache_file = sprintf('%s%d.%s.cache', $cache_path, $widget_sequence, Context::getLangType()); 41 42 // 캐시 파일이 존재하면 해당 파일의 유효성 검사 43 if(file_exists($cache_file)) { 42 $cache_file = sprintf('%s%d.%s.cache', $cache_path, $widget_sequence, $lang_type); 43 44 // 캐시 Lock 파일을 구함 45 $lock_file = sprintf('%s%d.%s.lock', $cache_path, $widget_sequence, $lang_type); 46 47 // 캐시 파일이 존재하면 해당 파일의 유효성 검사 (lock파일이 있을 경우 유효성 검사하지 않음) 48 if(!$ignore_cache && file_exists($cache_file)) { 44 49 $filemtime = filemtime($cache_file); 45 50 46 51 // 수정 시간을 비교해서 캐싱중이어야 하거나 WidgetHandler.class.php 파일보다 나중에 만들어 졌다면 캐시값을 return 47 if( $filemtime + $widget_cache*60 > time() && $filemtime > filemtime('./classes/widget/WidgetHandler.class.php')) {52 if(file_exists($lock_file) || ($filemtime + $widget_cache*60 > time() && $filemtime > filemtime('./classes/widget/WidgetHandler.class.php'))) { 48 53 return FileHandler::readFile($cache_file); 49 54 } 50 55 } 51 56 52 // 캐시를 새로 해야 할 경우임 57 // lock 파일 생성 58 FileHandler::writeFile($lock_file, ''); 59 60 // 캐시 파일을 갱신하여야 할 경우 lock파일을 만들고 캐시 생성 53 61 $oWidget = WidgetHandler::getObject($widget); 54 62 if(!$oWidget) return; 55 63 56 64 $widget_content = $oWidget->proc($args); 57 WidgetHandler::writeCache($widget_sequence, $widget_content); 65 FileHandler::writeFile($cache_file, $widget_content); 66 67 // lock 파일 제거 68 @unlink($lock_file); 58 69 59 70 return $widget_content; … … 61 72 62 73 /** 63 * @brief 캐시 파일 생성 64 **/ 65 function writeCache($widget_sequence, $output) { 66 $cache_path = './files/cache/widget_cache/'; 67 $cache_file = sprintf('%s%d.%s.cache', $cache_path, $widget_sequence, Context::getLangType()); 68 FileHandler::writeFile($cache_file, $output); 69 } 70 71 /** 72 * @brief 위젯을 찾아서 실행하고 결과를 출력 74 * @brief 위젯이름과 인자를 받아서 결과를 생성하고 결과 리턴 73 75 * 태그 사용 templateHandler에서 WidgetHandler::execute()를 실행하는 코드로 대체하게 된다 74 76 * -
sandbox/modules/page/page.admin.controller.php
r3603 r4283 181 181 $content = $module_info->content; 182 182 183 // 언어 종류 가져옴 184 $lang_list = Context::get('lang_supported'); 185 186 // 위젯 캐시 sequence 를 가져옴 187 preg_match_all('/widget_sequence="([0-9]+)"/i',$content, $matches); 188 189 $cache_path = './files/cache/widget_cache/'; 190 191 for($i=0;$i<count($matches[1]);$i++) { 192 $sequence = $matches[1][$i]; 193 194 foreach($lang_list as $lang_type => $val) { 195 $cache_file = sprintf('%s%d.%s.cache', $cache_path, $sequence, $lang_type); 196 @unlink($cache_file); 197 } 198 } 183 // widget controller 의 캐시파일 재생성 실행 184 $oWidgetController = &getController('widget'); 185 $oWidgetController->recompileWidget($content); 199 186 200 187 $this->setMessage('success_updated'); -
sandbox/modules/widget/widget.controller.php
r4118 r4283 176 176 } 177 177 178 /** 179 * @brief 특정 content내의 위젯을 다시 생성 180 **/ 181 function recompileWidget($content) { 182 // 언어 종류 가져옴 183 $lang_list = Context::get('lang_supported'); 184 185 // 위젯 캐시 sequence 를 가져옴 186 preg_match_all('!<img([^\>]*)widget=([^\>]*?)\>!is', $content, $matches); 187 188 $cache_path = './files/cache/widget_cache/'; 189 190 $oWidget = new WidgetHandler(); 191 $oXmlParser = new XmlParser(); 192 193 for($i=0;$i<count($matches[1]);$i++) { 194 $buff = $matches[0][$i]; 195 $xml_doc = $oXmlParser->parse(trim($buff)); 196 197 $args = $xml_doc->img->attrs; 198 if(!$args) continue; 199 200 // 캐싱하지 않을 경우 패스 201 $widget = $args->widget; 202 $sequence = $args->widget_sequence; 203 $cache = $args->widget_cache; 204 if(!$sequence || !$cache) continue; 205 206 // 언어별로 위젯 캐시 파일이 있을 경우 재생성 207 foreach($lang_list as $lang_type => $val) { 208 $cache_file = sprintf('%s%d.%s.cache', $cache_path, $sequence, $lang_type); 209 if(!file_exists($cache_file)) continue; 210 211 $oWidget->getCache($widget, $args, $lang_type, true); 212 } 213 } 214 215 } 216 178 217 } 179 218 ?>