Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
316ca106fd | ||
|
|
fd9b201346 | ||
|
|
667dc4de8e | ||
|
|
fed67e990d | ||
|
|
c181a83b48 | ||
|
|
c830a32962 | ||
|
|
82bc99b181 | ||
|
|
556cabca38 | ||
|
|
6f4c5e36e6 | ||
|
|
a3c49e408a | ||
|
|
cc77d7e031 | ||
|
|
d553c1364f | ||
|
|
3f374a2cd7 | ||
|
|
9e99275db5 | ||
|
|
330e2baf39 | ||
|
|
5a81626e8c | ||
|
|
41cff5e3c6 | ||
|
|
e463f48ad4 | ||
|
|
f8ee6044f9 | ||
|
|
4b0e9b44c3 | ||
|
|
e5309b5dbc | ||
|
|
aad2e9b11b | ||
|
|
d6baf58231 | ||
|
|
c464a7d884 | ||
|
|
60613bf311 | ||
|
|
2a583e525c | ||
|
|
04b0476b4d | ||
|
|
13fb22385b | ||
|
|
b7f594e683 |
@@ -95,7 +95,7 @@ return [
|
|||||||
'www/vendor',
|
'www/vendor',
|
||||||
'www/tests',
|
'www/tests',
|
||||||
'www/lib/Smarty',
|
'www/lib/Smarty',
|
||||||
'www/lib/smarty-3.1.30',
|
'www/lib/smarty-4.1.0',
|
||||||
'www/templates_c',
|
'www/templates_c',
|
||||||
'www/log',
|
'www/log',
|
||||||
'www/tmp',
|
'www/tmp',
|
||||||
@@ -117,11 +117,7 @@ return [
|
|||||||
'www/admin/qq_file_upload_front.php',
|
'www/admin/qq_file_upload_front.php',
|
||||||
'www/admin/qq_file_upload_ajax.php',
|
'www/admin/qq_file_upload_ajax.php',
|
||||||
// symlink ignore
|
// symlink ignore
|
||||||
'www/lib/smarty-3.1.30/SmartyBC.class.php',
|
'www/lib/smarty-4.1.0/libs/Smarty.class.php'
|
||||||
'www/lib/htmlMimeMail-2.5.1/HtmlMimeMailCreate.php',
|
|
||||||
// current not checking smarty4 test file
|
|
||||||
'www/lib/CoreLibs/Template/SmartyExtend4.php',
|
|
||||||
'www/admin/class_test.smarty4.php',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// what not to show as problem
|
// what not to show as problem
|
||||||
|
|||||||
@@ -68,9 +68,10 @@ INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3
|
|||||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
||||||
|
|
||||||
-- edit language
|
-- edit language
|
||||||
|
-- iso_name = encoding
|
||||||
DELETE FROM edit_language;
|
DELETE FROM edit_language;
|
||||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('en', 'English', 'UTF-8', 1, 1, 1);
|
INSERT INTO edit_language (long_name, short_name, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
|
||||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('ja', 'Japanese', 'UTF-8', 2, 1, 0);
|
INSERT INTO edit_language (long_name, short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('Japanese', 'ja_JP', 'UTF-8', 2, 1, 0);
|
||||||
|
|
||||||
-- edit group
|
-- edit group
|
||||||
DELETE FROM edit_group;
|
DELETE FROM edit_group;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ CREATE TABLE edit_language (
|
|||||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||||
long_name VARCHAR,
|
long_name VARCHAR,
|
||||||
short_name VARCHAR,
|
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
|
||||||
iso_name VARCHAR,
|
iso_name VARCHAR, -- should actually be encoding
|
||||||
order_number INT
|
order_number INT
|
||||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||||
|
|||||||
55
4dev/locale/Readme.md
Normal file
55
4dev/locale/Readme.md
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# Translation files
|
||||||
|
|
||||||
|
## Source file name convetion
|
||||||
|
|
||||||
|
Locale Name . Domain . Encoding .po
|
||||||
|
|
||||||
|
## Name parte explenations
|
||||||
|
|
||||||
|
### Locale Name Examples
|
||||||
|
|
||||||
|
If underscore in name the long version is checked first, then the short version:
|
||||||
|
en_US@latin -> en_US -> en
|
||||||
|
|
||||||
|
* en
|
||||||
|
* en_US
|
||||||
|
* en_US.UTF-8
|
||||||
|
* en_US@latin
|
||||||
|
|
||||||
|
### Domain
|
||||||
|
|
||||||
|
For current case auto set CONTENT_PATH is used
|
||||||
|
|
||||||
|
* admin
|
||||||
|
* frontend
|
||||||
|
|
||||||
|
### Encoding
|
||||||
|
|
||||||
|
if not set UTF-8 is assumed. Any other utf8 encoding is changed to UTF-8
|
||||||
|
|
||||||
|
* UTF-8
|
||||||
|
* SJIS
|
||||||
|
* EUC
|
||||||
|
|
||||||
|
## File name example source
|
||||||
|
|
||||||
|
`ja-admin.po`
|
||||||
|
|
||||||
|
First part is LOCALE, second part is domain. Separator is `-`
|
||||||
|
|
||||||
|
## Folder layout
|
||||||
|
|
||||||
|
`includes/locale/ja/LC_MESSAGES/frontend.mo`
|
||||||
|
|
||||||
|
ALTERNATE LOCALE NAMES:
|
||||||
|
* ja
|
||||||
|
* ja_JP
|
||||||
|
* ja.UTF-8
|
||||||
|
* ja_JP.UTF-8
|
||||||
|
|
||||||
|
ja_JP.UTF-8: Locale Name
|
||||||
|
frontend: dmain (CONTENT_PATH)
|
||||||
|
|
||||||
|
## command
|
||||||
|
|
||||||
|
`msgfmt -o www/includes/locale/ja/LC_MESSAGES/frontend.mo 4dev/lang/ja.admin.po`
|
||||||
@@ -3,21 +3,22 @@
|
|||||||
# CREATED: 2005/08/09
|
# CREATED: 2005/08/09
|
||||||
# SHORT DESCRIPTION:
|
# SHORT DESCRIPTION:
|
||||||
# Backned English Messages file for gettext
|
# Backned English Messages file for gettext
|
||||||
# to craete: msgfmt -o ja.mo messages_en.po
|
# to craete: msgfmt -o <output.po> <input.mo>
|
||||||
# HISTORY:
|
|
||||||
# ********************************************************************/
|
# ********************************************************************/
|
||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Project Version\n"
|
"Project-Id-Version: en.UTF-8 LC_MESSAGES admin\n"
|
||||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: clemens.schwaighofer@egplusww.co\n"
|
||||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||||
|
"Language: en\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=n != 1;\n"
|
||||||
|
|
||||||
msgid "Year"
|
msgid "Year"
|
||||||
msgstr "Year"
|
msgstr "Year"
|
||||||
@@ -26,10 +27,31 @@ msgid "Month"
|
|||||||
msgstr "Month"
|
msgstr "Month"
|
||||||
|
|
||||||
msgid "INPUT TEST"
|
msgid "INPUT TEST"
|
||||||
msgstr "OUTPUT TEST EN"
|
msgstr "OUTPUT TEST ADMIN EN"
|
||||||
|
|
||||||
|
# testing multi
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
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"
|
||||||
|
|
||||||
|
msgctxt "month name"
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
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"
|
msgid "I should be translated"
|
||||||
msgstr "I should be translated: I WAS TRANSLATED"
|
msgstr "I should be translated: I WAS TRANSLATED"
|
||||||
|
|
||||||
msgid "Are we translated?"
|
msgid "Are we translated?"
|
||||||
msgstr "Are we translated? Yes, we are!"
|
msgstr "Are we translated? Yes, we are!"
|
||||||
|
|
||||||
|
msgid "Original with string: %1"
|
||||||
|
msgstr "Translated with: %1"
|
||||||
24
4dev/locale/en-frontend.po
Normal file
24
4dev/locale/en-frontend.po
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# to craete: msgfmt -o <output.po> <input.mo>
|
||||||
|
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"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\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 EN"
|
||||||
|
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi frontend en 0"
|
||||||
|
msgstr[1] "Multi frontend en 1"
|
||||||
|
msgstr[2] "Multi frontend en 2"
|
||||||
@@ -3,21 +3,22 @@
|
|||||||
# CREATED: 2018/03/28
|
# CREATED: 2018/03/28
|
||||||
# SHORT DESCRIPTION:
|
# SHORT DESCRIPTION:
|
||||||
# Backend Japanese Messages file for gettext
|
# Backend Japanese Messages file for gettext
|
||||||
# to craete: msgfmt -o ja.mo messages_ja.po
|
# to craete: msgfmt -o <output.po> <input.mo>
|
||||||
# HISTORY:
|
|
||||||
# ********************************************************************/
|
# ********************************************************************/
|
||||||
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Project Version\n"
|
"Project-Id-Version: ja.UTF-8 LC_MESSAGES admin\n"
|
||||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: \n"
|
"Last-Translator: clemens.schwaighofer@egplusww.com\n"
|
||||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||||
|
"Language: ja\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=UTF-8\n"
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
|
||||||
|
|
||||||
msgid "Yes"
|
msgid "Yes"
|
||||||
msgstr "はい"
|
msgstr "はい"
|
||||||
@@ -63,7 +64,25 @@ msgid "Sun"
|
|||||||
msgstr "日"
|
msgstr "日"
|
||||||
|
|
||||||
msgid "INPUT TEST"
|
msgid "INPUT TEST"
|
||||||
msgstr "OUTPUT TEST JA"
|
msgstr "OUTPUT TEST ADMIN JA"
|
||||||
|
|
||||||
|
# testing multi
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
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
|
# login string
|
||||||
msgid "Hello %s"
|
msgid "Hello %s"
|
||||||
@@ -75,3 +94,5 @@ msgstr "「スマーティー」これは正しいです"
|
|||||||
msgid "Are we translated?"
|
msgid "Are we translated?"
|
||||||
msgstr "「クラス」これは翻訳です?"
|
msgstr "「クラス」これは翻訳です?"
|
||||||
|
|
||||||
|
msgid "Original with string: %1"
|
||||||
|
msgstr "%1と翻訳した"
|
||||||
24
4dev/locale/ja-frontend.po
Normal file
24
4dev/locale/ja-frontend.po
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# to craete: msgfmt -o <output.po> <input.mo>
|
||||||
|
|
||||||
|
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"
|
||||||
117
4dev/tests/CoreLibsCheckEncodingTest.php
Normal file
117
4dev/tests/CoreLibsCheckEncodingTest.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Check\Encoding
|
||||||
|
* @coversDefaultClass \CoreLibs\Check\Encoding
|
||||||
|
* @testdox \CoreLibs\Check\Encoding method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsCheckEncodingTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function checkConvertEncodingProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: string to test
|
||||||
|
// 1: source encoding
|
||||||
|
// 2: target encoding
|
||||||
|
// 3: substitue character
|
||||||
|
// 4: false for ok, array with error list
|
||||||
|
'valid test UTF-8 to SJIS (default)' => [
|
||||||
|
'日本語',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
],
|
||||||
|
'invalid test UTF-8 to SJIS (dots as code point)' => [
|
||||||
|
'❶',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
0x2234,
|
||||||
|
['❶']
|
||||||
|
],
|
||||||
|
'invalid test UTF-8 to SJIS (dots as string)' => [
|
||||||
|
'❶',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
'∴',
|
||||||
|
['❶']
|
||||||
|
],
|
||||||
|
'invalid test UTF-8 to SJIS (none)' => [
|
||||||
|
'❶',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
'none',
|
||||||
|
['❶']
|
||||||
|
],
|
||||||
|
'invalid test UTF-8 to SJIS (long)' => [
|
||||||
|
'❶',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
'long',
|
||||||
|
['❶']
|
||||||
|
],
|
||||||
|
'invalid test UTF-8 to SJIS (entity)' => [
|
||||||
|
'❶',
|
||||||
|
'UTF-8',
|
||||||
|
'SJIS',
|
||||||
|
'entity',
|
||||||
|
['❶']
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::checkConvertEncoding
|
||||||
|
* @dataProvider checkConvertEncodingProvider
|
||||||
|
* @testdox check encoding convert from $from_encoding to $to_encoding [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $from_encoding
|
||||||
|
* @param string $to_encoding
|
||||||
|
* @param string|int|null $error_char
|
||||||
|
* @param array|bool $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testCheckConvertEncoding(
|
||||||
|
string $input,
|
||||||
|
string $from_encoding,
|
||||||
|
string $to_encoding,
|
||||||
|
$error_char,
|
||||||
|
$expected
|
||||||
|
): void {
|
||||||
|
if ($error_char !== null) {
|
||||||
|
\CoreLibs\Check\Encoding::setErrorChar($error_char);
|
||||||
|
if (!in_array($error_char, ['none', 'long', 'entity'])) {
|
||||||
|
$this->assertEquals(
|
||||||
|
\IntlChar::chr($error_char),
|
||||||
|
\CoreLibs\Check\Encoding::getErrorChar()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$error_char,
|
||||||
|
\CoreLibs\Check\Encoding::getErrorChar()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$return = \CoreLibs\Check\Encoding::checkConvertEncoding($input, $from_encoding, $to_encoding);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$return
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
* @coversDefaultClass \CoreLibs\Check\PHPVersion
|
* @coversDefaultClass \CoreLibs\Check\PHPVersion
|
||||||
* @testdox \CoreLibs\Check\PHPVersion method tests
|
* @testdox \CoreLibs\Check\PHPVersion method tests
|
||||||
*/
|
*/
|
||||||
final class CoreLibsCheckPHPVersionTest extends TestCase
|
final class CoreLibsCheckPhpVersionTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* NOTE: The checks must be adapted to the PHP version or they will fail
|
* NOTE: The checks must be adapted to the PHP version or they will fail
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
],
|
],
|
||||||
'valid color' => [
|
'valid color' => [
|
||||||
'rgb' => [10, 100, 200],
|
'rgb' => [10, 100, 200],
|
||||||
'hsb' => [212, 95, 78],
|
'hsb' => [212, 95, 78.0],
|
||||||
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
|
||||||
'hsl' => [211.6, 90.5, 41.2],
|
'hsl' => [211.6, 90.5, 41.2],
|
||||||
'valid' => true,
|
'valid' => true,
|
||||||
@@ -327,13 +327,13 @@ final class CoreLibsConvertColorsTest extends TestCase
|
|||||||
* @dataProvider hsb2rgbColorProvider
|
* @dataProvider hsb2rgbColorProvider
|
||||||
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param integer $input_h
|
* @param float $input_h
|
||||||
* @param integer $input_s
|
* @param float $input_s
|
||||||
* @param integer $input_b
|
* @param float $input_b
|
||||||
* @param array|bool $expected
|
* @param array|bool $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testHsb2rgb(int $input_h, int $input_s, int $input_b, $expected): void
|
public function testHsb2rgb(float $input_h, float $input_s, float $input_b, $expected): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
|
|||||||
102
4dev/tests/CoreLibsConvertEncodingTest.php
Normal file
102
4dev/tests/CoreLibsConvertEncodingTest.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Convert\Encoding
|
||||||
|
* @coversDefaultClass \CoreLibs\Convert\Encoding
|
||||||
|
* @testdox \CoreLibs\Convert\Encoding method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsConvertEncodingTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function convertEncodingProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: original string
|
||||||
|
// 1: target encoding
|
||||||
|
// 2: optional source encoding
|
||||||
|
// 3: auto check (not used)
|
||||||
|
// 4: expected string
|
||||||
|
// 5: expected string encoding
|
||||||
|
'simple from UTF-8 to SJIS' => [
|
||||||
|
'input string',
|
||||||
|
'SJIS',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'input string',
|
||||||
|
'SJIS'
|
||||||
|
],
|
||||||
|
'kanji from UTF-8 to SJIS' => [
|
||||||
|
'日本語',
|
||||||
|
'SJIS',
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
'日本語',
|
||||||
|
'SJIS'
|
||||||
|
],
|
||||||
|
'kanji from UTF-8 to SJIS with source' => [
|
||||||
|
'日本語',
|
||||||
|
'SJIS',
|
||||||
|
'UTF-8',
|
||||||
|
null,
|
||||||
|
'日本語',
|
||||||
|
'SJIS'
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::convertEncoding
|
||||||
|
* @dataProvider convertEncodingProvider
|
||||||
|
* @testdox convert encoding $target_encoding, source: $source_encoding, auto: $auto_check [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $target_encoding
|
||||||
|
* @param string $source_encoding
|
||||||
|
* @param bool $auto_check
|
||||||
|
* @param string $expected
|
||||||
|
* @param string $expected_encoding
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testConvertEncoding(
|
||||||
|
string $input,
|
||||||
|
string $target_encoding,
|
||||||
|
?string $source_encoding,
|
||||||
|
?bool $auto_check,
|
||||||
|
string $expected,
|
||||||
|
string $expected_encoding
|
||||||
|
): void {
|
||||||
|
if ($source_encoding === null and $auto_check === null) {
|
||||||
|
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding);
|
||||||
|
} elseif ($auto_check === null) {
|
||||||
|
$string = \CoreLibs\Convert\Encoding::convertEncoding($input, $target_encoding, $source_encoding);
|
||||||
|
} else {
|
||||||
|
$string = \CoreLibs\Convert\Encoding::convertEncoding(
|
||||||
|
$input,
|
||||||
|
$target_encoding,
|
||||||
|
$source_encoding,
|
||||||
|
$auto_check
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// because we can't store encoding in here anyway
|
||||||
|
$target = mb_convert_encoding($expected, $expected_encoding, 'UTF-8');
|
||||||
|
// print "IN: $input, $target_encoding\n";
|
||||||
|
$this->assertEquals(
|
||||||
|
$target,
|
||||||
|
$string
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
* @coversDefaultClass \CoreLibs\Convert\Json
|
* @coversDefaultClass \CoreLibs\Convert\Json
|
||||||
* @testdox \CoreLibs\Convert\Json method tests
|
* @testdox \CoreLibs\Convert\Json method tests
|
||||||
*/
|
*/
|
||||||
final class CoreLibsCheckJsonTest extends TestCase
|
final class CoreLibsConvertJsonTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
101
4dev/tests/CoreLibsConvertMimeEncodeTest.php
Normal file
101
4dev/tests/CoreLibsConvertMimeEncodeTest.php
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for Convert\MimeEncode
|
||||||
|
* @coversDefaultClass \CoreLibs\Convert\MimeEncode
|
||||||
|
* @testdox \CoreLibs\Convert\MimeEncode method tests
|
||||||
|
*/
|
||||||
|
final class CoreLibsConvertMimeEncodeTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function mbMimeEncodeProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: input string
|
||||||
|
// 1: encoding
|
||||||
|
// 2: expected
|
||||||
|
'standard UTF-8' => [
|
||||||
|
'Test string',
|
||||||
|
'UTF-8',
|
||||||
|
'Test string'
|
||||||
|
],
|
||||||
|
'long text UTF-8' => [
|
||||||
|
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||||
|
. 'and has no idea what is going on here',
|
||||||
|
'UTF-8',
|
||||||
|
'The quick brown fox jumps over the lazy sheep that sleeps in the ravine '
|
||||||
|
. 'and has no idea what is going on here'
|
||||||
|
],
|
||||||
|
'standard with special chars UTF-8' => [
|
||||||
|
'This is ümläßtと漢字もカタカナ!!^$%&',
|
||||||
|
'UTF-8',
|
||||||
|
'This is =?UTF-8?B?w7xtbMOkw59044Go5ryi5a2X44KC44Kr44K/44Kr44OK77yBIV4k?='
|
||||||
|
. "\r\n"
|
||||||
|
. ' =?UTF-8?B?JQ==?=&'
|
||||||
|
],
|
||||||
|
'35 chars and space at the end UTF-8' => [
|
||||||
|
'12345678901234567890123456789012345 '
|
||||||
|
. 'is there a space?',
|
||||||
|
'UTF-8',
|
||||||
|
'12345678901234567890123456789012345 '
|
||||||
|
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||||
|
],
|
||||||
|
'36 chars and space at the end UTF-8' => [
|
||||||
|
'123456789012345678901234567890123456 '
|
||||||
|
. 'is there a space?',
|
||||||
|
'UTF-8',
|
||||||
|
'123456789012345678901234567890123456 '
|
||||||
|
. 'is there a =?UTF-8?B?c3BhY2U/?='
|
||||||
|
],
|
||||||
|
'36 kanji and space UTF-8' => [
|
||||||
|
'カタカナカタカナかなカタカナカタカナかなカタカナカタカナかなカタカナカタ '
|
||||||
|
. 'is there a space?',
|
||||||
|
'UTF-8',
|
||||||
|
"=?UTF-8?B?44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr44OK44Kr?=\r\n"
|
||||||
|
. " =?UTF-8?B?44K/44Kr44OK?=\r\n"
|
||||||
|
. " =?UTF-8?B?44GL44Gq44Kr44K/44Kr44OK44Kr44K/44Kr44OK44GL44Gq44Kr44K/44Kr?=\r\n"
|
||||||
|
. " =?UTF-8?B?44OK44Kr44K/?= is there a =?UTF-8?B?c3BhY2U/?="
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mb mime header encoding test
|
||||||
|
*
|
||||||
|
* @covers ::__mbMimeEncode
|
||||||
|
* @dataProvider mbMimeEncodeProvider
|
||||||
|
* @testdox mb encoding target $encoding [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testUuMbMimeEncode(string $input, string $encoding, string $expected): void
|
||||||
|
{
|
||||||
|
// encode string first
|
||||||
|
$encoded = \CoreLibs\Convert\MimeEncode::__mbMimeEncode($input, $encoding);
|
||||||
|
// print "MIME: -" . $encoded . "-\n";
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$encoded
|
||||||
|
);
|
||||||
|
$decoded = mb_decode_mimeheader($encoded);
|
||||||
|
// print "INPUT : " . $input . "\n";
|
||||||
|
// print "DECODED: " . $decoded . "\n";
|
||||||
|
// back compare decoded
|
||||||
|
$this->assertEquals(
|
||||||
|
$input,
|
||||||
|
$decoded
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -347,6 +347,7 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns test list for dbCompareVersion check
|
* Returns test list for dbCompareVersion check
|
||||||
|
* NOTE: unless we fully mock the =version check needs to be updated
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@@ -357,16 +358,16 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
return [
|
return [
|
||||||
'compare = ok' => [ '=13.6.0', true ],
|
'compare = ok' => [ '=13.6.0', true ],
|
||||||
'compare = bad' => [ '=9.2.0', false ],
|
'compare = bad' => [ '=9.2.0', false ],
|
||||||
'compare < ok' => [ '<20.0.0', true ],
|
'compare < ok' => [ '<99.0.0', true ],
|
||||||
'compare < bad' => [ '<9.2.0', false ],
|
'compare < bad' => [ '<9.2.0', false ],
|
||||||
'compare <= ok a' => [ '<=20.0.0', true ],
|
'compare <= ok a' => [ '<=99.0.0', true ],
|
||||||
'compare <= ok b' => [ '<=13.6.0', true ],
|
'compare <= ok b' => [ '<=13.6.0', true ],
|
||||||
'compare <= false' => [ '<=9.2.0', false ],
|
'compare <= false' => [ '<=9.2.0', false ],
|
||||||
'compare > ok' => [ '>9.2.0', true ],
|
'compare > ok' => [ '>9.2.0', true ],
|
||||||
'compare > bad' => [ '>20.2.0', false ],
|
'compare > bad' => [ '>99.2.0', false ],
|
||||||
'compare >= ok a' => [ '>=13.6.0', true ],
|
'compare >= ok a' => [ '>=13.6.0', true ],
|
||||||
'compare >= ok b' => [ '>=9.2.0', true ],
|
'compare >= ok b' => [ '>=9.2.0', true ],
|
||||||
'compare >= bad' => [ '>=20.0.0', false ],
|
'compare >= bad' => [ '>=99.0.0', false ],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2646,7 +2647,8 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'level' => 'error',
|
'level' => 'error',
|
||||||
'id' => '51',
|
'id' => '51',
|
||||||
'error' => 'Max query call needs to be set to at least 1',
|
'error' => 'Max query call needs to be set to at least 1',
|
||||||
'source' => 'main::run::run::run::run::run::run::runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall',
|
// run:: can be +1 if called in set and not direct
|
||||||
|
'source' => "/^main::run::run::run::run::run::run::(run::)?runBare::runTest::testDbErrorHandling::dbSetMaxQueryCall$/",
|
||||||
'pg_error' => '',
|
'pg_error' => '',
|
||||||
'msg' => '',
|
'msg' => '',
|
||||||
]
|
]
|
||||||
@@ -3384,6 +3386,53 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if this is a select query, db dbReturn, dbReturnRow, dbReturnArray too
|
||||||
|
if (preg_match("/^(select|show|with) /i", $query)) {
|
||||||
|
// dbReturn
|
||||||
|
$db->dbReturn($query);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_rows,
|
||||||
|
$db->dbGetNumRows()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_cols,
|
||||||
|
$db->dbGetNumFields()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_col_names,
|
||||||
|
$db->dbGetFieldNames()
|
||||||
|
);
|
||||||
|
// dbReturnRow
|
||||||
|
// will return ALL rows there, but returns only the first
|
||||||
|
$db->dbReturnRow($query);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_rows,
|
||||||
|
$db->dbGetNumRows()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_cols,
|
||||||
|
$db->dbGetNumFields()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_col_names,
|
||||||
|
$db->dbGetFieldNames()
|
||||||
|
);
|
||||||
|
// dbReturnArray
|
||||||
|
$db->dbReturnArray($query);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_rows,
|
||||||
|
$db->dbGetNumRows()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_cols,
|
||||||
|
$db->dbGetNumFields()
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_col_names,
|
||||||
|
$db->dbGetFieldNames()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// reset all data
|
// reset all data
|
||||||
$db->dbExec("TRUNCATE table_with_primary_key");
|
$db->dbExec("TRUNCATE table_with_primary_key");
|
||||||
$db->dbExec("TRUNCATE table_without_primary_key");
|
$db->dbExec("TRUNCATE table_without_primary_key");
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?php
|
<?php // phpcs:disable Generic.Files.LineLength
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
@@ -255,18 +255,27 @@ final class CoreLibsDebugSupportTest extends TestCase
|
|||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @cover ::getCallerMethodList
|
* @cover ::getCallerMethodList
|
||||||
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
* @testWith [["main", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"],["main", "run", "run", "run", "run", "run", "run", "run", "runBare", "runTest", "testGetCallerMethodList"]]
|
||||||
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
* @testdox getCallerMethodList check if it returns $expected [$_dataName]
|
||||||
*
|
*
|
||||||
* @param array $expected
|
* @param array $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetCallerMethodList(array $expected): void
|
public function testGetCallerMethodList(array $expected, array $expected_group): void
|
||||||
{
|
{
|
||||||
$this->assertEquals(
|
$compare = \CoreLibs\Debug\Support::getCallerMethodList();
|
||||||
$expected,
|
// if we direct call we have 10, if we call as folder we get 11
|
||||||
\CoreLibs\Debug\Support::getCallerMethodList()
|
if (count($compare) == 10) {
|
||||||
);
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
\CoreLibs\Debug\Support::getCallerMethodList()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_group,
|
||||||
|
\CoreLibs\Debug\Support::getCallerMethodList()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace tests;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test class for Language\Encoding
|
|
||||||
* @coversDefaultClass \CoreLibs\Language\Encoding
|
|
||||||
* @testdox \CoreLibs\Language\Encoding method tests
|
|
||||||
*/
|
|
||||||
final class CoreLibsLanguageEncodingTest extends TestCase
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Undocumented function
|
|
||||||
*
|
|
||||||
* @testdox Language\Encoding Class tests
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testLanguageEncoding()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true, 'Language Encoding Tests not implemented');
|
|
||||||
$this->markTestIncomplete(
|
|
||||||
'Language\Encoding Tests have not yet been implemented'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
291
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
291
4dev/tests/CoreLibsLanguageGetLocaleTest.php
Normal file
@@ -0,0 +1,291 @@
|
|||||||
|
<?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
|
||||||
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
|
// site
|
||||||
|
define('SITE_ENCODING', DEFAULT_ENCODING);
|
||||||
|
define('SITE_LOCALE', DEFAULT_LOCALE);
|
||||||
|
// just set
|
||||||
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
|
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||||
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
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,4 +1,4 @@
|
|||||||
<?php
|
<?php // phpcs:disable Generic.Files.LineLength
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
@@ -16,17 +16,979 @@ use PHPUnit\Framework\TestCase;
|
|||||||
final class CoreLibsLanguageL10nTest extends TestCase
|
final class CoreLibsLanguageL10nTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* set all constant variables that must be set before call
|
||||||
*
|
|
||||||
* @testdox Language\L10n Class tests
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testLanguageEncoding()
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
$this->assertTrue(true, 'Language L10n Tests not implemented');
|
define('DEFAULT_LANG', 'en_US');
|
||||||
$this->markTestIncomplete(
|
// default web page encoding setting
|
||||||
'Language\L10n Tests have not yet been implemented'
|
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('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get instance self type check
|
||||||
|
*
|
||||||
|
* @covers ::getInstance
|
||||||
|
* @testdox check that getInstance() returns valid instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetInstance(): void
|
||||||
|
{
|
||||||
|
$l10n_obj = \CoreLibs\Language\L10n::getInstance();
|
||||||
|
$this->assertIsObject(
|
||||||
|
$l10n_obj
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'\CoreLibs\Language\L10n',
|
||||||
|
$l10n_obj
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current translator class type check
|
||||||
|
*
|
||||||
|
* @covers ::getTranslatorClass
|
||||||
|
* @testdox check that getTranslatorClass() returns valid instance
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetTranslatorClass(): void
|
||||||
|
{
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
$translator = $l10n->getTranslatorClass();
|
||||||
|
$this->assertIsObject(
|
||||||
|
$translator
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
'\CoreLibs\Language\Core\GetTextReader',
|
||||||
|
$translator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provider for class load parameters
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function l10nObjectProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: locale
|
||||||
|
// 1: domain
|
||||||
|
// 2: encoding
|
||||||
|
// 3: path
|
||||||
|
// 4: locale expected
|
||||||
|
// 5: domain exepcted
|
||||||
|
// 6: context (null for none)
|
||||||
|
// 7: test string in
|
||||||
|
// 8: test translated
|
||||||
|
// new style load
|
||||||
|
'gettext load en' => [
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
null,
|
||||||
|
'Original',
|
||||||
|
'Translated frontend en_US',
|
||||||
|
],
|
||||||
|
'gettext load en' => [
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
'context',
|
||||||
|
'Original',
|
||||||
|
'Original context frontend en_US',
|
||||||
|
],
|
||||||
|
'gettext load ja' => [
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'admin',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
//
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'admin',
|
||||||
|
null,
|
||||||
|
'Original',
|
||||||
|
'Translated admin ja_JP',
|
||||||
|
],
|
||||||
|
// mixed path and domain
|
||||||
|
'mixed path and domain' => [
|
||||||
|
'en_US.UTF-8',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
'frontend',
|
||||||
|
//
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
'context',
|
||||||
|
'Original',
|
||||||
|
'Original context frontend en_US',
|
||||||
|
],
|
||||||
|
// null set
|
||||||
|
'empty load new ' => [
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
//
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
'Original',
|
||||||
|
'Original',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* new class load test (basic test)
|
||||||
|
*
|
||||||
|
* @covers ::__construct
|
||||||
|
* @dataProvider l10nObjectProvider
|
||||||
|
* @testdox check l10n init with Locale $locale, Path $path, Domain $domain, Legacy: $legacy with $context [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|null $locale
|
||||||
|
* @param string|null $domain
|
||||||
|
* @param string|null $path
|
||||||
|
* @param string $locale_expected
|
||||||
|
* @param string $domain_expected
|
||||||
|
* @param ?string $context
|
||||||
|
* @param string $original
|
||||||
|
* @param string $translated
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testL10nObject(
|
||||||
|
?string $locale,
|
||||||
|
?string $domain,
|
||||||
|
?string $path,
|
||||||
|
string $locale_expected,
|
||||||
|
string $domain_expected,
|
||||||
|
?string $context,
|
||||||
|
string $original,
|
||||||
|
string $translated,
|
||||||
|
): void {
|
||||||
|
if ($locale === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
} elseif ($domain === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||||
|
} elseif ($path === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||||
|
} else {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||||
|
}
|
||||||
|
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||||
|
// print "MO: " . $l10n->getMoFile() . "\n";
|
||||||
|
$this->assertEquals(
|
||||||
|
$locale_expected,
|
||||||
|
$l10n->getLocale(),
|
||||||
|
'Locale assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$domain_expected,
|
||||||
|
$l10n->getDomain(),
|
||||||
|
'Domain assert failed'
|
||||||
|
);
|
||||||
|
if (empty($context)) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated,
|
||||||
|
$l10n->__($original),
|
||||||
|
'Translated string assert failed'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated,
|
||||||
|
$l10n->__p($context, $original),
|
||||||
|
'Translated string assert failed in context: ' . $context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// l10nReloadMOfile and getTranslator
|
||||||
|
// null init with loader
|
||||||
|
// loader with reload (change type)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTranslatorProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: locale
|
||||||
|
// 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 domain
|
||||||
|
// 10: change path
|
||||||
|
// 11: change load error
|
||||||
|
// 12: expected locale
|
||||||
|
// 13: expected domain
|
||||||
|
// 14: expected translation
|
||||||
|
'load and change (en->ja)' => [
|
||||||
|
// set 0-2
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status 3
|
||||||
|
false,
|
||||||
|
// to translate 4
|
||||||
|
'Original',
|
||||||
|
// check setter 5-7
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
'Translated frontend en_US',
|
||||||
|
// set new 8-10
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status new 11
|
||||||
|
false,
|
||||||
|
// check new setter 12-14
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
'Translated frontend ja_JP',
|
||||||
|
],
|
||||||
|
'empty load and change to en' => [
|
||||||
|
// set 0-2
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
// status 3
|
||||||
|
false,
|
||||||
|
// to translate 4
|
||||||
|
'Original',
|
||||||
|
// check setter 5-7
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
'Original',
|
||||||
|
// set new 8-10
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
// status new 11
|
||||||
|
false,
|
||||||
|
// check new setter 12-14
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
'Translated frontend en_US',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init check and connected change translation
|
||||||
|
*
|
||||||
|
* @covers ::getTranslator
|
||||||
|
* @covers ::l10nReloadMOfile
|
||||||
|
* @dataProvider getTranslatorProvider
|
||||||
|
* @testdox change locale from $locale and domain $domain to locale $locale_new and domain $domain_new [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string|null $locale
|
||||||
|
* @param string|null $domain
|
||||||
|
* @param string|null $path
|
||||||
|
* @param bool $load_error
|
||||||
|
* @param string $original
|
||||||
|
* @param string $locale_expected_a
|
||||||
|
* @param string $domain_expected_a
|
||||||
|
* @param string $translated_a
|
||||||
|
* @param string|null $locale_new
|
||||||
|
* @param string|null $domain_new
|
||||||
|
* @param string|null $path_new
|
||||||
|
* @param bool $load_error_new
|
||||||
|
* @param string $locale_expected_b
|
||||||
|
* @param string $domain_expected_b
|
||||||
|
* @param string $translated_b
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testGetTranslator(
|
||||||
|
// 0-2
|
||||||
|
?string $locale,
|
||||||
|
?string $domain,
|
||||||
|
?string $path,
|
||||||
|
// 3
|
||||||
|
bool $load_error,
|
||||||
|
// 4
|
||||||
|
string $original,
|
||||||
|
// 5-7
|
||||||
|
string $locale_expected_a,
|
||||||
|
string $domain_expected_a,
|
||||||
|
string $translated_a,
|
||||||
|
// 8-10
|
||||||
|
?string $locale_new,
|
||||||
|
?string $domain_new,
|
||||||
|
?string $path_new,
|
||||||
|
// 11
|
||||||
|
bool $load_error_new,
|
||||||
|
// 12-14
|
||||||
|
string $locale_expected_b,
|
||||||
|
string $domain_expected_b,
|
||||||
|
string $translated_b,
|
||||||
|
): void {
|
||||||
|
if ($locale === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
} elseif ($domain === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale);
|
||||||
|
} elseif ($path === null) {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain);
|
||||||
|
} else {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale, $domain, $path);
|
||||||
|
}
|
||||||
|
// print "LOC: " . $locale . ", " . $l10n->getLocale() . ", " . $locale_expected . "\n";
|
||||||
|
// status check
|
||||||
|
$this->assertEquals(
|
||||||
|
$load_error,
|
||||||
|
$l10n->getLoadError(),
|
||||||
|
'Legacy method load error init check'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$locale_expected_a,
|
||||||
|
$l10n->getLocale(),
|
||||||
|
'Locale init assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$domain_expected_a,
|
||||||
|
$l10n->getDomain(),
|
||||||
|
'Domain init assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated_a,
|
||||||
|
$l10n->__($original),
|
||||||
|
'Translated string init assert failed'
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
$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(
|
||||||
|
$domain_expected_b,
|
||||||
|
$l10n->getDomain(),
|
||||||
|
'Domain change assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated_b,
|
||||||
|
$l10n->__($original),
|
||||||
|
'Translated string change assert failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: domain based
|
||||||
|
// ->dgettext
|
||||||
|
// ->dngettext
|
||||||
|
// ->dpgettext
|
||||||
|
// ->dpngettext
|
||||||
|
|
||||||
|
/**
|
||||||
|
* for plural and plural context
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function ngettextProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: locale
|
||||||
|
// 1: path
|
||||||
|
// 2: domain
|
||||||
|
// 3: context (null for none)
|
||||||
|
// 4: single string
|
||||||
|
// 5: plural string
|
||||||
|
// 6: array for each n value expected string
|
||||||
|
'plural text en' => [
|
||||||
|
'en_US',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
'admin',
|
||||||
|
// context
|
||||||
|
null,
|
||||||
|
// text single/multi in
|
||||||
|
'single',
|
||||||
|
'multi',
|
||||||
|
// confirm translation, pos in array equal n
|
||||||
|
[
|
||||||
|
0 => 'Multi admin en_US 1',
|
||||||
|
1 => 'Multi admin en_US 0',
|
||||||
|
2 => 'Multi admin en_US 1',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'plural text context en' => [
|
||||||
|
'en_US',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
'admin',
|
||||||
|
// context
|
||||||
|
'context',
|
||||||
|
// text single/multi in
|
||||||
|
'single',
|
||||||
|
'multi',
|
||||||
|
// confirm translation, pos in array equal n
|
||||||
|
[
|
||||||
|
0 => 'Multi context admin en_US 1',
|
||||||
|
1 => 'Multi context admin en_US 0',
|
||||||
|
2 => 'Multi context admin en_US 1',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* plural and plural context
|
||||||
|
*
|
||||||
|
* @covers ::__n
|
||||||
|
* @covers ::__pn
|
||||||
|
* @dataProvider ngettextProvider
|
||||||
|
* @testdox plural string test for locale $locale and domain $domain with $context [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $locale
|
||||||
|
* @param string $path
|
||||||
|
* @param string $domain
|
||||||
|
* @param ?string $context
|
||||||
|
* @param string $original_single
|
||||||
|
* @param string $original_plural
|
||||||
|
* @param array $expected_strings
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNgettext(
|
||||||
|
// config 0-3
|
||||||
|
string $locale,
|
||||||
|
string $path,
|
||||||
|
string $domain,
|
||||||
|
// context string
|
||||||
|
?string $context,
|
||||||
|
// input strings
|
||||||
|
string $original_single,
|
||||||
|
string $original_plural,
|
||||||
|
// expected
|
||||||
|
array $expected_strings
|
||||||
|
): void {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n($locale, $path, $domain, false);
|
||||||
|
|
||||||
|
foreach ($expected_strings as $n => $expected) {
|
||||||
|
if (empty($context)) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$l10n->__n($original_single, $original_plural, $n),
|
||||||
|
'assert failed for plural: ' . $n
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$l10n->__pn($context, $original_single, $original_plural, $n),
|
||||||
|
'assert failed for plural: ' . $n . ' in context: ' . $context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* locales list for testing locale folder lookup
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function localesProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: locale
|
||||||
|
// 1: return array
|
||||||
|
'en' => [
|
||||||
|
'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',
|
||||||
|
[
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'modifier' => null,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'en_US@subtext' => [
|
||||||
|
'en_US@subtext',
|
||||||
|
[
|
||||||
|
'en_US@subtext',
|
||||||
|
'en@subtext',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => null,
|
||||||
|
'modifier' => 'subtext',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'en_US.UTF-8@subtext' => [
|
||||||
|
'en_US.UTF-8@subtext',
|
||||||
|
[
|
||||||
|
'en_US.UTF-8@subtext',
|
||||||
|
'en_US@subtext',
|
||||||
|
'en@subtext',
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'en_US',
|
||||||
|
'en',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'lang' => 'en',
|
||||||
|
'country' => 'US',
|
||||||
|
'charset' => 'UTF-8',
|
||||||
|
'modifier' => 'subtext',
|
||||||
|
],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test locales array return
|
||||||
|
*
|
||||||
|
* @covers ::listLocales
|
||||||
|
* @dataProvider localesProvider
|
||||||
|
* @testdox check $locale [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $locale
|
||||||
|
* @param array $expected_list
|
||||||
|
* @param array $expected_detail
|
||||||
|
* @return 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_list,
|
||||||
|
$locale_list,
|
||||||
|
'List locale assert failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @covers ::detectLocale
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function detectLocaleProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: type: global | env
|
||||||
|
// 1: global variable name or enviroment var
|
||||||
|
// 2: value to set
|
||||||
|
// 3: value to expect back
|
||||||
|
'global locale' => [
|
||||||
|
'global',
|
||||||
|
'LOCALE',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
],
|
||||||
|
'env LC_ALL' => [
|
||||||
|
'env',
|
||||||
|
'LC_ALL',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
],
|
||||||
|
'env LANG' => [
|
||||||
|
'env',
|
||||||
|
'LANG',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
],
|
||||||
|
'default return' => [
|
||||||
|
'env',
|
||||||
|
'LC_ALL',
|
||||||
|
'',
|
||||||
|
'en',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
* @covers ::detectLocale
|
||||||
|
* @dataProvider detectLocaleProvider
|
||||||
|
* @testdox check detectLocale for $type with $var and $value is $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDetectLocale(
|
||||||
|
string $type,
|
||||||
|
string $var,
|
||||||
|
string $value,
|
||||||
|
string $expected,
|
||||||
|
): void {
|
||||||
|
switch ($type) {
|
||||||
|
case 'global':
|
||||||
|
$GLOBALS[$var] = $value;
|
||||||
|
break;
|
||||||
|
case 'env':
|
||||||
|
$old_value = getenv("$var");
|
||||||
|
putenv("$var=$value");
|
||||||
|
// unset all other env vars
|
||||||
|
foreach (['LC_ALL', 'LC_MESSAGES', 'LANG'] as $env) {
|
||||||
|
if ($env != $var) {
|
||||||
|
putenv("$env=");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$locale = \CoreLibs\Language\L10n::detectLocale();
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$locale
|
||||||
|
);
|
||||||
|
// reset post run
|
||||||
|
switch ($type) {
|
||||||
|
case 'global':
|
||||||
|
unset($GLOBALS[$var]);
|
||||||
|
break;
|
||||||
|
case 'env':
|
||||||
|
putenv("$var=$old_value");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set/get text domain, domain, locale
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function textDomainProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: set domain
|
||||||
|
// 1: set path
|
||||||
|
// 2: get domain
|
||||||
|
// 3: expected path
|
||||||
|
'valid set and get' => [
|
||||||
|
'foo',
|
||||||
|
'foo/bar',
|
||||||
|
'foo',
|
||||||
|
'foo/bar',
|
||||||
|
],
|
||||||
|
'invalid set and get' => [
|
||||||
|
'foo',
|
||||||
|
'foo/bar',
|
||||||
|
'iamnotset',
|
||||||
|
false
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setTextDomain
|
||||||
|
* @covers ::getTextDomain
|
||||||
|
* @dataProvider textDomainProvider
|
||||||
|
* @testdox set $domain with $path and get $get_domain and expect $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @param string $path
|
||||||
|
* @param string $get_domain
|
||||||
|
* @param string|bool $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetGetTextDomain(string $domain, string $path, string $get_domain, $expected): void
|
||||||
|
{
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
$l10n->setTextDomain($domain, $path);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$l10n->getTextDomain($get_domain)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function domainProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: set domain
|
||||||
|
// 1: expected domain from get
|
||||||
|
'valid domain' => [
|
||||||
|
'foo',
|
||||||
|
'foo',
|
||||||
|
],
|
||||||
|
'empty domain' => [
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setDomain
|
||||||
|
* @covers ::getDomain
|
||||||
|
* @dataProvider domainProvider
|
||||||
|
* @testdox set $domain and expect $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetGetDomain(string $domain, string $expected): void
|
||||||
|
{
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
$l10n->setDomain($domain);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$l10n->getDomain()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function localeProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: set locale
|
||||||
|
// 1: pre set if not null or not empty
|
||||||
|
// 2: expected return from set
|
||||||
|
// 3: expected from get
|
||||||
|
'valid locale' => [
|
||||||
|
'foo',
|
||||||
|
null,
|
||||||
|
'foo',
|
||||||
|
'foo',
|
||||||
|
],
|
||||||
|
'empty locale' => [
|
||||||
|
'',
|
||||||
|
null,
|
||||||
|
'',
|
||||||
|
'',
|
||||||
|
],
|
||||||
|
'empty locale, pre set' => [
|
||||||
|
'',
|
||||||
|
'foo',
|
||||||
|
'foo',
|
||||||
|
'foo',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::setLocale
|
||||||
|
* @covers ::getLocale
|
||||||
|
* @dataProvider localeProvider
|
||||||
|
* @testdox set $locale with $expected_return and expect $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $locale
|
||||||
|
* @param string $pre_locale
|
||||||
|
* @param string $expected_return
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testSetGetLocale(
|
||||||
|
string $locale,
|
||||||
|
?string $pre_locale,
|
||||||
|
string $expected_return,
|
||||||
|
string $expected
|
||||||
|
): void {
|
||||||
|
$l10n = new \CoreLibs\Language\L10n();
|
||||||
|
if (!empty($pre_locale)) {
|
||||||
|
$l10n->setLocale($pre_locale);
|
||||||
|
}
|
||||||
|
$returned = $l10n->setLocale($locale);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected_return,
|
||||||
|
$returned,
|
||||||
|
'Set locale return assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expected,
|
||||||
|
$l10n->getLocale(),
|
||||||
|
'Get locale aszert failed'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static load
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function functionsProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
// 0: lang/locale
|
||||||
|
// 1: domain
|
||||||
|
// 2: path
|
||||||
|
// 3: encoding
|
||||||
|
// 4: string
|
||||||
|
// 5: translated string
|
||||||
|
'standard en' => [
|
||||||
|
'en_US.UTF-8',
|
||||||
|
'frontend',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
'UTF-8',
|
||||||
|
'Original',
|
||||||
|
'Translated frontend en_US',
|
||||||
|
],
|
||||||
|
'standard ja' => [
|
||||||
|
'ja_JP.UTF-8',
|
||||||
|
'admin',
|
||||||
|
__DIR__ . 'includes/locale/',
|
||||||
|
'UTF-8',
|
||||||
|
'Original',
|
||||||
|
'Translated admin ja_JP',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fuctions check
|
||||||
|
* TODO: others d/dn/dp/dpn gettext functions
|
||||||
|
*
|
||||||
|
* @covers __setlocale
|
||||||
|
* @covers __bindtextdomain
|
||||||
|
* @covers __bind_textdomain_codeset
|
||||||
|
* @covers __textdomain
|
||||||
|
* @covers __gettext
|
||||||
|
* @covers __
|
||||||
|
* @dataProvider functionsProvider
|
||||||
|
* @testdox check functions with locale $locale and domain $domain [$_dataName]
|
||||||
|
* @param string $locale
|
||||||
|
* @param string $domain
|
||||||
|
* @param string $path
|
||||||
|
* @param string $encoding
|
||||||
|
* @param string $original
|
||||||
|
* @param string $translated
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFunctions(
|
||||||
|
string $locale,
|
||||||
|
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);
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated,
|
||||||
|
__($original),
|
||||||
|
'function __ assert failed'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$translated,
|
||||||
|
__gettext($original),
|
||||||
|
'function gettext assert failed'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
4dev/tests/includes/create_po.sh
Executable file
16
4dev/tests/includes/create_po.sh
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# if we don't have one base file we are in the wrong folder
|
||||||
|
if [ ! -f "locale/en_US/LC_MESSAGES/admin.mo" ]; then
|
||||||
|
echo "Locale file is missing, wrong base folder?"
|
||||||
|
echo "Should be: 4dev/tests/includes/"
|
||||||
|
exit;
|
||||||
|
fi;
|
||||||
|
|
||||||
|
for file in $(ls -1 locale/*.po); do
|
||||||
|
echo $file;
|
||||||
|
file=$(basename $file .po);
|
||||||
|
locale=$(echo "${file}" | cut -d "-" -f 1);
|
||||||
|
domain=$(echo "${file}" | cut -d "-" -f 2);
|
||||||
|
msgfmt -o locale/${locale}/LC_MESSAGES/${domain}.mo locale/${locale}-${domain}.po;
|
||||||
|
done;
|
||||||
34
4dev/tests/includes/locale/en_US-admin.po
Normal file
34
4dev/tests/includes/locale/en_US-admin.po
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: en_US.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"
|
||||||
|
"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 "Original"
|
||||||
|
msgstr "Translated admin en_US"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Original context admin en_US"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi context admin en_US 0"
|
||||||
|
msgstr[1] "Multi context admin en_US 1"
|
||||||
|
msgstr[2] "Multi context admin en_US 2"
|
||||||
34
4dev/tests/includes/locale/en_US-frontend.po
Normal file
34
4dev/tests/includes/locale/en_US-frontend.po
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: en_US.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"
|
||||||
|
"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 "Original"
|
||||||
|
msgstr "Translated frontend en_US"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Original context frontend en_US"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi context frontend en_US 0"
|
||||||
|
msgstr[1] "Multi context frontend en_US 1"
|
||||||
|
msgstr[2] "Multi context frontend en_US 2"
|
||||||
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
BIN
4dev/tests/includes/locale/en_US/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
35
4dev/tests/includes/locale/ja_JP-admin.po
Normal file
35
4dev/tests/includes/locale/ja_JP-admin.po
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: ja_JP.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: ja\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
|
||||||
|
# 0, 1, 2 plural
|
||||||
|
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Translated admin ja_JP"
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Original context admin ja_JP"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi context admin ja_JP 0"
|
||||||
|
msgstr[1] "Multi context admin ja_JP 1"
|
||||||
|
msgstr[2] "Multi context admin ja_JP 2"
|
||||||
35
4dev/tests/includes/locale/ja_JP-frontend.po
Normal file
35
4dev/tests/includes/locale/ja_JP-frontend.po
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: ja_JP.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: ja\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;\n"
|
||||||
|
# 0, 1, 2 plural
|
||||||
|
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Translated frontend ja_JP"
|
||||||
|
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi frontend ja_JP 0"
|
||||||
|
msgstr[1] "Multi frontend ja_JP 1"
|
||||||
|
msgstr[2] "Multi frontend ja_JP 2"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "Original"
|
||||||
|
msgstr "Original context frontend ja_JP"
|
||||||
|
|
||||||
|
msgctxt "context"
|
||||||
|
msgid "single"
|
||||||
|
msgid_plural "multi"
|
||||||
|
msgstr[0] "Multi context frontend ja_JP 0"
|
||||||
|
msgstr[1] "Multi context frontend ja_JP 1"
|
||||||
|
msgstr[2] "Multi context frontend ja_JP 2"
|
||||||
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/admin.mo
Normal file
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
BIN
4dev/tests/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
|||||||
// login & page access check
|
// login & page access check
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$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
|
* admin backend also needs logger
|
||||||
```php
|
```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 and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
|
||||||
* update all `config.*.php` files where needed
|
* update all `config.*.php` files where needed
|
||||||
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
|
|||||||
```
|
```
|
||||||
**UPDATE:**
|
**UPDATE:**
|
||||||
```php
|
```php
|
||||||
|
// po langs [DEPRECAED: use LOCALE]
|
||||||
|
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
|
||||||
|
// po locale file
|
||||||
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
|
```
|
||||||
|
```php
|
||||||
// SSL host name
|
// SSL host name
|
||||||
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
// 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'] ?? ''));
|
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
||||||
```
|
```
|
||||||
```php
|
```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:
|
// BAIL ON MISSING DB CONFIG:
|
||||||
// we have either no db selction for this host but have db config entries
|
// 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
|
// or we have a db selection but no db config as array or empty
|
||||||
@@ -104,6 +132,10 @@ if (
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
```php
|
```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
|
```php
|
||||||
/************* GENERAL PAGE TITLE ********/
|
/************* GENERAL PAGE TITLE ********/
|
||||||
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||||
@@ -118,6 +150,15 @@ In the config then
|
|||||||
```php
|
```php
|
||||||
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
|
'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`
|
* copy `layout/admin/javascript/edit.jq.js`
|
||||||
* check other javacsript files if needed (`edit.jq.js`)
|
* check other javacsript files if needed (`edit.jq.js`)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
// sets the _SERVER['HTTP_HOST'] var so we can have DB detection
|
// sets the _SERVER['HTTP_HOST'] var so we can have DB detection
|
||||||
$_SERVER['HTTP_HOST'] = 'soba.tokyo.tequila.jp';
|
$_SERVER['HTTP_HOST'] = 'soba.tokyo.tequila.jp';
|
||||||
// so www/includes/edit_base.php works
|
// so www/includes/edit_base.php works
|
||||||
require_once('www/lib/Smarty/SmartyBC.class.php');
|
// require_once('www/lib/Smarty/SmartyBC.class.php');
|
||||||
// for whatever reason it does not load that from the confing.master.php
|
// for whatever reason it does not load that from the confing.master.php
|
||||||
// for includes/admin_header.php
|
// for includes/admin_header.php
|
||||||
define('BASE_NAME', '');
|
define('BASE_NAME', '');
|
||||||
|
|||||||
@@ -45,9 +45,6 @@ parameters:
|
|||||||
- www/lib/smarty-*/
|
- www/lib/smarty-*/
|
||||||
# ignore composer
|
# ignore composer
|
||||||
- www/vendor
|
- www/vendor
|
||||||
# temp ignore smarty 4
|
|
||||||
- www/lib/CoreLibs/Template/SmartyExtend4.php
|
|
||||||
- www/admin/class_test.smarty4.php
|
|
||||||
# ignore errores with
|
# ignore errores with
|
||||||
ignoreErrors:
|
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_*
|
||||||
|
|||||||
@@ -43,18 +43,25 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
// db config with logger
|
// db config with logger
|
||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$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);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|
||||||
// set acl, from eg login acl
|
// 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 "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
|
||||||
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
|
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
|
||||||
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
|
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
|
||||||
print "Messaes: " . \CoreLibs\Debug\Support::printAr($this->messages) . "<br>";
|
print "Messaes: " . \CoreLibs\Debug\Support::printAr($backend->messages) . "<br>";
|
||||||
print "ADBPRINTDATETIME:<br>" . $backend->adbPrintDateTime(2021, 6, 21, 6, 38, '_test') . "<br>";
|
print "ADBPRINTDATETIME:<br>" . $backend->adbPrintDateTime(2021, 6, 21, 6, 38, '_test') . "<br>";
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
// $_array = new CoreLibs\Combined\ArrayHandler();
|
// $_array = new CoreLibs\Combined\ArrayHandler();
|
||||||
// $array_class = 'CoreLibs\Combination\ArrayHandler';
|
// $array_class = 'CoreLibs\Combination\ArrayHandler';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
|
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ ob_end_flush();
|
|||||||
|
|
||||||
use CoreLibs\Convert\Byte;
|
use CoreLibs\Convert\Byte;
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
|
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$byte_class = 'CoreLibs\Convert\Byte';
|
$byte_class = 'CoreLibs\Convert\Byte';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
|
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$color_class = 'CoreLibs\Convert\Colors';
|
$color_class = 'CoreLibs\Convert\Colors';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: COLORS</title><head>";
|
print "<html><head><title>TEST CLASS: COLORS</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
@@ -57,6 +58,7 @@ print "\$C::S/COLOR invalid rgb->hex (gray 125): -1, -1, -1: " . $color_class::r
|
|||||||
$rgb = [10, 20, 30];
|
$rgb = [10, 20, 30];
|
||||||
$hex = '#0a141e';
|
$hex = '#0a141e';
|
||||||
$hsb = [210, 67, 12];
|
$hsb = [210, 67, 12];
|
||||||
|
$hsb_f = [210.5, 67.5, 12.5];
|
||||||
$hsl = [210, 50, 7.8];
|
$hsl = [210, 50, 7.8];
|
||||||
print "S::COLOR rgb->hex: $rgb[0], $rgb[1], $rgb[2]: " . Colors::rgb2hex($rgb[0], $rgb[1], $rgb[2]) . "<br>";
|
print "S::COLOR rgb->hex: $rgb[0], $rgb[1], $rgb[2]: " . Colors::rgb2hex($rgb[0], $rgb[1], $rgb[2]) . "<br>";
|
||||||
print "S::COLOR hex->rgb: $hex: " . DgS::printAr(Colors::hex2rgb($hex)) . "<br>";
|
print "S::COLOR hex->rgb: $hex: " . DgS::printAr(Colors::hex2rgb($hex)) . "<br>";
|
||||||
@@ -69,6 +71,8 @@ print "S::COLOR rgb->hsl: $rgb[0], $rgb[1], $rgb[2]: "
|
|||||||
// D(from hsb/hsl) Note that param 2 + 3 is always 0-100 divided
|
// D(from hsb/hsl) Note that param 2 + 3 is always 0-100 divided
|
||||||
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
||||||
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
||||||
|
print "S::COLOR hsb_f->rgb: $hsb_f[0], $hsb_f[1], $hsb_f[2]: "
|
||||||
|
. DgS::printAr(Colors::hsb2rgb($hsb_f[0], $hsb_f[1], $hsb_f[2])) . "<br>";
|
||||||
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
|
print "S::COLOR hsl->rgb: $hsl[0], $hsl[1], $hsl[2]: "
|
||||||
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
|
. DgS::printAr(Colors::hsl2rgb($hsl[0], $hsl[1], $hsl[2])) . "<br>";
|
||||||
|
|
||||||
@@ -76,6 +80,15 @@ $hsb = [0, 0, 5];
|
|||||||
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
|
||||||
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
. DgS::printAr(Colors::hsb2rgb($hsb[0], $hsb[1], $hsb[2])) . "<br>";
|
||||||
|
|
||||||
|
// Random text
|
||||||
|
$h = rand(0, 359);
|
||||||
|
$s = rand(15, 70);
|
||||||
|
$b = 100;
|
||||||
|
$l = 50;
|
||||||
|
print "RANDOM IN: H: " . $h . ", S: " . $s . ", B/L: " . $b . "/" . $l . "<br>";
|
||||||
|
print "RANDOM hsb->rgb: <pre>" . DgS::printAr(Colors::hsb2rgb($h, $s, $b)) . "</pre><br>";
|
||||||
|
print "RANDOM hsl->rgb: <pre>" . DgS::printAr(Colors::hsl2rgb($h, $s, $l)) . "</pre><br>";
|
||||||
|
|
||||||
// TODO: run compare check input must match output
|
// TODO: run compare check input must match output
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$datetime_class = 'CoreLibs\Combined\DateTime';
|
$datetime_class = 'CoreLibs\Combined\DateTime';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
|
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
$db->log->debug('START', '=============================>');
|
$db->log->debug('START', '=============================>');
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: DB</title><head>";
|
print "<html><head><title>TEST CLASS: DB</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
@@ -69,6 +70,9 @@ $db->dbSetEncoding('SJIS');
|
|||||||
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
|
print "ENCODING TEST: " . $db->dbVersionInfo('client_encoding') . "/" . $db->dbGetEncoding() . "<br>";
|
||||||
$db->dbResetEncoding();
|
$db->dbResetEncoding();
|
||||||
|
|
||||||
|
$res = $db->dbReturn("SELECT * FROM max_test");
|
||||||
|
print "DB RETURN ROWS: " . $db->dbGetNumRows() . "<br>";
|
||||||
|
|
||||||
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) {
|
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", DbIo::USE_CACHE, true))) {
|
||||||
print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
|
print "UUD/TIME: " . $res['uid'] . "/" . $res['time'] . "<br>";
|
||||||
}
|
}
|
||||||
@@ -277,7 +281,7 @@ print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got p
|
|||||||
// return Array Test
|
// return Array Test
|
||||||
$query = "SELECT type, sdate, integer FROM foobar";
|
$query = "SELECT type, sdate, integer FROM foobar";
|
||||||
$data = $db->dbReturnArray($query, true);
|
$data = $db->dbReturnArray($query, true);
|
||||||
print "Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
|
print "Rows: " . $db->dbGetNumRows() . ", Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
|
||||||
|
|
||||||
// trigger a warning
|
// trigger a warning
|
||||||
print "<b>WARNING NEXT</b><br>";
|
print "<b>WARNING NEXT</b><br>";
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ $debug = new CoreLibs\Debug\Logging([
|
|||||||
$debug_support_class = 'CoreLibs\Debug\Support';
|
$debug_support_class = 'CoreLibs\Debug\Support';
|
||||||
$debug_logging_class = 'CoreLibs\Debug\Logging';
|
$debug_logging_class = 'CoreLibs\Debug\Logging';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
|
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ if (!defined('SET_SESSION_NAME')) {
|
|||||||
$LOG_FILE_ID = 'classTest-encoding';
|
$LOG_FILE_ID = 'classTest-encoding';
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
use CoreLibs\Language\Encoding;
|
use CoreLibs\Convert\Encoding as ConEnc;
|
||||||
|
use CoreLibs\Check\Encoding as ChkEnc;
|
||||||
|
use CoreLibs\Convert\MimeEncode;
|
||||||
|
|
||||||
$log = new CoreLibs\Debug\Logging([
|
$log = new CoreLibs\Debug\Logging([
|
||||||
'log_folder' => BASE . LOG,
|
'log_folder' => BASE . LOG,
|
||||||
@@ -41,10 +43,13 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'echo_all' => $ECHO_ALL ?? false,
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
$_encoding = new CoreLibs\Language\Encoding();
|
// class type
|
||||||
$encoding_class = 'CoreLibs\Language\Encoding';
|
$_chk_enc = new CoreLibs\Check\Encoding();
|
||||||
|
$_con_enc = new CoreLibs\Convert\Encoding();
|
||||||
|
$chk_enc = 'CoreLibs\Check\Encoding';
|
||||||
|
|
||||||
print "<html><head><title>TEST CLASS: ENCODING</title><head>";
|
print "<!DOCTYPE html>";
|
||||||
|
print "<html><head><title>TEST CLASS: ENCODING (CHECK/CONVERT/MIME)</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|
||||||
@@ -58,41 +63,47 @@ $mime_encodes = [
|
|||||||
['日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい', 'ISO-2022-JP-MS'],
|
['日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい', 'ISO-2022-JP-MS'],
|
||||||
];
|
];
|
||||||
foreach ($mime_encodes as $mime_encode) {
|
foreach ($mime_encodes as $mime_encode) {
|
||||||
print "__MBMIMEENCODE: $mime_encode[0]: " . Encoding::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
|
print "__MBMIMEENCODE: $mime_encode[0]: " . MimeEncode::__mbMimeEncode($mime_encode[0], $mime_encode[1]) . "<br>";
|
||||||
}
|
}
|
||||||
|
echo "<br>";
|
||||||
|
|
||||||
$enc_strings = [
|
$enc_strings = [
|
||||||
'Normal Text',
|
'Normal Text',
|
||||||
'日本語',
|
'日本語',
|
||||||
|
// bad
|
||||||
|
'❶',
|
||||||
// unworkable
|
// unworkable
|
||||||
''
|
''
|
||||||
];
|
];
|
||||||
// class
|
// class
|
||||||
$_encoding->setErrorChar('∴');
|
$_chk_enc->setErrorChar(0x2234);
|
||||||
|
$_chk_enc->setErrorChar('∴');
|
||||||
|
print "ERROR CHAR: " . $_chk_enc->getErrorChar() . "<br>";
|
||||||
foreach ($enc_strings as $_string) {
|
foreach ($enc_strings as $_string) {
|
||||||
$string = $_encoding->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
$string = $_chk_enc->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||||
print "ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
print "ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
|
||||||
print "CONV ENCODING: $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
print "CONV ENCODING: $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||||
print "CONV ENCODING (s): $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
print "CONV ENCODING (s): $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||||
print "CONV ENCODING (s,a-false): $_string: "
|
print "CONV ENCODING (s,a-false): $_string: "
|
||||||
. $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
. $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||||
}
|
}
|
||||||
print "ERROR CHAR: " . $_encoding->getErrorChar() . "<br>";
|
echo "<br>";
|
||||||
// static
|
// static
|
||||||
$encoding_class::setErrorChar('∴');
|
// ChkEnc::setErrorChar('∴');
|
||||||
|
ChkEnc::setErrorChar(0x2234);
|
||||||
|
print "S::ERROR CHAR: " . ChkEnc::getErrorChar() . "<br>";
|
||||||
foreach ($enc_strings as $_string) {
|
foreach ($enc_strings as $_string) {
|
||||||
$string = $encoding_class::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
$string = ChkEnc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||||
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
print "S::ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
|
||||||
print "S::CONV ENCODING: $_string: " . $encoding_class::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
print "S::CONV ENCODING: $_string: " . ConEnc::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
|
||||||
print "S::CONV ENCODING (s): $_string: "
|
print "S::CONV ENCODING (s): $_string: "
|
||||||
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
|
||||||
print "S::CONV ENCODING (s,a-false): $_string: "
|
print "S::CONV ENCODING (s,a-false): $_string: "
|
||||||
. $encoding_class::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
. ConEnc::convertEncoding($_string, 'ISO-2022-JP', 'UTF-8', false) . "<br>";
|
||||||
}
|
}
|
||||||
print "S::ERROR CHAR: " . $encoding_class::getErrorChar() . "<br>";
|
|
||||||
// static use
|
// static use
|
||||||
$_string = $enc_strings[1];
|
$_string = $enc_strings[1];
|
||||||
$string = Encoding::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
$string = $chk_enc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
|
||||||
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: FILE</title><head>";
|
print "<html><head><title>TEST CLASS: FILE</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ $hash_class = 'CoreLibs\Create\Hash';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: HASH</title><head>";
|
print "<html><head><title>TEST CLASS: HASH</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ $image_class = 'CoreLibs\Output\Image';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
|
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ $json_class = 'CoreLibs\Convert\Json';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: JSON</title><head>";
|
print "<html><head><title>TEST CLASS: JSON</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ ob_start();
|
|||||||
|
|
||||||
// basic class test file
|
// basic class test file
|
||||||
define('USE_DATABASE', false);
|
define('USE_DATABASE', false);
|
||||||
// init language
|
|
||||||
$lang = 'en_utf8';
|
|
||||||
// sample config
|
// sample config
|
||||||
require 'config.php';
|
require 'config.php';
|
||||||
// set session name
|
// set session name
|
||||||
@@ -29,28 +27,145 @@ if (!defined('SET_SESSION_NAME')) {
|
|||||||
}
|
}
|
||||||
// define log file id
|
// define log file id
|
||||||
$LOG_FILE_ID = 'classTest-lang';
|
$LOG_FILE_ID = 'classTest-lang';
|
||||||
|
|
||||||
$l = new CoreLibs\Language\L10n($lang);
|
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: LANG</title><head>";
|
print "<html><head><title>TEST CLASS: LANG</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></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';
|
$string = 'INPUT TEST';
|
||||||
|
// new path test
|
||||||
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
|
$lang = 'ja';
|
||||||
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
|
$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 "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
|
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||||
// switch to other language
|
$single_string = 'single';
|
||||||
$lang = 'ja_utf8';
|
$multi_string = 'multi';
|
||||||
$l->l10nReloadMOfile($lang);
|
for ($n = 0; $n <= 3; $n++) {
|
||||||
|
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||||
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
|
. $l->__n($single_string, $multi_string, $n) . "<br>";
|
||||||
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
|
}
|
||||||
|
$context = "month name";
|
||||||
|
$context_string = "May";
|
||||||
|
echo "CONTEXT TRANSLATION: " . $context_string . " => " . $l->__p($context, $context_string) . "<br>";
|
||||||
|
$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>";
|
||||||
|
}
|
||||||
|
// change domain
|
||||||
|
$domain = 'frontend';
|
||||||
|
$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 "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||||
// TODO: run compare check input must match output
|
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>";
|
||||||
|
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>";
|
||||||
|
|
||||||
|
$domain = 'admin';
|
||||||
|
echo "<br><b>STATIC TYPE TEST</b><br>";
|
||||||
|
// static tests from l10n_load
|
||||||
|
L10n::getInstance()->setLocale($lang);
|
||||||
|
echo "SET LOCALE: " . L10n::getInstance()->getLocale() . "<br>";
|
||||||
|
L10n::getInstance()->setDomain($domain);
|
||||||
|
echo "SET DOMAIN: " . L10n::getInstance()->getDomain() . "<br>";
|
||||||
|
L10n::getInstance()->setTextDomain($domain, $path);
|
||||||
|
echo "SET TEXT DOMAIN: " . L10n::getInstance()->getTextDomain($domain) . "<br>";
|
||||||
|
// null call __bind_textdomain_codeset
|
||||||
|
echo "INPUT TEST: " . $string . " => " . L10n::getInstance()->getTranslator()->gettext($string) . "<br>";
|
||||||
|
|
||||||
|
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);
|
||||||
|
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||||
|
|
||||||
|
$locale = 'en_US.UTF-8';
|
||||||
|
__setlocale(LC_MESSAGES, $locale);
|
||||||
|
__textdomain($domain);
|
||||||
|
__bindtextdomain($domain, $path);
|
||||||
|
__bind_textdomain_codeset($domain, $encoding);
|
||||||
|
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ $math_class = 'CoreLibs\Convert\Math';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: MATH</title><head>";
|
print "<html><head><title>TEST CLASS: MATH</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$_mime = new CoreLibs\Convert\MimeAppName();
|
$_mime = new CoreLibs\Convert\MimeAppName();
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: MIME</title><head>";
|
print "<html><head><title>TEST CLASS: MIME</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
|
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ $password_class = 'CoreLibs\Check\Password';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
|
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -41,10 +41,17 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
$login = new CoreLibs\ACL\Login($db, $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);
|
$backend->db->dbInfo(true);
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS</title><head>";
|
print "<html><head><title>TEST CLASS</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
|
|
||||||
@@ -60,7 +67,7 @@ print '<div><a href="class_test.email.php">Class Test: EMAIL</a></div>';
|
|||||||
print '<div><a href="class_test.uids.php">Class Test: UIDS</a></div>';
|
print '<div><a href="class_test.uids.php">Class Test: UIDS</a></div>';
|
||||||
print '<div><a href="class_test.phpv.php">Class Test: PHP VERSION</a></div>';
|
print '<div><a href="class_test.phpv.php">Class Test: PHP VERSION</a></div>';
|
||||||
print '<div><a href="class_test.hash.php">Class Test: HASH</a></div>';
|
print '<div><a href="class_test.hash.php">Class Test: HASH</a></div>';
|
||||||
print '<div><a href="class_test.encoding.php">Class Test: ENCODING</a></div>';
|
print '<div><a href="class_test.encoding.php">Class Test: ENCODING (CHECK/CONVERT/MIME)</a></div>';
|
||||||
print '<div><a href="class_test.image.php">Class Test: IMAGE</a></div>';
|
print '<div><a href="class_test.image.php">Class Test: IMAGE</a></div>';
|
||||||
print '<div><a href="class_test.byte.php">Class Test: BYTE CONVERT</a></div>';
|
print '<div><a href="class_test.byte.php">Class Test: BYTE CONVERT</a></div>';
|
||||||
print '<div><a href="class_test.datetime.php">Class Test: DATE/TIME</a></div>';
|
print '<div><a href="class_test.datetime.php">Class Test: DATE/TIME</a></div>';
|
||||||
@@ -72,15 +79,16 @@ print '<div><a href="class_test.readenvfile.php">Class Test: READ ENV FILE</a></
|
|||||||
print '<div><a href="class_test.runningtime.php">Class Test: RUNNING TIME</a></div>';
|
print '<div><a href="class_test.runningtime.php">Class Test: RUNNING TIME</a></div>';
|
||||||
print '<div><a href="class_test.debug.php">Class Test: DEBUG</a></div>';
|
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.output.form.php">Class Test: OUTPUT FORM</a></div>';
|
||||||
print '<div><a href="class_test.backend.php">Class Test: BACKEND ADMIN CLASS</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.lang.php">Class Test: LANG/L10n</a></div>';
|
||||||
print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
|
print '<div><a href="class_test.smarty.php">Class Test: SMARTY</a></div>';
|
||||||
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
|
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
|
||||||
|
|
||||||
print "<hr>";
|
print "<hr>";
|
||||||
|
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
|
||||||
// print all _ENV vars set
|
// print all _ENV vars set
|
||||||
print "<div>READ _ENV ARRAY:</div>";
|
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
|
// set + check edit access id
|
||||||
$edit_access_id = 3;
|
$edit_access_id = 3;
|
||||||
if (is_object($login) && isset($login->acl['unit'])) {
|
if (is_object($login) && isset($login->acl['unit'])) {
|
||||||
@@ -145,9 +153,7 @@ print "BASE: " . BASE . "<br>";
|
|||||||
print "ROOT: " . ROOT . "<br>";
|
print "ROOT: " . ROOT . "<br>";
|
||||||
print "HOST: " . HOST_NAME . " => DB HOST: " . DB_CONFIG_NAME . " => " . print_r(DB_CONFIG, true) . "<br>";
|
print "HOST: " . HOST_NAME . " => DB HOST: " . DB_CONFIG_NAME . " => " . print_r(DB_CONFIG, true) . "<br>";
|
||||||
|
|
||||||
$ds = defined('DS') ? DS : DIRECTORY_SEPARATOR;
|
print "DS is: " . DIRECTORY_SEPARATOR . "<br>";
|
||||||
$du = DS ?? DIRECTORY_SEPARATOR;
|
|
||||||
print "DS is: " . $ds . "<br>";
|
|
||||||
print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "<br>";
|
print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "<br>";
|
||||||
|
|
||||||
// print error messages
|
// print error messages
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
|
|||||||
|
|
||||||
// define a list of from to color sets for conversion test
|
// define a list of from to color sets for conversion test
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: PHP VERSION</title><head>";
|
print "<html><head><title>TEST CLASS: PHP VERSION</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$array_class = 'CoreLibs\Create\RandomKey';
|
$array_class = 'CoreLibs\Create\RandomKey';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
|
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$ref_class = 'CoreLibs\Get\ReadEnvFile';
|
$ref_class = 'CoreLibs\Get\ReadEnvFile';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
|
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
|
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ ob_start();
|
|||||||
|
|
||||||
// basic class test file
|
// basic class test file
|
||||||
define('USE_DATABASE', true);
|
define('USE_DATABASE', true);
|
||||||
// set language
|
|
||||||
$lang = 'en_utf8';
|
|
||||||
// sample config
|
// sample config
|
||||||
require 'config.php';
|
require 'config.php';
|
||||||
// override ECHO ALL FALSE
|
// override ECHO ALL FALSE
|
||||||
@@ -43,9 +41,15 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
'echo_all' => $ECHO_ALL ?? false,
|
'echo_all' => $ECHO_ALL ?? false,
|
||||||
'print_all' => $PRINT_ALL ?? false,
|
'print_all' => $PRINT_ALL ?? false,
|
||||||
]);
|
]);
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||||
$l = new CoreLibs\Language\L10n($lang);
|
$l10n = new \CoreLibs\Language\L10n(
|
||||||
|
$locale['locale'],
|
||||||
|
$locale['domain'],
|
||||||
|
$locale['path'],
|
||||||
|
);
|
||||||
|
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
@@ -65,16 +69,26 @@ if ($smarty->USE_PROTOTYPE) {
|
|||||||
$smarty->JS_SPECIAL_TEMPLATE_NAME = 'jquery.test.js';
|
$smarty->JS_SPECIAL_TEMPLATE_NAME = 'jquery.test.js';
|
||||||
}
|
}
|
||||||
$smarty->PAGE_WIDTH = '100%';
|
$smarty->PAGE_WIDTH = '100%';
|
||||||
// require BASE.INCLUDES.'admin_set_paths.php';
|
|
||||||
$smarty->setSmartyPaths();
|
$smarty->setSmartyPaths();
|
||||||
|
|
||||||
// smarty test
|
// smarty test
|
||||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
$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_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
||||||
|
$smarty->DATA['replace'] = 'Replaced';
|
||||||
|
// variable variables
|
||||||
|
$smarty->DATA['test'] = 'foo';
|
||||||
|
$smarty->DATA['foo'] = 'bar';
|
||||||
|
// loop
|
||||||
|
$smarty->DATA['loop_start'] = 5;
|
||||||
// drop down test with optgroups
|
// drop down test with optgroups
|
||||||
$options = [
|
$smarty->DATA['drop_down_test'] = [
|
||||||
|
'foo' => 'Foo',
|
||||||
|
'bar' => 'Bar',
|
||||||
|
'foobar' => 'Foo Bar',
|
||||||
|
];
|
||||||
|
$smarty->DATA['drop_down_test_selected'] = 'bar';
|
||||||
|
$smarty->DATA['drop_down_test_nested'] = [
|
||||||
'' => '選択してください',
|
'' => '選択してください',
|
||||||
'4/25(木)' => [
|
'4/25(木)' => [
|
||||||
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
||||||
@@ -89,11 +103,26 @@ $options = [
|
|||||||
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
$smarty->DATA['drop_down_test_nested_selected'] = '';
|
||||||
|
$smarty->DATA['radio_test'] = [
|
||||||
|
'0' => 'On',
|
||||||
|
'1' => 'Off',
|
||||||
|
'-1' => 'Undefined'
|
||||||
|
];
|
||||||
|
$smarty->DATA['radio_test_selected'] = -1;
|
||||||
|
$smarty->DATA['checkbox_test'] = [
|
||||||
|
'0' => 'On',
|
||||||
|
'1' => 'Off',
|
||||||
|
'-1' => 'Undefined'
|
||||||
|
];
|
||||||
|
$smarty->DATA['checkbox_test_pos'] = [
|
||||||
|
'0' => 'A',
|
||||||
|
'1' => 'B'
|
||||||
|
];
|
||||||
|
$smarty->DATA['checkbox_test_selected'] = ['1', '-1'];
|
||||||
|
$smarty->DATA['checkbox_test_pos_selected'] = ['0', '-1'];
|
||||||
|
|
||||||
|
|
||||||
$smarty->DATA['drop_down_test'] = $options;
|
|
||||||
$smarty->DATA['drop_down_test_selected'] = '';
|
|
||||||
$smarty->DATA['loop_start'] = 2;
|
|
||||||
// require BASE.INCLUDES.'admin_smarty.php';
|
|
||||||
$smarty->setSmartyVarsAdmin();
|
$smarty->setSmartyVarsAdmin();
|
||||||
|
|
||||||
// error message
|
// error message
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
<?php // phpcs:ignore warning
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @phan-file-suppress PhanTypeSuspiciousStringExpression
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
$DEBUG_ALL_OVERRIDE = false; // set to 1 to debug on live/remote server locations
|
|
||||||
$DEBUG_ALL = true;
|
|
||||||
$PRINT_ALL = true;
|
|
||||||
$DB_DEBUG = true;
|
|
||||||
|
|
||||||
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', true);
|
|
||||||
// set language
|
|
||||||
$lang = 'en_utf8';
|
|
||||||
// sample config
|
|
||||||
require 'config.php';
|
|
||||||
// override ECHO ALL FALSE
|
|
||||||
$ECHO_ALL = true;
|
|
||||||
// set session name
|
|
||||||
if (!defined('SET_SESSION_NAME')) {
|
|
||||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
|
||||||
}
|
|
||||||
// define log file id
|
|
||||||
$LOG_FILE_ID = 'classTest-smarty';
|
|
||||||
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,
|
|
||||||
]);
|
|
||||||
$basic = new CoreLibs\Basic($log);
|
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend4();
|
|
||||||
$l = new CoreLibs\Language\L10n($lang);
|
|
||||||
|
|
||||||
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
|
|
||||||
print "<body>";
|
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
|
||||||
|
|
||||||
$smarty->DATA['JS_DEBUG'] = DEBUG;
|
|
||||||
$smarty->MASTER_TEMPLATE_NAME = 'main_body4.tpl';
|
|
||||||
$smarty->TEMPLATE_NAME = 'smarty_test4.tpl';
|
|
||||||
$smarty->CSS_SPECIAL_TEMPLATE_NAME = 'smart_test.css';
|
|
||||||
$smarty->USE_PROTOTYPE = false;
|
|
||||||
$smarty->USE_JQUERY = true;
|
|
||||||
$smarty->JS_DATEPICKR = false;
|
|
||||||
if ($smarty->USE_PROTOTYPE) {
|
|
||||||
$smarty->ADMIN_JAVASCRIPT = 'edit.pt.js';
|
|
||||||
$smarty->JS_SPECIAL_TEMPLATE_NAME = 'prototype.test.js';
|
|
||||||
} elseif ($smarty->USE_JQUERY) {
|
|
||||||
$smarty->ADMIN_JAVASCRIPT = 'edit.jq.js';
|
|
||||||
$smarty->JS_SPECIAL_TEMPLATE_NAME = 'jquery.test.js';
|
|
||||||
}
|
|
||||||
$smarty->PAGE_WIDTH = '100%';
|
|
||||||
// require BASE.INCLUDES.'admin_set_paths.php';
|
|
||||||
$smarty->setSmartyPaths();
|
|
||||||
|
|
||||||
// smarty test
|
|
||||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
|
||||||
$smarty->DATA['TRANSLATE_TEST'] = $l->__('Are we translated?');
|
|
||||||
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
|
|
||||||
|
|
||||||
// drop down test with optgroups
|
|
||||||
$options = [
|
|
||||||
'' => '選択してください',
|
|
||||||
'4/25(木)' => [
|
|
||||||
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
|
||||||
'4/25(木) 12:20-13:00' => '4/25(木) 12:20-13:00'
|
|
||||||
],
|
|
||||||
'4/26(金)' => [
|
|
||||||
'4/26(金) 11:00-11:50' => '4/26(金) 11:00-11:50',
|
|
||||||
'4/26(金) 12:20-13:00' => '4/26(金) 12:20-13:00'
|
|
||||||
],
|
|
||||||
'4/27(土)' => [
|
|
||||||
'4/27(土) 11:00-11:50' => '4/27(土) 11:00-11:50',
|
|
||||||
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$smarty->DATA['drop_down_test'] = $options;
|
|
||||||
$smarty->DATA['drop_down_test_selected'] = '';
|
|
||||||
$smarty->DATA['loop_start'] = 2;
|
|
||||||
// require BASE.INCLUDES.'admin_smarty.php';
|
|
||||||
$smarty->setSmartyVarsAdmin();
|
|
||||||
|
|
||||||
// error message
|
|
||||||
print $log->printErrorMsg();
|
|
||||||
|
|
||||||
print "</body></html>";
|
|
||||||
|
|
||||||
// __END__
|
|
||||||
@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
]);
|
]);
|
||||||
$basic = new CoreLibs\Basic($log);
|
$basic = new CoreLibs\Basic($log);
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
|
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
|
|||||||
$_token = new CoreLibs\Output\Form\Token();
|
$_token = new CoreLibs\Output\Form\Token();
|
||||||
$token_class = 'CoreLibs\Output\Form\Token';
|
$token_class = 'CoreLibs\Output\Form\Token';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
|
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ $_uids = new CoreLibs\Create\Uids();
|
|||||||
use CoreLibs\Create\Uids;
|
use CoreLibs\Create\Uids;
|
||||||
$uids_class = 'CoreLibs\Create\Uids';
|
$uids_class = 'CoreLibs\Create\Uids';
|
||||||
|
|
||||||
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>TEST CLASS: UIDS</title><head>";
|
print "<html><head><title>TEST CLASS: UIDS</title><head>";
|
||||||
print "<body>";
|
print "<body>";
|
||||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "gullevek/corelibs",
|
"name": "gullevek/corelibs-dev",
|
||||||
"description": "CoreLibs",
|
"version": "dev-master",
|
||||||
|
"description": "CoreLibs: Development package",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ $__LOCAL_CONFIG = [
|
|||||||
'db_host' => 'test',
|
'db_host' => 'test',
|
||||||
'location' => 'test',
|
'location' => 'test',
|
||||||
'debug_flag' => true,
|
'debug_flag' => true,
|
||||||
'site_lang' => 'en_utf8',
|
'site_locale' => 'en_US.UTF-8',
|
||||||
|
'site_encoding' => 'UTF-8',
|
||||||
'login_enabled' => true
|
'login_enabled' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -44,8 +45,10 @@ $SITE_CONFIG = [
|
|||||||
'location' => 'test',
|
'location' => 'test',
|
||||||
// show DEBUG override
|
// show DEBUG override
|
||||||
'debug_flag' => true,
|
'debug_flag' => true,
|
||||||
// site language
|
// site locale
|
||||||
'site_lang' => 'en_utf8',
|
'site_locale' => 'en_US.UTF-8',
|
||||||
|
// site encoding
|
||||||
|
'site_encoding' => 'UTF-8',
|
||||||
// enable/disable login override
|
// enable/disable login override
|
||||||
'login_enabled' => true
|
'login_enabled' => true
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -11,72 +11,72 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
/************* PATHS *********************/
|
/************* PATHS *********************/
|
||||||
// directory seperator
|
// [DEPRECATED] directory seperator
|
||||||
define('DS', DIRECTORY_SEPARATOR);
|
define('DS', DIRECTORY_SEPARATOR);
|
||||||
// ** NEW/BETTER DIR DECLARATIONS **
|
// ** NEW/BETTER DIR DECLARATIONS **
|
||||||
// path to original file (if symlink)
|
// path to original file (if symlink)
|
||||||
define('DIR', __DIR__ . DS);
|
define('DIR', __DIR__ . DIRECTORY_SEPARATOR);
|
||||||
// base dir root folder level
|
// base dir root folder level
|
||||||
define('BASE', str_replace('/configs', '', __DIR__) . DS);
|
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
// ** OLD DIR DECLARATIONS **
|
// ** OLD DIR DECLARATIONS **
|
||||||
// path to document root of file called
|
// path to document root of file called
|
||||||
define('ROOT', getcwd() . DS);
|
define('ROOT', getcwd() . DIRECTORY_SEPARATOR);
|
||||||
// libs path
|
// libs path
|
||||||
define('LIB', 'lib' . DS);
|
define('LIB', 'lib' . DIRECTORY_SEPARATOR);
|
||||||
define('LIBS', 'lib' . DS);
|
define('LIBS', 'lib' . DIRECTORY_SEPARATOR);
|
||||||
// configs folder
|
// configs folder
|
||||||
define('CONFIGS', 'configs' . DS);
|
define('CONFIGS', 'configs' . DIRECTORY_SEPARATOR);
|
||||||
// includes (strings, arrays for static, etc)
|
// includes (strings, arrays for static, etc)
|
||||||
define('INCLUDES', 'includes' . DS);
|
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
|
||||||
// data folder (mostly in includes, or root for internal data)
|
// data folder (mostly in includes, or root for internal data)
|
||||||
define('DATA', 'data' . DS);
|
define('DATA', 'data' . DIRECTORY_SEPARATOR);
|
||||||
// layout base path
|
// layout base path
|
||||||
define('LAYOUT', 'layout' . DS);
|
define('LAYOUT', 'layout' . DIRECTORY_SEPARATOR);
|
||||||
// pic-root (compatible to CMS)
|
// pic-root (compatible to CMS)
|
||||||
define('PICTURES', 'images' . DS);
|
define('PICTURES', 'images' . DIRECTORY_SEPARATOR);
|
||||||
// images
|
// images
|
||||||
define('IMAGES', 'images' . DS);
|
define('IMAGES', 'images' . DIRECTORY_SEPARATOR);
|
||||||
// icons (below the images/ folder)
|
// icons (below the images/ folder)
|
||||||
define('ICONS', 'icons' . DS);
|
define('ICONS', 'icons' . DIRECTORY_SEPARATOR);
|
||||||
// media (accessable from outside)
|
// media (accessable from outside)
|
||||||
define('MEDIA', 'media' . DS);
|
define('MEDIA', 'media' . DIRECTORY_SEPARATOR);
|
||||||
// uploads (anything to keep or data)
|
// uploads (anything to keep or data)
|
||||||
define('UPLOADS', 'uploads' . DS);
|
define('UPLOADS', 'uploads' . DIRECTORY_SEPARATOR);
|
||||||
// files (binaries) (below media or data)
|
// files (binaries) (below media or data)
|
||||||
define('BINARIES', 'binaries' . DS);
|
define('BINARIES', 'binaries' . DIRECTORY_SEPARATOR);
|
||||||
// files (videos) (below media or data)
|
// files (videos) (below media or data)
|
||||||
define('VIDEOS', 'videos' . DS);
|
define('VIDEOS', 'videos' . DIRECTORY_SEPARATOR);
|
||||||
// files (documents) (below media or data)
|
// files (documents) (below media or data)
|
||||||
define('DOCUMENTS', 'documents' . DS);
|
define('DOCUMENTS', 'documents' . DIRECTORY_SEPARATOR);
|
||||||
// files (pdfs) (below media or data)
|
// files (pdfs) (below media or data)
|
||||||
define('PDFS', 'documents' . DS);
|
define('PDFS', 'documents' . DIRECTORY_SEPARATOR);
|
||||||
// files (general) (below media or data)
|
// files (general) (below media or data)
|
||||||
define('FILES', 'files' . DS);
|
define('FILES', 'files' . DIRECTORY_SEPARATOR);
|
||||||
// CSV
|
// CSV
|
||||||
define('CSV', 'csv' . DS);
|
define('CSV', 'csv' . DIRECTORY_SEPARATOR);
|
||||||
// css
|
// css
|
||||||
define('CSS', 'css' . DS);
|
define('CSS', 'css' . DIRECTORY_SEPARATOR);
|
||||||
// font (web)
|
// font (web)
|
||||||
define('FONT', 'font' . DS);
|
define('FONT', 'font' . DIRECTORY_SEPARATOR);
|
||||||
// js
|
// js
|
||||||
define('JS', 'javascript' . DS);
|
define('JS', 'javascript' . DIRECTORY_SEPARATOR);
|
||||||
// table arrays
|
// table arrays
|
||||||
define('TABLE_ARRAYS', 'table_arrays' . DS);
|
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
|
||||||
// smarty libs path
|
// smarty libs path
|
||||||
define('SMARTY', 'Smarty' . DS);
|
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
|
||||||
// po langs
|
// po locale file
|
||||||
define('LANG', 'lang' . DS);
|
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
|
||||||
// cache path
|
// cache path
|
||||||
define('CACHE', 'cache' . DS);
|
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
|
||||||
// temp path
|
// temp path
|
||||||
define('TMP', 'tmp' . DS);
|
define('TMP', 'tmp' . DIRECTORY_SEPARATOR);
|
||||||
// log files
|
// log files
|
||||||
define('LOG', 'log' . DS);
|
define('LOG', 'log' . DIRECTORY_SEPARATOR);
|
||||||
// compiled template folder
|
// compiled template folder
|
||||||
define('TEMPLATES_C', 'templates_c' . DS);
|
define('TEMPLATES_C', 'templates_c' . DIRECTORY_SEPARATOR);
|
||||||
// template base
|
// template base
|
||||||
define('TEMPLATES', 'templates' . DS);
|
define('TEMPLATES', 'templates' . DIRECTORY_SEPARATOR);
|
||||||
|
|
||||||
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
|
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
|
||||||
// default hash type
|
// default hash type
|
||||||
@@ -158,7 +158,8 @@ define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
|||||||
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
define('COMPILE_ID', 'COMPILE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||||
|
|
||||||
/************* LANGUAGE / ENCODING *******/
|
/************* LANGUAGE / ENCODING *******/
|
||||||
define('DEFAULT_LANG', 'en_utf8');
|
// default lang + encoding
|
||||||
|
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||||
// default web page encoding setting
|
// default web page encoding setting
|
||||||
define('DEFAULT_ENCODING', 'UTF-8');
|
define('DEFAULT_ENCODING', 'UTF-8');
|
||||||
|
|
||||||
@@ -256,10 +257,12 @@ $GLOBALS['DB_CONFIG'] = DB_CONFIG;
|
|||||||
// where global tables are that are used by all schemas (eg queue tables for online, etc)
|
// where global tables are that are used by all schemas (eg queue tables for online, etc)
|
||||||
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
|
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
|
||||||
// debug settings, site lang, etc
|
// debug settings, site lang, etc
|
||||||
define('TARGET', $SITE_CONFIG[HOST_NAME]['location']);
|
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
|
||||||
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag']);
|
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
|
||||||
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang']);
|
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
|
||||||
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']);
|
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
|
// paths
|
||||||
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
|
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
|
||||||
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
|
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
|
||||||
@@ -274,8 +277,8 @@ define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
|||||||
/************ STYLE SHEETS / JS **********/
|
/************ STYLE SHEETS / JS **********/
|
||||||
define('ADMIN_STYLESHEET', 'edit.css');
|
define('ADMIN_STYLESHEET', 'edit.css');
|
||||||
define('ADMIN_JAVASCRIPT', 'edit.js');
|
define('ADMIN_JAVASCRIPT', 'edit.js');
|
||||||
define('STYLESHEET', 'frontend.css');
|
define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
|
||||||
define('JAVASCRIPT', 'frontend.js');
|
define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
|
||||||
|
|
||||||
// anything optional
|
// anything optional
|
||||||
/************* INTERNAL ******************/
|
/************* INTERNAL ******************/
|
||||||
|
|||||||
@@ -21,9 +21,12 @@ $paths = [
|
|||||||
];
|
];
|
||||||
// find convert
|
// find convert
|
||||||
foreach ($paths as $path) {
|
foreach ($paths as $path) {
|
||||||
if (file_exists($path . DS . 'convert') && is_file($path . DS . 'convert')) {
|
if (
|
||||||
|
file_exists($path . DIRECTORY_SEPARATOR . 'convert') &&
|
||||||
|
is_file($path . DIRECTORY_SEPARATOR . 'convert')
|
||||||
|
) {
|
||||||
// image magick convert location
|
// image magick convert location
|
||||||
define('CONVERT', $path . DS . 'convert');
|
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,16 +46,21 @@ for ($dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__)); $dir
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// fail if no base DS is not set
|
// fail if no base DIR is not set
|
||||||
if (!defined('DS')) {
|
if (!defined('DIR')) {
|
||||||
exit('Base config unloadable');
|
exit('Base config unloadable');
|
||||||
}
|
}
|
||||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||||
foreach (['admin', 'frontend'] as $folder) {
|
foreach (['admin', 'frontend'] as $folder) {
|
||||||
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
|
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
|
||||||
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
|
|
||||||
break;
|
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__
|
// __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__
|
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
* AUTHOR: Clemens Schwaighofer
|
* AUTHOR: Clemens Schwaighofer
|
||||||
* CREATED: 2008/08/01
|
* CREATED: 2008/08/01
|
||||||
* SHORT DESCRIPTION:
|
* SHORT DESCRIPTION:
|
||||||
* URL redirect header
|
|
||||||
* HISTORY:
|
* HISTORY:
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
@@ -73,10 +72,19 @@ if (
|
|||||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
// login & page access check
|
// login & page access check
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$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
|
// create smarty object
|
||||||
$smarty = new CoreLibs\Template\SmartyExtend();
|
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||||
// create new Backend class with db and loger attached
|
// 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)
|
// the menu show flag (what menu to show)
|
||||||
$cms->menu_show_flag = 'main';
|
$cms->menu_show_flag = 'main';
|
||||||
// db info
|
// 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);
|
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||||
// login page
|
// login page
|
||||||
$login = new CoreLibs\ACL\Login($db, $log);
|
$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
|
// flush and start
|
||||||
ob_end_flush();
|
ob_end_flush();
|
||||||
// turn off set log per class
|
// turn off set log per class
|
||||||
$log->setLogPer('class', false);
|
$log->setLogPer('class', false);
|
||||||
// create form class
|
// 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) {
|
if ($form->mobile_phone) {
|
||||||
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
echo "I am sorry, but this page cannot be viewed by a mobile phone";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
// smarty template engine (extended Translation version)
|
// 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));
|
// $form->log->debug('POST', $form->log->prAr($_POST));
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
www/includes/locale/en/LC_MESSAGES/admin.mo
Normal file
BIN
www/includes/locale/en/LC_MESSAGES/admin.mo
Normal file
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.
BIN
www/includes/locale/ja/LC_MESSAGES/admin.mo
Normal file
BIN
www/includes/locale/ja/LC_MESSAGES/admin.mo
Normal file
Binary file not shown.
BIN
www/includes/locale/ja/LC_MESSAGES/frontend.mo
Normal file
BIN
www/includes/locale/ja/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
@@ -33,26 +33,26 @@ function pop(theURL, winName, features) {
|
|||||||
<!-- ERROR MSG END //-->
|
<!-- ERROR MSG END //-->
|
||||||
<!-- TOP MENU START //-->
|
<!-- TOP MENU START //-->
|
||||||
<tr>
|
<tr>
|
||||||
<td width="{$table_width}" class="menu_bgcolor" valign="top">
|
<td width="{$table_width}" class="menu_bgcolor" valign="top">
|
||||||
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<tr>
|
<tr>
|
||||||
<td bgcolor="{$HEADER_COLOR}" class="normal">
|
<td bgcolor="{$HEADER_COLOR}" class="normal">
|
||||||
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$GROUP_LEVEL}</b>
|
Hello <b>{$USER_NAME|upper}</b> [{$EUID}] from the group <b>{$GROUP_NAME}</b> with Access Level <b>{$GROUP_LEVEL}</b>
|
||||||
</td>
|
</td>
|
||||||
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
|
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
|
||||||
<input type="submit" name="login_logout" value="Logout">
|
<input type="submit" name="login_logout" value="Logout">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</form>
|
</form>
|
||||||
</table>
|
</table>
|
||||||
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
||||||
<tr>
|
<tr>
|
||||||
{* foreach menu *}
|
{* foreach menu *}
|
||||||
{foreach from=$menu_data item=menu_element}
|
{foreach from=$menu_data item=menu_element}
|
||||||
{* if split factor is reached *}
|
{* if split factor is reached *}
|
||||||
{if $menu_element.splitfactor_in}
|
{if $menu_element.splitfactor_in}
|
||||||
<td class="menu_fgcolor" class="small" valign="top">
|
<td class="menu_fgcolor" class="small" valign="top">
|
||||||
{/if}
|
{/if}
|
||||||
{if $menu_element.position}
|
{if $menu_element.position}
|
||||||
<b><a href="{$menu_element.filename}">{$menu_element.pagename}</a></b><br>
|
<b><a href="{$menu_element.filename}">{$menu_element.pagename}</a></b><br>
|
||||||
@@ -67,22 +67,22 @@ function pop(theURL, winName, features) {
|
|||||||
</td>
|
</td>
|
||||||
{/if}
|
{/if}
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<table width="100%" border="0" cellpadding="10" cellspacing="1">
|
<table width="100%" border="0" cellpadding="10" cellspacing="1">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="edit_fgcolor_alt" class="headline" align="center">
|
<td class="edit_fgcolor_alt" class="headline" align="center">
|
||||||
{$page_name}
|
{$page_name}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- TOP MENU END //-->
|
<!-- TOP MENU END //-->
|
||||||
<tr>
|
<tr>
|
||||||
<td width="{$table_width}" class="edit_bgcolor">
|
<td width="{$table_width}" class="edit_bgcolor">
|
||||||
<form method="post" name="edit_form" style="margin-block-end: 0em;">
|
<form method="post" name="edit_form" style="margin-block-end: 0em;">
|
||||||
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
||||||
<!-- LOAD START //-->
|
<!-- LOAD START //-->
|
||||||
{include file="edit_load.tpl"}
|
{include file="edit_load.tpl"}
|
||||||
<!-- LOAD END //-->
|
<!-- LOAD END //-->
|
||||||
@@ -93,23 +93,23 @@ function pop(theURL, winName, features) {
|
|||||||
{if $form_yes}
|
{if $form_yes}
|
||||||
{include file="edit_save_delete.tpl"}
|
{include file="edit_save_delete.tpl"}
|
||||||
{if $form_my_page_name == "edit_pages" && $filename_exist}
|
{if $form_my_page_name == "edit_pages" && $filename_exist}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="edit_fgcolor" class="normal">
|
<td class="edit_fgcolor" class="normal">
|
||||||
Filename:
|
Filename:
|
||||||
</td>
|
</td>
|
||||||
<td class="edit_fgcolor" class="normal">
|
<td class="edit_fgcolor" class="normal">
|
||||||
{$filename}
|
{$filename}
|
||||||
<input type="hidden" name="filename" value="{$filename}">
|
<input type="hidden" name="filename" value="{$filename}">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
{include file="edit_elements.tpl"}
|
{include file="edit_elements.tpl"}
|
||||||
{include file="edit_hidden.tpl"}
|
{include file="edit_hidden.tpl"}
|
||||||
{include file="edit_save_delete.tpl"}
|
{include file="edit_save_delete.tpl"}
|
||||||
{/if}
|
{/if}
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -8,16 +8,16 @@
|
|||||||
********************************************************************
|
********************************************************************
|
||||||
*}
|
*}
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="edit_fgcolor_alt" class="normal">
|
<td class="edit_fgcolor_alt" class="normal">
|
||||||
{t}Create new media:{/t}
|
{t}Create new media:{/t}
|
||||||
</td>
|
</td>
|
||||||
<td class="edit_fgcolor_alt" class="normal">
|
<td class="edit_fgcolor_alt" class="normal">
|
||||||
{if $new.show_checkbox}
|
{if $new.show_checkbox}
|
||||||
<input type="checkbox" name="really_new" value="yes"> {t}really{/t}
|
<input type="checkbox" name="really_new" value="yes"> {t}really{/t}
|
||||||
{else}
|
{else}
|
||||||
<input type="hidden" name="really_new" value="yes">
|
<input type="hidden" name="really_new" value="yes">
|
||||||
{/if}
|
{/if}
|
||||||
<input type="submit" name="new" value="{$new.new_name}">
|
<input type="submit" name="new" value="{$new.new_name}">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<!-- ERROR MSG END //-->
|
<!-- ERROR MSG END //-->
|
||||||
<!-- BODY START //-->
|
<!-- BODY START //-->
|
||||||
<tr>
|
<tr>
|
||||||
<td class="edit_bgcolor">
|
<td class="edit_bgcolor">
|
||||||
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
<table width="100%" border="0" cellpadding="2" cellspacing="1">
|
||||||
<!-- ANFANG Neu //-->
|
<!-- ANFANG Neu //-->
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" enctype="multipart/form-data">
|
||||||
@@ -68,7 +68,7 @@
|
|||||||
</form>
|
</form>
|
||||||
<!-- ENDE FOOTER //-->
|
<!-- ENDE FOOTER //-->
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- BODY END //-->
|
<!-- BODY END //-->
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
<input type="submit" name="delete" value="{t}Delete{/t}">
|
<input type="submit" name="delete" value="{t}Delete{/t}">
|
||||||
{else}
|
{else}
|
||||||
<td class="edit_fgcolor_alt" class="normal">
|
<td class="edit_fgcolor_alt" class="normal">
|
||||||
|
|
||||||
{/if}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -1,16 +1,27 @@
|
|||||||
<div>
|
<div>
|
||||||
{$SMARTY_TEST}
|
SMARTY_TEST: {$SMARTY_TEST}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div {popup width="250" caption="Info" text="Text block<br>Control"} style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
|
||||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
|
POPUP HERE (hover mouse)
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
<b>Outside translation test</b><br>
|
||||||
|
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<select id="drop_down_test" name="drop_down_test">
|
<b>Translate Test with replace:</b><br>
|
||||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||||
</select>
|
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||||
|
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<b>Variable variables:</b><br>
|
||||||
|
Test: {$test}<br>
|
||||||
|
Foo: {$foo}<br>
|
||||||
|
{assign var="bar" value="test"}
|
||||||
|
vFoo ($test = $foo = bar): {$test|getvar}<br>
|
||||||
|
vFoo ($bar = $test = foo): {$bar|getvar}
|
||||||
</div>
|
</div>
|
||||||
<div class="jq-container">
|
<div class="jq-container">
|
||||||
<div id="jq-test" class="jp-test">
|
<div id="jq-test" class="jp-test">
|
||||||
@@ -23,11 +34,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="loop-test">
|
<div class="loop-test">
|
||||||
<div>LOOP TEST</div>
|
<div><b>LOOP TEST</b></div>
|
||||||
{section name=page_list start=1 loop=$loop_start+1}
|
{section name=page_list start=1 loop=$loop_start+1}
|
||||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||||
{/section}
|
{/section}
|
||||||
</div>
|
</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>
|
||||||
|
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
||||||
|
{html_options options=$drop_down_test_nested selected=$drop_down_test_nested_selected}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{html_radios name="radio_test" options=$radio_test selected=$radio_test_selected}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{html_checkboxes name="checkbox_test" options=$checkbox_test selected=$checkbox_test_selected}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{html_checkboxes name="checkbox_test_pos" options=$checkbox_test selected=$checkbox_test_pos_selected pos=$checkbox_test_pos}
|
||||||
|
</div>
|
||||||
{* progresss indicator *}
|
{* progresss indicator *}
|
||||||
<div id="indicator"></div>
|
<div id="indicator"></div>
|
||||||
{* the action confirm box *}
|
{* the action confirm box *}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -92,6 +92,8 @@ class Backend
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
public $lang_short;
|
public $lang_short;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
public $domain;
|
||||||
|
/** @var string */
|
||||||
public $encoding;
|
public $encoding;
|
||||||
/** @var \CoreLibs\Debug\Logging logger */
|
/** @var \CoreLibs\Debug\Logging logger */
|
||||||
public $log;
|
public $log;
|
||||||
@@ -112,15 +114,16 @@ class Backend
|
|||||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||||
/**
|
/**
|
||||||
* main class constructor
|
* main class constructor
|
||||||
* @param \CoreLibs\DB\IO $db Database connection class
|
* @param \CoreLibs\DB\IO $db Database connection class
|
||||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||||
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
|
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||||
* if null, auto set
|
* @param array<string,string> $locale locale data read from setLocale
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
\CoreLibs\DB\IO $db,
|
\CoreLibs\DB\IO $db,
|
||||||
\CoreLibs\Debug\Logging $log,
|
\CoreLibs\Debug\Logging $log,
|
||||||
?\CoreLibs\Language\L10n $l10n = null
|
\CoreLibs\Language\L10n $l10n,
|
||||||
|
array $locale
|
||||||
) {
|
) {
|
||||||
// set to log not per class
|
// set to log not per class
|
||||||
$log->setLogPer('class', false);
|
$log->setLogPer('class', false);
|
||||||
@@ -128,10 +131,15 @@ class Backend
|
|||||||
$this->log = $log;
|
$this->log = $log;
|
||||||
// attach db class
|
// attach db class
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
// TODO lang create outside of class
|
|
||||||
$this->setLangEncoding();
|
|
||||||
// get the language sub class & init it
|
// 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
|
// set the page name
|
||||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||||
@@ -157,43 +165,6 @@ class Backend
|
|||||||
// NO OP
|
// 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
|
|
||||||
{
|
|
||||||
// just emergency fallback for language
|
|
||||||
// set encoding
|
|
||||||
if (isset($_SESSION['DEFAULT_CHARSET'])) {
|
|
||||||
$this->encoding = $_SESSION['DEFAULT_CHARSET'];
|
|
||||||
} else {
|
|
||||||
$this->encoding = DEFAULT_ENCODING;
|
|
||||||
}
|
|
||||||
// gobal override
|
|
||||||
if (isset($GLOBALS['OVERRIDE_LANG'])) {
|
|
||||||
$this->lang = $GLOBALS['OVERRIDE_LANG'];
|
|
||||||
} elseif (isset($_SESSION['DEFAULT_LANG'])) {
|
|
||||||
// session (login)
|
|
||||||
$this->lang = $_SESSION['DEFAULT_LANG'];
|
|
||||||
} else {
|
|
||||||
// mostly default SITE LANG or DEFAULT LANG
|
|
||||||
$this->lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
|
||||||
}
|
|
||||||
// create the char lang encoding
|
|
||||||
$this->lang_short = substr($this->lang, 0, 2);
|
|
||||||
// set the language folder
|
|
||||||
$this->lang_dir = BASE . INCLUDES . LANG . CONTENT_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PUBLIC METHODS |=================================================>
|
// PUBLIC METHODS |=================================================>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -715,20 +715,20 @@ class Basic
|
|||||||
|
|
||||||
// *** ARRAY HANDLING END
|
// *** ARRAY HANDLING END
|
||||||
// [!!! DEPRECATED !!!]
|
// [!!! DEPRECATED !!!]
|
||||||
// Moved to \CoreLibs\Language\Encoding
|
// Moved to \CoreLibs\Convert\MimeEncode
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper function for mb mime convert, for correct conversion with long strings
|
* wrapper function for mb mime convert, for correct conversion with long strings
|
||||||
* @param string $string string to encode
|
* @param string $string string to encode
|
||||||
* @param string $encoding target encoding
|
* @param string $encoding target encoding
|
||||||
* @return string encoded string
|
* @return string encoded string
|
||||||
* @deprecated Use \CoreLibs\Language\Encoding::__mbMimeEncode() instead
|
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode() instead
|
||||||
*/
|
*/
|
||||||
public static function __mbMimeEncode(string $string, string $encoding): string
|
public static function __mbMimeEncode(string $string, string $encoding): string
|
||||||
{
|
{
|
||||||
|
|
||||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
|
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeEncode::__mbMimeEncode()', E_USER_DEPRECATED);
|
||||||
return \CoreLibs\Language\Encoding::__mbMimeEncode($string, $encoding);
|
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** HUMAND BYTE READABLE CONVERT
|
// *** HUMAND BYTE READABLE CONVERT
|
||||||
@@ -1009,7 +1009,7 @@ class Basic
|
|||||||
|
|
||||||
// *** ENCODING FUNCTIONS
|
// *** ENCODING FUNCTIONS
|
||||||
// [!!! DEPRECATED !!!]
|
// [!!! DEPRECATED !!!]
|
||||||
// Moved to \CoreLibs\Language\Encoding
|
// Moved to \CoreLibs\Check\Encoding and \CoreLibs\Convert\Encoding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
|
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
|
||||||
@@ -1026,12 +1026,12 @@ class Basic
|
|||||||
* @param string $from_encoding encoding of string to test
|
* @param string $from_encoding encoding of string to test
|
||||||
* @param string $to_encoding target encoding
|
* @param string $to_encoding target encoding
|
||||||
* @return bool|array<mixed> false if no error or array with failed characters
|
* @return bool|array<mixed> false if no error or array with failed characters
|
||||||
* @deprecated use \CoreLibs\Language\Encoding::checkConvertEncoding() instead
|
* @deprecated use \CoreLibs\Check\Encoding::checkConvertEncoding() instead
|
||||||
*/
|
*/
|
||||||
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
||||||
{
|
{
|
||||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
|
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
|
||||||
return \CoreLibs\Language\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1047,12 +1047,12 @@ class Basic
|
|||||||
* check that the source is actually matching
|
* check that the source is actually matching
|
||||||
* to what we sav the source is
|
* to what we sav the source is
|
||||||
* @return string encoding converted string
|
* @return string encoding converted string
|
||||||
* @deprecated use \CoreLibs\Language\Encoding::convertEncoding() instead
|
* @deprecated use \CoreLibs\Convert\Encoding::convertEncoding() instead
|
||||||
*/
|
*/
|
||||||
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
|
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
|
||||||
{
|
{
|
||||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
|
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Encoding::convertEncoding()', E_USER_DEPRECATED);
|
||||||
return \CoreLibs\Language\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
|
return \CoreLibs\Convert\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
|
||||||
}
|
}
|
||||||
|
|
||||||
// *** ENCODING FUNCTIONS END
|
// *** ENCODING FUNCTIONS END
|
||||||
|
|||||||
117
www/lib/CoreLibs/Check/Encoding.php
Normal file
117
www/lib/CoreLibs/Check/Encoding.php
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if string is valid in target encoding
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Check;
|
||||||
|
|
||||||
|
class Encoding
|
||||||
|
{
|
||||||
|
/** @var int<min, -1>|int<1, max>|string */
|
||||||
|
private static $mb_error_char = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set error char
|
||||||
|
*
|
||||||
|
* @param string|int|null $string The character to use to represent
|
||||||
|
* error chars
|
||||||
|
* "long" for long, "none" for none
|
||||||
|
* or a valid code point in int
|
||||||
|
* like 0x2234 (8756, ∴)
|
||||||
|
* default character is ? (63)
|
||||||
|
* if null is set then "none"
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function setErrorChar($string): void
|
||||||
|
{
|
||||||
|
if (empty($string)) {
|
||||||
|
$string = 'none';
|
||||||
|
}
|
||||||
|
// if not special string or char but code point
|
||||||
|
if (in_array($string, ['none', 'long', 'entity'])) {
|
||||||
|
self::$mb_error_char = $string;
|
||||||
|
} else {
|
||||||
|
// always convert to char for internal use
|
||||||
|
self::$mb_error_char = \IntlChar::chr($string);
|
||||||
|
// if string convert to code point
|
||||||
|
if (is_string($string)) {
|
||||||
|
$string = \IntlChar::ord($string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mb_substitute_character($string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the current set error character
|
||||||
|
*
|
||||||
|
* @param bool $return_substitute_func if set to true return the set
|
||||||
|
* character from the php function
|
||||||
|
* directly
|
||||||
|
* @return string|int Set error character
|
||||||
|
*/
|
||||||
|
public static function getErrorChar(bool $return_substitute_func = false)
|
||||||
|
{
|
||||||
|
// return mb_substitute_character();
|
||||||
|
if ($return_substitute_func === true) {
|
||||||
|
return mb_substitute_character();
|
||||||
|
} else {
|
||||||
|
return self::$mb_error_char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test if a string can be safely convert between encodings.
|
||||||
|
* mostly utf8 to shift jis
|
||||||
|
* the default compare has a possibility of failure, especially with windows
|
||||||
|
* it is recommended to the following in the script which uses this method:
|
||||||
|
* mb_substitute_character(0x2234);
|
||||||
|
* $class->mb_error_char = '∴';
|
||||||
|
* if check to Shift JIS
|
||||||
|
* if check to ISO-2022-JP
|
||||||
|
* if check to ISO-2022-JP-MS
|
||||||
|
* set three dots (∴) as wrong character for correct convert error detect
|
||||||
|
* (this char is used, because it is one of the least used ones)
|
||||||
|
*
|
||||||
|
* @param string $string string to test
|
||||||
|
* @param string $from_encoding encoding of string to test
|
||||||
|
* @param string $to_encoding target encoding
|
||||||
|
* @return bool|array<string> false if no error or
|
||||||
|
* array with failed characters
|
||||||
|
*/
|
||||||
|
public static function checkConvertEncoding(
|
||||||
|
string $string,
|
||||||
|
string $from_encoding,
|
||||||
|
string $to_encoding
|
||||||
|
) {
|
||||||
|
// convert to target encoding and convert back
|
||||||
|
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
||||||
|
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
||||||
|
// if string does not match anymore we have a convert problem
|
||||||
|
if ($string != $compare) {
|
||||||
|
$failed = [];
|
||||||
|
// go through each character and find the ones that do not match
|
||||||
|
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
|
||||||
|
$char = mb_substr($string, $i, 1, $from_encoding);
|
||||||
|
$r_char = mb_substr($compare, $i, 1, $from_encoding);
|
||||||
|
// the ord 194 is a hack to fix the IE7/IE8
|
||||||
|
// bug with line break and illegal character
|
||||||
|
if (
|
||||||
|
(($char != $r_char && (!self::$mb_error_char ||
|
||||||
|
in_array(self::$mb_error_char, ['none', 'long', 'entity']))) ||
|
||||||
|
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
|
||||||
|
ord($char) != 194
|
||||||
|
) {
|
||||||
|
$failed[] = $char;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $failed;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -66,7 +66,8 @@ class Colors
|
|||||||
}
|
}
|
||||||
$rgbArray = [];
|
$rgbArray = [];
|
||||||
if (strlen($hexStr) == 6) {
|
if (strlen($hexStr) == 6) {
|
||||||
// If a proper hex code, convert using bitwise operation. No overhead... faster
|
// If a proper hex code, convert using bitwise operation.
|
||||||
|
// No overhead... faster
|
||||||
$colorVal = hexdec($hexStr);
|
$colorVal = hexdec($hexStr);
|
||||||
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
|
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
|
||||||
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
|
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
|
||||||
@@ -135,13 +136,13 @@ class Colors
|
|||||||
* hsb2rgb does not clean convert back to hsb in a round trip
|
* hsb2rgb does not clean convert back to hsb in a round trip
|
||||||
* converts HSB/V to RGB values RGB is full INT
|
* converts HSB/V to RGB values RGB is full INT
|
||||||
* if HSB/V value is invalid, sets this value to 0
|
* if HSB/V value is invalid, sets this value to 0
|
||||||
* @param int $H hue 0-360 (int)
|
* @param float $H hue 0-360 (int)
|
||||||
* @param int $S saturation 0-100 (int)
|
* @param float $S saturation 0-100 (int)
|
||||||
* @param int $V brightness/value 0-100 (int)
|
* @param float $V brightness/value 0-100 (int)
|
||||||
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
|
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
|
||||||
* false for input value error
|
* false for input value error
|
||||||
*/
|
*/
|
||||||
public static function hsb2rgb(int $H, int $S, int $V)
|
public static function hsb2rgb(float $H, float $S, float $V)
|
||||||
{
|
{
|
||||||
// check that H is 0 to 359, 360 = 0
|
// check that H is 0 to 359, 360 = 0
|
||||||
// and S and V are 0 to 1
|
// and S and V are 0 to 1
|
||||||
@@ -270,12 +271,12 @@ class Colors
|
|||||||
/**
|
/**
|
||||||
* converts an HSL to RGB
|
* converts an HSL to RGB
|
||||||
* if HSL value is invalid, set this value to 0
|
* if HSL value is invalid, set this value to 0
|
||||||
* @param int|float $hue hue: 0-360 (degrees)
|
* @param float $hue hue: 0-360 (degrees)
|
||||||
* @param float $sat saturation: 0-100
|
* @param float $sat saturation: 0-100
|
||||||
* @param float $lum luminance: 0-100
|
* @param float $lum luminance: 0-100
|
||||||
* @return array<int,float|int>|bool red/blue/green 0-255 each
|
* @return array<int,float|int>|bool red/blue/green 0-255 each
|
||||||
*/
|
*/
|
||||||
public static function hsl2rgb($hue, float $sat, float $lum)
|
public static function hsl2rgb(float $hue, float $sat, float $lum)
|
||||||
{
|
{
|
||||||
if (!is_numeric($hue)) {
|
if (!is_numeric($hue)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -289,7 +290,8 @@ class Colors
|
|||||||
if ($lum < 0 || $lum > 100) {
|
if ($lum < 0 || $lum > 100) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$hue = (1 / 360) * $hue; // calc to internal convert value for hue
|
// calc to internal convert value for hue
|
||||||
|
$hue = (1 / 360) * $hue;
|
||||||
// convert to internal 0-1 format
|
// convert to internal 0-1 format
|
||||||
$sat /= 100;
|
$sat /= 100;
|
||||||
$lum /= 100;
|
$lum /= 100;
|
||||||
|
|||||||
60
www/lib/CoreLibs/Convert/Encoding.php
Normal file
60
www/lib/CoreLibs/Convert/Encoding.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* check if string is valid in target encoding
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class Encoding
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* detects the source encoding of the string and if doesn't match
|
||||||
|
* to the given target encoding it convert is
|
||||||
|
* if source encoding is set and auto check is true (default) a second
|
||||||
|
* check is done so that the source string encoding actually matches
|
||||||
|
* will be skipped if source encoding detection is ascii
|
||||||
|
*
|
||||||
|
* @param string $string string to convert
|
||||||
|
* @param string $to_encoding target encoding
|
||||||
|
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||||
|
* @param bool $auto_check default true, if source encoding is set
|
||||||
|
* check that the source is actually matching
|
||||||
|
* to what we sav the source is
|
||||||
|
* @return string encoding converted string
|
||||||
|
*/
|
||||||
|
public static function convertEncoding(
|
||||||
|
string $string,
|
||||||
|
string $to_encoding,
|
||||||
|
string $source_encoding = '',
|
||||||
|
bool $auto_check = true
|
||||||
|
): string {
|
||||||
|
// set if not given
|
||||||
|
if (!$source_encoding) {
|
||||||
|
$source_encoding = mb_detect_encoding($string);
|
||||||
|
} else {
|
||||||
|
$_source_encoding = mb_detect_encoding($string);
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
$auto_check === true &&
|
||||||
|
isset($_source_encoding) &&
|
||||||
|
$_source_encoding == $source_encoding
|
||||||
|
) {
|
||||||
|
// trigger check if we have override source encoding.
|
||||||
|
// if different (_source is all but not ascii) then trigger
|
||||||
|
// skip if matching
|
||||||
|
}
|
||||||
|
if ($source_encoding != $to_encoding) {
|
||||||
|
if ($source_encoding) {
|
||||||
|
$string = mb_convert_encoding($string, $to_encoding, $source_encoding);
|
||||||
|
} else {
|
||||||
|
$string = mb_convert_encoding($string, $to_encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
67
www/lib/CoreLibs/Convert/MimeEncode.php
Normal file
67
www/lib/CoreLibs/Convert/MimeEncode.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* alternate for header mime encode to void problems with long strings and
|
||||||
|
* spaces/strange encoding problems.
|
||||||
|
* Orignal issues during PHP5/7
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace CoreLibs\Convert;
|
||||||
|
|
||||||
|
class MimeEncode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* wrapper function for mb mime convert
|
||||||
|
* for correct conversion with long strings
|
||||||
|
*
|
||||||
|
* @param string $string string to encode
|
||||||
|
* @param string $encoding target encoding
|
||||||
|
* @param string $line_break default line break is \r\n
|
||||||
|
* @return string encoded string
|
||||||
|
*/
|
||||||
|
public static function __mbMimeEncode(
|
||||||
|
string $string,
|
||||||
|
string $encoding,
|
||||||
|
string $line_break = "\r\n"
|
||||||
|
): string {
|
||||||
|
// set internal encoding, so the mimeheader encode works correctly
|
||||||
|
mb_internal_encoding($encoding);
|
||||||
|
// if a subject, make a work around for the broken mb_mimencode
|
||||||
|
$pos = 0;
|
||||||
|
// after 36 single bytes characters,
|
||||||
|
// if then comes MB, it is broken
|
||||||
|
// has to 2 x 36 < 74 so the mb_encode_mimeheader
|
||||||
|
// 74 hardcoded split does not get triggered
|
||||||
|
$split = 36;
|
||||||
|
$_string = '';
|
||||||
|
while ($pos < mb_strlen($string, $encoding)) {
|
||||||
|
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
|
||||||
|
$pos += mb_strlen($output, $encoding);
|
||||||
|
// if the strinlen is 0 here, get out of the loop
|
||||||
|
if (!mb_strlen($output, $encoding)) {
|
||||||
|
$pos += mb_strlen($string, $encoding);
|
||||||
|
}
|
||||||
|
$_string_encoded = mb_encode_mimeheader($output, $encoding);
|
||||||
|
// only make linebreaks if we have mime encoded code inside
|
||||||
|
// the space only belongs in the second line
|
||||||
|
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
|
||||||
|
$_string .= $line_break . " ";
|
||||||
|
} elseif (
|
||||||
|
// hack for plain text with space at the end
|
||||||
|
mb_strlen($output, $encoding) == $split &&
|
||||||
|
mb_substr($output, -1, 1, $encoding) == " "
|
||||||
|
) {
|
||||||
|
// if output ends with space, add one more
|
||||||
|
$_string_encoded .= " ";
|
||||||
|
}
|
||||||
|
$_string .= $_string_encoded;
|
||||||
|
}
|
||||||
|
// strip out any spaces BEFORE a line break
|
||||||
|
$string = str_replace(" " . $line_break, $line_break, $_string);
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// __END__
|
||||||
@@ -382,7 +382,7 @@ class IO
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
array $db_config,
|
array $db_config,
|
||||||
?\CoreLibs\Debug\Logging $log = null,
|
?\CoreLibs\Debug\Logging $log = null,
|
||||||
?bool $db_debug_override = null,
|
?bool $db_debug_override = null
|
||||||
) {
|
) {
|
||||||
// attach logger
|
// attach logger
|
||||||
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
$this->log = $log ?? new \CoreLibs\Debug\Logging();
|
||||||
@@ -410,9 +410,6 @@ class IO
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
// set the target encoding to the DEFAULT_ENCODING if it is one of them: EUC, Shift_JIS, UTF-8
|
|
||||||
// @ the moment set only from outside
|
|
||||||
|
|
||||||
// set loop protection max count
|
// set loop protection max count
|
||||||
$this->MAX_QUERY_CALL = self::DEFAULT_MAX_QUERY_CALL;
|
$this->MAX_QUERY_CALL = self::DEFAULT_MAX_QUERY_CALL;
|
||||||
|
|
||||||
@@ -1786,9 +1783,12 @@ class IO
|
|||||||
// count the rows returned (if select)
|
// count the rows returned (if select)
|
||||||
$this->cursor_ext[$query_hash]['num_rows'] =
|
$this->cursor_ext[$query_hash]['num_rows'] =
|
||||||
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
|
$this->db_functions->__dbNumRows($this->cursor_ext[$query_hash]['cursor']);
|
||||||
|
// also set last return
|
||||||
|
$this->num_rows = $this->cursor_ext[$query_hash]['num_rows'];
|
||||||
// count the fields
|
// count the fields
|
||||||
$this->cursor_ext[$query_hash]['num_fields'] =
|
$this->cursor_ext[$query_hash]['num_fields'] =
|
||||||
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
|
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
|
||||||
|
$this->num_fields = $this->cursor_ext[$query_hash]['num_fields'];
|
||||||
// set field names
|
// set field names
|
||||||
$this->cursor_ext[$query_hash]['field_names'] = [];
|
$this->cursor_ext[$query_hash]['field_names'] = [];
|
||||||
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
|
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
|
||||||
@@ -1798,6 +1798,7 @@ class IO
|
|||||||
$i
|
$i
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
|
||||||
// reset first call vars
|
// reset first call vars
|
||||||
$this->cursor_ext[$query_hash]['firstcall'] = 0;
|
$this->cursor_ext[$query_hash]['firstcall'] = 0;
|
||||||
// reset the internal pos counter
|
// reset the internal pos counter
|
||||||
@@ -2870,7 +2871,7 @@ class IO
|
|||||||
*/
|
*/
|
||||||
public function dbGetInsertPKName(): string
|
public function dbGetInsertPKName(): string
|
||||||
{
|
{
|
||||||
return $this->insert_id_pk_name;
|
return (string)$this->insert_id_pk_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace CoreLibs\DB\SQL;
|
|||||||
// as main system. Currently all @var sets are written as object
|
// as main system. Currently all @var sets are written as object
|
||||||
/** @#phan-file-suppress PhanUndeclaredTypeProperty,PhanUndeclaredTypeParameter,PhanUndeclaredTypeReturnType */
|
/** @#phan-file-suppress PhanUndeclaredTypeProperty,PhanUndeclaredTypeParameter,PhanUndeclaredTypeReturnType */
|
||||||
|
|
||||||
class PgSQL implements Interface\SqlFunctions
|
class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
||||||
{
|
{
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $last_error_query;
|
private $last_error_query;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace CoreLibs\DB\SQL\Interface;
|
namespace CoreLibs\DB\SQL\SqlInterface;
|
||||||
|
|
||||||
interface SqlFunctions
|
interface SqlFunctions
|
||||||
{
|
{
|
||||||
@@ -39,7 +39,7 @@ class FileReader
|
|||||||
* file read constructor
|
* file read constructor
|
||||||
* @param string $filename file name to load
|
* @param string $filename file name to load
|
||||||
*/
|
*/
|
||||||
public function __construct($filename)
|
public function __construct(string $filename)
|
||||||
{
|
{
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
$this->fr_length = filesize($filename) ?: 0;
|
$this->fr_length = filesize($filename) ?: 0;
|
||||||
@@ -58,7 +58,7 @@ class FileReader
|
|||||||
* @param int $bytes how many bytes to read
|
* @param int $bytes how many bytes to read
|
||||||
* @return string read data as string
|
* @return string read data as string
|
||||||
*/
|
*/
|
||||||
public function read($bytes)
|
public function read(int $bytes): string
|
||||||
{
|
{
|
||||||
if (!$bytes || !is_resource($this->fr_fd)) {
|
if (!$bytes || !is_resource($this->fr_fd)) {
|
||||||
return '';
|
return '';
|
||||||
@@ -86,7 +86,7 @@ class FileReader
|
|||||||
* @param int $pos position where to go to
|
* @param int $pos position where to go to
|
||||||
* @return int file position after seek done
|
* @return int file position after seek done
|
||||||
*/
|
*/
|
||||||
public function seekto($pos)
|
public function seekto(int $pos): int
|
||||||
{
|
{
|
||||||
if (!is_resource($this->fr_fd)) {
|
if (!is_resource($this->fr_fd)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -100,7 +100,7 @@ class FileReader
|
|||||||
* get current position in file
|
* get current position in file
|
||||||
* @return int current position in bytes
|
* @return int current position in bytes
|
||||||
*/
|
*/
|
||||||
public function currentpos()
|
public function currentpos(): int
|
||||||
{
|
{
|
||||||
return $this->fr_pos;
|
return $this->fr_pos;
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ class FileReader
|
|||||||
* file length/size
|
* file length/size
|
||||||
* @return int file size in bytes
|
* @return int file size in bytes
|
||||||
*/
|
*/
|
||||||
public function length()
|
public function length(): int
|
||||||
{
|
{
|
||||||
return $this->fr_length;
|
return $this->fr_length;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,17 +67,15 @@ class GetTextReader
|
|||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
private $cache_translations = []; // original -> translation mapping
|
private $cache_translations = []; // original -> translation mapping
|
||||||
|
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a 32bit Integer from the Stream
|
* Reads a 32bit Integer from the Stream
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @return int Integer from the Stream
|
* @return int Integer from the Stream
|
||||||
*/
|
*/
|
||||||
private function readint()
|
private function readint(): int
|
||||||
{
|
{
|
||||||
if ($this->BYTEORDER == 0) {
|
if ($this->BYTEORDER == 0) {
|
||||||
// low endian
|
// low endian
|
||||||
@@ -91,10 +89,11 @@ class GetTextReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* read bytes
|
* read bytes
|
||||||
|
*
|
||||||
* @param int $bytes byte length to read
|
* @param int $bytes byte length to read
|
||||||
* @return string return data, possible string
|
* @return string return data, possible string
|
||||||
*/
|
*/
|
||||||
public function read($bytes)
|
public function read(int $bytes): string
|
||||||
{
|
{
|
||||||
return $this->STREAM->read($bytes);
|
return $this->STREAM->read($bytes);
|
||||||
}
|
}
|
||||||
@@ -105,7 +104,7 @@ class GetTextReader
|
|||||||
* @param int $count How many elements should be read
|
* @param int $count How many elements should be read
|
||||||
* @return array<mixed> Array of Integers
|
* @return array<mixed> Array of Integers
|
||||||
*/
|
*/
|
||||||
public function readintarray($count)
|
public function readintarray(int $count): array
|
||||||
{
|
{
|
||||||
if ($this->BYTEORDER == 0) {
|
if ($this->BYTEORDER == 0) {
|
||||||
// low endian
|
// low endian
|
||||||
@@ -120,9 +119,10 @@ class GetTextReader
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param FileReader|bool $Reader the StreamReader object
|
* @param FileReader|bool $Reader the StreamReader object
|
||||||
* @param bool $enable_cache Enable or disable caching of strings (default on)
|
* @param bool $enable_cache Enable or disable caching
|
||||||
|
* of strings (default on)
|
||||||
*/
|
*/
|
||||||
public function __construct($Reader, $enable_cache = true)
|
public function __construct($Reader, bool $enable_cache = true)
|
||||||
{
|
{
|
||||||
// If there isn't a StreamReader, turn on short circuit mode.
|
// If there isn't a StreamReader, turn on short circuit mode.
|
||||||
if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
|
if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
|
||||||
@@ -159,6 +159,26 @@ class GetTextReader
|
|||||||
$this->translations = $this->readint();
|
$this->translations = $this->readint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current short circuit, equals to no translator running
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getShortCircuit(): bool
|
||||||
|
{
|
||||||
|
return $this->short_circuit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the current cache enabled status
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getEnableCache(): bool
|
||||||
|
{
|
||||||
|
return $this->enable_cache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the translation tables from the MO file into the cache
|
* Loads the translation tables from the MO file into the cache
|
||||||
* If caching is enabled, also loads all strings into a cache
|
* If caching is enabled, also loads all strings into a cache
|
||||||
@@ -207,7 +227,7 @@ class GetTextReader
|
|||||||
* @param int $num Offset number of original string
|
* @param int $num Offset number of original string
|
||||||
* @return string Requested string if found, otherwise ''
|
* @return string Requested string if found, otherwise ''
|
||||||
*/
|
*/
|
||||||
private function getOriginalString($num)
|
private function getOriginalString(int $num): string
|
||||||
{
|
{
|
||||||
$length = $this->table_originals[$num * 2 + 1] ?? 0;
|
$length = $this->table_originals[$num * 2 + 1] ?? 0;
|
||||||
$offset = $this->table_originals[$num * 2 + 2] ?? 0;
|
$offset = $this->table_originals[$num * 2 + 2] ?? 0;
|
||||||
@@ -226,7 +246,7 @@ class GetTextReader
|
|||||||
* @param int $num Offset number of original string
|
* @param int $num Offset number of original string
|
||||||
* @return string Requested string if found, otherwise ''
|
* @return string Requested string if found, otherwise ''
|
||||||
*/
|
*/
|
||||||
private function getTranslationString($num)
|
private function getTranslationString(int $num): string
|
||||||
{
|
{
|
||||||
$length = $this->table_translations[$num * 2 + 1] ?? 0;
|
$length = $this->table_translations[$num * 2 + 1] ?? 0;
|
||||||
$offset = $this->table_translations[$num * 2 + 2] ?? 0;
|
$offset = $this->table_translations[$num * 2 + 2] ?? 0;
|
||||||
@@ -242,12 +262,12 @@ class GetTextReader
|
|||||||
* Binary search for string
|
* Binary search for string
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param string $string string to find
|
* @param string $string string to find
|
||||||
* @param int $start (internally used in recursive function)
|
* @param int $start (internally used in recursive function)
|
||||||
* @param int $end (internally used in recursive function)
|
* @param int $end (internally used in recursive function)
|
||||||
* @return int (offset in originals table)
|
* @return int (offset in originals table)
|
||||||
*/
|
*/
|
||||||
private function findString($string, $start = -1, $end = -1)
|
private function findString(string $string, int $start = -1, int $end = -1): int
|
||||||
{
|
{
|
||||||
if (($start == -1) or ($end == -1)) {
|
if (($start == -1) or ($end == -1)) {
|
||||||
// findString is called with only one parameter, set start end end
|
// findString is called with only one parameter, set start end end
|
||||||
@@ -289,7 +309,7 @@ class GetTextReader
|
|||||||
* @param string $string to be translated
|
* @param string $string to be translated
|
||||||
* @return string translated string (or original, if not found)
|
* @return string translated string (or original, if not found)
|
||||||
*/
|
*/
|
||||||
public function translate($string)
|
public function translate(string $string): string
|
||||||
{
|
{
|
||||||
if ($this->short_circuit) {
|
if ($this->short_circuit) {
|
||||||
return $string;
|
return $string;
|
||||||
@@ -298,7 +318,10 @@ class GetTextReader
|
|||||||
|
|
||||||
if ($this->enable_cache) {
|
if ($this->enable_cache) {
|
||||||
// Caching enabled, get translated string from cache
|
// Caching enabled, get translated string from cache
|
||||||
if (is_array($this->cache_translations) && array_key_exists($string, $this->cache_translations)) {
|
if (
|
||||||
|
is_array($this->cache_translations) &&
|
||||||
|
array_key_exists($string, $this->cache_translations)
|
||||||
|
) {
|
||||||
return $this->cache_translations[$string];
|
return $this->cache_translations[$string];
|
||||||
} else {
|
} else {
|
||||||
return $string;
|
return $string;
|
||||||
@@ -321,7 +344,7 @@ class GetTextReader
|
|||||||
* @param string $expr an expression to match
|
* @param string $expr an expression to match
|
||||||
* @return string sanitized plural form expression
|
* @return string sanitized plural form expression
|
||||||
*/
|
*/
|
||||||
private function sanitizePluralExpression($expr)
|
private function sanitizePluralExpression(string $expr): string
|
||||||
{
|
{
|
||||||
// Get rid of disallowed characters.
|
// Get rid of disallowed characters.
|
||||||
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
|
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
|
||||||
@@ -330,7 +353,8 @@ class GetTextReader
|
|||||||
$expr .= ';';
|
$expr .= ';';
|
||||||
$res = '';
|
$res = '';
|
||||||
$p = 0;
|
$p = 0;
|
||||||
for ($i = 0; $i < strlen($expr); $i++) {
|
$expr_len = strlen($expr);
|
||||||
|
for ($i = 0; $i < $expr_len; $i++) {
|
||||||
$ch = $expr[$i];
|
$ch = $expr[$i];
|
||||||
switch ($ch) {
|
switch ($ch) {
|
||||||
case '?':
|
case '?':
|
||||||
@@ -358,7 +382,7 @@ class GetTextReader
|
|||||||
* @param string $header header search in plurals
|
* @param string $header header search in plurals
|
||||||
* @return string verbatim plural form header field
|
* @return string verbatim plural form header field
|
||||||
*/
|
*/
|
||||||
private function extractPluralFormsHeaderFromPoHeader($header)
|
private function extractPluralFormsHeaderFromPoHeader(string $header): string
|
||||||
{
|
{
|
||||||
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
|
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
|
||||||
$expr = $regs[2];
|
$expr = $regs[2];
|
||||||
@@ -374,14 +398,14 @@ class GetTextReader
|
|||||||
* @access private
|
* @access private
|
||||||
* @return string plural form header
|
* @return string plural form header
|
||||||
*/
|
*/
|
||||||
private function getPluralForms()
|
private function getPluralForms(): string
|
||||||
{
|
{
|
||||||
// lets assume message number 0 is header
|
// lets assume message number 0 is header
|
||||||
// this is true, right?
|
// this is true, right?
|
||||||
$this->loadTables();
|
$this->loadTables();
|
||||||
|
|
||||||
// cache header field for plural forms
|
// cache header field for plural forms
|
||||||
if (! is_string($this->pluralheader)) {
|
if (empty($this->pluralheader) || !is_string($this->pluralheader)) {
|
||||||
if ($this->enable_cache) {
|
if ($this->enable_cache) {
|
||||||
$header = $this->cache_translations[''];
|
$header = $this->cache_translations[''];
|
||||||
} else {
|
} else {
|
||||||
@@ -397,25 +421,38 @@ class GetTextReader
|
|||||||
* Detects which plural form to take
|
* Detects which plural form to take
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param string $n count
|
* @param int $n count
|
||||||
* @return int array index of the right plural form
|
* @return int array index of the right plural form
|
||||||
*/
|
*/
|
||||||
private function selectString($n)
|
private function selectString(int $n): int
|
||||||
{
|
{
|
||||||
$string = $this->getPluralForms();
|
$string = $this->getPluralForms();
|
||||||
$string = str_replace('nplurals', "\$total", $string);
|
$string = str_replace('nplurals', "\$total", $string);
|
||||||
$string = str_replace("n", $n, $string);
|
$string = str_replace("n", (string)$n, $string);
|
||||||
$string = str_replace('plural', "\$plural", $string);
|
$string = str_replace('plural', "\$plural", $string);
|
||||||
|
|
||||||
$total = 0;
|
$total = 0;
|
||||||
$plural = 0;
|
$plural = 0;
|
||||||
|
|
||||||
|
// FIXME use Symfony\Component\ExpressionLanguage\ExpressionLanguage or similar
|
||||||
eval("$string");
|
eval("$string");
|
||||||
/** @phpstan-ignore-next-line */
|
/** @phpstan-ignore-next-line 0 >= 0 is always true*/
|
||||||
if ($plural >= $total) {
|
if ($plural >= $total) {
|
||||||
$plural = $total - 1;
|
$plural = $total - 1;
|
||||||
}
|
}
|
||||||
return $plural;
|
return (int)$plural;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wrapper for translate() method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @param string $string
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function gettext(string $string): string
|
||||||
|
{
|
||||||
|
return $this->translate($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -424,10 +461,10 @@ class GetTextReader
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string $single
|
* @param string $single
|
||||||
* @param string $plural
|
* @param string $plural
|
||||||
* @param string $number
|
* @param int $number
|
||||||
* @return string plural form
|
* @return string plural form
|
||||||
*/
|
*/
|
||||||
public function ngettext($single, $plural, $number)
|
public function ngettext(string $single, string $plural, int $number): string
|
||||||
{
|
{
|
||||||
if ($this->short_circuit) {
|
if ($this->short_circuit) {
|
||||||
if ($number != 1) {
|
if ($number != 1) {
|
||||||
@@ -465,11 +502,12 @@ class GetTextReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* p get text
|
* p get text
|
||||||
|
*
|
||||||
* @param string $context [description]
|
* @param string $context [description]
|
||||||
* @param string $msgid [description]
|
* @param string $msgid [description]
|
||||||
* @return string [description]
|
* @return string [description]
|
||||||
*/
|
*/
|
||||||
public function pgettext($context, $msgid)
|
public function pgettext(string $context, string $msgid): string
|
||||||
{
|
{
|
||||||
$key = $context . chr(4) . $msgid;
|
$key = $context . chr(4) . $msgid;
|
||||||
$ret = $this->translate($key);
|
$ret = $this->translate($key);
|
||||||
@@ -482,14 +520,19 @@ class GetTextReader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* np get text
|
* np get text
|
||||||
|
*
|
||||||
* @param string $context [description]
|
* @param string $context [description]
|
||||||
* @param string $singular [description]
|
* @param string $singular [description]
|
||||||
* @param string $plural [description]
|
* @param string $plural [description]
|
||||||
* @param string $number [description]
|
* @param int $number [description]
|
||||||
* @return string [description]
|
* @return string [description]
|
||||||
*/
|
*/
|
||||||
public function npgettext($context, $singular, $plural, $number)
|
public function npgettext(
|
||||||
{
|
string $context,
|
||||||
|
string $singular,
|
||||||
|
string $plural,
|
||||||
|
int $number
|
||||||
|
): string {
|
||||||
$key = $context . chr(4) . $singular;
|
$key = $context . chr(4) . $singular;
|
||||||
$ret = $this->ngettext($key, $plural, $number);
|
$ret = $this->ngettext($key, $plural, $number);
|
||||||
if (strpos($ret, "\004") !== false) {
|
if (strpos($ret, "\004") !== false) {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class StreamReader
|
|||||||
* @param int $bytes bytes to read
|
* @param int $bytes bytes to read
|
||||||
* @return bool dummy false
|
* @return bool dummy false
|
||||||
*/
|
*/
|
||||||
public function read($bytes)
|
public function read(int $bytes): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ class StreamReader
|
|||||||
* @param int $position seek to position
|
* @param int $position seek to position
|
||||||
* @return bool dummy false
|
* @return bool dummy false
|
||||||
*/
|
*/
|
||||||
public function seekto($position)
|
public function seekto(int $position): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ class StreamReader
|
|||||||
* returns current position
|
* returns current position
|
||||||
* @return bool dummy false
|
* @return bool dummy false
|
||||||
*/
|
*/
|
||||||
public function currentpos()
|
public function currentpos(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@ class StreamReader
|
|||||||
* returns length of entire stream (limit for seekto()s)
|
* returns length of entire stream (limit for seekto()s)
|
||||||
* @return bool dummy false
|
* @return bool dummy false
|
||||||
*/
|
*/
|
||||||
public function length()
|
public function length(): bool
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class StringReader
|
|||||||
* constructor for string reader
|
* constructor for string reader
|
||||||
* @param string $str basic string
|
* @param string $str basic string
|
||||||
*/
|
*/
|
||||||
public function __construct($str = '')
|
public function __construct(string $str = '')
|
||||||
{
|
{
|
||||||
$this->sr_str = $str;
|
$this->sr_str = $str;
|
||||||
$this->sr_pos = 0;
|
$this->sr_pos = 0;
|
||||||
@@ -46,7 +46,7 @@ class StringReader
|
|||||||
* @param int $bytes bytes to read in string
|
* @param int $bytes bytes to read in string
|
||||||
* @return string data read in length of bytes as string
|
* @return string data read in length of bytes as string
|
||||||
*/
|
*/
|
||||||
public function read($bytes)
|
public function read(int $bytes): string
|
||||||
{
|
{
|
||||||
$data = substr($this->sr_str, $this->sr_pos, $bytes);
|
$data = substr($this->sr_str, $this->sr_pos, $bytes);
|
||||||
$this->sr_pos += $bytes;
|
$this->sr_pos += $bytes;
|
||||||
@@ -62,7 +62,7 @@ class StringReader
|
|||||||
* @param int $pos position in string
|
* @param int $pos position in string
|
||||||
* @return int new position in string after seek
|
* @return int new position in string after seek
|
||||||
*/
|
*/
|
||||||
public function seekto($pos)
|
public function seekto(int $pos): int
|
||||||
{
|
{
|
||||||
$this->sr_pos = $pos;
|
$this->sr_pos = $pos;
|
||||||
if (strlen($this->sr_str) < $this->sr_pos) {
|
if (strlen($this->sr_str) < $this->sr_pos) {
|
||||||
@@ -75,7 +75,7 @@ class StringReader
|
|||||||
* get current position in string
|
* get current position in string
|
||||||
* @return int position in string
|
* @return int position in string
|
||||||
*/
|
*/
|
||||||
public function currentpos()
|
public function currentpos(): int
|
||||||
{
|
{
|
||||||
return $this->sr_pos;
|
return $this->sr_pos;
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ class StringReader
|
|||||||
* get length of string
|
* get length of string
|
||||||
* @return int return length of assigned string
|
* @return int return length of assigned string
|
||||||
*/
|
*/
|
||||||
public function length()
|
public function length(): int
|
||||||
{
|
{
|
||||||
return strlen($this->sr_str);
|
return strlen($this->sr_str);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* hash wrapper functions for old problem fixes
|
* deprecated function calls
|
||||||
|
* 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::convertEncoding -> Convert\Encoding::convertEncoding
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -10,67 +15,59 @@ namespace CoreLibs\Language;
|
|||||||
|
|
||||||
class Encoding
|
class Encoding
|
||||||
{
|
{
|
||||||
/** @var string */
|
|
||||||
private static $mb_error_char = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wrapper function for mb mime convert, for correct conversion with long strings
|
* wrapper function for mb mime convert
|
||||||
* @param string $string string to encode
|
* for correct conversion with long strings
|
||||||
* @param string $encoding target encoding
|
*
|
||||||
* @return string encoded string
|
* @param string $string string to encode
|
||||||
|
* @param string $encoding target encoding
|
||||||
|
* @param string $line_break default line break is \r\n
|
||||||
|
* @return string encoded string
|
||||||
|
* @deprecated Use \CoreLibs\Convert\MimeEncode::__mbMimeEncode();
|
||||||
*/
|
*/
|
||||||
public static function __mbMimeEncode(string $string, string $encoding): string
|
public static function __mbMimeEncode(
|
||||||
{
|
string $string,
|
||||||
// set internal encoding, so the mimeheader encode works correctly
|
string $encoding,
|
||||||
mb_internal_encoding($encoding);
|
string $line_break = "\r\n"
|
||||||
// if a subject, make a work around for the broken mb_mimencode
|
): string {
|
||||||
$pos = 0;
|
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding, $line_break);
|
||||||
$split = 36; // after 36 single bytes characters, if then comes MB, it is broken
|
|
||||||
// has to 2 x 36 < 74 so the mb_encode_mimeheader 74 hardcoded split does not get triggered
|
|
||||||
$_string = '';
|
|
||||||
while ($pos < mb_strlen($string, $encoding)) {
|
|
||||||
$output = mb_strimwidth($string, $pos, $split, "", $encoding);
|
|
||||||
$pos += mb_strlen($output, $encoding);
|
|
||||||
// if the strinlen is 0 here, get out of the loop
|
|
||||||
if (!mb_strlen($output, $encoding)) {
|
|
||||||
$pos += mb_strlen($string, $encoding);
|
|
||||||
}
|
|
||||||
$_string_encoded = mb_encode_mimeheader($output, $encoding);
|
|
||||||
// only make linebreaks if we have mime encoded code inside
|
|
||||||
// the space only belongs in the second line
|
|
||||||
if ($_string && preg_match("/^=\?/", $_string_encoded)) {
|
|
||||||
$_string .= "\n ";
|
|
||||||
}
|
|
||||||
$_string .= $_string_encoded;
|
|
||||||
}
|
|
||||||
// strip out any spaces BEFORE a line break
|
|
||||||
$string = str_replace(" \n", "\n", $_string);
|
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set error char
|
* set error char
|
||||||
*
|
*
|
||||||
* @param string $string The character to use to represent error chars
|
* @param string|int|null $string The character to use to represent
|
||||||
|
* error chars
|
||||||
|
* "long" for long, "none" for none
|
||||||
|
* or a valid code point in int
|
||||||
|
* like 0x2234 (8756, ∴)
|
||||||
|
* default character is ? (63)
|
||||||
|
* if null is set then "none"
|
||||||
* @return void
|
* @return void
|
||||||
|
* @deprecated Use \CoreLibs\Check\Encoding::setErrorChar();
|
||||||
*/
|
*/
|
||||||
public static function setErrorChar(string $string): void
|
public static function setErrorChar($string): void
|
||||||
{
|
{
|
||||||
self::$mb_error_char = $string;
|
\CoreLibs\Check\Encoding::setErrorChar($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the current set error character
|
* get the current set error character
|
||||||
*
|
*
|
||||||
* @return string Set error character
|
* @param bool $return_substitute_func if set to true return the set
|
||||||
|
* character from the php function
|
||||||
|
* directly
|
||||||
|
* @return string|int Set error character
|
||||||
|
* @deprecated Use \CoreLibs\Check\Encoding::getErrorChar();
|
||||||
*/
|
*/
|
||||||
public static function getErrorChar(): string
|
public static function getErrorChar(bool $return_substitute_func = false)
|
||||||
{
|
{
|
||||||
return self::$mb_error_char;
|
return \CoreLibs\Check\Encoding::getErrorChar($return_substitute_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test if a string can be safely convert between encodings. mostly utf8 to shift jis
|
* test if a string can be safely convert between encodings.
|
||||||
|
* mostly utf8 to shift jis
|
||||||
* the default compare has a possibility of failure, especially with windows
|
* the default compare has a possibility of failure, especially with windows
|
||||||
* it is recommended to the following in the script which uses this method:
|
* it is recommended to the following in the script which uses this method:
|
||||||
* mb_substitute_character(0x2234);
|
* mb_substitute_character(0x2234);
|
||||||
@@ -80,36 +77,20 @@ class Encoding
|
|||||||
* if check to ISO-2022-JP-MS
|
* if check to ISO-2022-JP-MS
|
||||||
* set three dots (∴) as wrong character for correct convert error detect
|
* set three dots (∴) as wrong character for correct convert error detect
|
||||||
* (this char is used, because it is one of the least used ones)
|
* (this char is used, because it is one of the least used ones)
|
||||||
|
*
|
||||||
* @param string $string string to test
|
* @param string $string string to test
|
||||||
* @param string $from_encoding encoding of string to test
|
* @param string $from_encoding encoding of string to test
|
||||||
* @param string $to_encoding target encoding
|
* @param string $to_encoding target encoding
|
||||||
* @return bool|array<string> false if no error or array with failed characters
|
* @return bool|array<string> false if no error or
|
||||||
|
* array with failed characters
|
||||||
|
* @deprecated Use \CoreLibs\Check\Encoding::checkConvertEncoding();
|
||||||
*/
|
*/
|
||||||
public static function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
public static function checkConvertEncoding(
|
||||||
{
|
string $string,
|
||||||
// convert to target encoding and convert back
|
string $from_encoding,
|
||||||
$temp = mb_convert_encoding($string, $to_encoding, $from_encoding);
|
string $to_encoding
|
||||||
$compare = mb_convert_encoding($temp, $from_encoding, $to_encoding);
|
) {
|
||||||
// if string does not match anymore we have a convert problem
|
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
|
||||||
if ($string != $compare) {
|
|
||||||
$failed = [];
|
|
||||||
// go through each character and find the ones that do not match
|
|
||||||
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
|
|
||||||
$char = mb_substr($string, $i, 1, $from_encoding);
|
|
||||||
$r_char = mb_substr($compare, $i, 1, $from_encoding);
|
|
||||||
// the ord 194 is a hack to fix the IE7/IE8 bug with line break and illegal character
|
|
||||||
if (
|
|
||||||
(($char != $r_char && !self::$mb_error_char) ||
|
|
||||||
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
|
|
||||||
ord($char) != 194
|
|
||||||
) {
|
|
||||||
$failed[] = $char;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $failed;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -118,6 +99,7 @@ class Encoding
|
|||||||
* if source encoding is set and auto check is true (default) a second
|
* if source encoding is set and auto check is true (default) a second
|
||||||
* check is done so that the source string encoding actually matches
|
* check is done so that the source string encoding actually matches
|
||||||
* will be skipped if source encoding detection is ascii
|
* will be skipped if source encoding detection is ascii
|
||||||
|
*
|
||||||
* @param string $string string to convert
|
* @param string $string string to convert
|
||||||
* @param string $to_encoding target encoding
|
* @param string $to_encoding target encoding
|
||||||
* @param string $source_encoding optional source encoding, will try to auto detect
|
* @param string $source_encoding optional source encoding, will try to auto detect
|
||||||
@@ -125,6 +107,7 @@ class Encoding
|
|||||||
* check that the source is actually matching
|
* check that the source is actually matching
|
||||||
* to what we sav the source is
|
* to what we sav the source is
|
||||||
* @return string encoding converted string
|
* @return string encoding converted string
|
||||||
|
* @deprecated Use \CoreLibs\Convert\Encoding::convertEncoding();
|
||||||
*/
|
*/
|
||||||
public static function convertEncoding(
|
public static function convertEncoding(
|
||||||
string $string,
|
string $string,
|
||||||
@@ -132,28 +115,12 @@ class Encoding
|
|||||||
string $source_encoding = '',
|
string $source_encoding = '',
|
||||||
bool $auto_check = true
|
bool $auto_check = true
|
||||||
): string {
|
): string {
|
||||||
// set if not given
|
return \CoreLibs\Convert\Encoding::convertEncoding(
|
||||||
if (!$source_encoding) {
|
$string,
|
||||||
$source_encoding = mb_detect_encoding($string);
|
$to_encoding,
|
||||||
} else {
|
$source_encoding,
|
||||||
$_source_encoding = mb_detect_encoding($string);
|
$auto_check
|
||||||
}
|
);
|
||||||
if (
|
|
||||||
$auto_check === true &&
|
|
||||||
isset($_source_encoding) &&
|
|
||||||
$_source_encoding == $source_encoding
|
|
||||||
) {
|
|
||||||
// trigger check if we have override source encoding.
|
|
||||||
// if different (_source is all but not ascii) then trigger skip if matching
|
|
||||||
}
|
|
||||||
if ($source_encoding != $to_encoding) {
|
|
||||||
if ($source_encoding) {
|
|
||||||
$string = mb_convert_encoding($string, $to_encoding, $source_encoding);
|
|
||||||
} else {
|
|
||||||
$string = mb_convert_encoding($string, $to_encoding);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $string;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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__
|
||||||
@@ -3,24 +3,23 @@
|
|||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* AUTHOR: Clemens Schwaighofer
|
* AUTHOR: Clemens Schwaighofer
|
||||||
* CREATED: 2004/11/18
|
* CREATED: 2004/11/18
|
||||||
* VERSION: 1.0.0
|
* VERSION: 3.0.0
|
||||||
* RELEASED LICENSE: GNU GPL 3
|
* RELEASED LICENSE: GNU GPL 3
|
||||||
* SHORT DESCRIPTION:
|
* 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
|
* I changed that to a class to be more portable with my style of coding
|
||||||
*
|
* VERSION 3.0 (2022/4) removes all old folder layout and uses standard gettext
|
||||||
* PUBLIC VARIABLES
|
|
||||||
*
|
|
||||||
* PRIVATE VARIABLES
|
|
||||||
*
|
|
||||||
* PUBLIC METHODS
|
* PUBLIC METHODS
|
||||||
* __: returns string (translated or original if not found)
|
* __ : returns string (translated or original if not found)
|
||||||
* __e: echos out string (translated or original if not found)
|
* __n : plural string
|
||||||
* __ngettext: should return plural. never tested this.
|
* __p : string with context
|
||||||
*
|
* __pb: string with context and plural
|
||||||
* PRIVATE METHODS
|
|
||||||
*
|
*
|
||||||
* HISTORY:
|
* 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)
|
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
|
||||||
*********************************************************************/
|
*********************************************************************/
|
||||||
|
|
||||||
@@ -33,86 +32,516 @@ use CoreLibs\Language\Core\GetTextReader;
|
|||||||
|
|
||||||
class L10n
|
class L10n
|
||||||
{
|
{
|
||||||
/** @var string */
|
/** @var string the current locale */
|
||||||
private $lang = '';
|
private $locale = '';
|
||||||
/** @var string */
|
/** @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 = '';
|
private $mofile = '';
|
||||||
/** @var FileReader|bool */
|
/** @var string base path to search level */
|
||||||
private $input;
|
private $base_locale_path = '';
|
||||||
/** @var GetTextReader */
|
/** @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 */
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
/**
|
||||||
|
* @static
|
||||||
|
* @var L10n self class
|
||||||
|
*/
|
||||||
|
private static $instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class constructor call for language getstring
|
* class constructor call for language getstring
|
||||||
* @param string $lang language name (optional), fallback is en
|
* if locale is not empty will load translation
|
||||||
* @param string $path path, if empty fallback on default internal path
|
* else getTranslator needs to be called
|
||||||
|
*
|
||||||
|
* @param string $locale language name, default empty string
|
||||||
|
* will return self instance
|
||||||
|
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||||
|
* @param string $path path, if empty fallback on default internal path
|
||||||
*/
|
*/
|
||||||
public function __construct(string $lang = '', string $path = '')
|
public function __construct(
|
||||||
{
|
string $locale = '',
|
||||||
if (!$lang) {
|
string $domain = '',
|
||||||
$this->lang = 'en';
|
string $path = '',
|
||||||
} else {
|
) {
|
||||||
$this->lang = $lang;
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// override path check
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->mofile = $path . $this->lang . ".mo";
|
|
||||||
|
|
||||||
// check if get a readable mofile
|
|
||||||
if (is_readable($this->mofile)) {
|
|
||||||
$this->input = new FileReader($this->mofile);
|
|
||||||
} else {
|
|
||||||
$this->input = false;
|
|
||||||
}
|
|
||||||
$this->l10n = new GetTextReader($this->input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reloads the mofile, if the location of the lang file changes
|
* Returns the singleton L10n object.
|
||||||
* @param string $lang language to reload data
|
* For function wrapper use
|
||||||
* @param string $path optional path, if not set fallback on internal
|
*
|
||||||
* @return bool successfull reload true/false
|
* @return L10n object
|
||||||
*/
|
*/
|
||||||
public function l10nReloadMOfile(string $lang, string $path = ''): bool
|
public static function getInstance(): L10n
|
||||||
{
|
{
|
||||||
$success = false;
|
/** @phpstan-ignore-next-line */
|
||||||
$old_mofile = $this->mofile;
|
if (empty(self::$instance)) {
|
||||||
$old_lang = $this->lang;
|
self::$instance = new self();
|
||||||
|
|
||||||
$this->lang = $lang;
|
|
||||||
|
|
||||||
// override path check
|
|
||||||
if (!is_dir($path)) {
|
|
||||||
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
|
|
||||||
}
|
}
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
$this->mofile = $path . $this->lang . ".mo";
|
/**
|
||||||
|
* Loads global localization functions.
|
||||||
|
* prefixed with double underscore
|
||||||
|
* eg: gettext -> __gettext
|
||||||
|
*/
|
||||||
|
public static function loadFunctions(): void
|
||||||
|
{
|
||||||
|
require_once __DIR__ . '/l10n_functions.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loads the mo file base on path, locale and domain set
|
||||||
|
*
|
||||||
|
* @param string $locale language name (optional), fallback is en
|
||||||
|
* @param string $domain override CONTENT_PATH . $encoding name for mo file
|
||||||
|
* @param string $path path, if empty fallback on default internal path
|
||||||
|
* @return GetTextReader the main gettext reader object
|
||||||
|
*/
|
||||||
|
public function getTranslator(
|
||||||
|
string $locale = '',
|
||||||
|
string $domain = '',
|
||||||
|
string $path = ''
|
||||||
|
): GetTextReader {
|
||||||
|
// set local if not from parameter
|
||||||
|
if (empty($locale)) {
|
||||||
|
$locale = $this->locale;
|
||||||
|
}
|
||||||
|
// set domain if not given
|
||||||
|
if (empty($domain)) {
|
||||||
|
$domain = $this->domain;
|
||||||
|
}
|
||||||
|
// store old settings
|
||||||
|
$old_mofile = $this->mofile;
|
||||||
|
$old_lang = $this->locale;
|
||||||
|
$old_domain = $this->domain;
|
||||||
|
$old_base_locale_path = $this->base_locale_path;
|
||||||
|
$old_base_content_path = $this->base_content_path;
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if get a readable mofile
|
// check if get a readable mofile
|
||||||
if (is_readable($this->mofile)) {
|
if (is_readable($this->mofile)) {
|
||||||
|
// locale and domain current wanted
|
||||||
|
$this->locale = $locale;
|
||||||
|
$this->domain = $domain;
|
||||||
|
// set empty domains path with current locale
|
||||||
|
if (empty($this->domains[$locale])) {
|
||||||
|
$this->domains[$locale] = [];
|
||||||
|
}
|
||||||
|
// store current base path (without locale, etc)
|
||||||
|
if (empty($this->paths[$domain])) {
|
||||||
|
$this->paths[$domain] = $this->base_locale_path;
|
||||||
|
}
|
||||||
|
// file reader and mo reader
|
||||||
$this->input = new FileReader($this->mofile);
|
$this->input = new FileReader($this->mofile);
|
||||||
$this->l10n = new GetTextReader($this->input);
|
$this->l10n = new GetTextReader($this->input);
|
||||||
// we successfully loaded
|
// if short circuit is true, we failed to have a translator loaded
|
||||||
$success = true;
|
$this->load_failure = $this->l10n->getShortCircuit();
|
||||||
} else {
|
// below is not used at the moment, but can be to avoid reloading
|
||||||
|
$this->domains[$this->locale][$domain] = $this->l10n;
|
||||||
|
} elseif (!empty($old_mofile)) {
|
||||||
|
// mo file not readable
|
||||||
|
$this->load_failure = true;
|
||||||
// else fall back to the old ones
|
// else fall back to the old ones
|
||||||
$this->mofile = $old_mofile;
|
$this->mofile = $old_mofile;
|
||||||
$this->lang = $old_lang;
|
$this->locale = $old_lang;
|
||||||
|
$this->domain = $old_domain;
|
||||||
|
$this->base_locale_path = $old_base_locale_path;
|
||||||
|
$this->base_content_path = $old_base_content_path;
|
||||||
|
} else {
|
||||||
|
// mo file not readable, no previous mo file set, set short circuit
|
||||||
|
$this->load_failure = true;
|
||||||
|
// dummy
|
||||||
|
$this->l10n = new GetTextReader($this->input);
|
||||||
}
|
}
|
||||||
return $success;
|
return $this->l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return current set GetTextReader or return the one for given
|
||||||
|
* domain name if set
|
||||||
|
* This can be used to access all the public methods from the
|
||||||
|
* GetTextReader
|
||||||
|
*
|
||||||
|
* @param string $domain optional domain name
|
||||||
|
* @return GetTextReader
|
||||||
|
*/
|
||||||
|
public function getTranslatorClass(string $domain = ''): GetTextReader
|
||||||
|
{
|
||||||
|
if (!empty($domain) && !empty($this->domains[$this->locale][$domain])) {
|
||||||
|
return $this->domains[$this->locale][$domain];
|
||||||
|
}
|
||||||
|
// if null return short circuit version
|
||||||
|
if ($this->l10n === null) {
|
||||||
|
return new GetTextReader($this->input);
|
||||||
|
}
|
||||||
|
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
|
||||||
|
*
|
||||||
|
* Returns array with all possible locale combinations based on the
|
||||||
|
* given locale name
|
||||||
|
*
|
||||||
|
* I.e. for sr_CS.UTF-8@latin, look through all of
|
||||||
|
* sr_CS.UTF-8@latin, sr_CS@latin, sr@latin, sr_CS.UTF-8, sr_CS, sr.
|
||||||
|
*
|
||||||
|
* @param string $locale Locale string
|
||||||
|
* @return array<string> List of locale path parts that can be possible
|
||||||
|
*/
|
||||||
|
public static function listLocales(string $locale): array
|
||||||
|
{
|
||||||
|
$locale_list = [];
|
||||||
|
|
||||||
|
if (empty($locale)) {
|
||||||
|
return $locale_list;
|
||||||
|
}
|
||||||
|
// is matching regex
|
||||||
|
$locale_detail = L10n::parseLocale($locale);
|
||||||
|
// all null = nothing mached, return locale as is
|
||||||
|
if ($locale_detail === array_filter($locale_detail, 'is_null')) {
|
||||||
|
return [$locale];
|
||||||
|
}
|
||||||
|
// 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)
|
||||||
|
// %s_%s@%s (lang _ country @ suffix)
|
||||||
|
// %s@%s (lang @ suffix)
|
||||||
|
// %s_%s.%s (lang _ country . encoding)
|
||||||
|
// %s_%s (lang _ country)
|
||||||
|
// %s (lang)
|
||||||
|
|
||||||
|
// if lang is set
|
||||||
|
if ($lang) {
|
||||||
|
// modifier group
|
||||||
|
if ($modifier) {
|
||||||
|
if ($country) {
|
||||||
|
if ($charset) {
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s_%s.%s@%s', $lang, $country, $charset, $modifier)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s_%s@%s', $lang, $country, $modifier)
|
||||||
|
);
|
||||||
|
} elseif ($charset) {
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s.%s@%s', $lang, $charset, $modifier)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s@%s', $lang, $modifier)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// country group
|
||||||
|
if ($country) {
|
||||||
|
if ($charset) {
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s_%s.%s', $lang, $country, $charset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s_%s', $lang, $country)
|
||||||
|
);
|
||||||
|
} elseif ($charset) {
|
||||||
|
array_push(
|
||||||
|
$locale_list,
|
||||||
|
sprintf('%s.%s', $lang, $charset)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// lang only
|
||||||
|
array_push($locale_list, $lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the locale name doesn't match POSIX style, just include it as-is.
|
||||||
|
if (!in_array($locale, $locale_list)) {
|
||||||
|
array_push($locale_list, $locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $locale_list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tries to detect the locale set in the following order:
|
||||||
|
* - globals: LOCALE
|
||||||
|
* - globals: LANG
|
||||||
|
* - env: LC_ALL
|
||||||
|
* - env: LC_MESSAGES
|
||||||
|
* - env: LANG
|
||||||
|
* if nothing set, returns 'en' as default
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function detectLocale(): string
|
||||||
|
{
|
||||||
|
// globals
|
||||||
|
foreach (['LOCALE', 'LANG'] as $global) {
|
||||||
|
if (!empty($GLOBALS[$global])) {
|
||||||
|
return $GLOBALS[$global];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// enviroment
|
||||||
|
foreach (['LC_ALL', 'LC_MESSAGES', 'LANG'] as $env) {
|
||||||
|
$locale = getenv($env);
|
||||||
|
if ($locale !== false && !empty($locale)) {
|
||||||
|
return $locale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 'en';
|
||||||
|
}
|
||||||
|
|
||||||
|
/************
|
||||||
|
* INTERNAL VAR SET/GET
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the path for a domain.
|
||||||
|
* must be set before running l10nReloadMOfile
|
||||||
|
*
|
||||||
|
* @param string $domain Domain name
|
||||||
|
* @param string $path Path where to find locales
|
||||||
|
*/
|
||||||
|
public function setTextDomain(string $domain, string $path): void
|
||||||
|
{
|
||||||
|
$this->paths[$domain] = $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return set path for given domain
|
||||||
|
* if not found return false
|
||||||
|
*
|
||||||
|
* @param string $domain
|
||||||
|
* @return string|bool
|
||||||
|
*/
|
||||||
|
public function getTextDomain(string $domain)
|
||||||
|
{
|
||||||
|
return $this->paths[$domain] ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the default domain.
|
||||||
|
*
|
||||||
|
* @param string $domain Domain name
|
||||||
|
*/
|
||||||
|
public function setDomain(string $domain): void
|
||||||
|
{
|
||||||
|
$this->domain = $domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return current set domain name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getDomain(): string
|
||||||
|
{
|
||||||
|
return $this->domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets a requested locale.
|
||||||
|
*
|
||||||
|
* @param string $locale Locale name
|
||||||
|
* @return string Set or current locale
|
||||||
|
*/
|
||||||
|
public function setLocale(string $locale): string
|
||||||
|
{
|
||||||
|
if (!empty($locale)) {
|
||||||
|
$this->locale = $locale;
|
||||||
|
}
|
||||||
|
return $this->locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current set locale
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getLocale(): string
|
||||||
|
{
|
||||||
|
return $this->locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current set language
|
||||||
|
*
|
||||||
|
* @return string current set language string
|
||||||
|
* @deprecated Use getLocale()
|
||||||
|
*/
|
||||||
|
public function __getLang(): string
|
||||||
|
{
|
||||||
|
return $this->getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current set mo file
|
||||||
|
*
|
||||||
|
* @return string current set mo language file
|
||||||
|
*/
|
||||||
|
public function getMoFile(): string
|
||||||
|
{
|
||||||
|
return $this->mofile;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get current set mo file
|
||||||
|
*
|
||||||
|
* @return string current set mo language file
|
||||||
|
* @deprecated Use getMoFile()
|
||||||
|
*/
|
||||||
|
public function __getMoFile(): string
|
||||||
|
{
|
||||||
|
return $this->getMoFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the current base path in which we search
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBaseLocalePath(): string
|
||||||
|
{
|
||||||
|
return $this->base_locale_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the path below the base path to where the mo file is located
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getBaseContentPath(): string
|
||||||
|
{
|
||||||
|
return $this->base_content_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the current load error status
|
||||||
|
* if true then the mo file failed to load
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function getLoadError(): bool
|
||||||
|
{
|
||||||
|
return $this->load_failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
/************
|
||||||
|
* TRANSLATION METHODS
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* translates a string and returns translated text
|
* translates a string and returns translated text
|
||||||
|
*
|
||||||
* @param string $text text to translate
|
* @param string $text text to translate
|
||||||
* @return string translated text
|
* @return string translated text
|
||||||
*/
|
*/
|
||||||
public function __($text): string
|
public function __(string $text): string
|
||||||
{
|
{
|
||||||
|
// fallback passthrough
|
||||||
|
if ($this->l10n === null) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
return $this->l10n->translate($text);
|
return $this->l10n->translate($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,42 +549,100 @@ class L10n
|
|||||||
* prints translated string out to the screen
|
* prints translated string out to the screen
|
||||||
* @param string $text text to translate
|
* @param string $text text to translate
|
||||||
* @return void has no return
|
* @return void has no return
|
||||||
|
* @deprecated use echo __() instead
|
||||||
*/
|
*/
|
||||||
public function __e($text): void
|
public function __e(string $text): void
|
||||||
{
|
{
|
||||||
|
// fallback passthrough
|
||||||
|
if ($this->l10n === null) {
|
||||||
|
echo $text;
|
||||||
|
}
|
||||||
echo $this->l10n->translate($text);
|
echo $this->l10n->translate($text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the plural form.
|
|
||||||
/**
|
/**
|
||||||
* Return the plural form.
|
* Return the plural form.
|
||||||
* @param string $single string for single word
|
*
|
||||||
* @param string $plural string for plural word
|
* @param string $single string for single word
|
||||||
* @param string $number number value
|
* @param string $plural string for plural word
|
||||||
* @return string translated plural string
|
* @param int $number number value
|
||||||
|
* @return string translated plural string
|
||||||
*/
|
*/
|
||||||
public function __ngettext($single, $plural, $number)
|
public function __n(string $single, string $plural, int $number): string
|
||||||
{
|
{
|
||||||
|
// in case nothing got set yet, this is fallback
|
||||||
|
if ($this->l10n === null) {
|
||||||
|
return $number > 1 ? $plural : $single;
|
||||||
|
}
|
||||||
return $this->l10n->ngettext($single, $plural, $number);
|
return $this->l10n->ngettext($single, $plural, $number);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current set language
|
* context translation via msgctxt
|
||||||
* @return string current set language string
|
*
|
||||||
|
* @param string $context context string
|
||||||
|
* @param string $text text to translate
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __getLang()
|
public function __p(string $context, string $text): string
|
||||||
{
|
{
|
||||||
return $this->lang;
|
if ($this->l10n === null) {
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
return $this->l10n->pgettext($context, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get current set mo file
|
* context translation via msgctxt
|
||||||
* @return string current set mo language file
|
*
|
||||||
|
* @param string $context context string
|
||||||
|
* @param string $single string for single word
|
||||||
|
* @param string $plural string for plural word
|
||||||
|
* @param int $number number value
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __getMoFile()
|
public function __pn(string $context, string $single, string $plural, int $number): string
|
||||||
{
|
{
|
||||||
return $this->mofile;
|
if ($this->l10n === null) {
|
||||||
|
return $number > 1 ? $plural : $single;
|
||||||
|
}
|
||||||
|
return $this->l10n->npgettext($context, $single, $plural, $number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// alias functions to mimic gettext calls
|
||||||
|
|
||||||
|
/**
|
||||||
|
* alias for gettext,
|
||||||
|
* calls __
|
||||||
|
*
|
||||||
|
* @param string $text
|
||||||
|
* @return string
|
||||||
|
* @deprecated Use __()
|
||||||
|
*/
|
||||||
|
public function gettext(string $text): string
|
||||||
|
{
|
||||||
|
return $this->__($text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* alias for ngettext
|
||||||
|
* calls __n
|
||||||
|
*
|
||||||
|
* @param string $single
|
||||||
|
* @param string $plural
|
||||||
|
* @param int $number
|
||||||
|
* @return string
|
||||||
|
* @deprecated Use __n()
|
||||||
|
*/
|
||||||
|
public function ngettext(string $single, string $plural, int $number): string
|
||||||
|
{
|
||||||
|
return $this->__n($single, $plural, $number);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: dgettext(string $domain, string $message): string
|
||||||
|
// TODO: dngettext(string $domain, string $singular, string $plural, int $count): string
|
||||||
|
// TODO: dpgettext(string $domain, string $message, int $category): string
|
||||||
|
// TODO: dpngettext(string $domain, string $singular, string $plural, int $count, int $category): string
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user