Compare commits

...

31 Commits

Author SHA1 Message Date
Clemens Schwaighofer
805c695d68 Language\L10n method name fixes, update Smarty block.t.php
__pn for context plural has now correct name __np

Update smarty plugin block.t.php to use __* named gettext methods for
all calls, for __n/__np/__/__p calls we fallback to check internal set
class on l10n object variable.

This will be removed in future calls
2022-04-15 16:53:02 +09:00
Clemens Schwaighofer
ffdd45e32a Fix phpUnit tests with constant settings and missing checks
BASE constant setting: moved all to same base folder in 4dev/tests
check all other CONSTANT settings if they are already set and skip (used
only in Language default set)

Add missing phpunit check for array merge recursive
2022-04-15 15:19:30 +09:00
Clemens Schwaighofer
316ca106fd Composer autoload update 2022-04-15 13:57:48 +09:00
Clemens Schwaighofer
fd9b201346 Remove old GetSettings for language legacy flow 2022-04-15 13:57:26 +09:00
Clemens Schwaighofer
667dc4de8e Clean up of old _LANG config variables 2022-04-15 13:53:37 +09:00
Clemens Schwaighofer
fed67e990d Update Language\L10n class and drop all legacy code
new Langauge\GetLocale::setLocale() for getting new type lang info from
session, etc
L10n class call chnage of parameters:
NEW: locale, domain, path
OLD: locale, path, domain, legacy(bool)

Temporary auto detect for possible path/domain switch if domain value
has slash inside

Rename all local files to names matching locale folder
en_US -> en

Delete lang folders with symlinks as they are no longer used

Update all header files and class Backend\Admin, ACL\Login,
Output\Form\Generate, Template\SmartyExtend with new language order:
call ::setLocale() afer login class

Update missing test translation strings in all po files

Update phpUnit tests to match all new changes
2022-04-15 13:29:41 +09:00
Clemens Schwaighofer
c181a83b48 Rename po files to new standard <locale>-<domain>.po 2022-04-14 14:47:58 +09:00
Clemens Schwaighofer
c830a32962 Minor fix in gettext loop for max string lenght 2022-04-14 13:43:26 +09:00
Clemens Schwaighofer
82bc99b181 Language\ namespace update
Update the Core Language classes to have all method parameter type
declaration.
GetTextReader has gettext as alias to translate.
GetTextReader public methods to get cache enable status and short
circuit (no translation loaded) status

Main language:
Add new methods for plural and plural in context (__n, __p, __pn)
Deprecate gettext, ngettext, _e

Add new translation loader in gettext standard
<locale>/LC_MESSAGES/<domain> style
Including locales checker, auto detect on enviroment variables, return
self as class (for functions type) return translator class after
loading, etc

New LoadFunctions to run all like functions. Names like php but with two
underscores prefixed. eg gettext -> __gettext
2022-04-13 16:26:15 +09:00
Clemens Schwaighofer
556cabca38 Add DOCTYPE to all admin test files, update phpunit DB IO test
DB IO Test: Change max DB version to 99 from 20 in Version check test

Add DOCTYPE html to all admin class test files
2022-04-13 10:25:04 +09:00
Clemens Schwaighofer
6f4c5e36e6 Move Encoding class away from the Language namespace
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

Also fixed encoding check that not only a code point but a string can
also be used as a parameter.

Update phpunit tests and split them out for each class

Normal test page is still combined for all classes but updated to
correctly use each class
2022-04-13 09:25:42 +09:00
Clemens Schwaighofer
a3c49e408a Update to get default language settings with correct POSIX locale form
Also add phpunit test
2022-04-12 20:20:10 +09:00
Clemens Schwaighofer
cc77d7e031 Update Language\Encoding and phpunit tets
Fix missing replace char settings for conversion check call.
The php replace char method was never called. Also add standard type
settings next to char settings.
Return (get) call can either class set or current set in php

Fix mime encode with trailing space problem if length is on split
length. Mime encode uses \r\n for all line breaks now, can be controlled
via parameter
2022-04-12 20:19:48 +09:00
Clemens Schwaighofer
d553c1364f Add LOCALE config settings
next to the current lang/encoding add locale that is a combination of
both.
Also add a locale folder constant

the default LANG variables (DEFAULT_LANG, SITE_LANG) change from en_utf8
to en_US
new DEFAULT_LOCALE with en_US.UTF-8
2022-04-12 20:14:41 +09:00
Clemens Schwaighofer
3f374a2cd7 Update default db edit* language settings
en = en_US
jp = ja_JP
2022-04-12 20:13:23 +09:00
Clemens Schwaighofer
9e99275db5 phpunit tests includes folder for translation tests 2022-04-12 20:12:38 +09:00
Clemens Schwaighofer
330e2baf39 Add new locale folder structure and symlinks for old lang layout 2022-04-12 14:25:19 +09:00
Clemens Schwaighofer
5a81626e8c Clean up ACL/Login
Add locale global variable in the format
<lang>_<country>.<encoding>@<suffix>
Default set to en_US.UTF-8

Also remove nested if callse and do early abort/method return for
flatten code:
loginUser
logoutUser
setAcl
printLogin
passwordChange
2022-04-11 09:17:19 +09:00
Clemens Schwaighofer
41cff5e3c6 Remove old comment from DB\IO class about encoding settings 2022-04-08 19:59:37 +09:00
Clemens Schwaighofer
e463f48ad4 Updates for language auto detect, fixes for PHP 7.4
There was a bug in ther SQL interface class where the folder was just
called "Interface" which is not an allowed Namespace name. Renamed to
SqlInterface

Moved the detect lang/etc function used in Form/Generate,
Template/SmartyExtend and Admin/Backend to Language/GetSettings.

Fixed some test class calls
2022-04-07 10:49:28 +09:00
Clemens Schwaighofer
f8ee6044f9 Upgrade from Smarty 3 to Smarty 4 to be PHP 8.1 compatible
Remove all Smarty4 dedicated tests, all are done in the same test file
like before
2022-04-06 15:19:06 +09:00
Clemens Schwaighofer
4b0e9b44c3 Smarty template updates for testing, edit templates updates, translation strings update 2022-04-06 14:51:21 +09:00
Clemens Schwaighofer
e5309b5dbc Stop using DS for DIRECTORY_SEPARATOR replacement
There is no need for a short entry, use the long one.
The DS is still defined for backwards compatible use
2022-04-06 09:21:15 +09:00
Clemens Schwaighofer
aad2e9b11b Test psalm config changes 2022-04-01 16:09:02 +09:00
Clemens Schwaighofer
d6baf58231 Update PHPunit tests 2022-03-28 17:41:32 +09:00
Clemens Schwaighofer
c464a7d884 Add phpunit tests for db\io db num rows, etc calls with dbReturn* 2022-03-23 15:13:32 +09:00
Clemens Schwaighofer
60613bf311 Comment fixes in Convert\Color 2022-03-23 11:38:05 +09:00
Clemens Schwaighofer
2a583e525c Update config.master, color convert hsb/hsl is full float
All Convert\Color calls for hsb or hsl are full float compatible
2022-03-23 10:38:23 +09:00
Clemens Schwaighofer
04b0476b4d Info TODO text 2022-03-22 20:23:44 +09:00
Clemens Schwaighofer
13fb22385b Fix DB\IO return for unset pk name to be always string
Add Test for SELECT typ query and num rows type with dbReturn
2022-03-22 20:17:30 +09:00
Clemens Schwaighofer
b7f594e683 Fix, config master base style/js, fix DB\IO num rows
DB\IO dbReturn also sets internal num_rows, num_fields, field_names so
the normal dbGet* calls can be used after dbReturn call

JAVASCRIPT/STYLESHEET in config.master is now override able from .env
file. Others will follow
2022-03-22 20:11:13 +09:00
584 changed files with 39672 additions and 15424 deletions

View File

@@ -95,7 +95,7 @@ return [
'www/vendor',
'www/tests',
'www/lib/Smarty',
'www/lib/smarty-3.1.30',
'www/lib/smarty-4.1.0',
'www/templates_c',
'www/log',
'www/tmp',
@@ -117,11 +117,7 @@ return [
'www/admin/qq_file_upload_front.php',
'www/admin/qq_file_upload_ajax.php',
// symlink ignore
'www/lib/smarty-3.1.30/SmartyBC.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',
'www/lib/smarty-4.1.0/libs/Smarty.class.php'
],
// what not to show as problem

View File

@@ -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);
-- edit language
-- iso_name = encoding
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 (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, iso_name, order_number, enabled, lang_default) VALUES ('English', 'en_US', 'UTF-8', 1, 1, 1);
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
DELETE FROM edit_group;

View File

@@ -12,7 +12,7 @@ CREATE TABLE edit_language (
enabled SMALLINT NOT NULL DEFAULT 0,
lang_default SMALLINT NOT NULL DEFAULT 0,
long_name VARCHAR,
short_name VARCHAR,
iso_name VARCHAR,
short_name VARCHAR, -- en_US, en or en_US@latin without encoding
iso_name VARCHAR, -- should actually be encoding
order_number INT
) INHERITS (edit_generic) WITHOUT OIDS;

55
4dev/locale/Readme.md Normal file
View 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`

View File

@@ -3,21 +3,22 @@
# CREATED: 2005/08/09
# SHORT DESCRIPTION:
# Backned English Messages file for gettext
# to craete: msgfmt -o ja.mo messages_en.po
# HISTORY:
# to craete: msgfmt -o <output.po> <input.mo>
# ********************************************************************/
msgid ""
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"
"POT-Creation-Date: 2018-03-28 10:40+0900\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: 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 "Year"
msgstr "Year"
@@ -26,10 +27,31 @@ msgid "Month"
msgstr "Month"
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"
msgstr "I should be translated: I WAS TRANSLATED"
msgid "Are we translated?"
msgstr "Are we translated? Yes, we are!"
msgid "Original with string: %1"
msgstr "Translated with: %1"

View 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"

View File

@@ -3,21 +3,22 @@
# CREATED: 2018/03/28
# SHORT DESCRIPTION:
# Backend Japanese Messages file for gettext
# to craete: msgfmt -o ja.mo messages_ja.po
# HISTORY:
# to craete: msgfmt -o <output.po> <input.mo>
# ********************************************************************/
msgid ""
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"
"POT-Creation-Date: 2018-03-28 10:40+0900\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: 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%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
msgid "Yes"
msgstr "はい"
@@ -63,7 +64,25 @@ msgid "Sun"
msgstr "日"
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
msgid "Hello %s"
@@ -75,3 +94,5 @@ msgstr "「スマーティー」これは正しいです"
msgid "Are we translated?"
msgstr "「クラス」これは翻訳です?"
msgid "Original with string: %1"
msgstr "%1と翻訳した"

View 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"

View 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__

View File

@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
* @coversDefaultClass \CoreLibs\Check\PHPVersion
* @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

View File

@@ -7,6 +7,7 @@ declare(strict_types=1);
namespace tests;
use Exception;
use PHPUnit\Framework\TestCase;
/**
@@ -274,7 +275,6 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
}
/**
* TODO: create provider for n array merge
* provides array listing for the merge test
*
* @return array
@@ -282,6 +282,61 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
public function arrayMergeRecursiveProvider(): array
{
return [
// 0: expected
// 1..n: to merge arrays
// n+1: trigger for handle keys as string
'two arrays' => [
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2],
['b' => 2, 'c' => 3],
],
'two arrays, string flag' => [
['a' => 1, 'b' => 2, 'c' => 3],
['a' => 1, 'b' => 2],
['b' => 2, 'c' => 3],
true,
],
// non hash arrays
'non hash array merge, no string flag' => [
[3, 4, 5],
[1, 2, 3],
[3, 4, 5],
],
'non hash array merge, string flag' => [
[1, 2, 3, 3, 4, 5],
[1, 2, 3],
[3, 4, 5],
true
],
];
}
/**
* for warning checks
*
* @return array
*/
public function arrayMergeRecursiveProviderWarning(): array
{
return [
// error <2 arguments
'too view arguments' => [
'arrayMergeRecursive needs two or more array arguments',
[1]
],
// error <2 arrays
'only one array' => [
'arrayMergeRecursive needs two or more array arguments',
[1],
true,
],
// error element is not array
'non array between array' => [
'arrayMergeRecursive encountered a non array argument',
[1],
'string',
[2]
],
];
}
@@ -626,21 +681,43 @@ final class CoreLibsCombinedArrayHandlerTest extends TestCase
* Undocumented function
*
* @covers ::arrayMergeRecursive
* @#dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... will be $expected [$_dataName]
* @dataProvider arrayMergeRecursiveProvider
* @testdox arrayMergeRecursive ... [$_dataName]
*
* @param array $input nested array set as each parameter
* @param bool $flag
* @param bool|array $expected
* @return void
* array $input, bool $flag, $expected
*
*/
public function testArrayMergeRecursive(): void
{
$this->assertTrue(true, 'Implement proper test run');
$this->markTestIncomplete(
'testArrayMergeRecursive has not been implemented yet.'
$arrays = func_get_args();
// first is expected array, always
$expected = array_shift($arrays);
$output = \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(
...$arrays
);
$this->assertEquals(
$expected,
$output
);
}
/**
* Undocumented function
*
* @covers ::arrayMergeRecursive
* @dataProvider arrayMergeRecursiveProviderWarning
* @testdox arrayMergeRecursive with E_USER_WARNING [$_dataName]
*
* @return void
*/
public function testArrayMergeRecursiveWarningA(): void
{
$arrays = func_get_args();
// first is expected warning
$warning = array_shift($arrays);
$this->expectWarning();
$this->expectWarningMessage($warning);
\CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...$arrays);
}
/**

View File

@@ -132,7 +132,7 @@ final class CoreLibsConvertColorsTest extends TestCase
],
'valid color' => [
'rgb' => [10, 100, 200],
'hsb' => [212, 95, 78],
'hsb' => [212, 95, 78.0],
'hsb_rgb' => [10, 98, 199], // should be rgb, but rounding error
'hsl' => [211.6, 90.5, 41.2],
'valid' => true,
@@ -327,13 +327,13 @@ final class CoreLibsConvertColorsTest extends TestCase
* @dataProvider hsb2rgbColorProvider
* @testdox hsb2rgb $input_h,$input_s,$input_b will be $expected [$_dataName]
*
* @param integer $input_h
* @param integer $input_s
* @param integer $input_b
* @param float $input_h
* @param float $input_s
* @param float $input_b
* @param array|bool $expected
* @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(
$expected,

View 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__

View File

@@ -11,7 +11,7 @@ use PHPUnit\Framework\TestCase;
* @coversDefaultClass \CoreLibs\Convert\Json
* @testdox \CoreLibs\Convert\Json method tests
*/
final class CoreLibsCheckJsonTest extends TestCase
final class CoreLibsConvertJsonTest extends TestCase
{
/**

View 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__

View File

@@ -68,6 +68,7 @@ final class CoreLibsCreateSessionTest extends TestCase
*/
public function testStartSession(string $input, string $type, $expected_n, $expected_i): void
{
// NEEDS MOCKING
/* $session_id = '';
switch ($type) {
case 'p':
@@ -97,7 +98,8 @@ final class CoreLibsCreateSessionTest extends TestCase
if ($type == 'g') {
unset($GLOBALS['SET_SESSION_NAME']);
} */
$this->markTestSkipped('No implementation for Create\Session. Cannot run session_start in CLI');
$this->markTestSkipped('[CoreLibsCreateSessionTest] No implementation '
. 'for Create\Session. Cannot run session_start in CLI');
}
}

View File

@@ -347,6 +347,7 @@ final class CoreLibsDBIOTest extends TestCase
/**
* Returns test list for dbCompareVersion check
* NOTE: unless we fully mock the =version check needs to be updated
*
* @return array
*/
@@ -357,16 +358,16 @@ final class CoreLibsDBIOTest extends TestCase
return [
'compare = ok' => [ '=13.6.0', true ],
'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 <= ok a' => [ '<=20.0.0', true ],
'compare <= ok a' => [ '<=99.0.0', true ],
'compare <= ok b' => [ '<=13.6.0', true ],
'compare <= false' => [ '<=9.2.0', false ],
'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 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',
'id' => '51',
'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' => '',
'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
$db->dbExec("TRUNCATE table_with_primary_key");
$db->dbExec("TRUNCATE table_without_primary_key");

View File

@@ -54,14 +54,16 @@ final class CoreLibsDebugLoggingTest extends TestCase
'no options set, constant set' => [
null,
[
'log_folder' => '/tmp/',
'log_folder' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR . 'log/',
'debug_all' => false,
'print_all' => false,
],
[
'constant' => [
'BASE' => '/tmp',
'LOG' => '/'
'BASE' => str_replace('/configs', '', __DIR__)
. DIRECTORY_SEPARATOR,
'LOG' => 'log/'
]
]
],

View File

@@ -1,4 +1,4 @@
<?php
<?php // phpcs:disable Generic.Files.LineLength
declare(strict_types=1);
@@ -255,18 +255,27 @@ final class CoreLibsDebugSupportTest extends TestCase
* Undocumented function
*
* @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]
*
* @param array $expected
* @return void
*/
public function testGetCallerMethodList(array $expected): void
public function testGetCallerMethodList(array $expected, array $expected_group): void
{
$this->assertEquals(
$expected,
\CoreLibs\Debug\Support::getCallerMethodList()
);
$compare = \CoreLibs\Debug\Support::getCallerMethodList();
// if we direct call we have 10, if we call as folder we get 11
if (count($compare) == 10) {
$this->assertEquals(
$expected,
\CoreLibs\Debug\Support::getCallerMethodList()
);
} else {
$this->assertEquals(
$expected_group,
\CoreLibs\Debug\Support::getCallerMethodList()
);
}
}
/**

View File

@@ -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__

View File

@@ -0,0 +1,310 @@
<?php // phpcs:disable Generic.Files.LineLength
declare(strict_types=1);
namespace tests;
use PHPUnit\Framework\TestCase;
/**
* Test class for Language\GetLocale
*
* @coversDefaultClass \CoreLibs\Language\GetLocale
* @testdox \CoreLibs\Language\GetLocale method tests
*/
final class CoreLibsLanguageGetLocaleTest extends TestCase
{
/**
* set all constant variables that must be set before call
*
* @return void
*/
public static function setUpBeforeClass(): void
{
// default web page encoding setting
if (!defined('DEFAULT_ENCODING')) {
define('DEFAULT_ENCODING', 'UTF-8');
}
if (!defined('DEFAULT_LOCALE')) {
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
}
// site
if (!defined('SITE_ENCODING')) {
define('SITE_ENCODING', DEFAULT_ENCODING);
}
if (!defined('SITE_LOCALE')) {
define('SITE_LOCALE', DEFAULT_LOCALE);
}
// just set
if (!defined('BASE')) {
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
}
if (!defined('INCLUDES')) {
define('INCLUDES', 'includes' . DIRECTORY_SEPARATOR);
}
if (!defined('LANG')) {
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
}
if (!defined('LOCALE')) {
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
}
if (!defined('CONTENT_PATH')) {
define('CONTENT_PATH', 'frontend' . DIRECTORY_SEPARATOR);
}
// array session
$_SESSION = [];
global $_SESSION;
}
/**
* all the test data
*
* @return array
*/
public function setLocaleProvider(): array
{
return [
// 0: locale
// 1: domain
// 2: encoding
// 3: path
// 4: SESSION: DEFAULT_LOCALE
// 5: SESSION: DEFAULT_CHARSET
// 6: expected array
'no params, all default constants' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'en_US.UTF-8',
'lang' => 'en_US',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
'no params, session charset and lang' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
'ja_JP', 'UTF-8',
// return array
[
'locale' => 'ja_JP',
'lang' => 'ja_JP',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
'no params, session charset and lang short' => [
// lang, domain, encoding, path
null, null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
'ja', 'UTF-8',
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang (no sessions)
'locale param only, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'frontend',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// different locale setting
'locale complex param only, no sessions' => [
// lang, domain, encoding, path
'ja_JP.SJIS', null, null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja_JP.SJIS',
'lang' => 'ja_JP',
'domain' => 'frontend',
'encoding' => 'SJIS',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang and domain (no override)
'locale, domain params, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', null, null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// param lang and domain (no override)
'locale, domain, encoding params, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', 'UTF-8', null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// lang, domain, path (no override)
'locale, domain and path, no sessions' => [
// lang, domain, encoding, path
'ja.UTF-8', 'admin', '', __DIR__ . '/locale_other/',
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja.UTF-8',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// all params set (no override)
'all parameter, no sessions' => [
// lang, domain, encoding, path
'ja', 'admin', 'UTF-8', __DIR__ . '/locale_other/',
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'ja',
'lang' => 'ja',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?locale_other\/$/",
],
],
// param lang and domain (no override)
'long locale, domain, encoding params, no sessions' => [
// lang, domain, encoding, path
'de_CH.UTF-8@euro', 'admin', 'UTF-8', null,
// SESSION DEFAULT_LOCALE, SESSION: DEFAULT_CHARSET
null, null,
// return array
[
'locale' => 'de_CH.UTF-8@euro',
'lang' => 'de_CH',
'domain' => 'admin',
'encoding' => 'UTF-8',
'path' => "/^\/(.*\/)?includes\/locale\/$/",
],
],
// TODO invalid params (bad path) (no override)
// TODO param calls, but with override set
];
}
/**
* Undocumented function
*
* @covers ::setLocale
* @dataProvider setLocaleProvider
* @testdox lang settings lang $language, domain $domain, encoding $encoding, path $path; session lang: $SESSION_DEFAULT_LOCALE, session char: $SESSION_DEFAULT_CHARSET [$_dataName]
*
* @return void
*/
public function testsetLocale(
?string $language,
?string $domain,
?string $encoding,
?string $path,
?string $SESSION_DEFAULT_LOCALE,
?string $SESSION_DEFAULT_CHARSET,
array $expected,
): void {
$return_lang_settings = [];
global $_SESSION;
// set override
if ($SESSION_DEFAULT_LOCALE !== null) {
$_SESSION['DEFAULT_LOCALE'] = $SESSION_DEFAULT_LOCALE;
}
if ($SESSION_DEFAULT_CHARSET !== null) {
$_SESSION['DEFAULT_CHARSET'] = $SESSION_DEFAULT_CHARSET;
}
// function call
if ($language === null && $domain === null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale();
} elseif ($language !== null && $domain === null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language
);
} elseif ($language !== null && $domain !== null && $encoding === null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain
);
} elseif ($language !== null && $domain !== null && $encoding !== null && $path === null) {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain,
$encoding
);
} else {
$return_lang_settings = \CoreLibs\Language\GetLocale::setLocale(
$language,
$domain,
$encoding,
$path
);
}
// print "RETURN: " . print_r($return_lang_settings, true) . "\n";
foreach (
[
'locale', 'lang', 'domain', 'encoding', 'path'
] as $key
) {
$value = $expected[$key];
if (strpos($value, "/") === 0) {
// this is regex
$this->assertMatchesRegularExpression(
$value,
$return_lang_settings[$key],
'assert regex failed for ' . $key
);
} else {
// assert equal
$this->assertEquals(
$value,
$return_lang_settings[$key],
'assert equal failed for ' . $key
);
}
}
// unset all vars
$_SESSION = [];
unset($GLOBALS['OVERRIDE_LANG']);
}
}
// __END__

File diff suppressed because it is too large Load Diff

View 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;

View 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"

View 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"

Binary file not shown.

View 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"

View 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"

Binary file not shown.

View File

@@ -44,9 +44,24 @@ $db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
```
* update language class
```php
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
```
* smarty needs language
```php
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
```
* admin backend also needs logger
```php
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
```
* update and `$cms` or similar calls so db is in `$cms->db->...` and log are in `$cms->log->...`
* update all `config.*.php` files where needed
@@ -60,6 +75,12 @@ require BASE . LIB . 'autoloader.php';
```
**UPDATE:**
```php
// po langs [DEPRECAED: use LOCALE]
define('LANG', 'lang' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
```
```php
// SSL host name
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
```
@@ -85,6 +106,13 @@ define('CONTENT_WIDTH', '100%');
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
```
```php
/************* LANGUAGE / ENCODING *******/
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
define('DEFAULT_ENCODING', 'UTF-8');
```
```php
// BAIL ON MISSING DB CONFIG:
// we have either no db selction for this host but have db config entries
// or we have a db selection but no db config as array or empty
@@ -104,6 +132,10 @@ if (
}
```
```php
// remove SITE_LANG
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
```
```php
/************* GENERAL PAGE TITLE ********/
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
@@ -118,6 +150,15 @@ In the config then
```php
'db_name' => $_ENV['DB_NAME.TEST'] ?? '',
```
* config.host.php update
must add site_locale (site_lang + site_encoding)
remove site_lang
```php
// lang + encoding
'site_locale' => 'en_US.UTF-8',
// site language
'site_encoding' => 'UTF-8',
```
* copy `layout/admin/javascript/edit.jq.js`
* check other javacsript files if needed (`edit.jq.js`)

View File

@@ -4,7 +4,7 @@
// sets the _SERVER['HTTP_HOST'] var so we can have DB detection
$_SERVER['HTTP_HOST'] = 'soba.tokyo.tequila.jp';
// 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 includes/admin_header.php
define('BASE_NAME', '');

View File

@@ -45,9 +45,6 @@ parameters:
- www/lib/smarty-*/
# ignore composer
- www/vendor
# temp ignore smarty 4
- www/lib/CoreLibs/Template/SmartyExtend4.php
- www/admin/class_test.smarty4.php
# ignore errores with
ignoreErrors:
- # this error is ignore because of the PHP 8.0 to 8.1 change for pg_*

View File

@@ -43,18 +43,25 @@ $log = new CoreLibs\Debug\Logging([
]);
// db config with logger
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: ADMIN BACKEND</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
// set acl, from eg login acl
print "SETACL[]: " . $backend->setACL([]) . "<br>";
print "SETACL[]: " . $backend->setACL(['EMPTY' => 'EMPTY']) . "<br>";
print "ADBEDITLOG: " . $backend->adbEditLog('CLASSTEST-ADMIN', 'Some info stirng') . "<br>";
print "ADBTOPMENU(0): " . \CoreLibs\Debug\Support::printAr($backend->adbTopMenu()) . "<br>";
print "ADBMSG: " . $backend->adbMsg('info', 'Message: %1$d', [1]) . "<br>";
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>";
// error message

View File

@@ -45,6 +45,7 @@ $log = new CoreLibs\Debug\Logging([
// $_array = new CoreLibs\Combined\ArrayHandler();
// $array_class = 'CoreLibs\Combination\ArrayHandler';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -32,6 +32,7 @@ ob_end_flush();
use CoreLibs\Convert\Byte;
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$byte_class = 'CoreLibs\Convert\Byte';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: BYTE CONVERT</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$color_class = 'CoreLibs\Convert\Colors';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: COLORS</title><head>";
print "<body>";
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];
$hex = '#0a141e';
$hsb = [210, 67, 12];
$hsb_f = [210.5, 67.5, 12.5];
$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 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
print "S::COLOR hsb->rgb: $hsb[0], $hsb[1], $hsb[2]: "
. 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]: "
. 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]: "
. 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
// error message

View File

@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$datetime_class = 'CoreLibs\Combined\DateTime';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -39,6 +39,7 @@ $log = new CoreLibs\Debug\Logging([
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$db->log->debug('START', '=============================>');
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: DB</title><head>";
print "<body>";
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>";
$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))) {
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
$query = "SELECT type, sdate, integer FROM foobar";
$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
print "<b>WARNING NEXT</b><br>";

View File

@@ -44,6 +44,7 @@ $debug = new CoreLibs\Debug\Logging([
$debug_support_class = 'CoreLibs\Debug\Support';
$debug_logging_class = 'CoreLibs\Debug\Logging';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: DEBUG</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: HTML/ELEMENTS</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -29,7 +29,9 @@ if (!defined('SET_SESSION_NAME')) {
$LOG_FILE_ID = 'classTest-encoding';
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_folder' => BASE . LOG,
@@ -41,10 +43,13 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$_encoding = new CoreLibs\Language\Encoding();
$encoding_class = 'CoreLibs\Language\Encoding';
// class type
$_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 '<div><a href="class_test.php">Class Test Master</a></div>';
@@ -58,41 +63,47 @@ $mime_encodes = [
['日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい日本語ながい', 'ISO-2022-JP-MS'],
];
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 = [
'Normal Text',
'日本語',
// bad
'❶',
// unworkable
''
];
// class
$_encoding->setErrorChar('∴');
$_chk_enc->setErrorChar(0x2234);
$_chk_enc->setErrorChar('∴');
print "ERROR CHAR: " . $_chk_enc->getErrorChar() . "<br>";
foreach ($enc_strings as $_string) {
$string = $_encoding->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
print "CONV ENCODING: $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
print "CONV ENCODING (s): $_string: " . $_encoding->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
$string = $_chk_enc->checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
print "CONV ENCODING: $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP') . "<br>";
print "CONV ENCODING (s): $_string: " . $_con_enc->convertEncoding($_string, 'ISO-2022-JP', 'UTF-8') . "<br>";
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
$encoding_class::setErrorChar('∴');
// ChkEnc::setErrorChar('∴');
ChkEnc::setErrorChar(0x2234);
print "S::ERROR CHAR: " . ChkEnc::getErrorChar() . "<br>";
foreach ($enc_strings as $_string) {
$string = $encoding_class::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "S::ENC CHECK: $_string: " . ($string === false ? '-OK-' : $string) . "<br>";
print "S::CONV ENCODING: $_string: " . $encoding_class::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
$string = ChkEnc::checkConvertEncoding($_string, 'UTF-8', 'ISO-2022-JP-MS');
print "S::ENC CHECK: $_string: " . ($string === false ? '<b>-OK-</b>' : print_r($string, true)) . "<br>";
print "S::CONV ENCODING: $_string: " . ConEnc::convertEncoding($_string, 'ISO-2022-JP') . "<br>";
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: "
. $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
$_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>";
// error message

View File

@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: FILE</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -45,6 +45,7 @@ $hash_class = 'CoreLibs\Create\Hash';
// define a list of from to color sets for conversion test
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: HASH</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -49,6 +49,7 @@ $elements_class = 'CoreLibs\Output\Form\Elements';
// 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 "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -46,6 +46,7 @@ $image_class = 'CoreLibs\Output\Image';
// define a list of from to color sets for conversion test
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: IMAGE</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -46,6 +46,7 @@ $json_class = 'CoreLibs\Convert\Json';
// define a list of from to color sets for conversion test
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: JSON</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -19,8 +19,6 @@ ob_start();
// basic class test file
define('USE_DATABASE', false);
// init language
$lang = 'en_utf8';
// sample config
require 'config.php';
// set session name
@@ -29,28 +27,145 @@ if (!defined('SET_SESSION_NAME')) {
}
// define log file id
$LOG_FILE_ID = 'classTest-lang';
$l = new CoreLibs\Language\L10n($lang);
ob_end_flush();
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: LANG</title><head>";
print "<body>";
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';
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
// new path test
$lang = 'ja';
$domain = 'admin';
$encoding = 'UTF-8';
$path = BASE . INCLUDES . LOCALE;
// load direct
$l = new CoreLibs\Language\L10n($lang, $domain, $path);
echo "*<br>";
echo "LANGUAGE WANT/SET: " . $lang . '/' . $l->getLocale() . "<br>";
echo "DOMAIN WANT/SET: " . $domain . '/' . $l->getDomain() . "<br>";
echo "LANGUAGE FILE: " . $l->getMoFile() . "<br>";
echo "CONTENT PATH: " . $l->getBaseContentPath() . "<br>";
echo "DOMAIN PATH: " . $l->getTextDomain($domain) . "<br>";
echo "BASE PATH: " . $l->getBaseLocalePath() . "<br>";
echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
// switch to other language
$lang = 'ja_utf8';
$l->l10nReloadMOfile($lang);
echo "LANGUAGE SET: " . $l->__getLang() . "<br>";
echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
$single_string = 'single';
$multi_string = 'multi';
for ($n = 0; $n <= 3; $n++) {
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
. $l->__n($single_string, $multi_string, $n) . "<br>";
}
$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->__np($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>";
// 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>";

View File

@@ -44,6 +44,7 @@ $math_class = 'CoreLibs\Convert\Math';
// define a list of from to color sets for conversion test
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: MATH</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -41,6 +41,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$_mime = new CoreLibs\Convert\MimeAppName();
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: MIME</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -69,6 +69,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: FORM GENERATE</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -46,6 +46,7 @@ $password_class = 'CoreLibs\Check\Password';
// define a list of from to color sets for conversion test
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: PASSWORD</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -41,10 +41,17 @@ $log = new CoreLibs\Debug\Logging([
]);
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
$login = new CoreLibs\ACL\Login($db, $log);
$backend = new CoreLibs\Admin\Backend($db, $log);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
$backend->db->dbInfo(true);
ob_end_flush();
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS</title><head>";
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.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.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.byte.php">Class Test: BYTE CONVERT</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.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.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.smarty.php">Class Test: SMARTY</a></div>';
print '<div><a href="class_test.autoloader.php">Class Test: AUTOLOADER</a></div>';
print "<hr>";
print "L: " . CoreLibs\Debug\Support::printAr($locale) . "<br>";
// print all _ENV vars set
print "<div>READ _ENV ARRAY:</div>";
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
print CoreLibs\Debug\Support::printAr(array_map('htmlentities', $_ENV));
// set + check edit access id
$edit_access_id = 3;
if (is_object($login) && isset($login->acl['unit'])) {
@@ -145,9 +153,7 @@ print "BASE: " . BASE . "<br>";
print "ROOT: " . ROOT . "<br>";
print "HOST: " . HOST_NAME . " => DB HOST: " . DB_CONFIG_NAME . " => " . print_r(DB_CONFIG, true) . "<br>";
$ds = defined('DS') ? DS : DIRECTORY_SEPARATOR;
$du = DS ?? DIRECTORY_SEPARATOR;
print "DS is: " . $ds . "<br>";
print "DS is: " . DIRECTORY_SEPARATOR . "<br>";
print "SERVER HOST: " . $_SERVER['HTTP_HOST'] . "<br>";
// print error messages

View File

@@ -46,6 +46,7 @@ $phpv_class = 'CoreLibs\Check\PhpVersion';
// 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 "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -43,6 +43,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$array_class = 'CoreLibs\Create\RandomKey';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: RANDOM KEY</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -34,6 +34,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$ref_class = 'CoreLibs\Get\ReadEnvFile';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: READ ENV FILE</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
'print_all' => $PRINT_ALL ?? false,
]);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: RUNNING IMTE</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -19,8 +19,6 @@ ob_start();
// basic class test file
define('USE_DATABASE', true);
// set language
$lang = 'en_utf8';
// sample config
require 'config.php';
// override ECHO ALL FALSE
@@ -43,9 +41,15 @@ $log = new CoreLibs\Debug\Logging([
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
$smarty = new CoreLibs\Template\SmartyExtend();
$l = new CoreLibs\Language\L10n($lang);
$locale = \CoreLibs\Language\GetLocale::setLocale();
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: SMARTY</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';
@@ -65,16 +69,27 @@ if ($smarty->USE_PROTOTYPE) {
$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'] = $l10n->__('Are we translated?');
$smarty->DATA['TRANSLATE_TEST_FUNCTION'] = __gettext('Are we translated?');
$smarty->DATA['TRANSLATE_TEST_SMARTY'] = $smarty->l10n->__('Are we translated?');
$smarty->DATA['replace'] = 'Replaced';
// variable variables
$smarty->DATA['test'] = 'foo';
$smarty->DATA['foo'] = 'bar';
// loop
$smarty->DATA['loop_start'] = 5;
// 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(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
@@ -89,11 +104,26 @@ $options = [
'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();
// error message

View File

@@ -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__

View File

@@ -44,6 +44,7 @@ $log = new CoreLibs\Debug\Logging([
]);
$basic = new CoreLibs\Basic($log);
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: SYSTEM</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -42,6 +42,7 @@ $log = new CoreLibs\Debug\Logging([
$_token = new CoreLibs\Output\Form\Token();
$token_class = 'CoreLibs\Output\Form\Token';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: FORM TOKEN</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -43,6 +43,7 @@ $_uids = new CoreLibs\Create\Uids();
use CoreLibs\Create\Uids;
$uids_class = 'CoreLibs\Create\Uids';
print "<!DOCTYPE html>";
print "<html><head><title>TEST CLASS: UIDS</title><head>";
print "<body>";
print '<div><a href="class_test.php">Class Test Master</a></div>';

View File

@@ -1,6 +1,7 @@
{
"name": "gullevek/corelibs",
"description": "CoreLibs",
"name": "gullevek/corelibs-dev",
"version": "dev-master",
"description": "CoreLibs: Development package",
"type": "library",
"authors": [
{

View File

@@ -27,7 +27,8 @@ $__LOCAL_CONFIG = [
'db_host' => 'test',
'location' => 'test',
'debug_flag' => true,
'site_lang' => 'en_utf8',
'site_locale' => 'en_US.UTF-8',
'site_encoding' => 'UTF-8',
'login_enabled' => true
];
@@ -44,8 +45,10 @@ $SITE_CONFIG = [
'location' => 'test',
// show DEBUG override
'debug_flag' => true,
// site language
'site_lang' => 'en_utf8',
// site locale
'site_locale' => 'en_US.UTF-8',
// site encoding
'site_encoding' => 'UTF-8',
// enable/disable login override
'login_enabled' => true
],

View File

@@ -11,72 +11,72 @@
declare(strict_types=1);
/************* PATHS *********************/
// directory seperator
// [DEPRECATED] directory seperator
define('DS', DIRECTORY_SEPARATOR);
// ** NEW/BETTER DIR DECLARATIONS **
// path to original file (if symlink)
define('DIR', __DIR__ . DS);
define('DIR', __DIR__ . DIRECTORY_SEPARATOR);
// base dir root folder level
define('BASE', str_replace('/configs', '', __DIR__) . DS);
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
// ** OLD DIR DECLARATIONS **
// path to document root of file called
define('ROOT', getcwd() . DS);
define('ROOT', getcwd() . DIRECTORY_SEPARATOR);
// libs path
define('LIB', 'lib' . DS);
define('LIBS', 'lib' . DS);
define('LIB', 'lib' . DIRECTORY_SEPARATOR);
define('LIBS', 'lib' . DIRECTORY_SEPARATOR);
// configs folder
define('CONFIGS', 'configs' . DS);
define('CONFIGS', 'configs' . DIRECTORY_SEPARATOR);
// 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)
define('DATA', 'data' . DS);
define('DATA', 'data' . DIRECTORY_SEPARATOR);
// layout base path
define('LAYOUT', 'layout' . DS);
define('LAYOUT', 'layout' . DIRECTORY_SEPARATOR);
// pic-root (compatible to CMS)
define('PICTURES', 'images' . DS);
define('PICTURES', 'images' . DIRECTORY_SEPARATOR);
// images
define('IMAGES', 'images' . DS);
define('IMAGES', 'images' . DIRECTORY_SEPARATOR);
// icons (below the images/ folder)
define('ICONS', 'icons' . DS);
define('ICONS', 'icons' . DIRECTORY_SEPARATOR);
// media (accessable from outside)
define('MEDIA', 'media' . DS);
define('MEDIA', 'media' . DIRECTORY_SEPARATOR);
// uploads (anything to keep or data)
define('UPLOADS', 'uploads' . DS);
define('UPLOADS', 'uploads' . DIRECTORY_SEPARATOR);
// files (binaries) (below media or data)
define('BINARIES', 'binaries' . DS);
define('BINARIES', 'binaries' . DIRECTORY_SEPARATOR);
// files (videos) (below media or data)
define('VIDEOS', 'videos' . DS);
define('VIDEOS', 'videos' . DIRECTORY_SEPARATOR);
// files (documents) (below media or data)
define('DOCUMENTS', 'documents' . DS);
define('DOCUMENTS', 'documents' . DIRECTORY_SEPARATOR);
// files (pdfs) (below media or data)
define('PDFS', 'documents' . DS);
define('PDFS', 'documents' . DIRECTORY_SEPARATOR);
// files (general) (below media or data)
define('FILES', 'files' . DS);
define('FILES', 'files' . DIRECTORY_SEPARATOR);
// CSV
define('CSV', 'csv' . DS);
define('CSV', 'csv' . DIRECTORY_SEPARATOR);
// css
define('CSS', 'css' . DS);
define('CSS', 'css' . DIRECTORY_SEPARATOR);
// font (web)
define('FONT', 'font' . DS);
define('FONT', 'font' . DIRECTORY_SEPARATOR);
// js
define('JS', 'javascript' . DS);
define('JS', 'javascript' . DIRECTORY_SEPARATOR);
// table arrays
define('TABLE_ARRAYS', 'table_arrays' . DS);
define('TABLE_ARRAYS', 'table_arrays' . DIRECTORY_SEPARATOR);
// smarty libs path
define('SMARTY', 'Smarty' . DS);
// po langs
define('LANG', 'lang' . DS);
define('SMARTY', 'Smarty' . DIRECTORY_SEPARATOR);
// po locale file
define('LOCALE', 'locale' . DIRECTORY_SEPARATOR);
// cache path
define('CACHE', 'cache' . DS);
define('CACHE', 'cache' . DIRECTORY_SEPARATOR);
// temp path
define('TMP', 'tmp' . DS);
define('TMP', 'tmp' . DIRECTORY_SEPARATOR);
// log files
define('LOG', 'log' . DS);
define('LOG', 'log' . DIRECTORY_SEPARATOR);
// compiled template folder
define('TEMPLATES_C', 'templates_c' . DS);
define('TEMPLATES_C', 'templates_c' . DIRECTORY_SEPARATOR);
// template base
define('TEMPLATES', 'templates' . DS);
define('TEMPLATES', 'templates' . DIRECTORY_SEPARATOR);
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
// 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);
/************* LANGUAGE / ENCODING *******/
define('DEFAULT_LANG', 'en_utf8');
// default lang + encoding
define('DEFAULT_LOCALE', 'en_US.UTF-8');
// default web page encoding setting
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)
// define('GLOBAL_DB_SCHEMA', PUBLIC_SCHEMA);
// debug settings, site lang, etc
define('TARGET', $SITE_CONFIG[HOST_NAME]['location']);
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag']);
define('SITE_LANG', $SITE_CONFIG[HOST_NAME]['site_lang']);
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']);
define('TARGET', $SITE_CONFIG[HOST_NAME]['location'] ?? 'test');
define('DEBUG', $SITE_CONFIG[HOST_NAME]['debug_flag'] ?? false);
define('SITE_LOCALE', $SITE_CONFIG[HOST_NAME]['site_locale'] ?? DEFAULT_LOCALE);
define('SITE_ENCODING', $SITE_CONFIG[HOST_NAME]['site_encoding'] ?? DEFAULT_ENCODING);
define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled'] ?? false);
define('AUTH', $SITE_CONFIG[HOST_NAME]['auth'] ?? false);
// paths
// define('CSV_PATH', $PATHS[TARGET]['csv_path']);
// define('EXPORT_SCRIPT', $PATHS[TARGET]['perl_bin']);
@@ -274,8 +277,8 @@ define('G_TITLE', $_ENV['G_TITLE'] ?? '');
/************ STYLE SHEETS / JS **********/
define('ADMIN_STYLESHEET', 'edit.css');
define('ADMIN_JAVASCRIPT', 'edit.js');
define('STYLESHEET', 'frontend.css');
define('JAVASCRIPT', 'frontend.js');
define('STYLESHEET', $_ENV['STYLESHEET'] ?? 'frontend.css');
define('JAVASCRIPT', $_ENV['JAVASCRIPT'] ?? 'frontend.js');
// anything optional
/************* INTERNAL ******************/

View File

@@ -21,9 +21,12 @@ $paths = [
];
// find convert
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
define('CONVERT', $path . DS . 'convert');
define('CONVERT', $path . DIRECTORY_SEPARATOR . 'convert');
break;
}
}

View File

@@ -46,16 +46,21 @@ for ($dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__)); $dir
break;
}
}
// fail if no base DS is not set
if (!defined('DS')) {
// fail if no base DIR is not set
if (!defined('DIR')) {
exit('Base config unloadable');
}
// find trigger name "admin/" or "frontend/" in the getcwd() folder
foreach (['admin', 'frontend'] as $folder) {
if (strstr(getcwd() ?: '', DIRECTORY_SEPARATOR . $folder)) {
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
break;
}
}
// if content path is empty, fallback is default
/** @phpstan-ignore-next-line can be empty */
if (empty($folder)) {
$folder = 'default';
}
define('CONTENT_PATH', $folder . DIRECTORY_SEPARATOR);
// __END__

View File

@@ -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__

View File

@@ -4,7 +4,6 @@
* AUTHOR: Clemens Schwaighofer
* CREATED: 2008/08/01
* SHORT DESCRIPTION:
* URL redirect header
* HISTORY:
*********************************************************************/
@@ -73,10 +72,19 @@ if (
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login & page access check
$login = new CoreLibs\ACL\Login($db, $log);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// create smarty object
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
// create new Backend class with db and loger attached
$cms = new CoreLibs\Admin\Backend($db, $log);
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
// the menu show flag (what menu to show)
$cms->menu_show_flag = 'main';
// db info

View File

@@ -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__

View File

@@ -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__

View File

@@ -61,18 +61,27 @@ $log = new CoreLibs\Debug\Logging([
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
// login page
$login = new CoreLibs\ACL\Login($db, $log);
// lang, path, domain
// pre auto detect language after login
$locale = \CoreLibs\Language\GetLocale::setLocale();
// set lang and pass to smarty/backend
$l10n = new \CoreLibs\Language\L10n(
$locale['locale'],
$locale['domain'],
$locale['path'],
);
// flush and start
ob_end_flush();
// turn off set log per class
$log->setLogPer('class', false);
// create form class
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log);
$form = new CoreLibs\Output\Form\Generate(DB_CONFIG, $log, $l10n, $locale);
if ($form->mobile_phone) {
echo "I am sorry, but this page cannot be viewed by a mobile phone";
exit;
}
// smarty template engine (extended Translation version)
$smarty = new CoreLibs\Template\SmartyExtend();
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
// $form->log->debug('POST', $form->log->prAr($_POST));

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -33,26 +33,26 @@ function pop(theURL, winName, features) {
<!-- ERROR MSG END //-->
<!-- TOP MENU START //-->
<tr>
<td width="{$table_width}" class="menu_bgcolor" valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<form method="post">
<tr>
<td width="{$table_width}" class="menu_bgcolor" valign="top">
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<form method="post">
<tr>
<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>
</td>
<td bgcolor="{$HEADER_COLOR}" class="normal" align="right">
<input type="submit" name="login_logout" value="Logout">
</td>
</tr>
</form>
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<tr>
</tr>
</form>
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<tr>
{* foreach menu *}
{foreach from=$menu_data item=menu_element}
{* if split factor is reached *}
{if $menu_element.splitfactor_in}
<td class="menu_fgcolor" class="small" valign="top">
<td class="menu_fgcolor" class="small" valign="top">
{/if}
{if $menu_element.position}
<b><a href="{$menu_element.filename}">{$menu_element.pagename}</a></b><br>
@@ -67,22 +67,22 @@ function pop(theURL, winName, features) {
</td>
{/if}
{/foreach}
</tr>
</table>
<table width="100%" border="0" cellpadding="10" cellspacing="1">
<tr>
<td class="edit_fgcolor_alt" class="headline" align="center">
{$page_name}
</td>
</tr>
</table>
</td>
</tr>
</tr>
</table>
<table width="100%" border="0" cellpadding="10" cellspacing="1">
<tr>
<td class="edit_fgcolor_alt" class="headline" align="center">
{$page_name}
</td>
</tr>
</table>
</td>
</tr>
<!-- TOP MENU END //-->
<tr>
<td width="{$table_width}" class="edit_bgcolor">
<form method="post" name="edit_form" style="margin-block-end: 0em;">
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="{$table_width}" class="edit_bgcolor">
<form method="post" name="edit_form" style="margin-block-end: 0em;">
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<!-- LOAD START //-->
{include file="edit_load.tpl"}
<!-- LOAD END //-->
@@ -93,23 +93,23 @@ function pop(theURL, winName, features) {
{if $form_yes}
{include file="edit_save_delete.tpl"}
{if $form_my_page_name == "edit_pages" && $filename_exist}
<tr>
<td class="edit_fgcolor" class="normal">
Filename:
</td>
<td class="edit_fgcolor" class="normal">
{$filename}
<input type="hidden" name="filename" value="{$filename}">
</td>
</tr>
<tr>
<td class="edit_fgcolor" class="normal">
Filename:
</td>
<td class="edit_fgcolor" class="normal">
{$filename}
<input type="hidden" name="filename" value="{$filename}">
</td>
</tr>
{/if}
{include file="edit_elements.tpl"}
{include file="edit_hidden.tpl"}
{include file="edit_save_delete.tpl"}
{/if}
</table>
</form>
</td>
</table>
</form>
</td>
</tr>
</table>
</body>

View File

@@ -8,16 +8,16 @@
********************************************************************
*}
<tr>
<td class="edit_fgcolor_alt" class="normal">
{t}Create new media:{/t}
</td>
<td class="edit_fgcolor_alt" class="normal">
{if $new.show_checkbox}
<input type="checkbox" name="really_new" value="yes">&nbsp;{t}really{/t}&nbsp;
{else}
<input type="hidden" name="really_new" value="yes">
{/if}
<input type="submit" name="new" value="{$new.new_name}">
</td>
</tr>
<tr>
<td class="edit_fgcolor_alt" class="normal">
{t}Create new media:{/t}
</td>
<td class="edit_fgcolor_alt" class="normal">
{if $new.show_checkbox}
<input type="checkbox" name="really_new" value="yes">&nbsp;{t}really{/t}&nbsp;
{else}
<input type="hidden" name="really_new" value="yes">
{/if}
<input type="submit" name="new" value="{$new.new_name}">
</td>
</tr>

View File

@@ -25,7 +25,7 @@
<!-- ERROR MSG END //-->
<!-- BODY START //-->
<tr>
<td class="edit_bgcolor">
<td class="edit_bgcolor">
<table width="100%" border="0" cellpadding="2" cellspacing="1">
<!-- ANFANG Neu //-->
<form method="post" enctype="multipart/form-data">
@@ -68,7 +68,7 @@
</form>
<!-- ENDE FOOTER //-->
</table>
</td>
</td>
</tr>
<!-- BODY END //-->
</table>

View File

@@ -26,7 +26,7 @@
<input type="submit" name="delete" value="{t}Delete{/t}">
{else}
<td class="edit_fgcolor_alt" class="normal">
&nbsp;
&nbsp;
{/if}
</td>
</tr>

View File

@@ -1,16 +1,28 @@
<div>
{$SMARTY_TEST}
SMARTY_TEST: {$SMARTY_TEST}
</div>
<div {popup width="250" caption="Info" text="Text block<br>Control"} style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
POPUP HERE (hover mouse)
</div>
<div>
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
<b>Outside translation test</b><br>
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
</div>
<div>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
<b>Translate Test with replace:</b><br>
ORIGINAL: Original with string: %1 ({$replace})<br>
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
</div>
<div>
<select id="drop_down_test" name="drop_down_test">
{html_options options=$drop_down_test selected=$drop_down_test_selected}
</select>
<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 class="jq-container">
<div id="jq-test" class="jp-test">
@@ -23,11 +35,30 @@
</div>
</div>
<div class="loop-test">
<div>LOOP TEST</div>
<div><b>LOOP TEST</b></div>
{section name=page_list start=1 loop=$loop_start+1}
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
{/section}
</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 *}
<div id="indicator"></div>
{* the action confirm box *}

View File

@@ -1,37 +0,0 @@
<div>
{$SMARTY_TEST}
</div>
<div>
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}
</div>
<div>
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}
</div>
<div>
<select id="drop_down_test" name="drop_down_test">
{html_options options=$drop_down_test selected=$drop_down_test_selected}
</select>
</div>
<div class="jq-container">
<div id="jq-test" class="jp-test">
<div id="test-div" class="test-div">
Some content here or asdfasdfasf
</div>
<div id="translate-div">
{* TRANSLATION SMARTY: {t}I should be translated{/t} *}
TRANSLATION SMARTY: I should be translated
</div>
</div>
</div>
<div class="loop-test">
<div>LOOP TEST</div>
{section name=page_list start=1 loop=$loop_start+1}
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
{/section}
</div>
{* progresss indicator *}
<div id="indicator"></div>
{* the action confirm box *}
<div id="actionBox" class="actionBoxElement"></div>
{* The Overlay box *}
<div id="overlayBox" class="overlayBoxElement"></div>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -92,6 +92,8 @@ class Backend
/** @var string */
public $lang_short;
/** @var string */
public $domain;
/** @var string */
public $encoding;
/** @var \CoreLibs\Debug\Logging logger */
public $log;
@@ -112,15 +114,16 @@ class Backend
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
/**
* main class constructor
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n|null $l10n l10n language class
* if null, auto set
* @param \CoreLibs\DB\IO $db Database connection class
* @param \CoreLibs\Debug\Logging $log Logging class
* @param \CoreLibs\Language\L10n $l10n l10n language class
* @param array<string,string> $locale locale data read from setLocale
*/
public function __construct(
\CoreLibs\DB\IO $db,
\CoreLibs\Debug\Logging $log,
?\CoreLibs\Language\L10n $l10n = null
\CoreLibs\Language\L10n $l10n,
array $locale
) {
// set to log not per class
$log->setLogPer('class', false);
@@ -128,10 +131,15 @@ class Backend
$this->log = $log;
// attach db class
$this->db = $db;
// TODO lang create outside of class
$this->setLangEncoding();
// get the language sub class & init it
$this->l = $l10n ?? new \CoreLibs\Language\L10n($this->lang);
$this->l = $l10n;
// parse and read, legacy stuff
$this->encoding = $locale['encoding'];
$this->lang = $locale['lang'];
// get first part from lang
$this->lang_short = explode('_', $locale['lang'])[0];
$this->domain = $this->l->getDomain();
$this->lang_dir = $this->l->getBaseLocalePath();
// set the page name
$this->page_name = \CoreLibs\Get\System::getPageName();
@@ -157,43 +165,6 @@ class Backend
// NO OP
}
// INTERNAL METHODS |===============================================>
/**
* set the language encoding and language settings
* use $OVERRIDE_LANG to override all language settings
* the default charset from _SESSION login or from
* config DEFAULT ENCODING
* the lang full name for mo loading from _SESSION login
* or SITE LANG or DEFAULT LANG from config
* creates short lang (only first two chars) from the lang
* @return void
*/
private function setLangEncoding(): void
{
// 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 |=================================================>
/**

View File

@@ -715,20 +715,20 @@ class Basic
// *** ARRAY HANDLING END
// [!!! DEPRECATED !!!]
// Moved to \CoreLibs\Language\Encoding
// Moved to \CoreLibs\Convert\MimeEncode
/**
* wrapper function for mb mime convert, for correct conversion with long strings
* @param string $string string to encode
* @param string $encoding target encoding
* @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
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::__mbMimeEncode($string, $encoding);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeEncode::__mbMimeEncode()', E_USER_DEPRECATED);
return \CoreLibs\Convert\MimeEncode::__mbMimeEncode($string, $encoding);
}
// *** HUMAND BYTE READABLE CONVERT
@@ -1009,7 +1009,7 @@ class Basic
// *** ENCODING FUNCTIONS
// [!!! 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
@@ -1026,12 +1026,12 @@ class Basic
* @param string $from_encoding encoding of string to test
* @param string $to_encoding target encoding
* @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)
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Check\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
}
/**
@@ -1047,12 +1047,12 @@ class Basic
* check that the source is actually matching
* to what we sav the source is
* @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
{
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Encoding::convertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
}
// *** ENCODING FUNCTIONS END

View 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__

View File

@@ -218,7 +218,8 @@ class ArrayHandler
continue;
}
foreach ($array as $key => $value) {
// if string or if key is assumed to be string do key match else add new entry
// if string or if key is assumed to be string do key match
// else add new entry
if (is_string($key) || $key_is_string === false) {
if (is_array($value) && array_key_exists($key, $merged) && is_array($merged[$key])) {
// $merged[$key] = call_user_func(__METHOD__, $merged[$key], $value, $key_is_string);

View File

@@ -66,7 +66,8 @@ class Colors
}
$rgbArray = [];
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);
$rgbArray['r'] = 0xFF & ($colorVal >> 0x10);
$rgbArray['g'] = 0xFF & ($colorVal >> 0x8);
@@ -135,13 +136,13 @@ class Colors
* hsb2rgb does not clean convert back to hsb in a round trip
* converts HSB/V to RGB values RGB is full INT
* if HSB/V value is invalid, sets this value to 0
* @param int $H hue 0-360 (int)
* @param int $S saturation 0-100 (int)
* @param int $V brightness/value 0-100 (int)
* @param float $H hue 0-360 (int)
* @param float $S saturation 0-100 (int)
* @param float $V brightness/value 0-100 (int)
* @return array<int>|bool 0 red/1 green/2 blue array as 0-255
* false for input value error
*/
public static function hsb2rgb(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
// and S and V are 0 to 1
@@ -270,12 +271,12 @@ class Colors
/**
* converts an HSL to RGB
* 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 $lum luminance: 0-100
* @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)) {
return false;
@@ -289,7 +290,8 @@ class Colors
if ($lum < 0 || $lum > 100) {
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
$sat /= 100;
$lum /= 100;

View 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__

View 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__

View File

@@ -382,7 +382,7 @@ class IO
public function __construct(
array $db_config,
?\CoreLibs\Debug\Logging $log = null,
?bool $db_debug_override = null,
?bool $db_debug_override = null
) {
// attach logger
$this->log = $log ?? new \CoreLibs\Debug\Logging();
@@ -410,9 +410,6 @@ class IO
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
$this->MAX_QUERY_CALL = self::DEFAULT_MAX_QUERY_CALL;
@@ -1786,9 +1783,12 @@ class IO
// count the rows returned (if select)
$this->cursor_ext[$query_hash]['num_rows'] =
$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
$this->cursor_ext[$query_hash]['num_fields'] =
$this->db_functions->__dbNumFields($this->cursor_ext[$query_hash]['cursor']);
$this->num_fields = $this->cursor_ext[$query_hash]['num_fields'];
// set field names
$this->cursor_ext[$query_hash]['field_names'] = [];
for ($i = 0; $i < $this->cursor_ext[$query_hash]['num_fields']; $i++) {
@@ -1798,6 +1798,7 @@ class IO
$i
);
}
$this->field_names = $this->cursor_ext[$query_hash]['field_names'];
// reset first call vars
$this->cursor_ext[$query_hash]['firstcall'] = 0;
// reset the internal pos counter
@@ -2870,7 +2871,7 @@ class IO
*/
public function dbGetInsertPKName(): string
{
return $this->insert_id_pk_name;
return (string)$this->insert_id_pk_name;
}
/**

View File

@@ -51,7 +51,7 @@ namespace CoreLibs\DB\SQL;
// as main system. Currently all @var sets are written as object
/** @#phan-file-suppress PhanUndeclaredTypeProperty,PhanUndeclaredTypeParameter,PhanUndeclaredTypeReturnType */
class PgSQL implements Interface\SqlFunctions
class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
{
/** @var string */
private $last_error_query;

View File

@@ -6,7 +6,7 @@
declare(strict_types=1);
namespace CoreLibs\DB\SQL\Interface;
namespace CoreLibs\DB\SQL\SqlInterface;
interface SqlFunctions
{

View File

@@ -39,7 +39,7 @@ class FileReader
* file read constructor
* @param string $filename file name to load
*/
public function __construct($filename)
public function __construct(string $filename)
{
if (file_exists($filename)) {
$this->fr_length = filesize($filename) ?: 0;
@@ -58,7 +58,7 @@ class FileReader
* @param int $bytes how many bytes to read
* @return string read data as string
*/
public function read($bytes)
public function read(int $bytes): string
{
if (!$bytes || !is_resource($this->fr_fd)) {
return '';
@@ -86,7 +86,7 @@ class FileReader
* @param int $pos position where to go to
* @return int file position after seek done
*/
public function seekto($pos)
public function seekto(int $pos): int
{
if (!is_resource($this->fr_fd)) {
return 0;
@@ -100,7 +100,7 @@ class FileReader
* get current position in file
* @return int current position in bytes
*/
public function currentpos()
public function currentpos(): int
{
return $this->fr_pos;
}
@@ -109,7 +109,7 @@ class FileReader
* file length/size
* @return int file size in bytes
*/
public function length()
public function length(): int
{
return $this->fr_length;
}

View File

@@ -67,17 +67,15 @@ class GetTextReader
/** @var array<mixed> */
private $cache_translations = []; // original -> translation mapping
/* Methods */
/**
* Reads a 32bit Integer from the Stream
*
* @access private
* @return int Integer from the Stream
*/
private function readint()
private function readint(): int
{
if ($this->BYTEORDER == 0) {
// low endian
@@ -91,10 +89,11 @@ class GetTextReader
/**
* read bytes
*
* @param int $bytes byte length to read
* @return string return data, possible string
*/
public function read($bytes)
public function read(int $bytes): string
{
return $this->STREAM->read($bytes);
}
@@ -105,7 +104,7 @@ class GetTextReader
* @param int $count How many elements should be read
* @return array<mixed> Array of Integers
*/
public function readintarray($count)
public function readintarray(int $count): array
{
if ($this->BYTEORDER == 0) {
// low endian
@@ -120,9 +119,10 @@ class GetTextReader
* Constructor
*
* @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 ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
@@ -159,6 +159,26 @@ class GetTextReader
$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
* 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
* @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;
$offset = $this->table_originals[$num * 2 + 2] ?? 0;
@@ -226,7 +246,7 @@ class GetTextReader
* @param int $num Offset number of original string
* @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;
$offset = $this->table_translations[$num * 2 + 2] ?? 0;
@@ -242,12 +262,12 @@ class GetTextReader
* Binary search for string
*
* @access private
* @param string $string string to find
* @param int $start (internally used in recursive function)
* @param int $end (internally used in recursive function)
* @return int (offset in originals table)
* @param string $string string to find
* @param int $start (internally used in recursive function)
* @param int $end (internally used in recursive function)
* @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)) {
// findString is called with only one parameter, set start end end
@@ -289,7 +309,7 @@ class GetTextReader
* @param string $string to be translated
* @return string translated string (or original, if not found)
*/
public function translate($string)
public function translate(string $string): string
{
if ($this->short_circuit) {
return $string;
@@ -298,7 +318,10 @@ class GetTextReader
if ($this->enable_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];
} else {
return $string;
@@ -321,7 +344,7 @@ class GetTextReader
* @param string $expr an expression to match
* @return string sanitized plural form expression
*/
private function sanitizePluralExpression($expr)
private function sanitizePluralExpression(string $expr): string
{
// Get rid of disallowed characters.
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
@@ -330,7 +353,8 @@ class GetTextReader
$expr .= ';';
$res = '';
$p = 0;
for ($i = 0; $i < strlen($expr); $i++) {
$expr_len = strlen($expr);
for ($i = 0; $i < $expr_len; $i++) {
$ch = $expr[$i];
switch ($ch) {
case '?':
@@ -358,7 +382,7 @@ class GetTextReader
* @param string $header header search in plurals
* @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)) {
$expr = $regs[2];
@@ -374,14 +398,14 @@ class GetTextReader
* @access private
* @return string plural form header
*/
private function getPluralForms()
private function getPluralForms(): string
{
// lets assume message number 0 is header
// this is true, right?
$this->loadTables();
// cache header field for plural forms
if (! is_string($this->pluralheader)) {
if (empty($this->pluralheader) || !is_string($this->pluralheader)) {
if ($this->enable_cache) {
$header = $this->cache_translations[''];
} else {
@@ -397,25 +421,38 @@ class GetTextReader
* Detects which plural form to take
*
* @access private
* @param string $n count
* @return int array index of the right plural form
* @param int $n count
* @return int array index of the right plural form
*/
private function selectString($n)
private function selectString(int $n): int
{
$string = $this->getPluralForms();
$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);
$total = 0;
$plural = 0;
// FIXME use Symfony\Component\ExpressionLanguage\ExpressionLanguage or similar
eval("$string");
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line 0 >= 0 is always true*/
if ($plural >= $total) {
$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
* @param string $single
* @param string $plural
* @param string $number
* @param int $number
* @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 ($number != 1) {
@@ -465,11 +502,12 @@ class GetTextReader
/**
* p get text
*
* @param string $context [description]
* @param string $msgid [description]
* @return string [description]
*/
public function pgettext($context, $msgid)
public function pgettext(string $context, string $msgid): string
{
$key = $context . chr(4) . $msgid;
$ret = $this->translate($key);
@@ -482,14 +520,19 @@ class GetTextReader
/**
* np get text
*
* @param string $context [description]
* @param string $singular [description]
* @param string $plural [description]
* @param string $number [description]
* @param int $number [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;
$ret = $this->ngettext($key, $plural, $number);
if (strpos($ret, "\004") !== false) {

Some files were not shown because too many files have changed in this diff Show More