Compare commits
301 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 | ||
|
|
8577345799 | ||
|
|
4779e4ccbe | ||
|
|
c1240c0614 | ||
|
|
6722468bdb | ||
|
|
11daac6d23 | ||
|
|
678aa7460e | ||
|
|
76e0c0ac06 | ||
|
|
3512fa73ee | ||
|
|
0a80b28553 | ||
|
|
2c5fcd973f | ||
|
|
4515a5fdd1 | ||
|
|
f04487d553 | ||
|
|
d068aaeed7 | ||
|
|
b628331a9b | ||
|
|
3035287b5c | ||
|
|
cb17b553b0 | ||
|
|
448b54f5c1 | ||
|
|
e80915cd5c | ||
|
|
4ae1c2bde0 | ||
|
|
ee6e0581da | ||
|
|
70a30c3182 | ||
|
|
9d54d6b0d1 | ||
|
|
a46888d101 | ||
|
|
be092fc449 | ||
|
|
6059b83637 | ||
|
|
b6c6d76b43 | ||
|
|
80993a06ac | ||
|
|
50073479d4 | ||
|
|
85f701ab2a | ||
|
|
519de8a23c | ||
|
|
d5fdb22e93 | ||
|
|
0ec0007569 | ||
|
|
7165a50b4d | ||
|
|
71ee80fa06 | ||
|
|
bb5276ee44 | ||
|
|
9c242ed1b9 | ||
|
|
0fcbe91ea2 | ||
|
|
ee4417fc52 | ||
|
|
ee1dafd8d8 | ||
|
|
96104095d0 | ||
|
|
a311552c56 | ||
|
|
f694539a0b | ||
|
|
2f1388494f | ||
|
|
06fe9657e2 | ||
|
|
d4e5f92277 | ||
|
|
b2c0a57924 | ||
|
|
5522348c8a | ||
|
|
ed01d248ec | ||
|
|
899ddc011c | ||
|
|
a86eaf0f02 | ||
|
|
3e29073664 | ||
|
|
5601b14d5f | ||
|
|
a1afc1fb2e | ||
|
|
d445bc3526 | ||
|
|
719d82d4ee | ||
|
|
6807f33120 | ||
|
|
114ca6c24a | ||
|
|
e46d0fa4a4 | ||
|
|
f7db84c62f | ||
|
|
3267fc0266 | ||
|
|
d9e13ae14c | ||
|
|
50db770992 | ||
|
|
e439945a54 | ||
|
|
8223441ca9 | ||
|
|
0153c9721f | ||
|
|
b6f6eeac9b | ||
|
|
beedf629e5 | ||
|
|
04b47574eb | ||
|
|
ecc52e2dbd | ||
|
|
12e335c69c | ||
|
|
3ae3b1b761 | ||
|
|
3c9ca025f5 | ||
|
|
96afa463e0 | ||
|
|
5195212fae | ||
|
|
e990d6b410 | ||
|
|
b5dd85bc75 | ||
|
|
b2945a8fa0 | ||
|
|
c77562b595 | ||
|
|
2210f62441 | ||
|
|
dfb2a93fbd | ||
|
|
ca073c1b56 | ||
|
|
f316dde8b7 | ||
|
|
13b18c3a62 | ||
|
|
18bf829c6b | ||
|
|
723b6345bb | ||
|
|
e235721c8b | ||
|
|
fd0af5a294 | ||
|
|
fd8caaf5de | ||
|
|
3d842d4107 | ||
|
|
c895beb35f | ||
|
|
b6a35d15cf | ||
|
|
20c44694e8 | ||
|
|
f6424bdd35 | ||
|
|
ea3a8edae6 | ||
|
|
d04cc380b2 | ||
|
|
98bf11e0c9 | ||
|
|
a6918bac6f | ||
|
|
86c5085f92 | ||
|
|
63bcdc0eff | ||
|
|
ef1df6f171 | ||
|
|
8ade113070 | ||
|
|
4508692330 | ||
|
|
98c87a755a | ||
|
|
bf96eb755d | ||
|
|
9ea8364aab | ||
|
|
25941f4b49 | ||
|
|
56612cb13b | ||
|
|
d9ad041c47 | ||
|
|
5558a21824 | ||
|
|
05c48bce60 | ||
|
|
b25f280849 | ||
|
|
745faacb30 | ||
|
|
fd2e0937b5 | ||
|
|
6be1b3008e | ||
|
|
46554e6965 | ||
|
|
c8686024e2 | ||
|
|
605ea06bf0 | ||
|
|
9ec19f5940 | ||
|
|
a27e4603a8 | ||
|
|
54b7af348b | ||
|
|
c5d624a318 | ||
|
|
47ffec1fd4 | ||
|
|
72c6844e74 | ||
|
|
d0753512a3 | ||
|
|
d0de3821f8 | ||
|
|
0d89eea1af | ||
|
|
d87033d57d | ||
|
|
19a44d9340 | ||
|
|
436025dd22 | ||
|
|
19458a2eba | ||
|
|
aa9e985120 | ||
|
|
a0d5e18832 | ||
|
|
6c1c528e2e | ||
|
|
d44325501a | ||
|
|
1b45a1b770 | ||
|
|
fe32dd4543 | ||
|
|
0111762315 | ||
|
|
89c2b54889 | ||
|
|
70d51025f8 | ||
|
|
1ecdd5f6d7 | ||
|
|
593e8fa7b0 | ||
|
|
4b08a4d856 | ||
|
|
23d2483855 | ||
|
|
729541f280 | ||
|
|
d47f525480 | ||
|
|
b5290971c1 | ||
|
|
2f1cb6a0a5 | ||
|
|
d813ce0e35 | ||
|
|
22b4fbce8d | ||
|
|
7fe27b8040 | ||
|
|
be03bc96cb | ||
|
|
4f73a88a8b | ||
|
|
b2019226da | ||
|
|
754c2edbd2 | ||
|
|
98e16e6143 | ||
|
|
005584e2ed | ||
|
|
7e34c5321d | ||
|
|
9d918f3b43 | ||
|
|
433b21ab6f | ||
|
|
826b5fdfd6 | ||
|
|
a923f07fc7 | ||
|
|
736415e939 | ||
|
|
2e8712d935 | ||
|
|
c6a15506c5 | ||
|
|
b2f5d439d5 | ||
|
|
071395bfe5 | ||
|
|
03ff1862c1 | ||
|
|
71ab3e27bd | ||
|
|
a190148125 | ||
|
|
fa5350baa2 | ||
|
|
4d70f8a017 | ||
|
|
d5476b4269 | ||
|
|
bddc196e25 | ||
|
|
e3d1679f86 | ||
|
|
34f33772d0 | ||
|
|
bfe3fdcff4 | ||
|
|
1feb7bf574 | ||
|
|
272a5ad202 | ||
|
|
8a86145307 | ||
|
|
1afc0eb982 | ||
|
|
a7e7539911 | ||
|
|
6e3f017960 | ||
|
|
80715e5ef1 | ||
|
|
0408483aa8 | ||
|
|
02d1d03c15 | ||
| 6db87c64b0 | |||
|
|
765297d2a2 | ||
|
|
382cc0524a | ||
|
|
aa57c6218f | ||
|
|
b3f9fd27e6 | ||
|
|
4e6463a849 | ||
|
|
5ad0419613 | ||
|
|
e23389a7f8 | ||
|
|
c21e194eaf | ||
|
|
41b1f14594 | ||
|
|
62eb2d61b0 | ||
|
|
7abdc96499 | ||
|
|
5a6c7ec187 | ||
|
|
0f483a2d20 | ||
|
|
3400902241 | ||
|
|
f51b74d8b5 | ||
|
|
bf5486a59e | ||
|
|
8a6a83ef06 | ||
|
|
2051d17901 | ||
|
|
477aae6232 | ||
|
|
cb0ed2b6c0 | ||
|
|
484444b97a | ||
|
|
0b1c0da131 | ||
| 6dc6a58765 | |||
| ca8da46a58 | |||
| a28e5244ab | |||
|
|
8151c05d91 | ||
|
|
5c3b45ef08 | ||
|
|
9086196f7d | ||
|
|
5474ae2dda | ||
|
|
31acfd1ee4 | ||
|
|
f1155ad824 | ||
|
|
eef3a81be7 | ||
|
|
bf60e9fcbf | ||
| 7d42256a30 | |||
|
|
5226fbcfc3 | ||
|
|
87b9af9786 | ||
|
|
7981e3ab51 | ||
|
|
21b9b99197 | ||
|
|
d9df0d64b8 | ||
|
|
73cdbe27c0 | ||
| 759b5527f8 | |||
| 8417e60c9d | |||
| aec8a5ee70 | |||
| f34d4214f4 | |||
| a2b6f29886 | |||
| a95d28a09f | |||
|
|
57b1aae9b4 | ||
| 42b4112a5e | |||
| 63a2495183 | |||
|
|
717962edc5 | ||
|
|
dc692f14e4 | ||
| b1a30b6dde | |||
| 967af4dc37 | |||
|
|
7a8fdcdf07 | ||
|
|
a06320c42b | ||
|
|
f0ba8c3c50 | ||
|
|
2e85bf5ee8 | ||
|
|
ff94efee8d | ||
|
|
93f2cf9b73 | ||
|
|
c39e48a709 | ||
|
|
1cc010818d | ||
|
|
1e164f3b93 | ||
|
|
9f7ab65a15 | ||
|
|
c69607323a | ||
|
|
13a7900bd6 | ||
|
|
dc94fa1cd5 | ||
|
|
fd191877cd | ||
|
|
65a5785ce5 | ||
|
|
adcfaf5fa0 | ||
|
|
f7685463b4 | ||
|
|
dd92fa6031 | ||
|
|
6606f30ceb | ||
|
|
e1255e0872 | ||
|
|
5c53621f96 | ||
|
|
581518963b | ||
|
|
23735eba92 | ||
|
|
9eb78f40fd | ||
|
|
f599033a38 | ||
|
|
61f1b92bad | ||
|
|
1dfe246e0f | ||
|
|
d64e40ca2c | ||
|
|
6810c030e8 | ||
|
|
d7a6abd5b9 | ||
|
|
2a2221af31 | ||
|
|
03be3a317f | ||
|
|
bdcd83c579 | ||
|
|
f4f84bdd67 | ||
|
|
86535c23f1 | ||
|
|
5d146c1dfd | ||
|
|
82ca78d8b3 | ||
|
|
55f35868bd | ||
|
|
e0805c9dc6 |
29
.htaccess.old
Normal file
29
.htaccess.old
Normal file
@@ -0,0 +1,29 @@
|
||||
# PHP XDEBUG SETTINGS
|
||||
# php_value xdebug.profiler_output_dir xdebug/
|
||||
# php_value xdebug.profiler_output_name timestamp
|
||||
# php_value xdebug.profiler_enable 1
|
||||
php_value xdebug.collect_params 2
|
||||
php_value xdebug.collect_vars 0
|
||||
php_value xdebug.show_local_vars 0
|
||||
#php_value xdebug.dump_globals 0
|
||||
# allowed COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION
|
||||
#php_value xdebug.dump.GET *
|
||||
# PHP ERROR SETTINGS
|
||||
php_flag short_open_tag off
|
||||
php_flag display_startup_errors on
|
||||
php_flag display_errors on
|
||||
php_flag html_errors on
|
||||
php_flag log_errors on
|
||||
php_flag ignore_repeated_errors off
|
||||
php_flag ignore_repeated_source off
|
||||
php_flag report_memleaks on
|
||||
php_flag track_errors on
|
||||
php_value docref_root 0
|
||||
php_value docref_ext 0
|
||||
# Turn this on to redirect log to different folder
|
||||
#php_value error_log /var/www/html/developers/clemens/php/php-error/php-errors.log
|
||||
# this is E_ALL reporting ON
|
||||
php_value error_reporting -1
|
||||
# this is E_ALL | ~E_NOTICE
|
||||
#php_value error_reporting 2039
|
||||
php_value log_errors_max_len 0
|
||||
127
.phan/config.php
Normal file
127
.phan/config.php
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
* default configuration. Command line arguments will be applied
|
||||
* after this file is read.
|
||||
*
|
||||
* @see src/Phan/Config.php
|
||||
* See Config for all configurable options.
|
||||
*
|
||||
* A Note About Paths
|
||||
* ==================
|
||||
*
|
||||
* Files referenced from this file should be defined as
|
||||
*
|
||||
* ```
|
||||
* Config::projectPath('relative_path/to/file')
|
||||
* ```
|
||||
*
|
||||
* where the relative path is relative to the root of the
|
||||
* project which is defined as either the working directory
|
||||
* of the phan executable or a path passed in via the CLI
|
||||
* '-d' flag.
|
||||
*/
|
||||
|
||||
use Phan\Config;
|
||||
|
||||
return [
|
||||
// If true, missing properties will be created when
|
||||
// they are first seen. If false, we'll report an
|
||||
// error message.
|
||||
"allow_missing_properties" => false,
|
||||
|
||||
// Allow null to be cast as any type and for any
|
||||
// type to be cast to null.
|
||||
"null_casts_as_any_type" => false,
|
||||
|
||||
// Backwards Compatibility Checking
|
||||
'backward_compatibility_checks' => true,
|
||||
|
||||
// Run a quick version of checks that takes less
|
||||
// time
|
||||
"quick_mode" => false,
|
||||
|
||||
// Only emit critical issues to start with
|
||||
// (0 is low severity, 5 is normal severity, 10 is critical)
|
||||
"minimum_severity" => 0,
|
||||
|
||||
// default false for include path check
|
||||
"enable_include_path_checks" => true,
|
||||
"include_paths" => [
|
||||
'.', '../configs/'
|
||||
],
|
||||
'ignore_undeclared_variables_in_global_scope' => true,
|
||||
|
||||
"file_list" => [
|
||||
"./www/configs/config.db.php",
|
||||
"./www/configs/config.host.php",
|
||||
"./www/configs/config.path.php",
|
||||
"./www/configs/config.other.php",
|
||||
"./www/configs/config.master.php",
|
||||
"./www/includes/admin_header.php",
|
||||
],
|
||||
|
||||
// A list of directories that should be parsed for class and
|
||||
// method information. After excluding the directories
|
||||
// defined in exclude_analysis_directory_list, the remaining
|
||||
// files will be statically analyzed for errors.
|
||||
//
|
||||
// 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',
|
||||
],
|
||||
|
||||
|
||||
// A list of directories holding code that we want
|
||||
// to parse, but not analyze
|
||||
"exclude_analysis_directory_list" => [
|
||||
'www/vendor',
|
||||
'www/tests',
|
||||
'www/lib/Smarty',
|
||||
'www/lib/smarty-3.1.30',
|
||||
'www/templates_c',
|
||||
'www/log',
|
||||
'www/tmp',
|
||||
'www/cache',
|
||||
'www/media',
|
||||
],
|
||||
'exclude_file_list' => [
|
||||
// ignore all symlink files to edit
|
||||
'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',
|
||||
// ignore the old qq tests
|
||||
'www/admin/qq_file_upload_front.php',
|
||||
'www/admin/qq_file_upload_ajax.php',
|
||||
// symlink ignore
|
||||
'www/lib/smarty-3.1.30/SmartyBC.class.php',
|
||||
'www/lib/htmlMimeMail-2.5.1/HtmlMimeMailCreate.php',
|
||||
],
|
||||
|
||||
// what not to show as problem
|
||||
'suppress_issue_types' => [
|
||||
// 'PhanUndeclaredMethod',
|
||||
'PhanEmptyFile',
|
||||
],
|
||||
|
||||
// Override to hardcode existence and types of (non-builtin) globals in the global scope.
|
||||
// Class names should be prefixed with `\`.
|
||||
//
|
||||
// (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`)
|
||||
'globals_type_map' => [],
|
||||
];
|
||||
1
.phplint-cache
Normal file
1
.phplint-cache
Normal file
File diff suppressed because one or more lines are too long
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/
|
||||
27
4dev/composer/install.txt
Normal file
27
4dev/composer/install.txt
Normal file
@@ -0,0 +1,27 @@
|
||||
Install composer:
|
||||
# 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-8.0-httpd-2.4/bin/php composer.phar selfupdate
|
||||
|
||||
Install something:
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar require something/something
|
||||
|
||||
Update all installed:
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar update
|
||||
|
||||
Or update only one package:
|
||||
/usr/local/php-8.0-httpd-2.4/bin/php composer.phar something/something
|
||||
|
||||
Install AWS SDK:
|
||||
/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-8.0-httpd-2.4/bin/php composer.phar require maennchen/zipstream-php
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# functions
|
||||
function/update_function.sql
|
||||
function/set_uid.sql
|
||||
function/set_generic.sql
|
||||
function/random_string.sql
|
||||
function/set_edit_generic.sql
|
||||
function/edit_set_access_uid.sql
|
||||
function/edit_log_partition_insert.sql
|
||||
# generic tables
|
||||
table/edit_temp_files.sql
|
||||
table/edit_generic.sql
|
||||
@@ -14,22 +19,29 @@ table/edit_scheme.sql
|
||||
table/edit_language.sql
|
||||
table/edit_group.sql
|
||||
table/edit_page_access.sql
|
||||
table/edit_page_content.sql
|
||||
table/edit_user.sql
|
||||
table/edit_log.sql
|
||||
table/edit_log_overflow.sql
|
||||
table/edit_access.sql
|
||||
table/edit_access_user.sql
|
||||
table/edit_access_data.sql
|
||||
# all triggers (after all tables have been created)
|
||||
trigger/trg_edit_access_right.sql
|
||||
trigger/trg_edit_access.sql
|
||||
trigger/trg_edit_access_data.sql
|
||||
trigger/trg_edit_access_user.sql
|
||||
trigger/trg_edit_generic.sql
|
||||
trigger/trg_edit_group.sql
|
||||
trigger/trg_edit_language.sql
|
||||
trigger/trg_edit_log_overflow.sql
|
||||
trigger/trg_edit_log.sql
|
||||
trigger/trg_edit_page_access.sql
|
||||
trigger/trg_edit_page_content.sql
|
||||
trigger/trg_edit_page.sql
|
||||
trigger/trg_edit_query_string.sql
|
||||
trigger/trg_edit_scheme.sql
|
||||
trigger/trg_edit_user.sql
|
||||
trigger/trg_edit_visible_group.sql
|
||||
trigger/trg_edit_menu_group.sql
|
||||
# insert data
|
||||
data/edit_tables.sql
|
||||
|
||||
@@ -15,22 +15,20 @@ function_name="set_generic";
|
||||
#sql_path_prep=`echo $sql_path | sed -e "s/\///g"`;
|
||||
|
||||
# goes for each file and strips headers and endings, and creates trigger name
|
||||
for name in $sql_path*;
|
||||
do
|
||||
for name in $sql_path*; do
|
||||
echo "Wokring on $name";
|
||||
# strip ending
|
||||
# t_name=`echo $name | sed -e 's/.sql$//g' | sed -e "s/^$sql_path_prep//g" | sed -e 's/\///g'`;
|
||||
t_name=`echo $name | sed -e 's/^.*\///g' | sed -e 's/.sql$//g'`;
|
||||
# clean all beginnings
|
||||
for prefix in $file_prefix;
|
||||
do
|
||||
for prefix in $file_prefix; do
|
||||
prefix=$prefix"_";
|
||||
t_name=`echo $t_name | sed -e "s/\$prefix//g"`;
|
||||
done;
|
||||
|
||||
# those tables don't need a trigger
|
||||
# edit_generic
|
||||
# generic
|
||||
# those tables don't need a trigger
|
||||
# edit_generic
|
||||
# generic
|
||||
|
||||
# copy the trigger template to the target
|
||||
trg_filename=$trigger_path$trigger_prefix"_"$t_name".sql";
|
||||
|
||||
@@ -5,26 +5,23 @@
|
||||
#echo "EXIT";
|
||||
#exit;
|
||||
|
||||
db='cibavision_jp_cms';
|
||||
host='db.tokyo.tequila.jp';
|
||||
user='ciba_vision';
|
||||
db='<db name>';
|
||||
host='<db host>';
|
||||
user='<db user>';
|
||||
schemas="public dev";
|
||||
|
||||
file_prefix="trg";
|
||||
trigger_prefix="trg";
|
||||
index_prefix="idx";
|
||||
|
||||
for file in `cat ORDER`;
|
||||
do
|
||||
if [ -f $file ];
|
||||
then
|
||||
for file in `cat ORDER`; do
|
||||
if [ -f $file ]; then
|
||||
# write them into a var, so we can re order them in the other way
|
||||
new_order=$file" "$new_order;
|
||||
fi;
|
||||
done;
|
||||
|
||||
for file in $new_order;
|
||||
do
|
||||
for file in $new_order; do
|
||||
sqltype=`echo $file | egrep "table/"`;
|
||||
trgtype=`echo $file | egrep "trigger/"`;
|
||||
idxtype=`echo $file | egrep "index/"`;
|
||||
@@ -32,43 +29,34 @@ do
|
||||
datatype=`echo $file | egrep "data/"`;
|
||||
# remove all around to get table name
|
||||
t_file=`echo $file | sed -e 's/^.*\///g' | sed -e 's/.sql$//g'`;
|
||||
for prefix in $file_prefix;
|
||||
do
|
||||
for prefix in $file_prefix; do
|
||||
prefix=$prefix"_";
|
||||
t_file=`echo $t_file | sed -e "s/\$prefix//g"`;
|
||||
done;
|
||||
# copy the trigger template to the target
|
||||
|
||||
for path in $schema;
|
||||
do
|
||||
if [ $sqltype ];
|
||||
then
|
||||
for path in $schemas; do
|
||||
if [ $sqltype ]; then
|
||||
echo "SQL "$path"."$t_file;
|
||||
echo "DROP TABLE "$path"."$t_file" CASCADE;" | psql -U $user -h $host $db
|
||||
fi;
|
||||
if [ $trgtype ];
|
||||
then
|
||||
if [ $trgtype ]; then
|
||||
trigger=$trigger_prefix"_"$t_file;
|
||||
echo "TRG $trigger TBL "$path".$t_file";
|
||||
echo "DROP TRIGGER "$path".$trigger ON "$t_file" CASCADE;" | psql -U $user -h $host $db
|
||||
fi;
|
||||
if [ $fcttype ];
|
||||
then
|
||||
if [ $fcttype ]; then
|
||||
echo "FCT "$path"."$t_file;
|
||||
echo "DROP FUNCTION "$path"."$t_file"();" | psql -U $user -h $host $db
|
||||
fi;
|
||||
if [ $idxtype ];
|
||||
then
|
||||
if [ $idxtype ]; then
|
||||
index=$index_prefix"_"$t_file;
|
||||
# echo "IDX "$t_file;
|
||||
# echo "DROP INDEX $index ON $t_file;" | psql -U $user -h $host $db
|
||||
# echo "IDX "$t_file;
|
||||
# echo "DROP INDEX $index ON $t_file;" | psql -U $user -h $host $db
|
||||
fi;
|
||||
if [ $datatype ];
|
||||
then
|
||||
if [ $datatype ]; then
|
||||
echo "DATA "$t_file;
|
||||
# echo "DROP FUNCTION "$t_file"();" | psql -U $user -h $host $db
|
||||
# echo "DROP FUNCTION "$t_file"();" | psql -U $user -h $host $db
|
||||
fi;
|
||||
|
||||
# psql -U cms_user -h 192.168.12.14 -f $file CMSv2
|
||||
done;
|
||||
done;
|
||||
|
||||
@@ -5,19 +5,63 @@
|
||||
#echo "EXIT";
|
||||
#exit;
|
||||
|
||||
db='gullevek';
|
||||
host='db.tokyo.tequila.jp';
|
||||
user='gullevek';
|
||||
#schema="publicv";
|
||||
# if flagged 'y' then it will ask after each import to continue
|
||||
development='y';
|
||||
test='n';
|
||||
input='';
|
||||
# database connection info
|
||||
db='<db name>';
|
||||
host='<db host>';
|
||||
user='<db user>';
|
||||
schema="public";
|
||||
export PGPASSWORD='';
|
||||
|
||||
for file in `cat ORDER`;
|
||||
do
|
||||
if [ -f $file ];
|
||||
then
|
||||
# for path in $schema;
|
||||
# do
|
||||
# echo "WORK ON "$schema"."$file;
|
||||
psql -U $user -h $host -f $file $db 1>> output 2>> error
|
||||
# done;
|
||||
# log files
|
||||
error_file="log/error";
|
||||
output_file="log/output";
|
||||
|
||||
if [ ! -f ORDER ]; then
|
||||
echo "Could not find ORDER file";
|
||||
exit;
|
||||
fi;
|
||||
|
||||
if [ "$test" != "n" ]; then
|
||||
echo "TESTING MODE, NO DATA WILL BE IMPORTED";
|
||||
fi;
|
||||
if [ "$development" = "y" ]; then
|
||||
echo "STEP BY STEP IMPORT MODE ACTIVATED";
|
||||
fi;
|
||||
|
||||
while read file <&3; do
|
||||
if [ "$file" = "FINISHED" ]; then
|
||||
echo "Database data is flagged as FINISHED in ORDER file";
|
||||
exit;
|
||||
fi;
|
||||
done;
|
||||
if [ -f "$file" ]; then
|
||||
for path in "$schemas"; do
|
||||
echo "[+] WORK ON '${file}' @ '${path}'";
|
||||
if [ "$test" = 'n' ]; then
|
||||
echo "=== START [$file] ===>" >> ${error_file};
|
||||
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
||||
echo "=== END [$file] ===>" >> ${error_file};
|
||||
fi;
|
||||
if [ "$development" = "y" ]; then
|
||||
echo "Press 'y' to move to next. Press 'r' to reload last file. ^c to abort";
|
||||
fi;
|
||||
while [ "$development" = "y" ] && [ "$input" != "y" ]; do
|
||||
read -ep "Continue (y|r|^c): " input;
|
||||
if [ "$input" = "r" ]; then
|
||||
echo "Reload File '${file}' ...";
|
||||
if [ "$test" = 'n' ]; then
|
||||
echo "=== START RELOAD [$file] ===>" >> ${error_file};
|
||||
psql -U ${user} -h ${host} -f "${file}" ${db} 1>> ${output_file} 2>> ${error_file}
|
||||
echo "=== END RELOAD [$file] ===>" >> ${error_file};
|
||||
fi;
|
||||
fi;
|
||||
done;
|
||||
input='';
|
||||
done;
|
||||
elif [[ ${file::1} != "#" ]]; then
|
||||
echo "[!] COULD NOT FIND FILE: '${file}'";
|
||||
fi;
|
||||
done 3<ORDER;
|
||||
|
||||
148
4dev/database/data/edit_tables.sql
Executable file
148
4dev/database/data/edit_tables.sql
Executable file
@@ -0,0 +1,148 @@
|
||||
-- edit tables insert data in order
|
||||
|
||||
-- edit visible group
|
||||
DELETE FROM edit_visible_group;
|
||||
INSERT INTO edit_visible_group (name, flag) VALUES ('Main Menu', 'main');
|
||||
INSERT INTO edit_visible_group (name, flag) VALUES ('Data popup Menu', 'datapopup');
|
||||
|
||||
-- edit menu group
|
||||
DELETE FROM edit_menu_group;
|
||||
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Menu', 'admin', 1);
|
||||
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Data Popup Menu', 'AdminDataPopup', 2);
|
||||
|
||||
-- edit page
|
||||
DELETE FROM edit_page;
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_pages.php', 'Edit Pages', 1, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_users.php', 'Edit Users', 2, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_languages.php', 'Edit Languages', 3, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_schemes.php', 'Edit Schemes', 4, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_groups.php', 'Edit Groups', 5, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_visible_group.php', 'Edit Visible Groups', 6, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_menu_group.php', 'Edit Menu Groups', 7, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_access.php', 'Edit Access', 8, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_order.php', 'Edit Order', 9, 1, 0);
|
||||
|
||||
-- edit visible group
|
||||
DELETE FROM edit_page_visible_group;
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
-- INSERT INTO edit_page_visible_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_visible_group_id FROM edit_visible_group WHERE flag = 'main'));
|
||||
|
||||
-- edit page menu group
|
||||
DELETE FROM edit_page_menu_group;
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
-- INSERT INTO edit_page_menu_group VALUES ((SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'), (SELECT edit_menu_group_id FROM edit_menu_group WHERE flag = 'admin'));
|
||||
|
||||
|
||||
-- edit access right
|
||||
DELETE FROM edit_access_right;
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Default', -1, 'default');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('No Access', 0, 'none');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('List', 10, 'list');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Read', 20, 'read');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Translator', 30, 'mod_trans');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Modify', 40, 'mod');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Create/Write', 60, 'write');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Delete', 80, 'del');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Site Admin', 90, 'siteadmin');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Admin', 100, 'admin');
|
||||
|
||||
-- edit scheme
|
||||
DELETE FROM edit_scheme;
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Default Scheme', 'E0E2FF', 1);
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Admin', 'CC7E7E', 1);
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', 'B0C4B3', 1);
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('User', '1E789E', 1);
|
||||
|
||||
-- edit language
|
||||
DELETE FROM edit_language;
|
||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('en', 'English', 'UTF-8', 1, 1, 1);
|
||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('ja', 'Japanese', 'UTF-8', 2, 1, 0);
|
||||
|
||||
-- edit group
|
||||
DELETE FROM edit_group;
|
||||
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('Admin', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin'));
|
||||
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('User', 1, (SELECT edit_scheme_id FROM edit_scheme WHERE name = 'User'), (SELECT edit_access_right_id FROM edit_access_right WHERE type = 'write'));
|
||||
|
||||
-- edit page access
|
||||
DELETE FROM edit_page_access;
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Pages'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Users'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Languages'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Schemes'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Groups'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Visible Groups'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Menu Groups'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Access'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1,
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_page_id FROM edit_page WHERE name = 'Edit Order'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
|
||||
-- edit user
|
||||
-- inserts admin user so basic users can be created
|
||||
DELETE FROM edit_user;
|
||||
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1,
|
||||
(SELECT edit_language_id FROM edit_language WHERE short_name = 'en'),
|
||||
(SELECT edit_group_id FROM edit_group WHERE name = 'Admin'),
|
||||
(SELECT edit_scheme_id FROM edit_scheme WHERE name = 'Admin'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
|
||||
-- edit access
|
||||
DELETE FROM edit_access;
|
||||
INSERT INTO edit_access (name, enabled, protected) VALUES ('Admin Access', 1, 1);
|
||||
|
||||
-- edit access user
|
||||
DELETE FROM edit_access_user;
|
||||
INSERT INTO edit_access_user (edit_default, enabled, edit_access_id, edit_user_id, edit_access_right_id) VALUES (1, 1,
|
||||
(SELECT edit_access_id FROM edit_access WHERE uid = 'AdminAccess'),
|
||||
(SELECT edit_user_id FROM edit_user WHERE username = 'admin'),
|
||||
(SELECT edit_access_right_id FROM edit_access_right WHERE type = 'admin')
|
||||
);
|
||||
150
4dev/database/function/edit_log_partition_insert.sql
Normal file
150
4dev/database/function/edit_log_partition_insert.sql
Normal file
@@ -0,0 +1,150 @@
|
||||
-- AUTHOR: Clemens Schwaighofer
|
||||
-- DATE: 2018-07-17
|
||||
-- DESCRIPTION:
|
||||
-- partition the edit_log table by year
|
||||
-- auto creates table if missing, if failure writes to overflow table
|
||||
-- HISTORY:
|
||||
|
||||
CREATE OR REPLACE FUNCTION edit_log_insert_trigger ()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
start_date DATE := '2010-01-01';
|
||||
end_date DATE;
|
||||
timeformat TEXT := 'YYYY';
|
||||
selector TEXT := 'year';
|
||||
base_table TEXT := 'edit_log';
|
||||
_interval INTERVAL := '1 ' || selector;
|
||||
_interval_next INTERVAL := '2 ' || selector;
|
||||
table_name TEXT;
|
||||
-- compare date column
|
||||
compare_date DATE := NEW.event_date;
|
||||
compare_date_name TEXT := 'event_date';
|
||||
-- the create commands
|
||||
command_create_table TEXT := 'CREATE TABLE IF NOT EXISTS {TABLE_NAME} (CHECK({COMPARE_DATE_NAME} >= {START_DATE} AND {COMPARE_DATE_NAME} < {END_DATE})) INHERITS ({BASE_NAME})';
|
||||
command_create_primary_key TEXT := 'ALTER TABLE {TABLE_NAME} ADD PRIMARY KEY ({BASE_TABLE}_id)';
|
||||
command_create_foreign_key_1 TEXT := 'ALTER TABLE {TABLE_NAME} ADD CONSTRAINT {TABLE_NAME}_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL';
|
||||
command_create_trigger_1 TEXT = 'CREATE TRIGGER trg_{TABLE_NAME} BEFORE INSERT OR UPDATE ON {TABLE_NAME} FOR EACH ROW EXECUTE PROCEDURE set_edit_generic()';
|
||||
BEGIN
|
||||
-- we are in valid start time area
|
||||
IF (NEW.event_date >= start_date) THEN
|
||||
-- current table name
|
||||
table_name := base_table || '_' || to_char(NEW.event_date, timeformat);
|
||||
BEGIN
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
-- if insert failed because of missing table, create new below
|
||||
EXCEPTION
|
||||
WHEN undefined_table THEN
|
||||
-- another block, so in case the creation fails here too
|
||||
BEGIN
|
||||
-- create new table here + all indexes
|
||||
start_date := date_trunc(selector, NEW.event_date);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
-- creat table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
|
||||
-- insert try again
|
||||
EXECUTE 'INSERT INTO ' || quote_ident(table_name) || ' SELECT ($1).*' USING NEW;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- other errors, insert into overlow
|
||||
WHEN OTHERS THEN
|
||||
-- if this faled, throw it into the overflow table (so we don't loose anything)
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END;
|
||||
-- main insert run done, check if we have to create next months table
|
||||
BEGIN
|
||||
-- check if next month table exists
|
||||
table_name := base_table || '_' || to_char((SELECT NEW.event_date + _interval)::DATE, timeformat);
|
||||
-- RAISE NOTICE 'SEARCH NEXT: %', table_name;
|
||||
IF (SELECT to_regclass(table_name)) IS NULL THEN
|
||||
-- move inner interval same
|
||||
start_date := date_trunc(selector, NEW.event_date + _interval);
|
||||
end_date := date_trunc(selector, NEW.event_date + _interval_next);
|
||||
-- RAISE NOTICE 'CREATE NEXT: %', table_name;
|
||||
-- create table
|
||||
EXECUTE format(REPLACE( -- end date
|
||||
REPLACE( -- start date
|
||||
REPLACE( -- compare date name
|
||||
REPLACE( -- base name (inherit)
|
||||
REPLACE( -- table name
|
||||
command_create_table,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_NAME}',
|
||||
base_table
|
||||
),
|
||||
'{COMPARE_DATE_NAME}',
|
||||
compare_date_name
|
||||
),
|
||||
'{START_DATE}',
|
||||
quote_literal(start_date)
|
||||
),
|
||||
'{END_DATE}',
|
||||
quote_literal(end_date)
|
||||
));
|
||||
-- create all indexes and triggers
|
||||
EXECUTE format(REPLACE(
|
||||
REPLACE(
|
||||
command_create_primary_key,
|
||||
'{TABLE_NAME}',
|
||||
table_name
|
||||
),
|
||||
'{BASE_TABLE}',
|
||||
base_table
|
||||
));
|
||||
-- FK constraints
|
||||
EXECUTE format(REPLACE(command_create_foreign_key_1, '{TABLE_NAME}', table_name));
|
||||
-- generic trigger
|
||||
EXECUTE format(REPLACE(command_create_trigger_1, '{TABLE_NAME}', table_name));
|
||||
END IF;
|
||||
EXCEPTION
|
||||
WHEN OTHERS THEN
|
||||
RAISE NOTICE 'Failed to create next table: %', table_name;
|
||||
END;
|
||||
ELSE
|
||||
-- if outside valid date, insert into overflow
|
||||
INSERT INTO edit_log_overflow VALUES (NEW.*);
|
||||
END IF;
|
||||
RETURN NULL;
|
||||
END
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
@@ -1,6 +1,6 @@
|
||||
-- add uid add for edit_access table
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
|
||||
CREATE OR REPLACE FUNCTION set_edit_access_uid() RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
myrec RECORD;
|
||||
|
||||
28
4dev/database/function/edit_set_group_uid.sql
Executable file
28
4dev/database/function/edit_set_group_uid.sql
Executable file
@@ -0,0 +1,28 @@
|
||||
-- add uid add for edit_group table
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_edit_group_uid() RETURNS TRIGGER AS
|
||||
$$
|
||||
DECLARE
|
||||
myrec RECORD;
|
||||
v_uid VARCHAR;
|
||||
BEGIN
|
||||
-- skip if NEW.name is not set
|
||||
IF NEW.name IS NOT NULL AND NEW.name <> '' THEN
|
||||
-- use NEW.name as base, remove all spaces
|
||||
-- name data is already unique, so we do not need to worry about this here
|
||||
v_uid := REPLACE(NEW.name, ' ', '');
|
||||
IF TG_OP = 'INSERT' THEN
|
||||
-- always set
|
||||
NEW.uid := v_uid;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
-- check if not set, then set
|
||||
SELECT INTO myrec t.* FROM edit_group t WHERE edit_group_id = NEW.edit_group_id;
|
||||
IF FOUND THEN
|
||||
NEW.uid := v_uid;
|
||||
END IF;
|
||||
END IF;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$
|
||||
LANGUAGE 'plpgsql';
|
||||
18
4dev/database/function/random_string.sql
Normal file
18
4dev/database/function/random_string.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
-- create random string with length X
|
||||
|
||||
CREATE FUNCTION random_string(randomLength int)
|
||||
RETURNS text AS $$
|
||||
SELECT array_to_string(
|
||||
ARRAY(
|
||||
SELECT substring(
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
|
||||
trunc(random() * 62)::int + 1,
|
||||
1
|
||||
)
|
||||
FROM generate_series(1, randomLength) AS gs(x)
|
||||
),
|
||||
''
|
||||
)
|
||||
$$ LANGUAGE SQL
|
||||
RETURNS NULL ON NULL INPUT
|
||||
VOLATILE; -- LEAKPROOF;
|
||||
15
4dev/database/function/set_edit_generic.sql
Normal file
15
4dev/database/function/set_edit_generic.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_edit_generic() RETURNS TRIGGER AS '
|
||||
DECLARE
|
||||
random_length INT = 12; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = ''INSERT'' THEN
|
||||
NEW.date_created := ''now'';
|
||||
NEW.cuid := random_string(random_length);
|
||||
ELSIF TG_OP = ''UPDATE'' THEN
|
||||
NEW.date_updated := ''now'';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
12
4dev/database/function/set_generic.sql
Normal file
12
4dev/database/function/set_generic.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
|
||||
BEGIN
|
||||
IF TG_OP = ''INSERT'' THEN
|
||||
NEW.date_created := ''now'';
|
||||
ELSIF TG_OP = ''UPDATE'' THEN
|
||||
NEW.date_updated := ''now'';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
12
4dev/database/function/set_uid.sql
Normal file
12
4dev/database/function/set_uid.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_uid() RETURNS TRIGGER AS '
|
||||
DECLARE
|
||||
random_length INT = 32; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = ''INSERT'' THEN
|
||||
NEW.uid := random_string(random_length);
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
@@ -1,14 +1,16 @@
|
||||
-- adds the created or updated date tags
|
||||
|
||||
CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
|
||||
BEGIN
|
||||
IF TG_OP = ''INSERT'' THEN
|
||||
NEW.date_created := clock_timestamp();
|
||||
NEW.user_created := current_user;
|
||||
ELSIF TG_OP = ''UPDATE'' THEN
|
||||
NEW.date_updated := clock_timestamp();
|
||||
NEW.user_updated := current_user;
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
-- OLD, DEPRECATED, use set_generic.sql
|
||||
|
||||
-- CREATE OR REPLACE FUNCTION set_generic() RETURNS TRIGGER AS '
|
||||
-- BEGIN
|
||||
-- IF TG_OP = ''INSERT'' THEN
|
||||
-- NEW.date_created := clock_timestamp();
|
||||
-- NEW.user_created := current_user;
|
||||
-- ELSIF TG_OP = ''UPDATE'' THEN
|
||||
-- NEW.date_updated := clock_timestamp();
|
||||
-- NEW.user_updated := current_user;
|
||||
-- END IF;
|
||||
-- RETURN NEW;
|
||||
-- END;
|
||||
-- ' LANGUAGE 'plpgsql';
|
||||
|
||||
2
4dev/database/log/.gitignore
vendored
Normal file
2
4dev/database/log/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -8,10 +8,12 @@
|
||||
-- DROP TABLE edit_access;
|
||||
CREATE TABLE edit_access (
|
||||
edit_access_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255) UNIQUE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
protected SMALLINT DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
description VARCHAR,
|
||||
COLOR VARCHAR
|
||||
color VARCHAR,
|
||||
additional_acl JSONB
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_access;
|
||||
INSERT INTO edit_access (name) VALUES ('Admin Access');
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
CREATE TABLE edit_access_data (
|
||||
edit_access_data_id SERIAL PRIMARY KEY,
|
||||
edit_access_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
value VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -14,14 +14,3 @@ CREATE TABLE edit_access_right (
|
||||
type VARCHAR,
|
||||
UNIQUE (level,type)
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_access_right;
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Default', -1, 'default');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('No Access', 0, 'none');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Read', 20, 'read');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Translator', 30, 'mod_trans');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Modify', 40, 'mod');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Create/Write', 60, 'write');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Delete', 80, 'del');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Site Admin', 90, 'siteadmin');
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('Admin', 100, 'admin');
|
||||
|
||||
@@ -8,15 +8,12 @@
|
||||
-- DROP TABLE edit_access_user;
|
||||
CREATE TABLE edit_access_user (
|
||||
edit_access_user_id SERIAL PRIMARY KEY,
|
||||
edit_default SMALLINT DEFAULT 0,
|
||||
edit_access_id INT NOT NULL,
|
||||
edit_user_id INT NOT NULL,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (edit_access_id) REFERENCES edit_access (edit_access_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_user_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_default SMALLINT DEFAULT 0,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_access_user;
|
||||
INSERT INTO edit_access_user (edit_default, edit_access_id, edit_user_id, edit_access_right_id) VALUES (1, 1, 1, 8);
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
|
||||
-- DROP TABLE edit_generic;
|
||||
CREATE TABLE edit_generic (
|
||||
eg_status INT,
|
||||
cuid VARCHAR,
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||
user_created VARCHAR(25) DEFAULT CURRENT_USER,
|
||||
user_updated VARCHAR(25)
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
@@ -8,12 +8,13 @@
|
||||
-- DROP TABLE edit_group;
|
||||
CREATE TABLE edit_group (
|
||||
edit_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(50),
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
edit_scheme_id INT,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT DEFAULT 0,
|
||||
uid VARCHAR,
|
||||
name VARCHAR,
|
||||
additional_acl JSONB
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
INSERT INTO edit_group (name, enabled, edit_scheme_id, edit_access_right_id) VALUES ('Admin', 1, 2, 8);
|
||||
|
||||
@@ -9,12 +9,10 @@
|
||||
-- DROP TABLE edit_language;
|
||||
CREATE TABLE edit_language (
|
||||
edit_language_id SERIAL PRIMARY KEY,
|
||||
short_name VARCHAR(2),
|
||||
long_name VARCHAR(70),
|
||||
iso_name VARCHAR(12),
|
||||
order_number INT,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0 UNIQUE
|
||||
lang_default SMALLINT NOT NULL DEFAULT 0,
|
||||
long_name VARCHAR,
|
||||
short_name VARCHAR,
|
||||
iso_name VARCHAR,
|
||||
order_number INT
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
INSERT INTO edit_language (short_name, long_name, iso_name, order_number, enabled, lang_default) VALUES ('en', 'English', 'UTF-8', 1, 1, 1);
|
||||
|
||||
@@ -8,9 +8,11 @@
|
||||
-- DROP TABLE edit_log;
|
||||
CREATE TABLE edit_log (
|
||||
edit_log_id SERIAL PRIMARY KEY,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
username VARCHAR,
|
||||
password VARCHAR,
|
||||
event_date TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
event_date TIMESTAMP WITHOUT TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||
ip VARCHAR,
|
||||
error TEXT,
|
||||
event TEXT,
|
||||
@@ -26,7 +28,6 @@ CREATE TABLE edit_log (
|
||||
action_value VARCHAR,
|
||||
action_type VARCHAR,
|
||||
action_error VARCHAR,
|
||||
euid INT, -- this is a foreign key, but I don't nedd to reference to it
|
||||
user_agent VARCHAR,
|
||||
referer VARCHAR,
|
||||
script_name VARCHAR,
|
||||
@@ -36,6 +37,5 @@ CREATE TABLE edit_log (
|
||||
http_accept VARCHAR,
|
||||
http_accept_charset VARCHAR,
|
||||
http_accept_encoding VARCHAR,
|
||||
session_id VARCHAR,
|
||||
FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE
|
||||
session_id VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
12
4dev/database/table/edit_log_overflow.sql
Normal file
12
4dev/database/table/edit_log_overflow.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- AUTHOR: Clemens Schwaighofer
|
||||
-- DATE: 2020/1/28
|
||||
-- DESCRIPTION:
|
||||
-- edit log overflow table
|
||||
-- this is the overflow table for partition
|
||||
-- TABLE: edit_log_overflow
|
||||
-- HISTORY:
|
||||
|
||||
-- DROP TABLE edit_log_overflow;
|
||||
CREATE TABLE IF NOT EXISTS edit_log_overflow () INHERITS (edit_log);
|
||||
ALTER TABLE edit_log_overflow ADD PRIMARY KEY (edit_log_id);
|
||||
ALTER TABLE edit_log_overflow ADD CONSTRAINT edit_log_overflow_euid_fkey FOREIGN KEY (euid) REFERENCES edit_user (edit_user_id) MATCH FULL ON UPDATE CASCADE ON DELETE SET NULL;
|
||||
@@ -8,11 +8,9 @@
|
||||
-- DROP TABLE edit_menu_group;
|
||||
CREATE TABLE edit_menu_group (
|
||||
edit_menu_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255),
|
||||
flag VARCHAR(50),
|
||||
name VARCHAR,
|
||||
flag VARCHAR,
|
||||
order_number INT NOT NULL
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_menu_group;
|
||||
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Menu', 'admin', 1);
|
||||
INSERT INTO edit_menu_group (name, flag, order_number) VALUES ('Admin Data Popup Menu', 'AdminDataPopup', 2);
|
||||
|
||||
|
||||
@@ -2,29 +2,21 @@
|
||||
-- DATE: 2005/07/05
|
||||
-- DESCRIPTION:
|
||||
-- edit tables, this table contains all pages in the edit interface and allocates rights + values to it
|
||||
-- TABLE: edit_table
|
||||
-- TABLE: edit_page
|
||||
-- HISTORY:
|
||||
|
||||
-- DROP TABLE edit_page;
|
||||
CREATE TABLE edit_page (
|
||||
edit_page_id SERIAL PRIMARY KEY,
|
||||
filename VARCHAR(70),
|
||||
name VARCHAR(255) UNIQUE,
|
||||
content_alias_edit_page_id INT, -- alias for page content, if the page content is defined on a different page, ege for ajax backend pages
|
||||
FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE,
|
||||
filename VARCHAR,
|
||||
name VARCHAR UNIQUE,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0,
|
||||
menu SMALLINT NOT NULL DEFAULT 0,
|
||||
popup SMALLINT NOT NULL DEFAULT 0,
|
||||
popup_x SMALLINT,
|
||||
popup_y SMALLINT
|
||||
popup_y SMALLINT,
|
||||
hostname VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_page;
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_pages.php', 'Edit Pages', 1, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_users.php', 'Edit Users', 2, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_languages.php', 'Edit Languages', 3, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_schemes.php', 'Edit Schemes', 4, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_groups.php', 'Edit Groups', 5, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_visible_group.php', 'Edit Visible Groups', 6, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_menu_group.php', 'Edit Menu Groups', 7, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_access.php', 'Edit Access', 8, 1, 1);
|
||||
INSERT INTO edit_page (filename, name, order_number, online, menu) VALUES ('edit_order.php', 'Edit Order', 9, 1, 0);
|
||||
|
||||
@@ -8,21 +8,13 @@
|
||||
-- DROP TABLE edit_page_access;
|
||||
CREATE TABLE edit_page_access (
|
||||
edit_page_access_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
edit_group_id INT NOT NULL,
|
||||
edit_page_id INT NOT NULL,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 1, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 2, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 3, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 4, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 5, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 6, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 7, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 8, 8);
|
||||
INSERT INTO edit_page_access (enabled, edit_group_id, edit_page_id, edit_access_right_id) VALUES (1, 1, 9, 8);
|
||||
|
||||
|
||||
20
4dev/database/table/edit_page_content.sql
Normal file
20
4dev/database/table/edit_page_content.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
-- AUTHOR: Clemens Schwaighofer
|
||||
-- DATE: 2019/9/9
|
||||
-- DESCRIPTION:
|
||||
-- sub content to one page with additional edit access right set
|
||||
-- can be eg JS content groups on one page
|
||||
-- TABLE: edit_page_content
|
||||
-- HISTORY:
|
||||
|
||||
-- DROP TABLE edit_page_content;
|
||||
CREATE TABLE edit_page_content (
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
uid VARCHAR UNIQUE,
|
||||
name VARCHAR,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
@@ -8,16 +8,7 @@
|
||||
-- DROP TABLE edit_page_menu_group;
|
||||
CREATE TABLE edit_page_menu_group (
|
||||
edit_page_id INT NOT NULL,
|
||||
edit_menu_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_menu_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_menu_group_id) REFERENCES edit_menu_group (edit_menu_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
DELETE FROM edit_page_menu_group;
|
||||
INSERT INTO edit_page_menu_group VALUES (1, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (2, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (3, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (4, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (5, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (6, 1);
|
||||
INSERT INTO edit_page_menu_group VALUES (7, 1);
|
||||
|
||||
@@ -8,16 +8,7 @@
|
||||
-- DROP TABLE edit_page_visible_group;
|
||||
CREATE TABLE edit_page_visible_group (
|
||||
edit_page_id INT NOT NULL,
|
||||
edit_visible_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_visible_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_visible_group_id) REFERENCES edit_visible_group (edit_visible_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
DELETE FROM edit_page_visible_group;
|
||||
INSERT INTO edit_page_visible_group VALUES (1, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (2, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (3, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (4, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (5, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (6, 1);
|
||||
INSERT INTO edit_page_visible_group VALUES (7, 1);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
-- DROP TABLE edit_query_string;
|
||||
CREATE TABLE edit_query_string (
|
||||
edit_query_string_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255),
|
||||
value VARCHAR(255),
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
dynamic SMALLINT NOT NULL DEFAULT 0,
|
||||
edit_page_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR,
|
||||
value VARCHAR,
|
||||
dynamic SMALLINT NOT NULL DEFAULT 0
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
@@ -9,12 +9,8 @@
|
||||
CREATE TABLE edit_scheme (
|
||||
edit_scheme_id SERIAL PRIMARY KEY,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
name VARCHAR(50),
|
||||
header_color VARCHAR(7),
|
||||
css_file VARCHAR(50),
|
||||
template VARCHAR(50)
|
||||
name VARCHAR,
|
||||
header_color VARCHAR,
|
||||
css_file VARCHAR,
|
||||
template VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Default Scheme', '#E0E2FF', 1);
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Admin', '#CC7E7E', 1);
|
||||
INSERT INTO edit_scheme (name, header_color, enabled) VALUES ('Visitor', '#B0C4B3', 1);
|
||||
|
||||
@@ -7,5 +7,6 @@
|
||||
|
||||
-- DROP TABLE temp_files;
|
||||
CREATE TABLE temp_files (
|
||||
filename VARCHAR(250)
|
||||
filename VARCHAR,
|
||||
folder VARCHAR
|
||||
);
|
||||
|
||||
@@ -8,31 +8,41 @@
|
||||
-- DROP TABLE edit_user;
|
||||
CREATE TABLE edit_user (
|
||||
edit_user_id SERIAL PRIMARY KEY,
|
||||
connect_edit_user_id INT, -- possible reference to other user
|
||||
FOREIGN KEY (connect_edit_user_id) REFERENCES edit_user (edit_user_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_language_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_group_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_scheme_id INT,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
deleted SMALLINT NOT NULL DEFAULT 0,
|
||||
username VARCHAR UNIQUE,
|
||||
password VARCHAR,
|
||||
enabled SMALLINT NOT NULL DEFAULT 0,
|
||||
first_name VARCHAR,
|
||||
last_name VARCHAR,
|
||||
first_name_furigana VARCHAR,
|
||||
last_name_furigana VARCHAR,
|
||||
debug SMALLINT NOT NULL DEFAULT 0,
|
||||
db_debug SMALLINT NOT NULL DEFAULT 0,
|
||||
email VARCHAR,
|
||||
protected SMALLINT NOT NULL DEFAULT 0,
|
||||
admin SMALLINT NOT NULL DEFAULT 0,
|
||||
edit_language_id INT NOT NULL,
|
||||
edit_group_id INT NOT NULL,
|
||||
edit_scheme_id INT,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
login_error_count INT,
|
||||
login_error_date_last TIMESTAMP WTIHOUT TIME ZONE,
|
||||
login_error_date_first TIMESTAMP WTIHOUT TIME ZONE,
|
||||
last_login TIMESTAMP WITHOUT TIME ZONE,
|
||||
login_error_count INT DEFAULT 0,
|
||||
login_error_date_last TIMESTAMP WITHOUT TIME ZONE,
|
||||
login_error_date_first TIMESTAMP WITHOUT TIME ZONE,
|
||||
strict SMALLINT DEFAULT 0,
|
||||
locked SMALLINT DEFAULT 0,
|
||||
password_change_date TIMESTAMP WITHOUT TIME ZONE, -- only when password is first set or changed
|
||||
password_change_interval INTERVAL, -- null if no change is needed, or d/m/y time interval
|
||||
FOREIGN KEY (edit_language_id) REFERENCES edit_language (edit_language_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_group_id) REFERENCES edit_group (edit_group_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_scheme_id) REFERENCES edit_scheme (edit_scheme_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
password_reset_time TIMESTAMP WITHOUT TIME ZONE, -- when the password reset was requested
|
||||
password_reset_uid VARCHAR, -- the uid to access the password reset page
|
||||
additional_acl JSONB -- additional ACL as JSON string (can be set by other pages)
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
-- inserts admin user so basic users can be created
|
||||
DELETE FROM edit_user;
|
||||
INSERT INTO edit_user (username, password, enabled, debug, db_debug, email, protected, admin, edit_language_id, edit_group_id, edit_scheme_id, edit_access_right_id) VALUES ('admin', 'admin', 1, 1, 1, '', 1, 1, 1, 1, 2, 8);
|
||||
COMMENT ON COLUMN edit_user.password_reset_time IS 'When the password reset was requested. For reset page uid valid check';
|
||||
COMMENT ON COLUMN edit_user.password_reset_uid IS 'Password reset page uid';
|
||||
|
||||
@@ -8,10 +8,6 @@
|
||||
-- DROP TABLE edit_visible_group;
|
||||
CREATE TABLE edit_visible_group (
|
||||
edit_visible_group_id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255),
|
||||
flag VARCHAR(50)
|
||||
name VARCHAR,
|
||||
flag VARCHAR
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
|
||||
DELETE FROM edit_visible_group;
|
||||
INSERT INTO edit_visible_group (name, flag) VALUES ('Main Menu', 'main');
|
||||
INSERT INTO edit_visible_group (name, flag) VALUES ('Data popup Menu', 'datapopup');
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
-- DROP TABLE edit_generic;
|
||||
CREATE TABLE generic (
|
||||
row_status INT,
|
||||
date_created TIMESTAMP WITHOUT TIME ZONE DEFAULT clock_timestamp(),
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE,
|
||||
user_created VARCHAR(25) DEFAULT CURRENT_USER,
|
||||
user_updated VARCHAR(25)
|
||||
date_updated TIMESTAMP WITHOUT TIME ZONE
|
||||
);
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
-- DROP TRIGGER trg_edit_access ON edit_access;
|
||||
DROP TRIGGER IF EXISTS trg_edit_access ON edit_access;
|
||||
CREATE TRIGGER trg_edit_access
|
||||
BEFORE INSERT OR UPDATE ON edit_access
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
DROP TRIGGER IF EXISTS trg_set_edit_access_uid ON edit_access;
|
||||
CREATE TRIGGER trg_set_edit_access_uid
|
||||
BEFORE INSERT OR UPDATE ON edit_access
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_access_data ON edit_access_data;
|
||||
DROP TRIGGER IF EXISTS trg_edit_access_data ON edit_access_data;
|
||||
CREATE TRIGGER trg_edit_access_data
|
||||
BEFORE INSERT OR UPDATE ON edit_access_data
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_access_right ON edit_access_right;
|
||||
DROP TRIGGER IF EXISTS trg_edit_access_right ON edit_access_right;
|
||||
CREATE TRIGGER trg_edit_access_right
|
||||
BEFORE INSERT OR UPDATE ON edit_access_right
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_access_user ON edit_access_user;
|
||||
DROP TRIGGER IF EXISTS trg_edit_access_user ON edit_access_user;
|
||||
CREATE TRIGGER trg_edit_access_user
|
||||
BEFORE INSERT OR UPDATE ON edit_access_user
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
-- DROP TRIGGER trg_edit_group ON edit_group;
|
||||
DROP TRIGGER IF EXISTS trg_edit_group ON edit_group;
|
||||
CREATE TRIGGER trg_edit_group
|
||||
BEFORE INSERT OR UPDATE ON edit_group
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
DROP TRIGGER IF EXISTS trg_set_edit_group_uid ON edit_group;
|
||||
CREATE TRIGGER trg_set_edit_group_uid
|
||||
BEFORE INSERT OR UPDATE ON edit_group
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_group_uid();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_language ON edit_language;
|
||||
DROP TRIGGER IF EXISTS trg_edit_language ON edit_language;
|
||||
CREATE TRIGGER trg_edit_language
|
||||
BEFORE INSERT OR UPDATE ON edit_language
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
-- DROP TRIGGER trg_edit_log ON edit_log;
|
||||
DROP TRIGGER IF EXISTS trg_edit_log ON edit_log;
|
||||
CREATE TRIGGER trg_edit_log
|
||||
BEFORE INSERT OR UPDATE ON edit_log
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
DROP TRIGGER IF EXISTS trg_edit_log_insert_partition ON edit_log;
|
||||
CREATE TRIGGER trg_edit_log_insert_partition
|
||||
BEFORE INSERT OR UPDATE ON edit_log
|
||||
FOR EACH ROW EXECUTE PROCEDURE edit_log_insert_trigger();
|
||||
|
||||
4
4dev/database/trigger/trg_edit_log_overflow.sql
Normal file
4
4dev/database/trigger/trg_edit_log_overflow.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
DROP TRIGGER IF EXISTS trg_edit_log_overflow ON edit_log_overflow;
|
||||
CREATE TRIGGER trg_edit_log_overflow
|
||||
BEFORE INSERT OR UPDATE ON edit_log_overflow
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_visible_group ON edit_visible_group;
|
||||
DROP TRIGGER IF EXISTS trg_edit_menu_group ON edit_menu_group;
|
||||
CREATE TRIGGER trg_edit_menu_group
|
||||
BEFORE INSERT OR UPDATE ON edit_menu_group
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_page ON edit_page;
|
||||
DROP TRIGGER IF EXISTS trg_edit_page ON edit_page;
|
||||
CREATE TRIGGER trg_edit_page
|
||||
BEFORE INSERT OR UPDATE ON edit_page
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_page_access ON edit_page_access;
|
||||
DROP TRIGGER IF EXISTS trg_edit_page_access ON edit_page_access;
|
||||
CREATE TRIGGER trg_edit_page_access
|
||||
BEFORE INSERT OR UPDATE ON edit_page_access
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
4
4dev/database/trigger/trg_edit_page_content.sql
Normal file
4
4dev/database/trigger/trg_edit_page_content.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
DROP TRIGGER IF EXISTS trg_edit_page_content ON edit_page_content;
|
||||
CREATE TRIGGER trg_edit_page_content
|
||||
BEFORE INSERT OR UPDATE ON edit_page_content
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_query_string ON edit_query_string;
|
||||
DROP TRIGGER IF EXISTS trg_edit_query_string ON edit_query_string;
|
||||
CREATE TRIGGER trg_edit_query_string
|
||||
BEFORE INSERT OR UPDATE ON edit_query_string
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_scheme ON edit_scheme;
|
||||
DROP TRIGGER IF EXISTS trg_edit_scheme ON edit_scheme;
|
||||
CREATE TRIGGER trg_edit_scheme
|
||||
BEFORE INSERT OR UPDATE ON edit_scheme
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_user ON edit_user;
|
||||
DROP TRIGGER IF EXISTS trg_edit_user ON edit_user;
|
||||
CREATE TRIGGER trg_edit_user
|
||||
BEFORE INSERT OR UPDATE ON edit_user
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- DROP TRIGGER trg_edit_visible_group ON edit_visible_group;
|
||||
DROP TRIGGER IF EXISTS trg_edit_visible_group ON edit_visible_group;
|
||||
CREATE TRIGGER trg_edit_visible_group
|
||||
BEFORE INSERT OR UPDATE ON edit_visible_group
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_generic();
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
-- DROP TRIGGER trg_set_edit_access_uid ON edit_access;
|
||||
CREATE TRIGGER trg_set_edit_access_uid
|
||||
BEFORE INSERT OR UPDATE ON edit_access
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_access_uid();
|
||||
14
4dev/database/update/edit_tables_missing_columns.sql
Normal file
14
4dev/database/update/edit_tables_missing_columns.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- update missing edit_* table data
|
||||
|
||||
ALTER TABLE edit_generic ADD cuid VARCHAR;
|
||||
|
||||
ALTER TABLE edit_access ADD enabled SMALLINT DEFAULT 0;
|
||||
ALTER TABLE edit_access ADD protected SMALLINT DEFAULT 0;
|
||||
|
||||
ALTER TABLE edit_group ADD uid VARCHAR;
|
||||
ALTER TABLE edit_group ADD deleted SMALLINT DEFAULT 0;
|
||||
|
||||
ALTER TABLE temp_files ADD folder VARCHAR;
|
||||
ALTER TABLE edit_page ADD hostname VARCHAR;
|
||||
|
||||
ALTER TABLE edit_user ADD deleted SMALLINT DEFAULT 0;
|
||||
17
4dev/database/update/edit_update_missing_cuid.sql
Normal file
17
4dev/database/update/edit_update_missing_cuid.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- 2019/9/10 UPDATE missing cuid in edit_* tables
|
||||
|
||||
UPDATE edit_access SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_data SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_right SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_user SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_language SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_log SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_menu_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page_access SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page_content SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_query_string SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_scheme SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_user SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_visible_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
35
4dev/lang/admin/messages_en_utf8.po
Normal file
35
4dev/lang/admin/messages_en_utf8.po
Normal file
@@ -0,0 +1,35 @@
|
||||
# ********************************************************************
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2005/08/09
|
||||
# SHORT DESCRIPTION:
|
||||
# Backned English Messages file for gettext
|
||||
# to craete: msgfmt -o ja.mo messages_en.po
|
||||
# HISTORY:
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Project Version\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
msgid "Year"
|
||||
msgstr "Year"
|
||||
|
||||
msgid "Month"
|
||||
msgstr "Month"
|
||||
|
||||
msgid "INPUT TEST"
|
||||
msgstr "OUTPUT TEST EN"
|
||||
|
||||
msgid "I should be translated"
|
||||
msgstr "I should be translated: I WAS TRANSLATED"
|
||||
|
||||
msgid "Are we translated?"
|
||||
msgstr "Are we translated? Yes, we are!"
|
||||
77
4dev/lang/admin/messages_ja_utf8.po
Normal file
77
4dev/lang/admin/messages_ja_utf8.po
Normal file
@@ -0,0 +1,77 @@
|
||||
# ********************************************************************
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# CREATED: 2018/03/28
|
||||
# SHORT DESCRIPTION:
|
||||
# Backend Japanese Messages file for gettext
|
||||
# to craete: msgfmt -o ja.mo messages_ja.po
|
||||
# HISTORY:
|
||||
# ********************************************************************/
|
||||
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Project Version\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@egplusww.com\n"
|
||||
"POT-Creation-Date: 2018-03-28 10:40+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: E-GRAPHICS COMMUNICATIONS Japan <info.jp@egplusww.com>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
msgid "Yes"
|
||||
msgstr "はい"
|
||||
|
||||
msgid "No"
|
||||
msgstr "いいえ"
|
||||
|
||||
# Basic date info
|
||||
msgid "Year"
|
||||
msgstr "年"
|
||||
|
||||
msgid "Month"
|
||||
msgstr "月"
|
||||
|
||||
msgid "Day"
|
||||
msgstr "日"
|
||||
|
||||
msgid "Hour"
|
||||
msgstr "時"
|
||||
|
||||
msgid "Minute"
|
||||
msgstr "分"
|
||||
|
||||
msgid "Mon"
|
||||
msgstr "月"
|
||||
|
||||
msgid "Tue"
|
||||
msgstr "火"
|
||||
|
||||
msgid "Wed"
|
||||
msgstr "水"
|
||||
|
||||
msgid "Thu"
|
||||
msgstr "木"
|
||||
|
||||
msgid "Fri"
|
||||
msgstr "金"
|
||||
|
||||
msgid "Sat"
|
||||
msgstr "土"
|
||||
|
||||
msgid "Sun"
|
||||
msgstr "日"
|
||||
|
||||
msgid "INPUT TEST"
|
||||
msgstr "OUTPUT TEST JA"
|
||||
|
||||
# login string
|
||||
msgid "Hello %s"
|
||||
msgstr "こにちは %s"
|
||||
|
||||
msgid "I should be translated"
|
||||
msgstr "「スマーティー」これは正しいです"
|
||||
|
||||
msgid "Are we translated?"
|
||||
msgstr "「クラス」これは翻訳です?"
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# create path
|
||||
path=`pwd`"/"$0;
|
||||
path=$(pwd)"/"$0;
|
||||
|
||||
LOCAL_BASE_DIR="";
|
||||
LOCAL_BASE_DIR="<local folder>";
|
||||
LOCAL_DIR=$LOCAL_BASE_DIR"";
|
||||
REMOTE_WEB="";
|
||||
TARGET_HOST_WEB="developer@10.76.32.25";
|
||||
TMP_DIR=$LOCAL_BASE_DIR"/4dev/";
|
||||
tmpf_web=$TMP_DIR"tmp.web";
|
||||
REMOTE_WEB="<remote folder>";
|
||||
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;
|
||||
@@ -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__
|
||||
2
4dev/tmp/.gitignore
vendored
Normal file
2
4dev/tmp/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
259
4dev/update/20180322_db_interface/TRAIT_db_pgsql.inc
Normal file
259
4dev/update/20180322_db_interface/TRAIT_db_pgsql.inc
Normal file
@@ -0,0 +1,259 @@
|
||||
<?
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2003/04/09
|
||||
* SHORT DESCRIPTION:
|
||||
* pgsq; wrapper calls
|
||||
* HISTORY:
|
||||
* 2008/04/16 (cs) wrapper for pg escape string
|
||||
* 2007/01/11 (cs) add prepare/execute for postgres
|
||||
* 2006/09/12 (cs) in case db_query retuns false, save the query and run the query through the send/get procedure to get correct error data from the db
|
||||
* 2006/06/26 (cs) added port for db connection
|
||||
* 2006/04/03 (cs) added meta data for table
|
||||
* 2005/07/25 (cs) removed the plural s remove, not needed and not 100% working
|
||||
* 2005/07/07 (cs) the default it is table_name _ id
|
||||
* 2005/01/19 (cs) changed the pgsql connect, so it dies if it can't connect to the DB
|
||||
* 2004/09/30 (cs) layout cleanup
|
||||
* /
|
||||
|
||||
/* collection of PostgreSQL wrappers
|
||||
* REQUIRES 5.4 PHP!!! (should do check for this)
|
||||
*
|
||||
* pg_prepare
|
||||
* pg_execute
|
||||
* pg_num_rows
|
||||
* pg_num_fields
|
||||
* pg_field_name
|
||||
* pg_affected_rows (*)
|
||||
* pg_fetch_array
|
||||
* pg_query
|
||||
* pg_close
|
||||
* pg_connect (*)
|
||||
* pg_meta_data
|
||||
* pg_escape_string
|
||||
*
|
||||
*/
|
||||
|
||||
trait db_pgsql
|
||||
{
|
||||
private $last_error_query;
|
||||
private $currval_query;
|
||||
|
||||
// METHOD: _db_query
|
||||
// PARAMS: query, database handler
|
||||
// RETURN: query result
|
||||
// DESC : wrapper for gp_query, catches error and stores it in class var
|
||||
private function _db_query($query, $dbh)
|
||||
{
|
||||
// read out the query status and save the query if needed
|
||||
$result = @pg_query($dbh, $query);
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: _db_close
|
||||
// PARAMS: database handler
|
||||
// RETURN: none
|
||||
// DESC : wrapper for pg_close
|
||||
private function _db_close($dbh)
|
||||
{
|
||||
pg_close($dbh);
|
||||
}
|
||||
|
||||
// METHOD: _db_prepare
|
||||
// PARAMS: database handler, prepare name, query
|
||||
// RETURN: prepared statement handler
|
||||
// DESC : wrapper for pg_prepare
|
||||
private function _db_prepare($dbh, $name, $query)
|
||||
{
|
||||
return @pg_prepare($dbh, $name, $query);
|
||||
}
|
||||
|
||||
// METHOD: _db_execute
|
||||
// PARAMS: database handler, prepare name, data for query
|
||||
// RETURN: returns status
|
||||
// DESC : wrapper for pg_execute for running a prepared statement
|
||||
private function _db_execute($dbh, $name, $data)
|
||||
{
|
||||
return @pg_execute($dbh, $name, $data);
|
||||
}
|
||||
|
||||
// METHOD: _db_num_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: rows
|
||||
// DESC : wrapper for pg_num_rows
|
||||
private function _db_num_rows($cursor)
|
||||
{
|
||||
return pg_num_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: _db_num_fields
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for fields in query
|
||||
// DESC : wrapper for pg_num_fields
|
||||
private function _db_num_fields($cursor)
|
||||
{
|
||||
return pg_num_fields($cursor);
|
||||
}
|
||||
|
||||
// METHOD: _db_field_name
|
||||
// PARAMS: cursor, field position
|
||||
// RETURN: name of field
|
||||
// DESC : wrapper for pg_field_name
|
||||
private function _db_field_name($cursor, $i)
|
||||
{
|
||||
return pg_field_name($cursor, $i);
|
||||
}
|
||||
|
||||
// METHOD: _db_fetch_array
|
||||
// PARAMS: cursor
|
||||
// RETURN: row
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
private function _db_fetch_array($cursor)
|
||||
{
|
||||
return pg_fetch_array($cursor);
|
||||
}
|
||||
|
||||
// METHOD: _db_affected_ros
|
||||
// PARAMS: database handler, cursor
|
||||
// RETURN: number for rows
|
||||
// DESC : wrapper for pg_affected_rows
|
||||
private function _db_affected_rows($dbh, $cursor)
|
||||
{
|
||||
return pg_affected_rows($cursor);
|
||||
}
|
||||
|
||||
// METHOD: _db_insert_id
|
||||
// PARAMS: database handler, query, primary key name
|
||||
// RETURN: last insert primary key
|
||||
// DESC : reads the last inserted primary key for the query
|
||||
// if ther 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
|
||||
private function _db_insert_id($dbh, $query, $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
// get table name from insert
|
||||
$array = explode(' ', $query);
|
||||
$_table = $array[2];
|
||||
// if there is a dot inside, we need to split
|
||||
if (strstr($_table, '.')) {
|
||||
list ($schema, $table) = explode('.', $_table);
|
||||
} else {
|
||||
$table = $_table;
|
||||
}
|
||||
// no PK name given at all
|
||||
if (!$pk_name) {
|
||||
// if name is plurar, make it singular
|
||||
// if (preg_match("/.*s$/i", $table))
|
||||
// $table = substr($table, 0, -1);
|
||||
// set pk_name to "id"
|
||||
$pk_name = $table."_id";
|
||||
}
|
||||
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
|
||||
$q = "SELECT CURRVAL('$seq') AS insert_id";
|
||||
$this->currval_query = $q;
|
||||
//echo "Q: $q<Br>";
|
||||
// I have to do manually or I overwrite the original insert internal vars ...
|
||||
if ($q = @pg_query($dbh, $q)) {
|
||||
list($id) = pg_fetch_array($q);
|
||||
} else {
|
||||
$id = array(-1, $q);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: _db_connect
|
||||
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
|
||||
// RETURN: database handler
|
||||
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
private function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
|
||||
{
|
||||
// to avoid empty db_port
|
||||
if (!$db_port) {
|
||||
$db_port = 5432;
|
||||
}
|
||||
$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 $this->dbh;
|
||||
}
|
||||
|
||||
// METHOD: _db_print_error
|
||||
// PARAMS: database handler, cursor
|
||||
// RETURN: error string (HTML)
|
||||
// DESC : reads the last error for this cursor
|
||||
private function _db_print_error($dbh, $cursor = '')
|
||||
{
|
||||
// run the query again for the error result here
|
||||
if (!$cursor && $this->last_error_query) {
|
||||
pg_send_query($dbh, $this->last_error_query);
|
||||
$this->last_error_query = "";
|
||||
$cursor = pg_get_result($dbh);
|
||||
}
|
||||
if (pg_result_error($cursor)) {
|
||||
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: _db_meta_data
|
||||
// PARAMS: database handler, table name
|
||||
// RETURN: array with table data
|
||||
// DESC : wrapper for pg_emta_data
|
||||
private function _db_meta_data($dbh, $table)
|
||||
{
|
||||
return @pg_meta_data($dbh, $table);
|
||||
}
|
||||
|
||||
// METHOD: _db_escape_string
|
||||
// PARAMS: string
|
||||
// RETURN: escaped string for postgres
|
||||
// DESC : wrapper for pg_escape_string
|
||||
private function _db_escape_string($string)
|
||||
{
|
||||
return pg_escape_string($this->dbh, $string);
|
||||
}
|
||||
|
||||
// METHOD: _db_escape_bytea
|
||||
// PARAMS: string
|
||||
// RETURN: escape bytes for postgres
|
||||
// DESC : wrapper for pg_escape_bytea
|
||||
private function _db_escape_bytea($bytea)
|
||||
{
|
||||
return pg_escape_bytea($this->dbh, $bytea);
|
||||
}
|
||||
|
||||
// METHOD: _db_array_parse
|
||||
// PARAMS: input text, output array [needed]
|
||||
// [internal] limit: are we at the end of the parse
|
||||
// [internal] offset: shift for {}
|
||||
// RETURN: array with the elements
|
||||
// DESC : postgresql array to php array
|
||||
private function _db_array_parse($text, &$output, $limit = false, $offset = 1)
|
||||
{
|
||||
if (false === $limit) {
|
||||
$limit = strlen($text) - 1;
|
||||
$output = array();
|
||||
}
|
||||
if ('{}' != $text) {
|
||||
do {
|
||||
if ('{' != $text{$offset}) {
|
||||
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
|
||||
$offset += strlen($match[0]);
|
||||
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
|
||||
if ('},' == $match[3]) {
|
||||
return $offset;
|
||||
}
|
||||
} else {
|
||||
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
|
||||
}
|
||||
} while ($limit > $offset);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
375
4dev/update/20180322_db_interface/db_pgsql_pdo.inc
Normal file
375
4dev/update/20180322_db_interface/db_pgsql_pdo.inc
Normal file
@@ -0,0 +1,375 @@
|
||||
<?
|
||||
/*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2014/12/3
|
||||
* SHORT DESCRIPTION:
|
||||
* pgsql pdo wrapper calls
|
||||
* HISTORY:
|
||||
* /
|
||||
|
||||
/* collection of PostgreSQL wrappers
|
||||
* REQUIRES 5.x PHP with compiled pdo pgsql (--with-pdo-pgsql)
|
||||
*
|
||||
*/
|
||||
|
||||
class db_pgsql
|
||||
{
|
||||
private $last_error_query;
|
||||
private $dbh;
|
||||
private $cursor = array();
|
||||
|
||||
// METHOD: __construct
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : class constructor
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function _db_last_error_query()
|
||||
{
|
||||
if ($this->last_error_query) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: _db_query
|
||||
// PARAMS: query
|
||||
// RETURN: cursor
|
||||
// DESC : was wrapper for pg_query, now it runs pepare and execute in one set. uses the query md5 as the cursor name
|
||||
public function _db_query($query)
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
/* // read out the query status and save the query if needed
|
||||
$result = @pg_query($this->dbh, $query);
|
||||
if (!$result)
|
||||
$this->last_error_query = $query; */
|
||||
$cursor = $this->_db_prepare(md5($query), $query);
|
||||
$result = $this->_db_execute(md5($query), array ());
|
||||
if (!$result) {
|
||||
$this->last_error_query = $query;
|
||||
}
|
||||
return $cursor;
|
||||
}
|
||||
|
||||
// METHOD: _db_query_result
|
||||
// PARAMS: query
|
||||
// RETURN: result from query
|
||||
// DESC : only valid for the pdo version here. use with care
|
||||
public function _db_query_result($query)
|
||||
{
|
||||
return $this->dbh->query($query);
|
||||
}
|
||||
|
||||
// METHOD: _db_send_query
|
||||
// PARAMS: query
|
||||
// RETURN: true/false if query was sent successful
|
||||
// DESC : sends an async query to the server
|
||||
public function _db_send_query($query)
|
||||
{
|
||||
// return @pg_send_query($this->dbh, $query);
|
||||
}
|
||||
|
||||
// METHOD: _db_get_result
|
||||
// PARAMS: none
|
||||
// RETURN: resource handler
|
||||
// DESC : wrapper for pg_get_result
|
||||
public function _db_get_result()
|
||||
{
|
||||
$this->last_error_query = '';
|
||||
/* $result = pg_get_result($this->dbh);
|
||||
if ($error = pg_result_error($result)) {
|
||||
$this->last_error_query = $error;
|
||||
}*/
|
||||
return $result;
|
||||
}
|
||||
|
||||
// METHOD: _db_close
|
||||
// PARAMS: none
|
||||
// RETURN: none
|
||||
// DESC : wrapper for pg_close
|
||||
public function _db_close()
|
||||
{
|
||||
if (is_array($this->cursor)) {
|
||||
foreach ($this->cursor as $key => $data) {
|
||||
$this->cursor[$key]->closeCursor;
|
||||
$this->cursor[$key] = null;
|
||||
}
|
||||
}
|
||||
$this->dbh = null;
|
||||
}
|
||||
|
||||
// METHOD: _db_prepare
|
||||
// PARAMS: prepare name, query
|
||||
// RETURN: prepared statement handler
|
||||
// DESC : wrapper for pg_prepare
|
||||
public function _db_prepare($name, $query)
|
||||
{
|
||||
// return @pg_prepare($this->dbh, $name, $query);
|
||||
$this->cursor[$name] = $this->dbh->prepare($query);
|
||||
return $this->cursor[$name];
|
||||
}
|
||||
|
||||
// METHOD: _db_execute
|
||||
// PARAMS: prepare name, data for query
|
||||
// RETURN: returns status
|
||||
// DESC : wrapper for pg_execute for running a prepared statement
|
||||
public function _db_execute($name, $data)
|
||||
{
|
||||
// return @pg_execute($this->dbh, $name, $data);
|
||||
return $this->cursor[$name]->execute($data);
|
||||
}
|
||||
|
||||
// METHOD: _db_num_rows
|
||||
// PARAMS: cursor
|
||||
// RETURN: rows
|
||||
// DESC : wrapper for pg_num_rows
|
||||
public function _db_num_rows($cursor)
|
||||
{
|
||||
// return pg_num_rows($cursor);
|
||||
return $cusor->rowCount();
|
||||
}
|
||||
|
||||
// METHOD: _db_num_fields
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for fields in query
|
||||
// DESC : wrapper for pg_num_fields
|
||||
public function _db_num_fields($cursor)
|
||||
{
|
||||
// return pg_num_fields($cursor);
|
||||
return $cursor->columnCount();
|
||||
}
|
||||
|
||||
// METHOD: _db_field_name
|
||||
// PARAMS: cursor, field position
|
||||
// RETURN: name of field
|
||||
// DESC : wrapper for pg_field_name
|
||||
public function _db_field_name($cursor, $i)
|
||||
{
|
||||
// return pg_field_name($cursor, $i);
|
||||
}
|
||||
|
||||
// METHOD: _db_fetch_array
|
||||
// PARAMS: cursor
|
||||
// RETURN: row
|
||||
// DESC : wrapper for pg_fetch_array
|
||||
public function _db_fetch_array($cursor)
|
||||
{
|
||||
// return pg_fetch_array($cursor);
|
||||
return $cursor->fetch();
|
||||
}
|
||||
|
||||
// METHOD: _db_affected_ros
|
||||
// PARAMS: cursor
|
||||
// RETURN: number for rows
|
||||
// DESC : wrapper for pg_affected_rows
|
||||
public function _db_affected_rows($cursor)
|
||||
{
|
||||
// return pg_affected_rows($cursor);
|
||||
return $cusor->rowCount();
|
||||
}
|
||||
|
||||
// METHOD: _db_insert_id
|
||||
// PARAMS: query, primary key name
|
||||
// RETURN: last insert primary key
|
||||
// DESC : reads the last inserted primary key for the query
|
||||
// if ther 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
|
||||
public function _db_insert_id($query, $pk_name)
|
||||
{
|
||||
// only if an insert has been done
|
||||
if (preg_match("/^insert /i", $query)) {
|
||||
$schema = '';
|
||||
// get table name from insert
|
||||
$array = explode(' ', $query);
|
||||
$_table = $array[2];
|
||||
// if there is a dot inside, we need to split
|
||||
if (strstr($_table, '.')) {
|
||||
list($schema, $table) = explode('.', $_table);
|
||||
} else {
|
||||
$table = $_table;
|
||||
}
|
||||
// no PK name given at all
|
||||
if (!$pk_name) {
|
||||
// if name is plural, make it singular
|
||||
// if (preg_match("/.*s$/i", $table))
|
||||
// $table = substr($table, 0, -1);
|
||||
// set pk_name to "id"
|
||||
$pk_name = $table."_id";
|
||||
}
|
||||
$seq = (($schema) ? $schema.'.' : '').$table."_".$pk_name."_seq";
|
||||
$q = "SELECT CURRVAL('$seq') AS insert_id";
|
||||
// I have to do manually or I overwrite the original insert internal vars ...
|
||||
$row = $this->_db_query_result($q);
|
||||
if ($row['insert_id']) {
|
||||
$id = $row['insert_id'];
|
||||
} else {
|
||||
$id = array(-1, $q);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: _db_primary_key
|
||||
// PARAMS: table and optional schema
|
||||
// RETURN: primary key name OR false if not possible
|
||||
// DESC : queries database for the primary key name to this table in the selected schema
|
||||
public function _db_primary_key($table, $schema = '')
|
||||
{
|
||||
if ($table) {
|
||||
// check if schema set is different from schema given, only needed if schema is not empty
|
||||
$table_prefix = '';
|
||||
if ($schema) {
|
||||
$q = "SHOW search_path";
|
||||
// $cursor = $this->_db_query($q);
|
||||
// $search_path = $this->_db_fetch_array($cursor)['search_path'];
|
||||
$search_path = $this->_db_query_result($q)['search_path'];
|
||||
if ($search_path != $schema) {
|
||||
$table_prefix = $schema.'.';
|
||||
}
|
||||
}
|
||||
// read from table the PK name
|
||||
// faster primary key get
|
||||
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
|
||||
$q .= "FROM pg_index, pg_class, pg_attribute ";
|
||||
if ($schema) {
|
||||
$q .= ", pg_namespace ";
|
||||
}
|
||||
$q .= "WHERE ";
|
||||
// regclass translates the OID to the name
|
||||
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
|
||||
$q .= "indrelid = pg_class.oid AND ";
|
||||
if ($schema) {
|
||||
$q .= "nspname = '".$schema."' AND ";
|
||||
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
|
||||
}
|
||||
$q .= "pg_attribute.attrelid = pg_class.oid AND ";
|
||||
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
|
||||
$q .= "AND indisprimary";
|
||||
$row = $this->_db_query_result($q);
|
||||
if ($row === false) {
|
||||
return false;
|
||||
} else {
|
||||
return $row['column_name'];
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD: _db_connect
|
||||
// PARAMS: host name, user name, password, database name, optional port (defaults to default postgres port), optional ssl (default allow)
|
||||
// RETURN: database handler
|
||||
// DESC : wrapper for pg_connect, writes out failure to screen if error occurs (hidden var)
|
||||
public function _db_connect($db_host, $db_user, $db_pass, $db_name, $db_port = 5432, $db_ssl = 'allow')
|
||||
{
|
||||
// to avoid empty db_port
|
||||
if (!$db_port) {
|
||||
$db_port = 5432;
|
||||
}
|
||||
try {
|
||||
$this->dbh = new PDO('pgsql:host='.$db_host.';dbname='.$db_name.';port='.$db_port.';sslmode='.$db_ssl, $db_user, $db_pass);
|
||||
} catch (PDOException $e) {
|
||||
print "Error!: ".$e->getMessage()."\n";
|
||||
die("<!-- Can't connect [host=".$db_host." port=".$db_port." user=".$db_user." password=XXXX dbname=".$db_name." sslmode=".$db_ssl."]: ".$e->getMEssage()."//-->");
|
||||
}
|
||||
return $this->dbh;
|
||||
}
|
||||
|
||||
// METHOD: _db_print_error
|
||||
// PARAMS: database handler, cursor
|
||||
// RETURN: error string (HTML)
|
||||
// DESC : reads the last error for this cursor
|
||||
public function _db_print_error($cursor = '')
|
||||
{
|
||||
/* // run the query again for the error result here
|
||||
if (!$cursor && $this->last_error_query)
|
||||
{
|
||||
pg_send_query($this->dbh, $this->last_error_query);
|
||||
$this->last_error_query = '';
|
||||
$cursor = pg_get_result($this->dbh);
|
||||
}
|
||||
if (pg_result_error($cursor))
|
||||
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>"; */
|
||||
}
|
||||
|
||||
// METHOD: _db_meta_data
|
||||
// PARAMS: table name
|
||||
// RETURN: array with table data
|
||||
// DESC : wrapper for pg_emta_data
|
||||
public function _db_meta_data($table)
|
||||
{
|
||||
// return @pg_meta_data($this->dbh, $table);
|
||||
}
|
||||
|
||||
// METHOD: _db_escape_string
|
||||
// PARAMS: string
|
||||
// RETURN: escaped string for postgres
|
||||
// DESC : wrapper for pg_escape_string
|
||||
public function _db_escape_string($string)
|
||||
{
|
||||
// return pg_escape_string($this->dbh, $string);
|
||||
}
|
||||
|
||||
// METHOD: _db_escape_bytea
|
||||
// PARAMS: string
|
||||
// RETURN: escape bytes for postgres
|
||||
// DESC : wrapper for pg_escape_bytea
|
||||
public function _db_escape_bytea($bytea)
|
||||
{
|
||||
// return pg_escape_bytea($this->dbh, $bytea);
|
||||
}
|
||||
|
||||
// METHOD: _db_connection_busy
|
||||
// PARAMS: none
|
||||
// RETURN: true/false for busy connection
|
||||
// DESC : wrapper for pg_connection_busy
|
||||
public function _db_connection_busy()
|
||||
{
|
||||
// return pg_connection_busy($this->dbh);
|
||||
}
|
||||
|
||||
// METHOD: _db_version
|
||||
// PARAMS: none
|
||||
// RETURN: databse version
|
||||
// DESC : wrapper for pg_version
|
||||
public function _db_version()
|
||||
{
|
||||
// array has client, protocol, server
|
||||
// we just need the server
|
||||
$v = pg_version($this->dbh);
|
||||
return $v['server'];
|
||||
}
|
||||
|
||||
// METHOD: _db_array_parse
|
||||
// PARAMS: input text, output array [needed]
|
||||
// [internal] limit: are we at the end of the parse
|
||||
// [internal] offset: shift for {}
|
||||
// RETURN: array with the elements
|
||||
// DESC : postgresql array to php array
|
||||
public function _db_array_parse($text, &$output, $limit = false, $offset = 1)
|
||||
{
|
||||
if (false === $limit) {
|
||||
$limit = strlen($text) - 1;
|
||||
$output = array();
|
||||
}
|
||||
if ('{}' != $text) {
|
||||
do {
|
||||
if ('{' != $text{$offset}) {
|
||||
preg_match("/(\\{?\"([^\"\\\\]|\\\\.)*\"|[^,{}]+)+([,}]+)/", $text, $match, 0, $offset);
|
||||
$offset += strlen($match[0]);
|
||||
$output[] = ('"' != $match[1]{0} ? $match[1] : stripcslashes(substr($match[1], 1, -1)));
|
||||
if ('},' == $match[3]) {
|
||||
return $offset;
|
||||
}
|
||||
} else {
|
||||
$offset = pg_array_parse($text, $output[], $limit, $offset + 1);
|
||||
}
|
||||
} while ($limit > $offset);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
72
4dev/update/20180323_namespace/comp_func.sh
Executable file
72
4dev/update/20180323_namespace/comp_func.sh
Executable file
@@ -0,0 +1,72 @@
|
||||
#!/bin/bash
|
||||
|
||||
OIFS=${IFS};
|
||||
base_dir="/home/clemens/html/developers/clemens/core_data/php_libraries/trunk/";
|
||||
class_file="CoreLibs/Output/Form/Generate.inc";
|
||||
tmp_file=${base_dir}"4dev/tmp/tmp.comp."$(echo "${class_file}" | tr \/. _);
|
||||
rpl_file=${base_dir}"4dev/tmp/tmp.rpl."$(echo "${class_file}" | tr \/. _);
|
||||
rm -f "${tmp_file}";
|
||||
rm -f "${rpl_file}";
|
||||
if [ ! -f ${class_file} ];
|
||||
then
|
||||
echo "Cannot find ${class_file} in current folder: $(pwd)";
|
||||
exit;
|
||||
fi;
|
||||
cat "${class_file}" | grep "WAS :" -B 1 | while read line;
|
||||
do
|
||||
# if method grep for function call
|
||||
found=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "METHOD:");
|
||||
if [ -n "${found}" ];
|
||||
then
|
||||
method=$(echo "${line}" | cut -d " " -f 3);
|
||||
echo "1 MET: ${method}";
|
||||
# is method
|
||||
if [ -n "${method}" ];
|
||||
then
|
||||
# the full new call
|
||||
new_function_call_full=$(grep "function ${method}(" "${class_file}" | grep "function" | sed -e 's/^[ \t]*//');
|
||||
# just the method name
|
||||
new_function_call=$(echo "${new_function_call_full}" | sed -e 's/public //' | sed -e 's/private //' | sed -e 's/static //' | sed -e 's/function //' | cut -d "(" -f 1);
|
||||
# check if func call is more than just alphanumeric (we don't need to redeclare those, functions are case insenstivie)
|
||||
#
|
||||
# only params (remove all = ... stuff)
|
||||
new_function_call_params=$(echo "${new_function_call_full}" | cut -d "(" -f 2- | sed -e 's/)//');
|
||||
old_function_call_params='';
|
||||
IFS=',';
|
||||
for el in ${new_function_call_params};
|
||||
do
|
||||
if [ -n "${old_function_call_params}" ];
|
||||
then
|
||||
old_function_call_params=${old_function_call_params}", ";
|
||||
fi;
|
||||
old_function_call_params=${old_function_call_params}$(echo "${el}" | cut -d "=" -f 1 | tr -d ' ');
|
||||
done;
|
||||
# cut -d "," "${new_function_call_params}" | while
|
||||
fi;
|
||||
fi;
|
||||
# if this is a WAS
|
||||
was=$(echo "${line}" | sed -e 's/^[ \t]*//' | grep "WAS :" | tr -s " ");
|
||||
if [ -n "${was}" ];
|
||||
then
|
||||
old_function_call=$(echo "${was}" | cut -d " " -f 4)
|
||||
echo "2 OLD: ${old_function_call} => ${new_function_call} [${new_function_call_full}]";
|
||||
# for return write:
|
||||
# rpl new -> old { new }
|
||||
rpl=$(echo "${new_function_call_full}" | sed -e "s/${new_function_call}/${old_function_call}/");
|
||||
new_call="${rpl}\n";
|
||||
new_call=${new_call}"{\n";
|
||||
new_call=${new_call}"\terror_log('DEPRECATED CALL: '.__METHOD__.', '.__FILE__.':'.__LINE__.', '.debug_backtrace()[0]['file'].':'.debug_backtrace()[0]['line']);\n";
|
||||
new_call=${new_call}"\treturn \$this->${new_function_call}(${old_function_call_params});\n";
|
||||
new_call=${new_call}"}\n";
|
||||
echo -e "${new_call}" >> "${tmp_file}";
|
||||
echo "3A RPL CALL: ${rpl}";
|
||||
echo "3B RPL CALL: return \$this->${new_function_call}(${old_function_call_params});";
|
||||
echo "4 SWT RPL : rpl '\$this->${old_function_call}' '\$this->${new_function_call}'";
|
||||
# write the replace calls for old $this->old_call to $this->new_call
|
||||
echo "rpl '\$this->${old_function_call}' '\$this->${new_function_call}' ##TARGET_FILE##" >> "${rpl_file}";
|
||||
echo "----";
|
||||
fi;
|
||||
done;
|
||||
IFS=${OIFS};
|
||||
|
||||
# __END__
|
||||
18
4dev/update/20180323_namespace/rpl_old_method_in_file.sh
Executable file
18
4dev/update/20180323_namespace/rpl_old_method_in_file.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
cat tmp.comp | while read i;
|
||||
do
|
||||
found=$(echo "${i}" | grep "function ");
|
||||
if [ -n "${found}" ]; then
|
||||
fk=$(echo "${i}" | cut -d " " -f 3 | cut -d "(" -f 1);
|
||||
fi;
|
||||
found=$(echo "${i}" | grep "\$this->");
|
||||
if [ -n "${found}" ]; then
|
||||
# no to debug
|
||||
found=$(echo "${i}" | grep "debug(");
|
||||
if [ -z "${found}" ]; then
|
||||
fk_n=$(echo "${i}" | cut -d "(" -f 1);
|
||||
echo "rpl '\$this->${fk}' '${fk_n}' CoreLibs/DB/IO.inc";
|
||||
fi;
|
||||
fi;
|
||||
done;
|
||||
92
4dev/update/20190910_page_content/20190910_page_content_updates.sql
Executable file
92
4dev/update/20190910_page_content/20190910_page_content_updates.sql
Executable file
@@ -0,0 +1,92 @@
|
||||
-- 2019/9/10 update edit_page with reference and additional ACLs, update core functions
|
||||
|
||||
-- * random_string function
|
||||
-- * add cuid column in edit_generic
|
||||
-- * update generic trigger function
|
||||
-- * edit_page_content table/trigger
|
||||
-- * edit_* additional_acl entries
|
||||
-- * edit_page content alias link
|
||||
-- * update any missing cuid entries
|
||||
|
||||
-- create random string with length X
|
||||
CREATE FUNCTION random_string(randomLength int)
|
||||
RETURNS text AS $$
|
||||
SELECT array_to_string(
|
||||
ARRAY(
|
||||
SELECT substring(
|
||||
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
|
||||
trunc(random() * 62)::int + 1,
|
||||
1
|
||||
)
|
||||
FROM generate_series(1, randomLength) AS gs(x)
|
||||
),
|
||||
''
|
||||
)
|
||||
$$ LANGUAGE SQL
|
||||
RETURNS NULL ON NULL INPUT
|
||||
VOLATILE;
|
||||
-- edit_gneric update
|
||||
ALTER TABLE edit_generic ADD cuid VARCHAR;
|
||||
-- adds the created or updated date tags
|
||||
CREATE OR REPLACE FUNCTION set_edit_generic() RETURNS TRIGGER AS '
|
||||
DECLARE
|
||||
random_length INT = 12; -- that should be long enough
|
||||
BEGIN
|
||||
IF TG_OP = ''INSERT'' THEN
|
||||
NEW.date_created := ''now'';
|
||||
NEW.cuid := random_string(random_length);
|
||||
ELSIF TG_OP = ''UPDATE'' THEN
|
||||
NEW.date_updated := ''now'';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
|
||||
-- DROP TABLE edit_page_content;
|
||||
CREATE TABLE edit_page_content (
|
||||
edit_page_content_id SERIAL PRIMARY KEY,
|
||||
edit_page_id INT NOT NULL,
|
||||
edit_access_right_id INT NOT NULL,
|
||||
name VARCHAR,
|
||||
uid VARCHAR UNIQUE,
|
||||
order_number INT NOT NULL,
|
||||
online SMALLINT NOT NULL DEFAULT 0,
|
||||
FOREIGN KEY (edit_access_right_id) REFERENCES edit_access_right (edit_access_right_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
FOREIGN KEY (edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) INHERITS (edit_generic) WITHOUT OIDS;
|
||||
DROP TRIGGER trg_edit_page_content ON edit_page_content;
|
||||
CREATE TRIGGER trg_edit_page_content
|
||||
BEFORE INSERT OR UPDATE ON edit_page_content
|
||||
FOR EACH ROW EXECUTE PROCEDURE set_edit_generic();
|
||||
|
||||
-- INSERT new list entry
|
||||
INSERT INTO edit_access_right (name, level, type) VALUES ('List', 10, 'list');
|
||||
|
||||
-- UPDATE
|
||||
ALTER TABLE edit_user ADD additional_acl JSONB;
|
||||
ALTER TABLE edit_group ADD additional_acl JSONB;
|
||||
ALTER TABLE edit_access ADD additional_acl JSONB;
|
||||
|
||||
-- page content reference settings
|
||||
ALTER TABLE edit_page ADD content_alias_edit_page_id INT;
|
||||
ALTER TABLE edit_page ADD CONSTRAINT edit_page_content_alias_edit_page_id_fkey FOREIGN KEY (content_alias_edit_page_id) REFERENCES edit_page (edit_page_id) MATCH FULL ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
|
||||
-- 2019/9/10 UPDATE missing cuid in edit_* tables
|
||||
UPDATE edit_access SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_data SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_right SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_access_user SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_language SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_log SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_menu_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page_access SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_page_content SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_query_string SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_scheme SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_user SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
UPDATE edit_visible_group SET cuid = random_string(12) WHERE cuid IS NULL;
|
||||
|
||||
-- update all triggers
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
10
README
10
README
@@ -1,10 +0,0 @@
|
||||
PHP Core Library
|
||||
================
|
||||
|
||||
Base PHP class files to setup any project
|
||||
* login
|
||||
* database wrapper
|
||||
* basic helper class for debugging and other features
|
||||
* admin/frontend split
|
||||
* domain controlled database/settings split
|
||||
* dynamic layout groups
|
||||
45
README.md
Normal file
45
README.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# PHP Core Library
|
||||
|
||||
## Code Standard
|
||||
|
||||
* Uses PSR-12
|
||||
* tab indent instead of 4 spaces indent
|
||||
* Warning at 120 character length, error at 240 character length
|
||||
|
||||
## General information
|
||||
|
||||
Base PHP class files to setup any project
|
||||
* login
|
||||
* database wrapper
|
||||
* basic helper class for debugging and other features
|
||||
* admin/frontend split
|
||||
* domain controlled database/settings split
|
||||
* dynamic layout groups
|
||||
|
||||
## NOTE
|
||||
|
||||
There are three branches:
|
||||
|
||||
### master
|
||||
|
||||
The active branch, which is the namespace branch
|
||||
|
||||
### legacy
|
||||
|
||||
The old non namepsace format layout.
|
||||
This is fully deprecated and will no longer be maintaned.
|
||||
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
|
||||
498
bin/Progress.pm
Normal file
498
bin/Progress.pm
Normal file
@@ -0,0 +1,498 @@
|
||||
package Progress;
|
||||
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# DATE CREATED: 2009/6/16
|
||||
# DESCRIPTION: progress percent class
|
||||
|
||||
# METHODS
|
||||
# * init
|
||||
# my $prg = Progress->new();
|
||||
# will init a new progress class in the var $prg
|
||||
# the following parameters can be set directly during a new call
|
||||
# - verbose (1/0)
|
||||
# - precision (-1~10)
|
||||
# - wide_time (0/1)
|
||||
# - microtime (0/1)
|
||||
# setting is done via
|
||||
# my $prg = Progress->new(verbose => 1, microtime = 1);
|
||||
# * setting methods
|
||||
# verbose($level int)
|
||||
# $level has to be int, if not set there is no output show, at least 1 has to be given to see visible output
|
||||
# precision($decimals int)
|
||||
# $decimals has to be int, if set to -1 then the steps are done in 10 increase, else it sets how many decimals are visible, 0 for no decimals
|
||||
# wide_time(0/1 int)
|
||||
# sets the flag for wide time, if set to 1 the estimated time to end and time run is left prefixed with 15 chars
|
||||
# microtime(0/1 int)
|
||||
# sets the flag to always show microtime (1) or only if the previous time was the same (0)
|
||||
# reset()
|
||||
# resets all the internal vars for another new run
|
||||
# SetStartTime(optional timestamp)
|
||||
# sets the start times for this progress run, the overall start/end time is set, and the time used for the actual progress
|
||||
# in case there is some processing done before the run starts, it is highly recommended to call SetETAStartTime before the actual processing starts
|
||||
# if no timestamp is given, internal timestamp is used (this is recommended)
|
||||
# SetETAStartTime(optional timestamp)
|
||||
# only sets the start/end time for the actual "estimated time" calculation. It is recommended to call this right before the processing loop starts
|
||||
# eg if there is a big query running that takes a lot of time, this method should be called before the reading loop
|
||||
# as with SetStartTime a timestamp can be given, if not then the internal timestamp is used (this is recommended)
|
||||
# SetEndTime(optional timestamp)
|
||||
# sets the end time for the overall processing. This should be called at the very end of the script before any final stat data is printed
|
||||
# linecount($lines int)
|
||||
# sets the maximum lines that will be processed, used for percentage calculation. If non int is given, will set to 1. This will be only set once, to
|
||||
# reset used reset() method.
|
||||
# Either this or filesize NEED to be set
|
||||
# filesize($bytes int)
|
||||
# filesize in bytes, if non valid data is given, then it is set to 1.
|
||||
# filesize() and linecount() can both be set, but at least one of them has to be set.
|
||||
# if filesize is set a byte data output is added, if only linecount is given, only the linecount output will be given (no bytes per second, etc)
|
||||
# ShowPosition(optional current byte position int)
|
||||
# this is the main processing and has to be called at the end of the loop where the data is processed. If no bytes are given the internal counter (linecount)
|
||||
# is used.
|
||||
# for bytes it is recommended to use IO::File and $FH->tell to pass on the bytes
|
||||
#
|
||||
# VARIABLES
|
||||
# * internal set
|
||||
# change: flagged 1 if output is given or would be given. can be used for any post processing after the ShowPosition is called
|
||||
# precision_ten_step: flagged 1 if the precision was set to -1
|
||||
# start: overall start time
|
||||
# end: overall end time
|
||||
# count: count of processed lines
|
||||
# [TODO: describe the others too, at the moment only below in %fields]
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
BEGIN {
|
||||
use POSIX;
|
||||
use Carp;
|
||||
use Time::HiRes qw(time);
|
||||
use File::Basename;
|
||||
use Number::Format qw(format_number);
|
||||
use vars qw($AUTOLOAD);
|
||||
push(@INC, File::Basename::dirname($0).'/');
|
||||
}
|
||||
|
||||
# important includes
|
||||
use functions;
|
||||
|
||||
# variable declarationf or access
|
||||
# * can be set
|
||||
# = only for read
|
||||
# unmarked are internal only, but can be read if they are needed in further processing in the script
|
||||
my %fields = (
|
||||
linecount => 0, # * max lines in input
|
||||
filesize => 0, # * max file size
|
||||
precision => 1, # * comma after percent
|
||||
wide_time => 0, # * if flagged 1, then the wide 15 char left bound format is used
|
||||
verbose => 0, # * verbose status from outside
|
||||
microtime => 0, # * microtime output for last run time (1 for enable, 0 for auto, -1 for disable)
|
||||
change => 0, # = flag if output was given
|
||||
start => undef, # = global start for the full script running time
|
||||
start_run => undef, # = for the eta time, can be set after a query or long read in, to not create a wrong ETA time
|
||||
start_time => undef, # loop start
|
||||
end => undef, # = global end
|
||||
end_time => undef, # loop end
|
||||
count_size => undef, # = filesize current
|
||||
count => 0, # = position current
|
||||
current_count => 0, # last count (position)
|
||||
lines_processed => 0, # lines processed in the last run
|
||||
last_group => 0, # time in seconds for the last group run (until percent change)
|
||||
lines_in_last_group => 0, # float value, lines processed per second to the last group run
|
||||
lines_in_global => 0, # float values, lines processed per second to complete run
|
||||
bytes_in_last_group => 0, # flaot value, bytes processes per second in the last group run
|
||||
bytes_in_global => 0, # float value, bytes processed per second to complete run
|
||||
size_in_last_group => 0, # bytes processed in last run (in bytes)
|
||||
current_size => 0, # current file position (size)
|
||||
last_percent => 0, # last percent position
|
||||
precision_ten_step => 0, # if we have normal % or in steps of 10
|
||||
percent_print => 5, # the default size, this is precision + 4
|
||||
percent_precision => 1, # this is 1 if it is 1 or 0 for precision, or precision size
|
||||
eta => undef, # estimated time to finish
|
||||
full_time_needed => undef, # run time since start
|
||||
lg_microtime => 0 # last group microtime, this is auto set during process.
|
||||
);
|
||||
|
||||
# class init
|
||||
sub new
|
||||
{
|
||||
my $proto = shift;
|
||||
my $class = ref($proto) || $proto;
|
||||
my %data = @_;
|
||||
my $self = {
|
||||
_permitted => \%fields,
|
||||
%fields,
|
||||
};
|
||||
# vars to init
|
||||
bless ($self, $class);
|
||||
if ($data{'verbose'} && $data{'verbose'} =~ /^\d{1}$/) {
|
||||
$self->{verbose} = $data{'verbose'};
|
||||
}
|
||||
if (exists($data{'precision'}) && (($data{'precision'} || $data{'precision'} == 0) && $data{'precision'} =~ /^\-?\d{1,2}$/)) {
|
||||
$self->precision($data{'precision'});
|
||||
}
|
||||
if ($data{'microtime'} && $data{'microtime'} =~ /^(0|1)$/) {
|
||||
$self->microtime($data{'microtime'});
|
||||
}
|
||||
if ($data{'wide_time'} && $data{'wide_time'} =~ /^(0|1)$/) {
|
||||
$self->wide_time($data{'wide_time'});
|
||||
}
|
||||
return $self;
|
||||
}
|
||||
|
||||
# auto load for vars
|
||||
sub AUTOLOAD
|
||||
{
|
||||
my $self = shift;
|
||||
my $type = ref($self) || croak "$self is not an object";
|
||||
my $name = $AUTOLOAD;
|
||||
$name =~ s/.*://;
|
||||
|
||||
unless (exists $self->{_permitted}->{$name}) {
|
||||
croak "Can't access '$name' field in class $type";
|
||||
}
|
||||
|
||||
if (@_) {
|
||||
return $self->{$name} = shift;
|
||||
} else {
|
||||
return $self->{$name};
|
||||
}
|
||||
}
|
||||
|
||||
# destructor
|
||||
sub DESTROY
|
||||
{
|
||||
# do nothing, there is nothing to close or finish
|
||||
}
|
||||
|
||||
# SUB: reset
|
||||
# PARAMS: none
|
||||
# DESC: resets all the current counters only and current start times
|
||||
sub reset
|
||||
{
|
||||
my $self = shift;
|
||||
# reset what always gets reset
|
||||
$self->{count} = 0;
|
||||
$self->{count_size} = undef;
|
||||
$self->{current_count} = 0;
|
||||
$self->{linecount} = 0;
|
||||
$self->{lines_processed} = 0;
|
||||
$self->{last_group} = 0;
|
||||
$self->{lines_in_last_group} = 0;
|
||||
$self->{lines_in_global} = 0;
|
||||
$self->{bytes_in_last_group} = 0;
|
||||
$self->{bytes_in_global} = 0;
|
||||
$self->{size_in_last_group} = 0;
|
||||
$self->{filesize} = 0;
|
||||
$self->{current_size} = 0;
|
||||
$self->{last_percent} = 0;
|
||||
$self->{eta} = 0;
|
||||
$self->{full_time_needed} = 0;
|
||||
$self->{start_run} = undef;
|
||||
$self->{start_time} = undef;
|
||||
$self->{end_time} = undef;
|
||||
}
|
||||
|
||||
# SUB: microtime
|
||||
# PARAMS: 1/0
|
||||
# DESC: flag to set microtime on or off in the time output
|
||||
# if not 1 or 0, set to 0
|
||||
sub microtime
|
||||
{
|
||||
my $self = shift;
|
||||
my $microtime;
|
||||
if (@_) {
|
||||
$microtime = shift;
|
||||
if ($microtime == 1 || $microtime == 0) {
|
||||
$self->{microtime} = $microtime;
|
||||
} else {
|
||||
$self->{microtime} = 0;
|
||||
}
|
||||
}
|
||||
return $self->{microtime};
|
||||
}
|
||||
|
||||
|
||||
# SUB: wide_time
|
||||
# PARAMS: 1/0
|
||||
# DESC: flag to set wide_time (15 char spacer).
|
||||
# if not 1 or 0, set to 0
|
||||
sub wide_time
|
||||
{
|
||||
my $self = shift;
|
||||
my $wide;
|
||||
if (@_) {
|
||||
$wide = shift;
|
||||
if ($wide == 1 || $wide == 0) {
|
||||
$self->{wide_time} = $wide;
|
||||
} else {
|
||||
$self->{wide_time} = 0;
|
||||
}
|
||||
}
|
||||
return $self->{wide_time};
|
||||
}
|
||||
|
||||
# SUB: precision
|
||||
# PARAMS: precision in int
|
||||
# DESC: sets the output percent precision calculation and printf width
|
||||
# if negative, to ten step, if bigger 10, set to one
|
||||
sub precision
|
||||
{
|
||||
my $self = shift;
|
||||
my $comma;
|
||||
if (@_) {
|
||||
$comma = shift;
|
||||
$comma = 0 if ($comma !~ /^\-?\d{1,}$/);
|
||||
if ($comma < 0) {
|
||||
# -2 is 5 step
|
||||
# -1 is 10 step
|
||||
if ($comma < -1) {
|
||||
$self->{precision_ten_step} = 5;
|
||||
} else {
|
||||
$self->{precision_ten_step} = 10;
|
||||
}
|
||||
$self->{precision} = 0; # no comma
|
||||
$self->{percent_precision} = 0; # no print precision
|
||||
$self->{percent_print} = 3; # max 3 length
|
||||
} else {
|
||||
$self->{precision} = $comma < 0 || $comma > 10 ? 10 : $comma;
|
||||
$self->{percent_precision} = $comma < 0 || $comma > 10 ? 10 : $comma;
|
||||
$self->{percent_print} = ($comma == 0 ? 3 : 4) + $self->{percent_precision};
|
||||
}
|
||||
}
|
||||
return $self->{precision};
|
||||
}
|
||||
|
||||
# SUB: linecount
|
||||
# PARAMS: max number of lines to be processed
|
||||
# DESC: sets the max number for lines for the percent calculation, if negative or not number, set to 1
|
||||
# can only be set ONCE
|
||||
sub linecount
|
||||
{
|
||||
my $self = shift;
|
||||
my $linecount;
|
||||
if (!$self->{linecount}) {
|
||||
if (@_) {
|
||||
$linecount = shift;
|
||||
$self->{linecount} = $linecount;
|
||||
$self->{linecount} = 1 if ($linecount < 0 || $linecount !~ /\d+/)
|
||||
}
|
||||
}
|
||||
return $self->{linecount};
|
||||
}
|
||||
|
||||
# SUB: filesize
|
||||
# PARAMS: max filesize for the to processed data
|
||||
# DESC: sets the max filesize for the to processed data, if negative or not number, set to 1
|
||||
# input data has to be in bytes without any suffix (no b, kb, etc)
|
||||
# can only be set ONCE
|
||||
sub filesize
|
||||
{
|
||||
my $self = shift;
|
||||
my $filesize;
|
||||
if (!$self->{filesize}) {
|
||||
if (@_) {
|
||||
$filesize = shift;
|
||||
$self->{filesize} = $filesize;
|
||||
$self->{filesize} = 1 if ($filesize < 0 || $filesize !~ /\d+/)
|
||||
}
|
||||
}
|
||||
return $self->{filesize};
|
||||
}
|
||||
|
||||
# SUB: SetStartTime
|
||||
# PARAMS: time, or nothing
|
||||
# DESC: sets all the start times
|
||||
sub SetStartTime
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{start} = shift;
|
||||
} else {
|
||||
$self->{start} = time();
|
||||
}
|
||||
$self->{start_time} = $self->{start};
|
||||
$self->{start_run} = $self->{start};
|
||||
}
|
||||
|
||||
# SUB: SetETAStartTime
|
||||
# PARAMS: time, or nothing
|
||||
# DESC: sets the loop & run time, for correct ETA callculation
|
||||
sub SetETAStartTime
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{start_time} = shift;
|
||||
} else {
|
||||
$self->{start_time} = time();
|
||||
}
|
||||
$self->{start_run} = $self->{start_time};
|
||||
}
|
||||
|
||||
# SUB: SetEndTime
|
||||
# PARAMS: time, or nothing
|
||||
# DESC: sets the end time for running time calculation
|
||||
sub SetEndTime
|
||||
{
|
||||
my $self = shift;
|
||||
if (@_) {
|
||||
$self->{end} = shift;
|
||||
} else {
|
||||
$self->{end} = time();
|
||||
}
|
||||
}
|
||||
|
||||
# SUB: ShowPosition
|
||||
# PARAMS: optiona; file position (via file pointer)
|
||||
# RETURN: string for percent position output
|
||||
# DESC: calculates the current percent position based on the passed parameter, if no parameter uses intneral counter
|
||||
sub ShowPosition
|
||||
{
|
||||
my $self = shift;
|
||||
# set local vars
|
||||
my $percent; # current percent
|
||||
my $full_time_needed; # complete process time
|
||||
my $full_time_per_line; # time per line
|
||||
my $eta; # estimated end time
|
||||
my $string = ''; # percent string that gets output
|
||||
my $show_filesize = 1;
|
||||
# microtime flags
|
||||
my $eta_microtime = 0;
|
||||
my $ftn_microtime = 0;
|
||||
my $lg_microtime = 0;
|
||||
# percent precision calc
|
||||
my $_p_spf = "%.".$self->{precision}."f";
|
||||
# output format for percent
|
||||
my $_pr_p_spf = "%".$self->{percent_print}.".".$self->{percent_precision}."f";
|
||||
# set the linecount precision based on the final linecount, if not, leave it empty
|
||||
my $_pr_lc = "%s";
|
||||
$_pr_lc = "%".length(format_number($self->{linecount}))."s" if ($self->{linecount});
|
||||
# time format, if flag is set, the wide format is used
|
||||
my $_pr_tf = "%s";
|
||||
$_pr_tf = "%-15s" if ($self->{'wide_time'});
|
||||
# do the smae for file size
|
||||
# my $_pr_fs = "%s";
|
||||
# $_pr_fs = "%".length(function::convert_number($self->{filesize}))."s" if ($self->{filesize});
|
||||
|
||||
# increase position by one
|
||||
$self->{count} ++;
|
||||
# see if we get anything from IO tell
|
||||
if (@_) {
|
||||
$self->{file_pos} = shift;
|
||||
} else {
|
||||
# we did not, so we set internal value
|
||||
$self->{file_pos} = $self->{count};
|
||||
# we also check if the filesize was set now
|
||||
if (!$self->{filesize}) {
|
||||
$self->{filesize} = $self->{linecount};
|
||||
}
|
||||
# set ignore filesize output (no data)
|
||||
$show_filesize = 0;
|
||||
}
|
||||
# set the count size based on the file pos, is only used if we have filesize
|
||||
$self->{count_size} = $self->{file_pos};
|
||||
|
||||
# do normal or down to 10 (0, 10, ...) %
|
||||
if ($self->{precision_ten_step}) {
|
||||
# calc 0 comma precision, so just do a floor
|
||||
my $_percent = sprintf("%d", ($self->{file_pos} / $self->{filesize}) * 100);
|
||||
# mod that to 10
|
||||
my $mod = $_percent % $self->{precision_ten_step};
|
||||
# either write this one, or write the previous, old one
|
||||
$percent = $mod == 0 ? $_percent : $self->last_percent;
|
||||
# print "P: $percent, Last: ".$self->last_percent.", Mod: ".$mod.", Calc: ".$_percent."\n";
|
||||
} else {
|
||||
$percent = sprintf($_p_spf, ($self->{file_pos} / $self->{filesize}) * 100);
|
||||
}
|
||||
# print "POS: ".$self->{file_pos}.", PERCENT: $percent / ".$self->last_percent."\n";
|
||||
if ($percent != $self->last_percent) {
|
||||
$self->{end_time} = time();
|
||||
# for from the beginning
|
||||
$full_time_needed = $self->{end_time} - $self->{start_run}; # how long from the start;
|
||||
$self->{last_group} = $self->{end_time} - $self->{start_time};
|
||||
$self->{lines_processed} = $self->{count} - $self->{current_count};
|
||||
# lines in last group
|
||||
$self->{lines_in_last_group} = $self->{'last_group'} ? ($self->{lines_processed} / $self->{last_group}) : 0;
|
||||
# lines in global
|
||||
$self->{lines_in_global} = $full_time_needed ? ($self->{'count'} / $full_time_needed) : 0;
|
||||
# if we have linecount
|
||||
if (!$self->{linecount}) {
|
||||
$full_time_per_line = (($full_time_needed) ? $full_time_needed : 1) / $self->{count_size}; # how long for all
|
||||
$eta = $full_time_per_line * ($self->{filesize} - $self->{count_size}); # estimate for the rest
|
||||
} else {
|
||||
$full_time_per_line = (($full_time_needed) ? $full_time_needed : 1) / $self->{count}; # how long for all
|
||||
$eta = $full_time_per_line * ($self->{linecount} - $self->{count}); # estimate for the rest
|
||||
}
|
||||
|
||||
# just in case ...
|
||||
$eta = '0' if ($eta < 0);
|
||||
# check if to show microtime
|
||||
# ON: if microtime is flagged as one
|
||||
$eta_microtime = $ftn_microtime = $lg_microtime = 1 if ($self->{microtime} == 1);
|
||||
# AUTO: foir microtime
|
||||
if ($self->{microtime} == 0) {
|
||||
$eta_microtime = 1 if ($eta > 0 && $eta < 1);
|
||||
$ftn_microtime = 1 if ($full_time_needed > 0 && $full_time_needed < 1);
|
||||
# pre check last group: if pre comma part is same add microtime anyway
|
||||
$lg_microtime = 1 if ($self->{last_group} > 0 && $self->{last_group} < 1);
|
||||
}
|
||||
# print out
|
||||
if ($show_filesize) {
|
||||
# last group size
|
||||
$self->{size_in_last_group} = $self->{count_size} - $self->{current_size};
|
||||
# calc kb/s if there is any filesize data
|
||||
# last group
|
||||
$self->{bytes_in_last_group} = $self->{'last_group'} ? ($self->{size_in_last_group} / $self->{last_group}) : 0;
|
||||
# global
|
||||
$self->{bytes_in_global} = $full_time_needed ? ($self->{count_size} / $full_time_needed) : 0;
|
||||
# only used if we run with file size for the next check
|
||||
$self->{current_size} = $self->{count_size};
|
||||
|
||||
$string = sprintf(
|
||||
"Processed ".$_pr_p_spf."%% [%s / %s] | ".$_pr_lc." / ".$_pr_lc." Lines | ETA: ".$_pr_tf." / TR: ".$_pr_tf." / LR: %s lines (%s) in %s, %s (%s) lines/s, %s (%s) b/s\n",
|
||||
$percent,
|
||||
function::convert_number($self->{count_size}),
|
||||
function::convert_number($self->{filesize}),
|
||||
format_number($self->{count}),
|
||||
format_number($self->{linecount}),
|
||||
function::convert_time($eta, $eta_microtime),
|
||||
function::convert_time($full_time_needed, $ftn_microtime),
|
||||
format_number($self->{lines_processed}),
|
||||
function::convert_number($self->{size_in_last_group}),
|
||||
function::convert_time($self->{last_group}, $lg_microtime),
|
||||
format_number($self->{lines_in_global}, 2, 1),
|
||||
format_number($self->{lines_in_last_group}, 2, 1),
|
||||
function::convert_number($self->{bytes_in_global}),
|
||||
function::convert_number($self->{bytes_in_last_group})
|
||||
) if ($self->{verbose} >= 1);
|
||||
} else {
|
||||
$string = sprintf(
|
||||
"Processed ".$_pr_p_spf."%% | ".$_pr_lc." / ".$_pr_lc." Lines | ETA: ".$_pr_tf." / TR: ".$_pr_tf." / LR: %s lines in %s, %s (%s) lines/s\n",
|
||||
$percent,
|
||||
format_number($self->{count}),
|
||||
format_number($self->{linecount}),
|
||||
function::convert_time($eta, $eta_microtime),
|
||||
function::convert_time($full_time_needed, $ftn_microtime),
|
||||
format_number($self->{lines_processed}),
|
||||
function::convert_time($self->{last_group}, $lg_microtime),
|
||||
format_number($self->{lines_in_global}, 2, 1),
|
||||
format_number($self->{lines_in_last_group}, 2, 1)
|
||||
) if ($self->{verbose} >= 1);
|
||||
}
|
||||
# write back vars
|
||||
$self->{last_percent} = $percent;
|
||||
$self->{eta} = $eta;
|
||||
$self->{full_time_needed} = $full_time_needed;
|
||||
$self->{lg_microtime} = $lg_microtime;
|
||||
# for the next run, check data
|
||||
$self->{start_time} = time();
|
||||
$self->{current_count} = $self->{count};
|
||||
# trigger if this is a change
|
||||
$self->{change} = 1;
|
||||
} else {
|
||||
# trigger if this is a change
|
||||
$self->{change} = 0;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
1;
|
||||
501
bin/functions.pm
Normal file
501
bin/functions.pm
Normal file
@@ -0,0 +1,501 @@
|
||||
package function;
|
||||
|
||||
# AUTHOR: Clemens Schwaighofer
|
||||
# DATE CREATED: 2004/11/09
|
||||
# DESCRIPTION: functions collection for Adidas scripts
|
||||
# HISTORY:
|
||||
# 2005/06/22 (cs) added header key check function
|
||||
# 2005/02/10 (cs) added debug flag to print output, added two new functions to format a number into B, KB, etc
|
||||
# 2005/01/13 (cs) fixed array problem with the clean up and int function
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use 5.000_000;
|
||||
use POSIX qw(floor);
|
||||
use File::Copy;
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use utf8;
|
||||
#require Exporter;
|
||||
#our @ISA = qw(Exporter);
|
||||
#our @EXPORT = qw();
|
||||
|
||||
# depending on the options given to the program, it gets the correct settings
|
||||
# to which db it should connect
|
||||
sub get_db_user
|
||||
{
|
||||
my ($target, $db) = @_;
|
||||
|
||||
# the parts of the hash array (tab seperated)
|
||||
my @array_names = qw{db_name db_port db_user db_pass db_host db_type db_test db_ssl};
|
||||
my %db_out = ();
|
||||
|
||||
# based on the two parameters find the correct vars
|
||||
# each level can hold data, higher level data overrules lower data
|
||||
# eg $config::db{'test'}{'db_user'} overrules $config::db{'db_user'}
|
||||
for (my $i = 1; $i <= 3; $i ++) {
|
||||
foreach my $name (@array_names) {
|
||||
# depending on the level check the level of data
|
||||
if ($i == 1) {
|
||||
$db_out{$name} = $config::db{$name} if (defined($config::db{$name}));
|
||||
} elsif ($i == 2) {
|
||||
$db_out{$name} = $config::db{$target}{$name} if (defined($config::db{$target}{$name}));
|
||||
} elsif ($i == 3) {
|
||||
$db_out{$name} = $config::db{$target}{$db}{$name} if (defined($config::db{$target}{$db}{$name}));
|
||||
}
|
||||
} # for each db data var
|
||||
} # for each data level in the hash
|
||||
|
||||
return (
|
||||
$db_out{'db_name'},
|
||||
$db_out{'db_port'},
|
||||
$db_out{'db_user'},
|
||||
$db_out{'db_pass'},
|
||||
$db_out{'db_host'},
|
||||
$db_out{'db_type'},
|
||||
$db_out{'db_test'},
|
||||
$db_out{'db_ssl'}
|
||||
);
|
||||
}
|
||||
|
||||
# get the DSN string for the DB connect
|
||||
sub get_db_dsn
|
||||
{
|
||||
my (
|
||||
$db_name,
|
||||
$db_port,
|
||||
$db_user,
|
||||
$db_pass,
|
||||
$db_host,
|
||||
$db_type,
|
||||
$db_ssl
|
||||
) = @_;
|
||||
my $dsn = '';
|
||||
|
||||
if ($db_type eq 'mysql' && $db_name && $db_host && $db_user) {
|
||||
$dsn = "DBI:mysql:database=".$db_name.";host=".$db_host.";port=".$db_port;
|
||||
} elsif ($db_type eq 'pgsql' && $db_name && $db_host && $db_user) {
|
||||
$dsn = "DBI:Pg:dbname=".$db_name.";host=".$db_host.";port=".$db_port.";sslmode=".$db_ssl;
|
||||
} else {
|
||||
# invalid db type
|
||||
$dsn = -1;
|
||||
}
|
||||
return $dsn;
|
||||
}
|
||||
|
||||
sub strip_white_spaces
|
||||
{
|
||||
my ($element) = @_;
|
||||
# get rid of spaces at the end and at the beginning of each bloack
|
||||
$element =~ s/^\s+//g;
|
||||
$element =~ s/\s+$//g;
|
||||
return $element;
|
||||
}
|
||||
|
||||
sub prepare_hash_keys
|
||||
{
|
||||
my($csv, $data, $csv_header) = @_;
|
||||
|
||||
# unset value starts at 1000 and goes up ...
|
||||
my $unset_value = 1000;
|
||||
my %keys = ();
|
||||
|
||||
# parse header
|
||||
if ($csv->parse($data)) {
|
||||
my @cols = $csv->fields();
|
||||
for (my $i = 0; $i < @cols; $i ++) {
|
||||
# remove all spaces before and afterward
|
||||
$cols[$i] = function::strip_white_spaces($cols[$i]);
|
||||
# write key - id number
|
||||
$keys{$cols[$i]} = $i;
|
||||
print $::DEBUG "\tPostion [".$i."]: ".$cols[$i]."\n" if ($::debug);
|
||||
print "\tPosition [".$i."]: ".$cols[$i]."\n" if ($::verbose > 1);
|
||||
}
|
||||
} else {
|
||||
die "ERROR[".$csv->error_diag()."]: ".$csv->error_input()."\n";
|
||||
}
|
||||
# add empty values
|
||||
foreach my $csv_header_value (@$csv_header) {
|
||||
if (!defined($keys{$csv_header_value})) {
|
||||
$keys{$csv_header_value} = $unset_value;
|
||||
$unset_value ++;
|
||||
print $::DEBUG "\tKey [$csv_header_value] gets position [".$keys{$csv_header_value}."]\n" if ($::debug);
|
||||
print "\tKey [$csv_header_value] gets position [".$keys{$csv_header_value}."]\n" if ($::verbose > 1);
|
||||
}
|
||||
}
|
||||
|
||||
return %keys;
|
||||
}
|
||||
|
||||
sub error_check_keys
|
||||
{
|
||||
my($csv_header, $keys) = @_;
|
||||
|
||||
if ((keys %$keys) != @$csv_header) {
|
||||
print $::ERR "TOTAL WRONG COUNT: CSV header ".(keys %$keys)." vs Needed headers ".@$csv_header.": perhaps your input file is not fitting this?\n";
|
||||
print "TOTAL WRONG COUNT: CSV header ".(keys %$keys)." vs Needed headers ".@$csv_header.": perhaps your input file is not fitting this?\n";
|
||||
|
||||
# if there are more keys in CSV file, then in the header defined in here
|
||||
if ((keys %$keys) > @$csv_header) {
|
||||
print $::ERR "Listing Perl Header missing\n";
|
||||
print "Listing Perl Header missing\n";
|
||||
foreach my $key (keys %$keys) {
|
||||
print $::ERR "Missing in perl Header list: $key\n" if (!grep {$_ eq $key} @$csv_header);
|
||||
print "Missing in perl Header list: $key\n" if (!grep {$_ eq $key} @$csv_header);
|
||||
}
|
||||
# if more keys are in the header defined than in the csv file
|
||||
} else {
|
||||
print $::ERR "Listing CSV Header missing\n";
|
||||
print "Listing CSV Header missing\n";
|
||||
for (my $i = 0; $i < @$csv_header; $i ++) {
|
||||
print $::ERR "Missing in CSV file: ".$$csv_header[$i]."\n" if (!defined($$keys{$$csv_header[$i]}));
|
||||
print "Missing in CSV file: ".$$csv_header[$i]."\n" if (!defined($$keys{$$csv_header[$i]}));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub clean_up_row
|
||||
{
|
||||
my ($row) = @_;
|
||||
|
||||
for (my $i = 0; $i < @$row; $i++) {
|
||||
# get rid of spaces at the end and at the beginning of each bloack
|
||||
$$row[$i] =~ s/^\s+//g;
|
||||
$$row[$i] =~ s/\s+$//g;
|
||||
# convert all half width Katakan to Full width Katakana
|
||||
$$row[$i] = Unicode::Japanese->new($$row[$i])->h2zKana->get;
|
||||
# need to decode the converted string, somehow Unicode::Japanese does not return proper utf8 if use utf8 is on
|
||||
utf8::decode($$row[$i]);
|
||||
}
|
||||
|
||||
return @$row;
|
||||
}
|
||||
|
||||
sub set_int_fields
|
||||
{
|
||||
my ($row, $keys, $int_fields) = @_;
|
||||
|
||||
# check ALL smallint/int/etc rows to be set to a number
|
||||
for (my $i = 0; $i < @$int_fields; $i++) {
|
||||
print "\t\tCheck ".$$int_fields[$i]." {".$$keys{$$int_fields[$i]}."} ... " if ($::verbose > 1);
|
||||
if (!$$row[$$keys{$$int_fields[$i]}]) {
|
||||
$$row[$$keys{$$int_fields[$i]}] = 0;
|
||||
}
|
||||
# if its filled, but not a digit, set to 1
|
||||
if ($$row[$$keys{$$int_fields[$i]}] =~ /\D/) {
|
||||
$$row[$$keys{$$int_fields[$i]}] = 1;
|
||||
}
|
||||
print "[".$$row[$$keys{$$int_fields[$i]}]."] [DONE]\n" if ($::verbose > 1);
|
||||
}
|
||||
return @$row;
|
||||
}
|
||||
|
||||
# formats a number with dots and ,
|
||||
sub format_number
|
||||
{
|
||||
my ($number) = @_;
|
||||
# dummy, does nothing now
|
||||
# should put . or , every 3 digits later
|
||||
return $number;
|
||||
}
|
||||
|
||||
# converts bytes to human readable format
|
||||
sub convert_number
|
||||
{
|
||||
my ($number) = @_;
|
||||
my $pos; # the original position in the labels array
|
||||
# divied number until its division would be < 1024. count that position for label usage
|
||||
for ($pos = 0; $number > 1024; $pos ++) {
|
||||
$number = $number / 1024;
|
||||
}
|
||||
# before we return it, we format it [rounded to 2 digits, if has decimals, else just int]
|
||||
# we add the right label to it and return
|
||||
return sprintf(!$pos ? '%d' : '%.2f', $number)." ".qw(B KB MB GB TB PB EB)[$pos];
|
||||
}
|
||||
|
||||
# make time from seconds string
|
||||
sub convert_time
|
||||
{
|
||||
my ($timestamp, $show_micro) = @_;
|
||||
my $ms = '';
|
||||
# cut of the ms, but first round them up to four
|
||||
$timestamp = sprintf("%.4f", $timestamp);
|
||||
# print "T: ".$timestamp."\n";
|
||||
($timestamp, $ms) = split(/\./, $timestamp);
|
||||
my @timegroups = ("86400", "3600", "60", "1");
|
||||
my @output = ();
|
||||
for (my $i = 0; $i < @timegroups; $i ++) {
|
||||
push(@output, floor($timestamp / $timegroups[$i]));
|
||||
$timestamp = $timestamp % $timegroups[$i];
|
||||
}
|
||||
# output has days|hours|min|sec
|
||||
return (($output[0]) ? $output[0]."d " : "").
|
||||
(($output[1] || $output[0]) ? $output[1]."h " : "").
|
||||
(($output[2] ||$output[1] || $output[0]) ? $output[2]."m " : "").
|
||||
$output[3]."s".
|
||||
(($show_micro) ? " ".((!$ms) ? 0 : $ms)."ms" : "");
|
||||
}
|
||||
|
||||
# get a timestamp and create a proper formated date/time field
|
||||
sub create_time
|
||||
{
|
||||
my ($timestamp, $show_micro) = @_;
|
||||
my $ms = '';
|
||||
$timestamp = 0 if (!$timestamp);
|
||||
# round ms to 4 numbers
|
||||
$timestamp = sprintf("%.4f", $timestamp);
|
||||
($timestamp, $ms) = split(/\./, $timestamp);
|
||||
# array for time
|
||||
my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($timestamp);
|
||||
# year, month fix
|
||||
$year += 1900;
|
||||
$month += 1;
|
||||
# string for return
|
||||
return $year."-".
|
||||
($month < 10 ? '0'.$month : $month)."-".
|
||||
($day < 10 ? '0'.$day : $day)." ".
|
||||
($hour < 10 ? '0'.$hour : $hour).":".
|
||||
($min < 10 ? '0'.$min : $min).":".
|
||||
($sec < 10 ? '0'.$sec : $sec).
|
||||
(($ms && $show_micro) ? ".".$ms : "");
|
||||
}
|
||||
|
||||
# create YYYYMMDD data
|
||||
sub create_date
|
||||
{
|
||||
my ($timestamp, $split_string) = @_;
|
||||
my $split = $split_string ? $split_string : '';
|
||||
$timestamp = time() if (!$timestamp);
|
||||
# array for time
|
||||
my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($timestamp);
|
||||
# year, month fix
|
||||
$year += 1900;
|
||||
$month += 1;
|
||||
# string for return
|
||||
return $year.$split.
|
||||
($month < 10 ? '0'.$month : $month).$split.
|
||||
($day < 10 ? '0'.$day : $day);
|
||||
}
|
||||
|
||||
# create YYYYMMDD_HHMMSS data
|
||||
sub create_datetime
|
||||
{
|
||||
my ($timestamp, $split_string) = @_;
|
||||
my $split = $split_string ? $split_string : '';
|
||||
$timestamp = time() if (!$timestamp);
|
||||
# array for time
|
||||
my ($sec, $min, $hour, $day, $month, $year, $wday, $yday, $isdst) = localtime($timestamp);
|
||||
# year, month fix
|
||||
$year += 1900;
|
||||
$month += 1;
|
||||
# string for return
|
||||
return $year.$split.
|
||||
($month < 10 ? '0'.$month : $month).$split.
|
||||
($day < 10 ? '0'.$day : $day).'_'.
|
||||
($hour < 10 ? '0'.$hour : $hour).$split.
|
||||
($min < 10 ? '0'.$min : $min).$split.
|
||||
($sec < 10 ? '0'.$sec : $sec);
|
||||
}
|
||||
|
||||
sub left_fill
|
||||
{
|
||||
my($number, $size, $char) = @_;
|
||||
return sprintf($char x ($size - length($number)).$number);
|
||||
}
|
||||
|
||||
# wrapper to flip the crc32 hex string, so it is like buggy php one (php <= 5.2.6)
|
||||
sub crc32b_fix
|
||||
{
|
||||
my ($crc) = @_;
|
||||
# left pad with 0 to 8 chars
|
||||
$crc = ('0' x (8 - length($crc))).$crc;
|
||||
# flip two chars (byte hex)
|
||||
$crc =~ s/^([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})([a-z0-9]{2})$/$4$3$2$1/;
|
||||
return $crc;
|
||||
}
|
||||
|
||||
# short sha1 (9 char) function
|
||||
sub sha1_short
|
||||
{
|
||||
my ($string) = @_;
|
||||
return substr(sha1_hex($string), 0, 9);
|
||||
}
|
||||
|
||||
# DEBUG helpers for dumping data
|
||||
# from: http://www.perlmonks.org/?node_id=390153
|
||||
# alternative use Dump::Dumper and print Dump(VAR);
|
||||
sub dump_data
|
||||
{
|
||||
my ($level, $base, $data) = @_;
|
||||
my $nextlevel = $level + 1;
|
||||
if (ref($data) eq 'ARRAY') {
|
||||
foreach my $k (0 .. $#{$data}) {
|
||||
my $baseval = $base.'['.$k.']';
|
||||
dump_it($nextlevel, $baseval, $data->[$k]);
|
||||
}
|
||||
} elsif (ref($data) eq 'HASH') {
|
||||
foreach my $k (sort(keys(%{$data}))) {
|
||||
my $baseval = $base.'{'.$k.'}';
|
||||
dump_it($nextlevel, $baseval, $data->{$k});
|
||||
}
|
||||
} elsif (ref($data) eq 'SCALAR') {
|
||||
my $baseval = $base;
|
||||
dump_it($nextlevel, $baseval, ${$data});
|
||||
}
|
||||
}
|
||||
|
||||
sub dump_it
|
||||
{
|
||||
my ($nextlevel, $baseval, $datum) = @_;
|
||||
my $reftype = ref($datum);
|
||||
if ($reftype eq 'HASH') {
|
||||
dump_data($nextlevel, $baseval, \%{$datum});
|
||||
} elsif ($reftype eq 'ARRAY') {
|
||||
dump_data($nextlevel, $baseval, \@{$datum});
|
||||
} else {
|
||||
process_data($nextlevel, $baseval, $datum);
|
||||
}
|
||||
}
|
||||
|
||||
sub process_data
|
||||
{
|
||||
my ($nextlevel, $baseval, $datum) = @_;
|
||||
my $indentation = ' ' x $nextlevel;
|
||||
print $indentation, $baseval, ' = ', $datum, "\n";
|
||||
}
|
||||
|
||||
# METHOD: lock_run
|
||||
# PARAMS: file (plus path) to lock to
|
||||
# the current running pid (if not given will be set in script)
|
||||
# the current name of the script (auto set if not given)
|
||||
# optional write encoding (set to utf8 if not given)
|
||||
# RETURN: nothing
|
||||
# DESC: checks if this script is already running based on the lock file, if if yes will abort
|
||||
# if file is there but pid not find it automatically cleans up the stale lock file
|
||||
sub lock_run
|
||||
{
|
||||
my ($file, $run_pid, $name, $encoding) = @_;
|
||||
# if no encoding, set utf8
|
||||
$encoding = 'utf8' if (!$encoding);
|
||||
# set the run pid if no pid is given
|
||||
$run_pid = $$ if (!$run_pid);
|
||||
# set the script base name
|
||||
$name = File::Basename::fileparse($0) if (!$name);
|
||||
# if lock file exists
|
||||
if (-f $file) {
|
||||
my $exists = 0;
|
||||
my $pid = `cat $file`;
|
||||
chomp($pid);
|
||||
# printDebug("Lock file found for $pid", 1);
|
||||
# check if process excists with this pid
|
||||
# better todo A for ALL processes
|
||||
# ps axu OR short ps a
|
||||
open(PS, 'ps axu|') || die("$!");
|
||||
while (<PS>) {
|
||||
# search for pid and run file name
|
||||
if ($_ =~ /\ $pid\ / && $_ =~ /$name/) {
|
||||
$exists = 1;
|
||||
}
|
||||
last if ($exists);
|
||||
}
|
||||
close(PS);
|
||||
if (!$exists) {
|
||||
# printDebug("Lock file cleaned up for $pid", 1);
|
||||
unlink($file);
|
||||
} else {
|
||||
die("Script is already running with PID $pid\n");
|
||||
}
|
||||
}
|
||||
# write current PID into lock file
|
||||
open(FP, '>:encoding('.$encoding.')', $file) || die ("Cannot open run lock file '$file' for writing\n");
|
||||
print FP $run_pid;
|
||||
close(FP);
|
||||
}
|
||||
|
||||
# METHOD: printDebug
|
||||
# PARAMS: message, verbose level
|
||||
# RETURN: nothing
|
||||
# DESC: depeding on the verbose and debug settings it will print out message and or write it to a debug file
|
||||
sub printDebug
|
||||
{
|
||||
my($msg, $vrb, $dbg) = @_;
|
||||
# print debug only if debug is on and debug file is available
|
||||
print $::DEBUG '['.create_time(time(), 1).'] '.$msg."\n" if ($::debug && $::DEBUG);
|
||||
# print to log if log is accessable and the verbose flag matches, or for debug flag if debug statement is set and not log only, or if log only, if not debug statement
|
||||
print $::LOG $msg."\n" if (($::verbose >= $vrb || (!$::log_only && $dbg && $::debug) || ($::log_only && !$dbg)) && $::LOG);
|
||||
# print to screen if verbose matches, but it is not a log only, or if it is debug statement and debug flag is set
|
||||
print $msg."\n" if (($::verbose >= $vrb && !$::log_only) || ($dbg && $::debug));
|
||||
}
|
||||
|
||||
# METHOD: waitAbort
|
||||
# PARAMS: time in seconds, if not provided set to 5
|
||||
# RETURN: nothing
|
||||
# DESC: simple prints out a char while waiting for an abort command
|
||||
sub waitAbort
|
||||
{
|
||||
my($sleep) = @_;
|
||||
$sleep = 5 if ($sleep !~ /\d/);
|
||||
print "Waiting $sleep seconds (Press CTRL + C to abort)\n";
|
||||
for (my $i = 1; $i <= $sleep; $i ++) {
|
||||
print ".";
|
||||
sleep 1;
|
||||
}
|
||||
print "\n\n";
|
||||
}
|
||||
|
||||
# METHOD: copyToTemporary
|
||||
# PARAMS: file to copy, and target file name
|
||||
# RETURN: the target file name
|
||||
# DESC : sets the source to read only and makes a copy, the copy is also set to read only
|
||||
sub copyToTemporary
|
||||
{
|
||||
my ($source, $target) = @_;
|
||||
# get the current rights
|
||||
my $current_chmod = (stat $source)[2];
|
||||
# set source file ARGV to read only
|
||||
# we skip that, the source might be NOT from the same user as the script read, just copy the file and set the target read only
|
||||
chmod(0444, $source);
|
||||
# create tmp backup file from which we read, data gets removed at the end of an run, or during an abort call
|
||||
copy($source, $target) || die("Copy failed: $!\n");
|
||||
# set read rights to r only for the copied file
|
||||
chmod(0444, $target);
|
||||
# set old access rights for ARGV file
|
||||
chmod($current_chmod, $source);
|
||||
# return target file name
|
||||
return $target;
|
||||
}
|
||||
|
||||
# METHOD: uniq
|
||||
# PARAMS: @array
|
||||
# RETURN: array with only unique entries
|
||||
# DESC : used in uniq(@array) to get only unique data back
|
||||
sub uniq
|
||||
{
|
||||
my %seen;
|
||||
grep !$seen{$_}++, @_;
|
||||
}
|
||||
|
||||
# METHOD: clean_test
|
||||
# PARAMS: array of data
|
||||
# RETURN: cleaned up array of data
|
||||
# DESC : sets all undefs to '' for debug output
|
||||
sub clean_test
|
||||
{
|
||||
my (@data) = @_;
|
||||
# map check for defined, if not, return ''
|
||||
return map { defined($_) ? $_ : '' } @data;
|
||||
}
|
||||
|
||||
# METHOD: clean_test_string
|
||||
# PARAMS: string to be checked
|
||||
# RETURN: data or empty for output
|
||||
# DESC : sets all input data to '' if it is undefined
|
||||
sub clean_test_string
|
||||
{
|
||||
my ($data) = @_;
|
||||
return defined($data) ? $data : '';
|
||||
}
|
||||
|
||||
1;
|
||||
12
phpstan-bootstrap.php
Executable file
12
phpstan-bootstrap.php
Executable file
@@ -0,0 +1,12 @@
|
||||
<?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__
|
||||
59
phpstan.neon
Normal file
59
phpstan.neon
Normal file
@@ -0,0 +1,59 @@
|
||||
# PHP Stan Config
|
||||
|
||||
parameters:
|
||||
tmpDir: /tmp/phpstan-corelibs
|
||||
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
|
||||
# if composer.json autoloader defined, this is not needed
|
||||
# - www/lib/autoloader.php
|
||||
- www/vendor/autoload.php
|
||||
- www/lib/Smarty/Autoloader.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_*.php
|
||||
# ignore admin header 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
|
||||
- www/templates_c
|
||||
- www/cache
|
||||
- www/log
|
||||
- www/media
|
||||
- www/tmp
|
||||
# external libs are not checked
|
||||
- www/lib/Smarty/
|
||||
- www/lib/smarty-*/
|
||||
# ignore composer
|
||||
- www/vendor
|
||||
# ignore errores with
|
||||
ignoreErrors:
|
||||
# this is ignored for now
|
||||
# - '#Expression in empty\(\) is always falsy.#'
|
||||
# -
|
||||
# message: '#Reflection error: [a-zA-Z0-9\\_]+ not found.#'
|
||||
# path: www/includes/edit_base.php
|
||||
#- 'error regex'
|
||||
#-
|
||||
# message: 'error regex'
|
||||
# path: %currentWorkingDirectory%/www/some/*
|
||||
# paths:
|
||||
# - ...
|
||||
# - ...
|
||||
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>
|
||||
9
static_checkers.txt
Normal file
9
static_checkers.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
# main static checker
|
||||
phan --progress-bar -C -o 4dev/tmp/analysis.txt
|
||||
# sub static checker
|
||||
phpstan analyse -c phpstan.neon --memory-limit=4G -l 0 www
|
||||
# only if we work with composer only
|
||||
www/: psalm (this needs the composer autoloader defined)
|
||||
|
||||
# for linting
|
||||
parallel-lint www/
|
||||
@@ -1 +0,0 @@
|
||||
smarty-3.1.27/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,467 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Project: Smarty: the PHP compiling template engine
|
||||
* File: SmartyBC.class.php
|
||||
* SVN: $Id: $
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
* For questions, help, comments, discussion, etc., please join the
|
||||
* Smarty mailing list. Send a blank e-mail to
|
||||
* smarty-discussion-subscribe@googlegroups.com
|
||||
*
|
||||
* @link http://www.smarty.net/
|
||||
* @copyright 2008 New Digital Group, Inc.
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
* @package Smarty
|
||||
*/
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
require_once(dirname(__FILE__) . '/Smarty.class.php');
|
||||
|
||||
/**
|
||||
* Smarty Backward Compatability Wrapper Class
|
||||
*
|
||||
* @package Smarty
|
||||
*/
|
||||
class SmartyBC extends Smarty
|
||||
{
|
||||
/**
|
||||
* Smarty 2 BC
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $_version = self::SMARTY_VERSION;
|
||||
|
||||
/**
|
||||
* Initialize new SmartyBC object
|
||||
*
|
||||
* @param array $options options to set during initialization, e.g. array( 'forceCompile' => false )
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
parent::__construct($options);
|
||||
// register {php} tag
|
||||
$this->registerPlugin('block', 'php', 'smarty_php_tag');
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for assign_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to assign
|
||||
*/
|
||||
public function assign_by_ref($tpl_var, &$value)
|
||||
{
|
||||
$this->assignByRef($tpl_var, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper for append_by_ref
|
||||
*
|
||||
* @param string $tpl_var the template variable name
|
||||
* @param mixed &$value the referenced value to append
|
||||
* @param boolean $merge flag if array elements shall be merged
|
||||
*/
|
||||
public function append_by_ref($tpl_var, &$value, $merge = false)
|
||||
{
|
||||
$this->appendByRef($tpl_var, $value, $merge);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the given assigned template variable.
|
||||
*
|
||||
* @param string $tpl_var the template variable to clear
|
||||
*/
|
||||
public function clear_assign($tpl_var)
|
||||
{
|
||||
$this->clearAssign($tpl_var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers custom function to be used in templates
|
||||
*
|
||||
* @param string $function the name of the template function
|
||||
* @param string $function_impl the name of the PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*/
|
||||
public function register_function($function, $function_impl, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
$this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters custom function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('function', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers object to be used in templates
|
||||
*
|
||||
* @param string $object name of template object
|
||||
* @param object $object_impl the referenced PHP object to register
|
||||
* @param array $allowed list of allowed methods (empty = all)
|
||||
* @param boolean $smarty_args smarty argument format, else traditional
|
||||
* @param array $block_methods list of methods that are block format
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @internal param array $block_functs list of methods that are block format
|
||||
*/
|
||||
public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
|
||||
{
|
||||
settype($allowed, 'array');
|
||||
settype($smarty_args, 'boolean');
|
||||
$this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters object
|
||||
*
|
||||
* @param string $object name of template object
|
||||
*/
|
||||
public function unregister_object($object)
|
||||
{
|
||||
$this->unregisterObject($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers block function to be used in templates
|
||||
*
|
||||
* @param string $block name of template block
|
||||
* @param string $block_impl PHP function to register
|
||||
* @param bool $cacheable
|
||||
* @param mixed $cache_attrs
|
||||
*/
|
||||
public function register_block($block, $block_impl, $cacheable = true, $cache_attrs = null)
|
||||
{
|
||||
$this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters block function
|
||||
*
|
||||
* @param string $block name of template function
|
||||
*/
|
||||
public function unregister_block($block)
|
||||
{
|
||||
$this->unregisterPlugin('block', $block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
* @param string $function_impl name of PHP function to register
|
||||
* @param bool $cacheable
|
||||
*/
|
||||
public function register_compiler_function($function, $function_impl, $cacheable = true)
|
||||
{
|
||||
$this->registerPlugin('compiler', $function, $function_impl, $cacheable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters compiler function
|
||||
*
|
||||
* @param string $function name of template function
|
||||
*/
|
||||
public function unregister_compiler_function($function)
|
||||
{
|
||||
$this->unregisterPlugin('compiler', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers modifier to be used in templates
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
* @param string $modifier_impl name of PHP function to register
|
||||
*/
|
||||
public function register_modifier($modifier, $modifier_impl)
|
||||
{
|
||||
$this->registerPlugin('modifier', $modifier, $modifier_impl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters modifier
|
||||
*
|
||||
* @param string $modifier name of template modifier
|
||||
*/
|
||||
public function unregister_modifier($modifier)
|
||||
{
|
||||
$this->unregisterPlugin('modifier', $modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a resource to fetch a template
|
||||
*
|
||||
* @param string $type name of resource
|
||||
* @param array $functions array of functions to handle resource
|
||||
*/
|
||||
public function register_resource($type, $functions)
|
||||
{
|
||||
$this->registerResource($type, $functions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a resource
|
||||
*
|
||||
* @param string $type name of resource
|
||||
*/
|
||||
public function unregister_resource($type)
|
||||
{
|
||||
$this->unregisterResource($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a prefilter function to apply
|
||||
* to a template before compiling
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_prefilter($function)
|
||||
{
|
||||
$this->registerFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a prefilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_prefilter($function)
|
||||
{
|
||||
$this->unregisterFilter('pre', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a postfilter function to apply
|
||||
* to a compiled template after compilation
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_postfilter($function)
|
||||
{
|
||||
$this->registerFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a postfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_postfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('post', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an output filter function to apply
|
||||
* to a template output
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function register_outputfilter($function)
|
||||
{
|
||||
$this->registerFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters an outputfilter function
|
||||
*
|
||||
* @param callable $function
|
||||
*/
|
||||
public function unregister_outputfilter($function)
|
||||
{
|
||||
$this->unregisterFilter('output', $function);
|
||||
}
|
||||
|
||||
/**
|
||||
* load a filter of specified type and name
|
||||
*
|
||||
* @param string $type filter type
|
||||
* @param string $name filter name
|
||||
*/
|
||||
public function load_filter($type, $name)
|
||||
{
|
||||
$this->loadFilter($type, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear cached content for the given template and cache id
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id name of cache_id
|
||||
* @param string $compile_id name of compile_id
|
||||
* @param string $exp_time expiration time
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear the entire contents of cache (all templates)
|
||||
*
|
||||
* @param string $exp_time expire time
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function clear_all_cache($exp_time = null)
|
||||
{
|
||||
return $this->clearCache(null, null, null, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* test to see if valid cache exists for this template
|
||||
*
|
||||
* @param string $tpl_file name of template file
|
||||
* @param string $cache_id
|
||||
* @param string $compile_id
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_cached($tpl_file, $cache_id = null, $compile_id = null)
|
||||
{
|
||||
return $this->isCached($tpl_file, $cache_id, $compile_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all the assigned template variables.
|
||||
*/
|
||||
public function clear_all_assign()
|
||||
{
|
||||
$this->clearAllAssign();
|
||||
}
|
||||
|
||||
/**
|
||||
* clears compiled version of specified template resource,
|
||||
* or all compiled template files if one is not specified.
|
||||
* This function is for advanced use only, not normally needed.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
* @param string $compile_id
|
||||
* @param string $exp_time
|
||||
*
|
||||
* @return boolean results of {@link smarty_core_rm_auto()}
|
||||
*/
|
||||
public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null)
|
||||
{
|
||||
return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether requested template exists.
|
||||
*
|
||||
* @param string $tpl_file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function template_exists($tpl_file)
|
||||
{
|
||||
return $this->templateExists($tpl_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing template variables
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_template_vars($name = null)
|
||||
{
|
||||
return $this->getTemplateVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing config variables
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_config_vars($name = null)
|
||||
{
|
||||
return $this->getConfigVars($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* load configuration values
|
||||
*
|
||||
* @param string $file
|
||||
* @param string $section
|
||||
* @param string $scope
|
||||
*/
|
||||
public function config_load($file, $section = null, $scope = 'global')
|
||||
{
|
||||
$this->ConfigLoad($file, $section, $scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* return a reference to a registered object
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function get_registered_object($name)
|
||||
{
|
||||
return $this->getRegisteredObject($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* clear configuration values
|
||||
*
|
||||
* @param string $var
|
||||
*/
|
||||
public function clear_config($var = null)
|
||||
{
|
||||
$this->clearConfig($var);
|
||||
}
|
||||
|
||||
/**
|
||||
* trigger Smarty error
|
||||
*
|
||||
* @param string $error_msg
|
||||
* @param integer $error_type
|
||||
*/
|
||||
public function trigger_error($error_msg, $error_type = E_USER_WARNING)
|
||||
{
|
||||
trigger_error("Smarty error: $error_msg", $error_type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty {php}{/php} block function
|
||||
*
|
||||
* @param array $params parameter list
|
||||
* @param string $content contents of the block
|
||||
* @param object $template template object
|
||||
* @param boolean &$repeat repeat flag
|
||||
*
|
||||
* @return string content re-formatted
|
||||
*/
|
||||
function smarty_php_tag($params, $content, $template, &$repeat)
|
||||
{
|
||||
eval($content);
|
||||
|
||||
return '';
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
{capture name='_smarty_debug' assign=debug_output}
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Smarty Debug Console</title>
|
||||
<style type="text/css">
|
||||
{literal}
|
||||
body, h1, h2, td, th, p {
|
||||
font-family: sans-serif;
|
||||
font-weight: normal;
|
||||
font-size: 0.9em;
|
||||
margin: 1px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 0;
|
||||
text-align: left;
|
||||
padding: 2px;
|
||||
background-color: #f0c040;
|
||||
color: black;
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
h2 {
|
||||
background-color: #9B410E;
|
||||
color: white;
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 2px;
|
||||
border-top: 1px solid black;
|
||||
}
|
||||
|
||||
body {
|
||||
background: black;
|
||||
}
|
||||
|
||||
p, table, div {
|
||||
background: #f0ead8;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
font-style: italic;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
th, td {
|
||||
font-family: monospace;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
width: 50%;
|
||||
}
|
||||
|
||||
td {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.odd {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
.even {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.exectime {
|
||||
font-size: 0.8em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
#table_assigned_vars th {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
#table_config_vars th {
|
||||
color: maroon;
|
||||
}
|
||||
|
||||
{/literal}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Smarty Debug Console
|
||||
- {if isset($template_name)}{$template_name|debug_print_var nofilter}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}</h1>
|
||||
|
||||
{if !empty($template_data)}
|
||||
<h2>included templates & config files (load time in seconds)</h2>
|
||||
<div>
|
||||
{foreach $template_data as $template}
|
||||
<font color=brown>{$template.name}</font>
|
||||
<span class="exectime">
|
||||
(compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}
|
||||
)
|
||||
</span>
|
||||
<br>
|
||||
{/foreach}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<h2>assigned template variables</h2>
|
||||
|
||||
<table id="table_assigned_vars">
|
||||
{foreach $assigned_vars as $vars}
|
||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
||||
<th>${$vars@key|escape:'html'}</th>
|
||||
<td>{$vars|debug_print_var nofilter}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
</table>
|
||||
|
||||
<h2>assigned config file variables (outer template scope)</h2>
|
||||
|
||||
<table id="table_config_vars">
|
||||
{foreach $config_vars as $vars}
|
||||
<tr class="{if $vars@iteration % 2 eq 0}odd{else}even{/if}">
|
||||
<th>{$vars@key|escape:'html'}</th>
|
||||
<td>{$vars|debug_print_var nofilter}</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
{/capture}
|
||||
<script type="text/javascript">
|
||||
{$id = $template_name|default:''|md5}
|
||||
_smarty_console = window.open("", "console{$id}", "width=680,height=600,resizable,scrollbars=yes");
|
||||
_smarty_console.document.write("{$debug_output|escape:'javascript' nofilter}");
|
||||
_smarty_console.document.close();
|
||||
</script>
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {counter} function plugin
|
||||
* Type: function<br>
|
||||
* Name: counter<br>
|
||||
* Purpose: print out a counter value
|
||||
*
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @link http://www.smarty.net/manual/en/language.function.counter.php {counter}
|
||||
* (Smarty online manual)
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
function smarty_function_counter($params, $template)
|
||||
{
|
||||
static $counters = array();
|
||||
|
||||
$name = (isset($params['name'])) ? $params['name'] : 'default';
|
||||
if (!isset($counters[$name])) {
|
||||
$counters[$name] = array(
|
||||
'start' => 1,
|
||||
'skip' => 1,
|
||||
'direction' => 'up',
|
||||
'count' => 1
|
||||
);
|
||||
}
|
||||
$counter =& $counters[$name];
|
||||
|
||||
if (isset($params['start'])) {
|
||||
$counter['start'] = $counter['count'] = (int) $params['start'];
|
||||
}
|
||||
|
||||
if (!empty($params['assign'])) {
|
||||
$counter['assign'] = $params['assign'];
|
||||
}
|
||||
|
||||
if (isset($counter['assign'])) {
|
||||
$template->assign($counter['assign'], $counter['count']);
|
||||
}
|
||||
|
||||
if (isset($params['print'])) {
|
||||
$print = (bool) $params['print'];
|
||||
} else {
|
||||
$print = empty($counter['assign']);
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
$retval = $counter['count'];
|
||||
} else {
|
||||
$retval = null;
|
||||
}
|
||||
|
||||
if (isset($params['skip'])) {
|
||||
$counter['skip'] = $params['skip'];
|
||||
}
|
||||
|
||||
if (isset($params['direction'])) {
|
||||
$counter['direction'] = $params['direction'];
|
||||
}
|
||||
|
||||
if ($counter['direction'] == "down") {
|
||||
$counter['count'] -= $counter['skip'];
|
||||
} else {
|
||||
$counter['count'] += $counter['skip'];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {cycle} function plugin
|
||||
* Type: function<br>
|
||||
* Name: cycle<br>
|
||||
* Date: May 3, 2002<br>
|
||||
* Purpose: cycle through given values<br>
|
||||
* Params:
|
||||
* <pre>
|
||||
* - name - name of cycle (optional)
|
||||
* - values - comma separated list of values to cycle, or an array of values to cycle
|
||||
* (this can be left out for subsequent calls)
|
||||
* - reset - boolean - resets given var to true
|
||||
* - print - boolean - print var or not. default is true
|
||||
* - advance - boolean - whether or not to advance the cycle
|
||||
* - delimiter - the value delimiter, default is ","
|
||||
* - assign - boolean, assigns to template var instead of printed.
|
||||
* </pre>
|
||||
* Examples:<br>
|
||||
* <pre>
|
||||
* {cycle values="#eeeeee,#d0d0d0d"}
|
||||
* {cycle name=row values="one,two,three" reset=true}
|
||||
* {cycle name=row}
|
||||
* </pre>
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author credit to Mark Priatel <mpriatel@rogers.com>
|
||||
* @author credit to Gerard <gerard@interfold.com>
|
||||
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
|
||||
* @version 1.3
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
|
||||
function smarty_function_cycle($params, $template)
|
||||
{
|
||||
static $cycle_vars;
|
||||
|
||||
$name = (empty($params['name'])) ? 'default' : $params['name'];
|
||||
$print = (isset($params['print'])) ? (bool) $params['print'] : true;
|
||||
$advance = (isset($params['advance'])) ? (bool) $params['advance'] : true;
|
||||
$reset = (isset($params['reset'])) ? (bool) $params['reset'] : false;
|
||||
|
||||
if (!isset($params['values'])) {
|
||||
if (!isset($cycle_vars[$name]['values'])) {
|
||||
trigger_error("cycle: missing 'values' parameter");
|
||||
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (isset($cycle_vars[$name]['values'])
|
||||
&& $cycle_vars[$name]['values'] != $params['values']
|
||||
) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
}
|
||||
$cycle_vars[$name]['values'] = $params['values'];
|
||||
}
|
||||
|
||||
if (isset($params['delimiter'])) {
|
||||
$cycle_vars[$name]['delimiter'] = $params['delimiter'];
|
||||
} elseif (!isset($cycle_vars[$name]['delimiter'])) {
|
||||
$cycle_vars[$name]['delimiter'] = ',';
|
||||
}
|
||||
|
||||
if (is_array($cycle_vars[$name]['values'])) {
|
||||
$cycle_array = $cycle_vars[$name]['values'];
|
||||
} else {
|
||||
$cycle_array = explode($cycle_vars[$name]['delimiter'], $cycle_vars[$name]['values']);
|
||||
}
|
||||
|
||||
if (!isset($cycle_vars[$name]['index']) || $reset) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
}
|
||||
|
||||
if (isset($params['assign'])) {
|
||||
$print = false;
|
||||
$template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
|
||||
}
|
||||
|
||||
if ($print) {
|
||||
$retval = $cycle_array[$cycle_vars[$name]['index']];
|
||||
} else {
|
||||
$retval = null;
|
||||
}
|
||||
|
||||
if ($advance) {
|
||||
if ($cycle_vars[$name]['index'] >= count($cycle_array) - 1) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
} else {
|
||||
$cycle_vars[$name]['index'] ++;
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
@@ -1,163 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_image} function plugin
|
||||
* Type: function<br>
|
||||
* Name: html_image<br>
|
||||
* Date: Feb 24, 2003<br>
|
||||
* Purpose: format HTML tags for the image<br>
|
||||
* Examples: {html_image file="/images/masthead.gif"}<br>
|
||||
* Output: <img src="/images/masthead.gif" width=400 height=23><br>
|
||||
* Params:
|
||||
* <pre>
|
||||
* - file - (required) - file (and path) of image
|
||||
* - height - (optional) - image height (default actual height)
|
||||
* - width - (optional) - image width (default actual width)
|
||||
* - basedir - (optional) - base directory for absolute paths, default is environment variable DOCUMENT_ROOT
|
||||
* - path_prefix - prefix for path output (optional, default empty)
|
||||
* </pre>
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.function.html.image.php {html_image}
|
||||
* (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author credits to Duda <duda@big.hu>
|
||||
* @version 1.0
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_image($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
|
||||
$alt = '';
|
||||
$file = '';
|
||||
$height = '';
|
||||
$width = '';
|
||||
$extra = '';
|
||||
$prefix = '';
|
||||
$suffix = '';
|
||||
$path_prefix = '';
|
||||
$basedir = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '';
|
||||
foreach ($params as $_key => $_val) {
|
||||
switch ($_key) {
|
||||
case 'file':
|
||||
case 'height':
|
||||
case 'width':
|
||||
case 'dpi':
|
||||
case 'path_prefix':
|
||||
case 'basedir':
|
||||
$$_key = $_val;
|
||||
break;
|
||||
|
||||
case 'alt':
|
||||
if (!is_array($_val)) {
|
||||
$$_key = smarty_function_escape_special_chars($_val);
|
||||
} else {
|
||||
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'link':
|
||||
case 'href':
|
||||
$prefix = '<a href="' . $_val . '">';
|
||||
$suffix = '</a>';
|
||||
break;
|
||||
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
} else {
|
||||
throw new SmartyException ("html_image: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($file)) {
|
||||
trigger_error("html_image: missing 'file' parameter", E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($file[0] == '/') {
|
||||
$_image_path = $basedir . $file;
|
||||
} else {
|
||||
$_image_path = $file;
|
||||
}
|
||||
|
||||
// strip file protocol
|
||||
if (stripos($params['file'], 'file://') === 0) {
|
||||
$params['file'] = substr($params['file'], 7);
|
||||
}
|
||||
|
||||
$protocol = strpos($params['file'], '://');
|
||||
if ($protocol !== false) {
|
||||
$protocol = strtolower(substr($params['file'], 0, $protocol));
|
||||
}
|
||||
|
||||
if (isset($template->smarty->security_policy)) {
|
||||
if ($protocol) {
|
||||
// remote resource (or php stream, …)
|
||||
if (!$template->smarty->security_policy->isTrustedUri($params['file'])) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// local file
|
||||
if (!$template->smarty->security_policy->isTrustedResourceDir($_image_path)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($params['width']) || !isset($params['height'])) {
|
||||
// FIXME: (rodneyrehm) getimagesize() loads the complete file off a remote resource, use custom [jpg,png,gif]header reader!
|
||||
if (!$_image_data = @getimagesize($_image_path)) {
|
||||
if (!file_exists($_image_path)) {
|
||||
trigger_error("html_image: unable to find '$_image_path'", E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
} elseif (!is_readable($_image_path)) {
|
||||
trigger_error("html_image: unable to read '$_image_path'", E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
} else {
|
||||
trigger_error("html_image: '$_image_path' is not a valid image file", E_USER_NOTICE);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($params['width'])) {
|
||||
$width = $_image_data[0];
|
||||
}
|
||||
if (!isset($params['height'])) {
|
||||
$height = $_image_data[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['dpi'])) {
|
||||
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mac')) {
|
||||
// FIXME: (rodneyrehm) wrong dpi assumption
|
||||
// don't know who thought this up… even if it was true in 1998, it's definitely wrong in 2011.
|
||||
$dpi_default = 72;
|
||||
} else {
|
||||
$dpi_default = 96;
|
||||
}
|
||||
$_resize = $dpi_default / $params['dpi'];
|
||||
$width = round($width * $_resize);
|
||||
$height = round($height * $_resize);
|
||||
}
|
||||
|
||||
return $prefix . '<img src="' . $path_prefix . $file . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '"' . $extra . ' />' . $suffix;
|
||||
}
|
||||
@@ -1,221 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_radios} function plugin
|
||||
* File: function.html_radios.php<br>
|
||||
* Type: function<br>
|
||||
* Name: html_radios<br>
|
||||
* Date: 24.Feb.2003<br>
|
||||
* Purpose: Prints out a list of radio input types<br>
|
||||
* Params:
|
||||
* <pre>
|
||||
* - name (optional) - string default "radio"
|
||||
* - values (required) - array
|
||||
* - options (required) - associative array
|
||||
* - checked (optional) - array default not set
|
||||
* - separator (optional) - ie <br> or
|
||||
* - output (optional) - the output next to each radio button
|
||||
* - assign (optional) - assign the output as an array to this variable
|
||||
* - escape (optional) - escape the content (not value), defaults to true
|
||||
* </pre>
|
||||
* Examples:
|
||||
* <pre>
|
||||
* {html_radios values=$ids output=$names}
|
||||
* {html_radios values=$ids name='box' separator='<br>' output=$names}
|
||||
* {html_radios values=$ids checked=$checked separator='<br>' output=$names}
|
||||
* </pre>
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.function.html.radios.php {html_radios}
|
||||
* (Smarty online manual)
|
||||
* @author Christopher Kvarme <christopher.kvarme@flashjab.com>
|
||||
* @author credits to Monte Ohrt <monte at ohrt dot com>
|
||||
* @version 1.0
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param Smarty_Internal_Template $template template object
|
||||
*
|
||||
* @return string
|
||||
* @uses smarty_function_escape_special_chars()
|
||||
*/
|
||||
function smarty_function_html_radios($params, $template)
|
||||
{
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php');
|
||||
|
||||
$name = 'radio';
|
||||
$values = null;
|
||||
$options = null;
|
||||
$selected = null;
|
||||
$separator = '';
|
||||
$escape = true;
|
||||
$labels = true;
|
||||
$label_ids = false;
|
||||
$output = null;
|
||||
$extra = '';
|
||||
|
||||
foreach ($params as $_key => $_val) {
|
||||
switch ($_key) {
|
||||
case 'name':
|
||||
case 'separator':
|
||||
$$_key = (string) $_val;
|
||||
break;
|
||||
|
||||
case 'checked':
|
||||
case 'selected':
|
||||
if (is_array($_val)) {
|
||||
trigger_error('html_radios: the "' . $_key . '" attribute cannot be an array', E_USER_WARNING);
|
||||
} elseif (is_object($_val)) {
|
||||
if (method_exists($_val, "__toString")) {
|
||||
$selected = smarty_function_escape_special_chars((string) $_val->__toString());
|
||||
} else {
|
||||
trigger_error("html_radios: selected attribute is an object of class '" . get_class($_val) . "' without __toString() method", E_USER_NOTICE);
|
||||
}
|
||||
} else {
|
||||
$selected = (string) $_val;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'escape':
|
||||
case 'labels':
|
||||
case 'label_ids':
|
||||
$$_key = (bool) $_val;
|
||||
break;
|
||||
|
||||
case 'options':
|
||||
$$_key = (array) $_val;
|
||||
break;
|
||||
|
||||
case 'values':
|
||||
case 'output':
|
||||
$$_key = array_values((array) $_val);
|
||||
break;
|
||||
|
||||
case 'radios':
|
||||
trigger_error('html_radios: the use of the "radios" attribute is deprecated, use "options" instead', E_USER_WARNING);
|
||||
$options = (array) $_val;
|
||||
break;
|
||||
|
||||
case 'assign':
|
||||
break;
|
||||
|
||||
case 'strict':
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
case 'readonly':
|
||||
if (!empty($params['strict'])) {
|
||||
if (!is_scalar($_val)) {
|
||||
trigger_error("html_options: $_key attribute must be a scalar, only boolean true or string '$_key' will actually add the attribute", E_USER_NOTICE);
|
||||
}
|
||||
|
||||
if ($_val === true || $_val === $_key) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_key) . '"';
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
// omit break; to fall through!
|
||||
|
||||
default:
|
||||
if (!is_array($_val)) {
|
||||
$extra .= ' ' . $_key . '="' . smarty_function_escape_special_chars($_val) . '"';
|
||||
} else {
|
||||
trigger_error("html_radios: extra attribute '$_key' cannot be an array", E_USER_NOTICE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($options) && !isset($values)) {
|
||||
/* raise error here? */
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
$_html_result = array();
|
||||
|
||||
if (isset($options)) {
|
||||
foreach ($options as $_key => $_val) {
|
||||
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
|
||||
}
|
||||
} else {
|
||||
foreach ($values as $_i => $_key) {
|
||||
$_val = isset($output[$_i]) ? $output[$_i] : '';
|
||||
$_html_result[] = smarty_function_html_radios_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($params['assign'])) {
|
||||
$template->assign($params['assign'], $_html_result);
|
||||
} else {
|
||||
return implode("\n", $_html_result);
|
||||
}
|
||||
}
|
||||
|
||||
function smarty_function_html_radios_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape)
|
||||
{
|
||||
$_output = '';
|
||||
|
||||
if (is_object($value)) {
|
||||
if (method_exists($value, "__toString")) {
|
||||
$value = (string) $value->__toString();
|
||||
} else {
|
||||
trigger_error("html_options: value is an object of class '" . get_class($value) . "' without __toString() method", E_USER_NOTICE);
|
||||
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$value = (string) $value;
|
||||
}
|
||||
|
||||
if (is_object($output)) {
|
||||
if (method_exists($output, "__toString")) {
|
||||
$output = (string) $output->__toString();
|
||||
} else {
|
||||
trigger_error("html_options: output is an object of class '" . get_class($output) . "' without __toString() method", E_USER_NOTICE);
|
||||
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
$output = (string) $output;
|
||||
}
|
||||
|
||||
if ($labels) {
|
||||
if ($label_ids) {
|
||||
$_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!' . Smarty::$_UTF8_MODIFIER, '_', $name . '_' . $value));
|
||||
$_output .= '<label for="' . $_id . '">';
|
||||
} else {
|
||||
$_output .= '<label>';
|
||||
}
|
||||
}
|
||||
|
||||
$name = smarty_function_escape_special_chars($name);
|
||||
$value = smarty_function_escape_special_chars($value);
|
||||
if ($escape) {
|
||||
$output = smarty_function_escape_special_chars($output);
|
||||
}
|
||||
|
||||
$_output .= '<input type="radio" name="' . $name . '" value="' . $value . '"';
|
||||
|
||||
if ($labels && $label_ids) {
|
||||
$_output .= ' id="' . $_id . '"';
|
||||
}
|
||||
|
||||
if ($value === $selected) {
|
||||
$_output .= ' checked="checked"';
|
||||
}
|
||||
|
||||
$_output .= $extra . ' />' . $output;
|
||||
if ($labels) {
|
||||
$_output .= '</label>';
|
||||
}
|
||||
|
||||
$_output .= $separator;
|
||||
|
||||
return $_output;
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty {html_table} function plugin
|
||||
* Type: function<br>
|
||||
* Name: html_table<br>
|
||||
* Date: Feb 17, 2003<br>
|
||||
* Purpose: make an html table from an array of data<br>
|
||||
* Params:
|
||||
* <pre>
|
||||
* - loop - array to loop through
|
||||
* - cols - number of columns, comma separated list of column names
|
||||
* or array of column names
|
||||
* - rows - number of rows
|
||||
* - table_attr - table attributes
|
||||
* - th_attr - table heading attributes (arrays are cycled)
|
||||
* - tr_attr - table row attributes (arrays are cycled)
|
||||
* - td_attr - table cell attributes (arrays are cycled)
|
||||
* - trailpad - value to pad trailing cells with
|
||||
* - caption - text for caption element
|
||||
* - vdir - vertical direction (default: "down", means top-to-bottom)
|
||||
* - hdir - horizontal direction (default: "right", means left-to-right)
|
||||
* - inner - inner loop (default "cols": print $loop line by line,
|
||||
* $loop will be printed column by column otherwise)
|
||||
* </pre>
|
||||
* Examples:
|
||||
* <pre>
|
||||
* {table loop=$data}
|
||||
* {table loop=$data cols=4 tr_attr='"bgcolor=red"'}
|
||||
* {table loop=$data cols="first,second,third" tr_attr=$colors}
|
||||
* </pre>
|
||||
*
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author credit to Messju Mohr <messju at lammfellpuschen dot de>
|
||||
* @author credit to boots <boots dot smarty at yahoo dot com>
|
||||
* @version 1.1
|
||||
* @link http://www.smarty.net/manual/en/language.function.html.table.php {html_table}
|
||||
* (Smarty online manual)
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_html_table($params)
|
||||
{
|
||||
$table_attr = 'border="1"';
|
||||
$tr_attr = '';
|
||||
$th_attr = '';
|
||||
$td_attr = '';
|
||||
$cols = $cols_count = 3;
|
||||
$rows = 3;
|
||||
$trailpad = ' ';
|
||||
$vdir = 'down';
|
||||
$hdir = 'right';
|
||||
$inner = 'cols';
|
||||
$caption = '';
|
||||
$loop = null;
|
||||
|
||||
if (!isset($params['loop'])) {
|
||||
trigger_error("html_table: missing 'loop' parameter", E_USER_WARNING);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($params as $_key => $_value) {
|
||||
switch ($_key) {
|
||||
case 'loop':
|
||||
$$_key = (array) $_value;
|
||||
break;
|
||||
|
||||
case 'cols':
|
||||
if (is_array($_value) && !empty($_value)) {
|
||||
$cols = $_value;
|
||||
$cols_count = count($_value);
|
||||
} elseif (!is_numeric($_value) && is_string($_value) && !empty($_value)) {
|
||||
$cols = explode(',', $_value);
|
||||
$cols_count = count($cols);
|
||||
} elseif (!empty($_value)) {
|
||||
$cols_count = (int) $_value;
|
||||
} else {
|
||||
$cols_count = $cols;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'rows':
|
||||
$$_key = (int) $_value;
|
||||
break;
|
||||
|
||||
case 'table_attr':
|
||||
case 'trailpad':
|
||||
case 'hdir':
|
||||
case 'vdir':
|
||||
case 'inner':
|
||||
case 'caption':
|
||||
$$_key = (string) $_value;
|
||||
break;
|
||||
|
||||
case 'tr_attr':
|
||||
case 'td_attr':
|
||||
case 'th_attr':
|
||||
$$_key = $_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$loop_count = count($loop);
|
||||
if (empty($params['rows'])) {
|
||||
/* no rows specified */
|
||||
$rows = ceil($loop_count / $cols_count);
|
||||
} elseif (empty($params['cols'])) {
|
||||
if (!empty($params['rows'])) {
|
||||
/* no cols specified, but rows */
|
||||
$cols_count = ceil($loop_count / $rows);
|
||||
}
|
||||
}
|
||||
|
||||
$output = "<table $table_attr>\n";
|
||||
|
||||
if (!empty($caption)) {
|
||||
$output .= '<caption>' . $caption . "</caption>\n";
|
||||
}
|
||||
|
||||
if (is_array($cols)) {
|
||||
$cols = ($hdir == 'right') ? $cols : array_reverse($cols);
|
||||
$output .= "<thead><tr>\n";
|
||||
|
||||
for ($r = 0; $r < $cols_count; $r ++) {
|
||||
$output .= '<th' . smarty_function_html_table_cycle('th', $th_attr, $r) . '>';
|
||||
$output .= $cols[$r];
|
||||
$output .= "</th>\n";
|
||||
}
|
||||
$output .= "</tr></thead>\n";
|
||||
}
|
||||
|
||||
$output .= "<tbody>\n";
|
||||
for ($r = 0; $r < $rows; $r ++) {
|
||||
$output .= "<tr" . smarty_function_html_table_cycle('tr', $tr_attr, $r) . ">\n";
|
||||
$rx = ($vdir == 'down') ? $r * $cols_count : ($rows - 1 - $r) * $cols_count;
|
||||
|
||||
for ($c = 0; $c < $cols_count; $c ++) {
|
||||
$x = ($hdir == 'right') ? $rx + $c : $rx + $cols_count - 1 - $c;
|
||||
if ($inner != 'cols') {
|
||||
/* shuffle x to loop over rows*/
|
||||
$x = floor($x / $cols_count) + ($x % $cols_count) * $rows;
|
||||
}
|
||||
|
||||
if ($x < $loop_count) {
|
||||
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">" . $loop[$x] . "</td>\n";
|
||||
} else {
|
||||
$output .= "<td" . smarty_function_html_table_cycle('td', $td_attr, $c) . ">$trailpad</td>\n";
|
||||
}
|
||||
}
|
||||
$output .= "</tr>\n";
|
||||
}
|
||||
$output .= "</tbody>\n";
|
||||
$output .= "</table>\n";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function smarty_function_html_table_cycle($name, $var, $no)
|
||||
{
|
||||
if (!is_array($var)) {
|
||||
$ret = $var;
|
||||
} else {
|
||||
$ret = $var[$no % count($var)];
|
||||
}
|
||||
|
||||
return ($ret) ? ' ' . $ret : '';
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty capitalize modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: capitalize<br>
|
||||
* Purpose: capitalize words in the string
|
||||
* {@internal {$string|capitalize:true:true} is the fastest option for MBString enabled systems }}
|
||||
*
|
||||
* @param string $string string to capitalize
|
||||
* @param boolean $uc_digits also capitalize "x123" to "X123"
|
||||
* @param boolean $lc_rest capitalize first letters, lowercase all following letters "aAa" to "Aaa"
|
||||
*
|
||||
* @return string capitalized string
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
function smarty_modifier_capitalize($string, $uc_digits = false, $lc_rest = false)
|
||||
{
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if ($lc_rest) {
|
||||
// uppercase (including hyphenated words)
|
||||
$upper_string = mb_convert_case($string, MB_CASE_TITLE, Smarty::$_CHARSET);
|
||||
} else {
|
||||
// uppercase word breaks
|
||||
$upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert_cb', $string);
|
||||
}
|
||||
// check uc_digits case
|
||||
if (!$uc_digits) {
|
||||
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
$upper_string = substr_replace($upper_string, mb_strtolower($match[0], Smarty::$_CHARSET), $match[1], strlen($match[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
$upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_mbconvert2_cb', $upper_string);
|
||||
return $upper_string;
|
||||
}
|
||||
|
||||
// lowercase first
|
||||
if ($lc_rest) {
|
||||
$string = strtolower($string);
|
||||
}
|
||||
// uppercase (including hyphenated words)
|
||||
$upper_string = preg_replace_callback("!(^|[^\p{L}'])([\p{Ll}])!S" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst_cb', $string);
|
||||
// check uc_digits case
|
||||
if (!$uc_digits) {
|
||||
if (preg_match_all("!\b([\p{L}]*[\p{N}]+[\p{L}]*)\b!" . Smarty::$_UTF8_MODIFIER, $string, $matches, PREG_OFFSET_CAPTURE)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
$upper_string = substr_replace($upper_string, strtolower($match[0]), $match[1], strlen($match[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
$upper_string = preg_replace_callback("!((^|\s)['\"])(\w)!" . Smarty::$_UTF8_MODIFIER, 'smarty_mod_cap_ucfirst2_cb', $upper_string);
|
||||
return $upper_string;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Bug: create_function() use exhausts memory when used in long loops
|
||||
* Fix: use declared functions for callbacks instead of using create_function()
|
||||
* Note: This can be fixed using anonymous functions instead, but that requires PHP >= 5.3
|
||||
*
|
||||
* @author Kyle Renfrow
|
||||
*/
|
||||
function smarty_mod_cap_mbconvert_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[2]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
function smarty_mod_cap_mbconvert2_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[1]) . mb_convert_case(stripslashes($matches[3]), MB_CASE_UPPER, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
function smarty_mod_cap_ucfirst_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[1]) . ucfirst(stripslashes($matches[2]));
|
||||
}
|
||||
|
||||
function smarty_mod_cap_ucfirst2_cb($matches)
|
||||
{
|
||||
return stripslashes($matches[1]) . ucfirst(stripslashes($matches[3]));
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty date_format modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: date_format<br>
|
||||
* Purpose: format datestamps via strftime<br>
|
||||
* Input:<br>
|
||||
* - string: input date string
|
||||
* - format: strftime format for output
|
||||
* - default_date: default date if $string is empty
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.date.format.php date_format (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param string $string input date string
|
||||
* @param string $format strftime format for output
|
||||
* @param string $default_date default date if $string is empty
|
||||
* @param string $formatter either 'strftime' or 'auto'
|
||||
*
|
||||
* @return string |void
|
||||
* @uses smarty_make_timestamp()
|
||||
*/
|
||||
function smarty_modifier_date_format($string, $format = null, $default_date = '', $formatter = 'auto')
|
||||
{
|
||||
if ($format === null) {
|
||||
$format = Smarty::$_DATE_FORMAT;
|
||||
}
|
||||
/**
|
||||
* Include the {@link shared.make_timestamp.php} plugin
|
||||
*/
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.make_timestamp.php');
|
||||
if ($string != '' && $string != '0000-00-00' && $string != '0000-00-00 00:00:00') {
|
||||
$timestamp = smarty_make_timestamp($string);
|
||||
} elseif ($default_date != '') {
|
||||
$timestamp = smarty_make_timestamp($default_date);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if ($formatter == 'strftime' || ($formatter == 'auto' && strpos($format, '%') !== false)) {
|
||||
if (DS == '\\') {
|
||||
$_win_from = array('%D', '%h', '%n', '%r', '%R', '%t', '%T');
|
||||
$_win_to = array('%m/%d/%y', '%b', "\n", '%I:%M:%S %p', '%H:%M', "\t", '%H:%M:%S');
|
||||
if (strpos($format, '%e') !== false) {
|
||||
$_win_from[] = '%e';
|
||||
$_win_to[] = sprintf('%\' 2d', date('j', $timestamp));
|
||||
}
|
||||
if (strpos($format, '%l') !== false) {
|
||||
$_win_from[] = '%l';
|
||||
$_win_to[] = sprintf('%\' 2d', date('h', $timestamp));
|
||||
}
|
||||
$format = str_replace($_win_from, $_win_to, $format);
|
||||
}
|
||||
|
||||
return strftime($format, $timestamp);
|
||||
} else {
|
||||
return date($format, $timestamp);
|
||||
}
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Debug
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty debug_print_var modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: debug_print_var<br>
|
||||
* Purpose: formats variable contents for display in the console
|
||||
*
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param array|object $var variable to be formatted
|
||||
* @param integer $depth maximum recursion depth if $var is an array
|
||||
* @param integer $length maximum string length if $var is a string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
|
||||
{
|
||||
$_replace = array("\n" => '<i>\n</i>',
|
||||
"\r" => '<i>\r</i>',
|
||||
"\t" => '<i>\t</i>'
|
||||
);
|
||||
|
||||
switch (gettype($var)) {
|
||||
case 'array' :
|
||||
$results = '<b>Array (' . count($var) . ')</b>';
|
||||
foreach ($var as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b>' . strtr($curr_key, $_replace) . '</b> => '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
$depth --;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'object' :
|
||||
$object_vars = get_object_vars($var);
|
||||
$results = '<b>' . get_class($var) . ' Object (' . count($object_vars) . ')</b>';
|
||||
foreach ($object_vars as $curr_key => $curr_val) {
|
||||
$results .= '<br>' . str_repeat(' ', $depth * 2)
|
||||
. '<b> ->' . strtr($curr_key, $_replace) . '</b> = '
|
||||
. smarty_modifier_debug_print_var($curr_val, ++$depth, $length);
|
||||
$depth --;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'boolean' :
|
||||
case 'NULL' :
|
||||
case 'resource' :
|
||||
if (true === $var) {
|
||||
$results = 'true';
|
||||
} elseif (false === $var) {
|
||||
$results = 'false';
|
||||
} elseif (null === $var) {
|
||||
$results = 'null';
|
||||
} else {
|
||||
$results = htmlspecialchars((string) $var);
|
||||
}
|
||||
$results = '<i>' . $results . '</i>';
|
||||
break;
|
||||
|
||||
case 'integer' :
|
||||
case 'float' :
|
||||
$results = htmlspecialchars((string) $var);
|
||||
break;
|
||||
|
||||
case 'string' :
|
||||
$results = strtr($var, $_replace);
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($var, Smarty::$_CHARSET) > $length) {
|
||||
$results = mb_substr($var, 0, $length - 3, Smarty::$_CHARSET) . '...';
|
||||
}
|
||||
} else {
|
||||
if (isset($var[$length])) {
|
||||
$results = substr($var, 0, $length - 3) . '...';
|
||||
}
|
||||
}
|
||||
|
||||
$results = htmlspecialchars('"' . $results . '"');
|
||||
break;
|
||||
|
||||
case 'unknown type' :
|
||||
default :
|
||||
$results = strtr((string) $var, $_replace);
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($results, Smarty::$_CHARSET) > $length) {
|
||||
$results = mb_substr($results, 0, $length - 3, Smarty::$_CHARSET) . '...';
|
||||
}
|
||||
} else {
|
||||
if (strlen($results) > $length) {
|
||||
$results = substr($results, 0, $length - 3) . '...';
|
||||
}
|
||||
}
|
||||
|
||||
$results = htmlspecialchars($results);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty escape modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: escape<br>
|
||||
* Purpose: escape string for output
|
||||
*
|
||||
* @link http://www.smarty.net/docs/en/language.modifier.escape
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param string $string input string
|
||||
* @param string $esc_type escape type
|
||||
* @param string $char_set character set, used for htmlspecialchars() or htmlentities()
|
||||
* @param boolean $double_encode encode already encoded entitites again, used for htmlspecialchars() or htmlentities()
|
||||
*
|
||||
* @return string escaped input string
|
||||
*/
|
||||
function smarty_modifier_escape($string, $esc_type = 'html', $char_set = null, $double_encode = true)
|
||||
{
|
||||
static $_double_encode = null;
|
||||
if ($_double_encode === null) {
|
||||
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
|
||||
}
|
||||
|
||||
if (!$char_set) {
|
||||
$char_set = Smarty::$_CHARSET;
|
||||
}
|
||||
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
if ($_double_encode) {
|
||||
// php >=5.3.2 - go native
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
// php <5.2.3 - prevent double encoding
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
// mb_convert_encoding ignores htmlspecialchars()
|
||||
if ($_double_encode) {
|
||||
// php >=5.3.2 - go native
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
// php <5.2.3 - prevent double encoding
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlspecialchars($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
// htmlentities() won't convert everything, so use mb_convert_encoding
|
||||
return mb_convert_encoding($string, 'HTML-ENTITIES', $char_set);
|
||||
}
|
||||
|
||||
// no MBString fallback
|
||||
if ($_double_encode) {
|
||||
return htmlentities($string, ENT_QUOTES, $char_set, $double_encode);
|
||||
} else {
|
||||
if ($double_encode) {
|
||||
return htmlentities($string, ENT_QUOTES, $char_set);
|
||||
} else {
|
||||
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
|
||||
$string = htmlentities($string, ENT_QUOTES, $char_set);
|
||||
$string = str_replace(array('%%%SMARTY_START%%%', '%%%SMARTY_END%%%'), array('&', ';'), $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
case 'url':
|
||||
return rawurlencode($string);
|
||||
|
||||
case 'urlpathinfo':
|
||||
return str_replace('%2F', '/', rawurlencode($string));
|
||||
|
||||
case 'quotes':
|
||||
// escape unescaped single quotes
|
||||
return preg_replace("%(?<!\\\\)'%", "\\'", $string);
|
||||
|
||||
case 'hex':
|
||||
// escape every byte into hex
|
||||
// Note that the UTF-8 encoded character ä will be represented as %c3%a4
|
||||
$return = '';
|
||||
$_length = strlen($string);
|
||||
for ($x = 0; $x < $_length; $x ++) {
|
||||
$return .= '%' . bin2hex($string[$x]);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
case 'hexentity':
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
$return = '';
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
$return .= '&#x' . strtoupper(dechex($unicode)) . ';';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
// no MBString fallback
|
||||
$_length = strlen($string);
|
||||
for ($x = 0; $x < $_length; $x ++) {
|
||||
$return .= '&#x' . bin2hex($string[$x]) . ';';
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
case 'decentity':
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
$return = '';
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
$return .= '&#' . $unicode . ';';
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
// no MBString fallback
|
||||
$_length = strlen($string);
|
||||
for ($x = 0; $x < $_length; $x ++) {
|
||||
$return .= '&#' . ord($string[$x]) . ';';
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
case 'javascript':
|
||||
// escape quotes and backslashes, newlines, etc.
|
||||
return strtr($string, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\/'));
|
||||
|
||||
case 'mail':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_str_replace.php');
|
||||
|
||||
return smarty_mb_str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
|
||||
}
|
||||
// no MBString fallback
|
||||
return str_replace(array('@', '.'), array(' [AT] ', ' [DOT] '), $string);
|
||||
|
||||
case 'nonstd':
|
||||
// escape non-standard chars, such as ms document quotes
|
||||
$return = '';
|
||||
if (Smarty::$_MBSTRING) {
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.mb_unicode.php');
|
||||
foreach (smarty_mb_to_unicode($string, Smarty::$_CHARSET) as $unicode) {
|
||||
if ($unicode >= 126) {
|
||||
$return .= '&#' . $unicode . ';';
|
||||
} else {
|
||||
$return .= chr($unicode);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
$_length = strlen($string);
|
||||
for ($_i = 0; $_i < $_length; $_i ++) {
|
||||
$_ord = ord(substr($string, $_i, 1));
|
||||
// non-standard char, escape it
|
||||
if ($_ord >= 126) {
|
||||
$return .= '&#' . $_ord . ';';
|
||||
} else {
|
||||
$return .= substr($string, $_i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
||||
default:
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty regex_replace modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: regex_replace<br>
|
||||
* Purpose: regular expression search/replace
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.regex.replace.php
|
||||
* regex_replace (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param string $string input string
|
||||
* @param string|array $search regular expression(s) to search for
|
||||
* @param string|array $replace string(s) that should be replaced
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function smarty_modifier_regex_replace($string, $search, $replace)
|
||||
{
|
||||
if (is_array($search)) {
|
||||
foreach ($search as $idx => $s) {
|
||||
$search[$idx] = _smarty_regex_replace_check($s);
|
||||
}
|
||||
} else {
|
||||
$search = _smarty_regex_replace_check($search);
|
||||
}
|
||||
|
||||
return preg_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search string(s) that should be replaced
|
||||
*
|
||||
* @return string
|
||||
* @ignore
|
||||
*/
|
||||
function _smarty_regex_replace_check($search)
|
||||
{
|
||||
// null-byte injection detection
|
||||
// anything behind the first null-byte is ignored
|
||||
if (($pos = strpos($search, "\0")) !== false) {
|
||||
$search = substr($search, 0, $pos);
|
||||
}
|
||||
// remove eval-modifier from $search
|
||||
if (preg_match('!([a-zA-Z\s]+)$!s', $search, $match) && (strpos($match[1], 'e') !== false)) {
|
||||
$search = substr($search, 0, - strlen($match[1])) . preg_replace('![e\s]+!', '', $match[1]);
|
||||
}
|
||||
|
||||
return $search;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty truncate modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: truncate<br>
|
||||
* Purpose: Truncate a string to a certain length if necessary,
|
||||
* optionally splitting in the middle of a word, and
|
||||
* appending the $etc string or inserting $etc into the middle.
|
||||
*
|
||||
* @link http://smarty.php.net/manual/en/language.modifier.truncate.php truncate (Smarty online manual)
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
*
|
||||
* @param string $string input string
|
||||
* @param integer $length length of truncated text
|
||||
* @param string $etc end string
|
||||
* @param boolean $break_words truncate at word boundary
|
||||
* @param boolean $middle truncate in the middle of text
|
||||
*
|
||||
* @return string truncated string
|
||||
*/
|
||||
function smarty_modifier_truncate($string, $length = 80, $etc = '...', $break_words = false, $middle = false)
|
||||
{
|
||||
if ($length == 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if (mb_strlen($string, Smarty::$_CHARSET) > $length) {
|
||||
$length -= min($length, mb_strlen($etc, Smarty::$_CHARSET));
|
||||
if (!$break_words && !$middle) {
|
||||
$string = preg_replace('/\s+?(\S+)?$/' . Smarty::$_UTF8_MODIFIER, '', mb_substr($string, 0, $length + 1, Smarty::$_CHARSET));
|
||||
}
|
||||
if (!$middle) {
|
||||
return mb_substr($string, 0, $length, Smarty::$_CHARSET) . $etc;
|
||||
}
|
||||
|
||||
return mb_substr($string, 0, $length / 2, Smarty::$_CHARSET) . $etc . mb_substr($string, - $length / 2, $length, Smarty::$_CHARSET);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
// no MBString fallback
|
||||
if (isset($string[$length])) {
|
||||
$length -= min($length, strlen($etc));
|
||||
if (!$break_words && !$middle) {
|
||||
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1));
|
||||
}
|
||||
if (!$middle) {
|
||||
return substr($string, 0, $length) . $etc;
|
||||
}
|
||||
|
||||
return substr($string, 0, $length / 2) . $etc . substr($string, - $length / 2);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty count_paragraphs modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: count_paragraphs<br>
|
||||
* Purpose: count the number of paragraphs in a text
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.count.paragraphs.php
|
||||
* count_paragraphs (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_count_paragraphs($params)
|
||||
{
|
||||
// count \r or \n characters
|
||||
return '(preg_match_all(\'#[\r\n]+#\', ' . $params[0] . ', $tmp)+1)';
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty default modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: default<br>
|
||||
* Purpose: designate default value for empty variables
|
||||
*
|
||||
* @link http://www.smarty.net/manual/en/language.modifier.default.php default (Smarty online manual)
|
||||
* @author Uwe Tews
|
||||
*
|
||||
* @param array $params parameters
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_default($params)
|
||||
{
|
||||
$output = $params[0];
|
||||
if (!isset($params[1])) {
|
||||
$params[1] = "''";
|
||||
}
|
||||
|
||||
array_shift($params);
|
||||
foreach ($params as $param) {
|
||||
$output = '(($tmp = @' . $output . ')===null||$tmp===\'\' ? ' . $param . ' : $tmp)';
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage PluginsModifierCompiler
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
require_once(SMARTY_PLUGINS_DIR . 'shared.literal_compiler_param.php');
|
||||
|
||||
/**
|
||||
* Smarty escape modifier plugin
|
||||
* Type: modifier<br>
|
||||
* Name: escape<br>
|
||||
* Purpose: escape string for output
|
||||
*
|
||||
* @link http://www.smarty.net/docsv2/en/language.modifier.escape count_characters (Smarty online manual)
|
||||
* @author Rodney Rehm
|
||||
*
|
||||
* @param array $params parameters
|
||||
* @param $compiler
|
||||
*
|
||||
* @return string with compiled code
|
||||
*/
|
||||
function smarty_modifiercompiler_escape($params, $compiler)
|
||||
{
|
||||
static $_double_encode = null;
|
||||
if ($_double_encode === null) {
|
||||
$_double_encode = version_compare(PHP_VERSION, '5.2.3', '>=');
|
||||
}
|
||||
|
||||
try {
|
||||
$esc_type = smarty_literal_compiler_param($params, 1, 'html');
|
||||
$char_set = smarty_literal_compiler_param($params, 2, Smarty::$_CHARSET);
|
||||
$double_encode = smarty_literal_compiler_param($params, 3, true);
|
||||
|
||||
if (!$char_set) {
|
||||
$char_set = Smarty::$_CHARSET;
|
||||
}
|
||||
|
||||
switch ($esc_type) {
|
||||
case 'html':
|
||||
if ($_double_encode) {
|
||||
return 'htmlspecialchars('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
return 'htmlspecialchars('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
|
||||
case 'htmlall':
|
||||
if (Smarty::$_MBSTRING) {
|
||||
if ($_double_encode) {
|
||||
// php >=5.2.3 - go native
|
||||
return 'mb_convert_encoding(htmlspecialchars('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true)
|
||||
. '), "HTML-ENTITIES", '
|
||||
. var_export($char_set, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return 'mb_convert_encoding(htmlspecialchars('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true)
|
||||
. '), "HTML-ENTITIES", '
|
||||
. var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
}
|
||||
|
||||
// no MBString fallback
|
||||
if ($_double_encode) {
|
||||
// php >=5.2.3 - go native
|
||||
return 'htmlentities('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ', '
|
||||
. var_export($double_encode, true) . ')';
|
||||
} elseif ($double_encode) {
|
||||
// php <5.2.3 - only handle double encoding
|
||||
return 'htmlentities('
|
||||
. $params[0] . ', ENT_QUOTES, '
|
||||
. var_export($char_set, true) . ')';
|
||||
} else {
|
||||
// fall back to modifier.escape.php
|
||||
}
|
||||
|
||||
case 'url':
|
||||
return 'rawurlencode(' . $params[0] . ')';
|
||||
|
||||
case 'urlpathinfo':
|
||||
return 'str_replace("%2F", "/", rawurlencode(' . $params[0] . '))';
|
||||
|
||||
case 'quotes':
|
||||
// escape unescaped single quotes
|
||||
return 'preg_replace("%(?<!\\\\\\\\)\'%", "\\\'",' . $params[0] . ')';
|
||||
|
||||
case 'javascript':
|
||||
// escape quotes and backslashes, newlines, etc.
|
||||
return 'strtr(' . $params[0] . ', array("\\\\" => "\\\\\\\\", "\'" => "\\\\\'", "\"" => "\\\\\"", "\\r" => "\\\\r", "\\n" => "\\\n", "</" => "<\/" ))';
|
||||
}
|
||||
}
|
||||
catch (SmartyException $e) {
|
||||
// pass through to regular plugin fallback
|
||||
}
|
||||
|
||||
// could not optimize |escape call, so fallback to regular plugin
|
||||
if ($compiler->template->caching && ($compiler->tag_nocache | $compiler->nocache)) {
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->template->required_plugins['nocache']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
} else {
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['file'] = SMARTY_PLUGINS_DIR . 'modifier.escape.php';
|
||||
$compiler->template->required_plugins['compiled']['escape']['modifier']['function'] = 'smarty_modifier_escape';
|
||||
}
|
||||
|
||||
return 'smarty_modifier_escape(' . join(', ', $params) . ')';
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user