Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27087a0e0e | ||
|
|
2b689b666a | ||
|
|
63aeebdee0 | ||
|
|
51e700cd10 | ||
|
|
71a431d5aa | ||
|
|
6970e6221b | ||
|
|
831f3be1a8 | ||
|
|
f2aba8c466 | ||
|
|
f085ccaa38 | ||
|
|
6c3c1a908d | ||
|
|
388b90913a | ||
|
|
07aea9d7b2 | ||
|
|
edcdbee523 | ||
|
|
43b51895f0 | ||
|
|
d0e294ecf5 | ||
|
|
3c35341e8b | ||
|
|
daf1f9263c | ||
|
|
805c695d68 | ||
|
|
ffdd45e32a | ||
|
|
316ca106fd | ||
|
|
fd9b201346 | ||
|
|
667dc4de8e | ||
|
|
fed67e990d |
14
4dev/bin/create_mo.sh
Executable file
14
4dev/bin/create_mo.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
base_folder='/var/www/html/developers/clemens/core_data/php_libraries/trunk/www/';
|
||||
|
||||
# locale gettext po to mo translator master
|
||||
for file in $(ls -1 ${base_folder}../4dev/locale/*.po); do
|
||||
file=$(basename $file .po);
|
||||
echo "Translate language ${file}";
|
||||
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||
msgfmt -o ${base_folder}/includes/locale/${locale}/LC_MESSAGES/${domain}.mo ${base_folder}../4dev/locale/${locale}-${domain}.po;
|
||||
done;
|
||||
|
||||
# __END__
|
||||
@@ -1,4 +1,42 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
${base}www/vendor/bin/phpunit -c ${base}phpunit.xml ${base}4dev/tests/
|
||||
# call with "t" to give verbose testdox output
|
||||
# SUPPORTED: https://www.php.net/supported-versions.php
|
||||
# call with 7.3, 7.4, 8.0, 8.1 to force a certain php version
|
||||
|
||||
opt_testdox="";
|
||||
if [ "${1}" = "t" ] || [ "${2}" = "t" ]; then
|
||||
opt_testdox="--testdox";
|
||||
fi;
|
||||
php_bin="";
|
||||
if [ ! -z "${1}" ]; then
|
||||
case "${1}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
if [ ! -z "${2}" ] && [ -z "${php_bin}" ]; then
|
||||
case "${2}" in
|
||||
# "7.3") php_bin="/usr/bin/php7.3 "; ;;
|
||||
"7.4") php_bin="/usr/bin/php7.4 "; ;;
|
||||
"8.0") php_bin="/usr/bin/php8.0 "; ;;
|
||||
"8.1") php_bin="/usr/bin/php8.1 "; ;;
|
||||
*) echo "Not support PHP: ${1}"; exit; ;;
|
||||
esac;
|
||||
fi;
|
||||
|
||||
phpunit_call="${php_bin}${base}www/vendor/bin/phpunit ${opt_testdox} -c ${base}phpunit.xml ${base}4dev/tests/";
|
||||
|
||||
${phpunit_call};
|
||||
|
||||
if [ ! -z "${php_bin}" ]; then
|
||||
echo "CALLED WITH PHP: ${php_bin}"$(${php_bin} --version);
|
||||
else
|
||||
echo "Default PHP used: "$(php --version);
|
||||
fi;
|
||||
|
||||
# __END__
|
||||
|
||||
@@ -2,19 +2,18 @@
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2005/08/09
|
||||
# SHORT DESCRIPTION:
|
||||
# Backned English Messages file for gettext
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# Backend English Messages file for gettext
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES admin\n"
|
||||
"Project-Id-Version: en.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\n"
|
||||
"Language: en\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
@@ -32,20 +31,20 @@ msgstr "OUTPUT TEST ADMIN EN"
|
||||
# testing multi
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin en_US 0"
|
||||
msgstr[1] "Multi Admin en_US 1"
|
||||
msgstr[2] "Multi Admin en_US 2"
|
||||
msgstr[0] "Multi Admin en 0"
|
||||
msgstr[1] "Multi Admin en 1"
|
||||
msgstr[2] "Multi Admin en 2"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "May"
|
||||
msgstr "May Admin en_US"
|
||||
msgstr "May Admin en"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin month en_US 0"
|
||||
msgstr[1] "Multi Admin month en_US 1"
|
||||
msgstr[2] "Multi Admin month en_US 2"
|
||||
msgstr[0] "Multi Admin month en 0"
|
||||
msgstr[1] "Multi Admin month en 1"
|
||||
msgstr[2] "Multi Admin month en 2"
|
||||
|
||||
msgid "I should be translated"
|
||||
msgstr "I should be translated: I WAS TRANSLATED"
|
||||
@@ -1,14 +1,19 @@
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# ********************************************************************
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2005/08/09
|
||||
# SHORT DESCRIPTION:
|
||||
# Frontend English Messages file for gettext
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: en_US.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Project-Id-Version: en.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: en_US\n"
|
||||
"Language: en\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
@@ -19,6 +24,6 @@ msgstr "OUTPUT TEST FRONTEND EN"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi frontend en_US 0"
|
||||
msgstr[1] "Multi frontend en_US 1"
|
||||
msgstr[2] "Multi frontend en_US 2"
|
||||
msgstr[0] "Multi frontend en 0"
|
||||
msgstr[1] "Multi frontend en 1"
|
||||
msgstr[2] "Multi frontend en 2"
|
||||
@@ -2,13 +2,12 @@
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2018/03/28
|
||||
# SHORT DESCRIPTION:
|
||||
# Backend Japanese Messages file for gettext
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# Backend Japanese Messages file for gettext>
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: ja_JP.UTF-8 LC_MESSAGES admin\n"
|
||||
"Project-Id-Version: ja.UTF-8 LC_MESSAGES admin\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
@@ -69,9 +68,20 @@ msgstr "OUTPUT TEST ADMIN JA"
|
||||
# testing multi
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin ja_JP 0"
|
||||
msgstr[1] "Multi Admin ja_JP 1"
|
||||
msgstr[2] "Multi Admin ja_JP 2"
|
||||
msgstr[0] "Multi Admin ja 0"
|
||||
msgstr[1] "Multi Admin ja 1"
|
||||
msgstr[2] "Multi Admin ja 2"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "May"
|
||||
msgstr "May Admin ja"
|
||||
|
||||
msgctxt "month name"
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi Admin month ja 0"
|
||||
msgstr[1] "Multi Admin month ja 1"
|
||||
msgstr[2] "Multi Admin month ja 2"
|
||||
|
||||
# login string
|
||||
msgid "Hello %s"
|
||||
|
||||
@@ -1,8 +1,29 @@
|
||||
# to craete: msgfmt -o <output.po> <input.mo>
|
||||
# ********************************************************************
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2005/08/09
|
||||
# SHORT DESCRIPTION:
|
||||
# Frontend Japanese Messages file for gettext
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: ja.UTF-8 LC_MESSAGES frontend\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: clemens.schwaighofer@egplusww.com\n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"Language: ja\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
|
||||
|
||||
msgid "INPUT TEST"
|
||||
msgstr "OUTPUT TEST FRONTEND JA"
|
||||
|
||||
msgid "single"
|
||||
msgid_plural "multi"
|
||||
msgstr[0] "Multi frontend ja 0"
|
||||
msgstr[1] "Multi frontend ja 1"
|
||||
msgstr[2] "Multi frontend ja 2"
|
||||
|
||||
@@ -13,18 +13,73 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsACLLoginTest extends TestCase
|
||||
{
|
||||
private static $db;
|
||||
private static $log;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* start DB conneciton, setup DB, etc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
self::markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
'debug_all' => false,
|
||||
'echo_all' => false,
|
||||
'print_all' => false,
|
||||
]);
|
||||
// if we do have pgsql, we need to create a test DB or check that one
|
||||
// exists and clean the table to zero state
|
||||
self::$db = new \CoreLibs\DB\IO(
|
||||
[
|
||||
'db_name' => 'corelibs_acl_login_test',
|
||||
'db_user' => 'corelibs_acl_login_test',
|
||||
'db_pass' => 'corelibs_acl_login_test',
|
||||
'db_host' => 'localhost',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
self::$log
|
||||
);
|
||||
if (!self::$db->dbGetConnectionStatus()) {
|
||||
self::markTestSkipped(
|
||||
'Cannot connect to valid Test DB for ACL\Login test.'
|
||||
);
|
||||
}
|
||||
/*
|
||||
// check if they already exist, drop them
|
||||
if ($db->dbShowTableMetaData('table_with_primary_key') !== false) {
|
||||
$db->dbExec("DROP TABLE table_with_primary_key");
|
||||
$db->dbExec("DROP TABLE table_without_primary_key");
|
||||
$db->dbExec("DROP TABLE test_meta");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* close db
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
if (self::$db->dbGetConnectionStatus()) {
|
||||
self::$db->dbClose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,6 +95,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
$this->markTestIncomplete(
|
||||
'ACL\Login Tests have not yet been implemented'
|
||||
);
|
||||
|
||||
$login = new \CoreLibs\ACL\Login(self::$db, self::$log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use Exception;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: create provider for n array merge
|
||||
* provides array listing for the merge test
|
||||
*
|
||||
* @return array
|
||||
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
public function arrayMergeRecursiveProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: expected
|
||||
// 1..n: to merge arrays
|
||||
// n+1: trigger for handle keys as string
|
||||
'two arrays' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
],
|
||||
'two arrays, string flag' => [
|
||||
['a' => 1, 'b' => 2, 'c' => 3],
|
||||
['a' => 1, 'b' => 2],
|
||||
['b' => 2, 'c' => 3],
|
||||
true,
|
||||
],
|
||||
// non hash arrays
|
||||
'non hash array merge, no string flag' => [
|
||||
[3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
],
|
||||
'non hash array merge, string flag' => [
|
||||
[1, 2, 3, 3, 4, 5],
|
||||
[1, 2, 3],
|
||||
[3, 4, 5],
|
||||
true
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* for warning checks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayMergeRecursiveProviderWarning(): array
|
||||
{
|
||||
return [
|
||||
// error <2 arguments
|
||||
'too view arguments' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1]
|
||||
],
|
||||
// error <2 arrays
|
||||
'only one array' => [
|
||||
'arrayMergeRecursive needs two or more array arguments',
|
||||
[1],
|
||||
true,
|
||||
],
|
||||
// error element is not array
|
||||
'non array between array' => [
|
||||
'arrayMergeRecursive encountered a non array argument',
|
||||
[1],
|
||||
'string',
|
||||
[2]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @#dataProvider arrayMergeRecursiveProvider
|
||||
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
|
||||
* @dataProvider arrayMergeRecursiveProvider
|
||||
* @testdox arrayMergeRecursive ... [$_dataName]
|
||||
*
|
||||
* @param array $input nested array set as each parameter
|
||||
* @param bool $flag
|
||||
* @param bool|array $expected
|
||||
* @return void
|
||||
* array $input, bool $flag, $expected
|
||||
*
|
||||
*/
|
||||
public function testArrayMergeRecursive(): void
|
||||
{
|
||||
$this->assertTrue(true, 'Implement proper test run');
|
||||
$this->markTestIncomplete(
|
||||
'testArrayMergeRecursive has not been implemented yet.'
|
||||
$arrays = func_get_args();
|
||||
// first is expected array, always
|
||||
$expected = array_shift($arrays);
|
||||
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
|
||||
...$arrays
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$output
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::arrayMergeRecursive
|
||||
* @dataProvider arrayMergeRecursiveProviderWarning
|
||||
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testArrayMergeRecursiveWarningA(): void
|
||||
{
|
||||
$arrays = func_get_args();
|
||||
// first is expected warning
|
||||
$warning = array_shift($arrays);
|
||||
$this->expectWarning();
|
||||
$this->expectWarningMessage($warning);
|
||||
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,6 +68,7 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
*/
|
||||
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
|
||||
{
|
||||
// NEEDS MOCKING
|
||||
/* $session_id = '';
|
||||
switch ($type) {
|
||||
case 'p':
|
||||
@@ -97,7 +98,8 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
if ($type == 'g') {
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
} */
|
||||
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
|
||||
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
|
||||
. 'for Create\Session. Cannot run session_start in CLI');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
);
|
||||
if (!$db->dbGetConnectionStatus()) {
|
||||
self::markTestSkipped(
|
||||
'Cannot connect to valid Test DB.'
|
||||
'Cannot connect to valid Test DB for DB\IO test.'
|
||||
);
|
||||
}
|
||||
// check if they already exist, drop them
|
||||
@@ -566,7 +566,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
public function testDbSetDebug(
|
||||
string $connection,
|
||||
?bool $set,
|
||||
bool $expected,
|
||||
bool $expected
|
||||
): void {
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
@@ -599,7 +599,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
public function testDbToggleDebug(
|
||||
string $connection,
|
||||
?bool $toggle,
|
||||
bool $expected,
|
||||
bool $expected
|
||||
): void {
|
||||
$db = new \CoreLibs\DB\IO(
|
||||
self::$db_config[$connection],
|
||||
@@ -1734,7 +1734,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
$expected,
|
||||
string $warning,
|
||||
string $error,
|
||||
string $insert_data,
|
||||
string $insert_data
|
||||
): void {
|
||||
// self::$log->setLogLevelAll('debug', true);
|
||||
// self::$log->setLogLevelAll('print', true);
|
||||
@@ -1871,7 +1871,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
$expected,
|
||||
string $warning,
|
||||
string $error,
|
||||
string $insert_data,
|
||||
string $insert_data
|
||||
): void {
|
||||
// self::$log->setLogLevelAll('debug', true);
|
||||
// self::$log->setLogLevelAll('print', true);
|
||||
@@ -2034,7 +2034,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
array $cursor_ext_checks,
|
||||
string $warning,
|
||||
string $error,
|
||||
string $insert_data,
|
||||
string $insert_data
|
||||
): void {
|
||||
// self::$log->setLogLevelAll('debug', true);
|
||||
// self::$log->setLogLevelAll('print', true);
|
||||
@@ -2356,7 +2356,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
string $error_execute,
|
||||
string $expected_data_query,
|
||||
array $expected_data,
|
||||
string $insert_data,
|
||||
string $insert_data
|
||||
): void {
|
||||
// self::$log->setLogLevelAll('debug', true);
|
||||
// self::$log->setLogLevelAll('print', true);
|
||||
@@ -2709,7 +2709,8 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
// comarep all, except timestamp that is a regex
|
||||
foreach ($expected_history as $key => $value) {
|
||||
// check if starts with / because this is regex (timestamp)
|
||||
if (strpos($value, "/") === 0) {
|
||||
// if (substr($expected_2, 0, 1) == '/) {
|
||||
if (strpos($value, '/') === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
@@ -3009,7 +3010,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
string $insert,
|
||||
?string $pk_name,
|
||||
string $table,
|
||||
string $primary_key,
|
||||
string $primary_key
|
||||
): void {
|
||||
// self::$log->setLogLevelAll('debug', true);
|
||||
// self::$log->setLogLevelAll('print', true);
|
||||
|
||||
@@ -54,14 +54,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
'no options set, constant set' => [
|
||||
null,
|
||||
[
|
||||
'log_folder' => '/tmp/',
|
||||
'log_folder' => str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR . 'log/',
|
||||
'debug_all' => false,
|
||||
'print_all' => false,
|
||||
],
|
||||
[
|
||||
'constant' => [
|
||||
'BASE' => '/tmp',
|
||||
'LOG' => '/'
|
||||
'BASE' => str_replace('/configs', '', __DIR__)
|
||||
. DIRECTORY_SEPARATOR,
|
||||
'LOG' => 'log/'
|
||||
]
|
||||
]
|
||||
],
|
||||
@@ -728,7 +730,7 @@ final class CoreLibsDebugLoggingTest extends TestCase
|
||||
bool $expected_debug,
|
||||
string $expected_file,
|
||||
string $expected_string_start,
|
||||
string $expected_string_contains,
|
||||
string $expected_string_contains
|
||||
): void {
|
||||
// must run with below matrix
|
||||
// level | debug | print | echo | debug() | printErrorMsg() | file
|
||||
|
||||
@@ -90,11 +90,16 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
public function getPageNameProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: input
|
||||
// 1: expected default/WITH_EXTENSION
|
||||
// 2: expected NO_EXTENSION
|
||||
// 3: expected FULL_PATH, if first and last character are / use regex
|
||||
'original set' => [
|
||||
0 => null, // input
|
||||
0 => null,
|
||||
1 => 'phpunit',
|
||||
2 => 'phpunit',
|
||||
3 => 'www/vendor/bin/phpunit', // NOTE: this can change
|
||||
// NOTE: this can change, so it is a regex check
|
||||
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
||||
],
|
||||
'some path with extension' => [
|
||||
0 => '/some/path/to/file.txt',
|
||||
@@ -147,11 +152,13 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
list ($host, $port) = \CoreLibs\Get\System::getHostName();
|
||||
$this->assertEquals(
|
||||
$expected_host,
|
||||
$host
|
||||
$host,
|
||||
'failed expected host assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_port,
|
||||
$port
|
||||
$port,
|
||||
'faile expected port assert'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,20 +183,38 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
// default 0,
|
||||
$this->assertEquals(
|
||||
$expected_0,
|
||||
\CoreLibs\Get\System::getPageName()
|
||||
\CoreLibs\Get\System::getPageName(),
|
||||
'failed default assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_0,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION)
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION),
|
||||
'failed WITH_EXTESION assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_1,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_2,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH)
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION),
|
||||
'failed NO_EXTENSION assert'
|
||||
);
|
||||
// FULL PATH check can be equals or regex
|
||||
$page_name_full_path = \CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH);
|
||||
if (
|
||||
substr($expected_2, 0, 1) == '/' &&
|
||||
substr($expected_2, -1, 1) == '/'
|
||||
) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected_2,
|
||||
$page_name_full_path,
|
||||
'failed FULL_PATH assert regex'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected_2,
|
||||
$page_name_full_path,
|
||||
'failed FULL_PATH assert equals'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
310
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
310
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\GetLocale
|
||||
*
|
||||
* @coversDefaultClass \CoreLibs\Language\GetLocale
|
||||
* @testdox \CoreLibs\Language\GetLocale method tests
|
||||
*/
|
||||
final class CoreLibsLanguageGetLocaleTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
// default web page encoding setting
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setLocaleProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: SESSION: DEFAULT_LOCALE
|
||||
// 5: SESSION: DEFAULT_CHARSET
|
||||
// 6: expected array
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'en_US.UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja_JP', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, encoding, path
|
||||
null, null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
'ja', 'UTF-8',
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang (no sessions)
|
||||
'locale param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja_JP.SJIS', null, null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja_JP.SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'domain' => 'frontend',
|
||||
'encoding' => 'SJIS',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', null, null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// lang, domain, path (no override)
|
||||
'locale, domain and path, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja.UTF-8',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// all params set (no override)
|
||||
'all parameter, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'ja',
|
||||
'lang' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'long locale, domain, encoding params, no sessions' => [
|
||||
// lang, domain, encoding, path
|
||||
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
|
||||
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
|
||||
null, null,
|
||||
// return array
|
||||
[
|
||||
'locale' => 'de_CH.UTF-8@euro',
|
||||
'lang' => 'de_CH',
|
||||
'domain' => 'admin',
|
||||
'encoding' => 'UTF-8',
|
||||
'path' => "/^\/(.*\/)?includes\/locale\/$/",
|
||||
],
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLocale
|
||||
* @dataProvider setLocaleProvider
|
||||
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testsetLocale(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $encoding,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_LOCALE,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
array $expected
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_LOCALE !== null) {
|
||||
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
|
||||
}
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
// function call
|
||||
if ($language === null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
|
||||
} elseif ($language !== null && $domain === null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
|
||||
$language,
|
||||
$domain,
|
||||
$encoding,
|
||||
$path
|
||||
);
|
||||
}
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
'locale', 'lang', 'domain', 'encoding', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert regex failed for ' . $key
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
'assert equal failed for ' . $key
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,325 +0,0 @@
|
||||
<?php // phpcs:disable Generic.Files.LineLength
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test class for Language\GetSettings
|
||||
*
|
||||
* @coversDefaultClass \CoreLibs\Language\GetSettings
|
||||
* @testdox \CoreLibs\Language\GetSettings method tests
|
||||
*/
|
||||
final class CoreLibsLanguageGetSettingsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* set all constant variables that must be set before call
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
define('DEFAULT_LANG', 'en_US');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
// site
|
||||
define('SITE_LANG', DEFAULT_LANG);
|
||||
// just set
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
// array session
|
||||
$_SESSION = [];
|
||||
global $_SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* all the test data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function setLangEncodingProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: locale/lang
|
||||
// 1: domain
|
||||
// 2: path
|
||||
// 3: SESSION DEFAULT_CHARSE
|
||||
// 4: GLOBALS: OVERRIDE_LANG
|
||||
// 5: SESSION: DEFAULT_LANG
|
||||
// 6: expected array
|
||||
'no params, all default constants' => [
|
||||
// lang, domain, path
|
||||
null, null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
null, null, null,
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'en_US',
|
||||
2 => 'en',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'lang_short' => 'en',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang' => [
|
||||
// lang, domain, path
|
||||
null, null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
'UTF-8', null, 'ja_JP',
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'ja_JP',
|
||||
2 => 'ja',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'ja_JP',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
'no params, session charset and lang short' => [
|
||||
// lang, domain, path
|
||||
null, null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
'UTF-8', null, 'ja',
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'ja',
|
||||
2 => 'ja',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'ja',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// globals override lang
|
||||
'no params, session charset and lang, default lang override' => [
|
||||
// lang, domain, path
|
||||
null, null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
'UTF-8', 'en_US', 'ja_JP',
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'en_US',
|
||||
2 => 'en',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'en_US',
|
||||
'lang_short' => 'en',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// globals override lang short
|
||||
'no params, session charset and lang, default lang short override' => [
|
||||
// lang, domain, path
|
||||
null, null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
'UTF-8', 'en', 'ja_JP',
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'en',
|
||||
2 => 'en',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'en',
|
||||
'lang_short' => 'en',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// param lang (no override)
|
||||
'locale param only, no override' => [
|
||||
// lang, domain, path
|
||||
'ja.UTF-8', null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
null, null, null,
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'ja',
|
||||
2 => 'ja',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'ja',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// different locale setting
|
||||
'locale complex param only, no override' => [
|
||||
// lang, domain, path
|
||||
'ja_JP.SJIS', null, null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
null, null, null,
|
||||
// return array
|
||||
[
|
||||
0 => 'SJIS',
|
||||
1 => 'ja_JP',
|
||||
2 => 'ja',
|
||||
3 => 'frontend',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'SJIS',
|
||||
'lang' => 'ja_JP',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'frontend',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// param lang and domain (no override)
|
||||
'locale, domain params, no override' => [
|
||||
// lang, domain, path
|
||||
'ja.UTF-8', 'admin', null,
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
null, null, null,
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'ja',
|
||||
2 => 'ja',
|
||||
3 => 'admin',
|
||||
4 => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'ja',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'path' => "/^\/(.*\/)?includes\/lang\/frontend\/$/",
|
||||
],
|
||||
],
|
||||
// all params set (no override)
|
||||
'all params, no override' => [
|
||||
// lang, domain, path
|
||||
'ja.UTF-8', 'admin', __DIR__ . '/locale_other/',
|
||||
// global set no session
|
||||
// SESSION: DEFAULT_CHARSET, GLOBALS: OVERRIDE_LANG, SESSION: DEFAULT_LANG
|
||||
null, null, null,
|
||||
// return array
|
||||
[
|
||||
0 => 'UTF-8',
|
||||
1 => 'ja',
|
||||
2 => 'ja',
|
||||
3 => 'admin',
|
||||
4 => "/^\/(.*\/)?locale_other\/$/",
|
||||
'encoding' => 'UTF-8',
|
||||
'lang' => 'ja',
|
||||
'lang_short' => 'ja',
|
||||
'domain' => 'admin',
|
||||
'path' => "/^\/(.*\/)?locale_other\/$/",
|
||||
],
|
||||
],
|
||||
// TODO invalid params (bad path) (no override)
|
||||
// TODO param calls, but with override set
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @covers ::setLangEncoding
|
||||
* @dataProvider setLangEncodingProvider
|
||||
* @testdox lang settings lang $language, domain $domain, path $path; null session char: $SESSION_DEFAULT_CHARSET, null global lang: $GLOBAL_OVERRIDE_LANG, null session lang: $SESSION_DEFAULT_LANG [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetLangEncoding(
|
||||
?string $language,
|
||||
?string $domain,
|
||||
?string $path,
|
||||
?string $SESSION_DEFAULT_CHARSET,
|
||||
?string $GLOBAL_OVERRIDE_LANG,
|
||||
?string $SESSION_DEFAULT_LANG,
|
||||
array $expected,
|
||||
): void {
|
||||
$return_lang_settings = [];
|
||||
global $_SESSION;
|
||||
// set override
|
||||
if ($SESSION_DEFAULT_CHARSET !== null) {
|
||||
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
|
||||
}
|
||||
if ($GLOBAL_OVERRIDE_LANG !== null) {
|
||||
$GLOBALS['OVERRIDE_LANG'] = $GLOBAL_OVERRIDE_LANG;
|
||||
}
|
||||
if ($SESSION_DEFAULT_LANG !== null) {
|
||||
$_SESSION['DEFAULT_LANG'] = $SESSION_DEFAULT_LANG;
|
||||
}
|
||||
// function call
|
||||
if ($language === null && $domain === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding();
|
||||
} elseif ($language !== null && $domain === null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
||||
$language
|
||||
);
|
||||
} elseif ($language !== null && $domain !== null && $path === null) {
|
||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
||||
$language,
|
||||
$domain
|
||||
);
|
||||
} else {
|
||||
$return_lang_settings = \CoreLibs\Language\GetSettings::setLangEncoding(
|
||||
$language,
|
||||
$domain,
|
||||
$path
|
||||
);
|
||||
}
|
||||
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
|
||||
|
||||
foreach (
|
||||
[
|
||||
0, 1, 2, 3, 4,
|
||||
'encoding', 'lang', 'lang_short', 'domain', 'path'
|
||||
] as $key
|
||||
) {
|
||||
$value = $expected[$key];
|
||||
if (strpos($value, "/") === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
$return_lang_settings[$key]
|
||||
);
|
||||
} else {
|
||||
// assert equal
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$return_lang_settings[$key],
|
||||
);
|
||||
}
|
||||
}
|
||||
// unset all vars
|
||||
$_SESSION = [];
|
||||
unset($GLOBALS['OVERRIDE_LANG']);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -22,19 +22,37 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
define('DEFAULT_LANG', 'en_US');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
if (!defined('DEFAULT_ENCODING')) {
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
}
|
||||
if (!defined('DEFAULT_LOCALE')) {
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
}
|
||||
// site
|
||||
define('SITE_LANG', DEFAULT_LANG);
|
||||
if (!defined('SITE_ENCODING')) {
|
||||
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||
}
|
||||
if (!defined('SITE_LOCALE')) {
|
||||
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||
}
|
||||
// just set
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
if (!defined('BASE')) {
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('INCLUDES')) {
|
||||
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LANG')) {
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('LOCALE')) {
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
if (!defined('CONTENT_PATH')) {
|
||||
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,45 +105,23 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: path
|
||||
// 2: domain
|
||||
// 3: legacy load (Default true)
|
||||
// 1: domain
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: locale expected
|
||||
// 5: domain exepcted
|
||||
// 6: context (null for none)
|
||||
// 7: test string in
|
||||
// 8: test translated
|
||||
'legacy load en' => [
|
||||
'en_utf8',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
//
|
||||
'en_utf8',
|
||||
'',
|
||||
//
|
||||
null,
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
],
|
||||
'legacy load ja' => [
|
||||
'ja_utf8',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'ja_utf8',
|
||||
'',
|
||||
null,
|
||||
'Original',
|
||||
'Translated frontend ja_JP',
|
||||
],
|
||||
// 5: locale set expected
|
||||
// 6: domain exepcted
|
||||
// 7: context (null for none)
|
||||
// 8: test string in
|
||||
// 9: test translated
|
||||
// new style load
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
false,
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
null,
|
||||
'Original',
|
||||
@@ -133,10 +129,11 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
],
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
false,
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'context',
|
||||
'Original',
|
||||
@@ -144,32 +141,36 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
],
|
||||
'gettext load ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
false,
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'admin',
|
||||
null,
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
],
|
||||
// null set locale legacy
|
||||
'empty load legacy' => [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
'Original',
|
||||
// mixed path and domain
|
||||
'mixed path and domain' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'context',
|
||||
'Original',
|
||||
'Original context frontend en_US',
|
||||
],
|
||||
// null set
|
||||
'empty load new ' => [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
//
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
@@ -187,10 +188,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @param string|null $path
|
||||
* @param string|null $domain
|
||||
* @param bool|null $legacy
|
||||
* @param string|null $path
|
||||
* @param string $locale_expected
|
||||
* @param string $locale_set_expected
|
||||
* @param string $domain_expected
|
||||
* @param ?string $context
|
||||
* @param string $original
|
||||
@@ -199,25 +200,23 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
*/
|
||||
public function testL10nObject(
|
||||
?string $locale,
|
||||
?string $path,
|
||||
?string $domain,
|
||||
?bool $legacy,
|
||||
?string $path,
|
||||
string $locale_expected,
|
||||
string $locale_set_expected,
|
||||
string $domain_expected,
|
||||
?string $context,
|
||||
string $original,
|
||||
string $translated,
|
||||
string $translated
|
||||
): void {
|
||||
if ($locale === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($domain === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path);
|
||||
} elseif ($legacy === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, $legacy);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
}
|
||||
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||
@@ -226,6 +225,11 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
$l10n->getLocale(),
|
||||
'Locale assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$locale_set_expected,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale set assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected,
|
||||
$l10n->getDomain(),
|
||||
@@ -259,95 +263,71 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: locale
|
||||
// 1: path
|
||||
// 2: domain
|
||||
// 3: legacy flag
|
||||
// 1: domain
|
||||
// 2: path
|
||||
// 3: load error
|
||||
// 4: input string to translated
|
||||
// 5: expected locale
|
||||
// 6: expected domain
|
||||
// 7: expected translation
|
||||
// 8: change locale
|
||||
// 9: change path
|
||||
// 6: expected locale set
|
||||
// 7: expected domain
|
||||
// 8: expected translation
|
||||
// 9: change locale
|
||||
// 10: change domain
|
||||
// 11: legacy flag
|
||||
// 12: expected locale
|
||||
// 13: expected domain
|
||||
// 14: expected translation
|
||||
'legacy load and change (en->ja)' => [
|
||||
// set 0-3
|
||||
'en_utf8',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
// status 4
|
||||
false,
|
||||
// to translate 5
|
||||
'Original',
|
||||
// check setter 6-8
|
||||
'en_utf8',
|
||||
'',
|
||||
'Translated frontend en_US',
|
||||
// set new 9-12
|
||||
'ja_utf8',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
// status new 13
|
||||
false,
|
||||
// check new setter 14-16
|
||||
'ja_utf8',
|
||||
'',
|
||||
'Translated frontend ja_JP',
|
||||
],
|
||||
// 11: change path
|
||||
// 12: change load error
|
||||
// 13: expected locale
|
||||
// 14: expected locale set
|
||||
// 15: expected domain
|
||||
// 16: expected translation
|
||||
'load and change (en->ja)' => [
|
||||
// set 0-3
|
||||
// set 0-2
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
// status 3
|
||||
false,
|
||||
// status 4
|
||||
false,
|
||||
// to translate 5
|
||||
// to translate 4
|
||||
'Original',
|
||||
// check setter 6-8
|
||||
// check setter 5-7
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'Translated frontend en_US',
|
||||
// set new 9-12
|
||||
// set new 8-10
|
||||
'ja_JP.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
// status new 11
|
||||
false,
|
||||
// status new 13
|
||||
false,
|
||||
// check new setter 14-16
|
||||
// check new setter 12-14
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'frontend',
|
||||
'Translated frontend ja_JP',
|
||||
],
|
||||
'empty load and change to en' => [
|
||||
// set 0-3
|
||||
// set 0-2
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
// status 3
|
||||
false,
|
||||
// status 4
|
||||
false,
|
||||
// to translate 5
|
||||
// to translate 4
|
||||
'Original',
|
||||
// check setter 6-8
|
||||
// check setter 5-7
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'Original',
|
||||
// set new 9-12
|
||||
// set new 8-10
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
// status new 11
|
||||
false,
|
||||
// status new 13
|
||||
false,
|
||||
// check new setter 14-16
|
||||
// check new setter 12-14
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'Translated frontend en_US',
|
||||
]
|
||||
@@ -363,60 +343,58 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox change locale from $locale and domain $domain to locale $locale_new and domain $domain_new [$_dataName]
|
||||
*
|
||||
* @param string|null $locale
|
||||
* @param string|null $path
|
||||
* @param string|null $domain
|
||||
* @param bool|null $legacy
|
||||
* @param string|null $path
|
||||
* @param bool $load_error
|
||||
* @param string $original
|
||||
* @param string $locale_expected_a
|
||||
* @param string $locale_set_expected_a
|
||||
* @param string $domain_expected_a
|
||||
* @param string $translated_a
|
||||
* @param string|null $locale_new
|
||||
* @param string|null $path_new
|
||||
* @param string|null $domain_new
|
||||
* @param bool|null $legacy_new
|
||||
* @param string|null $path_new
|
||||
* @param bool $load_error_new
|
||||
* @param string $locale_set_expected_b
|
||||
* @param string $locale_expected_b
|
||||
* @param string $domain_expected_b
|
||||
* @param string $translated_b
|
||||
* @return void
|
||||
*/
|
||||
public function testGetTranslator(
|
||||
// 0-3
|
||||
// 0-2
|
||||
?string $locale,
|
||||
?string $path,
|
||||
?string $domain,
|
||||
?bool $legacy,
|
||||
// 4
|
||||
?string $path,
|
||||
// 3
|
||||
bool $load_error,
|
||||
// 5
|
||||
// 4
|
||||
string $original,
|
||||
// 6-8
|
||||
// 5-7
|
||||
string $locale_expected_a,
|
||||
string $locale_set_expected_a,
|
||||
string $domain_expected_a,
|
||||
string $translated_a,
|
||||
// 9-12
|
||||
// 8-10
|
||||
?string $locale_new,
|
||||
?string $path_new,
|
||||
?string $domain_new,
|
||||
?bool $legacy_new,
|
||||
// 13
|
||||
?string $path_new,
|
||||
// 11
|
||||
bool $load_error_new,
|
||||
// 14-16
|
||||
// 12-14
|
||||
string $locale_expected_b,
|
||||
string $locale_set_expected_b,
|
||||
string $domain_expected_b,
|
||||
string $translated_b,
|
||||
string $translated_b
|
||||
): void {
|
||||
if ($locale === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n();
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($domain === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path);
|
||||
} elseif ($legacy === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||
} elseif ($path === null) {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
} else {
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, $legacy);
|
||||
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||
}
|
||||
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||
// status check
|
||||
@@ -429,6 +407,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
$locale_expected_a,
|
||||
$l10n->getLocale(),
|
||||
'Locale init assert failed'
|
||||
);$this->assertEquals(
|
||||
$locale_set_expected_a,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale Set init assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected_a,
|
||||
@@ -441,73 +423,50 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'Translated string init assert failed'
|
||||
);
|
||||
|
||||
// do reload with legacy l10nReloadMOfile IF legacy is null or true
|
||||
// use getTranslator if legacy is false
|
||||
if ($legacy === null || $legacy === true) {
|
||||
// there is no null/empty locale allowed directly
|
||||
// if empty will set previous one
|
||||
if ($path_new === null) {
|
||||
$ret_status = $l10n->l10nReloadMOfile($locale_new);
|
||||
} elseif ($domain_new === null) {
|
||||
$ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new);
|
||||
} elseif ($legacy_new === null) {
|
||||
$ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new, $domain_new);
|
||||
} else {
|
||||
$ret_status = $l10n->l10nReloadMOfile($locale_new, $path_new, $domain_new, $legacy_new);
|
||||
}
|
||||
// status check
|
||||
$this->assertEquals(
|
||||
$load_error_new,
|
||||
$l10n->getLoadError(),
|
||||
'Legacy method load error change check'
|
||||
);
|
||||
// retun status check is inverted to load error check
|
||||
$this->assertEquals(
|
||||
$load_error_new ? false : true,
|
||||
$ret_status,
|
||||
'Legacy return load error change check'
|
||||
);
|
||||
// switch
|
||||
if ($locale_new === null) {
|
||||
$translator = $l10n->getTranslator();
|
||||
} elseif ($domain_new === null) {
|
||||
$translator = $l10n->getTranslator($locale_new);
|
||||
} elseif ($path_new === null) {
|
||||
$translator = $l10n->getTranslator($locale_new, $domain_new);
|
||||
} else {
|
||||
if ($locale_new === null) {
|
||||
$translator = $l10n->getTranslator();
|
||||
} elseif ($path_new === null) {
|
||||
$translator = $l10n->getTranslator($locale_new);
|
||||
} elseif ($domain_new === null) {
|
||||
$translator = $l10n->getTranslator($locale_new, $path_new);
|
||||
} elseif ($legacy_new === null) {
|
||||
$translator = $l10n->getTranslator($locale_new, $path_new, $domain_new);
|
||||
} else {
|
||||
$translator = $l10n->getTranslator($locale_new, $path_new, $domain_new, $legacy_new);
|
||||
}
|
||||
// status check
|
||||
$this->assertEquals(
|
||||
$load_error_new,
|
||||
$l10n->getLoadError(),
|
||||
'Translate method load error change check'
|
||||
);
|
||||
// check that returned is class GetTextReader and object
|
||||
$this->assertIsObject(
|
||||
$translator,
|
||||
'translater class is object assert failed'
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
'\CoreLibs\Language\Core\GetTextReader',
|
||||
$translator,
|
||||
'translator class is correct instance assert failed'
|
||||
);
|
||||
// translator class
|
||||
$this->assertEquals(
|
||||
$translated_b,
|
||||
$translator->gettext($original),
|
||||
'Translated string change assert failed from returned class'
|
||||
);
|
||||
$translator = $l10n->getTranslator($locale_new, $domain_new, $path_new);
|
||||
}
|
||||
// status check
|
||||
$this->assertEquals(
|
||||
$load_error_new,
|
||||
$l10n->getLoadError(),
|
||||
'Translate method load error change check'
|
||||
);
|
||||
// check that returned is class GetTextReader and object
|
||||
$this->assertIsObject(
|
||||
$translator,
|
||||
'translater class is object assert failed'
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
'\CoreLibs\Language\Core\GetTextReader',
|
||||
$translator,
|
||||
'translator class is correct instance assert failed'
|
||||
);
|
||||
|
||||
// translator class
|
||||
$this->assertEquals(
|
||||
$translated_b,
|
||||
$translator->gettext($original),
|
||||
'Translated string change assert failed from returned class'
|
||||
);
|
||||
// new set check
|
||||
$this->assertEquals(
|
||||
$locale_expected_b,
|
||||
$l10n->getLocale(),
|
||||
'Locale change assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$locale_set_expected_b,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale Set change assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected_b,
|
||||
$l10n->getDomain(),
|
||||
@@ -520,16 +479,14 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: test all translation types
|
||||
// __/gettext
|
||||
// __n/ngettext
|
||||
// TODO: domain based
|
||||
// ->dgettext
|
||||
// ->dngettext
|
||||
// ->dpgettext
|
||||
// ->dpngettext
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* for plural and plural context
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -579,9 +536,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* plural and plural context
|
||||
*
|
||||
* @covers ::__n
|
||||
* @covers ::__pn
|
||||
* @dataProvider ngettextProvider
|
||||
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||
*
|
||||
@@ -619,7 +577,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$l10n->__pn($context, $original_single, $original_plural, $n),
|
||||
$l10n->__np($context, $original_single, $original_plural, $n),
|
||||
'assert failed for plural: ' . $n . ' in context: ' . $context
|
||||
);
|
||||
}
|
||||
@@ -640,21 +598,39 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'en',
|
||||
[
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => null,
|
||||
'charset' => null,
|
||||
'modifier' => null,
|
||||
],
|
||||
],
|
||||
'en.UTF-8' => [
|
||||
'en.UTF-8',
|
||||
[
|
||||
'en.UTF-8',
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => null,
|
||||
'charset' => 'UTF-8',
|
||||
'modifier' => null,
|
||||
],
|
||||
],
|
||||
'en_US' => [
|
||||
'en_US',
|
||||
[
|
||||
'en_US',
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => 'US',
|
||||
'charset' => null,
|
||||
'modifier' => null,
|
||||
],
|
||||
],
|
||||
'en_US.UTF-8' => [
|
||||
'en_US.UTF-8',
|
||||
@@ -662,7 +638,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => 'US',
|
||||
'charset' => 'UTF-8',
|
||||
'modifier' => null,
|
||||
],
|
||||
],
|
||||
'en_US@subtext' => [
|
||||
'en_US@subtext',
|
||||
@@ -671,7 +653,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'en@subtext',
|
||||
'en_US',
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => 'US',
|
||||
'charset' => null,
|
||||
'modifier' => 'subtext',
|
||||
],
|
||||
],
|
||||
'en_US.UTF-8@subtext' => [
|
||||
'en_US.UTF-8@subtext',
|
||||
@@ -682,7 +670,13 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'en',
|
||||
]
|
||||
],
|
||||
[
|
||||
'lang' => 'en',
|
||||
'country' => 'US',
|
||||
'charset' => 'UTF-8',
|
||||
'modifier' => 'subtext',
|
||||
],
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -695,16 +689,24 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @testdox check $locale [$_dataName]
|
||||
*
|
||||
* @param string $locale
|
||||
* @param array $expected
|
||||
* @param array $expected_list
|
||||
* @param array $expected_detail
|
||||
* @return void
|
||||
*/
|
||||
public function testListLocales(string $locale, array $expected): void
|
||||
public function testListLocales(string $locale, array $expected_list, array $expected_detail): void
|
||||
{
|
||||
$locale_detail = \CoreLibs\Language\L10n::parseLocale($locale);
|
||||
$this->assertEquals(
|
||||
$expected_detail,
|
||||
$locale_detail,
|
||||
'Parse local assert failed'
|
||||
);
|
||||
$locale_list = \CoreLibs\Language\L10n::listLocales($locale);
|
||||
// print "LOCALES: " . print_r($locale_list, true) . "\n";
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$locale_list
|
||||
$expected_list,
|
||||
$locale_list,
|
||||
'List locale assert failed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -761,7 +763,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
string $type,
|
||||
string $var,
|
||||
string $value,
|
||||
string $expected,
|
||||
string $expected
|
||||
): void {
|
||||
switch ($type) {
|
||||
case 'global':
|
||||
@@ -971,23 +973,23 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
{
|
||||
return [
|
||||
// 0: lang/locale
|
||||
// 1: path
|
||||
// 2: domain
|
||||
// 1: domain
|
||||
// 2: path
|
||||
// 3: encoding
|
||||
// 4: string
|
||||
// 5: translated string
|
||||
'standard en' => [
|
||||
'en_US.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'frontend',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated frontend en_US',
|
||||
],
|
||||
'standard ja' => [
|
||||
'ja_JP.UTF-8',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'admin',
|
||||
__DIR__ . 'includes/locale/',
|
||||
'UTF-8',
|
||||
'Original',
|
||||
'Translated admin ja_JP',
|
||||
@@ -997,7 +999,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
|
||||
/**
|
||||
* fuctions check
|
||||
* TODO: others d/dn/dp/dpn gettext functions
|
||||
* TODO: others d/dn/dp/dnp gettext functions
|
||||
*
|
||||
* @covers __setlocale
|
||||
* @covers __bindtextdomain
|
||||
@@ -1008,8 +1010,8 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @dataProvider functionsProvider
|
||||
* @testdox check functions with locale $locale and domain $domain [$_dataName]
|
||||
* @param string $locale
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param string $path
|
||||
* @param string $encoding
|
||||
* @param string $original
|
||||
* @param string $translated
|
||||
@@ -1017,17 +1019,17 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
*/
|
||||
public function testFunctions(
|
||||
string $locale,
|
||||
string $path,
|
||||
string $domain,
|
||||
string $path,
|
||||
string $encoding,
|
||||
string $original,
|
||||
string $translated
|
||||
): void {
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__($original),
|
||||
@@ -1035,7 +1037,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
);
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__gettext($original),
|
||||
_gettext($original),
|
||||
'function gettext assert failed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/ja_JP/LC_MESSAGES/admin.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/ja_JP/LC_MESSAGES/frontend.mo
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class TemplateMethodsTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function assertPreConditions(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
public function testOne(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testTwo(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
protected function assertPostConditions(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(\Throwable $t): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
throw $t;
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
// login & page access check
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
```
|
||||
* update language class
|
||||
```php
|
||||
// pre auto detect language after login
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
// set lang and pass to smarty/backend
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
```
|
||||
* smarty needs language
|
||||
```php
|
||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
```
|
||||
* admin backend also needs logger
|
||||
```php
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log);
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
```
|
||||
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
|
||||
* update all `config.*.php` files where needed
|
||||
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
|
||||
```
|
||||
**UPDATE:**
|
||||
```php
|
||||
// po langs [DEPRECAED: use LOCALE]
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
// po locale file
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
```
|
||||
```php
|
||||
// SSL host name
|
||||
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
||||
```
|
||||
@@ -85,6 +106,13 @@ define('CONTENT_WIDTH', '100%');
|
||||
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
||||
```
|
||||
```php
|
||||
/************* LANGUAGE / ENCODING *******/
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
```
|
||||
```php
|
||||
// BAIL ON MISSING DB CONFIG:
|
||||
// we have either no db selction for this host but have db config entries
|
||||
// or we have a db selection but no db config as array or empty
|
||||
@@ -104,6 +132,10 @@ if (
|
||||
}
|
||||
```
|
||||
```php
|
||||
// remove SITE_LANG
|
||||
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||
```
|
||||
```php
|
||||
/************* GENERAL PAGE TITLE ********/
|
||||
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||
@@ -118,6 +150,15 @@ In the config then
|
||||
```php
|
||||
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
|
||||
```
|
||||
* config.host.php update
|
||||
must add site_locale (site_lang + site_encoding)
|
||||
remove site_lang
|
||||
```php
|
||||
// lang + encoding
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
// site language
|
||||
'site_encoding' => 'UTF-8',
|
||||
```
|
||||
* copy `layout/admin/javascript/edit.jq.js`
|
||||
* check other javacsript files if needed (`edit.jq.js`)
|
||||
|
||||
|
||||
@@ -1,7 +1,72 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_result_error expects resource, object\\|resource\\|true given\\.$#"
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_connection_busy expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 3
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_connection_status expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_get_result expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 2
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_meta_data expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_send_query expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 2
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_socket expects PgSql\\\\Connection, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$connection of function pg_version expects PgSql\\\\Connection\\|null, object\\|resource given\\.$#"
|
||||
count: 2
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_affected_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_fetch_all expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_fetch_array expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_field_name expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_num_fields expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_num_rows expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$result of function pg_result_error expects PgSql\\\\Result, object\\|resource given\\.$#"
|
||||
count: 1
|
||||
path: www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
|
||||
|
||||
@@ -24,7 +24,9 @@ parameters:
|
||||
# do not check old qq file uploader tests
|
||||
- www/admin/qq_file_upload_*.php
|
||||
# ignore all test files
|
||||
- www/admin/class_test*php
|
||||
- www/admin/class_test*.php
|
||||
# extra in sub folder
|
||||
- www/admin/subfolder/class_test*.php
|
||||
- www/admin/error_test.php
|
||||
# admin synlink files
|
||||
- www/admin/edit_*.php
|
||||
@@ -47,9 +49,12 @@ parameters:
|
||||
- www/vendor
|
||||
# ignore errores with
|
||||
ignoreErrors:
|
||||
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*
|
||||
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*, only for 8.0 or lower
|
||||
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects resource(\\|null)?, object\\|resource(\\|bool)? given\\.$#"
|
||||
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
- # this is for 8.1 or newer
|
||||
message: "#^Parameter \\#1 \\$(result|connection) of function pg_\\w+ expects PgSql\\\\(Result|Connection(\\|null)?), object\\|resource given\\.$#"
|
||||
path: %currentWorkingDirectory%/www/lib/CoreLibs/DB/SQL/PgSQL.php
|
||||
# this is ignored for now
|
||||
# - '#Expression in empty\(\) is always falsy.#'
|
||||
# -
|
||||
|
||||
@@ -43,15 +43,23 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
// db config with logger
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log);
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ADMIN BACKEND';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// set acl, from eg login acl
|
||||
print "SETACL[]: " . $backend->setACL([]) . "<br>";
|
||||
print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "<br>";
|
||||
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
|
||||
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
|
||||
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
|
||||
|
||||
@@ -45,10 +45,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
// $_array = new CoreLibs\Combined\ArrayHandler();
|
||||
// $array_class = 'CoreLibs\Combination\ArrayHandler';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ARRAY HANDLER';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// recursive array search
|
||||
$test_array = [
|
||||
|
||||
@@ -32,10 +32,12 @@ ob_end_flush();
|
||||
|
||||
use CoreLibs\Convert\Byte;
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: AUTOLOADER';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$bytes = 10242424;
|
||||
$_bytes = Byte::humanReadableByteFormat($bytes);
|
||||
|
||||
@@ -43,10 +43,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$byte_class = 'CoreLibs\Convert\Byte';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: BYTE CONVERT';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// class
|
||||
$byte = 254779258;
|
||||
|
||||
@@ -44,10 +44,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$color_class = 'CoreLibs\Convert\Colors';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: COLORS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: COLORS</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
|
||||
59
www/admin/class_test.config.direct.php
Normal file
59
www/admin/class_test.config.direct.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require '../configs/config.php';
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-config-direct';
|
||||
ob_end_flush();
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "DIR: " . DIR . "<br>";
|
||||
print "BASE: " . BASE . "<br>";
|
||||
print "ROOT: " . ROOT . "<br>";
|
||||
print "BASE NAME: " . BASE_NAME . "<br>";
|
||||
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
|
||||
print "DB Name: " . DB_CONFIG_NAME . "<br>";
|
||||
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
59
www/admin/class_test.config.link.php
Normal file
59
www/admin/class_test.config.link.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-config-link';
|
||||
ob_end_flush();
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG LINK';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "DIR: " . DIR . "<br>";
|
||||
print "BASE: " . BASE . "<br>";
|
||||
print "ROOT: " . ROOT . "<br>";
|
||||
print "BASE NAME: " . BASE_NAME . "<br>";
|
||||
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
|
||||
print "DB Name: " . DB_CONFIG_NAME . "<br>";
|
||||
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
@@ -44,10 +44,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$datetime_class = 'CoreLibs\Combined\DateTime';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DATE/TIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// class
|
||||
$timestamp = 1622788315.123456;
|
||||
|
||||
@@ -39,10 +39,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$db->log->debug('START', '=============================>');
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DB';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DB</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "LOGFILE NAME: " . $db->log->getSetting('log_file_name') . "<br>";
|
||||
print "LOGFILE ID: " . $db->log->getSetting('log_file_id') . "<br>";
|
||||
|
||||
@@ -44,10 +44,12 @@ $debug = new CoreLibs\Debug\Logging([
|
||||
$debug_support_class = 'CoreLibs\Debug\Support';
|
||||
$debug_logging_class = 'CoreLibs\Debug\Logging';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: DEBUG';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
function test()
|
||||
{
|
||||
@@ -68,6 +70,9 @@ print "S::DEBUSTRING(s): " . DebugSupport::debugString('SET') . "<br>";
|
||||
print "S::DEBUSTRING(''): " . DebugSupport::debugString('') . "<br>";
|
||||
print "S::DEBUSTRING(,s): " . DebugSupport::debugString(null, '{-}') . "<br>";
|
||||
|
||||
// get test
|
||||
print "LOG FOLDER: " . $debug->getSetting('log_folder') . "<br>";
|
||||
|
||||
// debug
|
||||
print "C->DEBUG: " . $debug->debug('CLASS-TEST-DEBUG', 'Class Test Debug') . "<br>";
|
||||
print "C->DEBUG(html): " . $debug->debug('CLASS-TEST-DEBUG', 'HTML TAG<br><b>BOLD</b>') . "<br>";
|
||||
|
||||
@@ -43,10 +43,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// regex get
|
||||
print "S::GETEMAILREGEX(0): " . Email::getEmailRegex(0) . "<br>";
|
||||
|
||||
@@ -48,10 +48,12 @@ $_chk_enc = new CoreLibs\Check\Encoding();
|
||||
$_con_enc = new CoreLibs\Convert\Encoding();
|
||||
$chk_enc = 'CoreLibs\Check\Encoding';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ENCODING (CHECK/CONVERT/MIME)';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: ENCODING (CHECK/CONVERT/MIME)</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// print "Valid encoding: ".$log->printAr(mb_list_encodings())."<br>";
|
||||
|
||||
|
||||
@@ -42,10 +42,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FILE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FILE</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$file = '/some/path/to/some/file.txt';
|
||||
print "GETFILENAMEENDING: $file: " . File::getFilenameEnding($file) . "<br>";
|
||||
|
||||
@@ -45,10 +45,12 @@ $hash_class = 'CoreLibs\Create\Hash';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HASH';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HASH</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$to_crc = 'Some text block';
|
||||
// static
|
||||
|
||||
@@ -49,10 +49,12 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: HTML/ELEMENTS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$string = "Something < = > Other <br> Next line";
|
||||
print "HTMLENT: " . Html::htmlent($string) . ": " . $_html->htmlent($string) . "<br>";
|
||||
|
||||
@@ -46,10 +46,12 @@ $image_class = 'CoreLibs\Output\Image';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: IMAGE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// thumb sizes
|
||||
$thumb_width = 250;
|
||||
|
||||
@@ -46,10 +46,12 @@ $json_class = 'CoreLibs\Convert\Json';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: JSON';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: JSON</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$json = '{"foo": "bar"}';
|
||||
$output = Json::jsonConvertToArray($json);
|
||||
|
||||
@@ -19,8 +19,6 @@ ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// init language
|
||||
$lang = 'en_utf8';
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
@@ -31,24 +29,61 @@ if (!defined('SET_SESSION_NAME')) {
|
||||
$LOG_FILE_ID = 'classTest-lang';
|
||||
ob_end_flush();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LANG';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: LANG</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
use CoreLibs\Language\L10n;
|
||||
use CoreLibs\Debug\Support;
|
||||
|
||||
echo "<br><b>LIST LOCALES</b><br>";
|
||||
|
||||
$locale = 'en_US.UTF-8';
|
||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
|
||||
$locale = 'en.UTF-8';
|
||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||
print "[" . $locale . "] LOCALES: " . Support::printAr($locales) . "<br>";
|
||||
|
||||
echo "<br><b>LOCALE INFO</b><br>";
|
||||
$locale = 'en_US.UTF-8';
|
||||
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
|
||||
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
|
||||
$locale = 'en.UTF-8';
|
||||
$locale_info = CoreLibs\Language\L10n::parseLocale($locale);
|
||||
print "[" . $locale . "] INFO: " . Support::printAr($locale_info) . "<br>";
|
||||
|
||||
echo "<br><b>AUTO DETECT</b><br>";
|
||||
|
||||
$get_locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
print "[AUTO]: " . Support::printAr($get_locale) . "<br>";
|
||||
$get_locale = \CoreLibs\Language\GetLocale::setLocale('en', 'foo', 'ISO-8895');
|
||||
print "[OVERRIDE]: " . Support::printAr($get_locale) . "<br>";
|
||||
|
||||
// try to load non existing
|
||||
echo "<br><b>NEW TYPE</b><br>";
|
||||
// translate string
|
||||
$string = 'INPUT TEST';
|
||||
|
||||
echo "<br><b>LEGACY TEST</b><br>";
|
||||
|
||||
$lang = 'en_utf8';
|
||||
$l = new CoreLibs\Language\L10n($lang);
|
||||
// new path test
|
||||
$lang = 'ja';
|
||||
$domain = 'admin';
|
||||
$encoding = 'UTF-8';
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
// load direct
|
||||
$l = new CoreLibs\Language\L10n($lang, $domain, $path);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
@@ -62,63 +97,38 @@ $single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "CONTEXT MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. $l->__pn($context, $single_string, $multi_string, $n) . "<br>";
|
||||
. $l->__np($context, $single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
// switch to other language
|
||||
$lang = 'ja_utf8';
|
||||
$l->l10nReloadMOfile($lang);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
// switch to non existing language
|
||||
$lang = 'tr_utf8';
|
||||
$l->l10nReloadMOfile($lang);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
|
||||
echo "<br><b>LIST LOCALES</b><br>";
|
||||
|
||||
$locale = 'en_US.UTF-8';
|
||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||
print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "<br>";
|
||||
$locale = 'en.UTF-8';
|
||||
$locales = CoreLibs\Language\L10n::listLocales($locale);
|
||||
print "[" . $locale . "] LOCALES: " . CoreLibs\Debug\Support::printAr($locales) . "<br>";
|
||||
|
||||
// try to load non existing
|
||||
echo "<br><b>NEW TYPE</b><br>";
|
||||
// new path test
|
||||
$lang = 'ja';
|
||||
$domain = 'admin';
|
||||
$encoding = 'UTF-8';
|
||||
$path = BASE . INCLUDES . LOCALE;
|
||||
$l = new CoreLibs\Language\L10n($lang, $path, $domain, false);
|
||||
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. $l->__n($single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
// change domain
|
||||
$domain = 'frontend';
|
||||
$l->getTranslator('', $path, $domain);
|
||||
$l->getTranslator('', $domain, $path);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
// change language short type
|
||||
$lang = 'en';
|
||||
$domain = 'admin';
|
||||
$l->getTranslator($lang, $domain, $path);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
|
||||
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
|
||||
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
|
||||
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
|
||||
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
// chang to wrong language
|
||||
$lang = 'tr';
|
||||
$l->getTranslator($lang, $domain, $path);
|
||||
echo "*<br>";
|
||||
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
|
||||
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
|
||||
@@ -130,6 +140,7 @@ echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
|
||||
$lang = 'en';
|
||||
$domain = 'admin';
|
||||
echo "<br><b>STATIC TYPE TEST</b><br>";
|
||||
// static tests from l10n_load
|
||||
@@ -146,18 +157,30 @@ echo "<br><b>FUNCTIONS</b><br>";
|
||||
// real statisc test
|
||||
L10n::loadFunctions();
|
||||
$locale = 'ja';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
$locale = 'en_US.UTF-8';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
|
||||
63
www/admin/class_test.login.php
Normal file
63
www/admin/class_test.login.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-login';
|
||||
// init login & backend class
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
ob_end_flush();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LOGIN';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
echo "CHECK PERMISSION: " . ($login->loginCheckPermissions() ? 'OK' : 'BAD') . "<br>";
|
||||
echo "IS ADMIN: " . ($login->loginIsAdmin() ? 'OK' : 'BAD') . "<br>";
|
||||
echo "MIN ACCESS BASE: " . ($login->loginCheckAccessBase('admin') ? 'OK' : 'BAD') . "<br>";
|
||||
echo "MIN ACCESS PAGE: " . ($login->loginCheckAccessPage('admin') ? 'OK' : 'BAD') . "<br>";
|
||||
|
||||
echo "ACL: " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()) . "<br>";
|
||||
echo "ACL (MIN): " . \CoreLibs\Debug\Support::printAr($login->loginGetAcl()['min']) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
@@ -44,10 +44,12 @@ $math_class = 'CoreLibs\Convert\Math';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: MATH';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: MATH</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "FCEIL: " . $_math->fceil(5.1234567890, 5) . "<br>";
|
||||
print "FLOORP: " . $_math->floorp(5123456, -3) . "<br>";
|
||||
|
||||
@@ -41,10 +41,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$_mime = new CoreLibs\Convert\MimeAppName();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: MIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: MIME</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$mime = 'application/illustrator';
|
||||
print "MIME $mime: " . $_mime->mimeGetAppName($mime) . "<br>";
|
||||
|
||||
@@ -69,10 +69,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FORM GENERATE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "MOBILE PHONE: " . $form->mobile_phone . "<br>";
|
||||
// sets table array to include
|
||||
|
||||
@@ -46,10 +46,12 @@ $password_class = 'CoreLibs\Check\Password';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: PASSWORD';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$password = 'something1234';
|
||||
$enc_password = $_password->passwordSet($password);
|
||||
|
||||
@@ -41,7 +41,13 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log);
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
$backend->db->dbInfo(true);
|
||||
ob_end_flush();
|
||||
|
||||
@@ -75,13 +81,19 @@ print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
|
||||
print '<div><a href="class_test.output.form.php">Class Test: OUTPUT FORM</a></div>';
|
||||
print '<div><a href="class_test.admin.backend.php">Class Test: BACKEND ADMIN CLASS</a></div>';
|
||||
print '<div><a href="class_test.lang.php">Class Test: LANG/L10n</a></div>';
|
||||
print '<div><a href="class_test.session.php">Class Test: SESSION</a></div>';
|
||||
print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
|
||||
print '<div><a href="class_test.login.php">Class Test: LOGIN</a></div>';
|
||||
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
|
||||
print '<div><a href="class_test.config.link.php">Class Test: CONFIG LINK</a></div>';
|
||||
print '<div><a href="class_test.config.direct.php">Class Test: CONFIG DIRECT</a></div>';
|
||||
print '<div><a href="subfolder/class_test.config.direct.php">Class Test: CONFIG DIRECT SUB</a></div>';
|
||||
|
||||
print "<hr>";
|
||||
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
|
||||
// print all _ENV vars set
|
||||
print "<div>READ _ENV ARRAY:</div>";
|
||||
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
|
||||
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
|
||||
// set + check edit access id
|
||||
$edit_access_id = 3;
|
||||
if (is_object($login) && isset($login->acl['unit'])) {
|
||||
|
||||
@@ -46,10 +46,12 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
|
||||
|
||||
// define a list of from to color sets for conversion test
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: PHP VERSION';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: PHP VERSION</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$min_version_s = '7';
|
||||
$min_version_ss = '7.1';
|
||||
|
||||
@@ -43,10 +43,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$array_class = 'CoreLibs\Create\RandomKey';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: RANDOM KEY';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$key_length = 10;
|
||||
$key_length_b = 5;
|
||||
|
||||
@@ -34,10 +34,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
]);
|
||||
$ref_class = 'CoreLibs\Get\ReadEnvFile';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: READ ENV FILE';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "ALREADY from config.php: " . \CoreLibs\Debug\Support::printAr($_ENV) . "<br>";
|
||||
|
||||
|
||||
@@ -42,10 +42,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: RUNNING TIME';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
RunningTime::hrRunningTime();
|
||||
RunningTime::runningTime();
|
||||
|
||||
171
www/admin/class_test.session.php
Normal file
171
www/admin/class_test.session.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $status
|
||||
* @return string
|
||||
*/
|
||||
/** @phan-suppress-next-line PhanRedefineFunction */
|
||||
function getSessionStatusString(int $status): string
|
||||
{
|
||||
switch ($status) {
|
||||
case PHP_SESSION_DISABLED:
|
||||
$status = 'PHP_SESSION_DISABLED';
|
||||
break;
|
||||
case PHP_SESSION_NONE:
|
||||
$status = 'PHP_SESSION_NONE';
|
||||
break;
|
||||
case PHP_SESSION_ACTIVE:
|
||||
$status = 'PHP_SESSION_ACTIVE';
|
||||
break;
|
||||
default:
|
||||
$status = '[!] UNDEFINED';
|
||||
break;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
// if (!defined('SET_SESSION_NAME')) {
|
||||
// define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
// }
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-session';
|
||||
ob_end_flush();
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
use CoreLibs\Create\Session;
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$session_name = 'class-test-session';
|
||||
$var = 'foo';
|
||||
$value = 'bar';
|
||||
|
||||
foreach (['123', '123-123', '123abc'] as $_session_name) {
|
||||
print "[UNSET] Session Name valid for " . $_session_name . ": "
|
||||
. (Session::checkValidSessionName($_session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
}
|
||||
|
||||
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
|
||||
|
||||
print "[UNSET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
if (isset($_SESSION)) {
|
||||
print "[UNSET] _SESSION is: set<br>";
|
||||
} else {
|
||||
print "[UNSET] _SESSION is: not set<br>";
|
||||
}
|
||||
#
|
||||
print "[UNSET] To set session name valid: "
|
||||
. (Session::checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[SET] Current session id: " . $session . "<br>";
|
||||
}
|
||||
// set again
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[2 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[2 SET] Current session id: " . $session . "<br>";
|
||||
}
|
||||
print "[SET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
if (isset($_SESSION)) {
|
||||
print "[SET] _SESSION is: set<br>";
|
||||
} else {
|
||||
print "[SET] _SESSION is: not set<br>";
|
||||
}
|
||||
if (!isset($_SESSION['counter'])) {
|
||||
$_SESSION['counter'] = 0;
|
||||
}
|
||||
$_SESSION['counter']++;
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
$_SESSION[$var] = $value;
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] Confirm " . $var . " is " . $value . ": "
|
||||
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
||||
|
||||
// differnt session name
|
||||
$session_name = 'class-test-session-ALT';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[3 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[3 SET] Current session id: " . $session . "<br>";
|
||||
}
|
||||
print "[SET AGAIN] Current session id: " . Session::getSessionId() . "<br>";
|
||||
|
||||
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "<br>";
|
||||
|
||||
// close session
|
||||
Session::writeClose();
|
||||
// will never be written
|
||||
$_SESSION['will_never_be_written'] = 'empty';
|
||||
|
||||
// open again
|
||||
$session_name = 'class-test-session';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[4 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[4 SET] Current session id: " . $session . "<br>";
|
||||
}
|
||||
print "[START AGAIN] Current session id: " . Session::getSessionId() . "<br>";
|
||||
$_SESSION['will_be_written_again'] = 'Full';
|
||||
|
||||
// close session
|
||||
Session::writeClose();
|
||||
// invalid
|
||||
$session_name = '123';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[5 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[5 SET] Current session id: " . $session . "<br>";
|
||||
}
|
||||
print "[BAD NAME] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[BAD NAME] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[BAD NAME] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[BAD NAME] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
113
www/admin/class_test.session.read.php
Normal file
113
www/admin/class_test.session.read.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param int $status
|
||||
* @return string
|
||||
*/
|
||||
/** @phan-suppress-next-line PhanRedefineFunction */
|
||||
function getSessionStatusString(int $status): string
|
||||
{
|
||||
switch ($status) {
|
||||
case PHP_SESSION_DISABLED:
|
||||
$status = 'PHP_SESSION_DISABLED';
|
||||
break;
|
||||
case PHP_SESSION_NONE:
|
||||
$status = 'PHP_SESSION_NONE';
|
||||
break;
|
||||
case PHP_SESSION_ACTIVE:
|
||||
$status = 'PHP_SESSION_ACTIVE';
|
||||
break;
|
||||
default:
|
||||
$status = '[!] UNDEFINED';
|
||||
break;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-session.read';
|
||||
ob_end_flush();
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
use CoreLibs\Create\Session;
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION (READ)';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$session_name = 'class-test-session';
|
||||
// $session_name = '';
|
||||
$var = 'foo';
|
||||
$value = 'bar';
|
||||
|
||||
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
|
||||
|
||||
print "[UNSET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
// start
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "Current session id: " . $session . "<br>";
|
||||
}
|
||||
// set again
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[2] Session start failed<br>";
|
||||
} else {
|
||||
print "[2] Current session id: " . $session . "<br>";
|
||||
}
|
||||
print "[SET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] Confirm " . $var . " is " . $value . ": "
|
||||
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
||||
|
||||
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
@@ -19,8 +19,6 @@ ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', true);
|
||||
// set language
|
||||
$lang = 'en_utf8';
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// override ECHO ALL FALSE
|
||||
@@ -43,13 +41,20 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
||||
$l = new CoreLibs\Language\L10n($lang);
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SMARTY';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$smarty->DATA['JS_DEBUG'] = DEBUG;
|
||||
$smarty->MASTER_TEMPLATE_NAME = 'main_body.tpl';
|
||||
@@ -70,7 +75,8 @@ $smarty->setSmartyPaths();
|
||||
|
||||
// smarty test
|
||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
||||
$smarty->DATA['TRANSLATE_TEST'] = $l->__('Are we translated?');
|
||||
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
|
||||
$smarty->DATA['TRANSLATE_TEST_FUNCTION'] = _gettext('Are we translated?');
|
||||
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
||||
$smarty->DATA['replace'] = 'Replaced';
|
||||
// variable variables
|
||||
|
||||
@@ -42,12 +42,13 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$basic = new CoreLibs\Basic($log);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SYSTEM';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "GETHOSTNAME: " . DgS::printAr(System::getHostName()) . "<br>";
|
||||
print "GETPAGENAME(0): " . System::getPageName() . "<br>";
|
||||
|
||||
@@ -42,10 +42,12 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$_token = new CoreLibs\Output\Form\Token();
|
||||
$token_class = 'CoreLibs\Output\Form\Token';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: FORM TOKEN';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
$token = 'test_form_token';
|
||||
$token_id = $_token->setFormToken($token);
|
||||
|
||||
@@ -43,10 +43,12 @@ $_uids = new CoreLibs\Create\Uids();
|
||||
use CoreLibs\Create\Uids;
|
||||
$uids_class = 'CoreLibs\Create\Uids';
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: UIDS';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>TEST CLASS: UIDS</title><head>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
// class
|
||||
print "UUIDV4: " . $_uids->uuidv4() . "<br>";
|
||||
|
||||
59
www/admin/subfolder/class_test.config.direct.php
Normal file
59
www/admin/subfolder/class_test.config.direct.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php // phpcs:ignore warning
|
||||
|
||||
/**
|
||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$DEBUG_ALL_OVERRIDE = 0; // set to 1 to debug on live/remote server locations
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
|
||||
if ($DEBUG_ALL) {
|
||||
error_reporting(E_ALL | E_STRICT | E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR);
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
// basic class test file
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require '../../configs/config.php';
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-config-direct';
|
||||
ob_end_flush();
|
||||
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
// add file date
|
||||
'print_file_date' => true,
|
||||
// set debug and print flags
|
||||
'debug_all' => $DEBUG_ALL ?? false,
|
||||
'echo_all' => $ECHO_ALL ?? false,
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: CONFIG DIRECT SUB';
|
||||
print "<!DOCTYPE html>";
|
||||
print "<html><head><title>" . $PAGE_NAME . "</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="../class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "DIR: " . DIR . "<br>";
|
||||
print "BASE: " . BASE . "<br>";
|
||||
print "ROOT: " . ROOT . "<br>";
|
||||
print "BASE NAME: " . BASE_NAME . "<br>";
|
||||
echo "Config path prefix: " . $CONFIG_PATH_PREFIX . "<br>";
|
||||
print "DB Name: " . DB_CONFIG_NAME . "<br>";
|
||||
print "DB Config: " . \CoreLibs\Debug\Support::printAr(DB_CONFIG) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
@@ -27,9 +27,8 @@ $__LOCAL_CONFIG = [
|
||||
'db_host' => 'test',
|
||||
'location' => 'test',
|
||||
'debug_flag' => true,
|
||||
'site_lang' => 'en_US',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
'site_encoding' => 'UTF-8',
|
||||
'login_enabled' => true
|
||||
];
|
||||
|
||||
@@ -46,11 +45,10 @@ $SITE_CONFIG = [
|
||||
'location' => 'test',
|
||||
// show DEBUG override
|
||||
'debug_flag' => true,
|
||||
// site language
|
||||
'site_lang' => 'en_US',
|
||||
'site_encoding' => 'UTF-8',
|
||||
// lang + encoding
|
||||
// site locale
|
||||
'site_locale' => 'en_US.UTF-8',
|
||||
// site encoding
|
||||
'site_encoding' => 'UTF-8',
|
||||
// enable/disable login override
|
||||
'login_enabled' => true
|
||||
],
|
||||
|
||||
@@ -65,8 +65,6 @@ define('JS', 'javascript' . DIRECTORY_SEPARATOR);
|
||||
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
||||
// smarty libs path
|
||||
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
||||
// po langs [DEPRECAED: use LOCALE]
|
||||
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||
// po locale file
|
||||
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||
// cache path
|
||||
@@ -160,11 +158,10 @@ define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
|
||||
/************* LANGUAGE / ENCODING *******/
|
||||
define('DEFAULT_LANG', 'en_US');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
// default lang + encoding
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
// default web page encoding setting
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
|
||||
/************* LOGGING *******************/
|
||||
// below two can be defined here, but they should be
|
||||
@@ -262,9 +259,8 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
|
||||
// debug settings, site lang, etc
|
||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang'] ?? DEFAULT_LANG);
|
||||
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
|
||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
|
||||
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
|
||||
// paths
|
||||
|
||||
@@ -11,51 +11,68 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
define('CONFIG_PATH', 'configs' . DIRECTORY_SEPARATOR);
|
||||
// config path prefix search, start with 0, got down each level __DIR__ has, if nothing found -> bail
|
||||
// config path prefix search, start with 0, got down each level __DIR__ has,
|
||||
// if nothing found -> bail
|
||||
$CONFIG_PATH_PREFIX = '';
|
||||
// base path for loads
|
||||
$__DIR__PATH = __DIR__ . DIRECTORY_SEPARATOR;
|
||||
// don't load autoloader twice
|
||||
$end_autoload = false;
|
||||
for ($dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__)); $dir_pos <= $dir_max; $dir_pos++) {
|
||||
for (
|
||||
$dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__));
|
||||
$dir_pos <= $dir_max;
|
||||
$dir_pos++
|
||||
) {
|
||||
$CONFIG_PATH_PREFIX .= '..' . DIRECTORY_SEPARATOR;
|
||||
if ($end_autoload === false) {
|
||||
/************* AUTO LOADER *******************/
|
||||
// read auto loader for lib only
|
||||
// It is recommended to setup basic composer and use just one auto loader
|
||||
// if (is_file($CONFIG_PATH_PREFIX . 'lib' . DIRECTORY_SEPARATOR . 'autoloader.php')) {
|
||||
// require $CONFIG_PATH_PREFIX . 'lib' . DIRECTORY_SEPARATOR . 'autoloader.php';
|
||||
// $end_autoload = true;
|
||||
// }
|
||||
// composer auto loader, IF composer.json file includes classmap for lib/:
|
||||
// composer auto loader, in composer.json file add classmap for lib/:
|
||||
// "autoload": {
|
||||
// "classmap": [
|
||||
// "lib/"
|
||||
// ]
|
||||
// },
|
||||
// NOTE: MUST RUN composer dump-autoload if file/class names are changed or added
|
||||
// load auto loader
|
||||
if (is_file($CONFIG_PATH_PREFIX . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php')) {
|
||||
require $CONFIG_PATH_PREFIX . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
// NOTE: MUST RUN composer dump-autoload if file/class names are
|
||||
// changed or new ones are added
|
||||
if (
|
||||
is_file(
|
||||
$__DIR__PATH . $CONFIG_PATH_PREFIX
|
||||
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'
|
||||
)
|
||||
) {
|
||||
require $__DIR__PATH . $CONFIG_PATH_PREFIX
|
||||
. 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
$end_autoload = true;
|
||||
}
|
||||
// load enviorment file if it exists
|
||||
\CoreLibs\Get\ReadEnvFile::readEnvFile($CONFIG_PATH_PREFIX . CONFIG_PATH);
|
||||
}
|
||||
/************* MASTER CONFIG *******************/
|
||||
if (is_file($CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')) {
|
||||
if (
|
||||
is_file($__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')
|
||||
) {
|
||||
// load enviorment file if it exists
|
||||
\CoreLibs\Get\ReadEnvFile::readEnvFile(
|
||||
$__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH
|
||||
);
|
||||
// load master config file that loads all other config files
|
||||
require $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
|
||||
require $__DIR__PATH . $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fail if no base DIR is not set
|
||||
if (!defined('DIR')) {
|
||||
exit('Base config unloadable');
|
||||
exit('Base config could not be loaded');
|
||||
}
|
||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||
foreach (['admin', 'frontend'] as $folder) {
|
||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
|
||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if content path is empty, fallback is default
|
||||
/** @phpstan-ignore-next-line can be empty */
|
||||
if (empty($folder)) {
|
||||
$folder = 'default';
|
||||
}
|
||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2005/07/19
|
||||
* SHORT DESCRIPTION:
|
||||
* preset date variables
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/******
|
||||
All moved to CoreLibs\Combined\DateTime
|
||||
DAY_SHORT
|
||||
DAY_LONG
|
||||
MONTH_LONG
|
||||
MONTH_SHORT
|
||||
*******/
|
||||
trigger_error(
|
||||
'Date.VArs.php is deprecated. '
|
||||
. 'Use CoreLibs\Combined\DateTime:: with upper case old variable name',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
|
||||
$day_short = [
|
||||
1 => 'Mon',
|
||||
2 => 'Tue',
|
||||
3 => 'Wed',
|
||||
4 => 'Thu',
|
||||
5 => 'Fri',
|
||||
6 => 'Sat',
|
||||
7 => 'Sun'
|
||||
];
|
||||
|
||||
$day_long = [
|
||||
1 => 'Monday',
|
||||
2 => 'Tuesday',
|
||||
3 => 'Wednesday',
|
||||
4 => 'Thursday',
|
||||
5 => 'Friday',
|
||||
6 => 'Saturday',
|
||||
7 => 'Sunday'
|
||||
];
|
||||
|
||||
// months
|
||||
$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'
|
||||
];
|
||||
|
||||
$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'
|
||||
];
|
||||
|
||||
// __END__
|
||||
@@ -72,10 +72,19 @@ if (
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
// login & page access check
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
// lang, path, domain
|
||||
// pre auto detect language after login
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
// set lang and pass to smarty/backend
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
// create smarty object
|
||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
// create new Backend class with db and loger attached
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log);
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
// the menu show flag (what menu to show)
|
||||
$cms->menu_show_flag = 'main';
|
||||
// db info
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2007/09/03
|
||||
* SHORT DESCRIPTION:
|
||||
* set paths & language variables
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/******
|
||||
NOTE THAT THIS INCLUDE IS OBSOLETE
|
||||
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
|
||||
*******/
|
||||
trigger_error('admin_set_paths.php is deprecated. Use SmartyExtended->setSmartyPaths();', E_USER_DEPRECATED);
|
||||
if ($smarty) {
|
||||
$smarty->setSmartyPaths();
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
/********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2005/07/12
|
||||
* SHORT DESCRIPTION:
|
||||
* default smarty vars, and create output template for smarty
|
||||
* HISTORY:
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/******
|
||||
NOTE THAT THIS INCLUDE IS OBSOLETE
|
||||
USE THE BELOW FUNCTION CALL IN THE SCRIPT ITSELF
|
||||
*******/
|
||||
trigger_error(
|
||||
'admin_smarty.php is deprecated. Use SmartyExtended->setSmartyVarsAdmin(); or setSmartyVarsFrontend();',
|
||||
E_USER_DEPRECATED
|
||||
);
|
||||
$smarty->setSmartyVarsAdmin();
|
||||
|
||||
// __END__
|
||||
@@ -61,18 +61,27 @@ $log = new CoreLibs\Debug\Logging([
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
// login page
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
// lang, path, domain
|
||||
// pre auto detect language after login
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
// set lang and pass to smarty/backend
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
// flush and start
|
||||
ob_end_flush();
|
||||
// turn off set log per class
|
||||
$log->setLogPer('class', false);
|
||||
// create form class
|
||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, $l10n, $locale);
|
||||
if ($form->mobile_phone) {
|
||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||
exit;
|
||||
}
|
||||
// smarty template engine (extended Translation version)
|
||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
|
||||
// $form->log->debug('POST', $form->log->prAr($_POST));
|
||||
|
||||
@@ -437,16 +446,15 @@ if ($form->my_page_name == 'edit_order') {
|
||||
$t_q = '';
|
||||
foreach ($output as $output_file) {
|
||||
// split the ouput into folder and file
|
||||
// eg ../admin/test.php is ../admin/ and test.php
|
||||
preg_match("/([\.\/\w]+\/)+(\w+\.\w{1,})$/", $output_file, $matches);
|
||||
// if named config.php, skip
|
||||
if ($matches[2] != 'config.php') {
|
||||
if ($t_q) {
|
||||
$t_q .= ', ';
|
||||
}
|
||||
$t_q .= "('" . $form->dbEscapeString($matches[1]) . "', '"
|
||||
. $form->dbEscapeString($matches[2]) . "')";
|
||||
$pathinfo = pathinfo($output_file);
|
||||
if (!empty($pathinfo['dirname'])) {
|
||||
$pathinfo['dirname'] .= DIRECTORY_SEPARATOR;
|
||||
}
|
||||
if ($t_q) {
|
||||
$t_q .= ', ';
|
||||
}
|
||||
$t_q .= "('" . $form->dbEscapeString($pathinfo['dirname']) . "', '"
|
||||
. $form->dbEscapeString($pathinfo['basename']) . "')";
|
||||
}
|
||||
$form->dbExec($q . $t_q, 'NULL');
|
||||
$elements[] = $form->formCreateElement('filename');
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/en_US/LC_MESSAGES/admin.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/ja/LC_MESSAGES/admin.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/en_US/LC_MESSAGES/frontend.mo
|
||||
@@ -1 +0,0 @@
|
||||
../../locale/ja/LC_MESSAGES/frontend.mo
|
||||
Binary file not shown.
BIN
www/includes/locale/en/LC_MESSAGES/frontend.mo
Normal file
BIN
www/includes/locale/en/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -7,13 +7,19 @@
|
||||
<div>
|
||||
<b>Outside translation test</b><br>
|
||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
||||
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
|
||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
|
||||
</div>
|
||||
<div>
|
||||
<b>Translate Test with replace:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
|
||||
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
|
||||
Capture test: {$extra_title}<br>
|
||||
{section name=plural_test start=0 loop=3}
|
||||
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<b>Variable variables:</b><br>
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<div>
|
||||
{$SMARTY_TEST}
|
||||
</div>
|
||||
<div>
|
||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
|
||||
</div>
|
||||
<div>
|
||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test" name="drop_down_test">
|
||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div class="jq-container">
|
||||
<div id="jq-test" class="jp-test">
|
||||
<div id="test-div" class="test-div">
|
||||
Some content here or asdfasdfasf
|
||||
</div>
|
||||
<div id="translate-div">
|
||||
{* TRANSLATION SMARTY: {t}I should be translated{/t} *}
|
||||
TRANSLATION SMARTY: I should be translated
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="loop-test">
|
||||
<div>LOOP TEST</div>
|
||||
{section name=page_list start=1 loop=$loop_start+1}
|
||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||
{/section}
|
||||
</div>
|
||||
{* progresss indicator *}
|
||||
<div id="indicator"></div>
|
||||
{* the action confirm box *}
|
||||
<div id="actionBox" class="actionBoxElement"></div>
|
||||
{* The Overlay box *}
|
||||
<div id="overlayBox" class="overlayBoxElement"></div>
|
||||
@@ -164,16 +164,15 @@ class Login
|
||||
public $l;
|
||||
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||
* constructor, does ALL, opens db, works through connection checks,
|
||||
* finishes itself
|
||||
*
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
||||
* if null, auto set
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
?\CoreLibs\Language\L10n $l10n = null
|
||||
\CoreLibs\Debug\Logging $log
|
||||
) {
|
||||
// log login data for this class only
|
||||
$log->setLogPer('class', true);
|
||||
@@ -194,6 +193,7 @@ class Login
|
||||
// check if session exists and could be created
|
||||
// TODO: move session creation and check to outside?
|
||||
if (Session::startSession() === false) {
|
||||
$this->login_error = 1;
|
||||
echo '<b>Session not started or could not be started!</b><br>'
|
||||
. 'Use \'\CoreLibs\Create\Session::startSession();\'.<br>'
|
||||
. 'For less problems with other session, you can set a '
|
||||
@@ -203,31 +203,16 @@ class Login
|
||||
|
||||
// pre-check that password min/max lengths are inbetween 1 and 255;
|
||||
if ($this->password_max_length > 255) {
|
||||
echo '<b>Settings problem</b> PMaL<br>';
|
||||
exit;
|
||||
$this->password_max_length = 255;
|
||||
}
|
||||
if ($this->password_min_length < 1) {
|
||||
echo '<b>Settings problem</b> PMiL<br>';
|
||||
exit;
|
||||
$this->password_min_length = 1;
|
||||
}
|
||||
|
||||
// set global is ajax page for if we show the data directly,
|
||||
// or need to pass it back
|
||||
// to the continue AJAX class for output back to the user
|
||||
$this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false;
|
||||
// set the default lang
|
||||
$locale = 'en_US.UTF-8';
|
||||
$lang = 'en_utf8';
|
||||
if (Session::getSessionId() !== false && !empty($_SESSION['DEFAULT_LANG'])) {
|
||||
$lang = $_SESSION['DEFAULT_LANG'];
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'];
|
||||
} else {
|
||||
$lang = defined('SITE_LANG') && !empty(SITE_LANG) ?
|
||||
SITE_LANG : DEFAULT_LANG;
|
||||
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||
SITE_LOCALE : DEFAULT_LOCALE;
|
||||
}
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n($lang);
|
||||
|
||||
// if we have a search path we need to set it, to use the correct DB to login
|
||||
// check what schema to use. if there is a login schema use this, else check
|
||||
@@ -283,7 +268,8 @@ class Login
|
||||
// init default ACL list array
|
||||
$_SESSION['DEFAULT_ACL_LIST'] = [];
|
||||
// read the current edit_access_right list into an array
|
||||
$q = "SELECT level, type, name FROM edit_access_right WHERE level >= 0 ORDER BY level";
|
||||
$q = "SELECT level, type, name FROM edit_access_right "
|
||||
. "WHERE level >= 0 ORDER BY level";
|
||||
while (is_array($res = $this->db->dbReturn($q))) {
|
||||
// level to description format (numeric)
|
||||
$this->default_acl_list[$res['level']] = [
|
||||
@@ -300,6 +286,27 @@ class Login
|
||||
$this->loginCheckPermissions();
|
||||
// logsout user
|
||||
$this->loginLogoutUser();
|
||||
// ** LANGUAGE SET AFTER LOGIN **
|
||||
// set the locale
|
||||
if (
|
||||
Session::getSessionId() !== false &&
|
||||
!empty($_SESSION['DEFAULT_LANG'])
|
||||
) {
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'] ?? '';
|
||||
} else {
|
||||
$locale = defined('SITE_LOCALE') && !empty(SITE_LOCALE) ?
|
||||
SITE_LOCALE :
|
||||
/** @phpstan-ignore-next-line DEFAULT_LOCALE could be empty */
|
||||
(defined('DEFAULT_LOCALE') && !empty(DEFAULT_LOCALE) ?
|
||||
DEFAULT_LOCALE : 'en.UTF-8');
|
||||
}
|
||||
// set domain
|
||||
if (defined('CONTENT_PATH') && !empty(CONTENT_PATH)) {
|
||||
$domain = str_replace('/', '', CONTENT_PATH);
|
||||
} else {
|
||||
$domain = 'admin';
|
||||
}
|
||||
$this->l = new \CoreLibs\Language\L10n($locale, $domain);
|
||||
// if the password change flag is okay, run the password change method
|
||||
if ($this->password_change) {
|
||||
$this->loginPasswordChange();
|
||||
@@ -312,7 +319,8 @@ class Login
|
||||
$this->login_html = $this->loginPrintLogin();
|
||||
// closing all connections, depending on error status, exit
|
||||
if (!$this->loginCloseClass()) {
|
||||
// if variable AJAX flag is not set, show output, else pass through for ajax work
|
||||
// if variable AJAX flag is not set, show output
|
||||
// else pass through for ajax work
|
||||
if ($this->login_is_ajax_page !== true) {
|
||||
// the login screen if we hav no login permission & login screen html data
|
||||
if ($this->login_html !== null) {
|
||||
@@ -358,8 +366,13 @@ class Login
|
||||
// NO OP
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// **** PRIVATE INTERNAL
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* checks if password is valid, sets internal error login variable
|
||||
*
|
||||
* @param string $hash password hash
|
||||
* @param string $password submitted password
|
||||
* @return bool true or false on password ok or not
|
||||
@@ -416,7 +429,9 @@ class Login
|
||||
}
|
||||
|
||||
/**
|
||||
* if user pressed login button this script is called, but only if there is no preview euid set]
|
||||
* if user pressed login button this script is called,
|
||||
* but only if there is no preview euid set
|
||||
*
|
||||
* @return void has not return
|
||||
*/
|
||||
private function loginLoginUser(): void
|
||||
@@ -700,88 +715,6 @@ class Login
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* for every page the user access this script checks if he is allowed to do so
|
||||
* @return bool permission okay as true/false
|
||||
*/
|
||||
public function loginCheckPermissions(): bool
|
||||
{
|
||||
if ($this->euid && $this->login_error != 103) {
|
||||
$q = "SELECT filename "
|
||||
. "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu "
|
||||
. "WHERE ep.edit_page_id = epa.edit_page_id "
|
||||
. "AND eg.edit_group_id = epa.edit_group_id "
|
||||
. "AND eg.edit_group_id = eu.edit_group_id "
|
||||
. "AND eu.edit_user_id = " . $this->euid . " "
|
||||
. "AND filename = '" . $this->page_name . "' "
|
||||
. "AND eg.enabled = 1 AND epa.enabled = 1";
|
||||
$res = $this->db->dbReturnRow($q);
|
||||
if (!is_array($res)) {
|
||||
$this->login_error = 109;
|
||||
$this->permission_okay = false;
|
||||
return $this->permission_okay;
|
||||
}
|
||||
if (isset($res['filename']) && $res['filename'] == $this->page_name) {
|
||||
$this->permission_okay = true;
|
||||
} else {
|
||||
$this->login_error = 103;
|
||||
$this->permission_okay = false;
|
||||
}
|
||||
}
|
||||
// if called from public, so we can check if the permissions are ok
|
||||
return $this->permission_okay;
|
||||
}
|
||||
|
||||
/**
|
||||
* if a user pressed on logout, destroyes session and unsets all global vars
|
||||
* @return void has no return
|
||||
*/
|
||||
public function loginLogoutUser(): void
|
||||
{
|
||||
// must be either logout or error
|
||||
if (!$this->logout && !$this->login_error) {
|
||||
return;
|
||||
}
|
||||
// unregister and destroy session vars
|
||||
foreach (
|
||||
// TODO move this into some global array for easier update
|
||||
[
|
||||
'ADMIN',
|
||||
'BASE_ACL_LEVEL',
|
||||
'DB_DEBUG',
|
||||
'DEBUG_ALL',
|
||||
'DEFAULT_ACL_LIST',
|
||||
'DEFAULT_CHARSET',
|
||||
'DEFAULT_LANG',
|
||||
'DEFAULT_LOCALE',
|
||||
'EAID',
|
||||
'EUID',
|
||||
'GROUP_ACL_LEVEL',
|
||||
'GROUP_ACL_TYPE',
|
||||
'GROUP_NAME',
|
||||
'HEADER_COLOR',
|
||||
'LANG',
|
||||
'PAGES_ACL_LEVEL',
|
||||
'PAGES',
|
||||
'TEMPLATE',
|
||||
'UNIT_ACL_LEVEL',
|
||||
'UNIT_DEFAULT',
|
||||
'UNIT',
|
||||
'USER_ACL_LEVEL',
|
||||
'USER_ACL_TYPE',
|
||||
'USER_NAME',
|
||||
] as $session_var
|
||||
) {
|
||||
unset($_SESSION[$session_var]);
|
||||
}
|
||||
// final unset all
|
||||
session_unset();
|
||||
// final destroy session
|
||||
session_destroy();
|
||||
// then prints the login screen again
|
||||
$this->permission_okay = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets all the basic ACLs
|
||||
* init set the basic acl the user has, based on the following rules
|
||||
@@ -797,6 +730,7 @@ class Login
|
||||
* - if an account ACL is set, set this parallel, account ACL overrides user ACL if it applies
|
||||
* - if edit access ACL level is set, use this, else use page
|
||||
* set all base ACL levels as a list keyword -> ACL number
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginSetAcl(): void
|
||||
@@ -835,10 +769,10 @@ class Login
|
||||
$_SESSION['BASE_ACL_LEVEL'] = $this->acl['base'];
|
||||
|
||||
// set the current page acl
|
||||
// start with default acl
|
||||
// start with base acl
|
||||
// set group if not -1, overrides default
|
||||
// set page if not -1, overrides group set
|
||||
$this->acl['page'] = DEFAULT_ACL_LEVEL;
|
||||
$this->acl['page'] = $this->acl['base'];
|
||||
if ($_SESSION['GROUP_ACL_LEVEL'] != -1) {
|
||||
$this->acl['page'] = $_SESSION['GROUP_ACL_LEVEL'];
|
||||
}
|
||||
@@ -883,37 +817,47 @@ class Login
|
||||
$this->acl['show_ea_extra'] = false;
|
||||
}
|
||||
// set the default edit access
|
||||
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'];
|
||||
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||
$this->acl['min'] = [];
|
||||
// integrate the type acl list, but only for the keyword -> level
|
||||
foreach ($this->default_acl_list as $level => $data) {
|
||||
$this->acl['min'][$data['type']] = $level;
|
||||
}
|
||||
// set the full acl list too
|
||||
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'];
|
||||
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'] ?? [];
|
||||
// debug
|
||||
// $this->debug('ACL', $this->print_ar($this->acl));
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if this edit access id is valid
|
||||
* @param int|null $edit_access_id access id pk to check
|
||||
* @return bool true/false: if the edit access is not
|
||||
* in the valid list: false
|
||||
* Check if source (page, base) is matching to the given min access string
|
||||
* min access string must be valid access level string (eg read, mod, write)
|
||||
* This does not take in account admin flag set
|
||||
*
|
||||
* @param string $source a valid base level string eg base, page
|
||||
* @param string $min_access a valid min level string, eg read, mod, siteadmin
|
||||
* @return bool True for valid access, False for invalid
|
||||
*/
|
||||
public function loginCheckEditAccess($edit_access_id): bool
|
||||
public function loginCheckAccess(string $source, string $min_access): bool
|
||||
{
|
||||
if ($edit_access_id === null) {
|
||||
$source = 'base';
|
||||
if (
|
||||
empty($this->acl['min'][$min_access]) ||
|
||||
empty($this->acl[$source])
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if (array_key_exists($edit_access_id, $this->acl['unit'])) {
|
||||
// phan claims $this->acl['min'] can be null, but above should skip
|
||||
/** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */
|
||||
if ($this->acl[$source] >= $this->acl['min'][$min_access]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the password is in a valid format
|
||||
*
|
||||
* @param string $password the new password
|
||||
* @return bool true or false if valid password or not
|
||||
*/
|
||||
@@ -937,6 +881,7 @@ class Login
|
||||
|
||||
/**
|
||||
* dummy declare for password forget
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginPasswordForgot(): void
|
||||
@@ -944,25 +889,9 @@ class Login
|
||||
// will do some password recovert, eg send email
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the minium length and checks on valid
|
||||
* @param int $length set the minimum length
|
||||
* @return bool true/false on success
|
||||
*/
|
||||
public function loginSetPasswordMinLength(int $length): bool
|
||||
{
|
||||
// check that numeric, positive numeric, not longer than max input string lenght
|
||||
// and not short than min password length
|
||||
if (is_numeric($length) && $length >= PASSWORD_MIN_LENGTH && $length <= $this->password_max_length) {
|
||||
$this->password_min_length = $length;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* changes a user password
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginPasswordChange(): void
|
||||
@@ -1063,6 +992,7 @@ class Login
|
||||
|
||||
/**
|
||||
* prints out login html part if no permission (error) is set
|
||||
*
|
||||
* @return string|null html data for login page, or null for nothing
|
||||
*/
|
||||
private function loginPrintLogin()
|
||||
@@ -1168,6 +1098,7 @@ class Login
|
||||
/**
|
||||
* last function called, writes log and prints out error msg and
|
||||
* exists script if permission 0
|
||||
*
|
||||
* @return bool true on permission ok, false on permission wrong
|
||||
*/
|
||||
private function loginCloseClass(): bool
|
||||
@@ -1206,6 +1137,7 @@ class Login
|
||||
|
||||
/**
|
||||
* checks if there are external templates, if not uses internal fallback ones
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
private function loginSetTemplates(): void
|
||||
@@ -1387,6 +1319,7 @@ EOM;
|
||||
|
||||
/**
|
||||
* writes detailed data into the edit user log table (keep log what user does)
|
||||
*
|
||||
* @param string $event string of what has been done
|
||||
* @param string $data data information (id, etc)
|
||||
* @param string|int $error error id (mostly an int)
|
||||
@@ -1447,11 +1380,190 @@ EOM;
|
||||
$this->db->dbExec($q, 'NULL');
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// **** PUBLIC INTERNAL
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* sets the minium length and checks on valid
|
||||
*
|
||||
* @param int $length set the minimum length
|
||||
* @return bool true/false on success
|
||||
*/
|
||||
public function loginSetPasswordMinLength(int $length): bool
|
||||
{
|
||||
// check that numeric, positive numeric, not longer than max input string lenght
|
||||
// and not short than min password length
|
||||
if (is_numeric($length) && $length >= PASSWORD_MIN_LENGTH && $length <= $this->password_max_length) {
|
||||
$this->password_min_length = $length;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* if a user pressed on logout, destroyes session and unsets all global vars
|
||||
*
|
||||
* @return void has no return
|
||||
*/
|
||||
public function loginLogoutUser(): void
|
||||
{
|
||||
// must be either logout or error
|
||||
if (!$this->logout && !$this->login_error) {
|
||||
return;
|
||||
}
|
||||
// unregister and destroy session vars
|
||||
foreach (
|
||||
// TODO move this into some global array for easier update
|
||||
[
|
||||
'ADMIN',
|
||||
'BASE_ACL_LEVEL',
|
||||
'DB_DEBUG',
|
||||
'DEBUG_ALL',
|
||||
'DEFAULT_ACL_LIST',
|
||||
'DEFAULT_CHARSET',
|
||||
'DEFAULT_LANG',
|
||||
'DEFAULT_LOCALE',
|
||||
'EAID',
|
||||
'EUID',
|
||||
'GROUP_ACL_LEVEL',
|
||||
'GROUP_ACL_TYPE',
|
||||
'GROUP_NAME',
|
||||
'HEADER_COLOR',
|
||||
'LANG',
|
||||
'PAGES_ACL_LEVEL',
|
||||
'PAGES',
|
||||
'TEMPLATE',
|
||||
'UNIT_ACL_LEVEL',
|
||||
'UNIT_DEFAULT',
|
||||
'UNIT',
|
||||
'USER_ACL_LEVEL',
|
||||
'USER_ACL_TYPE',
|
||||
'USER_NAME',
|
||||
] as $session_var
|
||||
) {
|
||||
unset($_SESSION[$session_var]);
|
||||
}
|
||||
// final unset all
|
||||
session_unset();
|
||||
// final destroy session
|
||||
session_destroy();
|
||||
// then prints the login screen again
|
||||
$this->permission_okay = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* for every page the user access this script checks if he is allowed to do so
|
||||
*
|
||||
* @return bool permission okay as true/false
|
||||
*/
|
||||
public function loginCheckPermissions(): bool
|
||||
{
|
||||
// start with not allowed
|
||||
$this->permission_okay = false;
|
||||
// bail for no euid (no login)
|
||||
if (!$this->euid) {
|
||||
return $this->permission_okay;
|
||||
}
|
||||
// bail for previous wrong page match, eg if method is called twice
|
||||
if ($this->login_error == 103) {
|
||||
return $this->permission_okay;
|
||||
}
|
||||
// if ($this->euid && $this->login_error != 103) {
|
||||
$q = "SELECT filename "
|
||||
. "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu "
|
||||
. "WHERE ep.edit_page_id = epa.edit_page_id "
|
||||
. "AND eg.edit_group_id = epa.edit_group_id "
|
||||
. "AND eg.edit_group_id = eu.edit_group_id "
|
||||
. "AND eu.edit_user_id = " . $this->euid . " "
|
||||
. "AND filename = '" . $this->page_name . "' "
|
||||
. "AND eg.enabled = 1 AND epa.enabled = 1";
|
||||
$res = $this->db->dbReturnRow($q);
|
||||
if (!is_array($res)) {
|
||||
$this->login_error = 109;
|
||||
return $this->permission_okay;
|
||||
}
|
||||
if (isset($res['filename']) && $res['filename'] == $this->page_name) {
|
||||
$this->permission_okay = true;
|
||||
} else {
|
||||
$this->login_error = 103;
|
||||
}
|
||||
// if called from public, so we can check if the permissions are ok
|
||||
return $this->permission_okay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return ACL array as is
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function loginGetAcl(): array
|
||||
{
|
||||
return $this->acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if this edit access id is valid
|
||||
*
|
||||
* @param int|null $edit_access_id access id pk to check
|
||||
* @return bool true/false: if the edit access is not
|
||||
* in the valid list: false
|
||||
*/
|
||||
public function loginCheckEditAccess($edit_access_id): bool
|
||||
{
|
||||
if ($edit_access_id === null) {
|
||||
return false;
|
||||
}
|
||||
if (array_key_exists($edit_access_id, $this->acl['unit'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if admin flag is set
|
||||
*
|
||||
* @return bool True if admin flag set
|
||||
*/
|
||||
public function loginIsAdmin(): bool
|
||||
{
|
||||
if (!empty($this->acl['admin'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if min accesss string (eg, read, mod, etc) is matchable
|
||||
* EQUAL to BASE set right
|
||||
*
|
||||
* @param string $min_access
|
||||
* @return bool
|
||||
*/
|
||||
public function loginCheckAccessBase(string $min_access): bool
|
||||
{
|
||||
return $this->loginCheckAccess('base', $min_access);
|
||||
}
|
||||
|
||||
/**
|
||||
* check if min accesss string (eg, read, mod, etc) is matchable
|
||||
* EQUAL to PAGE set right
|
||||
*
|
||||
* @param string $min_access
|
||||
* @return bool
|
||||
*/
|
||||
public function loginCheckAccessPage(string $min_access): bool
|
||||
{
|
||||
return $this->loginCheckAccess('page', $min_access);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks that the given edit access id is valid for this user
|
||||
*
|
||||
* @param int|null $edit_access_id edit access id to check
|
||||
* @return int|null same edit access id if ok
|
||||
* or the default edit access id if given one is not valid
|
||||
* or the default edit access id
|
||||
* if given one is not valid
|
||||
*/
|
||||
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
||||
{
|
||||
@@ -1461,15 +1573,15 @@ EOM;
|
||||
is_array($_SESSION['UNIT']) &&
|
||||
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
|
||||
) {
|
||||
return (int)$_SESSION['UNIT_DEFAULT'];
|
||||
} else {
|
||||
return $edit_access_id;
|
||||
return $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||
}
|
||||
return $edit_access_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* retunrn a set entry from the UNIT session for an edit access_id
|
||||
* if not found return false
|
||||
*
|
||||
* @param int $edit_access_id edit access id
|
||||
* @param string|int $data_key key value to search for
|
||||
* @return bool|string false for not found or string for found data
|
||||
@@ -1478,9 +1590,8 @@ EOM;
|
||||
{
|
||||
if (!isset($_SESSION['UNIT'][$edit_access_id]['data'][$data_key])) {
|
||||
return false;
|
||||
} else {
|
||||
return $_SESSION['UNIT'][$edit_access_id]['data'][$data_key];
|
||||
}
|
||||
return $_SESSION['UNIT'][$edit_access_id]['data'][$data_key];
|
||||
}
|
||||
// close class
|
||||
}
|
||||
|
||||
@@ -114,15 +114,16 @@ class Backend
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
/**
|
||||
* main class constructor
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
||||
* if null, auto set
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging 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\Language\L10n $l10n = null
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
array $locale
|
||||
) {
|
||||
// set to log not per class
|
||||
$log->setLogPer('class', false);
|
||||
@@ -130,10 +131,15 @@ class Backend
|
||||
$this->log = $log;
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
// TODO lang create outside of class
|
||||
$this->setLangEncoding();
|
||||
// get the language sub class & init it
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
|
||||
$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();
|
||||
@@ -159,29 +165,6 @@ class Backend
|
||||
// NO OP
|
||||
}
|
||||
|
||||
// INTERNAL METHODS |===============================================>
|
||||
|
||||
/**
|
||||
* set the language encoding and language settings
|
||||
* use $OVERRIDE_LANG to override all language settings
|
||||
* the default charset from _SESSION login or from
|
||||
* config DEFAULT ENCODING
|
||||
* the lang full name for mo loading from _SESSION login
|
||||
* or SITE LANG or DEFAULT LANG from config
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
list (
|
||||
$this->encoding,
|
||||
$this->lang,
|
||||
$this->lang_short,
|
||||
$this->domain,
|
||||
$this->lang_dir
|
||||
) = \CoreLibs\Language\GetSettings::setLangEncoding();
|
||||
}
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,11 +85,13 @@ class Basic
|
||||
* main Basic constructor to init and check base settings
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
* @param string|null $session_name Set session name
|
||||
* @deprecated DO NOT USE Class\Basic anymore. Use dedicated logger and sub classes
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\Debug\Logging $log = null,
|
||||
?string $session_name = null
|
||||
) {
|
||||
trigger_error('Class \CoreLibs\Basic is deprected', E_USER_DEPRECATED);
|
||||
// TODO make check dynamic for entries we MUST have depending on load type
|
||||
// before we start any work, we should check that all MUST constants are defined
|
||||
$abort = false;
|
||||
|
||||
@@ -218,7 +218,8 @@ class ArrayHandler
|
||||
continue;
|
||||
}
|
||||
foreach ($array as $key => $value) {
|
||||
// if string or if key is assumed to be string do key match else add new entry
|
||||
// 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);
|
||||
|
||||
@@ -20,7 +20,7 @@ class DateTime
|
||||
4 => 'Thu',
|
||||
5 => 'Fri',
|
||||
6 => 'Sat',
|
||||
7 => 'Sun'
|
||||
7 => 'Sun',
|
||||
];
|
||||
/** @var array<int,string> */
|
||||
public const DAY_LONG = [
|
||||
@@ -30,7 +30,7 @@ class DateTime
|
||||
4 => 'Thursday',
|
||||
5 => 'Friday',
|
||||
6 => 'Saturday',
|
||||
7 => 'Sunday'
|
||||
7 => 'Sunday',
|
||||
];
|
||||
/** @var array<int,string> */
|
||||
public const MONTH_LONG = [
|
||||
@@ -45,7 +45,7 @@ class DateTime
|
||||
9 => 'September',
|
||||
10 => 'October',
|
||||
11 => 'November',
|
||||
12 => 'December'
|
||||
12 => 'December',
|
||||
];
|
||||
/** @var array<int,string> */
|
||||
public const MONTH_SHORT = [
|
||||
@@ -60,7 +60,7 @@ class DateTime
|
||||
9 => 'Sep',
|
||||
10 => 'Oct',
|
||||
11 => 'Nov',
|
||||
12 => 'Dec'
|
||||
12 => 'Dec',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -349,7 +349,7 @@ class DateTime
|
||||
try {
|
||||
$start = new \DateTime($start_date);
|
||||
$end = new \DateTime($end_date);
|
||||
} catch (Exception) {
|
||||
} catch (Exception $e) {
|
||||
if ($return_named === true) {
|
||||
return [
|
||||
'overall' => 0,
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace CoreLibs\Create;
|
||||
|
||||
class Session
|
||||
{
|
||||
/** @var string list for errors*/
|
||||
private static $error_str = '';
|
||||
|
||||
/**
|
||||
* init a session
|
||||
*/
|
||||
@@ -25,6 +28,41 @@ class Session
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return set error string, empty if none set
|
||||
*
|
||||
* @return string Last error string
|
||||
*/
|
||||
public static function getErrorStr(): string
|
||||
{
|
||||
return self::$error_str;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if session name is valid
|
||||
*
|
||||
* As from PHP 8.1/8.0/7.4 error
|
||||
* INVALID CHARS: =,; \t\r\n\013\014
|
||||
* NOTE: using . will fail even thought valid
|
||||
* we allow only alphanumeric with - (dash) and 1 to 128 characters
|
||||
*
|
||||
* @param string $session_name any string, not null
|
||||
* @return bool True for valid, False for invalid
|
||||
*/
|
||||
public static function checkValidSessionName(string $session_name): bool
|
||||
{
|
||||
// check
|
||||
if (
|
||||
// must only have those
|
||||
!preg_match('/^[-a-zA-Z0-9]{1,128}$/', $session_name) ||
|
||||
// cannot be only numbers
|
||||
preg_match('/^[0-9]+$/', $session_name)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@@ -35,10 +73,12 @@ class Session
|
||||
{
|
||||
// we can't start sessions on command line
|
||||
if (php_sapi_name() === 'cli') {
|
||||
self::$error_str = '[SESSION] No sessions in php cli';
|
||||
return false;
|
||||
}
|
||||
// if session are OFF
|
||||
if (self::getSessionStatus() === PHP_SESSION_DISABLED) {
|
||||
self::$error_str = '[SESSION] Sessions are disabled';
|
||||
return false;
|
||||
}
|
||||
// session_status
|
||||
@@ -59,6 +99,11 @@ class Session
|
||||
}
|
||||
// if set, set special session name
|
||||
if (!empty($session_name)) {
|
||||
// invalid session name, abort
|
||||
if (!self::checkValidSessionName($session_name)) {
|
||||
self::$error_str = '[SESSION] Invalid session name: ' . $session_name;
|
||||
return false;
|
||||
}
|
||||
session_name($session_name);
|
||||
}
|
||||
// start session
|
||||
@@ -66,6 +111,7 @@ class Session
|
||||
}
|
||||
// if we still have no active session
|
||||
if (!self::checkActiveSession()) {
|
||||
self::$error_str = '[SESSION] Failed to activate session';
|
||||
return false;
|
||||
}
|
||||
return self::getSessionId();
|
||||
@@ -95,7 +141,7 @@ class Session
|
||||
* Checks if there is an active session.
|
||||
* Does not check if we can have a session
|
||||
*
|
||||
* @return boolean True if there is an active session, else false
|
||||
* @return bool True if there is an active session, else false
|
||||
*/
|
||||
public static function checkActiveSession(): bool
|
||||
{
|
||||
@@ -106,6 +152,19 @@ class Session
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* unlock the session file, so concurrent AJAX requests can be done
|
||||
* NOTE: after this has been called, no changes in _SESSION will be stored
|
||||
* NOTE: a new session with a different name can be started after this one is called
|
||||
* if problem, run ob_flush() and flush() too
|
||||
*
|
||||
* @return bool True und sucess, false on failure
|
||||
*/
|
||||
public static function writeClose(): bool
|
||||
{
|
||||
return session_write_close();
|
||||
}
|
||||
|
||||
/**
|
||||
* get session status
|
||||
* PHP_SESSION_DISABLED if sessions are disabled.
|
||||
|
||||
@@ -43,7 +43,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
/** @var string */
|
||||
public $table_name; // the table_name
|
||||
/** @var string */
|
||||
public $pk_name; // the primary key from this table
|
||||
public $pk_name = ''; // the primary key from this table
|
||||
/** @var int|string|null */
|
||||
public $pk_id; // the PK id
|
||||
|
||||
@@ -503,7 +503,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// max id, falls INSERT
|
||||
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
|
||||
if (is_array($res = $this->dbReturnRow($q))) {
|
||||
$pk_id = $res['pkd_id'];
|
||||
$pk_id = $res['pk_id'];
|
||||
} else {
|
||||
$pk_id = 1;
|
||||
}
|
||||
|
||||
@@ -604,7 +604,7 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||
return '';
|
||||
}
|
||||
// extract element
|
||||
$return_string = pg_version($this->dbh)[$parameter] ?? '';
|
||||
$return_string = (string)(pg_version($this->dbh)[$parameter] ?? '');
|
||||
// for version, strip if requested
|
||||
if (
|
||||
in_array($parameter, ['server']) &&
|
||||
|
||||
@@ -401,10 +401,10 @@ class Logging
|
||||
|
||||
/**
|
||||
* Temporary method to read all class variables for testing purpose
|
||||
* @param string $name
|
||||
* @return mixed can be anything, bool, string, int, array
|
||||
* @param string $name what variable to return
|
||||
* @return mixed can be anything, bool, string, int, array
|
||||
*/
|
||||
public function getSetting(string $name): mixed
|
||||
public function getSetting(string $name) //:mixed DOES not work with PHP 7.4
|
||||
{
|
||||
// for debug purpose only
|
||||
return $this->{$name};
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Encoding::getErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Check\Encoding::getErrorChar
|
||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||
*/
|
||||
|
||||
|
||||
117
www/lib/CoreLibs/Language/GetLocale.php
Normal file
117
www/lib/CoreLibs/Language/GetLocale.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public static function setLocale(
|
||||
?string $locale = null,
|
||||
?string $domain = null,
|
||||
?string $encoding = null,
|
||||
?string $path = null
|
||||
): array {
|
||||
// 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 {
|
||||
// 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 no domain is set, fall back to content path
|
||||
$domain = str_replace('/', '', 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 {
|
||||
// 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)
|
||||
) {
|
||||
$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'] ?? 'en')
|
||||
// add country only if set
|
||||
. (!empty($matches['country']) ? '_' . $matches['country'] : '');
|
||||
} else {
|
||||
$lang = 'en';
|
||||
}
|
||||
return [
|
||||
'locale' => $locale,
|
||||
'lang' => $lang,
|
||||
'domain' => $domain,
|
||||
'encoding' => $encoding,
|
||||
'path' => $path,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Internal function for getting languange and encodig settings
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Language;
|
||||
|
||||
class GetSettings
|
||||
{
|
||||
/**
|
||||
* Sets encoding and language
|
||||
* Can be overridden with language + path to mo file
|
||||
* If locale is set it must be in the format of:
|
||||
* <lang>.<encoding>
|
||||
* <lang>_<country>.<encoding>
|
||||
* <lang>_<country>.<encoding>@<subset>
|
||||
* If no encoding is set in the is, UTF-8 is assumed
|
||||
*
|
||||
* Returned is an array with array indes and dictionary index
|
||||
* 0~4 array are
|
||||
* encoding: 0
|
||||
* lang: 1
|
||||
* lang_short: 2
|
||||
* domain: 3
|
||||
* path: 4
|
||||
*
|
||||
* @param string|null $locale A valid locale name
|
||||
* @param string|null $path A valid path where the mo files will be based
|
||||
* @return array<int|string,string> Settings as array/dictionary
|
||||
*/
|
||||
public static function setLangEncoding(
|
||||
?string $locale = null,
|
||||
?string $domain = null,
|
||||
?string $path = null
|
||||
): array {
|
||||
$lang = '';
|
||||
$lang_short = '';
|
||||
$encoding = '';
|
||||
// if is is set, extract
|
||||
if (!empty($locale)) {
|
||||
preg_match(
|
||||
// language code
|
||||
'/^(?P<lang>[a-z]{2,3})'
|
||||
// _ country code
|
||||
. '(?:_(?P<country>[A-Z]{2}))?'
|
||||
// . charset
|
||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
||||
// @ modifier
|
||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
||||
$locale,
|
||||
$matches
|
||||
);
|
||||
// lang short part
|
||||
$lang_short = $matches['lang'] ?? '';
|
||||
$lang = $lang_short;
|
||||
// lang + country if country is set
|
||||
if (!empty($matches['country'])) {
|
||||
$lang = sprintf('%s_%s', $lang_short, $matches['country']);
|
||||
}
|
||||
// encoding if set
|
||||
$encoding = strtoupper($matches['charset'] ?? 'UTF-8');
|
||||
}
|
||||
// if domain is set, must be alphanumeric, if not unset
|
||||
if (
|
||||
!empty($domain) &&
|
||||
!preg_match("/^\w+$/", $domain)
|
||||
) {
|
||||
$domain = '';
|
||||
}
|
||||
// path checks if set, if not valid path unset
|
||||
if (
|
||||
!empty($path) &&
|
||||
!is_dir($path)
|
||||
) {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
// just emergency fallback for language
|
||||
// set encoding
|
||||
if (empty($encoding)) {
|
||||
if (!empty($_SESSION['DEFAULT_CHARSET'])) {
|
||||
$encoding = $_SESSION['DEFAULT_CHARSET'];
|
||||
} else {
|
||||
$encoding = DEFAULT_ENCODING;
|
||||
}
|
||||
}
|
||||
// gobal override
|
||||
if (empty($lang)) {
|
||||
if (!empty($GLOBALS['OVERRIDE_LANG'])) {
|
||||
$lang = $GLOBALS['OVERRIDE_LANG'];
|
||||
} elseif (!empty($_SESSION['DEFAULT_LANG'])) {
|
||||
// session (login)
|
||||
$lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
// mostly default SITE LANG or DEFAULT LANG
|
||||
$lang = defined('SITE_LANG') && !empty(SITE_LANG) ?
|
||||
SITE_LANG :
|
||||
DEFAULT_LANG;
|
||||
}
|
||||
}
|
||||
// create the char lang encoding
|
||||
if (empty($lang_short)) {
|
||||
$lang_short = substr($lang, 0, 2);
|
||||
}
|
||||
// set the language folder
|
||||
if (empty($path)) {
|
||||
// LEGACY
|
||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
||||
// will be BASE . INCLUDES . LANG . $language . /LC_MESSAGES/
|
||||
// so CONTENT_PATH has to be removed
|
||||
}
|
||||
// if no domain is set, fall back to content path
|
||||
if (empty($domain)) {
|
||||
$domain = str_replace('/', '', CONTENT_PATH);
|
||||
}
|
||||
// return
|
||||
return [
|
||||
// as array
|
||||
0 => $encoding,
|
||||
1 => $lang,
|
||||
2 => $lang_short,
|
||||
3 => $domain,
|
||||
4 => $path,
|
||||
// with index name
|
||||
// encoding
|
||||
'encoding' => $encoding,
|
||||
// language full string, eg en_US
|
||||
'lang' => $lang,
|
||||
// lang short, if eg en_US only en
|
||||
'lang_short' => $lang_short,
|
||||
// translation domain (CONTENT_PATH)
|
||||
'domain' => $domain,
|
||||
// folder BASE ONLY
|
||||
'path' => $path,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,34 +3,26 @@
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2004/11/18
|
||||
* VERSION: 1.0.0
|
||||
* VERSION: 3.0.0
|
||||
* RELEASED LICENSE: GNU GPL 3
|
||||
* SHORT DESCRIPTION:
|
||||
* init class for gettext. Original was just a function & var setting include for wordpress.
|
||||
* init class for gettext. Original was just a function &
|
||||
* var setting include for wordpress.
|
||||
* I changed that to a class to be more portable with my style of coding
|
||||
*
|
||||
* PUBLIC VARIABLES
|
||||
*
|
||||
* PRIVATE VARIABLES
|
||||
*
|
||||
* VERSION 3.0 (2022/4) removes all old folder layout and uses standard gettext
|
||||
* PUBLIC METHODS
|
||||
* __: returns string (translated or original if not found)
|
||||
* __e: echos out string (translated or original if not found)
|
||||
* __n: should return plural. never tested this.
|
||||
*
|
||||
* PRIVATE METHODS
|
||||
* __ : returns string (translated or original if not found)
|
||||
* __n : plural string
|
||||
* __p : string with context
|
||||
* __np: string with context and plural
|
||||
*
|
||||
* HISTORY:
|
||||
* 2022/4/15 (cs) drop all old folder layout support, new folder base
|
||||
* in locale with standard gettext layout of
|
||||
* locale/LC_MESSAGES/domain.mo
|
||||
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||
*********************************************************************/
|
||||
|
||||
// TODO: default path change to <base>/lang/LC_MESSAGES/domain.encoding.mo
|
||||
// for example: lang: ja_JP.UTF-8, domain: admin
|
||||
// <base>/ja_JP/LC_MESSAGES/admin.UTF-8.mo
|
||||
// OLD: includes/lang/admin/ja_utf8.mo
|
||||
// NEW: includes/lang/ja_JP/LC_MESSAGES/admin.UTF-8.mo
|
||||
// or fallback: includes/lang/ja/LC_MESSAGES/admin.UTF-8.mo
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace CoreLibs\Language;
|
||||
@@ -42,21 +34,28 @@ class L10n
|
||||
{
|
||||
/** @var string the current locale */
|
||||
private $locale = '';
|
||||
/** @var string the SET locale as WHERE the domain file is */
|
||||
private $locale_set = '';
|
||||
/** @var string the default selected/active domain */
|
||||
private $domain = '';
|
||||
/** @var array<string,array<string,GetTextReader>> locale > domain = translator */
|
||||
private $domains = [];
|
||||
/** @var array<string,string> bound paths for domains */
|
||||
private $paths = ['' => './'];
|
||||
|
||||
// files
|
||||
/** @var string the full path to the mo file to loaded */
|
||||
private $mofile = '';
|
||||
/** @var string base path to search level */
|
||||
private $base_locale_path = '';
|
||||
/** @var string dynamic set path to where the mo file is actually */
|
||||
private $base_content_path = '';
|
||||
|
||||
// errors
|
||||
/** @var bool if load of mo file was unsuccessful */
|
||||
private $load_failure = false;
|
||||
|
||||
// object holders
|
||||
/** @var FileReader|bool reader class for file reading, false for short circuit */
|
||||
private $input = false;
|
||||
/** @var GetTextReader reader class for MO data */
|
||||
@@ -74,20 +73,24 @@ class L10n
|
||||
*
|
||||
* @param string $locale language name, default empty string
|
||||
* will return self instance
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param bool $legacy default true, if set to true, will look in the old
|
||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
*/
|
||||
public function __construct(
|
||||
string $locale = '',
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = true
|
||||
string $path = ''
|
||||
) {
|
||||
// load the mo file if locale is not empty
|
||||
if (!empty($locale)) {
|
||||
$this->getTranslator($locale, $path, $domain, $legacy);
|
||||
// auto load language only if at least locale and domain is set
|
||||
if (!empty($locale) && !empty($domain)) {
|
||||
// check hack if domain and path is switched
|
||||
// Note this can be removed in future versions
|
||||
if (strstr($domain, DIRECTORY_SEPARATOR) !== false) {
|
||||
$_domain = $path;
|
||||
$path = $domain;
|
||||
$domain = $_domain;
|
||||
}
|
||||
$this->getTranslator($locale, $domain, $path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,43 +119,18 @@ class L10n
|
||||
require_once __DIR__ . '/l10n_functions.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* legacy loader name for getTranslator
|
||||
* instead of returning the GetTextReader object it returns
|
||||
* true or false for successful load.
|
||||
* NOTE: some time down the road this will be deprecated
|
||||
*
|
||||
* @param string $locale
|
||||
* @param string $path
|
||||
* @param string $domain
|
||||
* @param bool $legacy
|
||||
* @return bool Returns true for successfull load, false for error
|
||||
*/
|
||||
public function l10nReloadMOfile(
|
||||
string $locale,
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = true
|
||||
): bool {
|
||||
$this->getTranslator($locale, $path, $domain, $legacy);
|
||||
return $this->load_failure ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* loads the mo file base on path, locale and domain set
|
||||
*
|
||||
* @param string $locale language name (optional), fallback is en
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||
* @param bool $legacy default true, if set to true, will look in the old
|
||||
* folder format lang/ CONTENT_PATH / $lang . mo
|
||||
* @param string $path path, if empty fallback on default internal path
|
||||
* @return GetTextReader the main gettext reader object
|
||||
*/
|
||||
public function getTranslator(
|
||||
string $locale = '',
|
||||
string $path = '',
|
||||
string $domain = '',
|
||||
bool $legacy = false
|
||||
string $path = ''
|
||||
): GetTextReader {
|
||||
// set local if not from parameter
|
||||
if (empty($locale)) {
|
||||
@@ -165,52 +143,40 @@ class L10n
|
||||
// store old settings
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->locale;
|
||||
$old_lang_set = $this->locale_set;
|
||||
$old_domain = $this->domain;
|
||||
$old_base_locale_path = $this->base_locale_path;
|
||||
$old_base_content_path = $this->base_content_path;
|
||||
|
||||
// legacy or new type
|
||||
// legacy will use the old lang/content/file.mo type as default
|
||||
// if path is not set, also locale is the file name
|
||||
// for new type it follows the gettext spec and path is just the
|
||||
// base folder where the mo files will be searched
|
||||
if ($legacy === true) {
|
||||
if (!is_dir($path)) {
|
||||
$this->base_locale_path = BASE . INCLUDES . LANG;
|
||||
$this->base_content_path = CONTENT_PATH;
|
||||
$path = $this->base_locale_path . $this->base_content_path;
|
||||
}
|
||||
$this->mofile = $path . $locale . ".mo";
|
||||
// if path is a dir
|
||||
// 1) from a previous set domain
|
||||
// 2) from method option as is
|
||||
// 3) fallback if BASE/INCLUDES/LOCALE set
|
||||
// 4) current dir
|
||||
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
|
||||
$this->base_locale_path = $this->paths[$domain];
|
||||
} elseif (is_dir($path)) {
|
||||
$this->base_locale_path = $path;
|
||||
} elseif (
|
||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||
) {
|
||||
// set fallback base path if constant set
|
||||
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||
} else {
|
||||
// if new path is a dir
|
||||
// 1) from a previous set domain
|
||||
// 2) from method option as is
|
||||
// 3) fallback if BASE/INCLUDES/LOCALE set
|
||||
// 4) current dir
|
||||
if (!empty($this->paths[$domain]) && is_dir($this->paths[$domain])) {
|
||||
$this->base_locale_path = $this->paths[$domain];
|
||||
} elseif (is_dir($path)) {
|
||||
$this->base_locale_path = $path;
|
||||
} elseif (
|
||||
defined('BASE') && defined('INCLUDES') && defined('LOCALE')
|
||||
) {
|
||||
// set fallback base path if constant set
|
||||
$this->base_locale_path = BASE . INCLUDES . LOCALE;
|
||||
} else {
|
||||
$this->base_locale_path = './';
|
||||
}
|
||||
// now we loop over lang compositions to get the base path
|
||||
// then we check
|
||||
$locales = $this->listLocales($locale);
|
||||
foreach ($locales as $_locale) {
|
||||
$this->base_content_path = $_locale . DIRECTORY_SEPARATOR
|
||||
. 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
|
||||
$this->mofile = $this->base_locale_path
|
||||
. $this->base_content_path
|
||||
. $domain . '.mo';
|
||||
if (file_exists($this->mofile)) {
|
||||
break;
|
||||
}
|
||||
$this->base_locale_path = './';
|
||||
}
|
||||
// now we loop over lang compositions to get the base path
|
||||
// then we check
|
||||
$locales = $this->listLocales($locale);
|
||||
foreach ($locales as $_locale) {
|
||||
$this->base_content_path = $_locale . DIRECTORY_SEPARATOR
|
||||
. 'LC_MESSAGES' . DIRECTORY_SEPARATOR;
|
||||
$this->mofile = $this->base_locale_path
|
||||
. $this->base_content_path
|
||||
. $domain . '.mo';
|
||||
if (file_exists($this->mofile)) {
|
||||
$this->locale_set = $_locale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +206,7 @@ class L10n
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->locale = $old_lang;
|
||||
$this->locale_set = $old_lang_set;
|
||||
$this->domain = $old_domain;
|
||||
$this->base_locale_path = $old_base_locale_path;
|
||||
$this->base_content_path = $old_base_content_path;
|
||||
@@ -273,6 +240,34 @@ class L10n
|
||||
return $this->l10n;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse the locale string for further processing
|
||||
*
|
||||
* @param string $locale Locale to parse
|
||||
* @return array<string,string|null> array with lang, country, charset, modifier
|
||||
*/
|
||||
public static function parseLocale(string $locale = ''): array
|
||||
{
|
||||
preg_match(
|
||||
// language code
|
||||
'/^(?P<lang>[a-z]{2,3})'
|
||||
// country code
|
||||
. '(?:_(?P<country>[A-Z]{2}))?'
|
||||
// charset
|
||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
||||
// @ modifier
|
||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
||||
$locale,
|
||||
$matches
|
||||
);
|
||||
return [
|
||||
'lang' => $matches['lang'] ?? null,
|
||||
'country' => $matches['country'] ?? null,
|
||||
'charset' => $matches['charset'] ?? null,
|
||||
'modifier' => $matches['modifier'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* original:
|
||||
* vendor/phpmyadmin/motranslator/src/Loader.php
|
||||
@@ -294,28 +289,16 @@ class L10n
|
||||
return $locale_list;
|
||||
}
|
||||
// is matching regex
|
||||
if (
|
||||
!preg_match(
|
||||
// language code
|
||||
'/^(?P<lang>[a-z]{2,3})'
|
||||
// country code
|
||||
. '(?:_(?P<country>[A-Z]{2}))?'
|
||||
// charset
|
||||
. '(?:\\.(?P<charset>[-A-Za-z0-9_]+))?'
|
||||
// @ modifier
|
||||
. '(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/',
|
||||
$locale,
|
||||
$matches
|
||||
)
|
||||
) {
|
||||
// not matching, return as is
|
||||
$locale_detail = L10n::parseLocale($locale);
|
||||
// all null = nothing mached, return locale as is
|
||||
if ($locale_detail === array_filter($locale_detail, 'is_null')) {
|
||||
return [$locale];
|
||||
}
|
||||
// do matching run
|
||||
$lang = $matches['lang'] ?? null;
|
||||
$country = $matches['country'] ?? null;
|
||||
$charset = $matches['charset'] ?? null;
|
||||
$modifier = $matches['modifier'] ?? null;
|
||||
// write to innteral vars
|
||||
$lang = $locale_detail['lang'];
|
||||
$country = $locale_detail['country'];
|
||||
$charset = $locale_detail['charset'];
|
||||
$modifier = $locale_detail['modifier'];
|
||||
// we need to add all possible cominations from not null set
|
||||
// entries to the list, from longest to shortest
|
||||
// %s_%s.%s@%s (lang _ country . encoding @ suffix)
|
||||
@@ -476,7 +459,7 @@ class L10n
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set locale
|
||||
* get current set locale (want locale)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -485,6 +468,16 @@ class L10n
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* current set locale where mo file is located
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocaleSet(): string
|
||||
{
|
||||
return $this->locale_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set language
|
||||
*
|
||||
@@ -623,7 +616,7 @@ class L10n
|
||||
* @param int $number number value
|
||||
* @return string
|
||||
*/
|
||||
public function __pn(string $context, string $single, string $plural, int $number): string
|
||||
public function __np(string $context, string $single, string $plural, int $number): string
|
||||
{
|
||||
if ($this->l10n === null) {
|
||||
return $number > 1 ? $plural : $single;
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*********************************************************************
|
||||
* Original: https://github.com/phpmyadmin/motranslator
|
||||
* Has the same function names, but uses a different base system
|
||||
* setlocale -> setLocale
|
||||
* bindtextdomain -> setTextDomain
|
||||
* textdomain -> setDomain
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use CoreLibs\Language\L10n;
|
||||
use CoreLibs\Language\L10n as Loader;
|
||||
|
||||
/**
|
||||
* Sets a requested locale.
|
||||
@@ -12,9 +20,9 @@ use CoreLibs\Language\L10n;
|
||||
*
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
function __setlocale(int $category, string $locale): string
|
||||
function _setlocale(int $category, string $locale): string
|
||||
{
|
||||
return L10n::getInstance()->setLocale($locale);
|
||||
return Loader::getInstance()->setLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,9 +31,9 @@ function __setlocale(int $category, string $locale): string
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
function __bindtextdomain(string $domain, string $path): void
|
||||
function _bindtextdomain(string $domain, string $path): void
|
||||
{
|
||||
L10n::getInstance()->setTextDomain($domain, $path);
|
||||
Loader::getInstance()->setTextDomain($domain, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +47,7 @@ function __bindtextdomain(string $domain, string $path): void
|
||||
* @param string $domain Domain where to set character set
|
||||
* @param string $codeset Character set to set
|
||||
*/
|
||||
function __bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
function _bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,9 +56,9 @@ function __bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
function __textdomain(string $domain): void
|
||||
function _textdomain(string $domain): void
|
||||
{
|
||||
L10n::getInstance()->setDomain($domain);
|
||||
Loader::getInstance()->setDomain($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +68,9 @@ function __textdomain(string $domain): void
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __gettext(string $msgid): string
|
||||
function _gettext(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -76,7 +84,7 @@ function __gettext(string $msgid): string
|
||||
*/
|
||||
function __(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -90,9 +98,9 @@ function __(string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
function _ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->ngettext(
|
||||
return Loader::getInstance()->getTranslator()->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
@@ -107,9 +115,9 @@ function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __pgettext(string $msgctxt, string $msgid): string
|
||||
function _pgettext(string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->pgettext(
|
||||
return Loader::getInstance()->getTranslator()->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
@@ -125,9 +133,9 @@ function __pgettext(string $msgctxt, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
function _npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->npgettext(
|
||||
return Loader::getInstance()->getTranslator()->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
@@ -143,9 +151,9 @@ function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $n
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __dgettext(string $domain, string $msgid): string
|
||||
function _dgettext(string $domain, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -160,9 +168,9 @@ function __dgettext(string $domain, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||
function _dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
@@ -178,9 +186,9 @@ function __dngettext(string $domain, string $msgid, string $msgidPlural, int $nu
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
function _dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
@@ -197,9 +205,9 @@ function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
function _dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
|
||||
@@ -299,23 +299,39 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* construct form generator
|
||||
* @param array<mixed> $db_config db config array
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
||||
* if null, auto set
|
||||
* @param array<mixed> $db_config db config array, mandatory
|
||||
* @param \CoreLibs\Debug\Logging|null $log Logging class, null auto set
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class, null auto set
|
||||
* @param array<string,string>|null $locale locale array from ::setLocale,
|
||||
* null auto set
|
||||
*/
|
||||
public function __construct(
|
||||
array $db_config,
|
||||
\CoreLibs\Debug\Logging $log = null,
|
||||
?\CoreLibs\Language\L10n $l10n = null
|
||||
?\CoreLibs\Debug\Logging $log = null,
|
||||
?\CoreLibs\Language\L10n $l10n = null,
|
||||
?array $locale = null
|
||||
) {
|
||||
global $table_arrays;
|
||||
// replace any non valid variable names
|
||||
// TODO extract only alphanumeric and _ after . to _ replacement
|
||||
$this->my_page_name = str_replace(['.'], '_', System::getPageName(System::NO_EXTENSION));
|
||||
$this->setLangEncoding();
|
||||
// if pass on locale is null
|
||||
if ($locale === null) {
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
}
|
||||
// init the language class
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
|
||||
$this->l = $l10n ?? new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
// legacy lang vars set
|
||||
$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();
|
||||
// load config array
|
||||
// get table array definitions for current page name
|
||||
|
||||
@@ -443,29 +459,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
// INTERNAL METHODS |===============================================>
|
||||
|
||||
/**
|
||||
* ORIGINAL in \CoreLibs\Admin\Backend
|
||||
* set the language encoding and language settings
|
||||
* the default charset from _SESSION login or from
|
||||
* config DEFAULT ENCODING
|
||||
* the lang full name for mo loading from _SESSION login
|
||||
* or SITE LANG or DEFAULT LANG from config
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
list (
|
||||
$this->encoding,
|
||||
$this->lang,
|
||||
$this->lang_short,
|
||||
$this->domain,
|
||||
$this->lang_dir
|
||||
) = \CoreLibs\Language\GetSettings::setLangEncoding();
|
||||
}
|
||||
|
||||
// PUBLIC METHODS |=================================================>
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,8 @@ class SmartyExtend extends \Smarty
|
||||
/** @var string */
|
||||
public $lang;
|
||||
/** @var string */
|
||||
public $locale_set;
|
||||
/** @var string */
|
||||
public $lang_short;
|
||||
/** @var string */
|
||||
public $domain;
|
||||
@@ -154,50 +156,42 @@ class SmartyExtend extends \Smarty
|
||||
* constructor class, just sets the language stuff
|
||||
* calls L10 for pass on internaly in smarty
|
||||
* also registers the getvar caller plugin
|
||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
||||
* if null, auto set
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,string> $locale locale data read from setLocale
|
||||
*/
|
||||
public function __construct(?\CoreLibs\Language\L10n $l10n = null)
|
||||
public function __construct(\CoreLibs\Language\L10n $l10n, array $locale)
|
||||
{
|
||||
// call basic smarty
|
||||
// or Smarty::__construct();
|
||||
parent::__construct();
|
||||
// set lang vars
|
||||
$this->setLangEncoding();
|
||||
// iinit lang
|
||||
$this->l10n = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
|
||||
// Smarty 3.x
|
||||
// $this->registerPlugin('modifier', 'getvar', [&$this, 'get_template_vars']);
|
||||
$this->l10n = $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->l10n->getDomain();
|
||||
$this->locale_set = $this->l10n->getLocaleSet();
|
||||
$this->lang_dir = $this->l10n->getBaseLocalePath();
|
||||
|
||||
// opt load functions so we can use legacy init for smarty run perhaps
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
_setlocale(LC_MESSAGES, $locale['locale']);
|
||||
_textdomain($this->domain);
|
||||
_bindtextdomain($this->domain, $this->lang_dir);
|
||||
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
|
||||
// register smarty variable
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||
|
||||
$this->page_name = pathinfo($_SERVER["PHP_SELF"])['basename'];
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
|
||||
// set internal settings
|
||||
$this->CACHE_ID = defined('CACHE_ID') ? CACHE_ID : '';
|
||||
$this->COMPILE_ID = defined('COMPILE_ID') ? COMPILE_ID : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* ORIGINAL in \CoreLibs\Admin\Backend
|
||||
* set the language encoding and language settings
|
||||
* the default charset from _SESSION login or from
|
||||
* config DEFAULT ENCODING
|
||||
* the lang full name for mo loading from _SESSION login
|
||||
* or SITE LANG or DEFAULT LANG from config
|
||||
* creates short lang (only first two chars) from the lang
|
||||
* @return void
|
||||
*/
|
||||
private function setLangEncoding(): void
|
||||
{
|
||||
list (
|
||||
$this->encoding,
|
||||
$this->lang,
|
||||
$this->lang_short,
|
||||
$this->domain,
|
||||
$this->lang_dir
|
||||
) = \CoreLibs\Language\GetSettings::setLangEncoding();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@@ -321,16 +315,24 @@ class SmartyExtend extends \Smarty
|
||||
}
|
||||
// javascript translate data as template for auto translate
|
||||
if (empty($this->TEMPLATE_TRANSLATE)) {
|
||||
$this->TEMPLATE_TRANSLATE = 'jsTranslate_' . $this->lang . '.tpl';
|
||||
$this->TEMPLATE_TRANSLATE = 'jsTranslate_'
|
||||
. $this->locale_set . '.' . $this->encoding
|
||||
. '.tpl';
|
||||
} else {
|
||||
// we assume we have some fixed set
|
||||
// we must add _<$this->lang>
|
||||
// if .tpl, put before .tpl
|
||||
// if not .tpl, add _<$this->lang>.tpl
|
||||
if (strpos($this->TEMPLATE_TRANSLATE, '.tpl')) {
|
||||
$this->TEMPLATE_TRANSLATE = str_replace('.tpl', '_' . $this->lang . '.tpl', $this->TEMPLATE_TRANSLATE);
|
||||
$this->TEMPLATE_TRANSLATE = str_replace(
|
||||
'.tpl',
|
||||
'-' . $this->locale_set . '.' . $this->encoding . '.tpl',
|
||||
$this->TEMPLATE_TRANSLATE
|
||||
);
|
||||
} else {
|
||||
$this->TEMPLATE_TRANSLATE .= '_' . $this->lang . '.tpl';
|
||||
$this->TEMPLATE_TRANSLATE .= '_'
|
||||
. $this->locale_set . '.' . $this->encoding
|
||||
. '.tpl';
|
||||
}
|
||||
}
|
||||
// if we can't find it, dump it
|
||||
|
||||
@@ -32,7 +32,8 @@ function MyErrorHandler(
|
||||
int $line,
|
||||
array $context = []
|
||||
): bool {
|
||||
if (!(error_reporting() & $type) && SHOW_ALL_ERRORS == false) {
|
||||
/** @phpstan-ignore-next-line cannot check show all errors constant */
|
||||
if (!(error_reporting() & $type) && SHOW_ALL_ERRORS === false) {
|
||||
// This error code is not included in error_reporting
|
||||
return false;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user