mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 18:51:41 +09:00
Initial implementation of new config use in Context class
This commit is contained in:
parent
0fba6ea226
commit
3460f63741
1 changed files with 120 additions and 143 deletions
|
|
@ -9,7 +9,6 @@
|
|||
*/
|
||||
class Context
|
||||
{
|
||||
|
||||
/**
|
||||
* Allow rewrite
|
||||
* @var bool TRUE: using rewrite mod, FALSE: otherwise
|
||||
|
|
@ -209,7 +208,7 @@ class Context
|
|||
*/
|
||||
public function init()
|
||||
{
|
||||
// fix missing HTTP_RAW_POST_DATA in PHP 5.6 and above
|
||||
// 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");
|
||||
|
|
@ -220,47 +219,27 @@ class Context
|
|||
unset($GLOBALS['HTTP_RAW_POST_DATA']);
|
||||
}
|
||||
}
|
||||
|
||||
// set context variables in $GLOBALS (backward compatibility)
|
||||
|
||||
// Set global variables for backward compatibility.
|
||||
$GLOBALS['__Context__'] = $this;
|
||||
$GLOBALS['lang'] = &$this->lang;
|
||||
$this->_COOKIE = $_COOKIE;
|
||||
|
||||
// 20140429 editor/image_link
|
||||
|
||||
// Set information about the current request.
|
||||
$this->setRequestMethod();
|
||||
$this->_checkGlobalVars();
|
||||
|
||||
$this->setRequestMethod('');
|
||||
|
||||
$this->_setXmlRpcArgument();
|
||||
$this->_setJSONRequestArgument();
|
||||
$this->_setRequestArgument();
|
||||
$this->_setUploadedArgument();
|
||||
|
||||
|
||||
// Load system configuration.
|
||||
$this->loadDBInfo();
|
||||
if($this->db_info->use_sitelock == 'Y')
|
||||
|
||||
// If the site is locked, display the locked page.
|
||||
if(Rhymix\Framework\Config::get('lock.locked'))
|
||||
{
|
||||
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;
|
||||
}
|
||||
self::enforceSiteLock();
|
||||
}
|
||||
|
||||
// If XE is installed, get virtual site information
|
||||
|
|
@ -531,79 +510,62 @@ class Context
|
|||
*/
|
||||
public static function loadDBInfo()
|
||||
{
|
||||
if(!self::isInstalled())
|
||||
// Load new configuration format.
|
||||
$config = Rhymix\Framework\Config::init();
|
||||
if(!count($config))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$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(isset($db_info->master_db["db_table_prefix"]) && substr_compare($db_info->master_db["db_table_prefix"], '_', -1) !== 0)
|
||||
{
|
||||
$db_info->master_db["db_table_prefix"] .= '_';
|
||||
}
|
||||
|
||||
$db_info->slave_db = array($db_info->master_db);
|
||||
self::setDBInfo($db_info);
|
||||
|
||||
$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;
|
||||
$GLOBALS['_time_zone_offset'] = get_time_zone_offset($db_info->time_zone);
|
||||
|
||||
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';
|
||||
|
||||
// Copy to old format for backward compatibility.
|
||||
$db_info = new stdClass;
|
||||
$db_info->master_db = array(
|
||||
'db_type' => $config['db']['master']['type'] . ($config['db']['master']['engine'] === 'innodb' ? '_innodb' : ''),
|
||||
'db_hostname' => $config['db']['master']['host'],
|
||||
'db_port' => $config['db']['master']['port'],
|
||||
'db_userid' => $config['db']['master']['user'],
|
||||
'db_password' => $config['db']['master']['pass'],
|
||||
'db_database' => $config['db']['master']['database'],
|
||||
'db_table_prefix' => $config['db']['master']['prefix'],
|
||||
'db_charset' => $config['db']['master']['charset'],
|
||||
);
|
||||
$db_info->slave_db = array($db_info->master_db);
|
||||
$db_info->use_object_cache = count($config['cache']) ? array_first($config['cache']) : null;
|
||||
$db_info->ftp_info = new stdClass;
|
||||
$db_info->ftp_info->ftp_host = $config['ftp']['host'];
|
||||
$db_info->ftp_info->ftp_port = $config['ftp']['port'];
|
||||
$db_info->ftp_info->ftp_user = $config['ftp']['user'];
|
||||
$db_info->ftp_info->ftp_pasv = $config['ftp']['pasv'] ? 'Y' : 'N';
|
||||
$db_info->ftp_info->ftp_root_path = $config['ftp']['path'];
|
||||
$db_info->ftp_info->sftp = $config['ftp']['sftp'] ? 'Y' : 'N';
|
||||
$db_info->default_url = $config['url']['default'];
|
||||
$db_info->http_port = $config['url']['http_port'];
|
||||
$db_info->https_port = $config['url']['https_port'];
|
||||
$db_info->use_ssl = $config['url']['ssl'];
|
||||
self::set('_http_port', $db_info->http_port ?: null);
|
||||
self::set('_https_port', $db_info->https_port ?: null);
|
||||
self::set('_use_ssl', $db_info->use_ssl);
|
||||
self::set('_http_port', ($db_info->http_port) ? $db_info->http_port : NULL);
|
||||
self::set('_https_port', ($db_info->https_port) ? $db_info->https_port : NULL);
|
||||
|
||||
if(!$db_info->sitelock_whitelist) {
|
||||
$db_info->sitelock_whitelist = '127.0.0.1';
|
||||
}
|
||||
|
||||
if(is_string($db_info->sitelock_whitelist)) {
|
||||
$db_info->sitelock_whitelist = explode(',', $db_info->sitelock_whitelist);
|
||||
}
|
||||
|
||||
self::setDBInfo($db_info);
|
||||
$db_info->lang_type = $config['locale']['default_lang'];
|
||||
$db_info->time_zone = $config['locale']['internal_timezone'];
|
||||
$db_info->time_zone = sprintf('%s%02d%02d', $db_info->time_zone >= 0 ? '+' : '-', abs($db_info->time_zone) / 3600, (abs($db_info->time_zone) % 3600 / 60));
|
||||
$GLOBALS['_time_zone'] = $db_info->time_zone;
|
||||
$GLOBALS['_time_zone_offset'] = $config['locale']['internal_timezone'];
|
||||
$GLOBALS['_qmail_compatibility'] = 'N';
|
||||
$db_info->delay_session = $config['session']['delay'] ? 'Y' : 'N';
|
||||
$db_info->use_db_session = $config['session']['use_db'] ? 'Y' : 'N';
|
||||
$db_info->minify_scripts = $config['view']['minify_scripts'] ? 'Y' : 'N';
|
||||
$db_info->admin_ip_list = count($config['admin']['allow']) ? $config['admin']['allow'] : null;
|
||||
$db_info->use_sitelock = $config['lock']['locked'] ? 'Y' : 'N';
|
||||
$db_info->sitelock_title = $config['lock']['title'];
|
||||
$db_info->sitelock_message = $config['lock']['message'];
|
||||
$db_info->sitelock_whitelist = count($config['lock']['allow']) ? $config['lock']['allow'] : array('127.0.0.1');
|
||||
$db_info->embed_white_iframe = $config['embedfilter']['iframe'];
|
||||
$db_info->embed_white_object = $config['embedfilter']['object'];
|
||||
$db_info->use_mobile_view = $config['use_mobile_view'] ? 'Y' : 'N';
|
||||
$db_info->use_prepared_statements = $config['use_prepared_statements'] ? 'Y' : 'N';
|
||||
$db_info->use_rewrite = $config['use_rewrite'] ? 'Y' : 'N';
|
||||
$db_info->use_sso = $config['use_sso'] ? 'Y' : 'N';
|
||||
self::$_instance->db_info = $db_info;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -644,7 +606,7 @@ class Context
|
|||
*/
|
||||
public static function getSslStatus()
|
||||
{
|
||||
return self::getDBInfo()->use_ssl;
|
||||
return Rhymix\Framework\Config::get('url.ssl');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -654,7 +616,7 @@ class Context
|
|||
*/
|
||||
public static function getDefaultUrl()
|
||||
{
|
||||
return self::getDBInfo()->default_url;
|
||||
return Rhymix\Framework\Config::get('url.default');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -674,39 +636,14 @@ class Context
|
|||
*/
|
||||
public static function loadLangSelected()
|
||||
{
|
||||
static $lang_selected = null;
|
||||
if(!$lang_selected)
|
||||
static $lang_selected = array();
|
||||
if(!count($lang_selected))
|
||||
{
|
||||
$selected_lang_file = _XE_PATH_ . 'files/config/lang_selected.info';
|
||||
if(!FileHandler::hasContent($selected_lang_file))
|
||||
$supported = Rhymix\Framework\Lang::getSupportedList();
|
||||
$selected = Rhymix\Framework\Config::get('locale.enabled_lang');
|
||||
foreach ($selected as $lang)
|
||||
{
|
||||
$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))
|
||||
{
|
||||
$lang_selected = Rhymix\Framework\Lang::getSupportedList();
|
||||
$buff = '';
|
||||
foreach($lang_selected as $key => $val)
|
||||
{
|
||||
$buff .= "$key,$val\n";
|
||||
}
|
||||
FileHandler::writeFile($selected_lang_file, $buff);
|
||||
}
|
||||
else
|
||||
{
|
||||
$langs = file($selected_lang_file);
|
||||
foreach($langs as $val)
|
||||
{
|
||||
list($lang_prefix, $lang_text) = explode(',', $val);
|
||||
if($lang_prefix === 'jp')
|
||||
{
|
||||
$lang_prefix = 'ja';
|
||||
}
|
||||
$lang_text = trim($lang_text);
|
||||
$lang_selected[$lang_prefix] = $lang_text;
|
||||
}
|
||||
$lang_selected[$lang] = $supported[$lang];
|
||||
}
|
||||
}
|
||||
return $lang_selected;
|
||||
|
|
@ -814,7 +751,8 @@ class Context
|
|||
*/
|
||||
public static function isFTPRegisted()
|
||||
{
|
||||
return file_exists(self::getFTPConfigFile());
|
||||
$ftp_info = self::$_instance->db_info->ftp_info;
|
||||
return ($ftp_info->ftp_user && $ftp_info->ftp_root_path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -824,11 +762,11 @@ class Context
|
|||
*/
|
||||
public static function getFTPInfo()
|
||||
{
|
||||
if(!self::isFTPRegisted())
|
||||
$ftp_info = self::$_instance->db_info->ftp_info;
|
||||
if (!$ftp_info->ftp_user || !$ftp_info->ftp_root_path)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
include(self::getFTPConfigFile());
|
||||
return $ftp_info;
|
||||
}
|
||||
|
||||
|
|
@ -961,8 +899,14 @@ class Context
|
|||
*/
|
||||
public static function getLang($code)
|
||||
{
|
||||
$lang = self::$_instance->lang;
|
||||
return isset($lang->{$code}) ? $lang->{$code} : $code;
|
||||
if (self::$_instance->lang)
|
||||
{
|
||||
return self::$_instance->lang->get($code);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -974,7 +918,10 @@ class Context
|
|||
*/
|
||||
public static function setLang($code, $val)
|
||||
{
|
||||
self::$_instance->lang->{$code} = $val;
|
||||
if (self::$_instance->lang)
|
||||
{
|
||||
self::$_instance->lang->set($code, $val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1472,6 +1419,36 @@ class Context
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enforce site lock.
|
||||
*/
|
||||
private static function enforceSiteLock()
|
||||
{
|
||||
$allowed_list = Rhymix\Framework\Config::get('lock.allow');
|
||||
foreach ($allowed_list as $allowed_ip)
|
||||
{
|
||||
if (Rhymix\Framework\IpFilter::inRange(RX_CLIENT_IP, $allowed_ip))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
define('_XE_SITELOCK_', TRUE);
|
||||
define('_XE_SITELOCK_TITLE_', Rhymix\Framework\Config::get('lock.title'));
|
||||
define('_XE_SITELOCK_MESSAGE_', Rhymix\Framework\Config::get('lock.message'));
|
||||
|
||||
header("HTTP/1.1 403 Forbidden");
|
||||
if(FileHandler::exists(RX_BASEDIR . 'common/tpl/sitelock.user.html'))
|
||||
{
|
||||
include RX_BASEDIR . 'common/tpl/sitelock.user.html';
|
||||
}
|
||||
else
|
||||
{
|
||||
include RX_BASEDIR . 'common/tpl/sitelock.html';
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return request method
|
||||
* @return string Request method type. (Optional - GET|POST|XMLRPC|JSON)
|
||||
|
|
@ -2462,7 +2439,7 @@ class Context
|
|||
*/
|
||||
public static function getConfigFile()
|
||||
{
|
||||
return _XE_PATH_ . 'files/config/db.config.php';
|
||||
return RX_BASEDIR . 'files/config/config.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2472,7 +2449,7 @@ class Context
|
|||
*/
|
||||
public static function getFTPConfigFile()
|
||||
{
|
||||
return _XE_PATH_ . 'files/config/ftp.config.php';
|
||||
return RX_BASEDIR . 'files/config/config.php';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue