Updates for phpstan 1.0 level 8, fix spaces in config.master.php, add phpunit tets for math, email; update email class with more check methods
This commit is contained in:
@@ -10,6 +10,9 @@ TARGET_HOST_WEB="<user>@<host>";
|
||||
TMP_DIR=$LOCAL_BASE_DIR"/4dev/tmp/";
|
||||
tmpf_web=$TMP_DIR"sync.exclude.tmp";
|
||||
|
||||
# if vendor be sure group folder is +x
|
||||
chmod -R ug+rX ${LOCAL_DIR}/vender/
|
||||
|
||||
# for web (ika)
|
||||
rm -f $tmpf_web;
|
||||
echo ".*.swp" >> $tmpf_web;
|
||||
@@ -35,20 +38,19 @@ cat $tmpf_web;
|
||||
|
||||
echo "($1) Syncing from $LOCAL_DIR/* to $TARGET_HOST_WEB:$REMOTE_WEB";
|
||||
echo "You hav 5 seconds to abort (<ctrl> + c)";
|
||||
#c=0;until [ $c -eq 10 ];do echo -n "#"; sleep 1; c=`expr $c + 1`;done;
|
||||
for ((i=5;i>=1;i--));
|
||||
do
|
||||
echo -n $i" ";
|
||||
sleep 1;
|
||||
echo -n $i" ";
|
||||
sleep 1;
|
||||
done;
|
||||
|
||||
if [ "$1" = "live" ];
|
||||
then
|
||||
# ika sync
|
||||
rsync -Plzvrupt --stats --include ".htaccess" --exclude-from=$tmpf_web --delete -e ssh $LOCAL_DIR/* $TARGET_HOST_WEB:$REMOTE_WEB
|
||||
# live sync
|
||||
rsync -Plzvrupt --stats --include ".htaccess" --exclude-from=$tmpf_web --delete -e ssh $LOCAL_DIR/* $TARGET_HOST_WEB:$REMOTE_WEB
|
||||
else
|
||||
# ika sync
|
||||
rsync -n -Plzvrupt --stats --include ".htaccess" --exclude-from=$tmpf_web --delete -e ssh $LOCAL_DIR/* $TARGET_HOST_WEB:$REMOTE_WEB
|
||||
# test sync
|
||||
rsync -n -Plzvrupt --stats --include ".htaccess" --exclude-from=$tmpf_web --delete -e ssh $LOCAL_DIR/* $TARGET_HOST_WEB:$REMOTE_WEB
|
||||
fi;
|
||||
|
||||
# END
|
||||
|
||||
373
4dev/tests/CoreLibsCheckEmailTest.php
Normal file
373
4dev/tests/CoreLibsCheckEmailTest.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @testdox CoreLibs\Check\Email method tests
|
||||
*/
|
||||
final class CoreLibsCheckEmailTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Array position to regex
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailRegexProvider(): array
|
||||
{
|
||||
return [
|
||||
'get email regex invalid -1, will be 0' => [
|
||||
-1,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
],
|
||||
'get email regex invalid 10, will be 0' => [
|
||||
10,
|
||||
"^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
],
|
||||
'get email regex valid 1, will be 1' => [
|
||||
1,
|
||||
"@(.*)@(.*)"
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test regex level return
|
||||
*
|
||||
* @dataProvider emailRegexProvider
|
||||
* @testdox Email::getEmailRegex $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param int $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailRegexReturn(int $input, string $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailRegex($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* provides data for emailCheckProvider and emailCheckFullProvider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckList(): array
|
||||
{
|
||||
return [
|
||||
'valid email' => ['test@test.com', true, []],
|
||||
'invalid empty email' => ['', false, [0, 2, 3, 4, 5]],
|
||||
'invalid email' => ['-@-', false, [0, 3, 4, 5]],
|
||||
'invalid email leading dot' => ['.test@test.com', false, [0, 2]],
|
||||
'invalid email invalid domain' => ['test@t_est.com', false, [0, 3, 4]],
|
||||
'invalid email double @' => ['test@@test.com', false, [0, 1]],
|
||||
'invalid email double dot' => ['test@test..com', false, [0, 3, 6]],
|
||||
'invalid email end with dot' => ['test@test.', false, [0, 3, 5, 7]],
|
||||
'invalid email bad top level' => ['test@test.j', false, [0, 3, 5]],
|
||||
'invalid email double @ and double dot' => ['test@@test..com', false, [0, 1, 3, 6]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Valids or not valid email address
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailCheckList() as $key => $data) {
|
||||
$list[$key] = [$data[0], $data[1]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailCheckProvider
|
||||
* @testdox Email::checkEmail $input will be $expected [$_dataName]
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckEmail(string $input, bool $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::checkEmail($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* this is like emailCheckProvider but it has the full detail errors
|
||||
* All errors should be tetsed in testGetEmailRegexErrorMessage
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailCheckFullProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailCheckList() as $key => $data) {
|
||||
$list[$key] = [$data[0], $data[2]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailCheckFullProvider
|
||||
* @testdox Email::checkEmailFull $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testCheckEmailFull(string $input, array $expected): void
|
||||
{
|
||||
$this->assertEqualsCanonicalizing(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::checkEmailFull($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* error data returned for each error position
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailRegexErrorProvider(): array
|
||||
{
|
||||
return [
|
||||
'error 0 will return general' => [
|
||||
0,
|
||||
[
|
||||
'error' => 0,
|
||||
'message' => 'Invalid email address',
|
||||
'regex' => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
]
|
||||
],
|
||||
'error 1 will return double @ error' => [
|
||||
1,
|
||||
[
|
||||
'error' => 1,
|
||||
'message' => 'Double @ mark in email address',
|
||||
'regex' => "@(.*)@(.*)"
|
||||
]
|
||||
],
|
||||
'error 2 will be invalid before @' => [
|
||||
2,
|
||||
[
|
||||
'error' => 2,
|
||||
'message' => 'Invalid email part before @ sign',
|
||||
'regex' => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
]
|
||||
],
|
||||
'error 3 will be invalid domain and top level' => [
|
||||
3,
|
||||
[
|
||||
'error' => 3,
|
||||
'message' => 'Invalid domain part after @ sign',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$"
|
||||
]
|
||||
],
|
||||
'error 4 will be invalid domain' => [
|
||||
4,
|
||||
[
|
||||
'error' => 4,
|
||||
'message' => 'Invalid domain name part',
|
||||
'regex' => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\."
|
||||
]
|
||||
],
|
||||
'error 5 will be invalid domain top level only' => [
|
||||
5,
|
||||
[
|
||||
'error' => 5,
|
||||
'message' => 'Wrong domain top level part',
|
||||
'regex' => "\.([a-zA-Z]{2,6}){1}$"
|
||||
]
|
||||
],
|
||||
'error 6 will be domain double dot' => [
|
||||
6,
|
||||
[
|
||||
'error' => 6,
|
||||
'message' => 'Double consecutive dots in domain name (..)',
|
||||
'regex' => "@(.*)\.{2,}"
|
||||
]
|
||||
],
|
||||
'error 7 will domain ends with dot' => [
|
||||
7,
|
||||
[
|
||||
'error' => 7,
|
||||
'message' => 'Domain ends with a dot or is missing top level part',
|
||||
'regex' => "@.*\.$"
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailRegexErrorProvider
|
||||
* @testdox Email::getEmailRegexErrorMessage $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param integer $input
|
||||
* @param array $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailRegexErrorMessage(int $input, array $expected): void
|
||||
{
|
||||
$this->assertEqualsCanonicalizing(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailRegexErrorMessage($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This holds all email type checks normal and short
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailTypeProvider(): array
|
||||
{
|
||||
return [
|
||||
['test@test.com', 'pc_html', 'pc'],
|
||||
['test@docomo.ne.jp', 'keitai_docomo', 'docomo'],
|
||||
['test@softbank.ne.jp', 'keitai_softbank', 'softbank'],
|
||||
['test@i.softbank.ne.jp', 'smartphone_softbank_iphone', 'iphone'],
|
||||
// TODO: add more test emails here
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns only normal email type checks
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailTypeProviderLong(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailTypeProvider() as $set) {
|
||||
$list['email ' . $set[0] . ' is valid and matches normal ' . $set[1]] = [$set[0], $set[1]];
|
||||
}
|
||||
$list['email is empty and not valid normal'] = ['', 'invalid'];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* only short email type list
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function emailTypeProviderShort(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->emailTypeProvider() as $set) {
|
||||
$list['email ' . $set[0] . ' is valid and matches short ' . $set[2]] = [$set[0], $set[2]];
|
||||
}
|
||||
$list['email is empty and not valid short'] = ['', 'invalid'];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailTypeProviderLong
|
||||
* @testdox Email::getEmailType $input will be normal $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailTypeNormal(string $input, string $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailType($input, false)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailTypeProviderShort
|
||||
* @testdox Email::getEmailType $input will be short $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetEmailTypeShort(string $input, string $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getEmailType($input, true)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emailProviderTypeLongToShort(): array
|
||||
{
|
||||
$mobile_email_type_short = [
|
||||
'keitai_docomo' => 'docomo',
|
||||
'keitai_kddi_ezweb' => 'kddi',
|
||||
'keitai_kddi' => 'kddi',
|
||||
'keitai_kddi_tu-ka' => 'kddi',
|
||||
'keitai_kddi_sky' => 'kddi',
|
||||
'keitai_softbank' => 'softbank',
|
||||
'smartphone_softbank_iphone' => 'iphone',
|
||||
'keitai_softbank_disney' => 'softbank',
|
||||
'keitai_softbank_vodafone' => 'softbank',
|
||||
'keitai_softbank_j-phone' => 'softbank',
|
||||
'keitai_willcom' => 'willcom',
|
||||
'keitai_willcom_pdx' => 'willcom',
|
||||
'keitai_willcom_bandai' => 'willcom',
|
||||
'keitai_willcom_pipopa' => 'willcom',
|
||||
'keitai_willcom_ymobile' => 'willcom',
|
||||
'keitai_willcom_emnet' => 'willcom',
|
||||
'pc_html' => 'pc',
|
||||
];
|
||||
$list = [];
|
||||
// use the static one
|
||||
foreach ($mobile_email_type_short as $long => $short) {
|
||||
$list[$long . ' matches to ' . $short] = [$long, $short];
|
||||
}
|
||||
// add invalid check
|
||||
$list['Not found will be bool false'] = ['invalid', false];
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider emailProviderTypeLongToShort
|
||||
* @testdox Email::getShortEmailType $input will be $expected [$_dataName]
|
||||
*
|
||||
* @param string $input
|
||||
* @param string|bool $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetShortEmailType(string $input, $expected)
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\Email::getShortEmailType($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
40
4dev/tests/CoreLibsCheckFileTest.php
Normal file
40
4dev/tests/CoreLibsCheckFileTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @testdox CoreLibs\Convert\Math method tests
|
||||
*/
|
||||
final class CoreLibsCheckFileTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
// write a dummy file for testing
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// unlink file
|
||||
}
|
||||
|
||||
public function testGetFilenameEnding(string $input, string $expected): void
|
||||
{
|
||||
// getFilenameEnding
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getFilenameEnding($input)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetLinesFromFile(): void
|
||||
{
|
||||
// getLinesFromFile
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,10 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Tests for
|
||||
* \CoreLibs\Convert\Math
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
@@ -17,11 +12,10 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
final class CoreLibsConvertMathTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function fceilProvider(): array
|
||||
{
|
||||
@@ -38,7 +32,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
* @dataProvider fceilProvider
|
||||
* @testdox Math::fceil: Input $input must be $expected
|
||||
*
|
||||
* @param int $input
|
||||
* @param float $input
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
@@ -53,7 +47,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function floorProvider(): array
|
||||
{
|
||||
@@ -85,7 +79,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function initNumericProvider(): array
|
||||
{
|
||||
@@ -105,6 +99,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
*
|
||||
* @param int|float|string $input
|
||||
* @param float $expected
|
||||
* @param string $info
|
||||
* @return void
|
||||
*/
|
||||
public function testMathInitNumericValue($input, float $expected, string $info): void
|
||||
@@ -122,7 +117,7 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
* @testWith [123.123, 123.123, "float"]
|
||||
* ["123.123", 123.123, "string"]
|
||||
*
|
||||
* @param [type] $input
|
||||
* @param int|float|string $input
|
||||
* @param float $expected
|
||||
* @param string $info
|
||||
* @return void
|
||||
@@ -135,3 +130,5 @@ final class CoreLibsConvertMathTest extends TestCase
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
10
phpstan.neon
10
phpstan.neon
@@ -2,7 +2,7 @@
|
||||
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs
|
||||
level: max
|
||||
level: 8 # max is now 9
|
||||
paths:
|
||||
- %currentWorkingDirectory%/www
|
||||
bootstrapFiles:
|
||||
@@ -18,7 +18,7 @@ parameters:
|
||||
# - www/lib/autoloader.php
|
||||
- www/vendor/autoload.php
|
||||
- www/lib/Smarty/Autoloader.php
|
||||
excludes_analyse:
|
||||
excludePaths:
|
||||
# do not check old qq file uploader tests
|
||||
- www/admin/qq_file_upload_*.php
|
||||
# ignore all test files
|
||||
@@ -39,14 +39,16 @@ parameters:
|
||||
- www/media
|
||||
- www/tmp
|
||||
# external libs are not checked
|
||||
- www/lib/pChart*
|
||||
- www/lib/Smarty*
|
||||
- www/lib/Smarty/
|
||||
- www/lib/smarty-*/
|
||||
# ignore composer
|
||||
- www/vendor
|
||||
# ignore tst folder
|
||||
- www/tests
|
||||
# ignore errores with
|
||||
ignoreErrors:
|
||||
# this is ignored for now
|
||||
- '#Expression in empty\(\) is always falsy.#'
|
||||
# -
|
||||
# message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#'
|
||||
# path: www/includes/edit_base.php
|
||||
|
||||
@@ -125,10 +125,18 @@ print "DIRECT INSERT NO RETURN STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
$last_insert_pk = $db->dbGetInsertPK();
|
||||
|
||||
// is_array read test
|
||||
$q = "SELECT test_foo_id, test FROM test_foo WHERE test_foo_id = " . $last_insert_pk;
|
||||
if (is_array($s_res = $db->dbReturnRow($q)) && !empty($s_res['test'])) {
|
||||
print "WE HAVE DATA FOR: " . $last_insert_pk . " WITH: " . $s_res['test'] . "<br>";
|
||||
}
|
||||
|
||||
// UPDATE WITH RETURNING
|
||||
$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT' WHERE test_foo_id = 3688452 RETURNING test");
|
||||
print "UPDATE WITH RETURN STATUS: $status | "
|
||||
$status = $db->dbExec("UPDATE test_foo SET test = 'SOMETHING DIFFERENT' "
|
||||
. "WHERE test_foo_id = " . $last_insert_pk . " RETURNING test");
|
||||
print "UPDATE WITH PK " . $last_insert_pk . " RETURN STATUS: $status | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ print "S::GETEMAILREGEX(2): " . Email::getEmailRegex(2) . "<br>";
|
||||
print "S::GETEMAILREGEX(7): " . Email::getEmailRegex(7) . "<br>";
|
||||
print "S::GETEMAILREGEX(8 invalid): " . Email::getEmailRegex(8) . "<br>";
|
||||
print "S::GETEMAILREGEXCHECK: " . DgS::printAr(Email::getEmailRegexCheck()) . "<br>";
|
||||
print "S::GETEMAILREGEXERRORMESSAGE " . Dgs::printAr(Email::getEmailRegexErrorMessage(1)) . "<br>";
|
||||
|
||||
$email = [
|
||||
'foo@bar.org',
|
||||
@@ -53,6 +54,23 @@ foreach ($email as $s_email) {
|
||||
print "S::EMAIL: $s_email: " . Email::getEmailType($s_email) . "<br>";
|
||||
print "S::EMAIL SHORT: $s_email: " . Email::getEmailType($s_email, true) . "<br>";
|
||||
}
|
||||
$email = [
|
||||
'test@test.com',
|
||||
'',
|
||||
'-@-',
|
||||
'.test@test.com',
|
||||
'test@t_est.com',
|
||||
'test@@test.com',
|
||||
'test@test..com',
|
||||
'test@@test..com',
|
||||
'test@test.',
|
||||
'test@test.j',
|
||||
];
|
||||
foreach ($email as $s_email) {
|
||||
print "S::CHECKEMAIL: " . $s_email . ": " . (Email::checkEmail($s_email) ? 'Yes' : 'No') . "<br>";
|
||||
print "S::CHECKEMAILFULL: " . $s_email . ": " . Dgs::printAr(Email::checkEmailFull($s_email)) . "<br>";
|
||||
print "S::CHECKEMAILFULL(true): " . $s_email . ": " . Dgs::printAr(Email::checkEmailFull($s_email, true)) . "<br>";
|
||||
}
|
||||
// DEPRECATED
|
||||
/* foreach ($email as $s_email) {
|
||||
print "D/S-EMAIL: $s_email: ".$basic->getEmailType($s_email)."<br>";
|
||||
|
||||
@@ -21,62 +21,62 @@ define('BASE', str_replace('/configs', '', __DIR__) . DS);
|
||||
|
||||
// ** OLD DIR DECLARATIONS **
|
||||
// path to document root of file called
|
||||
define('ROOT', getcwd() . DS);
|
||||
define('ROOT', getcwd() . DS);
|
||||
// libs path
|
||||
define('LIB', 'lib' . DS);
|
||||
define('LIBS', 'lib' . DS);
|
||||
define('LIB', 'lib' . DS);
|
||||
define('LIBS', 'lib' . DS);
|
||||
// configs folder
|
||||
define('CONFIGS', 'configs' . DS);
|
||||
define('CONFIGS', 'configs' . DS);
|
||||
// includes (strings, arrays for static, etc)
|
||||
define('INCLUDES', 'includes' . DS);
|
||||
define('INCLUDES', 'includes' . DS);
|
||||
// data folder (mostly in includes, or root for internal data)
|
||||
define('DATA', 'data' . DS);
|
||||
define('DATA', 'data' . DS);
|
||||
// layout base path
|
||||
define('LAYOUT', 'layout' . DS);
|
||||
define('LAYOUT', 'layout' . DS);
|
||||
// pic-root (compatible to CMS)
|
||||
define('PICTURES', 'images' . DS);
|
||||
define('PICTURES', 'images' . DS);
|
||||
// images
|
||||
define('IMAGES', 'images' . DS);
|
||||
define('IMAGES', 'images' . DS);
|
||||
// icons (below the images/ folder)
|
||||
define('ICONS', 'icons' . DS);
|
||||
define('ICONS', 'icons' . DS);
|
||||
// media (accessable from outside)
|
||||
define('MEDIA', 'media' . DS);
|
||||
define('MEDIA', 'media' . DS);
|
||||
// uploads (anything to keep or data)
|
||||
define('UPLOADS', 'uploads' . DS);
|
||||
define('UPLOADS', 'uploads' . DS);
|
||||
// files (binaries) (below media or data)
|
||||
define('BINARIES', 'binaries' . DS);
|
||||
define('BINARIES', 'binaries' . DS);
|
||||
// files (videos) (below media or data)
|
||||
define('VIDEOS', 'videos' . DS);
|
||||
define('VIDEOS', 'videos' . DS);
|
||||
// files (documents) (below media or data)
|
||||
define('DOCUMENTS', 'documents' . DS);
|
||||
define('DOCUMENTS', 'documents' . DS);
|
||||
// files (pdfs) (below media or data)
|
||||
define('PDFS', 'documents' . DS);
|
||||
define('PDFS', 'documents' . DS);
|
||||
// files (general) (below media or data)
|
||||
define('FILES', 'files' . DS);
|
||||
define('FILES', 'files' . DS);
|
||||
// CSV
|
||||
define('CSV', 'csv' . DS);
|
||||
define('CSV', 'csv' . DS);
|
||||
// css
|
||||
define('CSS', 'css' . DS);
|
||||
define('CSS', 'css' . DS);
|
||||
// font (web)
|
||||
define('FONT', 'font' . DS);
|
||||
define('FONT', 'font' . DS);
|
||||
// js
|
||||
define('JS', 'javascript' . DS);
|
||||
define('JS', 'javascript' . DS);
|
||||
// table arrays
|
||||
define('TABLE_ARRAYS', 'table_arrays' . DS);
|
||||
define('TABLE_ARRAYS', 'table_arrays' . DS);
|
||||
// smarty libs path
|
||||
define('SMARTY', 'Smarty' . DS);
|
||||
define('SMARTY', 'Smarty' . DS);
|
||||
// po langs
|
||||
define('LANG', 'lang' . DS);
|
||||
define('LANG', 'lang' . DS);
|
||||
// cache path
|
||||
define('CACHE', 'cache' . DS);
|
||||
define('CACHE', 'cache' . DS);
|
||||
// temp path
|
||||
define('TMP', 'tmp' . DS);
|
||||
define('TMP', 'tmp' . DS);
|
||||
// log files
|
||||
define('LOG', 'log' . DS);
|
||||
define('LOG', 'log' . DS);
|
||||
// compiled template folder
|
||||
define('TEMPLATES_C', 'templates_c' . DS);
|
||||
define('TEMPLATES_C', 'templates_c' . DS);
|
||||
// template base
|
||||
define('TEMPLATES', 'templates' . DS);
|
||||
define('TEMPLATES', 'templates' . DS);
|
||||
|
||||
/************* HASH / ACL DEFAULT / ERROR SETTINGS / SMARTY *************/
|
||||
// default hash type
|
||||
@@ -212,7 +212,7 @@ list($HOST_NAME) = array_pad(explode(':', $_SERVER['HTTP_HOST'], 2), 2, null);
|
||||
define('HOST_NAME', $HOST_NAME);
|
||||
// BAIL ON MISSING MASTER SITE CONFIG
|
||||
if (!isset($SITE_CONFIG[HOST_NAME]['location'])) {
|
||||
echo 'Missing SITE_CONFIG entry for: "' . HOST_NAME . '" . Contact Administrator';
|
||||
echo 'Missing SITE_CONFIG entry for: "' . HOST_NAME . '" . Contact Administrator';
|
||||
exit;
|
||||
}
|
||||
// BAIL ON MISSING DB CONFIG:
|
||||
@@ -229,7 +229,7 @@ if (
|
||||
(is_array($DB_CONFIG) && count($DB_CONFIG) && !isset($DB_CONFIG[$SITE_CONFIG[HOST_NAME]['db_host']])))
|
||||
)
|
||||
) {
|
||||
echo 'No matching DB config found for: "' . HOST_NAME . '" . Contact Administrator';
|
||||
echo 'No matching DB config found for: "' . HOST_NAME . '" . Contact Administrator';
|
||||
exit;
|
||||
}
|
||||
// set SSL on
|
||||
|
||||
@@ -98,7 +98,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
/** @var bool */
|
||||
private $password_forgot = false;
|
||||
/** @var bool */
|
||||
private $password_forgot_ok = false; // password forgot mail send ok
|
||||
// private $password_forgot_ok = false; // password forgot mail send ok
|
||||
/** @var string */
|
||||
private $change_password;
|
||||
/** @var string */
|
||||
@@ -196,7 +196,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false;
|
||||
// set the default lang
|
||||
$lang = 'en_utf8';
|
||||
if (session_id() && isset($_SESSION['DEFAULT_LANG']) && $_SESSION['DEFAULT_LANG']) {
|
||||
if (session_id() !== false && !empty($_SESSION['DEFAULT_LANG'])) {
|
||||
$lang = $_SESSION['DEFAULT_LANG'];
|
||||
} else {
|
||||
$lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
|
||||
@@ -922,8 +922,11 @@ class Login extends \CoreLibs\DB\IO
|
||||
. "FROM edit_user "
|
||||
. "WHERE enabled = 1 "
|
||||
. "AND username = '" . $this->dbEscapeString($this->pw_username) . "'";
|
||||
list ($edit_user_id) = $this->dbReturnRow($q);
|
||||
if (!$edit_user_id) {
|
||||
$res = $this->dbReturnRow($q);
|
||||
if (
|
||||
!is_array($res) ||
|
||||
(is_array($res) && empty($res['edit_user_id']))
|
||||
) {
|
||||
// username wrong
|
||||
$this->login_error = 201;
|
||||
$data = 'User could not be found';
|
||||
@@ -935,8 +938,17 @@ class Login extends \CoreLibs\DB\IO
|
||||
. "FROM edit_user "
|
||||
. "WHERE enabled = 1 "
|
||||
. "AND username = '" . $this->dbEscapeString($this->pw_username) . "'";
|
||||
list ($edit_user_id, $old_password_hash) = $this->dbReturnRow($q);
|
||||
if (!$edit_user_id || !$this->loginPasswordCheck($old_password_hash, $this->pw_old_password)) {
|
||||
$edit_user_id = '';
|
||||
$res = $this->dbReturnRow($q);
|
||||
if (is_array($res)) {
|
||||
$edit_user_id = $res['edit_user_id'];
|
||||
}
|
||||
if (
|
||||
!is_array($res) ||
|
||||
(is_array($res) &&
|
||||
(empty($res['edit_user_id']) ||
|
||||
!$this->loginPasswordCheck($res['old_password_hash'], $this->pw_old_password)))
|
||||
) {
|
||||
// old password wrong
|
||||
$this->login_error = 202;
|
||||
$data = 'The old password does not match';
|
||||
@@ -1096,7 +1108,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
// write to LOG table ...
|
||||
if ($this->login_error || $this->login || $this->logout) {
|
||||
$username = '';
|
||||
$password = '';
|
||||
// $password = '';
|
||||
// set event
|
||||
if ($this->login) {
|
||||
$event = 'Login';
|
||||
@@ -1109,7 +1121,10 @@ class Login extends \CoreLibs\DB\IO
|
||||
if ($this->euid) {
|
||||
// get user from user table
|
||||
$q = "SELECT username FROM edit_user WHERE edit_user_id = " . $this->euid;
|
||||
list($username) = $this->dbReturnRow($q);
|
||||
$username = '';
|
||||
if (is_array($res = $this->dbReturnRow($q))) {
|
||||
$username = $res['username'];
|
||||
}
|
||||
} // if euid is set, get username (or try)
|
||||
$this->writeLog($event, '', $this->login_error, $username);
|
||||
} // write log under certain settings
|
||||
|
||||
@@ -81,7 +81,7 @@ class Basic
|
||||
/** @var string */
|
||||
private $session_name = '';
|
||||
/** @var string */
|
||||
private $session_id = '';
|
||||
private $session_id = ''; /** @phpstan-ignore-line */
|
||||
|
||||
// ajax flag
|
||||
/** @var bool */
|
||||
@@ -164,7 +164,7 @@ class Basic
|
||||
// start session
|
||||
session_start();
|
||||
// set internal session id, we can use that later for protection check
|
||||
$this->session_id = session_id() ?: '';
|
||||
$this->session_id = (string)session_id();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1173,24 +1173,6 @@ class Basic
|
||||
|
||||
// *** UIDS END
|
||||
|
||||
// *** BETTER PASSWORD OPTIONS, must be used ***
|
||||
// [!!! DEPRECATED !!!]
|
||||
// moved to \CoreLibs\Check\Password
|
||||
/**
|
||||
* inits the password options set
|
||||
* currently this is et empty, and the default options are used
|
||||
* @return void has no reutrn
|
||||
* @deprecated use This function has been removed
|
||||
*/
|
||||
private function passwordInit(): void
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' has been removed', E_USER_DEPRECATED);
|
||||
/* // set default password cost: use default set automatically
|
||||
$this->password_options = [
|
||||
// 'cost' => PASSWORD_BCRYPT_DEFAULT_COST
|
||||
]; */
|
||||
}
|
||||
|
||||
/**
|
||||
* creates the password hash
|
||||
* @param string $password password
|
||||
|
||||
@@ -12,13 +12,25 @@ class Email
|
||||
0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
|
||||
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
|
||||
1 => "@(.*)@(.*)", // double @
|
||||
2 => "^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
|
||||
2 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
|
||||
3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
|
||||
4 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.", // wrong domain name part
|
||||
5 => "\.([a-zA-Z]{2,6}){1}$", // wrong top level part
|
||||
6 => "@(.*)\.{2,}", // double .. in domain name part
|
||||
7 => "@.*\.$" // ends with a dot, top level, domain missing
|
||||
];
|
||||
// for above position, description string below
|
||||
/** @var array<int,string> */
|
||||
private static $email_regex_check_message = [
|
||||
0 => 'Invalid email address',
|
||||
1 => 'Double @ mark in email address',
|
||||
2 => 'Invalid email part before @ sign',
|
||||
3 => 'Invalid domain part after @ sign',
|
||||
4 => 'Invalid domain name part',
|
||||
5 => 'Wrong domain top level part',
|
||||
6 => 'Double consecutive dots in domain name (..)',
|
||||
7 => 'Domain ends with a dot or is missing top level part'
|
||||
];
|
||||
// the array with the mobile types that are valid
|
||||
/** @var array<string,string> */
|
||||
private static $mobile_email_type = [
|
||||
@@ -100,7 +112,7 @@ class Email
|
||||
];
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* get one position from the regex check list
|
||||
*
|
||||
* @param int $type Which position in the regex list to get
|
||||
* if not set or not valid get default pos 0
|
||||
@@ -116,8 +128,10 @@ class Email
|
||||
}
|
||||
|
||||
/**
|
||||
* get the full check array
|
||||
* this will be deprected at some point
|
||||
* get the full check array, except position 0, but preserve keys
|
||||
* Currently used to add per error level type from
|
||||
* getEmailRegex to error reporting
|
||||
* Might be deprecated at some point
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
@@ -132,6 +146,22 @@ class Email
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns error message for email ergex error, or empty string if not set
|
||||
*
|
||||
* @param int $error
|
||||
* @return array<string,string|int> Error message and regex
|
||||
*/
|
||||
public static function getEmailRegexErrorMessage(int $error): array
|
||||
{
|
||||
// return error message and regex
|
||||
return [
|
||||
'error' => $error,
|
||||
'message' => self::$email_regex_check_message[$error] ?? '',
|
||||
'regex' => self::$email_regex_check[$error] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* guesses the email type (mostly for mobile) from the domain
|
||||
* if second is set to true, it will return short naming scheme (only provider)
|
||||
@@ -180,6 +210,54 @@ class Email
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* simple email check with the basic email eregex
|
||||
*
|
||||
* @param string $email Email address, will be checkd as lower
|
||||
* @return bool True if email is ok, or false if regex failed
|
||||
*/
|
||||
public static function checkEmail(string $email): bool
|
||||
{
|
||||
$email_regex = self::getEmailRegex();
|
||||
if (!preg_match("/$email_regex/", strtolower($email))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $email Email address, will be checkd as lower
|
||||
* @param bool $error_code_only If this is set to true it will only return
|
||||
* the error pos, instead of detailed array
|
||||
* @return array<mixed> Errors as array with message and regex
|
||||
*/
|
||||
public static function checkEmailFull(string $email, bool $error_code_only = false): array
|
||||
{
|
||||
$errors = [];
|
||||
foreach (self::$email_regex_check as $pos => $email_regex) {
|
||||
$match = preg_match("/$email_regex/", strtolower($email));
|
||||
// if the first does not fail, quit as ok
|
||||
if ($pos == 0 && $match) {
|
||||
break;
|
||||
}
|
||||
// else do error storage
|
||||
// not that for 1, 6, 7 the regex is matching
|
||||
if (
|
||||
(!$match && in_array($pos, [0, 2, 3, 4, 5])) ||
|
||||
($match && in_array($pos, [1, 6, 7]))
|
||||
) {
|
||||
if ($error_code_only === true) {
|
||||
$errors[] = $pos;
|
||||
} else {
|
||||
$errors[] = self::getEmailRegexErrorMessage($pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -27,7 +27,6 @@ class ArrayHandler
|
||||
}
|
||||
if (
|
||||
$key_lookin != null &&
|
||||
!empty($key_lookin) &&
|
||||
array_key_exists($key_lookin, $haystack) &&
|
||||
$needle === $haystack[$key_lookin]
|
||||
) {
|
||||
|
||||
@@ -302,8 +302,6 @@ class IO extends \CoreLibs\Basic
|
||||
private $insert_id_arr; // always return as array, even if only one
|
||||
/** @var string */
|
||||
private $insert_id_pk_name; // primary key name for insert recovery from insert_id_arr
|
||||
/** @var string */
|
||||
private $temp_sql;
|
||||
// other vars
|
||||
/** @var string */
|
||||
private $nbsp = ''; // used by print_array recursion function
|
||||
@@ -932,10 +930,7 @@ class IO extends \CoreLibs\Basic
|
||||
$this->warning_id = 31;
|
||||
$this->__dbError($cursor, '[dbExec]');
|
||||
}
|
||||
} elseif (
|
||||
$stm_name === null ||
|
||||
($stm_name !== null && !empty($cursor))
|
||||
) {
|
||||
} else { // was stm_name null or not null and cursor
|
||||
// we have returning, now we need to check if we get one or many returned
|
||||
// we'll need to loop this, if we have multiple insert_id returns
|
||||
while (
|
||||
@@ -2202,14 +2197,12 @@ class IO extends \CoreLibs\Basic
|
||||
$q = 'UPDATE ' . $table . ' SET ';
|
||||
$q .= $q_sub_data . ' ';
|
||||
$q .= 'WHERE ' . $primary_key['row'] . ' = ' . $primary_key['value'];
|
||||
$this->temp_sql = $q_sub_data;
|
||||
} else {
|
||||
$q = 'INSERT INTO ' . $table . ' (';
|
||||
$q .= $q_sub_value;
|
||||
$q .= ') VALUES (';
|
||||
$q .= $q_sub_data;
|
||||
$q .= ')';
|
||||
$this->temp_sql = $q;
|
||||
}
|
||||
if (!$this->dbExec($q)) {
|
||||
return false;
|
||||
@@ -2426,7 +2419,7 @@ class IO extends \CoreLibs\Basic
|
||||
*/
|
||||
public function dbGetNumRows()
|
||||
{
|
||||
return $this->num_rows ?? null;
|
||||
return $this->num_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2440,6 +2433,17 @@ class IO extends \CoreLibs\Basic
|
||||
return $this->had_error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets warning number that was last
|
||||
* So we always have the last warning number stored even if a new one is created
|
||||
*
|
||||
* @return int last error number
|
||||
*/
|
||||
public function getHadWarning()
|
||||
{
|
||||
return $this->had_warning;
|
||||
}
|
||||
|
||||
// DEPEREACTED CALLS
|
||||
|
||||
/**
|
||||
|
||||
@@ -295,7 +295,11 @@ class PgSQL
|
||||
if (!is_resource($q)) {
|
||||
return false;
|
||||
}
|
||||
list($id) = $this->__dbFetchArray($q) ?: [];
|
||||
if (is_array($res = $this->__dbFetchArray($q))) {
|
||||
list($id) = $res;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$id = [-1, $q];
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class Logging
|
||||
private function getCallerClass(): string
|
||||
{
|
||||
// get the last class entry and wrie that
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) ?? [['class' => get_class($this)]];
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
// make sure if false it is an array and then check if not class set return empty string
|
||||
return (end($backtrace) ?: [])['class'] ?? '';
|
||||
}
|
||||
|
||||
@@ -60,25 +60,30 @@ class Support
|
||||
|
||||
/**
|
||||
* Get the current class where this function is called
|
||||
* Is mostly used in debug log statements to get the class where the debug was called
|
||||
* Is mostly used in debug log statements to get the class where the debug
|
||||
* was called
|
||||
* gets top level class
|
||||
* loops over the debug backtrace until if finds the first class (from the end)
|
||||
* @return string Class name with namespace
|
||||
*/
|
||||
public static function getCallerClass(): string
|
||||
{
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) ?? [['class' => get_called_class()]];
|
||||
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
// ?? [['class' => get_called_class()]];
|
||||
// TODO make sure that this doesn't loop forver
|
||||
$class = null;
|
||||
while ($class === null) {
|
||||
while ($class === null && count($backtrace) > 0) {
|
||||
// if current is
|
||||
// [function] => debug
|
||||
// [class] => CoreLibs\Debug\Logging
|
||||
// then return
|
||||
// (OUTSIDE) because it was not called from a class method
|
||||
// or return file name
|
||||
$class = array_pop($backtrace)['class'] ?? null;
|
||||
$get_class = array_pop($backtrace);
|
||||
$class = $get_class['class'] ?? null;
|
||||
}
|
||||
return $class ?? '';
|
||||
// on null or empty return empty string
|
||||
return empty($class) ? '' : $class;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -355,9 +355,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if (isset($config_array['load_query']) && $config_array['load_query']) {
|
||||
$this->load_query = $config_array['load_query'];
|
||||
}
|
||||
$this->archive_pk_name = 'a_' . $this->pk_name ?? '';
|
||||
$this->col_name = str_replace('_id', '', $this->pk_name ?? '');
|
||||
$this->int_pk_name = $this->pk_name ?? '';
|
||||
$this->archive_pk_name = 'a_' . $this->pk_name;
|
||||
$this->col_name = str_replace('_id', '', $this->pk_name);
|
||||
$this->int_pk_name = $this->pk_name;
|
||||
// check if reference_arrays are given and proceed them
|
||||
if (isset($config_array['reference_arrays']) && is_array($config_array['reference_arrays'])) {
|
||||
foreach ($config_array['reference_arrays'] as $key => $value) {
|
||||
@@ -1197,16 +1197,18 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
break;
|
||||
// check unique, check if field in table is not yet exist
|
||||
case 'unique':
|
||||
$q = 'SELECT ' . $key
|
||||
. ' FROM ' . $this->table_name
|
||||
. ' WHERE ' . $key . ' = '
|
||||
$q = 'SELECT ' . $key . ' AS unique_row '
|
||||
. 'FROM ' . $this->table_name . ' '
|
||||
. 'WHERE ' . $key . ' = '
|
||||
. "'" . $this->dbEscapeString($this->table_array[$key]['value']) . "'";
|
||||
if ($this->table_array[$this->int_pk_name]['value']) {
|
||||
$q .= ' AND ' . $this->int_pk_name . ' <> '
|
||||
. $this->table_array[$this->int_pk_name]['value'];
|
||||
}
|
||||
list($$key) = $this->dbReturnRow($q);
|
||||
if ($$key) {
|
||||
if (
|
||||
is_array($s_res = $this->dbReturnRow($q)) &&
|
||||
!empty($s_res['unique_row'])
|
||||
) {
|
||||
$this->msg .= sprintf(
|
||||
$this->l->__('The field <b>%s</b> can be used only once!<br>'),
|
||||
$this->table_array[$key]['output_name']
|
||||
@@ -1538,20 +1540,30 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$order_name = $this->formGetColNameFromKey('order');
|
||||
if ($order_name) {
|
||||
// first check out of order ...
|
||||
|
||||
if (empty($this->table_array[$order_name]['value'])) {
|
||||
// set order (read max)
|
||||
$q = 'SELECT MAX(' . $order_name . ') + 1 AS max_page_order FROM ' . $this->table_name;
|
||||
list($this->table_array[$order_name]['value']) = $this->dbReturnRow($q);
|
||||
$q = 'SELECT MAX(' . $order_name . ') + 1 AS max_page_order '
|
||||
. 'FROM ' . $this->table_name;
|
||||
if (
|
||||
is_array($res = $this->dbReturnRow($q)) &&
|
||||
!empty($res['max_page_order'])
|
||||
) {
|
||||
$this->table_array[$order_name]['value'] = $res['max_page_order'];
|
||||
}
|
||||
// frist element is 0 because NULL gets returned, set to 1
|
||||
if (!$this->table_array[$order_name]['value']) {
|
||||
$this->table_array[$order_name]['value'] = 1;
|
||||
}
|
||||
} elseif (!empty($this->table_array[$this->int_pk_name]['value'])) {
|
||||
$q = 'SELECT ' . $order_name
|
||||
. ' FROM ' . $this->table_name
|
||||
. ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value'];
|
||||
list($this->table_array[$order_name]['value']) = $this->dbReturnRow($q);
|
||||
$q = 'SELECT ' . $order_name . ' AS order_name '
|
||||
. 'FROM ' . $this->table_name . ' '
|
||||
. 'WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value'];
|
||||
if (
|
||||
is_array($res = $this->dbReturnRow($q)) &&
|
||||
!empty($res['order_name'])
|
||||
) {
|
||||
$this->table_array[$order_name]['value'] = $res['order_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->table_array;
|
||||
@@ -1656,7 +1668,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
) {
|
||||
// $this->log->debug('form', 'HERE');
|
||||
// check if this text name already exists (lowercase compare)
|
||||
$q = 'SELECT ' . $this->table_array[$key]['pk_name']
|
||||
$q = 'SELECT ' . $this->table_array[$key]['pk_name'] . ' AS pk_name '
|
||||
. ' FROM ' . $this->table_array[$key]['table_name']
|
||||
. ' WHERE LCASE(' . $this->table_array[$key]['input_name'] . ') = '
|
||||
. "'" . $this->dbEscapeString(strtolower($this->table_array[$key]['input_value'])) . "'";
|
||||
@@ -1664,9 +1676,12 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if ($this->table_array[$key]['where']) {
|
||||
$q .= ' AND ' . $this->table_array[$key]['where'];
|
||||
}
|
||||
list($pk_name_temp) = $this->dbReturnRow($q);
|
||||
if ($this->num_rows >= 1) {
|
||||
$this->table_array[$key]['value'] = $pk_name_temp;
|
||||
if (
|
||||
is_array($s_res = $this->dbReturnRow($q)) &&
|
||||
!empty($s_res['pk_name'])
|
||||
) {
|
||||
// $this->table_array[$key]['value'] = $pk_name_temp;
|
||||
$this->table_array[$key]['value'] = $s_res['pk_name'];
|
||||
} else {
|
||||
// if a where was given, set this key also [dangerous!]
|
||||
// postgreSQL compatible insert
|
||||
@@ -1694,7 +1709,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// if drop down & input are different
|
||||
if ($this->table_array[$key]['input_value'] != $this->table_array[$key]['value']) {
|
||||
// check if 'right input' is in DB
|
||||
$q = 'SELECT ' . $this->table_array[$key]['input_name']
|
||||
$q = 'SELECT ' . $this->table_array[$key]['input_name'] . ' AS temp '
|
||||
. ' FROM ' . $this->table_array[$key]['table_name']
|
||||
. ' WHERE LCASE(' . $this->table_array[$key]['input_name'] . ') = '
|
||||
. "'" . strtolower($this->dbEscapeString($this->table_array[$key]['input_value'])) . "'";
|
||||
@@ -1702,9 +1717,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if ($this->table_array[$key]['where']) {
|
||||
$q .= ' AND ' . $this->table_array[$key]['where'];
|
||||
}
|
||||
list($temp) = $this->dbReturnRow($q);
|
||||
// nothing found in table, use new inserted key
|
||||
if (!$temp) {
|
||||
if (
|
||||
is_array($s_res = $this->dbReturnRow($q)) &&
|
||||
empty($s_res['temp'])
|
||||
) {
|
||||
$this->table_array[$key]['value'] = $this->table_array[$key]['input_value'];
|
||||
} else {
|
||||
// found in DB
|
||||
@@ -1800,7 +1816,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
} // foreach reference arrays
|
||||
} // if reference arrays
|
||||
// write element list
|
||||
if (isset($this->element_list) && is_array($this->element_list)) {
|
||||
if (is_array($this->element_list)) {
|
||||
$type = [];
|
||||
reset($this->element_list);
|
||||
foreach ($this->element_list as $table_name => $reference_array) {
|
||||
@@ -2294,7 +2310,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
}
|
||||
// @phan HACK
|
||||
$data['prefix'] = $data['prefix'] ?? '';
|
||||
$data['prefix'] = $data['prefix'];
|
||||
// set the rest of the data so we can print something out
|
||||
/** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */
|
||||
$data['type'][$data['prefix'] . $this->element_list[$table_name]['read_data']['name']] = 'string';
|
||||
@@ -2362,7 +2378,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// read out the list and add the selected data if needed
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
$_data = [];
|
||||
$prfx = $data['prefix'] ?? ''; // short
|
||||
$prfx = $data['prefix']; // short
|
||||
// go through each res
|
||||
for ($i = 0, $i_max = count($q_select); $i < $i_max; $i++) {
|
||||
// query select part, set to the element name
|
||||
@@ -2411,7 +2427,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$this->element_list[$table_name]['max_empty'] = 10;
|
||||
}
|
||||
// check if we need to fill fields
|
||||
$element_count = count($data['content'] ?? []);
|
||||
$element_count = count($data['content']);
|
||||
$missing_empty_count = $this->element_list[$table_name]['max_empty'] - $element_count;
|
||||
$this->log->debug('CFG MAX', 'Max empty: '
|
||||
. $this->element_list[$table_name]['max_empty'] . ', Missing: ' . $missing_empty_count
|
||||
@@ -2428,22 +2444,18 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$pos++
|
||||
) {
|
||||
$_data = [];
|
||||
// just in case
|
||||
if (!isset($data['type'])) {
|
||||
$data['type'] = [];
|
||||
}
|
||||
// the fields that need to be filled are in data->type array:
|
||||
// pk fields are unfilled
|
||||
// fk fields are filled with the fk_id 'int_pk_name' value
|
||||
foreach ($data['type'] as $el_name => $type) {
|
||||
$_data[$el_name] = '';
|
||||
if (
|
||||
isset($data['pk_name']) &&
|
||||
!empty($data['pk_name']) &&
|
||||
$el_name == $data['pk_name']
|
||||
) {
|
||||
// do nothing for pk name
|
||||
} elseif (
|
||||
isset($data['fk_name']) &&
|
||||
!empty($data['fk_name']) &&
|
||||
$el_name == $data['fk_name'] &&
|
||||
isset($this->table_array[$this->int_pk_name]['value'])
|
||||
) {
|
||||
@@ -2466,7 +2478,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$data['content'][] = $proto;
|
||||
// we also need the pos add or we through an error in smarty
|
||||
$data['pos'][] = [
|
||||
0 => isset($data['pos']) ? count($data['pos']) : 0
|
||||
0 => count($data['pos'])
|
||||
];
|
||||
}
|
||||
// $this->log->debug('CFG ELEMENT LIST FILL', 'Data array: ' . $this->log->prAr($data));
|
||||
|
||||
@@ -65,7 +65,7 @@ class Image
|
||||
}
|
||||
// does this picture exist and is it a picture
|
||||
if (file_exists($filename) && is_file($filename)) {
|
||||
list($width, $height, $type) = getimagesize($filename);
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [];
|
||||
$convert_prefix = '';
|
||||
$create_file = false;
|
||||
$delete_filename = '';
|
||||
@@ -94,7 +94,7 @@ class Image
|
||||
if (!is_file($filename)) {
|
||||
$filename .= '-0';
|
||||
}
|
||||
list($width, $height, $type) = getimagesize($filename);
|
||||
[$width, $height, $type] = getimagesize($filename) ?: [];
|
||||
}
|
||||
// if no size given, set size to original
|
||||
if (!$size_x || $size_x < 1 || !is_numeric($size_x)) {
|
||||
@@ -113,7 +113,7 @@ class Image
|
||||
$status = exec($convert_string, $output, $return);
|
||||
// get the size of the converted data, if converted
|
||||
if (is_file($thumbnail)) {
|
||||
list ($width, $height, $type) = getimagesize($thumbnail);
|
||||
[$width, $height, $type] = getimagesize($thumbnail) ?: [];
|
||||
}
|
||||
}
|
||||
if ($height > $size_y) {
|
||||
@@ -133,6 +133,7 @@ class Image
|
||||
if (!empty($dummy) && strstr($dummy, '/') === false) {
|
||||
// check if we have the "dummy" image flag set
|
||||
$filename = PICTURES . ICONS . strtoupper($dummy) . ".png";
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (!empty($dummy) && file_exists($filename) && is_file($filename)) {
|
||||
$return_data = $filename;
|
||||
} else {
|
||||
@@ -187,7 +188,7 @@ class Image
|
||||
is_writable(BASE . LAYOUT . CONTENT_PATH . CACHE)
|
||||
) {
|
||||
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
|
||||
list($inc_width, $inc_height, $img_type) = getimagesize($filename);
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
$thumbnail_write_path = null;
|
||||
$thumbnail_web_path = null;
|
||||
// path set first
|
||||
@@ -424,7 +425,7 @@ class Image
|
||||
if (!function_exists('exif_read_data') || !is_writeable($filename)) {
|
||||
return;
|
||||
}
|
||||
list($inc_width, $inc_height, $img_type) = getimagesize($filename);
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
// add @ to avoid "file not supported error"
|
||||
$exif = @exif_read_data($filename);
|
||||
$orientation = null;
|
||||
|
||||
@@ -280,12 +280,12 @@ class SmartyExtend extends SmartyBC
|
||||
public function setSmartyPaths(): void
|
||||
{
|
||||
// master template
|
||||
if (!isset($this->MASTER_TEMPLATE_NAME)) {
|
||||
if (empty($this->MASTER_TEMPLATE_NAME)) {
|
||||
$this->MASTER_TEMPLATE_NAME = MASTER_TEMPLATE_NAME;
|
||||
}
|
||||
|
||||
// set include & template names
|
||||
if (!isset($this->CONTENT_INCLUDE)) {
|
||||
if (empty($this->CONTENT_INCLUDE)) {
|
||||
$this->CONTENT_INCLUDE = str_replace('.php', '', $this->page_name) . '.tpl';
|
||||
}
|
||||
// strip tpl and replace it with php
|
||||
@@ -435,10 +435,10 @@ class SmartyExtend extends SmartyBC
|
||||
$this->DATA['show_ea_extra'] = $cms->acl['show_ea_extra'] ?? false;
|
||||
$this->DATA['ADMIN'] = $cms->acl['admin'] ?? 0;
|
||||
// top menu
|
||||
$this->DATA['nav_menu'] = $cms->adbTopMenu() ?? [];
|
||||
$this->DATA['nav_menu'] = $cms->adbTopMenu();
|
||||
$this->DATA['nav_menu_count'] = is_array($this->DATA['nav_menu']) ? count($this->DATA['nav_menu']) : 0;
|
||||
// messages = ['msg' =>, 'class' => 'error/warning/...']
|
||||
$this->DATA['messages'] = $cms->messages ?? [];
|
||||
$this->DATA['messages'] = $cms->messages;
|
||||
} else { /** @phpstan-ignore-line Because I assume object for phpstan */
|
||||
$this->DATA['show_ea_extra'] = false;
|
||||
$this->DATA['ADMIN'] = 0;
|
||||
@@ -451,7 +451,7 @@ class SmartyExtend extends SmartyBC
|
||||
$this->HEADER['JAVASCRIPT'] = $this->ADMIN_JAVASCRIPT ? $this->ADMIN_JAVASCRIPT : ADMIN_JAVASCRIPT;
|
||||
// the page name
|
||||
$this->DATA['page_name'] = $this->page_name;
|
||||
$this->DATA['table_width'] = $this->PAGE_WIDTH ?? PAGE_WIDTH;
|
||||
$this->DATA['table_width'] = empty($this->PAGE_WIDTH) ?: PAGE_WIDTH;
|
||||
$this->DATA['form_name'] = $this->DATA['FORM_NAME'];
|
||||
// for tinymce special
|
||||
$this->DATA['TINYMCE_LANG'] = $this->lang_short;
|
||||
|
||||
@@ -27,7 +27,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
function MyErrorHandler(int $type, string $message, string $file, int $line, array $context): bool
|
||||
{
|
||||
if (!(error_reporting() & $type) && empty(SHOW_ALL_ERRORS)) {
|
||||
if (!(error_reporting() & $type) && SHOW_ALL_ERRORS == false) {
|
||||
// This error code is not included in error_reporting
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class qqUploadedFileForm implements qqUploadedFile // phpcs:ignore Squiz.Classes
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $_FILES['qqfile']['name'] ?? '';
|
||||
return (string)$_FILES['qqfile']['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +38,7 @@ class qqUploadedFileForm implements qqUploadedFile // phpcs:ignore Squiz.Classes
|
||||
*/
|
||||
public function getSize(): int
|
||||
{
|
||||
return (int)$_FILES['qqfile']['size'] ?? 0;
|
||||
return (int)$_FILES['qqfile']['size'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ class qqFileUploader // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
}
|
||||
|
||||
$pathinfo = pathinfo($this->file->getName());
|
||||
$filename = $pathinfo['filename'] ?? '';
|
||||
$filename = $pathinfo['filename'];
|
||||
//$filename = md5(uniqid());
|
||||
$ext = $pathinfo['extension'] ?? '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user