Simplify language calls
There are no more lang vars passed on to any class calls The new order is the following $OVERRIDE_LANG > _SESSION > SITE_LANG > DEFAULT_LANG Todo: make the setLang better so we do not have the same method in Backend/Generic/SmartyExtended
This commit is contained in:
@@ -115,10 +115,9 @@ class Login extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||
* @param array $db_config db config array
|
||||
* @param string $lang language string (default en_utf8)
|
||||
* @param int $set_control_flag class variable check flags
|
||||
*/
|
||||
public function __construct(array $db_config, string $lang = 'en_utf8', int $set_control_flag = 0)
|
||||
public function __construct(array $db_config, int $set_control_flag = 0)
|
||||
{
|
||||
// log login data for this class only
|
||||
$this->log_per_class = 1;
|
||||
@@ -151,7 +150,13 @@ class Login extends \CoreLibs\DB\IO
|
||||
// set global is ajax page for if we show the data directly, or need to pass it back
|
||||
// to the continue AJAX class for output back to the user
|
||||
$this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false;
|
||||
|
||||
// set the default lang
|
||||
$lang = 'en_utf8';
|
||||
if (session_id() && isset($_SESSION['DEFAULT_LANG']) && $_SESSION['DEFAULT_LANG']) {
|
||||
$lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
$lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
}
|
||||
$this->l = new \CoreLibs\Language\L10n($lang);
|
||||
|
||||
// if we have a search path we need to set it, to use the correct DB to login
|
||||
|
||||
@@ -57,26 +57,25 @@ class Backend extends \CoreLibs\DB\IO
|
||||
public $lang;
|
||||
public $lang_short;
|
||||
public $encoding;
|
||||
// language
|
||||
public $l;
|
||||
// smarty publics [end processing in smarty class]
|
||||
public $DATA;
|
||||
public $HEADER;
|
||||
public $DEBUG_DATA;
|
||||
public $CONTENT_DATA;
|
||||
// language
|
||||
public $l;
|
||||
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
/**
|
||||
* main class constructor
|
||||
* @param array $db_config db config array
|
||||
* @param string $lang language string
|
||||
* @param int|integer $set_control_flag class variable check flag
|
||||
*/
|
||||
public function __construct(array $db_config, string $lang, int $set_control_flag = 0)
|
||||
public function __construct(array $db_config, int $set_control_flag = 0)
|
||||
{
|
||||
$this->setLangEncoding();
|
||||
// get the language sub class & init it
|
||||
$this->l = new \CoreLibs\Language\L10n($lang);
|
||||
$this->l = new \CoreLibs\Language\L10n($this->lang);
|
||||
|
||||
// init the database class
|
||||
parent::__construct($db_config, $set_control_flag);
|
||||
@@ -104,9 +103,6 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
// INTERNAL METHODS |===============================================>
|
||||
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
* set the language encoding and language settings
|
||||
* the default charset from _SESSION login or from
|
||||
@@ -116,7 +112,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
public function setLangEncoding(): void
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
// just emergency fallback for language
|
||||
// set encoding
|
||||
@@ -125,10 +121,14 @@ class Backend extends \CoreLibs\DB\IO
|
||||
} else {
|
||||
$this->encoding = DEFAULT_ENCODING;
|
||||
}
|
||||
// just emergency fallback for language
|
||||
if (isset($_SESSION['DEFAULT_LANG'])) {
|
||||
// gobal override
|
||||
if (isset($GLOBALS['OVERRIDE_LANG'])) {
|
||||
$this->lang = $GLOBALS['OVERRIDE_LANG'];
|
||||
} elseif (isset($_SESSION['DEFAULT_LANG'])) {
|
||||
// session (login)
|
||||
$this->lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
// mostly default SITE LANG or DEFAULT LANG
|
||||
$this->lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
}
|
||||
// create the char lang encoding
|
||||
@@ -137,6 +137,8 @@ class Backend extends \CoreLibs\DB\IO
|
||||
$this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH;
|
||||
}
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
* set internal ACL from login ACL
|
||||
* @param array $acl login acl array
|
||||
|
||||
@@ -242,6 +242,11 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
public $security_level;
|
||||
// layout publics
|
||||
public $table_width;
|
||||
// internal lang & encoding vars
|
||||
public $lang_dir = '';
|
||||
public $lang;
|
||||
public $lang_short;
|
||||
public $encoding;
|
||||
// language
|
||||
public $l;
|
||||
|
||||
@@ -251,15 +256,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* construct form generator
|
||||
* @param array $db_config db config array
|
||||
* @param string $lang interface language
|
||||
* @param int|integer $table_width table/div width (default 750)
|
||||
* @param int|integer $set_control_flag basic class set/get variable error flags
|
||||
*/
|
||||
public function __construct(array $db_config, string $lang, int $table_width = 750, int $set_control_flag = 0)
|
||||
public function __construct(array $db_config, int $table_width = 750, int $set_control_flag = 0)
|
||||
{
|
||||
$this->my_page_name = $this->getPageName(1);
|
||||
$this->setLangEncoding();
|
||||
// init the language class
|
||||
$this->l = new \CoreLibs\Language\L10n($lang);
|
||||
$this->l = new \CoreLibs\Language\L10n($this->lang);
|
||||
// load config array
|
||||
// get table array definitions for current page name
|
||||
// WARNING: auto spl load does not work with this as it is an array and not a function/object
|
||||
@@ -348,6 +353,45 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// INTERNAL METHODS |===============================================>
|
||||
|
||||
/**
|
||||
* ORIGINAL in \CoreLibs\Admin\Backend
|
||||
* set the language encoding and language settings
|
||||
* the default charset from _SESSION login or from
|
||||
* config DEFAULT ENCODING
|
||||
* the lang full name for mo loading from _SESSION login
|
||||
* or SITE LANG or DEFAULT LANG from config
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
// just emergency fallback for language
|
||||
// set encoding
|
||||
if (isset($_SESSION['DEFAULT_CHARSET'])) {
|
||||
$this->encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} else {
|
||||
$this->encoding = DEFAULT_ENCODING;
|
||||
}
|
||||
// gobal override
|
||||
if (isset($GLOBALS['OVERRIDE_LANG'])) {
|
||||
$this->lang = $GLOBALS['OVERRIDE_LANG'];
|
||||
} elseif (isset($_SESSION['DEFAULT_LANG'])) {
|
||||
// session (login)
|
||||
$this->lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
// mostly default SITE LANG or DEFAULT LANG
|
||||
$this->lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
}
|
||||
// create the char lang encoding
|
||||
$this->lang_short = substr($this->lang, 0, 2);
|
||||
// set the language folder
|
||||
$this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH;
|
||||
}
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
* dumps all values into output (for error msg)
|
||||
* @return string full table array data output as string html formatted
|
||||
|
||||
@@ -89,10 +89,9 @@ class SmartyExtend extends SmartyBC
|
||||
/**
|
||||
* constructor class, just sets the language stuff
|
||||
* calls L10 for pass on internaly in smarty
|
||||
* also registers the getvar caller pliugin
|
||||
* @param string $lang language string to set
|
||||
* also registers the getvar caller plugin
|
||||
*/
|
||||
public function __construct(string $lang)
|
||||
public function __construct()
|
||||
{
|
||||
// call basic smarty
|
||||
parent::__construct();
|
||||
@@ -121,7 +120,7 @@ class SmartyExtend extends SmartyBC
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
public function setLangEncoding(): void
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
// just emergency fallback for language
|
||||
// set encoding
|
||||
@@ -130,10 +129,14 @@ class SmartyExtend extends SmartyBC
|
||||
} else {
|
||||
$this->encoding = DEFAULT_ENCODING;
|
||||
}
|
||||
// just emergency fallback for language
|
||||
if (isset($_SESSION['DEFAULT_LANG'])) {
|
||||
// gobal override
|
||||
if (isset($GLOBALS['OVERRIDE_LANG'])) {
|
||||
$this->lang = $GLOBALS['OVERRIDE_LANG'];
|
||||
} elseif (isset($_SESSION['DEFAULT_LANG'])) {
|
||||
// session (login)
|
||||
$this->lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
// mostly default SITE LANG or DEFAULT LANG
|
||||
$this->lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
}
|
||||
// create the char lang encoding
|
||||
@@ -405,7 +408,7 @@ class SmartyExtend extends SmartyBC
|
||||
|
||||
/**
|
||||
* render smarty data (can be called sepparate)
|
||||
* @return [type] [description]
|
||||
* @return void
|
||||
*/
|
||||
public function renderSmarty(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user