Composer installed CoreLibs
This commit is contained in:
@@ -67,7 +67,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'echo_all' => $ECHO_ALL ?? false,
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, table_arrays: $table_arrays);
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: FORM GENERATE';
|
$PAGE_NAME = 'TEST CLASS: FORM GENERATE';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
|
|||||||
@@ -9,6 +9,15 @@
|
|||||||
"email": "clemens.schwaighofer@egplusww.com"
|
"email": "clemens.schwaighofer@egplusww.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "composer",
|
||||||
|
"url": "http://composer-local.tokyo.tequila.jp"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"egrajp/corelibs-composer-all": "@dev"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"classmap": [
|
"classmap": [
|
||||||
"lib/"
|
"lib/"
|
||||||
|
|||||||
18
www/composer.lock
generated
18
www/composer.lock
generated
@@ -4,12 +4,24 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4803358a39fae1c0e68aa8125f2ad09b",
|
"content-hash": "645565cf406bc619ebe37b74b2d0590f",
|
||||||
"packages": [],
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "egrajp/corelibs-composer-all",
|
||||||
|
"version": "7.11.0",
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://git.egplusww.jp/Composer/CoreLibs-Composer-All/archive/v7.11.0.zip"
|
||||||
|
},
|
||||||
|
"type": "library"
|
||||||
|
}
|
||||||
|
],
|
||||||
"packages-dev": [],
|
"packages-dev": [],
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": [],
|
"stability-flags": {
|
||||||
|
"egrajp/corelibs-composer-all": 20
|
||||||
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
"platform": [],
|
"platform": [],
|
||||||
|
|||||||
65
www/vendor/composer/autoload_classmap.php
vendored
65
www/vendor/composer/autoload_classmap.php
vendored
@@ -8,71 +8,6 @@ $baseDir = dirname($vendorDir);
|
|||||||
return array(
|
return array(
|
||||||
'Autoloader\\Autoload' => $baseDir . '/lib/autoloader.php',
|
'Autoloader\\Autoload' => $baseDir . '/lib/autoloader.php',
|
||||||
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
|
||||||
'CoreLibs\\ACL\\Login' => $baseDir . '/lib/CoreLibs/ACL/Login.php',
|
|
||||||
'CoreLibs\\Admin\\Backend' => $baseDir . '/lib/CoreLibs/Admin/Backend.php',
|
|
||||||
'CoreLibs\\Admin\\EditBase' => $baseDir . '/lib/CoreLibs/Admin/EditBase.php',
|
|
||||||
'CoreLibs\\Basic' => $baseDir . '/lib/CoreLibs/Basic.php',
|
|
||||||
'CoreLibs\\Check\\Colors' => $baseDir . '/lib/CoreLibs/Check/Colors.php',
|
|
||||||
'CoreLibs\\Check\\Email' => $baseDir . '/lib/CoreLibs/Check/Email.php',
|
|
||||||
'CoreLibs\\Check\\Encoding' => $baseDir . '/lib/CoreLibs/Check/Encoding.php',
|
|
||||||
'CoreLibs\\Check\\File' => $baseDir . '/lib/CoreLibs/Check/File.php',
|
|
||||||
'CoreLibs\\Check\\Jason' => $baseDir . '/lib/CoreLibs/Check/Jason.php',
|
|
||||||
'CoreLibs\\Check\\Password' => $baseDir . '/lib/CoreLibs/Check/Password.php',
|
|
||||||
'CoreLibs\\Check\\PhpVersion' => $baseDir . '/lib/CoreLibs/Check/PhpVersion.php',
|
|
||||||
'CoreLibs\\Combined\\ArrayHandler' => $baseDir . '/lib/CoreLibs/Combined/ArrayHandler.php',
|
|
||||||
'CoreLibs\\Combined\\DateTime' => $baseDir . '/lib/CoreLibs/Combined/DateTime.php',
|
|
||||||
'CoreLibs\\Convert\\Byte' => $baseDir . '/lib/CoreLibs/Convert/Byte.php',
|
|
||||||
'CoreLibs\\Convert\\Colors' => $baseDir . '/lib/CoreLibs/Convert/Colors.php',
|
|
||||||
'CoreLibs\\Convert\\Encoding' => $baseDir . '/lib/CoreLibs/Convert/Encoding.php',
|
|
||||||
'CoreLibs\\Convert\\Extends\\VarSetTypeMain' => $baseDir . '/lib/CoreLibs/Convert/Extends/VarSetTypeMain.php',
|
|
||||||
'CoreLibs\\Convert\\Html' => $baseDir . '/lib/CoreLibs/Convert/Html.php',
|
|
||||||
'CoreLibs\\Convert\\Json' => $baseDir . '/lib/CoreLibs/Convert/Json.php',
|
|
||||||
'CoreLibs\\Convert\\Math' => $baseDir . '/lib/CoreLibs/Convert/Math.php',
|
|
||||||
'CoreLibs\\Convert\\MimeAppName' => $baseDir . '/lib/CoreLibs/Convert/MimeAppName.php',
|
|
||||||
'CoreLibs\\Convert\\MimeEncode' => $baseDir . '/lib/CoreLibs/Convert/MimeEncode.php',
|
|
||||||
'CoreLibs\\Convert\\Strings' => $baseDir . '/lib/CoreLibs/Convert/Strings.php',
|
|
||||||
'CoreLibs\\Convert\\VarSetType' => $baseDir . '/lib/CoreLibs/Convert/VarSetType.php',
|
|
||||||
'CoreLibs\\Convert\\VarSetTypeNull' => $baseDir . '/lib/CoreLibs/Convert/VarSetTypeNull.php',
|
|
||||||
'CoreLibs\\Create\\Email' => $baseDir . '/lib/CoreLibs/Create/Email.php',
|
|
||||||
'CoreLibs\\Create\\Hash' => $baseDir . '/lib/CoreLibs/Create/Hash.php',
|
|
||||||
'CoreLibs\\Create\\RandomKey' => $baseDir . '/lib/CoreLibs/Create/RandomKey.php',
|
|
||||||
'CoreLibs\\Create\\Session' => $baseDir . '/lib/CoreLibs/Create/Session.php',
|
|
||||||
'CoreLibs\\Create\\Uids' => $baseDir . '/lib/CoreLibs/Create/Uids.php',
|
|
||||||
'CoreLibs\\DB\\Extended\\ArrayIO' => $baseDir . '/lib/CoreLibs/DB/Extended/ArrayIO.php',
|
|
||||||
'CoreLibs\\DB\\IO' => $baseDir . '/lib/CoreLibs/DB/IO.php',
|
|
||||||
'CoreLibs\\DB\\SQL\\PgSQL' => $baseDir . '/lib/CoreLibs/DB/SQL/PgSQL.php',
|
|
||||||
'CoreLibs\\DB\\SQL\\SqlInterface\\SqlFunctions' => $baseDir . '/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php',
|
|
||||||
'CoreLibs\\Debug\\FileWriter' => $baseDir . '/lib/CoreLibs/Debug/FileWriter.php',
|
|
||||||
'CoreLibs\\Debug\\Logging' => $baseDir . '/lib/CoreLibs/Debug/Logging.php',
|
|
||||||
'CoreLibs\\Debug\\MemoryUsage' => $baseDir . '/lib/CoreLibs/Debug/MemoryUsage.php',
|
|
||||||
'CoreLibs\\Debug\\RunningTime' => $baseDir . '/lib/CoreLibs/Debug/RunningTime.php',
|
|
||||||
'CoreLibs\\Debug\\Support' => $baseDir . '/lib/CoreLibs/Debug/Support.php',
|
|
||||||
'CoreLibs\\Get\\DotEnv' => $baseDir . '/lib/CoreLibs/Get/DotEnv.php',
|
|
||||||
'CoreLibs\\Get\\ReadEnvFile' => $baseDir . '/lib/CoreLibs/Get/ReadEnvFile.php',
|
|
||||||
'CoreLibs\\Get\\System' => $baseDir . '/lib/CoreLibs/Get/System.php',
|
|
||||||
'CoreLibs\\Language\\Core\\CachedFileReader' => $baseDir . '/lib/CoreLibs/Language/Core/CachedFileReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\FileReader' => $baseDir . '/lib/CoreLibs/Language/Core/FileReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\GetTextReader' => $baseDir . '/lib/CoreLibs/Language/Core/GetTextReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\StreamReader' => $baseDir . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\StringReader' => $baseDir . '/lib/CoreLibs/Language/Core/StringReader.php',
|
|
||||||
'CoreLibs\\Language\\Encoding' => $baseDir . '/lib/CoreLibs/Language/Encoding.php',
|
|
||||||
'CoreLibs\\Language\\GetLocale' => $baseDir . '/lib/CoreLibs/Language/GetLocale.php',
|
|
||||||
'CoreLibs\\Language\\L10n' => $baseDir . '/lib/CoreLibs/Language/L10n.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Elements' => $baseDir . '/lib/CoreLibs/Output/Form/Elements.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Generate' => $baseDir . '/lib/CoreLibs/Output/Form/Generate.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArraysInterface' => $baseDir . '/lib/CoreLibs/Output/TableArraysInterface.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditAccess' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditGroups' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditLanguages' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditMenuGroup' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditPages' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditPages.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditSchemas' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditUsers' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditVisibleGroup' => $baseDir . '/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Token' => $baseDir . '/lib/CoreLibs/Output/Form/Token.php',
|
|
||||||
'CoreLibs\\Output\\Image' => $baseDir . '/lib/CoreLibs/Output/Image.php',
|
|
||||||
'CoreLibs\\Output\\ProgressBar' => $baseDir . '/lib/CoreLibs/Output/ProgressBar.php',
|
|
||||||
'CoreLibs\\Template\\SmartyExtend' => $baseDir . '/lib/CoreLibs/Template/SmartyExtend.php',
|
|
||||||
'FileUpload\\Core\\qqUploadedFile' => $baseDir . '/lib/FileUpload/Core/qqUploadedFile.php',
|
'FileUpload\\Core\\qqUploadedFile' => $baseDir . '/lib/FileUpload/Core/qqUploadedFile.php',
|
||||||
'FileUpload\\Core\\qqUploadedFileForm' => $baseDir . '/lib/FileUpload/Core/qqUploadedFileForm.php',
|
'FileUpload\\Core\\qqUploadedFileForm' => $baseDir . '/lib/FileUpload/Core/qqUploadedFileForm.php',
|
||||||
'FileUpload\\Core\\qqUploadedFileXhr' => $baseDir . '/lib/FileUpload/Core/qqUploadedFileXhr.php',
|
'FileUpload\\Core\\qqUploadedFileXhr' => $baseDir . '/lib/FileUpload/Core/qqUploadedFileXhr.php',
|
||||||
|
|||||||
65
www/vendor/composer/autoload_static.php
vendored
65
www/vendor/composer/autoload_static.php
vendored
@@ -9,71 +9,6 @@ class ComposerStaticInit10fe8fe2ec4017b8644d2b64bcf398b9
|
|||||||
public static $classMap = array (
|
public static $classMap = array (
|
||||||
'Autoloader\\Autoload' => __DIR__ . '/../..' . '/lib/autoloader.php',
|
'Autoloader\\Autoload' => __DIR__ . '/../..' . '/lib/autoloader.php',
|
||||||
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
|
||||||
'CoreLibs\\ACL\\Login' => __DIR__ . '/../..' . '/lib/CoreLibs/ACL/Login.php',
|
|
||||||
'CoreLibs\\Admin\\Backend' => __DIR__ . '/../..' . '/lib/CoreLibs/Admin/Backend.php',
|
|
||||||
'CoreLibs\\Admin\\EditBase' => __DIR__ . '/../..' . '/lib/CoreLibs/Admin/EditBase.php',
|
|
||||||
'CoreLibs\\Basic' => __DIR__ . '/../..' . '/lib/CoreLibs/Basic.php',
|
|
||||||
'CoreLibs\\Check\\Colors' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Colors.php',
|
|
||||||
'CoreLibs\\Check\\Email' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Email.php',
|
|
||||||
'CoreLibs\\Check\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Encoding.php',
|
|
||||||
'CoreLibs\\Check\\File' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/File.php',
|
|
||||||
'CoreLibs\\Check\\Jason' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Jason.php',
|
|
||||||
'CoreLibs\\Check\\Password' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/Password.php',
|
|
||||||
'CoreLibs\\Check\\PhpVersion' => __DIR__ . '/../..' . '/lib/CoreLibs/Check/PhpVersion.php',
|
|
||||||
'CoreLibs\\Combined\\ArrayHandler' => __DIR__ . '/../..' . '/lib/CoreLibs/Combined/ArrayHandler.php',
|
|
||||||
'CoreLibs\\Combined\\DateTime' => __DIR__ . '/../..' . '/lib/CoreLibs/Combined/DateTime.php',
|
|
||||||
'CoreLibs\\Convert\\Byte' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Byte.php',
|
|
||||||
'CoreLibs\\Convert\\Colors' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Colors.php',
|
|
||||||
'CoreLibs\\Convert\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Encoding.php',
|
|
||||||
'CoreLibs\\Convert\\Extends\\VarSetTypeMain' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Extends/VarSetTypeMain.php',
|
|
||||||
'CoreLibs\\Convert\\Html' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Html.php',
|
|
||||||
'CoreLibs\\Convert\\Json' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Json.php',
|
|
||||||
'CoreLibs\\Convert\\Math' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Math.php',
|
|
||||||
'CoreLibs\\Convert\\MimeAppName' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeAppName.php',
|
|
||||||
'CoreLibs\\Convert\\MimeEncode' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/MimeEncode.php',
|
|
||||||
'CoreLibs\\Convert\\Strings' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/Strings.php',
|
|
||||||
'CoreLibs\\Convert\\VarSetType' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/VarSetType.php',
|
|
||||||
'CoreLibs\\Convert\\VarSetTypeNull' => __DIR__ . '/../..' . '/lib/CoreLibs/Convert/VarSetTypeNull.php',
|
|
||||||
'CoreLibs\\Create\\Email' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Email.php',
|
|
||||||
'CoreLibs\\Create\\Hash' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Hash.php',
|
|
||||||
'CoreLibs\\Create\\RandomKey' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/RandomKey.php',
|
|
||||||
'CoreLibs\\Create\\Session' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Session.php',
|
|
||||||
'CoreLibs\\Create\\Uids' => __DIR__ . '/../..' . '/lib/CoreLibs/Create/Uids.php',
|
|
||||||
'CoreLibs\\DB\\Extended\\ArrayIO' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/Extended/ArrayIO.php',
|
|
||||||
'CoreLibs\\DB\\IO' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/IO.php',
|
|
||||||
'CoreLibs\\DB\\SQL\\PgSQL' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/SQL/PgSQL.php',
|
|
||||||
'CoreLibs\\DB\\SQL\\SqlInterface\\SqlFunctions' => __DIR__ . '/../..' . '/lib/CoreLibs/DB/SQL/SqlInterface/SqlFunctions.php',
|
|
||||||
'CoreLibs\\Debug\\FileWriter' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/FileWriter.php',
|
|
||||||
'CoreLibs\\Debug\\Logging' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/Logging.php',
|
|
||||||
'CoreLibs\\Debug\\MemoryUsage' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/MemoryUsage.php',
|
|
||||||
'CoreLibs\\Debug\\RunningTime' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/RunningTime.php',
|
|
||||||
'CoreLibs\\Debug\\Support' => __DIR__ . '/../..' . '/lib/CoreLibs/Debug/Support.php',
|
|
||||||
'CoreLibs\\Get\\DotEnv' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/DotEnv.php',
|
|
||||||
'CoreLibs\\Get\\ReadEnvFile' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/ReadEnvFile.php',
|
|
||||||
'CoreLibs\\Get\\System' => __DIR__ . '/../..' . '/lib/CoreLibs/Get/System.php',
|
|
||||||
'CoreLibs\\Language\\Core\\CachedFileReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/CachedFileReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\FileReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/FileReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\GetTextReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/GetTextReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\StreamReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StreamReader.php',
|
|
||||||
'CoreLibs\\Language\\Core\\StringReader' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Core/StringReader.php',
|
|
||||||
'CoreLibs\\Language\\Encoding' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/Encoding.php',
|
|
||||||
'CoreLibs\\Language\\GetLocale' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/GetLocale.php',
|
|
||||||
'CoreLibs\\Language\\L10n' => __DIR__ . '/../..' . '/lib/CoreLibs/Language/L10n.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Elements' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Elements.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Generate' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Generate.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArraysInterface' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/TableArraysInterface.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditAccess' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditAccess.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditGroups' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditGroups.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditLanguages' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditLanguages.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditMenuGroup' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditMenuGroup.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditPages' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditPages.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditSchemas' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditSchemas.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditUsers' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditUsers.php',
|
|
||||||
'CoreLibs\\Output\\Form\\TableArrays\\EditVisibleGroup' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/TableArrays/EditVisibleGroup.php',
|
|
||||||
'CoreLibs\\Output\\Form\\Token' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Form/Token.php',
|
|
||||||
'CoreLibs\\Output\\Image' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/Image.php',
|
|
||||||
'CoreLibs\\Output\\ProgressBar' => __DIR__ . '/../..' . '/lib/CoreLibs/Output/ProgressBar.php',
|
|
||||||
'CoreLibs\\Template\\SmartyExtend' => __DIR__ . '/../..' . '/lib/CoreLibs/Template/SmartyExtend.php',
|
|
||||||
'FileUpload\\Core\\qqUploadedFile' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFile.php',
|
'FileUpload\\Core\\qqUploadedFile' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFile.php',
|
||||||
'FileUpload\\Core\\qqUploadedFileForm' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFileForm.php',
|
'FileUpload\\Core\\qqUploadedFileForm' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFileForm.php',
|
||||||
'FileUpload\\Core\\qqUploadedFileXhr' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFileXhr.php',
|
'FileUpload\\Core\\qqUploadedFileXhr' => __DIR__ . '/../..' . '/lib/FileUpload/Core/qqUploadedFileXhr.php',
|
||||||
|
|||||||
15
www/vendor/composer/installed.json
vendored
15
www/vendor/composer/installed.json
vendored
@@ -1,5 +1,18 @@
|
|||||||
{
|
{
|
||||||
"packages": [],
|
"packages": [
|
||||||
|
{
|
||||||
|
"name": "egrajp/corelibs-composer-all",
|
||||||
|
"version": "7.11.0",
|
||||||
|
"version_normalized": "7.11.0.0",
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://git.egplusww.jp/Composer/CoreLibs-Composer-All/archive/v7.11.0.zip"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"installation-source": "dist",
|
||||||
|
"install-path": "../egrajp/corelibs-composer-all"
|
||||||
|
}
|
||||||
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dev-package-names": []
|
"dev-package-names": []
|
||||||
}
|
}
|
||||||
|
|||||||
13
www/vendor/composer/installed.php
vendored
13
www/vendor/composer/installed.php
vendored
@@ -1,6 +1,6 @@
|
|||||||
<?php return array(
|
<?php return array(
|
||||||
'root' => array(
|
'root' => array(
|
||||||
'name' => 'gullevek/corelibs-dev',
|
'name' => 'egrajp/corelibs-dev',
|
||||||
'pretty_version' => 'dev-master',
|
'pretty_version' => 'dev-master',
|
||||||
'version' => 'dev-master',
|
'version' => 'dev-master',
|
||||||
'reference' => NULL,
|
'reference' => NULL,
|
||||||
@@ -10,7 +10,16 @@
|
|||||||
'dev' => true,
|
'dev' => true,
|
||||||
),
|
),
|
||||||
'versions' => array(
|
'versions' => array(
|
||||||
'gullevek/corelibs-dev' => array(
|
'egrajp/corelibs-composer-all' => array(
|
||||||
|
'pretty_version' => '7.11.0',
|
||||||
|
'version' => '7.11.0.0',
|
||||||
|
'reference' => NULL,
|
||||||
|
'type' => 'library',
|
||||||
|
'install_path' => __DIR__ . '/../egrajp/corelibs-composer-all',
|
||||||
|
'aliases' => array(),
|
||||||
|
'dev_requirement' => false,
|
||||||
|
),
|
||||||
|
'egrajp/corelibs-dev' => array(
|
||||||
'pretty_version' => 'dev-master',
|
'pretty_version' => 'dev-master',
|
||||||
'version' => 'dev-master',
|
'version' => 'dev-master',
|
||||||
'reference' => NULL,
|
'reference' => NULL,
|
||||||
|
|||||||
19
www/vendor/egrajp/corelibs-composer-all/composer.json
vendored
Normal file
19
www/vendor/egrajp/corelibs-composer-all/composer.json
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "egrajp/corelibs-composer-all",
|
||||||
|
"description": "CoreLibs in a composer package",
|
||||||
|
"type": "library",
|
||||||
|
"license": "MIT",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Corelibs\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Clemens Schwaighofer",
|
||||||
|
"email": "clemens.schwaighofer@egplusww.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"minimum-stability": "dev",
|
||||||
|
"require": {}
|
||||||
|
}
|
||||||
2213
www/vendor/egrajp/corelibs-composer-all/src/ACL/Login.php
vendored
Normal file
2213
www/vendor/egrajp/corelibs-composer-all/src/ACL/Login.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
622
www/vendor/egrajp/corelibs-composer-all/src/Admin/Backend.php
vendored
Normal file
622
www/vendor/egrajp/corelibs-composer-all/src/Admin/Backend.php
vendored
Normal file
@@ -0,0 +1,622 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* AUTHOR: Clemens Schwaighofer
|
||||||
|
* CREATED: 2006/08/15
|
||||||
|
* VERSION: 1.0.0
|
||||||
|
* RELEASED LICENSE: GNU GPL 3
|
||||||
|
* DESCRIPTION
|
||||||
|
* Basic Admin interface backend
|
||||||
|
* - sets action flags
|
||||||
|
* - menu creation
|
||||||
|
* - array vars for smarty
|
||||||
|
*
|
||||||
|
* CHANGE PLAN:
|
||||||
|
* loads DB\IO + Logger and returns one group object
|
||||||
|
* also checks all missing CONFIG vars from Basic class
|
||||||
|
*
|
||||||
|
* PUBLIC VARIABLES
|
||||||
|
*
|
||||||
|
* PRIVATE VARIABLES
|
||||||
|
*
|
||||||
|
* PUBLIC METHODS
|
||||||
|
*
|
||||||
|
* PRIVATE METHODS
|
||||||
|
*
|
||||||
|
* HISTORY:
|
||||||
|
*
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Admin;
|
||||||
|
|
||||||
|
class Backend
|
||||||
|
{
|
||||||
|
// page name
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $menu = [];
|
||||||
|
/** @var int|string */
|
||||||
|
public $menu_show_flag = 0; // top menu flag (mostly string)
|
||||||
|
// action ids
|
||||||
|
/** @var array<string> */
|
||||||
|
public $action_list = [
|
||||||
|
'action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag',
|
||||||
|
'action_menu', 'action_value', 'action_error', 'action_loaded'
|
||||||
|
];
|
||||||
|
/** @var string */
|
||||||
|
public $action;
|
||||||
|
/** @var string|int */
|
||||||
|
public $action_id;
|
||||||
|
/** @var string|int */
|
||||||
|
public $action_sub_id;
|
||||||
|
/** @var string|int|bool */
|
||||||
|
public $action_yes;
|
||||||
|
/** @var string */
|
||||||
|
public $action_flag;
|
||||||
|
/** @var string */
|
||||||
|
public $action_menu;
|
||||||
|
/** @var string */
|
||||||
|
public $action_loaded;
|
||||||
|
/** @var string */
|
||||||
|
public $action_value;
|
||||||
|
/** @var string */
|
||||||
|
public $action_error;
|
||||||
|
// ACL array variable if we want to set acl data from outisde
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $acl = [];
|
||||||
|
/** @var int */
|
||||||
|
public $default_acl;
|
||||||
|
// queue key
|
||||||
|
/** @var string */
|
||||||
|
public $queue_key;
|
||||||
|
// 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 = [];
|
||||||
|
/** @var bool */
|
||||||
|
public $error = false;
|
||||||
|
/** @var bool */
|
||||||
|
public $warning = false;
|
||||||
|
/** @var bool */
|
||||||
|
public $info = false;
|
||||||
|
// internal lang & encoding vars
|
||||||
|
/** @var string */
|
||||||
|
public $lang_dir = '';
|
||||||
|
/** @var string */
|
||||||
|
public $lang;
|
||||||
|
/** @var string */
|
||||||
|
public $lang_short;
|
||||||
|
/** @var string */
|
||||||
|
public $domain;
|
||||||
|
/** @var string */
|
||||||
|
public $encoding;
|
||||||
|
/** @var \CoreLibs\Debug\Logging logger */
|
||||||
|
public $log;
|
||||||
|
/** @var \CoreLibs\DB\IO database */
|
||||||
|
public $db;
|
||||||
|
/** @var \CoreLibs\Language\L10n language */
|
||||||
|
public $l;
|
||||||
|
/** @var \CoreLibs\Create\Session session class */
|
||||||
|
public $session;
|
||||||
|
// smarty publics [end processing in smarty class]
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $DATA;
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $HEADER;
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $DEBUG_DATA;
|
||||||
|
/** @var array<mixed> */
|
||||||
|
public $CONTENT_DATA;
|
||||||
|
|
||||||
|
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||||
|
/**
|
||||||
|
* main class constructor
|
||||||
|
*
|
||||||
|
* @param \CoreLibs\DB\IO $db Database connection class
|
||||||
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
|
* @param \CoreLibs\Create\Session $session Session interface class
|
||||||
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
|
* @param array<string,string> $locale locale data read from setLocale
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
\CoreLibs\DB\IO $db,
|
||||||
|
\CoreLibs\Debug\Logging $log,
|
||||||
|
\CoreLibs\Create\Session $session,
|
||||||
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
array $locale
|
||||||
|
) {
|
||||||
|
// attach db class
|
||||||
|
$this->db = $db;
|
||||||
|
// set to log not per class
|
||||||
|
$log->setLogPer('class', false);
|
||||||
|
// attach logger
|
||||||
|
$this->log = $log;
|
||||||
|
// attach session class
|
||||||
|
$this->session = $session;
|
||||||
|
// get the language sub class & init it
|
||||||
|
$this->l = $l10n;
|
||||||
|
// parse and read, legacy stuff
|
||||||
|
$this->encoding = $locale['encoding'];
|
||||||
|
$this->lang = $locale['lang'];
|
||||||
|
// get first part from lang
|
||||||
|
$this->lang_short = explode('_', $locale['lang'])[0];
|
||||||
|
$this->domain = $this->l->getDomain();
|
||||||
|
$this->lang_dir = $this->l->getBaseLocalePath();
|
||||||
|
|
||||||
|
// 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] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->default_acl = DEFAULT_ACL_LEVEL;
|
||||||
|
|
||||||
|
// queue key
|
||||||
|
if (preg_match("/^(add|save|delete|remove|move|up|down|push_live)$/", $this->action)) {
|
||||||
|
$this->queue_key = \CoreLibs\Create\RandomKey::randomKeyGen(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class deconstructor
|
||||||
|
*/
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
// NO OP
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUBLIC METHODS |=================================================>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set internal ACL from login ACL
|
||||||
|
*
|
||||||
|
* @param array<mixed> $acl login acl array
|
||||||
|
*/
|
||||||
|
public function setACL(array $acl): void
|
||||||
|
{
|
||||||
|
$this->acl = $acl;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes all action vars plus other info into edit_log table
|
||||||
|
*
|
||||||
|
* @param string $event any kind of event description,
|
||||||
|
* @param string|array<mixed> $data any kind of data related to that event
|
||||||
|
* @param string $write_type write type can bei STRING or BINARY
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function adbEditLog(
|
||||||
|
string $event = '',
|
||||||
|
$data = '',
|
||||||
|
string $write_type = 'STRING'
|
||||||
|
): void {
|
||||||
|
$data_binary = '';
|
||||||
|
if ($write_type == 'BINARY') {
|
||||||
|
$data_binary = $this->db->dbEscapeBytea((string)bzcompress(serialize($data)));
|
||||||
|
$data = 'see bzip compressed data_binary field';
|
||||||
|
}
|
||||||
|
if ($write_type == 'STRING') {
|
||||||
|
$data_binary = '';
|
||||||
|
$data = $this->db->dbEscapeString(serialize($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
// check schema
|
||||||
|
$SCHEMA = 'public';
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) {
|
||||||
|
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||||
|
} elseif ($this->db->dbGetSchema()) {
|
||||||
|
$SCHEMA = $this->db->dbGetSchema();
|
||||||
|
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||||
|
$SCHEMA = PUBLIC_SCHEMA;
|
||||||
|
}
|
||||||
|
/** @phpstan-ignore-next-line for whatever reason $SCHEMA is seen as possible array */
|
||||||
|
$q = "INSERT INTO " . $SCHEMA . ".edit_log "
|
||||||
|
. "(euid, event_date, event, data, data_binary, page, "
|
||||||
|
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
|
||||||
|
. "http_accept, http_accept_charset, http_accept_encoding, session_id, "
|
||||||
|
. "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "
|
||||||
|
. "VALUES "
|
||||||
|
. "(" . $this->db->dbEscapeString(isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ?
|
||||||
|
$_SESSION['EUID'] :
|
||||||
|
'NULL')
|
||||||
|
. ", "
|
||||||
|
. "NOW(), "
|
||||||
|
. "'" . $this->db->dbEscapeString((string)$event) . "', '" . $data . "', "
|
||||||
|
. "'" . $data_binary . "', '" . $this->db->dbEscapeString((string)$this->page_name) . "', "
|
||||||
|
. "'" . @$_SERVER["REMOTE_ADDR"] . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString(@$_SERVER['HTTP_USER_AGENT']) . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_REFERER'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['SCRIPT_FILENAME'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['QUERY_STRING'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['SERVER_NAME'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_HOST'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '') . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '') . "', "
|
||||||
|
. ($this->session->getSessionId() === false ?
|
||||||
|
"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->dbExec($q, 'NULL');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the menu show flag
|
||||||
|
*
|
||||||
|
* @param string|int $menu_show_flag
|
||||||
|
* @return string|int
|
||||||
|
*/
|
||||||
|
public function adbSetMenuShowFlag($menu_show_flag)
|
||||||
|
{
|
||||||
|
// must be string or int
|
||||||
|
$this->menu_show_flag = $menu_show_flag;
|
||||||
|
return $this->menu_show_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the menu show flag
|
||||||
|
*
|
||||||
|
* @return string|int
|
||||||
|
*/
|
||||||
|
public function adbGetMenuShowFlag()
|
||||||
|
{
|
||||||
|
return $this->menu_show_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* menu creater (from login menu session pages)
|
||||||
|
*
|
||||||
|
* @param int $flag visible flag trigger
|
||||||
|
* @return array<mixed> menu array for output on page (smarty)
|
||||||
|
*/
|
||||||
|
public function adbTopMenu(int $flag = 0): array
|
||||||
|
{
|
||||||
|
if ($this->menu_show_flag) {
|
||||||
|
$flag = $this->menu_show_flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the session pages array
|
||||||
|
$PAGES = $_SESSION['PAGES'] ?? null;
|
||||||
|
if (!isset($PAGES) || !is_array($PAGES)) {
|
||||||
|
$PAGES = [];
|
||||||
|
}
|
||||||
|
$pages = [];
|
||||||
|
foreach ($PAGES as $PAGE_DATA) {
|
||||||
|
$pages[] = $PAGE_DATA;
|
||||||
|
}
|
||||||
|
// $this->debug('pages', $this->print_ar($pages));
|
||||||
|
// if flag is 0, then we show all, else, we show only the matching flagges array points
|
||||||
|
// array is already sorted after correct order
|
||||||
|
reset($pages);
|
||||||
|
foreach ($pages as $data) {
|
||||||
|
// for ($i = 0, $iMax = count($pages); $i < $iMax; $i ++) {
|
||||||
|
$show = 0;
|
||||||
|
// is it visible in the menu & is it online
|
||||||
|
if ($data['menu'] && $data['online']) {
|
||||||
|
// check if it falls into our flag if we have a flag
|
||||||
|
if ($flag) {
|
||||||
|
foreach ($data['visible'] as $name => $key) {
|
||||||
|
if ($key == $flag) {
|
||||||
|
$show = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if no flag given, show all menu points
|
||||||
|
$show = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($show) {
|
||||||
|
// if it is popup, write popup arrayound
|
||||||
|
if (isset($data['popup']) && $data['popup']) {
|
||||||
|
$type = 'popup';
|
||||||
|
} else {
|
||||||
|
$type = 'normal';
|
||||||
|
$data['popup'] = 0;
|
||||||
|
}
|
||||||
|
$query_string = '';
|
||||||
|
|
||||||
|
if (
|
||||||
|
isset($data['query']) &&
|
||||||
|
is_array($data['query']) &&
|
||||||
|
count($data['query'])
|
||||||
|
) {
|
||||||
|
// for ($j = 0, $jMax = count($pages[$i]['query']); $j < $jMax; $j ++) {
|
||||||
|
foreach ($data['query'] as $j => $query) {
|
||||||
|
if (
|
||||||
|
!empty($query['name']) &&
|
||||||
|
!empty($query['value'])
|
||||||
|
) {
|
||||||
|
if (strlen($query_string)) {
|
||||||
|
$query_string .= '&';
|
||||||
|
}
|
||||||
|
$query_string .= $query['name'] . '=';
|
||||||
|
if (
|
||||||
|
isset($query['dynamic']) &&
|
||||||
|
$query['dynamic']
|
||||||
|
) {
|
||||||
|
if (isset($_GET[$query['value']])) {
|
||||||
|
$query_string .= urlencode($_GET[$query['value']]);
|
||||||
|
} elseif (isset($_POST[$query['value']])) {
|
||||||
|
$query_string .= urlencode($_POST[$query['value']]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$query_string .= urlencode($query['value']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$url = '';
|
||||||
|
if (isset($data['hostname']) && $data['hostname']) {
|
||||||
|
$url .= $data['hostname'];
|
||||||
|
}
|
||||||
|
$url .= $data['filename'] ?? '';
|
||||||
|
if (strlen($query_string)) {
|
||||||
|
$url .= '?' . $query_string;
|
||||||
|
}
|
||||||
|
$name = $data['page_name'] ?? '';
|
||||||
|
// if page name matchs -> set selected flag
|
||||||
|
$selected = 0;
|
||||||
|
if (
|
||||||
|
isset($data['filename']) &&
|
||||||
|
\CoreLibs\Get\System::getPageName() == $data['filename'] &&
|
||||||
|
(!isset($data['hostname']) || (
|
||||||
|
isset($data['hostname']) &&
|
||||||
|
(!$data['hostname'] || strstr($data['hostname'], CONTENT_PATH) !== false)
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
$selected = 1;
|
||||||
|
$this->page_name = $name;
|
||||||
|
}
|
||||||
|
// last check, is this menu point okay to show
|
||||||
|
$enabled = 0;
|
||||||
|
if (
|
||||||
|
isset($data['filename']) &&
|
||||||
|
$this->adbShowMenuPoint($data['filename'])
|
||||||
|
) {
|
||||||
|
$enabled = 1;
|
||||||
|
}
|
||||||
|
// write in to view menu array
|
||||||
|
array_push($this->menu, [
|
||||||
|
'name' => $this->l->__($name),
|
||||||
|
'url' => $url,
|
||||||
|
'selected' => $selected,
|
||||||
|
'enabled' => $enabled,
|
||||||
|
'popup' => $type == 'popup' ? 1 : 0,
|
||||||
|
'type' => $type
|
||||||
|
]);
|
||||||
|
} // show page
|
||||||
|
} // online and in menu
|
||||||
|
} // for each page
|
||||||
|
return $this->menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ONLY USED IN adbTopMenu
|
||||||
|
* checks if this filename is in the current situation (user id, etc) available
|
||||||
|
*
|
||||||
|
* @param string|null $filename filename
|
||||||
|
* @return bool true for visible/accessable menu point, false for not
|
||||||
|
*/
|
||||||
|
private function adbShowMenuPoint(?string $filename): bool
|
||||||
|
{
|
||||||
|
$enabled = false;
|
||||||
|
if ($filename === null) {
|
||||||
|
return $enabled;
|
||||||
|
}
|
||||||
|
/** @phan-suppress-next-line PhanNoopSwitchCases */
|
||||||
|
switch ($filename) {
|
||||||
|
default:
|
||||||
|
$enabled = true;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
return $enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates out of a normal db_return array an assoc array
|
||||||
|
*
|
||||||
|
* @param array<mixed> $db_array input array
|
||||||
|
* @param string|int|bool $key key
|
||||||
|
* @param string|int|bool $value value
|
||||||
|
* @return array<mixed> associative array
|
||||||
|
* @deprecated \CoreLibs\Combined\ArrayHandler::genAssocArray()
|
||||||
|
*/
|
||||||
|
public function adbAssocArray(array $db_array, $key, $value): array
|
||||||
|
{
|
||||||
|
trigger_error(
|
||||||
|
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Combined\ArrayHandler::genAssocArray',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
return \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts bytes into formated string with KB, MB, etc
|
||||||
|
*
|
||||||
|
* @param string|int|float $number string or int or number
|
||||||
|
* @return string formatted string
|
||||||
|
* @deprecated \CoreLibs\Convert\Byte::humanReadableByteFormat()
|
||||||
|
*/
|
||||||
|
public function adbByteStringFormat($number): string
|
||||||
|
{
|
||||||
|
trigger_error(
|
||||||
|
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Convert\Byte::humanReadableByteFormat()',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
return \CoreLibs\Convert\Byte::humanReadableByteFormat($number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts picture to a thumbnail with max x and max y size
|
||||||
|
*
|
||||||
|
* @param string $pic source image file with or without path
|
||||||
|
* @param int $size_x maximum size width
|
||||||
|
* @param int $size_y maximum size height
|
||||||
|
* @param string $dummy empty, or file_type to show an icon
|
||||||
|
* instead of nothing if file is not found
|
||||||
|
* @param string $path if source start is not ROOT path
|
||||||
|
* if empty ROOT is choosen
|
||||||
|
* @return string|bool thumbnail name, or false for error
|
||||||
|
* @deprecated \CoreLibs\Output\Image::createThumbnail()
|
||||||
|
*/
|
||||||
|
public function adbCreateThumbnail(
|
||||||
|
string $pic,
|
||||||
|
int $size_x,
|
||||||
|
int $size_y,
|
||||||
|
string $dummy = '',
|
||||||
|
string $path = '',
|
||||||
|
string $cache = ''
|
||||||
|
) {
|
||||||
|
trigger_error(
|
||||||
|
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Output\Image::createThumbnail()',
|
||||||
|
E_USER_DEPRECATED
|
||||||
|
);
|
||||||
|
return \CoreLibs\Output\Image::createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper function to fill up the mssages array
|
||||||
|
*
|
||||||
|
* @param string $level info/warning/error
|
||||||
|
* @param string $msg string, can be printf formated
|
||||||
|
* @param array<mixed> $vars optional data for a possible printf formated msg
|
||||||
|
* @return void has no return
|
||||||
|
*/
|
||||||
|
public function adbMsg(string $level, string $msg, array $vars = []): void
|
||||||
|
{
|
||||||
|
if (!preg_match("/^info|warning|error$/", $level)) {
|
||||||
|
$level = "info";
|
||||||
|
}
|
||||||
|
$this->messages[] = [
|
||||||
|
'msg' => vsprintf($this->l->__($msg), $vars),
|
||||||
|
'class' => $level
|
||||||
|
];
|
||||||
|
switch ($level) {
|
||||||
|
case 'info':
|
||||||
|
$this->info = true;
|
||||||
|
break;
|
||||||
|
case 'warning':
|
||||||
|
$this->warning = true;
|
||||||
|
break;
|
||||||
|
case 'error':
|
||||||
|
$this->error = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* writes live queue
|
||||||
|
*
|
||||||
|
* @param string $queue_key string to identfy the queue
|
||||||
|
* @param string $type [description]
|
||||||
|
* @param string $target [description]
|
||||||
|
* @param string $data [description]
|
||||||
|
* @param string $key_name [description]
|
||||||
|
* @param string $key_value [description]
|
||||||
|
* @param ?string $associate [description]
|
||||||
|
* @param ?string $file [description]
|
||||||
|
* @return void has no return
|
||||||
|
*/
|
||||||
|
public function adbLiveQueue(
|
||||||
|
string $queue_key,
|
||||||
|
string $type,
|
||||||
|
string $target,
|
||||||
|
string $data,
|
||||||
|
string $key_name,
|
||||||
|
string $key_value,
|
||||||
|
string $associate = null,
|
||||||
|
string $file = null
|
||||||
|
): void {
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
if (defined('GLOBAL_DB_SCHEMA') && !empty(GLOBAL_DB_SCHEMA)) {
|
||||||
|
$SCHEMA = GLOBAL_DB_SCHEMA;
|
||||||
|
} elseif ($this->db->dbGetSchema()) {
|
||||||
|
$SCHEMA = $this->db->dbGetSchema();
|
||||||
|
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||||
|
$SCHEMA = PUBLIC_SCHEMA;
|
||||||
|
} else {
|
||||||
|
$SCHEMA = 'public';
|
||||||
|
}
|
||||||
|
$q = "INSERT INTO " . $SCHEMA . ".live_queue ("
|
||||||
|
. "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file"
|
||||||
|
. ") VALUES ("
|
||||||
|
. "'" . $this->db->dbEscapeString($queue_key) . "', '" . $this->db->dbEscapeString($key_value) . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($key_name) . "', '" . $this->db->dbEscapeString($type) . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString($target) . "', '" . $this->db->dbEscapeString($data) . "', "
|
||||||
|
. "'" . $this->queue_key . "', '" . $this->action . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString((string)$associate) . "', "
|
||||||
|
. "'" . $this->db->dbEscapeString((string)$file) . "')";
|
||||||
|
$this->db->dbExec($q);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic class holds exact the same, except the Year/Month/Day/etc strings
|
||||||
|
* are translated in this call
|
||||||
|
*
|
||||||
|
* @param int $year year YYYY
|
||||||
|
* @param int $month month m
|
||||||
|
* @param int $day day d
|
||||||
|
* @param int $hour hour H
|
||||||
|
* @param int $min min i
|
||||||
|
* @param string $suffix additional info printed after the date time
|
||||||
|
* variable in the drop down
|
||||||
|
* also used for ID in the on change JS call
|
||||||
|
* @param int $min_steps default is 1 (minute), can set to anything,
|
||||||
|
* is used as sum up from 0
|
||||||
|
* @param bool $name_pos_back default false, if set to true,
|
||||||
|
* the name will be printend
|
||||||
|
* after the drop down and not before the drop down
|
||||||
|
* @return string HTML formated strings for drop down lists
|
||||||
|
* of date and time
|
||||||
|
*/
|
||||||
|
public function adbPrintDateTime(
|
||||||
|
$year,
|
||||||
|
$month,
|
||||||
|
$day,
|
||||||
|
$hour,
|
||||||
|
$min,
|
||||||
|
string $suffix = '',
|
||||||
|
int $min_steps = 1,
|
||||||
|
bool $name_pos_back = false
|
||||||
|
) {
|
||||||
|
// get the build layout
|
||||||
|
$html_time = \CoreLibs\Output\Form\Elements::printDateTime(
|
||||||
|
$year,
|
||||||
|
$month,
|
||||||
|
$day,
|
||||||
|
$hour,
|
||||||
|
$min,
|
||||||
|
$suffix,
|
||||||
|
$min_steps,
|
||||||
|
$name_pos_back
|
||||||
|
);
|
||||||
|
// translate the strings inside
|
||||||
|
foreach (['Year ', 'Month ', 'Day ', 'Hour ', 'Minute '] as $_time) {
|
||||||
|
$html_time = str_replace($_time, $this->l->__(str_replace(' ', '', $_time)) . ' ', $html_time);
|
||||||
|
}
|
||||||
|
// replace week days in short
|
||||||
|
foreach (['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] as $_date) {
|
||||||
|
$html_time = str_replace('(' . $_date . ')', '(' . $this->l->__($_date) . ')', $html_time);
|
||||||
|
}
|
||||||
|
// return the datetime select string with strings translated
|
||||||
|
return $html_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
588
www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php
vendored
Normal file
588
www/vendor/egrajp/corelibs-composer-all/src/Admin/EditBase.php
vendored
Normal file
@@ -0,0 +1,588 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* AUTHOR: Clemens Schwaighofer
|
||||||
|
* CREATED: 2023/1/6
|
||||||
|
* DESCRIPTION:
|
||||||
|
* Original created: 2003/06/10
|
||||||
|
* This is the edit_base.php data as is moved into a class so we can
|
||||||
|
* more easy update this and also move to a different AJAX style more
|
||||||
|
* easy
|
||||||
|
*********************************************************************/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Admin;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use SmartyException;
|
||||||
|
|
||||||
|
class EditBase
|
||||||
|
{
|
||||||
|
/** @var array<mixed> */
|
||||||
|
private $HEADER = [];
|
||||||
|
/** @var array<mixed> */
|
||||||
|
private $DATA = [];
|
||||||
|
/** @var array<mixed> */
|
||||||
|
private $DEBUG_DATA = [];
|
||||||
|
|
||||||
|
/** @var string the template name */
|
||||||
|
private $EDIT_TEMPLATE = '';
|
||||||
|
|
||||||
|
/** @var \CoreLibs\Template\SmartyExtend smarty system */
|
||||||
|
private $smarty;
|
||||||
|
/** @var \CoreLibs\Output\Form\Generate form generate system */
|
||||||
|
private $form;
|
||||||
|
/** @var \CoreLibs\Debug\Logging */
|
||||||
|
public $log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* construct form generator
|
||||||
|
*
|
||||||
|
* @param array<mixed> $db_config db config array, mandatory
|
||||||
|
* @param \CoreLibs\Debug\Logging $log Logging class, null auto set
|
||||||
|
* @param \CoreLibs\Language\L10n $l10n l10n language class, null auto set
|
||||||
|
* @param array<string,string> $locale locale array from ::setLocale,
|
||||||
|
* null auto set
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
array $db_config,
|
||||||
|
\CoreLibs\Debug\Logging $log,
|
||||||
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
array $locale
|
||||||
|
) {
|
||||||
|
$this->log = $log;
|
||||||
|
// smarty template engine (extended Translation version)
|
||||||
|
$this->smarty = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
|
// turn off set log per class
|
||||||
|
$log->setLogPer('class', false);
|
||||||
|
|
||||||
|
// create form class
|
||||||
|
$this->form = new \CoreLibs\Output\Form\Generate(
|
||||||
|
$db_config,
|
||||||
|
$log,
|
||||||
|
$l10n,
|
||||||
|
$locale
|
||||||
|
);
|
||||||
|
if ($this->form->mobile_phone) {
|
||||||
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
// $this->form->log->debug('POST', $this->form->log->prAr($_POST));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* edit order page
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function editOrderPage(): void
|
||||||
|
{
|
||||||
|
// get is for "table_name" and "where" only
|
||||||
|
$table_name = $_GET['table_name'] ?? $_POST['table_name'] ?? '';
|
||||||
|
// not in use
|
||||||
|
// $where_string = $_GET['where'] ?? $_POST['where'] ?? '';
|
||||||
|
// order name is _always_ order_number for the edit interface
|
||||||
|
|
||||||
|
// follwing arrays do exist here:
|
||||||
|
// $position ... has the positions of the [0..max], cause in a <select>
|
||||||
|
// I can't put an number into the array field, in this array,
|
||||||
|
// there are the POSITION stored,
|
||||||
|
// that should CHANGE there order (up/down)
|
||||||
|
// $row_data_id ... has ALL ids from the sorting part
|
||||||
|
// $row_data_order ... has ALL order positions from the soirting part
|
||||||
|
$position = $_POST['position'] ?? [];
|
||||||
|
$row_data_id = $_POST['row_data_id'] ?? [];
|
||||||
|
$original_id = $row_data_id;
|
||||||
|
$row_data_order = $_POST['row_data_order'] ?? [];
|
||||||
|
// direction
|
||||||
|
$up = $_POST['up'] ?? '';
|
||||||
|
$down = $_POST['down'] ?? '';
|
||||||
|
if (count($position)) {
|
||||||
|
// FIRST u have to put right sort, then read again ...
|
||||||
|
// hast to be >0 or the first one is selected and then there is no move
|
||||||
|
if (!empty($up) && isset($position[0]) && $position[0] > 0) {
|
||||||
|
for ($i = 0; $i < count($position); $i++) {
|
||||||
|
// change position order
|
||||||
|
// this gets temp, id before that, gets actual (moves one "down")
|
||||||
|
// this gets the old before (moves one "up")
|
||||||
|
// is done for every element in row
|
||||||
|
// echo "A: ".$row_data_id[$position[$i]]
|
||||||
|
// ." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]
|
||||||
|
// ." (".$row_data_order[$position[$i]-1].")<br>";
|
||||||
|
$temp_id = $row_data_id[$position[$i]] ?? null;
|
||||||
|
$row_data_id[$position[$i]] = $row_data_id[(int)$position[$i] - 1] ?? null;
|
||||||
|
$row_data_id[(int)$position[$i] - 1] = $temp_id;
|
||||||
|
// echo "A: ".$row_data_id[$position[$i]]
|
||||||
|
// ." (".$row_data_order[$position[$i]].") -- "
|
||||||
|
// .$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")<br>";
|
||||||
|
} // for
|
||||||
|
} // if up
|
||||||
|
|
||||||
|
// the last position id from position array is not to be the count - 1 of
|
||||||
|
// row_data_id array, or it is the last element
|
||||||
|
if (!empty($down) && ($position[count($position) - 1] != (count($row_data_id) - 1))) {
|
||||||
|
for ($i = count($position) - 1; $i >= 0; $i--) {
|
||||||
|
// same as up, just up in other way, starts from bottom (last element) and moves "up"
|
||||||
|
// element before actuel gets temp, this element, becomes element after this,
|
||||||
|
// element after this, gets this
|
||||||
|
$temp_id = $row_data_id[(int)$position[$i] + 1] ?? null;
|
||||||
|
$row_data_id[(int)$position[$i] + 1] = $row_data_id[$position[$i]] ?? null;
|
||||||
|
$row_data_id[$position[$i]] = $temp_id;
|
||||||
|
} // for
|
||||||
|
} // if down
|
||||||
|
|
||||||
|
// write data ... (which has to be abstrackt ...)
|
||||||
|
if (
|
||||||
|
(!empty($up) && $position[0] > 0) ||
|
||||||
|
(!empty($down) && ($position[count($position) - 1] != (count($row_data_id) - 1)))
|
||||||
|
) {
|
||||||
|
for ($i = 0; $i < count($row_data_id); $i++) {
|
||||||
|
if (isset($row_data_order[$i]) && isset($row_data_id[$i])) {
|
||||||
|
$q = "UPDATE " . $table_name
|
||||||
|
. " SET order_number = " . $row_data_order[$i]
|
||||||
|
. " WHERE " . $table_name . "_id = " . $row_data_id[$i];
|
||||||
|
$q = $this->form->dbExec($q);
|
||||||
|
}
|
||||||
|
} // for all article ids ...
|
||||||
|
} // if write
|
||||||
|
} // if there is something to move
|
||||||
|
|
||||||
|
// get ...
|
||||||
|
$q = "SELECT " . $table_name . "_id, name, order_number FROM " . $table_name . " ";
|
||||||
|
// /* if (!empty($where_string)) {
|
||||||
|
// $q .= "WHERE $where_string ";
|
||||||
|
// } */
|
||||||
|
$q .= "ORDER BY order_number";
|
||||||
|
|
||||||
|
// init arrays
|
||||||
|
$row_data = [];
|
||||||
|
$options_id = [];
|
||||||
|
$options_name = [];
|
||||||
|
$options_selected = [];
|
||||||
|
// DB read data for menu
|
||||||
|
while (is_array($res = $this->form->dbReturn($q))) {
|
||||||
|
$row_data[] = [
|
||||||
|
"id" => $res[$table_name . "_id"],
|
||||||
|
"name" => $res["name"],
|
||||||
|
"order" => $res["order_number"]
|
||||||
|
];
|
||||||
|
} // while read data ...
|
||||||
|
|
||||||
|
// html title
|
||||||
|
$this->HEADER['HTML_TITLE'] = $this->form->l->__('Edit Order');
|
||||||
|
|
||||||
|
$messages = [];
|
||||||
|
$error = $_POST['error'] ?? 0;
|
||||||
|
// error msg
|
||||||
|
if (!empty($error)) {
|
||||||
|
$msg = $_POST['msg'] ?? [];
|
||||||
|
if (!is_array($msg)) {
|
||||||
|
$msg = [];
|
||||||
|
}
|
||||||
|
$messages[] = [
|
||||||
|
'msg' => $msg,
|
||||||
|
'class' => 'error',
|
||||||
|
'width' => '100%'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$this->DATA['form_error_msg'] = $messages;
|
||||||
|
|
||||||
|
// all the row data
|
||||||
|
for ($i = 0; $i < count($row_data); $i++) {
|
||||||
|
$options_id[] = $i;
|
||||||
|
$options_name[] = $row_data[$i]['name'];
|
||||||
|
// list of points to order
|
||||||
|
for ($j = 0; $j < count($position); $j++) {
|
||||||
|
// if matches, put into select array
|
||||||
|
if (
|
||||||
|
isset($original_id[$position[$j]]) && isset($row_data[$i]['id']) &&
|
||||||
|
$original_id[$position[$j]] == $row_data[$i]['id']
|
||||||
|
) {
|
||||||
|
$options_selected[] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->DATA['options_id'] = $options_id;
|
||||||
|
$this->DATA['options_name'] = $options_name;
|
||||||
|
$this->DATA['options_selected'] = $options_selected;
|
||||||
|
|
||||||
|
// hidden list for the data (id, order number)
|
||||||
|
$row_data_id = [];
|
||||||
|
$row_data_order = [];
|
||||||
|
for ($i = 0; $i < count($row_data); $i++) {
|
||||||
|
$row_data_id[] = $row_data[$i]['id'];
|
||||||
|
$row_data_order[] = $row_data[$i]['order'];
|
||||||
|
}
|
||||||
|
$this->DATA['row_data_id'] = $row_data_id;
|
||||||
|
$this->DATA['row_data_order'] = $row_data_order;
|
||||||
|
|
||||||
|
// hidden names for the table & where string
|
||||||
|
$this->DATA['table_name'] = $table_name;
|
||||||
|
$this->DATA['where_string'] = '';
|
||||||
|
// $this->DATA['where_string'] = $where_string ?? '';
|
||||||
|
|
||||||
|
$this->EDIT_TEMPLATE = 'edit_order.tpl';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* all edit pages
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function editPageFlow(): void
|
||||||
|
{
|
||||||
|
// set table width
|
||||||
|
$table_width = '100%';
|
||||||
|
// load call only if id is set
|
||||||
|
if (!empty($_POST[$this->form->archive_pk_name])) {
|
||||||
|
$this->form->formProcedureLoad($_POST[$this->form->archive_pk_name]);
|
||||||
|
}
|
||||||
|
$this->form->formProcedureNew();
|
||||||
|
$this->form->formProcedureSave();
|
||||||
|
$this->form->formProcedureDelete();
|
||||||
|
// delete call only if those two are set
|
||||||
|
// and we are not in new/save/master delete
|
||||||
|
if (
|
||||||
|
!$this->form->new &&
|
||||||
|
!$this->form->save &&
|
||||||
|
!$this->form->delete &&
|
||||||
|
!empty($_POST['element_list']) &&
|
||||||
|
!empty($_POST['remove_name'])
|
||||||
|
) {
|
||||||
|
$this->form->formProcedureDeleteFromElementList(
|
||||||
|
$_POST['element_list'],
|
||||||
|
$_POST['remove_name']
|
||||||
|
);
|
||||||
|
// run a load post element delete to not end up with empty page
|
||||||
|
$this->form->formLoadTableArray($_POST[$this->form->archive_pk_name]);
|
||||||
|
$this->form->yes = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->DATA['table_width'] = $table_width;
|
||||||
|
|
||||||
|
$messages = [];
|
||||||
|
// write out error / status messages
|
||||||
|
$messages[] = $this->form->formPrintMsg();
|
||||||
|
$this->DATA['form_error_msg'] = $messages;
|
||||||
|
|
||||||
|
// MENU START
|
||||||
|
// request some session vars
|
||||||
|
if (empty($_SESSION['HEADER_COLOR'])) {
|
||||||
|
$this->DATA['HEADER_COLOR'] = '#E0E2FF';
|
||||||
|
} else {
|
||||||
|
$this->DATA['HEADER_COLOR'] = $_SESSION['HEADER_COLOR'];
|
||||||
|
}
|
||||||
|
$this->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
|
||||||
|
$this->DATA['EUID'] = $_SESSION['EUID'];
|
||||||
|
$this->DATA['GROUP_NAME'] = $_SESSION['GROUP_NAME'];
|
||||||
|
$this->DATA['GROUP_LEVEL'] = $_SESSION['GROUP_ACL_LEVEL'];
|
||||||
|
$PAGES = $_SESSION['PAGES'];
|
||||||
|
|
||||||
|
//$this->form->log->debug('menu', $this->form->log->prAr($PAGES));
|
||||||
|
|
||||||
|
// build nav from $PAGES ...
|
||||||
|
if (!isset($PAGES) || !is_array($PAGES)) {
|
||||||
|
$PAGES = [];
|
||||||
|
}
|
||||||
|
$menuarray = [];
|
||||||
|
foreach ($PAGES as $PAGE_CUID => $PAGE_DATA) {
|
||||||
|
if ($PAGE_DATA['menu'] && $PAGE_DATA['online']) {
|
||||||
|
$menuarray[] = $PAGE_DATA;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// split point for nav points
|
||||||
|
$COUNT_NAV_POINTS = count($menuarray);
|
||||||
|
$SPLIT_FACTOR = 3;
|
||||||
|
$START_SPLIT_COUNT = 3;
|
||||||
|
// WTF ?? I dunno what I am doing here ...
|
||||||
|
for ($i = 9; $i < $COUNT_NAV_POINTS; $i += $START_SPLIT_COUNT) {
|
||||||
|
if ($COUNT_NAV_POINTS > $i) {
|
||||||
|
$SPLIT_FACTOR += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$position = 0;
|
||||||
|
$menu_data = [];
|
||||||
|
// for ($i = 1; $i <= count($menuarray); $i ++) {
|
||||||
|
foreach ($menuarray as $i => $menu_element) {
|
||||||
|
// do that for new array
|
||||||
|
$j = $i + 1;
|
||||||
|
$menu_data[$i]['pagename'] = htmlentities($menu_element['page_name']);
|
||||||
|
$menu_data[$i]['filename'] =
|
||||||
|
// prefix folder or host name
|
||||||
|
(isset($menu_element['hostname']) && $menu_element['hostname'] ?
|
||||||
|
$menu_element['hostname'] :
|
||||||
|
''
|
||||||
|
)
|
||||||
|
// filename
|
||||||
|
. ($menu_element['filename'] ?? '')
|
||||||
|
// query string
|
||||||
|
. (isset($menu_element['query_string']) && $menu_element['query_string'] ?
|
||||||
|
$menu_element['query_string'] :
|
||||||
|
''
|
||||||
|
);
|
||||||
|
if ($j == 1 || !($i % $SPLIT_FACTOR)) {
|
||||||
|
$menu_data[$i]['splitfactor_in'] = 1;
|
||||||
|
} else {
|
||||||
|
$menu_data[$i]['splitfactor_in'] = 0;
|
||||||
|
}
|
||||||
|
// on matching, we also need to check if we are in the same folder
|
||||||
|
if (
|
||||||
|
isset($menu_element['filename']) &&
|
||||||
|
$menu_element['filename'] == \CoreLibs\Get\System::getPageName() &&
|
||||||
|
(!isset($menu_element['hostname']) || (
|
||||||
|
isset($menu_element['hostname']) &&
|
||||||
|
(!$menu_element['hostname'] || strstr($menu_element['hostname'], CONTENT_PATH) !== false)
|
||||||
|
))
|
||||||
|
) {
|
||||||
|
$position = $i;
|
||||||
|
$menu_data[$i]['position'] = 1;
|
||||||
|
$menu_data[$i]['popup'] = 0;
|
||||||
|
} else {
|
||||||
|
// add query stuff
|
||||||
|
// HAS TO DONE LATER ... set urlencode, etc ...
|
||||||
|
// check if popup needed
|
||||||
|
if (isset($menu_element['popup']) && $menu_element['popup'] == 1) {
|
||||||
|
$menu_data[$i]['popup'] = 1;
|
||||||
|
$menu_data[$i]['rand'] = uniqid((string)rand());
|
||||||
|
$menu_data[$i]['width'] = $menu_element['popup_x'];
|
||||||
|
$menu_data[$i]['height'] = $menu_element['popup_y'];
|
||||||
|
} else {
|
||||||
|
$menu_data[$i]['popup'] = 0;
|
||||||
|
}
|
||||||
|
$menu_data[$i]['position'] = 0;
|
||||||
|
} // highlight or not
|
||||||
|
if (!($j % $SPLIT_FACTOR) || (($j + 1) > count($menuarray))) {
|
||||||
|
$menu_data[$i]['splitfactor_out'] = 1;
|
||||||
|
} else {
|
||||||
|
$menu_data[$i]['splitfactor_out'] = 0;
|
||||||
|
}
|
||||||
|
} // for
|
||||||
|
// $this->form->log->debug('MENU ARRAY', $this->form->log->prAr($menu_data));
|
||||||
|
$this->DATA['menu_data'] = $menu_data;
|
||||||
|
$this->DATA['page_name'] = $menuarray[$position]['page_name'] ?? '-Undefined [' . $position . '] -';
|
||||||
|
$L_TITLE = $this->DATA['page_name'];
|
||||||
|
// html title
|
||||||
|
$this->HEADER['HTML_TITLE'] = $this->form->l->__($L_TITLE);
|
||||||
|
// END MENU
|
||||||
|
// LOAD AND NEW
|
||||||
|
$this->DATA['load'] = $this->form->formCreateLoad();
|
||||||
|
$this->DATA['new'] = $this->form->formCreateNew();
|
||||||
|
// SHOW DATA PART
|
||||||
|
if ($this->form->yes) {
|
||||||
|
$this->DATA['form_yes'] = $this->form->yes;
|
||||||
|
$this->DATA['form_my_page_name'] = $this->form->my_page_name;
|
||||||
|
$this->DATA['filename_exist'] = 0;
|
||||||
|
$this->DATA['drop_down_input'] = 0;
|
||||||
|
$elements = [];
|
||||||
|
// depending on the "getPageName()" I show different stuff
|
||||||
|
switch ($this->form->my_page_name) {
|
||||||
|
case 'edit_users':
|
||||||
|
$elements[] = $this->form->formCreateElement('login_error_count');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_error_date_last');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_error_date_first');
|
||||||
|
$elements[] = $this->form->formCreateElement('enabled');
|
||||||
|
$elements[] = $this->form->formCreateElement('deleted');
|
||||||
|
$elements[] = $this->form->formCreateElement('protected');
|
||||||
|
$elements[] = $this->form->formCreateElement('username');
|
||||||
|
$elements[] = $this->form->formCreateElement('password');
|
||||||
|
$elements[] = $this->form->formCreateElement('password_change_interval');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_set_date');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_last_revalidate');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_locked');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_revalidate_after');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_valid_from');
|
||||||
|
$elements[] = $this->form->formCreateElement('login_user_id_valid_until');
|
||||||
|
$elements[] = $this->form->formCreateElement('email');
|
||||||
|
$elements[] = $this->form->formCreateElement('last_name');
|
||||||
|
$elements[] = $this->form->formCreateElement('first_name');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_group_id');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_access_right_id');
|
||||||
|
$elements[] = $this->form->formCreateElement('strict');
|
||||||
|
$elements[] = $this->form->formCreateElement('locked');
|
||||||
|
$elements[] = $this->form->formCreateElement('lock_until');
|
||||||
|
$elements[] = $this->form->formCreateElement('lock_after');
|
||||||
|
$elements[] = $this->form->formCreateElement('admin');
|
||||||
|
$elements[] = $this->form->formCreateElement('debug');
|
||||||
|
$elements[] = $this->form->formCreateElement('db_debug');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_language_id');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_scheme_id');
|
||||||
|
$elements[] = $this->form->formCreateElementListTable('edit_access_user');
|
||||||
|
$elements[] = $this->form->formCreateElement('additional_acl');
|
||||||
|
break;
|
||||||
|
case 'edit_schemes':
|
||||||
|
$elements[] = $this->form->formCreateElement('enabled');
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
$elements[] = $this->form->formCreateElement('header_color');
|
||||||
|
$elements[] = $this->form->formCreateElement('template');
|
||||||
|
break;
|
||||||
|
case 'edit_pages':
|
||||||
|
if (!isset($this->form->table_array['edit_page_id']['value'])) {
|
||||||
|
$q = "DELETE FROM temp_files";
|
||||||
|
$this->form->dbExec($q);
|
||||||
|
// gets all files in the current dir and dirs given ending with .php
|
||||||
|
$folders = ['../admin/', '../frontend/'];
|
||||||
|
$files = ['*.php'];
|
||||||
|
$search_glob = [];
|
||||||
|
foreach ($folders as $folder) {
|
||||||
|
// make sure this folder actually exists
|
||||||
|
if (is_dir(ROOT . $folder)) {
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$search_glob[] = $folder . $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$crap = exec('ls ' . join(' ', $search_glob), $output, $status);
|
||||||
|
// now get all that are NOT in de DB
|
||||||
|
$q = "INSERT INTO temp_files (folder, filename) VALUES ";
|
||||||
|
$t_q = '';
|
||||||
|
foreach ($output as $output_file) {
|
||||||
|
// split the ouput into folder and file
|
||||||
|
$pathinfo = pathinfo($output_file);
|
||||||
|
if (!empty($pathinfo['dirname'])) {
|
||||||
|
$pathinfo['dirname'] .= DIRECTORY_SEPARATOR;
|
||||||
|
} else {
|
||||||
|
$pathinfo['dirname'] = '';
|
||||||
|
}
|
||||||
|
if ($t_q) {
|
||||||
|
$t_q .= ', ';
|
||||||
|
}
|
||||||
|
$t_q .= "('" . $this->form->dbEscapeString($pathinfo['dirname']) . "', '"
|
||||||
|
. $this->form->dbEscapeString($pathinfo['basename']) . "')";
|
||||||
|
}
|
||||||
|
$this->form->dbExec($q . $t_q, 'NULL');
|
||||||
|
$elements[] = $this->form->formCreateElement('filename');
|
||||||
|
} else {
|
||||||
|
// show file menu
|
||||||
|
// just show name of file ...
|
||||||
|
$this->DATA['filename_exist'] = 1;
|
||||||
|
$this->DATA['filename'] = $this->form->table_array['filename']['value'];
|
||||||
|
} // File Name View IF
|
||||||
|
$elements[] = $this->form->formCreateElement('hostname');
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
// $elements[] = $this->form->formCreateElement('tag');
|
||||||
|
// $elements[] = $this->form->formCreateElement('min_acl');
|
||||||
|
$elements[] = $this->form->formCreateElement('order_number');
|
||||||
|
$elements[] = $this->form->formCreateElement('online');
|
||||||
|
$elements[] = $this->form->formCreateElement('menu');
|
||||||
|
$elements[] = $this->form->formCreateElementListTable('edit_query_string');
|
||||||
|
$elements[] = $this->form->formCreateElement('content_alias_edit_page_id');
|
||||||
|
$elements[] = $this->form->formCreateElementListTable('edit_page_content');
|
||||||
|
$elements[] = $this->form->formCreateElement('popup');
|
||||||
|
$elements[] = $this->form->formCreateElement('popup_x');
|
||||||
|
$elements[] = $this->form->formCreateElement('popup_y');
|
||||||
|
$elements[] = $this->form->formCreateElementReferenceTable('edit_visible_group');
|
||||||
|
$elements[] = $this->form->formCreateElementReferenceTable('edit_menu_group');
|
||||||
|
break;
|
||||||
|
case 'edit_languages':
|
||||||
|
$elements[] = $this->form->formCreateElement('enabled');
|
||||||
|
$elements[] = $this->form->formCreateElement('short_name');
|
||||||
|
$elements[] = $this->form->formCreateElement('long_name');
|
||||||
|
$elements[] = $this->form->formCreateElement('iso_name');
|
||||||
|
break;
|
||||||
|
case 'edit_groups':
|
||||||
|
$elements[] = $this->form->formCreateElement('enabled');
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_access_right_id');
|
||||||
|
$elements[] = $this->form->formCreateElement('edit_scheme_id');
|
||||||
|
$elements[] = $this->form->formCreateElementListTable('edit_page_access');
|
||||||
|
$elements[] = $this->form->formCreateElement('additional_acl');
|
||||||
|
break;
|
||||||
|
case 'edit_visible_group':
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
$elements[] = $this->form->formCreateElement('flag');
|
||||||
|
break;
|
||||||
|
case 'edit_menu_group':
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
$elements[] = $this->form->formCreateElement('flag');
|
||||||
|
$elements[] = $this->form->formCreateElement('order_number');
|
||||||
|
break;
|
||||||
|
case 'edit_access':
|
||||||
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
$elements[] = $this->form->formCreateElement('enabled');
|
||||||
|
$elements[] = $this->form->formCreateElement('protected');
|
||||||
|
$elements[] = $this->form->formCreateElement('color');
|
||||||
|
$elements[] = $this->form->formCreateElement('description');
|
||||||
|
// add name/value list here
|
||||||
|
$elements[] = $this->form->formCreateElementListTable('edit_access_data');
|
||||||
|
$elements[] = $this->form->formCreateElement('additional_acl');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print '[No valid page definition given]';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// $this->form->log->debug('edit', "Elements: <pre>".$this->form->log->prAr($elements));
|
||||||
|
$this->DATA['elements'] = $elements;
|
||||||
|
$this->DATA['hidden'] = $this->form->formCreateHiddenFields();
|
||||||
|
$this->DATA['save_delete'] = $this->form->formCreateSaveDelete();
|
||||||
|
} else {
|
||||||
|
$this->DATA['form_yes'] = 0;
|
||||||
|
}
|
||||||
|
$this->EDIT_TEMPLATE = 'edit_body.tpl';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* main method that either calls edit order page method or general page
|
||||||
|
* builds the smarty content and runs smarty display output
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws Exception
|
||||||
|
* @throws SmartyException
|
||||||
|
*/
|
||||||
|
public function editBaseRun()
|
||||||
|
{
|
||||||
|
// set the template dir
|
||||||
|
// WARNING: this has a special check for the mailing tool layout (old layout)
|
||||||
|
if (defined('LAYOUT')) {
|
||||||
|
$this->smarty->setTemplateDir(BASE . INCLUDES . TEMPLATES . CONTENT_PATH);
|
||||||
|
$this->DATA['css'] = LAYOUT . CSS;
|
||||||
|
$this->DATA['js'] = LAYOUT . JS;
|
||||||
|
} else {
|
||||||
|
$this->smarty->setTemplateDir(TEMPLATES);
|
||||||
|
$this->DATA['css'] = CSS;
|
||||||
|
$this->DATA['js'] = JS;
|
||||||
|
}
|
||||||
|
$ADMIN_STYLESHEET = 'edit.css';
|
||||||
|
// define all needed smarty stuff for the general HTML/page building
|
||||||
|
$this->HEADER['CSS'] = CSS;
|
||||||
|
$this->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||||
|
/** @phpstan-ignore-next-line because ADMIN_STYLESHEET can be null */
|
||||||
|
$this->HEADER['STYLESHEET'] = $ADMIN_STYLESHEET ?? ADMIN_STYLESHEET;
|
||||||
|
|
||||||
|
// main run
|
||||||
|
if ($this->form->my_page_name == 'edit_order') {
|
||||||
|
$this->editOrderPage();
|
||||||
|
} else {
|
||||||
|
$this->editPageFlow();
|
||||||
|
}
|
||||||
|
|
||||||
|
// debug data, if DEBUG flag is on, this data is print out
|
||||||
|
// $this->DEBUG_DATA['DEBUG'] = $DEBUG_TMPL ?? '';
|
||||||
|
$this->DEBUG_DATA['DEBUG'] = '';
|
||||||
|
|
||||||
|
// create main data array
|
||||||
|
$CONTENT_DATA = array_merge($this->HEADER, $this->DATA, $this->DEBUG_DATA);
|
||||||
|
// data is 1:1 mapping (all vars, values, etc)
|
||||||
|
foreach ($CONTENT_DATA as $key => $value) {
|
||||||
|
$this->smarty->assign($key, $value);
|
||||||
|
}
|
||||||
|
if (is_dir(BASE . TEMPLATES_C)) {
|
||||||
|
$this->smarty->setCompileDir(BASE . TEMPLATES_C);
|
||||||
|
}
|
||||||
|
if (is_dir(BASE . CACHE)) {
|
||||||
|
$this->smarty->setCacheDir(BASE . CACHE);
|
||||||
|
}
|
||||||
|
$this->smarty->display(
|
||||||
|
$this->EDIT_TEMPLATE,
|
||||||
|
'editAdmin_' . $this->smarty->lang,
|
||||||
|
'editAdmin_' . $this->smarty->lang
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->form->log->debug('DEBUGEND', '==================================== [Form END]');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
1549
www/vendor/egrajp/corelibs-composer-all/src/Basic.php
vendored
Normal file
1549
www/vendor/egrajp/corelibs-composer-all/src/Basic.php
vendored
Normal file
File diff suppressed because it is too large
Load Diff
187
www/vendor/egrajp/corelibs-composer-all/src/Check/Colors.php
vendored
Normal file
187
www/vendor/egrajp/corelibs-composer-all/src/Check/Colors.php
vendored
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* valid checks for css/html based colors
|
||||||
|
* # hex
|
||||||
|
* # hex + alpha
|
||||||
|
* rgb
|
||||||
|
* rgba
|
||||||
|
* hsl
|
||||||
|
* hsla
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class Colors
|
||||||
|
{
|
||||||
|
/** @var int 1 for HEX rgb */
|
||||||
|
public const HEX_RGB = 1;
|
||||||
|
/** @var int 2 for HEX rgb with alpha */
|
||||||
|
public const HEX_RGBA = 2;
|
||||||
|
/** @var int 4 for rgb() */
|
||||||
|
public const RGB = 4;
|
||||||
|
/** @var int 8 for rgba() */
|
||||||
|
public const RGBA = 8;
|
||||||
|
/** @var int 16 for hsl() */
|
||||||
|
public const HSL = 16;
|
||||||
|
/** @var int 32 for hsla() */
|
||||||
|
public const HSLA = 32;
|
||||||
|
/** @var int 63 for all bits set (sum of above) */
|
||||||
|
public const ALL = 63;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check rgb/hsl content values in detail
|
||||||
|
* will abort and return false on first error found
|
||||||
|
*
|
||||||
|
* @param string $color html/css tring to check
|
||||||
|
* @param int|false $rgb_flag flag to check for rgb
|
||||||
|
* @param int|false $hsl_flag flag to check for hsl type
|
||||||
|
* @return bool True if no error, False if error
|
||||||
|
*/
|
||||||
|
private static function rgbHslContentCheck(string $color, $rgb_flag, $hsl_flag): bool
|
||||||
|
{
|
||||||
|
// extract string between () and split into elements
|
||||||
|
preg_match("/\((.*)\)/", $color, $matches);
|
||||||
|
if (
|
||||||
|
!is_array($color_list = preg_split("/,\s*/", $matches[1] ?? ''))
|
||||||
|
) {
|
||||||
|
throw new \Exception("Could not extract color list from rgg/hsl", 3);
|
||||||
|
}
|
||||||
|
// based on rgb/hsl settings check that entries are valid
|
||||||
|
// rgb: either 0-255 OR 0-100%
|
||||||
|
// hsl: first: 0-360
|
||||||
|
foreach ($color_list as $pos => $color_check) {
|
||||||
|
if (empty($color_check)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$percent_check = false;
|
||||||
|
if (strrpos($color_check, '%', -1) !== false) {
|
||||||
|
$percent_check = true;
|
||||||
|
$color_check = str_replace('%', '', $color_check);
|
||||||
|
}
|
||||||
|
// first three normal percent or valid number
|
||||||
|
if ($rgb_flag !== false) {
|
||||||
|
if ($percent_check === true) {
|
||||||
|
// for ALL pos
|
||||||
|
if ($color_check < 0 || $color_check > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif (
|
||||||
|
$pos < 3 &&
|
||||||
|
($color_check < 0 || $color_check > 255)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
} elseif (
|
||||||
|
// RGBA set pos 3 if not percent
|
||||||
|
$pos == 3 &&
|
||||||
|
($color_check < 0 || $color_check > 1)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} elseif ($hsl_flag !== false) {
|
||||||
|
// pos 0: 0-360
|
||||||
|
// pos 1,2: %
|
||||||
|
// pos 3: % or 0-1 (float)
|
||||||
|
if (
|
||||||
|
$pos == 0 &&
|
||||||
|
($color_check < 0 || $color_check > 360)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
} elseif (
|
||||||
|
// if pos 1/2 are not percent
|
||||||
|
($pos == 1 || $pos == 2) &&
|
||||||
|
($percent_check != true ||
|
||||||
|
($color_check < 0 || $color_check > 100))
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
} elseif (
|
||||||
|
// 3 is either percent or 0~1
|
||||||
|
$pos == 3 &&
|
||||||
|
(
|
||||||
|
($percent_check == false &&
|
||||||
|
($color_check < 0 || $color_check > 1)) ||
|
||||||
|
($percent_check === true &&
|
||||||
|
($color_check < 0 || $color_check > 100))
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if html/css color string is valid
|
||||||
|
* @param string $color A color string of any format
|
||||||
|
* @param int $flags defaults to ALL, else use | to combined from
|
||||||
|
* HEX_RGB, HEX_RGBA, RGB, RGBA, HSL, HSLA
|
||||||
|
* @return bool True if valid, False if not
|
||||||
|
* @throws Exception 1: no valid flag set
|
||||||
|
*/
|
||||||
|
public static function validateColor(string $color, int $flags = self::ALL): bool
|
||||||
|
{
|
||||||
|
// blocks for each check
|
||||||
|
$regex_blocks = [];
|
||||||
|
// set what to check
|
||||||
|
if ($flags & self::HEX_RGB) {
|
||||||
|
$regex_blocks[] = '#[\dA-Fa-f]{6}';
|
||||||
|
}
|
||||||
|
if ($flags & self::HEX_RGBA) {
|
||||||
|
$regex_blocks[] = '#[\dA-Fa-f]{8}';
|
||||||
|
}
|
||||||
|
if ($flags & self::RGB) {
|
||||||
|
$regex_blocks[] = 'rgb\(\d{1,3}%?,\s*\d{1,3}%?,\s*\d{1,3}%?\)';
|
||||||
|
}
|
||||||
|
if ($flags & self::RGBA) {
|
||||||
|
$regex_blocks[] = 'rgba\(\d{1,3}%?,\s*\d{1,3}%?,\s*\d{1,3}%?(,\s*(0\.\d{1,2}|1(\.0)?|\d{1,3}%))?\)';
|
||||||
|
}
|
||||||
|
if ($flags & self::HSL) {
|
||||||
|
$regex_blocks[] = 'hsl\(\d{1,3},\s*\d{1,3}(\.\d{1})?%,\s*\d{1,3}(\.\d{1})?%\)';
|
||||||
|
}
|
||||||
|
if ($flags & self::HSLA) {
|
||||||
|
$regex_blocks[] = 'hsla\(\d{1,3},\s*\d{1,3}(\.\d{1})?%,\s*\d{1,3}'
|
||||||
|
. '(\.\d{1})?%(,\s*(0\.\d{1,2}|1(\.0)?|\d{1,3}%))?\)';
|
||||||
|
}
|
||||||
|
// wrong flag set
|
||||||
|
if ($flags > self::ALL) {
|
||||||
|
throw new \Exception("Invalid flags parameter: $flags", 1);
|
||||||
|
}
|
||||||
|
if (!count($regex_blocks)) {
|
||||||
|
throw new \Exception("No regex blocks set: $flags", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// build regex
|
||||||
|
$regex = '^('
|
||||||
|
. join('|', $regex_blocks)
|
||||||
|
// close regex
|
||||||
|
. ')$';
|
||||||
|
// print "C: $color, F: $flags, R: $regex\n";
|
||||||
|
|
||||||
|
if (preg_match("/$regex/", $color)) {
|
||||||
|
// if valid regex, we now need to check if the content is actually valid
|
||||||
|
// only for rgb/hsl type
|
||||||
|
/** @var int|false */
|
||||||
|
$rgb_flag = strpos($color, 'rgb');
|
||||||
|
/** @var int|false */
|
||||||
|
$hsl_flag = strpos($color, 'hsl');
|
||||||
|
// if both not match, return true
|
||||||
|
if (
|
||||||
|
$rgb_flag === false &&
|
||||||
|
$hsl_flag === false
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// run detaul rgb/hsl content check
|
||||||
|
return self::rgbHslContentCheck($color, $rgb_flag, $hsl_flag);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
265
www/vendor/egrajp/corelibs-composer-all/src/Check/Email.php
vendored
Normal file
265
www/vendor/egrajp/corelibs-composer-all/src/Check/Email.php
vendored
Normal file
@@ -0,0 +1,265 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class Email
|
||||||
|
{
|
||||||
|
// this is for error check parts in where the email regex failed
|
||||||
|
/** @var array<int,string> */
|
||||||
|
private static $email_regex_check = [
|
||||||
|
0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||||
|
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
|
||||||
|
1 => "@(.*)@(.*)", // double @
|
||||||
|
2 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
|
||||||
|
3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
|
||||||
|
4 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.", // wrong domain name part
|
||||||
|
5 => "\.([a-zA-Z]{2,6}){1}$", // wrong top level part
|
||||||
|
6 => "@(.*)\.{2,}", // double .. in domain name part
|
||||||
|
7 => "@.*\.$" // ends with a dot, top level, domain missing
|
||||||
|
];
|
||||||
|
// for above position, description string below
|
||||||
|
/** @var array<int,string> */
|
||||||
|
private static $email_regex_check_message = [
|
||||||
|
0 => 'Invalid email address',
|
||||||
|
1 => 'Double @ mark in email address',
|
||||||
|
2 => 'Invalid email part before @ sign',
|
||||||
|
3 => 'Invalid domain part after @ sign',
|
||||||
|
4 => 'Invalid domain name part',
|
||||||
|
5 => 'Wrong domain top level part',
|
||||||
|
6 => 'Double consecutive dots in domain name (..)',
|
||||||
|
7 => 'Domain ends with a dot or is missing top level part'
|
||||||
|
];
|
||||||
|
// the array with the mobile types that are valid
|
||||||
|
/** @var array<string,string> */
|
||||||
|
private static $mobile_email_type = [
|
||||||
|
'.*@docomo\.ne\.jp$' => 'keitai_docomo',
|
||||||
|
// correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
|
||||||
|
'.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb',
|
||||||
|
// ez[a-j] or nothing
|
||||||
|
'.*@(ez[a-j]{1}\.)?ido\.ne\.jp$' => 'keitai_kddi_ido',
|
||||||
|
// (sky group)
|
||||||
|
'.*@([a-z]{2}\.)?sky\.tu-ka\.ne\.jp$' => 'keitai_kddi_tu-ka',
|
||||||
|
// (sky group) [tkk,tkc only]
|
||||||
|
'.*@([a-z]{2}\.)?sky\.tk[kc]{1}\.ne\.jp$' => 'keitai_kddi_sky',
|
||||||
|
// dtg (sky group)
|
||||||
|
'.*@([a-z]{2}\.)?sky\.dtg\.ne\.jp$' => 'keitai_kddi_dtg',
|
||||||
|
// old vodafone [t,k,d,h,c,r,n,s,q]
|
||||||
|
'.*@[tkdhcrnsq]{1}\.vodafone\.ne\.jp$' => 'keitai_softbank_vodafone',
|
||||||
|
// very old j-phone (pre vodafone) [d,h,t,k,r,s,n,q,c]
|
||||||
|
'.*@jp-[dhtkrsnqc]{1}\.ne\.jp$' => 'keitai_softbank_j-phone',
|
||||||
|
// add i for iphone also as keitai, others similar to the vodafone group
|
||||||
|
'.*@([dhtcrknsq]{1}\.)?softbank\.ne\.jp$' => 'keitai_softbank',
|
||||||
|
// add iPhone also as keitai and not as pc
|
||||||
|
'.*@i{1}\.softbank(\.ne)?\.jp$' => 'smartphone_softbank_iphone',
|
||||||
|
'.*@disney\.ne\.jp$' => 'keitai_softbank_disney', // (kids)
|
||||||
|
'.*@willcom\.ne\.jp$' => 'keitai_willcom',
|
||||||
|
'.*@willcom\.com$' => 'keitai_willcom', // new for pdx.ne.jp address
|
||||||
|
'.*@wcm\.ne\.jp$' => 'keitai_willcom', // old willcom wcm.ne.jp
|
||||||
|
'.*@pdx\.ne\.jp$' => 'keitai_willcom_pdx', // old pdx address for willcom
|
||||||
|
'.*@bandai\.jp$' => 'keitai_willcom_bandai', // willcom paipo! (kids)
|
||||||
|
'.*@pipopa\.ne\.jp$' => 'keitai_willcom_pipopa', // willcom paipo! (kids)
|
||||||
|
// actually only di,dj,dk,wm -> all others are "wrong", but none also allowed?
|
||||||
|
'.*@([a-z0-9]{2,4}\.)?pdx\.ne\.jp$' => 'keitai_willcom_pdx',
|
||||||
|
// ymobile, ymobile1 techincally not willcom, but I group them there (softbank sub)
|
||||||
|
'.*@ymobile([1]{1})?\.ne\.jp$' => 'keitai_willcom_ymobile',
|
||||||
|
// y-mobile techincally not willcom, but I group them there (softbank sub)
|
||||||
|
'.*@y-mobile\.ne\.jp$' => 'keitai_willcom_ymobile',
|
||||||
|
'.*@emnet\.ne\.jp$' => 'keitai_willcom_emnet', // e-mobile, group will willcom
|
||||||
|
'.*@emobile\.ne\.jp$' => 'keitai_willcom_emnet', // e-mobile, group will willcom
|
||||||
|
'.*@emobile-s\.ne\.jp$' => 'keitai_willcom_emnet' # e-mobile, group will willcom
|
||||||
|
];
|
||||||
|
// short list for mobile email types
|
||||||
|
/** @var array<string,string> */
|
||||||
|
private static $mobile_email_type_short = [
|
||||||
|
'keitai_docomo' => 'docomo',
|
||||||
|
'keitai_kddi_ezweb' => 'kddi',
|
||||||
|
'keitai_kddi' => 'kddi',
|
||||||
|
'keitai_kddi_tu-ka' => 'kddi',
|
||||||
|
'keitai_kddi_sky' => 'kddi',
|
||||||
|
'keitai_softbank' => 'softbank',
|
||||||
|
'smartphone_softbank_iphone' => 'iphone',
|
||||||
|
'keitai_softbank_disney' => 'softbank',
|
||||||
|
'keitai_softbank_vodafone' => 'softbank',
|
||||||
|
'keitai_softbank_j-phone' => 'softbank',
|
||||||
|
'keitai_willcom' => 'willcom',
|
||||||
|
'keitai_willcom_pdx' => 'willcom',
|
||||||
|
'keitai_willcom_bandai' => 'willcom',
|
||||||
|
'keitai_willcom_pipopa' => 'willcom',
|
||||||
|
'keitai_willcom_ymobile' => 'willcom',
|
||||||
|
'keitai_willcom_emnet' => 'willcom',
|
||||||
|
'pc_html' => 'pc',
|
||||||
|
// old sets -> to be removed later
|
||||||
|
'docomo' => 'docomo',
|
||||||
|
'kddi_ezweb' => 'kddi',
|
||||||
|
'kddi' => 'kddi',
|
||||||
|
'kddi_tu-ka' => 'kddi',
|
||||||
|
'kddi_sky' => 'kddi',
|
||||||
|
'softbank' => 'softbank',
|
||||||
|
'keitai_softbank_iphone' => 'iphone',
|
||||||
|
'softbank_iphone' => 'iphone',
|
||||||
|
'softbank_disney' => 'softbank',
|
||||||
|
'softbank_vodafone' => 'softbank',
|
||||||
|
'softbank_j-phone' => 'softbank',
|
||||||
|
'willcom' => 'willcom',
|
||||||
|
'willcom_pdx' => 'willcom',
|
||||||
|
'willcom_bandai' => 'willcom',
|
||||||
|
'willcom_pipopa' => 'willcom',
|
||||||
|
'willcom_ymobile' => 'willcom',
|
||||||
|
'willcom_emnet' => 'willcom',
|
||||||
|
'pc' => 'pc'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get one position from the regex check list
|
||||||
|
*
|
||||||
|
* @param int $type Which position in the regex list to get
|
||||||
|
* if not set or not valid get default pos 0
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function getEmailRegex(int $type = 0): string
|
||||||
|
{
|
||||||
|
// make sure type is in valid range
|
||||||
|
if ($type < 0 || $type >= count(self::$email_regex_check)) {
|
||||||
|
$type = 0;
|
||||||
|
}
|
||||||
|
return self::$email_regex_check[$type];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the full check array, except position 0, but preserve keys
|
||||||
|
* Currently used to add per error level type from
|
||||||
|
* getEmailRegex to error reporting
|
||||||
|
* Might be deprecated at some point
|
||||||
|
*
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public static function getEmailRegexCheck(): array
|
||||||
|
{
|
||||||
|
// return all but the first
|
||||||
|
return array_slice(
|
||||||
|
self::$email_regex_check,
|
||||||
|
1,
|
||||||
|
count(self::$email_regex_check) - 1,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns error message for email ergex error, or empty string if not set
|
||||||
|
*
|
||||||
|
* @param int $error
|
||||||
|
* @return array<string,string|int> Error message and regex
|
||||||
|
*/
|
||||||
|
public static function getEmailRegexErrorMessage(int $error): array
|
||||||
|
{
|
||||||
|
// return error message and regex
|
||||||
|
return [
|
||||||
|
'error' => $error,
|
||||||
|
'message' => self::$email_regex_check_message[$error] ?? '',
|
||||||
|
'regex' => self::$email_regex_check[$error] ?? '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* guesses the email type (mostly for mobile) from the domain
|
||||||
|
* if second is set to true, it will return short naming scheme (only provider)
|
||||||
|
*
|
||||||
|
* @param string $email email string
|
||||||
|
* @param bool $short default false, if true,
|
||||||
|
* returns only short type (pc instead of pc_html)
|
||||||
|
* @return string|bool email type, eg "pc", "docomo", etc,
|
||||||
|
* false for invalid short type
|
||||||
|
*/
|
||||||
|
public static function getEmailType(string $email, bool $short = false)
|
||||||
|
{
|
||||||
|
// trip if there is no email address
|
||||||
|
if (!$email) {
|
||||||
|
return 'invalid';
|
||||||
|
}
|
||||||
|
// loop until we match a mobile type, return this first found type
|
||||||
|
foreach (self::$mobile_email_type as $email_regex => $email_type) {
|
||||||
|
if (preg_match("/$email_regex/", $email)) {
|
||||||
|
if ($short) {
|
||||||
|
return self::getShortEmailType($email_type);
|
||||||
|
} else {
|
||||||
|
return $email_type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if no previous return we assume this is a pc address
|
||||||
|
if ($short) {
|
||||||
|
return 'pc';
|
||||||
|
} else {
|
||||||
|
return 'pc_html';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the short email type from a long email type
|
||||||
|
*
|
||||||
|
* @param string $email_type email string
|
||||||
|
* @return string|bool short string or false for invalid
|
||||||
|
*/
|
||||||
|
public static function getShortEmailType(string $email_type)
|
||||||
|
{
|
||||||
|
// check if the short email type exists
|
||||||
|
if (isset(self::$mobile_email_type_short[$email_type])) {
|
||||||
|
return self::$mobile_email_type_short[$email_type];
|
||||||
|
} else {
|
||||||
|
// return false on not found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* simple email check with the basic email eregex
|
||||||
|
*
|
||||||
|
* @param string $email Email address, will be checkd as lower
|
||||||
|
* @return bool True if email is ok, or false if regex failed
|
||||||
|
*/
|
||||||
|
public static function checkEmail(string $email): bool
|
||||||
|
{
|
||||||
|
$email_regex = self::getEmailRegex();
|
||||||
|
if (!preg_match("/$email_regex/", strtolower($email))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check email with all regex checks possible and return errors as array
|
||||||
|
*
|
||||||
|
* @param string $email Email address, will be checkd as lower
|
||||||
|
* @param bool $error_code_only If this is set to true it will only return
|
||||||
|
* the error pos, instead of detailed array
|
||||||
|
* @return array<mixed> Errors as array with message and regex
|
||||||
|
*/
|
||||||
|
public static function checkEmailFull(string $email, bool $error_code_only = false): array
|
||||||
|
{
|
||||||
|
$errors = [];
|
||||||
|
foreach (self::$email_regex_check as $pos => $email_regex) {
|
||||||
|
$match = preg_match("/$email_regex/", strtolower($email));
|
||||||
|
// if the first does not fail, quit as ok
|
||||||
|
if ($pos == 0 && $match) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// else do error storage
|
||||||
|
// not that for 1, 6, 7 the regex is matching
|
||||||
|
if (
|
||||||
|
(!$match && in_array($pos, [0, 2, 3, 4, 5])) ||
|
||||||
|
($match && in_array($pos, [1, 6, 7]))
|
||||||
|
) {
|
||||||
|
if ($error_code_only === true) {
|
||||||
|
$errors[] = $pos;
|
||||||
|
} else {
|
||||||
|
$errors[] = self::getEmailRegexErrorMessage($pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $errors;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
117
www/vendor/egrajp/corelibs-composer-all/src/Check/Encoding.php
vendored
Normal file
117
www/vendor/egrajp/corelibs-composer-all/src/Check/Encoding.php
vendored
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if string is valid in target encoding
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class Encoding
|
||||||
|
{
|
||||||
|
/** @var int<min, -1>|int<1, max>|string */
|
||||||
|
private static $mb_error_char = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set error char
|
||||||
|
*
|
||||||
|
* @param string|int|null $string The character to use to represent
|
||||||
|
* error chars
|
||||||
|
* "long" for long, "none" for none
|
||||||
|
* or a valid code point in int
|
||||||
|
* like 0x2234 (8756, ∴)
|
||||||
|
* default character is ? (63)
|
||||||
|
* if null is set then "none"
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setErrorChar($string): void
|
||||||
|
{
|
||||||
|
if (empty($string)) {
|
||||||
|
$string = 'none';
|
||||||
|
}
|
||||||
|
// if not special string or char but code point
|
||||||
|
if (in_array($string, ['none', 'long', 'entity'])) {
|
||||||
|
self::$mb_error_char = $string;
|
||||||
|
} else {
|
||||||
|
// always convert to char for internal use
|
||||||
|
self::$mb_error_char = \IntlChar::chr($string);
|
||||||
|
// if string convert to code point
|
||||||
|
if (is_string($string)) {
|
||||||
|
$string = \IntlChar::ord($string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mb_substitute_character($string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the current set error character
|
||||||
|
*
|
||||||
|
* @param bool $return_substitute_func if set to true return the set
|
||||||
|
* character from the php function
|
||||||
|
* directly
|
||||||
|
* @return string|int Set error character
|
||||||
|
*/
|
||||||
|
public static function getErrorChar(bool $return_substitute_func = false)
|
||||||
|
{
|
||||||
|
// return mb_substitute_character();
|
||||||
|
if ($return_substitute_func === true) {
|
||||||
|
return mb_substitute_character();
|
||||||
|
} else {
|
||||||
|
return self::$mb_error_char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a string can be safely convert between encodings.
|
||||||
|
* mostly utf8 to shift jis
|
||||||
|
* the default compare has a possibility of failure, especially with windows
|
||||||
|
* it is recommended to the following in the script which uses this method:
|
||||||
|
* mb_substitute_character(0x2234);
|
||||||
|
* $class->mb_error_char = '∴';
|
||||||
|
* if check to Shift JIS
|
||||||
|
* if check to ISO-2022-JP
|
||||||
|
* if check to ISO-2022-JP-MS
|
||||||
|
* set three dots (∴) as wrong character for correct convert error detect
|
||||||
|
* (this char is used, because it is one of the least used ones)
|
||||||
|
*
|
||||||
|
* @param string $string string to test
|
||||||
|
* @param string $from_encoding encoding of string to test
|
||||||
|
* @param string $to_encoding target encoding
|
||||||
|
* @return bool|array<string> false if no error or
|
||||||
|
* array with failed characters
|
||||||
|
*/
|
||||||
|
public static function checkConvertEncoding(
|
||||||
|
string $string,
|
||||||
|
string $from_encoding,
|
||||||
|
string $to_encoding
|
||||||
|
) {
|
||||||
|
// convert to target encoding and convert back
|
||||||
|
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||||
|
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||||
|
// if string does not match anymore we have a convert problem
|
||||||
|
if ($string != $compare) {
|
||||||
|
$failed = [];
|
||||||
|
// go through each character and find the ones that do not match
|
||||||
|
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
|
||||||
|
$char = mb_substr($string, $i, 1, $from_encoding);
|
||||||
|
$r_char = mb_substr($compare, $i, 1, $from_encoding);
|
||||||
|
// the ord 194 is a hack to fix the IE7/IE8
|
||||||
|
// bug with line break and illegal character
|
||||||
|
if (
|
||||||
|
(($char != $r_char && (!self::$mb_error_char ||
|
||||||
|
in_array(self::$mb_error_char, ['none', 'long', 'entity']))) ||
|
||||||
|
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
|
||||||
|
ord($char) != 194
|
||||||
|
) {
|
||||||
|
$failed[] = $char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $failed;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
56
www/vendor/egrajp/corelibs-composer-all/src/Check/File.php
vendored
Normal file
56
www/vendor/egrajp/corelibs-composer-all/src/Check/File.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* various file/file name functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class File
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* quick return the extension of the given file name
|
||||||
|
*
|
||||||
|
* @param string $filename file name
|
||||||
|
* @return string extension of the file name
|
||||||
|
*/
|
||||||
|
public static function getFilenameEnding(string $filename): string
|
||||||
|
{
|
||||||
|
$page_temp = pathinfo($filename);
|
||||||
|
return $page_temp['extension'] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get lines in a file
|
||||||
|
*
|
||||||
|
* @param string $file file for line count read
|
||||||
|
* @return int number of lines or -1 for non readable file
|
||||||
|
*/
|
||||||
|
public static function getLinesFromFile(string $file): int
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
is_file($file) &&
|
||||||
|
file_exists($file) &&
|
||||||
|
is_readable($file)
|
||||||
|
) {
|
||||||
|
$f = fopen($file, 'rb');
|
||||||
|
if (!is_resource($f)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$lines = 0;
|
||||||
|
while (!feof($f)) {
|
||||||
|
$lines += substr_count(fread($f, 8192) ?: '', "\n");
|
||||||
|
}
|
||||||
|
fclose($f);
|
||||||
|
} else {
|
||||||
|
// if file does not exist or is not readable, return -1
|
||||||
|
$lines = -1;
|
||||||
|
}
|
||||||
|
// return lines in file
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
41
www/vendor/egrajp/corelibs-composer-all/src/Check/Jason.php
vendored
Normal file
41
www/vendor/egrajp/corelibs-composer-all/src/Check/Jason.php
vendored
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DEPRECATED: Use correct Convert\Json:: instead
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
use CoreLibs\Convert\Json;
|
||||||
|
|
||||||
|
class Jason
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string|null $json a json string, or null data
|
||||||
|
* @param bool $override if set to true, then on json error
|
||||||
|
* set original value as array
|
||||||
|
* @return array<mixed> returns an array from the json values
|
||||||
|
* @deprecated Use Json::jsonConvertToArray()
|
||||||
|
*/
|
||||||
|
public static function jsonConvertToArray(?string $json, bool $override = false): array
|
||||||
|
{
|
||||||
|
return Json::jsonConvertToArray($json, $override);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool|boolean $return_string [default=false] if set to true
|
||||||
|
* it will return the message string and not
|
||||||
|
* the error number
|
||||||
|
* @return int|string Either error number (0 for no error)
|
||||||
|
* or error string ('' for no error)
|
||||||
|
* @deprecated Use Json::jsonGetLastError()
|
||||||
|
*/
|
||||||
|
public static function jsonGetLastError(bool $return_string = false)
|
||||||
|
{
|
||||||
|
return Json::jsonGetLastError($return_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
59
www/vendor/egrajp/corelibs-composer-all/src/Check/Password.php
vendored
Normal file
59
www/vendor/egrajp/corelibs-composer-all/src/Check/Password.php
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* core password set, check and rehash check wrapper functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class Password
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* creates the password hash
|
||||||
|
*
|
||||||
|
* @param string $password password
|
||||||
|
* @return string hashed password
|
||||||
|
*/
|
||||||
|
public static function passwordSet(string $password): string
|
||||||
|
{
|
||||||
|
// always use the PHP default for the password
|
||||||
|
// password options ca be set in the password init,
|
||||||
|
// but should be kept as default
|
||||||
|
return password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if the entered password matches the hash
|
||||||
|
*
|
||||||
|
* @param string $password password
|
||||||
|
* @param string $hash password hash
|
||||||
|
* @return bool true or false
|
||||||
|
*/
|
||||||
|
public static function passwordVerify(string $password, string $hash): bool
|
||||||
|
{
|
||||||
|
if (password_verify($password, $hash)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* checks if the password needs to be rehashed
|
||||||
|
*
|
||||||
|
* @param string $hash password hash
|
||||||
|
* @return bool true or false
|
||||||
|
*/
|
||||||
|
public static function passwordRehashCheck(string $hash): bool
|
||||||
|
{
|
||||||
|
if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
75
www/vendor/egrajp/corelibs-composer-all/src/Check/PhpVersion.php
vendored
Normal file
75
www/vendor/egrajp/corelibs-composer-all/src/Check/PhpVersion.php
vendored
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class PhpVersion
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* checks if running PHP version matches given PHP version (min or max)
|
||||||
|
* if either is empty or null it will be ignored
|
||||||
|
* if no min version (null or empty)
|
||||||
|
*
|
||||||
|
* @param string|null $min_version minimum version as string (x, x.y, x.y.x)
|
||||||
|
* @param string|null $max_version optional maximum version as string (x, x.y, x.y.x)
|
||||||
|
* @return bool true if ok, false if not matching version
|
||||||
|
*/
|
||||||
|
public static function checkPHPVersion(?string $min_version, ?string $max_version = null): bool
|
||||||
|
{
|
||||||
|
// exit with false if the min/max strings are wrong
|
||||||
|
if (
|
||||||
|
!empty($min_version) &&
|
||||||
|
!preg_match("/^\d{1,2}(\.\d{1,2})?(\.\d{1,2})?$/", $min_version)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// max is only chcked if it is set
|
||||||
|
if (
|
||||||
|
!empty($max_version) &&
|
||||||
|
!preg_match("/^\d{1,2}(\.\d{1,2})?(\.\d{1,2})?$/", $max_version)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// split up the version strings to calc the compare number
|
||||||
|
if (!empty($min_version)) {
|
||||||
|
$version = explode('.', $min_version);
|
||||||
|
$min_version = (int)$version[0] * 10000 + (int)($version[1] ?? 0) * 100 + (int)($version[2] ?? 0);
|
||||||
|
}
|
||||||
|
if (!empty($max_version)) {
|
||||||
|
$version = explode('.', $max_version);
|
||||||
|
$max_version = (int)$version[0] * 10000 + (int)($version[1] ?? 0) * 100 + (int)($version[2] ?? 0);
|
||||||
|
// drop out if min is bigger max, equal size is okay, that would be only THIS
|
||||||
|
if (!empty($min_version) && $min_version > $max_version) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// set the php version id
|
||||||
|
if (!defined('PHP_VERSION_ID')) {
|
||||||
|
$version = explode('.', phpversion() ?: '');
|
||||||
|
// creates something like 50107
|
||||||
|
define('PHP_VERSION_ID', (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2]);
|
||||||
|
}
|
||||||
|
// check if matching for version
|
||||||
|
if (
|
||||||
|
!empty($min_version) && empty($max_version) &&
|
||||||
|
PHP_VERSION_ID >= $min_version
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} elseif (
|
||||||
|
empty($min_version) && !empty($max_version) &&
|
||||||
|
PHP_VERSION_ID <= $max_version
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} elseif (
|
||||||
|
!empty($min_version) && !empty($max_version) &&
|
||||||
|
PHP_VERSION_ID >= $min_version && PHP_VERSION_ID <= $max_version
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// if no previous return, fail
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
412
www/vendor/egrajp/corelibs-composer-all/src/Combined/ArrayHandler.php
vendored
Normal file
412
www/vendor/egrajp/corelibs-composer-all/src/Combined/ArrayHandler.php
vendored
Normal file
@@ -0,0 +1,412 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* array search and transform functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Combined;
|
||||||
|
|
||||||
|
class ArrayHandler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* searches key = value in an array / array
|
||||||
|
* only returns the first one found
|
||||||
|
*
|
||||||
|
* @param string|int $needle needle (search for)
|
||||||
|
* @param array<mixed> $haystack haystack (search in)
|
||||||
|
* @param string|null $key_search_for the key to look out for, default empty
|
||||||
|
* @return array<mixed> array with the elements where
|
||||||
|
* the needle can be found in the
|
||||||
|
* haystack array
|
||||||
|
*/
|
||||||
|
public static function arraySearchRecursive($needle, array $haystack, ?string $key_search_for = null): array
|
||||||
|
{
|
||||||
|
$path = [];
|
||||||
|
if (!is_array($haystack)) {
|
||||||
|
$haystack = [];
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$key_search_for != null &&
|
||||||
|
array_key_exists($key_search_for, $haystack) &&
|
||||||
|
$needle === $haystack[$key_search_for]
|
||||||
|
) {
|
||||||
|
$path[] = $key_search_for;
|
||||||
|
} else {
|
||||||
|
foreach ($haystack as $key => $val) {
|
||||||
|
if (
|
||||||
|
is_scalar($val) &&
|
||||||
|
$val === $needle &&
|
||||||
|
empty($key_search_for)
|
||||||
|
) {
|
||||||
|
$path[] = $key;
|
||||||
|
break;
|
||||||
|
} elseif (
|
||||||
|
is_scalar($val) &&
|
||||||
|
!empty($key_search_for) &&
|
||||||
|
$key === $key_search_for &&
|
||||||
|
$val === $needle
|
||||||
|
) {
|
||||||
|
$path[] = $key;
|
||||||
|
break;
|
||||||
|
} elseif (
|
||||||
|
is_array($val) &&
|
||||||
|
$path = self::arraySearchRecursive(
|
||||||
|
$needle,
|
||||||
|
(array)$val,
|
||||||
|
// to avoid PhanTypeMismatchArgumentNullable
|
||||||
|
($key_search_for === null ? $key_search_for : (string)$key_search_for)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
array_unshift($path, $key);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* recursive array search function, which returns all found not only the first one
|
||||||
|
*
|
||||||
|
* @param string|int $needle needle (search for)
|
||||||
|
* @param array<mixed> $haystack haystack (search in)
|
||||||
|
* @param string|int $key_search_for the key to look for in
|
||||||
|
* @param bool $old [true], if set to false will
|
||||||
|
* return new flat layout
|
||||||
|
* @param array<mixed>|null $path recursive call for previous path
|
||||||
|
* @return array<mixed>|null all array elements paths where
|
||||||
|
* the element was found
|
||||||
|
*/
|
||||||
|
public static function arraySearchRecursiveAll(
|
||||||
|
$needle,
|
||||||
|
array $haystack,
|
||||||
|
$key_search_for,
|
||||||
|
bool $old = true,
|
||||||
|
?array $path = null
|
||||||
|
): ?array {
|
||||||
|
// init if not set on null
|
||||||
|
if ($path === null) {
|
||||||
|
$path = [
|
||||||
|
'level' => 0,
|
||||||
|
'work' => []
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
// init sub sets if not set
|
||||||
|
if (!isset($path['level'])) {
|
||||||
|
$path['level'] = 0;
|
||||||
|
}
|
||||||
|
if (!isset($path['work'])) {
|
||||||
|
$path['work'] = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// should not be needed because it would trigger a php mehtod error
|
||||||
|
if (!is_array($haystack)) {
|
||||||
|
$haystack = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// go through the array,
|
||||||
|
foreach ($haystack as $_key => $_value) {
|
||||||
|
if (
|
||||||
|
is_scalar($_value) &&
|
||||||
|
$_value === $needle &&
|
||||||
|
empty($key_search_for)
|
||||||
|
) {
|
||||||
|
// only value matches
|
||||||
|
$path['work'][$path['level'] ?? 0] = $_key;
|
||||||
|
$path['found'][] = $path['work'];
|
||||||
|
} elseif (
|
||||||
|
is_scalar($_value) &&
|
||||||
|
!empty($key_search_for) &&
|
||||||
|
$_key === $key_search_for &&
|
||||||
|
$_value === $needle
|
||||||
|
) {
|
||||||
|
// key and value matches
|
||||||
|
$path['work'][$path['level'] ?? 0] = $_key;
|
||||||
|
$path['found'][] = $path['work'];
|
||||||
|
} elseif (is_array($_value)) {
|
||||||
|
// add position to working
|
||||||
|
$path['work'][$path['level'] ?? 0] = $_key;
|
||||||
|
// we will up a level
|
||||||
|
$path['level'] += 1;
|
||||||
|
// call recursive
|
||||||
|
$path = self::arraySearchRecursiveAll($needle, $_value, $key_search_for, $old, $path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// be 100% sure the array elements are set
|
||||||
|
$path['level'] = $path['level'] ?? 0;
|
||||||
|
$path['work'] = $path['work'] ?? [];
|
||||||
|
// cut all that is >= level
|
||||||
|
array_splice($path['work'], $path['level']);
|
||||||
|
// step back a level
|
||||||
|
$path['level'] -= 1;
|
||||||
|
if ($old === false && $path['level'] == -1) {
|
||||||
|
return $path['found'] ?? [];
|
||||||
|
} else {
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* array search simple. looks for key, value combination, if found, returns true
|
||||||
|
* on default does not strict check, so string '4' will match int 4 and vica versa
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array search in as array
|
||||||
|
* @param string|int $key key (key to search in)
|
||||||
|
* @param string|int $value value (what to find)
|
||||||
|
* @param bool $strict [false], if set to true, will strict check key/value
|
||||||
|
* @return bool true on found, false on not found
|
||||||
|
*/
|
||||||
|
public static function arraySearchSimple(array $array, $key, $value, bool $strict = false): bool
|
||||||
|
{
|
||||||
|
if (!is_array($array)) {
|
||||||
|
$array = [];
|
||||||
|
}
|
||||||
|
foreach ($array as $_key => $_value) {
|
||||||
|
// if value is an array, we search
|
||||||
|
if (is_array($_value)) {
|
||||||
|
// call recursive, and return result if it is true, else continue
|
||||||
|
if (($result = self::arraySearchSimple($_value, $key, $value, $strict)) !== false) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
} elseif ($strict === false && $_key == $key && $_value == $value) {
|
||||||
|
return true;
|
||||||
|
} elseif ($strict === true && $_key === $key && $_value === $value) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no true returned, not found
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* correctly recursive merges as an array as array_merge_recursive
|
||||||
|
* just glues things together
|
||||||
|
* array first array to merge
|
||||||
|
* array second array to merge
|
||||||
|
* ... etc
|
||||||
|
* bool key flag: true: handle keys as string or int
|
||||||
|
* default false: all keys are string
|
||||||
|
*
|
||||||
|
* @return array<mixed>|bool merged array
|
||||||
|
*/
|
||||||
|
public static function arrayMergeRecursive()
|
||||||
|
{
|
||||||
|
// croak on not enough arguemnts (we need at least two)
|
||||||
|
if (func_num_args() < 2) {
|
||||||
|
trigger_error(__FUNCTION__ . ' needs two or more array arguments', E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// default key is not string
|
||||||
|
$key_is_string = false;
|
||||||
|
$arrays = func_get_args();
|
||||||
|
// if last is not array, then assume it is trigger for key is always string
|
||||||
|
if (!is_array(end($arrays))) {
|
||||||
|
if (array_pop($arrays)) {
|
||||||
|
$key_is_string = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check that arrays count is at least two, else we don't have enough to do anything
|
||||||
|
if (count($arrays) < 2) {
|
||||||
|
trigger_error(__FUNCTION__ . ' needs two or more array arguments', E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$merged = [];
|
||||||
|
while ($arrays) {
|
||||||
|
$array = array_shift($arrays);
|
||||||
|
if (!is_array($array)) {
|
||||||
|
trigger_error(__FUNCTION__ . ' encountered a non array argument', E_USER_WARNING);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!$array) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
// if string or if key is assumed to be string do key match
|
||||||
|
// else add new entry
|
||||||
|
if (is_string($key) || $key_is_string === false) {
|
||||||
|
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
|
||||||
|
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);
|
||||||
|
$merged[$key] = self::arrayMergeRecursive($merged[$key], $value, $key_is_string);
|
||||||
|
} else {
|
||||||
|
$merged[$key] = $value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$merged[] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $merged;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* correct array_diff that does an actualy difference between two arrays.
|
||||||
|
* array_diff only checks elements from A that are not in B, but not the
|
||||||
|
* other way around.
|
||||||
|
* Note that like array_diff this only checks first level values not keys
|
||||||
|
*
|
||||||
|
* @param array<mixed> $a array to compare a
|
||||||
|
* @param array<mixed> $b array to compare b
|
||||||
|
* @return array<mixed> array with missing elements from a & b
|
||||||
|
*/
|
||||||
|
public static function arrayDiff(array $a, array $b): array
|
||||||
|
{
|
||||||
|
$intersect = array_intersect($a, $b);
|
||||||
|
return array_merge(array_diff($a, $intersect), array_diff($b, $intersect));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* search for the needle array elements in haystack and
|
||||||
|
* return the ones found as an array,
|
||||||
|
* is there nothing found, it returns FALSE (boolean)
|
||||||
|
*
|
||||||
|
* @param array<mixed> $needle elements to search for
|
||||||
|
* @param array<mixed> $haystack array where the $needle elements should
|
||||||
|
* be searched int
|
||||||
|
* @return array<mixed>|bool either the found elements or
|
||||||
|
* false for nothing found or error
|
||||||
|
*/
|
||||||
|
public static function inArrayAny(array $needle, array $haystack)
|
||||||
|
{
|
||||||
|
$found = [];
|
||||||
|
foreach ($needle as $element) {
|
||||||
|
if (in_array($element, $haystack)) {
|
||||||
|
$found[] = $element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($found) == 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return $found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates out of a normal db_return array an assoc array
|
||||||
|
*
|
||||||
|
* @param array<mixed> $db_array return array from the database
|
||||||
|
* @param string|int|bool $key key set, false for not set
|
||||||
|
* @param string|int|bool $value value set, false for not set
|
||||||
|
* @param bool $set_only flag to return all (default), or set only
|
||||||
|
* @return array<mixed> associative array
|
||||||
|
*/
|
||||||
|
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
|
||||||
|
{
|
||||||
|
$ret_array = [];
|
||||||
|
// do this to only run count once
|
||||||
|
for ($i = 0, $iMax = count($db_array); $i < $iMax; $i++) {
|
||||||
|
// if no key then we make an order reference
|
||||||
|
if (
|
||||||
|
$key !== false &&
|
||||||
|
$value !== false &&
|
||||||
|
(($set_only && !empty($db_array[$i][$value])) ||
|
||||||
|
(!$set_only && isset($db_array[$i][$value]))) &&
|
||||||
|
!empty($db_array[$i][$key])
|
||||||
|
) {
|
||||||
|
$ret_array[$db_array[$i][$key]] = $db_array[$i][$value];
|
||||||
|
} elseif (
|
||||||
|
$key === false && $value !== false &&
|
||||||
|
isset($db_array[$i][$value])
|
||||||
|
) {
|
||||||
|
$ret_array[] = $db_array[$i][$value];
|
||||||
|
} elseif (
|
||||||
|
$key !== false && $value === false &&
|
||||||
|
!empty($db_array[$i][$key])
|
||||||
|
) {
|
||||||
|
$ret_array[$db_array[$i][$key]] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $ret_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts multi dimensional array to a flat array
|
||||||
|
* does NOT preserve keys
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array multi dimensionial array
|
||||||
|
* @return array<mixed> flattened array
|
||||||
|
*/
|
||||||
|
public static function flattenArray(array $array): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
array_walk_recursive(
|
||||||
|
$array,
|
||||||
|
function ($value) use (&$return) {
|
||||||
|
$return[] = $value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* will loop through an array recursivly and write the array keys back
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array multidemnsional array to flatten
|
||||||
|
* @param array<mixed> $return recoursive pass on array of keys
|
||||||
|
* @return array<mixed> flattened keys array
|
||||||
|
*/
|
||||||
|
public static function flattenArrayKey(array $array, array $return = []): array
|
||||||
|
{
|
||||||
|
foreach ($array as $key => $sub) {
|
||||||
|
$return[] = $key;
|
||||||
|
if (is_array($sub) && count($sub) > 0) {
|
||||||
|
$return = self::flattenArrayKey($sub, $return);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* as above will flatten an array, but in this case only the outmost
|
||||||
|
* leave nodes, all other keyswill be skipped
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array multidemnsional array to flatten
|
||||||
|
* @return array<mixed> flattened keys array
|
||||||
|
*/
|
||||||
|
public static function flattenArrayKeyLeavesOnly(array $array): array
|
||||||
|
{
|
||||||
|
$return = [];
|
||||||
|
array_walk_recursive(
|
||||||
|
$array,
|
||||||
|
function ($value, $key) use (&$return) {
|
||||||
|
$return[] = $key;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* searches for key -> value in an array tree and writes the value one level up
|
||||||
|
* this will remove this leaf will all other values
|
||||||
|
*
|
||||||
|
* @param array<mixed> $array nested array
|
||||||
|
* @param string|int $search key to find that has no sub leaf
|
||||||
|
* and will be pushed up
|
||||||
|
* @return array<mixed> modified, flattened array
|
||||||
|
*/
|
||||||
|
public static function arrayFlatForKey(array $array, $search): array
|
||||||
|
{
|
||||||
|
if (!is_array($array)) {
|
||||||
|
$array = [];
|
||||||
|
}
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
// if it is not an array do just nothing
|
||||||
|
if (!is_array($value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// probe it has search key
|
||||||
|
if (isset($value[$search])) {
|
||||||
|
// set as current
|
||||||
|
$array[$key] = $value[$search];
|
||||||
|
} else {
|
||||||
|
// call up next node down
|
||||||
|
// $array[$key] = call_user_func(__METHOD__, $value, $search);
|
||||||
|
$array[$key] = self::arrayFlatForKey($value, $search);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
452
www/vendor/egrajp/corelibs-composer-all/src/Combined/DateTime.php
vendored
Normal file
452
www/vendor/egrajp/corelibs-composer-all/src/Combined/DateTime.php
vendored
Normal file
@@ -0,0 +1,452 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* date convert and check functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Combined;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class DateTime
|
||||||
|
{
|
||||||
|
/** @var array<int,string> */
|
||||||
|
public const DAY_SHORT = [
|
||||||
|
1 => 'Mon',
|
||||||
|
2 => 'Tue',
|
||||||
|
3 => 'Wed',
|
||||||
|
4 => 'Thu',
|
||||||
|
5 => 'Fri',
|
||||||
|
6 => 'Sat',
|
||||||
|
7 => 'Sun',
|
||||||
|
];
|
||||||
|
/** @var array<int,string> */
|
||||||
|
public const DAY_LONG = [
|
||||||
|
1 => 'Monday',
|
||||||
|
2 => 'Tuesday',
|
||||||
|
3 => 'Wednesday',
|
||||||
|
4 => 'Thursday',
|
||||||
|
5 => 'Friday',
|
||||||
|
6 => 'Saturday',
|
||||||
|
7 => 'Sunday',
|
||||||
|
];
|
||||||
|
/** @var array<int,string> */
|
||||||
|
public const MONTH_LONG = [
|
||||||
|
1 => 'January',
|
||||||
|
2 => 'February',
|
||||||
|
3 => 'March',
|
||||||
|
4 => 'April',
|
||||||
|
5 => 'May',
|
||||||
|
6 => 'June',
|
||||||
|
7 => 'July',
|
||||||
|
8 => 'August',
|
||||||
|
9 => 'September',
|
||||||
|
10 => 'October',
|
||||||
|
11 => 'November',
|
||||||
|
12 => 'December',
|
||||||
|
];
|
||||||
|
/** @var array<int,string> */
|
||||||
|
public const MONTH_SHORT = [
|
||||||
|
1 => 'Jan',
|
||||||
|
2 => 'Feb',
|
||||||
|
3 => 'Mar',
|
||||||
|
4 => 'Apr',
|
||||||
|
5 => 'May',
|
||||||
|
6 => 'Jun',
|
||||||
|
7 => 'Jul',
|
||||||
|
8 => 'Aug',
|
||||||
|
9 => 'Sep',
|
||||||
|
10 => 'Oct',
|
||||||
|
11 => 'Nov',
|
||||||
|
12 => 'Dec',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a simple wrapper for the date format
|
||||||
|
* if an invalid timestamp is give zero timestamp unix time is used
|
||||||
|
*
|
||||||
|
* @param int|float $timestamp unix timestamp
|
||||||
|
* @param bool $show_micro show the micro time (default false)
|
||||||
|
* @param bool $micro_as_float Add the micro time with . instead
|
||||||
|
* of ms (default false)
|
||||||
|
* @return string formated date+time in Y-M-D h:m:s ms
|
||||||
|
*/
|
||||||
|
public static function dateStringFormat(
|
||||||
|
$timestamp,
|
||||||
|
bool $show_micro = false,
|
||||||
|
bool $micro_as_float = false
|
||||||
|
): string {
|
||||||
|
// split up the timestamp, assume . in timestamp
|
||||||
|
// array pad $ms if no microtime
|
||||||
|
list ($timestamp, $ms) = array_pad(explode('.', (string)round($timestamp, 4)), 2, null);
|
||||||
|
$string = date("Y-m-d H:i:s", (int)$timestamp);
|
||||||
|
if ($show_micro && $ms) {
|
||||||
|
if ($micro_as_float == false) {
|
||||||
|
$string .= ' ' . $ms . 'ms';
|
||||||
|
} else {
|
||||||
|
$string .= '.' . $ms;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* formats a timestamp into interval, not into a date
|
||||||
|
*
|
||||||
|
* @param string|int|float $timestamp interval in seconds and optional
|
||||||
|
* float micro seconds
|
||||||
|
* @param bool $show_micro show micro seconds, default true
|
||||||
|
* @return string interval formatted string or string as is
|
||||||
|
*/
|
||||||
|
public static function timeStringFormat($timestamp, bool $show_micro = true): string
|
||||||
|
{
|
||||||
|
// check if the timestamp has any h/m/s/ms inside, if yes skip
|
||||||
|
if (!preg_match("/(h|m|s|ms)/", (string)$timestamp)) {
|
||||||
|
list($timestamp, $ms) = array_pad(explode('.', (string)round((float)$timestamp, 4)), 2, null);
|
||||||
|
// if negative remember
|
||||||
|
$negative = false;
|
||||||
|
if ((int)$timestamp < 0) {
|
||||||
|
$negative = true;
|
||||||
|
}
|
||||||
|
$timestamp = abs((float)$timestamp);
|
||||||
|
$timegroups = [86400, 3600, 60, 1];
|
||||||
|
$labels = ['d', 'h', 'm', 's'];
|
||||||
|
$time_string = '';
|
||||||
|
// if timestamp is zero, return zero string
|
||||||
|
if ($timestamp == 0) {
|
||||||
|
$time_string = '0s';
|
||||||
|
} else {
|
||||||
|
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) {
|
||||||
|
$output = floor((float)$timestamp / $timegroups[$i]);
|
||||||
|
$timestamp = (float)$timestamp % $timegroups[$i];
|
||||||
|
// output has days|hours|min|sec
|
||||||
|
if ($output || $time_string) {
|
||||||
|
$time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// only add ms if we have an ms value
|
||||||
|
if ($ms !== null) {
|
||||||
|
// if we have ms and it has leading zeros, remove them, but only if it is nut just 0
|
||||||
|
$ms = preg_replace("/^0+(\d+)$/", '${1}', $ms);
|
||||||
|
if (!is_string($ms) || empty($ms)) {
|
||||||
|
$ms = '0';
|
||||||
|
}
|
||||||
|
// add ms if there
|
||||||
|
if ($show_micro) {
|
||||||
|
$time_string .= ' ' . $ms . 'ms';
|
||||||
|
} elseif (!$time_string) {
|
||||||
|
$time_string .= $ms . 'ms';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($negative) {
|
||||||
|
$time_string = '-' . $time_string;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$time_string = $timestamp;
|
||||||
|
}
|
||||||
|
return (string)$time_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* does a reverse of the timeStringFormat and converts the string from
|
||||||
|
* xd xh xm xs xms to a timestamp.microtime format
|
||||||
|
*
|
||||||
|
* @param string|int|float $timestring formatted interval
|
||||||
|
* @return string|int|float converted float interval, or string as is
|
||||||
|
*/
|
||||||
|
public static function stringToTime($timestring)
|
||||||
|
{
|
||||||
|
$timestamp = 0;
|
||||||
|
if (preg_match("/(d|h|m|s|ms)/", (string)$timestring)) {
|
||||||
|
$timestring = (string)$timestring;
|
||||||
|
// pos for preg match read + multiply factor
|
||||||
|
$timegroups = [2 => 86400, 4 => 3600, 6 => 60, 8 => 1];
|
||||||
|
$matches = [];
|
||||||
|
// if start with -, strip and set negative
|
||||||
|
$negative = false;
|
||||||
|
if (preg_match("/^-/", $timestring)) {
|
||||||
|
$negative = true;
|
||||||
|
$timestring = substr($timestring, 1);
|
||||||
|
}
|
||||||
|
// preg match: 0: full string
|
||||||
|
// 2, 4, 6, 8 are the to need values
|
||||||
|
preg_match("/^((\d+)d ?)?((\d+)h ?)?((\d+)m ?)?((\d+)s ?)?((\d+)ms)?$/", $timestring, $matches);
|
||||||
|
// multiply the returned matches and sum them up. the last one (ms) is added with .
|
||||||
|
foreach ($timegroups as $i => $time_multiply) {
|
||||||
|
if (isset($matches[$i]) && is_numeric($matches[$i])) {
|
||||||
|
$timestamp += (float)$matches[$i] * $time_multiply;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isset($matches[10]) && is_numeric($matches[10])) {
|
||||||
|
$timestamp .= '.' . $matches[10];
|
||||||
|
}
|
||||||
|
if ($negative) {
|
||||||
|
// cast to flaot so we can do a negative multiplication
|
||||||
|
$timestamp = (float)$timestamp * -1;
|
||||||
|
}
|
||||||
|
return $timestamp;
|
||||||
|
} else {
|
||||||
|
return $timestring;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns long or short day of week name based on ISO day of week number
|
||||||
|
* 1: Monday
|
||||||
|
* ...
|
||||||
|
* 7: Sunday
|
||||||
|
*
|
||||||
|
* @param int $isodow 1: Monday, 7: Sunday
|
||||||
|
* @param bool $long Default false 'Mon', if true 'Monday'
|
||||||
|
* @return string Day of week string either short 'Mon' or long 'Monday'
|
||||||
|
*/
|
||||||
|
public static function setWeekdayNameFromIsoDow(int $isodow, bool $long = false): string
|
||||||
|
{
|
||||||
|
// if not valid, set to invalid
|
||||||
|
if ($isodow < 1 || $isodow > 7) {
|
||||||
|
return $long ? 'Invalid' : 'Inv';
|
||||||
|
}
|
||||||
|
return date($long ? 'l' : 'D', strtotime("Sunday +{$isodow} days") ?: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the day of week Name from date
|
||||||
|
*
|
||||||
|
* @param string $date Any valid date
|
||||||
|
* @param bool $long Default false 'Mon', if true 'Monday'
|
||||||
|
* @return string Day of week string either short 'Mon' or long 'Monday'
|
||||||
|
*/
|
||||||
|
public static function setWeekdayNameFromDate(string $date, bool $long = false): string
|
||||||
|
{
|
||||||
|
if (!self::checkDate($date)) {
|
||||||
|
return $long ? 'Invalid' : 'Inv';
|
||||||
|
}
|
||||||
|
return date($long ? 'l' : 'D', strtotime($date) ?: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the day of week Name from date
|
||||||
|
*
|
||||||
|
* @param string $date Any valid date
|
||||||
|
* @return int ISO Weekday number 1: Monday, 7: Sunday, -1 for invalid date
|
||||||
|
*/
|
||||||
|
public static function setWeekdayNumberFromDate(string $date): int
|
||||||
|
{
|
||||||
|
if (!self::checkDate($date)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (int)date('N', strtotime($date) ?: null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* splits & checks date, wrap around for check_date function
|
||||||
|
*
|
||||||
|
* @param string $date a date string in the format YYYY-MM-DD
|
||||||
|
* @return bool true if valid date, false if date not valid
|
||||||
|
*/
|
||||||
|
public static function checkDate($date): bool
|
||||||
|
{
|
||||||
|
if (!$date) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
list ($year, $month, $day) = array_pad(
|
||||||
|
preg_split("/[\/-]/", $date) ?: [],
|
||||||
|
3,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (!$year || !$month || !$day) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!checkdate((int)$month, (int)$day, (int)$year)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* splits & checks date, wrap around for check_date function
|
||||||
|
*
|
||||||
|
* @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
|
||||||
|
* @return bool true if valid date, false if date not valid
|
||||||
|
*/
|
||||||
|
public static function checkDateTime(string $datetime): bool
|
||||||
|
{
|
||||||
|
if (!$datetime) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// catch last overflow if sec has - in front
|
||||||
|
list ($year, $month, $day, $hour, $min, $sec, $sec_overflow) = array_pad(
|
||||||
|
preg_split("/[\/\- :]/", $datetime) ?: [],
|
||||||
|
7,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (!$year || !$month || !$day) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!checkdate((int)$month, (int)$day, (int)$year)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!is_numeric($hour) || !is_numeric($min)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($sec) && !is_numeric($sec)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!empty($sec) && ($sec < 0 || $sec > 60)) {
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// in case we have - for seconds
|
||||||
|
if (!empty($sec_overflow)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
($hour < 0 || $hour > 24) ||
|
||||||
|
($min < 0 || $min > 60)
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compares two dates, tries to convert them via strtotime to timestamps
|
||||||
|
* returns int/bool in:
|
||||||
|
* -1 if the first date is smaller the last
|
||||||
|
* 0 if both are equal
|
||||||
|
* 1 if the first date is bigger than the last
|
||||||
|
* false if date validation/conversion failed
|
||||||
|
*
|
||||||
|
* @param string $start_date start date string in YYYY-MM-DD
|
||||||
|
* @param string $end_date end date string in YYYY-MM-DD
|
||||||
|
* @return int|bool false on error
|
||||||
|
* or int -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
|
*/
|
||||||
|
public static function compareDate($start_date, $end_date)
|
||||||
|
{
|
||||||
|
// pre check for empty or wrong
|
||||||
|
if ($start_date == '--' || $end_date == '--' || !$start_date || !$end_date) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// if invalid, quit
|
||||||
|
if (($start_timestamp = strtotime($start_date)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (($end_timestamp = strtotime($end_date)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// convert anything to Y-m-d and then to timestamp
|
||||||
|
// this is to remove any time parts
|
||||||
|
$start_timestamp = strtotime(date('Y-m-d', $start_timestamp));
|
||||||
|
$end_timestamp = strtotime(date('Y-m-d', $end_timestamp));
|
||||||
|
// compare, or end with false
|
||||||
|
if ($start_timestamp < $end_timestamp) {
|
||||||
|
return -1;
|
||||||
|
} elseif ($start_timestamp == $end_timestamp) {
|
||||||
|
return 0;
|
||||||
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* compares the two dates + times. if seconds missing in one set,
|
||||||
|
* adds :00, converts date + times via strtotime to timestamps
|
||||||
|
* returns int/bool in:
|
||||||
|
* -1 if the first date is smaller the last
|
||||||
|
* 0 if both are equal
|
||||||
|
* 1 if the first date is bigger than the last
|
||||||
|
* false if date/times validation/conversion failed
|
||||||
|
*
|
||||||
|
* @param string $start_datetime start date/time in YYYY-MM-DD HH:mm:ss
|
||||||
|
* @param string $end_datetime end date/time in YYYY-MM-DD HH:mm:ss
|
||||||
|
* @return int|bool false for error
|
||||||
|
* or -1 (s<e)/0 (s=e)/1 (s>e) as difference
|
||||||
|
*/
|
||||||
|
public static function compareDateTime($start_datetime, $end_datetime)
|
||||||
|
{
|
||||||
|
// pre check for empty or wrong
|
||||||
|
if ($start_datetime == '--' || $end_datetime == '--' || !$start_datetime || !$end_datetime) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// quit if invalid timestamp
|
||||||
|
if (($start_timestamp = strtotime($start_datetime)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (($end_timestamp = strtotime($end_datetime)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// compare, or return false
|
||||||
|
if ($start_timestamp < $end_timestamp) {
|
||||||
|
return -1;
|
||||||
|
} elseif ($start_timestamp == $end_timestamp) {
|
||||||
|
return 0;
|
||||||
|
} elseif ($start_timestamp > $end_timestamp) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculates the days between two dates
|
||||||
|
* return: overall days, week days, weekend days as array 0...2 or named
|
||||||
|
* as overall, weekday and weekend
|
||||||
|
*
|
||||||
|
* @param string $start_date valid start date (y/m/d)
|
||||||
|
* @param string $end_date valid end date (y/m/d)
|
||||||
|
* @param bool $return_named return array type, false (default), true for named
|
||||||
|
* @return array<mixed> 0/overall, 1/weekday, 2/weekend
|
||||||
|
*/
|
||||||
|
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
|
||||||
|
{
|
||||||
|
// pos 0 all, pos 1 weekday, pos 2 weekend
|
||||||
|
$days = [];
|
||||||
|
// if anything invalid, return 0,0,0
|
||||||
|
try {
|
||||||
|
$start = new \DateTime($start_date);
|
||||||
|
$end = new \DateTime($end_date);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
if ($return_named === true) {
|
||||||
|
return [
|
||||||
|
'overall' => 0,
|
||||||
|
'weekday' => 0,
|
||||||
|
'weekend' => 0,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return [0, 0, 0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// so we include the last day too, we need to add +1 second in the time
|
||||||
|
$end->setTime(0, 0, 1);
|
||||||
|
// if end date before start date, only this will be filled
|
||||||
|
$days[0] = $end->diff($start)->days;
|
||||||
|
$days[1] = 0;
|
||||||
|
$days[2] = 0;
|
||||||
|
// get period for weekends/weekdays
|
||||||
|
$period = new \DatePeriod($start, new \DateInterval('P1D'), $end);
|
||||||
|
foreach ($period as $dt) {
|
||||||
|
$curr = $dt->format('D');
|
||||||
|
if ($curr == 'Sat' || $curr == 'Sun') {
|
||||||
|
$days[2] ++;
|
||||||
|
} else {
|
||||||
|
$days[1] ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($return_named === true) {
|
||||||
|
return [
|
||||||
|
'overall' => $days[0],
|
||||||
|
'weekday' => $days[1],
|
||||||
|
'weekend' => $days[2],
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
return $days;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
167
www/vendor/egrajp/corelibs-composer-all/src/Convert/Byte.php
vendored
Normal file
167
www/vendor/egrajp/corelibs-composer-all/src/Convert/Byte.php
vendored
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* byte conversion from and to human readable
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Byte
|
||||||
|
{
|
||||||
|
// define byteFormat
|
||||||
|
public const BYTE_FORMAT_NOSPACE = 1;
|
||||||
|
public const BYTE_FORMAT_ADJUST = 2;
|
||||||
|
public const BYTE_FORMAT_SI = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function replaces the old byteStringFormat
|
||||||
|
*
|
||||||
|
* Converts any number string to human readable byte format
|
||||||
|
* Maxium is Exobytes and above that the Exobytes suffix is used for all
|
||||||
|
* If more are needed only the correct short name for the suffix has to be
|
||||||
|
* added to the labels array
|
||||||
|
* On no number string it returns string as is
|
||||||
|
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
|
||||||
|
*
|
||||||
|
* The class itself hast the following defined
|
||||||
|
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and suffix
|
||||||
|
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
||||||
|
* BYTE_FORMAT_SI [4] use si standard 1000 instead of bytes 1024
|
||||||
|
* To use the constant from outside use class::CONSTANT
|
||||||
|
*
|
||||||
|
* @param string|int|float $bytes bytes as string int or pure int
|
||||||
|
* @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
|
||||||
|
* @throws \Exception 1: no valid flag set
|
||||||
|
*/
|
||||||
|
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
||||||
|
{
|
||||||
|
// if not numeric, return as is
|
||||||
|
if (is_numeric($bytes)) {
|
||||||
|
// flags bit wise check
|
||||||
|
// remove space between number and suffix
|
||||||
|
if ($flags & self::BYTE_FORMAT_NOSPACE) {
|
||||||
|
$space = false;
|
||||||
|
} else {
|
||||||
|
$space = true;
|
||||||
|
}
|
||||||
|
// use sprintf instead of round
|
||||||
|
if ($flags & self::BYTE_FORMAT_ADJUST) {
|
||||||
|
$adjust = true;
|
||||||
|
} else {
|
||||||
|
$adjust = false;
|
||||||
|
}
|
||||||
|
// use SI 1000 mod and not 1024 mod
|
||||||
|
if ($flags & self::BYTE_FORMAT_SI) {
|
||||||
|
$si = true;
|
||||||
|
} else {
|
||||||
|
$si = false;
|
||||||
|
}
|
||||||
|
if ($flags > 7) {
|
||||||
|
throw new \Exception("Invalid flags parameter: $flags", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// si or normal
|
||||||
|
$unit = $si ? 1000 : 1024;
|
||||||
|
// always positive
|
||||||
|
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs((float)$bytes);
|
||||||
|
// smaller than unit is always B
|
||||||
|
if ($abs_bytes < $unit) {
|
||||||
|
return $bytes . 'B';
|
||||||
|
}
|
||||||
|
// labels in order of size [Y, Z]
|
||||||
|
$labels = ['', 'K', 'M', 'G', 'T', 'P', 'E'];
|
||||||
|
// exp position calculation
|
||||||
|
$exp = floor(log($abs_bytes, $unit));
|
||||||
|
// avoid printing out anything larger than max labels
|
||||||
|
if ($exp >= count($labels)) {
|
||||||
|
$exp = count($labels) - 1;
|
||||||
|
}
|
||||||
|
// deviation calculation
|
||||||
|
$dev = pow($unit, $exp) * ($unit - 0.05);
|
||||||
|
// shift the exp +1 for on the border units
|
||||||
|
if (
|
||||||
|
$exp < 6 &&
|
||||||
|
$abs_bytes > ($dev - (((int)$dev & 0xfff) == 0xd00 ? 52 : 0))
|
||||||
|
) {
|
||||||
|
$exp++;
|
||||||
|
}
|
||||||
|
// label name, including leading space if flagged
|
||||||
|
$pre = ($space ? ' ' : '') . ($labels[$exp] ?? '>E') . ($si ? 'i' : '') . 'B';
|
||||||
|
$bytes_calc = $abs_bytes / pow($unit, $exp);
|
||||||
|
// if original is negative, reverse
|
||||||
|
if ($bytes < 0) {
|
||||||
|
$bytes_calc *= -1;
|
||||||
|
}
|
||||||
|
if ($adjust) {
|
||||||
|
return sprintf("%.2f%s", $bytes_calc, $pre);
|
||||||
|
} else {
|
||||||
|
return round($bytes_calc, 2) . $pre;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if anything other return as string
|
||||||
|
return (string)$bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculates the bytes based on a string with nnG, nnGB, nnM, etc
|
||||||
|
* NOTE: large exabyte numbers will overflow
|
||||||
|
* flag allowed:
|
||||||
|
* BYTE_FORMAT_SI [4] use si standard 1000 instead of bytes 1024
|
||||||
|
*
|
||||||
|
* @param string|int|float $number any string or number to convert
|
||||||
|
* @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
|
||||||
|
* @throws \Exception 1: no valid flag set
|
||||||
|
*/
|
||||||
|
public static function stringByteFormat($number, int $flags = 0)
|
||||||
|
{
|
||||||
|
// use SI 1000 mod and not 1024 mod
|
||||||
|
if ($flags & self::BYTE_FORMAT_SI) {
|
||||||
|
$si = true;
|
||||||
|
} else {
|
||||||
|
$si = false;
|
||||||
|
}
|
||||||
|
if ($flags != 0 && $flags != 4) {
|
||||||
|
throw new \Exception("Invalid flags parameter: $flags", 1);
|
||||||
|
}
|
||||||
|
// matches in regex
|
||||||
|
$matches = [];
|
||||||
|
// all valid units
|
||||||
|
$valid_units_ = 'bkmgtpezy';
|
||||||
|
// detects up to exo bytes
|
||||||
|
preg_match(
|
||||||
|
"/(-)?([\d.,]*)\s?(eib|pib|tib|gib|mib|kib|eb|pb|tb|gb|mb|kb|e|p|t|g|m|k|b)$/i",
|
||||||
|
strtolower((string)$number),
|
||||||
|
$matches
|
||||||
|
);
|
||||||
|
if (isset($matches[2]) && isset($matches[3])) {
|
||||||
|
// remove all non valid characters from the number
|
||||||
|
$number = preg_replace('/[^0-9\.]/', '', $matches[2]);
|
||||||
|
// final clean up and convert to float
|
||||||
|
$number = (float)trim((string)$number);
|
||||||
|
// convert any mb/gb/etc to single m/b
|
||||||
|
$unit = preg_replace('/[^bkmgtpezy]/i', '', $matches[3]);
|
||||||
|
if ($unit) {
|
||||||
|
$number = $number * pow($si ? 1000 : 1024, stripos($valid_units_, $unit[0]) ?: 0);
|
||||||
|
}
|
||||||
|
// convert to INT to avoid +E output
|
||||||
|
$number = (int)round($number);
|
||||||
|
// if negative input, keep nnegative
|
||||||
|
if (!empty($matches[1])) {
|
||||||
|
$number *= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if not matching return as is
|
||||||
|
return $number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
344
www/vendor/egrajp/corelibs-composer-all/src/Convert/Colors.php
vendored
Normal file
344
www/vendor/egrajp/corelibs-composer-all/src/Convert/Colors.php
vendored
Normal file
@@ -0,0 +1,344 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert color spaces
|
||||||
|
* rgb to hex
|
||||||
|
* hex to rgb
|
||||||
|
* rgb to hsb
|
||||||
|
* hsb to rgb
|
||||||
|
* rgb to hsl
|
||||||
|
* hsl to rgb
|
||||||
|
*/
|
||||||
|
|
||||||
|
// TODO: use oklab as base for converting colors
|
||||||
|
// https://bottosson.github.io/posts/oklab/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Colors
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* converts the rgb values from int data to the valid rgb html hex string
|
||||||
|
* optional can turn of leading #
|
||||||
|
* if one value is invalid, will return false
|
||||||
|
*
|
||||||
|
* @param int $red red 0-255
|
||||||
|
* @param int $green green 0-255
|
||||||
|
* @param int $blue blue 0-255
|
||||||
|
* @param bool $hex_prefix default true, prefix with "#"
|
||||||
|
* @return string|bool rgb in hex values with leading # if set,
|
||||||
|
* false for invalid color
|
||||||
|
*/
|
||||||
|
public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true)
|
||||||
|
{
|
||||||
|
$hex_color = '';
|
||||||
|
if ($hex_prefix === true) {
|
||||||
|
$hex_color = '#';
|
||||||
|
}
|
||||||
|
foreach (['red', 'green', 'blue'] as $color) {
|
||||||
|
// if not valid, abort
|
||||||
|
if ($$color < 0 || $$color > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// pad left with 0
|
||||||
|
$hex_color .= str_pad(dechex($$color), 2, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
return $hex_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts a hex RGB color to the int numbers
|
||||||
|
*
|
||||||
|
* @param string $hexStr RGB hexstring
|
||||||
|
* @param bool $return_as_string flag to return as string
|
||||||
|
* @param string $seperator string seperator: default: ","
|
||||||
|
* @return string|array<string,float|int>|bool false on error or array with RGB
|
||||||
|
* or a string with the seperator
|
||||||
|
*/
|
||||||
|
public static function hex2rgb(
|
||||||
|
string $hexStr,
|
||||||
|
bool $return_as_string = false,
|
||||||
|
string $seperator = ','
|
||||||
|
) {
|
||||||
|
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
|
||||||
|
if (!is_string($hexStr)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$rgbArray = [];
|
||||||
|
if (strlen($hexStr) == 6) {
|
||||||
|
// If a proper hex code, convert using bitwise operation.
|
||||||
|
// No overhead... faster
|
||||||
|
$colorVal = hexdec($hexStr);
|
||||||
|
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
|
||||||
|
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
|
||||||
|
$rgbArray['b'] = 0xFF & $colorVal;
|
||||||
|
} elseif (strlen($hexStr) == 3) {
|
||||||
|
// If shorthand notation, need some string manipulations
|
||||||
|
$rgbArray['r'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2));
|
||||||
|
$rgbArray['g'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2));
|
||||||
|
$rgbArray['b'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2));
|
||||||
|
} else {
|
||||||
|
// Invalid hex color code
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// returns the rgb string or the associative array
|
||||||
|
return $return_as_string ? implode($seperator, $rgbArray) : $rgbArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* rgb2hsb does not clean convert back to rgb in a round trip
|
||||||
|
* converts RGB to HSB/V values
|
||||||
|
* returns:
|
||||||
|
* array with hue (0-360), sat (0-100%), brightness/value (0-100%)
|
||||||
|
*
|
||||||
|
* @param int $red red 0-255
|
||||||
|
* @param int $green green 0-255
|
||||||
|
* @param int $blue blue 0-255
|
||||||
|
* @return array<int|float>|bool Hue, Sat, Brightness/Value
|
||||||
|
* false for input value error
|
||||||
|
*/
|
||||||
|
public static function rgb2hsb(int $red, int $green, int $blue)
|
||||||
|
{
|
||||||
|
// check that rgb is from 0 to 255
|
||||||
|
foreach (['red', 'green', 'blue'] as $c) {
|
||||||
|
if ($$c < 0 || $$c > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$$c = $$c / 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
$MAX = max($red, $green, $blue);
|
||||||
|
$MIN = min($red, $green, $blue);
|
||||||
|
$HUE = 0;
|
||||||
|
|
||||||
|
if ($MAX == $MIN) {
|
||||||
|
return [0, 0, round($MAX * 100)];
|
||||||
|
}
|
||||||
|
if ($red == $MAX) {
|
||||||
|
$HUE = ($green - $blue) / ($MAX - $MIN);
|
||||||
|
} elseif ($green == $MAX) {
|
||||||
|
$HUE = 2 + (($blue - $red) / ($MAX - $MIN));
|
||||||
|
} elseif ($blue == $MAX) {
|
||||||
|
$HUE = 4 + (($red - $green) / ($MAX - $MIN));
|
||||||
|
}
|
||||||
|
$HUE *= 60;
|
||||||
|
if ($HUE < 0) {
|
||||||
|
$HUE += 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
(int)round($HUE),
|
||||||
|
(int)round((($MAX - $MIN) / $MAX) * 100),
|
||||||
|
(int)round($MAX * 100)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hsb2rgb does not clean convert back to hsb in a round trip
|
||||||
|
* converts HSB/V to RGB values RGB is full INT
|
||||||
|
* if HSB/V value is invalid, sets this value to 0
|
||||||
|
*
|
||||||
|
* @param float $H hue 0-360 (int)
|
||||||
|
* @param float $S saturation 0-100 (int)
|
||||||
|
* @param float $V brightness/value 0-100 (int)
|
||||||
|
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
|
||||||
|
* false for input value error
|
||||||
|
*/
|
||||||
|
public static function hsb2rgb(float $H, float $S, float $V)
|
||||||
|
{
|
||||||
|
// check that H is 0 to 359, 360 = 0
|
||||||
|
// and S and V are 0 to 1
|
||||||
|
if ($H == 360) {
|
||||||
|
$H = 0;
|
||||||
|
}
|
||||||
|
if ($H < 0 || $H > 359) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($S < 0 || $S > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($V < 0 || $V > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// convert to internal 0-1 format
|
||||||
|
$S /= 100;
|
||||||
|
$V /= 100;
|
||||||
|
|
||||||
|
if ($S == 0) {
|
||||||
|
$V = (int)round($V * 255);
|
||||||
|
return [$V, $V, $V];
|
||||||
|
}
|
||||||
|
|
||||||
|
$Hi = floor($H / 60);
|
||||||
|
$f = ($H / 60) - $Hi;
|
||||||
|
$p = $V * (1 - $S);
|
||||||
|
$q = $V * (1 - ($S * $f));
|
||||||
|
$t = $V * (1 - ($S * (1 - $f)));
|
||||||
|
|
||||||
|
switch ($Hi) {
|
||||||
|
case 0:
|
||||||
|
$red = $V;
|
||||||
|
$green = $t;
|
||||||
|
$blue = $p;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
$red = $q;
|
||||||
|
$green = $V;
|
||||||
|
$blue = $p;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
$red = $p;
|
||||||
|
$green = $V;
|
||||||
|
$blue = $t;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
$red = $p;
|
||||||
|
$green = $q;
|
||||||
|
$blue = $V;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
$red = $t;
|
||||||
|
$green = $p;
|
||||||
|
$blue = $V;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$red = $V;
|
||||||
|
$green = $p;
|
||||||
|
$blue = $q;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$red = 0;
|
||||||
|
$green = 0;
|
||||||
|
$blue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
(int)round($red * 255),
|
||||||
|
(int)round($green * 255),
|
||||||
|
(int)round($blue * 255)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts a RGB (0-255) to HSL
|
||||||
|
* return:
|
||||||
|
* array with hue (0-360), saturation (0-100%) and luminance (0-100%)
|
||||||
|
*
|
||||||
|
* @param int $red red 0-255
|
||||||
|
* @param int $green green 0-255
|
||||||
|
* @param int $blue blue 0-255
|
||||||
|
* @return array<float>|bool hue/sat/luminance
|
||||||
|
* false for input value error
|
||||||
|
*/
|
||||||
|
public static function rgb2hsl(int $red, int $green, int $blue)
|
||||||
|
{
|
||||||
|
// check that rgb is from 0 to 255
|
||||||
|
foreach (['red', 'green', 'blue'] as $c) {
|
||||||
|
if ($$c < 0 || $$c > 255) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$$c = $$c / 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
$min = min($red, $green, $blue);
|
||||||
|
$max = max($red, $green, $blue);
|
||||||
|
$chroma = $max - $min;
|
||||||
|
$sat = 0;
|
||||||
|
$hue = 0;
|
||||||
|
// luminance
|
||||||
|
$lum = ($max + $min) / 2;
|
||||||
|
|
||||||
|
// achromatic
|
||||||
|
if ($chroma == 0) {
|
||||||
|
// H, S, L
|
||||||
|
return [0.0, 0.0, round($lum * 100, 1)];
|
||||||
|
} else {
|
||||||
|
$sat = $chroma / (1 - abs(2 * $lum - 1));
|
||||||
|
if ($max == $red) {
|
||||||
|
$hue = fmod((($green - $blue) / $chroma), 6);
|
||||||
|
if ($hue < 0) {
|
||||||
|
$hue = (6 - fmod(abs($hue), 6));
|
||||||
|
}
|
||||||
|
} elseif ($max == $green) {
|
||||||
|
$hue = ($blue - $red) / $chroma + 2;
|
||||||
|
} elseif ($max == $blue) {
|
||||||
|
$hue = ($red - $green) / $chroma + 4;
|
||||||
|
}
|
||||||
|
$hue = $hue * 60;
|
||||||
|
// $sat = 1 - abs(2 * $lum - 1);
|
||||||
|
return [
|
||||||
|
round($hue, 1),
|
||||||
|
round($sat * 100, 1),
|
||||||
|
round($lum * 100, 1)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts an HSL to RGB
|
||||||
|
* if HSL value is invalid, set this value to 0
|
||||||
|
*
|
||||||
|
* @param float $hue hue: 0-360 (degrees)
|
||||||
|
* @param float $sat saturation: 0-100
|
||||||
|
* @param float $lum luminance: 0-100
|
||||||
|
* @return array<int,float|int>|bool red/blue/green 0-255 each
|
||||||
|
*/
|
||||||
|
public static function hsl2rgb(float $hue, float $sat, float $lum)
|
||||||
|
{
|
||||||
|
if (!is_numeric($hue)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($hue == 360) {
|
||||||
|
$hue = 0;
|
||||||
|
}
|
||||||
|
if ($hue < 0 || $hue > 359) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($sat < 0 || $sat > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($lum < 0 || $lum > 100) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// calc to internal convert value for hue
|
||||||
|
$hue = (1 / 360) * $hue;
|
||||||
|
// convert to internal 0-1 format
|
||||||
|
$sat /= 100;
|
||||||
|
$lum /= 100;
|
||||||
|
// if saturation is 0
|
||||||
|
if ($sat == 0) {
|
||||||
|
$lum = (int)round($lum * 255);
|
||||||
|
return [$lum, $lum, $lum];
|
||||||
|
} else {
|
||||||
|
$m2 = $lum < 0.5 ? $lum * ($sat + 1) : ($lum + $sat) - ($lum * $sat);
|
||||||
|
$m1 = $lum * 2 - $m2;
|
||||||
|
$hueue = function ($base) use ($m1, $m2) {
|
||||||
|
// base = hue, hue > 360 (1) - 360 (1), else < 0 + 360 (1)
|
||||||
|
$base = $base < 0 ? $base + 1 : ($base > 1 ? $base - 1 : $base);
|
||||||
|
// 6: 60, 2: 180, 3: 240
|
||||||
|
// 2/3 = 240
|
||||||
|
// 1/3 = 120 (all from 360)
|
||||||
|
if ($base * 6 < 1) {
|
||||||
|
return $m1 + ($m2 - $m1) * $base * 6;
|
||||||
|
}
|
||||||
|
if ($base * 2 < 1) {
|
||||||
|
return $m2;
|
||||||
|
}
|
||||||
|
if ($base * 3 < 2) {
|
||||||
|
return $m1 + ($m2 - $m1) * ((2 / 3) - $base) * 6;
|
||||||
|
}
|
||||||
|
return $m1;
|
||||||
|
};
|
||||||
|
|
||||||
|
return [
|
||||||
|
(int)round(255 * $hueue($hue + (1 / 3))),
|
||||||
|
(int)round(255 * $hueue($hue)),
|
||||||
|
(int)round(255 * $hueue($hue - (1 / 3)))
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
60
www/vendor/egrajp/corelibs-composer-all/src/Convert/Encoding.php
vendored
Normal file
60
www/vendor/egrajp/corelibs-composer-all/src/Convert/Encoding.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* convert string frmo one encdoing to another with auto detect flags
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Encoding
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* detects the source encoding of the string and if doesn't match
|
||||||
|
* to the given target encoding it convert is
|
||||||
|
* if source encoding is set and auto check is true (default) a second
|
||||||
|
* check is done so that the source string encoding actually matches
|
||||||
|
* will be skipped if source encoding detection is ascii
|
||||||
|
*
|
||||||
|
* @param string $string string to convert
|
||||||
|
* @param string $to_encoding target encoding
|
||||||
|
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||||
|
* @param bool $auto_check default true, if source encoding is set
|
||||||
|
* check that the source is actually matching
|
||||||
|
* to what we sav the source is
|
||||||
|
* @return string encoding converted string
|
||||||
|
*/
|
||||||
|
public static function convertEncoding(
|
||||||
|
string $string,
|
||||||
|
string $to_encoding,
|
||||||
|
string $source_encoding = '',
|
||||||
|
bool $auto_check = true
|
||||||
|
): string {
|
||||||
|
// set if not given
|
||||||
|
if (!$source_encoding) {
|
||||||
|
$source_encoding = mb_detect_encoding($string);
|
||||||
|
} else {
|
||||||
|
$_source_encoding = mb_detect_encoding($string);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$auto_check === true &&
|
||||||
|
isset($_source_encoding) &&
|
||||||
|
$_source_encoding == $source_encoding
|
||||||
|
) {
|
||||||
|
// trigger check if we have override source encoding.
|
||||||
|
// if different (_source is all but not ascii) then trigger
|
||||||
|
// skip if matching
|
||||||
|
}
|
||||||
|
if ($source_encoding != $to_encoding) {
|
||||||
|
if ($source_encoding) {
|
||||||
|
$string = mb_convert_encoding($string, $to_encoding, $source_encoding);
|
||||||
|
} else {
|
||||||
|
$string = mb_convert_encoding($string, $to_encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
256
www/vendor/egrajp/corelibs-composer-all/src/Convert/Extends/VarSetTypeMain.php
vendored
Normal file
256
www/vendor/egrajp/corelibs-composer-all/src/Convert/Extends/VarSetTypeMain.php
vendored
Normal file
@@ -0,0 +1,256 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run is_<type> checks and return default value if not this type
|
||||||
|
* This will return default null on invalid entries
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert\Extends;
|
||||||
|
|
||||||
|
class VarSetTypeMain
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* If input variable is string then returns it, else returns default set
|
||||||
|
* if not null is true, then null as return is allowed, else return is
|
||||||
|
* converted to string
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param string|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return string|null Input var or default value
|
||||||
|
*/
|
||||||
|
protected static function setStrMain(
|
||||||
|
mixed $val,
|
||||||
|
?string $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?string {
|
||||||
|
if (is_string($val)) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (string)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will convert input data to string if possible.
|
||||||
|
* Runs for string/int/float/bool/null
|
||||||
|
* Will skip array/object/resource/callable/etc and use default for that
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param string|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return string|null Converted input data to string/null
|
||||||
|
*/
|
||||||
|
protected static function makeStrMain(
|
||||||
|
mixed $val,
|
||||||
|
string $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?string {
|
||||||
|
// int/float/string/bool/null, everything else is ignored
|
||||||
|
// no: array/object/resource/callable
|
||||||
|
if (
|
||||||
|
is_int($val) ||
|
||||||
|
is_float($val) ||
|
||||||
|
is_string($val) ||
|
||||||
|
is_bool($val) ||
|
||||||
|
is_null($val)
|
||||||
|
) {
|
||||||
|
return (string)$val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (string)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If input variable is int, return it, else return default value. If to_null
|
||||||
|
* is true then null as return is allowed, else only int is returned
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param int|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return int|null Input var or default value
|
||||||
|
*/
|
||||||
|
protected static function setIntMain(
|
||||||
|
mixed $val,
|
||||||
|
?int $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?int {
|
||||||
|
if (is_int($val)) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (int)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert input to int via filter_var. If not convertable return default value.
|
||||||
|
* If to_null is set to true null return is allowed
|
||||||
|
* NOTE: this is only a drastic fallback and not recommned for special use.
|
||||||
|
* It will try to check via filter_var if we can get an int value and then use
|
||||||
|
* intval to convert it.
|
||||||
|
* Reason is that filter_var will convert eg 1.5 to 15 instead 1
|
||||||
|
* One is very wrong, the other is at least better, but not perfect
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param int|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return int|null Converted input data to int/null
|
||||||
|
*/
|
||||||
|
protected static function makeIntMain(
|
||||||
|
mixed $val,
|
||||||
|
int $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?int {
|
||||||
|
// if we can filter it to a valid int, we can convert it
|
||||||
|
// we so avoid object, array, etc
|
||||||
|
if (
|
||||||
|
filter_var(
|
||||||
|
$val,
|
||||||
|
FILTER_SANITIZE_NUMBER_INT
|
||||||
|
) !== false
|
||||||
|
) {
|
||||||
|
return intval($val);
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (int)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If input is float return it, else set to default value. If to_null is set
|
||||||
|
* to true, allow null return
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param float|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return float|null Input var or default value
|
||||||
|
*/
|
||||||
|
protected static function setFloatMain(
|
||||||
|
mixed $val,
|
||||||
|
?float $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?float {
|
||||||
|
if (is_float($val)) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (float)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert intput var to float via filter_var. If failed to so return default.
|
||||||
|
* If to_null is set to true allow null return
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param float|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return float|null Converted intput data to float/null
|
||||||
|
*/
|
||||||
|
protected static function makeFloatMain(
|
||||||
|
mixed $val,
|
||||||
|
float $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?float {
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
$val = filter_var(
|
||||||
|
$val,
|
||||||
|
FILTER_SANITIZE_NUMBER_FLOAT,
|
||||||
|
FILTER_FLAG_ALLOW_FRACTION
|
||||||
|
)
|
||||||
|
) !== false
|
||||||
|
) {
|
||||||
|
return (float)$val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (float)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If input var is array return it, else return default value. If to_null is
|
||||||
|
* set to true, allow null return
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param array<mixed>|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return array<mixed>|null Input var or default value
|
||||||
|
*/
|
||||||
|
protected static function setArrayMain(
|
||||||
|
mixed $val,
|
||||||
|
?array $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?array {
|
||||||
|
if (is_array($val)) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (array)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If input var is bool return it, else return default value. If to_null is
|
||||||
|
* set to true will allow null return.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param bool|null $default Default value
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return bool|null Input var or default value
|
||||||
|
*/
|
||||||
|
protected static function setBoolMain(
|
||||||
|
mixed $val,
|
||||||
|
?bool $default = null,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?bool {
|
||||||
|
if (is_bool($val)) {
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
if ($to_null === false) {
|
||||||
|
return (bool)$default;
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert anything to bool. If it is a string it will try to use the filter_var
|
||||||
|
* to convert know true/false strings.
|
||||||
|
* Else it uses (bool) to convert the rest
|
||||||
|
* If null is allowed, will return null
|
||||||
|
*
|
||||||
|
* @param mixed $val Input variable
|
||||||
|
* @param bool $default Default value if to_null if false
|
||||||
|
* @param bool $to_null Convert to null (default no)
|
||||||
|
* @return bool|null Converted input data to bool/ null
|
||||||
|
*/
|
||||||
|
protected static function makeBoolMain(
|
||||||
|
mixed $val,
|
||||||
|
bool $default = false,
|
||||||
|
bool $to_null = false
|
||||||
|
): ?bool {
|
||||||
|
$boolvar = is_string($val) ?
|
||||||
|
filter_var(
|
||||||
|
$val,
|
||||||
|
FILTER_VALIDATE_BOOLEAN,
|
||||||
|
FILTER_NULL_ON_FAILURE
|
||||||
|
) :
|
||||||
|
(bool)$val;
|
||||||
|
return $boolvar === null && !$to_null ? $default : $boolvar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
70
www/vendor/egrajp/corelibs-composer-all/src/Convert/Html.php
vendored
Normal file
70
www/vendor/egrajp/corelibs-composer-all/src/Convert/Html.php
vendored
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* html convert functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Html
|
||||||
|
{
|
||||||
|
public const SELECTED = 0;
|
||||||
|
public const CHECKED = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* full wrapper for html entities
|
||||||
|
*
|
||||||
|
* @param mixed $string string to html encode
|
||||||
|
* @return mixed if string, encoded, else as is (eg null)
|
||||||
|
*/
|
||||||
|
public static function htmlent($string)
|
||||||
|
{
|
||||||
|
if (is_string($string)) {
|
||||||
|
return htmlentities($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||||
|
} else {
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* strips out all line breaks or replaced with given string
|
||||||
|
* @param string $string string
|
||||||
|
* @param string $replace replace character, default ' '
|
||||||
|
* @return string cleaned string without any line breaks
|
||||||
|
*/
|
||||||
|
public static function removeLB(string $string, string $replace = ' '): string
|
||||||
|
{
|
||||||
|
return str_replace(["\n\r", "\r", "\n"], $replace, $string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns 'checked' or 'selected' if okay
|
||||||
|
* $needle is a var, $haystack an array or a string
|
||||||
|
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
|
||||||
|
*
|
||||||
|
* @param array<mixed>|string $haystack (search in) haystack can be
|
||||||
|
* an array or a string
|
||||||
|
* @param string $needle needle (search for)
|
||||||
|
* @param int $type type: 0: returns selected, 1,
|
||||||
|
* returns checked
|
||||||
|
* @return ?string returns checked or selected,
|
||||||
|
* else returns null
|
||||||
|
*/
|
||||||
|
public static function checked($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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
97
www/vendor/egrajp/corelibs-composer-all/src/Convert/Json.php
vendored
Normal file
97
www/vendor/egrajp/corelibs-composer-all/src/Convert/Json.php
vendored
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converts a json string to array and stores error for later checking
|
||||||
|
* can also return empty array on demand
|
||||||
|
* and self set json as is on error as array
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Json
|
||||||
|
{
|
||||||
|
/** @var int */
|
||||||
|
private static $json_last_error;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* converts a json string to an array
|
||||||
|
* or inits an empty array on null string
|
||||||
|
* or failed convert to array
|
||||||
|
* In ANY case it will ALWAYS return array.
|
||||||
|
* Does not throw errors
|
||||||
|
*
|
||||||
|
* @param string|null $json a json string, or null data
|
||||||
|
* @param bool $override if set to true, then on json error
|
||||||
|
* set original value as array
|
||||||
|
* @return array<mixed> returns an array from the json values
|
||||||
|
*/
|
||||||
|
public static function jsonConvertToArray(?string $json, bool $override = false): array
|
||||||
|
{
|
||||||
|
if ($json !== null) {
|
||||||
|
$_json = json_decode($json, true);
|
||||||
|
if (self::$json_last_error = json_last_error()) {
|
||||||
|
if ($override == true) {
|
||||||
|
// init return as array with original as element
|
||||||
|
$json = [$json];
|
||||||
|
} else {
|
||||||
|
$json = [];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$json = $_json;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$json = [];
|
||||||
|
}
|
||||||
|
// be sure that we return an array
|
||||||
|
return (array)$json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns human readable string for json errors thrown in jsonConvertToArray
|
||||||
|
*
|
||||||
|
* @param bool|boolean $return_string [default=false] if set to true
|
||||||
|
* it will return the message string and not
|
||||||
|
* the error number
|
||||||
|
* @return int|string Either error number (0 for no error)
|
||||||
|
* or error string ('' for no error)
|
||||||
|
*/
|
||||||
|
public static function jsonGetLastError(bool $return_string = false)
|
||||||
|
{
|
||||||
|
$json_error_string = '';
|
||||||
|
// valid errors as of php 8.0
|
||||||
|
switch (self::$json_last_error) {
|
||||||
|
case JSON_ERROR_NONE:
|
||||||
|
$json_error_string = '';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_DEPTH:
|
||||||
|
$json_error_string = 'Maximum stack depth exceeded';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_STATE_MISMATCH:
|
||||||
|
$json_error_string = 'Underflow or the modes mismatch';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_CTRL_CHAR:
|
||||||
|
$json_error_string = 'Unexpected control character found';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_SYNTAX:
|
||||||
|
$json_error_string = 'Syntax error, malformed JSON';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_UTF8:
|
||||||
|
$json_error_string = 'Malformed UTF-8 characters, possibly incorrectly encoded';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_INVALID_PROPERTY_NAME:
|
||||||
|
$json_error_string = 'A key starting with \u0000 character was in the string';
|
||||||
|
break;
|
||||||
|
case JSON_ERROR_UTF16:
|
||||||
|
$json_error_string = 'Single unpaired UTF-16 surrogate in unicode escape';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$json_error_string = 'Unknown error';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $return_string === true ? $json_error_string : self::$json_last_error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
61
www/vendor/egrajp/corelibs-composer-all/src/Convert/Math.php
vendored
Normal file
61
www/vendor/egrajp/corelibs-composer-all/src/Convert/Math.php
vendored
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* various math related function wrappers
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Math
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* some float numbers will be rounded up even if they have no decimal entries
|
||||||
|
* this function fixes this by pre-rounding before calling ceil
|
||||||
|
*
|
||||||
|
* @param float $number number to round
|
||||||
|
* @param int|integer $precision intermediat round up decimals (default 10)
|
||||||
|
* @return float correct ceil number
|
||||||
|
*/
|
||||||
|
public static function fceil(float $number, int $precision = 10): float
|
||||||
|
{
|
||||||
|
return ceil(round($number, $precision));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* round inside an a number, not the decimal part only
|
||||||
|
* eg 48767 with -2 -> 48700
|
||||||
|
*
|
||||||
|
* @param float $number number to round
|
||||||
|
* @param int $precision negative number for position in number (default -2)
|
||||||
|
* @return float rounded number
|
||||||
|
*/
|
||||||
|
public static function floorp(float $number, int $precision = -2): float
|
||||||
|
{
|
||||||
|
// if precision is requal or larger than the number length,
|
||||||
|
// set precision to length -1
|
||||||
|
if (abs($precision) >= strlen((string)$number)) {
|
||||||
|
$precision = (strlen((string)$number) - 1) * -1;
|
||||||
|
}
|
||||||
|
$mult = pow(10, $precision); // Can be cached in lookup table
|
||||||
|
return floor($number * $mult) / $mult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inits input to 0, if value is not numeric
|
||||||
|
*
|
||||||
|
* @param string|int|float $number string or number to check
|
||||||
|
* @return float if not number, then returns 0, else original input
|
||||||
|
*/
|
||||||
|
public static function initNumeric($number): float
|
||||||
|
{
|
||||||
|
if (!is_numeric($number)) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return (float)$number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
85
www/vendor/egrajp/corelibs-composer-all/src/Convert/MimeAppName.php
vendored
Normal file
85
www/vendor/egrajp/corelibs-composer-all/src/Convert/MimeAppName.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Translates a mime id string into the actual application or file name
|
||||||
|
* for example 'text/plain' will output 'Text file'
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class MimeAppName
|
||||||
|
{
|
||||||
|
/** @var array<string,string> */
|
||||||
|
private static $mime_apps = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor: init mime list
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
self::$mime_apps = [
|
||||||
|
// zip
|
||||||
|
'application/zip' => 'Zip File',
|
||||||
|
// Powerpoint
|
||||||
|
'application/vnd.ms-powerpoint' => 'Microsoft Powerpoint',
|
||||||
|
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'Microsoft Powerpoint',
|
||||||
|
// PDF
|
||||||
|
'pplication/pdf' => 'PDF',
|
||||||
|
// JPEG
|
||||||
|
'image/jpeg' => 'JPEG',
|
||||||
|
// PNG
|
||||||
|
'image/png' => 'PNG',
|
||||||
|
// Indesign
|
||||||
|
'application/x-indesign' => 'Adobe InDesign',
|
||||||
|
// Photoshop
|
||||||
|
'image/vnd.adobe.photoshop' => 'Adobe Photoshop',
|
||||||
|
'application/photoshop' => 'Adobe Photoshop',
|
||||||
|
// Illustrator
|
||||||
|
'application/illustrator' => 'Adobe Illustrator',
|
||||||
|
// Word
|
||||||
|
'application/vnd.ms-word' => 'Microsoft Word',
|
||||||
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'Microsoft Word',
|
||||||
|
// Excel
|
||||||
|
'application/vnd.ms-excel' => 'Microsoft Excel',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'Microsoft Excel',
|
||||||
|
// plain text
|
||||||
|
'text/plain' => 'Text file',
|
||||||
|
// html
|
||||||
|
'text/html' => 'HTML',
|
||||||
|
// mp4 (max 45MB each)
|
||||||
|
'video/mpeg' => 'MPEG Video'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or updates a mime type
|
||||||
|
*
|
||||||
|
* @param string $mime MIME Name, no validiation
|
||||||
|
* @param string $app Applicaiton name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function mimeSetAppName(string $mime, string $app): void
|
||||||
|
{
|
||||||
|
// if empty, don't set
|
||||||
|
if (empty($mime) || empty($app)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self::$mime_apps[$mime] = $app;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the application name from mime type
|
||||||
|
* if not set returns "Other file"
|
||||||
|
*
|
||||||
|
* @param string $mime MIME Name
|
||||||
|
* @return string Application name matching
|
||||||
|
*/
|
||||||
|
public static function mimeGetAppName(string $mime): string
|
||||||
|
{
|
||||||
|
return self::$mime_apps[$mime] ?? 'Other file';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
71
www/vendor/egrajp/corelibs-composer-all/src/Convert/MimeEncode.php
vendored
Normal file
71
www/vendor/egrajp/corelibs-composer-all/src/Convert/MimeEncode.php
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* alternate for header mime encode to void problems with long strings and
|
||||||
|
* spaces/strange encoding problems.
|
||||||
|
* Orignal issues during PHP5/7
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class MimeEncode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* wrapper function for mb mime convert
|
||||||
|
* for correct conversion with long strings
|
||||||
|
*
|
||||||
|
* @param string $string string to encode
|
||||||
|
* @param string $encoding target encoding
|
||||||
|
* @param string $line_break default line break is \r\n
|
||||||
|
* @return string encoded string
|
||||||
|
*/
|
||||||
|
public static function __mbMimeEncode(
|
||||||
|
string $string,
|
||||||
|
string $encoding,
|
||||||
|
string $line_break = "\r\n"
|
||||||
|
): string {
|
||||||
|
$current_internal_encoding = mb_internal_encoding();
|
||||||
|
// set internal encoding, so the mimeheader encode works correctly
|
||||||
|
mb_internal_encoding($encoding);
|
||||||
|
// if a subject, make a work around for the broken mb_mimencode
|
||||||
|
$pos = 0;
|
||||||
|
// after 36 single bytes characters,
|
||||||
|
// if then comes MB, it is broken
|
||||||
|
// has to 2 x 36 < 74 so the mb_encode_mimeheader
|
||||||
|
// 74 hardcoded split does not get triggered
|
||||||
|
$split = 36;
|
||||||
|
$_string = '';
|
||||||
|
while ($pos < mb_strlen($string, $encoding)) {
|
||||||
|
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
|
||||||
|
$pos += mb_strlen($output, $encoding);
|
||||||
|
// if the strinlen is 0 here, get out of the loop
|
||||||
|
if (!mb_strlen($output, $encoding)) {
|
||||||
|
$pos += mb_strlen($string, $encoding);
|
||||||
|
}
|
||||||
|
$_string_encoded = mb_encode_mimeheader($output, $encoding);
|
||||||
|
// only make linebreaks if we have mime encoded code inside
|
||||||
|
// the space only belongs in the second line
|
||||||
|
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
|
||||||
|
$_string .= $line_break . " ";
|
||||||
|
} elseif (
|
||||||
|
// hack for plain text with space at the end
|
||||||
|
mb_strlen($output, $encoding) == $split &&
|
||||||
|
mb_substr($output, -1, 1, $encoding) == " "
|
||||||
|
) {
|
||||||
|
// if output ends with space, add one more
|
||||||
|
$_string_encoded .= " ";
|
||||||
|
}
|
||||||
|
$_string .= $_string_encoded;
|
||||||
|
}
|
||||||
|
// strip out any spaces BEFORE a line break
|
||||||
|
$string = str_replace(" " . $line_break, $line_break, $_string);
|
||||||
|
// before we end, reset internal encoding
|
||||||
|
mb_internal_encoding($current_internal_encoding);
|
||||||
|
// return mime encoded string
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
123
www/vendor/egrajp/corelibs-composer-all/src/Convert/Strings.php
vendored
Normal file
123
www/vendor/egrajp/corelibs-composer-all/src/Convert/Strings.php
vendored
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* string convert and transform functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Strings
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* return the number of elements in the split list
|
||||||
|
* 0 if nothing / invalid split
|
||||||
|
* 1 if no split character found
|
||||||
|
* n for the numbers in the split list
|
||||||
|
*
|
||||||
|
* @param string $split_format
|
||||||
|
* @param string $split_characters
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function countSplitParts(
|
||||||
|
string $split_format,
|
||||||
|
string $split_characters = '-'
|
||||||
|
): int {
|
||||||
|
if (
|
||||||
|
empty($split_format) ||
|
||||||
|
// non valid characters inside, abort
|
||||||
|
!preg_match("/^[0-9" . $split_characters . "]/", $split_format) ||
|
||||||
|
preg_match('/[^\x20-\x7e]/', $split_characters)
|
||||||
|
) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$split_list = preg_split(
|
||||||
|
// allowed split characters
|
||||||
|
"/([" . $split_characters . "]{1})/",
|
||||||
|
$split_format
|
||||||
|
);
|
||||||
|
if (!is_array($split_list)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return count(array_filter($split_list));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* split format a string base on a split format string
|
||||||
|
* split format string is eg
|
||||||
|
* 4-4-4 that means 4 characters DASH 4 characters DASH 4 characters
|
||||||
|
* So a string in the format of
|
||||||
|
* ABCD1234EFGH will be ABCD-1234-EFGH
|
||||||
|
* Note a string LONGER then the maxium will be attached with the LAST
|
||||||
|
* split character. In above exmaple
|
||||||
|
* ABCD1234EFGHTOOLONG will be ABCD-1234-EFGH-TOOLONG
|
||||||
|
*
|
||||||
|
* @param string $value string value to split
|
||||||
|
* @param string $split_format split format
|
||||||
|
* @param string $split_characters list of charcters with which we split
|
||||||
|
* if not set uses dash ('-')
|
||||||
|
* @return string split formatted string or original value if not chnaged
|
||||||
|
*/
|
||||||
|
public static function splitFormatString(
|
||||||
|
string $value,
|
||||||
|
string $split_format,
|
||||||
|
string $split_characters = '-'
|
||||||
|
): string {
|
||||||
|
if (
|
||||||
|
// abort if split format is empty
|
||||||
|
empty($split_format) ||
|
||||||
|
// if not in the valid ASCII character range for any of the strings
|
||||||
|
preg_match('/[^\x20-\x7e]/', $value) ||
|
||||||
|
// preg_match('/[^\x20-\x7e]/', $split_format) ||
|
||||||
|
preg_match('/[^\x20-\x7e]/', $split_characters) ||
|
||||||
|
// only numbers and split characters in split_format
|
||||||
|
!preg_match("/[0-9" . $split_characters . "]/", $split_format)
|
||||||
|
) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
// split format list
|
||||||
|
$split_list = preg_split(
|
||||||
|
// allowed split characters
|
||||||
|
"/([" . $split_characters . "]{1})/",
|
||||||
|
$split_format,
|
||||||
|
-1,
|
||||||
|
PREG_SPLIT_DELIM_CAPTURE
|
||||||
|
);
|
||||||
|
// if this is false, or only one array, abort split
|
||||||
|
if (!is_array($split_list) || count($split_list) == 1) {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
$out = '';
|
||||||
|
$pos = 0;
|
||||||
|
$last_split = '';
|
||||||
|
foreach ($split_list as $offset) {
|
||||||
|
if (is_numeric($offset)) {
|
||||||
|
$_part = substr($value, $pos, (int)$offset);
|
||||||
|
if (empty($_part)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$out .= $_part;
|
||||||
|
$pos += (int)$offset;
|
||||||
|
} elseif ($pos) { // if first, do not add
|
||||||
|
$out .= $offset;
|
||||||
|
$last_split = $offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($out) && $pos < strlen($value)) {
|
||||||
|
$out .= $last_split . substr($value, $pos);
|
||||||
|
}
|
||||||
|
// if last is not alphanumeric remove, remove
|
||||||
|
if (!strcspn(substr($out, -1, 1), $split_characters)) {
|
||||||
|
$out = substr($out, 0, -1);
|
||||||
|
}
|
||||||
|
// overwrite only if out is set
|
||||||
|
if (!empty($out)) {
|
||||||
|
return $out;
|
||||||
|
} else {
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
136
www/vendor/egrajp/corelibs-composer-all/src/Convert/VarSetType.php
vendored
Normal file
136
www/vendor/egrajp/corelibs-composer-all/src/Convert/VarSetType.php
vendored
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run is_<type> checks and return default value if not this type
|
||||||
|
* This will return a default value as always what is expected and never null
|
||||||
|
* Use this for santize output from multi return functions where we know what
|
||||||
|
* will come back
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
use CoreLibs\Convert\Extends\VarSetTypeMain;
|
||||||
|
|
||||||
|
class VarSetType extends Extends\VarSetTypeMain
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Check is input is string, if not return default string.
|
||||||
|
* Will always return string
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param string $default Default override value
|
||||||
|
* @return string Input value or default as string
|
||||||
|
*/
|
||||||
|
public static function setStr(mixed $val, string $default = ''): string
|
||||||
|
{
|
||||||
|
return (string)VarSetTypeMain::setStrMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert input to string if possible.
|
||||||
|
* Will only work on string/int/float/bool/null types
|
||||||
|
* Will always return string
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param string $default Default override value
|
||||||
|
* @return string Input value as string or default as string
|
||||||
|
*/
|
||||||
|
public static function makeStr(mixed $val, string $default = ''): string
|
||||||
|
{
|
||||||
|
return (string)VarSetTypeMain::makeStrMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is int, if not return default int value 0.
|
||||||
|
* Will always return int.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param int $default Default override value
|
||||||
|
* @return int Input value or default as int
|
||||||
|
*/
|
||||||
|
public static function setInt(mixed $val, int $default = 0): int
|
||||||
|
{
|
||||||
|
return (int)VarSetTypeMain::setIntMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert intput to int if possible, if not return default value 0.
|
||||||
|
* Will always return int.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param int $default Default override value
|
||||||
|
* @return int Input value as int or default as int
|
||||||
|
*/
|
||||||
|
public static function makeInt(mixed $val, int $default = 0): int
|
||||||
|
{
|
||||||
|
return (int)VarSetTypeMain::makeIntMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is float, if not return default value value 0.0.
|
||||||
|
* Will always return float
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param float $default Default override value
|
||||||
|
* @return float Input value or default as float
|
||||||
|
*/
|
||||||
|
public static function setFloat(mixed $val, float $default = 0.0): float
|
||||||
|
{
|
||||||
|
return (float)VarSetTypeMain::setFloatMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert input to float, if not possible return default value 0.0.
|
||||||
|
* Will always return float
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param float $default Default override value
|
||||||
|
* @return float Input value as float or default as float
|
||||||
|
*/
|
||||||
|
public static function makeFloat(mixed $val, float $default = 0.0): float
|
||||||
|
{
|
||||||
|
return (float)VarSetTypeMain::makeFloatMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is array, if not return default empty array.
|
||||||
|
* Will always return array.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param array<mixed> $default Default override value
|
||||||
|
* @return array<mixed> Input value or default as array
|
||||||
|
*/
|
||||||
|
public static function setArray(mixed $val, array $default = []): array
|
||||||
|
{
|
||||||
|
return (array)VarSetTypeMain::setArrayMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is bool, if not will return default value false.
|
||||||
|
* Will aways return bool.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param bool $default Default override value
|
||||||
|
* @return bool Input value or default as bool
|
||||||
|
*/
|
||||||
|
public static function setBool(mixed $val, bool $default = false): bool
|
||||||
|
{
|
||||||
|
return (bool)VarSetTypeMain::setBoolMain($val, $default, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert anything to bool
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param bool $default Default override value
|
||||||
|
* @return bool Input value as bool or default as bool
|
||||||
|
*/
|
||||||
|
public static function makeBool(mixed $val, bool $default = false): bool
|
||||||
|
{
|
||||||
|
return (bool)VarSetTypeMain::makeBoolMain($val, $default, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
130
www/vendor/egrajp/corelibs-composer-all/src/Convert/VarSetTypeNull.php
vendored
Normal file
130
www/vendor/egrajp/corelibs-composer-all/src/Convert/VarSetTypeNull.php
vendored
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run is_<type> checks and return default value if not this type
|
||||||
|
* This will return default null on invalid entries
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
use CoreLibs\Convert\Extends\VarSetTypeMain;
|
||||||
|
|
||||||
|
class VarSetTypeNull extends Extends\VarSetTypeMain
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Check is input is string, if not return default string.
|
||||||
|
* Will return null if no string as default.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param string|null $default Default override value
|
||||||
|
* @return string|null Input value or default as string/null
|
||||||
|
*/
|
||||||
|
public static function setStr(mixed $val, ?string $default = null): ?string
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::setStrMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert input to string if possible.
|
||||||
|
* Will only work on string/int/float/bool/null types.
|
||||||
|
* Will return null if convert failed as default.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::makeStrMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is int, if not return default value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value
|
||||||
|
* @param int|null $default Default override value
|
||||||
|
* @return int|null Input value or default as int/null
|
||||||
|
*/
|
||||||
|
public static function setInt(mixed $val, ?int $default = null): ?int
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::setIntMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert intput to int if possible, if not return default value value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::makeIntMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is float, if not return default value value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @param float|null $default Default override value
|
||||||
|
* @return float|null Input value or default as float/null
|
||||||
|
*/
|
||||||
|
public static function setFloat(mixed $val, ?float $default = null): ?float
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::setFloatMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert input to float, if not possible return default value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @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
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::makeFloatMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is array, if not return default value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @param array<mixed>|null $default Default override value
|
||||||
|
* @return array<mixed>|null Input value or default as array/null
|
||||||
|
*/
|
||||||
|
public static function setArray(mixed $val, ?array $default = null): ?array
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::setArrayMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if input is bool, if not will return default value null.
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @param bool|null $default Default override value
|
||||||
|
* @return bool|null Input value or default as bool/null
|
||||||
|
*/
|
||||||
|
public static function setBool(mixed $val, ?bool $default = null): ?bool
|
||||||
|
{
|
||||||
|
return VarSetTypeMain::setBoolMain($val, $default, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert anything to bool
|
||||||
|
*
|
||||||
|
* @param mixed $val Input value $val
|
||||||
|
* @return bool|null Input value as bool or default as bool/null
|
||||||
|
*/
|
||||||
|
public static function makeBool(mixed $val): ?bool
|
||||||
|
{
|
||||||
|
// note that the default value here is irrelevant, we return null
|
||||||
|
// on unsetable string var
|
||||||
|
return VarSetTypeMain::makeBoolMain($val, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
291
www/vendor/egrajp/corelibs-composer-all/src/Create/Email.php
vendored
Normal file
291
www/vendor/egrajp/corelibs-composer-all/src/Create/Email.php
vendored
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create email class
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Create;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sending simple text emails
|
||||||
|
*/
|
||||||
|
class Email
|
||||||
|
{
|
||||||
|
/** @var array<string> allowed list for encodings that can do KV folding */
|
||||||
|
private static $encoding_kv_allowed = [
|
||||||
|
'UTF-8',
|
||||||
|
'EUC-JP',
|
||||||
|
'SJIS',
|
||||||
|
'SJIS-win',
|
||||||
|
'ISO-2022-JP',
|
||||||
|
'ISO-2022-JP-MS',
|
||||||
|
'JIS',
|
||||||
|
'JIS-ms',
|
||||||
|
];
|
||||||
|
/** @var string normaly this does not need to be changed */
|
||||||
|
private static $mb_convert_kana_mode = 'KV';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create mime encoded email part for to/from emails.
|
||||||
|
* If encoding is not UTF-8 it will convert the email name to target encoding
|
||||||
|
* FROM UTF-8
|
||||||
|
* Source data is ALWAYS seen as utf-8
|
||||||
|
*
|
||||||
|
* @param string $email E-Mail address
|
||||||
|
* @param string $email_name Name for the email address, in UTF-8, if not set, empty
|
||||||
|
* @param string $encoding Encoding, if not set UTF-8
|
||||||
|
* @param bool $kv_folding If set to true and a valid encoding, do KV folding
|
||||||
|
* @return string Correctly encoded and build email string
|
||||||
|
*/
|
||||||
|
public static function encodeEmailName(
|
||||||
|
string $email,
|
||||||
|
string $email_name = '',
|
||||||
|
string $encoding = 'UTF-8',
|
||||||
|
bool $kv_folding = false
|
||||||
|
): string {
|
||||||
|
if (empty($email_name)) {
|
||||||
|
return $email;
|
||||||
|
}
|
||||||
|
// if encoding is not UTF-8 then we convert
|
||||||
|
if ($encoding != 'UTF-8') {
|
||||||
|
$email_name = mb_convert_encoding($email_name, $encoding, 'UTF-8');
|
||||||
|
}
|
||||||
|
$email_name =
|
||||||
|
mb_encode_mimeheader(
|
||||||
|
in_array($encoding, self::$encoding_kv_allowed) && $kv_folding ?
|
||||||
|
mb_convert_kana(
|
||||||
|
$email_name,
|
||||||
|
self::$mb_convert_kana_mode,
|
||||||
|
$encoding
|
||||||
|
) :
|
||||||
|
$email_name,
|
||||||
|
$encoding
|
||||||
|
);
|
||||||
|
return '"' . $email_name . '" '
|
||||||
|
. '<' . (string)$email . '>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subject/Body replace sub function
|
||||||
|
*
|
||||||
|
* @param string $subject Subject string, in UTF-8
|
||||||
|
* @param string $body Body string, in UTF-8
|
||||||
|
* @param array<string,string> $replace Replace the array as key -> value, in UTF-8
|
||||||
|
* @param string $encoding Encoding for subject encode mime header
|
||||||
|
* @param bool $kv_folding If set to true and a valid encoding,
|
||||||
|
* do KV folding
|
||||||
|
* @return array<string> Pos 0: Subject, Pos 1: Body
|
||||||
|
*/
|
||||||
|
private static function replaceContent(
|
||||||
|
string $subject,
|
||||||
|
string $body,
|
||||||
|
array $replace,
|
||||||
|
string $encoding,
|
||||||
|
bool $kv_folding
|
||||||
|
): array {
|
||||||
|
foreach (['subject', 'body'] as $element) {
|
||||||
|
$$element = str_replace(
|
||||||
|
array_map(
|
||||||
|
function ($key) {
|
||||||
|
return '{' . $key . '}';
|
||||||
|
},
|
||||||
|
array_keys($replace)
|
||||||
|
),
|
||||||
|
array_values($replace),
|
||||||
|
$$element
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// if encoding is NOT UTF-8 convert to target
|
||||||
|
if ($encoding != 'UTF-8') {
|
||||||
|
$subject = mb_convert_encoding($subject, $encoding, 'UTF-8');
|
||||||
|
$body = mb_convert_encoding($body, $encoding, 'UTF-8');
|
||||||
|
}
|
||||||
|
// we need to encodde the subject
|
||||||
|
$subject = mb_encode_mimeheader(
|
||||||
|
in_array($encoding, self::$encoding_kv_allowed) && $kv_folding ?
|
||||||
|
// for any non UTF-8 encoding convert kana
|
||||||
|
mb_convert_kana(
|
||||||
|
$subject,
|
||||||
|
self::$mb_convert_kana_mode,
|
||||||
|
$encoding
|
||||||
|
) :
|
||||||
|
$subject,
|
||||||
|
$encoding
|
||||||
|
);
|
||||||
|
return [$subject, $body];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send plain text email with possible to replace subject/body data
|
||||||
|
* either global or per to email set.
|
||||||
|
* replace to tags are in {} in the subject or body
|
||||||
|
*
|
||||||
|
* @param string $subject Mail subject, mandatory, in UTF-8
|
||||||
|
* @param string $body Mail body, mandatory, in UTF-8
|
||||||
|
* @param string $from_email From email, mandatory
|
||||||
|
* @param string $from_name From email name, in UTF-8
|
||||||
|
* if empty '' then not set
|
||||||
|
* @param array<mixed> $send_to_emails to email or array for email/replace
|
||||||
|
* If array: name/email/replace[key,value]
|
||||||
|
* name and replace must be in UTF-8
|
||||||
|
* At least one must be set
|
||||||
|
* @param array<string,string> $replace_content Subject/Body replace as
|
||||||
|
* search -> replace, in UTF-8
|
||||||
|
* @param string $encoding E-Mail encoding, default UTF-8
|
||||||
|
* @param bool $kv_folding If set to true and a valid encoding,
|
||||||
|
* do KV folding
|
||||||
|
* @param bool $test test flag, default off
|
||||||
|
* @param \CoreLibs\Debug\Logging|null $log Logging class,
|
||||||
|
* only used if test flag is true
|
||||||
|
* @return int 2 test only, no sent
|
||||||
|
* 1 for ok,
|
||||||
|
* 0 for send not ok
|
||||||
|
* -1 for nothing set (emails, subject, body)
|
||||||
|
* -2 for empty to list
|
||||||
|
* -3 encoding target not valid or not installed
|
||||||
|
*/
|
||||||
|
public static function sendEmail(
|
||||||
|
string $subject,
|
||||||
|
string $body,
|
||||||
|
string $from_email,
|
||||||
|
string $from_name,
|
||||||
|
array $send_to_emails,
|
||||||
|
array $replace_content = [],
|
||||||
|
string $encoding = 'UTF-8',
|
||||||
|
bool $kv_folding = false,
|
||||||
|
bool $test = false,
|
||||||
|
?\CoreLibs\Debug\Logging $log = null
|
||||||
|
): int {
|
||||||
|
/** @var array<string> */
|
||||||
|
$to_emails = [];
|
||||||
|
/** @var array<string,array<string,string>> */
|
||||||
|
$to_replace = [];
|
||||||
|
/** @var string */
|
||||||
|
$out_subject = $subject;
|
||||||
|
/** @var string */
|
||||||
|
$out_body = $body;
|
||||||
|
// check basic set
|
||||||
|
if (empty($subject) || empty($body) || empty($from_email)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$encoding != 'UTF-8' &&
|
||||||
|
!in_array($encoding, mb_list_encodings())
|
||||||
|
) {
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
// if not one valid to, abort
|
||||||
|
foreach ($send_to_emails as $to_email) {
|
||||||
|
// to_email can be string, then only to email
|
||||||
|
// else expect 'email' & 'name'
|
||||||
|
if (
|
||||||
|
is_array($to_email) &&
|
||||||
|
isset($to_email['email'])
|
||||||
|
) {
|
||||||
|
$_to_email = self::encodeEmailName(
|
||||||
|
$to_email['email'],
|
||||||
|
$to_email['name'] ?? '',
|
||||||
|
$encoding,
|
||||||
|
$kv_folding
|
||||||
|
);
|
||||||
|
$to_emails[] = $_to_email;
|
||||||
|
// if we have to replacement, this override replace content
|
||||||
|
if (isset($to_email['replace']) && count($to_email['replace'])) {
|
||||||
|
// merge with original replace content,
|
||||||
|
// to data will override original data
|
||||||
|
$to_replace[$_to_email] = array_merge(
|
||||||
|
$replace_content,
|
||||||
|
$to_email['replace']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} elseif (is_string($to_email)) {
|
||||||
|
$to_emails[] = $to_email;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!count($to_emails)) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the email headers needed
|
||||||
|
$headers = [
|
||||||
|
'From' => self::encodeEmailName($from_email, $from_name, $encoding),
|
||||||
|
'Content-type' => "text/plain; charset=" . $encoding,
|
||||||
|
'MIME-Version' => "1.0",
|
||||||
|
];
|
||||||
|
|
||||||
|
// if we have a replace string, we need to do replace run
|
||||||
|
// only if there is no dedicated to replace
|
||||||
|
// also run replace if there is nothing to replace at all
|
||||||
|
// this will mime encode the subject
|
||||||
|
if (!count($to_replace)) {
|
||||||
|
list($out_subject, $out_body) = self::replaceContent(
|
||||||
|
$subject,
|
||||||
|
$body,
|
||||||
|
$replace_content,
|
||||||
|
$encoding,
|
||||||
|
$kv_folding
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail_delivery_status = 1;
|
||||||
|
// send the email
|
||||||
|
foreach ($to_emails as $to_email) {
|
||||||
|
// default mail status is success
|
||||||
|
$mail_status = true;
|
||||||
|
// if there is a to replace, if not use the original replace content
|
||||||
|
if (count($to_replace)) {
|
||||||
|
$_replace = [];
|
||||||
|
if (!empty($to_replace[$to_email])) {
|
||||||
|
$_replace = $to_replace[$to_email];
|
||||||
|
} elseif (count($replace_content)) {
|
||||||
|
$_replace = $replace_content;
|
||||||
|
}
|
||||||
|
if (count($_replace)) {
|
||||||
|
list($out_subject, $out_body) = self::replaceContent(
|
||||||
|
$subject,
|
||||||
|
$body,
|
||||||
|
$_replace,
|
||||||
|
$encoding,
|
||||||
|
$kv_folding
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if we are in test mode, do not send an email and set status to 2
|
||||||
|
if ($test === false) {
|
||||||
|
$mail_status = mail($to_email, $out_subject, $out_body, $headers);
|
||||||
|
} else {
|
||||||
|
$mail_delivery_status = 2;
|
||||||
|
}
|
||||||
|
// log if an log instance exists
|
||||||
|
if ($log instanceof \CoreLibs\Debug\Logging) {
|
||||||
|
// build debug strings: convert to UTF-8 if not utf-8
|
||||||
|
$log->debug('SEND EMAIL', 'HEADERS: ' . $log->prAr($headers) . ', '
|
||||||
|
. 'ENCODING: ' . $encoding . ', '
|
||||||
|
. 'KV FOLDING: ' . $log->prBl($kv_folding) . ', '
|
||||||
|
. 'TO: ' . $to_email . ', '
|
||||||
|
. 'SUBJECT: ' . $out_subject . ', '
|
||||||
|
. 'BODY: ' . ($encoding == 'UTF-8' ?
|
||||||
|
$out_body :
|
||||||
|
mb_convert_encoding($out_body, 'UTF-8', $encoding)));
|
||||||
|
$log->debug('SEND EMAIL JSON', json_encode([
|
||||||
|
'encoding' => $encoding,
|
||||||
|
'kv_folding' => $kv_folding,
|
||||||
|
'header' => $headers,
|
||||||
|
'to' => $to_email,
|
||||||
|
'subject' => $out_subject,
|
||||||
|
'body' => ($encoding == 'UTF-8' ?
|
||||||
|
$out_body :
|
||||||
|
mb_convert_encoding($out_body, 'UTF-8', $encoding))
|
||||||
|
]) ?: '{}');
|
||||||
|
}
|
||||||
|
if (!$mail_status) {
|
||||||
|
$mail_delivery_status = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $mail_delivery_status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user