blog module make categories cache file by php

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@3479 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
zero 2008-01-07 07:37:37 +00:00
parent 3fb36cfb3e
commit 8995cae0cc
8 changed files with 85 additions and 12 deletions

View file

@ -331,7 +331,7 @@
}
// XML 파일을 갱신하고 위치을 넘겨 받음
$xml_file = $oDocumentController->makeCategoryXmlFile($args->module_srl);
$xml_file = $oDocumentController->makeCategoryFile($args->module_srl);
$oDB->commit();
@ -403,7 +403,7 @@
}
// XML 파일을 갱신하고 위치을 넘겨 받음
$xml_file = $oDocumentController->makeCategoryXmlFile($args->module_srl);
$xml_file = $oDocumentController->makeCategoryFile($args->module_srl);
$oDB->commit();
@ -440,7 +440,7 @@
if(!$output->toBool()) return $output;
// xml파일 재생성
$xml_file = $oDocumentController->makeCategoryXmlFile($source_category->module_srl);
$xml_file = $oDocumentController->makeCategoryFile($source_category->module_srl);
// return 변수 설정
$this->add('xml_file', $xml_file);
@ -459,7 +459,7 @@
// xml파일 재생성
$oDocumentController = &getController('document');
$xml_file = $oDocumentController->makeCategoryXmlFile($module_srl);
$xml_file = $oDocumentController->makeCategoryFile($module_srl);
// return 값 설정
$this->add('xml_file',$xml_file);

View file

@ -82,7 +82,7 @@
// 블로그 모듈에서 사용되는 모든 메뉴 목록을 재 생성
foreach($list as $blog_item) {
$module_srl = $blog_item->module_srl;
$oDocumentController->makeCategoryXmlFile($module_srl);
$oDocumentController->makeCategoryFile($module_srl);
}
}

View file

@ -45,6 +45,7 @@
// 카테고리 xml 파일 위치 지정
$this->module_info->category_xml_file = getUrl().$oDocumentModel->getCategoryXmlFile($this->module_info->module_srl);
$this->module_info->category_php_file = $oDocumentModel->getCategoryPhpFile($this->module_info->module_srl);
// 메뉴 등록시 메뉴 정보를 구해옴
if($this->module_info->menu) {

View file

@ -537,7 +537,7 @@
$args->category_srl = $category_srl;
$args->document_count = $document_count;
$output = executeQuery('document.updateCategoryCount', $args);
if($output->toBool()) $this->makeCategoryXmlFile($module_srl);
if($output->toBool()) $this->makeCategoryFile($module_srl);
return $output;
}
@ -688,10 +688,10 @@
}
/**
* @brief 카테고리를 xml파일로 저장
* @brief 카테고리를 캐시 파일로 저장
**/
function makeCategoryXmlFile($module_srl) {
// xml파일 생성시 필요한 정보가 없으면 그냥 return
function makeCategoryFile($module_srl) {
// 캐시 파일 생성시 필요한 정보가 없으면 그냥 return
if(!$module_srl) return;
// 모듈 정보를 가져옴 (mid를 구하기 위해)
@ -703,6 +703,7 @@
// 캐시 파일의 이름을 지정
$xml_file = sprintf("./files/cache/document_category/%s.xml.php", $module_srl);
$php_file = sprintf("./files/cache/document_category/%s.php", $module_srl);
// DB에서 module_srl 에 해당하는 카테고리 목록을 listorder순으로 구해옴
$oDocumentModel = &getModel('document');
@ -712,6 +713,7 @@
if(!$list) {
$xml_buff = "<root />";
FileHandler::writeFile($xml_file, $xml_buff);
FileHandler::writeFile($php_file, '<?php if(!defined("__ZBXE__")) exit(); ?>');
return $xml_file;
}
@ -739,8 +741,13 @@
// xml 캐시 파일 생성
$xml_buff = sprintf('<?php %s header("Content-Type: text/xml; charset=UTF-8"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); @session_start(); ?><root>%s</root>', $php_script, $this->getXmlTree($tree[0], $tree));
// php 캐시 파일 생성
$php_output = $this->getPhpCacheCode($tree[0], $tree);
$php_buff = sprintf('<?php if(!defined("__ZBXE__")) exit(); %s; $menu->list = array(%s); ?>', $php_output['category_title_str'], $php_output['buff']);
// 파일 저장
FileHandler::writeFile($xml_file, $xml_buff);
FileHandler::writeFile($php_file, $php_buff);
return $xml_file;
}
@ -782,5 +789,57 @@
}
return $buff;
}
/**
* @brief array로 정렬된 노드들을 php code로 변경하여 return
* 메뉴에서 메뉴를 tpl에 사용시 xml데이터를 사용할 수도 있지만 별도의 javascript 사용이 필요하기에
* php로 캐시파일을 만들어서 db이용없이 바로 메뉴 정보를 구할 있도록 한다
* 캐시는 ModuleHandler::displayContent() 에서 include하여 Context::set() 한다
**/
function getPhpCacheCode($source_node, $tree) {
$output = array("buff"=>"", "category_srl_list"=>array());
if(!$source_node) return $output;
foreach($source_node as $category_srl => $node) {
// 자식 노드가 있으면 자식 노드의 데이터를 먼저 얻어옴
if($category_srl&&$tree[$category_srl]) $child_output = $this->getPhpCacheCode($tree[$category_srl], $tree);
else $child_output = array("buff"=>"", "category_srl_list"=>array());
// 변수 정리
$category_title_str = sprintf('$_category_title[%d] = "%s"; %s', $node->category_srl, $node->title, $child_output['category_title_str']);
// 현재 노드의 url값이 공란이 아니라면 category_srl_list 배열값에 입력
$child_output['category_srl_list'][] = $node->category_srl;
$output['category_srl_list'] = array_merge($output['category_srl_list'], $child_output['category_srl_list']);
// node->group_srls값이 있으면
if($node->group_srls) $group_check_code = sprintf('($_SESSION["is_admin"]==true||(is_array($_SESSION["group_srls"])&&count(array_intersect($_SESSION["group_srls"], array(%s)))))',$node->group_srls);
else $group_check_code = "true";
// 변수 정리
$selected = '"'.implode('","',$child_output['category_srl_list']).'"';
$child_buff = $child_output['buff'];
$expand = $node->expand;
// 속성을 생성한다 ( category_srl_list를 이용해서 선택된 메뉴의 노드에 속하는지를 검사한다. 꽁수지만 빠르고 강력하다고 생각;;)
$attribute = sprintf(
'"node_srl"=>"%s","category_srl"=>"%s","parent_srl"=>"%s","text"=>%s?$_category_title[%d]:"","selected"=>(in_array(Context::get("category"),array(%s))?1:0),"expand"=>"%s", "list"=>array(%s)',
$node->category_srl,
$node->category_srl,
$node->parent_srl,
$group_check_code,
$node->category_srl,
$selected,
$expand,
$child_buff
);
// buff 데이터를 생성한다
$output['buff'] .= sprintf('%s=>array(%s),', $node->category_srl, $attribute);
$output['category_title_str'] .= $category_title_str;
}
return $output;
}
}
?>

View file

@ -461,11 +461,23 @@
$xml_file = sprintf('files/cache/document_category/%s.xml.php',$module_srl);
if(!file_exists($xml_file)) {
$oDocumentController = &getController('document');
$oDocumentController->makeCategoryXmlFile($module_srl);
$oDocumentController->makeCategoryFile($module_srl);
}
return $xml_file;
}
/**
* @brief 문서 category정보의 php 캐시 파일을 return
**/
function getCategoryPhpFile($module_srl) {
$php_file = sprintf('files/cache/document_category/%s.php',$module_srl);
if(!file_exists($php_file)) {
$oDocumentController = &getController('document');
$oDocumentController->makeCategoryFile($module_srl);
}
return $php_file;
}
/**
* @brief 월별 보관현황을 가져옴
**/

View file

@ -1061,7 +1061,7 @@
$this->insertTTCategory($xml_doc, 0, $module_srl, $category_titles);
// 입력완료 후 카테고리 xml파일 재생성
$this->oDocumentController->makeCategoryXmlFile($module_srl);
$this->oDocumentController->makeCategoryFile($module_srl);
$xml_doc = null;
}

View file

@ -272,6 +272,7 @@
if(!$list) {
$xml_buff = "<root />";
FileHandler::writeFile($xml_file, $xml_buff);
FileHandler::writeFile($php_file, '<?php if(!defined("__ZBXE__")) exit(); ?>');
return $xml_file;
}

View file

@ -15,7 +15,7 @@
{@ $_row = 0;}
<!--@foreach($lang_supported as $key => $val)-->
<tr>
<!--@if($_row==0)--><th scope="row" scope="row" rowspan="{count($lang_supported)}">{$lang->menu_name}</th><!--@end-->
<!--@if($_row==0)--><th scope="row" rowspan="{count($lang_supported)}">{$lang->menu_name}</th><!--@end-->
<th>{$val}</th>
<td><input type="text" name="menu_name_{$key}" value="{htmlspecialchars($item_info->name[$key])}" class="inputTypeText"/></td>
{@ $_row ++ }