XE 코드 고도화

1. 위젯/ 에디터컴포넌트의 코드 컴파일을 Context가 아닌 각 모듈이 trigger로 동작하게 개선 : 관리자 페이지에서 모듈 업데이트 필요
2. IE7에서 버튼 이미지가 어긋나는 문제 수정
3. 페이지 모듈의 캐싱 기능 추가 : 페이지 자체 캐시 가능하도록 함
4. 에디터에서 파일업로드시 파일 크기가 제대로 적용되지 않던 문제 수정 및 파일을 올리는 중에 남은 용량을 체크하여 미리 파일 업로드가 되지 않도록 함



git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6103 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
zero 2009-04-14 09:34:12 +00:00
parent 1ee64389ab
commit 32c3e86b1b
42 changed files with 838 additions and 810 deletions

View file

@ -45,8 +45,6 @@
var $is_uploaded = false; ///< @brief 첨부파일이 업로드 된 요청이였는지에 대한 체크 플래그
var $widget_include_info_flag = false; // 위젯 정보 코드 출력
/**
* @brief 유일한 Context 객체를 반환 (Singleton)
* Context는 어디서든 객체 선언없이 사용하기 위해서 static 하게 사용
@ -1331,117 +1329,11 @@
return file_exists(Context::getConfigFile()) && filesize(Context::getConfigFile());
}
/**
* @brief 내용의 위젯이나 기타 기능에 대한 code를 실제 code로 변경을 위한 flag set
**/
function setTransWidgetCodeIncludeInfo($flag=false){
$oContext = &Context::getInstance();
$oContext->widget_include_info_flag = $flag ? true : false;
}
/**
* @brief 내용의 위젯이나 기타 기능에 대한 code를 실제 code로 변경
**/
function transContent($content) {
// 사용자 정의 언어로 변경
$oModuleController = &getController('module');
$oModuleController->replaceDefinedLangCode($content);
// 위젯 코드 변경
$oWidgetController = &getController('widget');
$content = $oWidgetController->transWidgetCode($content,$this->widget_include_info_flag);
// 메타 파일 변경
$content = preg_replace_callback('!<\!\-\-Meta:([^\-]*?)\-\->!is', array($this,'transMeta'), $content);
// 에디터 컴포넌트를 찾아서 결과 코드로 변환
$content = preg_replace_callback('!<div([^\>]*)editor_component=([^\>]*)>(.*?)\<\/div\>!is', array($this,'transEditorComponent'), $content);
$content = preg_replace_callback('!<img([^\>]*)editor_component=([^\>]*?)\>!is', array($this,'transEditorComponent'), $content);
// style의 url 경로를 재정의 한다.
$content = preg_replace('/url\(http:\/\/([^ ]+)http:\/\//is','url(http://', $content);
// body 내의 <style ..></style>를 header로 이동
$content = preg_replace_callback('!<style(.*?)<\/style>!is', array($this,'moveStyleToHeader'), $content);
// templateHandler의 이미지 경로로 인하여 생기는 절대경로 이미지등의 경로 중복 처리
//$content = preg_replace('/<(img|input)([^>]*)src=(["|\']?)http:\/\/([^ ]+)http:\/\//is','<$1$2src=$3http://', $content);
$content = preg_replace('/src=(["|\']?)http:\/\/([^ ]+)http:\/\//is','src=$1http://', $content);
return $content;
}
/**
* @brief IE위지윅에디터에서 태그가 대문자로 사용되기에 이를 소문자로 치환
**/
function transTagToLowerCase($matches) {
return sprintf('<%s%s%s>', $matches[1], strtolower($matches[2]), $matches[3]);
}
/**
* @brief <!--Meta:파일이름.(css|js)--> 변경
**/
function transMeta($matches) {
if(substr($matches[1],'-4')=='.css') $this->addCSSFile($matches[1]);
elseif(substr($matches[1],'-3')=='.js') $this->addJSFile($matches[1]);
}
/**
* @brief <body>내의 <style태그를 header로 이동
**/
function moveStyleToHeader($matches) {
$this->addHtmlHeader($matches[0]);
return '';
}
/**
* @brief 내용의 에디터 컴포넌트 코드를 변환
**/
function transEditorComponent($matches) {
// IE에서는 태그의 특성중에서 " 를 빼어 버리는 경우가 있기에 정규표현식으로 추가해줌
$buff = $matches[0];
$buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff);
$buff = str_replace("&","&amp;",$buff);
// 에디터 컴포넌트에서 생성된 코드
$oXmlParser = new XmlParser();
$xml_doc = $oXmlParser->parse($buff);
if($xml_doc->div) $xml_doc = $xml_doc->div;
else if($xml_doc->img) $xml_doc = $xml_doc->img;
$xml_doc->body = $matches[3];
// attribute가 없으면 return
$editor_component = $xml_doc->attrs->editor_component;
if(!$editor_component) return $matches[0];
// component::transHTML() 을 이용하여 변환된 코드를 받음
$oEditorModel = &getModel('editor');
$oComponent = &$oEditorModel->getComponentObject($editor_component, 0);
if(!is_object($oComponent)||!method_exists($oComponent, 'transHTML')) return $matches[0];
return $oComponent->transHTML($xml_doc);
}
/**
* @brief gzip encoding 여부 체크
**/
function isGzEnabled() {
if(
(defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1) &&
strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false &&
function_exists('ob_gzhandler') &&
extension_loaded('zlib')
) return true;
return false;
}
function getFixUrl($url){
if(eregi("(http|https):\/\/",$url)) return $url;
if(ereg("^/",$url)) return $url;
return dirname($_SERVER['PHP_SELF']) . "/" . $url;
}
}
?>

View file

@ -7,7 +7,6 @@
* Response Method에 따라서 html or xml 출력방법을 결정한다
* xml : oModule의 variables를 simple xml 출력
* html : oModule의 template/variables로 html을 만들고 contents_html로 처리
* widget이나 layout의 html과 연동하여 출력
**/
class DisplayHandler extends Handler {
@ -22,108 +21,136 @@
function printContent(&$oModule) {
// gzip encoding 지원 여부 체크
$this->gz_enabled = Context::isGzEnabled();
if(
(defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1) &&
strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')!==false &&
function_exists('ob_gzhandler') &&
extension_loaded('zlib')
) $this->gz_enabled = true;
// header 출력
$this->_printHeader();
// request method에 따른 처리
if(Context::getRequestMethod() == 'XMLRPC') $content = $this->_toXmlDoc($oModule);
else if(Context::getRequestMethod() == 'JSON') $content = $this->_toJSON($oModule);
else $content = $this->_toHTMLDoc($oModule);
// request method에 따른 컨텐츠 결과물 추출
if(Context::getRequestMethod() == 'XMLRPC') $output = $this->_toXmlDoc($oModule);
else if(Context::getRequestMethod() == 'JSON') $output = $this->_toJSON($oModule);
else $output = $this->_toHTMLDoc($oModule);
// 요청방식에 따라 출력을 별도로
// HTML 출력 요청일 경우 레이아웃 컴파일과 더블어 완성된 코드를 제공
if(Context::getResponseMethod()=="HTML") {
// 관리자 모드일 경우 #xeAdmin id를 가지는 div 추가
if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin')>0) $content = '<div id="xeAdmin">'.$content.'</div>';
if(Context::get('module')!='admin' && strpos(Context::get('act'),'Admin')>0) $output = '<div id="xeAdmin">'.$output.'</div>';
// 내용을 content라는 변수로 설정 (layout에서 {$content}에서 대체됨)
Context::set('content', $content);
// 내용을 content라는 변수로 설정 (layout에서 {$output}에서 대체됨)
Context::set('content', $output);
// 레이아웃을 컴파일
if(__DEBUG__==3) $start = getMicroTime();
$oTemplate = &TemplateHandler::getInstance();
// layout이라는 변수가 none으로 설정되면 기본 레이아웃으로 변경
if(Context::get('layout') != 'none') {
if(__DEBUG__==3) $start = getMicroTime();
$layout_path = $oModule->getLayoutPath();
if(!$layout_path) $layout_path = "./common/tpl";
$layout_file = $oModule->getLayoutFile();
$edited_layout_file = $oModule->getEditedLayoutFile();
}
if(!$layout_path) $layout_path = './common/tpl/';
if(!$layout_file) $layout_file = 'default_layout.html';
// 현재 요청된 레이아웃 정보를 구함
$oLayoutModel = &getModel('layout');
$current_module_info = Context::get('current_module_info');
$layout_srl = $current_module_info->layout_srl;
// 현재 요청된 레이아웃 정보를 구함
$oLayoutModel = &getModel('layout');
$current_module_info = Context::get('current_module_info');
$layout_srl = $current_module_info->layout_srl;
// 생성된 레이아웃과 연결되어 있으면 처리
if($layout_srl > 0){
$layout_info = Context::get('layout_info');
// 레이아웃과 연결되어 있으면 레이아웃 컴파일
if($layout_srl > 0){
$layout_info = Context::get('layout_info');
// faceoff 레이아웃일 경우 별도 처리
if($layout_info && $layout_info->type == 'faceoff') {
$oLayoutModel->doActivateFaceOff($layout_info);
// faceoff 레이아웃일 경우 별도 처리
if($layout_info && $layout_info->type == 'faceoff') {
$oLayoutModel->doActivateFaceOff($layout_info);
Context::set('layout_info', $layout_info);
}
// 관리자 레이아웃 수정화면에서 변경된 CSS가 있는지 조사
$edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
if(file_exists($edited_layout_css)) Context::addCSSFile($edited_layout_css,true,'all','',100);
}
// 관리자 레이아웃 수정화면에서 변경된 CSS가 있는지 조사
$edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
$output = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
if(file_exists($edited_layout_css)) Context::addCSSFile($edited_layout_css,true,'all','',100);
if(__DEBUG__==3) $GLOBALS['__layout_compile_elapsed__'] = getMicroTime()-$start;
}
Context::set('layout_info', $layout_info);
$zbxe_final_content = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
if(__DEBUG__==3) $GLOBALS['__layout_compile_elapsed__'] = getMicroTime()-$start;
// 각 위젯, 에디터 컴포넌트의 코드 변경
if(__DEBUG__==3) $start = getMicroTime();
$oContext = &Context::getInstance();
$zbxe_final_content= $oContext->transContent($zbxe_final_content);
if(__DEBUG__==3) $GLOBALS['__trans_widget_editor_elapsed__'] = getMicroTime()-$start;
// 최종 결과를 common_layout에 넣어버림
Context::set('zbxe_final_content', $zbxe_final_content);
$output = $oTemplate->compile('./common/tpl', 'common_layout');
// 사용자 정의 언어 변경
$oModuleController = &getController('module');
$oModuleController->replaceDefinedLangCode($output);
} else {
$output = $content;
}
// 출력하기 전에 trigger 호출 (before)
ModuleHandler::triggerCall('display', 'before', $output);
// 애드온 실행
$called_position = 'before_display_content';
$oAddonController = &getController('addon');
$addon_file = $oAddonController->getCacheFilePath();
if(file_exists($addon_file)) @include($addon_file);
$this->content_size = strlen($output);
// HTML 출력일 경우 최종적으로 common layout을 씌워서 출력
if(Context::getResponseMethod()=="HTML") {
if(__DEBUG__==3) $start = getMicroTime();
// 컨텐츠 출력
$this->display($output);
// 메타 파일 변경 (캐싱기능등으로 인해 위젯등에서 <!--Meta:경로--> 태그를 content에 넣는 경우가 있음
$output = preg_replace_callback('/<!--Meta:([a-z0-9\_\/\.]+)-->/is', array($this,'transMeta'), $output);
// style의 url 경로를 재정의 한다. (잘못 기입된 경우들이 발생함)
$output = preg_replace('/url\(http:\/\/([^ ]+)http:\/\//is','url(http://', $output);
// body 내의 <style ..></style>를 header로 이동
$output = preg_replace_callback('!<style(.*?)<\/style>!is', array($this,'moveStyleToHeader'), $output);
// templateHandler의 이미지 경로로 인하여 생기는 절대경로 이미지등의 경로 중복 처리
$output = preg_replace('/src=(["|\']?)http:\/\/([^ ]+)http:\/\//is','src=$1http://', $output);
// 사용자 정의 언어 변환
$oModuleController = &getController('module');
$oModuleController->replaceDefinedLangCode($output);
if(__DEBUG__==3) $GLOBALS['__trans_content_elapsed__'] = getMicroTime()-$start;
// 최종 레이아웃 변환
Context::set('content', $output);
$output = $oTemplate->compile('./common/tpl', 'common_layout');
}
// header 출력
if($this->gz_enabled) header("Content-Encoding: gzip");
if(Context::getResponseMethod() == 'JSON') $this->_printJSONHeader();
else if(Context::getResponseMethod() != 'HTML') $this->_printXMLHeader();
else $this->_printHTMLHeader();
// debugOutput 출력
$this->content_size = strlen($output);
$output .= $this->_debugOutput();
// 결과물 직접 출력
if($this->gz_enabled) print ob_gzhandler($output, 5);
else print $output;
// 출력 후 trigger 호출 (after)
ModuleHandler::triggerCall('display', 'after', $content);
}
/**
* @brief 최종 결과물의 출력
* @brief <!--Meta:파일이름.(css|js)--> 변경
**/
function display($content) {
$content .= $this->_debugOutput();
function transMeta($matches) {
if(substr($matches[1],'-4')=='.css') Context::addCSSFile($matches[1]);
elseif(substr($matches[1],'-3')=='.js') Context::addJSFile($matches[1]);
}
// 출력하기 전에 trigger 호출 (after)
ModuleHandler::triggerCall('display', 'after', $content);
if($this->gz_enabled) print ob_gzhandler($content, 5);
else print $content;
/**
* @brief <body>내의 <style태그를 header로 이동
**/
function moveStyleToHeader($matches) {
Context::addHtmlHeader($matches[0]);
}
/**
@ -186,13 +213,6 @@
return $oTemplate->compile($template_path, $tpl_file);
}
/**
* @brief content size return
**/
function getContentSize() {
return $this->content_size;
}
/**
* @brief 디버그 모드일 경우 디버깅 메시지 출력
*
@ -225,7 +245,7 @@
sprintf("%s:%s%s%s%s", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']),
$_SERVER['REQUEST_METHOD'],
Context::getResponseMethod(),
$this->getContentSize().' byte'
$this->content_size.' byte'
)
)
),
@ -233,7 +253,7 @@
);
$firephp->fb(
array('Elapsed time >>> Total : '.sprintf('%0.5f sec', $end - __StartTime__),
array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans widget&editor'),
array(array('DB queries', 'class file load', 'Template compile', 'XmlParse compile', 'PHP', 'Widgets', 'Trans Content'),
array(
sprintf('%0.5f sec', $GLOBALS['__db_elapsed_time__']),
sprintf('%0.5f sec', $GLOBALS['__elapsed_class_load__']),
@ -241,7 +261,7 @@
sprintf('%0.5f sec', $GLOBALS['__xmlparse_elapsed__']),
sprintf('%0.5f sec', $end-__StartTime__-$GLOBALS['__template_elapsed__']-$GLOBALS['__xmlparse_elapsed__']-$GLOBALS['__db_elapsed_time__']-$GLOBALS['__elapsed_class_load__']),
sprintf('%0.5f sec', $GLOBALS['__widget_excute_elapsed__']),
sprintf('%0.5f sec', $GLOBALS['__trans_widget_editor_elapsed__'])
sprintf('%0.5f sec', $GLOBALS['__trans_content_elapsed__'])
)
)
),
@ -275,7 +295,7 @@
$buff .= sprintf("\tRequest URI \t\t\t: %s:%s%s%s%s\n", $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $_SERVER['PHP_SELF'], $_SERVER['QUERY_STRING']?'?':'', $_SERVER['QUERY_STRING']);
$buff .= sprintf("\tRequest method \t\t\t: %s\n", $_SERVER['REQUEST_METHOD']);
$buff .= sprintf("\tResponse method \t\t: %s\n", Context::getResponseMethod());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->getContentSize());
$buff .= sprintf("\tResponse contents size\t\t: %d byte\n", $this->content_size);
// 전체 실행 시간
$buff .= sprintf("\n- Total elapsed time : %0.5f sec\n", $end-__StartTime__);
@ -292,7 +312,7 @@
$buff .= sprintf("\n\tLayout compile elapsed time \t: %0.5f sec", $GLOBALS['__layout_compile_elapsed__']);
// 위젯, 에디터 컴포넌트 치환 시간
$buff .= sprintf("\n\tTrans widget&editor elapsed time: %0.5f sec\n", $GLOBALS['__trans_widget_editor_elapsed__']);
$buff .= sprintf("\n\tTrans Content \t\t\t: %0.5f sec\n", $GLOBALS['__trans_content_elapsed__']);
}
// DB 로그 작성
@ -338,17 +358,6 @@
}
}
/**
* @brief RequestMethod에 맞춰 헤더 출력
***/
function _printHeader() {
if($this->gz_enabled) header("Content-Encoding: gzip");
if(Context::getResponseMethod() == 'JSON') return $this->_printJSONHeader();
else if(Context::getResponseMethod() != 'HTML') return $this->_printXMLHeader();
else return $this->_printHTMLHeader();
}
/**
* @brief xml header 출력 (utf8 고정)
**/

View file

@ -437,7 +437,7 @@
if(!$oModule || !method_exists($oModule, $called_method)) continue;
$output = $oModule->{$called_method}($obj);
if(!$output->toBool()) return $output;
if(is_object($output) && method_exists($output, 'toBool') && !$output->toBool()) continue;
unset($oModule);
}

View file

@ -9,337 +9,5 @@
var $widget_path = '';
/**
* @brief 위젯 캐시 처리
**/
function getCache($widget, $args, $lang_type = null, $ignore_cache = false) {
// 지정된 언어가 없으면 현재 언어 지정
if(!$lang_type) $lang_type = Context::getLangType();
// widget, 캐시 번호와 캐시값이 설정되어 있는지 확인
$widget_sequence = $args->widget_sequence;
$widget_cache = $args->widget_cache;
// args값에서 urldecode를 해줌
$object_vars = get_object_vars($args);
if(count($object_vars)) {
foreach($object_vars as $key => $val) {
if(in_array($key, array('body','class','style','widget_sequence','widget','widget_padding_left','widget_padding_top','widget_padding_bottom','widget_padding_right','document_srl'))) continue;
$args->{$key} = utf8RawUrlDecode($val);
}
}
/**
* 캐시 번호와 캐시 값이 아예 없으면 바로 데이터를 추출해서 리턴
**/
if(!$ignore_cache && (!$widget_cache || !$widget_sequence)) {
$oWidget = WidgetHandler::getObject($widget);
if(!$oWidget) return;
return $oWidget->proc($args);
}
/**
* 캐시 번호와 캐시값이 설정되어 있으면 캐시 파일을 불러오도록
**/
// 캐시 디렉토리가 없으면 생성
$cache_path = './files/cache/widget_cache/';
if(!is_dir($cache_path)) FileHandler::makeDir($cache_path);
// 캐시파일명을 구함
$cache_file = sprintf('%s%d.%s.cache', $cache_path, $widget_sequence, $lang_type);
// 캐시 Lock 파일을 구함
$lock_file = sprintf('%s%d.%s.lock', $cache_path, $widget_sequence, $lang_type);
// 캐시 파일이 존재하면 해당 파일의 유효성 검사 (lock파일이 있을 경우 유효성 검사하지 않음)
if(!$ignore_cache && file_exists($cache_file)) {
$filemtime = filemtime($cache_file);
// 수정 시간을 비교해서 캐싱중이어야 하거나 WidgetHandler.class.php 파일보다 나중에 만들어 졌다면 캐시값을 return
if(file_exists($lock_file) || ($filemtime + $widget_cache*60 > time() && $filemtime > filemtime('./classes/widget/WidgetHandler.class.php'))) {
return FileHandler::readFile($cache_file);
}
}
// lock 파일 생성
FileHandler::writeFile($lock_file, '');
// 캐시 파일을 갱신하여야 할 경우 lock파일을 만들고 캐시 생성
$oWidget = WidgetHandler::getObject($widget);
if(!$oWidget || !method_exists($oWidget,'proc')) return;
$widget_content = $oWidget->proc($args);
FileHandler::writeFile($cache_file, $widget_content);
// lock 파일 제거
FileHandler::removeFile($lock_file);
return $widget_content;
}
/**
* @brief 위젯이름과 인자를 받아서 결과를 생성하고 결과 리턴
* 태그 사용 templateHandler에서 WidgetHandler::execute() 실행하는 코드로 대체하게 된다
*
* $include_info가 true일 경우 페이지 수정시 위젯 핸들링을 위한 코드까지 포함함
**/
function execute($widget, $args, $include_info = false) {
// 디버그를 위한 위젯 실행 시간 저장
if(__DEBUG__==3) $start = getMicroTime();
// args값에서 urldecode를 해줌
$object_vars = get_object_vars($args);
if(count($object_vars)) {
foreach($object_vars as $key => $val) {
if(in_array($key, array('widgetbox_content','body','class','style','widget_sequence','widget','widget_padding_left','widget_padding_top','widget_padding_bottom','widget_padding_right','widgetstyle','document_srl'))) continue;
$args->{$key} = utf8RawUrlDecode($val);
}
}
/**
* 위젯이 widgetContent/ widgetBox가 아니라면 내용을 구함
**/
$widget_content = '';
if($widget != 'widgetContent' && $widget != 'widgetBox') {
if(!is_dir(sprintf('./widgets/%s/',$widget))) return;
// 위젯의 내용을 담을 변수
$widget_content = WidgetHandler::getCache($widget, $args);
}
if($widget == 'widgetBox'){
$widgetbox_content = $args->widgetbox_content;
}
/**
* 관리자가 지정한 위젯의 style을 구함
**/
// 가끔 잘못된 코드인 background-image:url(none)이 들어 있을 수가 있는데 이럴 경우 none에 대한 url을 요청하므로 무조건 제거함
$style = preg_replace('/background\-image: url\((.+)(\/?)none\)/is','', $args->style);
// 내부 여백을 둔 것을 구해서 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;
$inner_style = sprintf("padding:%dpx %dpx %dpx %dpx !important; padding:none !important;", $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left);
$oDocumentModel = &getModel('document');
/**
* 위젯 출력물을 구함
**/
$widget_content_header = '';
$widget_content_body = '';
$widget_content_footer = '';
// 일반 페이지 호출일 경우 지정된 스타일만 꾸면서 바로 return 함
if(!$include_info) {
if($args->id) $args->id = ' id="'.$args->id.'" ';
switch($widget) {
// 내용 직접 추가일 경우
case 'widgetContent' :
if($args->document_srl) {
$oDocument = $oDocumentModel->getDocument($args->document_srl);
$body = $oDocument->getContent(false,false,false, false);
} else {
$body = base64_decode($args->body);
}
$widget_content_header = sprintf('<div %sstyle="overflow:hidden;%s"><div style="%s">', $args->id, $style, $inner_style);
$widget_content_body = $body;
$widget_content_footer = '</div></div>';
break;
// 위젯 박스일 경우
case 'widgetBox' :
$widget_content_header = sprintf('<div %sstyle="overflow:hidden;%s;"><div style="%s"><div>', $args->id, $style, $inner_style);
$widget_content_body = $widgetbox_content;
break;
// 일반 위젯일 경우
default :
$widget_content_header = sprintf('<div %sstyle="overflow:hidden;%s">',$args->id,$style);
$widget_content_body = sprintf('<div style="*zoom:1;%s">%s</div>', $inner_style,$widget_content);
$widget_content_footer = '</div>';
break;
}
// 페이지 수정시에 호출되었을 경우 위젯 핸들링을 위한 코드 추가
} else {
switch($widget) {
// 내용 직접 추가일 경우
case 'widgetContent' :
if($args->document_srl) {
$oDocument = $oDocumentModel->getDocument($args->document_srl);
$body = $oDocument->getContent(false,false,false);
} else {
$body = base64_decode($args->body);
}
// args 정리
$attribute = array();
if($args) {
foreach($args as $key => $val) {
if(in_array($key, array('class','style','widget_padding_top','widget_padding_right','widget_padding_bottom','widget_padding_left','widget','widgetstyle','document_srl'))) continue;
if(strpos($val,'|@|')>0) $val = str_replace('|@|',',',$val);
$attribute[] = sprintf('%s="%s"', $key, str_replace('"','\"',$val));
}
}
$oWidgetController = &getController('widget');
$widget_content_header = sprintf(
'<div class="widgetOutput" widgetstyle="%s" style="%s" widget_padding_left="%s" widget_padding_right="%s" widget_padding_top="%s" widget_padding_bottom="%s" widget="widgetContent" document_srl="%d" %s>'.
'<div class="widgetResize"></div>'.
'<div class="widgetResizeLeft"></div>'.
'<div class="widgetBorder">'.
'<div style="%s">',$args->widgetstyle,
$style,
$args->widget_padding_left, $args->widget_padding_right, $args->widget_padding_top, $args->widget_padding_bottom,
$args->document_srl,
implode(' ',$attribute),
$inner_style);
$widget_content_body = $body;
$widget_content_footer = sprintf('</div><div class="clear"></div>'.
'</div>'.
'<div class="widgetContent" style="display:none;width:1px;height:1px;overflow:hidden;">%s</div>'.
'</div>',base64_encode($body));
break;
// 위젯 박스일 경우
case 'widgetBox' :
// args 정리
$attribute = array();
if($args) {
foreach($args as $key => $val) {
if(in_array($key, array('class','style','widget_padding_top','widget_padding_right','widget_padding_bottom','widget_padding_left','widget','widgetstyle','document_srl'))) continue;
if(strpos($val,'|@|')>0) $val = str_replace('|@|',',',$val);
$attribute[] = sprintf('%s="%s"', $key, str_replace('"','\"',$val));
}
}
$widget_content_header = sprintf(
'<div class="widgetOutput" widgetstyle="%s" widget="widgetBox" style="%s;" widget_padding_top="%s" widget_padding_right="%s" widget_padding_bottom="%s" widget_padding_left="%s" %s >'.
'<div class="widgetBoxResize"></div>'.
'<div class="widgetBoxResizeLeft"></div>'.
'<div class="widgetBoxBorder"><div class="nullWidget" style="%s">',$args->widgetstyle,$style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left,implode(' ',$attribute),$inner_style);
$widget_content_body = $widgetbox_content;
break;
// 일반 위젯일 경우
default :
// args 정리
$attribute = array();
if($args) {
foreach($args as $key => $val) {
if(in_array($key, array('class','style','widget_padding_top','widget_padding_right','widget_padding_bottom','widget_padding_left','widget'))) continue;
if(strlen($val)==0) continue;
if(strpos($val,'|@|')>0) $val = str_replace('|@|',',',$val);
$attribute[] = sprintf('%s="%s"', $key, str_replace('"','\"',$val));
}
}
$widget_content_header = sprintf('<div class="widgetOutput" widgetstyle="%s" style="%s" widget_padding_top="%s" widget_padding_right="%s" widget_padding_bottom="%s" widget_padding_left="%s" widget="%s" %s >'.
'<div class="widgetResize"></div>'.
'<div class="widgetResizeLeft"></div>'.
'<div class="widgetBorder">',$args->widgetstyle,$style,
$widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left,
$widget, implode(' ',$attribute));
$widget_content_body = sprintf('<div style="%s">%s</div><div class="clear"></div>',$inner_style, $widget_content);
$widget_content_footer = '</div></div>';
break;
}
}
// 위젯 스타일을 컴파일 한다.
if($args->widgetstyle){
$widget_content_body = WidgetHandler::complieWidgetStyle($args->widgetstyle,$widget, $widget_content_body, $args, $include_info);
}
$output = $widget_content_header . $widget_content_body . $widget_content_footer;
// 위젯 결과물 생성 시간을 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];
}
function complieWidgetStyle($widgetStyle,$widget,$widget_content_body, $args, $include_info){
if(!$widgetStyle) return $widget_content_body;
$oWidgetModel = &getModel('widget');
// 위젯 스타일의 extra_var를 가져와 묶는다
$widgetstyle_info = $oWidgetModel->getWidgetStyleInfo($widgetStyle);
if(!$widgetstyle_info) return $widget_content_body;
$widgetstyle_extar_var_key = get_object_vars($widgetstyle_info);
if(count($widgetstyle_extar_var_key['extra_var'])){
foreach($widgetstyle_extar_var_key['extra_var'] as $key => $val){
$widgetstyle_extar_var->{$key} = $args->{$key};
}
}
Context::set('widgetstyle_extar_var', $widgetstyle_extar_var);
if($include_info && $widget=='widgetBox'){
Context::set('widget_content', '<div class="widget_inner">'.$widget_content_body.'</div>');
}else{
Context::set('widget_content', $widget_content_body);
}
// 컴파일
$widgetstyle_path = $oWidgetModel->getWidgetStylePath($widgetStyle);
$oTemplate = &TemplateHandler::getInstance();
$tpl = $oTemplate->compile($widgetstyle_path, 'widgetstyle');
return $tpl;
}
}
?>