diff --git a/classes/widget/WidgetHandler.class.php b/classes/widget/WidgetHandler.class.php index 5c9ba0207..c85c10960 100644 --- a/classes/widget/WidgetHandler.class.php +++ b/classes/widget/WidgetHandler.class.php @@ -13,20 +13,29 @@ * @brief 위젯 캐시 처리 **/ function getCache($sequence, $cache) { + // 위젯 캐시는 캐시 번호와 캐시 시간이 없으면 캐시하지 않는 것으로 처리함 if(!$sequence || !$cache) return; + // 캐시 디렉토리가 없으면 생성하고 return $cache_path = './files/cache/widget_cache/'; if(!is_dir($cache_path)) { FileHandler::makeDir($cache_path); return; } + // 캐시파일명을 구해서 해당 파일이 없으면 return $cache_file = sprintf('%s%d.%s.cache', $cache_path, $sequence, Context::getLangType()); if(!file_exists($cache_file)) return; - $filemtime= filemtime($cache_file); + $filemtime = filemtime($cache_file); + + // 만약 캐시파일이 widgetHandler보다 이전에 생성된 파일이면 새로 캐시해야 함 + if($filemtime < filemtime('./classes/widget/WidgetHandler.class.php')) return; + + // 캐시 파일의 수정일이 캐시시간보다 크면 새로 만들기 위해서 return if($filemtime + $cache*60 < time()) return; + // 캐시 파일 내용을 읽어서 return $output = FileHandler::readFile($cache_file); return $output; } @@ -42,130 +51,170 @@ /** * @brief 위젯을 찾아서 실행하고 결과를 출력 - *
태그 사용 templateHandler에서 WidgetHandler::execute()를 실행하는 코드로 대체하게 된다 + * 태그 사용 templateHandler에서 WidgetHandler::execute()를 실행하는 코드로 대체하게 된다 * - * $include_info가 true일 경우 css 코드와 위젯핸들링을 위한 코드까지 포함하도록 한다 + * $include_info가 true일 경우 페이지 수정시 위젯 핸들링을 위한 코드까지 포함함 **/ function execute($widget, $args, $include_info = false) { // 디버그를 위한 위젯 실행 시간 저장 if(__DEBUG__==3) $start = getMicroTime(); - $args->style = preg_replace('/background\-image: url\(none\)/is','', $args->style); - - // 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); + // 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'))) continue; + $args->{$key} = urldecode($val); } - 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로 꾸밈 + * 위젯이 widgetContent/ widgetBox가 아니라면 내용을 구함 **/ - // 서비스에 사용하기 위해 위젯 정보를 포함하지 않을 경우 - if(!$include_info) { + if($widget != 'widgetContent' && $widget != 'widgetBox') { + if(!is_dir(sprintf('./widgets/%s/',$widget))) return; - // 위젯 실행 - $html = $oWidget->proc($args); - $output = sprintf('
%s
', $args->style, $inner_style, $html); + // 위젯의 내용을 담을 변수 + $widget_content = ''; - // 위젯 sequence가 있고 위젯의 캐싱을 지정하였고 위젯정보를 담지 않도록 하였을 경우 캐시 파일을 저장 - if($args->widget_sequence && $args->widget_cache) WidgetHandler::writeCache($args->widget_sequence, $output); + // 캐시된 코드가 있는지 확인 + $widget_sequence = $args->widget_sequence; + $widget_cache = $args->widget_cache; + if($widget_cache && $widget_sequence) $widget_content = WidgetHandler::getCache($widget_sequence, $widget_cache); - // 에디팅등에 사용하기 위한 목적으로 위젯 정보를 포함할 경우 - } 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); + // 캐시된 코드가 없을 경우 코드 생성 + if(!$widget_content) { + $oWidget = WidgetHandler::getObject($widget); + if(!$oWidget) return; - // 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)); + $widget_content = $oWidget->proc($args); + + if(!is_string($widget_content)) { + if(is_object($widget_content) && (is_a($widget_content, 'Object')||is_subclass_of($widget_content, 'Object'))) { + $widget_content = $widget_content->getMessage(); + } else $widget_content = ''; } } - // 결과물에 있는 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"; + // 위젯의 캐시값과 위젯 sequence가 있을 경우 캐시 파일에 저장 + if($widget_cache && $widget_sequence) WidgetHandler::writeCache($widget_sequence, $widget_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); + + /** + * 위젯 출력물을 구함 + **/ + // 일반 페이지 호출일 경우 지정된 스타일만 꾸면서 바로 return 함 + if(!$include_info) { + switch($widget) { + // 내용 직접 추가일 경우 + case 'widgetContent' : + $body = base64_decode($args->body); + $output = sprintf('
%s
', $style, $inner_style, $body); + break; + + // 위젯 박스일 경우 + case 'widgetBox' : + $output = sprintf('
', $style, $inner_style); + break; + + // 일반 위젯일 경우 + default : + $output = sprintf('
%s
', $style, $inner_style, $widget_content); + break; } - 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 - ); + // 페이지 수정시에 호출되었을 경우 위젯 핸들링을 위한 코드 추가 + } else { + switch($widget) { + // 내용 직접 추가일 경우 + case 'widgetContent' : + $body = base64_decode($args->body); + $oWidgetController = &getController('widget'); + + $output = sprintf( + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '%s'. + '
'. + '
'. + ''. + '
', + $style, + $args->widget_padding_left, $args->widget_padding_right, $args->widget_padding_top, $args->widget_padding_bottom, + $inner_style, + $body, + base64_encode($body) + ); + break; + + // 위젯 박스일 경우 + case 'widgetBox' : + $output = sprintf( + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
', + $style, $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, $inner_style); + 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(strpos($val,'|@|')>0) $val = str_replace('|@|',',',$val); + $attribute[] = sprintf('%s="%s"', $key, str_replace('"','\"',$val)); + } + } + + $output = sprintf( + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '
'. + '%s'. + '
'. + '
'. + '
', + $style, + $widget_padding_top, $widget_padding_right, $widget_padding_bottom, $widget_padding_left, + $widget, implode(' ',$attribute), + $inner_style, + $widget_content + ); + break; + } } // 위젯 결과물 생성 시간을 debug 정보에 추가 diff --git a/modules/page/page.admin.controller.php b/modules/page/page.admin.controller.php index e1f03f88c..bfd2fb5a9 100644 --- a/modules/page/page.admin.controller.php +++ b/modules/page/page.admin.controller.php @@ -98,10 +98,11 @@ $oFileController->setFilesValid($module_info->module_srl); // 캐시파일 재생성 - $this->procPageAdminRemoveWidgetCache(); + //$this->procPageAdminRemoveWidgetCache(); $this->add("module_srl", $module_info->module_srl); $this->add("page", Context::get('page')); + $this->add("mid", $module_info->mid); $this->setMessage($msg_code); } diff --git a/modules/page/page.admin.view.php b/modules/page/page.admin.view.php index d112b5876..b41821af3 100644 --- a/modules/page/page.admin.view.php +++ b/modules/page/page.admin.view.php @@ -153,7 +153,9 @@ Context::set('module_info', $this->module_info); // 내용을 세팅 - $content = $this->module_info->content; + $content = Context::get('content'); + if(!$content) $content = $this->module_info->content; + Context::set('content', $content); // 내용중 위젯들을 변환 $oWidgetController = &getController('widget'); diff --git a/modules/page/tpl/filter/insert_page_content.xml b/modules/page/tpl/filter/insert_page_content.xml index bdc237398..58e3b5c2e 100644 --- a/modules/page/tpl/filter/insert_page_content.xml +++ b/modules/page/tpl/filter/insert_page_content.xml @@ -10,6 +10,7 @@ + diff --git a/modules/page/tpl/js/page_admin.js b/modules/page/tpl/js/page_admin.js index 1282949d2..fb95953f6 100644 --- a/modules/page/tpl/js/page_admin.js +++ b/modules/page/tpl/js/page_admin.js @@ -32,8 +32,9 @@ function completeInsertPageContent(ret_obj) { var page = ret_obj['page']; var module_srl = ret_obj['module_srl']; + var mid = ret_obj['mid']; - location.href = current_url.setQuery('act',''); + location.href = current_url.setQuery('mid',mid).setQuery('act',''); } /* 수정한 페이지 컨텐츠를 저장 */ diff --git a/modules/page/tpl/page_content_modify.html b/modules/page/tpl/page_content_modify.html index 733a2ce50..28a8faf63 100644 --- a/modules/page/tpl/page_content_modify.html +++ b/modules/page/tpl/page_content_modify.html @@ -1,13 +1,20 @@ + + + + +
{$page_content}
-
+ + + - +
+
- +
diff --git a/modules/widget/tpl/add_content_widget.html b/modules/widget/tpl/add_content_widget.html index 74e08c898..f6ed89969 100644 --- a/modules/widget/tpl/add_content_widget.html +++ b/modules/widget/tpl/add_content_widget.html @@ -1,9 +1,8 @@ -
-
+ diff --git a/modules/widget/tpl/js/widget.js b/modules/widget/tpl/js/widget.js index ecec79d36..529980953 100644 --- a/modules/widget/tpl/js/widget.js +++ b/modules/widget/tpl/js/widget.js @@ -49,7 +49,7 @@ function getPadding(obj, direct) { } -/* 위젯 배치 시작을 함 */ +/* 위젯 핸들링 시작 */ var zonePageObj = null; var zoneModuleSrl = 0; function doStartPageModify(zoneID, module_srl) { @@ -155,8 +155,7 @@ function getWidgetCode(childObj, widget) { var value = childObj.attributes[i].nodeValue; if(!value) continue; - if(value && typeof(value)=="string") value = value.replace(/\"/ig,'"'); - attrs += name+'="'+value+'" '; + attrs += name+'="'+escape(value)+'" '; } var style = childObj.getAttribute("style"); return ''; @@ -196,11 +195,28 @@ function doSyncPageContent() { } // 부모창에 위젯을 추가 -function completeAddContent(ret_obj) { - var tpl = ret_obj["tpl"]; +function completeAddContent(fo_obj) { + var editor_sequence = fo_obj.getAttribute('editor_sequence'); + var content = editorGetContent(editor_sequence); + + var tpl = ''+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + '
'+ + content+ + '
'+ + '
'+ + ''+ + '
'; + opener.doAddWidgetCode(tpl); window.close(); - return false; } /* 박스 위젯 추가 */ @@ -259,6 +275,7 @@ function doAddWidgetCode(widget_code) { var nodes = dummy.childNodes; var zoneObj = xGetElementById('zonePageContent'); + zoneObj.style.visibility = 'hidden'; if(selectedWidget && selectedWidget.getAttribute("widget")) { while ( nodes.length ) { @@ -273,7 +290,13 @@ function doAddWidgetCode(widget_code) { } } - doFitBorderSize(); + // 위젯 추가후 페이지 리로딩 + var tpl = getWidgetContent(); + + var fo_obj = xGetElementById('pageFo'); + fo_obj.content.value = tpl; + + fo_obj.submit(); } // 클릭 이벤트시 위젯의 수정/제거/이벤트 무효화 처리 diff --git a/modules/widget/tpl/js/widget_admin.js b/modules/widget/tpl/js/widget_admin.js index 63cd16205..aba022d46 100644 --- a/modules/widget/tpl/js/widget_admin.js +++ b/modules/widget/tpl/js/widget_admin.js @@ -102,7 +102,10 @@ function doFillWidgetVars() { case "text" : case "textarea" : var val = selected_node.getAttribute(name); - if(val) node.value = val; + if(!val) continue; + var unescaped_val = unescape(val); + if(!unescaped_val) node.value = val; + else node.value = unescaped_val; break; case "checkbox" : if(selected_node.getAttribute(name)) { diff --git a/modules/widget/widget.controller.php b/modules/widget/widget.controller.php index 62d6801ad..ade15ed22 100644 --- a/modules/widget/widget.controller.php +++ b/modules/widget/widget.controller.php @@ -130,34 +130,12 @@ $this->add('colorset_list', $colorsets); } - /** - * @brief 직접 내용 입력된 위젯의 처리 - **/ - function procWidgetAddContent() { - $content = Context::get('content'); - $args = Context::getRequestVars('style','widget_padding_left','widget_padding_right','widget_padding_bottom','widget_padding_top'); - - $tpl = $this->transEditorContent($content, $args); - - $this->add('tpl', $tpl); - } - /** * @breif 특정 content의 위젯 태그들을 변환하여 return **/ function transWidgetCode($content, $include_info = false) { - $this->include_info = $include_info; - // 내용중 widget이 아닌 것들을 일단 분리 - /* - $none_widget_code = preg_replace('!]*)widget=([^\>]*?)\>!is', '', $content); - $oPageAdminController = &getAdminController('page'); - if(trim($none_widget_code)) { - $args->style = "float:left;overflow:hidden;padding:none;padding:none"; - $args->widget_padding_left = $args->widget_padding_top = $args->widget_padding_right = $args->widget_padding_bottom = 0; - $none_widget_content = $oPageAdminController->transEditorContent($none_widget_code, $args); - } - */ + $this->include_info = $include_info; // 내용중 위젯을 또다시 구함 (기존 버전에서 페이지 수정해 놓은것과의 호환을 위해서) $content = preg_replace_callback('!]*)widget=([^\>]*?)\>!is', array($this,'transWidget'), $content); @@ -165,17 +143,6 @@ // 박스 위젯을 다시 구함 $content = preg_replace_callback('!]*)widget=([^\>]*?)\>
!is', array($this,'transWidgetBox'), $content); - // include_info, 즉 위젯의 수정일 경우 css와 js파일을 추가해 주고 위젯 수정용 레이어도 추가함 - if($this->include_info) { - Context::addJsFile("./modules/widget/tpl/js/widget.js"); - Context::addCSSFile("./modules/widget/tpl/css/widget.css"); - - $oTemplate = &TemplateHandler::getInstance(); - $tpl = $oTemplate->compile($this->module_path.'tpl', 'widget_layer'); - $content .= $tpl; - - } - return $content; } @@ -183,10 +150,7 @@ * @brief 위젯 코드를 실제 php코드로 변경 **/ function transWidget($matches) { - $oContext = &Context::getInstance(); $buff = trim($matches[0]); - $buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', array($oContext, _fixQuotation), $buff); - $buff = str_replace("&","&",$buff); $oXmlParser = new XmlParser(); $xml_doc = $oXmlParser->parse(trim($buff)); @@ -196,14 +160,6 @@ if(!$vars->widget) return ""; - // 캐시 체크 - $widget_sequence = $vars->widget_sequence; - $widget_cache = $vars->widget_cache; - if($widget_cache && $widget_sequence && !$this->include_info) { - $output = WidgetHandler::getCache($widget_sequence, $widget_cache); - if($output) return $output; - } - // 위젯의 이름을 구함 $widget = $vars->widget; unset($vars->widget); @@ -229,54 +185,5 @@ return WidgetHandler::execute($widget, $vars, $this->include_info); } - /** - * @brief 에디터에서 생성한 컨텐츠를 페이지 수정시 사용할 수 있도록 코드 생성 - **/ - function transEditorContent($content, $args = null) { - // 에디터의 내용을 변환하여 visual한 영역과 원본 소스를 가지고 있는 code로 분리 - $code = $content; - - $oContext = &Context::getInstance(); - $content = preg_replace_callback('!]*)editor_component=([^\>]*)>(.*?)\<\/div\>!is', array($oContext,'transEditorComponent'), $content); - $content = preg_replace_callback('!]*)editor_component=([^\>]*?)\>!is', array($oContext,'transEditorComponent'), $content); - - // 결과물에 있는 css Meta 목록을 구해와서 해당 css를 아예 읽어버림 - require_once("./classes/optimizer/Optimizer.class.php"); - $oOptimizer = new Optimizer(); - preg_match_all('!<\!\-\-Meta:([^\-]*?)\-\->!is', $content, $matches); - $css_header = null; - for($i=0;$ireplaceCssPath($css_file, $buff)."\n"; - } - - $tpl = sprintf( - ''. - '
'. - '
'. - '
'. - '
'. - '
'. - '
'. - '
'. - '
'. - '
'. - '%s'. - '
'. - '
'. - ''. - '
', - $css_header, - $args->style, - $args->widget_padding_left, $args->widget_padding_right, $args->widget_padding_top, $args->widget_padding_bottom, - $args->widget_padding_top, $args->widget_padding_right, $args->widget_padding_bottom, $args->widget_padding_left, - $content, - base64_encode($code) - ); - - return $tpl; - } - } ?>