* commit 5cec54d508fd4a34de509b3ac28d6277b6abc090 (HEAD -> master, all/master, all/development, all/NewFeatures) | log size 644 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-09-20 13:33:19 +0900 | | Add "Success" to message logging levels, fixes for PHP 8.4, other preg_match fixes | | The Logger/MessageLevel gets "success" as level 110 to something a bit | heigher than "ok" which is the general "OK" for anything ending without | an error. The "success" is currently only used in file uploads with the | java script ajax file uploader | | Fix any "type $var = null" with correctly "?type $var = null" for PHP 8.4 (phphan) | | Fix preg match no return catches for DB IO compare version and for language | look up. | | 4dev/tests/Logging/CoreLibsLoggingErrorMessagesTest.php | 5 +++++ | www/admin/class_test.html.php | 1 + | www/admin/class_test.php | 2 +- | www/admin/layout/javascript/edit.jq.js | 2 +- | www/lib/CoreLibs/Admin/Backend.php | 6 +++--- | www/lib/CoreLibs/Basic.php | 2 +- | www/lib/CoreLibs/Convert/Extends/SetVarTypeMain.php | 6 +++--- | www/lib/CoreLibs/Convert/SetVarTypeNull.php | 6 +++--- | www/lib/CoreLibs/DB/IO.php | 24 ++++++++++++++++++------ | www/lib/CoreLibs/Language/GetLocale.php | 4 ++-- | www/lib/CoreLibs/Logging/Logger/MessageLevel.php | 2 ++ | www/lib/CoreLibs/Output/Form/Elements.php | 12 ++++++------ | www/lib/CoreLibs/Template/HtmlBuilder/Element.php | 4 ++-- | 13 files changed, 48 insertions(+), 28 deletions(-) | * commit 8e60c992f109993b40d9e5ec9354ffb7d7db9f79 | log size 123 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-09-03 12:06:01 +0900 | | Fixes phan/phpstan | | phpstan.neon | 6 +++--- | www/lib/CoreLibs/Get/System.php | 2 +- | www/lib/CoreLibs/Template/HtmlBuilder/Block.php | 4 ---- | 3 files changed, 4 insertions(+), 8 deletions(-) | * commit 1b5437b675f6ceda4318f19522d47a08f28f95a8 | log size 147 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-09-03 11:58:36 +0900 | | Add testing for new added bom utf8 replace | | 4dev/tests/Convert/CoreLibsConvertStringsTest.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ | 4dev/tests/Convert/data/UTF8.csv | 1 + | 4dev/tests/Convert/data/UTF8BOM.csv | 1 + | 4dev/tests/Get/CoreLibsGetSystemTest.php | 23 +++++++++++++++++++++++ | www/admin/class_test.system.php | 4 +++- | 5 files changed, 76 insertions(+), 1 deletion(-) | * commit ef80cba5610b8acae8fc11d3f0a441c1f5a03735 | log size 659 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-09-03 09:49:01 +0900 | | Add new functions: get IPs, strip UTF8 BOM from text, text updates | | Add the following new static methods | | Convert\Strings::stripUTF8BomBytes: removes the UTF8 BOM bytes from the beginning of a line | Used for CSV files created in Excel for the first header entry (line 0/row 0) | | Get\Systen::getIpAddresses: gets all IP addresses for the the current access user | and returns an array | | Moved the frontend folder detection from the first load config to the config.path.php | | Cleaned up the translations JS scripts | | 4dev/bin/create_mo.sh | 9 +++++---- | 4dev/bin/mo_to_js.sh | 63 +++++++++++++++++++++++++++++++++++---------------------------- | www/configs/config.path.php | 16 +++++++++++++++- | www/configs/config.php | 15 +-------------- | www/lib/CoreLibs/Convert/Strings.php | 12 ++++++++++++ | www/lib/CoreLibs/DB/IO.php | 2 +- | www/lib/CoreLibs/Get/System.php | 23 +++++++++++++++++++++++ | www/lib/CoreLibs/Template/HtmlBuilder/Block.php | 37 ++++++++++++++++++++++++++----------- | 8 files changed, 118 insertions(+), 59 deletions(-) | * commit 2d71e760e8fb7b4b0a5552a2f62bedffad928f4f | log size 120 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-08-21 11:45:17 +0900 | | Composer update | | www/composer.lock | 12 ++++++------ | www/lib/CoreLibs/Template/SmartyExtend.php | 3 ++- | www/vendor/composer/installed.json | 14 +++++++------- | www/vendor/composer/installed.php | 6 +++--- | www/vendor/gullevek/dotenv/Readme.md | 23 +++++++++++++++++++++++ | www/vendor/gullevek/dotenv/src/DotEnv.php | 13 ++++++++++--- | 6 files changed, 51 insertions(+), 20 deletions(-) | * commit a8d07634ffaf961a37557437aac1f202ae18fa6e | log size 182 | Author: Clemens Schwaighofer <clemens.schwaighofer@egplusww.com> | Date: 2024-08-07 13:41:09 +0900 | | Add soba.egplusww.jp as local development host, jshint esversion update to 11 | | www/admin/layout/javascript/edit.jq.js | 2 +- | www/configs/config.host.php | 28 +++++++++++----------------- | 2 files changed, 12 insertions(+), 18 deletions(-) |
255 lines
7.1 KiB
PHP
255 lines
7.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Internal function for getting locale and encodig settings
|
|
* used for new locale layout
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace CoreLibs\Language;
|
|
|
|
class GetLocale
|
|
{
|
|
/**
|
|
* returns locale, lang, domain, encoding, path
|
|
* from either parameter set or from sessions/config variables
|
|
* NOTE: named constant usage is deprecated and will be removed in future
|
|
*
|
|
* @param string|null $locale override auto detect
|
|
* @param string|null $domain override domain
|
|
* @param string|null $encoding override encoding
|
|
* @param string|null $path override path
|
|
* @return array<string,string> locale, domain, encoding, path
|
|
* @deprecated use GetLocale::setLocaleSession(...) instead
|
|
*/
|
|
public static function setLocale(
|
|
?string $locale = null,
|
|
?string $domain = null,
|
|
?string $encoding = null,
|
|
?string $path = null
|
|
): array {
|
|
trigger_error(
|
|
'Use \CoreLibs\Language\GetLocale::setLocaleSession(...) instead',
|
|
E_USER_DEPRECATED
|
|
);
|
|
// locale must match at least basic rules
|
|
if (
|
|
empty($locale) ||
|
|
!preg_match("/^[-A-Za-z0-9_.@]+$/", $locale)
|
|
) {
|
|
if (!empty($_SESSION['DEFAULT_LOCALE'])) {
|
|
// parse from session (logged in)
|
|
$locale = $_SESSION['DEFAULT_LOCALE'];
|
|
} else {
|
|
trigger_error(
|
|
'setLocale: Unset $locale or unset SESSION locale is deprecated',
|
|
E_USER_DEPRECATED
|
|
);
|
|
// else parse from site locale
|
|
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
|
SITE_LOCALE :
|
|
// else parse from default, if not 'en'
|
|
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
|
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
|
|
DEFAULT_LOCALE : 'en');
|
|
}
|
|
}
|
|
// if domain is set, must be alphanumeric, if not unset
|
|
if (
|
|
empty($domain) ||
|
|
!preg_match("/^\w+$/", $domain)
|
|
) {
|
|
if (!empty($_SESSION['DEFAULT_DOMAIN'])) {
|
|
$domain = $_SESSION['DEFAULT_DOMAIN'];
|
|
} else {
|
|
trigger_error(
|
|
'setLocale: Unset $domain is deprecated',
|
|
E_USER_DEPRECATED
|
|
);
|
|
// if no domain is set, fall back to content path
|
|
$domain = str_replace(DIRECTORY_SEPARATOR, '', CONTENT_PATH);
|
|
}
|
|
}
|
|
// check that override encoding matches locale encoding
|
|
// if locale encoding is set
|
|
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale, $matches);
|
|
$locale_encoding = $matches['charset'] ?? null;
|
|
if (
|
|
// empty encoding
|
|
empty($encoding) ||
|
|
// not valid encoding
|
|
!preg_match("/^[-A-Za-z0-9_]+$/", $encoding) ||
|
|
// locale encoding set and not matching to encoding
|
|
(!empty($locale_encoding) && $encoding != $locale_encoding)
|
|
) {
|
|
if (!empty($locale_encoding)) {
|
|
$encoding = strtoupper($locale_encoding);
|
|
} elseif (!empty($_SESSION['DEFAULT_CHARSET'])) {
|
|
// else set from session
|
|
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
|
} else {
|
|
trigger_error(
|
|
'setLocale: Short $locale with unset $encoding or unset SESSION encoding is deprecated',
|
|
E_USER_DEPRECATED
|
|
);
|
|
// else set from site encoding
|
|
$encoding = defined('SITE_ENCODING') && !empty(SITE_ENCODING) ?
|
|
SITE_ENCODING :
|
|
// or default encoding, if not 'UTF-8'
|
|
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
|
(defined('DEFAULT_ENCODING') && !empty(DEFAULT_ENCODING) ?
|
|
DEFAULT_ENCODING : 'UTF-8');
|
|
}
|
|
}
|
|
// path checks if set, if not valid path unset to default BASE path
|
|
if (
|
|
empty($path) ||
|
|
!is_dir($path)
|
|
) {
|
|
if (!empty($_SESSION['LOCALE_PATH'])) {
|
|
$path = $_SESSION['LOCALE_PATH'];
|
|
} else {
|
|
trigger_error(
|
|
'setLocale: Unset $path is deprecated',
|
|
E_USER_DEPRECATED
|
|
);
|
|
$path = BASE . INCLUDES . LOCALE;
|
|
}
|
|
}
|
|
// extract lang & country from locale string, else set to en
|
|
if (
|
|
preg_match(
|
|
// lang
|
|
'/^(?P<lang>[a-z]{2,3})'
|
|
// country code
|
|
. '(?:_(?P<country>[A-Z]{2}))?/',
|
|
$locale,
|
|
$matches
|
|
)
|
|
) {
|
|
$lang = $matches['lang']
|
|
// add country only if set
|
|
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
|
} else {
|
|
$lang = 'en';
|
|
}
|
|
return [
|
|
'locale' => $locale,
|
|
'lang' => $lang,
|
|
'domain' => $domain,
|
|
'encoding' => $encoding,
|
|
'path' => $path,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* NOTE: For getting the login info via login class use ->loginGetLocale()
|
|
*
|
|
* Set locale from session or from override parameters
|
|
* This is the prefered version to setLocale
|
|
* It usese the following SESSION VARIABLES
|
|
* DEFAULT_LOCALE
|
|
* DEFAULT_DOMAIN
|
|
* DEFAULT_CHARSET (should be set from DEFAULT_LOCALE)
|
|
* LOCALE_PATH
|
|
* in the return array, null set invalid information
|
|
*
|
|
* @param string $locale override locale
|
|
* @param string $domain override domain
|
|
* @param string $encoding override encoding
|
|
* @param string $path override path
|
|
* @return array<string,string> locale, domain, encoding, path
|
|
* @return array<string,string|null> Return list of set locale information
|
|
* @deprecated This version will be removed in a future version use ACL\Login->loginGetLocale() instead
|
|
*/
|
|
public static function setLocaleFromSession(
|
|
string $locale,
|
|
string $domain,
|
|
string $encoding,
|
|
string $path
|
|
): array {
|
|
// locale must match at least basic rules
|
|
if (
|
|
!empty($_SESSION['DEFAULT_LOCALE']) &&
|
|
preg_match("/^[-A-Za-z0-9_.@]+$/", $_SESSION['DEFAULT_LOCALE'])
|
|
) {
|
|
// parse from session (logged in)
|
|
$locale = $_SESSION['DEFAULT_LOCALE'];
|
|
} elseif (
|
|
empty($locale) ||
|
|
!preg_match("/^[-A-Za-z0-9_.@]+$/", $locale)
|
|
) {
|
|
$locale = null;
|
|
}
|
|
// if domain is set, must be alphanumeric, if not unset
|
|
if (
|
|
!empty($_SESSION['DEFAULT_DOMAIN']) &&
|
|
preg_match("/^\w+$/", $_SESSION['DEFAULT_DOMAIN'])
|
|
) {
|
|
$domain = $_SESSION['DEFAULT_DOMAIN'];
|
|
} elseif (
|
|
empty($domain) ||
|
|
!preg_match("/^\w+$/", $domain)
|
|
) {
|
|
$domain = null;
|
|
}
|
|
// check that override encoding matches locale encoding
|
|
// if locale encoding is set
|
|
preg_match('/(?:\\.(?P<charset>[-A-Za-z0-9_]+))/', $locale ?? '', $matches);
|
|
$locale_encoding = $matches['charset'] ?? null;
|
|
if (!empty($locale_encoding)) {
|
|
$encoding = strtoupper($locale_encoding);
|
|
} elseif (
|
|
!empty($_SESSION['DEFAULT_CHARSET']) &&
|
|
preg_match("/^[-A-Za-z0-9_]+$/", $_SESSION['DEFAULT_CHARSET'])
|
|
) {
|
|
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
|
} elseif (
|
|
empty($encoding) ||
|
|
// not valid encoding
|
|
!preg_match("/^[-A-Za-z0-9_]+$/", $encoding)
|
|
) {
|
|
$encoding = null;
|
|
}
|
|
// path checks if set, if not valid path unset to default BASE path
|
|
if (
|
|
!empty($_SESSION['LOCALE_PATH']) &&
|
|
is_dir($_SESSION['LOCALE_PATH'])
|
|
) {
|
|
$path = $_SESSION['LOCALE_PATH'];
|
|
} elseif (
|
|
empty($path) ||
|
|
!is_dir($path)
|
|
) {
|
|
$path = null;
|
|
}
|
|
// extract lang & country from locale string, else set to en
|
|
if (
|
|
preg_match(
|
|
// lang
|
|
'/^(?P<lang>[a-z]{2,3})'
|
|
// country code
|
|
. '(?:_(?P<country>[A-Z]{2}))?/',
|
|
$locale ?? '',
|
|
$matches
|
|
)
|
|
) {
|
|
$lang = $matches['lang']
|
|
// add country only if set
|
|
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
|
} else {
|
|
$lang = null;
|
|
}
|
|
return [
|
|
'locale' => $locale,
|
|
'lang' => $lang,
|
|
'domain' => $domain,
|
|
'encoding' => $encoding,
|
|
'path' => $path,
|
|
];
|
|
}
|
|
}
|
|
|
|
// __END__
|