Compare commits

..

3 Commits

Author SHA1 Message Date
Clemens Schwaighofer
12e335c69c Move fileUploadErrorMessage from Admin\Backend to Basic
Also removed the auto translate, return just string.
Is also a static method so can be called by
Basic::fileUploadErrorMessage too

Removed left over LANG settings in admin header
2019-11-15 17:53:21 +09:00
Clemens Schwaighofer
3ae3b1b761 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
2019-11-15 17:07:35 +09:00
Clemens Schwaighofer
3c9ca025f5 Smarty Extended split out cms var merge & content render
The down merge of outside class smarty vars is now an extra function
that can be called stand alone.

The smarty render function call is also a stand alone function that can
be called from outside
2019-11-15 15:20:12 +09:00
9 changed files with 148 additions and 93 deletions

View File

@@ -24,12 +24,10 @@ if (!defined('SET_SESSION_NAME')) {
}
// define log file id
$LOG_FILE_ID = 'classTest';
// set language for l10n
$lang = 'en_utf8';
// init login & backend class
$login = new CoreLibs\ACL\Login(DB_CONFIG, $lang);
$basic = new CoreLibs\Admin\Backend(DB_CONFIG, $lang);
$login = new CoreLibs\ACL\Login(DB_CONFIG);
$basic = new CoreLibs\Admin\Backend(DB_CONFIG);
$basic->dbInfo(true);
ob_end_flush();

View File

@@ -14,8 +14,7 @@ $SET_SESSION_NAME = EDIT_SESSION_NAME;
echo "DIR: ".DIR."<br>ROOT: ".ROOT."<br>BASE: ".BASE."<br>";
$lang = 'ja_utf8';
$base = new CoreLibs\Admin\Backend(DB_CONFIG, $lang);
$base = new CoreLibs\Admin\Backend(DB_CONFIG);
ob_end_flush();
if ($base->getConnectionStatus()) {
die("Cannot connect to database");

View File

@@ -13,7 +13,6 @@ if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING) {
include BASE.LIBS."Error.Handling.php";
}
// predefine vars
$LANG = '';
$messages = array();
// import all POST vars
// extract($_POST, EXTR_SKIP);
@@ -38,12 +37,6 @@ if (!isset($ZIP_STREAM)) {
if (!isset($ENCODING) || !$ENCODING) {
$ENCODING = DEFAULT_ENCODING;
}
// set the default lang, if not given
if (session_id() && isset($_SESSION['DEFAULT_LANG']) && $_SESSION['DEFAULT_LANG']) {
$LANG = $_SESSION['DEFAULT_LANG'];
} else {
$LANG = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
}
// end the stop of the output flow, but only if we didn't request a csv file download
if (isset($_POST['action']) && $_POST['action'] != 'download_csv' && !$AJAX_PAGE) {
header("Content-type: text/html; charset=".$ENCODING);
@@ -55,15 +48,11 @@ if ($AJAX_PAGE && !$ZIP_STREAM) {
//------------------------------ class init start
// login & page access check
$login = new CoreLibs\ACL\Login(DB_CONFIG, $LANG);
// post login lang check
if (isset($_SESSION['DEFAULT_LANG'])) {
$LANG = $_SESSION['DEFAULT_LANG'];
}
$login = new CoreLibs\ACL\Login(DB_CONFIG);
// create smarty object
$smarty = new CoreLibs\Template\SmartyExtend($LANG);
$smarty = new CoreLibs\Template\SmartyExtend();
// create new DB class
$cms = new CoreLibs\Admin\Backend(DB_CONFIG, $LANG);
$cms = new CoreLibs\Admin\Backend(DB_CONFIG);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db nfo

View File

@@ -36,23 +36,19 @@ if (!DEBUG) {
$ECHO_ALL = 0;
}
// set default lang if not set otherwise
if (!isset($lang)) {
$lang = DEFAULT_LANG;
}
// should be utf8
header("Content-type: text/html; charset=".DEFAULT_ENCODING);
ob_end_flush();
$login = new CoreLibs\ACL\Login(DB_CONFIG, $lang);
$login = new CoreLibs\ACL\Login(DB_CONFIG);
// create form class
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $lang);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG);
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new CoreLibs\Template\SmartyExtend($lang);
$smarty = new CoreLibs\Template\SmartyExtend();
// $form->debug('POST', $form->printAr($_POST));
@@ -453,7 +449,7 @@ if (is_dir(BASE.TEMPLATES_C)) {
if (is_dir(BASE.CACHE)) {
$smarty->setCacheDir(BASE.CACHE);
}
$smarty->display($EDIT_TEMPLATE, 'editAdmin_'.$lang, 'editAdmin_'.$lang);
$smarty->display($EDIT_TEMPLATE, 'editAdmin_'.$smarty->lang, 'editAdmin_'.$smarty->lang);
// debug output
echo $login->printErrorMsg();

View File

@@ -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

View File

@@ -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
@@ -206,42 +208,6 @@ class Backend extends \CoreLibs\DB\IO
$this->dbExec($q, 'NULL');
}
/**
* helper function for PHP file upload error messgaes to messge string
* @param int $error_code integer _FILE upload error code
* @return string message string, translated
*/
public function fileUploadErrorMessage(int $error_code): string
{
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
break;
case UPLOAD_ERR_FORM_SIZE:
$message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
break;
case UPLOAD_ERR_PARTIAL:
$message = 'The uploaded file was only partially uploaded';
break;
case UPLOAD_ERR_NO_FILE:
$message = 'No file was uploaded';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = 'Missing a temporary folder';
break;
case UPLOAD_ERR_CANT_WRITE:
$message = 'Failed to write file to disk';
break;
case UPLOAD_ERR_EXTENSION:
$message = 'File upload stopped by extension';
break;
default:
$message = 'Unknown upload error';
break;
}
return $this->l->__($message);
}
/**
* menu creater (from login menu session pages)
* @param int $flag visible flag trigger

View File

@@ -891,6 +891,42 @@ class Basic
return "<pre>".print_r($array, true)."</pre>";
}
/**
* helper function for PHP file upload error messgaes to messge string
* @param int $error_code integer _FILE upload error code
* @return string message string, translated
*/
public function fileUploadErrorMessage(int $error_code): string
{
switch ($error_code) {
case UPLOAD_ERR_INI_SIZE:
$message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
break;
case UPLOAD_ERR_FORM_SIZE:
$message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
break;
case UPLOAD_ERR_PARTIAL:
$message = 'The uploaded file was only partially uploaded';
break;
case UPLOAD_ERR_NO_FILE:
$message = 'No file was uploaded';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = 'Missing a temporary folder';
break;
case UPLOAD_ERR_CANT_WRITE:
$message = 'Failed to write file to disk';
break;
case UPLOAD_ERR_EXTENSION:
$message = 'File upload stopped by extension';
break;
default:
$message = 'Unknown upload error';
break;
}
return $message;
}
// ****** DEBUG/ERROR FUNCTIONS ******
// ****** RANDOM KEY GEN ******

View File

@@ -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

View File

@@ -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
@@ -277,12 +280,7 @@ class SmartyExtend extends SmartyBC
private function setSmartyVars($admin_call = false): void
{
global $cms;
// array merge HEADER, DATA, DEBUG DATA
foreach (array('HEADER', 'DATA', 'DEBUG_DATA') as $ext_smarty) {
if (is_array($cms->{$ext_smarty})) {
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $cms->{$ext_smarty});
}
}
$this->mergeCmsSmartyVars($cms);
// trigger flags
$this->HEADER['USE_PROTOTYPE'] = $this->USE_PROTOTYPE;
@@ -389,7 +387,31 @@ class SmartyExtend extends SmartyBC
$this->DATA['CONTENT_INCLUDE'] = $this->CONTENT_INCLUDE;
$this->DATA['TEMPLATE_TRANSLATE'] = isset($this->TEMPLATE_TRANSLATE) ? $this->TEMPLATE_TRANSLATE : null;
$this->DATA['PAGE_FILE_NAME'] = str_replace('.php', '', $this->page_name).'.tpl';
// render page
$this->renderSmarty();
}
/**
* merge outside object HEADER/DATA/DEBUG_DATA vars into the smarty class
* @param object $cms object that has header/data/debug_data
* @return void
*/
public function mergeCmsSmartyVars(object $cms): void
{
// array merge HEADER, DATA, DEBUG DATA
foreach (array('HEADER', 'DATA', 'DEBUG_DATA') as $ext_smarty) {
if (is_array($cms->{$ext_smarty})) {
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $cms->{$ext_smarty});
}
}
}
/**
* render smarty data (can be called sepparate)
* @return void
*/
public function renderSmarty(): void
{
// create main data array
$this->CONTENT_DATA = array_merge($this->HEADER, $this->DATA, $this->DEBUG_DATA);
// data is 1:1 mapping (all vars, values, etc)