diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index e91dfcc94..cde31a5f5 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -9,8 +9,8 @@ define('RELEASE_SSL',2); * * @author NHN (developers@xpressengine.com) */ -class Context { - +class Context +{ /** * Allow rewrite * @var bool true: using rewrite mod, false: otherwise @@ -124,7 +124,8 @@ class Context { * * @return object Instance */ - function &getInstance() { + function &getInstance() + { static $theInstance = null; if(!$theInstance) $theInstance = new Context(); @@ -158,7 +159,8 @@ class Context { * @see This function should be called only once * @return void */ - function init() { + function init() + { // set context variables in $GLOBALS (to use in display handler) $this->context = &$GLOBALS['__Context__']; $this->context->lang = &$GLOBALS['lang']; @@ -174,11 +176,13 @@ class Context { $this->loadDBInfo(); // If XE is installed, get virtual site information - if(Context::isInstalled()) { + if(Context::isInstalled()) + { $oModuleModel = &getModel('module'); $site_module_info = $oModuleModel->getDefaultMid(); // if site_srl of site_module_info is 0 (default site), compare the domain to default_url of db_config - if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) { + if($site_module_info->site_srl == 0 && $site_module_info->domain != $this->db_info->default_url) + { $site_module_info->domain = $this->db_info->default_url; } @@ -194,12 +198,16 @@ class Context { $lang_supported = $this->loadLangSelected(); // Retrieve language type set in user's cookie - if($this->get('l')) { + if($this->get('l')) + { $this->lang_type = $this->get('l'); - if($_COOKIE['lang_type'] != $this->lang_type) { + if($_COOKIE['lang_type'] != $this->lang_type) + { setcookie('lang_type', $this->lang_type, time()+3600*24*1000, '/'); } - } elseif($_COOKIE['lang_type']) { + } + elseif($_COOKIE['lang_type']) + { $this->lang_type = $_COOKIE['lang_type']; } @@ -217,23 +225,25 @@ class Context { $this->loadLang(_XE_PATH_.'modules/module/lang'); // set session handler - if(Context::isInstalled() && $this->db_info->use_db_session == 'Y') { + if(Context::isInstalled() && $this->db_info->use_db_session == 'Y') + { $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') - ); + array(&$oSessionController, 'open'), + array(&$oSessionController, 'close'), + array(&$oSessionModel, 'read'), + array(&$oSessionController, 'write'), + array(&$oSessionController, 'destroy'), + array(&$oSessionController, 'gc') + ); } session_start(); if($sess=$_POST[session_name()]) session_id($sess); // set authentication information in Context and session - if(Context::isInstalled()) { + if(Context::isInstalled()) + { $oModuleModel = &getModel('module'); $oModuleModel->loadModuleExtends(); @@ -243,10 +253,13 @@ class Context { if($oMemberController && $oMemberModel) { // if signed in, validate it. - if($oMemberModel->isLogged()) { + if($oMemberModel->isLogged()) + { $oMemberController->setSessionInfo(); } - elseif($_COOKIE['xeak']) { // check auto sign-in + // check auto sign-in + elseif($_COOKIE['xeak']) + { $oMemberController->doAutologin(); } @@ -264,22 +277,33 @@ class Context { else $this->allow_rewrite = false; // set locations for javascript use - if($_SERVER['REQUEST_METHOD'] == 'GET') { - if($this->get_vars) { - foreach($this->get_vars as $key=>$val) { - if(is_array($val)&&count($val)) { - foreach($val as $k => $v) { + if($_SERVER['REQUEST_METHOD'] == 'GET') + { + if($this->get_vars) + { + foreach($this->get_vars as $key=>$val) + { + if(is_array($val)&&count($val)) + { + foreach($val as $k => $v) + { $url .= ($url?'&':'').$key.'['.$k.']='.urlencode($v); } - } elseif ($val) { + } + elseif ($val) + { $url .= ($url?'&':'').$key.'='.urlencode($val); } } $this->set('current_url',sprintf('%s?%s', Context::getRequestUri(), $url)); - } else { + } + else + { $this->set('current_url',$this->getUrl()); } - } else { + } + else + { $this->set('current_url',Context::getRequestUri()); } $this->set('request_uri',Context::getRequestUri()); @@ -290,7 +314,8 @@ class Context { * * @return void */ - function close() { + function close() + { // Session Close if(function_exists('session_write_close')) session_write_close(); @@ -304,7 +329,8 @@ class Context { * * @return void */ - function loadDBInfo() { + function loadDBInfo() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if(!$self->isInstalled()) return; @@ -312,32 +338,33 @@ class Context { $config_file = $self->getConfigFile(); if(is_readable($config_file)) @include($config_file); - // If master_db information does not exist, the config file needs to be updated - if(!isset($db_info->master_db)) { - $db_info->master_db = array(); - $db_info->master_db["db_type"] = $db_info->db_type; unset($db_info->db_type); - $db_info->master_db["db_port"] = $db_info->db_port; unset($db_info->db_port); - $db_info->master_db["db_hostname"] = $db_info->db_hostname; unset($db_info->db_hostname); - $db_info->master_db["db_password"] = $db_info->db_password; unset($db_info->db_password); - $db_info->master_db["db_database"] = $db_info->db_database; unset($db_info->db_database); - $db_info->master_db["db_userid"] = $db_info->db_userid; unset($db_info->db_userid); - $db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix; unset($db_info->db_table_prefix); - if(substr($db_info->master_db["db_table_prefix"],-1)!='_') $db_info->master_db["db_table_prefix"] .= '_'; + // If master_db information does not exist, the config file needs to be updated + if(!isset($db_info->master_db)) + { + $db_info->master_db = array(); + $db_info->master_db["db_type"] = $db_info->db_type; unset($db_info->db_type); + $db_info->master_db["db_port"] = $db_info->db_port; unset($db_info->db_port); + $db_info->master_db["db_hostname"] = $db_info->db_hostname; unset($db_info->db_hostname); + $db_info->master_db["db_password"] = $db_info->db_password; unset($db_info->db_password); + $db_info->master_db["db_database"] = $db_info->db_database; unset($db_info->db_database); + $db_info->master_db["db_userid"] = $db_info->db_userid; unset($db_info->db_userid); + $db_info->master_db["db_table_prefix"] = $db_info->db_table_prefix; unset($db_info->db_table_prefix); + if(substr($db_info->master_db["db_table_prefix"],-1)!='_') $db_info->master_db["db_table_prefix"] .= '_'; - $slave_db = $db_info->master_db; - $db_info->slave_db = array($slave_db); - - $self->setDBInfo($db_info); + $slave_db = $db_info->master_db; + $db_info->slave_db = array($slave_db); + + $self->setDBInfo($db_info); + + $oInstallController = &getController('install'); + $oInstallController->makeConfigFile(); + } - $oInstallController = &getController('install'); - $oInstallController->makeConfigFile(); - } - if(!$db_info->use_prepared_statements) { $db_info->use_prepared_statements = 'Y'; } - + if(!$db_info->time_zone) $db_info->time_zone = date('O'); $GLOBALS['_time_zone'] = $db_info->time_zone; @@ -359,7 +386,8 @@ class Context { * * @return string DB's db_type */ - function getDBType() { + function getDBType() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->db_info->master_db["db_type"]; } @@ -370,7 +398,8 @@ class Context { * @param object $db_info DB information * @return void */ - function setDBInfo($db_info) { + function setDBInfo($db_info) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->db_info = $db_info; } @@ -380,7 +409,8 @@ class Context { * * @return object DB information */ - function getDBInfo() { + function getDBInfo() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->db_info; } @@ -401,7 +431,8 @@ class Context { * * @return string Default URL */ - function getDefaultUrl() { + function getDefaultUrl() + { $db_info = Context::getDBInfo(); return $db_info->default_url; } @@ -411,11 +442,14 @@ class Context { * * @return array Supported languages */ - function loadLangSupported() { + function loadLangSupported() + { static $lang_supported = null; - if(!$lang_supported) { + if(!$lang_supported) + { $langs = file(_XE_PATH_.'common/lang/lang.info'); - foreach($langs as $val) { + foreach($langs as $val) + { list($lang_prefix, $lang_text) = explode(',',$val); $lang_text = trim($lang_text); $lang_supported[$lang_prefix] = $lang_text; @@ -429,23 +463,30 @@ class Context { * * @return array Selected languages */ - function loadLangSelected() { + function loadLangSelected() + { static $lang_selected = null; - if(!$lang_selected) { + if(!$lang_selected) + { $orig_lang_file = _XE_PATH_.'common/lang/lang.info'; $selected_lang_file = _XE_PATH_.'files/config/lang_selected.info'; - if(!FileHandler::hasContent($selected_lang_file)) { + if(!FileHandler::hasContent($selected_lang_file)) + { $old_selected_lang_file = _XE_PATH_.'files/cache/lang_selected.info'; FileHandler::moveFile($old_selected_lang_file, $selected_lang_file); } - if(!FileHandler::hasContent($selected_lang_file)) { + if(!FileHandler::hasContent($selected_lang_file)) + { $buff = FileHandler::readFile($orig_lang_file); FileHandler::writeFile($selected_lang_file, $buff); $lang_selected = Context::loadLangSupported(); - } else { + } + else + { $langs = file($selected_lang_file); - foreach($langs as $val) { + foreach($langs as $val) + { list($lang_prefix, $lang_text) = explode(',',$val); $lang_text = trim($lang_text); $lang_selected[$lang_prefix] = $lang_text; @@ -460,7 +501,8 @@ class Context { * * @return bool True : Module handling is necessary in the control path of current request , False : Otherwise */ - function checkSSO() { + function checkSSO() + { // pass if it's not GET request or XE is not yet installed if($this->db_info->use_sso != 'Y' || isCrawler()) return true; $checkActList = array('rss'=>1, 'atom'=>1); @@ -472,8 +514,10 @@ class Context { if(substr($default_url,-1)!='/') $default_url .= '/'; // for sites recieving SSO valdiation - if($default_url == Context::getRequestUri()) { - if(Context::get('default_url')) { + 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(); @@ -481,18 +525,23 @@ class Context { header('location:'.$redirect_url); return false; } - // for sites requesting SSO validation - } else { + // for sites requesting SSO validation + } + else + { // result handling : set session_name() - if(Context::get('SSOID')) { + if(Context::get('SSOID')) + { $session_name = Context::get('SSOID'); setcookie(session_name(), $session_name); $url = preg_replace('/([\?\&])$/','',str_replace('SSOID='.$session_name,'',Context::getRequestUrl())); header('location:'.$url); return false; - // send SSO request - } else if($_COOKIE['sso']!=md5(Context::getRequestUri()) && !Context::get('SSOID')) { + // send SSO request + } + 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); @@ -508,7 +557,8 @@ class Context { * * @return bool True: FTP information is registered, False: otherwise */ - function isFTPRegisted() { + function isFTPRegisted() + { $ftp_config_file = Context::getFTPConfigFile(); if(file_exists($ftp_config_file)) return true; return false; @@ -519,7 +569,8 @@ class Context { * * @return object FTP information */ - function getFTPInfo() { + function getFTPInfo() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if(!$self->isFTPRegisted()) return null; @@ -535,7 +586,8 @@ class Context { * @param string $site_title Browser title to be added * @return void */ - function addBrowserTitle($site_title) { + function addBrowserTitle($site_title) + { if(!$site_title) return; is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); @@ -549,7 +601,8 @@ class Context { * @param string $site_title Browser title to be set * @return void */ - function setBrowserTitle($site_title) { + function setBrowserTitle($site_title) + { if(!$site_title) return; is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->site_title = $site_title; @@ -560,7 +613,8 @@ class Context { * * @return string Browser title(htmlspecialchars applied) */ - function getBrowserTitle() { + function getBrowserTitle() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $oModuleController = &getController('module'); @@ -580,7 +634,8 @@ class Context { * @param string $path Path of the language file * @return void */ - function loadLang($path) { + function loadLang($path) + { global $lang; is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); @@ -593,10 +648,13 @@ class Context { if(!is_array($self->loaded_lang_files)) $self->loaded_lang_files = array(); if(in_array($filename, $self->loaded_lang_files)) return; - if ($filename && is_readable($filename)){ + if ($filename && is_readable($filename)) + { $self->loaded_lang_files[] = $filename; @include($filename); - }else{ + } + else + { $self->_evalxmlLang($path); } } @@ -607,9 +665,10 @@ class Context { * @param string Path of the language file * @return void */ - function _evalxmlLang($path) { + function _evalxmlLang($path) + { global $lang; - + $_path = 'eval://'.$path; if(in_array($_path, $this->loaded_lang_files)) return; @@ -620,7 +679,8 @@ class Context { $oXmlLangParser = new XmlLangParser($file, $this->lang_type); $content = $oXmlLangParser->getCompileContent(); - if ($content){ + if ($content) + { $this->loaded_lang_files[] = $_path; eval($content); } @@ -632,7 +692,8 @@ class Context { * @param string $path Path of the language file * @return string file name */ - function _loadXmlLang($path) { + function _loadXmlLang($path) + { if(substr($path,-1)!='/') $path .= '/'; $file = $path.'lang.xml'; @@ -648,13 +709,15 @@ class Context { * @param string $path Path of the language file * @return string file name */ - function _loadPhpLang($path) { + function _loadPhpLang($path) + { if(substr($path,-1)!='/') $path .= '/'; $path_tpl = $path.'%s.lang.php'; $file = sprintf($path_tpl, $this->lang_type); $langs = array('ko','en'); // this will be configurable. - while(!is_readable($file) && $langs[0]) { + while(!is_readable($file) && $langs[0]) + { $file = sprintf($path_tpl, array_shift($langs)); } @@ -668,7 +731,8 @@ class Context { * @param string $lang_type Language type. * @return void */ - function setLangType($lang_type = 'ko') { + function setLangType($lang_type = 'ko') + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->lang_type = $lang_type; @@ -682,7 +746,8 @@ class Context { * * @return string Language type */ - function getLangType() { + function getLangType() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->lang_type; } @@ -693,7 +758,8 @@ class Context { * @param string $code Language variable name * @return string If string for the code exists returns it, otherwise returns original code */ - function getLang($code) { + function getLang($code) + { if(!$code) return; if($GLOBALS['lang']->{$code}) return $GLOBALS['lang']->{$code}; return $code; @@ -706,7 +772,8 @@ class Context { * @param string $val `$code`s value * @return void */ - function setLang($code, $val) { + function setLang($code, $val) + { $GLOBALS['lang']->{$code} = $val; } @@ -716,23 +783,26 @@ class Context { * @param object $source_obj Conatins strings to convert * @return object converted object */ - function convertEncoding($source_obj) { + 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', - ); + '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); - foreach($charset_list as $charset) { + foreach($charset_list as $charset) + { $flag = true; - foreach($obj as $key=>$val) { + foreach($obj as $key=>$val) + { if(!$val) continue; if(!is_array($val) && iconv($charset,$charset,$val)!=$val) $flag = false; else if(is_array($val)) @@ -742,7 +812,8 @@ class Context { if($userdata['returnFlag'] === false) $flag = false; } } - if($flag) { + if($flag) + { if($charset == 'UTF-8') return $obj; foreach($obj as $key => $val) { @@ -756,6 +827,7 @@ class Context { return $obj; } + /** * Convert array type variables into UTF-8 * @@ -767,7 +839,7 @@ class Context { */ function arrayConvWalkCallback(&$val, $key = null, &$userdata) { - if (is_array($val)) array_walk($val,'Context::arrayConvWalkCallback',&$userdata); + if (is_array($val)) array_walk($val,'Context::arrayConvWalkCallback', $userdata); else { if(!$userdata['useFlag']) $val = iconv($userdata['charset1'],$userdata['charset2'],$val); @@ -784,7 +856,8 @@ class Context { * @param string $str String to convert * @return string converted string */ - function convertEncodingStr($str) { + function convertEncodingStr($str) + { $obj->str = $str; $obj = Context::convertEncoding($obj); return $obj->str; @@ -796,7 +869,8 @@ class Context { * @param string $method Response method. [HTML|XMLRPC|JSON] * @return void */ - function setResponseMethod($method='HTML') { + function setResponseMethod($method='HTML') + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1, 'JS_CALLBACK' => 1); @@ -808,7 +882,8 @@ class Context { * * @return string Response method. If it's not set, returns request method. */ - function getResponseMethod() { + function getResponseMethod() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if($self->response_method) return $self->response_method; @@ -825,16 +900,17 @@ class Context { * @param string $type Request method. (Optional - GET|POST|XMLRPC|JSON) * @return void */ - function setRequestMethod($type='') { + function setRequestMethod($type='') + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->js_callback_func = isset($_GET['xe_js_callback']) ? $_GET['xe_js_callback'] : $_POST['xe_js_callback']; ($type && $self->request_method=$type) or - (strpos($_SERVER['CONTENT_TYPE'],'json') && $self->request_method='JSON') or - ($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method='XMLRPC') or - ($self->js_callback_func && $self->request_method='JS_CALLBACK') or - ($self->request_method = $_SERVER['REQUEST_METHOD']); + (strpos($_SERVER['CONTENT_TYPE'],'json') && $self->request_method='JSON') or + ($GLOBALS['HTTP_RAW_POST_DATA'] && $self->request_method='XMLRPC') or + ($self->js_callback_func && $self->request_method='JS_CALLBACK') or + ($self->request_method = $_SERVER['REQUEST_METHOD']); } /** @@ -842,10 +918,12 @@ class Context { * * @return void */ - function _setRequestArgument() { + function _setRequestArgument() + { if(!count($_REQUEST)) return; - foreach($_REQUEST as $key => $val) { + foreach($_REQUEST as $key => $val) + { if($val === '' || Context::get($key)) continue; $val = $this->_filterRequestVar($key, $val); @@ -870,13 +948,15 @@ class Context { * * @return void */ - function _setJSONRequestArgument() { + function _setJSONRequestArgument() + { if($this->getRequestMethod() != 'JSON') return; $params = array(); parse_str($GLOBALS['HTTP_RAW_POST_DATA'],$params); - foreach($params as $key => $val) { + foreach($params as $key => $val) + { $val = $this->_filterRequestVar($key, $val,0); $this->set($key, $val, true); } @@ -887,7 +967,8 @@ class Context { * * @return void */ - function _setXmlRpcArgument() { + function _setXmlRpcArgument() + { if($this->getRequestMethod() != 'XMLRPC') return; $oXml = new XmlParser(); $xml_obj = $oXml->parse(); @@ -897,7 +978,8 @@ class Context { unset($params->attrs); if(!count($params)) return; - foreach($params as $key => $obj) { + foreach($params as $key => $obj) + { $val = $this->_filterRequestVar($key, $obj->body,0); $this->set($key, $val, true); } @@ -912,7 +994,8 @@ class Context { * @param string $do_stripslashes Whether to strip slashes * @return mixed filtered value. Type are string or array */ - function _filterRequestVar($key, $val, $do_stripslashes = 1) { + function _filterRequestVar($key, $val, $do_stripslashes = 1) + { $isArray = TRUE; if(!is_array($val)) { @@ -959,7 +1042,8 @@ class Context { * * @return bool True: exists, False: otherwise */ - function isUploaded() { + function isUploaded() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->is_uploaded; } @@ -969,21 +1053,28 @@ class Context { * * @return void */ - function _setUploadedArgument() { + function _setUploadedArgument() + { if($_SERVER['REQUEST_METHOD'] != 'POST') return; if(!preg_match('/multipart\/form-data/i',$_SERVER['CONTENT_TYPE'])) return; if(!$_FILES) return; - foreach($_FILES as $key => $val) { + foreach($_FILES as $key => $val) + { $tmp_name = $val['tmp_name']; - if(!is_array($tmp_name)){ + if(!is_array($tmp_name)) + { if(!$tmp_name || !is_uploaded_file($tmp_name)) continue; $val['name'] = htmlspecialchars($val['name']); $this->set($key, $val, true); $this->is_uploaded = true; - }else { - for($i=0;$i< count($tmp_name);$i++){ - if($val['size'][$i] > 0){ + } + else + { + for($i=0;$i< count($tmp_name);$i++) + { + if($val['size'][$i] > 0) + { $file['name']=$val['name'][$i]; $file['type']=$val['type'][$i]; $file['tmp_name']=$val['tmp_name'][$i]; @@ -1001,7 +1092,8 @@ class Context { * Return request method * @return string Request method type. (Optional - GET|POST|XMLRPC|JSON) */ - function getRequestMethod() { + function getRequestMethod() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->request_method; } @@ -1010,9 +1102,11 @@ class Context { * Return request URL * @return string request URL */ - function getRequestUrl() { + function getRequestUrl() + { static $url = null; - if(is_null($url)) { + if(is_null($url)) + { $url = Context::getRequestUri(); if(count($_GET)) { @@ -1046,7 +1140,8 @@ class Context { * @param bool $autoEncode If true, url encode automatically, detailed. Use this option, $encode value should be true * @return string URL */ - function getUrl($num_args=0, $args_list=array(), $domain = null, $encode = true, $autoEncode = false) { + function getUrl($num_args=0, $args_list=array(), $domain = null, $encode = true, $autoEncode = false) + { static $site_module_info = null; static $current_info = null; @@ -1056,49 +1151,60 @@ class Context { if(is_null($site_module_info)) $site_module_info = Context::get('site_module_info'); // If $domain is set, handle it (if $domain is vid type, remove $domain and handle with $vid) - if($domain && isSiteID($domain)) { + if($domain && isSiteID($domain)) + { $vid = $domain; $domain = ''; } // If $domain, $vid are not set, use current site information - if(!$domain && !$vid) { + if(!$domain && !$vid) + { if($site_module_info->domain && isSiteID($site_module_info->domain)) $vid = $site_module_info->domain; else $domain = $site_module_info->domain; } // if $domain is set, compare current URL. If they are same, remove the domain, otherwise link to the domain. - if($domain) { + if($domain) + { $domain_info = parse_url($domain); if(is_null($current_info)) $current_info = parse_url(($_SERVER['HTTPS']=='on'?'https':'http').'://'.$_SERVER['HTTP_HOST'].getScriptPath()); - if($domain_info['host'].$domain_info['path']==$current_info['host'].$current_info['path']) { + if($domain_info['host'].$domain_info['path']==$current_info['host'].$current_info['path']) + { unset($domain); - } else { + } + else + { $domain = preg_replace('/^(http|https):\/\//i','', trim($domain)); - if(substr($domain,-1) != '/') $domain .= '/'; + if(substr($domain,-1) != '/') $domain .= '/'; } } $get_vars = null; // If there is no GET variables or first argument is '' to reset variables - if(!$self->get_vars || $args_list[0]=='') { + if(!$self->get_vars || $args_list[0]=='') + { // rearrange args_list if(is_array($args_list) && $args_list[0]=='') array_shift($args_list); - } else { + } + else + { // Otherwise, make GET variables into array $get_vars = get_object_vars($self->get_vars); } // arrange args_list - for($i=0,$c=count($args_list);$i<$c;$i=$i+2) { + for($i=0,$c=count($args_list);$i<$c;$i=$i+2) + { $key = $args_list[$i]; $val = trim($args_list[$i+1]); // If value is not set, remove the key - if(!isset($val) || !strlen($val)) { - unset($get_vars[$key]); - continue; + if(!isset($val) || !strlen($val)) + { + unset($get_vars[$key]); + continue; } // set new variables $get_vars[$key] = $val; @@ -1112,18 +1218,20 @@ class Context { // for compatibility to lower versions $act = $get_vars['act']; $act_alias = array( - 'dispMemberFriend'=>'dispCommunicationFriend', - 'dispMemberMessages'=>'dispCommunicationMessages', - 'dispDocumentAdminManageDocument'=>'dispDocumentManageDocument', - 'dispModuleAdminSelectList'=>'dispModuleSelectList' - ); + 'dispMemberFriend'=>'dispCommunicationFriend', + 'dispMemberMessages'=>'dispCommunicationMessages', + 'dispDocumentAdminManageDocument'=>'dispDocumentManageDocument', + 'dispModuleAdminSelectList'=>'dispModuleSelectList' + ); if($act_alias[$act]) $get_vars['act'] = $act_alias[$act]; // organize URL $query = ''; - if(count($get_vars)) { + if(count($get_vars)) + { // if using rewrite mod - if($self->allow_rewrite) { + if($self->allow_rewrite) + { $var_keys = array_keys($get_vars); sort($var_keys); @@ -1139,35 +1247,40 @@ class Context { $is_feed = isset($tmpArray[$act]); $target_map = array( - 'vid'=>$vid, - 'mid'=>$mid, - 'mid.vid'=>"$vid/$mid", + 'vid'=>$vid, + 'mid'=>$mid, + 'mid.vid'=>"$vid/$mid", - 'entry.mid' =>"$mid/entry/".$get_vars['entry'], - 'entry.mid.vid'=>"$vid/$mid/entry/".$get_vars['entry'], + 'entry.mid' =>"$mid/entry/".$get_vars['entry'], + 'entry.mid.vid'=>"$vid/$mid/entry/".$get_vars['entry'], - 'document_srl'=>$srl, - 'document_srl.mid'=>"$mid/$srl", - 'document_srl.vid'=>"$vid/$srl", - 'document_srl.mid.vid'=>"$vid/$mid/$srl", + 'document_srl'=>$srl, + 'document_srl.mid'=>"$mid/$srl", + 'document_srl.vid'=>"$vid/$srl", + 'document_srl.mid.vid'=>"$vid/$mid/$srl", - 'act.mid' =>$is_feed?"$mid/$act":'', - 'act.mid.vid'=>$is_feed?"$vid/$mid/$act":'', - 'act.document_srl.key' =>($act=='trackback')?"$srl/$key/$act":'', - 'act.document_srl.key.mid'=>($act=='trackback')?"$mid/$srl/$key/$act":'', - 'act.document_srl.key.vid'=>($act=='trackback')?"$vid/$srl/$key/$act":'', - 'act.document_srl.key.mid.vid'=>($act=='trackback')?"$vid/$mid/$srl/$key/$act":'' - ); + 'act.mid' =>$is_feed?"$mid/$act":'', + 'act.mid.vid'=>$is_feed?"$vid/$mid/$act":'', + 'act.document_srl.key' =>($act=='trackback')?"$srl/$key/$act":'', + 'act.document_srl.key.mid'=>($act=='trackback')?"$mid/$srl/$key/$act":'', + 'act.document_srl.key.vid'=>($act=='trackback')?"$vid/$srl/$key/$act":'', + 'act.document_srl.key.mid.vid'=>($act=='trackback')?"$vid/$mid/$srl/$key/$act":'' + ); $query = $target_map[$target]; } - if(!$query) { + if(!$query) + { $queries = array(); - foreach($get_vars as $key => $val) { - if(is_array($val) && count($val)) { + foreach($get_vars as $key => $val) + { + if(is_array($val) && count($val)) + { foreach($val as $k => $v) $queries[] = $key.'['.$k.']='.urlencode($v); - } else { + } + else + { $queries[] = $key.'='.@urlencode($val); } } @@ -1177,15 +1290,20 @@ class Context { // If using SSL always $_use_ssl = $self->get('_use_ssl'); - if($_use_ssl == 'always') { + if($_use_ssl == 'always') + { $query = $self->getRequestUri(ENFORCE_SSL, $domain).$query; - // optional SSL use - } elseif($_use_ssl == 'optional') { + // optional SSL use + } + elseif($_use_ssl == 'optional') + { $ssl_mode = RELEASE_SSL; if($get_vars['act'] && $self->isExistsSSLAction($get_vars['act'])) $ssl_mode = ENFORCE_SSL; $query = $self->getRequestUri($ssl_mode, $domain).$query; - // no SSL - } else { + // no SSL + } + else + { // currently on SSL but target is not based on SSL if($_SERVER['HTTPS']=='on' ) $query = $self->getRequestUri(ENFORCE_SSL, $domain).$query; @@ -1195,13 +1313,17 @@ class Context { else $query = getScriptPath().$query; } - if ($encode){ - if($autoEncode){ + if ($encode) + { + if($autoEncode) + { $parsedUrl = parse_url($query); parse_str($parsedUrl['query'], $output); $encode_queries = array(); - foreach($output as $key=>$value){ - if (preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value))){ + foreach($output as $key=>$value) + { + if (preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value))) + { $value = urlencode(htmlspecialchars_decode(urldecode($value))); } $encode_queries[] = $key.'='.$value; @@ -1209,10 +1331,13 @@ class Context { $encode_query = implode('&', $encode_queries); return htmlspecialchars($parsedUrl['path'].'?'.$encode_query); } - else{ + else + { return htmlspecialchars($query); } - }else{ + } + else + { return $query; } } @@ -1224,7 +1349,8 @@ class Context { * @param string $domain Domain * @retrun string converted URL */ - function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) { + function getRequestUri($ssl_mode = FOLLOW_REQUEST_SSL, $domain = null) + { static $url = array(); // HTTP Request가 아니면 패스 @@ -1238,16 +1364,20 @@ class Context { $current_use_ssl = $_SERVER['HTTPS']=='on' ? true : false; - switch($ssl_mode) { + switch($ssl_mode) + { case FOLLOW_REQUEST_SSL: $use_ssl = $current_use_ssl; break; case ENFORCE_SSL: $use_ssl = true; break; case RELEASE_SSL: $use_ssl = false; break; } - if($domain) { + if($domain) + { $target_url = trim($domain); if(substr($target_url,-1) != '/') $target_url.= '/'; - } else { + } + else + { $target_url= $_SERVER['HTTP_HOST'].getScriptPath(); } @@ -1258,11 +1388,14 @@ class Context { unset($url_info['port']); } - if($use_ssl) { + if($use_ssl) + { $port = Context::get('_https_port'); if($port && $port != 443) $url_info['port'] = $port; elseif($url_info['port']==443) unset($url_info['port']); - } else { + } + else + { $port = Context::get('_http_port'); if($port && $port != 80) $url_info['port'] = $port; elseif($url_info['port']==80) unset($url_info['port']); @@ -1281,7 +1414,8 @@ class Context { * @param mixed $set_to_get_vars If not false, Set to get vars. * @return void */ - function set($key, $val, $set_to_get_vars=0) { + function set($key, $val, $set_to_get_vars=0) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->context->{$key} = $val; if($set_to_get_vars === false) return; @@ -1299,7 +1433,8 @@ class Context { * @param string $key Key * @return string Key */ - function get($key) { + function get($key) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if(!isset($self->context->{$key})) return null; @@ -1311,13 +1446,15 @@ class Context { * * @return object */ - function gets() { + function gets() + { $num_args = func_num_args(); if($num_args<1) return; is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $args_list = func_get_args(); - foreach($args_list as $v) { + foreach($args_list as $v) + { $output->{$v} = $self->get($v); } return $output; @@ -1328,7 +1465,8 @@ class Context { * * @return object All data */ - function getAll() { + function getAll() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->context; } @@ -1338,7 +1476,8 @@ class Context { * * @return Object Request variables. */ - function getRequestVars() { + function getRequestVars() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if($self->get_vars) return clone($self->get_vars); return new stdClass; @@ -1373,7 +1512,8 @@ class Context { * * @return string act */ - function getSSLActions() { + function getSSLActions() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->ssl_actions; } @@ -1384,7 +1524,8 @@ class Context { * @param string $action act name * @return bool If SSL exists, return true. */ - function isExistsSSLAction($action) { + function isExistsSSLAction($action) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return isset($self->ssl_actions[$action]); } @@ -1396,7 +1537,8 @@ class Context { * @param string $file file path * @return string normalized file path */ - function normalizeFilePath($file) { + function normalizeFilePath($file) + { if(strpos($file,'://')===false && $file{0}!='/' && $file{0}!='.') $file = './'.$file; $file = preg_replace('@/\./|(?oFrontEndFileHandler->unloadFile($file, $targetie); } @@ -1526,7 +1672,8 @@ class Context { * * @return void */ - function unloadAllJsFiles() { + function unloadAllJsFiles() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->oFrontEndFileHandler->unloadAllFiles('js'); } @@ -1538,7 +1685,8 @@ class Context { * @param string $filename File name * @return void */ - function addJsFilter($path, $filename) { + function addJsFilter($path, $filename) + { $oXmlFilter = new XmlJSFilter($path, $filename); $oXmlFilter->compile(); } @@ -1548,8 +1696,9 @@ class Context { * @deprecated * @param array $files File list * @return array File list - */ - function _getUniqueFileList($files) { + */ + function _getUniqueFileList($files) + { ksort($files); $files = array_values($files); $filenames = array(); @@ -1569,7 +1718,8 @@ class Context { * @param string $type Added position. (head:.., body:..) * @return array Returns javascript file list. Array contains file, targetie. */ - function getJsFile($type='head') { + function getJsFile($type='head') + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->oFrontEndFileHandler->getJsFileList($type); } @@ -1586,7 +1736,8 @@ class Context { * @return void * */ - function addCSSFile($file, $optimized=false, $media='all', $targetie='',$index=0) { + function addCSSFile($file, $optimized=false, $media='all', $targetie='',$index=0) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index)); } @@ -1601,7 +1752,8 @@ class Context { * @param string $targetie target IE * @return void */ - function unloadCSSFile($file, $optimized = false, $media = 'all', $targetie = '') { + function unloadCSSFile($file, $optimized = false, $media = 'all', $targetie = '') + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->oFrontEndFileHandler->unloadFile($file, $targetie, $media); } @@ -1611,7 +1763,8 @@ class Context { * * @return void */ - function unloadAllCSSFiles() { + function unloadAllCSSFiles() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->oFrontEndFileHandler->unloadAllFiles('css'); } @@ -1621,7 +1774,8 @@ class Context { * * @return array Returns css file list. Array contains file, media, targetie. */ - function getCSSFile() { + function getCSSFile() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->oFrontEndFileHandler->getCssFileList(); } @@ -1632,7 +1786,8 @@ class Context { * @param string $plugin_name plugin name * @return void */ - function loadJavascriptPlugin($plugin_name) { + function loadJavascriptPlugin($plugin_name) + { static $loaded_plugins = array(); is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); @@ -1646,7 +1801,8 @@ class Context { if(!is_readable($info_file)) return; $list = file($info_file); - foreach($list as $filename) { + foreach($list as $filename) + { $filename = trim($filename); if(!$filename) continue; @@ -1664,7 +1820,8 @@ class Context { * @param string $header add html code before . * @return void */ - function addHtmlHeader($header) { + function addHtmlHeader($header) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->html_header .= "\n".$header; } @@ -1680,7 +1837,8 @@ class Context { * * @return string Added html code before */ - function getHtmlHeader() { + function getHtmlHeader() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->html_header; } @@ -1690,7 +1848,8 @@ class Context { * * @param string $class_name class name */ - function addBodyClass($class_name) { + function addBodyClass($class_name) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->body_class[] = $class_name; } @@ -1700,7 +1859,8 @@ class Context { * * @return string Return class to html body */ - function getBodyClass() { + function getBodyClass() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->body_class = array_unique($self->body_class); @@ -1712,7 +1872,8 @@ class Context { * * @param string $header Add html code after */ - function addBodyHeader($header) { + function addBodyHeader($header) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->body_header .= "\n".$header; } @@ -1722,7 +1883,8 @@ class Context { * * @return string Added html code after */ - function getBodyHeader() { + function getBodyHeader() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->body_header; } @@ -1732,7 +1894,8 @@ class Context { * * @param string $footer Add html code before */ - function addHtmlFooter($footer) { + function addHtmlFooter($footer) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $self->html_footer .= ($self->Htmlfooter?"\n":'').$footer; } @@ -1742,7 +1905,8 @@ class Context { * * @return string Added html code before */ - function getHtmlFooter() { + function getHtmlFooter() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); return $self->html_footer; } @@ -1752,7 +1916,8 @@ class Context { * * @retrun string The path of the config file that contains database settings */ - function getConfigFile() { + function getConfigFile() + { return _XE_PATH_.'files/config/db.config.php'; } @@ -1761,7 +1926,8 @@ class Context { * * @return string The path of the config file that contains FTP settings */ - function getFTPConfigFile() { + function getFTPConfigFile() + { return _XE_PATH_.'files/config/ftp.config.php'; } @@ -1770,7 +1936,8 @@ class Context { * * @return bool True if the config file exists, otherwise false. */ - function isInstalled() { + function isInstalled() + { return FileHandler::hasContent(Context::getConfigFile()); } @@ -1780,7 +1947,8 @@ class Context { * @param string Transforms codes * @return string Transforms codes */ - function transContent($content) { + function transContent($content) + { return $content; } @@ -1789,7 +1957,8 @@ class Context { * * @return bool True if it is allowed to use rewrite mod, otherwise false */ - function isAllowRewrite() { + function isAllowRewrite() + { $oContext = &Context::getInstance(); return $oContext->allow_rewrite; } @@ -1800,7 +1969,8 @@ class Context { * @param string $path URL path * @return string Converted path */ - function pathToUrl($path) { + function pathToUrl($path) + { $xe = _XE_PATH_; $path = strtr($path, "\\", "/"); @@ -1812,18 +1982,21 @@ class Context { if(!$_base[count($_base)-1]) array_pop($_base); - foreach($_xe as $idx=>$dir) { + foreach($_xe as $idx=>$dir) + { if($_path[0] != $dir) break; array_shift($_path); } $idx = count($_xe) - $idx - 1; - while($idx--) { + while($idx--) + { if(count($_base)) array_shift($_base); else array_unshift($_base, '..'); } - if(count($_base)) { + if(count($_base)) + { array_unshift($_path, implode('/', $_base)); } @@ -1836,7 +2009,8 @@ class Context { * Get meta tag * @return array The list of meta tags */ - function getMetaTag() { + function getMetaTag() + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); if(!is_array($self->meta_tags)) $self->meta_tags = array(); @@ -1844,7 +2018,8 @@ class Context { $ret = array(); $map = &$self->meta_tags; - foreach($map as $key=>$val) { + foreach($map as $key=>$val) + { list($name, $is_http_equiv) = explode("\t", $key); $ret[] = array('name'=>$name, 'is_http_equiv'=>$is_http_equiv, 'content' => $val); } @@ -1860,7 +2035,8 @@ class Context { * @param mixed $is_http_equiv value of http_equiv * @return void */ - function addMetaTag($name, $content, $is_http_equiv = false) { + function addMetaTag($name, $content, $is_http_equiv = false) + { is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); $key = $name."\t".($is_http_equiv ? '1' : '0'); @@ -1869,3 +2045,6 @@ class Context { $map[$key] = $content; } } + +/* End of file Context.class.php */ +/* Location: ./classes/context/Context.class.php */