/** * Get or set lang variable. * * @param string $code Lang variable name * @param string $value `$code`s value * @return mixed */ function lang($code, $value = null) { if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang) { $GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(Context::getLangType() ?: config('locale.default_lang') ?: 'ko'); $GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); } if ($value === null) { return $GLOBALS['lang']->get($code); } else { $GLOBALS['lang']->set($code, $value); } }
/** * Initialization, it sets DB information, request arguments and so on. * * @see This function should be called only once * @return void */ public function init() { // fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above if (!isset($GLOBALS['HTTP_RAW_POST_DATA']) && version_compare(PHP_VERSION, '5.6.0', '>=') === TRUE) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input"); // If content is not XML or JSON, unset if (!preg_match('/^[\\<\\{\\[]/', $GLOBALS['HTTP_RAW_POST_DATA'])) { unset($GLOBALS['HTTP_RAW_POST_DATA']); } } // set context variables in $GLOBALS (backward compatibility) $GLOBALS['__Context__'] = $this; $GLOBALS['lang'] =& $this->lang; $this->_COOKIE = $_COOKIE; // 20140429 editor/image_link $this->_checkGlobalVars(); $this->setRequestMethod(''); $this->_setXmlRpcArgument(); $this->_setJSONRequestArgument(); $this->_setRequestArgument(); $this->_setUploadedArgument(); $this->loadDBInfo(); if ($this->db_info->use_sitelock == 'Y') { if (is_array($this->db_info->sitelock_whitelist)) { $whitelist = $this->db_info->sitelock_whitelist; } if (!IpFilter::filter($whitelist)) { $title = $this->db_info->sitelock_title ? $this->db_info->sitelock_title : 'Maintenance in progress...'; $message = $this->db_info->sitelock_message; define('_XE_SITELOCK_', TRUE); define('_XE_SITELOCK_TITLE_', $title); define('_XE_SITELOCK_MESSAGE_', $message); header("HTTP/1.1 403 Forbidden"); if (FileHandler::exists(_XE_PATH_ . 'common/tpl/sitelock.user.html')) { include _XE_PATH_ . 'common/tpl/sitelock.user.html'; } else { include _XE_PATH_ . 'common/tpl/sitelock.html'; } exit; } } // If XE is installed, get virtual site information if (self::isInstalled()) { $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) { $site_module_info->domain = $this->db_info->default_url; } self::set('site_module_info', $site_module_info); if ($site_module_info->site_srl && isSiteID($site_module_info->domain)) { self::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 = 'ko'; } if (!$this->db_info->use_db_session) { $this->db_info->use_db_session = 'N'; } } // Load Language File $lang_supported = self::loadLangSelected(); // Retrieve language type set in user's cookie if ($this->lang_type = self::get('l')) { if ($_COOKIE['lang_type'] != $this->lang_type) { setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/'); } } elseif ($_COOKIE['lang_type']) { $this->lang_type = $_COOKIE['lang_type']; } // 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 still lang_type has not been set or has not-supported type , set as Korean. if (!$this->lang_type) { $this->lang_type = 'ko'; } if (is_array($lang_supported) && !isset($lang_supported[$this->lang_type])) { $this->lang_type = 'ko'; } self::set('lang_supported', $lang_supported); self::setLangType($this->lang_type); // Load languages $this->lang = Rhymix\Framework\Lang::getInstance($this->lang_type); $this->lang->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); $this->lang->loadDirectory(RX_BASEDIR . 'modules/module/lang', 'module'); // set session handler if (self::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')); } // start session if it was previously started $session_name = session_name(); $session_id = NULL; if ($session_id = $_POST[$session_name]) { session_id($session_id); } else { $session_id = $_COOKIE[$session_name]; } if ($session_id !== NULL || $this->db_info->delay_session != 'Y') { $this->setCacheControl(0, false); session_start(); } else { ob_start(); $this->setCacheControl(-1, true); register_shutdown_function(array($this, 'checkSessionStatus')); $_SESSION = array(); } // set authentication information in Context and session if (self::isInstalled()) { $oModuleModel = getModel('module'); $oModuleModel->loadModuleExtends(); $oMemberModel = getModel('member'); $oMemberController = getController('member'); if ($oMemberController && $oMemberModel) { // if signed in, validate it. if ($oMemberModel->isLogged()) { $oMemberController->setSessionInfo(); } elseif ($_COOKIE['xeak']) { $oMemberController->doAutologin(); } self::set('is_logged', $oMemberModel->isLogged()); if ($oMemberModel->isLogged()) { self::set('logged_info', $oMemberModel->getLoggedInfo()); } } } // check if using rewrite module $this->allow_rewrite = $this->db_info->use_rewrite == 'Y' ? TRUE : FALSE; // set locations for javascript use $url = array(); $current_url = self::getRequestUri(); if ($_SERVER['REQUEST_METHOD'] == 'GET') { if ($this->get_vars) { $url = array(); foreach ($this->get_vars as $key => $val) { if (is_array($val) && count($val) > 0) { foreach ($val as $k => $v) { $url[] = $key . '[' . $k . ']=' . urlencode($v); } } elseif ($val) { $url[] = $key . '=' . urlencode($val); } } $current_url = self::getRequestUri(); if ($url) { $current_url .= '?' . join('&', $url); } } else { $current_url = self::getUrl(); } } else { $current_url = self::getRequestUri(); } self::set('current_url', $current_url); self::set('request_uri', self::getRequestUri()); if (strpos($current_url, 'xn--') !== FALSE) { self::set('current_url', self::decodeIdna($current_url)); } if (strpos(self::getRequestUri(), 'xn--') !== FALSE) { self::set('request_uri', self::decodeIdna(self::getRequestUri())); } }
/** * Set data to lang variable * * @param string $code Language variable name * @param string $val `$code`s value * @return void */ public static function setLang($code, $val) { if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang) { $GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko'); $GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); } $GLOBALS['lang']->set($code, $val); }
/** * Initialization, it sets DB information, request arguments and so on. * * @see This function should be called only once * @return void */ public function init() { // Fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above. if (!isset($GLOBALS['HTTP_RAW_POST_DATA']) && version_compare(PHP_VERSION, '5.6.0', '>=') === TRUE) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents("php://input"); // If content is not XML or JSON, unset if (!preg_match('/^[\\<\\{\\[]/', $GLOBALS['HTTP_RAW_POST_DATA'])) { unset($GLOBALS['HTTP_RAW_POST_DATA']); } } // Set global variables for backward compatibility. $GLOBALS['__Context__'] = $this; $GLOBALS['lang'] =& $this->lang; $this->_COOKIE = $_COOKIE; // Set information about the current request. $this->setRequestMethod(); $this->_checkGlobalVars(); $this->_setXmlRpcArgument(); $this->_setJSONRequestArgument(); $this->_setRequestArgument(); $this->_setUploadedArgument(); if (isset($_POST['_rx_ajax_compat']) && $_POST['_rx_ajax_compat'] === 'XMLRPC') { self::$_instance->request_method = 'XMLRPC'; self::$_instance->response_method = 'JSON'; } // Load system configuration. $this->loadDBInfo(); // If Rhymix is installed, get virtual site information. if (self::isInstalled()) { $oModuleModel = getModel('module'); $site_module_info = $oModuleModel->getDefaultMid() ?: 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) { $site_module_info->domain = $this->db_info->default_url; } self::set('site_module_info', $site_module_info); if ($site_module_info->site_srl && isSiteID($site_module_info->domain)) { self::set('vid', $site_module_info->domain, TRUE); } } else { $site_module_info = new stdClass(); } // Load language support. $enabled_langs = self::loadLangSelected(); self::set('lang_supported', $enabled_langs); if ($this->lang_type = self::get('l')) { if ($_COOKIE['lang_type'] != $this->lang_type) { setcookie('lang_type', $this->lang_type, $_SERVER['REQUEST_TIME'] + 3600 * 24 * 1000, '/'); } } elseif ($_COOKIE['lang_type']) { $this->lang_type = $_COOKIE['lang_type']; } elseif ($site_module_info->default_language) { $this->lang_type = $this->db_info->lang_type = $site_module_info->default_language; } else { $this->lang_type = $this->db_info->lang_type; } if (!$this->lang_type || !isset($enabled_langs[$this->lang_type])) { $this->lang_type = 'ko'; } self::setLangType($this->lang_type); $this->lang = Rhymix\Framework\Lang::getInstance($this->lang_type); $this->lang->loadDirectory(RX_BASEDIR . 'common/lang', 'common'); $this->lang->loadDirectory(RX_BASEDIR . 'modules/module/lang', 'module'); // set session handler if (self::isInstalled() && config('session.use_db')) { $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')); } // start session if it was previously started $session_name = session_name(); $session_id = NULL; if ($session_id = $_POST[$session_name]) { session_id($session_id); } else { $session_id = $_COOKIE[$session_name]; } if ($session_id !== NULL || !config('session.delay')) { $this->setCacheControl(0, false); session_start(); } else { ob_start(); $this->setCacheControl(-1, true); register_shutdown_function(array($this, 'checkSessionStatus')); $_SESSION = array(); } // set authentication information in Context and session if (self::isInstalled()) { $oModuleModel = getModel('module'); $oModuleModel->loadModuleExtends(); $oMemberModel = getModel('member'); $oMemberController = getController('member'); if ($oMemberController && $oMemberModel) { // if signed in, validate it. if ($oMemberModel->isLogged()) { $oMemberController->setSessionInfo(); } elseif ($_COOKIE['xeak']) { $oMemberController->doAutologin(); } self::set('is_logged', $oMemberModel->isLogged()); if ($oMemberModel->isLogged()) { self::set('logged_info', $oMemberModel->getLoggedInfo()); } } } // set locations for javascript use $current_url = $request_uri = self::getRequestUri(); if ($_SERVER['REQUEST_METHOD'] == 'GET' && $this->get_vars) { if ($query_string = http_build_query($this->get_vars)) { $current_url .= '?' . $query_string; } } if (strpos($current_url, 'xn--') !== false) { $current_url = self::decodeIdna($current_url); } if (strpos($request_uri, 'xn--') !== false) { $request_uri = self::decodeIdna($request_uri); } self::set('current_url', $current_url); self::set('request_uri', $request_uri); // If the site is locked, display the locked page. if (config('lock.locked')) { self::enforceSiteLock(); } }