Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07aea9d7b2 | ||
|
|
edcdbee523 | ||
|
|
43b51895f0 | ||
|
|
d0e294ecf5 | ||
|
|
3c35341e8b | ||
|
|
daf1f9263c |
@@ -13,18 +13,73 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsACLLoginTest extends TestCase
|
||||
{
|
||||
private static $db;
|
||||
private static $log;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* start DB conneciton, setup DB, etc
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp(): void
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (!extension_loaded('pgsql')) {
|
||||
$this->markTestSkipped(
|
||||
self::markTestSkipped(
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
// 'log_folder' => __DIR__ . DIRECTORY_SEPARATOR . 'log',
|
||||
'log_folder' => DIRECTORY_SEPARATOR . 'tmp',
|
||||
'file_id' => 'CoreLibs-ACL-Login-Test',
|
||||
'debug_all' => false,
|
||||
'echo_all' => false,
|
||||
'print_all' => false,
|
||||
]);
|
||||
// if we do have pgsql, we need to create a test DB or check that one
|
||||
// exists and clean the table to zero state
|
||||
self::$db = new \CoreLibs\DB\IO(
|
||||
[
|
||||
'db_name' => 'corelibs_acl_login_test',
|
||||
'db_user' => 'corelibs_acl_login_test',
|
||||
'db_pass' => 'corelibs_acl_login_test',
|
||||
'db_host' => 'localhost',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow', // allow, disable, require, prefer
|
||||
'db_debug' => true,
|
||||
],
|
||||
self::$log
|
||||
);
|
||||
if (!self::$db->dbGetConnectionStatus()) {
|
||||
self::markTestSkipped(
|
||||
'Cannot connect to valid Test DB for ACL\Login test.'
|
||||
);
|
||||
}
|
||||
/*
|
||||
// check if they already exist, drop them
|
||||
if ($db->dbShowTableMetaData('table_with_primary_key') !== false) {
|
||||
$db->dbExec("DROP TABLE table_with_primary_key");
|
||||
$db->dbExec("DROP TABLE table_without_primary_key");
|
||||
$db->dbExec("DROP TABLE test_meta");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* close db
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
if (self::$db->dbGetConnectionStatus()) {
|
||||
self::$db->dbClose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -145,7 +145,7 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
);
|
||||
if (!$db->dbGetConnectionStatus()) {
|
||||
self::markTestSkipped(
|
||||
'Cannot connect to valid Test DB.'
|
||||
'Cannot connect to valid Test DB for DB\IO test.'
|
||||
);
|
||||
}
|
||||
// check if they already exist, drop them
|
||||
@@ -2709,7 +2709,8 @@ final class CoreLibsDBIOTest extends TestCase
|
||||
// comarep all, except timestamp that is a regex
|
||||
foreach ($expected_history as $key => $value) {
|
||||
// check if starts with / because this is regex (timestamp)
|
||||
if (strpos($value, "/") === 0) {
|
||||
// if (substr($expected_2, 0, 1) == '/) {
|
||||
if (strpos($value, '/') === 0) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$value,
|
||||
|
||||
@@ -90,11 +90,16 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
public function getPageNameProvider(): array
|
||||
{
|
||||
return [
|
||||
// 0: input
|
||||
// 1: expected default/WITH_EXTENSION
|
||||
// 2: expected NO_EXTENSION
|
||||
// 3: expected FULL_PATH, if first and last character are / use regex
|
||||
'original set' => [
|
||||
0 => null, // input
|
||||
0 => null,
|
||||
1 => 'phpunit',
|
||||
2 => 'phpunit',
|
||||
3 => 'www/vendor/bin/phpunit', // NOTE: this can change
|
||||
// NOTE: this can change, so it is a regex check
|
||||
3 => "/^(\/?.*\/?)?www\/vendor\/bin\/phpunit$/",
|
||||
],
|
||||
'some path with extension' => [
|
||||
0 => '/some/path/to/file.txt',
|
||||
@@ -147,11 +152,13 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
list ($host, $port) = \CoreLibs\Get\System::getHostName();
|
||||
$this->assertEquals(
|
||||
$expected_host,
|
||||
$host
|
||||
$host,
|
||||
'failed expected host assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_port,
|
||||
$port
|
||||
$port,
|
||||
'faile expected port assert'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,20 +183,38 @@ final class CoreLibsGetSystemTest extends TestCase
|
||||
// default 0,
|
||||
$this->assertEquals(
|
||||
$expected_0,
|
||||
\CoreLibs\Get\System::getPageName()
|
||||
\CoreLibs\Get\System::getPageName(),
|
||||
'failed default assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_0,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION)
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::WITH_EXTENSION),
|
||||
'failed WITH_EXTESION assert'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_1,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION)
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_2,
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH)
|
||||
\CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::NO_EXTENSION),
|
||||
'failed NO_EXTENSION assert'
|
||||
);
|
||||
// FULL PATH check can be equals or regex
|
||||
$page_name_full_path = \CoreLibs\Get\System::getPageName(\CoreLibs\Get\System::FULL_PATH);
|
||||
if (
|
||||
substr($expected_2, 0, 1) == '/' &&
|
||||
substr($expected_2, -1, 1) == '/'
|
||||
) {
|
||||
// this is regex
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected_2,
|
||||
$page_name_full_path,
|
||||
'failed FULL_PATH assert regex'
|
||||
);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expected_2,
|
||||
$page_name_full_path,
|
||||
'failed FULL_PATH assert equals'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,11 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// 2: encoding
|
||||
// 3: path
|
||||
// 4: locale expected
|
||||
// 5: domain exepcted
|
||||
// 6: context (null for none)
|
||||
// 7: test string in
|
||||
// 8: test translated
|
||||
// 5: locale set expected
|
||||
// 6: domain exepcted
|
||||
// 7: context (null for none)
|
||||
// 8: test string in
|
||||
// 9: test translated
|
||||
// new style load
|
||||
'gettext load en' => [
|
||||
'en_US.UTF-8',
|
||||
@@ -120,6 +121,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
null,
|
||||
'Original',
|
||||
@@ -131,6 +133,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'context',
|
||||
'Original',
|
||||
@@ -142,6 +145,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
__DIR__ . 'includes/locale/',
|
||||
//
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'admin',
|
||||
null,
|
||||
'Original',
|
||||
@@ -154,6 +158,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'frontend',
|
||||
//
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'context',
|
||||
'Original',
|
||||
@@ -167,6 +172,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
//
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
null,
|
||||
'Original',
|
||||
'Original',
|
||||
@@ -185,6 +191,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @param string|null $domain
|
||||
* @param string|null $path
|
||||
* @param string $locale_expected
|
||||
* @param string $locale_set_expected
|
||||
* @param string $domain_expected
|
||||
* @param ?string $context
|
||||
* @param string $original
|
||||
@@ -196,6 +203,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
?string $domain,
|
||||
?string $path,
|
||||
string $locale_expected,
|
||||
string $locale_set_expected,
|
||||
string $domain_expected,
|
||||
?string $context,
|
||||
string $original,
|
||||
@@ -217,6 +225,11 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
$l10n->getLocale(),
|
||||
'Locale assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$locale_set_expected,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale set assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected,
|
||||
$l10n->getDomain(),
|
||||
@@ -255,15 +268,17 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// 3: load error
|
||||
// 4: input string to translated
|
||||
// 5: expected locale
|
||||
// 6: expected domain
|
||||
// 7: expected translation
|
||||
// 8: change locale
|
||||
// 9: change domain
|
||||
// 10: change path
|
||||
// 11: change load error
|
||||
// 12: expected locale
|
||||
// 13: expected domain
|
||||
// 14: expected translation
|
||||
// 6: expected locale set
|
||||
// 7: expected domain
|
||||
// 8: expected translation
|
||||
// 9: change locale
|
||||
// 10: change domain
|
||||
// 11: change path
|
||||
// 12: change load error
|
||||
// 13: expected locale
|
||||
// 14: expected locale set
|
||||
// 15: expected domain
|
||||
// 16: expected translation
|
||||
'load and change (en->ja)' => [
|
||||
// set 0-2
|
||||
'en_US.UTF-8',
|
||||
@@ -275,6 +290,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
'Original',
|
||||
// check setter 5-7
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'Translated frontend en_US',
|
||||
// set new 8-10
|
||||
@@ -285,6 +301,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
false,
|
||||
// check new setter 12-14
|
||||
'ja_JP.UTF-8',
|
||||
'ja_JP',
|
||||
'frontend',
|
||||
'Translated frontend ja_JP',
|
||||
],
|
||||
@@ -300,6 +317,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
// check setter 5-7
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
'Original',
|
||||
// set new 8-10
|
||||
'en_US.UTF-8',
|
||||
@@ -309,6 +327,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
false,
|
||||
// check new setter 12-14
|
||||
'en_US.UTF-8',
|
||||
'en_US',
|
||||
'frontend',
|
||||
'Translated frontend en_US',
|
||||
]
|
||||
@@ -329,12 +348,14 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
* @param bool $load_error
|
||||
* @param string $original
|
||||
* @param string $locale_expected_a
|
||||
* @param string $locale_set_expected_a
|
||||
* @param string $domain_expected_a
|
||||
* @param string $translated_a
|
||||
* @param string|null $locale_new
|
||||
* @param string|null $domain_new
|
||||
* @param string|null $path_new
|
||||
* @param bool $load_error_new
|
||||
* @param string $locale_set_expected_b
|
||||
* @param string $locale_expected_b
|
||||
* @param string $domain_expected_b
|
||||
* @param string $translated_b
|
||||
@@ -351,6 +372,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
string $original,
|
||||
// 5-7
|
||||
string $locale_expected_a,
|
||||
string $locale_set_expected_a,
|
||||
string $domain_expected_a,
|
||||
string $translated_a,
|
||||
// 8-10
|
||||
@@ -361,6 +383,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
bool $load_error_new,
|
||||
// 12-14
|
||||
string $locale_expected_b,
|
||||
string $locale_set_expected_b,
|
||||
string $domain_expected_b,
|
||||
string $translated_b,
|
||||
): void {
|
||||
@@ -384,6 +407,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
$locale_expected_a,
|
||||
$l10n->getLocale(),
|
||||
'Locale init assert failed'
|
||||
);$this->assertEquals(
|
||||
$locale_set_expected_a,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale Set init assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected_a,
|
||||
@@ -435,6 +462,11 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
$l10n->getLocale(),
|
||||
'Locale change assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$locale_set_expected_b,
|
||||
$l10n->getLocaleSet(),
|
||||
'Locale Set change assert failed'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$domain_expected_b,
|
||||
$l10n->getDomain(),
|
||||
@@ -994,10 +1026,10 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
string $translated
|
||||
): void {
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__($original),
|
||||
@@ -1005,7 +1037,7 @@ final class CoreLibsLanguageL10nTest extends TestCase
|
||||
);
|
||||
$this->assertEquals(
|
||||
$translated,
|
||||
__gettext($original),
|
||||
_gettext($original),
|
||||
'function gettext assert failed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace test;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class TemplateMethodsTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function assertPreConditions(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
public function testOne(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testTwo(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
|
||||
protected function assertPostConditions(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
}
|
||||
|
||||
protected function onNotSuccessfulTest(\Throwable $t): void
|
||||
{
|
||||
fwrite(STDOUT, __METHOD__ . "\n");
|
||||
throw $t;
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@ echo "LOAD ERROR: " . $l->getLoadError() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
echo "TROUGH LOAD: " . $l->getTranslatorClass()->gettext($string) . "<br>";
|
||||
|
||||
$lang = 'en';
|
||||
$domain = 'admin';
|
||||
echo "<br><b>STATIC TYPE TEST</b><br>";
|
||||
// static tests from l10n_load
|
||||
@@ -154,18 +155,30 @@ echo "<br><b>FUNCTIONS</b><br>";
|
||||
// real statisc test
|
||||
L10n::loadFunctions();
|
||||
$locale = 'ja';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
$locale = 'en_US.UTF-8';
|
||||
__setlocale(LC_MESSAGES, $locale);
|
||||
__textdomain($domain);
|
||||
__bindtextdomain($domain, $path);
|
||||
__bind_textdomain_codeset($domain, $encoding);
|
||||
_setlocale(LC_MESSAGES, $locale);
|
||||
_textdomain($domain);
|
||||
_bindtextdomain($domain, $path);
|
||||
_bind_textdomain_codeset($domain, $encoding);
|
||||
echo "INPUT TEST $locale: " . $string . " => " . __($string) . "<br>";
|
||||
$single_string = 'single';
|
||||
$multi_string = 'multi';
|
||||
for ($n = 0; $n <= 3; $n++) {
|
||||
echo "MULTI TEST $n: " . $single_string . "/" . $multi_string . " => "
|
||||
. _ngettext($single_string, $multi_string, $n) . "<br>";
|
||||
}
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ $smarty->setSmartyPaths();
|
||||
// smarty test
|
||||
$smarty->DATA['SMARTY_TEST'] = 'Test Data';
|
||||
$smarty->DATA['TRANSLATE_TEST'] = $l10n->__('Are we translated?');
|
||||
$smarty->DATA['TRANSLATE_TEST_FUNCTION'] = __gettext('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
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
<b>Translate Test with replace:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
|
||||
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
|
||||
Capture test: {$extra_title}<br>
|
||||
{section name=plural_test start=0 loop=3}
|
||||
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<b>Variable variables:</b><br>
|
||||
|
||||
@@ -885,13 +885,13 @@ class Login
|
||||
$this->acl['show_ea_extra'] = false;
|
||||
}
|
||||
// set the default edit access
|
||||
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'];
|
||||
$this->acl['default_edit_access'] = $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||
// integrate the type acl list, but only for the keyword -> level
|
||||
foreach ($this->default_acl_list as $level => $data) {
|
||||
$this->acl['min'][$data['type']] = $level;
|
||||
}
|
||||
// set the full acl list too
|
||||
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'];
|
||||
$this->acl['acl_list'] = $_SESSION['DEFAULT_ACL_LIST'] ?? [];
|
||||
// debug
|
||||
// $this->debug('ACL', $this->print_ar($this->acl));
|
||||
}
|
||||
@@ -1453,7 +1453,8 @@ EOM;
|
||||
* checks that the given edit access id is valid for this user
|
||||
* @param int|null $edit_access_id edit access id to check
|
||||
* @return int|null same edit access id if ok
|
||||
* or the default edit access id if given one is not valid
|
||||
* or the default edit access id
|
||||
* if given one is not valid
|
||||
*/
|
||||
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
||||
{
|
||||
@@ -1463,7 +1464,7 @@ EOM;
|
||||
is_array($_SESSION['UNIT']) &&
|
||||
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
|
||||
) {
|
||||
return (int)$_SESSION['UNIT_DEFAULT'];
|
||||
return $_SESSION['UNIT_DEFAULT'] ?? null;
|
||||
} else {
|
||||
return $edit_access_id;
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
// max id, falls INSERT
|
||||
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
|
||||
if (is_array($res = $this->dbReturnRow($q))) {
|
||||
$pk_id = $res['pkd_id'];
|
||||
$pk_id = $res['pk_id'];
|
||||
} else {
|
||||
$pk_id = 1;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Language\Encoding::__mbMimeEncode -> Convert\MimeEncode::__mbMimeEncode
|
||||
* Langauge\Encoding::checkConvertEncoding -> Check\Encoding::checkConvertEncoding
|
||||
* Langauge\Encoding::setErrorChar -> Check\Encoding::setErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Encoding::getErrorChar
|
||||
* Langauge\Encoding::getErrorChar -> Check\Encoding::getErrorChar
|
||||
* Langauge\Encoding::convertEncoding -> Convert\Encoding::convertEncoding
|
||||
*/
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* __ : returns string (translated or original if not found)
|
||||
* __n : plural string
|
||||
* __p : string with context
|
||||
* __pb: string with context and plural
|
||||
* __np: string with context and plural
|
||||
*
|
||||
* HISTORY:
|
||||
* 2022/4/15 (cs) drop all old folder layout support, new folder base
|
||||
@@ -34,6 +34,8 @@ class L10n
|
||||
{
|
||||
/** @var string the current locale */
|
||||
private $locale = '';
|
||||
/** @var string the SET locale as WHERE the domain file is */
|
||||
private $locale_set = '';
|
||||
/** @var string the default selected/active domain */
|
||||
private $domain = '';
|
||||
/** @var array<string,array<string,GetTextReader>> locale > domain = translator */
|
||||
@@ -141,6 +143,7 @@ class L10n
|
||||
// store old settings
|
||||
$old_mofile = $this->mofile;
|
||||
$old_lang = $this->locale;
|
||||
$old_lang_set = $this->locale_set;
|
||||
$old_domain = $this->domain;
|
||||
$old_base_locale_path = $this->base_locale_path;
|
||||
$old_base_content_path = $this->base_content_path;
|
||||
@@ -172,6 +175,7 @@ class L10n
|
||||
. $this->base_content_path
|
||||
. $domain . '.mo';
|
||||
if (file_exists($this->mofile)) {
|
||||
$this->locale_set = $_locale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -202,6 +206,7 @@ class L10n
|
||||
// else fall back to the old ones
|
||||
$this->mofile = $old_mofile;
|
||||
$this->locale = $old_lang;
|
||||
$this->locale_set = $old_lang_set;
|
||||
$this->domain = $old_domain;
|
||||
$this->base_locale_path = $old_base_locale_path;
|
||||
$this->base_content_path = $old_base_content_path;
|
||||
@@ -454,7 +459,7 @@ class L10n
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set locale
|
||||
* get current set locale (want locale)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -463,6 +468,16 @@ class L10n
|
||||
return $this->locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* current set locale where mo file is located
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLocaleSet(): string
|
||||
{
|
||||
return $this->locale_set;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current set language
|
||||
*
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
<?php
|
||||
|
||||
/*********************************************************************
|
||||
* Original: https://github.com/phpmyadmin/motranslator
|
||||
* Has the same function names, but uses a different base system
|
||||
* setlocale -> setLocale
|
||||
* bindtextdomain -> setTextDomain
|
||||
* textdomain -> setDomain
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use CoreLibs\Language\L10n;
|
||||
use CoreLibs\Language\L10n as Loader;
|
||||
|
||||
/**
|
||||
* Sets a requested locale.
|
||||
@@ -12,9 +20,9 @@ use CoreLibs\Language\L10n;
|
||||
*
|
||||
* @return string Set or current locale
|
||||
*/
|
||||
function __setlocale(int $category, string $locale): string
|
||||
function _setlocale(int $category, string $locale): string
|
||||
{
|
||||
return L10n::getInstance()->setLocale($locale);
|
||||
return Loader::getInstance()->setLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,9 +31,9 @@ function __setlocale(int $category, string $locale): string
|
||||
* @param string $domain Domain name
|
||||
* @param string $path Path where to find locales
|
||||
*/
|
||||
function __bindtextdomain(string $domain, string $path): void
|
||||
function _bindtextdomain(string $domain, string $path): void
|
||||
{
|
||||
L10n::getInstance()->setTextDomain($domain, $path);
|
||||
Loader::getInstance()->setTextDomain($domain, $path);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,7 +47,7 @@ function __bindtextdomain(string $domain, string $path): void
|
||||
* @param string $domain Domain where to set character set
|
||||
* @param string $codeset Character set to set
|
||||
*/
|
||||
function __bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
function _bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
{
|
||||
}
|
||||
|
||||
@@ -48,9 +56,9 @@ function __bind_textdomain_codeset(string $domain, string $codeset): void
|
||||
*
|
||||
* @param string $domain Domain name
|
||||
*/
|
||||
function __textdomain(string $domain): void
|
||||
function _textdomain(string $domain): void
|
||||
{
|
||||
L10n::getInstance()->setDomain($domain);
|
||||
Loader::getInstance()->setDomain($domain);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +68,9 @@ function __textdomain(string $domain): void
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __gettext(string $msgid): string
|
||||
function _gettext(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -76,7 +84,7 @@ function __gettext(string $msgid): string
|
||||
*/
|
||||
function __(string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->gettext(
|
||||
return Loader::getInstance()->getTranslator()->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -90,9 +98,9 @@ function __(string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
function _ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->ngettext(
|
||||
return Loader::getInstance()->getTranslator()->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
@@ -107,9 +115,9 @@ function __ngettext(string $msgid, string $msgidPlural, int $number): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __pgettext(string $msgctxt, string $msgid): string
|
||||
function _pgettext(string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->pgettext(
|
||||
return Loader::getInstance()->getTranslator()->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
@@ -125,9 +133,9 @@ function __pgettext(string $msgctxt, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
function _npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator()->npgettext(
|
||||
return Loader::getInstance()->getTranslator()->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
@@ -143,9 +151,9 @@ function __npgettext(string $msgctxt, string $msgid, string $msgidPlural, int $n
|
||||
*
|
||||
* @return string translated string (or original, if not found)
|
||||
*/
|
||||
function __dgettext(string $domain, string $msgid): string
|
||||
function _dgettext(string $domain, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->gettext(
|
||||
$msgid
|
||||
);
|
||||
}
|
||||
@@ -160,9 +168,9 @@ function __dgettext(string $domain, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||
function _dngettext(string $domain, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->ngettext(
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
$number
|
||||
@@ -178,9 +186,9 @@ function __dngettext(string $domain, string $msgid, string $msgidPlural, int $nu
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
function _dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->pgettext(
|
||||
$msgctxt,
|
||||
$msgid
|
||||
);
|
||||
@@ -197,9 +205,9 @@ function __dpgettext(string $domain, string $msgctxt, string $msgid): string
|
||||
*
|
||||
* @return string translated plural form
|
||||
*/
|
||||
function __dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
function _dnpgettext(string $domain, string $msgctxt, string $msgid, string $msgidPlural, int $number): string
|
||||
{
|
||||
return L10n::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||
return Loader::getInstance()->getTranslator('', '', $domain)->npgettext(
|
||||
$msgctxt,
|
||||
$msgid,
|
||||
$msgidPlural,
|
||||
|
||||
@@ -32,6 +32,8 @@ class SmartyExtend extends \Smarty
|
||||
/** @var string */
|
||||
public $lang;
|
||||
/** @var string */
|
||||
public $locale_set;
|
||||
/** @var string */
|
||||
public $lang_short;
|
||||
/** @var string */
|
||||
public $domain;
|
||||
@@ -170,14 +172,15 @@ class SmartyExtend extends \Smarty
|
||||
// get first part from lang
|
||||
$this->lang_short = explode('_', $locale['lang'])[0];
|
||||
$this->domain = $this->l10n->getDomain();
|
||||
$this->locale_set = $this->l10n->getLocaleSet();
|
||||
$this->lang_dir = $this->l10n->getBaseLocalePath();
|
||||
|
||||
// opt load functions so we can use legacy init for smarty run perhaps
|
||||
$this->l10n->loadFunctions();
|
||||
__setlocale(LC_MESSAGES, $locale['locale']);
|
||||
__textdomain($this->domain);
|
||||
__bindtextdomain($this->domain, $this->lang_dir);
|
||||
__bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
_setlocale(LC_MESSAGES, $locale['locale']);
|
||||
_textdomain($this->domain);
|
||||
_bindtextdomain($this->domain, $this->lang_dir);
|
||||
_bind_textdomain_codeset($this->domain, $this->encoding);
|
||||
|
||||
// register smarty variable
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'getTemplateVars']);
|
||||
@@ -312,16 +315,24 @@ class SmartyExtend extends \Smarty
|
||||
}
|
||||
// javascript translate data as template for auto translate
|
||||
if (empty($this->TEMPLATE_TRANSLATE)) {
|
||||
$this->TEMPLATE_TRANSLATE = 'jsTranslate_' . $this->lang . '.tpl';
|
||||
$this->TEMPLATE_TRANSLATE = 'jsTranslate_'
|
||||
. $this->locale_set . '.' . $this->encoding
|
||||
. '.tpl';
|
||||
} else {
|
||||
// we assume we have some fixed set
|
||||
// we must add _<$this->lang>
|
||||
// if .tpl, put before .tpl
|
||||
// if not .tpl, add _<$this->lang>.tpl
|
||||
if (strpos($this->TEMPLATE_TRANSLATE, '.tpl')) {
|
||||
$this->TEMPLATE_TRANSLATE = str_replace('.tpl', '_' . $this->lang . '.tpl', $this->TEMPLATE_TRANSLATE);
|
||||
$this->TEMPLATE_TRANSLATE = str_replace(
|
||||
'.tpl',
|
||||
'-' . $this->locale_set . '.' . $this->encoding . '.tpl',
|
||||
$this->TEMPLATE_TRANSLATE
|
||||
);
|
||||
} else {
|
||||
$this->TEMPLATE_TRANSLATE .= '_' . $this->lang . '.tpl';
|
||||
$this->TEMPLATE_TRANSLATE .= '_'
|
||||
. $this->locale_set . '.' . $this->encoding
|
||||
. '.tpl';
|
||||
}
|
||||
}
|
||||
// if we can't find it, dump it
|
||||
|
||||
@@ -3,30 +3,19 @@
|
||||
/**
|
||||
* smarty-gettext.php - Gettext support for smarty
|
||||
*
|
||||
* ------------------------------------------------------------------------- *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Lesser General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2.1 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
|
||||
* Lesser General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Lesser General Public *
|
||||
* License along with this library; if not, write to the Free Software *
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
|
||||
* ------------------------------------------------------------------------- *
|
||||
*
|
||||
* To register as a smarty block function named 't', use:
|
||||
* $smarty->register_block('t', 'smarty_translate');
|
||||
*
|
||||
* NOTE: native php support for conext sensitive does not exist
|
||||
* Those jumps are disabled
|
||||
*
|
||||
* @package smarty-gettext
|
||||
* @version $Id: block.t.php 4738 2022-05-06 01:28:48Z clemens $
|
||||
* @link http://smarty-gettext.sf.net/
|
||||
* @author Sagi Bashari <sagi@boom.org.il>
|
||||
* @copyright 2004 Sagi Bashari
|
||||
* @copyright Elan Ruusamäe
|
||||
* @copyright Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,7 +28,7 @@
|
||||
*/
|
||||
function smarty_gettext_strarg($str/*, $varargs... */)
|
||||
{
|
||||
$tr = array();
|
||||
$tr = [];
|
||||
$p = 0;
|
||||
|
||||
$nargs = func_num_args();
|
||||
@@ -68,14 +57,18 @@ function smarty_gettext_strarg($str/*, $varargs... */)
|
||||
* - escape - sets escape mode:
|
||||
* - 'html' for HTML escaping, this is the default.
|
||||
* - 'js' for javascript escaping.
|
||||
* - 'url' for url escaping.
|
||||
* - 'no'/'off'/0 - turns off escaping
|
||||
* - plural - The plural version of the text (2nd parameter of ngettext())
|
||||
* - count - The item count for plural mode (3rd parameter of ngettext())
|
||||
* - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
|
||||
* - context - gettext context. reserved for future use.
|
||||
*
|
||||
*/
|
||||
|
||||
// cs modified: __ calls instead of direct gettext calls
|
||||
|
||||
function smarty_block_t($params, $text, $template, &$repeat)
|
||||
function smarty_block_t($params, $text)
|
||||
{
|
||||
if (!isset($text)) {
|
||||
return $text;
|
||||
@@ -120,55 +113,54 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
||||
// use plural if required parameters are set
|
||||
if (isset($count) && isset($plural)) {
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('__dnpgettext')) {
|
||||
$text = __dnpgettext($domain, $context, $text, $plural, $count);
|
||||
}
|
||||
if (is_callable('_dnpgettext')) {
|
||||
$text = _dnpgettext($domain, $context, $text, $plural, $count);
|
||||
}/* elseif (is_callable('dnpgettext')) {
|
||||
$text = dnpgettext($domain, $context, $text, $plural, $count);
|
||||
} */
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('__dngettext')) {
|
||||
$text = __dngettext($domain, $text, $plural, $count);
|
||||
if (is_callable('_dngettext')) {
|
||||
$text = _dngettext($domain, $text, $plural, $count);
|
||||
} elseif (is_callable('dngettext')) {
|
||||
$text = dngettext($domain, $text, $plural, $count);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('__npgettext')) {
|
||||
$text == __npgettext($context, $text, $plural, $count);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__pn')
|
||||
) {
|
||||
$text = $template->l10n->__pn($text, $plural, $count);
|
||||
if (is_callable('_npgettext')) {
|
||||
$text = _npgettext($context, $text, $plural, $count);
|
||||
}/* elseif (is_callable('npgettext')) {
|
||||
$text = npgettext($context, $text, $plural, $count);
|
||||
} */
|
||||
} else {
|
||||
if (is_callable('_ngettext')) {
|
||||
$text = _ngettext($text, $plural, $count);
|
||||
} elseif (is_callable('ngettext')) {
|
||||
$text = ngettext($text, $plural, $count);
|
||||
}
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__n')
|
||||
) {
|
||||
$text = $template->l10n->__n($text, $plural, $count);
|
||||
// $text == __ngettext($text, $plural, $count);
|
||||
}
|
||||
} else { // use normal
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('__dpgettext')) {
|
||||
$text = __dpgettext($domain, $context, $text);
|
||||
}
|
||||
if (is_callable('_dpgettext')) {
|
||||
$text = _dpgettext($domain, $context, $text);
|
||||
}/* elseif (is_callable('dpgettext')) {
|
||||
$text = dpgettext($domain, $context, $text);
|
||||
} */
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('__dgettext')) {
|
||||
$text = __dgettext($domain, $text);
|
||||
if (is_callable('_dgettext')) {
|
||||
$text = _dgettext($domain, $text);
|
||||
} elseif (is_callable('dpgettext')) {
|
||||
$text = dgettext($domain, $text);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('__pgettext')) {
|
||||
$text = __pgettext($context, $text);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__p')
|
||||
) {
|
||||
$text = $template->l10n->__p($context, $text);
|
||||
}
|
||||
if (is_callable('_pgettext')) {
|
||||
$text = _pgettext($context, $text);
|
||||
}/* elseif (is_callable('pgettext')) {
|
||||
$text = pgettext($context, $text);
|
||||
} */
|
||||
} else {
|
||||
if (is_callable('__gettext')) {
|
||||
$text = __gettext($text);
|
||||
} elseif (
|
||||
$template->l10n instanceof \CoreLibs\Language\L10n &&
|
||||
method_exists($template->l10n, '__')
|
||||
) {
|
||||
$text = $template->l10n->__($text);
|
||||
if (is_callable('_gettext')) {
|
||||
$text = _gettext($text);
|
||||
} elseif (is_callable('gettext')) {
|
||||
$text = gettext($text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,6 +172,7 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
||||
|
||||
switch ($escape) {
|
||||
case 'html':
|
||||
// default
|
||||
$text = nl2br(htmlspecialchars($text));
|
||||
break;
|
||||
case 'javascript':
|
||||
@@ -187,13 +180,29 @@ function smarty_block_t($params, $text, $template, &$repeat)
|
||||
// javascript escape
|
||||
$text = strtr(
|
||||
$text,
|
||||
array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/')
|
||||
[
|
||||
'\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/'
|
||||
]
|
||||
);
|
||||
break;
|
||||
case 'url':
|
||||
// url escape
|
||||
$text = urlencode($text);
|
||||
break;
|
||||
// below is a list for explicit OFF
|
||||
case 'no':
|
||||
case 'off':
|
||||
case 'false':
|
||||
case '0':
|
||||
case 0:
|
||||
// explicit OFF
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
Reference in New Issue
Block a user