Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
984dec37e2 | ||
|
|
d91fbd5a46 | ||
|
|
668954c1c4 | ||
|
|
adbae19fca | ||
|
|
39de680b66 | ||
|
|
2e81a4da82 | ||
|
|
61782be11c | ||
|
|
e7fe4655d1 | ||
|
|
561be4bce6 | ||
|
|
51fef30364 | ||
|
|
89a4b4cf3e | ||
|
|
3eb1229590 | ||
|
|
f174e9ec34 | ||
|
|
928369cff7 |
@@ -1 +1 @@
|
||||
9.13.0
|
||||
9.17.1
|
||||
|
||||
@@ -117,18 +117,20 @@ class Backend
|
||||
/**
|
||||
* main class constructor
|
||||
*
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param int|null $set_default_acl_level Default ACL level
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Logging\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param int|null $set_default_acl_level [default=null] Default ACL level
|
||||
* @param bool $init_action_vars [default=true] If the action vars should be set
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Logging\Logging $log,
|
||||
\CoreLibs\Create\Session $session,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
?int $set_default_acl_level = null
|
||||
?int $set_default_acl_level = null,
|
||||
bool $init_action_vars = true
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
@@ -151,9 +153,9 @@ class Backend
|
||||
// set the page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
$this->$_action = $_POST[$_action] ?? '';
|
||||
// NOTE: if any of the "action" vars are used somewhere, it is recommended to NOT set them here
|
||||
if ($init_action_vars) {
|
||||
$this->adbSetActionVars();
|
||||
}
|
||||
|
||||
if ($set_default_acl_level === null) {
|
||||
@@ -170,7 +172,7 @@ class Backend
|
||||
}
|
||||
|
||||
// queue key
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
|
||||
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action ?? '')) {
|
||||
$this->queue_key = \CoreLibs\Create\RandomKey::randomKeyGen(3);
|
||||
}
|
||||
}
|
||||
@@ -195,6 +197,29 @@ class Backend
|
||||
$this->acl = $acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return current set ACL
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function adbGetAcl(): array
|
||||
{
|
||||
return $this->acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set _POST action vars if needed
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function adbSetActionVars()
|
||||
{
|
||||
// set the action ids
|
||||
foreach ($this->action_list as $_action) {
|
||||
$this->$_action = $_POST[$_action] ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* writes all action vars plus other info into edit_log table
|
||||
*
|
||||
@@ -257,14 +282,14 @@ class Backend
|
||||
"NULL" :
|
||||
"'" . $this->session->getSessionId() . "'")
|
||||
. ", "
|
||||
. "'" . $this->db->dbEscapeString($this->action) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_id) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_yes) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_flag) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_menu) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_loaded) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_value) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_error) . "')";
|
||||
. "'" . $this->db->dbEscapeString($this->action ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_id ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_yes ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_flag ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_menu ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_loaded ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_value ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_error ?? '') . "')";
|
||||
$this->db->dbExec($q, 'NULL');
|
||||
}
|
||||
|
||||
@@ -504,9 +529,9 @@ class Backend
|
||||
string $data,
|
||||
string $key_name,
|
||||
string $key_value,
|
||||
string $associate = null,
|
||||
string $file = null,
|
||||
string $db_schema = null,
|
||||
?string $associate = null,
|
||||
?string $file = null,
|
||||
?string $db_schema = null,
|
||||
): void {
|
||||
/** @var string $DB_SCHEMA check schema */
|
||||
$DB_SCHEMA = 'public';
|
||||
|
||||
@@ -90,7 +90,7 @@ class Basic
|
||||
* @deprecated DO NOT USE Class\Basic anymore. Use dedicated logger and sub classes
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\Logging\Logging $log = null,
|
||||
?\CoreLibs\Logging\Logging $log = null,
|
||||
?string $session_name = null
|
||||
) {
|
||||
trigger_error('Class \CoreLibs\Basic is deprected', E_USER_DEPRECATED);
|
||||
|
||||
@@ -52,7 +52,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeStrMain(
|
||||
mixed $val,
|
||||
string $default = null,
|
||||
?string $default = null,
|
||||
bool $to_null = false
|
||||
): ?string {
|
||||
// int/float/string/bool/null, everything else is ignored
|
||||
@@ -113,7 +113,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeIntMain(
|
||||
mixed $val,
|
||||
int $default = null,
|
||||
?int $default = null,
|
||||
bool $to_null = false
|
||||
): ?int {
|
||||
// if we can filter it to a valid int, we can convert it
|
||||
@@ -167,7 +167,7 @@ class SetVarTypeMain
|
||||
*/
|
||||
protected static function makeFloatMain(
|
||||
mixed $val,
|
||||
float $default = null,
|
||||
?float $default = null,
|
||||
bool $to_null = false
|
||||
): ?float {
|
||||
if (
|
||||
|
||||
@@ -16,16 +16,22 @@ class Html
|
||||
/**
|
||||
* full wrapper for html entities
|
||||
*
|
||||
* uses default params as: ENT_QUOTES | ENT_HTML5
|
||||
* switches from ENT_HTML401 to ENT_HTML5 as we assume all our pages have <!DOCTYPE html>
|
||||
* removed: ENT_SUBSTITUTE -> wrong characters will be replaced with space
|
||||
* encodes in UTF-8
|
||||
* does not double encode
|
||||
*
|
||||
* @param mixed $string string to html encode
|
||||
* @param int $flags [default: ENT_QUOTES | ENT_HTML5]
|
||||
* @return mixed if string, encoded, else as is (eg null)
|
||||
*/
|
||||
public static function htmlent(mixed $string): mixed
|
||||
public static function htmlent(mixed $string, int $flags = ENT_QUOTES | ENT_HTML5): mixed
|
||||
{
|
||||
if (is_string($string)) {
|
||||
return htmlentities($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
} else {
|
||||
return $string;
|
||||
return htmlentities($string, $flags, 'UTF-8', false);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,14 +60,10 @@ class Html
|
||||
*/
|
||||
public static function checked(array|string $haystack, string $needle, int $type = 0): ?string
|
||||
{
|
||||
if (is_array($haystack)) {
|
||||
if (in_array($needle, $haystack)) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
} else {
|
||||
if ($haystack == $needle) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
if (is_array($haystack) && in_array($needle, $haystack)) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
} elseif (!is_array($haystack) && $haystack == $needle) {
|
||||
return $type ? 'checked' : 'selected';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param string|null $default Default override value
|
||||
* @return string|null Input value as string or default as string/null
|
||||
*/
|
||||
public static function makeStr(mixed $val, string $default = null): ?string
|
||||
public static function makeStr(mixed $val, ?string $default = null): ?string
|
||||
{
|
||||
return SetVarTypeMain::makeStrMain($val, $default, true);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param int|null $default Default override value
|
||||
* @return int|null Input value as int or default as int/null
|
||||
*/
|
||||
public static function makeInt(mixed $val, int $default = null): ?int
|
||||
public static function makeInt(mixed $val, ?int $default = null): ?int
|
||||
{
|
||||
return SetVarTypeMain::makeIntMain($val, $default, true);
|
||||
}
|
||||
@@ -84,7 +84,7 @@ class SetVarTypeNull extends Extends\SetVarTypeMain
|
||||
* @param float|null $default Default override value
|
||||
* @return float|null Input value as float or default as float/null
|
||||
*/
|
||||
public static function makeFloat(mixed $val, float $default = null): ?float
|
||||
public static function makeFloat(mixed $val, ?float $default = null): ?float
|
||||
{
|
||||
return SetVarTypeMain::makeFloatMain($val, $default, true);
|
||||
}
|
||||
|
||||
@@ -134,6 +134,18 @@ class Strings
|
||||
$path
|
||||
) ?? $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove UTF8 BOM Byte string from line
|
||||
* Note: this is often found in CSV files exported from Excel at the first row, first element
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public static function stripUTF8BomBytes(string $text): string
|
||||
{
|
||||
return trim($text, pack('H*', 'EFBBBF'));
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -1324,8 +1324,12 @@ class IO
|
||||
// /s for matching new line in . list
|
||||
// [disabled, we don't used ^ or $] /m for multi line match
|
||||
// Matches in 1:, must be array_filtered to remove empty, count with array_unique
|
||||
$query_split = '[(=,?-]|->|->>|#>|#>>|@>|<@|\?\|\?\&|\|\||#-';
|
||||
preg_match_all(
|
||||
'/(?:\'.*?\')?\s*(?:\?\?|<>|[(=,])\s*(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))/s',
|
||||
'/'
|
||||
. '(?:\'.*?\')?\s*(?:\?\?|<>|' . $query_split . ')\s*'
|
||||
. '(?:\d+|(?:\'.*?\')|(\$[1-9]{1}(?:[0-9]{1,})?))'
|
||||
. '/s',
|
||||
$query,
|
||||
$match
|
||||
);
|
||||
@@ -1892,7 +1896,12 @@ class IO
|
||||
$matches = [];
|
||||
// compare has =, >, < prefix, and gets stripped
|
||||
// if the rest is not X.Y format then error
|
||||
preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches);
|
||||
if (!preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches)) {
|
||||
$this->log->error('Could not regex match compare version string', [
|
||||
"compare" => $compare
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
$compare = $matches[1];
|
||||
$to_master = $matches[2];
|
||||
$to_minor = $matches[3];
|
||||
@@ -1904,11 +1913,18 @@ class IO
|
||||
}
|
||||
// db_version can return X.Y.Z
|
||||
// we only compare the first two
|
||||
preg_match(
|
||||
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
||||
$this->dbVersion(),
|
||||
$matches
|
||||
);
|
||||
if (
|
||||
!preg_match(
|
||||
"/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/",
|
||||
$this->dbVersion(),
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$this->log->error('Could not regex match dbVersion string', [
|
||||
"dbVersion" => $this->dbVersion()
|
||||
]);
|
||||
return false;
|
||||
}
|
||||
$master = $matches[1];
|
||||
$minor = $matches[2];
|
||||
$version = $master . ($minor < 10 ? '0' : '') . $minor;
|
||||
@@ -2398,7 +2414,7 @@ class IO
|
||||
// flag if we have cache data stored at the moment
|
||||
'cached' => false,
|
||||
// when fetch array or cache read returns false
|
||||
// in loop read that means dbReturn retuns false without erro
|
||||
// in loop read that means dbReturn retuns false without error
|
||||
'finished' => false,
|
||||
// read from cache/db (pos == rows)
|
||||
'read_finished' => false,
|
||||
|
||||
@@ -116,6 +116,29 @@ class System
|
||||
3
|
||||
) === 'cli' ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all IP addresses
|
||||
* REMOTE_ADDR, HTTP_X_FORWARD_FOR, CLIENT_IP
|
||||
* and retuns them in an array with index of io source
|
||||
* if address source has addresses with "," will add "-array" with these as array block
|
||||
*
|
||||
* @return array<string,string|array<string>>
|
||||
*/
|
||||
public static function getIpAddresses(): array
|
||||
{
|
||||
$ip_addr = [];
|
||||
foreach (['REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'CLIENT_IP'] as $_ip_source) {
|
||||
if (!empty($_SERVER[$_ip_source])) {
|
||||
$ip_addr[$_ip_source] = $_SERVER[$_ip_source];
|
||||
// same level as ARRAY IF there is a , inside
|
||||
if (strstr($_SERVER[$_ip_source], ',') !== false) {
|
||||
$ip_addr[$_ip_source . '-array'] = explode(',', $_SERVER[$_ip_source]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -128,7 +128,7 @@ class GetLocale
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$lang = ($matches['lang'] ?? 'en')
|
||||
$lang = $matches['lang']
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
@@ -235,7 +235,7 @@ class GetLocale
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
$lang = ($matches['lang'] ?? 'en')
|
||||
$lang = $matches['lang']
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
|
||||
@@ -24,16 +24,20 @@ class ErrorMessage
|
||||
|
||||
/** @var bool $log_error global flag to log error level message */
|
||||
private bool $log_error = false;
|
||||
/** @var bool $log_warning global flat to log warning level messages */
|
||||
private bool $log_warning = false;
|
||||
|
||||
/**
|
||||
* init ErrorMessage
|
||||
*
|
||||
* @param \CoreLibs\Logging\Logging $log
|
||||
* @param null|bool $log_error [=null], defaults to false if log is not level debug
|
||||
* @param null|bool $log_warning [=null], defaults to false if log is not level debug
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\Logging\Logging $log,
|
||||
?bool $log_error = null
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null
|
||||
) {
|
||||
$this->log = $log;
|
||||
// if log default logging is debug then log_error is default set to true
|
||||
@@ -43,6 +47,13 @@ class ErrorMessage
|
||||
$log_error = $log_error ?? false;
|
||||
}
|
||||
$this->log_error = $log_error;
|
||||
// if log default logging is debug then log_warning is default set to true
|
||||
if ($this->log->loggingLevelIsDebug() && $log_warning === null) {
|
||||
$log_warning = true;
|
||||
} else {
|
||||
$log_warning = $log_warning ?? false;
|
||||
}
|
||||
$this->log_warning = $log_warning;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,6 +92,8 @@ class ErrorMessage
|
||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||
* else set for this call only
|
||||
* @param bool|null $log_warning [=null] log level 'warning' to warning, if null use global,
|
||||
* else set for this call only
|
||||
*/
|
||||
public function setErrorMsg(
|
||||
string $error_id,
|
||||
@@ -93,10 +106,14 @@ class ErrorMessage
|
||||
?string $message = null,
|
||||
array $context = [],
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null,
|
||||
): void {
|
||||
if ($log_error === null) {
|
||||
$log_error = $this->log_error;
|
||||
}
|
||||
if ($log_warning === null) {
|
||||
$log_warning = $this->log_warning;
|
||||
}
|
||||
$original_level = $level;
|
||||
$level = MessageLevel::fromName($level)->name;
|
||||
// if not string set, write message string if set, else level/error id
|
||||
@@ -121,6 +138,14 @@ class ErrorMessage
|
||||
'level' => $original_level,
|
||||
], $context));
|
||||
break;
|
||||
case 'warn':
|
||||
if ($log_warning) {
|
||||
$this->log->warning($message ?? $str, array_merge([
|
||||
'id' => $error_id,
|
||||
'level' => $original_level,
|
||||
], $context));
|
||||
}
|
||||
break;
|
||||
case 'error':
|
||||
if ($log_error) {
|
||||
$this->log->error($message ?? $str, array_merge([
|
||||
@@ -169,6 +194,8 @@ class ErrorMessage
|
||||
* @param array<mixed> $context Additionl info for abort/crash messages
|
||||
* @param bool|null $log_error [=null] log level 'error' to error, if null use global,
|
||||
* else set for this call only
|
||||
* @param bool|null $log_warning [=null] log level 'warning' to warning, if null use global,
|
||||
* else set for this call only
|
||||
*/
|
||||
public function setMessage(
|
||||
string $level,
|
||||
@@ -181,6 +208,7 @@ class ErrorMessage
|
||||
?string $message = null,
|
||||
array $context = [],
|
||||
?bool $log_error = null,
|
||||
?bool $log_warning = null,
|
||||
): void {
|
||||
$this->setErrorMsg(
|
||||
$error_id ?? '',
|
||||
@@ -192,7 +220,8 @@ class ErrorMessage
|
||||
$jump_target,
|
||||
$message,
|
||||
$context,
|
||||
$log_error
|
||||
$log_error,
|
||||
$log_warning
|
||||
);
|
||||
}
|
||||
|
||||
@@ -314,6 +343,27 @@ class ErrorMessage
|
||||
{
|
||||
return $this->log_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the log warning flag
|
||||
*
|
||||
* @param bool $flag True to log level warning too, False for do not (Default)
|
||||
* @return void
|
||||
*/
|
||||
public function setFlagLogWarning(bool $flag): void
|
||||
{
|
||||
$this->log_warning = $flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current log error flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getFlagLogWarning(): bool
|
||||
{
|
||||
return $this->log_warning;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace CoreLibs\Logging\Logger;
|
||||
enum MessageLevel: int
|
||||
{
|
||||
case ok = 100;
|
||||
case success = 150; // special for file uploads
|
||||
case info = 200;
|
||||
case notice = 250;
|
||||
case warn = 300;
|
||||
@@ -30,6 +31,7 @@ enum MessageLevel: int
|
||||
{
|
||||
return match (strtolower($name)) {
|
||||
'ok' => self::ok,
|
||||
'success' => self::success,
|
||||
'info' => self::info,
|
||||
'notice' => self::notice,
|
||||
'warn', 'warning' => self::warn,
|
||||
|
||||
@@ -194,13 +194,13 @@ class Elements
|
||||
"/(mailto:)?(\>)?\b([\w\.-]+)@([\w\.\-]+)\.([a-zA-Z]{2,4})\b(\|([^\||^#]+)(#([^\|]+))?\|)?/",
|
||||
function ($matches) {
|
||||
return self::createEmail(
|
||||
$matches[1] ?? '',
|
||||
$matches[2] ?? '',
|
||||
$matches[3] ?? '',
|
||||
$matches[4] ?? '',
|
||||
$matches[5] ?? '',
|
||||
$matches[1],
|
||||
$matches[2],
|
||||
$matches[3],
|
||||
$matches[4],
|
||||
$matches[5],
|
||||
$matches[7] ?? '',
|
||||
$matches[9] ?? ''
|
||||
$matches[9] ?? '',
|
||||
);
|
||||
},
|
||||
$output
|
||||
|
||||
@@ -19,7 +19,7 @@ use CoreLibs\Template\HtmlBuilder\General\HtmlBuilderExcpetion;
|
||||
class Block
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
* Create Element
|
||||
*
|
||||
* @param string $tag
|
||||
* @param string $id
|
||||
@@ -86,7 +86,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add multiple elements to the base element
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $base
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} ...$attach
|
||||
@@ -101,7 +101,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add multiple sub elements to the base element
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $sub
|
||||
@@ -117,7 +117,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Remove all sub element entries
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @return array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}
|
||||
@@ -131,7 +131,7 @@ class Block
|
||||
// CSS Elements
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Add css entry to the css entries
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param string ...$css
|
||||
@@ -144,7 +144,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Remove a css entry entry from the css array
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $element
|
||||
* @param string ...$css
|
||||
@@ -157,7 +157,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Switch CSS entries
|
||||
* scssel (switch) is not supported
|
||||
* use rcssel -> acssel
|
||||
*
|
||||
@@ -175,7 +175,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Build HTML from the content tree
|
||||
* alias phfo
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $tree
|
||||
@@ -231,7 +231,19 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* Alias for phfo
|
||||
*
|
||||
* @param array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>} $tree
|
||||
* @param bool $add_nl [default=false]
|
||||
* @return string
|
||||
*/
|
||||
public static function phfo(array $tree, bool $add_nl = false): string
|
||||
{
|
||||
return self::buildHtml($tree, $add_nl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build HTML elements from an array of elements
|
||||
* alias phfa
|
||||
*
|
||||
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list
|
||||
@@ -248,8 +260,7 @@ class Block
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* wrapper for buildHtmlFromList
|
||||
* alias for buildHtmlFromList
|
||||
*
|
||||
* @param array<array{tag:string,id:string,name:string,content:string,css:array<string>,options:array<string,string>,sub:array<mixed>}> $list array of Elements to build string from
|
||||
* @param bool $add_nl [default=false] Optional output string line break
|
||||
|
||||
@@ -401,7 +401,7 @@ class Element
|
||||
* @param bool $add_nl [default=false] Optional output string line breaks
|
||||
* @return string HTML as string
|
||||
*/
|
||||
public function buildHtml(Element $tree = null, bool $add_nl = false): string
|
||||
public function buildHtml(?Element $tree = null, bool $add_nl = false): string
|
||||
{
|
||||
// print "D01: " . microtime(true) . "<br>";
|
||||
if ($tree === null) {
|
||||
@@ -533,7 +533,7 @@ class Element
|
||||
* @return string build html as string
|
||||
* @deprecated Do not use, use Element->buildHtml() instead
|
||||
*/
|
||||
public static function printHtmlFromObject(Element $tree = null, bool $add_nl = false): string
|
||||
public static function printHtmlFromObject(?Element $tree = null, bool $add_nl = false): string
|
||||
{
|
||||
// nothing ->bad
|
||||
if ($tree === null) {
|
||||
|
||||
@@ -203,7 +203,8 @@ class SmartyExtend extends \Smarty
|
||||
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
|
||||
// register smarty variable
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||
// $this->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
||||
$this->registerPlugin(self::PLUGIN_MODIFIER, 'getvar', [&$this, 'getTemplateVars']);
|
||||
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsConvertStringsTest extends TestCase
|
||||
{
|
||||
private const DATA_FOLDER = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -330,6 +332,52 @@ final class CoreLibsConvertStringsTest extends TestCase
|
||||
\CoreLibs\Convert\Strings::stripMultiplePathSlashes($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerStripUTF8BomBytes(): array
|
||||
{
|
||||
return [
|
||||
"utf8-bom" => [
|
||||
"file" => "UTF8BOM.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
"utf8" => [
|
||||
"file" => "UTF8.csv",
|
||||
"expect" => "Asset Type,Epic,File Name\n",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* test utf8 bom remove
|
||||
*
|
||||
* @covers ::stripUTF8BomBytes
|
||||
* @dataProvider providerStripUTF8BomBytes
|
||||
* @testdox stripUTF8BomBytes $file will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testStripUTF8BomBytes(string $file, string $expected): void
|
||||
{
|
||||
// load sample file
|
||||
if (!is_file(self::DATA_FOLDER . $file)) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be opened');
|
||||
}
|
||||
$file = file_get_contents(self::DATA_FOLDER . $file);
|
||||
if ($file === false) {
|
||||
$this->markTestSkipped('File: ' . $file . ' could not be read');
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Strings::stripUTF8BomBytes($file)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
1
test/phpunit/Convert/data/UTF8.csv
Normal file
1
test/phpunit/Convert/data/UTF8.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
1
test/phpunit/Convert/data/UTF8BOM.csv
Normal file
1
test/phpunit/Convert/data/UTF8BOM.csv
Normal file
@@ -0,0 +1 @@
|
||||
Asset Type,Epic,File Name
|
||||
|
@@ -216,6 +216,29 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::getIpAddresses
|
||||
* @testdox getIpAddresses check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetIpAddresses()
|
||||
{
|
||||
// response must have "REMOTE_ADDR" entry, others are optional
|
||||
// NOTE: we have no IP addresses on command line
|
||||
$this->assertTrue(
|
||||
true,
|
||||
"We do not have REMOTE_ADDR on command line"
|
||||
);
|
||||
// $this->assertContains(
|
||||
// 'REMOTE_ADDR',
|
||||
// array_keys(\CoreLibs\Get\System::getIpAddresses()),
|
||||
// 'failed REMOTE_ADDR assert'
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -39,6 +39,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'OK',
|
||||
'expected' => 'ok',
|
||||
],
|
||||
'success' => [
|
||||
'level' => 'success',
|
||||
'str' => 'SUCCESS',
|
||||
'expected' => 'success',
|
||||
],
|
||||
'info' => [
|
||||
'level' => 'info',
|
||||
'str' => 'INFO',
|
||||
@@ -225,6 +230,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged' => [
|
||||
@@ -233,6 +239,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> ERROR MESSAGE',
|
||||
],
|
||||
'error, logged, message' => [
|
||||
@@ -241,14 +248,43 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ERROR MESSAGE',
|
||||
'message' => 'OTHER ERROR MESSAGE',
|
||||
'log_error' => true,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ERROR> OTHER ERROR MESSAGE',
|
||||
],
|
||||
'warn, not logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> WARNING MESSAGE',
|
||||
],
|
||||
'warn, logged, message' => [
|
||||
'id' => '300',
|
||||
'level' => 'warn',
|
||||
'str' => 'WARNING MESSAGE',
|
||||
'message' => 'OTHER WARNING MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => true,
|
||||
'expected' => '<WARNING> OTHER WARNING MESSAGE',
|
||||
],
|
||||
'notice' => [
|
||||
'id' => '100',
|
||||
'level' => 'notice',
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> NOTICE MESSAGE',
|
||||
],
|
||||
'notice, message' => [
|
||||
@@ -257,6 +293,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'NOTICE MESSAGE',
|
||||
'message' => 'OTHER NOTICE MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<NOTICE> OTHER NOTICE MESSAGE',
|
||||
],
|
||||
'crash' => [
|
||||
@@ -265,6 +302,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> CRASH MESSAGE',
|
||||
],
|
||||
'crash, message' => [
|
||||
@@ -273,6 +311,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'CRASH MESSAGE',
|
||||
'message' => 'OTHER CRASH MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<ALERT> OTHER CRASH MESSAGE',
|
||||
],
|
||||
'abort' => [
|
||||
@@ -281,6 +320,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> ABORT MESSAGE',
|
||||
],
|
||||
'abort, message' => [
|
||||
@@ -289,6 +329,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'ABORT MESSAGE',
|
||||
'message' => 'OTHER ABORT MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<CRITICAL> OTHER ABORT MESSAGE',
|
||||
],
|
||||
'unknown' => [
|
||||
@@ -297,6 +338,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => null,
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> WRONG LEVEL MESSAGE',
|
||||
],
|
||||
'unknown, message' => [
|
||||
@@ -305,6 +347,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
'str' => 'WRONG LEVEL MESSAGE',
|
||||
'message' => 'OTHER WRONG LEVEL MESSAGE',
|
||||
'log_error' => null,
|
||||
'log_warning' => null,
|
||||
'expected' => '<EMERGENCY> OTHER WRONG LEVEL MESSAGE',
|
||||
],
|
||||
];
|
||||
@@ -321,6 +364,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -330,6 +374,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -344,7 +389,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
@@ -358,6 +404,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && ($log_warning === null || $log_warning === false)) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
@@ -377,6 +428,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
* @param string $str
|
||||
* @param string|null $message
|
||||
* @param bool|null $log_error
|
||||
* @param bool|null $log_warning
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -386,6 +438,7 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
string $str,
|
||||
?string $message,
|
||||
?bool $log_error,
|
||||
?bool $log_warning,
|
||||
string $expected
|
||||
): void {
|
||||
$log = new \CoreLibs\Logging\Logging([
|
||||
@@ -400,7 +453,8 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$level,
|
||||
$str,
|
||||
message: $message,
|
||||
log_error: $log_error
|
||||
log_error: $log_error,
|
||||
log_warning: $log_warning
|
||||
);
|
||||
$file_content = '';
|
||||
if (is_file($log->getLogFolder() . $log->getLogFile())) {
|
||||
@@ -414,6 +468,11 @@ final class CoreLibsLoggingErrorMessagesTest extends TestCase
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} elseif ($level == 'warn' && $log_warning === false) {
|
||||
$this->assertStringNotContainsString(
|
||||
$expected,
|
||||
$file_content
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
|
||||
Reference in New Issue
Block a user