Last login value, minor update for array to [, smarty include core

When logged in, the last loggedin time is stored in the edit_user table,
additional to the normal logging.

More array() to [] conversion in config files, etc

Javascript: add math.round

Basic Class: Fix key length array mapping to more efficiont loop run
DB/IO: some name fixes in get key function description/comments
SmartyExtended: add CORE CSS/JS file include if exists. Follows after
MAIN and BEFORE page and special
This commit is contained in:
Clemens Schwaighofer
2021-01-21 06:55:28 +09:00
parent 85f701ab2a
commit 50073479d4
11 changed files with 105 additions and 88 deletions

View File

@@ -31,6 +31,7 @@ CREATE TABLE edit_user (
email VARCHAR, email VARCHAR,
protected SMALLINT NOT NULL DEFAULT 0, protected SMALLINT NOT NULL DEFAULT 0,
admin SMALLINT NOT NULL DEFAULT 0, admin SMALLINT NOT NULL DEFAULT 0,
last_login TIMESTAMP WITHOUT TIME ZONE,
login_error_count INT DEFAULT 0, login_error_count INT DEFAULT 0,
login_error_date_last TIMESTAMP WITHOUT TIME ZONE, login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
login_error_date_first TIMESTAMP WITHOUT TIME ZONE, login_error_date_first TIMESTAMP WITHOUT TIME ZONE,

View File

@@ -8,8 +8,8 @@
*********************************************************************/ *********************************************************************/
// please be VERY carefull only to change the right side // please be VERY carefull only to change the right side
$DB_CONFIG = array( $DB_CONFIG = [
'test' => array( 'test' => [
'db_name' => 'gullevek', 'db_name' => 'gullevek',
'db_user' => 'gullevek', 'db_user' => 'gullevek',
'db_pass' => 'gullevek', 'db_pass' => 'gullevek',
@@ -19,7 +19,7 @@ $DB_CONFIG = array(
'db_type' => 'pgsql', 'db_type' => 'pgsql',
'db_encoding' => '', 'db_encoding' => '',
'db_ssl' => 'disable' // allow, disable, require, prefer 'db_ssl' => 'disable' // allow, disable, require, prefer
) ]
); ];
// __END__ // __END__

View File

@@ -21,9 +21,9 @@
// ); // );
// each host has a different db_host // each host has a different db_host
$SITE_CONFIG = array( $SITE_CONFIG = [
// development host // development host
'soba.tokyo.tequila.jp' => array( 'soba.tokyo.tequila.jp' => [
// db config selection // db config selection
'db_host' => 'test', 'db_host' => 'test',
// other db connections // other db connections
@@ -37,8 +37,8 @@ $SITE_CONFIG = array(
'site_lang' => 'en_utf8', 'site_lang' => 'en_utf8',
// enable/disable login override // enable/disable login override
'login_enabled' => true 'login_enabled' => true
), ],
// 'other.host.com' => $__LOCAL_CONFIG // 'other.host.com' => $__LOCAL_CONFIG
); ];
// __END__ // __END__

View File

@@ -185,7 +185,7 @@ if (file_exists(BASE.CONFIGS.'config.host.php')) {
require BASE.CONFIGS.'config.host.php'; require BASE.CONFIGS.'config.host.php';
} }
if (!isset($SITE_CONFIG)) { if (!isset($SITE_CONFIG)) {
$SITE_CONFIG = array(); $SITE_CONFIG = [];
} }
/************* DB ACCESS *****************/ /************* DB ACCESS *****************/
if (file_exists(BASE.CONFIGS.'config.db.php')) { if (file_exists(BASE.CONFIGS.'config.db.php')) {
@@ -238,7 +238,7 @@ if ((array_key_exists('HTTPS', $_SERVER) && !empty($_SERVER['HTTPS']) && $_SERVE
} }
// define the db config set name, the db config and the db schema // define the db config set name, the db config and the db schema
define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']); define('DB_CONFIG_NAME', $SITE_CONFIG[HOST_NAME]['db_host']);
define('DB_CONFIG', isset($DB_CONFIG[DB_CONFIG_NAME]) ? $DB_CONFIG[DB_CONFIG_NAME] : array()); define('DB_CONFIG', isset($DB_CONFIG[DB_CONFIG_NAME]) ? $DB_CONFIG[DB_CONFIG_NAME] : []);
// define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']); // define('DB_CONFIG_TARGET', SITE_CONFIG[$HOST_NAME]['db_host_target']);
// define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']); // define('DB_CONFIG_OTHER', SITE_CONFIG[$HOST_NAME]['db_host_other']);
// override for login and global schemas // override for login and global schemas

View File

@@ -11,11 +11,11 @@
/************* CONVERT *******************/ /************* CONVERT *******************/
// this only needed if the external thumbnail create is used // this only needed if the external thumbnail create is used
$paths = array( $paths = [
'/bin', '/bin',
'/usr/bin', '/usr/bin',
'/usr/local/bin' '/usr/local/bin'
); ];
// find convert // find convert
foreach ($paths as $path) { foreach ($paths as $path) {
if (file_exists($path.DS.'convert') && is_file($path.DS.'convert')) { if (file_exists($path.DS.'convert') && is_file($path.DS.'convert')) {

View File

@@ -10,12 +10,12 @@
// File and Folder paths // File and Folder paths
// ID is TARGET (first array element) // ID is TARGET (first array element)
/*$PATHS = array( /*$PATHS = [
'test' => array( 'test' => [
'csv_path' => '', 'csv_path' => '',
'perl_bin' => '', 'perl_bin' => '',
'other_url' => '', 'other_url' => '',
) ]
)*/ ]*/
// __END__ // __END__

View File

@@ -22,7 +22,7 @@ if (!defined('DS')) {
exit('Base config unloadable'); exit('Base config unloadable');
} }
// find trigger name "admin/" or "frontend/" in the getcwd() folder // find trigger name "admin/" or "frontend/" in the getcwd() folder
foreach (array('admin', 'frontend') as $folder) { foreach (['admin', 'frontend'] as $folder) {
if (strstr(getcwd(), DS.$folder)) { if (strstr(getcwd(), DS.$folder)) {
define('CONTENT_PATH', $folder.DS); define('CONTENT_PATH', $folder.DS);
break; break;

View File

@@ -154,8 +154,8 @@ function __(string)
* simple sprintf formater for replace * simple sprintf formater for replace
* usage: "{0} is cool, {1} is not".format("Alpha", "Beta"); * usage: "{0} is cool, {1} is not".format("Alpha", "Beta");
* First, checks if it isn't implemented yet. * First, checks if it isn't implemented yet.
* @param {String} !String.prototype.format string with elements to be replaced * @param {String} String.prototype.format string with elements to be replaced
* @return {String} Formated string * @return {String} Formated string
*/ */
if (!String.prototype.format) { if (!String.prototype.format) {
String.prototype.format = function() String.prototype.format = function()
@@ -171,6 +171,18 @@ if (!String.prototype.format) {
}; };
} }
/**
* round to digits (float)
* @param {Float} Number.prototype.round Float type number to round
* @param {Number} prec Precision to round to
* @return {Float} Rounded number
*/
if (Number.prototype.round) {
Number.prototype.round = function (prec) {
return Math.round(this * Math.pow(10, prec)) / Math.pow(10, prec);
};
}
/** /**
* formats flat number 123456 to 123,456 * formats flat number 123456 to 123,456
* @param {Number} x number to be formated * @param {Number} x number to be formated
@@ -630,7 +642,7 @@ function showActionIndicator(loc)
/** /**
* hide action indicator, if it is visiable * hide action indicator, if it is visiable
* If the global variable GL_OB_S is > 10 then * If the global variable GL_OB_S is > GL_OB_BASE then
* the overlayBox is not hidden but the zIndex * the overlayBox is not hidden but the zIndex
* is set to this value * is set to this value
* @param {String} loc ID string, only used for console log * @param {String} loc ID string, only used for console log
@@ -954,7 +966,7 @@ function phfo(tree)
function phfa(list) function phfa(list)
{ {
var content = []; var content = [];
for (i = 0; i < list.length; i ++) { for (var i = 0; i < list.length; i ++) {
content.push(phfo(list[i])); content.push(phfo(list[i]));
} }
return content.join(''); return content.join('');

View File

@@ -976,15 +976,11 @@ class Basic
$use_key_length = $this->key_length; $use_key_length = $this->key_length;
} }
return join( $pieces = [];
'', for ($i = 1; $i <= $use_key_length; $i ++) {
array_map( $pieces[] = $this->key_range[random_int(0, $this->one_key_length - 1)];
function () { }
return $this->key_range[rand(0, $this->one_key_length - 1)]; return join('', $pieces);
},
range(1, $use_key_length)
)
);
} }
// ****** RANDOM KEY GEN ****** // ****** RANDOM KEY GEN ******

View File

@@ -1201,6 +1201,10 @@ class IO extends \CoreLibs\Basic
$this->db_functions->__dbResultType($assoc_only) $this->db_functions->__dbResultType($assoc_only)
) )
); );
// if returned is NOT an array, abort to false
if (!is_array($return)) {
$return = false;
}
} }
// check if cached call or reset call ... // check if cached call or reset call ...
if (!$return && !$reset) { if (!$return && !$reset) {
@@ -2076,11 +2080,11 @@ class IO extends \CoreLibs\Basic
* old call for getInserReturnExt * old call for getInserReturnExt
* @param string|null $key See above * @param string|null $key See above
* @return array|string|null See above * @return array|string|null See above
* @deprecated use getInsertReturnExt($key = null) instead * @deprecated use getReturningExt($key = null) instead
*/ */
public function getInsertReturn($key = null) public function getInsertReturn($key = null)
{ {
trigger_error('Method '.__METHOD__.' is deprecated, use getInsertReturnExt($key = null)', E_USER_DEPRECATED); trigger_error('Method '.__METHOD__.' is deprecated, use getReturningExt($key = null)', E_USER_DEPRECATED);
return $this->getReturningExt($key); return $this->getReturningExt($key);
} }

View File

@@ -67,6 +67,11 @@ class SmartyExtend extends SmartyBC
public $JS_TEMPLATE_NAME; public $JS_TEMPLATE_NAME;
public $CSS_TEMPLATE_NAME; public $CSS_TEMPLATE_NAME;
public $TEMPLATE_TRANSLATE; public $TEMPLATE_TRANSLATE;
// core group
public $JS_CORE_TEMPLATE_NAME;
public $CSS_CORE_TEMPLATE_NAME;
public $JS_CORE_INCLUDE;
public $CSS_CORE_INCLUDE;
// local names // local names
public $JS_SPECIAL_TEMPLATE_NAME = ''; public $JS_SPECIAL_TEMPLATE_NAME = '';
public $CSS_SPECIAL_TEMPLATE_NAME = ''; public $CSS_SPECIAL_TEMPLATE_NAME = '';
@@ -147,6 +152,55 @@ class SmartyExtend extends SmartyBC
$this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH; $this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH;
} }
/**
* @return void
*/
private function setSmartCoreIncludeCssJs(): void
{
// core CS
$this->CSS_CORE_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_CORE_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_CORE_TEMPLATE_NAME)
) {
$this->CSS_CORE_INCLUDE = $this->CSS.$this->CSS_CORE_TEMPLATE_NAME;
}
// core JS
$this->JS_CORE_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME)
) {
$this->JS_CORE_INCLUDE = $this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME;
}
// additional per page Javascript include
$this->JS_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME)
) {
$this->JS_INCLUDE = $this->JAVASCRIPT.$this->JS_TEMPLATE_NAME;
}
// per page css file
$this->CSS_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_TEMPLATE_NAME)
) {
$this->CSS_INCLUDE = $this->CSS.$this->CSS_TEMPLATE_NAME;
}
// optional CSS file
$this->CSS_SPECIAL_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME)
) {
$this->CSS_SPECIAL_INCLUDE = $this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$this->JS_SPECIAL_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME)
) {
$this->JS_SPECIAL_INCLUDE = $this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME;
}
}
/** /**
* sets all internal paths and names that need to be passed on to the smarty template * sets all internal paths and names that need to be passed on to the smarty template
@@ -196,34 +250,8 @@ class SmartyExtend extends SmartyBC
$this->COMPILE_ID .= '_'.$this->TEMPLATE_NAME; $this->COMPILE_ID .= '_'.$this->TEMPLATE_NAME;
$this->CACHE_ID .= '_'.$this->TEMPLATE_NAME; $this->CACHE_ID .= '_'.$this->TEMPLATE_NAME;
} }
// additional per page Javascript include // set all the additional CSS/JS parths
$this->JS_INCLUDE = ''; $this->setSmartCoreIncludeCssJs();
if (file_exists($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME)
) {
$this->JS_INCLUDE = $this->JAVASCRIPT.$this->JS_TEMPLATE_NAME;
}
// per page css file
$this->CSS_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_TEMPLATE_NAME)
) {
$this->CSS_INCLUDE = $this->CSS.$this->CSS_TEMPLATE_NAME;
}
// optional CSS file
$this->CSS_SPECIAL_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME)
) {
$this->CSS_SPECIAL_INCLUDE = $this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$this->JS_SPECIAL_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME)
) {
$this->JS_SPECIAL_INCLUDE = $this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME;
}
// check if template names exist // check if template names exist
if (!$this->MASTER_TEMPLATE_NAME) { if (!$this->MASTER_TEMPLATE_NAME) {
exit('MASTER TEMPLATE is not set'); exit('MASTER TEMPLATE is not set');
@@ -294,36 +322,12 @@ class SmartyExtend extends SmartyBC
// jquery and prototype should not be used together // jquery and prototype should not be used together
$this->HEADER['USE_JQUERY'] = $this->USE_JQUERY; $this->HEADER['USE_JQUERY'] = $this->USE_JQUERY;
// additional per page Javascript include // set all the additional CSS/JS parths
$this->JS_INCLUDE = ''; $this->setSmartCoreIncludeCssJs();
if (file_exists($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME)
) {
$this->JS_INCLUDE = $this->JAVASCRIPT.$this->JS_TEMPLATE_NAME;
}
// per page css file
$this->CSS_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_TEMPLATE_NAME)
) {
$this->CSS_INCLUDE = $this->CSS.$this->CSS_TEMPLATE_NAME;
}
// optional CSS file
$this->CSS_SPECIAL_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME)
) {
$this->CSS_SPECIAL_INCLUDE = $this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$this->JS_SPECIAL_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME)
) {
$this->JS_SPECIAL_INCLUDE = $this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME;
}
// the actual include files for javascript (per page) // the actual include files for javascript (per page)
$this->HEADER['JS_CORE_INCLUDE'] = $this->JS_CORE_INCLUDE;
$this->HEADER['CSS_CORE_INCLUDE'] = $this->CSS_CORE_INCLUDE;
$this->HEADER['JS_INCLUDE'] = $this->JS_INCLUDE; $this->HEADER['JS_INCLUDE'] = $this->JS_INCLUDE;
$this->HEADER['CSS_INCLUDE'] = $this->CSS_INCLUDE; $this->HEADER['CSS_INCLUDE'] = $this->CSS_INCLUDE;
$this->HEADER['CSS_SPECIAL_INCLUDE'] = $this->CSS_SPECIAL_INCLUDE; $this->HEADER['CSS_SPECIAL_INCLUDE'] = $this->CSS_SPECIAL_INCLUDE;