From 0dbaa1e40b598f859d3c558f32b38b8aad305d75 Mon Sep 17 00:00:00 2001 From: zero Date: Thu, 15 Feb 2007 07:07:34 +0000 Subject: [PATCH] git-svn-id: http://xe-core.googlecode.com/svn/trunk@53 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- classes/module/ModuleHandler.class.php | 103 +---- modules/module/module.controller.php | 566 ++++++------------------- modules/module/module.model.php | 302 ++++++++++++- modules/module/module.view.php | 26 +- 4 files changed, 474 insertions(+), 523 deletions(-) diff --git a/classes/module/ModuleHandler.class.php b/classes/module/ModuleHandler.class.php index f3f8ebfb6..02e1e38ac 100644 --- a/classes/module/ModuleHandler.class.php +++ b/classes/module/ModuleHandler.class.php @@ -23,26 +23,28 @@ * 단 유연한 처리를 위해 $document_srl 을 이용하기도 한다. **/ function ModuleHandler() { + // Request Argument중 모듈을 찾을 수 있는 변수를 구함 $module = Context::get('module'); $act = Context::get('act'); + $mid = Context::get('mid'); + $document_srl = Context::get('document_srl'); - // 설치가 안되어 있다면 설치를 위한 준비를 한다 + // ModuleModel 객체 생성 + $oModuleModel = getModule('module','model'); + + // 설치가 안되어 있다면 install module을 지정 if(!Context::isInstalled()) { - // install 모듈로 강제 지정 $module = 'install'; $mid = NULL; - // Request Argument의 mid값으로 모듈 객체 생성 // mid가 없이 document_srl만 있다면 document_srl로 mid를 찾음 } elseif(!$module) { - $mid = Context::get('mid'); - $document_srl = Context::get('document_srl'); // document_srl만 있다면 mid를 구해옴 - if(!$mid && $document_srl) $module_info = $this->getModuleInfoByDocumentSrl($document_srl); + if(!$mid && $document_srl) $module_info = $oModuleModel->getModuleInfoByDocumentSrl($document_srl); // mid 값에 대한 모듈 정보를 추출 - if(!$module_info) $module_info = $this->getModuleInfoByMid($mid); + if(!$module_info) $module_info = $oModuleModel->getModuleInfoByMid($mid); // 모듈 정보에서 module 이름을 구해움 $module = $module_info->module; @@ -55,7 +57,7 @@ } // 해당 모듈의 conf/action.xml 을 분석하여 action 정보를 얻어옴 - $action_info = $this->getActionInfo($module); + $action_info = $oModuleModel->getActionInfo($module); // 현재 요청된 act가 있으면 $action_info에서 type을 찾음, 없다면 기본 action을 이용 if(!$act || !$action_info->{$act}) $act = $action_info->default_action; @@ -68,7 +70,7 @@ Context::set('act', $act, true); // 모듈 객체 생성 - $oModule = &$this->getModuleInstance($module, $type, $module_info); + $oModule = $this->getModuleInstance($module, $type, $module_info); if(!is_object($oModule)) return; @@ -77,50 +79,6 @@ $this->oModule = $oModule; } - /** - * @brief constructor에서 생성한 oModule를 return - **/ - function getModule() { - return $this->oModule; - } - - /** - * @brief document_srl로 모듈의 정보르 구함 - **/ - function getModuleInfoByDocumentSrl($document_srl) { - // DB 객체 생성후 데이터를 DB에서 가져옴 - $oDB = &DB::getInstance(); - $args->document_srl = $document_srl; - $output = $oDB->executeQuery('module_manager.getModuleInfoByDocument', $args); - - // extra_vars의 정리 - $module_info = module_manager::extractExtraVar($output->data); - return $module_info; - } - - /** - * @brief mid로 모듈의 정보를 구함 - **/ - function getModuleInfo($mid='') { - // DB 객체 생성후 데이터를 DB에서 가져옴 - $oDB = &DB::getInstance(); - - // $mid값이 인자로 주어질 경우 $mid로 모듈의 정보를 구함 - if($mid) { - $args->mid = $mid; - $output = $oDB->executeQuery('module_manager.getMidInfo', $args); - } - - // 모듈의 정보가 없다면($mid가 잘못이거나 없었을 경우) 기본 모듈을 가져옴 - if(!$output->data) { - $output = $oDB->executeQuery('module_manager.getDefaultMidInfo'); - } - - // extra_vars의 정리 - $module_info = module_manager::extractExtraVar($output->data); - return $module_info; - } - /** * @brief module의 위치를 찾아서 return **/ @@ -134,36 +92,6 @@ return ""; } - /** - * @brief module의 conf/action.xml 을 통해 act값에 해당하는 action type을 return - **/ - function getActionInfo($module) { - $class_path = $this->getModulePath($module); - if(!$class_path) return; - - $action_xml_file = sprintf("%sconf/action.xml", $class_path); - if(!file_exists($action_xml_file)) return; - - $xml_obj = XmlParser::loadXmlFile($action_xml_file); - if(!count($xml_obj->module)) return; - - $output->default_action = $xml_obj->module->attrs->default_action; - $output->manage_action = $xml_obj->module->attrs->manage_action; - - if(is_array($xml_obj->module->action)) $action_list = $xml_obj->module->action; - else $action_list[] = $xml_obj->module->action; - - foreach($action_list as $action) { - $name = $action->attrs->name; - $type = $action->attrs->type; - $grant = $action->attrs->grant; - $output->{$name}->type = $type; - $output->{$name}->grant = $grant; - } - - return $output; - } - /** * @brief 모듈 객체를 생성함 **/ @@ -175,7 +103,7 @@ if(!$GLOBALS['_loaded_module'][$module][$type]) { /** - * 모듈의 위치를 파악 + * 모듈의 위치를 파악 * 기본적으로는 ./modules/* 에 있지만 웹업데이트나 웹설치시 ./files/modules/* 에 있음 * ./files/modules/* 의 클래스 파일을 우선으로 처리해야 함 **/ @@ -222,5 +150,12 @@ // 객체 리턴 return $GLOBALS['_loaded_module'][$module][$type]; } + + /** + * @brief constructor에서 생성한 oModule를 return + **/ + function getModule() { + return $this->oModule; + } } ?> diff --git a/modules/module/module.controller.php b/modules/module/module.controller.php index 502a4b850..d83fd9675 100644 --- a/modules/module/module.controller.php +++ b/modules/module/module.controller.php @@ -1,452 +1,146 @@ 공통 - * dispInit() => disp시에 - * procInit() => proc시에 - * - * $this->module_path는 현재 이 모듈파일의 위치를 나타낸다 - * (ex: $this->module_path = "./modules/module/"; + * @class moduleModel + * @author zero (zero@nzeo.com) + * @brief module 모듈의 Controller class **/ - // 초기화 - function init() {/*{{{*/ - Context::loadLang($this->module_path.'lang'); - }/*}}}*/ + class moduleController extends Module { - // disp 초기화 - function dispInit() {/*{{{*/ - return true; - }/*}}}*/ - - // proc 초기화 - function procInit() {/*{{{*/ - return true; - }/*}}}*/ - - /** - * 여기서부터는 action의 구현 - * request parameter의 경우 각 method의 첫번째 인자로 넘어온다 - * - * dispXXXX : 출력을 위한 method, output에 tpl file이 지정되어야 한다 - * procXXXX : 처리를 위한 method, output에는 error, message가 지정되어야 한다 - * - * 변수의 사용은 Context::get('이름')으로 얻어오면 된다 - **/ - - /** - * 여기서부터는 관련 lib... - **/ - // public string getModuleInfoByDocument($document_srl)/*{{{*/ - // $document_srl로 모듈정보를 구함 - function getModuleInfoByDocument($document_srl) { - $oDB = &DB::getInstance(); - $args->document_srl = $document_srl; - $output = $oDB->executeQuery('module_manager.getModuleInfoByDocument', $args); - // extra_vars의 정리 - $module_info = module_manager::extractExtraVar($output->data); - return $module_info; - }/*}}}*/ - - // public object getModuleInfo($mid='')/*{{{*/ - // $mid의 정보를 load, mid값이 없다면 기본 mid 정보를 읽음 - function getModuleInfo($mid='') { - // DB에서 가져옴 - $oDB = &DB::getInstance(); - if($mid) { - $args->mid = $mid; - $output = $oDB->executeQuery('module_manager.getMidInfo', $args); - } - if(!$output->data) $output = $oDB->executeQuery('module_manager.getDefaultMidInfo'); - return module_manager::arrangeModuleInfo($output->data); - }/*}}}*/ - - // public object getModuleInfoByModuleSrl($module_srl='')/*{{{*/ - // $modulr_srl로 모듈의 정보를 읽음 - function getModuleInfoByModuleSrl($module_srl='') { - $oDB = &DB::getInstance(); - $args->module_srl = $module_srl; - $output = $oDB->executeQuery('module_manager.getMidInfo', $args); - if(!$output->data) return; - return module_manager::arrangeModuleInfo($output->data); - }/*}}}*/ - - // public object arrangeModuleInfo($source_module_info)/*{{{*/ - // grant, extraVar등의 정리 - function arrangeModuleInfo($source_module_info) { - if(!$source_module_info) return; - - // serialize되어 있는 변수들 추출 - $extra_vars = $source_module_info->extra_vars; - $grant = $source_module_info->grant; - //$admin_id = $source_module_info->admin_id; - - unset($source_module_info->extra_vars); - unset($source_module_info->grant); - //unset($source_module_info->admin_id); - - $module_info = clone($source_module_info); - - // extra_vars의 정리 - if($extra_vars) { - $extra_vars = unserialize($extra_vars); - foreach($extra_vars as $key => $val) if(!$module_info->{$key}) $module_info->{$key} = $val; - } - - // 권한의 정리 - if($grant) $module_info->grant = unserialize($grant); - - // 관리자 아이디의 정리 - if($module_info->admin_id) { - $module_info->admin_id = explode(',',$module_info->admin_id); - } - - return $module_info; - }/*}}}*/ - - // public object getModuleObject($module)/*{{{*/ - // module을 찾아서 instance를 생성하여 return - function getModuleObject($module) { - // 요청받은 모듈이 있는지 확인 - $module = strtolower($module); - - // global 변수에 저장한 객체가 있으면 그걸 return - if($GLOBALS['_loaded_module'][$module]) return $GLOBALS['_loaded_module'][$module]; - - $class_path = sprintf('./modules/%s/', $module); - if(!is_dir($class_path)) $class_path = sprintf('./classs/modules/%s/', $module); - if(!is_dir($class_path)) return NULL; - - $class_file = $class_path.$module.'.module.php'; - if(!file_exists($class_file)) return NULL; - - // 새로 객체 생성 - require_once($class_file); - $eval_str = sprintf('$oModule = new %s();', $module); - eval($eval_str); - $oModule->setModulePath($class_path); - - // 언어파일 읽기 - Context::loadLang($class_path.'lang'); - - $GLOBALS['_loaded_module'][$module] = $oModule; - - // 객체 리턴 - return $oModule; - }/*}}}*/ - - // public object getAdminModuleObject($module)/*{{{*/ - // module의 관리자를 찾아서 instance를 생성하여 return - function getAdminModuleObject($module) { - // 요청받은 모듈이 있는지 확인 - $module = strtolower($module); - - // global 변수에 저장한 객체가 있으면 그걸 return - if($GLOBALS['_loaded_admin_module'][$module]) return $GLOBALS['_loaded_admin_module'][$module]; - - $class_path = sprintf('./modules/%s/', $module); - if(!is_dir($class_path)) $class_path = sprintf('./classs/modules/%s/', $module); - if(!is_dir($class_path)) return NULL; - - $class_file = $class_path.$module.'.admin.php'; - if(!file_exists($class_file)) return NULL; - - // 새로 객체 생성 - require_once($class_file); - $eval_str = sprintf('$oModule = new %s_admin();', $module); - eval($eval_str); - $oModule->setModulePath($class_path); - $oModule->init(); - - $template_path = sprintf("%sadmin/", $class_path); - $oModule->setTemplatePath($template_path); - - // 언어파일 읽기 - Context::loadLang($class_path.'lang'); - - // global 변수에 객체 저장 - $GLOBALS['_loaded_admin_module'][$module] = $oModule; - - return $oModule; - }/*}}}*/ - - // public object makeDefaultModule() /*{{{*/ - // 설치시 기본 모듈을 생성 - function makeDefaultModule() { - $oDB = &DB::getInstance(); - - // 설치된 기본 모듈이 있는지 확인 - $output = $oDB->executeQuery('module_manager.getDefaultMidInfo'); - if($output->data) return; - - // 기본 모듈 입력 - $args->mid = 'board'; - $args->browser_title = '테스트 모듈'; - $args->is_default = 'Y'; - $args->module = 'board'; - $args->skin = 'default'; - - $extra_vars->colorset = 'normal'; - $args->extra_vars = serialize($extra_vars); - - return $this->insertModule($args); - }/*}}}*/ - - // public object insertModule($args)/*{{{*/ - // 모듈 입력 - function insertModule($args) { - // 등록하려는 모듈의 path를 구함 - $oModule = getModule($args->module); - - // 선택된 스킨정보에서 colorset을 구함 - $skin_info = $this->loadSkinInfo($oModule->module_path, $args->skin); - $extra_vars->colorset = $skin_info->colorset[0]->name; - - // db에 입력 - $oDB = &DB::getInstance(); - $args->module_srl = $oDB->getNextSequence(); - $args->extra_vars = serialize($extra_vars); - $output = $oDB->executeQuery('module_manager.insertModule', $args); - $output->add('module_srl',$args->module_srl); - return $output; - }/*}}}*/ - - // public object updateModule($args)/*{{{*/ - // 모듈 입력 - function updateModule($args) { - $oDB = &DB::getInstance(); - $output = $oDB->executeQuery('module_manager.updateModule', $args); - $output->add('module_srl',$args->module_srl); - return $output; - }/*}}}*/ - - // public object updateModuleExtraVars($args)/*{{{*/ - // 모듈 입력 - function updateModuleExtraVars($module_srl, $extra_vars) { - $oDB = &DB::getInstance(); - $args->module_srl = $module_srl; - $args->extra_vars = $extra_vars; - $output = $oDB->executeQuery('module_manager.updateModuleExtraVars', $args); - return $output; - }/*}}}*/ - - // public object updateModuleGrant($module_srl, $grant)/*{{{*/ - // 모듈 입력 - function updateModuleGrant($module_srl, $grant) { - $oDB = &DB::getInstance(); - $args->module_srl = $module_srl; - $args->grant = $grant; - $output = $oDB->executeQuery('module_manager.updateModuleGrant', $args); - return $output; - }/*}}}*/ - - // public object deleteModule($module_srl)/*{{{*/ - // 모듈 입력 - function deleteModule($module_srl) { - $oDB = &DB::getInstance(); - $oDocument = getModule('document'); - - // addon 삭제 - // plugin 삭제 - - // document 삭제 - $output = $oDocument->deleteModuleDocument($module_srl); - if(!$output->toBool()) return $output; - - // category 삭제 - $output = $oDocument->deleteModuleCategory($module_srl); - if(!$output->toBool()) return $output; - - // trackbacks 삭제 - $oTrackback = getModule('trackback'); - $output = $oTrackback->deleteModuleTrackbacks($module_srl); - if(!$output->toBool()) return $output; - - // comments 삭제 - $oComment = getModule('comment'); - $output = $oComment->deleteModuleComments($module_srl); - if(!$output->toBool()) return $output; - - // tags 삭제 - $oTag = getModule('tag'); - $output = $oTag->deleteModuleTags($module_srl); - if(!$output->toBool()) return $output; - - // files 삭제 - $output = $oDocument->deleteModuleFiles($module_srl); - if(!$output->toBool()) return $output; - - // module 정보 삭제 - $args->module_srl = $module_srl; - $output = $oDB->executeQuery('module_manager.deleteModule', $args); - - return $output; - }/*}}}*/ - - // public object clearDefaultModule() /*{{{*/ - // 모든 모듈의 is_default='N'로 세팅 - function clearDefaultModule() { - $oDB = &DB::getInstance(); - return $oDB->executeQuery('module_manager.clearDefaultModule'); - }/*}}}*/ - - // public object getAdminModuleList() /*{{{*/ - // 관리자 모듈 목록을 가져옴 - function getAdminModuleList() { - // 다운받은 모듈과 설치된 모듈의 목록을 구함 - $downloaded_list = FileHandler::readDir('./files/modules'); - $installed_list = FileHandler::readDir('./modules'); - - // 찾아진 모듈목록에서 admin은 제외시킴 - $searched_list = array_merge($downloaded_list, $installed_list); - if(!count($searched_list)) return; - - for($i=0;$ititle; - } - if($list) asort($list); - return $list; - }/*}}}*/ + /** + * @brief 기본 모듈 생성 + **/ + function makeDefaultModule() { + $oDB = &DB::getInstance(); - function loadModuleXml($module_path) {/*{{{*/ - // 현재 선택된 모듈의 스킨의 정보 xml 파일을 읽음 - $xml_file = sprintf("%s/module.xml", $module_path); - if(!file_exists($xml_file)) return; - $oXmlParser = new XmlParser(); - $xml_obj = $oXmlParser->loadXmlFile($xml_file); + // 설치된 기본 모듈이 있는지 확인 + $output = $oDB->executeQuery('module_manager.getDefaultMidInfo'); + if($output->data) return; - // 스킨 정보를 이용 변수 정리 - if(!$xml_obj) return; + // 기본 모듈 입력 + $args->mid = 'board'; + $args->browser_title = '테스트 모듈'; + $args->is_default = 'Y'; + $args->module = 'board'; + $args->skin = 'default'; - // 스킨이름 - $info->title = $xml_obj->title->body; + $extra_vars->colorset = 'normal'; + $args->extra_vars = serialize($extra_vars); - // 작성자 정보 - $module_info->title = $xml_obj->title->body; - $module_info->version = $xml_obj->attrs->version; - $module_info->author->name = $xml_obj->author->name->body; - $module_info->author->email_address = $xml_obj->author->attrs->email_address; - $module_info->author->homepage = $xml_obj->author->attrs->link; - $module_info->author->date = $xml_obj->author->attrs->date; - $module_info->author->description = $xml_obj->author->description->body; - - // history - if(!is_array($xml_obj->history->author)) $history[] = $xml_obj->history->author; - else $history = $xml_obj->history->author; - foreach($history as $item) { - unset($obj); - $obj->name = $item->name->body; - $obj->email_address = $item->attrs->email_address; - $obj->homepage = $item->attrs->link; - $obj->date = $item->attrs->date; - $obj->description = $item->description->body; - $module_info->history[] = $obj; - } - - return $module_info; - }/*}}}*/ - - function getSkins($module_path) {/*{{{*/ - $skins_path = sprintf("%s/skins/", $module_path); - $list = FileHandler::readDir($skins_path); - return $list; - }/*}}}*/ - - function loadSkinInfo($module_path, $skin) {/*{{{*/ - // 현재 선택된 모듈의 스킨의 정보 xml 파일을 읽음 - $skin_xml_file = sprintf("%sskins/%s/skin.xml", $module_path, $skin); - if(!file_exists($skin_xml_file)) return; - $oXmlParser = new XmlParser(); - $xml_obj = $oXmlParser->loadXmlFile($skin_xml_file); - - // 스킨 정보를 이용 변수 정리 - if(!$xml_obj) return; - - // 스킨이름 - $skin_info->title = $xml_obj->title->body; - - // 작성자 정보 - $skin_info->maker->name = $xml_obj->maker->name->body; - $skin_info->maker->email_address = $xml_obj->maker->attrs->email_address; - $skin_info->maker->homepage = $xml_obj->maker->attrs->link; - $skin_info->maker->date = $xml_obj->maker->attrs->date; - $skin_info->maker->description = $xml_obj->maker->description->body; - - // colorset - if(!is_array($xml_obj->colorset->color)) $colorset[] = $xml_obj->colorset->color; - else $colorset = $xml_obj->colorset->color; - foreach($colorset as $color) { - $name = $color->attrs->name; - $title = $color->title->body; - $screenshot = $color->attrs->src; - if($screenshot && file_exists($screenshot)) $screenshot = sprintf("%sskins/%s/%s",$module_path,$skin,$screenshot); - else $screenshot = ""; - - unset($obj); - $obj->name = $name; - $obj->title = $title; - $obj->screenshot = $screenshot; - $skin_info->colorset[] = $obj; - } - - // 스킨에서 사용되는 변수들 - if(!is_array($xml_obj->extra_vars->var)) $extra_vars[] = $xml_obj->extra_vars->var; - else $extra_vars = $xml_obj->extra_vars->var; - foreach($extra_vars as $var) { - $name = $var->attrs->name; - $type = $var->attrs->type; - $title = $var->title->body; - $description = $var->description->body; - if($var->default) { - unset($default); - if(is_array($var->default)) { - for($i=0;$idefault);$i++) $default[] = $var->default[$i]->body; - } else { - $default = $var->default->body; - } + return $this->insertModule($args); } - $width = $var->attrs->width; - $height = $var->attrs->height; - unset($obj); - $obj->title = $title; - $obj->description = $description; - $obj->name = $name; - $obj->type = $type; - $obj->default = $default; - $obj->width = $width; - $obj->height = $height; + /** + * @brief 모듈 입력 + **/ + function insertModule($args) { + // module model 객체 생성 + $oModuleModel = getModule('module','model'); - $skin_info->extra_vars[] = $obj; - } + // 선택된 스킨정보에서 colorset을 구함 + $skin_info = $oModuleModel->loadSkinInfo($args->module, $args->skin); + $extra_vars->colorset = $skin_info->colorset[0]->name; - return $skin_info; - }/*}}}*/ - } + // db에 입력 + $oDB = &DB::getInstance(); + $args->module_srl = $oDB->getNextSequence(); + $args->extra_vars = serialize($extra_vars); + $output = $oDB->executeQuery('module_manager.insertModule', $args); + $output->add('module_srl',$args->module_srl); + return $output; + } + + /** + * @brief 모듈의 정보를 수정 + **/ + function updateModule($args) { + $oDB = &DB::getInstance(); + $output = $oDB->executeQuery('module_manager.updateModule', $args); + $output->add('module_srl',$args->module_srl); + return $output; + } + + /** + * @brief 모듈의 기타 정보를 변경 + **/ + function updateModuleExtraVars($module_srl, $extra_vars) { + $oDB = &DB::getInstance(); + $args->module_srl = $module_srl; + $args->extra_vars = $extra_vars; + $output = $oDB->executeQuery('module_manager.updateModuleExtraVars', $args); + return $output; + } + + /** + * @brief 모듈의 권한 정보 변경 + **/ + function updateModuleGrant($module_srl, $grant) { + $oDB = &DB::getInstance(); + $args->module_srl = $module_srl; + $args->grant = $grant; + $output = $oDB->executeQuery('module_manager.updateModuleGrant', $args); + return $output; + } + + /** + * @brief 모듈을 삭제 + * + * 모듈 삭제시는 관련 정보들을 모두 삭제 시도한다. + **/ + function deleteModule($module_srl) { + $oDB = &DB::getInstance(); + + // addon 삭제 + // plugin 삭제 + + // document 삭제 + $oDocumentController = getModule('document', 'controller'); + $output = $oDocumentController->deleteModuleDocument($module_srl); + if(!$output->toBool()) return $output; + + // category 삭제 + $output = $oDocumentController->deleteModuleCategory($module_srl); + if(!$output->toBool()) return $output; + + // trackbacks 삭제 + $oTrackbackController = getModule('trackback','controller'); + $output = $oTrackbackController->deleteModuleTrackbacks($module_srl); + if(!$output->toBool()) return $output; + + // comments 삭제 + $oCommentController = getModule('comment','controller'); + $output = $oCommentController->deleteModuleComments($module_srl); + if(!$output->toBool()) return $output; + + // tags 삭제 + $oTagController = getModule('tag','controller'); + $output = $oTagController->deleteModuleTags($module_srl); + if(!$output->toBool()) return $output; + + // files 삭제 + $output = $oDocumentController->deleteModuleFiles($module_srl); + if(!$output->toBool()) return $output; + + // module 정보 삭제 + $args->module_srl = $module_srl; + $output = $oDB->executeQuery('module_manager.deleteModule', $args); + + return $output; + } + + /** + * @brief 모든 모듈의 is_default값을 N 으로 세팅 (기본 모듈 해제) + **/ + function clearDefaultModule() { + $oDB = &DB::getInstance(); + return $oDB->executeQuery('module_manager.clearDefaultModule'); + } + + } ?> diff --git a/modules/module/module.model.php b/modules/module/module.model.php index b86c0aae2..2335452c2 100644 --- a/modules/module/module.model.php +++ b/modules/module/module.model.php @@ -2,5 +2,305 @@ /** * @class moduleModel * @author zero (zero@nzeo.com) - * @brief 모듈 모델 + * @brief module 모듈의 Model class **/ + + class moduleModel extends Module { + + /** + * @brief 초기화 + **/ + function init() { + } + + /** + * @brief module의 conf/action.xml 을 통해 act값에 해당하는 action type을 return + **/ + function getActionInfo($module) { + $class_path = ModuleHandler::getModulePath($module); + if(!$class_path) return; + + $action_xml_file = sprintf("%sconf/action.xml", $class_path); + if(!file_exists($action_xml_file)) return; + + $xml_obj = XmlParser::loadXmlFile($action_xml_file); + if(!count($xml_obj->module)) return; + + $output->default_action = $xml_obj->module->attrs->default_action; + $output->manage_action = $xml_obj->module->attrs->manage_action; + + if(is_array($xml_obj->module->action)) $action_list = $xml_obj->module->action; + else $action_list[] = $xml_obj->module->action; + + foreach($action_list as $action) { + $name = $action->attrs->name; + $type = $action->attrs->type; + $grant = $action->attrs->grant; + $output->{$name}->type = $type; + $output->{$name}->grant = $grant; + } + + return $output; + } + + + /** + * @brief 모듈의 종류와 정보를 구함 + **/ + function getModuleList() { + // DB 객체 생성 + $oDB = &DB::getInstance(); + + // 다운받은 모듈과 설치된 모듈의 목록을 구함 + $downloaded_list = FileHandler::readDir('./files/modules'); + $installed_list = FileHandler::readDir('./modules'); + $searched_list = array_merge($downloaded_list, $installed_list); + if(!count($searched_list)) return; + + for($i=0;$iisTableExists($table_name)) $created_table_count ++; + } + + // 해당 모듈의 정보를 구함 + $info = $this->loadModuleXml($path); + unset($obj); + + $info->module = $module_name; + $info->created_table_count = $created_table_count; + $info->table_count = $table_count; + $info->path = $path; + + $list[] = $info; + } + return $list; + } + + /** + * @brief document_srl로 모듈의 정보르 구함 + **/ + function getModuleInfoByDocumentSrl($document_srl) { + // DB 객체 생성후 데이터를 DB에서 가져옴 + $oDB = &DB::getInstance(); + $args->document_srl = $document_srl; + $output = $oDB->executeQuery('module.getModuleInfoByDocument', $args); + + return $this->arrangeModuleInfo($output->data); + } + + /** + * @brief mid로 모듈의 정보를 구함 + **/ + function getModuleInfo($mid='') { + // DB 객체 생성후 데이터를 DB에서 가져옴 + $oDB = &DB::getInstance(); + + // $mid값이 인자로 주어질 경우 $mid로 모듈의 정보를 구함 + if($mid) { + $args->mid = $mid; + $output = $oDB->executeQuery('module.getMidInfo', $args); + } + + // 모듈의 정보가 없다면($mid가 잘못이거나 없었을 경우) 기본 모듈을 가져옴 + if(!$output->data) { + $output = $oDB->executeQuery('module.getDefaultMidInfo'); + } + + return $this->arrangeModuleInfo($output->data); + } + + /** + * @brief module_srl에 해당하는 모듈의 정보를 구함 + **/ + function getModuleInfoByModuleSrl($module_srl='') { + // db에서 데이터를 가져옴 + $oDB = &DB::getInstance(); + $args->module_srl = $module_srl; + $output = $oDB->executeQuery('module_manager.getMidInfo', $args); + if(!$output->data) return; + + return $this->arrangeModuleInfo($output->data); + } + + /** + * @brief DB에서 가져온 원 모듈 정보에서 grant, extraVar등의 정리 + **/ + function arrangeModuleInfo($source_module_info) { + if(!$source_module_info) return; + + // serialize되어 있는 변수들 추출 + $extra_vars = $source_module_info->extra_vars; + $grant = $source_module_info->grant; + $admin_id = $source_module_info->admin_id; + + unset($source_module_info->extra_vars); + unset($source_module_info->grant); + unset($source_module_info->admin_id); + + $module_info = clone($source_module_info); + + // extra_vars의 정리 + if($extra_vars) { + $extra_vars = unserialize($extra_vars); + foreach($extra_vars as $key => $val) if(!$module_info->{$key}) $module_info->{$key} = $val; + } + + // 권한의 정리 + if($grant) $module_info->grant = unserialize($grant); + + // 관리자 아이디의 정리 + if($module_info->admin_id) { + $module_info->admin_id = explode(',',$module_info->admin_id); + } + + return $module_info; + } + + /** + * @brief 특정 모듈의 스킨의 정보를 구해옴 + **/ + function loadSkinInfo($module, $skin) { + + // 등록하려는 모듈의 path를 구함 + $module_path = ModuleHandler::getModulePath($args->module); + + // 모듈의 스킨의 정보 xml 파일을 읽음 + $skin_xml_file = sprintf("%sskins/%s/skin.xml", $module_path, $skin); + if(!file_exists($skin_xml_file)) return; + + // XmlParser 객체 생성 + $oXmlParser = new XmlParser(); + $xml_obj = $oXmlParser->loadXmlFile($skin_xml_file); + + // 스킨 정보가 없으면 return + if(!$xml_obj) return; + + // 스킨이름 + $skin_info->title = $xml_obj->title->body; + + // 작성자 정보 + $skin_info->maker->name = $xml_obj->maker->name->body; + $skin_info->maker->email_address = $xml_obj->maker->attrs->email_address; + $skin_info->maker->homepage = $xml_obj->maker->attrs->link; + $skin_info->maker->date = $xml_obj->maker->attrs->date; + $skin_info->maker->description = $xml_obj->maker->description->body; + + // colorset + if(!is_array($xml_obj->colorset->color)) $colorset[] = $xml_obj->colorset->color; + else $colorset = $xml_obj->colorset->color; + + foreach($colorset as $color) { + $name = $color->attrs->name; + $title = $color->title->body; + $screenshot = $color->attrs->src; + if($screenshot && file_exists($screenshot)) $screenshot = sprintf("%sskins/%s/%s",$module_path,$skin,$screenshot); + else $screenshot = ""; + + unset($obj); + $obj->name = $name; + $obj->title = $title; + $obj->screenshot = $screenshot; + $skin_info->colorset[] = $obj; + } + + // 스킨에서 사용되는 변수들 + if(!is_array($xml_obj->extra_vars->var)) $extra_vars[] = $xml_obj->extra_vars->var; + else $extra_vars = $xml_obj->extra_vars->var; + + foreach($extra_vars as $var) { + $name = $var->attrs->name; + $type = $var->attrs->type; + $title = $var->title->body; + $description = $var->description->body; + if($var->default) { + unset($default); + if(is_array($var->default)) { + for($i=0;$idefault);$i++) $default[] = $var->default[$i]->body; + } else { + $default = $var->default->body; + } + } + + $width = $var->attrs->width; + $height = $var->attrs->height; + + unset($obj); + $obj->title = $title; + $obj->description = $description; + $obj->name = $name; + $obj->type = $type; + $obj->default = $default; + $obj->width = $width; + $obj->height = $height; + + $skin_info->extra_vars[] = $obj; + } + + return $skin_info; + } + + /** + * @brief 모듈의 conf/info.xml 을 읽어서 정보를 구함 + **/ + function loadModuleXml($module_path) { + // 현재 선택된 모듈의 스킨의 정보 xml 파일을 읽음 + $xml_file = sprintf("%s/module.xml", $module_path); + if(!file_exists($xml_file)) return; + + $oXmlParser = new XmlParser(); + $xml_obj = $oXmlParser->loadXmlFile($xml_file); + + if(!$xml_obj) return; + + $info->title = $xml_obj->title->body; + + // 작성자 정보 + $module_info->title = $xml_obj->title->body; + $module_info->version = $xml_obj->attrs->version; + $module_info->author->name = $xml_obj->author->name->body; + $module_info->author->email_address = $xml_obj->author->attrs->email_address; + $module_info->author->homepage = $xml_obj->author->attrs->link; + $module_info->author->date = $xml_obj->author->attrs->date; + $module_info->author->description = $xml_obj->author->description->body; + + // history + if(!is_array($xml_obj->history->author)) $history[] = $xml_obj->history->author; + else $history = $xml_obj->history->author; + + foreach($history as $item) { + unset($obj); + $obj->name = $item->name->body; + $obj->email_address = $item->attrs->email_address; + $obj->homepage = $item->attrs->link; + $obj->date = $item->attrs->date; + $obj->description = $item->description->body; + $module_info->history[] = $obj; + } + + return $module_info; + } + + /** + * @brief 모듈의 스킨 목록을 구함 + **/ + function getSkins($module_path) { + $skins_path = sprintf("%s/skins/", $module_path); + $list = FileHandler::readDir($skins_path); + return $list; + } + + } +?> diff --git a/modules/module/module.view.php b/modules/module/module.view.php index eaa83ff36..e6885d4e1 100644 --- a/modules/module/module.view.php +++ b/modules/module/module.view.php @@ -2,9 +2,31 @@ /** * @class moduleView * @author zero (zero@nzeo.com) - * @brief 모듈의 view class + * @brief module 모듈의 View class **/ - class moduleView + class moduleView extends Module { + /** + * @brief 초기화 + **/ + function init() { + } + + /** + * @brief 모듈 목록을 출력 + **/ + function dispContent() { + // 모듈모델 객체를 구함 + $oModuleModel = getModule('module','model'); + + // 등록된 모듈의 목록을 구해옴 + $installed_module_list = $oModuleModel->getModulesInfo(); + Context::set('installed_module_list', $installed_module_list); + + // 템플릿 파일 지정 + $this->setTemplateFile('index'); + } + + } ?>