..내의 스크립트코드 var $body_header = NULL; ///< @brief display시에 사용하게 되는
바로 다음에 출력될 스크립트 코드 var $html_footer = NULL; ///< @brief display시에 사용하게 되는 바로 앞에 추가될 코드 var $path = ''; ///< zbxe의 경로 /** * @brief 언어 정보 * 기본으로 ko. HTTP_USER_AGENT나 사용자의 직접 세팅(쿠키이용)등을 통해 변경됨 **/ var $lang_type = ''; ///< 언어 종류 var $lang = NULL; ///< 언어 데이터를 담고 있는 변수 var $loaded_lang_files = array(); ///< 로딩된 언어파일의 목록 (재로딩을 피하기 위함) var $site_title = ''; ///< @brief 현 사이트의 browser title. Context::setBrowserTitle() 로 변경 가능 var $get_vars = NULL; ///< @brief form이나 get으로 요청이 들어온 변수만 별도로 관리 var $is_uploaded = false; ///< @brief 첨부파일이 업로드 된 요청이였는지에 대한 체크 플래그 var $widget_include_info_flag = false; // 위젯 정보 코드 출력 /** * @brief 유일한 Context 객체를 반환 (Singleton) * Context는 어디서든 객체 선언없이 사용하기 위해서 static 하게 사용 **/ function &getInstance() { static $theInstance; if(!isset($theInstance)) $theInstance = new Context(); return $theInstance; } /** * @brief DB정보, Request Argument등을 세팅 * Context::init()은 단 한번만 호출되어야 하며 init()시에 Request Argument, DB/언어/세션정보등의 모든 정보를 세팅한다 **/ function init() { // context 변수를 $GLOBALS의 변수로 지정 $this->context = &$GLOBALS['__Context__']; $this->context->lang = &$GLOBALS['lang']; $this->context->_COOKIE = $_COOKIE; // 사용자의 쿠키 설정된 언어 타입 추출 if($_COOKIE['lang_type']) $this->lang_type = $_COOKIE['lang_type']; // 기본적인 DB정보 세팅 $this->_loadDBInfo(); // 언어 파일 불러오기 $lang_supported = $this->loadLangSelected(); // 세션 핸들러 지정 $oSessionModel = &getModel('session'); $oSessionController = &getController('session'); session_set_save_handler( array(&$oSessionController,"open"), array(&$oSessionController,"close"), array(&$oSessionModel,"read"), array(&$oSessionController,"write"), array(&$oSessionController,"destroy"), array(&$oSessionController,"gc") ); session_start(); // Request Method 설정 $this->_setRequestMethod(); // Request Argument 설정 $this->_setXmlRpcArgument(); $this->_setJSONRequestArgument(); $this->_setRequestArgument(); $this->_setUploadedArgument(); // 설치가 되어 있다면 가상 사이트 정보를 구함 if(Context::isInstalled()) { // site_module_info를 구함 $oModuleModel = &getModel('module'); $site_module_info = $oModuleModel->getDefaultMid(); Context::set('site_module_info', $site_module_info); if($site_module_info->site_srl && isSiteID($site_module_info->vid)) Context::set('vid', $site_module_info->vid); } // 사용자 설정 언어 타입이 없으면 기본 언어타입으로 지정 if(!$this->lang_type) { // 가상 사이트라면 가상사이트의 언어타입으로 지정 if($site_module_info && $site_module_info->default_language) $this->db_info->lang_type = $site_module_info->default_language; // 언어 타입 지정 $this->lang_type = $this->db_info->lang_type; } // 지정된 언어가 지원 언어에 속하지 않거나 없으면 영문으로 지정 if(!in_array($this->lang_type, array_keys($lang_supported))) $this->lang_type = $this->db_info->lang_type; if(!$this->lang_type) $this->lang_type = "en"; Context::set('lang_supported', $lang_supported); $this->setLangType($this->lang_type); // 인증 관련 정보를 Context와 세션에 설정 if(Context::isInstalled()) { // 인증관련 데이터를 Context에 설정 $oMemberModel = &getModel('member'); $oMemberController = &getController('member'); // 인증이 되어 있을 경우 유효성 체크 if($oMemberModel->isLogged()) { $oMemberController->setSessionInfo(); // 인증이 되어 있지 않을 경우 자동 로그인 확인 } elseif($_COOKIE['xeak']) { $oMemberController->doAutologin(); } $this->_set('is_logged', $oMemberModel->isLogged() ); $this->_set('logged_info', $oMemberModel->getLoggedInfo() ); } // 기본 언어파일 로드 $this->lang = &$GLOBALS['lang']; $this->_loadLang(_XE_PATH_."common/lang/"); // rewrite 모듈사용 상태 체크 if(file_exists(_XE_PATH_.'.htaccess')&&$this->db_info->use_rewrite == 'Y') $this->allow_rewrite = true; else $this->allow_rewrite = false; // 기본 JS/CSS 등록 $this->addJsFile("./common/js/jquery.js"); $this->addJsFile("./common/js/x.js"); $this->addJsFile("./common/js/common.js"); $this->addJsFile("./common/js/xml_handler.js"); $this->addJsFile("./common/js/xml_js_filter.js"); $this->addCSSFile("./common/css/default.css"); $this->addCSSFile("./common/css/button.css"); // 관리자 페이지일 경우 관리자 공용 CSS 추가 if(Context::get('module')=='admin' || strpos(Context::get('act'),'Admin')>0) $this->addCssFile("./modules/admin/tpl/css/admin.css", false); // rewrite module때문에 javascript에서 location.href 문제 해결을 위해 직접 실제 경로 설정 if($_SERVER['REQUEST_METHOD'] == 'GET') { if($this->get_vars) { foreach($this->get_vars as $key => $val) { if(!$val) continue; if(is_array($val)&&count($val)) { foreach($val as $k => $v) { $url .= ($url?'&':'').$key.'['.$k.']='.urlencode($v); } } else { $url .= ($url?'&':'').$key.'='.urlencode($val); } } Context::set('current_url',sprintf('%s?%s', $this->getRequestUri(), $url)); } else { Context::set('current_url',$this->getUrl()); } } else { Context::set('current_url',$this->getRequestUri()); } Context::set('request_uri',Context::getRequestUri()); } /** * @brief DB및 기타 자원들의 close **/ function close() { // Session Close if(function_exists('session_write_close')) session_write_close(); // DB close $oDB = &DB::getInstance(); if(is_object($oDB)&&method_exists($oDB, 'close')) $oDB->close(); } /** * @brief DB의 및 기타 정보 load **/ function loadDBInfo() { $oContext = &Context::getInstance(); return $oContext->_loadDBInfo(); } /** * @brief DB 정보를 설정하고 DB Type과 DB 정보를 return **/ function _loadDBInfo() { if(!$this->isInstalled()) return; // db 정보 설정 $db_config_file = $this->getConfigFile(); if(file_exists($db_config_file)) @include($db_config_file); if(!$db_info->time_zone) $db_info->time_zone = date("O"); if(!$db_info->use_optimizer || $db_info->use_optimizer != 'N') $db_info->use_optimizer = 'Y'; else $db_info->use_optimizer = 'N'; if(!$db_info->qmail_compatibility || $db_info->qmail_compatibility != 'Y') $db_info->qmail_compatibility = 'N'; else $db_info->qmail_compatibility = 'Y'; if(!$db_info->use_ssl) $db_info->use_ssl = 'none'; $this->_setDBInfo($db_info); $GLOBALS['_time_zone'] = $db_info->time_zone; $GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility; $this->set('_use_ssl', $db_info->use_ssl); if($db_info->http_port) { $this->set('_http_port', $db_info->http_port); } if($db_info->https_port) { $this->set('_https_port', $db_info->https_port); } } /** * @brief DB의 db_type을 return **/ function getDBType() { $oContext = &Context::getInstance(); return $oContext->_getDBType(); } /** * @brief DB의 db_type을 return **/ function _getDBType() { return $this->db_info->db_type; } /** * @brief DB 정보가 담긴 object를 return **/ function setDBInfo($db_info) { $oContext = &Context::getInstance(); $oContext->_setDBInfo($db_info); } /** * @brief DB 정보가 담긴 object를 return **/ function _setDBInfo($db_info) { $this->db_info = $db_info; } /** * @brief DB 정보가 담긴 object를 return **/ function getDBInfo() { $oContext = &Context::getInstance(); return $oContext->_getDBInfo(); } /** * @brief DB 정보가 담긴 object를 return **/ function _getDBInfo() { return $this->db_info; } /** * @brief 기본 URL을 return **/ function getDefaultUrl() { $db_info = Context::getDBInfo(); return $db_info->default_url; } /** * @brief 지원되는 언어 파일 찾기 **/ function loadLangSupported() { static $lang_supported = null; if(is_null($lang_supported)) { $langs = file(_XE_PATH_.'common/lang/lang.info'); foreach($langs as $val) { list($lang_prefix, $lang_text) = explode(',',$val); $lang_text = trim($lang_text); $lang_supported[$lang_prefix] = $lang_text; } } return $lang_supported; } /** * @brief 설정한 언어 파일 찾기 **/ function loadLangSelected() { static $lang_selected = null; if(is_null($lang_selected)) { $orig_lang_file = _XE_PATH_.'common/lang/lang.info'; $selected_lang_file = _XE_PATH_.'files/cache/lang_selected.info'; if(!file_exists($selected_lang_file) || !filesize($selected_lang_file)) { $buff = FileHandler::readFile($orig_lang_file); FileHandler::writeFile($selected_lang_file, $buff); $lang_selected = Context::loadLangSupported(); } else { $langs = file($selected_lang_file); foreach($langs as $val) { list($lang_prefix, $lang_text) = explode(',',$val); $lang_text = trim($lang_text); $lang_selected[$lang_prefix] = $lang_text; } } } return $lang_selected; } /** * @brief SSO URL이 설정되어 있고 아직 SSO URL검사를 하지 않았다면 return true **/ function checkSSO() { // GET 접속이 아니거나 설치가 안되어 있으면 패스 if(Context::getRequestMethod()!='GET' || !Context::isInstalled()) return true; // DB info에 설정된 Default URL이 없다면 무조건 무사통과 $default_url = trim($this->db_info->default_url); if(!$default_url) return true; if(substr($default_url,-1)!='/') $default_url .= '/'; // SSO 검증을 요청 받는 사이트 if($default_url == Context::getRequestUri()) { if(Context::get('default_url')) { $url = base64_decode(Context::get('default_url')); $url_info = parse_url($url); $url_info['query'].= ($url_info['query']?'&':'').'SSOID='.session_id(); $redirect_url = sprintf('%s://%s%s%s?%s',$url_info['scheme'],$url_info['host'],$url_info['port']?':'.$url_info['port']:'',$url_info['path'], $url_info['query']); header("location:".$redirect_url); return false; } // SSO 검증을 요청하는 사이트 } else { // SSO 결과를 받는 경우 session_name() 세팅 if(Context::get('SSOID')) { setcookie(session_name(), Context::get('SSOID'), 0, '/'); header("location:".getUrl('SSOID','')); return false; // SSO 결과를 요청 } else if($_COOKIE['sso']!=md5(Context::getRequestUri()) && !Context::get('SSOID')) { setcookie('sso',md5(Context::getRequestUri()),0,'/'); $url = sprintf("%s?default_url=%s", $default_url, base64_encode(Context::getRequestUrl())); header("location:".$url); return false; } } return true; } /** * @biref FTP 정보가 등록되었는지 확인 **/ function isFTPRegisted() { $ftp_config_file = Context::getFTPConfigFile(); if(file_exists($ftp_config_file)) return true; return false; } /** * @brief FTP 정보가 담긴 object를 return **/ function getFTPInfo() { $oContext = &Context::getInstance(); return $oContext->_getFTPInfo(); } /** * @brief FTP 정보가 담긴 object를 return **/ function _getFTPInfo() { if(!$this->isFTPRegisted()) return null; $ftp_config_file = $this->getFTPConfigFile(); @include($ftp_config_file); return $ftp_info; } /** * @brief 사이트 title adding **/ function addBrowserTitle($site_title) { if(!$site_title) return; $oContext = &Context::getInstance(); $oContext->_addBrowserTitle($site_title); } /** * @brief 사이트 title adding **/ function _addBrowserTitle($site_title) { if($this->site_title) $this->site_title .= ' - '.$site_title; else $this->site_title .= $site_title; } /** * @brief 사이트 title setting **/ function setBrowserTitle($site_title) { if(!$site_title) return; $oContext = &Context::getInstance(); $oContext->_setBrowserTitle($site_title); } /** * @brief 사이트 title setting **/ function _setBrowserTitle($site_title) { $this->site_title = $site_title; } /** * @brief 사이트 title return **/ function getBrowserTitle() { $oContext = &Context::getInstance(); return $oContext->_getBrowserTitle(); } /** * @brief 사이트 title return **/ function _getBrowserTitle() { return $this->site_title; } /** * @brief 지정된 언어파일 로드 **/ function loadLang($path) { $oContext = &Context::getInstance(); $oContext->_loadLang($path); } /** * @brief 지정된 언어파일 로드 * * loaded_lang_files 변수를 이용하여 한번 로드된 파일을 다시 로드하지 않음 **/ function _loadLang($path) { global $lang; if(substr($path,-1)!='/') $path .= '/'; $filename = sprintf('%s%s.lang.php', $path, $this->lang_type); if(!file_exists($filename)) $filename = sprintf('%s%s.lang.php', $path, 'ko'); if(!file_exists($filename)) return; if(!is_array($this->loaded_lang_files)) $this->loaded_lang_files = array(); if(in_array($filename, $this->loaded_lang_files)) return; $this->loaded_lang_files[] = $filename; include($filename); } /** * @brief lang_type을 세팅 (기본 ko) **/ function setLangType($lang_type = 'ko') { $oContext = &Context::getInstance(); $oContext->_setLangType($lang_type); $_SESSION['lang_type'] = $lang_type; } /** * @brief lang_type을 세팅 (기본 ko) **/ function _setLangType($lang_type = 'ko') { $this->lang_type = $lang_type; $this->_set('lang_type',$lang_type); } /** * @brief lang_type을 return **/ function getLangType() { $oContext = &Context::getInstance(); return $oContext->_getLangType(); } /** * @brief lang_type을 return **/ function _getLangType() { return $this->lang_type; } /** * @brief code에 해당하는 문자열을 return * * 만약 code에 해당하는 문자열이 없다면 code를 그대로 리턴 **/ function getLang($code) { if(!$code) return; if($GLOBALS['lang']->{$code}) return $GLOBALS['lang']->{$code}; return $code; } /** * @brief 직접 lang 변수에 데이터를 추가 **/ function setLang($code, $val) { $GLOBALS['lang']->{$code} = $val; } /** * @brief object내의 variables의 문자열을 utf8로 변경 **/ function convertEncoding($source_obj) { $charset_list = array( 'UTF-8', 'EUC-KR', 'CP949', 'ISO8859-1', 'EUC-JP', 'SHIFT_JIS', 'CP932', 'EUC-CN', 'HZ', 'GBK', 'GB18030', 'EUC-TW', 'BIG5', 'CP950', 'BIG5-HKSCS', 'ISO2022-CN', 'ISO2022-CN-EXT', 'ISO2022-JP', 'ISO2022-JP-2', 'ISO2022-JP-1', 'ISO8859-6', 'ISO8859-8', 'JOHAB', 'ISO2022-KR', 'CP1255', 'CP1256', 'CP862', 'ASCII', 'ISO8859-1', 'ISO8850-2', 'ISO8850-3', 'ISO8850-4', 'ISO8850-5', 'ISO8850-7', 'ISO8850-9', 'ISO8850-10', 'ISO8850-13', 'ISO8850-14', 'ISO8850-15', 'ISO8850-16', 'CP1250', 'CP1251', 'CP1252', 'CP1253', 'CP1254', 'CP1257', 'CP850', 'CP866', ); $obj = clone($source_obj); for($i=0;$i