htmlent add encoding, date combined add wrapper for calc date interval for numeric and named index return
This commit is contained in:
@@ -423,14 +423,9 @@ class Login
|
|||||||
|
|
||||||
// LOGOUT TARGET
|
// LOGOUT TARGET
|
||||||
if (!isset($options['logout_target'])) {
|
if (!isset($options['logout_target'])) {
|
||||||
if (defined('LOGOUT_TARGET')) {
|
// defaults to ''
|
||||||
trigger_error(
|
$options['logout_target'] = '';
|
||||||
'loginMainCall: LOGOUT_TARGET should not be used',
|
$this->logout_target = $options['logout_target'];
|
||||||
E_USER_DEPRECATED
|
|
||||||
);
|
|
||||||
$options['logout_target'] = LOGOUT_TARGET;
|
|
||||||
$this->logout_target = $options['logout_target'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** PASSWORD SETTINGS
|
// *** PASSWORD SETTINGS
|
||||||
|
|||||||
@@ -103,11 +103,7 @@ class Basic
|
|||||||
'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS', 'UPLOADS', 'CSV', 'JS',
|
'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS', 'UPLOADS', 'CSV', 'JS',
|
||||||
'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES',
|
'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES',
|
||||||
'TEMPLATES_C', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
|
'TEMPLATES_C', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
|
||||||
'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE',
|
'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET'
|
||||||
'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY', 'PAGE_WIDTH',
|
|
||||||
'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA',
|
|
||||||
'LIVE_SCHEMA', 'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET', 'DEBUG',
|
|
||||||
'SHOW_ALL_ERRORS'
|
|
||||||
] as $constant
|
] as $constant
|
||||||
) {
|
) {
|
||||||
if (!defined($constant)) {
|
if (!defined($constant)) {
|
||||||
|
|||||||
@@ -714,6 +714,66 @@ class DateTime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for calcDaysInterval with numeric return only
|
||||||
|
*
|
||||||
|
* @param string $start_date valid start date (y/m/d)
|
||||||
|
* @param string $end_date valid end date (y/m/d)
|
||||||
|
* @param bool $include_end_date [default=true] include end date in calc
|
||||||
|
* @param bool $exclude_start_date [default=false] include end date in calc
|
||||||
|
* @return array{0:int,1:int,2:int,3:bool}
|
||||||
|
*/
|
||||||
|
public static function calcDaysIntervalNumIndex(
|
||||||
|
string $start_date,
|
||||||
|
string $end_date,
|
||||||
|
bool $include_end_date = true,
|
||||||
|
bool $exclude_start_date = false
|
||||||
|
): array {
|
||||||
|
$values = self::calcDaysInterval(
|
||||||
|
$start_date,
|
||||||
|
$end_date,
|
||||||
|
false,
|
||||||
|
$include_end_date,
|
||||||
|
$exclude_start_date
|
||||||
|
);
|
||||||
|
return [
|
||||||
|
$values[0] ?? 0,
|
||||||
|
$values[1] ?? 0,
|
||||||
|
$values[2] ?? 0,
|
||||||
|
$values[3] ?? false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for calcDaysInterval with named return only
|
||||||
|
*
|
||||||
|
* @param string $start_date valid start date (y/m/d)
|
||||||
|
* @param string $end_date valid end date (y/m/d)
|
||||||
|
* @param bool $include_end_date [default=true] include end date in calc
|
||||||
|
* @param bool $exclude_start_date [default=false] include end date in calc
|
||||||
|
* @return array{overall:int,weekday:int,weekend:int,reverse:bool}
|
||||||
|
*/
|
||||||
|
public static function calcDaysIntervalNamedIndex(
|
||||||
|
string $start_date,
|
||||||
|
string $end_date,
|
||||||
|
bool $include_end_date = true,
|
||||||
|
bool $exclude_start_date = false
|
||||||
|
): array {
|
||||||
|
$values = self::calcDaysInterval(
|
||||||
|
$start_date,
|
||||||
|
$end_date,
|
||||||
|
true,
|
||||||
|
$include_end_date,
|
||||||
|
$exclude_start_date
|
||||||
|
);
|
||||||
|
return [
|
||||||
|
'overall' => $values['overall'] ?? 0,
|
||||||
|
'weekday' => $values['weekday'] ?? 0,
|
||||||
|
'weekend' => $values['weekend'] ?? 0,
|
||||||
|
'reverse' => $values['reverse'] ?? false,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if a weekend day (sat/sun) is in the given date range
|
* check if a weekend day (sat/sun) is in the given date range
|
||||||
* Can have time too, but is not needed
|
* Can have time too, but is not needed
|
||||||
|
|||||||
@@ -10,9 +10,16 @@ namespace CoreLibs\Convert;
|
|||||||
|
|
||||||
class Html
|
class Html
|
||||||
{
|
{
|
||||||
|
/** @var int */
|
||||||
public const SELECTED = 0;
|
public const SELECTED = 0;
|
||||||
|
/** @var int */
|
||||||
public const CHECKED = 1;
|
public const CHECKED = 1;
|
||||||
|
|
||||||
|
// TODO: check for not valid htmlentites encoding
|
||||||
|
// as of PHP 8.4: https://www.php.net/manual/en/function.htmlentities.php
|
||||||
|
/** @#var array<string> */
|
||||||
|
// public const VALID_HTMLENT_ENCODINGS = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* full wrapper for html entities
|
* full wrapper for html entities
|
||||||
*
|
*
|
||||||
@@ -22,14 +29,19 @@ class Html
|
|||||||
* encodes in UTF-8
|
* encodes in UTF-8
|
||||||
* does not double encode
|
* does not double encode
|
||||||
*
|
*
|
||||||
* @param mixed $string string to html encode
|
* @param mixed $string string to html encode
|
||||||
* @param int $flags [default: ENT_QUOTES | ENT_HTML5]
|
* @param int $flags [default=ENT_QUOTES | ENT_HTML5]
|
||||||
|
* @param string $encoding [default=UTF-8]
|
||||||
* @return mixed if string, encoded, else as is (eg null)
|
* @return mixed if string, encoded, else as is (eg null)
|
||||||
*/
|
*/
|
||||||
public static function htmlent(mixed $string, int $flags = ENT_QUOTES | ENT_HTML5): mixed
|
public static function htmlent(
|
||||||
{
|
mixed $string,
|
||||||
|
int $flags = ENT_QUOTES | ENT_HTML5,
|
||||||
|
string $encoding = 'UTF-8'
|
||||||
|
): mixed {
|
||||||
if (is_string($string)) {
|
if (is_string($string)) {
|
||||||
return htmlentities($string, $flags, 'UTF-8', false);
|
// if not a valid encoding this will throw a warning and use UTF-8
|
||||||
|
return htmlentities($string, $flags, $encoding, false);
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
@@ -37,7 +49,7 @@ class Html
|
|||||||
/**
|
/**
|
||||||
* strips out all line breaks or replaced with given string
|
* strips out all line breaks or replaced with given string
|
||||||
* @param string $string string
|
* @param string $string string
|
||||||
* @param string $replace replace character, default ' '
|
* @param string $replace [default=' '] replace character
|
||||||
* @return string cleaned string without any line breaks
|
* @return string cleaned string without any line breaks
|
||||||
*/
|
*/
|
||||||
public static function removeLB(string $string, string $replace = ' '): string
|
public static function removeLB(string $string, string $replace = ' '): string
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class GetLocale
|
|||||||
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||||
SITE_LOCALE :
|
SITE_LOCALE :
|
||||||
// else parse from default, if not 'en'
|
// else parse from default, if not 'en'
|
||||||
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
|
||||||
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
|
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
|
||||||
DEFAULT_LOCALE : 'en');
|
DEFAULT_LOCALE : 'en');
|
||||||
}
|
}
|
||||||
@@ -97,8 +96,7 @@ class GetLocale
|
|||||||
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
||||||
SITE_ENCODING :
|
SITE_ENCODING :
|
||||||
// or default encoding, if not 'UTF-8'
|
// or default encoding, if not 'UTF-8'
|
||||||
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
(defined('DEFAULT_ENCODING') ?
|
||||||
(defined('DEFAULT_ENCODING') && !empty(DEFAULT_ENCODING) ?
|
|
||||||
DEFAULT_ENCODING : 'UTF-8');
|
DEFAULT_ENCODING : 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,9 +418,7 @@ class ProgressBar
|
|||||||
// if this is percent, we ignore anything, it is auto positioned
|
// if this is percent, we ignore anything, it is auto positioned
|
||||||
if ($this->label[$name]['type'] != 'percent') {
|
if ($this->label[$name]['type'] != 'percent') {
|
||||||
foreach (['top', 'left', 'width', 'height'] as $pos_name) {
|
foreach (['top', 'left', 'width', 'height'] as $pos_name) {
|
||||||
if ($$pos_name !== false) {
|
$this->label[$name][$pos_name] = intval($$pos_name);
|
||||||
$this->label[$name][$pos_name] = intval($$pos_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($align != '') {
|
if ($align != '') {
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ final class CoreLibsACLLoginTest extends TestCase
|
|||||||
// TARGET
|
// TARGET
|
||||||
define('TARGET', 'test');
|
define('TARGET', 'test');
|
||||||
// LOGIN DB SCHEMA
|
// LOGIN DB SCHEMA
|
||||||
// define('LOGIN_DB_SCHEMA', '');
|
|
||||||
|
|
||||||
// SHOULD SET
|
// SHOULD SET
|
||||||
// DEFAULT_ACL_LEVEL (d80)
|
// DEFAULT_ACL_LEVEL (d80)
|
||||||
|
|||||||
@@ -1068,8 +1068,32 @@ final class CoreLibsCombinedDateTimeTest extends TestCase
|
|||||||
return_named:$return_named,
|
return_named:$return_named,
|
||||||
include_end_date:$include_end_date,
|
include_end_date:$include_end_date,
|
||||||
exclude_start_date:$exclude_start_date
|
exclude_start_date:$exclude_start_date
|
||||||
)
|
),
|
||||||
|
'call calcDaysInterval'
|
||||||
);
|
);
|
||||||
|
if ($return_named) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::calcDaysIntervalNamedIndex(
|
||||||
|
$input_a,
|
||||||
|
$input_b,
|
||||||
|
include_end_date:$include_end_date,
|
||||||
|
exclude_start_date:$exclude_start_date
|
||||||
|
),
|
||||||
|
'call calcDaysIntervalNamedIndex'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Combined\DateTime::calcDaysIntervalNumIndex(
|
||||||
|
$input_a,
|
||||||
|
$input_b,
|
||||||
|
include_end_date:$include_end_date,
|
||||||
|
exclude_start_date:$exclude_start_date
|
||||||
|
),
|
||||||
|
'call calcDaysIntervalNamedIndex'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
4 => '1.00 KB',
|
4 => '1.00 KB',
|
||||||
5 => '1.02KiB',
|
5 => '1.02KiB',
|
||||||
],
|
],
|
||||||
'invalud string number' => [
|
'invalid string number' => [
|
||||||
0 => '1024 MB',
|
0 => '1024 MB',
|
||||||
1 => '1024 MB',
|
1 => '1024 MB',
|
||||||
2 => '1024 MB',
|
2 => '1024 MB',
|
||||||
|
|||||||
Reference in New Issue
Block a user