diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 071c08fdd..25c9d83cb 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -1,7 +1,8 @@ .. * @var string */ var $html_header = NULL; + /** * class names of * @var array */ - var $body_class = array(); + var $body_class = array(); + /** * codes after * @var string */ var $body_header = NULL; + /** * class names before * @var string */ var $html_footer = NULL; + /** * path of Xpress Engine * @var string */ var $path = ''; - // language information - it is changed by HTTP_USER_AGENT or user's cookie /** * language type * @var string */ var $lang_type = ''; + /** * contains language-specific data * @var object */ var $lang = NULL; + /** * list of loaded languages (to avoid re-loading them) * @var array */ var $loaded_lang_files = array(); + /** * site's browser title * @var string */ var $site_title = ''; + /** * variables from GET or form submit * @var mixed */ var $get_vars = NULL; + /** * Checks uploaded * @var bool true if attached file exists @@ -141,17 +161,9 @@ class Context function &getInstance() { static $theInstance = null; - if(!$theInstance) $theInstance = new Context(); - - // include ssl action cache file - $theInstance->sslActionCacheFile = FileHandler::getRealPath($theInstance->sslActionCacheFile); - if(is_readable($theInstance->sslActionCacheFile)) + if(!$theInstance) { - require_once($theInstance->sslActionCacheFile); - if(isset($sslActions)) - { - $theInstance->ssl_actions = $sslActions; - } + $theInstance = new Context(); } return $theInstance; @@ -165,6 +177,18 @@ class Context function Context() { $this->oFrontEndFileHandler = new FrontEndFileHandler(); + $this->get_vars = new stdClass(); + + // include ssl action cache file + $this->sslActionCacheFile = FileHandler::getRealPath($theInstance->sslActionCacheFile); + if(is_readable($this->sslActionCacheFile)) + { + require_once($this->sslActionCacheFile); + if(isset($sslActions)) + { + $this->ssl_actions = $sslActions; + } + } } /** @@ -192,8 +216,14 @@ class Context // If XE is installed, get virtual site information if(Context::isInstalled()) { - $oModuleModel = &getModel('module'); + $oModuleModel = getModel('module'); $site_module_info = $oModuleModel->getDefaultMid(); + + if(!isset($site_module_info)) + { + $site_module_info = new stdClass(); + } + // 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) { @@ -201,11 +231,25 @@ class Context } $this->set('site_module_info', $site_module_info); - if($site_module_info->site_srl && isSiteID($site_module_info->domain)) $this->set('vid', $site_module_info->domain, true); + if($site_module_info->site_srl && isSiteID($site_module_info->domain)) + { + $this->set('vid', $site_module_info->domain, true); + } + + if(!isset($this->db_info)) + { + $this->db_info = new stdClass(); + } $this->db_info->lang_type = $site_module_info->default_language; - if(!$this->db_info->lang_type) $this->db_info->lang_type = 'en'; - if(!$this->db_info->use_db_session) $this->db_info->use_db_session = 'N'; + if(!$this->db_info->lang_type) + { + $this->db_info->lang_type = 'en'; + } + if(!$this->db_info->use_db_session) + { + $this->db_info->use_db_session = 'N'; + } } // Load Language File @@ -217,7 +261,7 @@ class Context $this->lang_type = $this->get('l'); if($_COOKIE['lang_type'] != $this->lang_type) { - setcookie('lang_type', $this->lang_type, time()+3600*24*1000, '/'); + setcookie('lang_type', $this->lang_type, time() + 3600 * 24 * 1000, '/'); } } elseif($_COOKIE['lang_type']) @@ -226,43 +270,50 @@ class Context } // If it's not exists, follow default language type set in db_info - if(!$this->lang_type) $this->lang_type = $this->db_info->lang_type; + if(!$this->lang_type) + { + $this->lang_type = $this->db_info->lang_type; + } // if still lang_type has not been set or has not-supported type , set as English. - if(!$this->lang_type) $this->lang_type = 'en'; - if(is_array($lang_supported)&&!isset($lang_supported[$this->lang_type])) $this->lang_type = 'en'; + if(!$this->lang_type) + { + $this->lang_type = 'en'; + } + if(is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) + { + $this->lang_type = 'en'; + } $this->set('lang_supported', $lang_supported); $this->setLangType($this->lang_type); // load module module's language file according to language setting - $this->loadLang(_XE_PATH_.'modules/module/lang'); + $this->loadLang(_XE_PATH_ . 'modules/module/lang'); // set session handler if(Context::isInstalled() && $this->db_info->use_db_session == 'Y') { - $oSessionModel = &getModel('session'); - $oSessionController = &getController('session'); + $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); + if($sess = $_POST[session_name()]) + { + session_id($sess); + } // set authentication information in Context and session if(Context::isInstalled()) { - $oModuleModel = &getModel('module'); + $oModuleModel = getModel('module'); $oModuleModel->loadModuleExtends(); - $oMemberModel = &getModel('member'); - $oMemberController = &getController('member'); + $oMemberModel = getModel('member'); + $oMemberController = getController('member'); if($oMemberController && $oMemberModel) { @@ -277,50 +328,56 @@ class Context $oMemberController->doAutologin(); } - $this->set('is_logged', $oMemberModel->isLogged() ); - $this->set('logged_info', $oMemberModel->getLoggedInfo() ); + $this->set('is_logged', $oMemberModel->isLogged()); + $this->set('logged_info', $oMemberModel->getLoggedInfo()); } } // load common language file $this->lang = &$GLOBALS['lang']; - $this->loadLang(_XE_PATH_.'common/lang/'); + $this->loadLang(_XE_PATH_ . 'common/lang/'); // check if using rewrite module - if(file_exists(_XE_PATH_.'.htaccess')&&$this->db_info->use_rewrite == 'Y') $this->allow_rewrite = true; - else $this->allow_rewrite = false; + if(file_exists(_XE_PATH_ . '.htaccess') && $this->db_info->use_rewrite == 'Y') + { + $this->allow_rewrite = true; + } + 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) + foreach($this->get_vars as $key => $val) { - if(is_array($val)&&count($val)) + if(is_array($val) && count($val)) { foreach($val as $k => $v) { - $url .= ($url?'&':'').$key.'['.$k.']='.urlencode($v); + $url .= ($url ? '&' : '') . $key . '[' . $k . ']=' . urlencode($v); } } - elseif ($val) + elseif($val) { - $url .= ($url?'&':'').$key.'='.urlencode($val); + $url .= ($url ? '&' : '') . $key . '=' . urlencode($val); } } - $this->set('current_url',sprintf('%s?%s', Context::getRequestUri(), $url)); + $this->set('current_url', sprintf('%s?%s', Context::getRequestUri(), $url)); } else { - $this->set('current_url',$this->getUrl()); + $this->set('current_url', $this->getUrl()); } } else { - $this->set('current_url',Context::getRequestUri()); + $this->set('current_url', Context::getRequestUri()); } - $this->set('request_uri',Context::getRequestUri()); + $this->set('request_uri', Context::getRequestUri()); } /** @@ -331,11 +388,17 @@ class Context function close() { // Session Close - if(function_exists('session_write_close')) session_write_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(); + $oDB = DB::getInstance(); + if(is_object($oDB) && method_exists($oDB, 'close')) + { + $oDB->close(); + } } /** @@ -345,52 +408,74 @@ class Context */ function loadDBInfo() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - if(!$self->isInstalled()) return; + if(!$self->isInstalled()) + { + return; + } $config_file = $self->getConfigFile(); - if(is_readable($config_file)) @include($config_file); + 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"] .= '_'; + $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); - $oInstallController = &getController('install'); + $oInstallController = getController('install'); $oInstallController->makeConfigFile(); } - if(!$db_info->use_prepared_statements) + if(!$db_info->use_prepared_statements) { $db_info->use_prepared_statements = 'Y'; } - if(!$db_info->time_zone) $db_info->time_zone = date('O'); + if(!$db_info->time_zone) + $db_info->time_zone = date('O'); $GLOBALS['_time_zone'] = $db_info->time_zone; - if($db_info->qmail_compatibility != 'Y') $db_info->qmail_compatibility = 'N'; + if($db_info->qmail_compatibility != 'Y') + $db_info->qmail_compatibility = 'N'; $GLOBALS['_qmail_compatibility'] = $db_info->qmail_compatibility; - if(!$db_info->use_db_session) $db_info->use_db_session = 'N'; - if(!$db_info->use_ssl) $db_info->use_ssl = 'none'; + if(!$db_info->use_db_session) + $db_info->use_db_session = 'N'; + if(!$db_info->use_ssl) + $db_info->use_ssl = 'none'; $this->set('_use_ssl', $db_info->use_ssl); - if($db_info->http_port) $self->set('_http_port', $db_info->http_port); - if($db_info->https_port) $self->set('_https_port', $db_info->https_port); + if($db_info->http_port) + $self->set('_http_port', $db_info->http_port); + if($db_info->https_port) + $self->set('_https_port', $db_info->https_port); $self->setDBInfo($db_info); } @@ -402,7 +487,7 @@ class Context */ function getDBType() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->db_info->master_db["db_type"]; } @@ -414,7 +499,7 @@ class Context */ function setDBInfo($db_info) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->db_info = $db_info; } @@ -425,7 +510,7 @@ class Context */ function getDBInfo() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->db_info; } @@ -461,10 +546,10 @@ class Context static $lang_supported = null; if(!$lang_supported) { - $langs = file(_XE_PATH_.'common/lang/lang.info'); + $langs = file(_XE_PATH_ . 'common/lang/lang.info'); foreach($langs as $val) { - list($lang_prefix, $lang_text) = explode(',',$val); + list($lang_prefix, $lang_text) = explode(',', $val); $lang_text = trim($lang_text); $lang_supported[$lang_prefix] = $lang_text; } @@ -482,11 +567,11 @@ class Context static $lang_selected = null; if(!$lang_selected) { - $orig_lang_file = _XE_PATH_.'common/lang/lang.info'; - $selected_lang_file = _XE_PATH_.'files/config/lang_selected.info'; + $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)) { - $old_selected_lang_file = _XE_PATH_.'files/cache/lang_selected.info'; + $old_selected_lang_file = _XE_PATH_ . 'files/cache/lang_selected.info'; FileHandler::moveFile($old_selected_lang_file, $selected_lang_file); } @@ -501,7 +586,7 @@ class Context $langs = file($selected_lang_file); foreach($langs as $val) { - list($lang_prefix, $lang_text) = explode(',',$val); + list($lang_prefix, $lang_text) = explode(',', $val); $lang_text = trim($lang_text); $lang_selected[$lang_prefix] = $lang_text; } @@ -518,14 +603,26 @@ class Context 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); - if(Context::getRequestMethod()!='GET' || !Context::isInstalled() || isset($checkActList[Context::get('act')])) return true; + if($this->db_info->use_sso != 'Y' || isCrawler()) + { + return true; + } + $checkActList = array('rss' => 1, 'atom' => 1); + if(Context::getRequestMethod() != 'GET' || !Context::isInstalled() || isset($checkActList[Context::get('act')])) + { + return true; + } // pass if default URL is not set $default_url = trim($this->db_info->default_url); - if(!$default_url) return true; - if(substr($default_url,-1)!='/') $default_url .= '/'; + if(!$default_url) + { + return true; + } + if(substr($default_url, -1) != '/') + { + $default_url .= '/'; + } // for sites recieving SSO valdiation if($default_url == Context::getRequestUri()) @@ -534,9 +631,9 @@ class Context { $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); + $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; } // for sites requesting SSO validation @@ -549,16 +646,16 @@ class Context $session_name = Context::get('SSOID'); setcookie(session_name(), $session_name); - $url = preg_replace('/([\?\&])$/','',str_replace('SSOID='.$session_name,'',Context::getRequestUrl())); - header('location:'.$url); + $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')) + else if($_COOKIE['sso'] != md5(Context::getRequestUri()) && !Context::get('SSOID')) { - setcookie('sso',md5(Context::getRequestUri()),0,'/'); + setcookie('sso', md5(Context::getRequestUri()), 0, '/'); $url = sprintf("%s?default_url=%s", $default_url, base64_encode(Context::getRequestUrl())); - header('location:'.$url); + header('location:' . $url); return false; } } @@ -574,7 +671,10 @@ class Context function isFTPRegisted() { $ftp_config_file = Context::getFTPConfigFile(); - if(file_exists($ftp_config_file)) return true; + if(file_exists($ftp_config_file)) + { + return true; + } return false; } @@ -585,8 +685,11 @@ class Context */ function getFTPInfo() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - if(!$self->isFTPRegisted()) return null; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + if(!$self->isFTPRegisted()) + { + return null; + } $ftp_config_file = $self->getFTPConfigFile(); @include($ftp_config_file); @@ -602,11 +705,20 @@ class Context */ function addBrowserTitle($site_title) { - if(!$site_title) return; - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + if(!$site_title) + { + return; + } + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - if($self->site_title) $self->site_title .= ' - '.$site_title; - else $self->site_title = $site_title; + if($self->site_title) + { + $self->site_title .= ' - ' . $site_title; + } + else + { + $self->site_title = $site_title; + } } /** @@ -617,8 +729,11 @@ class Context */ function setBrowserTitle($site_title) { - if(!$site_title) return; - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + if(!$site_title) + { + return; + } + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->site_title = $site_title; } @@ -629,18 +744,22 @@ class Context */ function getBrowserTitle() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - $oModuleController = &getController('module'); + $oModuleController = getController('module'); $oModuleController->replaceDefinedLangCode($self->site_title); return htmlspecialchars($self->site_title); } + /** * Get browser title * @deprecated */ - function _getBrowserTitle() { return $this->getBrowserTitle(); } + function _getBrowserTitle() + { + return $this->getBrowserTitle(); + } /** * Load language file according to language type @@ -652,17 +771,32 @@ class Context { global $lang; - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - if(!is_object($lang)) $lang = new stdClass; - if(!$self->lang_type) return; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + if(!is_object($lang)) + { + $lang = new stdClass; + } + if(!$self->lang_type) + { + return; + } $filename = $self->_loadXmlLang($path); - if(!$filename) $filename = $self->_loadPhpLang($path); + if(!$filename) + { + $filename = $self->_loadPhpLang($path); + } - if(!is_array($self->loaded_lang_files)) $self->loaded_lang_files = array(); - if(in_array($filename, $self->loaded_lang_files)) return; + 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); @@ -683,17 +817,23 @@ class Context { global $lang; - $_path = 'eval://'.$path; + $_path = 'eval://' . $path; - if(in_array($_path, $this->loaded_lang_files)) return; + if(in_array($_path, $this->loaded_lang_files)) + { + return; + } - if(substr($path,-1)!='/') $path .= '/'; - $file = $path.'lang.xml'; + if(substr($path, -1) != '/') + { + $path .= '/'; + } + $file = $path . 'lang.xml'; $oXmlLangParser = new XmlLangParser($file, $this->lang_type); $content = $oXmlLangParser->getCompileContent(); - if ($content) + if($content) { $this->loaded_lang_files[] = $_path; eval($content); @@ -708,8 +848,11 @@ class Context */ function _loadXmlLang($path) { - if(substr($path,-1)!='/') $path .= '/'; - $file = $path.'lang.xml'; + if(substr($path, -1) != '/') + { + $path .= '/'; + } + $file = $path . 'lang.xml'; $oXmlLangParser = new XmlLangParser($file, $this->lang_type); $file = $oXmlLangParser->compile(); @@ -725,17 +868,23 @@ class Context */ function _loadPhpLang($path) { - if(substr($path,-1)!='/') $path .= '/'; - $path_tpl = $path.'%s.lang.php'; + 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. + $langs = array('ko', 'en'); // this will be configurable. while(!is_readable($file) && $langs[0]) { $file = sprintf($path_tpl, array_shift($langs)); } - if(!is_readable($file)) return false; + if(!is_readable($file)) + { + return false; + } return $file; } @@ -747,7 +896,7 @@ class Context */ function setLangType($lang_type = 'ko') { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->lang_type = $lang_type; $self->set('lang_type', $lang_type); @@ -762,7 +911,7 @@ class Context */ function getLangType() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->lang_type; } @@ -774,8 +923,14 @@ class Context */ function getLang($code) { - if(!$code) return; - if($GLOBALS['lang']->{$code}) return $GLOBALS['lang']->{$code}; + if(!$code) + { + return; + } + if($GLOBALS['lang']->{$code}) + { + return $GLOBALS['lang']->{$code}; + } return $code; } @@ -788,6 +943,10 @@ class Context */ function setLang($code, $val) { + if(isset($GLOBALS['lang'])) + { + $GLOBALS['lang'] = new stdClass(); + } $GLOBALS['lang']->{$code} = $val; } @@ -800,17 +959,17 @@ class Context 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); + $obj = clone $source_obj; foreach($charset_list as $charset) { @@ -818,7 +977,10 @@ class Context $flag = Context::checkConvertFlag($flag = true); if($flag) { - if($charset == 'UTF-8') return $obj; + if($charset == 'UTF-8') + { + return $obj; + } array_walk($obj,'Context::doConvertEncoding',$charset); return $obj; } @@ -879,6 +1041,7 @@ class Context */ function convertEncodingStr($str) { + $obj = new stdClass(); $obj->str = $str; $obj = Context::convertEncoding($obj); return $obj->str; @@ -890,11 +1053,11 @@ 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(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - $methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1, 'JS_CALLBACK' => 1); + $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); $self->response_method = isset($methods[$method]) ? $method : 'HTML'; } @@ -905,12 +1068,15 @@ class Context */ function getResponseMethod() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - if($self->response_method) return $self->response_method; + if($self->response_method) + { + return $self->response_method; + } - $method = $self->getRequestMethod(); - $methods = array('HTML'=>1, 'XMLRPC'=>1, 'JSON'=>1, 'JS_CALLBACK' => 1); + $method = $self->getRequestMethod(); + $methods = array('HTML' => 1, 'XMLRPC' => 1, 'JSON' => 1, 'JS_CALLBACK' => 1); return isset($methods[$method]) ? $method : 'HTML'; } @@ -921,17 +1087,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(); + 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']); + ($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']); } /** @@ -941,17 +1107,35 @@ class Context */ function _setRequestArgument() { - if(!count($_REQUEST)) return; + if(!count($_REQUEST)) + { + return; + } foreach($_REQUEST as $key => $val) { - if($val === '' || Context::get($key)) continue; + if($val === '' || Context::get($key)) + { + continue; + } $val = $this->_filterRequestVar($key, $val); - if($this->getRequestMethod()=='GET'&&isset($_GET[$key])) $set_to_vars = true; - elseif($this->getRequestMethod()=='POST'&&isset($_POST[$key])) $set_to_vars = true; - elseif($this->getRequestMethod()=='JS_CALLBACK' && (isset($_GET[$key]) || isset($_POST[$key]))) $set_to_vars = true; - else $set_to_vars = false; + if($this->getRequestMethod() == 'GET' && isset($_GET[$key])) + { + $set_to_vars = true; + } + elseif($this->getRequestMethod() == 'POST' && isset($_POST[$key])) + { + $set_to_vars = true; + } + elseif($this->getRequestMethod() == 'JS_CALLBACK' && (isset($_GET[$key]) || isset($_POST[$key]))) + { + $set_to_vars = true; + } + else + { + $set_to_vars = false; + } if($set_to_vars) { @@ -992,14 +1176,17 @@ class Context */ function _setJSONRequestArgument() { - if($this->getRequestMethod() != 'JSON') return; + if($this->getRequestMethod() != 'JSON') + { + return; + } $params = array(); - parse_str($GLOBALS['HTTP_RAW_POST_DATA'],$params); + parse_str($GLOBALS['HTTP_RAW_POST_DATA'], $params); foreach($params as $key => $val) { - $val = $this->_filterRequestVar($key, $val,0); + $val = $this->_filterRequestVar($key, $val, 0); $this->set($key, $val, true); } } @@ -1011,7 +1198,10 @@ class Context */ function _setXmlRpcArgument() { - if($this->getRequestMethod() != 'XMLRPC') return; + if($this->getRequestMethod() != 'XMLRPC') + { + return; + } $oXml = new XmlParser(); $xml_obj = $oXml->parse(); @@ -1019,10 +1209,13 @@ class Context unset($params->node_name); unset($params->attrs); - if(!count($params)) return; + if(!count($params)) + { + return; + } foreach($params as $key => $obj) { - $val = $this->_filterRequestVar($key, $obj->body,0); + $val = $this->_filterRequestVar($key, $obj->body, 0); $this->set($key, $val, true); } } @@ -1049,7 +1242,7 @@ class Context { if($key === 'page' || $key === 'cpage' || substr($key, -3) === 'srl') { - $val[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int)$v : $v; + $val[$k] = !preg_match('/^[0-9,]+$/', $v) ? (int) $v : $v; } elseif($key === 'mid' || $key === 'vid' || $key === 'search_keyword') { @@ -1086,7 +1279,7 @@ class Context */ function isUploaded() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->is_uploaded; } @@ -1097,31 +1290,43 @@ class Context */ function _setUploadedArgument() { - if($_SERVER['REQUEST_METHOD'] != 'POST') return; - if(!preg_match('/multipart\/form-data/i',$_SERVER['CONTENT_TYPE'])) return; - if(!$_FILES) return; + 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) { $tmp_name = $val['tmp_name']; if(!is_array($tmp_name)) { - if(!$tmp_name || !is_uploaded_file($tmp_name)) continue; + 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++) + 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]; - $file['error']=$val['error'][$i]; - $file['size']=$val['size'][$i]; + $file['name'] = $val['name'][$i]; + $file['type'] = $val['type'][$i]; + $file['tmp_name'] = $val['tmp_name'][$i]; + $file['error'] = $val['error'][$i]; + $file['size'] = $val['size'][$i]; $files[] = $file; } } @@ -1136,7 +1341,7 @@ class Context */ function getRequestMethod() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->request_method; } @@ -1168,7 +1373,7 @@ class Context */ function getJSCallbackFunc() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->js_callback_func; } @@ -1182,15 +1387,18 @@ 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; - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); // retrieve virtual site information - if(is_null($site_module_info)) $site_module_info = Context::get('site_module_info'); + 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)) @@ -1202,33 +1410,48 @@ class Context // If $domain, $vid are not set, use current site information 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($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) { $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(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']) { unset($domain); } else { - $domain = preg_replace('/^(http|https):\/\//i','', trim($domain)); - if(substr($domain,-1) != '/') $domain .= '/'; + $domain = preg_replace('/^(http|https):\/\//i', '', trim($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); + if(is_array($args_list) && $args_list[0] == '') + { + array_shift($args_list); + } } else { @@ -1237,10 +1460,10 @@ class Context } // 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]); + $val = trim($args_list[$i + 1]); // If value is not set, remove the key if(!isset($val) || !strlen($val)) @@ -1254,18 +1477,27 @@ class Context // remove vid, rnd unset($get_vars['rnd']); - if($vid) $get_vars['vid'] = $vid; - else unset($get_vars['vid']); + if($vid) + { + $get_vars['vid'] = $vid; + } + else + { + unset($get_vars['vid']); + } // for compatibility to lower versions $act = $get_vars['act']; $act_alias = array( - 'dispMemberFriend'=>'dispCommunicationFriend', - 'dispMemberMessages'=>'dispCommunicationMessages', - 'dispDocumentAdminManageDocument'=>'dispDocumentManageDocument', - 'dispModuleAdminSelectList'=>'dispModuleSelectList' - ); - if($act_alias[$act]) $get_vars['act'] = $act_alias[$act]; + 'dispMemberFriend' => 'dispCommunicationFriend', + 'dispMemberMessages' => 'dispCommunicationMessages', + 'dispDocumentAdminManageDocument' => 'dispDocumentManageDocument', + 'dispModuleAdminSelectList' => 'dispModuleSelectList' + ); + if($act_alias[$act]) + { + $get_vars['act'] = $act_alias[$act]; + } // organize URL $query = ''; @@ -1285,31 +1517,28 @@ class Context $key = $get_vars['key']; $srl = $get_vars['document_srl']; - $tmpArray = array('rss'=>1, 'atom'=>1, 'api'=>1); + $tmpArray = array('rss' => 1, 'atom' => 1, 'api' => 1); $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'], + '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" : '' + ); - '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", - - '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]; + $query = $target_map[$target]; } if(!$query) @@ -1319,14 +1548,20 @@ class Context { if(is_array($val) && count($val)) { - foreach($val as $k => $v) $queries[] = $key.'['.$k.']='.urlencode($v); + foreach($val as $k => $v) + { + $queries[] = $key . '[' . $k . ']=' . urlencode($v); + } } else { - $queries[] = $key.'='.@urlencode($val); + $queries[] = $key . '=' . @urlencode($val); } } - if(count($queries)) $query = 'index.php?'.implode('&', $queries); + if(count($queries)) + { + $query = 'index.php?' . implode('&', $queries); + } } } @@ -1334,44 +1569,56 @@ class Context $_use_ssl = $self->get('_use_ssl'); if($_use_ssl == 'always') { - $query = $self->getRequestUri(ENFORCE_SSL, $domain).$query; + $query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query; // 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; + if($get_vars['act'] && $self->isExistsSSLAction($get_vars['act'])) + { + $ssl_mode = ENFORCE_SSL; + } + $query = $self->getRequestUri($ssl_mode, $domain) . $query; // no SSL } else { // currently on SSL but target is not based on SSL - if($_SERVER['HTTPS']=='on' ) $query = $self->getRequestUri(ENFORCE_SSL, $domain).$query; + if($_SERVER['HTTPS'] == 'on') + { + $query = $self->getRequestUri(ENFORCE_SSL, $domain) . $query; + } // if $domain is set - else if($domain) $query = $self->getRequestUri(FOLLOW_REQUEST_SSL, $domain).$query; + else if($domain) + { + $query = $self->getRequestUri(FOLLOW_REQUEST_SSL, $domain) . $query; + } - else $query = getScriptPath().$query; + else + { + $query = getScriptPath() . $query; + } } - if ($encode) + if($encode) { if($autoEncode) { $parsedUrl = parse_url($query); parse_str($parsedUrl['query'], $output); $encode_queries = array(); - foreach($output as $key=>$value) + foreach($output as $key => $value) { - if (preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value))) + if(preg_match('/&([a-z]{2,}|#\d+);/', urldecode($value))) { $value = urlencode(htmlspecialchars_decode(urldecode($value))); } - $encode_queries[] = $key.'='.$value; + $encode_queries[] = $key . '=' . $value; } $encode_query = implode('&', $encode_queries); - return htmlspecialchars($parsedUrl['path'].'?'.$encode_query); + return htmlspecialchars($parsedUrl['path'] . '?' . $encode_query); } else { @@ -1380,7 +1627,7 @@ class Context } else { - return $query; + return $query; } } @@ -1396,34 +1643,56 @@ class Context static $url = array(); // HTTP Request가 아니면 패스 - if(!isset($_SERVER['SERVER_PROTOCOL'])) return ; - if(Context::get('_use_ssl') == 'always') $ssl_mode = ENFORCE_SSL; + if(!isset($_SERVER['SERVER_PROTOCOL'])) + { + return; + } - if($domain) $domain_key = md5($domain); - else $domain_key = 'default'; + if(Context::get('_use_ssl') == 'always') + { + $ssl_mode = ENFORCE_SSL; + } - if(isset($url[$ssl_mode][$domain_key])) return $url[$ssl_mode][$domain_key]; + if($domain) + { + $domain_key = md5($domain); + } + else + { + $domain_key = 'default'; + } - $current_use_ssl = $_SERVER['HTTPS']=='on' ? true : false; + if(isset($url[$ssl_mode][$domain_key])) + { + return $url[$ssl_mode][$domain_key]; + } + + $current_use_ssl = $_SERVER['HTTPS'] == 'on' ? true : false; 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; + 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) { $target_url = trim($domain); - if(substr($target_url,-1) != '/') $target_url.= '/'; + if(substr($target_url, -1) != '/') + { + $target_url.= '/'; + } } else { - $target_url= $_SERVER['HTTP_HOST'].getScriptPath(); + $target_url = $_SERVER['HTTP_HOST'] . getScriptPath(); } - $url_info = parse_url('http://'.$target_url); + $url_info = parse_url('http://' . $target_url); if($current_use_ssl != $use_ssl) { @@ -1433,17 +1702,29 @@ class Context 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']); + if($port && $port != 443) + { + $url_info['port'] = $port; + } + elseif($url_info['port'] == 443) + { + unset($url_info['port']); + } } else { $port = Context::get('_http_port'); - if($port && $port != 80) $url_info['port'] = $port; - elseif($url_info['port']==80) unset($url_info['port']); + if($port && $port != 80) + { + $url_info['port'] = $port; + } + elseif($url_info['port'] == 80) + { + unset($url_info['port']); + } } - $url[$ssl_mode][$domain_key] = sprintf('%s://%s%s%s',$use_ssl?'https':$url_info['scheme'], $url_info['host'], $url_info['port']&&$url_info['port']!=80?':'.$url_info['port']:'',$url_info['path']); + $url[$ssl_mode][$domain_key] = sprintf('%s://%s%s%s', $use_ssl ? 'https' : $url_info['scheme'], $url_info['host'], $url_info['port'] && $url_info['port'] != 80 ? ':' . $url_info['port'] : '', $url_info['path']); return $url[$ssl_mode][$domain_key]; } @@ -1456,17 +1737,23 @@ 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(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->context->{$key} = $val; - if($set_to_get_vars === false) return; + if($set_to_get_vars === false) + { + return; + } if($val === NULL || $val === '') { unset($self->get_vars->{$key}); return; } - if($set_to_get_vars || $self->get_vars->{$key}) $self->get_vars->{$key} = $val; + if($set_to_get_vars || $self->get_vars->{$key}) + { + $self->get_vars->{$key} = $val; + } } /** @@ -1477,9 +1764,12 @@ class Context */ function get($key) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - if(!isset($self->context->{$key})) return null; + if(!isset($self->context->{$key})) + { + return null; + } return $self->context->{$key}; } @@ -1491,8 +1781,11 @@ class Context function gets() { $num_args = func_num_args(); - if($num_args<1) return; - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + if($num_args < 1) + { + return; + } + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $args_list = func_get_args(); foreach($args_list as $v) @@ -1509,7 +1802,7 @@ class Context */ function getAll() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->context; } @@ -1520,12 +1813,14 @@ class Context */ function getRequestVars() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - if($self->get_vars) return clone($self->get_vars); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + if($self->get_vars) + { + return clone($self->get_vars); + } return new stdClass; } - /** * Register if actions is to be encrypted by SSL. Those actions are sent to https in common/js/xml_handler.js * @@ -1534,7 +1829,7 @@ class Context */ function addSSLAction($action) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); if(!is_readable($self->sslActionCacheFile)) { @@ -1556,7 +1851,7 @@ class Context */ function getSSLActions() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->ssl_actions; } @@ -1568,7 +1863,7 @@ class Context */ function isExistsSSLAction($action) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return isset($self->ssl_actions[$action]); } @@ -1581,9 +1876,15 @@ class Context */ function normalizeFilePath($file) { - if(strpos($file,'://')===false && $file{0}!='/' && $file{0}!='.') $file = './'.$file; + if(strpos($file, '://') === false && $file{0} != '/' && $file{0} != '.') + { + $file = './' . $file; + } $file = preg_replace('@/\./|(?oFrontEndFileHandler->unloadFile($file, $targetIe, $media); } @@ -1656,10 +1963,9 @@ class Context * @param string $type Unload target (optional - all|css|js) * @return void */ - function unloadAllFiles($type = 'all') { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->unloadAllFiles($type); } @@ -1676,21 +1982,24 @@ class Context * @param string $autoPath If path not readed, set the path automatically. * @return void */ - function addJsFile($file, $optimized = false, $targetie = '',$index=0, $type='head', $isRuleset = false, $autoPath = null) + function addJsFile($file, $optimized = false, $targetie = '', $index = 0, $type = 'head', $isRuleset = false, $autoPath = null) { if($isRuleset) { - if (strpos($file, '#') !== false) + if(strpos($file, '#') !== false) { $file = str_replace('#', '', $file); - if (!is_readable($file)) $file = $autoPath; + if(!is_readable($file)) + { + $file = $autoPath; + } } - $validator = new Validator($file); + $validator = new Validator($file); $validator->setCacheDir('files/cache'); $file = $validator->getJsPath(); } - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->loadFile(array($file, $type, $targetie, $index)); } @@ -1705,7 +2014,7 @@ class Context */ function unloadJsFile($file, $optimized = false, $targetie = '') { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->unloadFile($file, $targetie); } @@ -1716,7 +2025,7 @@ class Context */ function unloadAllJsFiles() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->unloadAllFiles('js'); } @@ -1732,6 +2041,7 @@ class Context $oXmlFilter = new XmlJSFilter($path, $filename); $oXmlFilter->compile(); } + /** * Same as array_unique but works only for file subscript * @@ -1745,9 +2055,12 @@ class Context $files = array_values($files); $filenames = array(); $size = count($files); - for($i = 0; $i < $size; ++ $i) + for($i = 0; $i < $size; ++$i) { - if(in_array($files[$i]['file'], $filenames)) unset($files[$i]); + if(in_array($files[$i]['file'], $filenames)) + { + unset($files[$i]); + } $filenames[] = $files[$i]['file']; } @@ -1760,9 +2073,9 @@ 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(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->oFrontEndFileHandler->getJsFileList($type); } @@ -1778,9 +2091,9 @@ 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(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->loadFile(array($file, $media, $targetie, $index)); } @@ -1796,7 +2109,7 @@ class Context */ function unloadCSSFile($file, $optimized = false, $media = 'all', $targetie = '') { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->unloadFile($file, $targetie, $media); } @@ -1807,7 +2120,7 @@ class Context */ function unloadAllCSSFiles() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->oFrontEndFileHandler->unloadAllFiles('css'); } @@ -1818,7 +2131,7 @@ class Context */ function getCSSFile() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->oFrontEndFileHandler->getCssFileList(); } @@ -1832,28 +2145,52 @@ class Context { static $loaded_plugins = array(); - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - if($plugin_name == 'ui.datepicker') $plugin_name = 'ui'; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + if($plugin_name == 'ui.datepicker') + { + $plugin_name = 'ui'; + } - if($loaded_plugins[$plugin_name]) return; + if($loaded_plugins[$plugin_name]) + { + return; + } $loaded_plugins[$plugin_name] = true; - $plugin_path = './common/js/plugins/'.$plugin_name.'/'; - $info_file = $plugin_path.'plugin.load'; - if(!is_readable($info_file)) return; + $plugin_path = './common/js/plugins/' . $plugin_name . '/'; + $info_file = $plugin_path . 'plugin.load'; + if(!is_readable($info_file)) + { + return; + } $list = file($info_file); foreach($list as $filename) { $filename = trim($filename); - if(!$filename) continue; + if(!$filename) + { + continue; + } - if(substr($filename,0,2)=='./') $filename = substr($filename,2); - if(preg_match('/\.js$/i', $filename)) $self->loadFile(array($plugin_path.$filename, 'body', '', 0), true); - elseif(preg_match('/\.css$/i', $filename)) $self->loadFile(array($plugin_path.$filename, 'all', '', 0), true); + if(substr($filename, 0, 2) == './') + { + $filename = substr($filename, 2); + } + if(preg_match('/\.js$/i', $filename)) + { + $self->loadFile(array($plugin_path . $filename, 'body', '', 0), true); + } + elseif(preg_match('/\.css$/i', $filename)) + { + $self->loadFile(array($plugin_path . $filename, 'all', '', 0), true); + } } - if(is_dir($plugin_path.'lang')) $self->loadLang($plugin_path.'lang'); + if(is_dir($plugin_path . 'lang')) + { + $self->loadLang($plugin_path . 'lang'); + } } /** @@ -1864,13 +2201,13 @@ class Context */ function addHtmlHeader($header) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - $self->html_header .= "\n".$header; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + $self->html_header .= "\n" . $header; } function clearHtmlHeader() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->html_header = ''; } @@ -1881,7 +2218,7 @@ class Context */ function getHtmlHeader() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->html_header; } @@ -1892,7 +2229,7 @@ class Context */ function addBodyClass($class_name) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->body_class[] = $class_name; } @@ -1903,10 +2240,10 @@ class Context */ function getBodyClass() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); $self->body_class = array_unique($self->body_class); - return count($self->body_class)?sprintf(' class="%s"', implode(' ',$self->body_class)):''; + return count($self->body_class) ? sprintf(' class="%s"', implode(' ', $self->body_class)) : ''; } /** @@ -1916,8 +2253,8 @@ class Context */ function addBodyHeader($header) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - $self->body_header .= "\n".$header; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + $self->body_header .= "\n" . $header; } /** @@ -1927,7 +2264,7 @@ class Context */ function getBodyHeader() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->body_header; } @@ -1938,8 +2275,8 @@ class Context */ function addHtmlFooter($footer) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); - $self->html_footer .= ($self->Htmlfooter?"\n":'').$footer; + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); + $self->html_footer .= ($self->Htmlfooter ? "\n" : '') . $footer; } /** @@ -1949,7 +2286,7 @@ class Context */ function getHtmlFooter() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); return $self->html_footer; } @@ -1960,7 +2297,7 @@ class Context */ function getConfigFile() { - return _XE_PATH_.'files/config/db.config.php'; + return _XE_PATH_ . 'files/config/db.config.php'; } /** @@ -1970,7 +2307,7 @@ class Context */ function getFTPConfigFile() { - return _XE_PATH_.'files/config/ftp.config.php'; + return _XE_PATH_ . 'files/config/ftp.config.php'; } /** @@ -2001,7 +2338,7 @@ class Context */ function isAllowRewrite() { - $oContext = &Context::getInstance(); + $oContext = Context::getInstance(); return $oContext->allow_rewrite; } @@ -2013,28 +2350,40 @@ class Context */ function pathToUrl($path) { - $xe = _XE_PATH_; + $xe = _XE_PATH_; $path = strtr($path, "\\", "/"); $base_url = preg_replace('@^https?://[^/]+/?@', '', Context::getRequestUri()); - $_xe = explode('/', $xe); + $_xe = explode('/', $xe); $_path = explode('/', $path); $_base = explode('/', $base_url); - if(!$_base[count($_base)-1]) array_pop($_base); - - foreach($_xe as $idx=>$dir) + if(!$_base[count($_base) - 1]) { - if($_path[0] != $dir) break; + array_pop($_base); + } + + foreach($_xe as $idx => $dir) + { + if($_path[0] != $dir) + { + break; + } array_shift($_path); } $idx = count($_xe) - $idx - 1; while($idx--) { - if(count($_base)) array_shift($_base); - else array_unshift($_base, '..'); + if(count($_base)) + { + array_shift($_base); + } + else + { + array_unshift($_base, '..'); + } } if(count($_base)) @@ -2042,8 +2391,11 @@ class Context array_unshift($_path, implode('/', $_base)); } - $path = '/'.implode('/', $_path); - if(substr($path,-1)!='/') $path .= '/'; + $path = '/' . implode('/', $_path); + if(substr($path, -1) != '/') + { + $path .= '/'; + } return $path; } @@ -2053,17 +2405,20 @@ class Context */ function getMetaTag() { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - if(!is_array($self->meta_tags)) $self->meta_tags = array(); + if(!is_array($self->meta_tags)) + { + $self->meta_tags = array(); + } $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); + $ret[] = array('name' => $name, 'is_http_equiv' => $is_http_equiv, 'content' => $val); } return $ret; @@ -2079,14 +2434,14 @@ class Context */ function addMetaTag($name, $content, $is_http_equiv = false) { - is_a($this,'Context')?$self=&$this:$self=&Context::getInstance(); + is_a($this, 'Context') ? $self = $this : $self = Context::getInstance(); - $key = $name."\t".($is_http_equiv ? '1' : '0'); + $key = $name . "\t" . ($is_http_equiv ? '1' : '0'); $map = &$self->meta_tags; $map[$key] = $content; } -} +} /* End of file Context.class.php */ /* Location: ./classes/context/Context.class.php */