Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26af6a07f4 | ||
|
|
b7c6d4b478 | ||
|
|
9936fc04da | ||
|
|
1e0dfa2106 | ||
|
|
3af6f6a8f0 | ||
|
|
1e793c0d16 | ||
|
|
5be34453ce |
@@ -4,7 +4,7 @@ CREATE OR REPLACE FUNCTION set_edit_generic()
|
|||||||
RETURNS TRIGGER AS
|
RETURNS TRIGGER AS
|
||||||
$$
|
$$
|
||||||
DECLARE
|
DECLARE
|
||||||
random_length INT = 12; -- that should be long enough
|
random_length INT = 25; -- that should be long enough
|
||||||
BEGIN
|
BEGIN
|
||||||
IF TG_OP = 'INSERT' THEN
|
IF TG_OP = 'INSERT' THEN
|
||||||
NEW.date_created := 'now';
|
NEW.date_created := 'now';
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsConvertByteTest extends TestCase
|
final class CoreLibsConvertByteTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -24,7 +23,31 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function byteProvider(): array
|
public function byteProvider(): array
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* 0: input string
|
||||||
|
* 1: default flags
|
||||||
|
* 2: BYTE_FORMAT_SI
|
||||||
|
* 3: BYTE_FORMAT_NOSPACE
|
||||||
|
* 4: BYTE_FORMAT_ADJUST
|
||||||
|
* 5: BYTE_FORMAT_SI | BYTE_FORMAT_NOSPACE
|
||||||
|
*/
|
||||||
return [
|
return [
|
||||||
|
'string number' => [
|
||||||
|
0 => '1024',
|
||||||
|
1 => '1 KB',
|
||||||
|
2 => '1.02 KiB',
|
||||||
|
3 => '1KB',
|
||||||
|
4 => '1.00 KB',
|
||||||
|
5 => '1.02KiB',
|
||||||
|
],
|
||||||
|
'invalud string number' => [
|
||||||
|
0 => '1024 MB',
|
||||||
|
1 => '1024 MB',
|
||||||
|
2 => '1024 MB',
|
||||||
|
3 => '1024 MB',
|
||||||
|
4 => '1024 MB',
|
||||||
|
5 => '1024 MB',
|
||||||
|
],
|
||||||
'negative number' => [
|
'negative number' => [
|
||||||
0 => -123123123,
|
0 => -123123123,
|
||||||
1 => '-117.42 MB',
|
1 => '-117.42 MB',
|
||||||
|
|||||||
@@ -113,7 +113,10 @@ final class CoreLibsCreateEmailTest extends TestCase
|
|||||||
'日本語カタカナパ',
|
'日本語カタカナパ',
|
||||||
'ISO-2022-JP',
|
'ISO-2022-JP',
|
||||||
true,
|
true,
|
||||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
// was ok php 8.1
|
||||||
|
// '"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
||||||
|
// below ok php 8.1.12, 2022/12/9
|
||||||
|
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -124,6 +127,11 @@ final class CoreLibsCreateEmailTest extends TestCase
|
|||||||
* @dataProvider encodeEmailNameProvider
|
* @dataProvider encodeEmailNameProvider
|
||||||
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
|
* @param string $email
|
||||||
|
* @param string|null $name
|
||||||
|
* @param string|null $encoding
|
||||||
|
* @param bool|null $kv_folding
|
||||||
|
* @param string $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testEncodeEmailName(
|
public function testEncodeEmailName(
|
||||||
|
|||||||
@@ -1189,7 +1189,13 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$db->dbEscapeBytea($input)
|
$db->dbEscapeBytea($input),
|
||||||
|
'Assert error to bytea'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$input,
|
||||||
|
$db->dbUnescapeBytea($expected),
|
||||||
|
'Assert error from bytes'
|
||||||
);
|
);
|
||||||
|
|
||||||
$db->dbClose();
|
$db->dbClose();
|
||||||
|
|||||||
@@ -50,21 +50,22 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
|||||||
$byte = 254779258;
|
$byte = 254779258;
|
||||||
$string = '242.98 MB';
|
$string = '242.98 MB';
|
||||||
// static
|
// static
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
print "S::BYTE TO (calls as var): $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
||||||
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
|
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "<br>";
|
||||||
//
|
//
|
||||||
$byte = 314572800;
|
$byte = 314572800;
|
||||||
$string = '300 MB';
|
$string = '300 MB';
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
||||||
print "S::BYTE TO: $byte: "
|
print "S::BYTE TO: $byte: "
|
||||||
. $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
. Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
|
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "<br>";
|
||||||
|
|
||||||
// *** BYTES TEST ***
|
// *** BYTES TEST ***
|
||||||
$bytes = [
|
$bytes = [
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ if ($is_secure) {
|
|||||||
define('HOST_PROTOCOL', 'http://');
|
define('HOST_PROTOCOL', 'http://');
|
||||||
}
|
}
|
||||||
// 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', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
|
define('DB_CONFIG', $DB_CONFIG[DB_CONFIG_NAME] ?? []);
|
||||||
// because we can't change constant, but we want to for db debug flag
|
// because we can't change constant, but we want to for db debug flag
|
||||||
$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
|
$GLOBALS['DB_CONFIG_SET'] = DB_CONFIG;
|
||||||
@@ -268,9 +268,9 @@ define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCO
|
|||||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||||
// paths
|
// paths
|
||||||
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
|
// define('CSV_PATH', $PATHS[TARGET]['csv_path'] ?? '');
|
||||||
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
|
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin'] ?? '');
|
||||||
// define('REDIRECT_URL', $PATHS[TARGET]['redirect_url']);
|
// define('REDIRECT_URL', $PATHS[TARGET]['redirect_url'] ?? '');
|
||||||
|
|
||||||
// show all errors if debug_all & show_error_handling are enabled
|
// show all errors if debug_all & show_error_handling are enabled
|
||||||
define('SHOW_ALL_ERRORS', true);
|
define('SHOW_ALL_ERRORS', true);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ if (defined('LAYOUT')) {
|
|||||||
}
|
}
|
||||||
// set table width
|
// set table width
|
||||||
$table_width = '100%';
|
$table_width = '100%';
|
||||||
|
$ADMIN_STYLESHEET = 'edit.css';
|
||||||
// define all needed smarty stuff for the general HTML/page building
|
// define all needed smarty stuff for the general HTML/page building
|
||||||
$HEADER['CSS'] = CSS;
|
$HEADER['CSS'] = CSS;
|
||||||
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||||
|
|||||||
@@ -26,13 +26,16 @@ class Byte
|
|||||||
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
|
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
|
||||||
*
|
*
|
||||||
* The class itself hast the following defined
|
* The class itself hast the following defined
|
||||||
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and extension
|
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and suffix
|
||||||
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
||||||
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
||||||
* To use the constant from outside use class::CONSTANT
|
* To use the constant from outside use class::CONSTANT
|
||||||
*
|
*
|
||||||
* @param string|int|float $bytes bytes as string int or pure int
|
* @param string|int|float $bytes bytes as string int or pure int
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
|
* BYTE_FORMAT_NOSPACE: no space between number and suffix
|
||||||
|
* BYTE_FORMAT_ADJUST: sprintf adjusted two 2 decimals
|
||||||
|
* BYTE_FORMAT_SI: use 1000 instead of 1024
|
||||||
* @return string converted byte number (float) with suffix
|
* @return string converted byte number (float) with suffix
|
||||||
*/
|
*/
|
||||||
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
||||||
@@ -62,7 +65,7 @@ class Byte
|
|||||||
// si or normal
|
// si or normal
|
||||||
$unit = $si ? 1000 : 1024;
|
$unit = $si ? 1000 : 1024;
|
||||||
// always positive
|
// always positive
|
||||||
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs($bytes);
|
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs((float)$bytes);
|
||||||
// smaller than unit is always B
|
// smaller than unit is always B
|
||||||
if ($abs_bytes < $unit) {
|
if ($abs_bytes < $unit) {
|
||||||
return $bytes . 'B';
|
return $bytes . 'B';
|
||||||
@@ -110,6 +113,7 @@ class Byte
|
|||||||
*
|
*
|
||||||
* @param string|int|float $number any string or number to convert
|
* @param string|int|float $number any string or number to convert
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
|
* BYTE_FORMAT_SI: use 1000 instead of 1024
|
||||||
* @return string|int|float converted value or original value
|
* @return string|int|float converted value or original value
|
||||||
*/
|
*/
|
||||||
public static function stringByteFormat($number, int $flags = 0)
|
public static function stringByteFormat($number, int $flags = 0)
|
||||||
|
|||||||
@@ -1488,12 +1488,17 @@ class IO
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* escape data for writing to bytea type column field
|
* escape data for writing to bytea type column field
|
||||||
* @param string $bytea bytea to escape
|
* @param string $data data to escape to bytea
|
||||||
* @return string escaped bytea
|
* @return string escaped bytea
|
||||||
*/
|
*/
|
||||||
public function dbEscapeBytea($bytea)
|
public function dbEscapeBytea($data)
|
||||||
{
|
{
|
||||||
return $this->db_functions->__dbEscapeBytea($bytea);
|
return $this->db_functions->__dbEscapeBytea($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dbUnescapeBytea($bytea)
|
||||||
|
{
|
||||||
|
return $this->db_functions->__dbUnescapeBytea($bytea);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -559,15 +559,26 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* wrapper for pg_escape_byte
|
* wrapper for pg_escape_byte
|
||||||
*
|
*
|
||||||
* @param string $bytea bytea data stream
|
* @param string $data data stream
|
||||||
* @return string escaped bytea string
|
* @return string escaped bytea string
|
||||||
*/
|
*/
|
||||||
public function __dbEscapeBytea(string $bytea): string
|
public function __dbEscapeBytea(string $data): string
|
||||||
{
|
{
|
||||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return pg_escape_bytea($this->dbh, $bytea);
|
return pg_escape_bytea($this->dbh, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unescape bytea data from postgesql
|
||||||
|
*
|
||||||
|
* @param string $bytea Bytea data stream
|
||||||
|
* @return string Unescaped bytea data
|
||||||
|
*/
|
||||||
|
public function __dbUnescapeBytea(string $bytea): string
|
||||||
|
{
|
||||||
|
return pg_unescape_bytea($bytea);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -217,7 +217,15 @@ interface SqlFunctions
|
|||||||
* @param string $bytea
|
* @param string $bytea
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __dbEscapeBytea(string $bytea): string;
|
public function __dbEscapeBytea(string $data): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string $bytea
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __dbUnescapeBytea(string $bytea): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ class SmartyExtend extends \Smarty
|
|||||||
$this->HEADER['JAVASCRIPT'] = $this->ADMIN_JAVASCRIPT ? $this->ADMIN_JAVASCRIPT : ADMIN_JAVASCRIPT;
|
$this->HEADER['JAVASCRIPT'] = $this->ADMIN_JAVASCRIPT ? $this->ADMIN_JAVASCRIPT : ADMIN_JAVASCRIPT;
|
||||||
// the page name
|
// the page name
|
||||||
$this->DATA['page_name'] = $this->page_name;
|
$this->DATA['page_name'] = $this->page_name;
|
||||||
$this->DATA['table_width'] = empty($this->PAGE_WIDTH) ?: PAGE_WIDTH;
|
$this->DATA['table_width'] = !empty($this->PAGE_WIDTH) ?: PAGE_WIDTH;
|
||||||
$this->DATA['form_name'] = $this->DATA['FORM_NAME'];
|
$this->DATA['form_name'] = $this->DATA['FORM_NAME'];
|
||||||
// for tinymce special
|
// for tinymce special
|
||||||
$this->DATA['TINYMCE_LANG'] = $this->lang_short;
|
$this->DATA['TINYMCE_LANG'] = $this->lang_short;
|
||||||
|
|||||||
Reference in New Issue
Block a user