Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6001934d9c | ||
|
|
f622d59ed9 | ||
|
|
6147d28b37 | ||
|
|
f9072f64f1 | ||
|
|
0f38cb4f89 | ||
|
|
08bbc913a9 | ||
|
|
4c859ada01 | ||
|
|
58e61b8902 | ||
|
|
edfbe476c4 | ||
|
|
0907325a38 | ||
|
|
60b6fae33a | ||
|
|
0b7dba5e2f | ||
|
|
c1212d8116 | ||
|
|
5230cbf5d3 | ||
|
|
a6b42f243f | ||
|
|
736f822363 | ||
|
|
ffd1a86dcc | ||
|
|
b3d783bf63 | ||
|
|
e0cc766cc7 | ||
|
|
f151509bfe | ||
|
|
e252a76c4c | ||
|
|
7005e07f4c | ||
|
|
a86ae3efc3 |
@@ -70,14 +70,14 @@ return [
|
||||
// Thus, both first-party and third-party code being used by
|
||||
// your application should be included in this list.
|
||||
'directory_list' => [
|
||||
// Change this to include the folders you wish to analyze
|
||||
// (and the folders of their dependencies)
|
||||
'www',
|
||||
// To speed up analysis, we recommend going back later and
|
||||
// limiting this to only the vendor/ subdirectories your
|
||||
// project depends on.
|
||||
// `phan --init` will generate a list of folders for you
|
||||
//'www/vendor',
|
||||
// Change this to include the folders you wish to analyze
|
||||
// (and the folders of their dependencies)
|
||||
'www',
|
||||
// To speed up analysis, we recommend going back later and
|
||||
// limiting this to only the vendor/ subdirectories your
|
||||
// project depends on.
|
||||
// `phan --init` will generate a list of folders for you
|
||||
//'www/vendor',
|
||||
],
|
||||
|
||||
|
||||
@@ -85,9 +85,7 @@ return [
|
||||
// to parse, but not analyze
|
||||
"exclude_analysis_directory_list" => [
|
||||
'www/vendor',
|
||||
// 'www/lib/FileUpload',
|
||||
'www/lib/pChart',
|
||||
'www/lib/pChart2.1.4',
|
||||
'www/tests',
|
||||
'www/lib/Smarty',
|
||||
'www/lib/smarty-3.1.30',
|
||||
'www/templates_c',
|
||||
|
||||
3
4dev/checking/phan.sh
Normal file
3
4dev/checking/phan.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phan --progress-bar -C --analyze-twice
|
||||
3
4dev/checking/phpstan.sh
Normal file
3
4dev/checking/phpstan.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# must be run in ${base}www/
|
||||
phpstan
|
||||
4
4dev/checking/phpunit.sh
Executable file
4
4dev/checking/phpunit.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
base="/storage/var/www/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
# -c phpunit.xml
|
||||
# --testdox
|
||||
${base}www/vendor/bin/phpunit -c ${base}phpunit.xml ${base}4dev/tests/
|
||||
@@ -1,21 +1,27 @@
|
||||
Install composer:
|
||||
curl -sS https://getcomposer.org/installer | /usr/local/php-7.3-httpd-2.4/bin/php
|
||||
# old
|
||||
curl -sS https://getcomposer.org/installer | /usr/local/php-8.0-httpd-2.4/bin/php
|
||||
# new (4 steps) https://getcomposer.org/download/
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer-setup.php
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php -r "unlink('composer-setup.php');
|
||||
|
||||
Update composer phar file
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php composer.phar selfupdate
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar selfupdate
|
||||
|
||||
Install something:
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php composer.phar require something/something
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar require something/something
|
||||
|
||||
Update all installed:
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php composer.phar update
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar update
|
||||
|
||||
Or update only one package:
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php composer.phar something/something
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar something/something
|
||||
|
||||
Install AWS SDK:
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php -d memory_limit=-1 composer.phar require aws/aws-sdk-php
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php -d memory_limit=-1 composer.phar require aws/aws-sdk-php
|
||||
|
||||
Install zipStream:
|
||||
/usr/local/php-7.3-httpd-2.4/bin/php composer.phar require maennchen/zipstream-php
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar require maennchen/zipstream-php
|
||||
|
||||
|
||||
@@ -147,4 +147,4 @@ BEGIN
|
||||
RETURN NULL;
|
||||
END
|
||||
$$
|
||||
LANGUAGE 'plpgsql'
|
||||
LANGUAGE 'plpgsql';
|
||||
|
||||
@@ -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__
|
||||
89
4dev/tests/CoreLibsCheckFileTest.php
Normal file
89
4dev/tests/CoreLibsCheckFileTest.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @testdox CoreLibs\Check\File method tests
|
||||
*/
|
||||
final class CoreLibsCheckFileTest extends TestCase
|
||||
{
|
||||
/** @var array<mixed> */
|
||||
private $files = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
// write a dummy files for testing
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// unlink files
|
||||
}
|
||||
|
||||
/**
|
||||
* main file list + data provider
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function filesList(): array
|
||||
{
|
||||
return [
|
||||
['filename.txt', 'txt', 5]
|
||||
];
|
||||
}
|
||||
|
||||
public function filesExtensionProvider(): array
|
||||
{
|
||||
$list = [];
|
||||
foreach ($this->filesList as $row) {
|
||||
$list[$row[0] . ' must be extension ' . $row[1]] = [$row[0], $row[1]];
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @#dataProvider filesExtensionProvider
|
||||
* @#testdox File::getFilenameEnding Input $input must be $expected
|
||||
* //string $input, string $expected
|
||||
*
|
||||
* @param string $input
|
||||
* @param string $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testGetFilenameEnding(): void
|
||||
{
|
||||
// getFilenameEnding
|
||||
/* $this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Check\File::getFilenameEnding($input)
|
||||
); */
|
||||
$this->assertTrue(true, 'This should already work.');
|
||||
$this->markTestIncomplete(
|
||||
'testGetFilenameEnding has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
* // string $input, string $expected
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLinesFromFile(): void
|
||||
{
|
||||
// getLinesFromFile
|
||||
$this->assertTrue(true, 'This should already work.');
|
||||
$this->markTestIncomplete(
|
||||
'testGetLinesFromFile has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
134
4dev/tests/CoreLibsConvertMathTest.php
Normal file
134
4dev/tests/CoreLibsConvertMathTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
* @testdox CoreLibs\Convert\Math method tests
|
||||
*/
|
||||
final class CoreLibsConvertMathTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function fceilProvider(): array
|
||||
{
|
||||
return [
|
||||
'5.5 must be 6' => [5.5, 6],
|
||||
'5.1234567890 with 5 must be 6' => [5.1234567890, 6],
|
||||
'6 must be 6' => [6, 6]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider fceilProvider
|
||||
* @testdox Math::fceil: Input $input must be $expected
|
||||
*
|
||||
* @param float $input
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMathFceilValue(float $input, int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::fceil($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function floorProvider(): array
|
||||
{
|
||||
return [
|
||||
'5123456 with -3 must be 5123000' => [5123456, -3, 5123000],
|
||||
'5123456 with -10 must be 5000000' => [5123456, -10, 5000000]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider floorProvider
|
||||
* @testdox Math::floor: Input $input with cutoff $cutoff must be $expected
|
||||
*
|
||||
* @param int $input
|
||||
* @param int $cutoff
|
||||
* @param int $expected
|
||||
* @return void
|
||||
*/
|
||||
public function testMathFloorValue(int $input, int $cutoff, int $expected): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::floorp($input, $cutoff)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function initNumericProvider(): array
|
||||
{
|
||||
return [
|
||||
'5 must be 5' => [5, 5, 'int'],
|
||||
'5.123 must be 5.123' => [5.123, 5.123, 'float'],
|
||||
"'5' must be 5" => ['5', 5, 'string'],
|
||||
"'5.123' must be 5.123" => ['5.123', 5.123, 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @dataProvider initNumericProvider
|
||||
* @testdox Math::initNumeric: Input $info $input must match $expected [$_dataName]
|
||||
*
|
||||
* @param int|float|string $input
|
||||
* @param float $expected
|
||||
* @param string $info
|
||||
* @return void
|
||||
*/
|
||||
public function testMathInitNumericValue($input, float $expected, string $info): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::initNumeric($input)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A testWith sample
|
||||
*
|
||||
* @testdox Math::initNumeric: alternate tests $input => $expected ($info) [$_dataName]
|
||||
* @testWith [123.123, 123.123, "float"]
|
||||
* ["123.123", 123.123, "string"]
|
||||
*
|
||||
* @param int|float|string $input
|
||||
* @param float $expected
|
||||
* @param string $info
|
||||
* @return void
|
||||
*/
|
||||
public function testMathInitNumericValueAlt($input, float $expected, string $info): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
\CoreLibs\Convert\Math::initNumeric($input)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
10
README.md
10
README.md
@@ -33,3 +33,13 @@ last tested PHP 5.6 and PHP 7.0
|
||||
### namespace
|
||||
|
||||
The new namespace branch. This is the development area for the master branch
|
||||
|
||||
## Static checks
|
||||
|
||||
With phpstan
|
||||
`phpstan`
|
||||
|
||||
With phan
|
||||
`phan --progress-bar -C --analyze-twice`
|
||||
|
||||
pslam is setup but not configured
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
<?php
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
// Boostrap file for PHPstand
|
||||
// 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');
|
||||
// for whatever reason it does not load that from the confing.master.php
|
||||
// for includes/admin_header.php
|
||||
define('BASE_NAME', '');
|
||||
|
||||
// __END__
|
||||
|
||||
47
phpstan.neon
47
phpstan.neon
@@ -2,37 +2,34 @@
|
||||
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs
|
||||
level: 1
|
||||
level: 8 # max is now 9
|
||||
paths:
|
||||
- %currentWorkingDirectory%/www
|
||||
bootstrapFiles:
|
||||
- %currentWorkingDirectory%/phpstan-bootstrap.php
|
||||
# - %currentWorkingDirectory%/www/lib/autoloader.php
|
||||
- %currentWorkingDirectory%/www/vendor/autoload.php
|
||||
scanDirectories:
|
||||
- www/lib/Smarty
|
||||
scanFiles:
|
||||
- www/configs/config.php
|
||||
- www/configs/config.master.php
|
||||
- www/lib/autoloader.php
|
||||
# if composer.json autoloader defined, this is not needed
|
||||
# - www/lib/autoloader.php
|
||||
- www/vendor/autoload.php
|
||||
- www/lib/Smarty/Autoloader.php
|
||||
- www/lib/CoreLibs/Template/SmartyExtend.php
|
||||
excludes_analyse:
|
||||
# no check admin
|
||||
- www/admin/qq_file_upload_front.php
|
||||
- www/admin/qq_file_upload_ajax.php
|
||||
excludePaths:
|
||||
# do not check old qq file uploader tests
|
||||
- www/admin/qq_file_upload_*.php
|
||||
# ignore all test files
|
||||
- www/admin/class_test*php
|
||||
- www/admin/error_test.php
|
||||
# admin synlink files
|
||||
- www/admin/edit_access.php
|
||||
- www/admin/edit_groups.php
|
||||
- www/admin/edit_languages.php
|
||||
- www/admin/edit_menu_group.php
|
||||
- www/admin/edit_order.php
|
||||
- www/admin/edit_pages.php
|
||||
- www/admin/edit_schemes.php
|
||||
- www/admin/edit_users.php
|
||||
- www/admin/edit_visible_group.php
|
||||
- www/admin/edit_*.php
|
||||
# ignore admin header stuff
|
||||
- www/includes/admin_header.php # ignore the admin include stuff
|
||||
# - www/includes/admin_header.php # ignore the admin include stuff
|
||||
- www/includes/admin_footer.php # ignore the admin include stuff
|
||||
# deprecated files
|
||||
- www/includes/admin_set_paths.php # ignore the admin include stuff
|
||||
- www/includes/admin_smarty.php # ignore the admin include stuff
|
||||
# folders with data no check needed
|
||||
@@ -41,16 +38,18 @@ parameters:
|
||||
- www/log
|
||||
- www/media
|
||||
- www/tmp
|
||||
- www/lib/pChart
|
||||
- www/lib/pChart2.1.4
|
||||
- www/lib/Smarty
|
||||
- www/lib/smarty-3.1.30
|
||||
# external libs are not checked
|
||||
- www/lib/Smarty/
|
||||
- www/lib/smarty-*/
|
||||
# ignore composer
|
||||
- www/vendor
|
||||
# ignore the smartyextend
|
||||
- www/lib/CoreLibs/Template/SmartyExtend.php
|
||||
# ignore errores with
|
||||
# ignoreErrors:
|
||||
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
|
||||
#- 'error regex'
|
||||
#-
|
||||
# message: 'error regex'
|
||||
|
||||
6
phpunit.xml
Normal file
6
phpunit.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<phpunit
|
||||
cacheResultFile="/tmp/phpunit-corelibs.result.cache"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
>
|
||||
</phpunit>
|
||||
@@ -33,7 +33,7 @@ use CoreLibs\Combined\ArrayHandler;
|
||||
use CoreLibs\Debug\Support as DgS;
|
||||
|
||||
$basic = new CoreLibs\Basic();
|
||||
// $_array= new CoreLibs\Combined\ArrayHandler();
|
||||
// $_array = new CoreLibs\Combined\ArrayHandler();
|
||||
// $array_class = 'CoreLibs\Combination\ArrayHandler';
|
||||
|
||||
print "<html><head><title>TEST CLASS: ARRAY HANDLER</title><head>";
|
||||
|
||||
45
www/admin/class_test.autoloader.php
Normal file
45
www/admin/class_test.autoloader.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-autoloader';
|
||||
ob_end_flush();
|
||||
|
||||
# Test if composer autoloader works here
|
||||
|
||||
use CoreLibs\Convert\Byte;
|
||||
|
||||
print "<html><head><title>TEST CLASS: AUTOLOADER</title><head>";
|
||||
print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
$bytes = 10242424;
|
||||
$_bytes = Byte::humanReadableByteFormat($bytes);
|
||||
print "BYTES: " . $_bytes . "<br>";
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
@@ -33,7 +33,7 @@ use CoreLibs\Combined\DateTime;
|
||||
use CoreLibs\Debug\Support as DgS;
|
||||
|
||||
$basic = new CoreLibs\Basic();
|
||||
$datetime_class = 'CoreLibs\Combination\DateTime';
|
||||
$datetime_class = 'CoreLibs\Combined\DateTime';
|
||||
|
||||
print "<html><head><title>TEST CLASS: DATE/TIME</title><head>";
|
||||
print "<body>";
|
||||
|
||||
@@ -52,83 +52,125 @@ echo "DB_CONFIG_SET constant: <pre>" . print_r(DB_CONFIG, true) . "</pre><br>";
|
||||
// DB client encoding
|
||||
print "DB Client encoding: " . $db->dbGetEncoding() . "<br>";
|
||||
|
||||
while ($res = $db->dbReturn("SELECT * FROM max_test", 0, true)) {
|
||||
while (is_array($res = $db->dbReturn("SELECT * FROM max_test", 0, true))) {
|
||||
print "TIME: " . $res['time'] . "<br>";
|
||||
}
|
||||
print "CACHED DATA: <pre>" . print_r($db->cursor_ext, true) . "</pre><br>";
|
||||
while ($res = $db->dbReturn("SELECT * FROM max_test")) {
|
||||
while (is_array($res = $db->dbReturn("SELECT * FROM max_test"))) {
|
||||
print "[CACHED] TIME: " . $res['time'] . "<br>";
|
||||
}
|
||||
// alternate check for valid data
|
||||
// while (($res = $db->dbReturn("SELECT * FROM max_test")) !== false) {
|
||||
// print "[CACHED] TIME: " . $res['time'] . "<br>";
|
||||
// }
|
||||
|
||||
print "<pre>";
|
||||
$status = $db->dbExec("INSERT INTO foo (test) VALUES ('FOO TEST " . time() . "') RETURNING test");
|
||||
|
||||
// truncate test_foo table before testing
|
||||
print "<b>TRUNCATE test_foo</b><br>";
|
||||
$query = "TRUNCATE test_foo";
|
||||
$db->dbExec($query);
|
||||
print "<b>TRUNCATE test_foobar</b><br>";
|
||||
$query = "TRUNCATE test_foobar";
|
||||
$db->dbExec($query);
|
||||
|
||||
$status = $db->dbExec("INSERT INTO test_foo (test) VALUES ('FOO TEST " . time() . "') RETURNING test");
|
||||
print "DIRECT INSERT STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING EXT[test]: " . print_r($db->dbGetReturningExt('test'), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
// should throw deprecated error
|
||||
// $db->getReturningExt();
|
||||
print "DIRECT INSERT PREVIOUS INSERTED: "
|
||||
. print_r($db->dbReturnRow("SELECT foo_id, test FROM foo WHERE foo_id = " . $db->dbGetInsertPK()), true) . "<br>";
|
||||
$db->dbPrepare("ins_foo", "INSERT INTO foo (test) VALUES ($1)");
|
||||
$status = $db->dbExecute("ins_foo", array('BAR TEST ' . time()));
|
||||
print "PREPARE INSERT STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING RETURN: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
. print_r($db->dbReturnRow("SELECT test_foo_id, test FROM test_foo "
|
||||
. "WHERE test_foo_id = " . $db->dbGetInsertPK()), true) . "<br>";
|
||||
|
||||
// PREPARED INSERT
|
||||
$db->dbPrepare("ins_test_foo", "INSERT INTO test_foo (test) VALUES ($1) RETURNING test");
|
||||
$status = $db->dbExecute("ins_test_foo", array('BAR TEST ' . time()));
|
||||
print "PREPARE INSERT[ins_test_foo] STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING RETURN: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
print "PREPARE INSERT PREVIOUS INSERTED: "
|
||||
. print_r($db->dbReturnRow("SELECT foo_id, test FROM foo WHERE foo_id = " . $db->dbGetInsertPK()), true) . "<br>";
|
||||
. print_r($db->dbReturnRow("SELECT test_foo_id, test FROM test_foo "
|
||||
. "WHERE test_foo_id = " . $db->dbGetInsertPK()), true) . "<br>";
|
||||
// returning test with multiple entries
|
||||
// $status = $db->db_exec(
|
||||
// "INSERT INTO foo (test) VALUES "
|
||||
// "INSERT INTO test_foo (test) VALUES "
|
||||
// . "('BAR 1 " . time() . "'), "
|
||||
// . "('BAR 2 " . time() . "'), "
|
||||
// . "('BAR 3 " . time() . "') "
|
||||
// . "RETURNING foo_id"
|
||||
// . "RETURNING test_foo_id"
|
||||
// );
|
||||
$status = $db->dbExec(
|
||||
"INSERT INTO foo (test) VALUES "
|
||||
"INSERT INTO test_foo (test) VALUES "
|
||||
. "('BAR 1 " . time() . "'), "
|
||||
. "('BAR 2 " . time() . "'), "
|
||||
. "('BAR 3 " . time() . "') "
|
||||
. "RETURNING foo_id, test"
|
||||
. "RETURNING test_foo_id, test"
|
||||
);
|
||||
print "DIRECT MULTIPLE INSERT STATUS: $status | "
|
||||
. "PRIMARY KEYS: " . print_r($db->dbGetInsertPK(), true) . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
print "DIRECT MULTIPLE INSERT WITH RETURN STATUS: $status | "
|
||||
. "PRIMARY KEYS: " . print_r($db->dbGetInsertPK(), true) . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING EXT[test]: " . print_r($db->dbGetReturningExt('test'), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
// no returning, but not needed ;
|
||||
$status = $db->dbExec("INSERT INTO foo (test) VALUES ('FOO; TEST " . time() . "');");
|
||||
print "DIRECT INSERT STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
$status = $db->dbExec("INSERT INTO test_foo (test) VALUES ('FOO; TEST " . time() . "');");
|
||||
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 foo SET test = 'SOMETHING DIFFERENT' WHERE foo_id = 3688452 RETURNING test");
|
||||
print "UPDATE STATUS: $status | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
$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>";
|
||||
|
||||
|
||||
// INSERT WITH NO RETURNING
|
||||
$status = $db->dbExec("INSERT INTO test_foobar (type, integer) VALUES ('WITH DATA', 123)");
|
||||
print "INSERT WITH NO PRIMARY KEY NO RETURNING STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
$status = $db->dbExec("INSERT INTO test_foobar (type, integer) VALUES ('WITH DATA', 123) RETURNING type, integer");
|
||||
print "INSERT WITH NO PRIMARY KEY WITH RETURNING STATUS: $status | "
|
||||
. "PRIMARY KEY: " . $db->dbGetInsertPK() . " | "
|
||||
. "RETURNING EXT: " . print_r($db->dbGetReturningExt(), true) . " | "
|
||||
. "RETURNING ARRAY: " . print_r($db->dbGetReturningArray(), true) . "<br>";
|
||||
|
||||
print "</pre>";
|
||||
|
||||
// REEAD PREPARE
|
||||
// READ PREPARE
|
||||
if (
|
||||
$db->dbPrepare(
|
||||
'sel_foo',
|
||||
"SELECT foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time "
|
||||
. "FROM foo ORDER BY foo_id DESC LIMIT 5"
|
||||
'sel_test_foo',
|
||||
"SELECT test_foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time "
|
||||
. "FROM test_foo ORDER BY test_foo_id DESC LIMIT 5"
|
||||
) === false
|
||||
) {
|
||||
print "Error in sel_foo prepare<br>";
|
||||
print "Error in sel_test_foo prepare<br>";
|
||||
} else {
|
||||
$max_rows = 6;
|
||||
// do not run this in dbFetchArray directly as
|
||||
// dbFetchArray(dbExecute(...))
|
||||
// this will end in an endless loop
|
||||
$cursor = $db->dbExecute('sel_foo', []);
|
||||
$cursor = $db->dbExecute('sel_test_foo', []);
|
||||
$i = 1;
|
||||
while (($res = $db->dbFetchArray($cursor, true)) !== false) {
|
||||
print "DB PREP EXEC FETCH ARR: " . $i . ": <pre>" . print_r($res, true) . "</pre><br>";
|
||||
@@ -138,14 +180,16 @@ if (
|
||||
|
||||
|
||||
# db write class test
|
||||
$table = 'foo';
|
||||
$table = 'test_foo';
|
||||
print "TABLE META DATA: " . DgS::printAr($db->dbShowTableMetaData($table)) . "<br>";
|
||||
// insert first, then use primary key to update
|
||||
$primary_key = ''; # unset
|
||||
$db_write_table = array('test', 'string_a', 'number_a', 'some_bool');
|
||||
// $db_write_table = array('test');
|
||||
$object_fields_not_touch = array();
|
||||
$object_fields_not_update = array();
|
||||
$data = array('test' => 'BOOL TEST SOMETHING ' . time(), 'string_a' => 'SOME TEXT', 'number_a' => 5);
|
||||
$db_write_table = ['test', 'string_a', 'number_a', 'some_bool'];
|
||||
$object_fields_not_touch = [];
|
||||
$object_fields_not_update = [];
|
||||
$data = [
|
||||
'test' => 'dbWriteDataExt: BOOL TEST SOMETHING ' . time(), 'string_a' => 'SOME TEXT', 'number_a' => 5
|
||||
];
|
||||
$primary_key = $db->dbWriteDataExt(
|
||||
$db_write_table,
|
||||
$primary_key,
|
||||
@@ -154,8 +198,10 @@ $primary_key = $db->dbWriteDataExt(
|
||||
$object_fields_not_update,
|
||||
$data
|
||||
);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array('test' => 'BOOL TEST ON ' . time(), 'string_a' => '', 'number_a' => 0, 'some_bool' => 1);
|
||||
print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got primary key $primary_key<br>";
|
||||
$data = [
|
||||
'test' => 'dbWriteDataExt: BOOL TEST ON ' . time(), 'string_a' => '', 'number_a' => 0, 'some_bool' => 1
|
||||
];
|
||||
$primary_key = $db->dbWriteDataExt(
|
||||
$db_write_table,
|
||||
$primary_key,
|
||||
@@ -164,8 +210,10 @@ $primary_key = $db->dbWriteDataExt(
|
||||
$object_fields_not_update,
|
||||
$data
|
||||
);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array('test' => 'BOOL TEST OFF ' . time(), 'string_a' => null, 'number_a' => null, 'some_bool' => 0);
|
||||
print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got primary key $primary_key<br>";
|
||||
$data = [
|
||||
'test' => 'dbWriteDataExt: BOOL TEST OFF ' . time(), 'string_a' => null, 'number_a' => null, 'some_bool' => 0
|
||||
];
|
||||
$primary_key = $db->dbWriteDataExt(
|
||||
$db_write_table,
|
||||
$primary_key,
|
||||
@@ -174,8 +222,10 @@ $primary_key = $db->dbWriteDataExt(
|
||||
$object_fields_not_update,
|
||||
$data
|
||||
);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
$data = array('test' => 'BOOL TEST UNSET ' . time());
|
||||
print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got primary key $primary_key<br>";
|
||||
$data = [
|
||||
'test' => 'dbWriteDataExt: BOOL TEST UNSET ' . time()
|
||||
];
|
||||
$primary_key = $db->dbWriteDataExt(
|
||||
$db_write_table,
|
||||
$primary_key,
|
||||
@@ -184,7 +234,7 @@ $primary_key = $db->dbWriteDataExt(
|
||||
$object_fields_not_update,
|
||||
$data
|
||||
);
|
||||
print "Wrote to DB tabel $table and got primary key $primary_key<br>";
|
||||
print "Wrote to DB tabel $table with data " . print_r($data, true) . " and got primary key $primary_key<br>";
|
||||
|
||||
// return Array Test
|
||||
$query = "SELECT type, sdate, integer FROM foobar";
|
||||
@@ -192,7 +242,8 @@ $data = $db->dbReturnArray($query, true);
|
||||
print "Full foobar list: <br><pre>" . print_r($data, true) . "</pre><br>";
|
||||
|
||||
# async test queries
|
||||
/* $db->dbExecAsync("SELECT test FROM foo, (SELECT pg_sleep(10)) as sub WHERE foo_id IN (27, 50, 67, 44, 10)");
|
||||
/*
|
||||
$db->dbExecAsync("SELECT test FROM test_foo, (SELECT pg_sleep(10)) as sub WHERE test_foo_id IN (27, 50, 67, 44, 10)");
|
||||
echo "WAITING FOR ASYNC: ";
|
||||
$chars = array('|', '/', '-', '\\');
|
||||
while (($ret = $db->dbCheckAsync()) === true)
|
||||
@@ -213,7 +264,7 @@ while ($res = $db->dbFetchArray())
|
||||
echo "RES: " . $res['test'] . "<br>";
|
||||
}
|
||||
# test async insert
|
||||
$db->dbExecAsync("INSERT INTO foo (Test) VALUES ('ASYNC TEST " . time() . "')");
|
||||
$db->dbExecAsync("INSERT INTO test_foo (Test) VALUES ('ASYNC TEST " . time() . "')");
|
||||
echo "WAITING FOR ASYNC INSERT: ";
|
||||
while (($ret = $db->dbCheckAsync()) === true)
|
||||
{
|
||||
@@ -223,7 +274,12 @@ while (($ret = $db->dbCheckAsync()) === true)
|
||||
}
|
||||
print "<br>END STATUS: " . $ret . " | PK: " . $db->insert_id . "<br>";
|
||||
print "ASYNC PREVIOUS INSERTED: "
|
||||
. print_r($db->dbReturnRow("SELECT foo_id, test FROM foo WHERE foo_id = " . $db->insert_id), true) . "<br>"; */
|
||||
. print_r(
|
||||
$db->dbReturnRow("SELECT test_foo_id, test FROM test_foo WHERE test_foo_id = "
|
||||
. $db->insert_id),
|
||||
true
|
||||
) . "<br>";
|
||||
*/
|
||||
|
||||
$to_db_version = '9.1.9';
|
||||
print "VERSION DB: " . $db->dbVersion() . "<br>";
|
||||
@@ -233,16 +289,17 @@ print "DB Version equal $to_db_version: " . $db->dbCompareVersion('=' . $to_db_v
|
||||
print "DB Version bigger than $to_db_version: " . $db->dbCompareVersion('>=' . $to_db_version) . "<br>";
|
||||
print "DB Version bigger $to_db_version: " . $db->dbCompareVersion('>' . $to_db_version) . "<br>";
|
||||
|
||||
/* $q = "SELECT FOO FRO BAR";
|
||||
// $q = "Select * from foo";
|
||||
$foo = $db->dbExecAsync($q);
|
||||
/*
|
||||
$q = "Select * from test_foo";
|
||||
$test_foo = $db->dbExecAsync($q);
|
||||
print "[ERR] Query: " . $q . "<br>";
|
||||
print "[ERR] RESOURCE: $foo<br>";
|
||||
print "[ERR] RESOURCE: $test_foo<br>";
|
||||
while (($ret = $db->dbCheckAsync()) === true)
|
||||
{
|
||||
print "[ERR]: $ret<br>";
|
||||
sleep(5);
|
||||
} */
|
||||
}
|
||||
*/
|
||||
|
||||
// search path check
|
||||
$q = "SHOW search_path";
|
||||
@@ -256,7 +313,7 @@ $status = $db->dbExec(
|
||||
. "('TIME: " . time() . "', " . rand(1, 10) . ")"
|
||||
);
|
||||
print "OTHER SCHEMA INSERT STATUS: "
|
||||
. $status . " | PK NAME: " . $db->pk_name . ", PRIMARY KEY: " . $db->insert_id . "<br>";
|
||||
. $status . " | PK NAME: " . $db->dbGetInsertPKName() . ", PRIMARY KEY: " . $db->dbGetInsertPK() . "<br>";
|
||||
|
||||
print "<b>NULL TEST DB READ</b><br>";
|
||||
$q = "SELECT uid, null_varchar, null_int FROM test_null_data WHERE uid = 'A'";
|
||||
|
||||
@@ -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>";
|
||||
|
||||
@@ -52,9 +52,6 @@ echo "LANGUAGE FILE: " . $l->__getMoFile() . "<br>";
|
||||
echo "INPUT TEST: " . $string . " => " . $l->__($string) . "<br>";
|
||||
// TODO: run compare check input must match output
|
||||
|
||||
// error message
|
||||
print $basic->log->printErrorMsg();
|
||||
|
||||
print "</body></html>";
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -41,11 +41,15 @@ print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
|
||||
print "FCEIL: " . $_math->fceil(5.1234567890, 5) . "<br>";
|
||||
print "FLOORP: " . $_math->floorp(5123456, -3) . "<br>";
|
||||
print "FLOORP: " . $_math->floorp(5123456, -10) . "<br>";
|
||||
print "INITNUMERIC: " . $_math->initNumeric('123') . "<br>";
|
||||
|
||||
print "S-FCEIL: " . $math_class::fceil(5.1234567890, 5) . "<br>";
|
||||
print "S-FLOORP: " . $math_class::floorp(5123456, -3) . "<br>";
|
||||
print "S-INITNUMERIC: " . $math_class::initNumeric(123) . "<br>";
|
||||
print "S-INITNUMERIC: " . $math_class::initNumeric(123.456) . "<br>";
|
||||
print "S-INITNUMERIC: " . $math_class::initNumeric('123') . "<br>";
|
||||
print "S-INITNUMERIC: " . $math_class::initNumeric('123.456') . "<br>";
|
||||
|
||||
// DEPRECATED
|
||||
/* print "FCEIL: ".$basic->fceil(5.1234567890, 5)."<br>";
|
||||
|
||||
@@ -32,6 +32,7 @@ $LOG_FILE_ID = 'classTest-form';
|
||||
ob_end_flush();
|
||||
|
||||
// define an array for page use
|
||||
$table_arrays = [];
|
||||
$table_arrays[\CoreLibs\Get\System::getPageName(1)] = [
|
||||
// form fields mtaching up with db fields
|
||||
'table_array' => [
|
||||
|
||||
@@ -63,7 +63,12 @@ print '<div><a href="class_test.form.php">Class Test: FORM</a></div>';
|
||||
print '<div><a href="class_test.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 all _ENV vars set
|
||||
print "<div>READ _ENV ARRAY:</div>";
|
||||
print "<pre>" . print_r(array_map('htmlentities', $_ENV), true) . "</pre>";
|
||||
// set + check edit access id
|
||||
$edit_access_id = 3;
|
||||
if (is_object($login) && isset($login->acl['unit'])) {
|
||||
|
||||
@@ -84,6 +84,7 @@ $options = [
|
||||
];
|
||||
|
||||
$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();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "gullevek/www",
|
||||
"name": "gullevek/corelibs",
|
||||
"description": "CoreLibs",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
@@ -8,5 +8,12 @@
|
||||
"email": "clemens.schwaighofer@egplusww.com"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"lib/"
|
||||
]
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9"
|
||||
}
|
||||
}
|
||||
|
||||
2112
www/composer.lock
generated
Normal file
2112
www/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
8
www/configs/.env.example
Normal file
8
www/configs/.env.example
Normal file
@@ -0,0 +1,8 @@
|
||||
# Master configs
|
||||
BASE_NAME=
|
||||
G_TITLE=
|
||||
# DB configs
|
||||
DB_NAME_TEST=
|
||||
DB_USER_TEST=
|
||||
DB_PASS_TEST=
|
||||
DB_HOST_TEST=
|
||||
@@ -13,15 +13,15 @@ declare(strict_types=1);
|
||||
// please be VERY carefull only to change the right side
|
||||
$DB_CONFIG = [
|
||||
'test' => [
|
||||
'db_name' => 'clemens',
|
||||
'db_user' => 'clemens',
|
||||
'db_pass' => 'clemens',
|
||||
'db_host' => 'db.tokyo.tequila.jp',
|
||||
'db_name' => $_ENV['DB_NAME_TEST'] ?? '',
|
||||
'db_user' => $_ENV['DB_USER_TEST'] ?? '',
|
||||
'db_pass' => $_ENV['DB_PASS_TEST'] ?? '',
|
||||
'db_host' => $_ENV['DB_HOST_TEST'] ?? '',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'disable' // allow, disable, require, prefer
|
||||
'db_ssl' => 'allow' // allow, disable, require, prefer
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
@@ -21,64 +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);
|
||||
// flash-root (below media or data)
|
||||
define('FLASH', 'flash' . 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
|
||||
@@ -86,7 +84,7 @@ define('DEFAULT_HASH', 'sha256');
|
||||
// default acl level
|
||||
define('DEFAULT_ACL_LEVEL', 80);
|
||||
// SSL host name
|
||||
// define('SSL_HOST', 'ssl.host.name');
|
||||
// define('SSL_HOST', $_ENV['SSL_HOST'] ?? '');
|
||||
// error page strictness, Default is 3
|
||||
// 1: only show error page as the last mesure if really no mid & aid can be loaded and found at all
|
||||
// 2: if template not found, do not search, show error template
|
||||
@@ -133,15 +131,16 @@ define('USE_SCRIPTACULOUS', false);
|
||||
define('USE_JQUERY', true);
|
||||
|
||||
/************* LAYOUT WIDTHS *************/
|
||||
define('PAGE_WIDTH', 800);
|
||||
define('CONTENT_WIDTH', 800);
|
||||
define('PAGE_WIDTH', '100%');
|
||||
define('CONTENT_WIDTH', '100%');
|
||||
// the default template name
|
||||
define('MASTER_TEMPLATE_NAME', 'main_body.tpl');
|
||||
|
||||
/************* OVERALL CONTROL NAMES *************/
|
||||
// BELOW has HAS to be changed
|
||||
// base name for all session and log names
|
||||
define('BASE_NAME', 'CoreLibs');
|
||||
// only alphanumeric characters, strip all others
|
||||
define('BASE_NAME', preg_replace('/[^A-Za-z0-9]/', '', $_ENV['BASE_NAME'] ?? ''));
|
||||
|
||||
/************* SESSION NAMES *************/
|
||||
// server name HASH
|
||||
@@ -213,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:
|
||||
@@ -230,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
|
||||
@@ -268,7 +267,7 @@ define('LOGIN_ENABLED', $SITE_CONFIG[HOST_NAME]['login_enabled']);
|
||||
define('SHOW_ALL_ERRORS', true);
|
||||
|
||||
/************* GENERAL PAGE TITLE ********/
|
||||
define('G_TITLE', '<OVERALL FALLBACK PAGE TITLE>');
|
||||
define('G_TITLE', $_ENV['G_TITLE'] ?? '');
|
||||
|
||||
/************ STYLE SHEETS / JS **********/
|
||||
define('ADMIN_STYLESHEET', 'edit.css');
|
||||
@@ -302,7 +301,15 @@ if (defined('DEBUG') && DEBUG == false) {
|
||||
}
|
||||
|
||||
/************* AUTO LOADER *******************/
|
||||
// read auto loader
|
||||
require BASE . LIB . 'autoloader.php';
|
||||
// read auto loader for lib only
|
||||
// require BASE . LIB . 'autoloader.php';
|
||||
// composer auto loader, IF composer.json file includes classmap for lib/:
|
||||
// "autoload": {
|
||||
// "classmap": [
|
||||
// "lib/"
|
||||
// ]
|
||||
// },
|
||||
// NOTE BASE: __DIR__ . DIRECTORY_SEPARATOR . '..' DIRECTORY_SEPARATOR;
|
||||
require BASE . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// DEFINE('SOME_ID', <SOME VALUE>);
|
||||
// define('SOME_ID', <SOME VALUE>);
|
||||
|
||||
/************* CONVERT *******************/
|
||||
// this only needed if the external thumbnail create is used
|
||||
|
||||
@@ -16,6 +16,13 @@ $CONFIG_PATH_PREFIX = '';
|
||||
for ($dir_pos = 0, $dir_max = count(explode(DIRECTORY_SEPARATOR, __DIR__)); $dir_pos <= $dir_max; $dir_pos++) {
|
||||
$CONFIG_PATH_PREFIX .= '..' . DIRECTORY_SEPARATOR;
|
||||
if (file_exists($CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php')) {
|
||||
// check if there is an read env file, load it
|
||||
if (file_exists($CONFIG_PATH_PREFIX . CONFIG_PATH . 'read_env_file.php')) {
|
||||
require $CONFIG_PATH_PREFIX . CONFIG_PATH . 'read_env_file.php';
|
||||
// load env variables first
|
||||
readEnvFile($CONFIG_PATH_PREFIX . CONFIG_PATH);
|
||||
}
|
||||
// then load master config file that loads all other config files
|
||||
require $CONFIG_PATH_PREFIX . CONFIG_PATH . 'config.master.php';
|
||||
break;
|
||||
}
|
||||
@@ -26,7 +33,7 @@ if (!defined('DS')) {
|
||||
}
|
||||
// find trigger name "admin/" or "frontend/" in the getcwd() folder
|
||||
foreach (['admin', 'frontend'] as $folder) {
|
||||
if (strstr(getcwd(), DS . $folder)) {
|
||||
if (strstr(getcwd() ?: '', DS . $folder)) {
|
||||
define('CONTENT_PATH', $folder . DS);
|
||||
break;
|
||||
}
|
||||
|
||||
84
www/configs/read_env_file.php
Normal file
84
www/configs/read_env_file.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* parses .env file
|
||||
*
|
||||
* Rules for .env file
|
||||
* variable is any alphanumeric string followed by = on the same line
|
||||
* content starts with the first non space part
|
||||
* strings can be contained in "
|
||||
* strings MUST be contained in " if they are multiline
|
||||
* if string starts with " it will match until another " is found
|
||||
* anything AFTER " is ignored
|
||||
* if there are two variables with the same name only the first is used
|
||||
* variables are case sensitive
|
||||
*
|
||||
* @param string $path Folder to file, default is __DIR__
|
||||
* @param string $env_file What file to load, default is .env
|
||||
* @return int -1 other error
|
||||
* 0 for success full load
|
||||
* 1 for file loadable, but no data inside
|
||||
* 2 for file not readable
|
||||
* 3 for file not found
|
||||
*/
|
||||
function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int
|
||||
{
|
||||
// default -1;
|
||||
$status = -1;
|
||||
$env_file_target = $path . DIRECTORY_SEPARATOR . $env_file;
|
||||
// this is not a file -> abort
|
||||
if (!is_file($env_file_target)) {
|
||||
$status = 3;
|
||||
return $status;
|
||||
}
|
||||
// cannot open file -> abort
|
||||
if (($fp = fopen($env_file_target, 'r')) === false) {
|
||||
$status = 2;
|
||||
return $status;
|
||||
}
|
||||
// set to readable but not yet any data loaded
|
||||
$status = 1;
|
||||
$block = false;
|
||||
$var = '';
|
||||
while ($line = fgets($fp)) {
|
||||
// main match for variable = value part
|
||||
if (preg_match("/^\s*([\w_.]+)\s*=\s*((\"?).*)/", $line, $matches)) {
|
||||
$var = $matches[1];
|
||||
$value = $matches[2];
|
||||
$quotes = $matches[3];
|
||||
// wirte only if env is not set yet, and write only the first time
|
||||
if (empty($_ENV[$var])) {
|
||||
if (!empty($quotes)) {
|
||||
// match greedy for first to last so we move any " if there are
|
||||
if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) {
|
||||
$value = $matches[1];
|
||||
} else {
|
||||
// this is a multi line
|
||||
$block = true;
|
||||
// first " in string remove
|
||||
// add removed new line back because this is a multi line
|
||||
$value = ltrim($value, '"') . PHP_EOL;
|
||||
}
|
||||
}
|
||||
// if block is set, we strip line of slashes
|
||||
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
|
||||
// set successful load
|
||||
$status = 0;
|
||||
}
|
||||
} elseif ($block === true) {
|
||||
// read line until there is a unescaped "
|
||||
// this also strips everything after the last "
|
||||
if (preg_match("/(.*[^\\\])\"/", $line, $matches)) {
|
||||
$block = false;
|
||||
// strip ending " and EVERYTHING that follows after that
|
||||
$line = $matches[1];
|
||||
}
|
||||
// strip line of slashes
|
||||
$_ENV[$var] .= stripslashes($line);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
return $status;
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -3,3 +3,5 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
require 'config.php';
|
||||
|
||||
// __END__
|
||||
|
||||
@@ -12,11 +12,9 @@ declare(strict_types=1);
|
||||
|
||||
//------------------------------ variable init start
|
||||
// for dev test we set full error reporting; writes everything, except E_ERROR into logs/php_error-<day>.log
|
||||
if ($DEBUG_ALL && $ENABLE_ERROR_HANDLING) {
|
||||
if (!empty($DEBUG_ALL) && !empty($ENABLE_ERROR_HANDLING)) {
|
||||
include BASE . LIBS . "Error.Handling.php";
|
||||
}
|
||||
// predefine vars
|
||||
$messages = array();
|
||||
//------------------------------ variable init end
|
||||
|
||||
//------------------------------ library include start
|
||||
@@ -82,7 +80,7 @@ if (!$login->login) {
|
||||
|
||||
// automatic hide for DEBUG messages on live server
|
||||
// can be overridden when setting DEBUG_ALL_OVERRIDE on top of the script (for emergency debugging of one page only)
|
||||
if ((TARGET == 'live' || TARGET == 'remote') && !$DEBUG_ALL_OVERRIDE) {
|
||||
if ((TARGET == 'live' || TARGET == 'remote') && !empty($DEBUG_ALL_OVERRIDE)) {
|
||||
foreach (['debug', 'echo', 'print'] as $target) {
|
||||
$login->log->setLogLevelAll($target, false);
|
||||
$cms->log->setLogLevelAll($target, false);
|
||||
|
||||
@@ -175,7 +175,7 @@ if ($form->my_page_name == 'edit_order') {
|
||||
$options_name = [];
|
||||
$options_selected = [];
|
||||
// DB read data for menu
|
||||
while ($res = $form->dbReturn($q)) {
|
||||
while (is_array($res = $form->dbReturn($q))) {
|
||||
$row_data[] = [
|
||||
"id" => $res[$table_name . "_id"],
|
||||
"name" => $res["name"],
|
||||
|
||||
@@ -100,10 +100,10 @@
|
||||
</script>
|
||||
<!-- /TinyMCE -->
|
||||
{/if}
|
||||
{popup_init src="`$js`/overlib/overlib.js"}
|
||||
</head>
|
||||
<body>
|
||||
<div style="margin: 2px; width: {$table_width}px; margin-bottom: 10px;">
|
||||
{popup_init src="`$js`/overlib/overlib.js"}
|
||||
<div style="margin: 2px; width: {$table_width}; margin-bottom: 10px;">
|
||||
<div style="position: relative; height: 20px;" class="menu">
|
||||
<div style="position: absolute; width: 200px;">{t 1=$USER_NAME|upper}Hello %1{/t}</div>
|
||||
<div style="position: absolute; text-align: right; right: 0px; width: 120px;">
|
||||
@@ -127,13 +127,13 @@
|
||||
{/if}
|
||||
{/foreach}
|
||||
</div>
|
||||
<div class="pagename">
|
||||
<div id="pagename" class="pagename">
|
||||
{$page_name}
|
||||
</div>
|
||||
</div>
|
||||
{* error/warning *}
|
||||
{if $messages}
|
||||
<div style="margin: 2px; width: {$table_width}px;">
|
||||
<div style="margin: 2px; width: {$table_width};">
|
||||
{foreach from=$messages item=item key=key}
|
||||
<div class="{$item.class}">{$item.msg}</div>
|
||||
{/foreach}
|
||||
@@ -143,7 +143,7 @@
|
||||
|
||||
{* debug info *}
|
||||
{if $DEBUG}
|
||||
<div style="width:{$table_width}px;" class="debug_message">
|
||||
<div style="width:{$table_width};" class="debug_message">
|
||||
{$Id}<br>
|
||||
<b>{$smarty.now|date_format:"%Y-%m-%d %H:%M:%S"}</b><br>
|
||||
{$debug_error_msg}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
/* jshint esversion: 6 */
|
||||
|
||||
/* global i18n */
|
||||
|
||||
// debug set
|
||||
/*var FRONTEND_DEBUG = false;
|
||||
var DEBUG = true;
|
||||
@@ -22,7 +24,8 @@ var GL_OB_BASE = 30;
|
||||
* @param {String} winName window name
|
||||
* @param {Object} features popup features
|
||||
*/
|
||||
function pop(theURL, winName, features) {
|
||||
function pop(theURL, winName, features) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
winName = window.open(theURL, winName, features);
|
||||
winName.focus();
|
||||
}
|
||||
@@ -31,7 +34,8 @@ function pop(theURL, winName, features) {
|
||||
* automatically resize a text area based on the amount of lines in it
|
||||
* @param {[string} ta_id element id
|
||||
*/
|
||||
function expandTA(ta_id) {
|
||||
function expandTA(ta_id) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var ta;
|
||||
// if a string comes, its a get by id, else use it as an element pass on
|
||||
if (!ta_id.length) {
|
||||
@@ -40,7 +44,7 @@ function expandTA(ta_id) {
|
||||
ta = document.getElementById(ta_id);
|
||||
}
|
||||
var maxChars = ta.cols;
|
||||
var theRows = ta.value.split("\n");
|
||||
var theRows = ta.value.split('\n');
|
||||
var numNewRows = 0;
|
||||
|
||||
for ( var i = 0; i < theRows.length; i++ ) {
|
||||
@@ -124,7 +128,7 @@ function setCenter(id, left, top)
|
||||
* @param {Number} [duration=500] animation time, default 500ms
|
||||
* @param {String} [base='body,html'] base element for offset scroll
|
||||
*/
|
||||
function goToPos(element, offset = 0, duration = 500, base = 'body,html')
|
||||
function goToPos(element, offset = 0, duration = 500, base = 'body,html') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
try {
|
||||
if ($('#' + element).length) {
|
||||
@@ -190,7 +194,7 @@ if (Number.prototype.round) {
|
||||
* @param {Number} x number to be formated
|
||||
* @return {String} formatted with , in thousands
|
||||
*/
|
||||
function numberWithCommas(x)
|
||||
function numberWithCommas(x) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var parts = x.toString().split('.');
|
||||
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
@@ -202,7 +206,7 @@ function numberWithCommas(x)
|
||||
* @param {String} string any string
|
||||
* @return {String} string with <br>
|
||||
*/
|
||||
function convertLBtoBR(string)
|
||||
function convertLBtoBR(string) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return string.replace(/(?:\r\n|\r|\n)/g, '<br>');
|
||||
}
|
||||
@@ -214,14 +218,14 @@ function convertLBtoBR(string)
|
||||
*/
|
||||
if (!String.prototype.escapeHTML) {
|
||||
String.prototype.escapeHTML = function() {
|
||||
return this.replace(/[&<>"'\/]/g, function (s) {
|
||||
return this.replace(/[&<>"'/]/g, function (s) {
|
||||
var entityMap = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
"/": '/'
|
||||
'\'': ''',
|
||||
'/': '/'
|
||||
};
|
||||
|
||||
return entityMap[s];
|
||||
@@ -238,12 +242,12 @@ if (!String.prototype.unescapeHTML) {
|
||||
String.prototype.unescapeHTML = function() {
|
||||
return this.replace(/&[#\w]+;/g, function (s) {
|
||||
var entityMap = {
|
||||
"&": "&",
|
||||
"<": "<",
|
||||
">": ">",
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
''': "'",
|
||||
'/': "/"
|
||||
''': '\'',
|
||||
'/': '/'
|
||||
};
|
||||
|
||||
return entityMap[s];
|
||||
@@ -255,7 +259,7 @@ if (!String.prototype.unescapeHTML) {
|
||||
* returns current timestamp (unix timestamp)
|
||||
* @return {Number} timestamp (in milliseconds)
|
||||
*/
|
||||
function getTimestamp()
|
||||
function getTimestamp() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var date = new Date();
|
||||
return date.getTime();
|
||||
@@ -278,7 +282,7 @@ function dec2hex(dec)
|
||||
* @param {Number} len length of unique id string
|
||||
* @return {String} random string in length of len
|
||||
*/
|
||||
function generateId(len)
|
||||
function generateId(len) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var arr = new Uint8Array((len || 40) / 2);
|
||||
(window.crypto || window.msCrypto).getRandomValues(arr);
|
||||
@@ -291,7 +295,7 @@ function generateId(len)
|
||||
* after many runs it will create duplicates
|
||||
* @return {String} not true random string
|
||||
*/
|
||||
function randomIdF()
|
||||
function randomIdF() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return Math.random().toString(36).substring(2);
|
||||
}
|
||||
@@ -301,7 +305,7 @@ function randomIdF()
|
||||
* @param {string} name Name of function to check if exists
|
||||
* @return {Boolean} true/false
|
||||
*/
|
||||
function isFunction(name)
|
||||
function isFunction(name) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
if (typeof window[name] !== 'undefined' &&
|
||||
typeof window[name] === 'function') {
|
||||
@@ -320,7 +324,7 @@ function isFunction(name)
|
||||
* hidden next are all the arguments
|
||||
* @return {mixed} Return values from functon
|
||||
*/
|
||||
function executeFunctionByName(functionName, context /*, args */)
|
||||
function executeFunctionByName(functionName, context /*, args */) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var args = Array.prototype.slice.call(arguments, 2);
|
||||
var namespaces = functionName.split('.');
|
||||
@@ -362,7 +366,7 @@ function getObjectCount(object)
|
||||
*/
|
||||
function keyInObject(key, object)
|
||||
{
|
||||
return (Object.prototype.hasOwnProperty.call(object, key)) ? true : false;
|
||||
return Object.prototype.hasOwnProperty.call(object, key) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -371,7 +375,7 @@ function keyInObject(key, object)
|
||||
* @param {Mixed} value any value (String, Number, etc)
|
||||
* @return {String} the key found for the first matching value
|
||||
*/
|
||||
function getKeyByValue(object, value)
|
||||
function getKeyByValue(object, value) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return Object.keys(object).find(key => object[key] === value);
|
||||
// return Object.keys(object).find(function (key) {
|
||||
@@ -385,9 +389,9 @@ function getKeyByValue(object, value)
|
||||
* @param {Mixed} value any value (String, Number, etc)
|
||||
* @return {Boolean} true on value found, false on not found
|
||||
*/
|
||||
function valueInObject(object, value)
|
||||
function valueInObject(object, value) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return (Object.keys(object).find(key => object[key] === value)) ? true : false;
|
||||
return Object.keys(object).find(key => object[key] === value) ? true : false;
|
||||
// return Object.keys(object).find(function (key) {
|
||||
// return object[key] === value;
|
||||
// }) ? true : false;
|
||||
@@ -403,7 +407,7 @@ function valueInObject(object, value)
|
||||
function deepCopyFunction(inObject)
|
||||
{
|
||||
var outObject, value, key;
|
||||
if (typeof inObject !== "object" || inObject === null) {
|
||||
if (typeof inObject !== 'object' || inObject === null) {
|
||||
return inObject; // Return the value if inObject is not an object
|
||||
}
|
||||
// Create an array or object to hold the values
|
||||
@@ -434,14 +438,15 @@ function exists(id)
|
||||
* @param {Number} bytes bytes in int
|
||||
* @return {String} string in GB/MB/KB
|
||||
*/
|
||||
function formatBytes(bytes)
|
||||
function formatBytes(bytes) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var i = -1;
|
||||
do {
|
||||
bytes = bytes / 1024;
|
||||
i++;
|
||||
} while (bytes > 99);
|
||||
return parseFloat(Math.round(bytes * Math.pow(10, 2)) / Math.pow(10, 2)) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
||||
return parseFloat(Math.round(bytes * Math.pow(10, 2)) / Math.pow(10, 2)) +
|
||||
['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -449,7 +454,7 @@ function formatBytes(bytes)
|
||||
* @param {Number} bytes bytes in int
|
||||
* @return {String} string in GB/MB/KB
|
||||
*/
|
||||
function formatBytesLong(bytes)
|
||||
function formatBytesLong(bytes) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
var sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
@@ -461,7 +466,7 @@ function formatBytesLong(bytes)
|
||||
* @param {String|Number} bytes Any string with B/K/M/etc
|
||||
* @return {String|Number} A byte number, or original string as is
|
||||
*/
|
||||
function stringByteFormat(bytes)
|
||||
function stringByteFormat(bytes) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// if anything not string return
|
||||
if (!(typeof bytes === 'string' || bytes instanceof String)) {
|
||||
@@ -536,7 +541,7 @@ function errorCatch(err)
|
||||
* default empty. for console.log
|
||||
* @param {Boolean} [overlay=true] override the auto hide/show over the overlay div block
|
||||
*/
|
||||
function actionIndicator(loc, overlay = true)
|
||||
function actionIndicator(loc, overlay = true) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
if ($('#indicator').is(':visible')) {
|
||||
actionIndicatorHide(loc, overlay);
|
||||
@@ -613,7 +618,7 @@ function overlayBoxHide()
|
||||
/**
|
||||
* position the overlay block box and shows it
|
||||
*/
|
||||
function setOverlayBox()
|
||||
function setOverlayBox() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
if (!$('#overlayBox').is(':visible')) {
|
||||
$('#overlayBox').show();
|
||||
@@ -623,7 +628,7 @@ function setOverlayBox()
|
||||
/**
|
||||
* opposite of set, always hides overlay box
|
||||
*/
|
||||
function hideOverlayBox()
|
||||
function hideOverlayBox() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
if ($('#overlayBox').is(':visible')) {
|
||||
$('#overlayBox').hide();
|
||||
@@ -633,7 +638,7 @@ function hideOverlayBox()
|
||||
/**
|
||||
* the abort call, clears the action box and hides it and the overlay box
|
||||
*/
|
||||
function ClearCall()
|
||||
function ClearCall() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
$('#actionBox').html('');
|
||||
$('#actionBox').hide();
|
||||
@@ -654,7 +659,7 @@ function ClearCall()
|
||||
* - indicator is page centered
|
||||
* @param {String} loc ID string, only used for console log
|
||||
*/
|
||||
function showActionIndicator(loc)
|
||||
function showActionIndicator(loc) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// console.log('Indicator: SHOW [%s]', loc);
|
||||
// check if indicator element exists
|
||||
@@ -692,7 +697,7 @@ function showActionIndicator(loc)
|
||||
* is set to this value
|
||||
* @param {String} loc ID string, only used for console log
|
||||
*/
|
||||
function hideActionIndicator(loc)
|
||||
function hideActionIndicator(loc) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// console.log('Indicator: HIDE [%s]', loc);
|
||||
// check if indicator is visible
|
||||
@@ -732,7 +737,7 @@ function checkOverlayExists()
|
||||
* if visible, add +1 to the GL_OB_S variable and
|
||||
* up zIndex by this value
|
||||
*/
|
||||
function showOverlayBoxLayers(el_id)
|
||||
function showOverlayBoxLayers(el_id) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// console.log('SHOW overlaybox: %s', GL_OB_S);
|
||||
// if overlay box is not visible show and set zIndex to 0
|
||||
@@ -789,7 +794,7 @@ function hideOverlayBoxLayers(el_id)
|
||||
/**
|
||||
* only for single action box
|
||||
*/
|
||||
function clearCallActionBox()
|
||||
function clearCallActionBox() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
$('#actionBox').html('');
|
||||
$('#actionBox').hide();
|
||||
@@ -872,7 +877,7 @@ function aelx(base, ...attach)
|
||||
* @param {Array} attach array of objects to attach
|
||||
* @return {Object} "none", technically there is no return needed, global attach
|
||||
*/
|
||||
function aelxar(base, attach)
|
||||
function aelxar(base, attach) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
for (var i = 0; i < attach.length; i ++) {
|
||||
// base.sub.push(Object.assign({}, attach[i]));
|
||||
@@ -886,7 +891,7 @@ function aelxar(base, attach)
|
||||
* @param {Object} base cel created element
|
||||
* @return {Object} returns reset base element
|
||||
*/
|
||||
function rel(base)
|
||||
function rel(base) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
base.sub = [];
|
||||
return base;
|
||||
@@ -930,7 +935,7 @@ function acssel(_element, css)
|
||||
* @param {String} acss style to add (name)
|
||||
* @return {Object} returns full element
|
||||
*/
|
||||
function scssel(_element, rcss, acss)
|
||||
function scssel(_element, rcss, acss) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
rcssel(_element, rcss);
|
||||
acssel(_element, acss);
|
||||
@@ -1008,7 +1013,7 @@ function phfo(tree)
|
||||
* @param {Array} list Array of cel created objects
|
||||
* @return {String} HTML String
|
||||
*/
|
||||
function phfa(list)
|
||||
function phfa(list) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var content = [];
|
||||
for (var i = 0; i < list.length; i ++) {
|
||||
@@ -1034,7 +1039,7 @@ function phfa(list)
|
||||
* 'values' all others are ignored
|
||||
* @return {String} html with build options block
|
||||
*/
|
||||
function html_options(name, data, selected = '', options_only = false, return_string = false, sort = '')
|
||||
function html_options(name, data, selected = '', options_only = false, return_string = false, sort = '') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// wrapper to new call
|
||||
return html_options_block(name, data, selected, false, options_only, return_string, sort);
|
||||
@@ -1067,6 +1072,7 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl
|
||||
var element_option;
|
||||
var data_list = []; // for sorted output
|
||||
var value;
|
||||
var options = {};
|
||||
// var option;
|
||||
if (multiple > 0) {
|
||||
select_options.multiple = '';
|
||||
@@ -1139,7 +1145,7 @@ function html_options_block(name, data, selected = '', multiple = 0, options_onl
|
||||
* @param {String} [sort=''] if empty as is, else allowed 'keys', 'values'
|
||||
* all others are ignored
|
||||
*/
|
||||
function html_options_refill(name, data, sort = '')
|
||||
function html_options_refill(name, data, sort = '') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var element_option;
|
||||
var option_selected;
|
||||
@@ -1186,21 +1192,26 @@ function html_options_refill(name, data, sort = '')
|
||||
* or empty for none
|
||||
* @return {Object|String} parameter entry list
|
||||
*/
|
||||
function parseQueryString(query = '', return_key = '') {
|
||||
function parseQueryString(query = '', return_key = '') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
if (!query) {
|
||||
query = window.location.search.substring(1);
|
||||
}
|
||||
var vars = query.split("&");
|
||||
var vars = query.split('&');
|
||||
var query_string = {};
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
var pair = vars[i].split('=');
|
||||
var key = decodeURIComponent(pair[0]);
|
||||
var value = decodeURIComponent(pair[1]);
|
||||
// skip over run if there is nothing
|
||||
if (!key || value === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
// If first entry with this name
|
||||
if (typeof query_string[key] === "undefined") {
|
||||
if (typeof query_string[key] === 'undefined') {
|
||||
query_string[key] = decodeURIComponent(value);
|
||||
// If second entry with this name
|
||||
} else if (typeof query_string[key] === "string") {
|
||||
} else if (typeof query_string[key] === 'string') {
|
||||
var arr = [query_string[key], decodeURIComponent(value)];
|
||||
query_string[key] = arr;
|
||||
// If third or later entry with this name
|
||||
@@ -1220,26 +1231,59 @@ function parseQueryString(query = '', return_key = '') {
|
||||
}
|
||||
|
||||
/**
|
||||
* searchs the current url for a parameter
|
||||
* @param {String} key uid key to get data for
|
||||
* @return {String} value for the key or '' for not found
|
||||
* searches query parameters for entry and returns data either as string or array
|
||||
* if no search is given the whole parameters are returned as an object
|
||||
* if a parameter is set several times it will be returned as an array
|
||||
* if search parameter set and nothing found and empty string is returned
|
||||
* if no parametes exist and no serach is set and empty object is returned
|
||||
* @param {String} [search=''] if set searches for this entry, if empty
|
||||
* all parameters are returned
|
||||
* @param {String} [query=''] different query string to parse, if not
|
||||
* set (default) the current window href is used
|
||||
* @param {Bool} [single=false] if set to true then only the first found
|
||||
* will be returned
|
||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||
* and only one entry, then string, else array
|
||||
* unless single is true
|
||||
*/
|
||||
function getQueryStringParam(key)
|
||||
function getQueryStringParam(search = '', query = '', single = false) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
var url = new URL(window.location.href);
|
||||
var param = url.searchParams.get(key);
|
||||
if (param) {
|
||||
return param;
|
||||
} else {
|
||||
return '';
|
||||
if (!query) {
|
||||
query = window.location.href;
|
||||
}
|
||||
const url = new URL(query);
|
||||
let param = '';
|
||||
if (search) {
|
||||
let _params = url.searchParams.getAll(search);
|
||||
if (_params.length == 1 || single === true) {
|
||||
param = _params[0];
|
||||
} else if (_params.length > 1) {
|
||||
param = _params;
|
||||
}
|
||||
} else {
|
||||
// will be object, so declare it one
|
||||
param = {};
|
||||
// loop over paramenters
|
||||
for (const [key] of url.searchParams.entries()) {
|
||||
// check if not yet set
|
||||
if (typeof param[key] === 'undefined') {
|
||||
// get the parameters multiple
|
||||
let _params = url.searchParams.getAll(key);
|
||||
// if 1 set as string, else attach array as is
|
||||
param[key] = _params.length < 2 || single === true ?
|
||||
_params[0] :
|
||||
_params;
|
||||
}
|
||||
}
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
// *** MASTER logout call
|
||||
/**
|
||||
* submits basic data for form logout
|
||||
*/
|
||||
function loginLogout()
|
||||
function loginLogout() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
const form = document.createElement('form');
|
||||
form.method = 'post';
|
||||
@@ -1259,7 +1303,7 @@ function loginLogout()
|
||||
* if not set mainHeader is assumed
|
||||
* this is the target div for the "loginRow"
|
||||
*/
|
||||
function createLoginRow(login_string, header_id = 'mainHeader')
|
||||
function createLoginRow(login_string, header_id = 'mainHeader') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// if header does not exist, we do nothing
|
||||
if (exists(header_id)) {
|
||||
@@ -1293,7 +1337,8 @@ function createLoginRow(login_string, header_id = 'mainHeader')
|
||||
* if not set mainHeader is assumed
|
||||
* this is the target div for the "menuRow"
|
||||
*/
|
||||
function createNavMenu(nav_menu, header_id = 'mainHeader') {
|
||||
function createNavMenu(nav_menu, header_id = 'mainHeader') // eslint-disable-line no-unused-vars
|
||||
{
|
||||
// must be an object
|
||||
if (isObject(nav_menu) && getObjectCount(nav_menu) > 1) {
|
||||
// do we have more than one entry, if not, do not show (single page)
|
||||
|
||||
@@ -72,44 +72,70 @@ use CoreLibs\Check\Password;
|
||||
|
||||
class Login extends \CoreLibs\DB\IO
|
||||
{
|
||||
/** @var string */
|
||||
private $euid; // the user id var
|
||||
// is set to one if login okay, or EUID is set and user is okay to access this page
|
||||
/** @var bool */
|
||||
private $permission_okay = false;
|
||||
/** @var string */
|
||||
public $login; // pressed login
|
||||
/** @var string */
|
||||
private $action; // master action command
|
||||
/** @var string */
|
||||
private $username; // login name
|
||||
/** @var string */
|
||||
private $password; // login password
|
||||
/** @var string */
|
||||
private $logout; // logout button
|
||||
// login error code, can be matched to the array login_error_msg, which holds the string
|
||||
/** @var int */
|
||||
private $login_error = 0;
|
||||
/** @var bool */
|
||||
private $password_change = false; // if this is set to true, the user can change passwords
|
||||
/** @var bool */
|
||||
private $password_change_ok = false; // password change was successful
|
||||
// can we reset password and mail to user with new password set screen
|
||||
/** @var bool */
|
||||
private $password_forgot = false;
|
||||
private $password_forgot_ok = false; // password forgot mail send ok
|
||||
/** @var bool */
|
||||
// private $password_forgot_ok = false; // password forgot mail send ok
|
||||
/** @var string */
|
||||
private $change_password;
|
||||
/** @var string */
|
||||
private $pw_username;
|
||||
/** @var string */
|
||||
private $pw_old_password;
|
||||
/** @var string */
|
||||
private $pw_new_password;
|
||||
/** @var string */
|
||||
private $pw_new_password_confirm;
|
||||
/** @var array<string> */
|
||||
private $pw_change_deny_users = []; // array of users for which the password change is forbidden
|
||||
/** @var string */
|
||||
private $logout_target;
|
||||
/** @var int */
|
||||
private $max_login_error_count = -1;
|
||||
/** @var array<string> */
|
||||
private $lock_deny_users = [];
|
||||
|
||||
// if we have password change we need to define some rules
|
||||
/** @var int */
|
||||
private $password_min_length = PASSWORD_MIN_LENGTH;
|
||||
// max length is fixed as 255 (for input type max), if set highter, it will be set back to 255
|
||||
/** @var int */
|
||||
private $password_max_length = PASSWORD_MAX_LENGTH;
|
||||
// can have several regexes, if nothing set, all is ok
|
||||
/** @var array<string> */
|
||||
private $password_valid_chars = [
|
||||
// '^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,}$',
|
||||
// '^(?.*(\pL)u)(?=.*(\pN)u)(?=.*([^\pL\pN])u).{8,}',
|
||||
];
|
||||
|
||||
// all possible login error conditions
|
||||
/** @var array<mixed> */
|
||||
private $login_error_msg = [];
|
||||
// this is an array holding all strings & templates passed from the outside (translation)
|
||||
/** @var array<mixed> */
|
||||
private $login_template = [
|
||||
'strings' => [],
|
||||
'password_change' => '',
|
||||
@@ -117,18 +143,23 @@ class Login extends \CoreLibs\DB\IO
|
||||
];
|
||||
|
||||
// acl vars
|
||||
/** @var array<mixed> */
|
||||
public $acl = [];
|
||||
/** @var array<mixed> */
|
||||
public $default_acl_list = [];
|
||||
// login html, if we are on an ajax page
|
||||
/** @var string|null */
|
||||
private $login_html = '';
|
||||
/** @var bool */
|
||||
private $login_is_ajax_page = false;
|
||||
|
||||
// language
|
||||
/** @var \CoreLibs\Language\L10n */
|
||||
public $l;
|
||||
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks, closes itself
|
||||
* @param array $db_config db config array
|
||||
* @param array<mixed> $db_config db config array
|
||||
*/
|
||||
public function __construct(array $db_config)
|
||||
{
|
||||
@@ -160,12 +191,13 @@ class Login extends \CoreLibs\DB\IO
|
||||
exit;
|
||||
}
|
||||
|
||||
// set global is ajax page for if we show the data directly, or need to pass it back
|
||||
// set global is ajax page for if we show the data directly,
|
||||
// or need to pass it back
|
||||
// to the continue AJAX class for output back to the user
|
||||
$this->login_is_ajax_page = isset($GLOBALS['AJAX_PAGE']) && $GLOBALS['AJAX_PAGE'] ? true : false;
|
||||
// set the default lang
|
||||
$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;
|
||||
@@ -176,7 +208,8 @@ class Login extends \CoreLibs\DB\IO
|
||||
// check what schema to use. if there is a login schema use this, else check
|
||||
// if there is a schema set in the config, or fall back to DB_SCHEMA
|
||||
// if this exists, if this also does not exists use public schema
|
||||
if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) {
|
||||
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||
} elseif (isset($db_config['db_schema']) && $db_config['db_schema']) {
|
||||
$SCHEMA = $db_config['db_schema'];
|
||||
@@ -185,6 +218,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
} else {
|
||||
$SCHEMA = 'public';
|
||||
}
|
||||
// echo "<h1>*****SCHEMA******</h1>: $SCHEMA<br>";
|
||||
// set schema if schema differs to schema set in db conneciton
|
||||
if ($this->dbGetSchema() && $this->dbGetSchema() != $SCHEMA) {
|
||||
$this->dbExec("SET search_path TO " . $SCHEMA);
|
||||
@@ -225,7 +259,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$_SESSION['DEFAULT_ACL_LIST'] = [];
|
||||
// read the current edit_access_right list into an array
|
||||
$q = "SELECT level, type, name FROM edit_access_right WHERE level >= 0 ORDER BY level";
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
// level to description format (numeric)
|
||||
$this->default_acl_list[$res['level']] = [
|
||||
'type' => $res['type'],
|
||||
@@ -387,8 +421,11 @@ class Login extends \CoreLibs\DB\IO
|
||||
// password match is done in script, against old plain or new blowfish encypted
|
||||
. "(LOWER(username) = '" . $this->dbEscapeString(strtolower($this->username)) . "') ";
|
||||
$res = $this->dbReturn($q);
|
||||
// username is wrong, but we throw for wrong username and wrong password the same error
|
||||
if (!$this->cursor_ext[md5($q)]['num_rows']) {
|
||||
if (!is_array($res)) {
|
||||
$this->login_error = 1009;
|
||||
$this->permission_okay = false;
|
||||
} elseif (!$this->cursor_ext[md5($q)]['num_rows']) {
|
||||
// username is wrong, but we throw for wrong username and wrong password the same error
|
||||
$this->login_error = 1010;
|
||||
} else {
|
||||
// if login errors is half of max errors and the last login error
|
||||
@@ -426,7 +463,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$_SESSION['EUID'] = $this->euid = $res['edit_user_id'];
|
||||
// check if user is okay
|
||||
$this->loginCheckPermissions();
|
||||
if (!$this->login_error) {
|
||||
if ($this->login_error == 0) {
|
||||
// now set all session vars and read page permissions
|
||||
$GLOBALS['DEBUG_ALL'] = $_SESSION['DEBUG_ALL'] = $res['debug'];
|
||||
$GLOBALS['DB_DEBUG'] = $_SESSION['DB_DEBUG'] = $res['db_debug'];
|
||||
@@ -470,6 +507,9 @@ class Login extends \CoreLibs\DB\IO
|
||||
. "AND epa.enabled = 1 AND epa.edit_group_id = " . $res["edit_group_id"] . " "
|
||||
. "ORDER BY ep.order_number";
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
if (!is_array($res)) {
|
||||
break;
|
||||
}
|
||||
// page id array for sub data readout
|
||||
$edit_page_ids[$res['edit_page_id']] = $res['cuid'];
|
||||
// create the array for pages
|
||||
@@ -496,22 +536,20 @@ class Login extends \CoreLibs\DB\IO
|
||||
$pages_acl[$res['filename']] = $res['level'];
|
||||
} // for each page
|
||||
// get the visible groups for all pages and write them to the pages
|
||||
$_edit_page_id = 0;
|
||||
$q = "SELECT epvg.edit_page_id, name, flag "
|
||||
. "FROM edit_visible_group evp, edit_page_visible_group epvg "
|
||||
. "WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id "
|
||||
. "AND epvg.edit_page_id IN (" . join(', ', array_keys($edit_page_ids)) . ") "
|
||||
. "ORDER BY epvg.edit_page_id";
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
$pages[$edit_page_ids[$res['edit_page_id']]]['visible'][$res['name']] = $res['flag'];
|
||||
}
|
||||
// get the same for the query strings
|
||||
$_edit_page_id = 0;
|
||||
$q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs "
|
||||
. "WHERE enabled = 1 AND edit_page_id "
|
||||
. "IN (" . join(', ', array_keys($edit_page_ids)) . ") "
|
||||
. "ORDER BY eqs.edit_page_id";
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
$pages[$edit_page_ids[$res['edit_page_id']]]['query'][] = [
|
||||
'name' => $res['name'],
|
||||
'value' => $res['value'],
|
||||
@@ -519,14 +557,13 @@ class Login extends \CoreLibs\DB\IO
|
||||
];
|
||||
}
|
||||
// get the page content and add them to the page
|
||||
$_edit_page_id = 0;
|
||||
$q = "SELECT epc.edit_page_id, epc.name, epc.uid, epc.order_number, "
|
||||
. "epc.online, ear.level, ear.type "
|
||||
. "FROM edit_page_content epc, edit_access_right ear "
|
||||
. "WHERE epc.edit_access_right_id = ear.edit_access_right_id AND "
|
||||
. "epc.edit_page_id IN (" . join(', ', array_keys($edit_page_ids)) . ") "
|
||||
. "ORDER BY epc.order_number";
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
$pages[$edit_page_ids[$res['edit_page_id']]]['content'][$res['uid']] = [
|
||||
'name' => $res['name'],
|
||||
'uid' => $res['uid'],
|
||||
@@ -550,13 +587,13 @@ class Login extends \CoreLibs\DB\IO
|
||||
$unit_access = [];
|
||||
$eauid = [];
|
||||
$unit_acl = [];
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
// read edit access data fields and drop them into the unit access array
|
||||
$q_sub = "SELECT name, value "
|
||||
. "FROM edit_access_data "
|
||||
. "WHERE enabled = 1 AND edit_access_id = " . $res['edit_access_id'];
|
||||
$ea_data = [];
|
||||
while ($res_sub = $this->dbReturn($q_sub)) {
|
||||
while (is_array($res_sub = $this->dbReturn($q_sub))) {
|
||||
$ea_data[$res_sub['name']] = $res_sub['value'];
|
||||
}
|
||||
// build master unit array
|
||||
@@ -583,7 +620,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$_SESSION['EAID'] = $eauid;
|
||||
} // user has permission to THIS page
|
||||
} // user was not enabled or other login error
|
||||
if ($this->login_error) {
|
||||
if ($this->login_error && is_array($res)) {
|
||||
$login_error_date_first = '';
|
||||
if ($res['login_error_count'] == 0) {
|
||||
$login_error_date_first = ", login_error_date_first = NOW()";
|
||||
@@ -633,6 +670,11 @@ class Login extends \CoreLibs\DB\IO
|
||||
. "AND filename = '" . $this->page_name . "' "
|
||||
. "AND eg.enabled = 1 AND epa.enabled = 1";
|
||||
$res = $this->dbReturnRow($q);
|
||||
if (!is_array($res)) {
|
||||
$this->login_error = 109;
|
||||
$this->permission_okay = false;
|
||||
return $this->permission_okay;
|
||||
}
|
||||
// unset mem limit if debug is set to 1
|
||||
// if (
|
||||
// ($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] ||
|
||||
@@ -795,10 +837,14 @@ class Login extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* checks if this edit access id is valid
|
||||
* @param int|null $edit_access_id access id pk to check
|
||||
* @return bool true/false: if the edit access is not in the valid list: false
|
||||
* @return bool true/false: if the edit access is not
|
||||
* in the valid list: false
|
||||
*/
|
||||
public function loginCheckEditAccess($edit_access_id): bool
|
||||
{
|
||||
if ($edit_access_id === null) {
|
||||
return false;
|
||||
}
|
||||
if (array_key_exists($edit_access_id, $this->acl['unit'])) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -879,8 +925,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';
|
||||
@@ -892,8 +941,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';
|
||||
@@ -943,7 +1001,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* prints out login html part if no permission (error) is set
|
||||
* @return ?string html data for login page, or null for nothing
|
||||
* @return string|null html data for login page, or null for nothing
|
||||
*/
|
||||
private function loginPrintLogin()
|
||||
{
|
||||
@@ -958,7 +1016,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
$LOGOUT_TARGET = "";
|
||||
}
|
||||
|
||||
$html_string = $this->login_template['template'];
|
||||
$html_string = (string)$this->login_template['template'];
|
||||
|
||||
// if password change is okay
|
||||
if ($this->password_change) {
|
||||
@@ -1053,7 +1111,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';
|
||||
@@ -1066,7 +1124,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
|
||||
@@ -1099,6 +1160,8 @@ class Login extends \CoreLibs\DB\IO
|
||||
$error_msgs = [
|
||||
// actually obsolete
|
||||
'100' => $this->l->__('Fatal Error: <b>[EUID] came in as GET/POST!</b>'),
|
||||
// query errors
|
||||
'1009' => $this->l->__('Fatal Error: <b>Login query reading failed<b>'),
|
||||
// user not found
|
||||
'1010' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'),
|
||||
// blowfish password wrong
|
||||
@@ -1111,6 +1174,7 @@ class Login extends \CoreLibs\DB\IO
|
||||
'103' => $this->l->__('Fatal Error: <b>You do not have the rights to access this Page</b>'),
|
||||
'104' => $this->l->__('Fatal Error: <b>Login Failed - User not enabled</b>'),
|
||||
'105' => $this->l->__('Fatal Error: <b>Login Failed - User is locked</b>'),
|
||||
'109' => $this->l->__('Fatal Error: <b>Check permission query reading failed</b>'),
|
||||
// actually this is an illegal user, but I mask it
|
||||
'220' => $this->l->__('Fatal Error: <b>Password change - The user could not be found</b>'),
|
||||
'200' => $this->l->__('Fatal Error: <b>Password change - Please enter username and old password</b>'),
|
||||
@@ -1123,7 +1187,8 @@ class Login extends \CoreLibs\DB\IO
|
||||
// for OK password change
|
||||
'300' => $this->l->__('Success: <b>Password change successful</b>'),
|
||||
// this is bad bad error
|
||||
'9999' => $this->l->__('Fatal Error: <b>necessary crypt engine could not be found</b>. Login is impossible')
|
||||
'9999' => $this->l->__('Fatal Error: <b>necessary crypt engine could not be found</b>. '
|
||||
. 'Login is impossible'),
|
||||
];
|
||||
|
||||
// if password change is okay
|
||||
@@ -1280,7 +1345,7 @@ EOM;
|
||||
'_FILES' => $_FILES,
|
||||
'error' => $this->login_error
|
||||
];
|
||||
$data_binary = $this->dbEscapeBytea(bzcompress(serialize($_data_binary)));
|
||||
$data_binary = $this->dbEscapeBytea((string)bzcompress(serialize($_data_binary)));
|
||||
// SQL querie for log entry
|
||||
$q = "INSERT INTO edit_log "
|
||||
. "(username, password, euid, event_date, event, error, data, data_binary, page, "
|
||||
@@ -1327,6 +1392,7 @@ EOM;
|
||||
public function loginCheckEditAccessId(?int $edit_access_id): ?int
|
||||
{
|
||||
if (
|
||||
$edit_access_id !== null &&
|
||||
isset($_SESSION['UNIT']) &&
|
||||
is_array($_SESSION['UNIT']) &&
|
||||
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
|
||||
|
||||
@@ -34,51 +34,80 @@ namespace CoreLibs\Admin;
|
||||
class Backend extends \CoreLibs\DB\IO
|
||||
{
|
||||
// page name
|
||||
/** @var array<mixed> */
|
||||
public $menu = [];
|
||||
/** @var int|string */
|
||||
public $menu_show_flag = 0; // top menu flag (mostly string)
|
||||
// action ids
|
||||
/** @var array<string> */
|
||||
public $action_list = [
|
||||
'action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag',
|
||||
'action_menu', 'action_value', 'action_error', 'action_loaded'
|
||||
];
|
||||
/** @var string */
|
||||
public $action;
|
||||
/** @var string|int */
|
||||
public $action_id;
|
||||
/** @var string|int */
|
||||
public $action_sub_id;
|
||||
/** @var string|int|bool */
|
||||
public $action_yes;
|
||||
/** @var string */
|
||||
public $action_flag;
|
||||
/** @var string */
|
||||
public $action_menu;
|
||||
/** @var string */
|
||||
public $action_loaded;
|
||||
/** @var string */
|
||||
public $action_value;
|
||||
/** @var string */
|
||||
public $action_error;
|
||||
// ACL array variable if we want to set acl data from outisde
|
||||
/** @var array<mixed> */
|
||||
public $acl = [];
|
||||
/** @var int */
|
||||
public $default_acl;
|
||||
// queue key
|
||||
/** @var string */
|
||||
public $queue_key;
|
||||
// the current active edit access id
|
||||
/** @var int */
|
||||
public $edit_access_id;
|
||||
// error/warning/info messages
|
||||
/** @var array<mixed> */
|
||||
public $messages = [];
|
||||
public $error = 0;
|
||||
public $warning = 0;
|
||||
public $info = 0;
|
||||
/** @var bool */
|
||||
public $error = false;
|
||||
/** @var bool */
|
||||
public $warning = false;
|
||||
/** @var bool */
|
||||
public $info = false;
|
||||
// internal lang & encoding vars
|
||||
/** @var string */
|
||||
public $lang_dir = '';
|
||||
/** @var string */
|
||||
public $lang;
|
||||
/** @var string */
|
||||
public $lang_short;
|
||||
/** @var string */
|
||||
public $encoding;
|
||||
// language
|
||||
/** @var \CoreLibs\Language\L10n */
|
||||
public $l;
|
||||
// smarty publics [end processing in smarty class]
|
||||
/** @var array<mixed> */
|
||||
public $DATA;
|
||||
/** @var array<mixed> */
|
||||
public $HEADER;
|
||||
/** @var array<mixed> */
|
||||
public $DEBUG_DATA;
|
||||
/** @var array<mixed> */
|
||||
public $CONTENT_DATA;
|
||||
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
/**
|
||||
* main class constructor
|
||||
* @param array $db_config db config array
|
||||
* @param array<mixed> $db_config db config array
|
||||
*/
|
||||
public function __construct(array $db_config)
|
||||
{
|
||||
@@ -151,7 +180,7 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* set internal ACL from login ACL
|
||||
* @param array $acl login acl array
|
||||
* @param array<mixed> $acl login acl array
|
||||
*/
|
||||
public function setACL(array $acl): void
|
||||
{
|
||||
@@ -160,16 +189,16 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* writes all action vars plus other info into edit_log tabl
|
||||
* @param string $event any kind of event description,
|
||||
* @param string|array $data any kind of data related to that event
|
||||
* @param string $write_type write type can bei STRING or BINARY
|
||||
* @return void has no return
|
||||
* @param string $event any kind of event description,
|
||||
* @param string|array<mixed> $data any kind of data related to that event
|
||||
* @param string $write_type write type can bei STRING or BINARY
|
||||
* @return void
|
||||
*/
|
||||
public function adbEditLog(string $event = '', $data = '', string $write_type = 'STRING'): void
|
||||
{
|
||||
$data_binary = '';
|
||||
if ($write_type == 'BINARY') {
|
||||
$data_binary = $this->dbEscapeBytea(bzcompress(serialize($data)));
|
||||
$data_binary = $this->dbEscapeBytea((string)bzcompress(serialize($data)));
|
||||
$data = 'see bzip compressed data_binary field';
|
||||
}
|
||||
if ($write_type == 'STRING') {
|
||||
@@ -178,16 +207,16 @@ class Backend extends \CoreLibs\DB\IO
|
||||
}
|
||||
|
||||
// check schema
|
||||
if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) {
|
||||
$SCHEMA = 'public';
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('LOGIN_DB_SCHEMA') && !empty(LOGIN_DB_SCHEMA)) {
|
||||
$SCHEMA = LOGIN_DB_SCHEMA;
|
||||
} elseif ($this->dbGetSchema()) {
|
||||
$SCHEMA = $this->dbGetSchema();
|
||||
} elseif (defined('PUBLIC_SCHEMA')) {
|
||||
$SCHEMA = PUBLIC_SCHEMA;
|
||||
} else {
|
||||
$SCHEMA = 'public';
|
||||
}
|
||||
|
||||
/** @phpstan-ignore-next-line for whatever reason $SCHEMA is seen as possible array */
|
||||
$q = "INSERT INTO " . $SCHEMA . ".edit_log "
|
||||
. "(euid, event_date, event, data, data_binary, page, "
|
||||
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
|
||||
@@ -225,8 +254,8 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* menu creater (from login menu session pages)
|
||||
* @param int $flag visible flag trigger
|
||||
* @return array menu array for output on page (smarty)
|
||||
* @param int $flag visible flag trigger
|
||||
* @return array<mixed> menu array for output on page (smarty)
|
||||
*/
|
||||
public function adbTopMenu(int $flag = 0): array
|
||||
{
|
||||
@@ -373,10 +402,10 @@ class Backend extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* @deprecated
|
||||
* creates out of a normal db_return array an assoc array
|
||||
* @param array $db_array input array
|
||||
* @param array<mixed> $db_array input array
|
||||
* @param string|int|bool $key key
|
||||
* @param string|int|bool $value value
|
||||
* @return array associative array
|
||||
* @return array<mixed> associative array
|
||||
* @deprecated \CoreLibs\Combined\ArrayHandler::genAssocArray()
|
||||
*/
|
||||
public function adbAssocArray(array $db_array, $key, $value): array
|
||||
@@ -407,16 +436,24 @@ class Backend extends \CoreLibs\DB\IO
|
||||
/**
|
||||
* @deprecated
|
||||
* converts picture to a thumbnail with max x and max y size
|
||||
* @param string $pic source image file with or without path
|
||||
* @param int $size_x maximum size width
|
||||
* @param int $size_y maximum size height
|
||||
* @param string $dummy empty, or file_type to show an icon instead of nothing if file is not found
|
||||
* @param string $path if source start is not ROOT path, if empty ROOT is choosen
|
||||
* @return string|bool thumbnail name, or false for error
|
||||
* @param string $pic source image file with or without path
|
||||
* @param int $size_x maximum size width
|
||||
* @param int $size_y maximum size height
|
||||
* @param string $dummy empty, or file_type to show an icon
|
||||
* instead of nothing if file is not found
|
||||
* @param string $path if source start is not ROOT path
|
||||
* if empty ROOT is choosen
|
||||
* @return string|bool thumbnail name, or false for error
|
||||
* @deprecated \CoreLibs\Output\Image::createThumbnail()
|
||||
*/
|
||||
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = '', $path = "", $cache = "")
|
||||
{
|
||||
public function adbCreateThumbnail(
|
||||
string $pic,
|
||||
int $size_x,
|
||||
int $size_y,
|
||||
string $dummy = '',
|
||||
string $path = '',
|
||||
string $cache = ''
|
||||
) {
|
||||
trigger_error(
|
||||
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Output\Image::createThumbnail()',
|
||||
E_USER_DEPRECATED
|
||||
@@ -426,10 +463,10 @@ class Backend extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* wrapper function to fill up the mssages array
|
||||
* @param string $level info/warning/error
|
||||
* @param string $msg string, can be printf formated
|
||||
* @param array $vars optional data for a possible printf formated msg
|
||||
* @return void has no return
|
||||
* @param string $level info/warning/error
|
||||
* @param string $msg string, can be printf formated
|
||||
* @param array<mixed> $vars optional data for a possible printf formated msg
|
||||
* @return void has no return
|
||||
*/
|
||||
public function adbMsg(string $level, string $msg, array $vars = []): void
|
||||
{
|
||||
@@ -442,13 +479,13 @@ class Backend extends \CoreLibs\DB\IO
|
||||
];
|
||||
switch ($level) {
|
||||
case 'info':
|
||||
$this->info = 1;
|
||||
$this->info = true;
|
||||
break;
|
||||
case 'warning':
|
||||
$this->warning = 1;
|
||||
$this->warning = true;
|
||||
break;
|
||||
case 'error':
|
||||
$this->error = 1;
|
||||
$this->error = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -475,7 +512,8 @@ class Backend extends \CoreLibs\DB\IO
|
||||
string $associate = null,
|
||||
string $file = null
|
||||
): void {
|
||||
if (defined('GLOBAL_DB_SCHEMA') && GLOBAL_DB_SCHEMA) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (defined('GLOBAL_DB_SCHEMA') && !empty(GLOBAL_DB_SCHEMA)) {
|
||||
$SCHEMA = GLOBAL_DB_SCHEMA;
|
||||
} elseif ($this->dbGetSchema()) {
|
||||
$SCHEMA = $this->dbGetSchema();
|
||||
|
||||
@@ -57,24 +57,34 @@ namespace CoreLibs;
|
||||
class Basic
|
||||
{
|
||||
// page and host name
|
||||
/** @var string */
|
||||
public $page_name;
|
||||
/** @var string */
|
||||
public $host_name;
|
||||
/** @var int */
|
||||
public $host_port;
|
||||
// logging interface, Debug\Logging class
|
||||
/** @var \CoreLibs\Debug\Logging */
|
||||
public $log;
|
||||
|
||||
// email valid checks
|
||||
/** @var array<mixed> */
|
||||
public $email_regex_check = [];
|
||||
/** @var string */
|
||||
public $email_regex; // regex var for email check
|
||||
|
||||
// data path for files
|
||||
/** @var array<mixed> */
|
||||
public $data_path = [];
|
||||
|
||||
// session name
|
||||
/** @var string */
|
||||
private $session_name = '';
|
||||
private $session_id = '';
|
||||
/** @var string */
|
||||
private $session_id = ''; /** @phpstan-ignore-line */
|
||||
|
||||
// ajax flag
|
||||
/** @var bool */
|
||||
protected $ajax_page_flag = false;
|
||||
|
||||
/**
|
||||
@@ -87,7 +97,7 @@ class Basic
|
||||
$abort = false;
|
||||
foreach (
|
||||
[
|
||||
'DS', 'DIR', 'BASE', 'ROOT', 'LIB', 'INCLUDES', 'LAYOUT', 'PICTURES', 'FLASH',
|
||||
'DS', 'DIR', 'BASE', 'ROOT', 'LIB', 'INCLUDES', 'LAYOUT', 'PICTURES', 'DATA',
|
||||
'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS', 'UPLOADS', 'CSV', 'JS',
|
||||
'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES',
|
||||
'TEMPLATES_C', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
|
||||
@@ -115,7 +125,7 @@ class Basic
|
||||
// set the paths matching to the valid file types
|
||||
$this->data_path = [
|
||||
'P' => PICTURES,
|
||||
'F' => FLASH,
|
||||
'F' => DATA,
|
||||
'V' => VIDEOS,
|
||||
'D' => DOCUMENTS,
|
||||
'A' => PDFS,
|
||||
@@ -154,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,14 +274,14 @@ class Basic
|
||||
* eg $foo->debugFor('print', 'on', ['LOG', 'DEBUG', 'INFO']);
|
||||
* @param string $type error, echo, print
|
||||
* @param string $flag on/off
|
||||
* array $array of levels to turn on/off debug
|
||||
* array<mixed> $array of levels to turn on/off debug
|
||||
* @return void has no return
|
||||
* @deprecated Use $basic->log->debugFor() instead
|
||||
*/
|
||||
public function debugFor(string $type, string $flag): void
|
||||
{
|
||||
trigger_error('Method ' . __METHOD__ . ' is deprecated, use $basic->log->debugFor() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal */
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal @phpstan-ignore-next-line */
|
||||
$this->log->debugFor(...[func_get_args()]);
|
||||
}
|
||||
|
||||
@@ -350,8 +360,8 @@ class Basic
|
||||
/**
|
||||
* merges the given error array with the one from this class
|
||||
* only merges visible ones
|
||||
* @param array $error_msg error array
|
||||
* @return void has no return
|
||||
* @param array<mixed> $error_msg error array
|
||||
* @return void
|
||||
* @deprecated Use $basic->log->mergeErrors() instead
|
||||
*/
|
||||
public function mergeErrors(array $error_msg = []): void
|
||||
@@ -391,8 +401,8 @@ class Basic
|
||||
|
||||
/**
|
||||
* prints a html formatted (pre) array
|
||||
* @param array $array any array
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* @param array<mixed> $array any array
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* @deprecated Use $this->log->prAr() instead
|
||||
*/
|
||||
public function printAr(array $array): string
|
||||
@@ -405,7 +415,8 @@ class Basic
|
||||
* eg for debugging, this function does this
|
||||
* call this method in the child method and you get the parent function that called
|
||||
* @param int $level debug level, default 2
|
||||
* @return ?string null or the function that called the function where this method is called
|
||||
* @return ?string null or the function that called the function
|
||||
* where this method is called
|
||||
* @deprecated Use \CoreLibs\Debug\Support::getCallerMethod() instead
|
||||
*/
|
||||
public static function getCallerMethod(int $level = 2): ?string
|
||||
@@ -471,7 +482,7 @@ class Basic
|
||||
* returns 'checked' or 'selected' if okay
|
||||
* $needle is a var, $haystack an array or a string
|
||||
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
|
||||
* @param array|string $haystack (search in) haystack can be an array or a string
|
||||
* @param array<mixed>|string $haystack (search in) haystack can be an array or a string
|
||||
* @param string $needle needle (search for)
|
||||
* @param int $type type: 0: returns selected, 1, returns checked
|
||||
* @return ?string returns checked or selected, else returns null
|
||||
@@ -504,7 +515,7 @@ class Basic
|
||||
|
||||
/**
|
||||
* get the host name without the port as given by the SELF var
|
||||
* @return array host name/port name
|
||||
* @return array<mixed> host name/port name
|
||||
* @deprecated Use \CoreLibs\Get\System::getHostName() instead
|
||||
*/
|
||||
public function getHostName(): array
|
||||
@@ -563,9 +574,9 @@ class Basic
|
||||
* searches key = value in an array / array
|
||||
* only returns the first one found
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array $haystack haystack (search in)
|
||||
* @param array<mixed> $haystack haystack (search in)
|
||||
* @param string|null $key_lookin the key to look out for, default empty
|
||||
* @return array array with the elements where the needle can be
|
||||
* @return array<mixed> array with the elements where the needle can be
|
||||
* found in the haystack array
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::arraySearchRecursive() instead
|
||||
*/
|
||||
@@ -577,11 +588,11 @@ class Basic
|
||||
|
||||
/**
|
||||
* recursive array search function, which returns all found not only the first one
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array $haystack haystack (search in)
|
||||
* @param string|int $key the key to look for in
|
||||
* @param array|null $path recursive call for previous path
|
||||
* @return ?array all array elements paths where the element was found
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array<mixed> $haystack haystack (search in)
|
||||
* @param string|int $key the key to look for in
|
||||
* @param array<mixed>|null $path recursive call for previous path
|
||||
* @return ?array<mixed> all array elements paths where the element was found
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll() instead
|
||||
*/
|
||||
public static function arraySearchRecursiveAll($needle, array $haystack, $key, ?array $path = null): ?array
|
||||
@@ -592,7 +603,7 @@ class Basic
|
||||
|
||||
/**
|
||||
* array search simple. looks for key, value Combined, if found, returns true
|
||||
* @param array $array array (search in)
|
||||
* @param array<mixed> $array array (search in)
|
||||
* @param string|int $key key (key to search in)
|
||||
* @param string|int $value value (what to find)
|
||||
* @return bool true on found, false on not found
|
||||
@@ -611,7 +622,7 @@ class Basic
|
||||
* ... etc
|
||||
* bool key flag: true: handle keys as string or int
|
||||
* default false: all keys are string
|
||||
* @return array|bool merged array
|
||||
* @return array<mixed>|bool merged array
|
||||
* @deprecated MUSER BE CONVERTED TO \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive() instead
|
||||
*/
|
||||
public static function arrayMergeRecursive()
|
||||
@@ -625,9 +636,9 @@ class Basic
|
||||
* array_diff only checks elements from A that are not in B, but not the
|
||||
* other way around.
|
||||
* Note that like array_diff this only checks first level values not keys
|
||||
* @param array $a array to compare a
|
||||
* @param array $b array to compare b
|
||||
* @return array array with missing elements from a & b
|
||||
* @param array<mixed> $a array to compare a
|
||||
* @param array<mixed> $b array to compare b
|
||||
* @return array<mixed> array with missing elements from a & b
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::arrayDiff() instead
|
||||
*/
|
||||
public static function arrayDiff(array $a, array $b): array
|
||||
@@ -639,9 +650,9 @@ class Basic
|
||||
/**
|
||||
* search for the needle array elements in haystack and return the ones found as an array,
|
||||
* is there nothing found, it returns FALSE (boolean)
|
||||
* @param array $needle elements to search for
|
||||
* @param array $haystack array where the $needle elements should be searched int
|
||||
* @return array|bool either the found elements or false for nothing found or error
|
||||
* @param array<mixed> $needle elements to search for
|
||||
* @param array<mixed> $haystack array where the $needle elements should be searched int
|
||||
* @return array<mixed>|bool either the found elements or false for nothing found or error
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::inArrayAny() instead
|
||||
*/
|
||||
public static function inArrayAny(array $needle, array $haystack)
|
||||
@@ -652,11 +663,11 @@ class Basic
|
||||
|
||||
/**
|
||||
* creates out of a normal db_return array an assoc array
|
||||
* @param array $db_array return array from the database
|
||||
* @param array<mixed> $db_array return array from the database
|
||||
* @param string|int|bool $key key set, false for not set
|
||||
* @param string|int|bool $value value set, false for not set
|
||||
* @param bool $set_only flag to return all (default), or set only
|
||||
* @return array associative array
|
||||
* @return array<mixed> associative array
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::genAssocArray() instead
|
||||
*/
|
||||
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
|
||||
@@ -668,7 +679,7 @@ class Basic
|
||||
/**
|
||||
* [NOTE]: This is an old function and is deprecated
|
||||
* wrapper for join, but checks if input is an array and if not returns null
|
||||
* @param array $array array to convert
|
||||
* @param array<mixed> $array array to convert
|
||||
* @param string $connect_char connection character
|
||||
* @return string joined string
|
||||
* @deprecated use join() instead
|
||||
@@ -685,8 +696,8 @@ class Basic
|
||||
/**
|
||||
* converts multi dimensional array to a flat array
|
||||
* does NOT preserve keys
|
||||
* @param array $array ulti dimensionial array
|
||||
* @return array flattened array
|
||||
* @param array<mixed> $array ulti dimensionial array
|
||||
* @return array<mixed> flattened array
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::flattenArray() instead
|
||||
*/
|
||||
public static function flattenArray(array $array): array
|
||||
@@ -697,8 +708,8 @@ class Basic
|
||||
|
||||
/**
|
||||
* will loop through an array recursivly and write the array keys back
|
||||
* @param array $array multidemnsional array to flatten
|
||||
* @return array flattened keys array
|
||||
* @param array<mixed> $array multidemnsional array to flatten
|
||||
* @return array<mixed> flattened keys array
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::flattenArrayKey() instead
|
||||
*/
|
||||
public static function flattenArrayKey(array $array/*, array $return = []*/): array
|
||||
@@ -710,9 +721,9 @@ class Basic
|
||||
/**
|
||||
* searches for key -> value in an array tree and writes the value one level up
|
||||
* this will remove this leaf will all other values
|
||||
* @param array $array array (nested)
|
||||
* @param array<mixed> $array array (nested)
|
||||
* @param string|int $search key to find that has no sub leaf and will be pushed up
|
||||
* @return array modified, flattened array
|
||||
* @return array<mixed> modified, flattened array
|
||||
* @deprecated Use \CoreLibs\Combined\ArrayHandler::arrayFlatForKey() instead
|
||||
*/
|
||||
public static function arrayFlatForKey(array $array, $search): array
|
||||
@@ -923,7 +934,7 @@ class Basic
|
||||
* @param string $start_date valid start date (y/m/d)
|
||||
* @param string $end_date valid end date (y/m/d)
|
||||
* @param bool $return_named return array type, false (default), true for named
|
||||
* @return array 0/overall, 1/weekday, 2/weekend
|
||||
* @return array<mixed> 0/overall, 1/weekday, 2/weekend
|
||||
* @deprecated Use \CoreLibs\Combined\DateTime::calcDaysInterval() instead
|
||||
*/
|
||||
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
|
||||
@@ -1033,7 +1044,7 @@ class Basic
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array false if no error or array with failed characters
|
||||
* @return bool|array<mixed> false if no error or array with failed characters
|
||||
* @deprecated use \CoreLibs\Language\Encoding::checkConvertEncoding() instead
|
||||
*/
|
||||
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
|
||||
@@ -1162,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
|
||||
@@ -1228,7 +1221,8 @@ class Basic
|
||||
* @param string $hexStr RGB hexstring
|
||||
* @param bool $returnAsString flag to return as string
|
||||
* @param string $seperator string seperator: default: ","
|
||||
* @return string|array|bool false on error or array with RGB or a string with the seperator
|
||||
* @return string|array<mixed>|bool false on error or array with RGB or
|
||||
* a string with the seperator
|
||||
* @deprecated use \CoreLibs\Convert\Colors::hex2rgb() instead
|
||||
*/
|
||||
public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
|
||||
@@ -1275,7 +1269,7 @@ class Basic
|
||||
* @param int $red red 0-255
|
||||
* @param int $green green 0-255
|
||||
* @param int $blue blue 0-255
|
||||
* @return array Hue, Sat, Brightness/Value
|
||||
* @return array<mixed> Hue, Sat, Brightness/Value
|
||||
* @deprecated use \CoreLibs\Convert\Colors::rgb2hsb() instead
|
||||
*/
|
||||
public static function rgb2hsb(int $red, int $green, int $blue): array
|
||||
@@ -1289,7 +1283,7 @@ class Basic
|
||||
* @param int $H hue 0-360
|
||||
* @param float $S saturation 0-1 (float)
|
||||
* @param float $V brightness/value 0-1 (float)
|
||||
* @return array 0 red/1 green/2 blue array
|
||||
* @return array<mixed> 0 red/1 green/2 blue array
|
||||
* @deprecated use \CoreLibs\Convert\Colors::hsb2rgb() instead
|
||||
*/
|
||||
public static function hsb2rgb(int $H, float $S, float $V): array
|
||||
@@ -1305,7 +1299,7 @@ class Basic
|
||||
* @param int $r red 0-255
|
||||
* @param int $g green 0-255
|
||||
* @param int $b blue 0-255
|
||||
* @return array hue/sat/luminance
|
||||
* @return array<mixed> hue/sat/luminance
|
||||
* @deprecated use \CoreLibs\Convert\Colors::rgb2hsl() instead
|
||||
*/
|
||||
public static function rgb2hsl(int $r, int $g, int $b): array
|
||||
@@ -1319,7 +1313,7 @@ class Basic
|
||||
* @param int $h hue: 0-360 (degrees)
|
||||
* @param float $s saturation: 0-1
|
||||
* @param float $l luminance: 0-1
|
||||
* @return array red/blue/green 0-255 each
|
||||
* @return array<mixed> red/blue/green 0-255 each
|
||||
* @deprecated use \CoreLibs\Convert\Colors::hsl2rgb() instead
|
||||
*/
|
||||
public static function hsl2rgb(int $h, float $s, float $l): array
|
||||
@@ -1538,7 +1532,7 @@ class Basic
|
||||
* @param string|null $json a json string, or null data
|
||||
* @param bool $override if set to true, then on json error
|
||||
* set original value as array
|
||||
* @return array returns an array from the json values
|
||||
* @return array<mixed> returns an array from the json values
|
||||
* @deprecated use \CoreLibs\Check\Jason::jsonConvertToArray() instead
|
||||
*/
|
||||
public function jsonConvertToArray(?string $json, bool $override = false): array
|
||||
|
||||
@@ -7,18 +7,32 @@ namespace CoreLibs\Check;
|
||||
class Email
|
||||
{
|
||||
// this is for error check parts in where the email regex failed
|
||||
/** @var array<int,string> */
|
||||
private static $email_regex_check = [
|
||||
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 = [
|
||||
'.*@docomo\.ne\.jp$' => 'keitai_docomo',
|
||||
// correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
|
||||
@@ -57,6 +71,7 @@ class Email
|
||||
'.*@emobile-s\.ne\.jp$' => 'keitai_willcom_emnet' # e-mobile, group will willcom
|
||||
];
|
||||
// short list for mobile email types
|
||||
/** @var array<string,string> */
|
||||
private static $mobile_email_type_short = [
|
||||
'keitai_docomo' => 'docomo',
|
||||
'keitai_kddi_ezweb' => 'kddi',
|
||||
@@ -97,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
|
||||
@@ -113,10 +128,12 @@ 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
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public static function getEmailRegexCheck(): array
|
||||
{
|
||||
@@ -129,12 +146,30 @@ 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)
|
||||
* @param string $email email string
|
||||
* @param bool $short default false, if true, returns only short type (pc instead of pc_html)
|
||||
* @return string|bool email type, eg "pc", "docomo", etc, false for invalid short type
|
||||
* @param string $email email string
|
||||
* @param bool $short default false, if true,
|
||||
* returns only short type (pc instead of pc_html)
|
||||
* @return string|bool email type, eg "pc", "docomo", etc,
|
||||
* false for invalid short type
|
||||
*/
|
||||
public static function getEmailType(string $email, bool $short = false)
|
||||
{
|
||||
@@ -175,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__
|
||||
|
||||
@@ -34,9 +34,12 @@ class File
|
||||
is_readable($file)
|
||||
) {
|
||||
$f = fopen($file, 'rb');
|
||||
if (!is_resource($f)) {
|
||||
return 0;
|
||||
}
|
||||
$lines = 0;
|
||||
while (!feof($f)) {
|
||||
$lines += substr_count(fread($f, 8192), "\n");
|
||||
$lines += substr_count(fread($f, 8192) ?: '', "\n");
|
||||
}
|
||||
fclose($f);
|
||||
} else {
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace CoreLibs\Check;
|
||||
|
||||
class Jason
|
||||
{
|
||||
/** @var int */
|
||||
private static $json_last_error;
|
||||
|
||||
/**
|
||||
@@ -23,7 +24,7 @@ class Jason
|
||||
* @param string|null $json a json string, or null data
|
||||
* @param bool $override if set to true, then on json error
|
||||
* set original value as array
|
||||
* @return array returns an array from the json values
|
||||
* @return array<mixed> returns an array from the json values
|
||||
*/
|
||||
public static function jsonConvertToArray(?string $json, bool $override = false): array
|
||||
{
|
||||
|
||||
@@ -35,8 +35,6 @@ class Password
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// in case something strange, return false on default
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,8 +49,6 @@ class Password
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// in case of strange, force re-hash
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,19 +35,15 @@ class PhpVersion
|
||||
}
|
||||
// set the php version id
|
||||
if (!defined('PHP_VERSION_ID')) {
|
||||
$version = explode('.', phpversion());
|
||||
$version = explode('.', phpversion() ?: '');
|
||||
// creates something like 50107
|
||||
define('PHP_VERSION_ID', (int)$version[0] * 10000 + (int)$version[1] * 100 + (int)$version[2]);
|
||||
}
|
||||
// check if matching for version
|
||||
if ($min_version && !$max_version) {
|
||||
if (PHP_VERSION_ID >= $min_version) {
|
||||
return true;
|
||||
}
|
||||
} elseif ($min_version && $max_version) {
|
||||
if (PHP_VERSION_ID >= $min_version && PHP_VERSION_ID <= $max_version) {
|
||||
return true;
|
||||
}
|
||||
if (!$max_version && PHP_VERSION_ID >= $min_version) {
|
||||
return true;
|
||||
} elseif (PHP_VERSION_ID >= $min_version && PHP_VERSION_ID <= $max_version) {
|
||||
return true;
|
||||
}
|
||||
// if no previous return, fail
|
||||
return false;
|
||||
|
||||
@@ -13,11 +13,11 @@ class ArrayHandler
|
||||
/**
|
||||
* searches key = value in an array / array
|
||||
* only returns the first one found
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array $haystack haystack (search in)
|
||||
* @param string|null $key_lookin the key to look out for, default empty
|
||||
* @return array array with the elements where the needle can be
|
||||
* found in the haystack array
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array<mixed> $haystack haystack (search in)
|
||||
* @param string|null $key_lookin the key to look out for, default empty
|
||||
* @return array<mixed> array with the elements where the needle can be
|
||||
* found in the haystack array
|
||||
*/
|
||||
public static function arraySearchRecursive($needle, array $haystack, ?string $key_lookin = null): array
|
||||
{
|
||||
@@ -27,7 +27,6 @@ class ArrayHandler
|
||||
}
|
||||
if (
|
||||
$key_lookin != null &&
|
||||
!empty($key_lookin) &&
|
||||
array_key_exists($key_lookin, $haystack) &&
|
||||
$needle === $haystack[$key_lookin]
|
||||
) {
|
||||
@@ -68,11 +67,11 @@ class ArrayHandler
|
||||
|
||||
/**
|
||||
* recursive array search function, which returns all found not only the first one
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array $haystack haystack (search in)
|
||||
* @param string|int $key the key to look for in
|
||||
* @param array|null $path recursive call for previous path
|
||||
* @return ?array all array elements paths where the element was found
|
||||
* @param string|int $needle needle (search for)
|
||||
* @param array<mixed> $haystack haystack (search in)
|
||||
* @param string|int $key the key to look for in
|
||||
* @param array<mixed>|null $path recursive call for previous path
|
||||
* @return array<mixed>|null all array elements paths where the element was found
|
||||
*/
|
||||
public static function arraySearchRecursiveAll($needle, array $haystack, $key, ?array $path = null): ?array
|
||||
{
|
||||
@@ -82,41 +81,40 @@ class ArrayHandler
|
||||
'level' => 0,
|
||||
'work' => []
|
||||
];
|
||||
}
|
||||
// init sub sets if not set
|
||||
if (!isset($path['level'])) {
|
||||
$path['level'] = 0;
|
||||
}
|
||||
if (!isset($path['work'])) {
|
||||
$path['work'] = [];
|
||||
} else {
|
||||
// init sub sets if not set
|
||||
if (!isset($path['level'])) {
|
||||
$path['level'] = 0;
|
||||
}
|
||||
if (!isset($path['work'])) {
|
||||
$path['work'] = [];
|
||||
}
|
||||
}
|
||||
// should not be needed because it would trigger a php mehtod error
|
||||
if (!is_array($haystack)) {
|
||||
$haystack = [];
|
||||
}
|
||||
|
||||
// @phan HACK
|
||||
$path['level'] = $path['level'] ?? 0;
|
||||
// go through the array,
|
||||
foreach ($haystack as $_key => $_value) {
|
||||
if (is_scalar($_value) && $_value == $needle && !$key) {
|
||||
// only value matches
|
||||
$path['work'][$path['level']] = $_key;
|
||||
$path['work'][$path['level'] ?? 0] = $_key;
|
||||
$path['found'][] = $path['work'];
|
||||
} elseif (is_scalar($_value) && $_value == $needle && $_key == $key) {
|
||||
// key and value matches
|
||||
$path['work'][$path['level']] = $_key;
|
||||
$path['work'][$path['level'] ?? 0] = $_key;
|
||||
$path['found'][] = $path['work'];
|
||||
} elseif (is_array($_value)) {
|
||||
// add position to working
|
||||
$path['work'][$path['level']] = $_key;
|
||||
$path['work'][$path['level'] ?? 0] = $_key;
|
||||
// we will up a level
|
||||
$path['level'] += 1;
|
||||
// call recursive
|
||||
$path = self::arraySearchRecursiveAll($needle, $_value, $key, $path);
|
||||
}
|
||||
}
|
||||
// @phan HACK
|
||||
// be 100% sure the array elements are set
|
||||
$path['level'] = $path['level'] ?? 0;
|
||||
$path['work'] = $path['work'] ?? [];
|
||||
// cut all that is >= level
|
||||
@@ -128,10 +126,10 @@ class ArrayHandler
|
||||
|
||||
/**
|
||||
* array search simple. looks for key, value combination, if found, returns true
|
||||
* @param array $array search in as array
|
||||
* @param string|int $key key (key to search in)
|
||||
* @param string|int $value value (what to find)
|
||||
* @return bool true on found, false on not found
|
||||
* @param array<mixed> $array search in as array
|
||||
* @param string|int $key key (key to search in)
|
||||
* @param string|int $value value (what to find)
|
||||
* @return bool true on found, false on not found
|
||||
*/
|
||||
public static function arraySearchSimple(array $array, $key, $value): bool
|
||||
{
|
||||
@@ -160,7 +158,7 @@ class ArrayHandler
|
||||
* ... etc
|
||||
* bool key flag: true: handle keys as string or int
|
||||
* default false: all keys are string
|
||||
* @return array|bool merged array
|
||||
* @return array<mixed>|bool merged array
|
||||
*/
|
||||
public static function arrayMergeRecursive()
|
||||
{
|
||||
@@ -215,9 +213,9 @@ class ArrayHandler
|
||||
* array_diff only checks elements from A that are not in B, but not the
|
||||
* other way around.
|
||||
* Note that like array_diff this only checks first level values not keys
|
||||
* @param array $a array to compare a
|
||||
* @param array $b array to compare b
|
||||
* @return array array with missing elements from a & b
|
||||
* @param array<mixed> $a array to compare a
|
||||
* @param array<mixed> $b array to compare b
|
||||
* @return array<mixed> array with missing elements from a & b
|
||||
*/
|
||||
public static function arrayDiff(array $a, array $b): array
|
||||
{
|
||||
@@ -228,9 +226,9 @@ class ArrayHandler
|
||||
/**
|
||||
* search for the needle array elements in haystack and return the ones found as an array,
|
||||
* is there nothing found, it returns FALSE (boolean)
|
||||
* @param array $needle elements to search for
|
||||
* @param array $haystack array where the $needle elements should be searched int
|
||||
* @return array|bool either the found elements or false for nothing found or error
|
||||
* @param array<mixed> $needle elements to search for
|
||||
* @param array<mixed> $haystack array where the $needle elements should be searched int
|
||||
* @return array<mixed>|bool either the found elements or false for nothing found or error
|
||||
*/
|
||||
public static function inArrayAny(array $needle, array $haystack)
|
||||
{
|
||||
@@ -255,11 +253,11 @@ class ArrayHandler
|
||||
|
||||
/**
|
||||
* creates out of a normal db_return array an assoc array
|
||||
* @param array $db_array return array from the database
|
||||
* @param array<mixed> $db_array return array from the database
|
||||
* @param string|int|bool $key key set, false for not set
|
||||
* @param string|int|bool $value value set, false for not set
|
||||
* @param bool $set_only flag to return all (default), or set only
|
||||
* @return array associative array
|
||||
* @return array<mixed> associative array
|
||||
*/
|
||||
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
|
||||
{
|
||||
@@ -285,8 +283,8 @@ class ArrayHandler
|
||||
/**
|
||||
* converts multi dimensional array to a flat array
|
||||
* does NOT preserve keys
|
||||
* @param array $array ulti dimensionial array
|
||||
* @return array flattened array
|
||||
* @param array<mixed> $array ulti dimensionial array
|
||||
* @return array<mixed> flattened array
|
||||
*/
|
||||
public static function flattenArray(array $array): array
|
||||
{
|
||||
@@ -302,8 +300,8 @@ class ArrayHandler
|
||||
|
||||
/**
|
||||
* will loop through an array recursivly and write the array keys back
|
||||
* @param array $array multidemnsional array to flatten
|
||||
* @return array flattened keys array
|
||||
* @param array<mixed> $array multidemnsional array to flatten
|
||||
* @return array<mixed> flattened keys array
|
||||
*/
|
||||
public static function flattenArrayKey(array $array): array
|
||||
{
|
||||
@@ -320,9 +318,9 @@ class ArrayHandler
|
||||
/**
|
||||
* searches for key -> value in an array tree and writes the value one level up
|
||||
* this will remove this leaf will all other values
|
||||
* @param array $array nested array
|
||||
* @param string|int $search key to find that has no sub leaf and will be pushed up
|
||||
* @return array modified, flattened array
|
||||
* @param array<mixed> $array nested array
|
||||
* @param string|int $search key to find that has no sub leaf and will be pushed up
|
||||
* @return array<mixed> modified, flattened array
|
||||
*/
|
||||
public static function arrayFlatForKey(array $array, $search): array
|
||||
{
|
||||
|
||||
@@ -38,7 +38,7 @@ class DateTime
|
||||
{
|
||||
// check if the timestamp has any h/m/s/ms inside, if yes skip
|
||||
if (!preg_match("/(h|m|s|ms)/", (string)$timestamp)) {
|
||||
list($timestamp, $ms) = array_pad(explode('.', (string)round($timestamp, 4)), 2, null);
|
||||
list($timestamp, $ms) = array_pad(explode('.', (string)round((float)$timestamp, 4)), 2, null);
|
||||
// if negative remember
|
||||
$negative = false;
|
||||
if ((int)$timestamp < 0) {
|
||||
@@ -65,11 +65,14 @@ class DateTime
|
||||
if ($ms !== null) {
|
||||
// if we have ms and it has leading zeros, remove them, but only if it is nut just 0
|
||||
$ms = preg_replace("/^0+(\d+)$/", '${1}', $ms);
|
||||
if (!is_string($ms) || empty($ms)) {
|
||||
$ms = '0';
|
||||
}
|
||||
// add ms if there
|
||||
if ($show_micro) {
|
||||
$time_string .= ' ' . (!$ms ? 0 : $ms) . 'ms';
|
||||
$time_string .= ' ' . $ms . 'ms';
|
||||
} elseif (!$time_string) {
|
||||
$time_string .= (!$ms ? 0 : $ms) . 'ms';
|
||||
$time_string .= $ms . 'ms';
|
||||
}
|
||||
}
|
||||
if ($negative) {
|
||||
@@ -78,7 +81,7 @@ class DateTime
|
||||
} else {
|
||||
$time_string = $timestamp;
|
||||
}
|
||||
return $time_string;
|
||||
return (string)$time_string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +93,8 @@ class DateTime
|
||||
public static function stringToTime($timestring)
|
||||
{
|
||||
$timestamp = 0;
|
||||
if (preg_match("/(d|h|m|s|ms)/", $timestring)) {
|
||||
if (preg_match("/(d|h|m|s|ms)/", (string)$timestring)) {
|
||||
$timestring = (string)$timestring;
|
||||
// pos for preg match read + multiply factor
|
||||
$timegroups = [2 => 86400, 4 => 3600, 6 => 60, 8 => 1];
|
||||
$matches = [];
|
||||
@@ -131,7 +135,11 @@ class DateTime
|
||||
if (!$date) {
|
||||
return false;
|
||||
}
|
||||
list ($year, $month, $day) = array_pad(preg_split("/[\/-]/", $date), 3, null);
|
||||
list ($year, $month, $day) = array_pad(
|
||||
preg_split("/[\/-]/", $date) ?: [],
|
||||
3,
|
||||
null
|
||||
);
|
||||
if (!$year || !$month || !$day) {
|
||||
return false;
|
||||
}
|
||||
@@ -146,12 +154,16 @@ class DateTime
|
||||
* @param string $datetime date (YYYY-MM-DD) + time (HH:MM:SS), SS can be dropped
|
||||
* @return bool true if valid date, false if date not valid
|
||||
*/
|
||||
public static function checkDateTime($datetime): bool
|
||||
public static function checkDateTime(string $datetime): bool
|
||||
{
|
||||
if (!$datetime) {
|
||||
return false;
|
||||
}
|
||||
list ($year, $month, $day, $hour, $min, $sec) = array_pad(preg_split("/[\/\- :]/", $datetime), 6, null);
|
||||
list ($year, $month, $day, $hour, $min, $sec) = array_pad(
|
||||
preg_split("/[\/\- :]/", $datetime) ?: [],
|
||||
6,
|
||||
null
|
||||
);
|
||||
if (!$year || !$month || !$day) {
|
||||
return false;
|
||||
}
|
||||
@@ -190,8 +202,16 @@ class DateTime
|
||||
}
|
||||
|
||||
// splits the data up with / or -
|
||||
list ($start_year, $start_month, $start_day) = array_pad(preg_split('/[\/-]/', $start_date), 3, null);
|
||||
list ($end_year, $end_month, $end_day) = array_pad(preg_split('/[\/-]/', $end_date), 3, null);
|
||||
list ($start_year, $start_month, $start_day) = array_pad(
|
||||
preg_split('/[\/-]/', $start_date) ?: [],
|
||||
3,
|
||||
null
|
||||
);
|
||||
list ($end_year, $end_month, $end_day) = array_pad(
|
||||
preg_split('/[\/-]/', $end_date) ?: [],
|
||||
3,
|
||||
null
|
||||
);
|
||||
// check that month & day are two digits and then combine
|
||||
foreach (['start', 'end'] as $prefix) {
|
||||
foreach (['month', 'day'] as $date_part) {
|
||||
@@ -214,6 +234,8 @@ class DateTime
|
||||
return 0;
|
||||
} elseif ($start_date > $end_date) {
|
||||
return 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +264,8 @@ class DateTime
|
||||
return 0;
|
||||
} elseif ($start_timestamp > $end_timestamp) {
|
||||
return 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +276,7 @@ class DateTime
|
||||
* @param string $start_date valid start date (y/m/d)
|
||||
* @param string $end_date valid end date (y/m/d)
|
||||
* @param bool $return_named return array type, false (default), true for named
|
||||
* @return array 0/overall, 1/weekday, 2/weekend
|
||||
* @return array<mixed> 0/overall, 1/weekday, 2/weekend
|
||||
*/
|
||||
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
|
||||
{
|
||||
|
||||
@@ -125,7 +125,7 @@ class Byte
|
||||
// detects up to exo bytes
|
||||
preg_match(
|
||||
"/([\d.,]*)\s?(eib|pib|tib|gib|mib|kib|eb|pb|tb|gb|mb|kb|e|p|t|g|m|k|b)$/i",
|
||||
strtolower($number),
|
||||
strtolower((string)$number),
|
||||
$matches
|
||||
);
|
||||
if (isset($matches[1]) && isset($matches[2])) {
|
||||
@@ -136,7 +136,7 @@ class Byte
|
||||
// convert any mb/gb/etc to single m/b
|
||||
$unit = preg_replace('/[^bkmgtpezy]/i', '', $matches[2]);
|
||||
if ($unit) {
|
||||
$number = $number * pow($si ? 1000 : 1024, stripos($valid_units_, $unit[0]));
|
||||
$number = $number * pow($si ? 1000 : 1024, stripos($valid_units_, $unit[0]) ?: 0);
|
||||
}
|
||||
// convert to INT to avoid +E output
|
||||
$number = (int)round($number);
|
||||
|
||||
@@ -18,14 +18,18 @@ class Colors
|
||||
{
|
||||
/**
|
||||
* converts a hex RGB color to the int numbers
|
||||
* @param string $hexStr RGB hexstring
|
||||
* @param bool $returnAsString flag to return as string
|
||||
* @param string $seperator string seperator: default: ","
|
||||
* @return string|array|bool false on error or array with RGB or a string with the seperator
|
||||
* @param string $hexStr RGB hexstring
|
||||
* @param bool $returnAsString flag to return as string
|
||||
* @param string $seperator string seperator: default: ","
|
||||
* @return string|array<string,float|int>|bool false on error or array with RGB
|
||||
* or a string with the seperator
|
||||
*/
|
||||
public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
|
||||
{
|
||||
$hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // Gets a proper hex string
|
||||
if (!is_string($hexStr)) {
|
||||
return false;
|
||||
}
|
||||
$rgbArray = [];
|
||||
if (strlen($hexStr) == 6) {
|
||||
// If a proper hex code, convert using bitwise operation. No overhead... faster
|
||||
@@ -76,10 +80,10 @@ class Colors
|
||||
* converts RGB to HSB/V values
|
||||
* returns:
|
||||
* array with hue (0-360), sat (0-100%), brightness/value (0-100%)
|
||||
* @param int $red red 0-255
|
||||
* @param int $green green 0-255
|
||||
* @param int $blue blue 0-255
|
||||
* @return array Hue, Sat, Brightness/Value
|
||||
* @param int $red red 0-255
|
||||
* @param int $green green 0-255
|
||||
* @param int $blue blue 0-255
|
||||
* @return array<int|float> Hue, Sat, Brightness/Value
|
||||
*/
|
||||
public static function rgb2hsb(int $red, int $green, int $blue): array
|
||||
{
|
||||
@@ -119,10 +123,10 @@ class Colors
|
||||
|
||||
/**
|
||||
* converts HSB/V to RGB values RGB is full INT
|
||||
* @param int $H hue 0-360
|
||||
* @param int $S saturation 0-100 (int)
|
||||
* @param int $V brightness/value 0-100 (int)
|
||||
* @return array 0 red/1 green/2 blue array as 0-255
|
||||
* @param int $H hue 0-360
|
||||
* @param int $S saturation 0-100 (int)
|
||||
* @param int $V brightness/value 0-100 (int)
|
||||
* @return array<int> 0 red/1 green/2 blue array as 0-255
|
||||
*/
|
||||
public static function hsb2rgb(int $H, int $S, int $V): array
|
||||
{
|
||||
@@ -199,10 +203,10 @@ class Colors
|
||||
* converts a RGB (0-255) to HSL
|
||||
* return:
|
||||
* array with hue (0-360), saturation (0-100%) and luminance (0-100%)
|
||||
* @param int $red red 0-255
|
||||
* @param int $green green 0-255
|
||||
* @param int $blue blue 0-255
|
||||
* @return array hue/sat/luminance
|
||||
* @param int $red red 0-255
|
||||
* @param int $green green 0-255
|
||||
* @param int $blue blue 0-255
|
||||
* @return array<float> hue/sat/luminance
|
||||
*/
|
||||
public static function rgb2hsl(int $red, int $green, int $blue): array
|
||||
{
|
||||
@@ -253,7 +257,7 @@ class Colors
|
||||
* @param int $hue hue: 0-360 (degrees)
|
||||
* @param float $sat saturation: 0-100
|
||||
* @param float $lum luminance: 0-100
|
||||
* @return array red/blue/green 0-255 each
|
||||
* @return array<int,float|int> red/blue/green 0-255 each
|
||||
*/
|
||||
public static function hsl2rgb(int $hue, float $sat, float $lum): array
|
||||
{
|
||||
|
||||
@@ -39,10 +39,10 @@ class Html
|
||||
* returns 'checked' or 'selected' if okay
|
||||
* $needle is a var, $haystack an array or a string
|
||||
* **** THE RETURN: VALUE WILL CHANGE TO A DEFAULT NULL IF NOT FOUND ****
|
||||
* @param array|string $haystack (search in) haystack can be an array or a string
|
||||
* @param string $needle needle (search for)
|
||||
* @param int $type type: 0: returns selected, 1, returns checked
|
||||
* @return ?string returns checked or selected, else returns null
|
||||
* @param array<mixed>|string $haystack (search in) haystack can be an array or a string
|
||||
* @param string $needle needle (search for)
|
||||
* @param int $type type: 0: returns selected, 1, returns checked
|
||||
* @return ?string returns checked or selected, else returns null
|
||||
*/
|
||||
public static function checked($haystack, $needle, int $type = 0): ?string
|
||||
{
|
||||
|
||||
@@ -31,6 +31,11 @@ class Math
|
||||
*/
|
||||
public static function floorp(float $number, int $precision = -2): float
|
||||
{
|
||||
// if precision is requal or larger than the number length,
|
||||
// set precision to length -1
|
||||
if (abs($precision) >= strlen((string)$number)) {
|
||||
$precision = (strlen((string)$number) - 1) * -1;
|
||||
}
|
||||
$mult = pow(10, $precision); // Can be cached in lookup table
|
||||
return floor($number * $mult) / $mult;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace CoreLibs\Convert;
|
||||
|
||||
class MimeAppName
|
||||
{
|
||||
/** @var array<string,string> */
|
||||
private static $mime_apps = [];
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,9 @@ class Hash
|
||||
{
|
||||
/**
|
||||
* checks php version and if >=5.2.7 it will flip the string
|
||||
* can return empty string if none of string sets work
|
||||
* hash returns false
|
||||
* preg_replace fails for older php version
|
||||
* @param string $string string to crc
|
||||
* @return string crc32b hash (old type)
|
||||
*/
|
||||
@@ -24,6 +27,9 @@ class Hash
|
||||
// flip it back to old (two char groups)
|
||||
$string = preg_replace("/^([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})$/", "$4$3$2$1", $string);
|
||||
}
|
||||
if (!is_string($string)) {
|
||||
$string = '';
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,13 @@ namespace CoreLibs\Create;
|
||||
class RandomKey
|
||||
{
|
||||
// key generation
|
||||
/** @var array<mixed> */
|
||||
private static $key_range = [];
|
||||
/** @var int */
|
||||
private static $one_key_length;
|
||||
/** @var int */
|
||||
private static $key_length = 4; // default key length
|
||||
/** @var int */
|
||||
private static $max_key_length = 256; // max allowed length
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,17 +38,21 @@ namespace CoreLibs\DB\Extended;
|
||||
class ArrayIO extends \CoreLibs\DB\IO
|
||||
{
|
||||
// main calss variables
|
||||
/** @var array<mixed> */
|
||||
public $table_array; // the array from the table to work on
|
||||
/** @var string */
|
||||
public $table_name; // the table_name
|
||||
/** @var string */
|
||||
public $pk_name; // the primary key from this table
|
||||
/** @var int|string|null */
|
||||
public $pk_id; // the PK id
|
||||
|
||||
/**
|
||||
* constructor for the array io class, set the
|
||||
* primary key name automatically (from array)
|
||||
* @param array $db_config db connection config
|
||||
* @param array $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
* @param array<mixed> $db_config db connection config
|
||||
* @param array<mixed> $table_array table array config
|
||||
* @param string $table_name table name string
|
||||
*/
|
||||
public function __construct(array $db_config, array $table_array, string $table_name)
|
||||
{
|
||||
@@ -174,9 +178,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* deletes one dataset
|
||||
* @param array $table_array optional override for table array set
|
||||
* set this as new table array too
|
||||
* @return array returns the table array that was deleted
|
||||
* @param array<mixed> $table_array optional override for table array set
|
||||
* set this as new table array too
|
||||
* @return array<mixed> returns the table array that was deleted
|
||||
*/
|
||||
public function dbDelete($table_array = [])
|
||||
{
|
||||
@@ -234,9 +238,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* reads one row into the array
|
||||
* @param boolean $edit on true convert data, else as is
|
||||
* @param array $table_array optional table array, overwrites internal set array
|
||||
* @return array set table array with values
|
||||
* @param boolean $edit on true convert data, else as is
|
||||
* @param array<mixed> $table_array optional table array, overwrites internal set array
|
||||
* @return array<mixed> set table array with values
|
||||
*/
|
||||
public function dbRead($edit = false, $table_array = [])
|
||||
{
|
||||
@@ -276,7 +280,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
|
||||
// if query was executed okay, else set error
|
||||
if ($this->dbExec($q)) {
|
||||
if ($res = $this->dbFetchArray()) {
|
||||
if (is_array($res = $this->dbFetchArray())) {
|
||||
reset($this->table_array);
|
||||
foreach ($this->table_array as $column => $data_array) {
|
||||
// wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten fr ausgabe
|
||||
@@ -309,9 +313,9 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
|
||||
/**
|
||||
* writes one set into DB or updates one set (if PK exists)
|
||||
* @param boolean $addslashes old convert entities and set set escape
|
||||
* @param array $table_array optional table array, overwrites internal one
|
||||
* @return array table array or null
|
||||
* @param boolean $addslashes old convert entities and set set escape
|
||||
* @param array<mixed> $table_array optional table array, overwrites internal one
|
||||
* @return array<mixed> table array or null
|
||||
*/
|
||||
public function dbWrite($addslashes = false, $table_array = [])
|
||||
{
|
||||
@@ -499,11 +503,12 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
if (!$this->table_array[$this->pk_name]['value']) {
|
||||
// max id, falls INSERT
|
||||
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
|
||||
$res = $this->dbReturnRow($q);
|
||||
if (!isset($res['pk_id'])) {
|
||||
$res['pk_id'] = 1;
|
||||
if (is_array($res = $this->dbReturnRow($q))) {
|
||||
$pk_id = $res['pkd_id'];
|
||||
} else {
|
||||
$pk_id = 1;
|
||||
}
|
||||
$this->table_array[$this->pk_name]['value'] = $res['pk_id'];
|
||||
$this->table_array[$this->pk_name]['value'] = $pk_id;
|
||||
}
|
||||
|
||||
if (!$insert) {
|
||||
@@ -533,8 +538,13 @@ class ArrayIO extends \CoreLibs\DB\IO
|
||||
}
|
||||
// set primary key
|
||||
if ($insert) {
|
||||
$this->table_array[$this->pk_name]['value'] = $this->insert_id;
|
||||
$this->pk_id = $this->insert_id;
|
||||
// FIXME: this has to be fixes by fixing DB::IO clas
|
||||
$insert_id = $this->dbGetInsertPK();
|
||||
if (is_array($insert_id)) {
|
||||
$insert_id = 0;
|
||||
}
|
||||
$this->table_array[$this->pk_name]['value'] = $insert_id;
|
||||
$this->pk_id = $insert_id;
|
||||
}
|
||||
// return the table if needed
|
||||
return $this->table_array;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -50,7 +50,9 @@ namespace CoreLibs\DB\SQL;
|
||||
|
||||
class PgSQL
|
||||
{
|
||||
/** @var string */
|
||||
private $last_error_query;
|
||||
/** @var resource|bool */
|
||||
private $dbh;
|
||||
|
||||
/**
|
||||
@@ -81,6 +83,9 @@ class PgSQL
|
||||
public function __dbQuery(string $query)
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
// read out the query status and save the query if needed
|
||||
$result = pg_query($this->dbh, $query);
|
||||
if (!$result) {
|
||||
@@ -96,7 +101,11 @@ class PgSQL
|
||||
*/
|
||||
public function __dbSendQuery(string $query): bool
|
||||
{
|
||||
return pg_send_query($this->dbh, $query);
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_send_query($this->dbh, $query);
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,7 +115,13 @@ class PgSQL
|
||||
public function __dbGetResult()
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_get_result($this->dbh);
|
||||
if (!is_resource($result)) {
|
||||
return false;
|
||||
}
|
||||
if ($error = pg_result_error($result)) {
|
||||
$this->last_error_query = $error;
|
||||
}
|
||||
@@ -119,10 +134,11 @@ class PgSQL
|
||||
*/
|
||||
public function __dbClose(): void
|
||||
{
|
||||
if (is_resource($this->dbh)) {
|
||||
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
|
||||
pg_close($this->dbh);
|
||||
}
|
||||
if (!is_resource($this->dbh)) {
|
||||
return;
|
||||
}
|
||||
if (pg_connection_status($this->dbh) === PGSQL_CONNECTION_OK) {
|
||||
pg_close($this->dbh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +150,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbPrepare(string $name, string $query)
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_prepare($this->dbh, $name, $query);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
@@ -144,11 +163,14 @@ class PgSQL
|
||||
/**
|
||||
* wrapper for pg_execute for running a prepared statement
|
||||
* @param string $name statement name
|
||||
* @param array $data data array
|
||||
* @param array<mixed> $data data array
|
||||
* @return resource|bool returns status or false for error
|
||||
*/
|
||||
public function __dbExecute(string $name, array $data)
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
$result = pg_execute($this->dbh, $name, $data);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $name;
|
||||
@@ -192,7 +214,7 @@ class PgSQL
|
||||
* if through/true false, use __dbResultType(true)
|
||||
* @param resource $cursor cursor resource
|
||||
* @param int $result_type result type as int number
|
||||
* @return array|bool array result data or false on end/error
|
||||
* @return array<mixed>|bool array result data or false on end/error
|
||||
*/
|
||||
public function __dbFetchArray($cursor, int $result_type = PGSQL_BOTH)
|
||||
{
|
||||
@@ -217,7 +239,7 @@ class PgSQL
|
||||
/**
|
||||
* wrapper for pg_fetch_all
|
||||
* @param resource $cursor cursor resource
|
||||
* @return array|bool data array or false for end/error
|
||||
* @return array<mixed>|bool data array or false for end/error
|
||||
*/
|
||||
public function __dbFetchAll($cursor)
|
||||
{
|
||||
@@ -239,11 +261,11 @@ class PgSQL
|
||||
* if there is no pk_name tries to auto built it from the table name
|
||||
* this only works if db schema is after "no plural names. and pk name is table name + _id
|
||||
* detects schema prefix in table name
|
||||
* @param string $query query string
|
||||
* @param string $pk_name primary key name, if '' then auto detect
|
||||
* @return string|int primary key value
|
||||
* @param string $query query string
|
||||
* @param string|null $pk_name primary key name, if '' then auto detect
|
||||
* @return string|int|false primary key value
|
||||
*/
|
||||
public function __dbInsertId(string $query, string $pk_name)
|
||||
public function __dbInsertId(string $query, ?string $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
@@ -258,7 +280,7 @@ class PgSQL
|
||||
$table = $_table;
|
||||
}
|
||||
// no PK name given at all
|
||||
if (!$pk_name) {
|
||||
if (empty($pk_name)) {
|
||||
// if name is plurar, make it singular
|
||||
// if (preg_match("/.*s$/i", $table))
|
||||
// $table = substr($table, 0, -1);
|
||||
@@ -269,11 +291,22 @@ class PgSQL
|
||||
$q = "SELECT CURRVAL('$seq') AS insert_id";
|
||||
// I have to do manually or I overwrite the original insert internal vars ...
|
||||
if ($q = $this->__dbQuery($q)) {
|
||||
list($id) = $this->__dbFetchArray($q);
|
||||
// abort if this is not an resource
|
||||
if (!is_resource($q)) {
|
||||
return false;
|
||||
}
|
||||
if (is_array($res = $this->__dbFetchArray($q))) {
|
||||
list($id) = $res;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$id = [-1, $q];
|
||||
}
|
||||
return $id;
|
||||
} else {
|
||||
//if not insert, return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +324,14 @@ class PgSQL
|
||||
if ($schema) {
|
||||
$q = "SHOW search_path";
|
||||
$cursor = $this->__dbQuery($q);
|
||||
$search_path = $this->__dbFetchArray($cursor)['search_path'];
|
||||
if (!is_resource($cursor)) {
|
||||
return false;
|
||||
}
|
||||
$__db_fetch_array = $this->__dbFetchArray($cursor);
|
||||
if (!is_array($__db_fetch_array)) {
|
||||
return false;
|
||||
}
|
||||
$search_path = $__db_fetch_array['search_path'] ?? '';
|
||||
if ($search_path != $schema) {
|
||||
$table_prefix = $schema . '.';
|
||||
}
|
||||
@@ -316,8 +356,12 @@ class PgSQL
|
||||
. "pg_attribute.attnum = any(pg_index.indkey) "
|
||||
. "AND indisprimary";
|
||||
$cursor = $this->__dbQuery($q);
|
||||
if ($cursor) {
|
||||
return $this->__dbFetchArray($cursor)['column_name'] ?? false;
|
||||
if (is_resource($cursor)) {
|
||||
$__db_fetch_array = $this->__dbFetchArray($cursor);
|
||||
if (!is_array($__db_fetch_array)) {
|
||||
return false;
|
||||
}
|
||||
return $__db_fetch_array['column_name'] ?? false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -328,13 +372,13 @@ class PgSQL
|
||||
|
||||
/**
|
||||
* wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
* @param string $db_host host name
|
||||
* @param string $db_user user name
|
||||
* @param string $db_pass password
|
||||
* @param string $db_name databse name
|
||||
* @param integer $db_port port (int, 5432 is default)
|
||||
* @param string $db_ssl SSL (allow is default)
|
||||
* @return ?resource db handler resource or null on error
|
||||
* @param string $db_host host name
|
||||
* @param string $db_user user name
|
||||
* @param string $db_pass password
|
||||
* @param string $db_name databse name
|
||||
* @param integer $db_port port (int, 5432 is default)
|
||||
* @param string $db_ssl SSL (allow is default)
|
||||
* @return resource|bool db handler resource or false on error
|
||||
*/
|
||||
public function __dbConnect(
|
||||
string $db_host,
|
||||
@@ -350,11 +394,9 @@ class PgSQL
|
||||
}
|
||||
$this->dbh = pg_connect("host=" . $db_host . " port=" . $db_port . " user="
|
||||
. $db_user . " password=" . $db_pass . " dbname=" . $db_name . " sslmode=" . $db_ssl);
|
||||
if (!$this->dbh) {
|
||||
die("<!-- Can't connect [host=" . $db_host . " port=" . $db_port . " user="
|
||||
. $db_user . " password=XXXX dbname=" . $db_name . " sslmode=" . $db_ssl . "] //-->");
|
||||
return null;
|
||||
}
|
||||
// if (!$this->dbh) {
|
||||
// die("<!-- Can't connect to database //-->");
|
||||
// }
|
||||
return $this->dbh;
|
||||
}
|
||||
|
||||
@@ -366,6 +408,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbPrintError($cursor = null): string
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// run the query again for the error result here
|
||||
if (!$cursor && $this->last_error_query) {
|
||||
pg_send_query($this->dbh, $this->last_error_query);
|
||||
@@ -381,12 +426,15 @@ class PgSQL
|
||||
|
||||
/**
|
||||
* wrapper for pg_meta_data
|
||||
* @param string $table table name
|
||||
* @param bool $extended show extended info (default false)
|
||||
* @return array|bool array data for the table info or false on error
|
||||
* @param string $table table name
|
||||
* @param bool $extended show extended info (default false)
|
||||
* @return array<mixed>|bool array data for the table info or false on error
|
||||
*/
|
||||
public function __dbMetaData(string $table, $extended = false)
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
// needs to prefixed with @ or it throws a warning on not existing table
|
||||
return @pg_meta_data($this->dbh, $table, $extended);
|
||||
}
|
||||
@@ -398,6 +446,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbEscapeString($string): string
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
return pg_escape_string($this->dbh, (string)$string);
|
||||
}
|
||||
|
||||
@@ -410,6 +461,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbEscapeLiteral($string): string
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
return pg_escape_string($this->dbh, (string)$string);
|
||||
}
|
||||
|
||||
@@ -420,6 +474,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbEscapeBytea($bytea): string
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
return pg_escape_bytea($this->dbh, $bytea);
|
||||
}
|
||||
|
||||
@@ -429,6 +486,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbConnectionBusy(): bool
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return false;
|
||||
}
|
||||
return pg_connection_busy($this->dbh);
|
||||
}
|
||||
|
||||
@@ -440,6 +500,9 @@ class PgSQL
|
||||
*/
|
||||
public function __dbVersion(): string
|
||||
{
|
||||
if (!is_resource($this->dbh)) {
|
||||
return '';
|
||||
}
|
||||
// array has client, protocol, server
|
||||
// we just need the server
|
||||
$v = pg_version($this->dbh);
|
||||
@@ -448,11 +511,12 @@ class PgSQL
|
||||
|
||||
/**
|
||||
* postgresql array to php array
|
||||
* @param string $text array text from PostgreSQL
|
||||
* @param array $output (internal) recursive pass on for nested arrays
|
||||
* @param bool|int $limit (internal) max limit to not overshoot the end, start with false
|
||||
* @param integer $offset (internal) shift offset for {}
|
||||
* @return array|int converted PHP array, interal recusrive int position
|
||||
* @param string $text array text from PostgreSQL
|
||||
* @param array<mixed> $output (internal) recursive pass on for nested arrays
|
||||
* @param bool|int $limit (internal) max limit to not overshoot
|
||||
* the end, start with false
|
||||
* @param integer $offset (internal) shift offset for {}
|
||||
* @return array<mixed>|int converted PHP array, interal recusrive int position
|
||||
*/
|
||||
public function __dbArrayParse($text, &$output, $limit = false, $offset = 1)
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace CoreLibs\Debug;
|
||||
|
||||
class FileWriter
|
||||
{
|
||||
/** @var string */
|
||||
private static $debug_filename = 'debug_file.log'; // where to write output
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,38 +27,65 @@ namespace CoreLibs\Debug;
|
||||
class Logging
|
||||
{
|
||||
// page and host name
|
||||
/** @var string */
|
||||
private $page_name;
|
||||
/** @var string */
|
||||
private $host_name;
|
||||
/** @var int */
|
||||
private $host_port;
|
||||
// internal error reporting vars
|
||||
/** @var array<mixed> */
|
||||
private $error_msg = []; // the "connection" to the outside errors
|
||||
// debug output prefix
|
||||
/** @var string */
|
||||
private $error_msg_prefix = ''; // prefix to the error string (the class name)
|
||||
// debug flags
|
||||
/** @var array<mixed> */
|
||||
private $debug_output = []; // if this is true, show debug on desconstructor
|
||||
/** @var array<mixed> */
|
||||
private $debug_output_not = [];
|
||||
/** @var bool */
|
||||
private $debug_output_all = false;
|
||||
/** @var array<mixed> */
|
||||
private $echo_output = []; // errors: echo out, default is 1
|
||||
/** @var array<mixed> */
|
||||
private $echo_output_not = [];
|
||||
/** @var bool */
|
||||
private $echo_output_all = false;
|
||||
/** @var array<mixed> */
|
||||
private $print_output = []; // errors: print to file, default is 0
|
||||
/** @var array<mixed> */
|
||||
private $print_output_not = [];
|
||||
/** @var bool */
|
||||
private $print_output_all = false;
|
||||
// debug flags/settings
|
||||
/** @var string */
|
||||
private $running_uid = ''; // unique ID set on class init and used in logging as prefix
|
||||
// log file name
|
||||
/** @var string */
|
||||
private $log_folder = '';
|
||||
/** @var string */
|
||||
private $log_file_name_ext = 'log'; // use this for date rotate
|
||||
/** @var int */
|
||||
private $log_max_filesize = 0; // set in kilobytes
|
||||
/** @var string */
|
||||
private $log_print_file = 'error_msg##LOGID####LEVEL####CLASS####PAGENAME####DATE##';
|
||||
/** @var string */
|
||||
private $log_file_unique_id; // a unique ID set only once for call derived from this class
|
||||
/** @var bool */
|
||||
private $log_print_file_date = true; // if set add Y-m-d and do automatic daily rotation
|
||||
/** @var string */
|
||||
private $log_file_id = ''; // a alphanumeric name that has to be set as global definition
|
||||
/** @var bool */
|
||||
private $log_per_level = false; // set, it will split per level (first parameter in debug call)
|
||||
/** @var bool */
|
||||
private $log_per_class = false; // set, will split log per class
|
||||
/** @var bool */
|
||||
private $log_per_page = false; // set, will split log per called file
|
||||
/** @var bool */
|
||||
private $log_per_run = false; // create a new log file per run (time stamp + unique ID)
|
||||
// script running time
|
||||
/** @var float */
|
||||
private $script_starttime;
|
||||
|
||||
public function __construct()
|
||||
@@ -281,8 +308,9 @@ 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)]];
|
||||
return end($backtrace)['class'];
|
||||
$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'] ?? '';
|
||||
}
|
||||
|
||||
// *** PUBLIC ***
|
||||
@@ -341,7 +369,7 @@ class Logging
|
||||
*/
|
||||
public function debugFor(string $type, string $flag): void
|
||||
{
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal */
|
||||
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal @phpstan-ignore-next-line */
|
||||
$this->setLogLevel(...[func_get_args()]);
|
||||
}
|
||||
|
||||
@@ -381,7 +409,7 @@ class Logging
|
||||
* @param string $flag on/off
|
||||
* @param string|null $level if not null then check if this array entry is set
|
||||
* else return false
|
||||
* @return bool|array if $level is null, return array, else boolean true/false
|
||||
* @return bool|array<mixed> if $level is null, return array, else boolean true/false
|
||||
*/
|
||||
public function getLogLevel(string $type, string $flag, ?string $level = null)
|
||||
{
|
||||
@@ -439,8 +467,8 @@ class Logging
|
||||
* It uses some special code sets so we can convert that to pre flags
|
||||
* for echo output {##HTMLPRE##} ... {##/HTMLPRE##}
|
||||
* Do not use this without using it in a string in debug function
|
||||
* @param array $a Array to format
|
||||
* @return string print_r formated
|
||||
* @param array<mixed> $a Array to format
|
||||
* @return string print_r formated
|
||||
*/
|
||||
public function prAr(array $a): string
|
||||
{
|
||||
@@ -486,9 +514,13 @@ class Logging
|
||||
($strip ?
|
||||
// find any <br> and replace them with \n
|
||||
// strip rest of html elements (base only)
|
||||
preg_replace("/(<\/?)(\w+)([^>]*>)/", '', str_replace('<br>', "\n", $prefix . $string)) :
|
||||
preg_replace(
|
||||
"/(<\/?)(\w+)([^>]*>)/",
|
||||
'',
|
||||
str_replace('<br>', "\n", $prefix . $string)
|
||||
) :
|
||||
$prefix . $string
|
||||
)
|
||||
) ?: ''
|
||||
)
|
||||
. "\n"
|
||||
);
|
||||
@@ -522,8 +554,8 @@ class Logging
|
||||
/**
|
||||
* merges the given error array with the one from this class
|
||||
* only merges visible ones
|
||||
* @param array $error_msg error array
|
||||
* @return void has no return
|
||||
* @param array<mixed> $error_msg error array
|
||||
* @return void has no return
|
||||
*/
|
||||
public function mergeErrors(array $error_msg = []): void
|
||||
{
|
||||
@@ -593,7 +625,7 @@ class Logging
|
||||
/**
|
||||
* Get current error message array
|
||||
*
|
||||
* @return array error messages collected
|
||||
* @return array<mixed> error messages collected
|
||||
*/
|
||||
public function getErrorMsg(): array
|
||||
{
|
||||
|
||||
@@ -11,12 +11,18 @@ namespace CoreLibs\Debug;
|
||||
class RunningTime
|
||||
{
|
||||
// hr
|
||||
/** @var float */
|
||||
private static $hr_starttime;
|
||||
/** @var float */
|
||||
private static $hr_runtime;
|
||||
/** @var float */
|
||||
private static $hr_endtime;
|
||||
// normal
|
||||
/** @var float */
|
||||
private static $starttime;
|
||||
/** @var float */
|
||||
private static $endtime;
|
||||
/** @var string */
|
||||
private static $runningtime_string;
|
||||
|
||||
/**
|
||||
@@ -77,8 +83,8 @@ class RunningTime
|
||||
* on second call it sends the end time and then also prints the running time
|
||||
* Sets the internal runningtime_string variable with Start/End/Run time string
|
||||
* NOTE: for pure running time check it is recommended to use hrRunningTime method
|
||||
* @param bool|boolean $simple if true prints HTML strings, default text only
|
||||
* @return float running time as float number
|
||||
* @param bool $simple if true prints HTML strings, default text only
|
||||
* @return float running time as float number
|
||||
*/
|
||||
public static function runningTime(bool $simple = false): float
|
||||
{
|
||||
|
||||
@@ -31,8 +31,8 @@ class Support
|
||||
|
||||
/**
|
||||
* prints a html formatted (pre) array
|
||||
* @param array $array any array
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
* @param array<mixed> $array any array
|
||||
* @return string formatted array for output with <pre> tag added
|
||||
*/
|
||||
public static function printAr(array $array): string
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,7 +48,7 @@ class System
|
||||
|
||||
/**
|
||||
* get the host name without the port as given by the SELF var
|
||||
* @return array host name/port name
|
||||
* @return array<mixed> host name/port name
|
||||
*/
|
||||
public static function getHostName(): array
|
||||
{
|
||||
@@ -86,7 +86,7 @@ class System
|
||||
/**
|
||||
* similar to getPageName, but it retuns the raw array
|
||||
*
|
||||
* @return array pathinfo array from PHP SELF
|
||||
* @return array<string> pathinfo array from PHP SELF
|
||||
*/
|
||||
public static function getPageNameArray(): array
|
||||
{
|
||||
|
||||
@@ -28,21 +28,27 @@ namespace CoreLibs\Language\Core;
|
||||
// over it (it assumes knowledge of StringReader internals)
|
||||
class CachedFileReader extends \CoreLibs\Language\Core\StringReader
|
||||
{
|
||||
/** @var int */
|
||||
public $error = 0;
|
||||
/** @var string */
|
||||
public $fd_str = '';
|
||||
|
||||
public function __construct($filename)
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $filename
|
||||
*/
|
||||
public function __construct(string $filename)
|
||||
{
|
||||
parent::__construct();
|
||||
if (file_exists($filename)) {
|
||||
$length = filesize($filename);
|
||||
$fd = fopen($filename, 'rb');
|
||||
|
||||
if (!$fd) {
|
||||
if (!is_resource($fd)) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
} else {
|
||||
$this->fd_str = fread($fd, filesize($filename) ?: 0) ?: '';
|
||||
fclose($fd);
|
||||
}
|
||||
$this->fd_str = fread($fd, $length);
|
||||
fclose($fd);
|
||||
} else {
|
||||
$this->error = 2; // File doesn't exist
|
||||
}
|
||||
|
||||
@@ -26,9 +26,13 @@ namespace CoreLibs\Language\Core;
|
||||
|
||||
class FileReader
|
||||
{
|
||||
/** @var int */
|
||||
public $fr_pos;
|
||||
/** @var resource|bool */
|
||||
public $fr_fd;
|
||||
/** @var int */
|
||||
public $fr_length;
|
||||
/** @var int */
|
||||
public $error = 0;
|
||||
|
||||
/**
|
||||
@@ -38,10 +42,10 @@ class FileReader
|
||||
public function __construct($filename)
|
||||
{
|
||||
if (file_exists($filename)) {
|
||||
$this->fr_length = filesize($filename);
|
||||
$this->fr_length = filesize($filename) ?: 0;
|
||||
$this->fr_pos = 0;
|
||||
$this->fr_fd = fopen($filename, 'rb');
|
||||
if (!$this->fr_fd) {
|
||||
if (!is_resource($this->fr_fd)) {
|
||||
$this->error = 3; // Cannot read file, probably permissions
|
||||
}
|
||||
} else {
|
||||
@@ -56,23 +60,25 @@ class FileReader
|
||||
*/
|
||||
public function read($bytes)
|
||||
{
|
||||
if ($bytes) {
|
||||
fseek($this->fr_fd, $this->fr_pos);
|
||||
|
||||
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
|
||||
// the discussions at PHP Bugs suggest it's the intended behaviour
|
||||
$data = '';
|
||||
while ($bytes > 0) {
|
||||
$chunk = fread($this->fr_fd, $bytes);
|
||||
$data .= $chunk;
|
||||
$bytes -= strlen($chunk);
|
||||
}
|
||||
$this->fr_pos = ftell($this->fr_fd);
|
||||
|
||||
return $data;
|
||||
} else {
|
||||
if (!$bytes || !is_resource($this->fr_fd)) {
|
||||
return '';
|
||||
}
|
||||
fseek($this->fr_fd, $this->fr_pos);
|
||||
|
||||
// PHP 5.1.1 does not read more than 8192 bytes in one fread()
|
||||
// the discussions at PHP Bugs suggest it's the intended behaviour
|
||||
$data = '';
|
||||
while ($bytes > 0) {
|
||||
$chunk = fread($this->fr_fd, $bytes);
|
||||
if ($chunk === false) {
|
||||
break;
|
||||
}
|
||||
$data .= $chunk;
|
||||
$bytes -= strlen($chunk);
|
||||
}
|
||||
$this->fr_pos = ftell($this->fr_fd) ?: 0;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +88,11 @@ class FileReader
|
||||
*/
|
||||
public function seekto($pos)
|
||||
{
|
||||
if (!is_resource($this->fr_fd)) {
|
||||
return 0;
|
||||
}
|
||||
fseek($this->fr_fd, $pos);
|
||||
$this->fr_pos = ftell($this->fr_fd);
|
||||
$this->fr_pos = ftell($this->fr_fd) ?: 0;
|
||||
return $this->fr_pos;
|
||||
}
|
||||
|
||||
@@ -111,7 +120,9 @@ class FileReader
|
||||
*/
|
||||
public function close(): void
|
||||
{
|
||||
fclose($this->fr_fd);
|
||||
if (is_resource($this->fr_fd)) {
|
||||
fclose($this->fr_fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,19 +40,31 @@ namespace CoreLibs\Language\Core;
|
||||
class GetTextReader
|
||||
{
|
||||
// public:
|
||||
/** @var int */
|
||||
public $error = 0; // public variable that holds error code (0 if no error)
|
||||
|
||||
// private:
|
||||
/** @var int */
|
||||
private $BYTEORDER = 0; // 0: low endian, 1: big endian
|
||||
private $STREAM = null;
|
||||
/** @var FileReader */
|
||||
private $STREAM;
|
||||
/** @var bool */
|
||||
private $short_circuit = false;
|
||||
/** @var bool */
|
||||
private $enable_cache = false;
|
||||
private $originals = null; // offset of original table
|
||||
private $translations = null; // offset of translation table
|
||||
private $pluralheader = null; // cache header field for plural forms
|
||||
/** @var int */
|
||||
private $originals = 0; // offset of original table
|
||||
/** @var int */
|
||||
private $translations = 0; // offset of translation table
|
||||
/** @var string */
|
||||
private $pluralheader = ''; // cache header field for plural forms
|
||||
/** @var int */
|
||||
private $total = 0; // total string count
|
||||
/** @var array<mixed>|null */
|
||||
private $table_originals = null; // table for original strings (offsets)
|
||||
/** @var array<mixed>|null */
|
||||
private $table_translations = null; // table for translated strings (offsets)
|
||||
/** @var array<mixed> */
|
||||
private $cache_translations = []; // original -> translation mapping
|
||||
|
||||
|
||||
@@ -69,13 +81,12 @@ class GetTextReader
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
$input = unpack('V', $this->STREAM->read(4));
|
||||
return array_shift($input);
|
||||
$input = unpack('V', $this->STREAM->read(4)) ?: [];
|
||||
} else {
|
||||
// big endian
|
||||
$input = unpack('N', $this->STREAM->read(4));
|
||||
return array_shift($input);
|
||||
$input = unpack('N', $this->STREAM->read(4)) ?: [];
|
||||
}
|
||||
return array_shift($input);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,29 +103,34 @@ class GetTextReader
|
||||
* Reads an array of Integers from the Stream
|
||||
*
|
||||
* @param int $count How many elements should be read
|
||||
* @return array Array of Integers
|
||||
* @return array<mixed> Array of Integers
|
||||
*/
|
||||
public function readintarray($count)
|
||||
{
|
||||
if ($this->BYTEORDER == 0) {
|
||||
// low endian
|
||||
return unpack('V' . $count, $this->STREAM->read(4 * $count));
|
||||
return unpack('V' . $count, $this->STREAM->read(4 * $count)) ?: [];
|
||||
} else {
|
||||
// big endian
|
||||
return unpack('N' . $count, $this->STREAM->read(4 * $count));
|
||||
return unpack('N' . $count, $this->STREAM->read(4 * $count)) ?: [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $Reader the StreamReader object
|
||||
* @param bool $enable_cache Enable or disable caching of strings (default on)
|
||||
* @param FileReader|bool $Reader the StreamReader object
|
||||
* @param bool $enable_cache Enable or disable caching of strings (default on)
|
||||
*/
|
||||
public function __construct($Reader, $enable_cache = true)
|
||||
{
|
||||
// If there isn't a StreamReader, turn on short circuit mode.
|
||||
if (!$Reader || $Reader->error) {
|
||||
if ((!is_object($Reader) && !$Reader) || (is_object($Reader) && $Reader->error)) {
|
||||
$this->short_circuit = true;
|
||||
return;
|
||||
}
|
||||
// bail out for sure if this is not an objet here
|
||||
if (!is_object($Reader)) {
|
||||
$this->short_circuit = true;
|
||||
return;
|
||||
}
|
||||
@@ -149,8 +165,9 @@ class GetTextReader
|
||||
* to speed up translation lookups
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function load_tables()
|
||||
private function loadTables(): void
|
||||
{
|
||||
if (
|
||||
is_array($this->cache_translations) &&
|
||||
@@ -190,10 +207,10 @@ class GetTextReader
|
||||
* @param int $num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function get_original_string($num)
|
||||
private function getOriginalString($num)
|
||||
{
|
||||
$length = $this->table_originals[$num * 2 + 1];
|
||||
$offset = $this->table_originals[$num * 2 + 2];
|
||||
$length = $this->table_originals[$num * 2 + 1] ?? 0;
|
||||
$offset = $this->table_originals[$num * 2 + 2] ?? 0;
|
||||
if (!$length) {
|
||||
return '';
|
||||
}
|
||||
@@ -209,10 +226,10 @@ class GetTextReader
|
||||
* @param int $num Offset number of original string
|
||||
* @return string Requested string if found, otherwise ''
|
||||
*/
|
||||
private function get_translation_string($num)
|
||||
private function getTranslationString($num)
|
||||
{
|
||||
$length = $this->table_translations[$num * 2 + 1];
|
||||
$offset = $this->table_translations[$num * 2 + 2];
|
||||
$length = $this->table_translations[$num * 2 + 1] ?? 0;
|
||||
$offset = $this->table_translations[$num * 2 + 2] ?? 0;
|
||||
if (!$length) {
|
||||
return '';
|
||||
}
|
||||
@@ -228,18 +245,18 @@ class GetTextReader
|
||||
* @param string $string string to find
|
||||
* @param int $start (internally used in recursive function)
|
||||
* @param int $end (internally used in recursive function)
|
||||
* @return int|string|float (offset in originals table)
|
||||
* @return int (offset in originals table)
|
||||
*/
|
||||
private function find_string($string, $start = -1, $end = -1)
|
||||
private function findString($string, $start = -1, $end = -1)
|
||||
{
|
||||
if (($start == -1) or ($end == -1)) {
|
||||
// find_string is called with only one parameter, set start end end
|
||||
// findString is called with only one parameter, set start end end
|
||||
$start = 0;
|
||||
$end = $this->total;
|
||||
}
|
||||
if (abs($start - $end) <= 1) {
|
||||
// We're done, now we either found the string, or it doesn't exist
|
||||
$txt = $this->get_original_string($start);
|
||||
$txt = $this->getOriginalString($start);
|
||||
if ($string == $txt) {
|
||||
return $start;
|
||||
} else {
|
||||
@@ -247,20 +264,20 @@ class GetTextReader
|
||||
}
|
||||
} elseif ($start > $end) {
|
||||
// start > end -> turn around and start over
|
||||
return $this->find_string($string, $end, $start);
|
||||
return $this->findString($string, $end, $start);
|
||||
} else {
|
||||
// Divide table in two parts
|
||||
$half = (int)(($start + $end) / 2);
|
||||
$cmp = strcmp($string, $this->get_original_string($half));
|
||||
$cmp = strcmp($string, $this->getOriginalString($half));
|
||||
if ($cmp == 0) {
|
||||
// string is exactly in the middle => return it
|
||||
return $half;
|
||||
} elseif ($cmp < 0) {
|
||||
// The string is in the upper half
|
||||
return $this->find_string($string, $start, $half);
|
||||
return $this->findString($string, $start, $half);
|
||||
} else {
|
||||
// Translateshe string is in the lower half
|
||||
return $this->find_string($string, $half, $end);
|
||||
return $this->findString($string, $half, $end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -277,7 +294,7 @@ class GetTextReader
|
||||
if ($this->short_circuit) {
|
||||
return $string;
|
||||
}
|
||||
$this->load_tables();
|
||||
$this->loadTables();
|
||||
|
||||
if ($this->enable_cache) {
|
||||
// Caching enabled, get translated string from cache
|
||||
@@ -288,11 +305,11 @@ class GetTextReader
|
||||
}
|
||||
} else {
|
||||
// Caching not enabled, try to find string
|
||||
$num = $this->find_string($string);
|
||||
$num = $this->findString($string);
|
||||
if ($num == -1) {
|
||||
return $string;
|
||||
} else {
|
||||
return $this->get_translation_string($num);
|
||||
return $this->getTranslationString($num);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,7 +321,7 @@ class GetTextReader
|
||||
* @param string $expr an expression to match
|
||||
* @return string sanitized plural form expression
|
||||
*/
|
||||
private function sanitize_plural_expression($expr)
|
||||
private function sanitizePluralExpression($expr)
|
||||
{
|
||||
// Get rid of disallowed characters.
|
||||
$expr = preg_replace('@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@', '', $expr);
|
||||
@@ -341,7 +358,7 @@ class GetTextReader
|
||||
* @param string $header header search in plurals
|
||||
* @return string verbatim plural form header field
|
||||
*/
|
||||
private function extract_plural_forms_header_from_po_header($header)
|
||||
private function extractPluralFormsHeaderFromPoHeader($header)
|
||||
{
|
||||
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs)) {
|
||||
$expr = $regs[2];
|
||||
@@ -351,27 +368,27 @@ class GetTextReader
|
||||
return $expr;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get possible plural forms from MO header
|
||||
*
|
||||
* @access private
|
||||
* @return string plural form header
|
||||
*/
|
||||
private function get_plural_forms()
|
||||
private function getPluralForms()
|
||||
{
|
||||
// lets assume message number 0 is header
|
||||
// this is true, right?
|
||||
$this->load_tables();
|
||||
$this->loadTables();
|
||||
|
||||
// cache header field for plural forms
|
||||
if (! is_string($this->pluralheader)) {
|
||||
if ($this->enable_cache) {
|
||||
$header = $this->cache_translations[''];
|
||||
} else {
|
||||
$header = $this->get_translation_string(0);
|
||||
$header = $this->getTranslationString(0);
|
||||
}
|
||||
$expr = $this->extract_plural_forms_header_from_po_header($header);
|
||||
$this->pluralheader = $this->sanitize_plural_expression($expr);
|
||||
$expr = $this->extractPluralFormsHeaderFromPoHeader($header);
|
||||
$this->pluralheader = $this->sanitizePluralExpression($expr);
|
||||
}
|
||||
return $this->pluralheader;
|
||||
}
|
||||
@@ -383,9 +400,9 @@ class GetTextReader
|
||||
* @param string $n count
|
||||
* @return int array index of the right plural form
|
||||
*/
|
||||
private function select_string($n)
|
||||
private function selectString($n)
|
||||
{
|
||||
$string = $this->get_plural_forms();
|
||||
$string = $this->getPluralForms();
|
||||
$string = str_replace('nplurals', "\$total", $string);
|
||||
$string = str_replace("n", $n, $string);
|
||||
$string = str_replace('plural', "\$plural", $string);
|
||||
@@ -394,6 +411,7 @@ class GetTextReader
|
||||
$plural = 0;
|
||||
|
||||
eval("$string");
|
||||
/** @phpstan-ignore-next-line */
|
||||
if ($plural >= $total) {
|
||||
$plural = $total - 1;
|
||||
}
|
||||
@@ -420,7 +438,7 @@ class GetTextReader
|
||||
}
|
||||
|
||||
// find out the appropriate form
|
||||
$select = $this->select_string($number);
|
||||
$select = $this->selectString($number);
|
||||
|
||||
// this should contains all strings separated by NULLs
|
||||
$key = $single . chr(0) . $plural;
|
||||
@@ -434,11 +452,11 @@ class GetTextReader
|
||||
return $list[$select];
|
||||
}
|
||||
} else {
|
||||
$num = $this->find_string($key);
|
||||
$num = $this->findString($key);
|
||||
if ($num == -1) {
|
||||
return ($number != 1) ? $plural : $single;
|
||||
} else {
|
||||
$result = $this->get_translation_string($num);
|
||||
$result = $this->getTranslationString($num);
|
||||
$list = explode(chr(0), $result);
|
||||
return $list[$select];
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ namespace CoreLibs\Language\Core;
|
||||
|
||||
class StringReader
|
||||
{
|
||||
/** @var int */
|
||||
public $sr_pos;
|
||||
/** @var string */
|
||||
public $sr_str;
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace CoreLibs\Language;
|
||||
|
||||
class Encoding
|
||||
{
|
||||
/** @var string */
|
||||
private static $mb_error_char = '';
|
||||
|
||||
/**
|
||||
@@ -82,7 +83,7 @@ class Encoding
|
||||
* @param string $string string to test
|
||||
* @param string $from_encoding encoding of string to test
|
||||
* @param string $to_encoding target encoding
|
||||
* @return bool|array false if no error or array with failed characters
|
||||
* @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)
|
||||
{
|
||||
|
||||
@@ -33,9 +33,13 @@ use CoreLibs\Language\Core\GetTextReader;
|
||||
|
||||
class L10n extends \CoreLibs\Basic
|
||||
{
|
||||
/** @var string */
|
||||
private $lang = '';
|
||||
/** @var string */
|
||||
private $mofile = '';
|
||||
/** @var FileReader|bool */
|
||||
private $input;
|
||||
/** @var GetTextReader */
|
||||
private $l10n;
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,10 @@ class Elements
|
||||
$hour = !$hour ? date('H', $timestamp) : $hour;
|
||||
$min = !$min ? date('i', $timestamp) : $min; // add to five min?
|
||||
// max days in selected month
|
||||
$days_in_month = date('t', strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':0'));
|
||||
$days_in_month = date(
|
||||
't',
|
||||
strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':0') ?: null
|
||||
);
|
||||
$string = '';
|
||||
// from now to ?
|
||||
if ($name_pos_back === false) {
|
||||
@@ -93,7 +96,7 @@ class Elements
|
||||
// set weekday text based on current month ($month) and year ($year)
|
||||
$string .= '<option value="' . ($i < 10 ? '0' . $i : $i) . '" '
|
||||
. ($day == $i ? 'selected' : '') . '>' . $i
|
||||
. ' (' . date('D', mktime(0, 0, 0, $month, $i, $year)) . ')</option>';
|
||||
. ' (' . date('D', mktime(0, 0, 0, (int)$month, $i, (int)$year) ?: null) . ')</option>';
|
||||
}
|
||||
$string .= '</select> ';
|
||||
if ($name_pos_back === true) {
|
||||
@@ -142,8 +145,8 @@ class Elements
|
||||
$protList = ["http", "https", "ftp", "news", "nntp"];
|
||||
|
||||
// find urls w/o protocol
|
||||
$output = preg_replace("/([^\/])www\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1http://www.\\2.\\3", $output);
|
||||
$output = preg_replace("/([^\/])ftp\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1ftp://ftp.\\2.\\3", $output);
|
||||
$output = preg_replace("/([^\/])www\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1http://www.\\2.\\3", $output) ?: '';
|
||||
$output = preg_replace("/([^\/])ftp\.([\w\.-]+)\.([a-zA-Z]{2,4})/", "\\1ftp://ftp.\\2.\\3", $output) ?: '';
|
||||
|
||||
// remove doubles, generate protocol-regex
|
||||
// DIRTY HACK
|
||||
@@ -181,7 +184,7 @@ class Elements
|
||||
);
|
||||
},
|
||||
$output
|
||||
);
|
||||
) ?: '';
|
||||
// find email-addresses, but not mailto prefix ones
|
||||
$output = preg_replace_callback(
|
||||
"/(mailto:)?(\>)?\b([\w\.-]+)@([\w\.\-]+)\.([a-zA-Z]{2,4})\b(\|([^\||^#]+)(#([^\|]+))?\|)?/",
|
||||
@@ -197,7 +200,7 @@ class Elements
|
||||
);
|
||||
},
|
||||
$output
|
||||
);
|
||||
) ?: '';
|
||||
|
||||
// we have one slashes after the Protocol -> internal link no domain, strip out the proto
|
||||
// $output = preg_replace("/($protRegex)\/(.*)/e", "\\2", $ouput);
|
||||
@@ -270,6 +273,9 @@ class Elements
|
||||
return "mailto:" . $email;
|
||||
} elseif ($atag) {
|
||||
return $atag . $email;
|
||||
} else {
|
||||
// else just return email as is
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,51 +222,83 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
{
|
||||
// for the load statetment describes which elements from
|
||||
// the load query should be shown and i which format
|
||||
/** @var array<mixed> */
|
||||
public $field_array = [];
|
||||
/** @var string */
|
||||
public $load_query; // the query needed for loading a data set (one row in the table)
|
||||
/** @var string */
|
||||
public $col_name; // the name of the columen (before _<type>) [used for order button]
|
||||
/** @var int */
|
||||
public $yes; // the yes flag that triggers the template to show ALL and not only new/load
|
||||
/** @var string */
|
||||
public $msg; // the error msg
|
||||
/** @var int */
|
||||
public $error; // the error flag set for printing red error msg
|
||||
/** @var int */
|
||||
public $warning; // warning flag, for information (saved, loaded, etc)
|
||||
/** @var string */
|
||||
public $archive_pk_name; // the pk name for the load select form
|
||||
/** @var string */
|
||||
private $int_pk_name; // primary key, only internal usage
|
||||
/** @var array<mixed> */
|
||||
public $reference_array = []; // reference arrays -> stored in $this->reference_array[$table_name] => [];
|
||||
// NOTE: should be changed to this @var mixed[]
|
||||
/** @var array<mixed> */
|
||||
public $element_list; // element list for elements next to each other as a special sub group
|
||||
/** @var array<mixed> */
|
||||
public $table_array = [];
|
||||
/** @var string */
|
||||
public $my_page_name; // the name of the page without .php extension
|
||||
/** @var bool */
|
||||
public $mobile_phone = false;
|
||||
// buttons and checkboxes
|
||||
/** @var string */
|
||||
public $archive;
|
||||
/** @var string */
|
||||
public $new;
|
||||
/** @var string */
|
||||
public $really_new;
|
||||
/** @var string */
|
||||
public $delete;
|
||||
/** @var string */
|
||||
public $really_delete;
|
||||
/** @var string */
|
||||
public $save;
|
||||
/** @var string */
|
||||
public $remove_button;
|
||||
// security publics
|
||||
/** @var int */
|
||||
public $base_acl_level;
|
||||
/** @var array<mixed> */
|
||||
public $security_level;
|
||||
// layout publics
|
||||
/** @var int */
|
||||
public $table_width;
|
||||
// internal lang & encoding vars
|
||||
/** @var string */
|
||||
public $lang_dir = '';
|
||||
/** @var string */
|
||||
public $lang;
|
||||
/** @var string */
|
||||
public $lang_short;
|
||||
/** @var string */
|
||||
public $encoding;
|
||||
// language
|
||||
/** @var \CoreLibs\Language\L10n */
|
||||
public $l;
|
||||
|
||||
// now some default error msgs (english)
|
||||
/** @var array<mixed> */
|
||||
public $language_array = [];
|
||||
|
||||
/**
|
||||
* construct form generator
|
||||
* @param array $db_config db config array
|
||||
* @param int|integer $table_width table/div width (default 750)
|
||||
* @param array<mixed> $db_config db config array
|
||||
* @param int|integer $table_width table/div width (default 750)
|
||||
*/
|
||||
public function __construct(array $db_config, int $table_width = 750)
|
||||
{
|
||||
global $table_arrays;
|
||||
// replace any non valid variable names
|
||||
// TODO extracft only alphanumeric and _ after . to _ replacement
|
||||
$this->my_page_name = str_replace(['.'], '_', \CoreLibs\Get\System::getPageName(1));
|
||||
@@ -278,12 +310,15 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
// first check if we have a in page override as $table_arrays[page name]
|
||||
if (
|
||||
isset($_GLOBALS['table_arrays']) &&
|
||||
is_array($_GLOBALS['table_arrays']) &&
|
||||
isset($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)])
|
||||
/* isset($GLOBALS['table_arrays']) &&
|
||||
is_array($GLOBALS['table_arrays']) &&
|
||||
isset($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)]) */
|
||||
isset($table_arrays[\CoreLibs\Get\System::getPageName(1)]) &&
|
||||
is_array($table_arrays[\CoreLibs\Get\System::getPageName(1)])
|
||||
) {
|
||||
$config_array = $_GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)];
|
||||
// $config_array = $GLOBALS['table_arrays'][\CoreLibs\Get\System::getPageName(1)];
|
||||
$config_array = $table_arrays[\CoreLibs\Get\System::getPageName(1)];
|
||||
} else {
|
||||
// WARNING: auto spl load does not work with this as it is an array and not a function/object
|
||||
// check if this is the old path or the new path
|
||||
@@ -474,7 +509,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
* array of fields
|
||||
* @param string $want_key the key where you want the data from
|
||||
* @param string|null $key_value if set searches for special right value
|
||||
* @return array found key fields
|
||||
* @return array<mixed> found key fields
|
||||
*/
|
||||
public function formGetColNameArrayFromKey(string $want_key, ?string $key_value = null): array
|
||||
{
|
||||
@@ -496,7 +531,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* formated output for the error && warning msg
|
||||
* @return array error message with msg, width, clas
|
||||
* @return array<string,string|int> error message with msg, width, clas
|
||||
*/
|
||||
public function formPrintMsg(): array
|
||||
{
|
||||
@@ -601,9 +636,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* default delete procedure
|
||||
* @param array $element_list element array that should be removed
|
||||
* @param array $remove_name key names that should be removed
|
||||
* @return void has no return
|
||||
* @param array<mixed> $element_list element array that should be removed
|
||||
* @param array<mixed> $remove_name key names that should be removed
|
||||
* @return void has no return
|
||||
*/
|
||||
public function formProcedureDeleteFromElementList(array $element_list, array $remove_name): void
|
||||
{
|
||||
@@ -617,8 +652,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if (
|
||||
isset($this->security_level['delete']) &&
|
||||
$this->base_acl_level >= $this->security_level['delete'] &&
|
||||
(!isset($this->table_array['protected']['value']) ||
|
||||
(isset($this->table_array['protected']['value']) && !$this->table_array['protected']['value'])) &&
|
||||
empty($this->table_array['protected']['value']) &&
|
||||
!$this->error
|
||||
) {
|
||||
if (!is_array($element_list)) {
|
||||
@@ -629,7 +663,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// . is_array($this->element_list[$element_list[$i]]['read_data']) . ' | '
|
||||
// . $this->element_list[$element_list[$i]]['delete']);
|
||||
// if prefix, set it
|
||||
$prfx = ($this->element_list[$element_list[$i]]['prefix']) ?
|
||||
$prfx = !empty($this->element_list[$element_list[$i]]['prefix']) ?
|
||||
$this->element_list[$element_list[$i]]['prefix'] . '_' :
|
||||
'';
|
||||
// get the primary key
|
||||
@@ -700,7 +734,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* create the load list and return it as an array
|
||||
* @return array load list array with primary key, name and selected entry
|
||||
* @return array<string,mixed> load list array with primary key, name and selected entry
|
||||
*/
|
||||
public function formCreateLoad(): array
|
||||
{
|
||||
@@ -717,7 +751,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
// load list data
|
||||
$this->dbExec($this->load_query);
|
||||
while ($res = $this->dbFetchArray()) {
|
||||
while (is_array($res = $this->dbFetchArray())) {
|
||||
$pk_ids[] = $res[$this->int_pk_name];
|
||||
if (
|
||||
isset($this->table_array[$this->int_pk_name]['value']) &&
|
||||
@@ -762,8 +796,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* Create new entry element for HTML output
|
||||
* @param bool $hide_new_checkbox show or hide the new checkbox, default is false
|
||||
* @return array return the new create array with name & checkbox show flag
|
||||
* @param bool $hide_new_checkbox show or hide the new checkbox, default is false
|
||||
* @return array<string,string|int> return the new create array with name & checkbox show flag
|
||||
*/
|
||||
public function formCreateNew($hide_new_checkbox = false): array
|
||||
{
|
||||
@@ -794,7 +828,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
* create the save and delete element html group data
|
||||
* @param bool $hide_delete hide the delete button (default false)
|
||||
* @param bool $hide_delete_checkbox hide the delete checkbox (default false)
|
||||
* @return array return the hide/show delete framework for html creation
|
||||
* @return array<string,mixed> return the hide/show delete framework
|
||||
* for html creation
|
||||
*/
|
||||
public function formCreateSaveDelete($hide_delete = false, $hide_delete_checkbox = false): array
|
||||
{
|
||||
@@ -810,7 +845,6 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
(isset($this->security_level['delete']) &&
|
||||
$this->base_acl_level >= $this->security_level['delete'])
|
||||
) {
|
||||
$old_school_hidden = 0;
|
||||
if ($this->base_acl_level >= $this->security_level['save']) {
|
||||
$seclevel_okay = 1;
|
||||
if (empty($this->table_array[$this->int_pk_name]['value'])) {
|
||||
@@ -819,7 +853,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$save = $this->l->__('Update');
|
||||
}
|
||||
// print the old_school hidden if requestet
|
||||
if ($old_school_hidden) {
|
||||
if ($old_school_hidden == 1) {
|
||||
$pk_name = $this->int_pk_name;
|
||||
$pk_value = $this->table_array[$this->int_pk_name]['value'];
|
||||
}
|
||||
@@ -850,8 +884,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
* @param string $element_name the name from the array, you want to have build
|
||||
* @param string|null $query can overrule internal query data,
|
||||
* for drop down, as data comes from a reference table
|
||||
* for drop_down_text it has to be an array with $key->$valu
|
||||
* @return array html settings array
|
||||
* for drop_down_text it has to be an
|
||||
* array with $key->$value
|
||||
* @return array<string,mixed> html settings array
|
||||
*/
|
||||
public function formCreateElement(string $element_name, ?string $query = null): array
|
||||
{
|
||||
@@ -990,7 +1025,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$data['name'] = $element_name;
|
||||
$data['value'][] = '';
|
||||
$data['output'][] = $this->l->__('Please choose .. . ');
|
||||
while ($res = $this->dbReturn($query)) {
|
||||
while (is_array($res = $this->dbReturn($query))) {
|
||||
$data['value'][] = $res[0];
|
||||
$data['output'][] = $res[1];
|
||||
if (
|
||||
@@ -1162,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']
|
||||
@@ -1270,7 +1307,10 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// if mandatory && no input
|
||||
// $this->log->debug('form', 'A: ' . $this->table_array[$key]['type'] . ' -- '
|
||||
// . $this->table_array[$key]['input_value'] . ' -- ' . $this->table_array[$key]['value']);
|
||||
if (!$this->table_array[$key]['value'] && $this->table_array[$key]['type'] != 'binary') {
|
||||
if (
|
||||
empty($this->table_array[$key]['value']) &&
|
||||
$this->table_array[$key]['type'] != 'binary'
|
||||
) {
|
||||
$this->msg .= sprintf(
|
||||
$this->l->__('Please enter something into the <b>%s</b> field!<br>'),
|
||||
$this->table_array[$key]['output_name']
|
||||
@@ -1303,22 +1343,18 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
} // while
|
||||
// do check for reference tables
|
||||
if (is_array($this->reference_array)) {
|
||||
reset($this->reference_array);
|
||||
foreach ($this->reference_array as $key => $value) {
|
||||
if (
|
||||
isset($this->reference_array[$key]['mandatory']) &&
|
||||
$this->reference_array[$key]['mandatory'] &&
|
||||
!$this->reference_array[$key]['selected'][0]
|
||||
) {
|
||||
$this->msg .= sprintf(
|
||||
$this->l->__('Please select at least one Element from field <b>%s</b>!<br>'),
|
||||
$this->reference_array[$key]['output_name']
|
||||
);
|
||||
}
|
||||
reset($this->reference_array);
|
||||
foreach ($this->reference_array as $key => $value) {
|
||||
if (
|
||||
isset($this->reference_array[$key]['mandatory']) &&
|
||||
$this->reference_array[$key]['mandatory'] &&
|
||||
!$this->reference_array[$key]['selected'][0]
|
||||
) {
|
||||
$this->msg .= sprintf(
|
||||
$this->l->__('Please select at least one Element from field <b>%s</b>!<br>'),
|
||||
$this->reference_array[$key]['output_name']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->reference_array = [];
|
||||
}
|
||||
// $this->log->debug('edit_error', 'QS: <pre>' . print_r($_POST, true) . '</pre>');
|
||||
if (is_array($this->element_list)) {
|
||||
@@ -1496,7 +1532,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* sets the order to the maximum, if order flag is set in array
|
||||
* @return array table array with set order number
|
||||
* @return array<mixed> table array with set order number
|
||||
*/
|
||||
public function formSetOrder(): array
|
||||
{
|
||||
@@ -1504,20 +1540,30 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$order_name = $this->formGetColNameFromKey('order');
|
||||
if ($order_name) {
|
||||
// first check out of order ...
|
||||
|
||||
if (!$this->table_array[$order_name]['value']) {
|
||||
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 ($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);
|
||||
} elseif (!empty($this->table_array[$this->int_pk_name]['value'])) {
|
||||
$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;
|
||||
@@ -1587,7 +1633,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
$q = 'SELECT ' . $this->reference_array[$key]['other_table_pk']
|
||||
. ' FROM ' . $this->reference_array[$key]['table_name']
|
||||
. ' WHERE ' . $this->int_pk_name . ' = ' . $this->table_array[$this->int_pk_name]['value'];
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
while (is_array($res = $this->dbReturn($q))) {
|
||||
$this->reference_array[$key]['selected'][] = $res[$this->reference_array[$key]['other_table_pk']];
|
||||
}
|
||||
}
|
||||
@@ -1622,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'])) . "'";
|
||||
@@ -1630,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
|
||||
@@ -1640,14 +1689,14 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
. ' (' . $this->table_array[$key]['input_name'] . ') VALUES ('
|
||||
. "'" . $this->dbEscapeString($this->table_array[$key]['input_value']) . "')";
|
||||
$this->dbExec($q);
|
||||
if (!empty($this->table_array[$key]['where'])) {
|
||||
if (!empty($this->table_array[$key]['where']) && is_numeric($this->dbGetInsertPK())) {
|
||||
// make an update on the just inseted data with the where data als update values
|
||||
$q = 'UPDATE ' . $this->table_array[$key]['table_name'] . ' SET ';
|
||||
$q .= $this->table_array[$key]['where'] . ' ';
|
||||
$q .= 'WHERE ' . $this->table_array[$key]['pk_name'] . ' = ' . $this->insert_id;
|
||||
$q .= 'WHERE ' . $this->table_array[$key]['pk_name'] . ' = ' . $this->dbGetInsertPK();
|
||||
$this->dbExec($q);
|
||||
}
|
||||
$this->table_array[$key]['value'] = $this->insert_id;
|
||||
$this->table_array[$key]['value'] = $this->dbGetInsertPK();
|
||||
} // set value from DB through select or insert
|
||||
unset($this->table_array[$key]['input_value']);
|
||||
} // if it is certain field type && if there is something in the temp field
|
||||
@@ -1660,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'])) . "'";
|
||||
@@ -1668,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
|
||||
@@ -1766,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) {
|
||||
@@ -2033,8 +2083,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* creates HTML hidden input fields out of an hash array
|
||||
* @param array $hidden_array The list of fields to be added as hidden
|
||||
* @return array key -> value list of hidden fileds data
|
||||
* @param array<mixed> $hidden_array The list of fields to be added as hidden
|
||||
* @return array<mixed> key -> value list of hidden fileds data
|
||||
*/
|
||||
public function formCreateHiddenFields(array $hidden_array = []): array
|
||||
{
|
||||
@@ -2066,8 +2116,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
|
||||
/**
|
||||
* creates the multiple select part for a reference_table
|
||||
* @param string $table_name Table name for reference array lookup
|
||||
* @return array Reference table output array
|
||||
* @param string $table_name Table name for reference array lookup
|
||||
* @return array<string,mixed> Reference table output array
|
||||
*/
|
||||
public function formCreateElementReferenceTable(string $table_name): array
|
||||
{
|
||||
@@ -2081,7 +2131,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
}
|
||||
$data['name'] = $this->reference_array[$table_name]['other_table_pk'];
|
||||
$data['size'] = $this->reference_array[$table_name]['select_size'];
|
||||
while ($res = $this->dbReturn($this->reference_array[$table_name]['query'])) {
|
||||
while (is_array($res = $this->dbReturn($this->reference_array[$table_name]['query']))) {
|
||||
$data['value'][] = $res[0];
|
||||
$data['output'][] = $res[1];
|
||||
$data['selected'][] = (\CoreLibs\Convert\Html::checked(
|
||||
@@ -2103,8 +2153,8 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
* this currently only works for a list that is filled from a sub table and creates
|
||||
* only a connection to this one new version will allow a sub list with free input
|
||||
* fields to directly fill a sub table to a master table
|
||||
* @param string $table_name which element entry to create
|
||||
* @return array element for html creation
|
||||
* @param string $table_name Which element entry to create
|
||||
* @return array<string,mixed> Element for html creation
|
||||
*/
|
||||
public function formCreateElementListTable(string $table_name): array
|
||||
{
|
||||
@@ -2183,7 +2233,7 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
// only two elements are allowed: pos 0 is key, pso 1 is visible output name
|
||||
if (isset($data_array['type']) && $data_array['type'] == 'drop_down_db') {
|
||||
$md_q = md5($data_array['query']);
|
||||
while ($res = $this->dbReturn($data_array['query'])) {
|
||||
while (is_array($res = $this->dbReturn($data_array['query']))) {
|
||||
/** @phan-suppress-next-line PhanTypeInvalidDimOffset */
|
||||
$this->log->debug('edit', 'Q[' . $md_q . '] pos: ' . $this->cursor_ext[$md_q]['pos']
|
||||
. ' | want: ' . ($data_array['preset'] ?? '-')
|
||||
@@ -2260,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';
|
||||
@@ -2326,9 +2376,9 @@ class Generate extends \CoreLibs\DB\Extended\ArrayIO
|
||||
if (isset($q)) {
|
||||
$pos = 0; // position in while for overwrite if needed
|
||||
// read out the list and add the selected data if needed
|
||||
while ($res = $this->dbReturn($q)) {
|
||||
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
|
||||
@@ -2377,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 = (isset($data['content']) && is_array($data['content'])) ? count($data['content']) : 0;
|
||||
$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
|
||||
@@ -2394,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'])
|
||||
) {
|
||||
@@ -2432,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) {
|
||||
@@ -127,13 +127,14 @@ class Image
|
||||
$return_data = $thumb;
|
||||
// if we have a delete filename, delete here with glob
|
||||
if ($delete_filename) {
|
||||
array_map('unlink', glob($delete_filename . '*'));
|
||||
array_map('unlink', glob($delete_filename . '*') ?: []);
|
||||
}
|
||||
} else {
|
||||
if ($dummy && strstr($dummy, '/') === false) {
|
||||
if (!empty($dummy) && strstr($dummy, '/') === false) {
|
||||
// check if we have the "dummy" image flag set
|
||||
$filename = PICTURES . ICONS . strtoupper($dummy) . ".png";
|
||||
if ($dummy && file_exists($filename) && is_file($filename)) {
|
||||
/** @phpstan-ignore-next-line */
|
||||
if (!empty($dummy) && file_exists($filename) && is_file($filename)) {
|
||||
$return_data = $filename;
|
||||
} else {
|
||||
$return_data = false;
|
||||
@@ -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
|
||||
@@ -255,11 +256,18 @@ class Image
|
||||
) {
|
||||
// image, copy source image, offset in image, source x/y, new size, source image size
|
||||
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
|
||||
if ($thumb === false) {
|
||||
return false;
|
||||
}
|
||||
if ($img_type == IMAGETYPE_PNG) {
|
||||
$imagecolorallocatealpha = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
|
||||
if ($imagecolorallocatealpha === false) {
|
||||
return false;
|
||||
}
|
||||
// preservere transaprency
|
||||
imagecolortransparent(
|
||||
$thumb,
|
||||
imagecolorallocatealpha($thumb, 0, 0, 0, 127)
|
||||
$imagecolorallocatealpha
|
||||
);
|
||||
imagealphablending($thumb, false);
|
||||
imagesavealpha($thumb, true);
|
||||
@@ -274,7 +282,7 @@ class Image
|
||||
break;
|
||||
}
|
||||
// check that we have a source image resource
|
||||
if ($source !== null) {
|
||||
if ($source !== null && $source !== false) {
|
||||
// resize no shift
|
||||
if ($high_quality === true) {
|
||||
imagecopyresized(
|
||||
@@ -356,10 +364,16 @@ class Image
|
||||
$thumb_width = 250;
|
||||
}
|
||||
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
||||
if ($thumb === false) {
|
||||
return false;
|
||||
}
|
||||
// add outside border px = 5% (rounded up)
|
||||
// eg 50px -> 2.5px
|
||||
$gray = imagecolorallocate($thumb, 200, 200, 200);
|
||||
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||
if ($gray === false || $white === false) {
|
||||
return false;
|
||||
}
|
||||
// fill gray background
|
||||
imagefill($thumb, 0, 0, $gray);
|
||||
// now create rectangle
|
||||
@@ -407,55 +421,66 @@ class Image
|
||||
*/
|
||||
public static function correctImageOrientation($filename): void
|
||||
{
|
||||
if (function_exists('exif_read_data') && is_writeable($filename)) {
|
||||
list($inc_width, $inc_height, $img_type) = getimagesize($filename);
|
||||
// add @ to avoid "file not supported error"
|
||||
$exif = @exif_read_data($filename);
|
||||
$orientation = null;
|
||||
$img = null;
|
||||
if ($exif && isset($exif['Orientation'])) {
|
||||
$orientation = $exif['Orientation'];
|
||||
}
|
||||
if ($orientation != 1) {
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$img = imagecreatefromjpeg($filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$img = imagecreatefrompng($filename);
|
||||
break;
|
||||
}
|
||||
$deg = 0;
|
||||
// 1 top, 6: left, 8: right, 3: bottom
|
||||
switch ($orientation) {
|
||||
case 3:
|
||||
$deg = 180;
|
||||
break;
|
||||
case 6:
|
||||
$deg = -90;
|
||||
break;
|
||||
case 8:
|
||||
$deg = 90;
|
||||
break;
|
||||
}
|
||||
if ($img !== null) {
|
||||
if ($deg) {
|
||||
$img = imagerotate($img, $deg, 0);
|
||||
}
|
||||
// then rewrite the rotated image back to the disk as $filename
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($img, $filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($img, $filename);
|
||||
break;
|
||||
}
|
||||
// clean up image if we have an image
|
||||
imagedestroy($img);
|
||||
}
|
||||
} // only if we need to rotate
|
||||
} // function exists & file is writeable, else do nothing
|
||||
// function exists & file is writeable, else do nothing
|
||||
if (!function_exists('exif_read_data') || !is_writeable($filename)) {
|
||||
return;
|
||||
}
|
||||
[$inc_width, $inc_height, $img_type] = getimagesize($filename) ?: [];
|
||||
// add @ to avoid "file not supported error"
|
||||
$exif = @exif_read_data($filename);
|
||||
$orientation = null;
|
||||
$img = null;
|
||||
if ($exif && isset($exif['Orientation'])) {
|
||||
$orientation = $exif['Orientation'];
|
||||
}
|
||||
// only if we need to rotate, if 1 it is already upright
|
||||
if ($orientation === null || $orientation == 1) {
|
||||
return;
|
||||
}
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
$img = imagecreatefromjpeg($filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
$img = imagecreatefrompng($filename);
|
||||
break;
|
||||
}
|
||||
// no image loaded (wrong type)
|
||||
if ($img === null || $img === false) {
|
||||
return;
|
||||
}
|
||||
$deg = 0;
|
||||
// 1 top, 6: left, 8: right, 3: bottom
|
||||
switch ($orientation) {
|
||||
case 3:
|
||||
$deg = 180;
|
||||
break;
|
||||
case 6:
|
||||
$deg = -90;
|
||||
break;
|
||||
case 8:
|
||||
$deg = 90;
|
||||
break;
|
||||
}
|
||||
// rotate if needed
|
||||
if ($deg) {
|
||||
$img = imagerotate($img, $deg, 0);
|
||||
}
|
||||
// rotate failed
|
||||
if ($img === false) {
|
||||
return;
|
||||
}
|
||||
// then rewrite the rotated image back to the disk as $filename
|
||||
switch ($img_type) {
|
||||
case IMAGETYPE_JPEG:
|
||||
imagejpeg($img, $filename);
|
||||
break;
|
||||
case IMAGETYPE_PNG:
|
||||
imagepng($img, $filename);
|
||||
break;
|
||||
}
|
||||
// clean up image if we have an image
|
||||
imagedestroy($img);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,13 @@ class ProgressBar
|
||||
{
|
||||
// private vars
|
||||
|
||||
/** @var string */
|
||||
public $code; // unique code
|
||||
/** @var string */
|
||||
public $status = 'new'; // current status (new,show,hide)
|
||||
/** @var float|int */
|
||||
public $step = 0; // current step
|
||||
/** @var array<string,null|int|float> */
|
||||
public $position = [ // current bar position
|
||||
'left' => null,
|
||||
'top' => null,
|
||||
@@ -32,27 +36,43 @@ class ProgressBar
|
||||
'height' => null,
|
||||
];
|
||||
|
||||
/** @var int */
|
||||
public $clear_buffer_size = 1; // we need to send this before the lfush to get browser output
|
||||
/** @var int */
|
||||
public $clear_buffer_size_init = 1024 * 1024; // if I don't send that junk, it won't send anything
|
||||
|
||||
// public vars
|
||||
|
||||
/** @var int */
|
||||
public $min = 0; // minimal steps
|
||||
/** @var int */
|
||||
public $max = 100; // maximal steps
|
||||
|
||||
/** @var int */
|
||||
public $left = 5; // bar position from left
|
||||
/** @var int */
|
||||
public $top = 5; // bar position from top
|
||||
/** @var int */
|
||||
public $width = 300; // bar width
|
||||
/** @var int */
|
||||
public $height = 25; // bar height
|
||||
/** @var int */
|
||||
public $pedding = 0; // bar pedding
|
||||
/** @var string */
|
||||
public $color = '#0033ff'; // bar color
|
||||
/** @var string */
|
||||
public $bgr_color = '#c0c0c0'; // bar background color
|
||||
/** @var string */
|
||||
public $bgr_color_master = '#ffffff'; // master div background color
|
||||
/** @var int */
|
||||
public $border = 1; // bar border width
|
||||
/** @var string */
|
||||
public $brd_color = '#000000'; // bar border color
|
||||
|
||||
/** @var string */
|
||||
public $direction = 'right'; // direction of motion (right,left,up,down)
|
||||
|
||||
/** @var array<string,string|bool|int> */
|
||||
public $frame = ['show' => false]; // ProgressBar Frame
|
||||
/* 'show' => false, # frame show (true/false)
|
||||
'left' => 200, # frame position from left
|
||||
@@ -64,6 +84,8 @@ class ProgressBar
|
||||
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf' # frame border color
|
||||
*/
|
||||
|
||||
/** @#var array{string}{string: string|int} */
|
||||
/** @var mixed[][] */
|
||||
public $label = []; // ProgressBar Labels
|
||||
/* 'name' => [ # label name
|
||||
'type' => 'text', # label type (text,button,step,percent,crossbar)
|
||||
@@ -81,6 +103,7 @@ class ProgressBar
|
||||
]
|
||||
*/
|
||||
|
||||
/** @var string */
|
||||
// output strings
|
||||
public $prefix_message = '';
|
||||
|
||||
@@ -141,8 +164,8 @@ class ProgressBar
|
||||
|
||||
/**
|
||||
* calculate position in bar step
|
||||
* @param float $step percent step to do
|
||||
* @return array bar position as array
|
||||
* @param float $step percent step to do
|
||||
* @return array<string,int|float> bar position as array
|
||||
*/
|
||||
private function __calculatePosition(float $step): array
|
||||
{
|
||||
@@ -201,8 +224,8 @@ class ProgressBar
|
||||
|
||||
/**
|
||||
* set the step
|
||||
* @param float $step percent step to do
|
||||
* @return void has no return
|
||||
* @param float $step percent step to do
|
||||
* @return void
|
||||
*/
|
||||
private function __setStep(float $step): void
|
||||
{
|
||||
@@ -220,7 +243,7 @@ class ProgressBar
|
||||
* set frame layout
|
||||
* @param integer $width bar width
|
||||
* @param integer $height bar height
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setFrame(int $width = 0, int $height = 0): void
|
||||
{
|
||||
@@ -249,7 +272,7 @@ class ProgressBar
|
||||
* @param string $type label type
|
||||
* @param string $name label name (internal)
|
||||
* @param string $value label output name (optional)
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function addLabel(string $type, string $name, string $value = ' '): void
|
||||
{
|
||||
@@ -355,7 +378,7 @@ class ProgressBar
|
||||
* @param string $value button text (output)
|
||||
* @param string $action button action (link)
|
||||
* @param string $target button action target (default self)
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function addButton(string $name, string $value, string $action, string $target = 'self'): void
|
||||
{
|
||||
@@ -372,7 +395,7 @@ class ProgressBar
|
||||
* @param int $width width px
|
||||
* @param int $height height px
|
||||
* @param string $align alignment (left/right/etc), default empty
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelPosition(
|
||||
string $name,
|
||||
@@ -418,7 +441,7 @@ class ProgressBar
|
||||
* set label color
|
||||
* @param string $name label name to set
|
||||
* @param string $color color value in rgb html hex
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelColor(string $name, string $color): void
|
||||
{
|
||||
@@ -434,7 +457,7 @@ class ProgressBar
|
||||
* set the label background color
|
||||
* @param string $name label name to set
|
||||
* @param string $color background color to set in rgb html hex
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelBackground(string $name, string $color): void
|
||||
{
|
||||
@@ -452,7 +475,7 @@ class ProgressBar
|
||||
* @param int $size font size in px
|
||||
* @param string $family font family (default empty)
|
||||
* @param string $weight font weight (default empty)
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelFont(string $name, int $size, string $family = '', string $weight = ''): void
|
||||
{
|
||||
@@ -501,7 +524,7 @@ class ProgressBar
|
||||
* set the label valeu
|
||||
* @param string $name label name to set
|
||||
* @param string $value label value (output)
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setLabelValue(string $name, string $value): void
|
||||
{
|
||||
@@ -517,7 +540,7 @@ class ProgressBar
|
||||
/**
|
||||
* set the bar color
|
||||
* @param string $color color for the progress bar in rgb html hex
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setBarColor(string $color): void
|
||||
{
|
||||
@@ -532,7 +555,7 @@ class ProgressBar
|
||||
/**
|
||||
* set the progress bar background color
|
||||
* @param string $color background color in rgb html hex
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setBarBackground(string $color): void
|
||||
{
|
||||
@@ -547,7 +570,7 @@ class ProgressBar
|
||||
/**
|
||||
* progress bar direct (left/right)
|
||||
* @param string $direction set direction as left/right
|
||||
* @return void has no return
|
||||
* @return void
|
||||
*/
|
||||
public function setBarDirection(string $direction): void
|
||||
{
|
||||
|
||||
@@ -20,80 +20,140 @@ declare(strict_types=1);
|
||||
namespace CoreLibs\Template;
|
||||
|
||||
// I need to manually load Smarty BC here (it is not namespaced)
|
||||
require_once(BASE . LIB . SMARTY . 'SmartyBC.class.php');
|
||||
// require_once(BASE . LIB . SMARTY . 'SmartyBC.class.php');
|
||||
// we set this hard coded so it works with all checkers
|
||||
// HARD CODED path:
|
||||
// __DIR__: lib/CoreLibs/Template/
|
||||
// smarty located in lib/Smarty/
|
||||
require_once(__DIR__ . '/../../Smarty/SmartyBC.class.php');
|
||||
// So it doesn't start looking around in the wrong naemspace as smarty doesn't have one
|
||||
use SmartyBC;
|
||||
|
||||
class SmartyExtend extends SmartyBC
|
||||
{
|
||||
// internal translation engine
|
||||
/** @var \CoreLibs\Language\L10n */
|
||||
public $l10n;
|
||||
|
||||
// lang & encoding
|
||||
/** @var string */
|
||||
public $lang_dir = '';
|
||||
/** @var string */
|
||||
public $lang;
|
||||
/** @var string */
|
||||
public $lang_short;
|
||||
/** @var string */
|
||||
public $encoding;
|
||||
// page name
|
||||
/** @var string */
|
||||
public $page_name;
|
||||
|
||||
// array for data parsing
|
||||
/** @var array<mixed> */
|
||||
public $HEADER = [];
|
||||
/** @var array<mixed> */
|
||||
public $DATA = [];
|
||||
/** @var array<mixed> */
|
||||
public $DEBUG_DATA = [];
|
||||
/** @var array<mixed> */
|
||||
private $CONTENT_DATA = [];
|
||||
// control vars
|
||||
/** @var bool */
|
||||
public $USE_PROTOTYPE = USE_PROTOTYPE;
|
||||
/** @var bool */
|
||||
public $USE_JQUERY = USE_JQUERY;
|
||||
/** @var bool */
|
||||
public $USE_SCRIPTACULOUS = USE_SCRIPTACULOUS;
|
||||
// sub content input vars
|
||||
/** @var bool */
|
||||
public $USE_TINY_MCE = false;
|
||||
/** @var bool */
|
||||
public $JS_DATEPICKR = false;
|
||||
/** @var bool */
|
||||
public $JS_FLATPICKR = false;
|
||||
/** @var bool */
|
||||
public $JS_FILE_UPLOADER = false;
|
||||
/** @var bool */
|
||||
public $DEBUG_TMPL = false;
|
||||
/** @var bool */
|
||||
public $USE_INCLUDE_TEMPLATE = false;
|
||||
// cache & compile
|
||||
/** @var string */
|
||||
public $CACHE_ID = '';
|
||||
/** @var string */
|
||||
public $COMPILE_ID = '';
|
||||
// template vars
|
||||
/** @var string */
|
||||
public $MASTER_TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $PAGE_FILE_NAME;
|
||||
/** @var string */
|
||||
public $CONTENT_INCLUDE;
|
||||
/** @var string */
|
||||
public $FORM_NAME;
|
||||
/** @var string */
|
||||
public $FORM_ACTION;
|
||||
/** @var string */
|
||||
public $L_TITLE;
|
||||
/** @var string|int */
|
||||
public $PAGE_WIDTH;
|
||||
// smarty include/set var
|
||||
/** @var string */
|
||||
public $TEMPLATE_PATH;
|
||||
/** @var string */
|
||||
public $TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $INC_TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $JS_TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $CSS_TEMPLATE_NAME;
|
||||
/** @var string|null */
|
||||
public $TEMPLATE_TRANSLATE;
|
||||
// core group
|
||||
/** @var string */
|
||||
public $JS_CORE_TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $CSS_CORE_TEMPLATE_NAME;
|
||||
/** @var string */
|
||||
public $JS_CORE_INCLUDE;
|
||||
/** @var string */
|
||||
public $CSS_CORE_INCLUDE;
|
||||
// local names
|
||||
/** @var string */
|
||||
public $JS_SPECIAL_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public $CSS_SPECIAL_TEMPLATE_NAME = '';
|
||||
/** @var string */
|
||||
public $JS_INCLUDE;
|
||||
/** @var string */
|
||||
public $CSS_INCLUDE;
|
||||
/** @var string */
|
||||
public $JS_SPECIAL_INCLUDE;
|
||||
/** @var string */
|
||||
public $CSS_SPECIAL_INCLUDE;
|
||||
/** @var string */
|
||||
public $ADMIN_JAVASCRIPT;
|
||||
/** @var string */
|
||||
public $ADMIN_STYLESHEET;
|
||||
/** @var string */
|
||||
public $FRONTEND_JAVASCRIPT;
|
||||
/** @var string */
|
||||
public $FRONTEND_STYLESHEET;
|
||||
// other smarty folder vars
|
||||
/** @var string */
|
||||
public $INCLUDES;
|
||||
/** @var string */
|
||||
public $JAVASCRIPT;
|
||||
/** @var string */
|
||||
public $CSS;
|
||||
/** @var string */
|
||||
public $FONT;
|
||||
/** @var string */
|
||||
public $PICTURES;
|
||||
/** @var string */
|
||||
public $CACHE_PICTURES;
|
||||
/** @var string */
|
||||
public $CACHE_PICTURES_ROOT;
|
||||
|
||||
// constructor class, just sets the language stuff
|
||||
@@ -112,6 +172,7 @@ class SmartyExtend extends SmartyBC
|
||||
$this->l10n = new \CoreLibs\Language\L10n($this->lang);
|
||||
// variable variable register
|
||||
// $this->register_modifier('getvar', [&$this, 'get_template_vars']);
|
||||
/** @phpstan-ignore-next-line */
|
||||
$this->registerPlugin('modifier', 'getvar', [&$this, 'get_template_vars']);
|
||||
|
||||
$this->page_name = pathinfo($_SERVER["PHP_SELF"])['basename'];
|
||||
@@ -219,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
|
||||
@@ -323,6 +384,7 @@ class SmartyExtend extends SmartyBC
|
||||
*/
|
||||
private function setSmartyVars($admin_call = false): void
|
||||
{
|
||||
/** @var \CoreLibs\Admin\Backend This is an assumption */
|
||||
global $cms;
|
||||
if (is_object($cms)) {
|
||||
$this->mergeCmsSmartyVars($cms);
|
||||
@@ -361,6 +423,11 @@ class SmartyExtend extends SmartyBC
|
||||
$this->HEADER['ENCODING'] = $this->encoding;
|
||||
$this->HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||
|
||||
// form name
|
||||
$this->DATA['FORM_NAME'] = !$this->FORM_NAME ?
|
||||
str_replace('.php', '', $this->page_name) :
|
||||
$this->FORM_NAME;
|
||||
$this->DATA['FORM_ACTION'] = $this->FORM_ACTION;
|
||||
// special for admin
|
||||
if ($admin_call === true) {
|
||||
// set ACL extra show
|
||||
@@ -368,11 +435,11 @@ 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 ?? [];
|
||||
} else {
|
||||
$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;
|
||||
$this->DATA['nav_menu'] = [];
|
||||
@@ -384,7 +451,8 @@ 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;
|
||||
// include flags
|
||||
@@ -404,11 +472,6 @@ class SmartyExtend extends SmartyBC
|
||||
|
||||
// LANG
|
||||
$this->DATA['LANG'] = $this->lang;
|
||||
// form name
|
||||
$this->DATA['FORM_NAME'] = !$this->FORM_NAME ?
|
||||
str_replace('.php', '', $this->page_name) :
|
||||
$this->FORM_NAME;
|
||||
$this->DATA['FORM_ACTION'] = $this->FORM_ACTION;
|
||||
// include flags
|
||||
$this->DATA['JS_DATEPICKR'] = $this->JS_DATEPICKR;
|
||||
$this->DATA['JS_FLATPICKR'] = $this->JS_FLATPICKR;
|
||||
|
||||
@@ -1,38 +1,33 @@
|
||||
<?php
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens Schwaighofer
|
||||
* CREATED: 2011/2/8
|
||||
* DESCRIPTION: pre function to collect all non critical errors into a log file if possible
|
||||
* include this file at the very beginning of the script to get the notices, strict, etc messages.
|
||||
* DESCRIPTION: pre function to collect all non critical errors
|
||||
* into a log file if possible
|
||||
* include this file at the very beginning of the script to get the notices,
|
||||
* strict, etc messages.
|
||||
* error etc will still be written to the log/display
|
||||
*********************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// define the base working directory outside because in the function it might return undefined
|
||||
// if we have config set BASE use this
|
||||
if (defined('BASE')) {
|
||||
DEFINE('CURRENT_WORKING_DIR', BASE);
|
||||
} else {
|
||||
// else we set. We fully assuem that Error.Handling is where it should be, in lib dir
|
||||
DEFINE('CURRENT_WORKING_DIR', str_replace('lib', '', __DIR__));
|
||||
}
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* will catch any error except E_ERROR and try to write them to the log file
|
||||
* in log/php_error-<DAY>.log
|
||||
* if this fails, it will print the data to the window via echo
|
||||
* @param int $type the error code from PHP
|
||||
* @param string $message the error message from php
|
||||
* @param string $file in which file the error happend. this is the source file (eg include)
|
||||
* @param int $line in which line the error happened
|
||||
* @param array $context array with all the variable
|
||||
* @return bool true, so cought errors do not get processed by the PHP error engine
|
||||
* @param int $type the error code from PHP
|
||||
* @param string $message the error message from php
|
||||
* @param string $file in which file the error happend.
|
||||
* this is the source file (eg include)
|
||||
* @param int $line in which line the error happened
|
||||
* @param array<mixed> $context array with all the variable
|
||||
* @return bool True, so cought errors do not get processed
|
||||
* by the PHP error engine
|
||||
*/
|
||||
function MyErrorHandler(int $type, string $message, string $file, int $line, array $context): bool
|
||||
{
|
||||
if (!(error_reporting() & $type) && !SHOW_ALL_ERRORS) {
|
||||
if (!(error_reporting() & $type) && SHOW_ALL_ERRORS == false) {
|
||||
// This error code is not included in error_reporting
|
||||
return false;
|
||||
}
|
||||
@@ -67,8 +62,15 @@ function MyErrorHandler(int $type, string $message, string $file, int $line, arr
|
||||
// : the php error message
|
||||
$output = '{' . array_pop($page_temp) . '} [' . $file . '] '
|
||||
. '<' . $line . '> [' . $error_level[$type] . '|' . $type . ']: ' . $message;
|
||||
# try to open file
|
||||
$ROOT = CURRENT_WORKING_DIR;
|
||||
// define the base working directory outside because in the function it might return undefined
|
||||
// if we have config set BASE use this
|
||||
$ROOT = '';
|
||||
if (defined('BASE')) {
|
||||
$ROOT = BASE;
|
||||
} else {
|
||||
// else we set. We fully assuem that Error.Handling is where it should be, in lib dir
|
||||
$ROOT = str_replace('lib', '', __DIR__);
|
||||
}
|
||||
$LOG = 'log' . DIRECTORY_SEPARATOR;
|
||||
// if the log folder is not found, try to create it
|
||||
if (!is_dir($ROOT . $LOG) && !is_file($ROOT . LOG)) {
|
||||
|
||||
32
www/lib/FileUpload/Core/qqUploadedFile.php
Normal file
32
www/lib/FileUpload/Core/qqUploadedFile.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace FileUpload\Core;
|
||||
|
||||
interface qqUploadedFile // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
*
|
||||
* @param string $path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
public function save(string $path): bool;
|
||||
|
||||
/**
|
||||
* get qqfile name from _GET array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string;
|
||||
|
||||
/**
|
||||
* Get file size from _SERVERa array, throws an error if not possible
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getSize(): int;
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -5,26 +5,40 @@ namespace FileUpload\Core;
|
||||
/**
|
||||
* Handle file uploads via regular form post (uses the $_FILES array)
|
||||
*/
|
||||
class qqUploadedFileForm
|
||||
class qqUploadedFileForm implements qqUploadedFile // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
*
|
||||
* @param string $path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
public function save($path)
|
||||
public function save(string $path): bool
|
||||
{
|
||||
if (!move_uploaded_file($_FILES['qqfile']['tmp_name'], $path)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public function getName()
|
||||
|
||||
/**
|
||||
* get qqfile name from _FILES array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $_FILES['qqfile']['name'];
|
||||
return (string)$_FILES['qqfile']['name'];
|
||||
}
|
||||
public function getSize()
|
||||
|
||||
/**
|
||||
* get files size from _FILES array
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSize(): int
|
||||
{
|
||||
return $_FILES['qqfile']['size'];
|
||||
return (int)$_FILES['qqfile']['size'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,22 @@ namespace FileUpload\Core;
|
||||
/**
|
||||
* Handle file uploads via XMLHttpRequest
|
||||
*/
|
||||
class qqUploadedFileXhr
|
||||
class qqUploadedFileXhr implements qqUploadedFile // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
{
|
||||
/**
|
||||
* Save the file to the specified path
|
||||
*
|
||||
* @param string $path
|
||||
* @return boolean TRUE on success
|
||||
*/
|
||||
public function save($path)
|
||||
public function save(string $path): bool
|
||||
{
|
||||
$input = fopen("php://input", "r");
|
||||
$temp = tmpfile();
|
||||
// abort if not resources
|
||||
if (!is_resource($input) || !is_resource($temp)) {
|
||||
return false;
|
||||
}
|
||||
$realSize = stream_copy_to_stream($input, $temp);
|
||||
fclose($input);
|
||||
|
||||
@@ -23,17 +29,34 @@ class qqUploadedFileXhr
|
||||
}
|
||||
|
||||
$target = fopen($path, "w");
|
||||
if (!is_resource($target)) {
|
||||
return false;
|
||||
}
|
||||
fseek($temp, 0, SEEK_SET);
|
||||
stream_copy_to_stream($temp, $target);
|
||||
fclose($target);
|
||||
|
||||
return true;
|
||||
}
|
||||
public function getName()
|
||||
|
||||
/**
|
||||
* get qqfile name from _GET array
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $_GET['qqfile'];
|
||||
return $_GET['qqfile'] ?? '';
|
||||
}
|
||||
public function getSize()
|
||||
|
||||
/**
|
||||
* Get file size from _SERVERa array, throws an error if not possible
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getSize(): int
|
||||
{
|
||||
if (isset($_SERVER['CONTENT_LENGTH'])) {
|
||||
return (int)$_SERVER['CONTENT_LENGTH'];
|
||||
|
||||
@@ -2,19 +2,31 @@
|
||||
|
||||
namespace FileUpload;
|
||||
|
||||
// use \FileUpload\Core;
|
||||
use FileUpload\Core;
|
||||
|
||||
class qqFileUploader
|
||||
// TODO: find all usages from qqFileUploader and name to Qq
|
||||
class qqFileUploader // phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
{
|
||||
private $allowedExtensions = array();
|
||||
/** @var array<mixed> */
|
||||
private $allowedExtensions = [];
|
||||
/** @var int */
|
||||
private $sizeLimit = 10485760;
|
||||
/** @var null|Core\qqUploadedFileXhr|Core\qqUploadedFileForm */
|
||||
private $file;
|
||||
/** @var string */
|
||||
public $uploadFileName;
|
||||
/** @var string */
|
||||
public $uploadFileExt;
|
||||
|
||||
public function __construct(array $allowedExtensions = array(), $sizeLimit = 10485760)
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param array<string> $allowedExtensions
|
||||
* @param integer $sizeLimit
|
||||
*/
|
||||
public function __construct(array $allowedExtensions = [], int $sizeLimit = 10485760)
|
||||
{
|
||||
$allowedExtensions = array_map("strtolower", $allowedExtensions);
|
||||
$allowedExtensions = array_map('strtolower', $allowedExtensions);
|
||||
|
||||
$this->allowedExtensions = $allowedExtensions;
|
||||
$this->sizeLimit = $sizeLimit;
|
||||
@@ -22,18 +34,23 @@ class qqFileUploader
|
||||
$this->checkServerSettings();
|
||||
|
||||
if (isset($_GET['qqfile'])) {
|
||||
$this->file = new \FileUpload\Core\qqUploadedFileXhr();
|
||||
$this->file = new Core\qqUploadedFileXhr();
|
||||
} elseif (isset($_FILES['qqfile'])) {
|
||||
$this->file = new \FileUpload\Core\qqUploadedFileForm();
|
||||
$this->file = new Core\qqUploadedFileForm();
|
||||
} else {
|
||||
$this->file = false;
|
||||
$this->file = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function checkServerSettings()
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function checkServerSettings(): void
|
||||
{
|
||||
$postSize = $this->toBytes(ini_get('post_max_size'));
|
||||
$uploadSize = $this->toBytes(ini_get('upload_max_filesize'));
|
||||
$postSize = $this->toBytes(ini_get('post_max_size') ?: '');
|
||||
$uploadSize = $this->toBytes(ini_get('upload_max_filesize') ?: '');
|
||||
|
||||
if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) {
|
||||
$size = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
|
||||
@@ -41,10 +58,16 @@ class qqFileUploader
|
||||
}
|
||||
}
|
||||
|
||||
private function toBytes($str)
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $str
|
||||
* @return integer
|
||||
*/
|
||||
private function toBytes(string $str): int
|
||||
{
|
||||
$val = (int)trim($str);
|
||||
$last = strtolower($str[strlen($str)-1]);
|
||||
$last = strtolower($str[strlen($str) - 1]);
|
||||
switch ($last) {
|
||||
case 'g':
|
||||
$val *= 1024;
|
||||
@@ -59,26 +82,32 @@ class qqFileUploader
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array('success'=>true) or array('error'=>'error message')
|
||||
* Undocumented function
|
||||
*
|
||||
* @param string $uploadDirectory
|
||||
* @param boolean $replaceOldFile
|
||||
* @return array<string,string|bool> Returns ['success'=>true] or
|
||||
* ['error'=>'error message']
|
||||
*/
|
||||
public function handleUpload($uploadDirectory, $replaceOldFile = false)
|
||||
public function handleUpload(string $uploadDirectory, bool $replaceOldFile = false): array
|
||||
{
|
||||
if (!is_writable($uploadDirectory)) {
|
||||
return array('error' => "Server error. Upload directory isn't writable.");
|
||||
return ['error' => "Server error. Upload directory isn't writable."];
|
||||
}
|
||||
|
||||
if (!$this->file) {
|
||||
return array('error' => 'No files were uploaded.');
|
||||
if (!is_object($this->file)) {
|
||||
return ['error' => 'No files were uploaded.'];
|
||||
}
|
||||
|
||||
$size = 0;
|
||||
$size = $this->file->getSize();
|
||||
|
||||
if ($size == 0) {
|
||||
return array('error' => 'File is empty');
|
||||
return ['error' => 'File is empty'];
|
||||
}
|
||||
|
||||
if ($size > $this->sizeLimit) {
|
||||
return array('error' => 'File is too large');
|
||||
return ['error' => 'File is too large'];
|
||||
}
|
||||
|
||||
$pathinfo = pathinfo($this->file->getName());
|
||||
@@ -88,7 +117,7 @@ class qqFileUploader
|
||||
|
||||
if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) {
|
||||
$these = implode(', ', $this->allowedExtensions);
|
||||
return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
|
||||
return ['error' => 'File has an invalid extension, it should be one of ' . $these . '.'];
|
||||
}
|
||||
|
||||
if (!$replaceOldFile) {
|
||||
@@ -102,10 +131,12 @@ class qqFileUploader
|
||||
$this->uploadFileExt = $ext;
|
||||
|
||||
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
|
||||
return array('success' => true);
|
||||
return ['success' => true];
|
||||
} else {
|
||||
return array('error' => 'Could not save uploaded file.' .
|
||||
'The upload was cancelled, or server error encountered');
|
||||
return [
|
||||
'error' => 'Could not save uploaded file.' .
|
||||
'The upload was cancelled, or server error encountered'
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
58
www/lib/Test/DB/TestDB.php
Normal file
58
www/lib/Test/DB/TestDB.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* TEST sets for DB::IO
|
||||
*/
|
||||
|
||||
namespace Test\DB;
|
||||
|
||||
use CoreLibs\DB\IO;
|
||||
|
||||
class TestDB
|
||||
{
|
||||
/** @var IO */
|
||||
private $db;
|
||||
/** @var array<mixed> */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = [
|
||||
'db_name' => $_ENV['DB_NAME_TEST'] ?? '',
|
||||
'db_user' => $_ENV['DB_USER_TEST'] ?? '',
|
||||
'db_pass' => $_ENV['DB_PASS_TEST'] ?? '',
|
||||
'db_host' => $_ENV['DB_HOST_TEST'] ?? '',
|
||||
'db_port' => 5432,
|
||||
'db_schema' => 'public',
|
||||
'db_type' => 'pgsql',
|
||||
'db_encoding' => '',
|
||||
'db_ssl' => 'allow'
|
||||
];
|
||||
$this->db = new IO($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function testDBa(): void
|
||||
{
|
||||
$this->db->dbInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRunDB(): void
|
||||
{
|
||||
$this->testDBa();
|
||||
}
|
||||
}
|
||||
|
||||
// __ENB__
|
||||
86
www/lib/Test/Test.php
Normal file
86
www/lib/Test/Test.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* TEST sets only
|
||||
*
|
||||
* composer.json
|
||||
* autoloader: {
|
||||
* ...
|
||||
* "psr-4": {
|
||||
* "gullevek\\CoreLibs\\": "src/"
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Test;
|
||||
|
||||
use Test\DB;
|
||||
|
||||
class Test
|
||||
{
|
||||
/** @var DB\TestDB */
|
||||
private $test_db;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// calls all tests
|
||||
$this->testPrivate();
|
||||
$this->testProtected();
|
||||
$this->testPublic();
|
||||
|
||||
// call intern
|
||||
$this->test_db = new DB\TestDB();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
// calls all close tests
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function testPrivate(): string
|
||||
{
|
||||
$string = 'TEST Private';
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function testProtected(): string
|
||||
{
|
||||
$string = 'TEST Protected';
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function testPublic(): string
|
||||
{
|
||||
$string = 'TEST Public';
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testClasses(): void
|
||||
{
|
||||
$this->test_db->testRunDB();
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
@@ -10,21 +10,26 @@ if (class_exists('Autoload', false) === false) {
|
||||
// define the auto loader class
|
||||
class Autoload
|
||||
{
|
||||
// we do it simple here
|
||||
// passes on the class to load and we search here in namespace
|
||||
// to load that class
|
||||
public static function load($class)
|
||||
/**
|
||||
* we do it simple here
|
||||
* passes on the class to load and we search here in namespace
|
||||
* to load that class
|
||||
*
|
||||
* @param string $class Namespace + class to load
|
||||
* @return void
|
||||
*/
|
||||
public static function load(string $class)
|
||||
{
|
||||
// print "(1) Class: $class / DIR: ".__DIR__."<br>";
|
||||
// set directory seperator (we need to replace from namespace)
|
||||
$DS = defined('DS') ? DS : DIRECTORY_SEPARATOR;
|
||||
$DS = DIRECTORY_SEPARATOR;
|
||||
// base lib
|
||||
$LIB = defined('LIB') ? LIB : 'lib' . $DS;
|
||||
// if lib is in path at the end, do not add lib again
|
||||
// note that $LIB can have a directory seperator at the end
|
||||
// strip that out before we do a match
|
||||
$_LIB = rtrim($LIB, $DS);
|
||||
if (preg_match("|$_LIB$|", __DIR__) === false) {
|
||||
if (!preg_match("|$_LIB$|", __DIR__)) {
|
||||
$LIB .= $DS;
|
||||
} else {
|
||||
$LIB = '';
|
||||
@@ -50,9 +55,7 @@ if (class_exists('Autoload', false) === false) {
|
||||
// we should sub that
|
||||
// self::loadFile($path);
|
||||
include $path;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// end class define
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
pChart2.1.4/
|
||||
@@ -1,184 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pBarcode128 - class to create barcodes (128B)
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
/* pData class definition */
|
||||
class pBarcode128
|
||||
{
|
||||
var $Codes;
|
||||
var $Reverse;
|
||||
var $Result;
|
||||
var $pChartObject;
|
||||
var $CRC;
|
||||
|
||||
/* Class creator */
|
||||
function pBarcode128($BasePath="")
|
||||
{
|
||||
$this->Codes = "";
|
||||
$this->Reverse = "";
|
||||
|
||||
$FileHandle = @fopen($BasePath."data/128B.db", "r");
|
||||
|
||||
if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."128B.db)."); }
|
||||
|
||||
while (!feof($FileHandle))
|
||||
{
|
||||
$Buffer = fgets($FileHandle,4096);
|
||||
$Buffer = str_replace(chr(10),"",$Buffer);
|
||||
$Buffer = str_replace(chr(13),"",$Buffer);
|
||||
$Values = preg_split("/;/",$Buffer);
|
||||
|
||||
$this->Codes[$Values[1]]["ID"] = $Values[0];
|
||||
$this->Codes[$Values[1]]["Code"] = $Values[2];
|
||||
$this->Reverse[$Values[0]]["Code"] = $Values[2];
|
||||
$this->Reverse[$Values[0]]["Asc"] = $Values[1];
|
||||
}
|
||||
fclose($FileHandle);
|
||||
}
|
||||
|
||||
/* Return the projected size of a barcode */
|
||||
function getSize($TextString,$Format="")
|
||||
{
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
|
||||
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
|
||||
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
|
||||
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
|
||||
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
|
||||
|
||||
$TextString = $this->encode128($TextString);
|
||||
$BarcodeLength = strlen($this->Result);
|
||||
|
||||
if ( $DrawArea ) { $WOffset = 20; } else { $WOffset = 0; }
|
||||
if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
|
||||
|
||||
$X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
|
||||
$Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
|
||||
|
||||
$X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
|
||||
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
|
||||
|
||||
|
||||
$AreaWidth = max(abs($X1),abs($X2));
|
||||
$AreaHeight = max(abs($Y1),abs($Y2));
|
||||
|
||||
return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
|
||||
}
|
||||
|
||||
function encode128($Value,$Format="")
|
||||
{
|
||||
$this->Result = "11010010000";
|
||||
$this->CRC = 104;
|
||||
$TextString = "";
|
||||
|
||||
for($i=1;$i<=strlen($Value);$i++)
|
||||
{
|
||||
$CharCode = ord($this->mid($Value,$i,1));
|
||||
if ( isset($this->Codes[$CharCode]) )
|
||||
{
|
||||
$this->Result = $this->Result.$this->Codes[$CharCode]["Code"];
|
||||
$this->CRC = $this->CRC + $i*$this->Codes[$CharCode]["ID"];
|
||||
$TextString = $TextString.chr($CharCode);
|
||||
}
|
||||
}
|
||||
$this->CRC = $this->CRC - floor($this->CRC/103)*103;
|
||||
|
||||
$this->Result = $this->Result.$this->Reverse[$this->CRC]["Code"];
|
||||
$this->Result = $this->Result."1100011101011";
|
||||
|
||||
return($TextString);
|
||||
}
|
||||
|
||||
/* Create the encoded string */
|
||||
function draw($Object,$Value,$X,$Y,$Format="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
|
||||
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
|
||||
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
|
||||
$AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
|
||||
$AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
|
||||
$AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
|
||||
$AreaBorderR = isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
|
||||
$AreaBorderG = isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
|
||||
$AreaBorderB = isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
|
||||
|
||||
$TextString = $this->encode128($Value);
|
||||
|
||||
if ( $DrawArea )
|
||||
{
|
||||
$X1 = $X + cos(($Angle-135) * PI / 180) * 10;
|
||||
$Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
|
||||
|
||||
$X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
|
||||
$Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
|
||||
|
||||
if ( $ShowLegend )
|
||||
{
|
||||
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
|
||||
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
|
||||
}
|
||||
else
|
||||
{
|
||||
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
|
||||
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
|
||||
}
|
||||
|
||||
$X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
|
||||
$Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
|
||||
|
||||
$Polygon = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
|
||||
$Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
|
||||
$this->pChartObject->drawPolygon($Polygon,$Settings);
|
||||
}
|
||||
|
||||
for($i=1;$i<=strlen($this->Result);$i++)
|
||||
{
|
||||
if ( $this->mid($this->Result,$i,1) == 1 )
|
||||
{
|
||||
$X1 = $X + cos($Angle * PI / 180) * $i;
|
||||
$Y1 = $Y + sin($Angle * PI / 180) * $i;
|
||||
$X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
|
||||
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
|
||||
|
||||
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ShowLegend )
|
||||
{
|
||||
$X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
|
||||
$Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
|
||||
|
||||
$LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
|
||||
$LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
|
||||
|
||||
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
|
||||
$this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
function left($value,$NbChar) { return substr($value,0,$NbChar); }
|
||||
function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }
|
||||
function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }
|
||||
}
|
||||
?>
|
||||
@@ -1,200 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pBarcode39 - class to create barcodes (39B)
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
/* pData class definition */
|
||||
class pBarcode39
|
||||
{
|
||||
var $Codes;
|
||||
var $Reverse;
|
||||
var $Result;
|
||||
var $pChartObject;
|
||||
var $CRC;
|
||||
var $MOD43;
|
||||
|
||||
/* Class creator */
|
||||
function pBarcode39($BasePath="",$EnableMOD43=FALSE)
|
||||
{
|
||||
$this->MOD43 = $EnableMOD43;
|
||||
$this->Codes = "";
|
||||
$this->Reverse = "";
|
||||
|
||||
$FileHandle = @fopen($BasePath."data/39.db", "r");
|
||||
|
||||
if (!$FileHandle) { die("Cannot find barcode database (".$BasePath."data/39.db)."); }
|
||||
|
||||
while (!feof($FileHandle))
|
||||
{
|
||||
$Buffer = fgets($FileHandle,4096);
|
||||
$Buffer = str_replace(chr(10),"",$Buffer);
|
||||
$Buffer = str_replace(chr(13),"",$Buffer);
|
||||
$Values = preg_split("/;/",$Buffer);
|
||||
|
||||
$this->Codes[$Values[0]] = $Values[1];
|
||||
}
|
||||
fclose($FileHandle);
|
||||
}
|
||||
|
||||
/* Return the projected size of a barcode */
|
||||
function getSize($TextString,$Format="")
|
||||
{
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
|
||||
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
|
||||
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
|
||||
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : 12;
|
||||
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
|
||||
|
||||
$TextString = $this->encode39($TextString);
|
||||
$BarcodeLength = strlen($this->Result);
|
||||
|
||||
if ( $DrawArea ) { $WOffset = 20; } else { $WOffset = 0; }
|
||||
if ( $ShowLegend ) { $HOffset = $FontSize+$LegendOffset+$WOffset; } else { $HOffset = 0; }
|
||||
|
||||
$X1 = cos($Angle * PI / 180) * ($WOffset+$BarcodeLength);
|
||||
$Y1 = sin($Angle * PI / 180) * ($WOffset+$BarcodeLength);
|
||||
|
||||
$X2 = $X1 + cos(($Angle+90) * PI / 180) * ($HOffset+$Height);
|
||||
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * ($HOffset+$Height);
|
||||
|
||||
|
||||
$AreaWidth = max(abs($X1),abs($X2));
|
||||
$AreaHeight = max(abs($Y1),abs($Y2));
|
||||
|
||||
return(array("Width"=>$AreaWidth,"Height"=>$AreaHeight));
|
||||
}
|
||||
|
||||
/* Create the encoded string */
|
||||
function encode39($Value)
|
||||
{
|
||||
$this->Result = "100101101101"."0";
|
||||
$TextString = "";
|
||||
for($i=1;$i<=strlen($Value);$i++)
|
||||
{
|
||||
$CharCode = ord($this->mid($Value,$i,1));
|
||||
if ( $CharCode >= 97 && $CharCode <= 122 ) { $CharCode = $CharCode - 32; }
|
||||
|
||||
if ( isset($this->Codes[chr($CharCode)]) )
|
||||
{
|
||||
$this->Result = $this->Result.$this->Codes[chr($CharCode)]."0";
|
||||
$TextString = $TextString.chr($CharCode);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->MOD43 )
|
||||
{
|
||||
$Checksum = $this->checksum($TextString);
|
||||
$this->Result = $this->Result.$this->Codes[$Checksum]."0";
|
||||
}
|
||||
|
||||
$this->Result = $this->Result."100101101101";
|
||||
$TextString = "*".$TextString."*";
|
||||
|
||||
return($TextString);
|
||||
}
|
||||
|
||||
/* Create the encoded string */
|
||||
function draw($Object,$Value,$X,$Y,$Format="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
$Height = isset($Format["Height"]) ? $Format["Height"] : 30;
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$ShowLegend = isset($Format["ShowLegend"]) ? $Format["ShowLegend"] : FALSE;
|
||||
$LegendOffset = isset($Format["LegendOffset"]) ? $Format["LegendOffset"] : 5;
|
||||
$DrawArea = isset($Format["DrawArea"]) ? $Format["DrawArea"] : FALSE;
|
||||
$AreaR = isset($Format["AreaR"]) ? $Format["AreaR"] : 255;
|
||||
$AreaG = isset($Format["AreaG"]) ? $Format["AreaG"] : 255;
|
||||
$AreaB = isset($Format["AreaB"]) ? $Format["AreaB"] : 255;
|
||||
$AreaBorderR = isset($Format["AreaBorderR"]) ? $Format["AreaBorderR"] : $AreaR;
|
||||
$AreaBorderG = isset($Format["AreaBorderG"]) ? $Format["AreaBorderG"] : $AreaG;
|
||||
$AreaBorderB = isset($Format["AreaBorderB"]) ? $Format["AreaBorderB"] : $AreaB;
|
||||
|
||||
$TextString = $this->encode39($Value);
|
||||
|
||||
if ( $DrawArea )
|
||||
{
|
||||
$X1 = $X + cos(($Angle-135) * PI / 180) * 10;
|
||||
$Y1 = $Y + sin(($Angle-135) * PI / 180) * 10;
|
||||
|
||||
$X2 = $X1 + cos($Angle * PI / 180) * (strlen($this->Result)+20);
|
||||
$Y2 = $Y1 + sin($Angle * PI / 180) * (strlen($this->Result)+20);
|
||||
|
||||
if ( $ShowLegend )
|
||||
{
|
||||
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
|
||||
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset+$this->pChartObject->FontSize+10);
|
||||
}
|
||||
else
|
||||
{
|
||||
$X3 = $X2 + cos(($Angle+90) * PI / 180) * ($Height+20);
|
||||
$Y3 = $Y2 + sin(($Angle+90) * PI / 180) * ($Height+20);
|
||||
}
|
||||
|
||||
$X4 = $X3 + cos(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
|
||||
$Y4 = $Y3 + sin(($Angle+180) * PI / 180) * (strlen($this->Result)+20);
|
||||
|
||||
$Polygon = array($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4);
|
||||
$Settings = array("R"=>$AreaR,"G"=>$AreaG,"B"=>$AreaB,"BorderR"=>$AreaBorderR,"BorderG"=>$AreaBorderG,"BorderB"=>$AreaBorderB);
|
||||
$this->pChartObject->drawPolygon($Polygon,$Settings);
|
||||
}
|
||||
|
||||
for($i=1;$i<=strlen($this->Result);$i++)
|
||||
{
|
||||
if ( $this->mid($this->Result,$i,1) == 1 )
|
||||
{
|
||||
$X1 = $X + cos($Angle * PI / 180) * $i;
|
||||
$Y1 = $Y + sin($Angle * PI / 180) * $i;
|
||||
$X2 = $X1 + cos(($Angle+90) * PI / 180) * $Height;
|
||||
$Y2 = $Y1 + sin(($Angle+90) * PI / 180) * $Height;
|
||||
|
||||
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y2,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ShowLegend )
|
||||
{
|
||||
$X1 = $X + cos($Angle * PI / 180) * (strlen($this->Result)/2);
|
||||
$Y1 = $Y + sin($Angle * PI / 180) * (strlen($this->Result)/2);
|
||||
|
||||
$LegendX = $X1 + cos(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
|
||||
$LegendY = $Y1 + sin(($Angle+90) * PI / 180) * ($Height+$LegendOffset);
|
||||
|
||||
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Angle"=>-$Angle,"Align"=>TEXT_ALIGN_TOPMIDDLE);
|
||||
$this->pChartObject->drawText($LegendX,$LegendY,$TextString,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
function checksum( $string )
|
||||
{
|
||||
$checksum = 0;
|
||||
$length = strlen( $string );
|
||||
$charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
|
||||
|
||||
for( $i=0; $i < $length; ++$i )
|
||||
$checksum += strpos( $charset, $string[$i] );
|
||||
|
||||
return substr( $charset, ($checksum % 43), 1 );
|
||||
}
|
||||
|
||||
function left($value,$NbChar) { return substr($value,0,$NbChar); }
|
||||
function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }
|
||||
function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }
|
||||
}
|
||||
?>
|
||||
@@ -1,326 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pBubble - class to draw bubble charts
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("BUBBLE_SHAPE_ROUND" , 700001);
|
||||
define("BUBBLE_SHAPE_SQUARE" , 700002);
|
||||
|
||||
/* pBubble class definition */
|
||||
class pBubble
|
||||
{
|
||||
var $pChartObject;
|
||||
var $pDataObject;
|
||||
|
||||
/* Class creator */
|
||||
function pBubble($pChartObject,$pDataObject)
|
||||
{
|
||||
$this->pChartObject = $pChartObject;
|
||||
$this->pDataObject = $pDataObject;
|
||||
}
|
||||
|
||||
/* Prepare the scale */
|
||||
function bubbleScale($DataSeries,$WeightSeries)
|
||||
{
|
||||
if ( !is_array($DataSeries) ) { $DataSeries = array($DataSeries); }
|
||||
if ( !is_array($WeightSeries) ) { $WeightSeries = array($WeightSeries); }
|
||||
|
||||
/* Parse each data series to find the new min & max boundaries to scale */
|
||||
$NewPositiveSerie = ""; $NewNegativeSerie = ""; $MaxValues = 0; $LastPositive = 0; $LastNegative = 0;
|
||||
foreach($DataSeries as $Key => $SerieName)
|
||||
{
|
||||
$SerieWeightName = $WeightSeries[$Key];
|
||||
|
||||
$this->pDataObject->setSerieDrawable($SerieWeightName,FALSE);
|
||||
|
||||
if ( count($this->pDataObject->Data["Series"][$SerieName]["Data"]) > $MaxValues ) { $MaxValues = count($this->pDataObject->Data["Series"][$SerieName]["Data"]); }
|
||||
|
||||
foreach($this->pDataObject->Data["Series"][$SerieName]["Data"] as $Key => $Value)
|
||||
{
|
||||
if ( $Value >= 0 )
|
||||
{
|
||||
$BubbleBounds = $Value + $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
|
||||
|
||||
if ( !isset($NewPositiveSerie[$Key]) )
|
||||
{ $NewPositiveSerie[$Key] = $BubbleBounds; }
|
||||
elseif ( $NewPositiveSerie[$Key] < $BubbleBounds )
|
||||
{ $NewPositiveSerie[$Key] = $BubbleBounds; }
|
||||
|
||||
$LastPositive = $BubbleBounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
$BubbleBounds = $Value - $this->pDataObject->Data["Series"][$SerieWeightName]["Data"][$Key];
|
||||
|
||||
if ( !isset($NewNegativeSerie[$Key]) )
|
||||
{ $NewNegativeSerie[$Key] = $BubbleBounds; }
|
||||
elseif ( $NewNegativeSerie[$Key] > $BubbleBounds )
|
||||
{ $NewNegativeSerie[$Key] = $BubbleBounds; }
|
||||
|
||||
$LastNegative = $BubbleBounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for missing values and all the fake positive serie */
|
||||
if ( $NewPositiveSerie != "" )
|
||||
{
|
||||
for ($i=0; $i<$MaxValues; $i++) { if (!isset($NewPositiveSerie[$i])) { $NewPositiveSerie[$i] = $LastPositive; } }
|
||||
|
||||
$this->pDataObject->addPoints($NewPositiveSerie,"BubbleFakePositiveSerie");
|
||||
}
|
||||
|
||||
/* Check for missing values and all the fake negative serie */
|
||||
if ( $NewNegativeSerie != "" )
|
||||
{
|
||||
for ($i=0; $i<$MaxValues; $i++) { if (!isset($NewNegativeSerie[$i])) { $NewNegativeSerie[$i] = $LastNegative; } }
|
||||
|
||||
$this->pDataObject->addPoints($NewNegativeSerie,"BubbleFakeNegativeSerie");
|
||||
}
|
||||
}
|
||||
|
||||
function resetSeriesColors()
|
||||
{
|
||||
$Data = $this->pDataObject->getData();
|
||||
$Palette = $this->pDataObject->getPalette();
|
||||
|
||||
$ID = 0;
|
||||
foreach($Data["Series"] as $SerieName => $SeriesParameters)
|
||||
{
|
||||
if ( $SeriesParameters["isDrawable"] )
|
||||
{
|
||||
$this->pDataObject->Data["Series"][$SerieName]["Color"]["R"] = $Palette[$ID]["R"];
|
||||
$this->pDataObject->Data["Series"][$SerieName]["Color"]["G"] = $Palette[$ID]["G"];
|
||||
$this->pDataObject->Data["Series"][$SerieName]["Color"]["B"] = $Palette[$ID]["B"];
|
||||
$this->pDataObject->Data["Series"][$SerieName]["Color"]["Alpha"] = $Palette[$ID]["Alpha"];
|
||||
$ID++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare the scale */
|
||||
function drawBubbleChart($DataSeries,$WeightSeries,$Format="")
|
||||
{
|
||||
$ForceAlpha = isset($Format["ForceAlpha"]) ? $Format["ForceAlpha"] : VOID;
|
||||
$DrawBorder = isset($Format["DrawBorder"]) ? $Format["DrawBorder"] : TRUE;
|
||||
$BorderWidth = isset($Format["BorderWidth"]) ? $Format["BorderWidth"] : 1;
|
||||
$Shape = isset($Format["Shape"]) ? $Format["Shape"] : BUBBLE_SHAPE_ROUND;
|
||||
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
|
||||
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
|
||||
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
|
||||
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
|
||||
$BorderAlpha = isset($Format["BorderAlpha"]) ? $Format["BorderAlpha"] : 30;
|
||||
$RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
|
||||
|
||||
if ( !is_array($DataSeries) ) { $DataSeries = array($DataSeries); }
|
||||
if ( !is_array($WeightSeries) ) { $WeightSeries = array($WeightSeries); }
|
||||
|
||||
$Data = $this->pDataObject->getData();
|
||||
$Palette = $this->pDataObject->getPalette();
|
||||
|
||||
if ( isset($Data["Series"]["BubbleFakePositiveSerie"] ) ) { $this->pDataObject->setSerieDrawable("BubbleFakePositiveSerie",FALSE); }
|
||||
if ( isset($Data["Series"]["BubbleFakeNegativeSerie"] ) ) { $this->pDataObject->setSerieDrawable("BubbleFakeNegativeSerie",FALSE); }
|
||||
|
||||
$this->resetSeriesColors();
|
||||
|
||||
list($XMargin,$XDivs) = $this->pChartObject->scaleGetXSettings();
|
||||
|
||||
foreach($DataSeries as $Key => $SerieName)
|
||||
{
|
||||
$AxisID = $Data["Series"][$SerieName]["Axis"];
|
||||
$Mode = $Data["Axis"][$AxisID]["Display"];
|
||||
$Format = $Data["Axis"][$AxisID]["Format"];
|
||||
$Unit = $Data["Axis"][$AxisID]["Unit"];
|
||||
|
||||
if (isset($Data["Series"][$SerieName]["Description"])) { $SerieDescription = $Data["Series"][$SerieName]["Description"]; } else { $SerieDescription = $SerieName; }
|
||||
|
||||
$XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs;
|
||||
|
||||
$X = $this->pChartObject->GraphAreaX1 + $XMargin;
|
||||
$Y = $this->pChartObject->GraphAreaY1 + $XMargin;
|
||||
|
||||
$Color = array("R"=>$Palette[$Key]["R"],"G"=>$Palette[$Key]["G"],"B"=>$Palette[$Key]["B"],"Alpha"=>$Palette[$Key]["Alpha"]);
|
||||
|
||||
if ( $ForceAlpha != VOID ) { $Color["Alpha"]=$ForceAlpha; }
|
||||
|
||||
if ( $DrawBorder )
|
||||
{
|
||||
if ( $BorderWidth != 1 )
|
||||
{
|
||||
if ( $Surrounding != NULL )
|
||||
{ $BorderR = $Palette[$Key]["R"]+$Surrounding; $BorderG = $Palette[$Key]["G"]+$Surrounding; $BorderB = $Palette[$Key]["B"]+$Surrounding; }
|
||||
else
|
||||
{ $BorderR = $BorderR; $BorderG = $BorderG; $BorderB = $BorderB; }
|
||||
if ( $ForceAlpha != VOID ) { $BorderAlpha = $ForceAlpha/2; }
|
||||
$BorderColor = array("R"=>$BorderR,"G"=>$BorderG,"B"=>$BorderB,"Alpha"=>$BorderAlpha);
|
||||
}
|
||||
else
|
||||
{
|
||||
$Color["BorderAlpha"] = $BorderAlpha;
|
||||
|
||||
if ( $Surrounding != NULL )
|
||||
{ $Color["BorderR"] = $Palette[$Key]["R"]+$Surrounding; $Color["BorderG"] = $Palette[$Key]["G"]+$Surrounding; $Color["BorderB"] = $Palette[$Key]["B"]+$Surrounding; }
|
||||
else
|
||||
{ $Color["BorderR"] = $BorderR; $Color["BorderG"] = $BorderG; $Color["BorderB"] = $BorderB; }
|
||||
if ( $ForceAlpha != VOID ) { $Color["BorderAlpha"] = $ForceAlpha/2; }
|
||||
}
|
||||
}
|
||||
|
||||
foreach($Data["Series"][$SerieName]["Data"] as $iKey => $Point)
|
||||
{
|
||||
$Weight = $Point + $Data["Series"][$WeightSeries[$Key]]["Data"][$iKey];
|
||||
|
||||
$PosArray = $this->pChartObject->scaleComputeY($Point,array("AxisID"=>$AxisID));
|
||||
$WeightArray = $this->pChartObject->scaleComputeY($Weight,array("AxisID"=>$AxisID));
|
||||
|
||||
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
|
||||
{
|
||||
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs; }
|
||||
$Y = floor($PosArray); $CircleRadius = floor(abs($PosArray - $WeightArray)/2);
|
||||
|
||||
if ( $Shape == BUBBLE_SHAPE_SQUARE )
|
||||
{
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($X-$CircleRadius).",".floor($Y-$CircleRadius).",".floor($X+$CircleRadius).",".floor($Y+$CircleRadius),$this->pChartObject->toHTMLColor($Palette[$Key]["R"],$Palette[$Key]["G"],$Palette[$Key]["B"]),$SerieDescription,$Data["Series"][$WeightSeries[$Key]]["Data"][$iKey]); }
|
||||
|
||||
if ( $BorderWidth != 1 )
|
||||
{
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius-$BorderWidth,$Y-$CircleRadius-$BorderWidth,$X+$CircleRadius+$BorderWidth,$Y+$CircleRadius+$BorderWidth,$BorderColor);
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
|
||||
}
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
|
||||
}
|
||||
elseif ( $Shape == BUBBLE_SHAPE_ROUND )
|
||||
{
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($CircleRadius),$this->pChartObject->toHTMLColor($Palette[$Key]["R"],$Palette[$Key]["G"],$Palette[$Key]["B"]),$SerieDescription,$Data["Series"][$WeightSeries[$Key]]["Data"][$iKey]); }
|
||||
|
||||
if ( $BorderWidth != 1 )
|
||||
{
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius+$BorderWidth,$BorderColor);
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
|
||||
}
|
||||
else
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
|
||||
}
|
||||
|
||||
$X = $X + $XStep;
|
||||
}
|
||||
elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
|
||||
{
|
||||
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1-$XMargin*2)/$XDivs; }
|
||||
$X = floor($PosArray); $CircleRadius = floor(abs($PosArray - $WeightArray)/2);
|
||||
|
||||
if ( $Shape == BUBBLE_SHAPE_SQUARE )
|
||||
{
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($X-$CircleRadius).",".floor($Y-$CircleRadius).",".floor($X+$CircleRadius).",".floor($Y+$CircleRadius),$this->pChartObject->toHTMLColor($Palette[$Key]["R"],$Palette[$Key]["G"],$Palette[$Key]["B"]),$SerieDescription,$Data["Series"][$WeightSeries[$Key]]["Data"][$iKey]); }
|
||||
|
||||
if ( $BorderWidth != 1 )
|
||||
{
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius-$BorderWidth,$Y-$CircleRadius-$BorderWidth,$X+$CircleRadius+$BorderWidth,$Y+$CircleRadius+$BorderWidth,$BorderColor);
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
|
||||
}
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($X-$CircleRadius,$Y-$CircleRadius,$X+$CircleRadius,$Y+$CircleRadius,$Color);
|
||||
}
|
||||
elseif ( $Shape == BUBBLE_SHAPE_ROUND )
|
||||
{
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($CircleRadius),$this->pChartObject->toHTMLColor($Palette[$Key]["R"],$Palette[$Key]["G"],$Palette[$Key]["B"]),$SerieDescription,$Data["Series"][$WeightSeries[$Key]]["Data"][$iKey]); }
|
||||
|
||||
if ( $BorderWidth != 1 )
|
||||
{
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius+$BorderWidth,$BorderColor);
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
|
||||
}
|
||||
else
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$CircleRadius,$Color);
|
||||
}
|
||||
|
||||
$Y = $Y + $XStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function writeBubbleLabel($SerieName,$SerieWeightName,$Points,$Format="")
|
||||
{
|
||||
$OverrideTitle = isset($Format["OverrideTitle"]) ? $Format["OverrideTitle"] : NULL;
|
||||
$DrawPoint = isset($Format["DrawPoint"]) ? $Format["DrawPoint"] : LABEL_POINT_BOX;
|
||||
|
||||
if ( !is_array($Points) ) { $Point = $Points; $Points = ""; $Points[] = $Point; }
|
||||
|
||||
$Data = $this->pDataObject->getData();
|
||||
$Palette = $this->pDataObject->getPalette();
|
||||
|
||||
if ( !isset($Data["Series"][$SerieName]) || !isset($Data["Series"][$SerieWeightName]) )
|
||||
return(0);
|
||||
|
||||
list($XMargin,$XDivs) = $this->pChartObject->scaleGetXSettings();
|
||||
|
||||
$AxisID = $Data["Series"][$SerieName]["Axis"];
|
||||
$AxisMode = $Data["Axis"][$AxisID]["Display"];
|
||||
$AxisFormat = $Data["Axis"][$AxisID]["Format"];
|
||||
$AxisUnit = $Data["Axis"][$AxisID]["Unit"];
|
||||
$XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs;
|
||||
|
||||
$X = $this->pChartObject->GraphAreaX1 + $XMargin;
|
||||
$Y = $this->pChartObject->GraphAreaY1 + $XMargin;
|
||||
|
||||
$Color = array("R"=>$Data["Series"][$SerieName]["Color"]["R"],"G"=>$Data["Series"][$SerieName]["Color"]["G"],"B"=>$Data["Series"][$SerieName]["Color"]["B"],"Alpha"=>$Data["Series"][$SerieName]["Color"]["Alpha"]);
|
||||
|
||||
foreach($Points as $Key => $Point)
|
||||
{
|
||||
$Value = $Data["Series"][$SerieName]["Data"][$Point];
|
||||
$PosArray = $this->pChartObject->scaleComputeY($Value,array("AxisID"=>$AxisID));
|
||||
|
||||
if ( isset($Data["Abscissa"]) && isset($Data["Series"][$Data["Abscissa"]]["Data"][$Point]) )
|
||||
$Abscissa = $Data["Series"][$Data["Abscissa"]]["Data"][$Point]." : ";
|
||||
else
|
||||
$Abscissa = "";
|
||||
|
||||
$Value = $this->pChartObject->scaleFormat($Value,$AxisMode,$AxisFormat,$AxisUnit);
|
||||
$Weight = $Data["Series"][$SerieWeightName]["Data"][$Point];
|
||||
$Caption = $Abscissa.$Value." / ".$Weight;
|
||||
|
||||
if ( isset($Data["Series"][$SerieName]["Description"]) )
|
||||
$Description = $Data["Series"][$SerieName]["Description"];
|
||||
else
|
||||
$Description = "No description";
|
||||
|
||||
$Series = "";
|
||||
$Series[] = array("Format"=>$Color,"Caption"=>$Caption);
|
||||
|
||||
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
|
||||
{
|
||||
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs; }
|
||||
|
||||
$X = floor($X + $Point * $XStep);
|
||||
$Y = floor($PosArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $XDivs == 0 ) { $YStep = 0; } else { $YStep = ($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1-$XMargin*2)/$XDivs; }
|
||||
|
||||
$X = floor($PosArray);
|
||||
$Y = floor($Y + $Point * $YStep);
|
||||
}
|
||||
|
||||
if ( $DrawPoint == LABEL_POINT_CIRCLE )
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,3,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
|
||||
elseif ( $DrawPoint == LABEL_POINT_BOX )
|
||||
$this->pChartObject->drawFilledRectangle($X-2,$Y-2,$X+2,$Y+2,array("R"=>255,"G"=>255,"B"=>255,"BorderR"=>0,"BorderG"=>0,"BorderB"=>0));
|
||||
|
||||
$this->pChartObject->drawLabelBox($X,$Y-3,$Description,$Series,$Format);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,280 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pCache - speed up the rendering by caching up the pictures
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
/* pData class definition */
|
||||
class pCache
|
||||
{
|
||||
var $CacheFolder;
|
||||
var $CacheIndex;
|
||||
var $CacheDB;
|
||||
|
||||
/* Class creator */
|
||||
function pCache($Settings="")
|
||||
{
|
||||
$CacheFolder = isset($Settings["CacheFolder"]) ? $Settings["CacheFolder"] : "cache";
|
||||
$CacheIndex = isset($Settings["CacheIndex"]) ? $Settings["CacheIndex"] : "index.db";
|
||||
$CacheDB = isset($Settings["CacheDB"]) ? $Settings["CacheDB"] : "cache.db";
|
||||
|
||||
$this->CacheFolder = $CacheFolder;
|
||||
$this->CacheIndex = $CacheIndex;
|
||||
$this->CacheDB = $CacheDB;
|
||||
|
||||
if (!file_exists($this->CacheFolder."/".$this->CacheIndex)) { touch($this->CacheFolder."/".$this->CacheIndex); }
|
||||
if (!file_exists($this->CacheFolder."/".$this->CacheDB)) { touch($this->CacheFolder."/".$this->CacheDB); }
|
||||
}
|
||||
|
||||
/* Flush the cache contents */
|
||||
function flush()
|
||||
{
|
||||
if (file_exists($this->CacheFolder."/".$this->CacheIndex)) { unlink($this->CacheFolder."/".$this->CacheIndex); touch($this->CacheFolder."/".$this->CacheIndex); }
|
||||
if (file_exists($this->CacheFolder."/".$this->CacheDB)) { unlink($this->CacheFolder."/".$this->CacheDB); touch($this->CacheFolder."/".$this->CacheDB); }
|
||||
}
|
||||
|
||||
/* Return the MD5 of the data array to clearly identify the chart */
|
||||
function getHash($Data,$Marker="")
|
||||
{ return(md5($Marker.serialize($Data->Data))); }
|
||||
|
||||
/* Write the generated picture to the cache */
|
||||
function writeToCache($ID,$pChartObject)
|
||||
{
|
||||
/* Compute the paths */
|
||||
$TemporaryFile = $this->CacheFolder."/tmp_".rand(0,1000).".png";
|
||||
$Database = $this->CacheFolder."/".$this->CacheDB;
|
||||
$Index = $this->CacheFolder."/".$this->CacheIndex;
|
||||
|
||||
/* Flush the picture to a temporary file */
|
||||
imagepng($pChartObject->Picture ,$TemporaryFile);
|
||||
|
||||
/* Retrieve the files size */
|
||||
$PictureSize = filesize($TemporaryFile);
|
||||
$DBSize = filesize($Database);
|
||||
|
||||
/* Save the index */
|
||||
$Handle = fopen($Index,"a");
|
||||
fwrite($Handle, $ID.",".$DBSize.",".$PictureSize.",".time().",0 \r\n");
|
||||
fclose($Handle);
|
||||
|
||||
/* Get the picture raw contents */
|
||||
$Handle = fopen($TemporaryFile,"r");
|
||||
$Raw = fread($Handle,$PictureSize);
|
||||
fclose($Handle);
|
||||
|
||||
/* Save the picture in the solid database file */
|
||||
$Handle = fopen($Database,"a");
|
||||
fwrite($Handle, $Raw);
|
||||
fclose($Handle);
|
||||
|
||||
/* Remove temporary file */
|
||||
unlink($TemporaryFile);
|
||||
}
|
||||
|
||||
/* Remove object older than the specified TS */
|
||||
function removeOlderThan($Expiry)
|
||||
{ $this->dbRemoval(array("Expiry"=>$Expiry)); }
|
||||
|
||||
/* Remove an object from the cache */
|
||||
function remove($ID)
|
||||
{ $this->dbRemoval(array("Name"=>$ID)); }
|
||||
|
||||
/* Remove with specified criterias */
|
||||
function dbRemoval($Settings)
|
||||
{
|
||||
$ID = isset($Settings["Name"]) ? $Settings["Name"] : NULL;
|
||||
$Expiry = isset($Settings["Expiry"]) ? $Settings["Expiry"] : -(24*60*60);
|
||||
$TS = time()-$Expiry;
|
||||
|
||||
/* Compute the paths */
|
||||
$Database = $this->CacheFolder."/".$this->CacheDB;
|
||||
$Index = $this->CacheFolder."/".$this->CacheIndex;
|
||||
$DatabaseTemp = $this->CacheFolder."/".$this->CacheDB.".tmp";
|
||||
$IndexTemp = $this->CacheFolder."/".$this->CacheIndex.".tmp";
|
||||
|
||||
/* Single file removal */
|
||||
if ( $ID != NULL )
|
||||
{
|
||||
/* Retrieve object informations */
|
||||
$Object = $this->isInCache($ID,TRUE);
|
||||
|
||||
/* If it's not in the cache DB, go away */
|
||||
if ( !$Object ) { return(0); }
|
||||
}
|
||||
|
||||
/* Create the temporary files */
|
||||
if (!file_exists($DatabaseTemp)) { touch($DatabaseTemp); }
|
||||
if (!file_exists($IndexTemp)) { touch($IndexTemp); }
|
||||
|
||||
/* Open the file handles */
|
||||
$IndexHandle = @fopen($Index, "r");
|
||||
$IndexTempHandle = @fopen($IndexTemp, "w");
|
||||
$DBHandle = @fopen($Database, "r");
|
||||
$DBTempHandle = @fopen($DatabaseTemp, "w");
|
||||
|
||||
/* Remove the selected ID from the database */
|
||||
while (!feof($IndexHandle))
|
||||
{
|
||||
$Entry = fgets($IndexHandle, 4096);
|
||||
$Entry = str_replace("\r","",$Entry);
|
||||
$Entry = str_replace("\n","",$Entry);
|
||||
$Settings = preg_split("/,/",$Entry);
|
||||
|
||||
if ( $Entry != "" )
|
||||
{
|
||||
$PicID = $Settings[0];
|
||||
$DBPos = $Settings[1];
|
||||
$PicSize = $Settings[2];
|
||||
$GeneratedTS = $Settings[3];
|
||||
$Hits = $Settings[4];
|
||||
|
||||
if ( $Settings[0] != $ID && $GeneratedTS > $TS)
|
||||
{
|
||||
$CurrentPos = ftell($DBTempHandle);
|
||||
fwrite($IndexTempHandle, $PicID.",".$CurrentPos.",".$PicSize.",".$GeneratedTS.",".$Hits."\r\n");
|
||||
|
||||
fseek($DBHandle,$DBPos);
|
||||
$Picture = fread($DBHandle,$PicSize);
|
||||
fwrite($DBTempHandle,$Picture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Close the handles */
|
||||
fclose($IndexHandle);
|
||||
fclose($IndexTempHandle);
|
||||
fclose($DBHandle);
|
||||
fclose($DBTempHandle);
|
||||
|
||||
/* Remove the prod files */
|
||||
unlink($Database);
|
||||
unlink($Index);
|
||||
|
||||
/* Swap the temp & prod DB */
|
||||
rename($DatabaseTemp,$Database);
|
||||
rename($IndexTemp,$Index);
|
||||
}
|
||||
|
||||
function isInCache($ID,$Verbose=FALSE,$UpdateHitsCount=FALSE)
|
||||
{
|
||||
/* Compute the paths */
|
||||
$Index = $this->CacheFolder."/".$this->CacheIndex;
|
||||
|
||||
/* Search the picture in the index file */
|
||||
$Handle = @fopen($Index, "r");
|
||||
while (!feof($Handle))
|
||||
{
|
||||
$IndexPos = ftell($Handle);
|
||||
$Entry = fgets($Handle, 4096);
|
||||
if ( $Entry != "" )
|
||||
{
|
||||
$Settings = preg_split("/,/",$Entry);
|
||||
$PicID = $Settings[0];
|
||||
if ( $PicID == $ID )
|
||||
{
|
||||
fclose($Handle);
|
||||
|
||||
$DBPos = $Settings[1];
|
||||
$PicSize = $Settings[2];
|
||||
$GeneratedTS = $Settings[3];
|
||||
$Hits = intval($Settings[4]);
|
||||
|
||||
if ( $UpdateHitsCount )
|
||||
{
|
||||
$Hits++;
|
||||
if ( strlen($Hits) < 7 ) { $Hits = $Hits.str_repeat(" ",7-strlen($Hits)); }
|
||||
|
||||
$Handle = @fopen($Index, "r+");
|
||||
fseek($Handle,$IndexPos);
|
||||
fwrite($Handle, $PicID.",".$DBPos.",".$PicSize.",".$GeneratedTS.",".$Hits."\r\n");
|
||||
fclose($Handle);
|
||||
}
|
||||
|
||||
if ($Verbose)
|
||||
{ return(array("DBPos"=>$DBPos,"PicSize"=>$PicSize,"GeneratedTS"=>$GeneratedTS,"Hits"=>$Hits)); }
|
||||
else
|
||||
{ return(TRUE); }
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($Handle);
|
||||
|
||||
/* Picture isn't in the cache */
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
/* Automatic output method based on the calling interface */
|
||||
function autoOutput($ID,$Destination="output.png")
|
||||
{
|
||||
if (php_sapi_name() == "cli")
|
||||
$this->saveFromCache($ID,$Destination);
|
||||
else
|
||||
$this->strokeFromCache($ID);
|
||||
}
|
||||
|
||||
function strokeFromCache($ID)
|
||||
{
|
||||
/* Get the raw picture from the cache */
|
||||
$Picture = $this->getFromCache($ID);
|
||||
|
||||
/* Do we have a hit? */
|
||||
if ( $Picture == NULL ) { return(FALSE); }
|
||||
|
||||
header('Content-type: image/png');
|
||||
echo $Picture;
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
function saveFromCache($ID,$Destination)
|
||||
{
|
||||
/* Get the raw picture from the cache */
|
||||
$Picture = $this->getFromCache($ID);
|
||||
|
||||
/* Do we have a hit? */
|
||||
if ( $Picture == NULL ) { return(FALSE); }
|
||||
|
||||
/* Flush the picture to a file */
|
||||
$Handle = fopen($Destination,"w");
|
||||
fwrite($Handle,$Picture);
|
||||
fclose($Handle);
|
||||
|
||||
/* All went fine */
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
function getFromCache($ID)
|
||||
{
|
||||
/* Compute the path */
|
||||
$Database = $this->CacheFolder."/".$this->CacheDB;
|
||||
|
||||
/* Lookup for the picture in the cache */
|
||||
$CacheInfo = $this->isInCache($ID,TRUE,TRUE);
|
||||
|
||||
/* Not in the cache */
|
||||
if (!$CacheInfo) { return(NULL); }
|
||||
|
||||
/* Get the database extended information */
|
||||
$DBPos = $CacheInfo["DBPos"];
|
||||
$PicSize = $CacheInfo["PicSize"];
|
||||
|
||||
/* Extract the picture from the solid cache file */
|
||||
$Handle = @fopen($Database, "r");
|
||||
fseek($Handle,$DBPos);
|
||||
$Picture = fread($Handle,$PicSize);
|
||||
fclose($Handle);
|
||||
|
||||
/* Return back the raw picture data */
|
||||
return($Picture);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,788 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pDraw - class to manipulate data arrays
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
/* Axis configuration */
|
||||
define("AXIS_FORMAT_DEFAULT" , 680001);
|
||||
define("AXIS_FORMAT_TIME" , 680002);
|
||||
define("AXIS_FORMAT_DATE" , 680003);
|
||||
define("AXIS_FORMAT_METRIC" , 680004);
|
||||
define("AXIS_FORMAT_CURRENCY" , 680005);
|
||||
define("AXIS_FORMAT_TRAFFIC" , 680006);
|
||||
define("AXIS_FORMAT_CUSTOM" , 680007);
|
||||
|
||||
/* Axis position */
|
||||
define("AXIS_POSITION_LEFT" , 681001);
|
||||
define("AXIS_POSITION_RIGHT" , 681002);
|
||||
define("AXIS_POSITION_TOP" , 681001);
|
||||
define("AXIS_POSITION_BOTTOM" , 681002);
|
||||
|
||||
/* Families of data points */
|
||||
define("SERIE_SHAPE_FILLEDCIRCLE" , 681011);
|
||||
define("SERIE_SHAPE_FILLEDTRIANGLE" , 681012);
|
||||
define("SERIE_SHAPE_FILLEDSQUARE" , 681013);
|
||||
define("SERIE_SHAPE_FILLEDDIAMOND" , 681017);
|
||||
define("SERIE_SHAPE_CIRCLE" , 681014);
|
||||
define("SERIE_SHAPE_TRIANGLE" , 681015);
|
||||
define("SERIE_SHAPE_SQUARE" , 681016);
|
||||
define("SERIE_SHAPE_DIAMOND" , 681018);
|
||||
|
||||
/* Axis position */
|
||||
define("AXIS_X" , 682001);
|
||||
define("AXIS_Y" , 682002);
|
||||
|
||||
/* Define value limits */
|
||||
define("ABSOLUTE_MIN" , -10000000000000);
|
||||
define("ABSOLUTE_MAX" , 10000000000000);
|
||||
|
||||
/* Replacement to the PHP NULL keyword */
|
||||
define("VOID" , 0.123456789);
|
||||
|
||||
/* Euro symbol for GD fonts */
|
||||
define("EURO_SYMBOL" , utf8_encode("€"));
|
||||
|
||||
/* pData class definition */
|
||||
class pData
|
||||
{
|
||||
var $Data;
|
||||
|
||||
var $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46,"Alpha"=>100),
|
||||
"1"=>array("R"=>224,"G"=>100,"B"=>46,"Alpha"=>100),
|
||||
"2"=>array("R"=>224,"G"=>214,"B"=>46,"Alpha"=>100),
|
||||
"3"=>array("R"=>46,"G"=>151,"B"=>224,"Alpha"=>100),
|
||||
"4"=>array("R"=>176,"G"=>46,"B"=>224,"Alpha"=>100),
|
||||
"5"=>array("R"=>224,"G"=>46,"B"=>117,"Alpha"=>100),
|
||||
"6"=>array("R"=>92,"G"=>224,"B"=>46,"Alpha"=>100),
|
||||
"7"=>array("R"=>224,"G"=>176,"B"=>46,"Alpha"=>100));
|
||||
|
||||
/* Class creator */
|
||||
function pData()
|
||||
{
|
||||
$this->Data = "";
|
||||
$this->Data["XAxisDisplay"] = AXIS_FORMAT_DEFAULT;
|
||||
$this->Data["XAxisFormat"] = NULL;
|
||||
$this->Data["XAxisName"] = NULL;
|
||||
$this->Data["XAxisUnit"] = NULL;
|
||||
$this->Data["Abscissa"] = NULL;
|
||||
$this->Data["AbsicssaPosition"] = AXIS_POSITION_BOTTOM;
|
||||
|
||||
$this->Data["Axis"][0]["Display"] = AXIS_FORMAT_DEFAULT;
|
||||
$this->Data["Axis"][0]["Position"] = AXIS_POSITION_LEFT;
|
||||
$this->Data["Axis"][0]["Identity"] = AXIS_Y;
|
||||
}
|
||||
|
||||
/* Add a single point or an array to the given serie */
|
||||
function addPoints($Values,$SerieName="Serie1")
|
||||
{
|
||||
if (!isset($this->Data["Series"][$SerieName]))
|
||||
$this->initialise($SerieName);
|
||||
|
||||
if ( is_array($Values) )
|
||||
{
|
||||
foreach($Values as $Key => $Value)
|
||||
{ $this->Data["Series"][$SerieName]["Data"][] = $Value; }
|
||||
}
|
||||
else
|
||||
$this->Data["Series"][$SerieName]["Data"][] = $Values;
|
||||
|
||||
if ( $Values != VOID )
|
||||
{
|
||||
$StrippedData = $this->stripVOID($this->Data["Series"][$SerieName]["Data"]);
|
||||
if ( empty($StrippedData) ) { $this->Data["Series"][$SerieName]["Max"] = 0; $this->Data["Series"][$SerieName]["Min"] =0; return(0); }
|
||||
$this->Data["Series"][$SerieName]["Max"] = max($StrippedData);
|
||||
$this->Data["Series"][$SerieName]["Min"] = min($StrippedData);
|
||||
}
|
||||
}
|
||||
|
||||
/* Strip VOID values */
|
||||
function stripVOID($Values)
|
||||
{ if (!is_array($Values)) { return(array()); } $Result = array(); foreach($Values as $Key => $Value) { if ( $Value != VOID ) { $Result[] = $Value; } } return($Result); }
|
||||
|
||||
/* Return the number of values contained in a given serie */
|
||||
function getSerieCount($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie]["Data"])) { return(sizeof($this->Data["Series"][$Serie]["Data"])); } else { return(0); } }
|
||||
|
||||
/* Remove a serie from the pData object */
|
||||
function removeSerie($Series)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie])) { unset($this->Data["Series"][$Serie]); } }
|
||||
}
|
||||
|
||||
/* Return a value from given serie & index */
|
||||
function getValueAt($Serie,$Index=0)
|
||||
{ if (isset($this->Data["Series"][$Serie]["Data"][$Index])) { return($this->Data["Series"][$Serie]["Data"][$Index]); } else { return(NULL); } }
|
||||
|
||||
/* Return the values array */
|
||||
function getValues($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie]["Data"])) { return($this->Data["Series"][$Serie]["Data"]); } else { return(NULL); } }
|
||||
|
||||
/* Reverse the values in the given serie */
|
||||
function reverseSerie($Series)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie]["Data"])) { $this->Data["Series"][$Serie]["Data"] = array_reverse($this->Data["Series"][$Serie]["Data"]); } }
|
||||
}
|
||||
|
||||
/* Return the sum of the serie values */
|
||||
function getSum($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie])) { return(array_sum($this->Data["Series"][$Serie]["Data"])); } else { return(NULL); } }
|
||||
|
||||
/* Return the max value of a given serie */
|
||||
function getMax($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie]["Max"])) { return($this->Data["Series"][$Serie]["Max"]); } else { return(NULL); } }
|
||||
|
||||
/* Return the min value of a given serie */
|
||||
function getMin($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie]["Min"])) { return($this->Data["Series"][$Serie]["Min"]); } else { return(NULL); } }
|
||||
|
||||
/* Set the description of a given serie */
|
||||
function setSerieShape($Series,$Shape=SERIE_SHAPE_FILLEDCIRCLE)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Shape"] = $Shape; } }
|
||||
}
|
||||
|
||||
/* Set the description of a given serie */
|
||||
function setSerieDescription($Series,$Description="My serie")
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Description"] = $Description; } }
|
||||
}
|
||||
|
||||
/* Set a serie as "drawable" while calling a rendering function */
|
||||
function setSerieDrawable($Series,$Drawable=TRUE)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["isDrawable"] = $Drawable; } }
|
||||
}
|
||||
|
||||
/* Set the icon associated to a given serie */
|
||||
function setSeriePicture($Series,$Picture=NULL)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if (isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Picture"] = $Picture; } }
|
||||
}
|
||||
|
||||
/* Set the name of the X Axis */
|
||||
function setXAxisName($Name)
|
||||
{ $this->Data["XAxisName"] = $Name; }
|
||||
|
||||
/* Set the display mode of the X Axis */
|
||||
function setXAxisDisplay($Mode,$Format=NULL)
|
||||
{ $this->Data["XAxisDisplay"] = $Mode; $this->Data["XAxisFormat"] = $Format; }
|
||||
|
||||
/* Set the unit that will be displayed on the X axis */
|
||||
function setXAxisUnit($Unit)
|
||||
{ $this->Data["XAxisUnit"] = $Unit; }
|
||||
|
||||
/* Set the serie that will be used as abscissa */
|
||||
function setAbscissa($Serie)
|
||||
{ if (isset($this->Data["Series"][$Serie])) { $this->Data["Abscissa"] = $Serie; } }
|
||||
|
||||
function setAbsicssaPosition($Position = AXIS_POSITION_BOTTOM)
|
||||
{ $this->Data["AbsicssaPosition"] = $Position; }
|
||||
|
||||
/* Set the name of the abscissa axis */
|
||||
function setAbscissaName($Name)
|
||||
{ $this->Data["AbscissaName"] = $Name; }
|
||||
|
||||
/* Create a scatter group specifyin X and Y data series */
|
||||
function setScatterSerie($SerieX,$SerieY,$ID=0)
|
||||
{ if (isset($this->Data["Series"][$SerieX]) && isset($this->Data["Series"][$SerieY]) ) { $this->initScatterSerie($ID); $this->Data["ScatterSeries"][$ID]["X"] = $SerieX; $this->Data["ScatterSeries"][$ID]["Y"] = $SerieY; } }
|
||||
|
||||
/* Set the shape of a given sctatter serie */
|
||||
function setScatterSerieShape($ID,$Shape=SERIE_SHAPE_FILLEDCIRCLE)
|
||||
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Shape"] = $Shape; } }
|
||||
|
||||
/* Set the description of a given scatter serie */
|
||||
function setScatterSerieDescription($ID,$Description="My serie")
|
||||
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Description"] = $Description; } }
|
||||
|
||||
/* Set the icon associated to a given scatter serie */
|
||||
function setScatterSeriePicture($ID,$Picture=NULL)
|
||||
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Picture"] = $Picture; } }
|
||||
|
||||
/* Set a scatter serie as "drawable" while calling a rendering function */
|
||||
function setScatterSerieDrawable($ID ,$Drawable=TRUE)
|
||||
{ if (isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["isDrawable"] = $Drawable; } }
|
||||
|
||||
/* Define if a scatter serie should be draw with ticks */
|
||||
function setScatterSerieTicks($ID,$Width=0)
|
||||
{ if ( isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Ticks"] = $Width; } }
|
||||
|
||||
/* Define if a scatter serie should be draw with a special weight */
|
||||
function setScatterSerieWeight($ID,$Weight=0)
|
||||
{ if ( isset($this->Data["ScatterSeries"][$ID]) ) { $this->Data["ScatterSeries"][$ID]["Weight"] = $Weight; } }
|
||||
|
||||
/* Associate a color to a scatter serie */
|
||||
function setScatterSerieColor($ID,$Format)
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
|
||||
if ( isset($this->Data["ScatterSeries"][$ID]) )
|
||||
{
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["R"] = $R;
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["G"] = $G;
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["B"] = $B;
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["Alpha"] = $Alpha;
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the series limits for an individual and global point of view */
|
||||
function limits()
|
||||
{
|
||||
$GlobalMin = ABSOLUTE_MAX;
|
||||
$GlobalMax = ABSOLUTE_MIN;
|
||||
|
||||
foreach($this->Data["Series"] as $Key => $Value)
|
||||
{
|
||||
if ( $this->Data["Abscissa"] != $Key && $this->Data["Series"][$Key]["isDrawable"] == TRUE)
|
||||
{
|
||||
if ( $GlobalMin > $this->Data["Series"][$Key]["Min"] ) { $GlobalMin = $this->Data["Series"][$Key]["Min"]; }
|
||||
if ( $GlobalMax < $this->Data["Series"][$Key]["Max"] ) { $GlobalMax = $this->Data["Series"][$Key]["Max"]; }
|
||||
}
|
||||
}
|
||||
$this->Data["Min"] = $GlobalMin;
|
||||
$this->Data["Max"] = $GlobalMax;
|
||||
|
||||
return(array($GlobalMin,$GlobalMax));
|
||||
}
|
||||
|
||||
/* Mark all series as drawable */
|
||||
function drawAll()
|
||||
{ foreach($this->Data["Series"] as $Key => $Value) { if ( $this->Data["Abscissa"] != $Key ) { $this->Data["Series"][$Key]["isDrawable"]=TRUE; } } }
|
||||
|
||||
/* Return the average value of the given serie */
|
||||
function getSerieAverage($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$SerieData = $this->stripVOID($this->Data["Series"][$Serie]["Data"]);
|
||||
return(array_sum($SerieData)/sizeof($SerieData));
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the geometric mean of the given serie */
|
||||
function getGeometricMean($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$SerieData = $this->stripVOID($this->Data["Series"][$Serie]["Data"]);
|
||||
$Seriesum = 1; foreach($SerieData as $Key => $Value) { $Seriesum = $Seriesum * $Value; }
|
||||
return(pow($Seriesum,1/sizeof($SerieData)));
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the harmonic mean of the given serie */
|
||||
function getHarmonicMean($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$SerieData = $this->stripVOID($this->Data["Series"][$Serie]["Data"]);
|
||||
$Seriesum = 0; foreach($SerieData as $Key => $Value) { $Seriesum = $Seriesum + 1/$Value; }
|
||||
return(sizeof($SerieData)/$Seriesum);
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the standard deviation of the given serie */
|
||||
function getStandardDeviation($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$Average = $this->getSerieAverage($Serie);
|
||||
$SerieData = $this->stripVOID($this->Data["Series"][$Serie]["Data"]);
|
||||
|
||||
$DeviationSum = 0;
|
||||
foreach($SerieData as $Key => $Value)
|
||||
$DeviationSum = $DeviationSum + ($Value-$Average)*($Value-$Average);
|
||||
|
||||
$Deviation = sqrt($DeviationSum/count($SerieData));
|
||||
|
||||
return($Deviation);
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the Coefficient of variation of the given serie */
|
||||
function getCoefficientOfVariation($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$Average = $this->getSerieAverage($Serie);
|
||||
$StandardDeviation = $this->getStandardDeviation($Serie);
|
||||
|
||||
if ( $StandardDeviation != 0 )
|
||||
return($StandardDeviation/$Average);
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the median value of the given serie */
|
||||
function getSerieMedian($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$SerieData = $this->stripVOID($this->Data["Series"][$Serie]["Data"]);
|
||||
sort($SerieData);
|
||||
$SerieCenter = floor(sizeof($SerieData)/2);
|
||||
|
||||
if ( isset($SerieData[$SerieCenter]) )
|
||||
return($SerieData[$SerieCenter]);
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Return the x th percentil of the given serie */
|
||||
function getSeriePercentile($Serie="Serie1",$Percentil=95)
|
||||
{
|
||||
if (!isset($this->Data["Series"][$Serie]["Data"])) { return(NULL); }
|
||||
|
||||
$Values = count($this->Data["Series"][$Serie]["Data"])-1;
|
||||
if ( $Values < 0 ) { $Values = 0; }
|
||||
|
||||
$PercentilID = floor(($Values/100)*$Percentil+.5);
|
||||
$SortedValues = $this->Data["Series"][$Serie]["Data"];
|
||||
sort($SortedValues);
|
||||
|
||||
if ( is_numeric($SortedValues[$PercentilID]) )
|
||||
return($SortedValues[$PercentilID]);
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* Add random values to a given serie */
|
||||
function addRandomValues($SerieName="Serie1",$Options="")
|
||||
{
|
||||
$Values = isset($Options["Values"]) ? $Options["Values"] : 20;
|
||||
$Min = isset($Options["Min"]) ? $Options["Min"] : 0;
|
||||
$Max = isset($Options["Max"]) ? $Options["Max"] : 100;
|
||||
$withFloat = isset($Options["withFloat"]) ? $Options["withFloat"] : FALSE;
|
||||
|
||||
for ($i=0;$i<=$Values;$i++)
|
||||
{
|
||||
if ( $withFloat ) { $Value = rand($Min*100,$Max*100)/100; } else { $Value = rand($Min,$Max); }
|
||||
$this->addPoints($Value,$SerieName);
|
||||
}
|
||||
}
|
||||
|
||||
/* Test if we have valid data */
|
||||
function containsData()
|
||||
{
|
||||
if (!isset($this->Data["Series"])) { return(FALSE); }
|
||||
|
||||
$Result = FALSE;
|
||||
foreach($this->Data["Series"] as $Key => $Value)
|
||||
{ if ( $this->Data["Abscissa"] != $Key && $this->Data["Series"][$Key]["isDrawable"]==TRUE) { $Result=TRUE; } }
|
||||
return($Result);
|
||||
}
|
||||
|
||||
/* Set the display mode of an Axis */
|
||||
function setAxisDisplay($AxisID,$Mode=AXIS_FORMAT_DEFAULT,$Format=NULL)
|
||||
{
|
||||
if ( isset($this->Data["Axis"][$AxisID] ) )
|
||||
{
|
||||
$this->Data["Axis"][$AxisID]["Display"] = $Mode;
|
||||
if ( $Format != NULL ) { $this->Data["Axis"][$AxisID]["Format"] = $Format; }
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the position of an Axis */
|
||||
function setAxisPosition($AxisID,$Position=AXIS_POSITION_LEFT)
|
||||
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Position"] = $Position; } }
|
||||
|
||||
/* Associate an unit to an axis */
|
||||
function setAxisUnit($AxisID,$Unit)
|
||||
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Unit"] = $Unit; } }
|
||||
|
||||
/* Associate a name to an axis */
|
||||
function setAxisName($AxisID,$Name)
|
||||
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Name"] = $Name; } }
|
||||
|
||||
/* Associate a color to an axis */
|
||||
function setAxisColor($AxisID,$Format)
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
|
||||
if ( isset($this->Data["Axis"][$AxisID] ) )
|
||||
{
|
||||
$this->Data["Axis"][$AxisID]["Color"]["R"] = $R;
|
||||
$this->Data["Axis"][$AxisID]["Color"]["G"] = $G;
|
||||
$this->Data["Axis"][$AxisID]["Color"]["B"] = $B;
|
||||
$this->Data["Axis"][$AxisID]["Color"]["Alpha"] = $Alpha;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Design an axis as X or Y member */
|
||||
function setAxisXY($AxisID,$Identity=AXIS_Y)
|
||||
{ if ( isset($this->Data["Axis"][$AxisID] ) ) { $this->Data["Axis"][$AxisID]["Identity"] = $Identity; } }
|
||||
|
||||
/* Associate one data serie with one axis */
|
||||
function setSerieOnAxis($Series,$AxisID)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie)
|
||||
{
|
||||
$PreviousAxis = $this->Data["Series"][$Serie]["Axis"];
|
||||
|
||||
/* Create missing axis */
|
||||
if ( !isset($this->Data["Axis"][$AxisID] ) )
|
||||
{ $this->Data["Axis"][$AxisID]["Position"] = AXIS_POSITION_LEFT; $this->Data["Axis"][$AxisID]["Identity"] = AXIS_Y;}
|
||||
|
||||
$this->Data["Series"][$Serie]["Axis"] = $AxisID;
|
||||
|
||||
/* Cleanup unused axis */
|
||||
$Found = FALSE;
|
||||
foreach($this->Data["Series"] as $SerieName => $Values) { if ( $Values["Axis"] == $PreviousAxis ) { $Found = TRUE; } }
|
||||
if (!$Found) { unset($this->Data["Axis"][$PreviousAxis]); }
|
||||
}
|
||||
}
|
||||
|
||||
/* Define if a serie should be draw with ticks */
|
||||
function setSerieTicks($Series,$Width=0)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if ( isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Ticks"] = $Width; } }
|
||||
}
|
||||
|
||||
/* Define if a serie should be draw with a special weight */
|
||||
function setSerieWeight($Series,$Weight=0)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $Serie) { if ( isset($this->Data["Series"][$Serie]) ) { $this->Data["Series"][$Serie]["Weight"] = $Weight; } }
|
||||
}
|
||||
|
||||
/* Returns the palette of the given serie */
|
||||
function getSeriePalette($Serie)
|
||||
{
|
||||
if ( !isset($this->Data["Series"][$Serie]) ) { return(NULL); }
|
||||
|
||||
$Result = "";
|
||||
$Result["R"] = $this->Data["Series"][$Serie]["Color"]["R"];
|
||||
$Result["G"] = $this->Data["Series"][$Serie]["Color"]["G"];
|
||||
$Result["B"] = $this->Data["Series"][$Serie]["Color"]["B"];
|
||||
$Result["Alpha"] = $this->Data["Series"][$Serie]["Color"]["Alpha"];
|
||||
|
||||
return($Result);
|
||||
}
|
||||
|
||||
/* Set the color of one serie */
|
||||
function setPalette($Series,$Format=NULL)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
|
||||
foreach($Series as $Key => $Serie)
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
|
||||
if ( isset($this->Data["Series"][$Serie]) )
|
||||
{
|
||||
$OldR = $this->Data["Series"][$Serie]["Color"]["R"]; $OldG = $this->Data["Series"][$Serie]["Color"]["G"]; $OldB = $this->Data["Series"][$Serie]["Color"]["B"];
|
||||
$this->Data["Series"][$Serie]["Color"]["R"] = $R;
|
||||
$this->Data["Series"][$Serie]["Color"]["G"] = $G;
|
||||
$this->Data["Series"][$Serie]["Color"]["B"] = $B;
|
||||
$this->Data["Series"][$Serie]["Color"]["Alpha"] = $Alpha;
|
||||
|
||||
/* Do reverse processing on the internal palette array */
|
||||
foreach ($this->Palette as $Key => $Value)
|
||||
{ if ($Value["R"] == $OldR && $Value["G"] == $OldG && $Value["B"] == $OldB) { $this->Palette[$Key]["R"] = $R; $this->Palette[$Key]["G"] = $G; $this->Palette[$Key]["B"] = $B; $this->Palette[$Key]["Alpha"] = $Alpha;} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load a palette file */
|
||||
function loadPalette($FileName,$Overwrite=FALSE)
|
||||
{
|
||||
if ( !file_exists($FileName) ) { return(-1); }
|
||||
if ( $Overwrite ) { $this->Palette = ""; }
|
||||
|
||||
$fileHandle = @fopen($FileName, "r");
|
||||
if (!$fileHandle) { return(-1); }
|
||||
while (!feof($fileHandle))
|
||||
{
|
||||
$buffer = fgets($fileHandle, 4096);
|
||||
if ( preg_match("/,/",$buffer) )
|
||||
{
|
||||
list($R,$G,$B,$Alpha) = preg_split("/,/",$buffer);
|
||||
if ( $this->Palette == "" ) { $ID = 0; } else { $ID = count($this->Palette); }
|
||||
$this->Palette[$ID] = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
}
|
||||
}
|
||||
fclose($fileHandle);
|
||||
|
||||
/* Apply changes to current series */
|
||||
$ID = 0;
|
||||
if ( isset($this->Data["Series"]))
|
||||
{
|
||||
foreach($this->Data["Series"] as $Key => $Value)
|
||||
{
|
||||
if ( !isset($this->Palette[$ID]) )
|
||||
$this->Data["Series"][$Key]["Color"] = array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>0);
|
||||
else
|
||||
$this->Data["Series"][$Key]["Color"] = $this->Palette[$ID];
|
||||
$ID++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise a given scatter serie */
|
||||
function initScatterSerie($ID)
|
||||
{
|
||||
if ( isset($this->Data["ScatterSeries"][$ID]) ) { return(0); }
|
||||
|
||||
$this->Data["ScatterSeries"][$ID]["Description"] = "Scatter ".$ID;
|
||||
$this->Data["ScatterSeries"][$ID]["isDrawable"] = TRUE;
|
||||
$this->Data["ScatterSeries"][$ID]["Picture"] = NULL;
|
||||
$this->Data["ScatterSeries"][$ID]["Ticks"] = 0;
|
||||
$this->Data["ScatterSeries"][$ID]["Weight"] = 0;
|
||||
|
||||
if ( isset($this->Palette[$ID]) )
|
||||
$this->Data["ScatterSeries"][$ID]["Color"] = $this->Palette[$ID];
|
||||
else
|
||||
{
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["R"] = rand(0,255);
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["G"] = rand(0,255);
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["B"] = rand(0,255);
|
||||
$this->Data["ScatterSeries"][$ID]["Color"]["Alpha"] = 100;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialise a given serie */
|
||||
function initialise($Serie)
|
||||
{
|
||||
if ( isset($this->Data["Series"]) ) { $ID = count($this->Data["Series"]); } else { $ID = 0; }
|
||||
|
||||
$this->Data["Series"][$Serie]["Description"] = $Serie;
|
||||
$this->Data["Series"][$Serie]["isDrawable"] = TRUE;
|
||||
$this->Data["Series"][$Serie]["Picture"] = NULL;
|
||||
$this->Data["Series"][$Serie]["Max"] = NULL;
|
||||
$this->Data["Series"][$Serie]["Min"] = NULL;
|
||||
$this->Data["Series"][$Serie]["Axis"] = 0;
|
||||
$this->Data["Series"][$Serie]["Ticks"] = 0;
|
||||
$this->Data["Series"][$Serie]["Weight"] = 0;
|
||||
$this->Data["Series"][$Serie]["Shape"] = SERIE_SHAPE_FILLEDCIRCLE;
|
||||
|
||||
if ( isset($this->Palette[$ID]) )
|
||||
$this->Data["Series"][$Serie]["Color"] = $this->Palette[$ID];
|
||||
else
|
||||
{
|
||||
$this->Data["Series"][$Serie]["Color"]["R"] = rand(0,255);
|
||||
$this->Data["Series"][$Serie]["Color"]["G"] = rand(0,255);
|
||||
$this->Data["Series"][$Serie]["Color"]["B"] = rand(0,255);
|
||||
$this->Data["Series"][$Serie]["Color"]["Alpha"] = 100;
|
||||
}
|
||||
}
|
||||
|
||||
function normalize($NormalizationFactor=100,$UnitChange=NULL,$Round=1)
|
||||
{
|
||||
$Abscissa = $this->Data["Abscissa"];
|
||||
|
||||
$SelectedSeries = "";
|
||||
$MaxVal = 0;
|
||||
foreach($this->Data["Axis"] as $AxisID => $Axis)
|
||||
{
|
||||
if ( $UnitChange != NULL ) { $this->Data["Axis"][$AxisID]["Unit"] = $UnitChange; }
|
||||
|
||||
foreach($this->Data["Series"] as $SerieName => $Serie)
|
||||
{
|
||||
if ($Serie["Axis"] == $AxisID && $Serie["isDrawable"] == TRUE && $SerieName != $Abscissa)
|
||||
{
|
||||
$SelectedSeries[$SerieName] = $SerieName;
|
||||
|
||||
if ( count($Serie["Data"] ) > $MaxVal ) { $MaxVal = count($Serie["Data"]); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($i=0;$i<=$MaxVal-1;$i++)
|
||||
{
|
||||
$Factor = 0;
|
||||
foreach ($SelectedSeries as $Key => $SerieName )
|
||||
{
|
||||
$Value = $this->Data["Series"][$SerieName]["Data"][$i];
|
||||
if ( $Value != VOID )
|
||||
$Factor = $Factor + abs($Value);
|
||||
}
|
||||
|
||||
if ( $Factor != 0 )
|
||||
{
|
||||
$Factor = $NormalizationFactor / $Factor;
|
||||
|
||||
foreach ($SelectedSeries as $Key => $SerieName )
|
||||
{
|
||||
$Value = $this->Data["Series"][$SerieName]["Data"][$i];
|
||||
|
||||
if ( $Value != VOID && $Factor != $NormalizationFactor )
|
||||
$this->Data["Series"][$SerieName]["Data"][$i] = round(abs($Value)*$Factor,$Round);
|
||||
elseif ( $Value == VOID || $Value == 0 )
|
||||
$this->Data["Series"][$SerieName]["Data"][$i] = VOID;
|
||||
elseif ( $Factor == $NormalizationFactor )
|
||||
$this->Data["Series"][$SerieName]["Data"][$i] = $NormalizationFactor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($SelectedSeries as $Key => $SerieName )
|
||||
{
|
||||
$this->Data["Series"][$SerieName]["Max"] = max($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
|
||||
$this->Data["Series"][$SerieName]["Min"] = min($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
|
||||
}
|
||||
}
|
||||
|
||||
/* Load data from a CSV (or similar) data source */
|
||||
function importFromCSV($FileName,$Options="")
|
||||
{
|
||||
$Delimiter = isset($Options["Delimiter"]) ? $Options["Delimiter"] : ",";
|
||||
$GotHeader = isset($Options["GotHeader"]) ? $Options["GotHeader"] : FALSE;
|
||||
$SkipColumns = isset($Options["SkipColumns"]) ? $Options["SkipColumns"] : array(-1);
|
||||
$DefaultSerieName = isset($Options["DefaultSerieName"]) ? $Options["DefaultSerieName"] : "Serie";
|
||||
|
||||
$Handle = @fopen($FileName,"r");
|
||||
if ($Handle)
|
||||
{
|
||||
$HeaderParsed = FALSE; $SerieNames = "";
|
||||
while (!feof($Handle))
|
||||
{
|
||||
$Buffer = fgets($Handle, 4096);
|
||||
$Buffer = str_replace(chr(10),"",$Buffer);
|
||||
$Buffer = str_replace(chr(13),"",$Buffer);
|
||||
$Values = preg_split("/".$Delimiter."/",$Buffer);
|
||||
|
||||
if ( $Buffer != "" )
|
||||
{
|
||||
if ( $GotHeader && !$HeaderParsed )
|
||||
{
|
||||
foreach($Values as $Key => $Name) { if ( !in_array($Key,$SkipColumns) ) { $SerieNames[$Key] = $Name; } }
|
||||
$HeaderParsed = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($SerieNames == "" ) { foreach($Values as $Key => $Name) { if ( !in_array($Key,$SkipColumns) ) { $SerieNames[$Key] = $DefaultSerieName.$Key; } } }
|
||||
foreach($Values as $Key => $Value) { if ( !in_array($Key,$SkipColumns) ) { $this->addPoints($Value,$SerieNames[$Key]); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($Handle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a dataset based on a formula */
|
||||
function createFunctionSerie($SerieName,$Formula="",$Options="")
|
||||
{
|
||||
$MinX = isset($Options["MinX"]) ? $Options["MinX"] : -10;
|
||||
$MaxX = isset($Options["MaxX"]) ? $Options["MaxX"] : 10;
|
||||
$XStep = isset($Options["XStep"]) ? $Options["XStep"] : 1;
|
||||
$AutoDescription = isset($Options["AutoDescription"]) ? $Options["AutoDescription"] : FALSE;
|
||||
$RecordAbscissa = isset($Options["RecordAbscissa"]) ? $Options["RecordAbscissa"] : FALSE;
|
||||
$AbscissaSerie = isset($Options["AbscissaSerie"]) ? $Options["AbscissaSerie"] : "Abscissa";
|
||||
|
||||
if ( $Formula == "" ) { return(0); }
|
||||
|
||||
$Result = ""; $Abscissa = "";
|
||||
for($i=$MinX; $i<=$MaxX; $i=$i+$XStep)
|
||||
{
|
||||
$Expression = "\$return = '!'.(".str_replace("z",$i,$Formula).");";
|
||||
if ( @eval($Expression) === FALSE ) { $return = VOID; }
|
||||
if ( $return == "!" ) { $return = VOID; } else { $return = $this->right($return,strlen($return)-1); }
|
||||
if ( $return == "NAN" ) { $return = VOID; }
|
||||
if ( $return == "INF" ) { $return = VOID; }
|
||||
if ( $return == "-INF" ) { $return = VOID; }
|
||||
|
||||
$Abscissa[] = $i;
|
||||
$Result[] = $return;
|
||||
}
|
||||
|
||||
$this->addPoints($Result,$SerieName);
|
||||
if ( $AutoDescription ) { $this->setSerieDescription($SerieName,$Formula); }
|
||||
if ( $RecordAbscissa ) { $this->addPoints($Abscissa,$AbscissaSerie); }
|
||||
}
|
||||
|
||||
function negateValues($Series)
|
||||
{
|
||||
if ( !is_array($Series) ) { $Series = $this->convertToArray($Series); }
|
||||
foreach($Series as $Key => $SerieName)
|
||||
{
|
||||
if (isset($this->Data["Series"][$SerieName]))
|
||||
{
|
||||
$Data = "";
|
||||
foreach($this->Data["Series"][$SerieName]["Data"] as $Key => $Value)
|
||||
{ if ( $Value == VOID ) { $Data[] = VOID; } else { $Data[] = -$Value; } }
|
||||
$this->Data["Series"][$SerieName]["Data"] = $Data;
|
||||
|
||||
$this->Data["Series"][$SerieName]["Max"] = max($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
|
||||
$this->Data["Series"][$SerieName]["Min"] = min($this->stripVOID($this->Data["Series"][$SerieName]["Data"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the data & configuration of the series */
|
||||
function getData()
|
||||
{ return($this->Data); }
|
||||
|
||||
/* Save a palette element */
|
||||
function savePalette($ID,$Color)
|
||||
{ $this->Palette[$ID] = $Color; }
|
||||
|
||||
/* Return the palette of the series */
|
||||
function getPalette()
|
||||
{ return($this->Palette); }
|
||||
|
||||
/* Called by the scaling algorithm to save the config */
|
||||
function saveAxisConfig($Axis) { $this->Data["Axis"]=$Axis; }
|
||||
|
||||
/* Save the Y Margin if set */
|
||||
function saveYMargin($Value) { $this->Data["YMargin"]=$Value; }
|
||||
|
||||
/* Save extended configuration to the pData object */
|
||||
function saveExtendedData($Tag,$Values) { $this->Data["Extended"][$Tag]=$Values; }
|
||||
|
||||
/* Called by the scaling algorithm to save the orientation of the scale */
|
||||
function saveOrientation($Orientation) { $this->Data["Orientation"]=$Orientation; }
|
||||
|
||||
/* Convert a string to a single elements array */
|
||||
function convertToArray($Value)
|
||||
{ $Values = ""; $Values[] = $Value; return($Values); }
|
||||
|
||||
/* Class string wrapper */
|
||||
function __toString()
|
||||
{ return("pData object."); }
|
||||
|
||||
function left($value,$NbChar) { return substr($value,0,$NbChar); }
|
||||
function right($value,$NbChar) { return substr($value,strlen($value)-$NbChar,$NbChar); }
|
||||
function mid($value,$Depart,$NbChar) { return substr($value,$Depart-1,$NbChar); }
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,472 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pDraw - pChart core class
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
/* The GD extension is mandatory */
|
||||
if (!extension_loaded('gd') && !extension_loaded('gd2'))
|
||||
{
|
||||
echo "GD extension must be loaded. \r\n";
|
||||
exit();
|
||||
}
|
||||
|
||||
/* Image map handling */
|
||||
define("IMAGE_MAP_STORAGE_FILE" , 680001);
|
||||
define("IMAGE_MAP_STORAGE_SESSION" , 680002);
|
||||
|
||||
/* Last generated chart layout */
|
||||
define("CHART_LAST_LAYOUT_REGULAR" , 680011);
|
||||
define("CHART_LAST_LAYOUT_STACKED" , 680012);
|
||||
|
||||
/* ImageMap string delimiter */
|
||||
define("IMAGE_MAP_DELIMITER" , chr(1));
|
||||
|
||||
class pImage extends pDraw
|
||||
{
|
||||
/* Image settings, size, quality, .. */
|
||||
var $XSize = NULL; // Width of the picture
|
||||
var $YSize = NULL; // Height of the picture
|
||||
var $Picture = NULL; // GD picture object
|
||||
var $Antialias = TRUE; // Turn antialias on or off
|
||||
var $AntialiasQuality = 0; // Quality of the antialiasing implementation (0-1)
|
||||
var $Mask = ""; // Already drawn pixels mask (Filled circle implementation)
|
||||
var $TransparentBackground = FALSE; // Just to know if we need to flush the alpha channels when rendering
|
||||
|
||||
/* Graph area settings */
|
||||
var $GraphAreaX1 = NULL; // Graph area X origin
|
||||
var $GraphAreaY1 = NULL; // Graph area Y origin
|
||||
var $GraphAreaX2 = NULL; // Graph area bottom right X position
|
||||
var $GraphAreaY2 = NULL; // Graph area bottom right Y position
|
||||
|
||||
/* Scale settings */
|
||||
var $ScaleMinDivHeight = 20; // Minimum height for scame divs
|
||||
|
||||
/* Font properties */
|
||||
var $FontName = "fonts/GeosansLight.ttf"; // Default font file
|
||||
var $FontSize = 12; // Default font size
|
||||
var $FontBox = NULL; // Return the bounding box of the last written string
|
||||
var $FontColorR = 0; // Default color settings
|
||||
var $FontColorG = 0; // Default color settings
|
||||
var $FontColorB = 0; // Default color settings
|
||||
var $FontColorA = 100; // Default transparency
|
||||
|
||||
/* Shadow properties */
|
||||
var $Shadow = FALSE; // Turn shadows on or off
|
||||
var $ShadowX = NULL; // X Offset of the shadow
|
||||
var $ShadowY = NULL; // Y Offset of the shadow
|
||||
var $ShadowR = NULL; // R component of the shadow
|
||||
var $ShadowG = NULL; // G component of the shadow
|
||||
var $ShadowB = NULL; // B component of the shadow
|
||||
var $Shadowa = NULL; // Alpha level of the shadow
|
||||
|
||||
/* Image map */
|
||||
var $ImageMap = NULL; // Aray containing the image map
|
||||
var $ImageMapIndex = "pChart"; // Name of the session array
|
||||
var $ImageMapStorageMode = NULL; // Save the current imagemap storage mode
|
||||
var $ImageMapAutoDelete = TRUE; // Automatic deletion of the image map temp files
|
||||
|
||||
/* Data Set */
|
||||
var $DataSet = NULL; // Attached dataset
|
||||
|
||||
/* Last generated chart info */
|
||||
var $LastChartLayout = CHART_LAST_LAYOUT_REGULAR; // Last layout : regular or stacked
|
||||
|
||||
/* Class constructor */
|
||||
function pImage($XSize,$YSize,$DataSet=NULL,$TransparentBackground=FALSE)
|
||||
{
|
||||
$this->TransparentBackground = $TransparentBackground;
|
||||
|
||||
if ( $DataSet != NULL ) { $this->DataSet = $DataSet; }
|
||||
|
||||
$this->XSize = $XSize;
|
||||
$this->YSize = $YSize;
|
||||
$this->Picture = imagecreatetruecolor($XSize,$YSize);
|
||||
|
||||
if ( $this->TransparentBackground )
|
||||
{
|
||||
imagealphablending($this->Picture,FALSE);
|
||||
imagefilledrectangle($this->Picture, 0,0,$XSize, $YSize, imagecolorallocatealpha($this->Picture, 255, 255, 255, 127));
|
||||
imagealphablending($this->Picture,TRUE);
|
||||
imagesavealpha($this->Picture,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$C_White = $this->AllocateColor($this->Picture,255,255,255);
|
||||
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable / Disable and set shadow properties */
|
||||
function setShadow($Enabled=TRUE,$Format="")
|
||||
{
|
||||
$X = isset($Format["X"]) ? $Format["X"] : 2;
|
||||
$Y = isset($Format["Y"]) ? $Format["Y"] : 2;
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 10;
|
||||
|
||||
$this->Shadow = $Enabled;
|
||||
$this->ShadowX = $X;
|
||||
$this->ShadowY = $Y;
|
||||
$this->ShadowR = $R;
|
||||
$this->ShadowG = $G;
|
||||
$this->ShadowB = $B;
|
||||
$this->Shadowa = $Alpha;
|
||||
}
|
||||
|
||||
/* Set the graph area position */
|
||||
function setGraphArea($X1,$Y1,$X2,$Y2)
|
||||
{
|
||||
if ( $X2 < $X1 || $X1 == $X2 || $Y2 < $Y1 || $Y1 == $Y2 ) { return(-1); }
|
||||
|
||||
$this->GraphAreaX1 = $X1; $this->DataSet->Data["GraphArea"]["X1"] = $X1;
|
||||
$this->GraphAreaY1 = $Y1; $this->DataSet->Data["GraphArea"]["Y1"] = $Y1;
|
||||
$this->GraphAreaX2 = $X2; $this->DataSet->Data["GraphArea"]["X2"] = $X2;
|
||||
$this->GraphAreaY2 = $Y2; $this->DataSet->Data["GraphArea"]["Y2"] = $Y2;
|
||||
}
|
||||
|
||||
/* Return the width of the picture */
|
||||
function getWidth()
|
||||
{ return($this->XSize); }
|
||||
|
||||
/* Return the heigth of the picture */
|
||||
function getHeight()
|
||||
{ return($this->YSize); }
|
||||
|
||||
/* Render the picture to a file */
|
||||
function render($FileName)
|
||||
{
|
||||
if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
|
||||
imagepng($this->Picture,$FileName);
|
||||
}
|
||||
|
||||
/* Render the picture to a web browser stream */
|
||||
function stroke($BrowserExpire=FALSE)
|
||||
{
|
||||
if ( $this->TransparentBackground ) { imagealphablending($this->Picture,false); imagesavealpha($this->Picture,true); }
|
||||
|
||||
if ( $BrowserExpire )
|
||||
{
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Cache-Control: no-cache");
|
||||
header("Pragma: no-cache");
|
||||
}
|
||||
|
||||
header('Content-type: image/png');
|
||||
imagepng($this->Picture);
|
||||
}
|
||||
|
||||
/* Automatic output method based on the calling interface */
|
||||
function autoOutput($FileName="output.png")
|
||||
{
|
||||
if (php_sapi_name() == "cli")
|
||||
$this->Render($FileName);
|
||||
else
|
||||
$this->Stroke();
|
||||
}
|
||||
|
||||
/* Return the length between two points */
|
||||
function getLength($X1,$Y1,$X2,$Y2)
|
||||
{ return(sqrt(pow(max($X1,$X2)-min($X1,$X2),2)+pow(max($Y1,$Y2)-min($Y1,$Y2),2))); }
|
||||
|
||||
/* Return the orientation of a line */
|
||||
function getAngle($X1,$Y1,$X2,$Y2)
|
||||
{
|
||||
$Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
|
||||
if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
|
||||
}
|
||||
|
||||
/* Return the surrounding box of text area */
|
||||
function getTextBox_deprecated($X,$Y,$FontName,$FontSize,$Angle,$Text)
|
||||
{
|
||||
$Size = imagettfbbox($FontSize,$Angle,$FontName,$Text);
|
||||
$Width = $this->getLength($Size[0],$Size[1],$Size[2],$Size[3])+1;
|
||||
$Height = $this->getLength($Size[2],$Size[3],$Size[4],$Size[5])+1;
|
||||
|
||||
$RealPos[0]["X"] = $X; $RealPos[0]["Y"] = $Y;
|
||||
$RealPos[1]["X"] = cos((360-$Angle)*PI/180)*$Width + $RealPos[0]["X"]; $RealPos[1]["Y"] = sin((360-$Angle)*PI/180)*$Width + $RealPos[0]["Y"];
|
||||
$RealPos[2]["X"] = cos((270-$Angle)*PI/180)*$Height + $RealPos[1]["X"]; $RealPos[2]["Y"] = sin((270-$Angle)*PI/180)*$Height + $RealPos[1]["Y"];
|
||||
$RealPos[3]["X"] = cos((180-$Angle)*PI/180)*$Width + $RealPos[2]["X"]; $RealPos[3]["Y"] = sin((180-$Angle)*PI/180)*$Width + $RealPos[2]["Y"];
|
||||
|
||||
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
|
||||
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
|
||||
|
||||
return($RealPos);
|
||||
}
|
||||
|
||||
/* Return the surrounding box of text area */
|
||||
function getTextBox($X,$Y,$FontName,$FontSize,$Angle,$Text)
|
||||
{
|
||||
$coords = imagettfbbox($FontSize, 0, $FontName, $Text);
|
||||
|
||||
$a = deg2rad($Angle); $ca = cos($a); $sa = sin($a); $RealPos = array();
|
||||
for($i = 0; $i < 7; $i += 2)
|
||||
{
|
||||
$RealPos[$i/2]["X"] = $X + round($coords[$i] * $ca + $coords[$i+1] * $sa);
|
||||
$RealPos[$i/2]["Y"] = $Y + round($coords[$i+1] * $ca - $coords[$i] * $sa);
|
||||
}
|
||||
|
||||
$RealPos[TEXT_ALIGN_BOTTOMLEFT]["X"] = $RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMLEFT]["Y"] = $RealPos[0]["Y"];
|
||||
$RealPos[TEXT_ALIGN_BOTTOMRIGHT]["X"] = $RealPos[1]["X"]; $RealPos[TEXT_ALIGN_BOTTOMRIGHT]["Y"] = $RealPos[1]["Y"];
|
||||
$RealPos[TEXT_ALIGN_TOPLEFT]["X"] = $RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPLEFT]["Y"] = $RealPos[3]["Y"];
|
||||
$RealPos[TEXT_ALIGN_TOPRIGHT]["X"] = $RealPos[2]["X"]; $RealPos[TEXT_ALIGN_TOPRIGHT]["Y"] = $RealPos[2]["Y"];
|
||||
$RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[0]["X"])/2+$RealPos[0]["X"]; $RealPos[TEXT_ALIGN_BOTTOMMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[1]["Y"])/2+$RealPos[1]["Y"];
|
||||
$RealPos[TEXT_ALIGN_TOPMIDDLE]["X"] = ($RealPos[2]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_TOPMIDDLE]["Y"] = ($RealPos[3]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
|
||||
$RealPos[TEXT_ALIGN_MIDDLELEFT]["X"] = ($RealPos[0]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLELEFT]["Y"] = ($RealPos[0]["Y"]-$RealPos[3]["Y"])/2+$RealPos[3]["Y"];
|
||||
$RealPos[TEXT_ALIGN_MIDDLERIGHT]["X"] = ($RealPos[1]["X"]-$RealPos[2]["X"])/2+$RealPos[2]["X"]; $RealPos[TEXT_ALIGN_MIDDLERIGHT]["Y"] = ($RealPos[1]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
|
||||
$RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["X"] = ($RealPos[1]["X"]-$RealPos[3]["X"])/2+$RealPos[3]["X"]; $RealPos[TEXT_ALIGN_MIDDLEMIDDLE]["Y"] = ($RealPos[0]["Y"]-$RealPos[2]["Y"])/2+$RealPos[2]["Y"];
|
||||
|
||||
return($RealPos);
|
||||
}
|
||||
|
||||
/* Set current font properties */
|
||||
function setFontProperties($Format="")
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : -1;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : -1;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : -1;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
$FontName = isset($Format["FontName"]) ? $Format["FontName"] : NULL;
|
||||
$FontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : NULL;
|
||||
|
||||
if ( $R != -1) { $this->FontColorR = $R; }
|
||||
if ( $G != -1) { $this->FontColorG = $G; }
|
||||
if ( $B != -1) { $this->FontColorB = $B; }
|
||||
if ( $Alpha != NULL) { $this->FontColorA = $Alpha; }
|
||||
|
||||
if ( $FontName != NULL )
|
||||
$this->FontName = $FontName;
|
||||
|
||||
if ( $FontSize != NULL )
|
||||
$this->FontSize = $FontSize;
|
||||
}
|
||||
|
||||
/* Returns the 1st decimal values (used to correct AA bugs) */
|
||||
function getFirstDecimal($Value)
|
||||
{
|
||||
$Values = preg_split("/\./",$Value);
|
||||
if ( isset($Values[1]) ) { return(substr($Values[1],0,1)); } else { return(0); }
|
||||
}
|
||||
|
||||
/* Attach a dataset to your pChart Object */
|
||||
function setDataSet(&$DataSet)
|
||||
{ $this->DataSet = $DataSet; }
|
||||
|
||||
/* Print attached dataset contents to STDOUT */
|
||||
function printDataSet()
|
||||
{ print_r($this->DataSet); }
|
||||
|
||||
/* Initialise the image map methods */
|
||||
function initialiseImageMap($Name="pChart",$StorageMode=IMAGE_MAP_STORAGE_SESSION,$UniqueID="imageMap",$StorageFolder="tmp")
|
||||
{
|
||||
$this->ImageMapIndex = $Name;
|
||||
$this->ImageMapStorageMode = $StorageMode;
|
||||
|
||||
if ($StorageMode == IMAGE_MAP_STORAGE_SESSION)
|
||||
{
|
||||
if(!isset($_SESSION)) { session_start(); }
|
||||
$_SESSION[$this->ImageMapIndex] = NULL;
|
||||
}
|
||||
elseif($StorageMode == IMAGE_MAP_STORAGE_FILE)
|
||||
{
|
||||
$this->ImageMapFileName = $UniqueID;
|
||||
$this->ImageMapStorageFolder = $StorageFolder;
|
||||
|
||||
if (file_exists($StorageFolder."/".$UniqueID.".map")) { unlink($StorageFolder."/".$UniqueID.".map"); }
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a zone to the image map */
|
||||
function addToImageMap($Type,$Plots,$Color=NULL,$Title=NULL,$Message=NULL,$HTMLEncode=FALSE)
|
||||
{
|
||||
if ( $this->ImageMapStorageMode == NULL ) { $this->initialiseImageMap(); }
|
||||
|
||||
/* Encode the characters in the imagemap in HTML standards */
|
||||
$Title = str_replace("€","\u20AC",$Title);
|
||||
$Title = htmlentities($Title,ENT_QUOTES,"ISO-8859-15");
|
||||
if ( $HTMLEncode )
|
||||
{
|
||||
$Message = htmlentities($Message,ENT_QUOTES,"ISO-8859-15");
|
||||
$Message = str_replace("<","<",$Message);
|
||||
$Message = str_replace(">",">",$Message);
|
||||
}
|
||||
|
||||
if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
|
||||
{
|
||||
if(!isset($_SESSION)) { $this->initialiseImageMap(); }
|
||||
$_SESSION[$this->ImageMapIndex][] = array($Type,$Plots,$Color,$Title,$Message);
|
||||
}
|
||||
elseif($this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE)
|
||||
{
|
||||
$Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'a');
|
||||
fwrite($Handle, $Type.IMAGE_MAP_DELIMITER.$Plots.IMAGE_MAP_DELIMITER.$Color.IMAGE_MAP_DELIMITER.$Title.IMAGE_MAP_DELIMITER.$Message."\r\n");
|
||||
fclose($Handle);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove VOID values from an imagemap custom values array */
|
||||
function removeVOIDFromArray($SerieName, $Values)
|
||||
{
|
||||
if ( !isset($this->DataSet->Data["Series"][$SerieName]) ) { return(-1); }
|
||||
|
||||
$Result = "";
|
||||
foreach($this->DataSet->Data["Series"][$SerieName]["Data"] as $Key => $Value)
|
||||
{ if ( $Value != VOID && isset($Values[$Key]) ) { $Result[] = $Values[$Key]; } }
|
||||
return($Result);
|
||||
}
|
||||
|
||||
/* Replace the title of one image map serie */
|
||||
function replaceImageMapTitle($OldTitle, $NewTitle)
|
||||
{
|
||||
if ( $this->ImageMapStorageMode == NULL ) { return(-1); }
|
||||
|
||||
if ( is_array($NewTitle) ) { $NewTitle = $this->removeVOIDFromArray($OldTitle, $NewTitle); }
|
||||
|
||||
if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
|
||||
{
|
||||
if(!isset($_SESSION)) { return(-1); }
|
||||
if ( is_array($NewTitle) )
|
||||
{ $ID = 0; foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $OldTitle && isset($NewTitle[$ID])) { $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle[$ID]; $ID++; } } }
|
||||
else
|
||||
{ foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $OldTitle ) { $_SESSION[$this->ImageMapIndex][$Key][3] = $NewTitle; } } }
|
||||
}
|
||||
elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
|
||||
{
|
||||
$TempArray = "";
|
||||
$Handle = @fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", "r");
|
||||
if ($Handle)
|
||||
{
|
||||
while (($Buffer = fgets($Handle, 4096)) !== false)
|
||||
{
|
||||
$Fields = preg_split("/".IMAGE_MAP_DELIMITER."/",str_replace(array(chr(10),chr(13)),"",$Buffer));
|
||||
$TempArray[] = array($Fields[0],$Fields[1],$Fields[2],$Fields[3],$Fields[4]);
|
||||
}
|
||||
fclose($Handle);
|
||||
|
||||
if ( is_array($NewTitle) )
|
||||
{ $ID = 0; foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $OldTitle && isset($NewTitle[$ID]) ) { $TempArray[$Key][3] = $NewTitle[$ID]; $ID++; } } }
|
||||
else
|
||||
{ foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $OldTitle ) { $TempArray[$Key][3] = $NewTitle; } } }
|
||||
|
||||
$Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'w');
|
||||
foreach($TempArray as $Key => $Settings)
|
||||
{ fwrite($Handle, $Settings[0].IMAGE_MAP_DELIMITER.$Settings[1].IMAGE_MAP_DELIMITER.$Settings[2].IMAGE_MAP_DELIMITER.$Settings[3].IMAGE_MAP_DELIMITER.$Settings[4]."\r\n"); }
|
||||
fclose($Handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Replace the values of the image map contents */
|
||||
function replaceImageMapValues($Title, $Values)
|
||||
{
|
||||
if ( $this->ImageMapStorageMode == NULL ) { return(-1); }
|
||||
|
||||
$Values = $this->removeVOIDFromArray($Title, $Values);
|
||||
$ID = 0;
|
||||
if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
|
||||
{
|
||||
if(!isset($_SESSION)) { return(-1); }
|
||||
foreach($_SESSION[$this->ImageMapIndex] as $Key => $Settings) { if ( $Settings[3] == $Title ) { if ( isset($Values[$ID]) ) { $_SESSION[$this->ImageMapIndex][$Key][4] = $Values[$ID]; } $ID++; } }
|
||||
}
|
||||
elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
|
||||
{
|
||||
$TempArray = "";
|
||||
$Handle = @fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", "r");
|
||||
if ($Handle)
|
||||
{
|
||||
while (($Buffer = fgets($Handle, 4096)) !== false)
|
||||
{
|
||||
$Fields = preg_split("/".IMAGE_MAP_DELIMITER."/",str_replace(array(chr(10),chr(13)),"",$Buffer));
|
||||
$TempArray[] = array($Fields[0],$Fields[1],$Fields[2],$Fields[3],$Fields[4]);
|
||||
}
|
||||
fclose($Handle);
|
||||
|
||||
foreach($TempArray as $Key => $Settings) { if ( $Settings[3] == $Title ) { if ( isset($Values[$ID]) ) { $TempArray[$Key][4] = $Values[$ID]; } $ID++; } }
|
||||
|
||||
$Handle = fopen($this->ImageMapStorageFolder."/".$this->ImageMapFileName.".map", 'w');
|
||||
foreach($TempArray as $Key => $Settings)
|
||||
{ fwrite($Handle, $Settings[0].IMAGE_MAP_DELIMITER.$Settings[1].IMAGE_MAP_DELIMITER.$Settings[2].IMAGE_MAP_DELIMITER.$Settings[3].IMAGE_MAP_DELIMITER.$Settings[4]."\r\n"); }
|
||||
fclose($Handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump the image map */
|
||||
function dumpImageMap($Name="pChart",$StorageMode=IMAGE_MAP_STORAGE_SESSION,$UniqueID="imageMap",$StorageFolder="tmp")
|
||||
{
|
||||
$this->ImageMapIndex = $Name;
|
||||
$this->ImageMapStorageMode = $StorageMode;
|
||||
|
||||
if ( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_SESSION )
|
||||
{
|
||||
if(!isset($_SESSION)) { session_start(); }
|
||||
if ( $_SESSION[$Name] != NULL )
|
||||
{
|
||||
foreach($_SESSION[$Name] as $Key => $Params)
|
||||
{ echo $Params[0].IMAGE_MAP_DELIMITER.$Params[1].IMAGE_MAP_DELIMITER.$Params[2].IMAGE_MAP_DELIMITER.$Params[3].IMAGE_MAP_DELIMITER.$Params[4]."\r\n"; }
|
||||
}
|
||||
}
|
||||
elseif( $this->ImageMapStorageMode == IMAGE_MAP_STORAGE_FILE )
|
||||
{
|
||||
if (file_exists($StorageFolder."/".$UniqueID.".map"))
|
||||
{
|
||||
$Handle = @fopen($StorageFolder."/".$UniqueID.".map", "r");
|
||||
if ($Handle) { while (($Buffer = fgets($Handle, 4096)) !== false) { echo $Buffer; } }
|
||||
fclose($Handle);
|
||||
|
||||
if ( $this->ImageMapAutoDelete ) { unlink($StorageFolder."/".$UniqueID.".map"); }
|
||||
}
|
||||
}
|
||||
|
||||
/* When the image map is returned to the client, the script ends */
|
||||
exit();
|
||||
}
|
||||
|
||||
/* Return the HTML converted color from the RGB composite values */
|
||||
function toHTMLColor($R,$G,$B)
|
||||
{
|
||||
$R=intval($R); $G=intval($G); $B=intval($B);
|
||||
$R=dechex($R<0?0:($R>255?255:$R)); $G=dechex($G<0?0:($G>255?255:$G));$B=dechex($B<0?0:($B>255?255:$B));
|
||||
$Color="#".(strlen($R) < 2?'0':'').$R; $Color.=(strlen($G) < 2?'0':'').$G; $Color.= (strlen($B) < 2?'0':'').$B;
|
||||
return($Color);
|
||||
}
|
||||
|
||||
/* Reverse an array of points */
|
||||
function reversePlots($Plots)
|
||||
{
|
||||
$Result = "";
|
||||
for($i=count($Plots)-2;$i>=0;$i=$i-2) { $Result[] = $Plots[$i]; $Result[] = $Plots[$i+1]; }
|
||||
return($Result);
|
||||
}
|
||||
|
||||
/* Mirror Effect */
|
||||
function drawAreaMirror($X,$Y,$Width,$Height,$Format="")
|
||||
{
|
||||
$StartAlpha = isset($Format["StartAlpha"]) ? $Format["StartAlpha"] : 80;
|
||||
$EndAlpha = isset($Format["EndAlpha"]) ? $Format["EndAlpha"] : 0;
|
||||
|
||||
$AlphaStep = ($StartAlpha-$EndAlpha)/$Height;
|
||||
|
||||
$Picture = imagecreatetruecolor($this->XSize,$this->YSize);
|
||||
imagecopy($Picture,$this->Picture,0,0,0,0,$this->XSize,$this->YSize);
|
||||
|
||||
for($i=1;$i<=$Height;$i++)
|
||||
{
|
||||
if ( $Y+($i-1) < $this->YSize && $Y-$i > 0 ) { imagecopymerge($Picture,$this->Picture,$X,$Y+($i-1),$X,$Y-$i,$Width,1,$StartAlpha-$AlphaStep*$i); }
|
||||
}
|
||||
|
||||
imagecopy($this->Picture,$Picture,0,0,0,0,$this->XSize,$this->YSize);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,241 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pIndicator - class to draw indicators
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("INDICATOR_CAPTION_DEFAULT" , 700001);
|
||||
define("INDICATOR_CAPTION_EXTENDED" , 700002);
|
||||
|
||||
define("INDICATOR_CAPTION_INSIDE" , 700011);
|
||||
define("INDICATOR_CAPTION_BOTTOM" , 700012);
|
||||
|
||||
define("INDICATOR_VALUE_BUBBLE" , 700021);
|
||||
define("INDICATOR_VALUE_LABEL" , 700022);
|
||||
|
||||
/* pIndicator class definition */
|
||||
class pIndicator
|
||||
{
|
||||
var $pChartObject;
|
||||
|
||||
/* Class creator */
|
||||
function pIndicator($pChartObject)
|
||||
{
|
||||
$this->pChartObject = $pChartObject;
|
||||
}
|
||||
|
||||
/* Draw an indicator */
|
||||
function draw($X,$Y,$Width,$Height,$Format="")
|
||||
{
|
||||
$Values = isset($Format["Values"]) ? $Format["Values"] : VOID;
|
||||
$IndicatorSections = isset($Format["IndicatorSections"]) ? $Format["IndicatorSections"] : NULL;
|
||||
$ValueDisplay = isset($Format["ValueDisplay"]) ? $Format["ValueDisplay"] : INDICATOR_VALUE_BUBBLE;
|
||||
$SectionsMargin = isset($Format["SectionsMargin"]) ? $Format["SectionsMargin"] : 4;
|
||||
$DrawLeftHead = isset($Format["DrawLeftHead"]) ? $Format["DrawLeftHead"] : TRUE;
|
||||
$DrawRightHead = isset($Format["DrawRightHead"]) ? $Format["DrawRightHead"] : TRUE;
|
||||
$HeadSize = isset($Format["HeadSize"]) ? $Format["HeadSize"] : floor($Height/4);
|
||||
$TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 4;
|
||||
$CaptionLayout = isset($Format["CaptionLayout"]) ? $Format["CaptionLayout"] : INDICATOR_CAPTION_EXTENDED;
|
||||
$CaptionPosition = isset($Format["CaptionPosition"]) ? $Format["CaptionPosition"] : INDICATOR_CAPTION_INSIDE;
|
||||
$CaptionColorFactor = isset($Format["CaptionColorFactor"]) ? $Format["CaptionColorFactor"] : NULL;
|
||||
$CaptionR = isset($Format["CaptionR"]) ? $Format["CaptionR"] : 255;
|
||||
$CaptionG = isset($Format["CaptionG"]) ? $Format["CaptionG"] : 255;
|
||||
$CaptionB = isset($Format["CaptionB"]) ? $Format["CaptionB"] : 255;
|
||||
$CaptionAlpha = isset($Format["CaptionAlpha"]) ? $Format["CaptionAlpha"] : 100;
|
||||
$SubCaptionColorFactor = isset($Format["SubCaptionColorFactor"]) ? $Format["SubCaptionColorFactor"] : NULL;
|
||||
$SubCaptionR = isset($Format["SubCaptionR"]) ? $Format["SubCaptionR"] : 50;
|
||||
$SubCaptionG = isset($Format["SubCaptionG"]) ? $Format["SubCaptionG"] : 50;
|
||||
$SubCaptionB = isset($Format["SubCaptionB"]) ? $Format["SubCaptionB"] : 50;
|
||||
$SubCaptionAlpha = isset($Format["SubCaptionAlpha"]) ? $Format["SubCaptionAlpha"] : 100;
|
||||
$ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName;
|
||||
$ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize;
|
||||
$CaptionFontName = isset($Format["CaptionFontName"]) ? $Format["CaptionFontName"] : $this->pChartObject->FontName;
|
||||
$CaptionFontSize = isset($Format["CaptionFontSize"]) ? $Format["CaptionFontSize"] : $this->pChartObject->FontSize;
|
||||
$Unit = isset($Format["Unit"]) ? $Format["Unit"] : "";
|
||||
|
||||
/* Convert the Values to display to an array if needed */
|
||||
if ( !is_array($Values) ) { $Value = $Values; $Values = ""; $Values[] = $Value; }
|
||||
|
||||
/* No section, let's die */
|
||||
if ( $IndicatorSections == NULL ) { return(0); }
|
||||
|
||||
/* Determine indicator visual configuration */
|
||||
$OverallMin = $IndicatorSections[0]["End"]; $OverallMax = $IndicatorSections[0]["Start"];
|
||||
foreach ($IndicatorSections as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["End"] > $OverallMax ) { $OverallMax = $Settings["End"]; }
|
||||
if ( $Settings["Start"] < $OverallMin ) { $OverallMin = $Settings["Start"]; }
|
||||
}
|
||||
$RealWidth = $Width - (count($IndicatorSections)-1)*$SectionsMargin;
|
||||
$XScale = $RealWidth / ($OverallMax-$OverallMin);
|
||||
|
||||
$X1 = $X; $ValuesPos = "";
|
||||
foreach ($IndicatorSections as $Key => $Settings)
|
||||
{
|
||||
$Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"]);
|
||||
$Caption = $Settings["Caption"];
|
||||
$SubCaption = $Settings["Start"]." - ".$Settings["End"];
|
||||
|
||||
$X2 = $X1 + ($Settings["End"] - $Settings["Start"]) * $XScale;
|
||||
|
||||
if ( $Key == 0 && $DrawLeftHead )
|
||||
{
|
||||
$Poly = ""; $Poly[] = $X1-1; $Poly[] = $Y; $Poly[] = $X1-1; $Poly[] = $Y+$Height; $Poly[] = $X1-1-$HeadSize; $Poly[] = $Y+($Height/2);
|
||||
$this->pChartObject->drawPolygon($Poly,$Color);
|
||||
$this->pChartObject->drawLine($X1-2,$Y,$X1-2-$HeadSize,$Y+($Height/2),$Color);
|
||||
$this->pChartObject->drawLine($X1-2,$Y+$Height,$X1-2-$HeadSize,$Y+($Height/2),$Color);
|
||||
}
|
||||
|
||||
/* Determine the position of the breaks */
|
||||
$Break = "";
|
||||
foreach($Values as $iKey => $Value)
|
||||
{
|
||||
if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
|
||||
{
|
||||
$XBreak = $X1 + ($Value - $Settings["Start"]) * $XScale;
|
||||
$ValuesPos[$Value] = $XBreak;
|
||||
$Break[] = floor($XBreak);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ValueDisplay == INDICATOR_VALUE_LABEL )
|
||||
{
|
||||
if ( $Break == "" )
|
||||
$this->pChartObject->drawFilledRectangle($X1,$Y,$X2,$Y+$Height,$Color);
|
||||
else
|
||||
{
|
||||
sort($Break);
|
||||
$Poly = ""; $Poly[] = $X1; $Poly[] = $Y; $LastPointWritten = FALSE;
|
||||
foreach($Break as $iKey => $Value)
|
||||
{
|
||||
if ( $Value-5 >= $X1 )
|
||||
{ $Poly[] = $Value-5; $Poly[] = $Y; }
|
||||
elseif ($X1 - ($Value-5) > 0 )
|
||||
{
|
||||
$Offset = $X1 - ($Value-5);
|
||||
$Poly = ""; $Poly[] = $X1; $Poly[] = $Y + $Offset;
|
||||
}
|
||||
|
||||
$Poly[] = $Value; $Poly[] = $Y+5;
|
||||
|
||||
if ( $Value+5 <= $X2 )
|
||||
{ $Poly[] = $Value+5; $Poly[] = $Y; }
|
||||
elseif (($Value+5) > $X2 )
|
||||
{
|
||||
$Offset = ($Value+5) - $X2;
|
||||
$Poly[] = $X2; $Poly[] = $Y + $Offset;
|
||||
$LastPointWritten = TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
if ( !$LastPointWritten ) { $Poly[] = $X2; $Poly[] = $Y; }
|
||||
$Poly[] = $X2; $Poly[] = $Y+$Height;
|
||||
$Poly[] = $X1; $Poly[] = $Y+$Height;
|
||||
|
||||
$this->pChartObject->drawPolygon($Poly,$Color);
|
||||
}
|
||||
}
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($X1,$Y,$X2,$Y+$Height,$Color);
|
||||
|
||||
if ( $Key == count($IndicatorSections)-1 && $DrawRightHead )
|
||||
{
|
||||
$Poly = ""; $Poly[] = $X2+1; $Poly[] = $Y; $Poly[] = $X2+1; $Poly[] = $Y+$Height; $Poly[] = $X2+1+$HeadSize; $Poly[] = $Y+($Height/2);
|
||||
$this->pChartObject->drawPolygon($Poly,$Color);
|
||||
$this->pChartObject->drawLine($X2+1,$Y,$X2+1+$HeadSize,$Y+($Height/2),$Color);
|
||||
$this->pChartObject->drawLine($X2+1,$Y+$Height,$X2+1+$HeadSize,$Y+($Height/2),$Color);
|
||||
}
|
||||
|
||||
if ( $CaptionPosition == INDICATOR_CAPTION_INSIDE )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
|
||||
$YOffset = ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding;
|
||||
|
||||
if ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$SubCaption);
|
||||
$YOffset = $YOffset + ($TxtPos[0]["Y"] - $TxtPos[2]["Y"]) + $TextPadding*2;
|
||||
}
|
||||
|
||||
$XOffset = $TextPadding;
|
||||
}
|
||||
else
|
||||
{ $YOffset = 0; $XOffset = 0; }
|
||||
|
||||
if ( $CaptionColorFactor == NULL )
|
||||
{ $CaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$CaptionR,"G"=>$CaptionG,"B"=>$CaptionB,"Alpha"=>$CaptionAlpha); }
|
||||
else
|
||||
{ $CaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$Settings["R"]+$CaptionColorFactor,"G"=>$Settings["G"]+$CaptionColorFactor,"B"=>$Settings["B"]+$CaptionColorFactor); }
|
||||
|
||||
if ( $SubCaptionColorFactor == NULL )
|
||||
$SubCaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$SubCaptionR,"G"=>$SubCaptionG,"B"=>$SubCaptionB,"Alpha"=>$SubCaptionAlpha);
|
||||
else
|
||||
$SubCaptionColor = array("Align"=>TEXT_ALIGN_TOPLEFT,"FontName"=>$CaptionFontName,"FontSize"=>$CaptionFontSize,"R"=>$Settings["R"]+$SubCaptionColorFactor,"G"=>$Settings["G"]+$SubCaptionColorFactor,"B"=>$Settings["B"]+$SubCaptionColorFactor);
|
||||
|
||||
$RestoreShadow = $this->pChartObject->Shadow;
|
||||
$this->pChartObject->Shadow = FALSE;
|
||||
|
||||
if ( $CaptionLayout == INDICATOR_CAPTION_DEFAULT )
|
||||
$this->pChartObject->drawText($X1,$Y+$Height+$TextPadding,$Caption,$CaptionColor);
|
||||
elseif ( $CaptionLayout == INDICATOR_CAPTION_EXTENDED )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($X1,$Y+$Height+$TextPadding,$CaptionFontName,$CaptionFontSize,0,$Caption);
|
||||
$CaptionHeight = $TxtPos[0]["Y"] - $TxtPos[2]["Y"];
|
||||
|
||||
$this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$TextPadding,$Caption,$CaptionColor);
|
||||
$this->pChartObject->drawText($X1+$XOffset,$Y+$Height-$YOffset+$CaptionHeight+$TextPadding*2,$SubCaption,$SubCaptionColor);
|
||||
}
|
||||
|
||||
$this->pChartObject->Shadow = $RestoreShadow;
|
||||
|
||||
$X1 = $X2 + $SectionsMargin;
|
||||
}
|
||||
|
||||
$RestoreShadow = $this->pChartObject->Shadow;
|
||||
$this->pChartObject->Shadow = FALSE;
|
||||
|
||||
foreach($Values as $Key => $Value)
|
||||
{
|
||||
if ( $Value >= $OverallMin && $Value <= $OverallMax )
|
||||
{
|
||||
foreach ($IndicatorSections as $Key => $Settings)
|
||||
{
|
||||
if ( $Value >= $Settings["Start"] && $Value <= $Settings["End"] )
|
||||
{
|
||||
$X1 = $ValuesPos[$Value]; //$X + $Key*$SectionsMargin + ($Value - $OverallMin) * $XScale;
|
||||
|
||||
if ( $ValueDisplay == INDICATOR_VALUE_BUBBLE )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($X1,$Y,$ValueFontName,$ValueFontSize,0,$Value.$Unit);
|
||||
$Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $TextPadding*4)/2);
|
||||
|
||||
$this->pChartObject->drawFilledCircle($X1,$Y,$Radius+4,array("R"=>$Settings["R"]+20,"G"=>$Settings["G"]+20,"B"=>$Settings["B"]+20));
|
||||
$this->pChartObject->drawFilledCircle($X1,$Y,$Radius,array("R"=>255,"G"=>255,"B"=>255));
|
||||
|
||||
$TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize);
|
||||
$this->pChartObject->drawText($X1-1,$Y-1,$Value.$Unit,$TextSettings);
|
||||
}
|
||||
elseif( $ValueDisplay == INDICATOR_VALUE_LABEL )
|
||||
{
|
||||
$Caption = "";
|
||||
$Caption[] = array("Format"=>array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>100),"Caption"=>$Value.$Unit);
|
||||
$this->pChartObject->drawLabelBox(floor($X1),floor($Y)+2,"Value - ".$Settings["Caption"],$Caption);
|
||||
}
|
||||
}
|
||||
$X1 = $X2 + $SectionsMargin;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->pChartObject->Shadow = $RestoreShadow;
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,681 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pRadar - class to draw radar charts
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("SEGMENT_HEIGHT_AUTO" , 690001);
|
||||
|
||||
define("RADAR_LAYOUT_STAR" , 690011);
|
||||
define("RADAR_LAYOUT_CIRCLE" , 690012);
|
||||
|
||||
define("RADAR_LABELS_ROTATED" , 690021);
|
||||
define("RADAR_LABELS_HORIZONTAL" , 690022);
|
||||
|
||||
/* pRadar class definition */
|
||||
class pRadar
|
||||
{
|
||||
var $pChartObject;
|
||||
|
||||
/* Class creator */
|
||||
function pRadar()
|
||||
{ }
|
||||
|
||||
/* Draw a radar chart */
|
||||
function drawRadar($Object,$Values,$Format="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$FixedMax = isset($Format["FixedMax"]) ? $Format["FixedMax"] : VOID;
|
||||
$AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60;
|
||||
$AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60;
|
||||
$AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60;
|
||||
$AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50;
|
||||
$AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : 0;
|
||||
$DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE;
|
||||
$TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2;
|
||||
$DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE;
|
||||
$AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE;
|
||||
$AxisFontName = isset($Format["AxisFontName"]) ? $Format["AxisFontName"] : $this->pChartObject->FontName;
|
||||
$AxisFontSize = isset($Format["AxisFontSize"]) ? $Format["AxisFontSize"] : $this->pChartObject->FontSize;
|
||||
$WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : FALSE;
|
||||
$WriteValuesInBubble = isset($Format["WriteValuesInBubble"]) ? $Format["WriteValuesInBubble"] : TRUE;
|
||||
$ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName;
|
||||
$ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize;
|
||||
$ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 4;
|
||||
$OuterBubbleRadius = isset($Format["OuterBubbleRadius"]) ? $Format["OuterBubbleRadius"] : 2;
|
||||
$OuterBubbleR = isset($Format["OuterBubbleR"]) ? $Format["OuterBubbleR"] : VOID;
|
||||
$OuterBubbleG = isset($Format["OuterBubbleG"]) ? $Format["OuterBubbleG"] : VOID;
|
||||
$OuterBubbleB = isset($Format["OuterBubbleB"]) ? $Format["OuterBubbleB"] : VOID;
|
||||
$OuterBubbleAlpha = isset($Format["OuterBubbleAlpha"]) ? $Format["OuterBubbleAlpha"] : 100;
|
||||
$InnerBubbleR = isset($Format["InnerBubbleR"]) ? $Format["InnerBubbleR"] : 255;
|
||||
$InnerBubbleG = isset($Format["InnerBubbleG"]) ? $Format["InnerBubbleG"] : 255;
|
||||
$InnerBubbleB = isset($Format["InnerBubbleB"]) ? $Format["InnerBubbleB"] : 255;
|
||||
$InnerBubbleAlpha = isset($Format["InnerBubbleAlpha"]) ? $Format["InnerBubbleAlpha"] : 100;
|
||||
$DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
|
||||
$BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
|
||||
$BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
|
||||
$BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
|
||||
$BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50;
|
||||
$BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL;
|
||||
$Layout = isset($Format["Layout"]) ? $Format["Layout"] : RADAR_LAYOUT_STAR;
|
||||
$SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO;
|
||||
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4;
|
||||
$WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE;
|
||||
$SkipLabels = isset($Format["SkipLabels"]) ? $Format["SkipLabels"] : 1;
|
||||
$LabelMiddle = isset($Format["LabelMiddle"]) ? $Format["LabelMiddle"] : FALSE;
|
||||
$LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE;
|
||||
$LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255;
|
||||
$LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255;
|
||||
$LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255;
|
||||
$LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50;
|
||||
$LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED;
|
||||
$LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4;
|
||||
$DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE;
|
||||
$PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4;
|
||||
$PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30;
|
||||
$DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE;
|
||||
$LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : TRUE;
|
||||
$DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE;
|
||||
$PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : 40;
|
||||
$FontSize = $Object->FontSize;
|
||||
$X1 = $Object->GraphAreaX1;
|
||||
$Y1 = $Object->GraphAreaY1;
|
||||
$X2 = $Object->GraphAreaX2;
|
||||
$Y2 = $Object->GraphAreaY2;
|
||||
$RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
|
||||
|
||||
/* Cancel default tick length if ticks not enabled */
|
||||
if ( $DrawTicks == FALSE ) { $TicksLength = 0; }
|
||||
|
||||
/* Data Processing */
|
||||
$Data = $Values->getData();
|
||||
$Palette = $Values->getPalette();
|
||||
|
||||
/* Catch the number of required axis */
|
||||
$LabelSerie = $Data["Abscissa"];
|
||||
if ( $LabelSerie != "" )
|
||||
{ $Points = count($Data["Series"][$LabelSerie]["Data"]); }
|
||||
else
|
||||
{
|
||||
$Points = 0;
|
||||
foreach($Data["Series"] as $SerieName => $DataArray)
|
||||
{ if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } }
|
||||
}
|
||||
|
||||
/* Draw the axis */
|
||||
$CenterX = ($X2-$X1)/2 + $X1;
|
||||
$CenterY = ($Y2-$Y1)/2 + $Y1;
|
||||
|
||||
$EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2);
|
||||
if ( $WriteLabels )
|
||||
$EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength;
|
||||
|
||||
/* Determine the scale if set to automatic */
|
||||
if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO)
|
||||
{
|
||||
if ( $FixedMax != VOID )
|
||||
$Max = $FixedMax;
|
||||
else
|
||||
{
|
||||
$Max = 0;
|
||||
foreach($Data["Series"] as $SerieName => $DataArray)
|
||||
{
|
||||
if ( $SerieName != $LabelSerie )
|
||||
{
|
||||
if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); }
|
||||
}
|
||||
}
|
||||
}
|
||||
$MaxSegments = $EdgeHeight/20;
|
||||
$Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5));
|
||||
|
||||
$Segments = $Scale["Rows"];
|
||||
$SegmentHeight = $Scale["RowHeight"];
|
||||
}
|
||||
|
||||
if ( $LabelMiddle && $SkipLabels == 1 )
|
||||
{ $Axisoffset = (360/$Points)/2; }
|
||||
elseif ( $LabelMiddle && $SkipLabels != 1 )
|
||||
{ $Axisoffset = (360/($Points/$SkipLabels))/2; }
|
||||
elseif ( !$LabelMiddle )
|
||||
{ $Axisoffset = 0; }
|
||||
|
||||
/* Background processing */
|
||||
if ( $DrawBackground )
|
||||
{
|
||||
$RestoreShadow = $Object->Shadow;
|
||||
$Object->Shadow = FALSE;
|
||||
|
||||
if ($BackgroundGradient == NULL)
|
||||
{
|
||||
if ( $Layout == RADAR_LAYOUT_STAR )
|
||||
{
|
||||
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
|
||||
$PointArray = "";
|
||||
for($i=0;$i<=360;$i=$i+(360/$Points))
|
||||
{
|
||||
$PointArray[] = cos(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterX;
|
||||
$PointArray[] = sin(deg2rad($i+$AxisRotation)) * $EdgeHeight + $CenterY;
|
||||
}
|
||||
$Object->drawPolygon($PointArray,$Color);
|
||||
}
|
||||
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
|
||||
{
|
||||
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
|
||||
$Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments;
|
||||
$GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments;
|
||||
$GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments;
|
||||
$GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments;
|
||||
|
||||
if ( $Layout == RADAR_LAYOUT_STAR )
|
||||
{
|
||||
for($j=$Segments;$j>=1;$j--)
|
||||
{
|
||||
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
|
||||
$PointArray = "";
|
||||
|
||||
for($i=0;$i<=360;$i=$i+(360/$Points))
|
||||
{
|
||||
$PointArray[] = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$PointArray[] = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
}
|
||||
$Object->drawPolygon($PointArray,$Color);
|
||||
}
|
||||
}
|
||||
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
|
||||
{
|
||||
for($j=$Segments;$j>=1;$j--)
|
||||
{
|
||||
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
|
||||
$Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
$Object->Shadow = $RestoreShadow;
|
||||
}
|
||||
|
||||
/* Axis to axis lines */
|
||||
$Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha);
|
||||
$ColorDotted = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha*.8, "Ticks"=>2);
|
||||
if ( $Layout == RADAR_LAYOUT_STAR )
|
||||
{
|
||||
for($j=1;$j<=$Segments;$j++)
|
||||
{
|
||||
for($i=0;$i<360;$i=$i+(360/$Points))
|
||||
{
|
||||
$EdgeX1 = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY1 = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
$EdgeX2 = cos(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY2 = sin(deg2rad($i+$AxisRotation+(360/$Points))) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
|
||||
$Object->drawLine($EdgeX1,$EdgeY1,$EdgeX2,$EdgeY2,$Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( $Layout == RADAR_LAYOUT_CIRCLE )
|
||||
{
|
||||
for($j=1;$j<=$Segments;$j++)
|
||||
{
|
||||
$Radius = ($EdgeHeight/$Segments)*$j;
|
||||
$Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $DrawAxisValues )
|
||||
{
|
||||
if ( $LabelsBackground )
|
||||
$Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha);
|
||||
else
|
||||
$Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE);
|
||||
|
||||
if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; }
|
||||
|
||||
$Options["FontName"] = $AxisFontName;
|
||||
$Options["FontSize"] = $AxisFontSize;
|
||||
|
||||
$Angle = 360 / ($Points*2);
|
||||
for($j=1;$j<=$Segments;$j++)
|
||||
{
|
||||
$Label = $j * $SegmentHeight;
|
||||
|
||||
if ( $Layout == RADAR_LAYOUT_CIRCLE )
|
||||
{
|
||||
$EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
}
|
||||
elseif ( $Layout == RADAR_LAYOUT_STAR )
|
||||
{
|
||||
$EdgeX1 = cos(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY1 = sin(deg2rad($AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
$EdgeX2 = cos(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY2 = sin(deg2rad((360 / $Points) + $AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
|
||||
$EdgeX1 = ($EdgeX2 - $EdgeX1)/2 + $EdgeX1;
|
||||
$EdgeY1 = ($EdgeY2 - $EdgeY1)/2 + $EdgeY1;
|
||||
}
|
||||
|
||||
$Object->drawText($EdgeX1,$EdgeY1,$Label,$Options);
|
||||
}
|
||||
}
|
||||
|
||||
/* Axis lines */
|
||||
$ID = 0;
|
||||
for($i=0;$i<360;$i=$i+(360/$Points))
|
||||
{
|
||||
$EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX;
|
||||
$EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY;
|
||||
|
||||
if ($ID % $SkipLabels == 0)
|
||||
{ $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color); }
|
||||
else
|
||||
{ $Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$ColorDotted); }
|
||||
|
||||
if ( $WriteLabels )
|
||||
{
|
||||
$LabelX = cos(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX;
|
||||
$LabelY = sin(deg2rad($i+$AxisRotation+$Axisoffset)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY;
|
||||
|
||||
if ( $LabelSerie != "" )
|
||||
{ $Label = isset($Data["Series"][$LabelSerie]["Data"][$ID]) ? $Data["Series"][$LabelSerie]["Data"][$ID] : ""; }
|
||||
else
|
||||
$Label = $ID;
|
||||
|
||||
if ($ID % $SkipLabels == 0)
|
||||
{
|
||||
if ( $LabelPos == RADAR_LABELS_ROTATED )
|
||||
$Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-($i+$AxisRotation+$Axisoffset))-90,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
|
||||
else
|
||||
{
|
||||
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); }
|
||||
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
$ID++;
|
||||
}
|
||||
|
||||
/* Compute the plots position */
|
||||
$ID = 0; $Plot = "";
|
||||
foreach($Data["Series"] as $SerieName => $DataS)
|
||||
{
|
||||
if ( $SerieName != $LabelSerie )
|
||||
{
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
foreach($DataS["Data"] as $Key => $Value)
|
||||
{
|
||||
$Angle = (360/$Points) * $Key;
|
||||
$Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value;
|
||||
|
||||
$X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX;
|
||||
$Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY;
|
||||
|
||||
$Plot[$ID][] = array($X,$Y,$Value);
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($PointRadius),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$DataS["Description"],$Data["Series"][$LabelSerie]["Data"][$Key]." = ".$Value); }
|
||||
}
|
||||
$ID++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw all that stuff! */
|
||||
foreach($Plot as $ID => $Points)
|
||||
{
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
|
||||
/* Draw the polygons */
|
||||
if ( $DrawPoly )
|
||||
{
|
||||
if ($PolyAlpha != NULL)
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding);
|
||||
|
||||
$PointsArray = "";
|
||||
for($i=0; $i<count($Points);$i++)
|
||||
{ $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; }
|
||||
$Object->drawPolygon($PointsArray,$Color);
|
||||
}
|
||||
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
|
||||
/* Bubble and labels settings */
|
||||
$TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize,"R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"]);
|
||||
$InnerColor = array("R"=>$InnerBubbleR,"G"=>$InnerBubbleG,"B"=>$InnerBubbleB,"Alpha"=>$InnerBubbleAlpha);
|
||||
if ( $OuterBubbleR != VOID )
|
||||
$OuterColor = array("R"=>$OuterBubbleR,"G"=>$OuterBubbleG,"B"=>$OuterBubbleB,"Alpha"=>$OuterBubbleAlpha);
|
||||
else
|
||||
$OuterColor = array("R"=>$Palette[$ID]["R"]+20,"G"=>$Palette[$ID]["G"]+20,"B"=>$Palette[$ID]["B"]+20,"Alpha"=>$Palette[$ID]["Alpha"]);
|
||||
|
||||
/* Loop to the starting points if asked */
|
||||
if ( $LineLoopStart && $DrawLines )
|
||||
$Object->drawLine($Points[count($Points)-1][0],$Points[count($Points)-1][1],$Points[0][0],$Points[0][1],$Color);
|
||||
|
||||
/* Draw the lines & points */
|
||||
for($i=0; $i<count($Points);$i++)
|
||||
{
|
||||
if ( $DrawLines && $i < count($Points)-1)
|
||||
$Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color);
|
||||
|
||||
if ( $DrawPoints )
|
||||
$Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color);
|
||||
|
||||
if ( $WriteValuesInBubble && $WriteValues )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($Points[$i][0],$Points[$i][1],$ValueFontName,$ValueFontSize,0,$Points[$i][2]);
|
||||
$Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $ValuePadding*2)/2);
|
||||
|
||||
$this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius+$OuterBubbleRadius,$OuterColor);
|
||||
$this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius,$InnerColor);
|
||||
}
|
||||
|
||||
if ( $WriteValues )
|
||||
$this->pChartObject->drawText($Points[$i][0]-1,$Points[$i][1]-1,$Points[$i][2],$TextSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Draw a radar chart */
|
||||
function drawPolar($Object,$Values,$Format="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$FixedMax = isset($Format["FixedMax"]) ? $Format["FixedMax"] : VOID;
|
||||
$AxisR = isset($Format["AxisR"]) ? $Format["AxisR"] : 60;
|
||||
$AxisG = isset($Format["AxisG"]) ? $Format["AxisG"] : 60;
|
||||
$AxisB = isset($Format["AxisB"]) ? $Format["AxisB"] : 60;
|
||||
$AxisAlpha = isset($Format["AxisAlpha"]) ? $Format["AxisAlpha"] : 50;
|
||||
$AxisRotation = isset($Format["AxisRotation"]) ? $Format["AxisRotation"] : -90;
|
||||
$DrawTicks = isset($Format["DrawTicks"]) ? $Format["DrawTicks"] : TRUE;
|
||||
$TicksLength = isset($Format["TicksLength"]) ? $Format["TicksLength"] : 2;
|
||||
$DrawAxisValues = isset($Format["DrawAxisValues"]) ? $Format["DrawAxisValues"] : TRUE;
|
||||
$AxisBoxRounded = isset($Format["AxisBoxRounded"]) ? $Format["AxisBoxRounded"] : TRUE;
|
||||
$AxisFontName = isset($Format["FontName"]) ? $Format["FontName"] : $this->pChartObject->FontName;
|
||||
$AxisFontSize = isset($Format["FontSize"]) ? $Format["FontSize"] : $this->pChartObject->FontSize;
|
||||
$WriteValues = isset($Format["WriteValues"]) ? $Format["WriteValues"] : FALSE;
|
||||
$WriteValuesInBubble = isset($Format["WriteValuesInBubble"]) ? $Format["WriteValuesInBubble"] : TRUE;
|
||||
$ValueFontName = isset($Format["ValueFontName"]) ? $Format["ValueFontName"] : $this->pChartObject->FontName;
|
||||
$ValueFontSize = isset($Format["ValueFontSize"]) ? $Format["ValueFontSize"] : $this->pChartObject->FontSize;
|
||||
$ValuePadding = isset($Format["ValuePadding"]) ? $Format["ValuePadding"] : 4;
|
||||
$OuterBubbleRadius = isset($Format["OuterBubbleRadius"]) ? $Format["OuterBubbleRadius"] : 2;
|
||||
$OuterBubbleR = isset($Format["OuterBubbleR"]) ? $Format["OuterBubbleR"] : VOID;
|
||||
$OuterBubbleG = isset($Format["OuterBubbleG"]) ? $Format["OuterBubbleG"] : VOID;
|
||||
$OuterBubbleB = isset($Format["OuterBubbleB"]) ? $Format["OuterBubbleB"] : VOID;
|
||||
$OuterBubbleAlpha = isset($Format["OuterBubbleAlpha"]) ? $Format["OuterBubbleAlpha"] : 100;
|
||||
$InnerBubbleR = isset($Format["InnerBubbleR"]) ? $Format["InnerBubbleR"] : 255;
|
||||
$InnerBubbleG = isset($Format["InnerBubbleG"]) ? $Format["InnerBubbleG"] : 255;
|
||||
$InnerBubbleB = isset($Format["InnerBubbleB"]) ? $Format["InnerBubbleB"] : 255;
|
||||
$InnerBubbleAlpha = isset($Format["InnerBubbleAlpha"]) ? $Format["InnerBubbleAlpha"] : 100;
|
||||
$DrawBackground = isset($Format["DrawBackground"]) ? $Format["DrawBackground"] : TRUE;
|
||||
$BackgroundR = isset($Format["BackgroundR"]) ? $Format["BackgroundR"] : 255;
|
||||
$BackgroundG = isset($Format["BackgroundG"]) ? $Format["BackgroundG"] : 255;
|
||||
$BackgroundB = isset($Format["BackgroundB"]) ? $Format["BackgroundB"] : 255;
|
||||
$BackgroundAlpha = isset($Format["BackgroundAlpha"]) ? $Format["BackgroundAlpha"] : 50;
|
||||
$BackgroundGradient= isset($Format["BackgroundGradient"]) ? $Format["BackgroundGradient"] : NULL;
|
||||
$AxisSteps = isset($Format["AxisSteps"]) ? $Format["AxisSteps"] : 20;
|
||||
$SegmentHeight = isset($Format["SegmentHeight"]) ? $Format["SegmentHeight"] : SEGMENT_HEIGHT_AUTO;
|
||||
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 4;
|
||||
$WriteLabels = isset($Format["WriteLabels"]) ? $Format["WriteLabels"] : TRUE;
|
||||
$LabelsBackground = isset($Format["LabelsBackground"]) ? $Format["LabelsBackground"] : TRUE;
|
||||
$LabelsBGR = isset($Format["LabelsBGR"]) ? $Format["LabelsBGR"] : 255;
|
||||
$LabelsBGG = isset($Format["LabelsBGR"]) ? $Format["LabelsBGG"] : 255;
|
||||
$LabelsBGB = isset($Format["LabelsBGR"]) ? $Format["LabelsBGB"] : 255;
|
||||
$LabelsBGAlpha = isset($Format["LabelsBGAlpha"]) ? $Format["LabelsBGAlpha"] : 50;
|
||||
$LabelPos = isset($Format["LabelPos"]) ? $Format["LabelPos"] : RADAR_LABELS_ROTATED;
|
||||
$LabelPadding = isset($Format["LabelPadding"]) ? $Format["LabelPadding"] : 4;
|
||||
$DrawPoints = isset($Format["DrawPoints"]) ? $Format["DrawPoints"] : TRUE;
|
||||
$PointRadius = isset($Format["PointRadius"]) ? $Format["PointRadius"] : 4;
|
||||
$PointSurrounding = isset($Format["PointRadius"]) ? $Format["PointRadius"] : -30;
|
||||
$DrawLines = isset($Format["DrawLines"]) ? $Format["DrawLines"] : TRUE;
|
||||
$LineLoopStart = isset($Format["LineLoopStart"]) ? $Format["LineLoopStart"] : FALSE;
|
||||
$DrawPoly = isset($Format["DrawPoly"]) ? $Format["DrawPoly"] : FALSE;
|
||||
$PolyAlpha = isset($Format["PolyAlpha"]) ? $Format["PolyAlpha"] : NULL;
|
||||
$FontSize = $Object->FontSize;
|
||||
$X1 = $Object->GraphAreaX1;
|
||||
$Y1 = $Object->GraphAreaY1;
|
||||
$X2 = $Object->GraphAreaX2;
|
||||
$Y2 = $Object->GraphAreaY2;
|
||||
$RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
|
||||
|
||||
if ( $AxisBoxRounded ) { $DrawAxisValues = TRUE; }
|
||||
|
||||
/* Cancel default tick length if ticks not enabled */
|
||||
if ( $DrawTicks == FALSE ) { $TicksLength = 0; }
|
||||
|
||||
/* Data Processing */
|
||||
$Data = $Values->getData();
|
||||
$Palette = $Values->getPalette();
|
||||
|
||||
/* Catch the number of required axis */
|
||||
$LabelSerie = $Data["Abscissa"];
|
||||
if ( $LabelSerie != "" )
|
||||
{ $Points = count($Data["Series"][$LabelSerie]["Data"]); }
|
||||
else
|
||||
{
|
||||
$Points = 0;
|
||||
foreach($Data["Series"] as $SerieName => $DataArray)
|
||||
{ if ( count($DataArray["Data"]) > $Points ) { $Points = count($DataArray["Data"]); } }
|
||||
}
|
||||
|
||||
/* Draw the axis */
|
||||
$CenterX = ($X2-$X1)/2 + $X1;
|
||||
$CenterY = ($Y2-$Y1)/2 + $Y1;
|
||||
|
||||
$EdgeHeight = min(($X2-$X1)/2,($Y2-$Y1)/2);
|
||||
if ( $WriteLabels )
|
||||
$EdgeHeight = $EdgeHeight - $FontSize - $LabelPadding - $TicksLength;
|
||||
|
||||
/* Determine the scale if set to automatic */
|
||||
if ( $SegmentHeight == SEGMENT_HEIGHT_AUTO)
|
||||
{
|
||||
if ( $FixedMax != VOID )
|
||||
$Max = $FixedMax;
|
||||
else
|
||||
{
|
||||
$Max = 0;
|
||||
foreach($Data["Series"] as $SerieName => $DataArray)
|
||||
{
|
||||
if ( $SerieName != $LabelSerie )
|
||||
{
|
||||
if ( max($DataArray["Data"]) > $Max ) { $Max = max($DataArray["Data"]); }
|
||||
}
|
||||
}
|
||||
}
|
||||
$MaxSegments = $EdgeHeight/20;
|
||||
$Scale = $Object->computeScale(0,$Max,$MaxSegments,array(1,2,5));
|
||||
|
||||
$Segments = $Scale["Rows"];
|
||||
$SegmentHeight = $Scale["RowHeight"];
|
||||
}
|
||||
|
||||
|
||||
/* Background processing */
|
||||
if ( $DrawBackground )
|
||||
{
|
||||
$RestoreShadow = $Object->Shadow;
|
||||
$Object->Shadow = FALSE;
|
||||
|
||||
if ($BackgroundGradient == NULL)
|
||||
{
|
||||
$Color = array("R"=>$BackgroundR,"G"=>$BackgroundG,"B"=>$BackgroundB,"Alpha"=>$BackgroundAlpha);
|
||||
$Object->drawFilledCircle($CenterX,$CenterY,$EdgeHeight,$Color);
|
||||
}
|
||||
else
|
||||
{
|
||||
$GradientROffset = ($BackgroundGradient["EndR"] - $BackgroundGradient["StartR"]) / $Segments;
|
||||
$GradientGOffset = ($BackgroundGradient["EndG"] - $BackgroundGradient["StartG"]) / $Segments;
|
||||
$GradientBOffset = ($BackgroundGradient["EndB"] - $BackgroundGradient["StartB"]) / $Segments;
|
||||
$GradientAlphaOffset = ($BackgroundGradient["EndAlpha"] - $BackgroundGradient["StartAlpha"]) / $Segments;
|
||||
|
||||
for($j=$Segments;$j>=1;$j--)
|
||||
{
|
||||
$Color = array("R"=>$BackgroundGradient["StartR"]+$GradientROffset*$j,"G"=>$BackgroundGradient["StartG"]+$GradientGOffset*$j,"B"=>$BackgroundGradient["StartB"]+$GradientBOffset*$j,"Alpha"=>$BackgroundGradient["StartAlpha"]+$GradientAlphaOffset*$j);
|
||||
$Object->drawFilledCircle($CenterX,$CenterY,($EdgeHeight/$Segments)*$j,$Color);
|
||||
}
|
||||
}
|
||||
$Object->Shadow = $RestoreShadow;
|
||||
}
|
||||
|
||||
/* Axis to axis lines */
|
||||
$Color = array("R"=>$AxisR,"G"=>$AxisG,"B"=>$AxisB,"Alpha"=>$AxisAlpha);
|
||||
for($j=1;$j<=$Segments;$j++)
|
||||
{
|
||||
$Radius = ($EdgeHeight/$Segments)*$j;
|
||||
$Object->drawCircle($CenterX,$CenterY,$Radius,$Radius,$Color);
|
||||
}
|
||||
|
||||
if ( $DrawAxisValues )
|
||||
{
|
||||
if ( $LabelsBackground )
|
||||
$Options = array("DrawBox"=>TRUE, "Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxR"=>$LabelsBGR,"BoxG"=>$LabelsBGG,"BoxB"=>$LabelsBGB,"BoxAlpha"=>$LabelsBGAlpha);
|
||||
else
|
||||
$Options = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE);
|
||||
|
||||
if ( $AxisBoxRounded ) { $Options["BoxRounded"] = TRUE; }
|
||||
|
||||
$Options["FontName"] = $AxisFontName;
|
||||
$Options["FontSize"] = $AxisFontSize;
|
||||
|
||||
$Angle = 360 / ($Points*2);
|
||||
for($j=1;$j<=$Segments;$j++)
|
||||
{
|
||||
$EdgeX1 = cos(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterX;
|
||||
$EdgeY1 = sin(deg2rad($Angle+$AxisRotation)) * ($EdgeHeight/$Segments)*$j + $CenterY;
|
||||
$Label = $j*$SegmentHeight;
|
||||
|
||||
$Object->drawText($EdgeX1,$EdgeY1,$Label,$Options);
|
||||
}
|
||||
}
|
||||
|
||||
/* Axis lines */
|
||||
$ID = 0;
|
||||
for($i=0;$i<=359;$i=$i+$AxisSteps)
|
||||
{
|
||||
$EdgeX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterX;
|
||||
$EdgeY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$TicksLength) + $CenterY;
|
||||
|
||||
$Object->drawLine($CenterX,$CenterY,$EdgeX,$EdgeY,$Color);
|
||||
|
||||
if ( $WriteLabels )
|
||||
{
|
||||
$LabelX = cos(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterX;
|
||||
$LabelY = sin(deg2rad($i+$AxisRotation)) * ($EdgeHeight+$LabelPadding+$TicksLength) + $CenterY;
|
||||
$Label = $i."°";
|
||||
|
||||
if ( $LabelPos == RADAR_LABELS_ROTATED )
|
||||
$Object->drawText($LabelX,$LabelY,$Label,array("Angle"=>(360-$i),"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));
|
||||
else
|
||||
{
|
||||
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMMIDDLE)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMLEFT)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT)); }
|
||||
if ( (floor($LabelX) > floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPLEFT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) < floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) == floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_MIDDLERIGHT)); }
|
||||
if ( (floor($LabelX) < floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPRIGHT)); }
|
||||
if ( (floor($LabelX) == floor($CenterX)) && (floor($LabelY) > floor($CenterY)) ) { $Object->drawText($LabelX,$LabelY,$Label,array("Align"=>TEXT_ALIGN_TOPMIDDLE)); }
|
||||
}
|
||||
}
|
||||
$ID++;
|
||||
}
|
||||
|
||||
/* Compute the plots position */
|
||||
$ID = 0; $Plot = "";
|
||||
foreach($Data["Series"] as $SerieName => $DataSet)
|
||||
{
|
||||
if ( $SerieName != $LabelSerie )
|
||||
{
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
foreach($DataSet["Data"] as $Key => $Value)
|
||||
{
|
||||
$Angle = $Data["Series"][$LabelSerie]["Data"][$Key];
|
||||
$Length = ($EdgeHeight/($Segments*$SegmentHeight))*$Value;
|
||||
|
||||
$X = cos(deg2rad($Angle+$AxisRotation)) * $Length + $CenterX;
|
||||
$Y = sin(deg2rad($Angle+$AxisRotation)) * $Length + $CenterY;
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("CIRCLE",floor($X).",".floor($Y).",".floor($PointRadius),$this->pChartObject->toHTMLColor($Palette[$ID]["R"],$Palette[$ID]["G"],$Palette[$ID]["B"]),$DataSet["Description"],$Data["Series"][$LabelSerie]["Data"][$Key]."° = ".$Value); }
|
||||
|
||||
$Plot[$ID][] = array($X,$Y,$Value);
|
||||
}
|
||||
$ID++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw all that stuff! */
|
||||
foreach($Plot as $ID => $Points)
|
||||
{
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
|
||||
/* Draw the polygons */
|
||||
if ( $DrawPoly )
|
||||
{
|
||||
if ($PolyAlpha != NULL)
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$PolyAlpha,"Surrounding"=>$PointSurrounding);
|
||||
|
||||
$PointsArray = "";
|
||||
for($i=0; $i<count($Points);$i++)
|
||||
{ $PointsArray[] = $Points[$i][0]; $PointsArray[] = $Points[$i][1]; }
|
||||
|
||||
$Object->drawPolygon($PointsArray,$Color);
|
||||
}
|
||||
|
||||
$Color = array("R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"],"Alpha"=>$Palette[$ID]["Alpha"],"Surrounding"=>$PointSurrounding);
|
||||
|
||||
/* Bubble and labels settings */
|
||||
$TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"FontName"=>$ValueFontName,"FontSize"=>$ValueFontSize,"R"=>$Palette[$ID]["R"],"G"=>$Palette[$ID]["G"],"B"=>$Palette[$ID]["B"]);
|
||||
$InnerColor = array("R"=>$InnerBubbleR,"G"=>$InnerBubbleG,"B"=>$InnerBubbleB,"Alpha"=>$InnerBubbleAlpha);
|
||||
if ( $OuterBubbleR != VOID )
|
||||
$OuterColor = array("R"=>$OuterBubbleR,"G"=>$OuterBubbleG,"B"=>$OuterBubbleB,"Alpha"=>$OuterBubbleAlpha);
|
||||
else
|
||||
$OuterColor = array("R"=>$Palette[$ID]["R"]+20,"G"=>$Palette[$ID]["G"]+20,"B"=>$Palette[$ID]["B"]+20,"Alpha"=>$Palette[$ID]["Alpha"]);
|
||||
|
||||
/* Loop to the starting points if asked */
|
||||
if ( $LineLoopStart && $DrawLines )
|
||||
$Object->drawLine($Points[count($Points)-1][0],$Points[count($Points)-1][1],$Points[0][0],$Points[0][1],$Color);
|
||||
|
||||
/* Draw the lines & points */
|
||||
for($i=0; $i<count($Points);$i++)
|
||||
{
|
||||
if ( $DrawLines && $i < count($Points)-1)
|
||||
$Object->drawLine($Points[$i][0],$Points[$i][1],$Points[$i+1][0],$Points[$i+1][1],$Color);
|
||||
|
||||
if ( $DrawPoints )
|
||||
$Object->drawFilledCircle($Points[$i][0],$Points[$i][1],$PointRadius,$Color);
|
||||
|
||||
if ( $WriteValuesInBubble && $WriteValues )
|
||||
{
|
||||
$TxtPos = $this->pChartObject->getTextBox($Points[$i][0],$Points[$i][1],$ValueFontName,$ValueFontSize,0,$Points[$i][2]);
|
||||
$Radius = floor(($TxtPos[1]["X"] - $TxtPos[0]["X"] + $ValuePadding*2)/2);
|
||||
|
||||
$this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius+$OuterBubbleRadius,$OuterColor);
|
||||
$this->pChartObject->drawFilledCircle($Points[$i][0],$Points[$i][1],$Radius,$InnerColor);
|
||||
}
|
||||
|
||||
if ( $WriteValues )
|
||||
$this->pChartObject->drawText($Points[$i][0]-1,$Points[$i][1]-1,$Points[$i][2],$TextSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pSplit - class to draw spline splitted charts
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("TEXT_POS_TOP" , 690001);
|
||||
define("TEXT_POS_RIGHT" , 690002);
|
||||
|
||||
/* pSplit class definition */
|
||||
class pSplit
|
||||
{
|
||||
var $pChartObject;
|
||||
|
||||
/* Class creator */
|
||||
function pSplit()
|
||||
{ }
|
||||
|
||||
/* Create the encoded string */
|
||||
function drawSplitPath($Object,$Values,$Format="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$Spacing = isset($Format["Spacing"]) ? $Format["Spacing"] : 20;
|
||||
$TextPadding = isset($Format["TextPadding"]) ? $Format["TextPadding"] : 2;
|
||||
$TextPos = isset($Format["TextPos"]) ? $Format["TextPos"] : TEXT_POS_TOP;
|
||||
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : NULL;
|
||||
$Force = isset($Format["Force"]) ? $Format["Force"] : 70;
|
||||
$Segments = isset($Format["Segments"]) ? $Format["Segments"] : 15;
|
||||
$FontSize = $Object->FontSize;
|
||||
$X1 = $Object->GraphAreaX1;
|
||||
$Y1 = $Object->GraphAreaY1;
|
||||
$X2 = $Object->GraphAreaX2;
|
||||
$Y2 = $Object->GraphAreaY2;
|
||||
|
||||
/* Data Processing */
|
||||
$Data = $Values->getData();
|
||||
$Palette = $Values->getPalette();
|
||||
|
||||
$LabelSerie = $Data["Abscissa"];
|
||||
$DataSerie = "";
|
||||
|
||||
foreach($Data["Series"] as $SerieName => $Value)
|
||||
{ if ( $SerieName != $LabelSerie && $DataSerie == "" ) { $DataSerie = $SerieName; } }
|
||||
|
||||
$DataSerieSum = array_sum($Data["Series"][$DataSerie]["Data"]);
|
||||
$DataSerieCount = count($Data["Series"][$DataSerie]["Data"]);
|
||||
|
||||
/* Scale Processing */
|
||||
if ( $TextPos == TEXT_POS_RIGHT )
|
||||
$YScale = (($Y2-$Y1) - (($DataSerieCount+1)*$Spacing)) / $DataSerieSum;
|
||||
else
|
||||
$YScale = (($Y2-$Y1) - ($DataSerieCount*$Spacing)) / $DataSerieSum;
|
||||
$LeftHeight = $DataSerieSum * $YScale;
|
||||
|
||||
/* Re-compute graph width depending of the text mode choosen */
|
||||
if ( $TextPos == TEXT_POS_RIGHT )
|
||||
{
|
||||
$MaxWidth = 0;
|
||||
foreach($Data["Series"][$LabelSerie]["Data"] as $Key => $Label)
|
||||
{
|
||||
$Boundardies = $Object->getTextBox(0,0,$Object->FontName,$Object->FontSize,0,$Label);
|
||||
if ( $Boundardies[1]["X"] > $MaxWidth ) { $MaxWidth = $Boundardies[1]["X"] + $TextPadding*2; }
|
||||
}
|
||||
$X2 = $X2 - $MaxWidth;
|
||||
}
|
||||
|
||||
/* Drawing */
|
||||
$LeftY = ((($Y2-$Y1) / 2) + $Y1) - ($LeftHeight/2);
|
||||
$RightY = $Y1;
|
||||
$VectorX = (($X2-$X1) / 2);
|
||||
|
||||
foreach($Data["Series"][$DataSerie]["Data"] as $Key => $Value)
|
||||
{
|
||||
if ( isset($Data["Series"][$LabelSerie]["Data"][$Key]) )
|
||||
$Label = $Data["Series"][$LabelSerie]["Data"][$Key];
|
||||
else
|
||||
$Label = "-";
|
||||
|
||||
$LeftY1 = $LeftY;
|
||||
$LeftY2 = $LeftY + $Value * $YScale;
|
||||
|
||||
$RightY1 = $RightY + $Spacing;
|
||||
$RightY2 = $RightY + $Spacing + $Value * $YScale;;
|
||||
|
||||
$Settings = array("R"=>$Palette[$Key]["R"],"G"=>$Palette[$Key]["G"],"B"=>$Palette[$Key]["B"],"Alpha"=>$Palette[$Key]["Alpha"],"NoDraw"=>TRUE,"Segments"=>$Segments,"Surrounding"=>$Surrounding);
|
||||
|
||||
$PolyGon = "";
|
||||
|
||||
$Angle = $Object->getAngle($X2,$RightY1,$X1,$LeftY1);
|
||||
$VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 + $X1;
|
||||
$VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1;
|
||||
$VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 + $X1;
|
||||
$VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY1-$LeftY1)/2 + $LeftY1;
|
||||
|
||||
$Points = $Object->drawBezier($X1,$LeftY1,$X2,$RightY1,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings);
|
||||
foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; }
|
||||
|
||||
|
||||
$Angle = $Object->getAngle($X2,$RightY2,$X1,$LeftY2);
|
||||
$VectorX1 = cos(deg2rad($Angle+90)) * $Force + ($X2-$X1)/2 +$X1;
|
||||
$VectorY1 = sin(deg2rad($Angle+90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2;
|
||||
$VectorX2 = cos(deg2rad($Angle-90)) * $Force + ($X2-$X1)/2 +$X1;
|
||||
$VectorY2 = sin(deg2rad($Angle-90)) * $Force + ($RightY2-$LeftY2)/2 + $LeftY2;
|
||||
|
||||
$Points = $Object->drawBezier($X1,$LeftY2,$X2,$RightY2,$VectorX1,$VectorY1,$VectorX2,$VectorY2,$Settings);
|
||||
$Points = array_reverse($Points);
|
||||
foreach($Points as $Key => $Pos) { $PolyGon[] = $Pos["X"]; $PolyGon[] = $Pos["Y"]; }
|
||||
|
||||
$Object->drawPolygon($PolyGon,$Settings);
|
||||
|
||||
if ( $TextPos == TEXT_POS_RIGHT )
|
||||
$Object->drawText($X2+$TextPadding,($RightY2-$RightY1)/2+$RightY1,$Label,array("Align"=>TEXT_ALIGN_MIDDLELEFT));
|
||||
else
|
||||
$Object->drawText($X2,$RightY1-$TextPadding,$Label,array("Align"=>TEXT_ALIGN_BOTTOMRIGHT));
|
||||
|
||||
$LeftY = $LeftY2;
|
||||
$RightY = $RightY2;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,868 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pSpring - class to draw spring graphs
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("NODE_TYPE_FREE" , 690001);
|
||||
define("NODE_TYPE_CENTRAL" , 690002);
|
||||
|
||||
define("NODE_SHAPE_CIRCLE" , 690011);
|
||||
define("NODE_SHAPE_TRIANGLE" , 690012);
|
||||
define("NODE_SHAPE_SQUARE" , 690013);
|
||||
|
||||
define("ALGORITHM_RANDOM" , 690021);
|
||||
define("ALGORITHM_WEIGHTED" , 690022);
|
||||
define("ALGORITHM_CIRCULAR" , 690023);
|
||||
define("ALGORITHM_CENTRAL" , 690024);
|
||||
|
||||
define("LABEL_CLASSIC" , 690031);
|
||||
define("LABEL_LIGHT" , 690032);
|
||||
|
||||
/* pSpring class definition */
|
||||
class pSpring
|
||||
{
|
||||
var $History;
|
||||
var $pChartObject;
|
||||
var $Data;
|
||||
var $Links;
|
||||
var $X1;
|
||||
var $Y1;
|
||||
var $X2;
|
||||
var $Y2;
|
||||
var $AutoComputeFreeZone;
|
||||
var $Labels;
|
||||
|
||||
/* Class creator */
|
||||
function pSpring()
|
||||
{
|
||||
/* Initialise data arrays */
|
||||
$this->Data = "";
|
||||
$this->Links = "";
|
||||
|
||||
/* Set nodes defaults */
|
||||
$this->Default["R"] = 255;
|
||||
$this->Default["G"] = 255;
|
||||
$this->Default["B"] = 255;
|
||||
$this->Default["Alpha"] = 100;
|
||||
$this->Default["BorderR"] = 0;
|
||||
$this->Default["BorderG"] = 0;
|
||||
$this->Default["BorderB"] = 0;
|
||||
$this->Default["BorderAlpha"] = 100;
|
||||
$this->Default["Surrounding"] = NULL;
|
||||
$this->Default["BackgroundR"] = 255;
|
||||
$this->Default["BackgroundG"] = 255;
|
||||
$this->Default["BackgroundB"] = 255;
|
||||
$this->Default["BackgroundAlpha"] = 0;
|
||||
$this->Default["Force"] = 1;
|
||||
$this->Default["NodeType"] = NODE_TYPE_FREE;
|
||||
$this->Default["Size"] = 5;
|
||||
$this->Default["Shape"] = NODE_SHAPE_CIRCLE;
|
||||
$this->Default["FreeZone"] = 40;
|
||||
$this->Default["LinkR"] = 0;
|
||||
$this->Default["LinkG"] = 0;
|
||||
$this->Default["LinkB"] = 0;
|
||||
$this->Default["LinkAlpha"] = 0;
|
||||
|
||||
$this->Labels["Type"] = LABEL_CLASSIC;
|
||||
$this->Labels["R"] = 0;
|
||||
$this->Labels["G"] = 0;
|
||||
$this->Labels["B"] = 0;
|
||||
$this->Labels["Alpha"] = 100;
|
||||
|
||||
$this->AutoComputeFreeZone = FALSE;
|
||||
}
|
||||
|
||||
/* Set default links options */
|
||||
function setLinkDefaults($Settings="")
|
||||
{
|
||||
if ( isset($Settings["R"]) ) { $this->Default["LinkR"] = $Settings["R"]; }
|
||||
if ( isset($Settings["G"]) ) { $this->Default["LinkG"] = $Settings["G"]; }
|
||||
if ( isset($Settings["B"]) ) { $this->Default["LinkB"] = $Settings["B"]; }
|
||||
if ( isset($Settings["Alpha"]) ) { $this->Default["LinkAlpha"] = $Settings["Alpha"]; }
|
||||
}
|
||||
|
||||
/* Set default links options */
|
||||
function setLabelsSettings($Settings="")
|
||||
{
|
||||
if ( isset($Settings["Type"]) ) { $this->Labels["Type"] = $Settings["Type"]; }
|
||||
if ( isset($Settings["R"]) ) { $this->Labels["R"] = $Settings["R"]; }
|
||||
if ( isset($Settings["G"]) ) { $this->Labels["G"] = $Settings["G"]; }
|
||||
if ( isset($Settings["B"]) ) { $this->Labels["B"] = $Settings["B"]; }
|
||||
if ( isset($Settings["Alpha"]) ) { $this->Labels["Alpha"] = $Settings["Alpha"]; }
|
||||
}
|
||||
|
||||
/* Auto compute the FreeZone size based on the number of connections */
|
||||
function autoFreeZone()
|
||||
{
|
||||
/* Check connections reciprocity */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{ $this->Data[$Key]["FreeZone"] = count($Settings["Connections"])*10 + 20; }
|
||||
else
|
||||
{ $this->Data[$Key]["FreeZone"] = 20; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Set link properties */
|
||||
function linkProperties($FromNode,$ToNode,$Settings)
|
||||
{
|
||||
if ( !isset($this->Data[$FromNode]) ) { return(0); }
|
||||
if ( !isset($this->Data[$ToNode]) ) { return(0); }
|
||||
|
||||
$R = isset($Settings["R"]) ? $Settings["R"] : 0;
|
||||
$G = isset($Settings["G"]) ? $Settings["G"] : 0;
|
||||
$B = isset($Settings["B"]) ? $Settings["B"] : 0;
|
||||
$Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : 100;
|
||||
$Name = isset($Settings["Name"]) ? $Settings["Name"] : NULL;
|
||||
$Ticks = isset($Settings["Ticks"]) ? $Settings["Ticks"] : NULL;
|
||||
|
||||
$this->Links[$FromNode][$ToNode]["R"] = $R; $this->Links[$ToNode][$FromNode]["R"] = $R;
|
||||
$this->Links[$FromNode][$ToNode]["G"] = $G; $this->Links[$ToNode][$FromNode]["G"] = $G;
|
||||
$this->Links[$FromNode][$ToNode]["B"] = $B; $this->Links[$ToNode][$FromNode]["B"] = $B;
|
||||
$this->Links[$FromNode][$ToNode]["Alpha"] = $Alpha; $this->Links[$ToNode][$FromNode]["Alpha"] = $Alpha;
|
||||
$this->Links[$FromNode][$ToNode]["Name"] = $Name; $this->Links[$ToNode][$FromNode]["Name"] = $Name;
|
||||
$this->Links[$FromNode][$ToNode]["Ticks"] = $Ticks; $this->Links[$ToNode][$FromNode]["Ticks"] = $Ticks;
|
||||
}
|
||||
|
||||
function setNodeDefaults($Settings="")
|
||||
{
|
||||
if ( isset($Settings["R"]) ) { $this->Default["R"] = $Settings["R"]; }
|
||||
if ( isset($Settings["G"]) ) { $this->Default["G"] = $Settings["G"]; }
|
||||
if ( isset($Settings["B"]) ) { $this->Default["B"] = $Settings["B"]; }
|
||||
if ( isset($Settings["Alpha"]) ) { $this->Default["Alpha"] = $Settings["Alpha"]; }
|
||||
if ( isset($Settings["BorderR"]) ) { $this->Default["BorderR"] = $Settings["BorderR"]; }
|
||||
if ( isset($Settings["BorderG"]) ) { $this->Default["BorderG"] = $Settings["BorderG"]; }
|
||||
if ( isset($Settings["BorderB"]) ) { $this->Default["BorderB"] = $Settings["BorderB"]; }
|
||||
if ( isset($Settings["BorderAlpha"]) ) { $this->Default["BorderAlpha"] = $Settings["BorderAlpha"]; }
|
||||
if ( isset($Settings["Surrounding"]) ) { $this->Default["Surrounding"] = $Settings["Surrounding"]; }
|
||||
if ( isset($Settings["BackgroundR"]) ) { $this->Default["BackgroundR"] = $Settings["BackgroundR"]; }
|
||||
if ( isset($Settings["BackgroundG"]) ) { $this->Default["BackgroundG"] = $Settings["BackgroundG"]; }
|
||||
if ( isset($Settings["BackgroundB"]) ) { $this->Default["BackgroundB"] = $Settings["BackgroundB"]; }
|
||||
if ( isset($Settings["BackgroundAlpha"]) ) { $this->Default["BackgroundAlpha"] = $Settings["BackgroundAlpha"]; }
|
||||
if ( isset($Settings["NodeType"]) ) { $this->Default["NodeType"] = $Settings["NodeType"]; }
|
||||
if ( isset($Settings["Size"]) ) { $this->Default["Size"] = $Settings["Size"]; }
|
||||
if ( isset($Settings["Shape"]) ) { $this->Default["Shape"] = $Settings["Shape"]; }
|
||||
if ( isset($Settings["FreeZone"]) ) { $this->Default["FreeZone"] = $Settings["FreeZone"]; }
|
||||
}
|
||||
|
||||
/* Add a node */
|
||||
function addNode($NodeID,$Settings="")
|
||||
{
|
||||
/* if the node already exists, ignore */
|
||||
if (isset($this->Data[$NodeID])) { return(0); }
|
||||
|
||||
$Name = isset($Settings["Name"]) ? $Settings["Name"] : "Node ".$NodeID;
|
||||
$Connections = isset($Settings["Connections"]) ? $Settings["Connections"] : NULL;
|
||||
|
||||
$R = isset($Settings["R"]) ? $Settings["R"] : $this->Default["R"];
|
||||
$G = isset($Settings["G"]) ? $Settings["G"] : $this->Default["G"];
|
||||
$B = isset($Settings["B"]) ? $Settings["B"] : $this->Default["B"];
|
||||
$Alpha = isset($Settings["Alpha"]) ? $Settings["Alpha"] : $this->Default["Alpha"];
|
||||
$BorderR = isset($Settings["BorderR"]) ? $Settings["BorderR"] : $this->Default["BorderR"];
|
||||
$BorderG = isset($Settings["BorderG"]) ? $Settings["BorderG"] : $this->Default["BorderG"];
|
||||
$BorderB = isset($Settings["BorderB"]) ? $Settings["BorderB"] : $this->Default["BorderB"];
|
||||
$BorderAlpha = isset($Settings["BorderAlpha"]) ? $Settings["BorderAlpha"] : $this->Default["BorderAlpha"];
|
||||
$Surrounding = isset($Settings["Surrounding"]) ? $Settings["Surrounding"] : $this->Default["Surrounding"];
|
||||
$BackgroundR = isset($Settings["BackgroundR"]) ? $Settings["BackgroundR"] : $this->Default["BackgroundR"];
|
||||
$BackgroundG = isset($Settings["BackgroundG"]) ? $Settings["BackgroundG"] : $this->Default["BackgroundG"];
|
||||
$BackgroundB = isset($Settings["BackgroundB"]) ? $Settings["BackgroundB"] : $this->Default["BackgroundB"];
|
||||
$BackgroundAlpha = isset($Settings["BackgroundAlpha"]) ? $Settings["BackgroundAlpha"] : $this->Default["BackgroundAlpha"];
|
||||
$Force = isset($Settings["Force"]) ? $Settings["Force"] : $this->Default["Force"];
|
||||
$NodeType = isset($Settings["NodeType"]) ? $Settings["NodeType"] : $this->Default["NodeType"];
|
||||
$Size = isset($Settings["Size"]) ? $Settings["Size"] : $this->Default["Size"];
|
||||
$Shape = isset($Settings["Shape"]) ? $Settings["Shape"] : $this->Default["Shape"];
|
||||
$FreeZone = isset($Settings["FreeZone"]) ? $Settings["FreeZone"] : $this->Default["FreeZone"];
|
||||
|
||||
if ( $Surrounding != NULL ) { $BorderR = $R + $Surrounding; $BorderG = $G + $Surrounding; $BorderB = $B + $Surrounding; }
|
||||
|
||||
$this->Data[$NodeID]["R"] = $R; $this->Data[$NodeID]["G"] = $G; $this->Data[$NodeID]["B"] = $B; $this->Data[$NodeID]["Alpha"] = $Alpha;
|
||||
$this->Data[$NodeID]["BorderR"] = $BorderR; $this->Data[$NodeID]["BorderG"] = $BorderG; $this->Data[$NodeID]["BorderB"] = $BorderB; $this->Data[$NodeID]["BorderAlpha"] = $BorderAlpha;
|
||||
$this->Data[$NodeID]["BackgroundR"] = $BackgroundR; $this->Data[$NodeID]["BackgroundG"] = $BackgroundG; $this->Data[$NodeID]["BackgroundB"] = $BackgroundB; $this->Data[$NodeID]["BackgroundAlpha"] = $BackgroundAlpha;
|
||||
$this->Data[$NodeID]["Name"] = $Name;
|
||||
$this->Data[$NodeID]["Force"] = $Force;
|
||||
$this->Data[$NodeID]["Type"] = $NodeType;
|
||||
$this->Data[$NodeID]["Size"] = $Size;
|
||||
$this->Data[$NodeID]["Shape"] = $Shape;
|
||||
$this->Data[$NodeID]["FreeZone"] = $FreeZone;
|
||||
if ( $Connections != NULL )
|
||||
{
|
||||
if ( is_array($Connections ) )
|
||||
{
|
||||
foreach($Connections as $Key => $Value)
|
||||
$this->Data[$NodeID]["Connections"][] = $Value;
|
||||
}
|
||||
else
|
||||
$this->Data[$NodeID]["Connections"][] = $Connections;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set color attribute for a list of nodes */
|
||||
function setNodesColor($Nodes,$Settings="")
|
||||
{
|
||||
if ( is_array($Nodes) )
|
||||
{
|
||||
foreach ($Nodes as $Key => $NodeID)
|
||||
{
|
||||
if (isset($this->Data[$NodeID]) )
|
||||
{
|
||||
if ( isset($Settings["R"]) ) { $this->Data[$NodeID]["R"] = $Settings["R"]; }
|
||||
if ( isset($Settings["G"]) ) { $this->Data[$NodeID]["G"] = $Settings["G"]; }
|
||||
if ( isset($Settings["B"]) ) { $this->Data[$NodeID]["B"] = $Settings["B"]; }
|
||||
if ( isset($Settings["Alpha"]) ) { $this->Data[$NodeID]["Alpha"] = $Settings["Alpha"]; }
|
||||
if ( isset($Settings["BorderR"]) ) { $this->Data[$NodeID]["BorderR"] = $Settings["BorderR"]; }
|
||||
if ( isset($Settings["BorderG"]) ) { $this->Data[$NodeID]["BorderG"] = $Settings["BorderG"]; }
|
||||
if ( isset($Settings["BorderB"]) ) { $this->Data[$NodeID]["BorderB"] = $Settings["BorderB"]; }
|
||||
if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$NodeID]["BorderAlpha"] = $Settings["BorderAlpha"]; }
|
||||
if ( isset($Settings["Surrounding"]) ) { $this->Data[$NodeID]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset($Settings["R"]) ) { $this->Data[$Nodes]["R"] = $Settings["R"]; }
|
||||
if ( isset($Settings["G"]) ) { $this->Data[$Nodes]["G"] = $Settings["G"]; }
|
||||
if ( isset($Settings["B"]) ) { $this->Data[$Nodes]["B"] = $Settings["B"]; }
|
||||
if ( isset($Settings["Alpha"]) ) { $this->Data[$Nodes]["Alpha"] = $Settings["Alpha"]; }
|
||||
if ( isset($Settings["BorderR"]) ) { $this->Data[$Nodes]["BorderR"] = $Settings["BorderR"]; }
|
||||
if ( isset($Settings["BorderG"]) ) { $this->Data[$Nodes]["BorderG"] = $Settings["BorderG"]; }
|
||||
if ( isset($Settings["BorderB"]) ) { $this->Data[$Nodes]["BorderB"] = $Settings["BorderB"]; }
|
||||
if ( isset($Settings["BorderAlpha"]) ) { $this->Data[$Nodes]["BorderAlpha"] = $Settings["BorderAlpha"]; }
|
||||
if ( isset($Settings["Surrounding"]) ) { $this->Data[$Nodes]["BorderR"] = $this->Data[$NodeID]["R"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderG"] = $this->Data[$NodeID]["G"] + $Settings["Surrounding"]; $this->Data[$NodeID]["BorderB"] = $this->Data[$NodeID]["B"] + $Settings["Surrounding"]; }
|
||||
}
|
||||
}
|
||||
|
||||
/* Returns all the nodes details */
|
||||
function dumpNodes()
|
||||
{ return($this->Data); }
|
||||
|
||||
/* Check if a connection exists and create it if required */
|
||||
function checkConnection($SourceID, $TargetID)
|
||||
{
|
||||
if ( isset($this->Data[$SourceID]["Connections"]) )
|
||||
{
|
||||
foreach ($this->Data[$SourceID]["Connections"] as $Key => $ConnectionID)
|
||||
{ if ( $TargetID == $ConnectionID ) { return(TRUE); } }
|
||||
}
|
||||
$this->Data[$SourceID]["Connections"][] = $TargetID;
|
||||
}
|
||||
/* Get the median linked nodes position */
|
||||
function getMedianOffset($Key,$X,$Y)
|
||||
{
|
||||
$Cpt = 1;
|
||||
if ( isset($this->Data[$Key]["Connections"]) )
|
||||
{
|
||||
foreach($this->Data[$Key]["Connections"] as $ID => $NodeID)
|
||||
{
|
||||
if ( isset($this->Data[$NodeID]["X"]) && isset($this->Data[$NodeID]["Y"]) )
|
||||
{
|
||||
$X = $X + $this->Data[$NodeID]["X"];
|
||||
$Y = $Y + $this->Data[$NodeID]["Y"];
|
||||
$Cpt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(array("X"=>$X/$Cpt,"Y"=>$Y/$Cpt));
|
||||
}
|
||||
|
||||
/* Return the ID of the attached partner with the biggest weight */
|
||||
function getBiggestPartner($Key)
|
||||
{
|
||||
if ( !isset($this->Data[$Key]["Connections"]) ) { return(""); }
|
||||
|
||||
$MaxWeight = 0; $Result = "";
|
||||
foreach($this->Data[$Key]["Connections"] as $Key => $PeerID)
|
||||
{
|
||||
if ( $this->Data[$PeerID]["Weight"] > $MaxWeight )
|
||||
{ $MaxWeight = $this->Data[$PeerID]["Weight"]; $Result = $PeerID; }
|
||||
}
|
||||
return($Result);
|
||||
}
|
||||
|
||||
/* Do the initial node positions computing pass */
|
||||
function firstPass($Algorithm)
|
||||
{
|
||||
$CenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
|
||||
$CenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
|
||||
|
||||
/* Check connections reciprocity */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{
|
||||
foreach($Settings["Connections"] as $ID => $ConnectionID)
|
||||
$this->checkConnection($ConnectionID,$Key);
|
||||
}
|
||||
}
|
||||
|
||||
if ( $this->AutoComputeFreeZone ) { $this->autoFreeZone(); }
|
||||
|
||||
/* Get the max number of connections */
|
||||
$MaxConnections = 0;
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{ if ( isset($Settings["Connections"]) ) { if ( $MaxConnections < count($Settings["Connections"] ) ) { $MaxConnections = count($Settings["Connections"]); } } }
|
||||
|
||||
if ( $Algorithm == ALGORITHM_WEIGHTED )
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
|
||||
if ( $Settings["Type"] == NODE_TYPE_FREE )
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{ $Connections = count($Settings["Connections"]); }
|
||||
else
|
||||
{ $Connections = 0; }
|
||||
|
||||
$Ring = $MaxConnections - $Connections;
|
||||
$Angle = rand(0,360);
|
||||
|
||||
$this->Data[$Key]["X"] = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
|
||||
$this->Data[$Key]["Y"] = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( $Algorithm == ALGORITHM_CENTRAL )
|
||||
{
|
||||
/* Put a weight on each nodes */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
$this->Data[$Key]["Weight"] = count($Settings["Connections"]);
|
||||
else
|
||||
$this->Data[$Key]["Weight"] = 0;
|
||||
}
|
||||
|
||||
$MaxConnections = $MaxConnections + 1;
|
||||
for($i=$MaxConnections;$i>=0;$i--)
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
|
||||
if ( $Settings["Type"] == NODE_TYPE_FREE )
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{ $Connections = count($Settings["Connections"]); }
|
||||
else
|
||||
{ $Connections = 0; }
|
||||
|
||||
if ( $Connections == $i )
|
||||
{
|
||||
$BiggestPartner = $this->getBiggestPartner($Key);
|
||||
if ( $BiggestPartner != "" )
|
||||
{
|
||||
$Ring = $this->Data[$BiggestPartner]["FreeZone"];
|
||||
$Weight = $this->Data[$BiggestPartner]["Weight"];
|
||||
$AngleDivision = 360 / $this->Data[$BiggestPartner]["Weight"];
|
||||
$Done = FALSE; $Tries = 0;
|
||||
while (!$Done && $Tries <= $Weight*2)
|
||||
{
|
||||
$Tries++;
|
||||
$Angle = floor(rand(0,$Weight)*$AngleDivision);
|
||||
if ( !isset($this->Data[$BiggestPartner]["Angular"][$Angle]) || !isset($this->Data[$BiggestPartner]["Angular"]) )
|
||||
{
|
||||
$this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle;
|
||||
$Done = TRUE;
|
||||
}
|
||||
}
|
||||
if ( !$Done )
|
||||
{ $Angle = rand(0,360); $this->Data[$BiggestPartner]["Angular"][$Angle] = $Angle; }
|
||||
|
||||
$X = cos(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["X"];
|
||||
$Y = sin(deg2rad($Angle)) * ($Ring) + $this->Data[$BiggestPartner]["Y"];
|
||||
|
||||
$this->Data[$Key]["X"] = $X;
|
||||
$this->Data[$Key]["Y"] = $Y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( $Algorithm == ALGORITHM_CIRCULAR )
|
||||
{
|
||||
$MaxConnections = $MaxConnections + 1;
|
||||
for($i=$MaxConnections;$i>=0;$i--)
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
|
||||
if ( $Settings["Type"] == NODE_TYPE_FREE )
|
||||
{
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{ $Connections = count($Settings["Connections"]); }
|
||||
else
|
||||
{ $Connections = 0; }
|
||||
|
||||
if ( $Connections == $i )
|
||||
{
|
||||
$Ring = $MaxConnections - $Connections;
|
||||
$Angle = rand(0,360);
|
||||
|
||||
$X = cos(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterX;
|
||||
$Y = sin(deg2rad($Angle)) * ($Ring*$this->RingSize) + $CenterY;
|
||||
|
||||
$MedianOffset = $this->getMedianOffset($Key,$X,$Y);
|
||||
|
||||
$this->Data[$Key]["X"] = $MedianOffset["X"];
|
||||
$this->Data[$Key]["Y"] = $MedianOffset["Y"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( $Algorithm == ALGORITHM_RANDOM )
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["Type"] == NODE_TYPE_FREE )
|
||||
{
|
||||
$this->Data[$Key]["X"] = $CenterX + rand(-20,20);
|
||||
$this->Data[$Key]["Y"] = $CenterY + rand(-20,20);
|
||||
}
|
||||
if ( $Settings["Type"] == NODE_TYPE_CENTRAL ) { $this->Data[$Key]["X"] = $CenterX; $this->Data[$Key]["Y"] = $CenterY; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute one pass */
|
||||
function doPass()
|
||||
{
|
||||
/* Compute vectors */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
if ( $Settings["Type"] != NODE_TYPE_CENTRAL )
|
||||
{
|
||||
unset($this->Data[$Key]["Vectors"]);
|
||||
|
||||
$X1 = $Settings["X"];
|
||||
$Y1 = $Settings["Y"];
|
||||
|
||||
/* Repulsion vectors */
|
||||
foreach($this->Data as $Key2 => $Settings2)
|
||||
{
|
||||
if ( $Key != $Key2 )
|
||||
{
|
||||
$X2 = $this->Data[$Key2]["X"];
|
||||
$Y2 = $this->Data[$Key2]["Y"];
|
||||
$FreeZone = $this->Data[$Key2]["FreeZone"];
|
||||
|
||||
$Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
|
||||
$Angle = $this->getAngle($X1,$Y1,$X2,$Y2) + 180;
|
||||
|
||||
/* Nodes too close, repulsion occurs */
|
||||
if ( $Distance < $FreeZone )
|
||||
{
|
||||
$Force = log(pow(2,$FreeZone-$Distance));
|
||||
if ( $Force > 1 )
|
||||
{ $this->Data[$Key]["Vectors"][] = array("Type"=>"R","Angle"=>$Angle % 360,"Force"=>$Force); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Attraction vectors */
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{
|
||||
foreach($Settings["Connections"] as $ID => $NodeID)
|
||||
{
|
||||
if ( isset($this->Data[$NodeID]) )
|
||||
{
|
||||
$X2 = $this->Data[$NodeID]["X"];
|
||||
$Y2 = $this->Data[$NodeID]["Y"];
|
||||
$FreeZone = $this->Data[$Key2]["FreeZone"];
|
||||
|
||||
$Distance = $this->getDistance($X1,$Y1,$X2,$Y2);
|
||||
$Angle = $this->getAngle($X1,$Y1,$X2,$Y2);
|
||||
|
||||
if ( $Distance > $FreeZone )
|
||||
$Force = log(($Distance-$FreeZone)+1);
|
||||
else
|
||||
{ $Force = log(($FreeZone-$Distance)+1); ($Angle = $Angle + 180); }
|
||||
|
||||
if ( $Force > 1 )
|
||||
$this->Data[$Key]["Vectors"][] = array("Type"=>"A","Angle"=>$Angle % 360,"Force"=>$Force);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Move the nodes accoding to the vectors */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
|
||||
if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
|
||||
{
|
||||
foreach($Settings["Vectors"] as $ID => $Vector)
|
||||
{
|
||||
$Type = $Vector["Type"];
|
||||
$Force = $Vector["Force"];
|
||||
$Angle = $Vector["Angle"];
|
||||
$Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
|
||||
|
||||
$X = cos(deg2rad($Angle)) * $Force * $Factor + $X;
|
||||
$Y = sin(deg2rad($Angle)) * $Force * $Factor + $Y;
|
||||
}
|
||||
}
|
||||
|
||||
$this->Data[$Key]["X"] = $X;
|
||||
$this->Data[$Key]["Y"] = $Y;
|
||||
}
|
||||
}
|
||||
|
||||
function lastPass()
|
||||
{
|
||||
/* Put everything inside the graph area */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
|
||||
if ( $X < $this->X1 ) { $X = $this->X1; }
|
||||
if ( $X > $this->X2 ) { $X = $this->X2; }
|
||||
if ( $Y < $this->Y1 ) { $Y = $this->Y1; }
|
||||
if ( $Y > $this->Y2 ) { $Y = $this->Y2; }
|
||||
|
||||
$this->Data[$Key]["X"] = $X;
|
||||
$this->Data[$Key]["Y"] = $Y;
|
||||
}
|
||||
|
||||
/* Dump all links */
|
||||
$Links = "";
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X1 = $Settings["X"];
|
||||
$Y1 = $Settings["Y"];
|
||||
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{
|
||||
foreach ($Settings["Connections"] as $ID => $NodeID)
|
||||
{
|
||||
if ( isset($this->Data[$NodeID]) )
|
||||
{
|
||||
$X2 = $this->Data[$NodeID]["X"];
|
||||
$Y2 = $this->Data[$NodeID]["Y"];
|
||||
|
||||
$Links[] = array("X1"=>$X1,"Y1"=>$Y1,"X2"=>$X2,"Y2"=>$Y2,"Source"=>$Settings["Name"],"Destination"=>$this->Data[$NodeID]["Name"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check collisions */
|
||||
$Conflicts = 0;
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X1 = $Settings["X"];
|
||||
$Y1 = $Settings["Y"];
|
||||
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{
|
||||
foreach ($Settings["Connections"] as $ID => $NodeID)
|
||||
{
|
||||
if ( isset($this->Data[$NodeID]) )
|
||||
{
|
||||
$X2 = $this->Data[$NodeID]["X"];
|
||||
$Y2 = $this->Data[$NodeID]["Y"];
|
||||
|
||||
foreach($Links as $IDLinks => $Link)
|
||||
{
|
||||
$X3 = $Link["X1"]; $Y3 = $Link["Y1"]; $X4 = $Link["X2"]; $Y4 = $Link["Y2"];
|
||||
|
||||
if ( !($X1 == $X3 && $X2 == $X4 && $Y1 == $Y3 && $Y2 == $Y4 ) )
|
||||
{
|
||||
if ( $this->intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4) )
|
||||
{
|
||||
if ( $Link["Source"] != $Settings["Name"] && $Link["Source"] != $this->Data[$NodeID]["Name"] && $Link["Destination"] != $Settings["Name"] && $Link["Destination"] != $this->Data[$NodeID]["Name"] )
|
||||
{ $Conflicts++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return($Conflicts/2);
|
||||
}
|
||||
|
||||
/* Center the graph */
|
||||
function center()
|
||||
{
|
||||
/* Determine the real center */
|
||||
$TargetCenterX = ($this->X2 - $this->X1) / 2 + $this->X1;
|
||||
$TargetCenterY = ($this->Y2 - $this->Y1) / 2 + $this->Y1;
|
||||
|
||||
/* Get current boundaries */
|
||||
$XMin = $this->X2; $XMax = $this->X1;
|
||||
$YMin = $this->Y2; $YMax = $this->Y1;
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
|
||||
if ( $X < $XMin) { $XMin = $X; }
|
||||
if ( $X > $XMax) { $XMax = $X; }
|
||||
if ( $Y < $YMin) { $YMin = $Y; }
|
||||
if ( $Y > $YMax) { $YMax = $Y; }
|
||||
}
|
||||
$CurrentCenterX = ($XMax - $XMin) / 2 + $XMin;
|
||||
$CurrentCenterY = ($YMax - $YMin) / 2 + $YMin;
|
||||
|
||||
/* Compute the offset to apply */
|
||||
$XOffset = $TargetCenterX - $CurrentCenterX;
|
||||
$YOffset = $TargetCenterY - $CurrentCenterY;
|
||||
|
||||
/* Correct the points position */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$this->Data[$Key]["X"] = $Settings["X"] + $XOffset;
|
||||
$this->Data[$Key]["Y"] = $Settings["Y"] + $YOffset;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the encoded string */
|
||||
function drawSpring($Object,$Settings="")
|
||||
{
|
||||
$this->pChartObject = $Object;
|
||||
|
||||
$Pass = isset($Settings["Pass"]) ? $Settings["Pass"] : 50;
|
||||
$Retries = isset($Settings["Retry"]) ? $Settings["Retry"] : 10;
|
||||
$this->MagneticForceA = isset($Settings["MagneticForceA"]) ? $Settings["MagneticForceA"] : 1.5;
|
||||
$this->MagneticForceR = isset($Settings["MagneticForceR"]) ? $Settings["MagneticForceR"] : 2;
|
||||
$this->RingSize = isset($Settings["RingSize"]) ? $Settings["RingSize"] : 40;
|
||||
$DrawVectors = isset($Settings["DrawVectors"]) ? $Settings["DrawVectors"] : FALSE;
|
||||
$DrawQuietZone = isset($Settings["DrawQuietZone"]) ? $Settings["DrawQuietZone"] : FALSE;
|
||||
$CenterGraph = isset($Settings["CenterGraph"]) ? $Settings["CenterGraph"] : TRUE;
|
||||
$TextPadding = isset($Settings["TextPadding"]) ? $Settings["TextPadding"] : 4;
|
||||
$Algorithm = isset($Settings["Algorithm"]) ? $Settings["Algorithm"] : ALGORITHM_WEIGHTED;
|
||||
|
||||
$FontSize = $Object->FontSize;
|
||||
$this->X1 = $Object->GraphAreaX1;
|
||||
$this->Y1 = $Object->GraphAreaY1;
|
||||
$this->X2 = $Object->GraphAreaX2;
|
||||
$this->Y2 = $Object->GraphAreaY2;
|
||||
|
||||
$Conflicts = 1; $Jobs = 0; $this->History["MinimumConflicts"] = -1;
|
||||
while ($Conflicts != 0 && $Jobs < $Retries )
|
||||
{
|
||||
$Jobs++;
|
||||
|
||||
/* Compute the initial settings */
|
||||
$this->firstPass($Algorithm);
|
||||
|
||||
/* Apply the vectors */
|
||||
if ( $Pass > 0 )
|
||||
{
|
||||
for ($i=0; $i<=$Pass; $i++) { $this->doPass(); }
|
||||
}
|
||||
|
||||
$Conflicts = $this->lastPass();
|
||||
if ( $this->History["MinimumConflicts"] == -1 || $Conflicts < $this->History["MinimumConflicts"] )
|
||||
{ $this->History["MinimumConflicts"] = $Conflicts; $this->History["Result"] = $this->Data; }
|
||||
}
|
||||
|
||||
$Conflicts = $this->History["MinimumConflicts"];
|
||||
$this->Data = $this->History["Result"];
|
||||
|
||||
if ( $CenterGraph ) { $this->center(); }
|
||||
|
||||
/* Draw the connections */
|
||||
$Drawn = "";
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
|
||||
if ( isset($Settings["Connections"]) )
|
||||
{
|
||||
foreach ($Settings["Connections"] as $ID => $NodeID)
|
||||
{
|
||||
if ( !isset($Drawn[$Key]) ) { $Drawn[$Key] = ""; }
|
||||
if ( !isset($Drawn[$NodeID]) ) { $Drawn[$NodeID] = ""; }
|
||||
|
||||
if ( isset($this->Data[$NodeID]) && !isset($Drawn[$Key][$NodeID]) && !isset($Drawn[$NodeID][$Key]) )
|
||||
{
|
||||
$Color = array("R"=>$this->Default["LinkR"],"G"=>$this->Default["LinkG"],"B"=>$this->Default["LinkB"],"Alpha"=>$this->Default["Alpha"]);
|
||||
|
||||
if ( $this->Links != "" )
|
||||
{
|
||||
if ( isset($this->Links[$Key][$NodeID]["R"]) )
|
||||
{ $Color = array("R"=>$this->Links[$Key][$NodeID]["R"],"G"=>$this->Links[$Key][$NodeID]["G"],"B"=>$this->Links[$Key][$NodeID]["B"],"Alpha"=>$this->Links[$Key][$NodeID]["Alpha"]); }
|
||||
|
||||
if ( isset($this->Links[$Key][$NodeID]["Ticks"]) )
|
||||
{ $Color["Ticks"] = $this->Links[$Key][$NodeID]["Ticks"]; }
|
||||
}
|
||||
|
||||
$X2 = $this->Data[$NodeID]["X"];
|
||||
$Y2 = $this->Data[$NodeID]["Y"];
|
||||
$this->pChartObject->drawLine($X,$Y,$X2,$Y2,$Color);
|
||||
$Drawn[$Key][$NodeID] = TRUE;
|
||||
|
||||
if ( isset($this->Links) && $this->Links != "" )
|
||||
{
|
||||
if ( isset($this->Links[$Key][$NodeID]["Name"]) || isset($this->Links[$NodeID][$Key]["Name"]) )
|
||||
{
|
||||
$Name = isset($this->Links[$Key][$NodeID]["Name"]) ? $this->Links[$Key][$NodeID]["Name"] : $this->Links[$NodeID][$Key]["Name"];
|
||||
$TxtX = ($X2 - $X)/2 + $X;
|
||||
$TxtY = ($Y2 - $Y)/2 + $Y;
|
||||
|
||||
if ( $X <= $X2 )
|
||||
$Angle = (360-$this->getAngle($X,$Y,$X2,$Y2)) % 360;
|
||||
else
|
||||
$Angle = (360-$this->getAngle($X2,$Y2,$X,$Y)) % 360;
|
||||
|
||||
$Settings = $Color;
|
||||
$Settings["Angle"] = $Angle;
|
||||
$Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE;
|
||||
$this->pChartObject->drawText($TxtX,$TxtY,$Name,$Settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the quiet zones */
|
||||
if ( $DrawQuietZone )
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
$FreeZone = $Settings["FreeZone"];
|
||||
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$FreeZone,array("R"=>0,"G"=>0,"B"=>0,"Alpha"=>2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Draw the nodes */
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X = $Settings["X"];
|
||||
$Y = $Settings["Y"];
|
||||
$Name = $Settings["Name"];
|
||||
$FreeZone = $Settings["FreeZone"];
|
||||
$Shape = $Settings["Shape"];
|
||||
$Size = $Settings["Size"];
|
||||
|
||||
$Color = array("R"=>$Settings["R"],"G"=>$Settings["G"],"B"=>$Settings["B"],"Alpha"=>$Settings["Alpha"],"BorderR"=>$Settings["BorderR"],"BorderG"=>$Settings["BorderG"],"BorderB"=>$Settings["BorderB"],"BorderApha"=>$Settings["BorderAlpha"]);
|
||||
|
||||
if ( $Shape == NODE_SHAPE_CIRCLE )
|
||||
{
|
||||
$this->pChartObject->drawFilledCircle($X,$Y,$Size,$Color);
|
||||
}
|
||||
elseif ( $Shape == NODE_SHAPE_TRIANGLE )
|
||||
{
|
||||
$Points = "";
|
||||
$Points[] = cos(deg2rad(270)) * $Size + $X; $Points[] = sin(deg2rad(270)) * $Size + $Y;
|
||||
$Points[] = cos(deg2rad(45)) * $Size + $X; $Points[] = sin(deg2rad(45)) * $Size + $Y;
|
||||
$Points[] = cos(deg2rad(135)) * $Size + $X; $Points[] = sin(deg2rad(135)) * $Size + $Y;
|
||||
$this->pChartObject->drawPolygon($Points,$Color);
|
||||
}
|
||||
elseif ( $Shape == NODE_SHAPE_SQUARE )
|
||||
{
|
||||
$Offset = $Size/2; $Size = $Size / 2;
|
||||
$this->pChartObject->drawFilledRectangle($X-$Offset,$Y-$Offset,$X+$Offset,$Y+$Offset,$Color);
|
||||
}
|
||||
|
||||
if ( $Name != "" )
|
||||
{
|
||||
$LabelOptions = array("R"=>$this->Labels["R"],"G"=>$this->Labels["G"],"B"=>$this->Labels["B"],"Alpha"=>$this->Labels["Alpha"]);
|
||||
|
||||
if ( $this->Labels["Type"] == LABEL_LIGHT )
|
||||
{
|
||||
$LabelOptions["Align"] = TEXT_ALIGN_BOTTOMLEFT;
|
||||
$this->pChartObject->drawText($X,$Y,$Name,$LabelOptions);
|
||||
}
|
||||
elseif ( $this->Labels["Type"] == LABEL_CLASSIC )
|
||||
{
|
||||
$LabelOptions["Align"] = TEXT_ALIGN_TOPMIDDLE;
|
||||
$LabelOptions["DrawBox"] = TRUE;
|
||||
$LabelOptions["BoxAlpha"] = 50;
|
||||
$LabelOptions["BorderOffset"] = 4;
|
||||
$LabelOptions["RoundedRadius"] = 3;
|
||||
$LabelOptions["BoxRounded"] = TRUE;
|
||||
$LabelOptions["NoShadow"] = TRUE;
|
||||
|
||||
$this->pChartObject->drawText($X,$Y+$Size+$TextPadding,$Name,$LabelOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the vectors */
|
||||
if ( $DrawVectors )
|
||||
{
|
||||
foreach($this->Data as $Key => $Settings)
|
||||
{
|
||||
$X1 = $Settings["X"];
|
||||
$Y1 = $Settings["Y"];
|
||||
|
||||
if ( isset($Settings["Vectors"]) && $Settings["Type"] != NODE_TYPE_CENTRAL )
|
||||
{
|
||||
foreach($Settings["Vectors"] as $ID => $Vector)
|
||||
{
|
||||
$Type = $Vector["Type"];
|
||||
$Force = $Vector["Force"];
|
||||
$Angle = $Vector["Angle"];
|
||||
$Factor = $Type == "A" ? $this->MagneticForceA : $this->MagneticForceR;
|
||||
$Color = $Type == "A" ? array("FillR"=>255,"FillG"=>0,"FillB"=>0) : array("FillR"=>0,"FillG"=>255,"FillB"=>0);
|
||||
|
||||
$X2 = cos(deg2rad($Angle)) * $Force * $Factor + $X1;
|
||||
$Y2 = sin(deg2rad($Angle)) * $Force * $Factor + $Y1;
|
||||
|
||||
$this->pChartObject->drawArrow($X1,$Y1,$X2,$Y2,$Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return(array("Pass"=>$Jobs,"Conflicts"=>$Conflicts));
|
||||
}
|
||||
|
||||
/* Return the distance between two points */
|
||||
function getDistance($X1,$Y1,$X2,$Y2)
|
||||
{ return (sqrt(($X2-$X1)*($X2-$X1)+($Y2-$Y1)*($Y2-$Y1))); }
|
||||
|
||||
/* Return the angle made by a line and the X axis */
|
||||
function getAngle($X1,$Y1,$X2,$Y2)
|
||||
{
|
||||
$Opposite = $Y2 - $Y1; $Adjacent = $X2 - $X1;$Angle = rad2deg(atan2($Opposite,$Adjacent));
|
||||
if ($Angle > 0) { return($Angle); } else { return(360-abs($Angle)); }
|
||||
}
|
||||
|
||||
function intersect($X1,$Y1,$X2,$Y2,$X3,$Y3,$X4,$Y4)
|
||||
{
|
||||
$A = (($X3 * $Y4 - $X4 * $Y3) * ($X1 - $X2) - ($X1 * $Y2 - $X2 * $Y1) * ($X3 - $X4));
|
||||
$B = (($Y1 - $Y2) * ($X3 - $X4) - ($Y3 - $Y4) * ($X1 - $X2));
|
||||
|
||||
if ( $B == 0 ) { return(FALSE); }
|
||||
$Xi = $A / $B;
|
||||
|
||||
$C = ($X1 - $X2);
|
||||
if ( $C == 0 ) { return(FALSE); }
|
||||
$Yi = $Xi * (($Y1 - $Y2)/$C) + (($X1 * $Y2 - $X2 * $Y1)/$C);
|
||||
|
||||
if ( $Xi >= min($X1,$X2) && $Xi >= min($X3,$X4) && $Xi <= max($X1,$X2) && $Xi <= max($X3,$X4))
|
||||
{
|
||||
if ( $Yi >= min($Y1,$Y2) && $Yi >= min($Y3,$Y4) && $Yi <= max($Y1,$Y2) && $Yi <= max($Y3,$Y4))
|
||||
{ return(TRUE); }
|
||||
}
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,216 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pStock - class to draw stock charts
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("STOCK_MISSING_SERIE" , 180001);
|
||||
|
||||
/* pStock class definition */
|
||||
class pStock
|
||||
{
|
||||
var $pChartObject;
|
||||
var $pDataObject;
|
||||
|
||||
/* Class creator */
|
||||
function pStock($pChartObject,$pDataObject)
|
||||
{
|
||||
$this->pChartObject = $pChartObject;
|
||||
$this->pDataObject = $pDataObject;
|
||||
}
|
||||
|
||||
/* Draw a stock chart */
|
||||
function drawStockChart($Format="")
|
||||
{
|
||||
$SerieOpen = isset($Format["SerieOpen"]) ? $Format["SerieOpen"] : "Open";
|
||||
$SerieClose = isset($Format["SerieClose"]) ? $Format["SerieClose"] : "Close";
|
||||
$SerieMin = isset($Format["SerieMin"]) ? $Format["SerieMin"] : "Min";
|
||||
$SerieMax = isset($Format["SerieMax"]) ? $Format["SerieMax"] : "Max";
|
||||
$SerieMedian = isset($Format["SerieMedian"]) ? $Format["SerieMedian"] : NULL;
|
||||
$LineWidth = isset($Format["LineWidth"]) ? $Format["LineWidth"] : 1;
|
||||
$LineR = isset($Format["LineR"]) ? $Format["LineR"] : 0;
|
||||
$LineG = isset($Format["LineG"]) ? $Format["LineG"] : 0;
|
||||
$LineB = isset($Format["LineB"]) ? $Format["LineB"] : 0;
|
||||
$LineAlpha = isset($Format["LineAlpha"]) ? $Format["LineAlpha"] : 100;
|
||||
$ExtremityWidth = isset($Format["ExtremityWidth"]) ? $Format["ExtremityWidth"] : 1;
|
||||
$ExtremityLength = isset($Format["ExtremityLength"]) ? $Format["ExtremityLength"] : 3;
|
||||
$ExtremityR = isset($Format["ExtremityR"]) ? $Format["ExtremityR"] : 0;
|
||||
$ExtremityG = isset($Format["ExtremityG"]) ? $Format["ExtremityG"] : 0;
|
||||
$ExtremityB = isset($Format["ExtremityB"]) ? $Format["ExtremityB"] : 0;
|
||||
$ExtremityAlpha = isset($Format["ExtremityAlpha"]) ? $Format["ExtremityAlpha"] : 100;
|
||||
$BoxWidth = isset($Format["BoxWidth"]) ? $Format["BoxWidth"] : 8;
|
||||
$BoxUpR = isset($Format["BoxUpR"]) ? $Format["BoxUpR"] : 188;
|
||||
$BoxUpG = isset($Format["BoxUpG"]) ? $Format["BoxUpG"] : 224;
|
||||
$BoxUpB = isset($Format["BoxUpB"]) ? $Format["BoxUpB"] : 46;
|
||||
$BoxUpAlpha = isset($Format["BoxUpAlpha"]) ? $Format["BoxUpAlpha"] : 100;
|
||||
$BoxUpSurrounding = isset($Format["BoxUpSurrounding"]) ? $Format["BoxUpSurrounding"] : NULL;
|
||||
$BoxUpBorderR = isset($Format["BoxUpBorderR"]) ? $Format["BoxUpBorderR"] : $BoxUpR-20;
|
||||
$BoxUpBorderG = isset($Format["BoxUpBorderG"]) ? $Format["BoxUpBorderG"] : $BoxUpG-20;
|
||||
$BoxUpBorderB = isset($Format["BoxUpBorderB"]) ? $Format["BoxUpBorderB"] : $BoxUpB-20;
|
||||
$BoxUpBorderAlpha = isset($Format["BoxUpBorderAlpha"]) ? $Format["BoxUpBorderAlpha"] : 100;
|
||||
$BoxDownR = isset($Format["BoxDownR"]) ? $Format["BoxDownR"] : 224;
|
||||
$BoxDownG = isset($Format["BoxDownG"]) ? $Format["BoxDownG"] : 100;
|
||||
$BoxDownB = isset($Format["BoxDownB"]) ? $Format["BoxDownB"] : 46;
|
||||
$BoxDownAlpha = isset($Format["BoxDownAlpha"]) ? $Format["BoxDownAlpha"] : 100;
|
||||
$BoxDownSurrounding= isset($Format["BoxDownSurrounding"]) ? $Format["BoxDownSurrounding"] : NULL;
|
||||
$BoxDownBorderR = isset($Format["BoxDownBorderR"]) ? $Format["BoxDownBorderR"] : $BoxDownR-20;
|
||||
$BoxDownBorderG = isset($Format["BoxDownBorderG"]) ? $Format["BoxDownBorderG"] : $BoxDownG-20;
|
||||
$BoxDownBorderB = isset($Format["BoxDownBorderB"]) ? $Format["BoxDownBorderB"] : $BoxDownB-20;
|
||||
$BoxDownBorderAlpha= isset($Format["BoxDownBorderAlpha"]) ? $Format["BoxDownBorderAlpha"] : 100;
|
||||
$ShadowOnBoxesOnly = isset($Format["ShadowOnBoxesOnly"]) ? $Format["ShadowOnBoxesOnly"] : TRUE;
|
||||
$MedianR = isset($Format["MedianR"]) ? $Format["MedianR"] : 255;
|
||||
$MedianG = isset($Format["MedianG"]) ? $Format["MedianG"] : 0;
|
||||
$MedianB = isset($Format["MedianB"]) ? $Format["MedianB"] : 0;
|
||||
$MedianAlpha = isset($Format["MedianAlpha"]) ? $Format["MedianAlpha"] : 100;
|
||||
$RecordImageMap = isset($Format["RecordImageMap"]) ? $Format["RecordImageMap"] : FALSE;
|
||||
$ImageMapTitle = isset($Format["ImageMapTitle"]) ? $Format["ImageMapTitle"] : "Stock Chart";
|
||||
|
||||
|
||||
/* Data Processing */
|
||||
$Data = $this->pDataObject->getData();
|
||||
$Palette = $this->pDataObject->getPalette();
|
||||
|
||||
if ( $BoxUpSurrounding != NULL ) { $BoxUpBorderR = $BoxUpR + $BoxUpSurrounding; $BoxUpBorderG = $BoxUpG + $BoxUpSurrounding; $BoxUpBorderB = $BoxUpB + $BoxUpSurrounding; }
|
||||
if ( $BoxDownSurrounding != NULL ) { $BoxDownBorderR = $BoxDownR + $BoxDownSurrounding; $BoxDownBorderG = $BoxDownG + $BoxDownSurrounding; $BoxDownBorderB = $BoxDownB + $BoxDownSurrounding; }
|
||||
|
||||
if ( $LineWidth != 1 ) { $LineOffset = $LineWidth / 2; }
|
||||
$BoxOffset = $BoxWidth / 2;
|
||||
|
||||
$Data = $this->pChartObject->DataSet->getData();
|
||||
list($XMargin,$XDivs) = $this->pChartObject->scaleGetXSettings();
|
||||
|
||||
if ( !isset($Data["Series"][$SerieOpen]) || !isset($Data["Series"][$SerieClose]) || !isset($Data["Series"][$SerieMin]) || !isset($Data["Series"][$SerieMax]) )
|
||||
return(STOCK_MISSING_SERIE);
|
||||
|
||||
$Plots = "";
|
||||
foreach($Data["Series"][$SerieOpen]["Data"] as $Key => $Value)
|
||||
{
|
||||
$Point = "";
|
||||
if ( isset($Data["Series"][$SerieClose]["Data"][$Key]) || isset($Data["Series"][$SerieMin]["Data"][$Key]) || isset($Data["Series"][$SerieMax]["Data"][$Key]) )
|
||||
$Point = array($Value,$Data["Series"][$SerieClose]["Data"][$Key],$Data["Series"][$SerieMin]["Data"][$Key],$Data["Series"][$SerieMax]["Data"][$Key]);
|
||||
if ( $SerieMedian != NULL && isset($Data["Series"][$SerieMedian]["Data"][$Key]) )
|
||||
$Point[] = $Data["Series"][$SerieMedian]["Data"][$Key];
|
||||
|
||||
$Plots[] = $Point;
|
||||
}
|
||||
|
||||
$AxisID = $Data["Series"][$SerieOpen]["Axis"];
|
||||
$Mode = $Data["Axis"][$AxisID]["Display"];
|
||||
$Format = $Data["Axis"][$AxisID]["Format"];
|
||||
$Unit = $Data["Axis"][$AxisID]["Unit"];
|
||||
|
||||
$YZero = $this->pChartObject->scaleComputeY(0,array("AxisID"=>$AxisID));
|
||||
$XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs;
|
||||
|
||||
$X = $this->pChartObject->GraphAreaX1 + $XMargin;
|
||||
$Y = $this->pChartObject->GraphAreaY1 + $XMargin;
|
||||
|
||||
$LineSettings = array("R"=>$LineR,"G"=>$LineG,"B"=>$LineB,"Alpha"=>$LineAlpha);
|
||||
$ExtremitySettings = array("R"=>$ExtremityR,"G"=>$ExtremityG,"B"=>$ExtremityB,"Alpha"=>$ExtremityAlpha);
|
||||
$BoxUpSettings = array("R"=>$BoxUpR,"G"=>$BoxUpG,"B"=>$BoxUpB,"Alpha"=>$BoxUpAlpha,"BorderR"=>$BoxUpBorderR,"BorderG"=>$BoxUpBorderG,"BorderB"=>$BoxUpBorderB,"BorderAlpha"=>$BoxUpBorderAlpha);
|
||||
$BoxDownSettings = array("R"=>$BoxDownR,"G"=>$BoxDownG,"B"=>$BoxDownB,"Alpha"=>$BoxDownAlpha,"BorderR"=>$BoxDownBorderR,"BorderG"=>$BoxDownBorderG,"BorderB"=>$BoxDownBorderB,"BorderAlpha"=>$BoxDownBorderAlpha);
|
||||
$MedianSettings = array("R"=>$MedianR,"G"=>$MedianG,"B"=>$MedianB,"Alpha"=>$MedianAlpha);
|
||||
|
||||
foreach($Plots as $Key =>$Points)
|
||||
{
|
||||
$PosArray = $this->pChartObject->scaleComputeY($Points,array("AxisID"=>$AxisID));
|
||||
|
||||
$Values = "Open :".$Data["Series"][$SerieOpen]["Data"][$Key]."<BR>Close : ".$Data["Series"][$SerieClose]["Data"][$Key]."<BR>Min : ".$Data["Series"][$SerieMin]["Data"][$Key]."<BR>Max : ".$Data["Series"][$SerieMax]["Data"][$Key]."<BR>";
|
||||
if ( $SerieMedian != NULL ) { $Values = $Values."Median : ".$Data["Series"][$SerieMedian]["Data"][$Key]."<BR>"; }
|
||||
if ( $PosArray[0] > $PosArray[1] ) { $ImageMapColor = $this->pChartObject->toHTMLColor($BoxUpR,$BoxUpG,$BoxUpB); } else { $ImageMapColor = $this->pChartObject->toHTMLColor($BoxDownR,$BoxDownG,$BoxDownB); }
|
||||
|
||||
if ( $Data["Orientation"] == SCALE_POS_LEFTRIGHT )
|
||||
{
|
||||
if ( $YZero > $this->pChartObject->GraphAreaY2-1 ) { $YZero = $this->pChartObject->GraphAreaY2-1; }
|
||||
if ( $YZero < $this->pChartObject->GraphAreaY1+1 ) { $YZero = $this->pChartObject->GraphAreaY1+1; }
|
||||
|
||||
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaX2-$this->pChartObject->GraphAreaX1-$XMargin*2)/$XDivs; }
|
||||
|
||||
if ( $ShadowOnBoxesOnly ) { $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; }
|
||||
|
||||
if ( $LineWidth == 1 )
|
||||
$this->pChartObject->drawLine($X,$PosArray[2],$X,$PosArray[3],$LineSettings);
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($X-$LineOffset,$PosArray[2],$X+$LineOffset,$PosArray[3],$LineSettings);
|
||||
|
||||
if ( $ExtremityWidth == 1 )
|
||||
{
|
||||
$this->pChartObject->drawLine($X-$ExtremityLength,$PosArray[2],$X+$ExtremityLength,$PosArray[2],$ExtremitySettings);
|
||||
$this->pChartObject->drawLine($X-$ExtremityLength,$PosArray[3],$X+$ExtremityLength,$PosArray[3],$ExtremitySettings);
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($X-$ExtremityLength).",".floor($PosArray[2]).",".floor($X+$ExtremityLength).",".floor($PosArray[3]),$ImageMapColor,$ImageMapTitle,$Values); }
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->pChartObject->drawFilledRectangle($X-$ExtremityLength,$PosArray[2],$X+$ExtremityLength,$PosArray[2]-$ExtremityWidth,$ExtremitySettings);
|
||||
$this->pChartObject->drawFilledRectangle($X-$ExtremityLength,$PosArray[3],$X+$ExtremityLength,$PosArray[3]+$ExtremityWidth,$ExtremitySettings);
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($X-$ExtremityLength).",".floor($PosArray[2]-$ExtremityWidth).",".floor($X+$ExtremityLength).",".floor($PosArray[3]+$ExtremityWidth),$ImageMapColor,$ImageMapTitle,$Values); }
|
||||
}
|
||||
|
||||
if ( $ShadowOnBoxesOnly ) { $this->pChartObject->Shadow = $RestoreShadow; }
|
||||
|
||||
if ( $PosArray[0] > $PosArray[1] )
|
||||
$this->pChartObject->drawFilledRectangle($X-$BoxOffset,$PosArray[0],$X+$BoxOffset,$PosArray[1],$BoxUpSettings);
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($X-$BoxOffset,$PosArray[0],$X+$BoxOffset,$PosArray[1],$BoxDownSettings);
|
||||
|
||||
if ( isset($PosArray[4]) )
|
||||
$this->pChartObject->drawLine($X-$ExtremityLength,$PosArray[4],$X+$ExtremityLength,$PosArray[4],$MedianSettings);
|
||||
|
||||
$X = $X + $XStep;
|
||||
}
|
||||
elseif ( $Data["Orientation"] == SCALE_POS_TOPBOTTOM )
|
||||
{
|
||||
if ( $YZero > $this->pChartObject->GraphAreaX2-1 ) { $YZero = $this->pChartObject->GraphAreaX2-1; }
|
||||
if ( $YZero < $this->pChartObject->GraphAreaX1+1 ) { $YZero = $this->pChartObject->GraphAreaX1+1; }
|
||||
|
||||
if ( $XDivs == 0 ) { $XStep = 0; } else { $XStep = ($this->pChartObject->GraphAreaY2-$this->pChartObject->GraphAreaY1-$XMargin*2)/$XDivs; }
|
||||
|
||||
if ( $LineWidth == 1 )
|
||||
$this->pChartObject->drawLine($PosArray[2],$Y,$PosArray[3],$Y,$LineSettings);
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($PosArray[2],$Y-$LineOffset,$PosArray[3],$Y+$LineOffset,$LineSettings);
|
||||
|
||||
if ( $ShadowOnBoxesOnly ) { $RestoreShadow = $this->pChartObject->Shadow; $this->pChartObject->Shadow = FALSE; }
|
||||
|
||||
if ( $ExtremityWidth == 1 )
|
||||
{
|
||||
$this->pChartObject->drawLine($PosArray[2],$Y-$ExtremityLength,$PosArray[2],$Y+$ExtremityLength,$ExtremitySettings);
|
||||
$this->pChartObject->drawLine($PosArray[3],$Y-$ExtremityLength,$PosArray[3],$Y+$ExtremityLength,$ExtremitySettings);
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($PosArray[2]).",".floor($Y-$ExtremityLength).",".floor($PosArray[3]).",".floor($Y+$ExtremityLength),$ImageMapColor,$ImageMapTitle,$Values); }
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->pChartObject->drawFilledRectangle($PosArray[2],$Y-$ExtremityLength,$PosArray[2]-$ExtremityWidth,$Y+$ExtremityLength,$ExtremitySettings);
|
||||
$this->pChartObject->drawFilledRectangle($PosArray[3],$Y-$ExtremityLength,$PosArray[3]+$ExtremityWidth,$Y+$ExtremityLength,$ExtremitySettings);
|
||||
|
||||
if ( $RecordImageMap ) { $this->pChartObject->addToImageMap("RECT",floor($PosArray[2]-$ExtremityWidth).",".floor($Y-$ExtremityLength).",".floor($PosArray[3]+$ExtremityWidth).",".floor($Y+$ExtremityLength),$ImageMapColor,$ImageMapTitle,$Values); }
|
||||
}
|
||||
|
||||
if ( $ShadowOnBoxesOnly ) { $this->pChartObject->Shadow = $RestoreShadow; }
|
||||
|
||||
if ( $PosArray[0] < $PosArray[1] )
|
||||
$this->pChartObject->drawFilledRectangle($PosArray[0],$Y-$BoxOffset,$PosArray[1],$Y+$BoxOffset,$BoxUpSettings);
|
||||
else
|
||||
$this->pChartObject->drawFilledRectangle($PosArray[0],$Y-$BoxOffset,$PosArray[1],$Y+$BoxOffset,$BoxDownSettings);
|
||||
|
||||
if ( isset($PosArray[4]) )
|
||||
$this->pChartObject->drawLine($PosArray[4],$Y-$ExtremityLength,$PosArray[4],$Y+$ExtremityLength,$MedianSettings);
|
||||
|
||||
$Y = $Y + $XStep;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,315 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
pSurface - class to draw surface charts
|
||||
|
||||
Version : 2.1.4
|
||||
Made by : Jean-Damien POGOLOTTI
|
||||
Last Update : 19/01/2014
|
||||
|
||||
This file can be distributed under the license you can find at :
|
||||
|
||||
http://www.pchart.net/license
|
||||
|
||||
You can find the whole class documentation on the pChart web site.
|
||||
*/
|
||||
|
||||
define("UNKNOWN" , 0.123456789);
|
||||
define("IGNORED" , -1);
|
||||
|
||||
define("LABEL_POSITION_LEFT" , 880001);
|
||||
define("LABEL_POSITION_RIGHT" , 880002);
|
||||
define("LABEL_POSITION_TOP" , 880003);
|
||||
define("LABEL_POSITION_BOTTOM" , 880004);
|
||||
|
||||
/* pStock class definition */
|
||||
class pSurface
|
||||
{
|
||||
var $pChartObject;
|
||||
var $GridSizeX;
|
||||
var $GridSizeY;
|
||||
var $Points;
|
||||
|
||||
/* Class creator */
|
||||
function pSurface($pChartObject)
|
||||
{
|
||||
$this->pChartObject = $pChartObject;
|
||||
$this->GridSize = 10;
|
||||
$this->Points = "";
|
||||
}
|
||||
|
||||
/* Define the grid size and initialise the 2D matrix */
|
||||
function setGrid($XSize=10,$YSize=10)
|
||||
{
|
||||
for($X=0; $X<=$XSize; $X++) { for($Y=0; $Y<=$YSize; $Y++) { $this->Points[$X][$Y]=UNKNOWN; } }
|
||||
|
||||
$this->GridSizeX = $XSize;
|
||||
$this->GridSizeY = $YSize;
|
||||
}
|
||||
|
||||
/* Add a point on the grid */
|
||||
function addPoint($X,$Y,$Value,$Force=TRUE)
|
||||
{
|
||||
if ( $X < 0 || $X >$this->GridSizeX ) { return(0); }
|
||||
if ( $Y < 0 || $Y >$this->GridSizeY ) { return(0); }
|
||||
|
||||
if ( $this->Points[$X][$Y] == UNKNOWN || $Force )
|
||||
$this->Points[$X][$Y] = $Value;
|
||||
elseif ( $this->Points[$X][$Y] == UNKNOWN )
|
||||
$this->Points[$X][$Y] = $Value;
|
||||
else
|
||||
$this->Points[$X][$Y] = ($this->Points[$X][$Y] + $Value)/2;
|
||||
}
|
||||
|
||||
/* Write the X labels */
|
||||
function writeXLabels($Format="")
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : $this->pChartObject->FontColorR;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : $this->pChartObject->FontColorG;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : $this->pChartObject->FontColorB;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->pChartObject->FontColorA;
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$Padding = isset($Format["Padding"]) ? $Format["Padding"] : 5;
|
||||
$Position = isset($Format["Position"]) ? $Format["Position"] : LABEL_POSITION_TOP;
|
||||
$Labels = isset($Format["Labels"]) ? $Format["Labels"] : NULL;
|
||||
$CountOffset = isset($Format["CountOffset"]) ? $Format["CountOffset"] : 0;
|
||||
|
||||
if ( $Labels != NULL && !is_array($Labels) ) { $Label = $Labels; $Labels = ""; $Labels[] = $Label; }
|
||||
|
||||
$X0 = $this->pChartObject->GraphAreaX1;
|
||||
$XSize = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) / ($this->GridSizeX+1);
|
||||
|
||||
$Settings = array("Angle"=>$Angle,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
if ( $Position == LABEL_POSITION_TOP )
|
||||
{
|
||||
$YPos = $this->pChartObject->GraphAreaY1 - $Padding;
|
||||
if ($Angle == 0 ) { $Settings["Align"] = TEXT_ALIGN_BOTTOMMIDDLE; }
|
||||
if ($Angle != 0 ) { $Settings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
|
||||
}
|
||||
elseif ( $Position == LABEL_POSITION_BOTTOM )
|
||||
{
|
||||
$YPos = $this->pChartObject->GraphAreaY2 + $Padding;
|
||||
if ($Angle == 0 ) { $Settings["Align"] = TEXT_ALIGN_TOPMIDDLE; }
|
||||
if ($Angle != 0 ) { $Settings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
|
||||
for($X=0;$X<=$this->GridSizeX;$X++)
|
||||
{
|
||||
$XPos = floor($X0+$X*$XSize + $XSize/2);
|
||||
|
||||
if( $Labels == NULL || !isset($Labels[$X]) )
|
||||
$Value = $X+$CountOffset;
|
||||
else
|
||||
$Value = $Labels[$X];
|
||||
|
||||
$this->pChartObject->drawText($XPos,$YPos,$Value,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write the Y labels */
|
||||
function writeYLabels($Format="")
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : $this->pChartObject->FontColorR;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : $this->pChartObject->FontColorG;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : $this->pChartObject->FontColorB;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : $this->pChartObject->FontColorA;
|
||||
$Angle = isset($Format["Angle"]) ? $Format["Angle"] : 0;
|
||||
$Padding = isset($Format["Padding"]) ? $Format["Padding"] : 5;
|
||||
$Position = isset($Format["Position"]) ? $Format["Position"] : LABEL_POSITION_LEFT;
|
||||
$Labels = isset($Format["Labels"]) ? $Format["Labels"] : NULL;
|
||||
$CountOffset = isset($Format["CountOffset"]) ? $Format["CountOffset"] : 0;
|
||||
|
||||
if ( $Labels != NULL && !is_array($Labels) ) { $Label = $Labels; $Labels = ""; $Labels[] = $Label; }
|
||||
|
||||
$Y0 = $this->pChartObject->GraphAreaY1;
|
||||
$YSize = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) / ($this->GridSizeY+1);
|
||||
|
||||
$Settings = array("Angle"=>$Angle,"R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
if ( $Position == LABEL_POSITION_LEFT )
|
||||
{ $XPos = $this->pChartObject->GraphAreaX1 - $Padding; $Settings["Align"] = TEXT_ALIGN_MIDDLERIGHT; }
|
||||
elseif ( $Position == LABEL_POSITION_RIGHT )
|
||||
{ $XPos = $this->pChartObject->GraphAreaX2 + $Padding; $Settings["Align"] = TEXT_ALIGN_MIDDLELEFT; }
|
||||
else
|
||||
return(-1);
|
||||
|
||||
for($Y=0;$Y<=$this->GridSizeY;$Y++)
|
||||
{
|
||||
$YPos = floor($Y0+$Y*$YSize + $YSize/2);
|
||||
|
||||
if( $Labels == NULL || !isset($Labels[$Y]) )
|
||||
$Value = $Y+$CountOffset;
|
||||
else
|
||||
$Value = $Labels[$Y];
|
||||
|
||||
$this->pChartObject->drawText($XPos,$YPos,$Value,$Settings);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the area arround the specified Threshold */
|
||||
function drawContour($Threshold,$Format="")
|
||||
{
|
||||
$R = isset($Format["R"]) ? $Format["R"] : 0;
|
||||
$G = isset($Format["G"]) ? $Format["G"] : 0;
|
||||
$B = isset($Format["B"]) ? $Format["B"] : 0;
|
||||
$Alpha = isset($Format["Alpha"]) ? $Format["Alpha"] : 100;
|
||||
$Ticks = isset($Format["Ticks"]) ? $Format["Ticks"] : 3;
|
||||
$Padding = isset($Format["Padding"]) ? $Format["Padding"] : 0;
|
||||
|
||||
$X0 = $this->pChartObject->GraphAreaX1;
|
||||
$Y0 = $this->pChartObject->GraphAreaY1;
|
||||
$XSize = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) / ($this->GridSizeX+1);
|
||||
$YSize = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) / ($this->GridSizeY+1);
|
||||
|
||||
$Color = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha,"Ticks"=>$Ticks);
|
||||
|
||||
for($X=0;$X<=$this->GridSizeX;$X++)
|
||||
{
|
||||
for($Y=0;$Y<=$this->GridSizeY;$Y++)
|
||||
{
|
||||
$Value = $this->Points[$X][$Y];
|
||||
|
||||
if ( $Value != UNKNOWN && $Value != IGNORED && $Value >= $Threshold)
|
||||
{
|
||||
$X1 = floor($X0+$X*$XSize)+$Padding;
|
||||
$Y1 = floor($Y0+$Y*$YSize)+$Padding;
|
||||
$X2 = floor($X0+$X*$XSize+$XSize);
|
||||
$Y2 = floor($Y0+$Y*$YSize+$YSize);
|
||||
|
||||
if ( $X > 0 && $this->Points[$X-1][$Y] != UNKNOWN && $this->Points[$X-1][$Y] != IGNORED && $this->Points[$X-1][$Y] < $Threshold)
|
||||
$this->pChartObject->drawLine($X1,$Y1,$X1,$Y2,$Color);
|
||||
if ( $Y > 0 && $this->Points[$X][$Y-1] != UNKNOWN && $this->Points[$X][$Y-1] != IGNORED && $this->Points[$X][$Y-1] < $Threshold)
|
||||
$this->pChartObject->drawLine($X1,$Y1,$X2,$Y1,$Color);
|
||||
if ( $X < $this->GridSizeX && $this->Points[$X+1][$Y] != UNKNOWN && $this->Points[$X+1][$Y] != IGNORED && $this->Points[$X+1][$Y] < $Threshold)
|
||||
$this->pChartObject->drawLine($X2,$Y1,$X2,$Y2,$Color);
|
||||
if ( $Y < $this->GridSizeY && $this->Points[$X][$Y+1] != UNKNOWN && $this->Points[$X][$Y+1] != IGNORED && $this->Points[$X][$Y+1] < $Threshold)
|
||||
$this->pChartObject->drawLine($X1,$Y2,$X2,$Y2,$Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw the surface chart */
|
||||
function drawSurface($Format="")
|
||||
{
|
||||
$Palette = isset($Format["Palette"]) ? $Format["Palette"] : NULL;
|
||||
$ShadeR1 = isset($Format["ShadeR1"]) ? $Format["ShadeR1"] : 77;
|
||||
$ShadeG1 = isset($Format["ShadeG1"]) ? $Format["ShadeG1"] : 205;
|
||||
$ShadeB1 = isset($Format["ShadeB1"]) ? $Format["ShadeB1"] : 21;
|
||||
$ShadeA1 = isset($Format["ShadeA1"]) ? $Format["ShadeA1"] : 40;
|
||||
$ShadeR2 = isset($Format["ShadeR2"]) ? $Format["ShadeR2"] : 227;
|
||||
$ShadeG2 = isset($Format["ShadeG2"]) ? $Format["ShadeG2"] : 135;
|
||||
$ShadeB2 = isset($Format["ShadeB2"]) ? $Format["ShadeB2"] : 61;
|
||||
$ShadeA2 = isset($Format["ShadeA2"]) ? $Format["ShadeA2"] : 100;
|
||||
$Border = isset($Format["Border"]) ? $Format["Border"] : FALSE;
|
||||
$BorderR = isset($Format["BorderR"]) ? $Format["BorderR"] : 0;
|
||||
$BorderG = isset($Format["BorderG"]) ? $Format["BorderG"] : 0;
|
||||
$BorderB = isset($Format["BorderB"]) ? $Format["BorderB"] : 0;
|
||||
$Surrounding = isset($Format["Surrounding"]) ? $Format["Surrounding"] : -1;
|
||||
$Padding = isset($Format["Padding"]) ? $Format["Padding"] : 1;
|
||||
|
||||
$X0 = $this->pChartObject->GraphAreaX1;
|
||||
$Y0 = $this->pChartObject->GraphAreaY1;
|
||||
$XSize = ($this->pChartObject->GraphAreaX2 - $this->pChartObject->GraphAreaX1) / ($this->GridSizeX+1);
|
||||
$YSize = ($this->pChartObject->GraphAreaY2 - $this->pChartObject->GraphAreaY1) / ($this->GridSizeY+1);
|
||||
|
||||
for($X=0;$X<=$this->GridSizeX;$X++)
|
||||
{
|
||||
for($Y=0;$Y<=$this->GridSizeY;$Y++)
|
||||
{
|
||||
$Value = $this->Points[$X][$Y];
|
||||
|
||||
if ( $Value != UNKNOWN && $Value != IGNORED )
|
||||
{
|
||||
$X1 = floor($X0+$X*$XSize)+$Padding;
|
||||
$Y1 = floor($Y0+$Y*$YSize)+$Padding;
|
||||
$X2 = floor($X0+$X*$XSize+$XSize);
|
||||
$Y2 = floor($Y0+$Y*$YSize+$YSize);
|
||||
|
||||
if ( $Palette != NULL )
|
||||
{
|
||||
if ( isset($Palette[$Value]) && isset($Palette[$Value]["R"]) ) { $R = $Palette[$Value]["R"]; } else { $R = 0; }
|
||||
if ( isset($Palette[$Value]) && isset($Palette[$Value]["G"]) ) { $G = $Palette[$Value]["G"]; } else { $G = 0; }
|
||||
if ( isset($Palette[$Value]) && isset($Palette[$Value]["B"]) ) { $B = $Palette[$Value]["B"]; } else { $B = 0; }
|
||||
if ( isset($Palette[$Value]) && isset($Palette[$Value]["Alpha"]) ) { $Alpha = $Palette[$Value]["Alpha"]; } else { $Alpha = 1000; }
|
||||
}
|
||||
else
|
||||
{
|
||||
$R = (($ShadeR2-$ShadeR1)/100)*$Value + $ShadeR1;
|
||||
$G = (($ShadeG2-$ShadeG1)/100)*$Value + $ShadeG1;
|
||||
$B = (($ShadeB2-$ShadeB1)/100)*$Value + $ShadeB1;
|
||||
$Alpha = (($ShadeA2-$ShadeA1)/100)*$Value + $ShadeA1;
|
||||
}
|
||||
|
||||
$Settings = array("R"=>$R,"G"=>$G,"B"=>$B,"Alpha"=>$Alpha);
|
||||
if ( $Border ) { $Settings["BorderR"] = $BorderR; $Settings["BorderG"] = $BorderG; $Settings["BorderB"] = $BorderB; }
|
||||
if ( $Surrounding != -1 ) { $Settings["BorderR"] = $R+$Surrounding; $Settings["BorderG"] = $G+$Surrounding; $Settings["BorderB"] = $B+$Surrounding; }
|
||||
|
||||
$this->pChartObject->drawFilledRectangle($X1,$Y1,$X2-1,$Y2-1,$Settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the missing points */
|
||||
function computeMissing()
|
||||
{
|
||||
$Missing = "";
|
||||
for($X=0;$X<=$this->GridSizeX;$X++)
|
||||
{
|
||||
for($Y=0;$Y<=$this->GridSizeY;$Y++)
|
||||
{
|
||||
if ( $this->Points[$X][$Y] == UNKNOWN )
|
||||
$Missing[] = $X.",".$Y;
|
||||
}
|
||||
}
|
||||
shuffle($Missing);
|
||||
|
||||
foreach($Missing as $Key => $Pos)
|
||||
{
|
||||
$Pos = preg_split("/,/",$Pos);
|
||||
$X = $Pos[0];
|
||||
$Y = $Pos[1];
|
||||
|
||||
if ( $this->Points[$X][$Y] == UNKNOWN )
|
||||
{
|
||||
$NearestNeighbor = $this->getNearestNeighbor($X,$Y);
|
||||
|
||||
$Value = 0; $Points = 0;
|
||||
for($Xi=$X-$NearestNeighbor;$Xi<=$X+$NearestNeighbor;$Xi++)
|
||||
{
|
||||
for($Yi=$Y-$NearestNeighbor;$Yi<=$Y+$NearestNeighbor;$Yi++)
|
||||
{
|
||||
if ($Xi >=0 && $Yi >= 0 && $Xi <= $this->GridSizeX && $Yi <= $this->GridSizeY && $this->Points[$Xi][$Yi] != UNKNOWN && $this->Points[$Xi][$Yi] != IGNORED)
|
||||
{
|
||||
$Value = $Value + $this->Points[$Xi][$Yi]; $Points++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $Points != 0 ) { $this->Points[$X][$Y] = $Value / $Points; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Return the nearest Neighbor distance of a point */
|
||||
function getNearestNeighbor($Xp,$Yp)
|
||||
{
|
||||
$Nearest = UNKNOWN;
|
||||
for($X=0;$X<=$this->GridSizeX;$X++)
|
||||
{
|
||||
for($Y=0;$Y<=$this->GridSizeY;$Y++)
|
||||
{
|
||||
if ( $this->Points[$X][$Y] != UNKNOWN && $this->Points[$X][$Y] != IGNORED )
|
||||
{
|
||||
$DistanceX = max($Xp,$X)-min($Xp,$X);
|
||||
$DistanceY = max($Yp,$Y)-min($Yp,$Y);
|
||||
$Distance = max($DistanceX,$DistanceY);
|
||||
if ( $Distance < $Nearest || $Nearest == UNKNOWN ) { $Nearest = $Distance; }
|
||||
}
|
||||
}
|
||||
}
|
||||
return($Nearest);
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,107 +0,0 @@
|
||||
0;32;11011001100
|
||||
1;33;11001101100
|
||||
2;34;11001100110
|
||||
3;35;10010011000
|
||||
4;36;10010001100
|
||||
5;37;10001001100
|
||||
6;38;10011001000
|
||||
7;39;10011000100
|
||||
8;40;10001100100
|
||||
9;41;11001001000
|
||||
10;42;11001000100
|
||||
11;43;11000100100
|
||||
12;44;10110011100
|
||||
13;45;10011011100
|
||||
14;46;10011001110
|
||||
15;47;10111001100
|
||||
16;48;10011101100
|
||||
17;49;10011100110
|
||||
18;50;11001110010
|
||||
19;51;11001011100
|
||||
20;52;11001001110
|
||||
21;53;11011100100
|
||||
22;54;11001110100
|
||||
23;55;11101101110
|
||||
24;56;11101001100
|
||||
25;57;11100101100
|
||||
26;58;11100100110
|
||||
27;59;11101100100
|
||||
28;60;11100110100
|
||||
29;61;11100110010
|
||||
30;62;11011011000
|
||||
31;63;11011000110
|
||||
32;64;11000110110
|
||||
33;65;10100011000
|
||||
34;66;10001011000
|
||||
35;67;10001000110
|
||||
36;68;10110001000
|
||||
37;69;10001101000
|
||||
38;70;10001100010
|
||||
39;71;11010001000
|
||||
40;72;11000101000
|
||||
41;73;11000100010
|
||||
42;74;10110111000
|
||||
43;75;10110001110
|
||||
44;76;10001101110
|
||||
45;77;10111011000
|
||||
46;78;10111000110
|
||||
47;79;10001110110
|
||||
48;80;11101110110
|
||||
49;81;11010001110
|
||||
50;82;11000101110
|
||||
51;83;11011101000
|
||||
52;84;11011100010
|
||||
53;85;11011101110
|
||||
54;86;11101011000
|
||||
55;87;11101000110
|
||||
56;88;11100010110
|
||||
57;89;11101101000
|
||||
58;90;11101100010
|
||||
59;91;11100011010
|
||||
60;92;11101111010
|
||||
61;93;11001000010
|
||||
62;94;11110001010
|
||||
63;95;10100110000
|
||||
64;96;10100001100
|
||||
65;97;10010110000
|
||||
66;98;10010000110
|
||||
67;99;10000101100
|
||||
68;100;10000100110
|
||||
69;101;10110010000
|
||||
70;102;10110000100
|
||||
71;103;10011010000
|
||||
72;104;10011000010
|
||||
73;105;10000110100
|
||||
74;106;10000110010
|
||||
75;107;11000010010
|
||||
76;108;11001010000
|
||||
77;109;11110111010
|
||||
78;110;11000010100
|
||||
79;111;10001111010
|
||||
80;112;10100111100
|
||||
81;113;10010111100
|
||||
82;114;10010011110
|
||||
83;115;10111100100
|
||||
84;116;10011110100
|
||||
85;117;10011110010
|
||||
86;118;11110100100
|
||||
87;119;11110010100
|
||||
88;120;11110010010
|
||||
89;121;11011011110
|
||||
90;122;11011110110
|
||||
91;123;11110110110
|
||||
92;124;10101111000
|
||||
93;125;10100011110
|
||||
94;126;10001011110
|
||||
95;200;10111101000
|
||||
96;201;10111100010
|
||||
97;202;11110101000
|
||||
98;203;11110100010
|
||||
99;204;10111011110
|
||||
100;205;10111101110
|
||||
101;206;11101011110
|
||||
102;207;11110101110
|
||||
103;208;11010000100
|
||||
104;209;11010010000
|
||||
105;210;11010011100
|
||||
106;211;1100011101011
|
||||
@@ -1,44 +0,0 @@
|
||||
0;101001101101
|
||||
1;110100101011
|
||||
2;101100101011
|
||||
3;110110010101
|
||||
4;101001101011
|
||||
5;110100110101
|
||||
6;101100110101
|
||||
7;101001011011
|
||||
8;110100101101
|
||||
9;101100101101
|
||||
A;110101001011
|
||||
B;101101001011
|
||||
C;110110100101
|
||||
D;101011001011
|
||||
E;110101100101
|
||||
F;101101100101
|
||||
G;101010011011
|
||||
H;110101001101
|
||||
I;101101001101
|
||||
J;101011001101
|
||||
K;110101010011
|
||||
L;101101010011
|
||||
M;110110101001
|
||||
N;101011010011
|
||||
O;110101101001
|
||||
P;101101101001
|
||||
Q;101010110011
|
||||
R;110101011001
|
||||
S;101101011001
|
||||
T;101011011001
|
||||
U;110010101011
|
||||
V;100110101011
|
||||
W;110011010101
|
||||
X;100101101011
|
||||
Y;110010110101
|
||||
Z;100110110101
|
||||
-;100101011011
|
||||
.;110010101101
|
||||
;100110101101
|
||||
$;100100100101
|
||||
/;100100101001
|
||||
+;100101001001
|
||||
%;101001001001
|
||||
*;100101101101
|
||||
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user