From 750d978f0ed762eba53b75628a24151c0101db7e Mon Sep 17 00:00:00 2001 From: Yuriy Pikhtarev Date: Fri, 23 Jun 2017 00:01:27 +0300 Subject: [PATCH] Display source language if no user language variable. --- src/Helpers/CronHelper.php | 4 +++- src/Legacy/Common/User.php | 12 ++++++++++-- src/Legacy/Template.php | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Helpers/CronHelper.php b/src/Helpers/CronHelper.php index 89aa498b7..a8469d10f 100644 --- a/src/Helpers/CronHelper.php +++ b/src/Helpers/CronHelper.php @@ -53,7 +53,9 @@ class CronHelper */ public static function releaseLockFile() { - rename(CRON_RUNNING, CRON_ALLOWED); + if (file_exists(CRON_RUNNING)) { + rename(CRON_RUNNING, CRON_ALLOWED); + } self::touchLockFile(CRON_ALLOWED); } diff --git a/src/Legacy/Common/User.php b/src/Legacy/Common/User.php index 89c3685a8..cd42e7942 100644 --- a/src/Legacy/Common/User.php +++ b/src/Legacy/Common/User.php @@ -571,14 +571,14 @@ class User */ public function init_userprefs() { - global $bb_cfg, $theme, $lang, $DeltaTime; + global $bb_cfg, $theme, $source_lang, $DeltaTime; if (defined('LANG_DIR')) { return; } // prevent multiple calling define('DEFAULT_LANG_DIR', LANG_ROOT_DIR . '/' . $bb_cfg['default_lang'] . '/'); - define('ENGLISH_LANG_DIR', LANG_ROOT_DIR . '/en/'); + define('SOURCE_LANG_DIR', LANG_ROOT_DIR . '/source/'); if ($this->data['user_id'] != GUEST_UID) { if ($this->data['user_lang'] && $this->data['user_lang'] != $bb_cfg['default_lang']) { @@ -598,6 +598,14 @@ class User define('LANG_DIR', DEFAULT_LANG_DIR); } + /** Temporary place source language to the global */ + $lang = []; + require(SOURCE_LANG_DIR . 'main.php'); + $source_lang = $lang; + unset($lang); + + /** Place user language to the global */ + global $lang; require(LANG_DIR . 'main.php'); setlocale(LC_ALL, isset($bb_cfg['lang'][$this->data['user_lang']]['locale']) ? $bb_cfg['lang'][$this->data['user_lang']]['locale'] : 'en_US.UTF-8'); diff --git a/src/Legacy/Template.php b/src/Legacy/Template.php index 281c92bdc..14c101ea4 100644 --- a/src/Legacy/Template.php +++ b/src/Legacy/Template.php @@ -239,10 +239,11 @@ class Template { $this->cur_tpl = $filename; - global $lang, $bb_cfg, $user; + global $lang, $source_lang, $bb_cfg, $user; $L =& $lang; $V =& $this->vars; + $SL =& $source_lang; if ($filename) { include $filename; @@ -773,7 +774,7 @@ class Template $code = str_replace($search, $replace, $code); } // This will handle the remaining root-level varrefs - $code = preg_replace('#\{(L_([a-z0-9\-_]+?))\}#i', '', $code); + $code = preg_replace('#\{(L_([a-z0-9\-_]+?))\}#i', '', $code); $code = preg_replace('#\{(\$[a-z_][a-z0-9_$\->\'\"\.\[\]]*?)\}#i', '', $code); $code = preg_replace('#\{(\#([a-z_][a-z0-9_]*?))\}#i', '', $code); $code = preg_replace('#\{([a-z0-9\-_]+?)\}#i', '', $code);