Remove \Basic class from all other Class extensions
If not created Logger class will be auto created in \DB\IO Recommended to run a CoreLibs\Debug\Logging([...]); and use this class for all ACL\Login, Admin\Backend, DB\IO, Output\Form\Generate calls. Last parameter after DB CONFIG is the log parameter Session create has been moved to a new Create\Session class from the \Basic class and MUST be started before using ACL\Login. Currently ACL\Login will fallback and start it if no session is yet started. See the Readme.md file for which classes use _SESSION data In future the _SESSION settings should be moved to some wrapper class for this so we can unit test sessions Only Output\Form\Generate class call has the new changed with the second parameter no longer beeing the table width setting but the class setting. But as this is a semi retired class and only used for edit_base this is not 100% breaking. All other classes can be used as is and have internal fallback to run as before. Deprecation messages will be added later.
This commit is contained in:
@@ -117,6 +117,8 @@ class Login extends \CoreLibs\DB\IO
|
||||
private $max_login_error_count = -1;
|
||||
/** @var array<string> */
|
||||
private $lock_deny_users = [];
|
||||
/** @var string */
|
||||
private $page_name;
|
||||
|
||||
// if we have password change we need to define some rules
|
||||
/** @var int */
|
||||
@@ -160,13 +162,20 @@ class Login extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||
* @param array<mixed> $db_config db config array
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, if null, auto set
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, if null, auto set
|
||||
*/
|
||||
public function __construct(array $db_config)
|
||||
{
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
?\CoreLibs\Debug\Logging $log = null,
|
||||
?\CoreLibs\Language\L10n $l10n = null
|
||||
) {
|
||||
// create db connection and init base class
|
||||
parent::__construct($db_config);
|
||||
parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging());
|
||||
// log login data for this class only
|
||||
$this->log->setLogPer('class', true);
|
||||
// set internal page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
// set db special errors
|
||||
if ($this->db_init_error === true) {
|
||||
echo 'Could not connect to DB<br>';
|
||||
@@ -174,7 +183,10 @@ class Login extends \CoreLibs\DB\IO
|
||||
exit;
|
||||
}
|
||||
|
||||
// no session could be found at all
|
||||
// initial the session if there is no session running already
|
||||
// TODO: move that to outside
|
||||
\CoreLibs\Create\Session::startSession();
|
||||
// check if session exists
|
||||
if (!session_id()) {
|
||||
echo '<b>Session not started!</b><br>Use \'session_start();\'.<br>';
|
||||
echo 'For less problems with other session, you can set a session name with \'session_name("name");\'.<br>';
|
||||
@@ -202,7 +214,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
} else {
|
||||
$lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
}
|
||||
$this->l = new \CoreLibs\Language\L10n($lang);
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n($lang);
|
||||
|
||||
// if we have a search path we need to set it, to use the correct DB to login
|
||||
// check what schema to use. if there is a login schema use this, else check
|
||||
|
||||
@@ -73,6 +73,8 @@ class Backend extends \CoreLibs\DB\IO
|
||||
// the current active edit access id
|
||||
/** @var int */
|
||||
public $edit_access_id;
|
||||
/** @var string */
|
||||
public $page_name;
|
||||
// error/warning/info messages
|
||||
/** @var array<mixed> */
|
||||
public $messages = [];
|
||||
@@ -108,15 +110,25 @@ class Backend extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* main class constructor
|
||||
* @param array<mixed> $db_config db config array
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, default set if not set
|
||||
*/
|
||||
public function __construct(array $db_config)
|
||||
{
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
?\CoreLibs\Debug\Logging $log = null
|
||||
) {
|
||||
// set to log not per class
|
||||
if ($log !== null) {
|
||||
$log->setLogPer('class', false);
|
||||
}
|
||||
$this->setLangEncoding();
|
||||
// get the language sub class & init it
|
||||
$this->l = new \CoreLibs\Language\L10n($this->lang);
|
||||
|
||||
// init the database class
|
||||
parent::__construct($db_config);
|
||||
parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging());
|
||||
|
||||
// set the page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
|
||||
@@ -77,21 +77,19 @@ class Basic
|
||||
/** @var array<mixed> */
|
||||
public $data_path = [];
|
||||
|
||||
// session name
|
||||
/** @var string */
|
||||
private $session_name = '';
|
||||
/** @var string */
|
||||
private $session_id = ''; /** @phpstan-ignore-line */
|
||||
|
||||
// ajax flag
|
||||
/** @var bool */
|
||||
protected $ajax_page_flag = false;
|
||||
|
||||
/**
|
||||
* main Basic constructor to init and check base settings
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
* @param string|null $session_name Set session name
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
public function __construct(
|
||||
\CoreLibs\Debug\Logging $log = null,
|
||||
?string $session_name = null
|
||||
) {
|
||||
// TODO make check dynamic for entries we MUST have depending on load type
|
||||
// before we start any work, we should check that all MUST constants are defined
|
||||
$abort = false;
|
||||
@@ -117,6 +115,9 @@ class Basic
|
||||
die('Core Constant missing. Check config file.');
|
||||
}
|
||||
|
||||
// logging interface moved here (->debug is now ->log->debug)
|
||||
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
||||
|
||||
// set ajax page flag based on the AJAX_PAGE varaibles
|
||||
// convert to true/false so if AJAX_PAGE is 0 or false it is
|
||||
// always boolean false
|
||||
@@ -136,8 +137,6 @@ class Basic
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
// set host name
|
||||
list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName();
|
||||
// logging interface moved here (->debug is now ->log->debug)
|
||||
$this->log = new \CoreLibs\Debug\Logging();
|
||||
|
||||
// set the regex for checking emails
|
||||
/** @deprecated */
|
||||
@@ -147,25 +146,7 @@ class Basic
|
||||
$this->email_regex_check = \CoreLibs\Check\Email::getEmailRegexCheck();
|
||||
|
||||
// initial the session if there is no session running already
|
||||
if (!session_id()) {
|
||||
// check if we have an external session name given, else skip this step
|
||||
if (defined('SET_SESSION_NAME')) {
|
||||
// set the session name for possible later check
|
||||
$this->session_name = SET_SESSION_NAME;
|
||||
}
|
||||
// override with global if set
|
||||
if (isset($GLOBALS['SET_SESSION_NAME'])) {
|
||||
$this->session_name = $GLOBALS['SET_SESSION_NAME'];
|
||||
}
|
||||
// if set, set special session name
|
||||
if ($this->session_name) {
|
||||
session_name($this->session_name);
|
||||
}
|
||||
// start session
|
||||
session_start();
|
||||
// set internal session id, we can use that later for protection check
|
||||
$this->session_id = (string)session_id();
|
||||
}
|
||||
\CoreLibs\Create\Session::startSession($session_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
74
www/lib/CoreLibs/Create/Session.php
Normal file
74
www/lib/CoreLibs/Create/Session.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* start a php sesseion
|
||||
* name can be given via startSession parameter
|
||||
* if not set tries to read $SET_SESSION_NAME from global
|
||||
* if this is not set tries to read SET_SESSION_NAME constant
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Create;
|
||||
|
||||
class Session
|
||||
{
|
||||
/**
|
||||
* init a session
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string|null $session_name
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function startSession(?string $session_name = null)
|
||||
{
|
||||
// initial the session if there is no session running already
|
||||
if (!session_id()) {
|
||||
$session_name = $session_name ?? $GLOBALS['SET_SESSION_NAME'] ?? '';
|
||||
// check if we have an external session name given, else skip this step
|
||||
if (
|
||||
empty($session_name) &&
|
||||
defined('SET_SESSION_NAME') &&
|
||||
!empty(SET_SESSION_NAME)
|
||||
) {
|
||||
// set the session name for possible later check
|
||||
$session_name = SET_SESSION_NAME;
|
||||
}
|
||||
// if set, set special session name
|
||||
if (!empty($session_name)) {
|
||||
session_name($session_name);
|
||||
}
|
||||
// start session
|
||||
session_start();
|
||||
}
|
||||
return self::getSessionId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function getSessionId()
|
||||
{
|
||||
return session_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function getSessionName()
|
||||
{
|
||||
return session_name();
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -53,11 +53,16 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
* @param array<mixed> $db_config db connection config
|
||||
* @param array<mixed> $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, default set if not set
|
||||
*/
|
||||
public function __construct(array $db_config, array $table_array, string $table_name)
|
||||
{
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
array $table_array,
|
||||
string $table_name,
|
||||
\CoreLibs\Debug\Logging $log = null
|
||||
) {
|
||||
// instance db_io class
|
||||
parent::__construct($db_config);
|
||||
parent::__construct($db_config, $log ?? new \CoreLibs\Debug\Logging());
|
||||
// more error vars for this class
|
||||
$this->error_string['91'] = 'No Primary Key given';
|
||||
$this->error_string['92'] = 'Could not run Array Query';
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
* - used for recursive function [var might disappear if I have time to recode the recursive function]
|
||||
*
|
||||
* PUBLIC METHODS
|
||||
* $mixed db_return($query,$reset=0)
|
||||
* $mixed db_return($query,$reset=self::USE_CACHE)
|
||||
* - executes query, returns data & caches it (1 = reset/destroy, 2 = reset/cache, 3 = reset/no cache)
|
||||
* 1/0 db_cache_reset($query)
|
||||
* - resets the cache for one query
|
||||
@@ -252,8 +252,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\DB;
|
||||
|
||||
class IO extends \CoreLibs\Basic
|
||||
class IO
|
||||
{
|
||||
// 0: normal read, store in cache
|
||||
// 1: read cache, clean at the end
|
||||
// 2: read new, clean at end
|
||||
// 3: never cache
|
||||
/** @var int */
|
||||
public const USE_CACHE = 0;
|
||||
/** @var int */
|
||||
public const CLEAR_CACHE = 1;
|
||||
/** @var int */
|
||||
public const READ_NEW = 2;
|
||||
/** @var int */
|
||||
public const NO_CACHE = 3;
|
||||
|
||||
// recommend to set private/protected and only allow setting via method
|
||||
// can bet set from outside
|
||||
// encoding to
|
||||
@@ -265,8 +278,8 @@ class IO extends \CoreLibs\Basic
|
||||
// basic vars
|
||||
/** @var resource|bool|int|null */
|
||||
private $dbh; // the dbh handler, if disconnected by command is null, bool:false/int:-1 on error,
|
||||
/** @var int|bool */
|
||||
public $db_debug; // DB_DEBUG ... (if set prints out debug msgs) [should be bool only]
|
||||
/** @var bool */
|
||||
public $db_debug = false; // DB_DEBUG ... (if set prints out debug msgs)
|
||||
/** @var string */
|
||||
private $db_name; // the DB connected to
|
||||
/** @var string */
|
||||
@@ -320,12 +333,11 @@ class IO extends \CoreLibs\Basic
|
||||
// sub include with the database functions
|
||||
/** @var \CoreLibs\DB\SQL\PgSQL */
|
||||
private $db_functions;
|
||||
|
||||
// endless loop protection
|
||||
/** @var int */
|
||||
private $MAX_QUERY_CALL;
|
||||
/** @var int */
|
||||
private $DEFAULT_MAX_QUERY_CALL = 20; // default
|
||||
private const DEFAULT_MAX_QUERY_CALL = 20; // default
|
||||
/** @var array<mixed> */
|
||||
private $query_called = [];
|
||||
// error string
|
||||
@@ -347,20 +359,21 @@ class IO extends \CoreLibs\Basic
|
||||
// if a sync is running holds the md5 key of the query
|
||||
/** @var string */
|
||||
private $async_running;
|
||||
// logging class, must be public so settings can be changed
|
||||
/** @var \CoreLibs\Debug\Logging */
|
||||
public $log;
|
||||
|
||||
/**
|
||||
* main DB concstructor with auto connection to DB and failure set on failed connection
|
||||
* @param array<mixed> $db_config DB configuration array
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
*/
|
||||
public function __construct(array $db_config)
|
||||
{
|
||||
// start basic class
|
||||
parent::__construct();
|
||||
// dummy init array for db config if not array
|
||||
if (!is_array($db_config)) {
|
||||
$db_config = [];
|
||||
}
|
||||
// TODO: check must set CONSTANTS
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
?\CoreLibs\Debug\Logging $log = null
|
||||
) {
|
||||
// attach logger
|
||||
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
||||
// sets the names (for connect/reconnect)
|
||||
$this->db_name = $db_config['db_name'] ?? '';
|
||||
$this->db_user = $db_config['db_user'] ?? '';
|
||||
@@ -372,12 +385,14 @@ class IO extends \CoreLibs\Basic
|
||||
$this->db_encoding = !empty($db_config['db_encoding']) ? $db_config['db_encoding'] : '';
|
||||
$this->db_type = $db_config['db_type'] ?? '';
|
||||
$this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow';
|
||||
// set debug, either via global var, or from config, else set to false
|
||||
$this->dbSetDebug($GLOBALS['DB_DEBUG'] ?? $db_config['db_debug'] ?? false);
|
||||
|
||||
// set the target encoding to the DEFAULT_ENCODING if it is one of them: EUC, Shift_JIS, UTF-8
|
||||
// @ the moment set only from outside
|
||||
|
||||
// set loop protection max count
|
||||
$this->MAX_QUERY_CALL = 20;
|
||||
$this->MAX_QUERY_CALL = self::DEFAULT_MAX_QUERY_CALL;
|
||||
|
||||
// error & debug stuff, error & warning ids are the same, its just in which var they get written
|
||||
$this->error_string['10'] = 'Could not load DB interface functions';
|
||||
@@ -409,13 +424,6 @@ class IO extends \CoreLibs\Basic
|
||||
$this->error_string['50'] = 'Setting max query call to -1 will disable loop protection for all subsequent runs';
|
||||
$this->error_string['51'] = 'Max query call needs to be set to at least 1';
|
||||
|
||||
// set debug, either via global var, or debug var during call
|
||||
$this->db_debug = false;
|
||||
// global overrules local
|
||||
if (isset($GLOBALS['DB_DEBUG'])) {
|
||||
$this->db_debug = $GLOBALS['DB_DEBUG'];
|
||||
}
|
||||
|
||||
// based on $this->db_type
|
||||
// here we need to load the db pgsql include one
|
||||
// How can we do this dynamic? eg for non PgSQL
|
||||
@@ -444,7 +452,6 @@ class IO extends \CoreLibs\Basic
|
||||
public function __destruct()
|
||||
{
|
||||
$this->__closeDB();
|
||||
// parent::__destruct();
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
@@ -982,18 +989,16 @@ class IO extends \CoreLibs\Basic
|
||||
* the previous setting to either then on or off
|
||||
* else override with boolean true/false
|
||||
* @param bool|null $debug true/false or null for no set
|
||||
* @return int debug flag in int
|
||||
* @return bool debug flag in int
|
||||
*/
|
||||
public function dbSetDebug($debug = null): int
|
||||
public function dbSetDebug($debug = null): bool
|
||||
{
|
||||
if ($debug === true) {
|
||||
$this->db_debug = 1;
|
||||
$this->db_debug = true;
|
||||
} elseif ($debug === false) {
|
||||
$this->db_debug = 0;
|
||||
} elseif ($this->db_debug) {
|
||||
$this->db_debug = 0;
|
||||
} else {
|
||||
$this->db_debug = 1;
|
||||
$this->db_debug = false;
|
||||
} elseif ($this->db_debug === null) {
|
||||
$this->db_debug = false;
|
||||
}
|
||||
return $this->db_debug;
|
||||
}
|
||||
@@ -1006,7 +1011,7 @@ class IO extends \CoreLibs\Basic
|
||||
* @param bool|null $debug Flag to turn debug on off
|
||||
* @return bool True for debug is on, False for off
|
||||
*/
|
||||
public function dbToggleDebug(?bool $debug = null)
|
||||
public function dbToggleDebug(?bool $debug = null): bool
|
||||
{
|
||||
if ($debug !== null) {
|
||||
$this->db_debug = $debug;
|
||||
@@ -1028,7 +1033,7 @@ class IO extends \CoreLibs\Basic
|
||||
$success = false;
|
||||
// if null then reset to default
|
||||
if ($max_calls === null) {
|
||||
$max_calls = $this->DEFAULT_MAX_QUERY_CALL;
|
||||
$max_calls = self::DEFAULT_MAX_QUERY_CALL;
|
||||
}
|
||||
// if -1 then disable loop check
|
||||
// DANGEROUS, WARN USER
|
||||
@@ -1272,17 +1277,18 @@ class IO extends \CoreLibs\Basic
|
||||
* (wheres 1 reads cache AND destroys at end of read)
|
||||
* - if set to 3, after EACH row, the data will be reset,
|
||||
* no caching is done except for basic (count, etc)
|
||||
* @param string $query Query string
|
||||
* @param int $reset reset status:
|
||||
* 1: read cache, clean at the end
|
||||
* 2: read new, clean at end
|
||||
* 3: never cache
|
||||
* @param bool $assoc_only true to only returned the named and not
|
||||
* index position ones
|
||||
* @return array<mixed>|bool return array data or false on error/end
|
||||
* @param string $query Query string
|
||||
* @param int $reset reset status:
|
||||
* USE_CACHE/0: normal read from cache on second run
|
||||
* CLEAR_CACHE/1: read cache, clean at the end
|
||||
* READ_NEW/2: read new, clean at end
|
||||
* NO_CACHE/3: never cache
|
||||
* @param bool $assoc_only True to only returned the named and not
|
||||
* index position ones
|
||||
* @return array<mixed>|bool return array data or false on error/end
|
||||
* @#suppress PhanTypeMismatchDimFetch
|
||||
*/
|
||||
public function dbReturn(string $query, int $reset = 0, bool $assoc_only = false)
|
||||
public function dbReturn(string $query, int $reset = self::USE_CACHE, bool $assoc_only = false)
|
||||
{
|
||||
if (!$query) {
|
||||
$this->error_id = 11;
|
||||
@@ -1445,11 +1451,18 @@ class IO extends \CoreLibs\Basic
|
||||
}
|
||||
} else {
|
||||
// return row, if last && reset, then unset the hole md5 array
|
||||
if (!$return && ($reset == 1 || $reset == 3) && $this->cursor_ext[$md5]['pos']) {
|
||||
if (
|
||||
!$return &&
|
||||
($reset == self::CLEAR_CACHE || $reset == self::NO_CACHE) &&
|
||||
$this->cursor_ext[$md5]['pos']
|
||||
) {
|
||||
// unset only the field names here of course
|
||||
$this->cursor_ext[$md5]['field_names'] = null;
|
||||
$this->cursor_ext[$md5]['pos'] = 0;
|
||||
} elseif (!$return && $reset == 2 && $this->cursor_ext[$md5]['pos']) {
|
||||
} elseif (
|
||||
!$return && $reset == self::READ_NEW &&
|
||||
$this->cursor_ext[$md5]['pos']
|
||||
) {
|
||||
// at end of read reset pos & set cursor to 1 (so it does not get lost in session transfer)
|
||||
$this->cursor_ext[$md5]['pos'] = 0;
|
||||
$this->cursor_ext[$md5]['cursor'] = 1;
|
||||
@@ -1461,7 +1474,7 @@ class IO extends \CoreLibs\Basic
|
||||
$this->cursor_ext[$md5]['pos'] ++;
|
||||
$this->cursor_ext[$md5]['read_rows'] ++;
|
||||
// if reset is <3 caching is done, else no
|
||||
if ($reset < 3) {
|
||||
if ($reset < self::NO_CACHE) {
|
||||
$temp = [];
|
||||
foreach ($return as $field_name => $data) {
|
||||
$temp[$field_name] = $data;
|
||||
|
||||
@@ -24,8 +24,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Debug;
|
||||
|
||||
use CoreLibs\Debug\Support;
|
||||
use CoreLibs\Create\Hash;
|
||||
use CoreLibs\Get\System;
|
||||
use CoreLibs\Convert\Html;
|
||||
|
||||
class Logging
|
||||
{
|
||||
// options
|
||||
/** @var array<mixed> */
|
||||
private $options = [];
|
||||
// page and host name
|
||||
/** @var string */
|
||||
private $page_name;
|
||||
@@ -66,12 +74,16 @@ class Logging
|
||||
private $log_folder = '';
|
||||
/** @var string */
|
||||
private $log_file_name_ext = 'log'; // use this for date rotate
|
||||
/** @var string */
|
||||
private $log_file_name = '';
|
||||
/** @var int */
|
||||
private $log_max_filesize = 0; // set in kilobytes
|
||||
/** @var string */
|
||||
private $log_print_file = 'error_msg##LOGID####LEVEL####CLASS####PAGENAME####DATE##';
|
||||
/** @var string */
|
||||
private $log_file_unique_id; // a unique ID set only once for call derived from this class
|
||||
/** @var string */
|
||||
private $log_file_date = ''; // Y-m-d file in file name
|
||||
/** @var bool */
|
||||
private $log_print_file_date = true; // if set add Y-m-d and do automatic daily rotation
|
||||
/** @var string */
|
||||
@@ -88,30 +100,82 @@ class Logging
|
||||
/** @var float */
|
||||
private $script_starttime;
|
||||
|
||||
public function __construct()
|
||||
/**
|
||||
* Init logger
|
||||
*
|
||||
* global vars that can be used
|
||||
* - BASE
|
||||
* - LOG
|
||||
* - LOG_FILE_ID
|
||||
* options array layout
|
||||
* - log_folder:
|
||||
* - print_file_date:
|
||||
* - file_id:
|
||||
* - unique_id:
|
||||
* - log_per_level:
|
||||
* - log_per_class:
|
||||
* - log_per_page:
|
||||
* - log_per_run:
|
||||
* - debug_all:
|
||||
* - echo_all:
|
||||
* - print_all:
|
||||
* - debug (array):
|
||||
* - echo (array):
|
||||
* - print (array):
|
||||
* - debug_not (array):
|
||||
* - echo_not (array):
|
||||
* - print_not (array):
|
||||
*
|
||||
* @param array<mixed> $options Array with settings options
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
// check must set constants
|
||||
if (defined('BASE') && defined('LOG')) {
|
||||
// copy the options over
|
||||
$this->options = $options;
|
||||
// set log folder from options
|
||||
$this->log_folder = $this->options['log_folder'] ?? '';
|
||||
// legacy flow, check must set constants
|
||||
if (empty($this->log_folder) && defined('BASE') && defined('LOG')) {
|
||||
// make sure this is writeable, else skip
|
||||
$this->log_folder = BASE . LOG;
|
||||
} else {
|
||||
// fallback + warning
|
||||
trigger_error('constant BASE or LOG are not defined, fallback to getcwd()', E_USER_WARNING);
|
||||
$this->log_folder = getcwd() . DS;
|
||||
}
|
||||
// fallback + notice
|
||||
if (empty($this->log_folder)) {
|
||||
/* trigger_error(
|
||||
'options or constant not set or folder not writable. fallback to: ' . getcwd(),
|
||||
E_USER_NOTICE
|
||||
); */
|
||||
$this->log_folder = getcwd() . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
// if folder is not writeable, abort
|
||||
if (!is_writeable($this->log_folder)) {
|
||||
trigger_error(
|
||||
'Folder: ' . $this->log_folder . ' is not writeable for logging',
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
// check if log_folder has a trailing /
|
||||
if (substr($this->log_folder, -1, 1) != DIRECTORY_SEPARATOR) {
|
||||
$this->log_folder .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
// running time start for script
|
||||
$this->script_starttime = microtime(true);
|
||||
// set per run UID for logging
|
||||
$this->running_uid = \CoreLibs\Create\Hash::__uniqId();
|
||||
$this->running_uid = Hash::__uniqId();
|
||||
// set the page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
$this->page_name = System::getPageName();
|
||||
// set host name
|
||||
list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName();
|
||||
list($this->host_name , $this->host_port) = System::getHostName();
|
||||
// add port to host name if not port 80
|
||||
if ($this->host_port != 80) {
|
||||
$this->host_name .= ':' . $this->host_port;
|
||||
}
|
||||
// can be overridden with basicSetLogFileId
|
||||
if (isset($GLOBALS['LOG_FILE_ID'])) {
|
||||
|
||||
// can be overridden with basicSetLogFileId later
|
||||
if (!empty($this->options['file_id'])) {
|
||||
$this->basicSetLogId($this->options['file_id'] ?? '');
|
||||
} elseif (!empty($GLOBALS['LOG_FILE_ID'])) {
|
||||
// legacy flow, should be removed and only set via options
|
||||
$this->basicSetLogId($GLOBALS['LOG_FILE_ID']);
|
||||
} elseif (defined('LOG_FILE_ID')) {
|
||||
$this->basicSetLogId(LOG_FILE_ID);
|
||||
@@ -132,38 +196,90 @@ class Logging
|
||||
{
|
||||
// if given via parameters, only for all
|
||||
// globals overrule given settings, for one (array), eg $ECHO['db'] = 1;
|
||||
if (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) {
|
||||
if (isset($this->options['debug']) && is_array($this->options['debug'])) {
|
||||
$this->debug_output = $this->options['debug'];
|
||||
} elseif (isset($GLOBALS['DEBUG']) && is_array($GLOBALS['DEBUG'])) {
|
||||
$this->debug_output = $GLOBALS['DEBUG'];
|
||||
}
|
||||
if (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) {
|
||||
if (isset($this->options['echo']) && is_array($this->options['echo'])) {
|
||||
$this->debug_output = $this->options['echo'];
|
||||
} elseif (isset($GLOBALS['ECHO']) && is_array($GLOBALS['ECHO'])) {
|
||||
$this->echo_output = $GLOBALS['ECHO'];
|
||||
}
|
||||
if (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) {
|
||||
if (isset($this->options['print']) && is_array($this->options['print'])) {
|
||||
$this->debug_output = $this->options['print'];
|
||||
} elseif (isset($GLOBALS['PRINT']) && is_array($GLOBALS['PRINT'])) {
|
||||
$this->print_output = $GLOBALS['PRINT'];
|
||||
}
|
||||
|
||||
// exclude these ones from output
|
||||
if (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) {
|
||||
if (isset($this->options['debug_not']) && is_array($this->options['debug_not'])) {
|
||||
$this->debug_output = $this->options['debug_not'];
|
||||
} elseif (isset($GLOBALS['DEBUG_NOT']) && is_array($GLOBALS['DEBUG_NOT'])) {
|
||||
$this->debug_output_not = $GLOBALS['DEBUG_NOT'];
|
||||
}
|
||||
if (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) {
|
||||
if (isset($this->options['echo_not']) && is_array($this->options['echo_not'])) {
|
||||
$this->debug_output = $this->options['echo_not'];
|
||||
} elseif (isset($GLOBALS['ECHO_NOT']) && is_array($GLOBALS['ECHO_NOT'])) {
|
||||
$this->echo_output_not = $GLOBALS['ECHO_NOT'];
|
||||
}
|
||||
if (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) {
|
||||
if (isset($this->options['print_not']) && is_array($this->options['print_not'])) {
|
||||
$this->debug_output = $this->options['print_not'];
|
||||
} elseif (isset($GLOBALS['PRINT_NOT']) && is_array($GLOBALS['PRINT_NOT'])) {
|
||||
$this->print_output_not = $GLOBALS['PRINT_NOT'];
|
||||
}
|
||||
|
||||
// all overrule
|
||||
$this->debug_output_all = $GLOBALS['DEBUG_ALL'] ?? false;
|
||||
$this->echo_output_all = $GLOBALS['ECHO_ALL'] ?? false;
|
||||
$this->print_output_all = $GLOBALS['PRINT_ALL'] ?? false;
|
||||
$this->debug_output_all =
|
||||
$this->options['debug_all'] ??
|
||||
$GLOBALS['DEBUG_ALL'] ??
|
||||
false;
|
||||
$this->echo_output_all =
|
||||
$this->options['echo_all'] ??
|
||||
$GLOBALS['ECHO_ALL'] ??
|
||||
false;
|
||||
$this->print_output_all =
|
||||
$this->options['print_all'] ??
|
||||
$GLOBALS['PRINT_ALL'] ??
|
||||
false;
|
||||
|
||||
// GLOBAL rules for log writing
|
||||
$this->log_print_file_date = $GLOBALS['LOG_PRINT_FILE_DATE'] ?? true;
|
||||
$this->log_per_level = $GLOBALS['LOG_PER_LEVEL'] ?? false;
|
||||
$this->log_per_class = $GLOBALS['LOG_PER_CLASS'] ?? false;
|
||||
$this->log_per_page = $GLOBALS['LOG_PER_PAGE'] ?? false;
|
||||
$this->log_per_run = $GLOBALS['LOG_PER_RUN'] ?? false;
|
||||
$this->log_print_file_date =
|
||||
$this->options['print_file_date'] ??
|
||||
$GLOBALS['LOG_PRINT_FILE_DATE'] ??
|
||||
true;
|
||||
$this->log_per_level =
|
||||
$this->options['per_level'] ??
|
||||
$GLOBALS['LOG_PER_LEVEL'] ??
|
||||
false;
|
||||
$this->log_per_class =
|
||||
$this->options['per_class'] ??
|
||||
$GLOBALS['LOG_PER_CLASS'] ??
|
||||
false;
|
||||
$this->log_per_page =
|
||||
$this->options['per_page'] ??
|
||||
$GLOBALS['LOG_PER_PAGE'] ??
|
||||
false;
|
||||
$this->log_per_run =
|
||||
$this->options['per_run'] ??
|
||||
$GLOBALS['LOG_PER_RUN'] ??
|
||||
false;
|
||||
// set log per date
|
||||
if ($this->log_print_file_date) {
|
||||
$this->log_file_date = date('Y-m-d');
|
||||
}
|
||||
// set per run ID
|
||||
if ($this->log_per_run) {
|
||||
/* if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) {
|
||||
$this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
|
||||
} */
|
||||
if (!$this->log_file_unique_id) {
|
||||
// $GLOBALS['LOG_FILE_UNIQUE_ID'] =
|
||||
$this->log_file_unique_id =
|
||||
date('Y-m-d_His') . '_U_'
|
||||
. substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,18 +354,13 @@ class Logging
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
// replace all html tags
|
||||
// $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string);
|
||||
// $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string);
|
||||
// replace special line break tag
|
||||
// $error_string = str_replace('<!--#BR#-->', "\n", $error_string);
|
||||
|
||||
// init output variable
|
||||
$output = $error_string; // output formated error string to output file
|
||||
// init base file path
|
||||
$fn = $this->log_folder . $this->log_print_file . '.' . $this->log_file_name_ext;
|
||||
// log ID prefix settings, if not valid, replace with empty
|
||||
if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) {
|
||||
if (!empty($this->log_file_id)) {
|
||||
$rpl_string = '_' . $this->log_file_id;
|
||||
} else {
|
||||
$rpl_string = '';
|
||||
@@ -257,17 +368,9 @@ class Logging
|
||||
$fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix)
|
||||
|
||||
if ($this->log_per_run) {
|
||||
if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) {
|
||||
$this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
|
||||
}
|
||||
if (!$this->log_file_unique_id) {
|
||||
$GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id =
|
||||
date('Y-m-d_His') . '_U_'
|
||||
. substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
|
||||
}
|
||||
$rpl_string = '_' . $this->log_file_unique_id; // add 8 char unique string
|
||||
} else {
|
||||
$rpl_string = !$this->log_print_file_date ? '' : '_' . date('Y-m-d'); // add date to file
|
||||
} elseif ($this->log_print_file_date) {
|
||||
$rpl_string = '_' . $this->log_file_date; // add date to file
|
||||
}
|
||||
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
|
||||
|
||||
@@ -276,11 +379,13 @@ class Logging
|
||||
// set per class, but don't use get_class as we will only get self
|
||||
$rpl_string = !$this->log_per_class ? '' : '_'
|
||||
// set sub class settings
|
||||
. str_replace('\\', '-', \CoreLibs\Debug\Support::getCallerClass());
|
||||
. str_replace('\\', '-', Support::getCallerClass());
|
||||
$fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename
|
||||
|
||||
// if request to write to one file
|
||||
$rpl_string = !$this->log_per_page ? '' : '_' . \CoreLibs\Get\System::getPageName(1);
|
||||
$rpl_string = !$this->log_per_page ?
|
||||
'' :
|
||||
'_' . System::getPageName(System::NO_EXTENSION);
|
||||
$fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename
|
||||
|
||||
// write to file
|
||||
@@ -289,32 +394,30 @@ class Logging
|
||||
// for easy purpose, rename file only to attach timestamp, nur sequence numbering
|
||||
rename($fn, $fn . '.' . date("YmdHis"));
|
||||
}
|
||||
$fp = fopen($fn, 'a');
|
||||
$this->log_file_name = $fn;
|
||||
$fp = fopen($this->log_file_name, 'a');
|
||||
if ($fp !== false) {
|
||||
fwrite($fp, $output);
|
||||
fclose($fp);
|
||||
} else {
|
||||
echo "<!-- could not open file: $fn //-->";
|
||||
echo "<!-- could not open file: " . $this->log_file_name . " //-->";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Superseeded by \CoreLibs\Debug\Support::getCallerClass() calls
|
||||
*
|
||||
* @return string Class name where called
|
||||
* @deprecated Use \CoreLibs\Debug\Support::getCallerClass() insteader
|
||||
*/
|
||||
private function getCallerClass(): string
|
||||
{
|
||||
// get the last class entry and wrie that
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
// make sure if false it is an array and then check if not class set return empty string
|
||||
return (end($backtrace) ?: [])['class'] ?? '';
|
||||
}
|
||||
|
||||
// *** PUBLIC ***
|
||||
|
||||
/**
|
||||
* Temporary method to read all class variables for testing purpose
|
||||
* @param string $name
|
||||
* @return mixed can be anything, bool, string, int, array
|
||||
*/
|
||||
public function getSetting(string $name): mixed
|
||||
{
|
||||
// for debug purpose only
|
||||
return $this->{$name};
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the internal log file prefix id
|
||||
* string must be a alphanumeric string
|
||||
@@ -324,12 +427,51 @@ class Logging
|
||||
*/
|
||||
public function basicSetLogId(string $string): string
|
||||
{
|
||||
if (preg_match("/^\w+$/", $string)) {
|
||||
if (preg_match("/^[\w\-]+$/", $string)) {
|
||||
$this->log_file_id = $string;
|
||||
}
|
||||
return $this->log_file_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* return current set log file id
|
||||
* @return string
|
||||
*/
|
||||
public function getLogId(): string
|
||||
{
|
||||
return $this->log_file_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* old name for setLogLevel
|
||||
* @param string $type debug, echo, print
|
||||
* @param string $flag on/off
|
||||
* array $array of levels to turn on/off debug
|
||||
* @return bool Return false if type or flag is invalid
|
||||
*/
|
||||
public function debugFor(string $type, string $flag): bool
|
||||
{
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal, PhanParamTooFew @phpstan-ignore-next-line */
|
||||
return $this->setLogLevel(...[func_get_args()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* set log level settings for All types
|
||||
* if invalid type, skip
|
||||
* @param string $type Type to get: debug, echo, print
|
||||
* @param bool $set True or False
|
||||
* @return bool Return false if type invalid
|
||||
*/
|
||||
public function setLogLevelAll(string $type, bool $set): bool
|
||||
{
|
||||
// skip set if not valid
|
||||
if (!in_array($type, ['debug', 'echo', 'print'])) {
|
||||
return false;
|
||||
}
|
||||
$this->{$type . '_output_all'} = $set;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current log level setting for All level blocks
|
||||
* @param string $type Type to get: debug, echo, print
|
||||
@@ -344,35 +486,6 @@ class Logging
|
||||
return $this->{$type . '_output_all'};
|
||||
}
|
||||
|
||||
/**
|
||||
* set log level settings for All types
|
||||
* if invalid type, skip
|
||||
* @param string $type Type to get: debug, echo, print
|
||||
* @param bool $set True or False
|
||||
* @return void No return
|
||||
*/
|
||||
public function setLogLevelAll(string $type, bool $set): void
|
||||
{
|
||||
// skip set if not valid
|
||||
if (!in_array($type, ['debug', 'echo', 'print'])) {
|
||||
return;
|
||||
}
|
||||
$this->{$type . '_output_all'} = $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* old name for setLogLevel
|
||||
* @param string $type debug, echo, print
|
||||
* @param string $flag on/off
|
||||
* array $array of levels to turn on/off debug
|
||||
* @return void has no return
|
||||
*/
|
||||
public function debugFor(string $type, string $flag): void
|
||||
{
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal, PhanParamTooFew @phpstan-ignore-next-line */
|
||||
$this->setLogLevel(...[func_get_args()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* passes list of level names, to turn on debug
|
||||
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
|
||||
@@ -380,17 +493,17 @@ class Logging
|
||||
* @param string $type debug, echo, print
|
||||
* @param string $flag on/off
|
||||
* array $array of levels to turn on/off debug
|
||||
* @return void has no return
|
||||
* @return bool Return false if type or falg invalid
|
||||
*/
|
||||
public function setLogLevel(string $type, string $flag): void
|
||||
public function setLogLevel(string $type, string $flag): bool
|
||||
{
|
||||
// abort if not valid type
|
||||
if (!in_array($type, ['debug', 'echo', 'print'])) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// invalid flag type
|
||||
if (!in_array($flag, ['on', 'off'])) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$debug_on = func_get_args();
|
||||
array_shift($debug_on); // kick out type
|
||||
@@ -401,6 +514,7 @@ class Logging
|
||||
$this->{$switch}[$level] = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -438,14 +552,15 @@ class Logging
|
||||
* - run: for each run
|
||||
* @param string $type Type to get: level, class, page, run
|
||||
* @param bool $set True or False
|
||||
* @return void
|
||||
* @return bool Return false if type invalid
|
||||
*/
|
||||
public function setLogPer(string $type, bool $set): void
|
||||
public function setLogPer(string $type, bool $set): bool
|
||||
{
|
||||
if (!in_array($type, ['level', 'class', 'page', 'run'])) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$this->{'log_per_' . $type} = $set;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -493,16 +608,16 @@ class Logging
|
||||
return false;
|
||||
}
|
||||
// get the last class entry and wrie that
|
||||
$class = \CoreLibs\Debug\Support::getCallerClass();
|
||||
$class = Support::getCallerClass();
|
||||
// get timestamp
|
||||
$timestamp = \CoreLibs\Debug\Support::printTime();
|
||||
$timestamp = Support::printTime();
|
||||
// same string put for print (no html data inside)
|
||||
// write to file if set
|
||||
$this->writeErrorMsg(
|
||||
$level,
|
||||
'[' . $timestamp . '] '
|
||||
. '[' . $this->host_name . '] '
|
||||
. '[' . \CoreLibs\Get\System::getPageName(2) . '] '
|
||||
. '[' . System::getPageName(System::FULL_PATH) . '] '
|
||||
. '[' . $this->running_uid . '] '
|
||||
. '{' . $class . '} '
|
||||
. '<' . $level . '> - '
|
||||
@@ -544,7 +659,7 @@ class Logging
|
||||
. str_replace(
|
||||
['##HTMLPRE##', '##/HTMLPRE##'],
|
||||
['<pre>', '</pre>'],
|
||||
\CoreLibs\Convert\Html::htmlent($string)
|
||||
Html::htmlent($string)
|
||||
)
|
||||
. "</div><!--#BR#-->";
|
||||
}
|
||||
@@ -583,7 +698,7 @@ class Logging
|
||||
if ($this->doDebugTrigger('echo', $level)) {
|
||||
$string_output .= '<div style="font-size: 12px;">'
|
||||
. '[<span style="font-style: italic; color: #c56c00;">' . $level . '</span>] '
|
||||
. ($string ? "<b>**** " . \CoreLibs\Convert\Html::htmlent($string) . " ****</br>\n" : "")
|
||||
. ($string ? "<b>**** " . Html::htmlent($string) . " ****</br>\n" : "")
|
||||
. '</div>'
|
||||
. join('', $temp_debug_output);
|
||||
} // echo it out
|
||||
@@ -596,7 +711,7 @@ class Logging
|
||||
. 'border-bottom: 1px solid black; margin: 10px 0 10px 0; '
|
||||
. 'background-color: white; color: black;">'
|
||||
. '<div style="font-size: 12px;">{<span style="font-style: italic; color: #928100;">'
|
||||
. \CoreLibs\Debug\Support::getCallerClass() . '</span>}</div>';
|
||||
. Support::getCallerClass() . '</span>}</div>';
|
||||
$string_output = $string_prefix . $string_output
|
||||
. '<div><span style="font-style: italic; color: #108db3;">Script Run Time:</span> '
|
||||
. $script_end . '</div>'
|
||||
|
||||
@@ -49,7 +49,6 @@ class L10n
|
||||
*/
|
||||
public function __construct(string $lang = '', string $path = '')
|
||||
{
|
||||
// parent::__construct();
|
||||
if (!$lang) {
|
||||
$this->lang = 'en';
|
||||
} else {
|
||||
|
||||
@@ -218,6 +218,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Output\Form;
|
||||
|
||||
use CoreLibs\Get\System;
|
||||
|
||||
class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
{
|
||||
// for the load statetment describes which elements from
|
||||
@@ -251,6 +253,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
public $my_page_name; // the name of the page without .php extension
|
||||
/** @var bool */
|
||||
public $mobile_phone = false;
|
||||
/** @var string */
|
||||
public $email_regex;
|
||||
// buttons and checkboxes
|
||||
/** @var string */
|
||||
public $archive;
|
||||
@@ -294,14 +298,16 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
/**
|
||||
* construct form generator
|
||||
* @param array<mixed> $db_config db config array
|
||||
* @param int|integer $table_width table/div width (default 750)
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
*/
|
||||
public function __construct(array $db_config, int $table_width = 750)
|
||||
{
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
\CoreLibs\Debug\Logging $log = null
|
||||
) {
|
||||
global $table_arrays;
|
||||
// replace any non valid variable names
|
||||
// TODO extracft only alphanumeric and _ after . to _ replacement
|
||||
$this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1));
|
||||
// TODO extract only alphanumeric and _ after . to _ replacement
|
||||
$this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION));
|
||||
$this->setLangEncoding();
|
||||
// init the language class
|
||||
$this->l = new \CoreLibs\Language\L10n($this->lang);
|
||||
@@ -312,13 +318,13 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if (
|
||||
/* isset($GLOBALS['table_arrays']) &&
|
||||
is_array($GLOBALS['table_arrays']) &&
|
||||
isset($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) */
|
||||
isset($table_arrays[\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($table_arrays[\CoreLibs\Get\System::getPageName(1)])
|
||||
isset($GLOBALS['table_arrays'][System::getPageName(System::NO_EXTENSION)]) &&
|
||||
is_array($GLOBALS['table_arrays'][System::getPageName(System::NO_EXTENSION)]) */
|
||||
isset($table_arrays[System::getPageName(System::NO_EXTENSION)]) &&
|
||||
is_array($table_arrays[System::getPageName(System::NO_EXTENSION)])
|
||||
) {
|
||||
// $config_array = $GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)];
|
||||
$config_array = $table_arrays[\CoreLibs\Get\System::getPageName(1)];
|
||||
// $config_array = $GLOBALS['table_arrays'][System::getPageName(1)];
|
||||
$config_array = $table_arrays[System::getPageName(1)];
|
||||
} else {
|
||||
// WARNING: auto spl load does not work with this as it is an array and not a function/object
|
||||
// check if this is the old path or the new path
|
||||
@@ -346,9 +352,17 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// don't log per class
|
||||
if ($log !== null) {
|
||||
$log->setLogPer('class', false);
|
||||
}
|
||||
// start the array_io class which will start db_io ...
|
||||
parent::__construct($db_config, $config_array['table_array'], $config_array['table_name']);
|
||||
parent::__construct(
|
||||
$db_config,
|
||||
$config_array['table_array'],
|
||||
$config_array['table_name'],
|
||||
$log ?? new \CoreLibs\Debug\Logging()
|
||||
);
|
||||
// here should be a check if the config_array is correct ...
|
||||
if (isset($config_array['show_fields']) && is_array($config_array['show_fields'])) {
|
||||
$this->field_array = $config_array['show_fields'];
|
||||
@@ -371,9 +385,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
|
||||
// layout
|
||||
$this->table_width = $table_width;
|
||||
|
||||
// set button vars
|
||||
$this->archive = $_POST['archive'] ?? '';
|
||||
$this->new = $_POST['new'] ?? '';
|
||||
@@ -411,6 +422,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
'delete' => 100
|
||||
];
|
||||
}
|
||||
|
||||
// set email regex
|
||||
$this->email_regex = \CoreLibs\Check\Email::getEmailRegex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
/*
|
||||
* sets a form token in the _SESSION variable
|
||||
* session must be started for this to work
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
Reference in New Issue
Block a user