태그 사용 templateHandler에서 WidgetHandler::execute()를 실행하는 코드로 대체하게 된다 * * $include_info가 true일 경우 css 코드와 위젯핸들링을 위한 코드까지 포함하도록 한다 **/ function execute($widget, $args, $include_info = false) { // 디버그를 위한 위젯 실행 시간 저장 if(__DEBUG__==3) $start = getMicroTime(); // widget중 widgetContent 는 page 모듈에 종속적인 위젯으로 직접 page.admin.controller.php를 호출하여 처리를 해야 함 (차후 정리 필요) if($widget == 'widgetContent') { $style = $args->style; $body = base64_decode($args->body); $widget_padding_left = $args->widget_padding_left; $widget_padding_right = $args->widget_padding_right; $widget_padding_top = $args->widget_padding_top; $widget_padding_bottom = $args->widget_padding_bottom; if($include_info) { $oWidgetController = &getController('widget'); $tpl = $oWidgetController->transEditorContent($body, $args); } else { $tpl = sprintf('
%s
', $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $body); } return $tpl; // widget Box일 경우 간단히 변경만 시도함 } else if($widget == 'widgetBox') { $style = $args->style; $widget_padding_left = $args->widget_padding_left; $widget_padding_right = $args->widget_padding_right; $widget_padding_top = $args->widget_padding_top; $widget_padding_bottom = $args->widget_padding_bottom; if($include_info) { $tpl = sprintf('
', $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left); } else { $tpl = sprintf('
%s', $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $body); } return $tpl; } // 설치된 위젯들에 대한 처리 if(!is_dir(sprintf('./widgets/%s/',$widget))) return; $cache_path = './files/cache/widget_cache/'; if(!is_dir($cache_path)) FileHandler::makeDir($cache_path); // $widget의 객체를 받음 $oWidget = WidgetHandler::getObject($widget); if(!$oWidget) return; // 위젯 output을 생성하기 위한 변수 설정 $widget_padding_top = $args->widget_padding_top; $widget_padding_bottom = $args->widget_padding_bottom; $widget_padding_left = $args->widget_padding_left; $widget_padding_right = $args->widget_padding_right; $inner_style = sprintf("padding:%dpx %dpx %dpx %dpx !important; padding:none !important;", $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left); /** * 출력을 위해 위젯 내용을 div로 꾸밈 **/ // 서비스에 사용하기 위해 위젯 정보를 포함하지 않을 경우 if(!$include_info) { // 위젯 실행 $html = $oWidget->proc($args); $output = sprintf('
%s
', $args->style, $inner_style, $html); // 위젯 sequence가 있고 위젯의 캐싱을 지정하였고 위젯정보를 담지 않도록 하였을 경우 캐시 파일을 저장 if($args->widget_sequence && $args->widget_cache) WidgetHandler::writeCache($args->widget_sequence, $output); // 에디팅등에 사용하기 위한 목적으로 위젯 정보를 포함할 경우 } else { // 위젯 실행 //if($args->widget_sequence && $args->widget_cache) $html = WidgetHandler::getCache($args->widget_sequence, $args->widget_cache); //if(!$html) $html = $oWidget->proc($args); $html = $oWidget->proc($args); // args 정리 $attribute = array(); if($args) { foreach($args as $key => $val) { if($key == 'class' || $key == 'style') continue; if(strpos($val,'|@|')>0) { $val = str_replace('|@|',',',$val); } $attribute[] = sprintf('%s="%s"', $key, str_replace('"','\"',$val)); } } // 결과물에 있는 css Meta 목록을 구해와서 해당 css를 아예 읽어버림 require_once("./classes/optimizer/Optimizer.class.php"); $oOptimizer = new Optimizer(); preg_match_all('!<\!\-\-Meta:([^\-]*?)\-\->!is', $html, $matches); $css_header = null; for($i=0;$ireplaceCssPath($css_file, $buff)."\n"; } if(!$html) $html = ' '; $output = sprintf( '
'. '
'. '
'. '
'. '
'. '
'. '
'. '
'. '
'. '
'. '%s'. '
'. '
'. '
', $css_header, $args->style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $widget, implode(' ',$attribute), $inner_style, $html ); } // 위젯 결과물 생성 시간을 debug 정보에 추가 if(__DEBUG__==3) $GLOBALS['__widget_excute_elapsed__'] += getMicroTime() - $start; // 결과 return return $output; } /** * @brief 위젯 객체를 return **/ function getObject($widget) { if(!$GLOBALS['_xe_loaded_widgets_'][$widget]) { // 일단 위젯의 위치를 찾음 $oWidgetModel = &getModel('widget'); $path = $oWidgetModel->getWidgetPath($widget); // 위젯 클래스 파일을 찾고 없으면 에러 출력 (html output) $class_file = sprintf('%s%s.class.php', $path, $widget); if(!file_exists($class_file)) return sprintf(Context::getLang('msg_widget_is_not_exists'), $widget); // 위젯 클래스를 include require_once($class_file); // 객체 생성 $eval_str = sprintf('$oWidget = new %s();', $widget); @eval($eval_str); if(!is_object($oWidget)) return sprintf(Context::getLang('msg_widget_object_is_null'), $widget); if(!method_exists($oWidget, 'proc')) return sprintf(Context::getLang('msg_widget_proc_is_null'), $widget); $oWidget->widget_path = $path; $GLOBALS['_xe_loaded_widgets_'][$widget] = $oWidget; } return $GLOBALS['_xe_loaded_widgets_'][$widget]; } } ?>