git-svn-id: http://xe-core.googlecode.com/svn/trunk@13 201d5d3c-b55e-5fd7-737f-ddc643e51545

This commit is contained in:
zero 2007-02-14 04:55:29 +00:00
parent a314c21ba7
commit 3d61ed75c1
10 changed files with 1686 additions and 1450 deletions

View file

@ -1,174 +1,180 @@
<?php
/**
* @file : classes/module/Module.class.php
* @author : zero <zero@nzeo.com>
* @desc : modulesabstract class
**/
/**
* @class Module
* @author zero (zero@nzeo.com)
* @brief modules abstract class
**/
// abstract class Module
class Module extends Output {
class Module extends Output {
// 현재 모듈의 실행 위치
var $module_path = NULL;
var $module_path = NULL; ///< 현재 모듈의 실행 위치
// skin 설정 (없을 경우도 있음)
var $skin = 'default';
var $skin = 'default'; ///< skin 설정 (없을 경우도 있음)
// 현재 모듈 생성시 주어진 설정 정보들
var $module_srl = NULL;
var $module_info = NULL;
var $module_srl = NULL; ///< 모듈 객체의 고유값인 module_srl
var $module_info = NULL; ///< 현재 모듈 생성시 주어진 설정 정보들
// 모듈의 action을 정의하는 변수 설정
var $act = NULL;
var $act_type = 'disp';
var $act = NULL; ///< act 값
var $act_type = 'disp'; ///< act_type (disp, proc, lib, admin 4가지 존재, act에서 type을 찾음)
// 레이아웃 path, tpl
var $layout_path = "./common/tpl/";
var $layout_tpl = "default_layout";
var $layout_path = "./common/tpl/"; ///< 레이아웃 파일의 path
var $layout_tpl = "default_layout"; ///< 레이아웃 파일
// public void moduleInit($module_info)/*{{{*/
// 모듈의 정보 세팅
function moduleInit($module_info) {
// 브라우저 타이틀 지정
Context::setBrowserTitle($module_info->browser_title?$module_info->browser_title:$module_info->mid);
/**
* @brief 모듈의 정보 세팅
**/
function moduleInit($module_info) {
// 브라우저 타이틀 지정
Context::setBrowserTitle($module_info->browser_title?$module_info->browser_title:$module_info->mid);
// 기본 변수 설정
$this->module_info = $module_info;
context::set('module_info', &$this->module_info);
// 기본 변수 설정
$this->module_info = $module_info;
context::set('module_info', &$this->module_info);
$this->module_srl = $module_info->module_srl;
$this->module_srl = $module_info->module_srl;
// skin 설정 (기본으로는 default)
if($this->module_info->skin) $this->skin = $this->module_info->skin;
else $this->skin = 'default';
// skin 설정 (기본으로는 default)
if($this->module_info->skin) $this->skin = $this->module_info->skin;
else $this->skin = 'default';
// 템플릿 위치 설정
if(!$this->template_path) {
$template_path = $this->module_path.'skins/'.$this->skin;
$this->setTemplatePath($template_path);
}
$oMember = getModule('member');
$user_id = $oMember->getUserID();
$logged_info = $oMember->getLoggedInfo();
$user_group = $logged_info->group_list;
$user_group_count = count($user_group);
// 로그인되어 있다면 admin 체크
if($oMember->isLogged() && ($logged_info->is_admin == 'Y' || in_array($user_id, $this->module_info->admin_id) )) {
$grant->is_admin = true;
} else {
$grant->is_admin = false;
}
// 권한 설정
if($this->grant_list) {
foreach($this->grant_list as $grant_name) {
$grant->{$grant_name} = false;
if($grant->is_admin || !$this->module_info->grant[$grant_name]) {
$grant->{$grant_name} = true;
continue;
}
if($user_group_count) {
foreach($user_group as $group_srl) {
if(in_array($group_srl, $this->module_info->grant[$grant_name])) {
$grant->{$grant_name} = true;
break;
}
// 템플릿 위치 설정
if(!$this->template_path) {
$template_path = $this->module_path.'skins/'.$this->skin;
$this->setTemplatePath($template_path);
}
}
$oMember = getModule('member');
$user_id = $oMember->getUserID();
$logged_info = $oMember->getLoggedInfo();
$user_group = $logged_info->group_list;
$user_group_count = count($user_group);
// 로그인되어 있다면 admin 체크
if($oMember->isLogged() && ($logged_info->is_admin == 'Y' || in_array($user_id, $this->module_info->admin_id) )) {
$grant->is_admin = true;
} else {
$grant->is_admin = false;
}
// 권한 설정
if($this->grant_list) {
foreach($this->grant_list as $grant_name) {
$grant->{$grant_name} = false;
if($grant->is_admin || !$this->module_info->grant[$grant_name]) {
$grant->{$grant_name} = true;
continue;
}
if($user_group_count) {
foreach($user_group as $group_srl) {
if(in_array($group_srl, $this->module_info->grant[$grant_name])) {
$grant->{$grant_name} = true;
break;
}
}
}
}
}
// 권한변수 설정
Context::set('grant',$grant);
$this->grant = $grant;
// 모듈의 init method 실행
$this->init();
}
}
// 권한변수 설정
Context::set('grant',$grant);
$this->grant = $grant;
// 모듈의 init method 실행
$this->init();
}/*}}}*/
// public boolean isExistsAct($act)/*{{{*/
// 현재 모듈에 $act에 해당하는 method가 있는지 체크
function isExistsAct($act) {
return method_exists($this, $act);
}/*}}}*/
// public String getActType()/*{{{*/
// 현재 acT_type의 return (disp/proc)
function getActType() {
return $this->act_type;
}/*}}}*/
// public void setModulePath($path)/*{{{*/
// 현재 모듈의 path를 지정
function setModulePath($path) {
if(substr($path,-1)!='/') $path.='/';
$this->module_path = $path;
}/*}}}*/
// public boolean doError($msg_code) /*{{{*/
function doError($msg_code) {
$this->setError(-1);
if(!Context::getLang($msg_code)) $this->setMessage($msg_code);
else $this->setMessage(Context::getLang($msg_code));
return false;
}/*}}}*/
// public void setLayoutPath($path)/*{{{*/
function setLayoutPath($path) {
$this->layout_path = $path;
}/*}}}*/
// public void setLayoutTpl($tpl)/*{{{*/
function setLayoutTpl($tpl) {
$this->layout_tpl = $tpl;
}/*}}}*/
// public void proc($act = null)/*{{{*/
//모듈의 각 action을 실행하는 부분
//$act값에 의해서 $action_list에 선언된 것들을 실행한다
function proc($act = null) {
// 별도로 요청한 act가 없으면 주어진 act를 이용
if($act) $this->act = $act;
else $this->act = Context::get('act');
// act의 종류가 disp/proc인지에 대한 확인
if($this->act&&strtolower(substr($this->act,0,4)) != 'disp') $this->act_type = 'proc';
// act값이 없거나 존재하지 않는 method를 호출시에 default_act를 지정
if(!$this->act || !$this->isExistsAct($this->act)) $this->act = $this->default_act;
// module의 *init 호출 (기본 init과 proc/disp init 2가지 있음)
if($this->act_type == 'proc') {
$output = $this->procInit();
if((is_a($output, 'Output') || is_subclass_of($output, 'Output')) && !$output->toBool() ) {
$this->setError($output->getError());
$this->setMessage($output->getMessage());
return;
} elseif(!$output) {
$this->setError(-1);
$this->setMessage('fail');
return;
/**
* @brief 현재 모듈에 $act에 해당하는 method가 있는지 체크
**/
function isExistsAct($act) {
return method_exists($this, $act);
}
} else $this->dispInit();
// 기본 act조차 없으면 return
if(!$this->isExistsAct($this->act)) return false;
/**
* @brief 현재 acT_type의 return (disp/proc)
**/
function getActType() {
return $this->act_type;
}
// act값으로 method 실행
$output = call_user_method($this->act, $this);
/**
* @brief 현재 모듈의 path를 지정
**/
function setModulePath($path) {
if(substr($path,-1)!='/') $path.='/';
$this->module_path = $path;
}
if(is_a($output, 'Output') || is_subclass_of($output, 'Output')) {
$this->setError($output->getError());
$this->setMessage($output->getMessage());
}
/**
* @brief 에러 유발. 에러시 message module을 바로 호출하고 현재 모듈은 exit
**/
function doError($msg_code) {
$this->setError(-1);
if(!Context::getLang($msg_code)) $this->setMessage($msg_code);
else $this->setMessage(Context::getLang($msg_code));
return false;
}
return true;
}/*}}}*/
}
/**
* @brief 레이아웃 경로를 지정
**/
function setLayoutPath($path) {
$this->layout_path = $path;
}
/**
* @brief 레이아웃 tpl 파일을 지정
**/
function setLayoutTpl($tpl) {
$this->layout_tpl = $tpl;
}
/**
* @brief 모듈의 action에 해당하는 method를 실행
*
* $act값에 의해서 $action_list에 선언된 것들을 실행한다
**/
function proc($act = null) {
// 별도로 요청한 act가 없으면 주어진 act를 이용
if($act) $this->act = $act;
else $this->act = Context::get('act');
// act의 종류가 disp/proc인지에 대한 확인
if($this->act&&strtolower(substr($this->act,0,4)) != 'disp') $this->act_type = 'proc';
// act값이 없거나 존재하지 않는 method를 호출시에 default_act를 지정
if(!$this->act || !$this->isExistsAct($this->act)) $this->act = $this->default_act;
// module의 *init 호출 (기본 init과 proc/disp init 2가지 있음)
if($this->act_type == 'proc') {
$output = $this->procInit();
if((is_a($output, 'Output') || is_subclass_of($output, 'Output')) && !$output->toBool() ) {
$this->setError($output->getError());
$this->setMessage($output->getMessage());
return;
} elseif(!$output) {
$this->setError(-1);
$this->setMessage('fail');
return;
}
} else $this->dispInit();
// 기본 act조차 없으면 return
if(!$this->isExistsAct($this->act)) return false;
// act값으로 method 실행
$output = call_user_method($this->act, $this);
if(is_a($output, 'Output') || is_subclass_of($output, 'Output')) {
$this->setError($output->getError());
$this->setMessage($output->getMessage());
}
return true;
}
}
?>

View file

@ -1,87 +1,93 @@
<?php
/**
* @file : classes/module/ModuleHandler.class.php
* @author : zero <zero@nzeo.com>
* @desc : mid의 값으로 모듈을 찾고 관련 정보들을 세팅
**/
/**
* @class ModuleHandler
* @author zero (zero@nzeo.com)
* @brief mid의 값으로 모듈을 찾아 객체 생성 & 모듈 정보 세팅
**/
class ModuleHandler {
class ModuleHandler {
// mid와 해당 mid의 설정 값
var $mid = NULL;
var $module_info = NULL;
var $mid = NULL; ///< module로 생성한 instance(관리상)의 값
var $module_info = NULL; ///< 해당 모듈의 정보
// 모듈과 해당 모듈의 instance
var $module = NULL;
var $oModule = NULL;
var $module = NULL; ///< mid로 찾아서 생성한 모듈 class 이름
var $oModule = NULL; ///< mid로 찾아서 생성한 모듈의 객체
// public void ModuleHandler()/*{{{*/
function ModuleHandler() {
/**
* @brief constructor
**/
function ModuleHandler() {
// 설치가 안되어 있다면 설치를 위한 준비
if(!Context::isInstalled()) return $this->_prepareInstall();
// 설치가 안되어 있다면 설치를 위한 준비
if(!Context::isInstalled()) return $this->_prepareInstall();
// 설치가 되어 있다면 요청받은 mid에 해당하는 모듈 instance 생성
// mid가 없이 document_srl만 있다면 document_srl로 mid를 찾음
$mid = Context::get('mid');
$document_srl = Context::get('document_srl');
// 설치가 되어 있다면 요청받은 mid에 해당하는 모듈 instance 생성
// mid가 없이 document_srl만 있다면 document_srl로 mid를 찾음
$mid = Context::get('mid');
$document_srl = Context::get('document_srl');
// document_srl만 있다면 mid를 구해옴
if(!$mid && $document_srl) {
$module_info = module_manager::getModuleInfoByDocument($document_srl);
if($module_info) $mid = $module_info->mid;
}
// document_srl만 있다면 mid를 구해옴
if(!$mid && $document_srl) {
$module_info = module_manager::getModuleInfoByDocument($document_srl);
if($module_info) $mid = $module_info->mid;
}
// mid 값에 대한 모듈 정보를 추출
if(!$module_info) $module_info = module_manager::getModuleInfo($mid);
// mid 값에 대한 모듈 정보를 추출
if(!$module_info) $module_info = module_manager::getModuleInfo($mid);
// 모듈 정보에서 module 이름을 구해움
$module = $module_info->module;
// 모듈 정보에서 module 이름을 구해움
$module = $module_info->module;
$this->mid = $module_info->mid;
$this->module_info = $module_info;
$this->mid = $module_info->mid;
$this->module_info = $module_info;
Context::set('module', $module);
Context::set('mid', $this->mid, true);
Context::set('module_srl', $this->module_info->module_srl, true);
Context::set('module', $module);
Context::set('mid', $this->mid, true);
Context::set('module_srl', $this->module_info->module_srl, true);
// 만약 모듈이 없다면 오류 출력
if(!$module) return $this->_moduleIsNotExists();
// 만약 모듈이 없다면 오류 출력
if(!$module) return $this->_moduleIsNotExists();
$this->oModule = getModule($module);
$this->module = $module;
}/*}}}*/
$this->oModule = getModule($module);
$this->module = $module;
}
// private void _prepareInstall()/*{{{*/
// 설치를 하기 위해서 mid, module등을 강제 지정
function _prepareInstall() {
// module로 install 모듈을 지정
$this->module = 'install';
Context::set('mid', NULL);
Context::set('module', $this->module);
/**
* @brief 설치를 하기 위해서 mid, module등을 강제 지정
**/
function _prepareInstall() {
// module로 install 모듈을 지정
$this->module = 'install';
Context::set('mid', NULL);
Context::set('module', $this->module);
// module_manager 호출
$this->oModule = getModule($this->module);
}/*}}}*/
// module_manager 호출
$this->oModule = getModule($this->module);
}
// private void _moduleIsNotExists()/*{{{*/
// 아무런 설정이 되어 있지 않다면 오류 표시
function _moduleIsNotExists() {
$this->module = 'message';
Context::set('mid', NULL);
Context::set('module', $this->module);
/**
* @brief 아무런 설정이 되어 있지 않다면 오류 표시
**/
function _moduleIsNotExists() {
$this->module = 'message';
Context::set('mid', NULL);
Context::set('module', $this->module);
$this->oModule = getModule($this->module);
$this->oModule = getModule($this->module);
Context::set('error', -1);
Context::set('message', Context::getLang('msg_mid_not_exists'));
}/*}}}*/
Context::set('error', -1);
Context::set('message', Context::getLang('msg_mid_not_exists'));
}
// public object proc()/*{{{*/
function proc() {
$this->oModule->moduleInit($this->module_info);
$this->oModule->proc();
return $this->oModule;
}/*}}}*/
}
/**
* @brief mid로 생성한 모듈 객체에 모듈 정보를 세팅하고 실행
*
* 모듈을 실행후에 모듈 객체를 return하여 DisplayHandler로 넘겨줌
**/
function proc() {
$this->oModule->moduleInit($this->module_info);
$this->oModule->proc();
return $this->oModule;
}
}
?>