Update from PSR-2 to PSR-12

- Tabs are indent
- Warning at 120, Error at 240 char length
This commit is contained in:
Clemens Schwaighofer
2021-07-14 10:00:56 +09:00
parent 11daac6d23
commit 6722468bdb
96 changed files with 2855 additions and 1677 deletions

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2000/06/01
@@ -32,16 +33,22 @@
*
* HISTORY:
* 2010/12/21 (cs) merge back password change interface
* 2010/12/17 (cs) change that password can be blowfish encrypted, auto detects if other encryption is used (md5, std des) and tries to use them
* 2010/12/17 (cs) change that password can be blowfish encrypted,
* auto detects if other encryption is used (md5, std des)
* and tries to use them
* 2007/05/29 (cs) BUG with assign query and visible sub arrays to pages
* 2005/09/21 (cs) if error -> unset the session vars
* 2005/07/04 (cs) add a function to write into the edit log file
* 2005/07/01 (cs) start adepting login class to new edit interface layout
* 2005/03/31 (cs) fixed the class call with all debug vars
* 2004/11/17 (cs) unused var cleanup
* 2004/11/16 (cs) rewrite login so it uses a template and not just plain html. prepare it, so it will be able to use external stuff later (some interface has to be designed for that
* 2004/11/16 (cs) removed the mobile html part from login * 2004/09/30 (cs) layout fix
* 2003-11-11: if user has debug 1 unset memlimit, because there can be serious problems with the query logging
* 2004/11/16 (cs) rewrite login so it uses a template and not just plain html.
* prepare it, so it will be able to use external stuff later
* (some interface has to be designed for that
* 2004/11/16 (cs) removed the mobile html part from login
* 2004/09/30 (cs) layout fix
* 2003-11-11: if user has debug 1 unset memlimit, because there can be serious
* problems with the query logging
* 2003-06-12: added flag to PAGES array
* changed the get vars from GLOBALS to _POST
* changed the session registration. no more GLOBAL vars are registered
@@ -57,6 +64,8 @@
* 2000-06-01: created basic idea and functions
*********************************************************************/
declare(strict_types=1);
namespace CoreLibs\ACL;
use CoreLibs\Check\Password;
@@ -64,16 +73,19 @@ use CoreLibs\Check\Password;
class Login extends \CoreLibs\DB\IO
{
private $euid; // the user id var
private $permission_okay = false; // is set to one if login okay, or EUID is set and user is okay to access this page
// is set to one if login okay, or EUID is set and user is okay to access this page
private $permission_okay = false;
public $login; // pressed login
private $action; // master action command
private $username; // login name
private $password; // login password
private $logout; // logout button
private $login_error = 0; // login error code, can be matched to the array login_error_msg, which holds the string
// login error code, can be matched to the array login_error_msg, which holds the string
private $login_error = 0;
private $password_change = false; // if this is set to true, the user can change passwords
private $password_change_ok = false; // password change was successful
private $password_forgot = false; // can we reset password and mail to user with new password set screen
// can we reset password and mail to user with new password set screen
private $password_forgot = false;
private $password_forgot_ok = false; // password forgot mail send ok
private $change_password;
private $pw_username;
@@ -161,7 +173,9 @@ class Login extends \CoreLibs\DB\IO
$this->l = new \CoreLibs\Language\L10n($lang);
// if we have a search path we need to set it, to use the correct DB to login
// check what schema to use. if there is a login schema use this, else check if there is a schema set in the config, or fall back to DB_SCHEMA if this exists, if this also does not exists use public schema
// check what schema to use. if there is a login schema use this, else check
// if there is a schema set in the config, or fall back to DB_SCHEMA
// if this exists, if this also does not exists use public schema
if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) {
$SCHEMA = LOGIN_DB_SCHEMA;
} elseif (isset($db_config['db_schema']) && $db_config['db_schema']) {
@@ -173,9 +187,10 @@ class Login extends \CoreLibs\DB\IO
}
// set schema if schema differs to schema set in db conneciton
if ($this->dbGetSchema() && $this->dbGetSchema() != $SCHEMA) {
$this->dbExec("SET search_path TO ".$SCHEMA);
$this->dbExec("SET search_path TO " . $SCHEMA);
}
$this->euid = array_key_exists('EUID', $_SESSION) ? $_SESSION['EUID'] : 0; // if there is none, there is none, saves me POST/GET check
// if there is none, there is none, saves me POST/GET check
$this->euid = array_key_exists('EUID', $_SESSION) ? $_SESSION['EUID'] : 0;
// get login vars, are so, can't be changed
// prepare
// pass on vars to Object vars
@@ -303,21 +318,24 @@ class Login extends \CoreLibs\DB\IO
$password = $this->password;
}
// first, errors on missing encryption
if ((preg_match("/^\\$2(a|y)\\$/", $hash) && CRYPT_BLOWFISH != 1) ||
if (
(preg_match("/^\\$2(a|y)\\$/", $hash) && CRYPT_BLOWFISH != 1) ||
(preg_match("/^\\$1\\$/", $hash) && CRYPT_MD5 != 1) ||
(preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash) && CRYPT_STD_DES != 1)
) {
// this means password cannot be decrypted because of missing crypt methods
$this->login_error = 9999;
$password_ok = false;
} elseif (preg_match("/^\\$2y\\$/", $hash) &&
} elseif (
preg_match("/^\\$2y\\$/", $hash) &&
!Password::passwordVerify($password, $hash)
) {
// this is the new password hash methid, is only $2y$
// all others are not valid anymore
$this->login_error = 1013;
$password_ok = false;
} elseif (!preg_match("/^\\$2(a|y)\\$/", $hash) &&
} elseif (
!preg_match("/^\\$2(a|y)\\$/", $hash) &&
!preg_match("/^\\$1\\$/", $hash) &&
!preg_match("/^\\$[0-9A-Za-z.]{12}$/", $hash) &&
$hash != $password
@@ -344,30 +362,37 @@ class Login extends \CoreLibs\DB\IO
$this->login_error = 102;
} else {
// we have to get the themes in here too
$q = "SELECT eu.edit_user_id, username, password, eu.edit_group_id, eg.name AS edit_group_name, admin, ";
$q .= "eu.login_error_count, eu.login_error_date_last, eu.login_error_date_first, eu.strict, eu.locked, ";
$q .= "debug, db_debug, ";
$q .= "eareu.level AS user_level, eareu.type AS user_type, ";
$q .= "eareg.level AS group_level, eareg.type AS group_type, ";
$q .= "eu.enabled, el.short_name AS lang_short, el.iso_name AS lang_iso, first.header_color AS first_header_color, ";
$q .= "second.header_color AS second_header_color, second.template ";
$q .= "FROM edit_user eu ";
$q .= "LEFT JOIN edit_scheme second ON (second.edit_scheme_id = eu.edit_scheme_id AND second.enabled = 1), ";
$q .= "edit_language el, edit_group eg, ";
$q .= "edit_access_right eareu, ";
$q .= "edit_access_right eareg, ";
$q .= "edit_scheme first ";
$q .= "WHERE first.edit_scheme_id = eg.edit_scheme_id AND eu.edit_group_id = eg.edit_group_id AND eu.edit_language_id = el.edit_language_id AND ";
$q .= "eu.edit_access_right_id = eareu.edit_access_right_id AND ";
$q .= "eg.edit_access_right_id = eareg.edit_access_right_id AND ";
// password match is done in script, against old plain or new blowfish encypted
$q .= "(LOWER(username) = '".$this->dbEscapeString(strtolower($this->username))."') ";
$q = "SELECT eu.edit_user_id, username, password, eu.edit_group_id, "
. "eg.name AS edit_group_name, admin, "
. "eu.login_error_count, eu.login_error_date_last, "
. "eu.login_error_date_first, eu.strict, eu.locked, "
. "debug, db_debug, "
. "eareu.level AS user_level, eareu.type AS user_type, "
. "eareg.level AS group_level, eareg.type AS group_type, "
. "eu.enabled, el.short_name AS lang_short, el.iso_name AS lang_iso, "
. "firstheader_color AS first_header_color, "
. "second.header_color AS second_header_color, second.template "
. "FROM edit_user eu "
. "LEFT JOIN edit_scheme second ON "
. "(second.edit_scheme_id = eu.edit_scheme_id AND second.enabled = 1), "
. "edit_language el, edit_group eg, "
. "edit_access_right eareu, "
. "edit_access_right eareg, "
. "edit_scheme first "
. "WHERE first.edit_scheme_id = eg.edit_scheme_id "
. "AND eu.edit_group_id = egedit_group_id "
. "AND eu.edit_language_id = el.edit_language_id AND "
. "eu.edit_access_right_id = eareu.edit_access_right_id AND "
. "eg.edit_access_right_id = eareg.edit_access_right_id AND "
// password match is done in script, against old plain or new blowfish encypted
. "(LOWER(username) = '" . $this->dbEscapeString(strtolower($this->username)) . "') ";
$res = $this->dbReturn($q);
// username is wrong, but we throw for wrong username and wrong password the same error
if (!$this->cursor_ext[md5($q)]['num_rows']) {
$this->login_error = 1010;
} else {
// if login errors is half of max errors and the last login error was less than 10s ago, forbid any new login try
// if login errors is half of max errors and the last login error
// was less than 10s ago, forbid any new login try
// check flow
// - user is enabled
@@ -386,10 +411,14 @@ class Login extends \CoreLibs\DB\IO
// none to be set, set in login password check
} else {
// check if the current password is an invalid hash and do a rehash and set password
// $this->debug('LOGIN', 'Hash: '.$res['password'].' -> VERIFY: '.($Password::passwordVerify($this->password, $res['password']) ? 'OK' : 'FAIL').' => HASH: '.(Password::passwordRehashCheck($res['password']) ? 'NEW NEEDED' : 'OK'));
// $this->debug('LOGIN', 'Hash: '.$res['password'].' -> VERIFY: '
// .($Password::passwordVerify($this->password, $res['password']) ? 'OK' : 'FAIL')
// .' => HASH: '.(Password::passwordRehashCheck($res['password']) ? 'NEW NEEDED' : 'OK'));
if (Password::passwordRehashCheck($res['password'])) {
// update password hash to new one now
$q = "UPDATE edit_user SET password = '".$this->dbEscapeString(Password::passwordSet($this->password))."' WHERE edit_user_id = ".$res['edit_user_id'];
$q = "UPDATE edit_user "
. "SET password = '" . $this->dbEscapeString(Password::passwordSet($this->password))
. "' WHERE edit_user_id = " . $res['edit_user_id'];
$this->dbExec($q);
}
// normal user processing
@@ -410,31 +439,36 @@ class Login extends \CoreLibs\DB\IO
$_SESSION['GROUP_ACL_TYPE'] = $res['group_type'];
// deprecated TEMPLATE setting
$_SESSION['TEMPLATE'] = $res['template'] ? $res['template'] : '';
$_SESSION['HEADER_COLOR'] = $res['second_header_color'] ? $res['second_header_color'] : $res['first_header_color'];
$_SESSION['HEADER_COLOR'] = $res['second_header_color'] ?
$res['second_header_color'] :
$res['first_header_color'];
$_SESSION['LANG'] = $res['lang_short'];
$_SESSION['DEFAULT_CHARSET'] = $res['lang_iso'];
$_SESSION['DEFAULT_LANG'] = $res['lang_short'].'_'.strtolower(str_replace('-', '', $res['lang_iso']));
$_SESSION['DEFAULT_LANG'] = $res['lang_short'] . '_'
. strtolower(str_replace('-', '', $res['lang_iso']));
// reset any login error count for this user
if ($res['login_error_count'] > 0) {
$q = "UPDATE edit_user ";
$q .= "SET login_error_count = 0, login_error_date_last = NULL, login_error_date_first = NULL ";
$q .= "WHERE edit_user_id = ".$res['edit_user_id'];
$q = "UPDATE edit_user "
. "SET login_error_count = 0, login_error_date_last = NULL, "
. "login_error_date_first = NULL "
. "WHERE edit_user_id = " . $res['edit_user_id'];
$this->dbExec($q);
}
$edit_page_ids = [];
$pages = [];
$pages_acl = [];
// set pages access
$q = "SELECT ep.edit_page_id, ep.cuid, epca.cuid AS content_alias_uid, ";
$q .= "ep.hostname, ep.filename, ep.name AS edit_page_name, ";
$q .= "ep.order_number AS edit_page_order, ep.menu, ";
$q .= "ep.popup, ep.popup_x, ep.popup_y, ep.online, ear.level, ear.type ";
$q .= "FROM edit_page ep ";
$q .= "LEFT JOIN edit_page epca ON (epca.edit_page_id = ep.content_alias_edit_page_id)";
$q .= ", edit_page_access epa, edit_access_right ear ";
$q .= "WHERE ep.edit_page_id = epa.edit_page_id AND ear.edit_access_right_id = epa.edit_access_right_id ";
$q .= "AND epa.enabled = 1 AND epa.edit_group_id = ".$res["edit_group_id"]." ";
$q .= "ORDER BY ep.order_number";
$q = "SELECT ep.edit_page_id, ep.cuid, epca.cuid AS content_alias_uid, "
. "ep.hostname, ep.filename, ep.name AS edit_page_name, "
. "ep.order_number AS edit_page_order, ep.menu, "
. "ep.popup, ep.popup_x, ep.popup_y, ep.online, ear.level, ear.type "
. "FROM edit_page ep "
. "LEFT JOIN edit_page epca ON (epca.edit_page_id = ep.content_alias_edit_page_id)"
. ", edit_page_access epa, edit_access_right ear "
. "WHERE ep.edit_page_id = epa.edit_page_id "
. "AND ear.edit_access_right_id = epa.edit_access_right_id "
. "AND epa.enabled = 1 AND epa.edit_group_id = " . $res["edit_group_id"] . " "
. "ORDER BY ep.order_number";
while ($res = $this->dbReturn($q)) {
// page id array for sub data readout
$edit_page_ids[$res['edit_page_id']] = $res['cuid'];
@@ -442,7 +476,8 @@ class Login extends \CoreLibs\DB\IO
$pages[$res['cuid']] = [
'edit_page_id' => $res['edit_page_id'],
'cuid' => $res['cuid'],
'content_alias_uid' => $res['content_alias_uid'], // for reference of content data on a differen page
// for reference of content data on a differen page
'content_alias_uid' => $res['content_alias_uid'],
'hostname' => $res['hostname'],
'filename' => $res['filename'],
'page_name' => $res['edit_page_name'],
@@ -462,18 +497,20 @@ class Login extends \CoreLibs\DB\IO
} // for each page
// get the visible groups for all pages and write them to the pages
$_edit_page_id = 0;
$q = "SELECT epvg.edit_page_id, name, flag ";
$q .= "FROM edit_visible_group evp, edit_page_visible_group epvg ";
$q .= "WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id AND epvg.edit_page_id IN (".join(', ', array_keys($edit_page_ids)).") ";
$q .= "ORDER BY epvg.edit_page_id";
$q = "SELECT epvg.edit_page_id, name, flag "
. "FROM edit_visible_group evp, edit_page_visible_group epvg "
. "WHERE evp.edit_visible_group_id = epvg.edit_visible_group_id "
. "AND epvg.edit_page_id IN (" . join(', ', array_keys($edit_page_ids)) . ") "
. "ORDER BY epvg.edit_page_id";
while ($res = $this->dbReturn($q)) {
$pages[$edit_page_ids[$res['edit_page_id']]]['visible'][$res['name']] = $res['flag'];
}
// get the same for the query strings
$_edit_page_id = 0;
$q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs ";
$q .= "WHERE enabled = 1 AND edit_page_id IN (".join(', ', array_keys($edit_page_ids)).") ";
$q .= "ORDER BY eqs.edit_page_id";
$q = "SELECT eqs.edit_page_id, name, value, dynamic FROM edit_query_string eqs "
. "WHERE enabled = 1 AND edit_page_id "
. "IN (" . join(', ', array_keys($edit_page_ids)) . ") "
. "ORDER BY eqs.edit_page_id";
while ($res = $this->dbReturn($q)) {
$pages[$edit_page_ids[$res['edit_page_id']]]['query'][] = [
'name' => $res['name'],
@@ -483,11 +520,12 @@ class Login extends \CoreLibs\DB\IO
}
// get the page content and add them to the page
$_edit_page_id = 0;
$q = "SELECT epc.edit_page_id, epc.name, epc.uid, epc.order_number, epc.online, ear.level, ear.type ";
$q .= "FROM edit_page_content epc, edit_access_right ear ";
$q .= "WHERE epc.edit_access_right_id = ear.edit_access_right_id AND ";
$q .= "epc.edit_page_id IN (".join(', ', array_keys($edit_page_ids)).") ";
$q .= "ORDER BY epc.order_number";
$q = "SELECT epc.edit_page_id, epc.name, epc.uid, epc.order_number, "
. "epc.online, ear.level, ear.type "
. "FROM edit_page_content epc, edit_access_right ear "
. "WHERE epc.edit_access_right_id = ear.edit_access_right_id AND "
. "epc.edit_page_id IN (" . join(', ', array_keys($edit_page_ids)) . ") "
. "ORDER BY epc.order_number";
while ($res = $this->dbReturn($q)) {
$pages[$edit_page_ids[$res['edit_page_id']]]['content'][$res['uid']] = [
'name' => $res['name'],
@@ -503,17 +541,20 @@ class Login extends \CoreLibs\DB\IO
$_SESSION['PAGES'] = $pages;
$_SESSION['PAGES_ACL_LEVEL'] = $pages_acl;
// load the edit_access user rights
$q = "SELECT ea.edit_access_id, level, type, ea.name, ea.color, ea.uid, edit_default ";
$q .= "FROM edit_access_user eau, edit_access_right ear, edit_access ea ";
$q .= "WHERE eau.edit_access_id = ea.edit_access_id AND eau.edit_access_right_id = ear.edit_access_right_id ";
$q .= "AND eau.enabled = 1 AND edit_user_id = ".$this->euid." ";
$q .= "ORDER BY ea.name";
$q = "SELECT ea.edit_access_id, level, type, ea.name, ea.color, ea.uid, edit_default "
. "FROM edit_access_user eau, edit_access_right ear, edit_access ea "
. "WHERE eau.edit_access_id = ea.edit_access_id "
. "AND eau.edit_access_right_id = ear.edit_access_right_id "
. "AND eau.enabled = 1 AND edit_user_id = " . $this->euid . " "
. "ORDER BY ea.name";
$unit_access = [];
$eauid = [];
$unit_acl = [];
while ($res = $this->dbReturn($q)) {
// read edit access data fields and drop them into the unit access array
$q_sub ="SELECT name, value FROM edit_access_data WHERE enabled = 1 AND edit_access_id = ".$res['edit_access_id'];
$q_sub = "SELECT name, value "
. "FROM edit_access_data "
. "WHERE enabled = 1 AND edit_access_id = " . $res['edit_access_id'];
$ea_data = [];
while ($res_sub = $this->dbReturn($q_sub)) {
$ea_data[$res_sub['name']] = $res_sub['value'];
@@ -548,19 +589,21 @@ class Login extends \CoreLibs\DB\IO
$login_error_date_first = ", login_error_date_first = NOW()";
}
// update login error count for this user
$q = "UPDATE edit_user ";
$q .= "SET login_error_count = login_error_count + 1, login_error_date_last = NOW() ".$login_error_date_first." ";
$q .= "WHERE edit_user_id = ".$res['edit_user_id'];
$q = "UPDATE edit_user "
. "SET login_error_count = login_error_count + 1, "
. "login_error_date_last = NOW() " . $login_error_date_first . " "
. "WHERE edit_user_id = " . $res['edit_user_id'];
$this->dbExec($q);
// totally lock the user if error max is reached
if ($this->max_login_error_count != -1 &&
if (
$this->max_login_error_count != -1 &&
$res['login_error_count'] + 1 > $this->max_login_error_count
) {
// do some alert reporting in case this error is too big
// if strict is set, lock this user
// this needs manual unlocking by an admin user
if ($res['strict'] && !in_array($this->username, $this->lock_deny_users)) {
$q = "UPDATE edit_user SET locked = 1 WHERE edit_user_id = ".$res['edit_user_id'];
$q = "UPDATE edit_user SET locked = 1 WHERE edit_user_id = " . $res['edit_user_id'];
}
}
}
@@ -581,14 +624,23 @@ class Login extends \CoreLibs\DB\IO
public function loginCheckPermissions(): bool
{
if ($this->euid && $this->login_error != 103) {
$q = "SELECT filename ";
$q .= "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu ";
$q .= "WHERE ep.edit_page_id = epa.edit_page_id AND eg.edit_group_id = epa.edit_group_id AND eg.edit_group_id = eu.edit_group_id ";
$q .= "AND eu.edit_user_id = ".$this->euid." AND filename = '".$this->page_name."' AND eg.enabled = 1 AND epa.enabled = 1";
$q = "SELECT filename "
. "FROM edit_page ep, edit_page_access epa, edit_group eg, edit_user eu "
. "WHERE ep.edit_page_id = epa.edit_page_id "
. "AND eg.edit_group_id = epa.edit_group_id "
. "AND eg.edit_group_id = eu.edit_group_id "
. "AND eu.edit_user_id = " . $this->euid . " "
. "AND filename = '" . $this->page_name . "' "
. "AND eg.enabled = 1 AND epa.enabled = 1";
$res = $this->dbReturnRow($q);
// unset mem limit if debug is set to 1
// if (($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] || $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) && ini_get('memory_limit') != -1)
// ini_set('memory_limit', -1);
// if (
// ($GLOBALS["DEBUG_ALL"] || $GLOBALS["DB_DEBUG"] ||
// $_SESSION["DEBUG_ALL"] || $_SESSION["DB_DEBUG"]) &&
// ini_get('memory_limit') != -1
// ) {
// ini_set('memory_limit', '-1');
// }
if (isset($res['filename']) && $res['filename'] == $this->page_name) {
$this->permission_okay = true;
} else {
@@ -687,7 +739,10 @@ class Login extends \CoreLibs\DB\IO
if ($_SESSION['GROUP_ACL_LEVEL'] != -1) {
$this->acl['page'] = $_SESSION['GROUP_ACL_LEVEL'];
}
if (isset($_SESSION['PAGES_ACL_LEVEL'][$this->page_name]) && $_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1) {
if (
isset($_SESSION['PAGES_ACL_LEVEL'][$this->page_name]) &&
$_SESSION['PAGES_ACL_LEVEL'][$this->page_name] != -1
) {
$this->acl['page'] = $_SESSION['PAGES_ACL_LEVEL'][$this->page_name];
}
@@ -820,7 +875,10 @@ class Login extends \CoreLibs\DB\IO
}
// check user exist, if not -> error
if (!$this->login_error) {
$q = "SELECT edit_user_id FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."'";
$q = "SELECT edit_user_id "
. "FROM edit_user "
. "WHERE enabled = 1 "
. "AND username = '" . $this->dbEscapeString($this->pw_username) . "'";
list ($edit_user_id) = $this->dbReturnRow($q);
if (!$edit_user_id) {
// username wrong
@@ -830,7 +888,10 @@ class Login extends \CoreLibs\DB\IO
}
// check old passwords match -> error
if (!$this->login_error) {
$q = "SELECT edit_user_id, password FROM edit_user WHERE enabled = 1 AND username = '".$this->dbEscapeString($this->pw_username)."'";
$q = "SELECT edit_user_id, password "
. "FROM edit_user "
. "WHERE enabled = 1 "
. "AND username = '" . $this->dbEscapeString($this->pw_username) . "'";
list ($edit_user_id, $old_password_hash) = $this->dbReturnRow($q);
if (!$edit_user_id || !$this->loginPasswordCheck($old_password_hash, $this->pw_old_password)) {
// old password wrong
@@ -862,15 +923,18 @@ class Login extends \CoreLibs\DB\IO
// no error change this users password
if (!$this->login_error && $edit_user_id) {
// update the user (edit_user_id) with the new password
$q = "UPDATE edit_user SET password = '".$this->dbEscapeString(Password::passwordSet($this->pw_new_password))."' WHERE edit_user_id = ".$edit_user_id;
$q = "UPDATE edit_user "
. "SET password = "
. "'" . $this->dbEscapeString(Password::passwordSet($this->pw_new_password)) . "' "
. "WHERE edit_user_id = " . $edit_user_id;
$this->dbExec($q);
$data = 'Password change for user "'.$this->pw_username.'"';
$data = 'Password change for user "' . $this->pw_username . '"';
$this->password_change_ok = true;
}
} else {
// illegal user error
$this->login_error = 220;
$data = 'Illegal user for password change: '.$this->pw_username;
$data = 'Illegal user for password change: ' . $this->pw_username;
}
// log this password change attempt
$this->writeLog($event, $data, $this->login_error, $this->pw_username);
@@ -903,43 +967,76 @@ class Login extends \CoreLibs\DB\IO
// pre change the data in the PASSWORD_CHANGE_DIV first
foreach ($this->login_template['strings'] as $string => $data) {
if ($data) {
$html_string_password_change = str_replace('{'.$string.'}', $data, $html_string_password_change);
$html_string_password_change = str_replace(
'{' . $string . '}',
$data,
$html_string_password_change
);
}
}
// print error messagae
if ($this->login_error) {
$html_string_password_change = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string_password_change);
$html_string_password_change = str_replace(
'{ERROR_MSG}',
$this->login_error_msg[$this->login_error] . '<br>',
$html_string_password_change
);
} else {
$html_string_password_change = str_replace('{ERROR_MSG}', '<br>', $html_string_password_change);
$html_string_password_change = str_replace(
'{ERROR_MSG}',
'<br>',
$html_string_password_change
);
}
// if pw change action, show the float again
if ($this->change_password && !$this->password_change_ok) {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '<script language="JavaScript">ShowHideDiv(\'pw_change_div\');</script>', $html_string_password_change);
$html_string_password_change = str_replace(
'{PASSWORD_CHANGE_SHOW}',
'<script language="JavaScript">'
. 'ShowHideDiv(\'pw_change_div\');</script>',
$html_string_password_change
);
} else {
$html_string_password_change = str_replace('{PASSWORD_CHANGE_SHOW}', '', $html_string_password_change);
$html_string_password_change = str_replace(
'{PASSWORD_CHANGE_SHOW}',
'',
$html_string_password_change
);
}
$this->login_template['strings']['PASSWORD_CHANGE_DIV'] = $html_string_password_change;
}
// put in the logout redirect string
if ($this->logout && $LOGOUT_TARGET) {
$html_string = str_replace('{LOGOUT_TARGET}', '<meta http-equiv="refresh" content="0; URL='.$LOGOUT_TARGET.'">', $html_string);
$html_string = str_replace(
'{LOGOUT_TARGET}',
'<meta http-equiv="refresh" content="0; URL=' . $LOGOUT_TARGET . '">',
$html_string
);
} else {
$html_string = str_replace('{LOGOUT_TARGET}', '', $html_string);
}
// print error messagae
if ($this->login_error) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[$this->login_error].'<br>', $html_string);
$html_string = str_replace(
'{ERROR_MSG}',
$this->login_error_msg[$this->login_error] . '<br>',
$html_string
);
} elseif ($this->password_change_ok && $this->password_change) {
$html_string = str_replace('{ERROR_MSG}', $this->login_error_msg[300].'<br>', $html_string);
$html_string = str_replace(
'{ERROR_MSG}',
$this->login_error_msg[300] . '<br>',
$html_string
);
} else {
$html_string = str_replace('{ERROR_MSG}', '<br>', $html_string);
}
// create the replace array context
foreach ($this->login_template['strings'] as $string => $data) {
$html_string = str_replace('{'.$string.'}', $data, $html_string);
$html_string = str_replace('{' . $string . '}', $data, $html_string);
}
} // if permission is 0 then print out login
// return the created HTML here or null for nothing
@@ -968,7 +1065,7 @@ class Login extends \CoreLibs\DB\IO
// prepare for log
if ($this->euid) {
// get user from user table
$q = "SELECT username FROM edit_user WHERE edit_user_id = ".$this->euid;
$q = "SELECT username FROM edit_user WHERE edit_user_id = " . $this->euid;
list($username) = $this->dbReturnRow($q);
} // if euid is set, get username (or try)
$this->writeLog($event, '', $this->login_error, $username);
@@ -1000,24 +1097,33 @@ class Login extends \CoreLibs\DB\IO
];
$error_msgs = [
'100' => $this->l->__('Fatal Error: <b>[EUID] came in as GET/POST!</b>'), // actually obsolete
'1010' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'), // user not found
'1011' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'), // blowfish password wrong
'1012' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'), // fallback md5 password wrong
'1013' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'), // new password_hash wrong
// actually obsolete
'100' => $this->l->__('Fatal Error: <b>[EUID] came in as GET/POST!</b>'),
// user not found
'1010' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'),
// blowfish password wrong
'1011' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'),
// fallback md5 password wrong
'1012' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'),
// new password_hash wrong
'1013' => $this->l->__('Fatal Error: <b>Login Failed - Wrong Username or Password</b>'),
'102' => $this->l->__('Fatal Error: <b>Login Failed - Please enter username and password</b>'),
'103' => $this->l->__('Fatal Error: <b>You do not have the rights to access this Page</b>'),
'104' => $this->l->__('Fatal Error: <b>Login Failed - User not enabled</b>'),
'105' => $this->l->__('Fatal Error: <b>Login Failed - User is locked</b>'),
'220' => $this->l->__('Fatal Error: <b>Password change - The user could not be found</b>'), // actually this is an illegal user, but I mask it
// actually this is an illegal user, but I mask it
'220' => $this->l->__('Fatal Error: <b>Password change - The user could not be found</b>'),
'200' => $this->l->__('Fatal Error: <b>Password change - Please enter username and old password</b>'),
'201' => $this->l->__('Fatal Error: <b>Password change - The user could not be found</b>'),
'202' => $this->l->__('Fatal Error: <b>Password change - The old password is not correct</b>'),
'203' => $this->l->__('Fatal Error: <b>Password change - Please fill out both new password fields</b>'),
'204' => $this->l->__('Fatal Error: <b>Password change - The new passwords do not match</b>'),
'205' => $this->l->__('Fatal Error: <b>Password change - The new password is not in a valid format</b>'), // we should also not here WHAT is valid
'300' => $this->l->__('Success: <b>Password change successful</b>'), // for OK password change
'9999' => $this->l->__('Fatal Error: <b>necessary crypt engine could not be found</b>. Login is impossible') // this is bad bad error
// we should also not here WHAT is valid
'205' => $this->l->__('Fatal Error: <b>Password change - The new password is not in a valid format</b>'),
// for OK password change
'300' => $this->l->__('Success: <b>Password change successful</b>'),
// this is bad bad error
'9999' => $this->l->__('Fatal Error: <b>necessary crypt engine could not be found</b>. Login is impossible')
];
// if password change is okay
@@ -1028,23 +1134,36 @@ class Login extends \CoreLibs\DB\IO
'NEW_PASSWORD' => $this->l->__('New Password'),
'NEW_PASSWORD_CONFIRM' => $this->l->__('New Password confirm'),
'CLOSE' => $this->l->__('Close'),
'JS_SHOW_HIDE' => "function ShowHideDiv(id) { element = document.getElementById(id); if (element.className == 'visible' || !element.className) element.className = 'hidden'; else element.className = 'visible'; }",
'PASSWORD_CHANGE_BUTTON' => '<input type="button" name="pw_change" value="'.$strings['PASSWORD_CHANGE_BUTTON_VALUE'].'" OnClick="ShowHideDiv(\'pw_change_div\');">'
'JS_SHOW_HIDE' => "function ShowHideDiv(id) { "
. "element = document.getElementById(id); "
. "if (element.className == 'visible' || !element.className) element.className = 'hidden'; "
. "else element.className = 'visible'; }",
'PASSWORD_CHANGE_BUTTON' => '<input type="button" name="pw_change" value="'
. $strings['PASSWORD_CHANGE_BUTTON_VALUE']
. '" OnClick="ShowHideDiv(\'pw_change_div\');">'
]);
// NOTE: for the HTML block I ignore line lengths
// phpcs:disable
$this->login_template['password_change'] = <<<EOM
<div id="pw_change_div" class="hidden" style="position: absolute; top: 30px; left: 50px; width: 400px; height: 220px; background-color: white; border: 1px solid black; padding: 25px;">
<table>
<tr><td class="norm" align="center" colspan="2"><h3>{TITLE_PASSWORD_CHANGE}</h3></td></tr>
<tr><td class="norm" colspan="2">{ERROR_MSG}</td></tr>
<tr><td class="norm" align="right">{USERNAME}</td><td><input type="text" name="pw_username" value=""></td></tr>
<tr><td class="norm" align="right">{OLD_PASSWORD}</td><td><input type="password" name="pw_old_password" value=""></td></tr>
<tr><td class="norm" align="right">{NEW_PASSWORD}</td><td><input type="password" name="pw_new_password" value=""></td></tr>
<tr><td class="norm" align="right">{NEW_PASSWORD_CONFIRM}</td><td><input type="password" name="pw_new_password_confirm" value=""></td></tr>
<tr><td></td><td><input type="submit" name="change_password" value="{PASSWORD_CHANGE_BUTTON_VALUE}"><input type="button" name="pw_change" value="{CLOSE}" OnClick="ShowHideDiv('pw_change_div');"></td></tr>
<tr><td class="norm" align="right">{OLD_PASSWORD}</td>
<td><input type="password" name="pw_old_password" value=""></td></tr>
<tr><td class="norm" align="right">{NEW_PASSWORD}</td>
<td><input type="password" name="pw_new_password" value=""></td></tr>
<tr><td class="norm" align="right">{NEW_PASSWORD_CONFIRM}</td>
<td><input type="password" name="pw_new_password_confirm" value=""></td></tr>
<tr><td></td>
<td><input type="submit" name="change_password" value="{PASSWORD_CHANGE_BUTTON_VALUE}">
<input type="button" name="pw_change" value="{CLOSE}" OnClick="ShowHideDiv('pw_change_div');"></td></tr>
</table>
</div>
{PASSWORD_CHANGE_SHOW}
EOM;
// phpcs:enable
}
if ($this->password_forgot) {
}
@@ -1163,28 +1282,38 @@ EOM;
];
$data_binary = $this->dbEscapeBytea(bzcompress(serialize($_data_binary)));
// SQL querie for log entry
$q = "INSERT INTO edit_log ";
$q .= "(username, password, euid, event_date, event, error, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ('".$this->dbEscapeString($username)."', 'PASSWORD', ".($this->euid ? $this->euid : 'NULL').", ";
$q .= "NOW(), '".$this->dbEscapeString($event)."', '".$this->dbEscapeString((string)$error)."', '".$this->dbEscapeString($data)."', '".$data_binary."', '".$this->page_name."', ";
foreach ([
'REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME', 'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT', 'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING'
] as $server_code) {
$q = "INSERT INTO edit_log "
. "(username, password, euid, event_date, event, error, data, data_binary, page, "
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
. "http_accept, http_accept_charset, http_accept_encoding, session_id, "
. "action, action_id, action_yes, action_flag, action_menu, action_loaded, "
. "action_value, action_error) "
. "VALUES ('" . $this->dbEscapeString($username) . "', 'PASSWORD', "
. ($this->euid ? $this->euid : 'NULL') . ", "
. "NOW(), '" . $this->dbEscapeString($event) . "', "
. "'" . $this->dbEscapeString((string)$error) . "', "
. "'" . $this->dbEscapeString($data) . "', '" . $data_binary . "', "
. "'" . $this->page_name . "', ";
foreach (
[
'REMOTE_ADDR', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'SCRIPT_FILENAME',
'QUERY_STRING', 'SERVER_NAME', 'HTTP_HOST', 'HTTP_ACCEPT',
'HTTP_ACCEPT_CHARSET', 'HTTP_ACCEPT_ENCODING'
] as $server_code
) {
if (array_key_exists($server_code, $_SERVER)) {
$q .= "'".$this->dbEscapeString($_SERVER[$server_code])."', ";
$q .= "'" . $this->dbEscapeString($_SERVER[$server_code]) . "', ";
} else {
$q .= "NULL, ";
}
}
$q .= "'".session_id()."', ";
$q .= "'".$this->dbEscapeString($this->action)."', ";
$q .= "'".$this->dbEscapeString($this->username)."', ";
$q .= "'" . session_id() . "', ";
$q .= "'" . $this->dbEscapeString($this->action) . "', ";
$q .= "'" . $this->dbEscapeString($this->username) . "', ";
$q .= "NULL, ";
$q .= "'".$this->dbEscapeString((string)$this->login_error)."', ";
$q .= "'" . $this->dbEscapeString((string)$this->login_error) . "', ";
$q .= "NULL, NULL, ";
$q .= "'".$this->dbEscapeString((string)$this->permission_okay)."', ";
$q .= "'" . $this->dbEscapeString((string)$this->permission_okay) . "', ";
$q .= "NULL)";
$this->dbExec($q, 'NULL');
}
@@ -1197,7 +1326,8 @@ EOM;
*/
public function loginCheckEditAccessId(?int $edit_access_id): ?int
{
if (isset($_SESSION['UNIT']) &&
if (
isset($_SESSION['UNIT']) &&
is_array($_SESSION['UNIT']) &&
!array_key_exists($edit_access_id, $_SESSION['UNIT'])
) {
@@ -1222,6 +1352,7 @@ EOM;
return $_SESSION['UNIT'][$edit_access_id]['data'][$data_key];
}
}
} // close class
// close class
}
// __END__

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2006/08/15
@@ -26,6 +27,8 @@
*
*********************************************************************/
declare(strict_types=1);
namespace CoreLibs\Admin;
class Backend extends \CoreLibs\DB\IO
@@ -34,7 +37,10 @@ class Backend extends \CoreLibs\DB\IO
public $menu = [];
public $menu_show_flag = 0; // top menu flag (mostly string)
// action ids
public $action_list = ['action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag', 'action_menu', 'action_value', 'action_error', 'action_loaded'];
public $action_list = [
'action', 'action_id', 'action_sub_id', 'action_yes', 'action_flag',
'action_menu', 'action_value', 'action_error', 'action_loaded'
];
public $action;
public $action_id;
public $action_sub_id;
@@ -138,7 +144,7 @@ class Backend extends \CoreLibs\DB\IO
// create the char lang encoding
$this->lang_short = substr($this->lang, 0, 2);
// set the language folder
$this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH;
$this->lang_dir = BASE . INCLUDES . LANG . CONTENT_PATH;
}
// PUBLIC METHODS |=================================================>
@@ -182,32 +188,38 @@ class Backend extends \CoreLibs\DB\IO
$SCHEMA = 'public';
}
$q = "INSERT INTO ".$SCHEMA.".edit_log ";
$q .= "(euid, event_date, event, data, data_binary, page, ";
$q .= "ip, user_agent, referer, script_name, query_string, server_name, http_host, http_accept, http_accept_charset, http_accept_encoding, session_id, ";
$q .= "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) ";
$q .= "VALUES ";
$q .= "(".$this->dbEscapeString(isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ? $_SESSION['EUID'] : 'NULL').", ";
$q .= "NOW(), ";
$q .= "'".$this->dbEscapeString((string)$event)."', '".$data."', '".$data_binary."', '".$this->dbEscapeString((string)$this->page_name)."', ";
$q .= "'".@$_SERVER["REMOTE_ADDR"]."', '".$this->dbEscapeString(@$_SERVER['HTTP_USER_AGENT'])."', ";
$q .= "'".$this->dbEscapeString($_SERVER['HTTP_REFERER'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['SCRIPT_FILENAME'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['QUERY_STRING'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['SERVER_NAME'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['HTTP_HOST'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '')."', ";
$q .= "'".$this->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '')."', ";
$q .= "'".session_id()."', ";
$q .= "'".$this->dbEscapeString($this->action)."', ";
$q .= "'".$this->dbEscapeString($this->action_id)."', ";
$q .= "'".$this->dbEscapeString($this->action_yes)."', ";
$q .= "'".$this->dbEscapeString($this->action_flag)."', ";
$q .= "'".$this->dbEscapeString($this->action_menu)."', ";
$q .= "'".$this->dbEscapeString($this->action_loaded)."', ";
$q .= "'".$this->dbEscapeString($this->action_value)."', ";
$q .= "'".$this->dbEscapeString($this->action_error)."')";
$q = "INSERT INTO " . $SCHEMA . ".edit_log "
. "(euid, event_date, event, data, data_binary, page, "
. "ip, user_agent, referer, script_name, query_string, server_name, http_host, "
. "http_accept, http_accept_charset, http_accept_encoding, session_id, "
. "action, action_id, action_yes, action_flag, action_menu, action_loaded, action_value, action_error) "
. "VALUES "
. "(" . $this->dbEscapeString(isset($_SESSION['EUID']) && is_numeric($_SESSION['EUID']) ?
$_SESSION['EUID'] :
'NULL')
. ", "
. "NOW(), "
. "'" . $this->dbEscapeString((string)$event) . "', '" . $data . "', "
. "'" . $data_binary . "', '" . $this->dbEscapeString((string)$this->page_name) . "', "
. "'" . @$_SERVER["REMOTE_ADDR"] . "', "
. "'" . $this->dbEscapeString(@$_SERVER['HTTP_USER_AGENT']) . "', "
. "'" . $this->dbEscapeString($_SERVER['HTTP_REFERER'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['SCRIPT_FILENAME'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['QUERY_STRING'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['SERVER_NAME'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['HTTP_HOST'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '') . "', "
. "'" . $this->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '') . "', "
. "'" . session_id() . "', "
. "'" . $this->dbEscapeString($this->action) . "', "
. "'" . $this->dbEscapeString($this->action_id) . "', "
. "'" . $this->dbEscapeString($this->action_yes) . "', "
. "'" . $this->dbEscapeString($this->action_flag) . "', "
. "'" . $this->dbEscapeString($this->action_menu) . "', "
. "'" . $this->dbEscapeString($this->action_loaded) . "', "
. "'" . $this->dbEscapeString($this->action_value) . "', "
. "'" . $this->dbEscapeString($this->action_error) . "')";
$this->dbExec($q, 'NULL');
}
@@ -262,20 +274,23 @@ class Backend extends \CoreLibs\DB\IO
}
$query_string = '';
if (isset($data['query']) &&
if (
isset($data['query']) &&
is_array($data['query']) &&
count($data['query'])
) {
// for ($j = 0, $jMax = count($pages[$i]['query']); $j < $jMax; $j ++) {
foreach ($data['query'] as $j => $query) {
if (!empty($query['name']) &&
if (
!empty($query['name']) &&
!empty($query['value'])
) {
if (strlen($query_string)) {
$query_string .= '&';
}
$query_string .= $query['name'].'=';
if (isset($query['dynamic']) &&
$query_string .= $query['name'] . '=';
if (
isset($query['dynamic']) &&
$query['dynamic']
) {
if (isset($_GET[$query['value']])) {
@@ -295,12 +310,13 @@ class Backend extends \CoreLibs\DB\IO
}
$url .= $data['filename'] ?? '';
if (strlen($query_string)) {
$url .= '?'.$query_string;
$url .= '?' . $query_string;
}
$name = $data['page_name'] ?? '';
// if page name matchs -> set selected flag
$selected = 0;
if (isset($data['filename']) &&
if (
isset($data['filename']) &&
\CoreLibs\Get\System::getPageName() == $data['filename'] &&
(!isset($data['hostname']) || (
isset($data['hostname']) &&
@@ -312,7 +328,8 @@ class Backend extends \CoreLibs\DB\IO
}
// last check, is this menu point okay to show
$enabled = 0;
if (isset($data['filename']) &&
if (
isset($data['filename']) &&
$this->adbShowMenuPoint($data['filename'])
) {
$enabled = 1;
@@ -364,7 +381,10 @@ class Backend extends \CoreLibs\DB\IO
*/
public function adbAssocArray(array $db_array, $key, $value): array
{
trigger_error('Method '.__METHOD__.' is deprecated: \CoreLibs\Combined\ArrayHandler::genAssocArray', E_USER_DEPRECATED);
trigger_error(
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Combined\ArrayHandler::genAssocArray',
E_USER_DEPRECATED
);
return \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value);
}
@@ -377,7 +397,10 @@ class Backend extends \CoreLibs\DB\IO
*/
public function adbByteStringFormat($number): string
{
trigger_error('Method '.__METHOD__.' is deprecated: \CoreLibs\Convert\Byte::humanReadableByteFormat()', E_USER_DEPRECATED);
trigger_error(
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Convert\Byte::humanReadableByteFormat()',
E_USER_DEPRECATED
);
return \CoreLibs\Convert\Byte::humanReadableByteFormat($number);
}
@@ -394,7 +417,10 @@ class Backend extends \CoreLibs\DB\IO
*/
public function adbCreateThumbnail($pic, $size_x, $size_y, $dummy = '', $path = "", $cache = "")
{
trigger_error('Method '.__METHOD__.' is deprecated: \CoreLibs\Output\Image::createThumbnail()', E_USER_DEPRECATED);
trigger_error(
'Method ' . __METHOD__ . ' is deprecated: \CoreLibs\Output\Image::createThumbnail()',
E_USER_DEPRECATED
);
return \CoreLibs\Output\Image::createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache);
}
@@ -458,14 +484,15 @@ class Backend extends \CoreLibs\DB\IO
} else {
$SCHEMA = 'public';
}
$q = "INSERT INTO ".$SCHEMA.".live_queue (";
$q .= "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file";
$q .= ") VALUES (";
$q .= "'".$this->dbEscapeString($queue_key)."', '".$this->dbEscapeString($key_value)."', ";
$q .= "'".$this->dbEscapeString($key_name)."', '".$this->dbEscapeString($type)."', ";
$q .= "'".$this->dbEscapeString($target)."', '".$this->dbEscapeString($data)."', ";
$q .= "'".$this->queue_key."', '".$this->action."', '".$this->dbEscapeString((string)$associate)."', ";
$q .= "'".$this->dbEscapeString((string)$file)."')";
$q = "INSERT INTO " . $SCHEMA . ".live_queue ("
. "queue_key, key_value, key_name, type, target, data, group_key, action, associate, file"
. ") VALUES ("
. "'" . $this->dbEscapeString($queue_key) . "', '" . $this->dbEscapeString($key_value) . "', "
. "'" . $this->dbEscapeString($key_name) . "', '" . $this->dbEscapeString($type) . "', "
. "'" . $this->dbEscapeString($target) . "', '" . $this->dbEscapeString($data) . "', "
. "'" . $this->queue_key . "', '" . $this->action . "', "
. "'" . $this->dbEscapeString((string)$associate) . "', "
. "'" . $this->dbEscapeString((string)$file) . "')";
$this->dbExec($q);
}
@@ -495,14 +522,23 @@ class Backend extends \CoreLibs\DB\IO
bool $name_pos_back = false
) {
// get the build layout
$html_time = \CoreLibs\Output\Form\Elements::printDateTime($year, $month, $day, $hour, $min, $suffix, $min_steps, $name_pos_back);
$html_time = \CoreLibs\Output\Form\Elements::printDateTime(
$year,
$month,
$day,
$hour,
$min,
$suffix,
$min_steps,
$name_pos_back
);
// translate the strings inside
foreach (['Year ', 'Month ', 'Day ', 'Hour ', 'Minute '] as $_time) {
$html_time = str_replace($_time, $this->l->__(str_replace(' ', '', $_time)).' ', $html_time);
$html_time = str_replace($_time, $this->l->__(str_replace(' ', '', $_time)) . ' ', $html_time);
}
// replace week days in short
foreach (['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] as $_date) {
$html_time = str_replace('('.$_date.')', '('.$this->l->__($_date).')', $html_time);
$html_time = str_replace('(' . $_date . ')', '(' . $this->l->__($_date) . ')', $html_time);
}
// return the datetime select string with strings translated
return $html_time;

View File

@@ -1,4 +1,7 @@
<?php declare(strict_types=1);
<?php
// phpcs:disable Generic.Files.LineLength
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2003/03/24
@@ -15,12 +18,15 @@
* HISTORY:
* 2021/06/16 (cs) CLASS MOSTLY DEPRECATED: moved all methids in their own classes
* 2010/12/24 (cs) add crypt classes with auto detect what crypt we can use, add php version check class
* 2008/08/07 (cs) fixed strange DEBUG_ALL on off behavour. data was written even thought DBEUG_ALL was off. now no debug logging is done at all if DEBUG_ALL is off
* 2008/08/07 (cs) fixed strange DEBUG_ALL on off behavour. data was written even thought
* DBEUG_ALL was off. now no debug logging is done at all if DEBUG_ALL is off
* 2007/11/13 (cs) add Comparedate function
* 2007/11/05 (cs) added GenAssocArray and CheckDate functions
* 2007/10/10 (cs) magic links function can use http:///path as a local prefix. blank target is removed & http:// also
* 2007/10/10 (cs) magic links function can use http:///path as a local prefix.
* blank target is removed & http:// also
* 2006/03/09 (cs) added Byte/TimeStringFormat functions
* 2006/02/21 (cs) fix various problems with the mime magic function: || not always working, fix prefix replacement, etc
* 2006/02/21 (cs) fix various problems with the mime magic function: || not always working,
* fix prefix replacement, etc
* 2006/02/09 (cs) added _mb_mime_encode function, replacement for php internal one
* 2005/07/12 (cs) added some small stylesheet defs to debug output
* 2005/06/24 (cs) made the check selected/checked function way easier
@@ -43,6 +49,8 @@
* 2003-03-24: start of stub/basic class
*********************************************************************/
declare(strict_types=1);
namespace CoreLibs;
/** Basic core class declaration */
@@ -77,13 +85,19 @@ class Basic
// TODO make check dynamic for entries we MUST have depending on load type
// before we start any work, we should check that all MUST constants are defined
$abort = false;
foreach ([
'DS', 'DIR', 'BASE', 'ROOT', 'LIB', 'INCLUDES', 'LAYOUT', 'PICTURES', 'FLASH', 'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS',
'UPLOADS', 'CSV', 'JS', 'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES', 'TEMPLATES_C',
'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE', 'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY',
'PAGE_WIDTH', 'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA', 'LIVE_SCHEMA', 'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET', 'DEBUG', 'SHOW_ALL_ERRORS'
] as $constant) {
foreach (
[
'DS', 'DIR', 'BASE', 'ROOT', 'LIB', 'INCLUDES', 'LAYOUT', 'PICTURES', 'FLASH',
'VIDEOS', 'DOCUMENTS', 'PDFS', 'BINARIES', 'ICONS', 'UPLOADS', 'CSV', 'JS',
'CSS', 'TABLE_ARRAYS', 'SMARTY', 'LANG', 'CACHE', 'TMP', 'LOG', 'TEMPLATES',
'TEMPLATES_C', 'DEFAULT_LANG', 'DEFAULT_ENCODING', 'DEFAULT_HASH',
'DEFAULT_ACL_LEVEL', 'LOGOUT_TARGET', 'PASSWORD_CHANGE', 'AJAX_REQUEST_TYPE',
'USE_PROTOTYPE', 'USE_SCRIPTACULOUS', 'USE_JQUERY', 'PAGE_WIDTH',
'MASTER_TEMPLATE_NAME', 'PUBLIC_SCHEMA', 'TEST_SCHEMA', 'DEV_SCHEMA',
'LIVE_SCHEMA', 'DB_CONFIG_NAME', 'DB_CONFIG', 'TARGET', 'DEBUG',
'SHOW_ALL_ERRORS'
] as $constant
) {
if (!defined($constant)) {
echo "Constant $constant misssing<br>";
$abort = true;
@@ -167,7 +181,7 @@ class Basic
*/
public function basicSetLogId(string $string): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use $basic->log->basicSetLogId() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use $basic->log->basicSetLogId() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
return $this->log->basicSetLogId($string);
}
@@ -190,7 +204,7 @@ class Basic
*/
public function hrRunningTime(string $out_time = 'ms'): float
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\RunningTime::hrRunningTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Debug\RunningTime::hrRunningTime()', E_USER_DEPRECATED);
return \CoreLibs\Debug\RunningTime::hrRunningTime($out_time);
}
@@ -205,7 +219,7 @@ class Basic
*/
public function runningTime(bool $simple = false): float
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\RunningTime::runningTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Debug\RunningTime::runningTime()', E_USER_DEPRECATED);
return \CoreLibs\Debug\RunningTime::runningTime($simple);
}
@@ -221,7 +235,7 @@ class Basic
*/
public static function printTime(int $set_microtime = -1): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\Support::printTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Debug\Support::printTime()', E_USER_DEPRECATED);
return \CoreLibs\Debug\Support::printTime($set_microtime);
}
@@ -238,7 +252,7 @@ class Basic
*/
public function fdebug(string $string, bool $enter = true): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\FileWriter::fdebug()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Debug\FileWriter::fdebug()', E_USER_DEPRECATED);
return \CoreLibs\Debug\FileWriter::fdebug($string, $enter);
}
@@ -256,7 +270,7 @@ class Basic
*/
public function debugFor(string $type, string $flag): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use $basic->log->debugFor() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use $basic->log->debugFor() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
/** @phan-suppress-next-line PhanTypeMismatchArgumentReal */
$this->log->debugFor(...[func_get_args()]);
}
@@ -342,7 +356,7 @@ class Basic
*/
public function mergeErrors(array $error_msg = []): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use $basic->log->mergeErrors() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use $basic->log->mergeErrors() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
$this->log->mergeErrors($error_msg);
}
@@ -357,74 +371,6 @@ class Basic
return $this->log->printErrorMsg($string);
}
/**
* writes error msg data to file for current level
* @param string $level the level to write
* @param string $error_string error string to write
* @return void has no return
*/
/* private function writeErrorMsg(string $level, string $error_string): void
{
// only write if write is requested
if ($this->doDebugTrigger('debug', $level) &&
$this->doDebugTrigger('print', $level)
) {
// replace all html tags
// $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string);
// $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string);
// replace special line break tag
// $error_string = str_replace('<!--#BR#-->', "\n", $error_string);
// init output variable
$output = $error_string; // output formated error string to output file
// init base file path
$fn = BASE.LOG.$this->log_print_file.'.'.$this->log_file_name_ext;
// log ID prefix settings, if not valid, replace with empty
if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) {
$rpl_string = '_'.$this->log_file_id;
} else {
$rpl_string = '';
}
$fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix)
if ($this->log_per_run) {
if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) {
$this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
}
if (!$this->log_file_unique_id) {
$GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
}
$rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string
} else {
$rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file
}
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file
$fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_class ? '' : '_'.str_replace('\\', '-', get_class($this)); // set sub class settings
$fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_page ? '' : '_'.\CoreLibs\Get\System::getPageName(1); // if request to write to one file
$fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename
// write to file
// first check if max file size is is set and file is bigger
if ($this->log_max_filesize > 0 && ((filesize($fn) / 1024) > $this->log_max_filesize)) {
// for easy purpose, rename file only to attach timestamp, nur sequence numbering
rename($fn, $fn.'.'.date("YmdHis"));
}
$fp = fopen($fn, 'a');
if ($fp !== false) {
fwrite($fp, $output);
fclose($fp);
} else {
echo "<!-- could not open file: $fn //-->";
}
} // do write to file
} */
/**
* unsests the error message array
* can be used if writing is primary to file
@@ -435,7 +381,7 @@ class Basic
*/
public function resetErrorMsg(string $level = ''): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use $basic->log->resetErrorMsg() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use $basic->log->resetErrorMsg() or use \CoreLibs\Debug\Logging() class', E_USER_DEPRECATED);
$this->log->resetErrorMsg($level);
}
@@ -464,7 +410,7 @@ class Basic
*/
public static function getCallerMethod(int $level = 2): ?string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Debug\Support::getCallerMethod()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Debug\Support::getCallerMethod()', E_USER_DEPRECATED);
return \CoreLibs\Debug\Support::getCallerMethod($level);
}
@@ -480,7 +426,7 @@ class Basic
*/
public function fileUploadErrorMessage(int $error_code): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::fileUploadErrorMessage()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Get\System::fileUploadErrorMessage()', E_USER_DEPRECATED);
return \CoreLibs\Get\System::fileUploadErrorMessage($error_code);
}
@@ -499,7 +445,7 @@ class Basic
*/
public function initRandomKeyLength(int $key_length): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\RandomKey::setRandomKeyLength()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\RandomKey::setRandomKeyLength()', E_USER_DEPRECATED);
return \CoreLibs\Create\RandomKey::setRandomKeyLength($key_length);
}
@@ -513,7 +459,7 @@ class Basic
*/
public function randomKeyGen(int $key_length = -1): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\RandomKey::randomKeyGen()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\RandomKey::randomKeyGen()', E_USER_DEPRECATED);
return \CoreLibs\Create\RandomKey::randomKeyGen($key_length);
}
@@ -533,7 +479,7 @@ class Basic
*/
public static function checked($haystack, $needle, int $type = 0): ?string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Html::checked()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Html::checked()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Html::checked($haystack, $needle, $type);
}
@@ -548,7 +494,7 @@ class Basic
*/
public function magicLinks(string $string, string $target = "_blank"): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Form\Elements::magicLinks()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Form\Elements::magicLinks()', E_USER_DEPRECATED);
return \CoreLibs\Output\Form\Elements::magicLinks($string, $target);
}
@@ -563,7 +509,7 @@ class Basic
*/
public function getHostName(): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::getHostName()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Get\System::getHostName()', E_USER_DEPRECATED);
return \CoreLibs\Get\System::getHostName();
}
@@ -577,7 +523,7 @@ class Basic
*/
public static function getPageName(int $strip_ext = 0): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Get\System::getPageName()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Get\System::getPageName()', E_USER_DEPRECATED);
return \CoreLibs\Get\System::getPageName($strip_ext);
}
@@ -593,7 +539,7 @@ class Basic
*/
public static function getFilenameEnding(string $filename): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\File::getFilenameEnding()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\File::getFilenameEnding()', E_USER_DEPRECATED);
return \CoreLibs\Check\File::getFilenameEnding($filename);
}
@@ -605,7 +551,7 @@ class Basic
*/
public static function getLinesFromFile(string $file): int
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\File::getLinesFromFile()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\File::getLinesFromFile()', E_USER_DEPRECATED);
return \CoreLibs\Check\File::getLinesFromFile($file);
}
@@ -625,7 +571,7 @@ class Basic
*/
public static function arraySearchRecursive($needle, array $haystack, ?string $key_lookin = null): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchRecursive()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchRecursive()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arraySearchRecursive($needle, $haystack, $key_lookin);
}
@@ -640,7 +586,7 @@ class Basic
*/
public static function arraySearchRecursiveAll($needle, array $haystack, $key, ?array $path = null): ?array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arraySearchRecursiveAll($needle, $haystack, $key, $path);
}
@@ -654,7 +600,7 @@ class Basic
*/
public static function arraySearchSimple(array $array, $key, $value): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchSimple()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arraySearchSimple()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arraySearchSimple($array, $key, $value);
}
@@ -670,7 +616,7 @@ class Basic
*/
public static function arrayMergeRecursive()
{
trigger_error('MUST CHANGE: Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive()', E_USER_DEPRECATED);
trigger_error('MUST CHANGE: Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arrayMergeRecursive(...func_get_args());
}
@@ -686,7 +632,7 @@ class Basic
*/
public static function arrayDiff(array $a, array $b): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayDiff()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayDiff()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arrayDiff($a, $b);
}
@@ -700,7 +646,7 @@ class Basic
*/
public static function inArrayAny(array $needle, array $haystack)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::inArrayAny()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::inArrayAny()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::inArrayAny($needle, $haystack);
}
@@ -715,7 +661,7 @@ class Basic
*/
public static function genAssocArray(array $db_array, $key, $value, bool $set_only = false): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArray()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArray()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::genAssocArray($db_array, $key, $value, $set_only);
}
@@ -729,7 +675,7 @@ class Basic
*/
public static function arrayToString(array $array, string $connect_char): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use join()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use join()', E_USER_DEPRECATED);
if (!is_array($array)) {
$array = [];
}
@@ -745,7 +691,7 @@ class Basic
*/
public static function flattenArray(array $array): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArray()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArray()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::flattenArray($array);
}
@@ -757,7 +703,7 @@ class Basic
*/
public static function flattenArrayKey(array $array/*, array $return = []*/): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArrayKey()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::flattenArrayKey()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::flattenArrayKey($array);
}
@@ -771,7 +717,7 @@ class Basic
*/
public static function arrayFlatForKey(array $array, $search): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayFlatForKey()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\ArrayHandler::arrayFlatForKey()', E_USER_DEPRECATED);
return \CoreLibs\Combined\ArrayHandler::arrayFlatForKey($array, $search);
}
@@ -789,7 +735,7 @@ class Basic
public static function __mbMimeEncode(string $string, string $encoding): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::__mbMimeEncode()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::__mbMimeEncode($string, $encoding);
}
@@ -809,7 +755,7 @@ class Basic
*/
public static function byteStringFormat($bytes, bool $space = true, bool $adjust = false, bool $si = false): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Byte::humanReadableByteFormat()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Byte::humanReadableByteFormat()', E_USER_DEPRECATED);
$flags = 0;
// match over the true/false flags to the new int style flag
// if space need to set 1
@@ -851,7 +797,7 @@ class Basic
*/
public static function humanReadableByteFormat($bytes, int $flags = 0): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Byte::humanReadableByteFormat()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Byte::humanReadableByteFormat()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Byte::humanReadableByteFormat($bytes, $flags);
}
@@ -863,7 +809,7 @@ class Basic
*/
public static function stringByteFormat($number)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Byte::stringByteFormat()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Byte::stringByteFormat()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Byte::stringByteFormat($number);
}
@@ -880,7 +826,7 @@ class Basic
*/
public static function dateStringFormat($timestamp, bool $show_micro = false): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::dateStringFormat()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::dateStringFormat()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::dateStringFormat($timestamp, $show_micro);
}
@@ -893,7 +839,7 @@ class Basic
*/
public static function timeStringFormat($timestamp, bool $show_micro = true): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::timeStringFormat()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::timeStringFormat()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::timeStringFormat($timestamp, $show_micro);
}
@@ -906,7 +852,7 @@ class Basic
*/
public static function stringToTime($timestring)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::stringToTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::stringToTime()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::stringToTime($timestring);
}
@@ -918,7 +864,7 @@ class Basic
*/
public static function checkDate($date): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::checkDate()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::checkDate()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::checkDate($date);
}
@@ -930,7 +876,7 @@ class Basic
*/
public static function checkDateTime($datetime): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::checkDateTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::checkDateTime()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::checkDateTime($datetime);
}
@@ -948,7 +894,7 @@ class Basic
*/
public static function compareDate($start_date, $end_date)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::compareDate()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::compareDate()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::compareDate($start_date, $end_date);
}
@@ -966,7 +912,7 @@ class Basic
*/
public static function compareDateTime($start_datetime, $end_datetime)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::compareDateTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::compareDateTime()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::compareDateTime($start_datetime, $end_datetime);
}
@@ -982,7 +928,7 @@ class Basic
*/
public static function calcDaysInterval($start_date, $end_date, bool $return_named = false): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Combined\DateTime::calcDaysInterval()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Combined\DateTime::calcDaysInterval()', E_USER_DEPRECATED);
return \CoreLibs\Combined\DateTime::calcDaysInterval($start_date, $end_date, $return_named);
}
@@ -1013,7 +959,7 @@ class Basic
string $cache_source = '',
bool $clear_cache = false
) {
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Image::createThumbnail()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Image::createThumbnail()', E_USER_DEPRECATED);
return \CoreLibs\Output\Image::createThumbnail($pic, $size_x, $size_y, $dummy, $path, $cache_source, $clear_cache);
}
@@ -1049,7 +995,7 @@ class Basic
bool $high_quality = true,
int $jpeg_quality = 80
) {
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Image::createThumbnailSimple()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Image::createThumbnailSimple()', E_USER_DEPRECATED);
return \CoreLibs\Output\Image::createThumbnailSimple($filename, $thumb_width, $thumb_height, $thumbnail_path, $create_dummy, $use_cache, $high_quality, $jpeg_quality);
}
@@ -1063,7 +1009,7 @@ class Basic
*/
public function correctImageOrientation($filename): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Image::correctImageOrientation()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Image::correctImageOrientation()', E_USER_DEPRECATED);
\CoreLibs\Output\Image::correctImageOrientation($filename);
}
@@ -1092,7 +1038,7 @@ class Basic
*/
public function checkConvertEncoding(string $string, string $from_encoding, string $to_encoding)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::checkConvertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::checkConvertEncoding($string, $from_encoding, $to_encoding);
}
@@ -1113,7 +1059,7 @@ class Basic
*/
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Language\Encoding::convertEncoding()', E_USER_DEPRECATED);
return \CoreLibs\Language\Encoding::convertEncoding($string, $to_encoding, $source_encoding, $auto_check);
}
@@ -1131,7 +1077,7 @@ class Basic
*/
public function __crc32b(string $string): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\Hash::__crc32b()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::__crc32b()', E_USER_DEPRECATED);
return \CoreLibs\Create\Hash::__crc32b($string);
}
@@ -1144,7 +1090,7 @@ class Basic
*/
public function __sha1Short(string $string, bool $use_sha = false): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\Hash::__sha1Short()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::__sha1Short()', E_USER_DEPRECATED);
return \CoreLibs\Create\Hash::__sha1Short($string, $use_sha);
}
@@ -1160,7 +1106,7 @@ class Basic
*/
public function __hash(string $string, string $hash_type = 'adler32'): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\Hash::__hash()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Hash::__hash()', E_USER_DEPRECATED);
return \CoreLibs\Create\Hash::__hash($string, $hash_type);
}
@@ -1178,7 +1124,7 @@ class Basic
*/
public static function checkPHPVersion(string $min_version, string $max_version = ''): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\PhpVersion::checkPHPVersion()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\PhpVersion::checkPHPVersion()', E_USER_DEPRECATED);
return \CoreLibs\Check\PhpVersion::checkPHPVersion($min_version, $max_version);
}
@@ -1195,7 +1141,7 @@ class Basic
*/
public static function uuidv4(): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\Uids::uuidv4()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Uids::uuidv4()', E_USER_DEPRECATED);
return \CoreLibs\Create\Uids::uuidv4();
}
@@ -1210,7 +1156,7 @@ class Basic
*/
public function uniqId(string $type = ''): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Create\Uids::uniqId()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Create\Uids::uniqId()', E_USER_DEPRECATED);
return \CoreLibs\Create\Uids::uniqId($type);
}
@@ -1227,7 +1173,7 @@ class Basic
*/
private function passwordInit(): void
{
trigger_error('Method '.__METHOD__.' has been removed', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' has been removed', E_USER_DEPRECATED);
/* // set default password cost: use default set automatically
$this->password_options = [
// 'cost' => PASSWORD_BCRYPT_DEFAULT_COST
@@ -1242,7 +1188,7 @@ class Basic
*/
public function passwordSet(string $password): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Password::passwordSet()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Password::passwordSet()', E_USER_DEPRECATED);
return \CoreLibs\Check\Password::passwordSet($password);
}
@@ -1255,7 +1201,7 @@ class Basic
*/
public function passwordVerify(string $password, string $hash): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Password::passwordVerify()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Password::passwordVerify()', E_USER_DEPRECATED);
return \CoreLibs\Check\Password::passwordVerify($password, $hash);
}
@@ -1267,7 +1213,7 @@ class Basic
*/
public function passwordRehashCheck(string $hash): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Password::passwordRehashCheck()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Password::passwordRehashCheck()', E_USER_DEPRECATED);
return \CoreLibs\Check\Password::passwordRehashCheck($hash);
}
@@ -1287,7 +1233,7 @@ class Basic
*/
public static function hex2rgb(string $hexStr, bool $returnAsString = false, string $seperator = ',')
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::hex2rgb()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hex2rgb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::hex2rgb($hexStr, $returnAsString, $seperator);
}
@@ -1303,7 +1249,7 @@ class Basic
*/
public static function rgb2hex(int $red, int $green, int $blue, bool $hex_prefix = true): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hex($red, $green, $blue, $hex_prefix);
}
@@ -1317,7 +1263,7 @@ class Basic
*/
public static function rgb2html(int $red, int $green, int $blue): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hex()', E_USER_DEPRECATED);
// check that each color is between 0 and 255
return \CoreLibs\Convert\Colors::rgb2hex($red, $green, $blue, true);
}
@@ -1334,7 +1280,7 @@ class Basic
*/
public static function rgb2hsb(int $red, int $green, int $blue): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsb()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hsb($red, $green, $blue);
}
@@ -1348,7 +1294,7 @@ class Basic
*/
public static function hsb2rgb(int $H, float $S, float $V): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::hsb2rgb()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsb2rgb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::hsb2rgb($H, (int)round($S * 100), (int)round($V * 100));
}
@@ -1364,7 +1310,7 @@ class Basic
*/
public static function rgb2hsl(int $r, int $g, int $b): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsl()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::rgb2hsl()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::rgb2hsb($r, $g, $b);
}
@@ -1378,7 +1324,7 @@ class Basic
*/
public static function hsl2rgb(int $h, float $s, float $l): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Colors::hsl2rgb()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Colors::hsl2rgb()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Colors::hsl2rgb($h, $s * 100, $l * 100);
}
@@ -1398,7 +1344,7 @@ class Basic
*/
public function getEmailType(string $email, bool $short = false)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Email::getEmailType()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Email::getEmailType()', E_USER_DEPRECATED);
return \CoreLibs\Check\Email::getEmailType($email, $short);
}
@@ -1410,7 +1356,7 @@ class Basic
*/
public function getShortEmailType(string $email_type)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Email::getShortEmailType()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Email::getShortEmailType()', E_USER_DEPRECATED);
return \CoreLibs\Check\Email::getShortEmailType($email_type);
}
@@ -1437,7 +1383,7 @@ class Basic
*/
public static function printDateTime($year, $month, $day, $hour, $min, string $suffix = '', int $min_steps = 1, bool $name_pos_back = false)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Form\Elements::printDateTime()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Form\Elements::printDateTime()', E_USER_DEPRECATED);
return \CoreLibs\Output\Form\Elements::printDateTime($year, $month, $day, $hour, $min, $suffix, $min_steps, $name_pos_back);
}
@@ -1451,7 +1397,7 @@ class Basic
*/
public static function htmlent($string)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Html::htmlent()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Html::htmlent()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Html::htmlent($string);
}
@@ -1464,7 +1410,7 @@ class Basic
*/
public static function removeLB(string $string, string $replace = ' '): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Html::removeLB()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Html::removeLB()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Html::removeLB($string, $replace);
}
@@ -1484,7 +1430,7 @@ class Basic
*/
public static function fceil(float $number, int $precision = 10): float
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Math::fceil()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Math::fceil()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Math::fceil($number, $precision);
}
@@ -1498,7 +1444,7 @@ class Basic
*/
public static function floorp(float $number, int $precision = -2): float
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Math::floorp()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Math::floorp()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Math::floorp($number, $precision);
}
@@ -1510,7 +1456,7 @@ class Basic
*/
public static function initNumeric($number): float
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\Math::initNumeric()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\Math::initNumeric()', E_USER_DEPRECATED);
return \CoreLibs\Convert\Math::initNumeric($number);
}
@@ -1528,7 +1474,7 @@ class Basic
*/
public static function setFormToken(string $name = 'form_token'): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Form\Token::setFormToken()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Form\Token::setFormToken()', E_USER_DEPRECATED);
return \CoreLibs\Output\Form\Token::setFormToken($name);
}
@@ -1541,7 +1487,7 @@ class Basic
*/
public static function validateFormToken(string $token, string $name = 'form_token'): bool
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Output\Form\Token::validateFormToken()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Output\Form\Token::validateFormToken()', E_USER_DEPRECATED);
return \CoreLibs\Output\Form\Token::validateFormToken($token, $name);
}
@@ -1560,7 +1506,7 @@ class Basic
*/
public function mimeSetAppName(string $mime, string $app): void
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeSetAppName()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeSetAppName()', E_USER_DEPRECATED);
\CoreLibs\Convert\MimeAppName::mimeSetAppName($mime, $app);
}
@@ -1573,7 +1519,7 @@ class Basic
*/
public function mimeGetAppName(string $mime): string
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeGetAppName()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Convert\MimeAppName()->mimeGetAppName()', E_USER_DEPRECATED);
return \CoreLibs\Convert\MimeAppName::mimeGetAppName($mime);
}
@@ -1597,7 +1543,7 @@ class Basic
*/
public function jsonConvertToArray(?string $json, bool $override = false): array
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Jason::jsonConvertToArray()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Jason::jsonConvertToArray()', E_USER_DEPRECATED);
return \CoreLibs\Check\Jason::jsonConvertToArray($json, $override);
}
@@ -1612,11 +1558,13 @@ class Basic
*/
public function jsonGetLastError(bool $return_string = false)
{
trigger_error('Method '.__METHOD__.' is deprecated, use \CoreLibs\Check\Jason::jsonGetLastError()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use \CoreLibs\Check\Jason::jsonGetLastError()', E_USER_DEPRECATED);
return \CoreLibs\Check\Jason::jsonGetLastError($return_string);
}
// *** JSON END ***
}
// phpcs:enable
// __END__

View File

@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace CoreLibs\Check;
@@ -6,7 +8,8 @@ class Email
{
// this is for error check parts in where the email regex failed
private static $email_regex_check = [
0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
0 => "^[A-Za-z0-9!#$%&'*+\-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+\-\/=?^_`{|}~\.]{0,63}@"
. "[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*\.([a-zA-Z]{2,}){1}$", // MASTER
1 => "@(.*)@(.*)", // double @
2 => "^[A-Za-z0-9!#$%&'*+-\/=?^_`{|}~][A-Za-z0-9!#$%:\(\)&'*+-\/=?^_`{|}~\.]{0,63}@", // wrong part before @
3 => "@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]{1,})*\.([a-zA-Z]{2,}){1}$", // wrong part after @
@@ -18,27 +21,39 @@ class Email
// the array with the mobile types that are valid
private static $mobile_email_type = [
'.*@docomo\.ne\.jp$' => 'keitai_docomo',
'.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb', # correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
'.*@(ez[a-j]{1}\.)?ido\.ne\.jp$' => 'keitai_kddi_ido', # ez[a-j] or nothing
'.*@([a-z]{2}\.)?sky\.tu-ka\.ne\.jp$' => 'keitai_kddi_tu-ka', # (sky group)
'.*@([a-z]{2}\.)?sky\.tk[kc]{1}\.ne\.jp$' => 'keitai_kddi_sky', # (sky group) [tkk,tkc only]
'.*@([a-z]{2}\.)?sky\.dtg\.ne\.jp$' => 'keitai_kddi_dtg', # dtg (sky group)
'.*@[tkdhcrnsq]{1}\.vodafone\.ne\.jp$' => 'keitai_softbank_vodafone', # old vodafone [t,k,d,h,c,r,n,s,q]
'.*@jp-[dhtkrsnqc]{1}\.ne\.jp$' => 'keitai_softbank_j-phone', # very old j-phone (pre vodafone) [d,h,t,k,r,s,n,q,c]
'.*@([dhtcrknsq]{1}\.)?softbank\.ne\.jp$' => 'keitai_softbank', # add i for iphone also as keitai, others similar to the vodafone group
'.*@i{1}\.softbank(\.ne)?\.jp$' => 'smartphone_softbank_iphone', # add iPhone also as keitai and not as pc
'.*@disney\.ne\.jp$' => 'keitai_softbank_disney', # (kids)
// correct are a[2-4], b2, c[1-9], e[2-9], h[2-4], t[1-9]
'.*@([a-z0-9]{2}\.)?ezweb\.ne\.jp$' => 'keitai_kddi_ezweb',
// ez[a-j] or nothing
'.*@(ez[a-j]{1}\.)?ido\.ne\.jp$' => 'keitai_kddi_ido',
// (sky group)
'.*@([a-z]{2}\.)?sky\.tu-ka\.ne\.jp$' => 'keitai_kddi_tu-ka',
// (sky group) [tkk,tkc only]
'.*@([a-z]{2}\.)?sky\.tk[kc]{1}\.ne\.jp$' => 'keitai_kddi_sky',
// dtg (sky group)
'.*@([a-z]{2}\.)?sky\.dtg\.ne\.jp$' => 'keitai_kddi_dtg',
// old vodafone [t,k,d,h,c,r,n,s,q]
'.*@[tkdhcrnsq]{1}\.vodafone\.ne\.jp$' => 'keitai_softbank_vodafone',
// very old j-phone (pre vodafone) [d,h,t,k,r,s,n,q,c]
'.*@jp-[dhtkrsnqc]{1}\.ne\.jp$' => 'keitai_softbank_j-phone',
// add i for iphone also as keitai, others similar to the vodafone group
'.*@([dhtcrknsq]{1}\.)?softbank\.ne\.jp$' => 'keitai_softbank',
// add iPhone also as keitai and not as pc
'.*@i{1}\.softbank(\.ne)?\.jp$' => 'smartphone_softbank_iphone',
'.*@disney\.ne\.jp$' => 'keitai_softbank_disney', // (kids)
'.*@willcom\.ne\.jp$' => 'keitai_willcom',
'.*@willcom\.com$' => 'keitai_willcom', # new for pdx.ne.jp address
'.*@wcm\.ne\.jp$' => 'keitai_willcom', # old willcom wcm.ne.jp
'.*@pdx\.ne\.jp$' => 'keitai_willcom_pdx', # old pdx address for willcom
'.*@bandai\.jp$' => 'keitai_willcom_bandai', # willcom paipo! (kids)
'.*@pipopa\.ne\.jp$' => 'keitai_willcom_pipopa', # willcom paipo! (kids)
'.*@([a-z0-9]{2,4}\.)?pdx\.ne\.jp$' => 'keitai_willcom_pdx', # actually only di,dj,dk,wm -> all others are "wrong", but none also allowed?
'.*@ymobile([1]{1})?\.ne\.jp$' => 'keitai_willcom_ymobile', # ymobile, ymobile1 techincally not willcom, but I group them there (softbank sub)
'.*@y-mobile\.ne\.jp$' => 'keitai_willcom_ymobile', # y-mobile techincally not willcom, but I group them there (softbank sub)
'.*@emnet\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
'.*@emobile\.ne\.jp$' => 'keitai_willcom_emnet', # e-mobile, group will willcom
'.*@willcom\.com$' => 'keitai_willcom', // new for pdx.ne.jp address
'.*@wcm\.ne\.jp$' => 'keitai_willcom', // old willcom wcm.ne.jp
'.*@pdx\.ne\.jp$' => 'keitai_willcom_pdx', // old pdx address for willcom
'.*@bandai\.jp$' => 'keitai_willcom_bandai', // willcom paipo! (kids)
'.*@pipopa\.ne\.jp$' => 'keitai_willcom_pipopa', // willcom paipo! (kids)
// actually only di,dj,dk,wm -> all others are "wrong", but none also allowed?
'.*@([a-z0-9]{2,4}\.)?pdx\.ne\.jp$' => 'keitai_willcom_pdx',
// ymobile, ymobile1 techincally not willcom, but I group them there (softbank sub)
'.*@ymobile([1]{1})?\.ne\.jp$' => 'keitai_willcom_ymobile',
// y-mobile techincally not willcom, but I group them there (softbank sub)
'.*@y-mobile\.ne\.jp$' => 'keitai_willcom_ymobile',
'.*@emnet\.ne\.jp$' => 'keitai_willcom_emnet', // e-mobile, group will willcom
'.*@emobile\.ne\.jp$' => 'keitai_willcom_emnet', // e-mobile, group will willcom
'.*@emobile-s\.ne\.jp$' => 'keitai_willcom_emnet' # e-mobile, group will willcom
];
// short list for mobile email types

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* various file/file name functions
*/
declare(strict_types=1);
namespace CoreLibs\Check;
class File
@@ -26,7 +28,8 @@ class File
*/
public static function getLinesFromFile(string $file): int
{
if (is_file($file) &&
if (
is_file($file) &&
file_exists($file) &&
is_readable($file)
) {

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
* Converts a json string to array and stores error for later checking
@@ -6,6 +6,8 @@
* and self set json as is on error as array
*/
declare(strict_types=1);
namespace CoreLibs\Check;
class Jason

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* core password set, check and rehash check wrapper functions
*/
declare(strict_types=1);
namespace CoreLibs\Check;
class Password

View File

@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace CoreLibs\Check;

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* html convert functions
*/
declare(strict_types=1);
namespace CoreLibs\Combined;
class ArrayHandler
@@ -23,7 +25,8 @@ class ArrayHandler
if (!is_array($haystack)) {
$haystack = [];
}
if ($key_lookin != null &&
if (
$key_lookin != null &&
!empty($key_lookin) &&
array_key_exists($key_lookin, $haystack) &&
$needle === $haystack[$key_lookin]
@@ -31,20 +34,23 @@ class ArrayHandler
$path[] = $key_lookin;
} else {
foreach ($haystack as $key => $val) {
if (is_scalar($val) &&
if (
is_scalar($val) &&
$val === $needle &&
empty($key_lookin)
) {
$path[] = $key;
break;
} elseif (is_scalar($val) &&
} elseif (
is_scalar($val) &&
!empty($key_lookin) &&
$key === $key_lookin &&
$val == $needle
) {
$path[] = $key;
break;
} elseif (is_array($val) &&
} elseif (
is_array($val) &&
$path = self::arraySearchRecursive(
$needle,
(array)$val,
@@ -160,7 +166,7 @@ class ArrayHandler
{
// croak on not enough arguemnts (we need at least two)
if (func_num_args() < 2) {
trigger_error(__FUNCTION__ .' needs two or more array arguments', E_USER_WARNING);
trigger_error(__FUNCTION__ . ' needs two or more array arguments', E_USER_WARNING);
return false;
}
// default key is not string
@@ -174,14 +180,14 @@ class ArrayHandler
}
// check that arrays count is at least two, else we don't have enough to do anything
if (count($arrays) < 2) {
trigger_error(__FUNCTION__.' needs two or more array arguments', E_USER_WARNING);
trigger_error(__FUNCTION__ . ' needs two or more array arguments', E_USER_WARNING);
return false;
}
$merged = [];
while ($arrays) {
$array = array_shift($arrays);
if (!is_array($array)) {
trigger_error(__FUNCTION__ .' encountered a non array argument', E_USER_WARNING);
trigger_error(__FUNCTION__ . ' encountered a non array argument', E_USER_WARNING);
return false;
}
if (!$array) {
@@ -259,9 +265,10 @@ class ArrayHandler
{
$ret_array = [];
// do this to only run count once
for ($i = 0, $iMax = count($db_array); $i < $iMax; $i ++) {
for ($i = 0, $iMax = count($db_array); $i < $iMax; $i++) {
// if no key then we make an order reference
if ($key !== false &&
if (
$key !== false &&
$value !== false &&
(($set_only && $db_array[$i][$value]) || (!$set_only))
) {

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* image thumbnail, rotate, etc
*/
declare(strict_types=1);
namespace CoreLibs\Combined;
class DateTime
@@ -21,7 +23,7 @@ class DateTime
list ($timestamp, $ms) = array_pad(explode('.', (string)round($timestamp, 4)), 2, null);
$string = date("Y-m-d H:i:s", (int)$timestamp);
if ($show_micro && $ms) {
$string .= ' '.$ms.'ms';
$string .= ' ' . $ms . 'ms';
}
return $string;
}
@@ -50,12 +52,12 @@ class DateTime
if ($timestamp == 0) {
$time_string = '0s';
} else {
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i ++) {
for ($i = 0, $iMax = count($timegroups); $i < $iMax; $i++) {
$output = floor((float)$timestamp / $timegroups[$i]);
$timestamp = (float)$timestamp % $timegroups[$i];
// output has days|hours|min|sec
if ($output || $time_string) {
$time_string .= $output.$labels[$i].(($i + 1) != count($timegroups) ? ' ' : '');
$time_string .= $output . $labels[$i] . (($i + 1) != count($timegroups) ? ' ' : '');
}
}
}
@@ -65,13 +67,13 @@ class DateTime
$ms = preg_replace("/^0+(\d+)$/", '${1}', $ms);
// add ms if there
if ($show_micro) {
$time_string .= ' '.(!$ms ? 0 : $ms).'ms';
$time_string .= ' ' . (!$ms ? 0 : $ms) . 'ms';
} elseif (!$time_string) {
$time_string .= (!$ms ? 0 : $ms).'ms';
$time_string .= (!$ms ? 0 : $ms) . 'ms';
}
}
if ($negative) {
$time_string = '-'.$time_string;
$time_string = '-' . $time_string;
}
} else {
$time_string = $timestamp;
@@ -108,7 +110,7 @@ class DateTime
}
}
if (isset($matches[10]) && is_numeric($matches[10])) {
$timestamp .= '.'.$matches[10];
$timestamp .= '.' . $matches[10];
}
if ($negative) {
$timestamp *= -1;
@@ -159,7 +161,8 @@ class DateTime
if (!is_numeric($hour) || !is_numeric($min)) {
return false;
}
if (($hour < 0 || $hour > 24) ||
if (
($hour < 0 || $hour > 24) ||
($min < 0 || $min > 60) ||
(is_numeric($sec) && ($sec < 0 || $sec > 60))
) {
@@ -192,15 +195,15 @@ class DateTime
// check that month & day are two digits and then combine
foreach (['start', 'end'] as $prefix) {
foreach (['month', 'day'] as $date_part) {
$_date = $prefix.'_'.$date_part;
$_date = $prefix . '_' . $date_part;
if (isset($$_date) && $$_date < 10 && !preg_match("/^0/", $$_date)) {
$$_date = '0'.$$_date;
$$_date = '0' . $$_date;
}
}
$_date = $prefix.'_date';
$_date = $prefix . '_date';
$$_date = '';
foreach (['year', 'month', 'day'] as $date_part) {
$_sub_date = $prefix.'_'.$date_part;
$_sub_date = $prefix . '_' . $date_part;
$$_date .= $$_sub_date;
}
}

View File

@@ -1,17 +1,19 @@
<?php declare(strict_types=1);
<?php
/*
* image thumbnail, rotate, etc
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class Byte
{
// define byteFormat
const BYTE_FORMAT_NOSPACE = 1;
const BYTE_FORMAT_ADJUST = 2;
const BYTE_FORMAT_SI = 4;
public const BYTE_FORMAT_NOSPACE = 1;
public const BYTE_FORMAT_ADJUST = 2;
public const BYTE_FORMAT_SI = 4;
/**
* This function replaces the old byteStringFormat
@@ -62,7 +64,7 @@ class Byte
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs($bytes);
// smaller than unit is always B
if ($abs_bytes < $unit) {
return $bytes.'B';
return $bytes . 'B';
}
// labels in order of size [Y, Z]
$labels = ['', 'K', 'M', 'G', 'T', 'P', 'E'];
@@ -75,13 +77,14 @@ class Byte
// deviation calculation
$dev = pow($unit, $exp) * ($unit - 0.05);
// shift the exp +1 for on the border units
if ($exp < 6 &&
if (
$exp < 6 &&
$abs_bytes > ($dev - (((int)$dev & 0xfff) == 0xd00 ? 52 : 0))
) {
$exp ++;
$exp++;
}
// label name, including leading space if flagged
$pre = ($space ? ' ' : '').($labels[$exp] ?? '>E').($si ? 'i' : '').'B';
$pre = ($space ? ' ' : '') . ($labels[$exp] ?? '>E') . ($si ? 'i' : '') . 'B';
$bytes_calc = $abs_bytes / pow($unit, $exp);
// if original is negative, reverse
if ($bytes < 0) {
@@ -90,7 +93,7 @@ class Byte
if ($adjust) {
return sprintf("%.2f%s", $bytes_calc, $pre);
} else {
return round($bytes_calc, 2).$pre;
return round($bytes_calc, 2) . $pre;
}
} else {
// if anything other return as string
@@ -120,7 +123,11 @@ class Byte
// all valid units
$valid_units_ = 'bkmgtpezy';
// detects up to exo bytes
preg_match("/([\d.,]*)\s?(eib|pib|tib|gib|mib|kib|eb|pb|tb|gb|mb|kb|e|p|t|g|m|k|b)$/i", strtolower($number), $matches);
preg_match(
"/([\d.,]*)\s?(eib|pib|tib|gib|mib|kib|eb|pb|tb|gb|mb|kb|e|p|t|g|m|k|b)$/i",
strtolower($number),
$matches
);
if (isset($matches[1]) && isset($matches[2])) {
// remove all non valid characters from the number
$number = preg_replace('/[^0-9\.]/', '', $matches[1]);

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
* Convert color spaces
@@ -10,6 +10,8 @@
* hsl to rgb
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class Colors

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* html convert functions
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class Html
@@ -16,7 +18,7 @@ class Html
public static function htmlent($string)
{
if (is_string($string)) {
return htmlentities($string, ENT_COMPAT|ENT_HTML401, 'UTF-8', false);
return htmlentities($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
} else {
return $string;
}

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* various math related function wrappers
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class Math

View File

@@ -1,10 +1,12 @@
<?php declare(strict_types=1);
<?php
/*
* Translates a mime id string into the actual application or file name
* for example 'text/plain' will output 'Text file'
*/
declare(strict_types=1);
namespace CoreLibs\Convert;
class MimeAppName

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* hash wrapper functions for old problem fixes
*/
declare(strict_types=1);
namespace CoreLibs\Create;
class Hash

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* html convert functions
*/
declare(strict_types=1);
namespace CoreLibs\Create;
class RandomKey
@@ -39,7 +41,8 @@ class RandomKey
*/
private static function validateRandomKeyLenght(int $key_length): bool
{
if (is_numeric($key_length) &&
if (
is_numeric($key_length) &&
$key_length > 0 &&
$key_length <= self::$max_key_length
) {
@@ -98,7 +101,7 @@ class RandomKey
}
$pieces = [];
for ($i = 1; $i <= $use_key_length; $i ++) {
for ($i = 1; $i <= $use_key_length; $i++) {
$pieces[] = self::$key_range[random_int(0, self::$one_key_length - 1)];
}
return join('', $pieces);

View File

@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace CoreLibs\Create;

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2002/12/17
@@ -29,6 +30,8 @@
// as it actually has nothing to do with this one here ? (or at least
// put into separete function in this class)
declare(strict_types=1);
namespace CoreLibs\DB\Extended;
// subclass for one array handling
@@ -122,7 +125,7 @@ class ArrayIO extends \CoreLibs\DB\IO
reset($this->table_array);
$string = '';
foreach ($this->table_array as $column => $data_array) {
$string .= '<b>'.$column.'</b> -> '.$data_array['value'].'<br>';
$string .= '<b>' . $column . '</b> -> ' . $data_array['value'] . '<br>';
}
// add output to internal error_msg
if ($write === true) {
@@ -185,22 +188,23 @@ class ArrayIO extends \CoreLibs\DB\IO
return $this->table_array;
}
// delete query
$q = 'DELETE FROM '.$this->table_name.' WHERE ';
$q .= $this->pk_name.' = '.$this->table_array[$this->pk_name]['value'].' ';
$q = 'DELETE FROM ' . $this->table_name . ' WHERE ';
$q .= $this->pk_name . ' = ' . $this->table_array[$this->pk_name]['value'] . ' ';
// delete files and build FK query
reset($this->table_array);
$q_where = '';
foreach ($this->table_array as $column => $data_array) {
// suchen nach bildern und lschen ...
if (!empty($this->table_array[$column]['file']) &&
file_exists($this->table_array[$column]['url'].$this->table_array[$column]['value'])
if (
!empty($this->table_array[$column]['file']) &&
file_exists($this->table_array[$column]['url'] . $this->table_array[$column]['value'])
) {
if (file_exists($this->table_array[$column]['path'].$this->table_array[$column]['value'])) {
unlink($this->table_array[$column]['path'].$this->table_array[$column]['value']);
if (file_exists($this->table_array[$column]['path'] . $this->table_array[$column]['value'])) {
unlink($this->table_array[$column]['path'] . $this->table_array[$column]['value']);
}
$file_name = str_replace('_tn', '', $this->table_array[$column]['value']);
if (file_exists($this->table_array[$column]['path'].$file_name)) {
unlink($this->table_array[$column]['path'].$file_name);
if (file_exists($this->table_array[$column]['path'] . $file_name)) {
unlink($this->table_array[$column]['path'] . $file_name);
}
}
// if we have a foreign key
@@ -209,7 +213,7 @@ class ArrayIO extends \CoreLibs\DB\IO
if ($q_where) {
$q_where .= ' AND ';
}
$q_where .= $column.' = '.$this->table_array[$column]['value'];
$q_where .= $column . ' = ' . $this->table_array[$column]['value'];
}
// allgemeines zurcksetzen des arrays
unset($this->table_array[$column]['value']);
@@ -217,7 +221,7 @@ class ArrayIO extends \CoreLibs\DB\IO
// attach fk row if there ...
if ($q_where) {
$q .= ' AND '.$q_where;
$q .= ' AND ' . $q_where;
}
// if 0, error
$this->pk_id = null;
@@ -258,16 +262,16 @@ class ArrayIO extends \CoreLibs\DB\IO
if ($q_where) {
$q_where .= ' AND ';
}
$q_where .= $column .= ' = '.$this->table_array[$column]['value'];
$q_where .= $column .= ' = ' . $this->table_array[$column]['value'];
}
}
$q = 'SELECT ';
$q .= $q_select;
$q .= ' FROM '.$this->table_name.' WHERE ';
$q .= $this->pk_name.' = '.$this->table_array[$this->pk_name]['value'].' ';
$q .= ' FROM ' . $this->table_name . ' WHERE ';
$q .= $this->pk_name . ' = ' . $this->table_array[$this->pk_name]['value'] . ' ';
if ($q_where) {
$q .= ' AND '.$q_where;
$q .= ' AND ' . $q_where;
}
// if query was executed okay, else set error
@@ -277,11 +281,13 @@ class ArrayIO extends \CoreLibs\DB\IO
foreach ($this->table_array as $column => $data_array) {
// wenn "edit" dann gib daten wie in DB zurück, ansonten aufbereiten fr ausgabe
// ?? sollte das nicht drauen ??? man weis ja net was da drin steht --> is noch zu berlegen
// echo 'EDIT: $edit | Spalte: $column | type: '.$this->table_array[$column]['type'].' | Res: '.$res[$column].'<br>';
// $this->log->debug('DB READ', 'EDIT: $edit | Spalte: $column | type: '
// .$this->table_array[$column]['type'].' | Res: '.$res[$column]);
if ($edit) {
$this->table_array[$column]['value'] = $res[$column];
// if password, also write to hidden
if (isset($this->table_array[$column]['type']) &&
if (
isset($this->table_array[$column]['type']) &&
$this->table_array[$column]['type'] == 'password'
) {
$this->table_array[$column]['HIDDEN_value'] = $res[$column];
@@ -336,12 +342,12 @@ class ArrayIO extends \CoreLibs\DB\IO
// falls in 'delete' 'ja' dann loeschen (und gibts eh nur beim update)
if ($this->table_array[$column]['delete']) {
unset($this->table_array[$column]['delete']);
if (file_exists($this->table_array[$column]['path'].$this->table_array[$column]['value'])) {
unlink($this->table_array[$column]['path'].$this->table_array[$column]['value']);
if (file_exists($this->table_array[$column]['path'] . $this->table_array[$column]['value'])) {
unlink($this->table_array[$column]['path'] . $this->table_array[$column]['value']);
}
$file_name = str_replace('_tn', '', $this->table_array[$column]['value']);
if (file_exists($this->table_array[$column]['path'].$file_name)) {
unlink($this->table_array[$column]['path'].$file_name);
if (file_exists($this->table_array[$column]['path'] . $file_name)) {
unlink($this->table_array[$column]['path'] . $file_name);
}
$this->table_array[$column]['value'] = '';
} else {
@@ -351,26 +357,26 @@ class ArrayIO extends \CoreLibs\DB\IO
// mozilla, patch
$fn_name = explode('/', $this->table_array[$column]['dn']);
$this->table_array[$column]['dn'] = $fn_name[count($fn_name)-1];
$this->table_array[$column]['dn'] = $fn_name[count($fn_name) - 1];
$filename_parts = explode('.', $this->table_array[$column]['dn']);
$ext = end($filename_parts);
array_splice($filename_parts, -1, 1);
$name = str_replace(' ', '_', implode('.', $filename_parts));
$file_name = $name.'.'.$ext;
$file_name = $name . '.' . $ext;
//echo 'Dn: $file_name';
copy($this->table_array[$column]['tmp'], $this->table_array[$column]['path'].$file_name);
copy($this->table_array[$column]['tmp'], $this->table_array[$column]['path'] . $file_name);
// automatisch thumbnail generieren, geht nur mit convert (ImageMagic!!!), aber nur bei bild ..
if (strtolower($ext) == 'jpeg' || strtolower($ext) == 'jpg' || strtolower($ext) == 'gif' || strtolower($ext) == 'png') {
$file_name_tn = $name.'_tn.'.$ext;
$input = $this->table_array[$column]['path'].$file_name;
$output = $this->table_array[$column]['path'].$file_name_tn;
$com = 'convert -geometry 115 '.$input.' '.$output;
if (in_array(strtolower($ext), ['jpeg', 'jpg', 'gif', 'png'])) {
$file_name_tn = $name . '_tn.' . $ext;
$input = $this->table_array[$column]['path'] . $file_name;
$output = $this->table_array[$column]['path'] . $file_name_tn;
$com = 'convert -geometry 115 ' . $input . ' ' . $output;
exec($com);
$this->table_array[$column]['value'] = $file_name_tn;
} else {
$this->table_array[$column]['value'] = $file_name;
}
} elseif (file_exists($this->table_array[$column]['path'].$this->table_array[$column]['value'])) {
} elseif (file_exists($this->table_array[$column]['path'] . $this->table_array[$column]['value'])) {
// mach gar nix, wenn bild schon da ???
}
} // delete or upload
@@ -378,13 +384,15 @@ class ArrayIO extends \CoreLibs\DB\IO
/********************************* END FILE **************************************/
// do not write 'pk' (primary key) or 'view' values
if (!isset($this->table_array[$column]['pk']) &&
if (
!isset($this->table_array[$column]['pk']) &&
isset($this->table_array[$column]['type']) &&
$this->table_array[$column]['type'] != 'view' &&
strlen($column) > 0
) {
// for password use hidden value if main is not set
if (isset($this->table_array[$column]['type']) &&
if (
isset($this->table_array[$column]['type']) &&
$this->table_array[$column]['type'] == 'password' &&
empty($this->table_array[$column]['value'])
) {
@@ -394,7 +402,7 @@ class ArrayIO extends \CoreLibs\DB\IO
if (strlen($q_data)) {
$q_data .= ', ';
}
$q_data .= $column.' = ';
$q_data .= $column . ' = ';
} else {
// this is insert
if (strlen($q_data)) {
@@ -407,15 +415,18 @@ class ArrayIO extends \CoreLibs\DB\IO
}
// integer is different
if (isset($this->table_array[$column]['int']) || isset($this->table_array[$column]['int_null'])) {
$this->log->debug('write_check', '['.$column.']['.$this->table_array[$column]['value'].']['.$this->table_array[$column]['type'].'] '.
'VALUE SET: '.(string)isset($this->table_array[$column]['value']).
' | INT NULL: '.(string)isset($this->table_array[$column]['int_null']));
if (isset($this->table_array[$column]['value']) &&
$this->log->debug('WRITE CHECK', '[' . $column . '][' . $this->table_array[$column]['value'] . ']'
. '[' . $this->table_array[$column]['type'] . '] '
. 'VALUE SET: ' . (string)isset($this->table_array[$column]['value'])
. ' | INT NULL: ' . (string)isset($this->table_array[$column]['int_null']));
if (
isset($this->table_array[$column]['value']) &&
!$this->table_array[$column]['value'] &&
isset($this->table_array[$column]['int_null'])
) {
$_value = 'NULL';
} elseif (!isset($this->table_array[$column]['value']) ||
} elseif (
!isset($this->table_array[$column]['value']) ||
(isset($this->table_array[$column]['value']) && !$this->table_array[$column]['value'])
) {
$_value = 0;
@@ -425,10 +436,11 @@ class ArrayIO extends \CoreLibs\DB\IO
$q_data .= $_value;
} elseif (isset($this->table_array[$column]['bool'])) {
// boolean storeage (reverse check on ifset)
$q_data .= "'".$this->dbBoolean($this->table_array[$column]['value'], true)."'";
$q_data .= "'" . $this->dbBoolean($this->table_array[$column]['value'], true) . "'";
} elseif (isset($this->table_array[$column]['interval'])) {
// for interval we check if no value, then we set null
if (!isset($this->table_array[$column]['value']) ||
if (
!isset($this->table_array[$column]['value']) ||
(isset($this->table_array[$column]['value']) && !$this->table_array[$column]['value'])
) {
$_value = 'NULL';
@@ -442,9 +454,14 @@ class ArrayIO extends \CoreLibs\DB\IO
} else {
// if the error check is json, we set field to null if NOT set
// else normal string write
if (isset($this->table_array[$column]['error_check']) &&
if (
isset($this->table_array[$column]['error_check']) &&
$this->table_array[$column]['error_check'] == 'json' &&
(!isset($this->table_array[$column]['value']) || (isset($this->table_array[$column]['value']) && !$this->table_array[$column]['value']))
(
!isset($this->table_array[$column]['value']) ||
(isset($this->table_array[$column]['value']) &&
!$this->table_array[$column]['value'])
)
) {
$q_data .= 'NULL';
} else {
@@ -452,7 +469,9 @@ class ArrayIO extends \CoreLibs\DB\IO
$q_data .= "'";
// if add slashes do convert & add slashes else write AS is
if ($addslashes) {
$q_data .= $this->dbEscapeString($this->convertEntities($this->table_array[$column]['value']));
$q_data .= $this->dbEscapeString(
$this->convertEntities($this->table_array[$column]['value'])
);
} else {
$q_data .= $this->dbEscapeString($this->table_array[$column]['value']);
}
@@ -472,14 +491,14 @@ class ArrayIO extends \CoreLibs\DB\IO
if (!empty($q_where)) {
$q_where .= ' AND ';
}
$q_where .= $column .= ' = '.$this->table_array[$column]['value'];
$q_where .= $column .= ' = ' . $this->table_array[$column]['value'];
}
}
// if no PK set, then get max ID from DB
if (!$this->table_array[$this->pk_name]['value']) {
// max id, falls INSERT
$q = 'SELECT MAX('.$this->pk_name.') + 1 AS pk_id FROM '.$this->table_name;
$q = 'SELECT MAX(' . $this->pk_name . ') + 1 AS pk_id FROM ' . $this->table_name;
$res = $this->dbReturnRow($q);
if (!isset($res['pk_id'])) {
$res['pk_id'] = 1;
@@ -488,19 +507,19 @@ class ArrayIO extends \CoreLibs\DB\IO
}
if (!$insert) {
$q = 'UPDATE '.$this->table_name.' SET ';
$q = 'UPDATE ' . $this->table_name . ' SET ';
$q .= $q_data;
$q .= ' WHERE ';
$q .= $this->pk_name.' = '.$this->table_array[$this->pk_name]['value'].' ';
$q .= $this->pk_name . ' = ' . $this->table_array[$this->pk_name]['value'] . ' ';
if (!empty($q_where)) {
$q .= ' AND '.$q_where;
$q .= ' AND ' . $q_where;
}
// set pk_id ... if it has changed or so
$this->pk_id = $this->table_array[$this->pk_name]['value'];
} else {
$q = 'INSERT INTO '.$this->table_name.' ';
$q .= '('.$q_vars.') ';
$q .= 'VALUES ('.$q_data.')';
$q = 'INSERT INTO ' . $this->table_name . ' ';
$q .= '(' . $q_vars . ') ';
$q .= 'VALUES (' . $q_data . ')';
// write primary key too
// if ($q_data)
// $q .= ", ";
@@ -520,6 +539,7 @@ class ArrayIO extends \CoreLibs\DB\IO
// return the table if needed
return $this->table_array;
}
} // end of class
// end of class
}
// __END__

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2000/11/23
@@ -107,9 +108,11 @@
* _db_io()
* - pseudo deconstructor - functionality moved to db_close
* $string info($show=1)
* - returns a string various info about class (version, authoer, etc), if $show set to 0, it will not be appended to the error_msgs string
* - returns a string various info about class (version, authoer, etc)
* - if $show set to 0, it will not be appended to the error_msgs string
* $string db_info($show=1)
* - returns a string with info about db connection, etc, if $show set to 0, it will not be appended to the error_msgs string
* - returns a string with info about db connection, etc, if $show set to 0,
* - it will not be appended to the error_msgs string
* $string db_dump_data($query=0)
* - returns a string with all data of that query or if no query given with all data in the cursor_ext
* 0/$cursor db_exec($query=0)
@@ -135,13 +138,15 @@
* $string db_boolean(string)
* - if the string value is 't' or 'f' it returns correct TRUE/FALSE for php
* $primary_key db_write_data($write_array, $not_write_array, $primary_key, $table, $data = [])
* - writes into one table based on arrays of columns to write and not write, reads data from global vars or optional array
* - writes into one table based on arrays of columns to write and not write,
* - reads data from global vars or optional array
* $boolean db_set_schema(schema)
* - sets search path to a schema
* $boolean db_set_encoding(encoding)
* - sets an encoding for this database output and input
* $string db_time_format($age/datetime diff, $micro_time = false/true)
* - returns a nice formatted time string based on a age or datetime difference (postgres only), micro time is default false
* - returns a nice formatted time string based on a age or datetime difference
* - (postgres only), micro time is default false
*
* PRIVATE METHODS
* _db_error()
@@ -159,10 +164,12 @@
* string _db_debug_prepare($prepare_id, $data_array)
* - returns the prepared statement with the actual data. for debug purposes only
* none _db_debug($debug_id, $string, $id, $type)
* - wrapper for normal debug, adds prefix data from id & type and strips all HTML from the query data (color codes, etc) via flag to debug call
* - wrapper for normal debug, adds prefix data from id & type and strips
* - all HTML from the query data (color codes, etc) via flag to debug call
*
* HISTORY:
* 2008/10/25 (cs) add db_boolean to fix the postgres to php boolean var problem (TODO: implement this in any select return)
* 2008/10/25 (cs) add db_boolean to fix the postgres to php boolean var problem
* (TODO: implement this in any select return)
* 2008/07/03 (cs) add db_write_data function, original written for inventory tool "invSQLWriteData"
* 2008/04/16 (cs) add db_escape_string function for correct string escape
* 2007/11/14 (cs) add a prepare debug statement to replace the placeholders with the actual data in a prepared statement
@@ -241,6 +248,8 @@
* 23.11.2000: erster Test
*********************************************************************/
declare(strict_types=1);
namespace CoreLibs\DB;
class IO extends \CoreLibs\Basic
@@ -324,7 +333,8 @@ class IO extends \CoreLibs\Basic
$this->db_pwd = $db_config['db_pass'] ?? '';
$this->db_host = $db_config['db_host'] ?? '';
$this->db_port = !empty($db_config['db_port']) ? $db_config['db_port'] : 5432;
$this->db_schema = !empty($db_config['db_schema']) ? $db_config['db_schema'] : ''; // do not set to 'public' if not set, because the default is already public
// do not set to 'public' if not set, because the default is already public
$this->db_schema = !empty($db_config['db_schema']) ? $db_config['db_schema'] : '';
$this->db_encoding = !empty($db_config['db_encoding']) ? $db_config['db_encoding'] : '';
$this->db_type = $db_config['db_type'] ?? '';
$this->db_ssl = !empty($db_config['db_ssl']) ? $db_config['db_ssl'] : 'allow';
@@ -343,16 +353,19 @@ class IO extends \CoreLibs\Basic
$this->error_string['14'] = 'Can\'t connect to DB server';
$this->error_string['15'] = 'Can\'t select DB';
$this->error_string['16'] = 'No DB Handler found / connect or reconnect failed';
$this->error_string['17'] = 'All dbReturn* methods work only with SELECT statements, please use dbExec for everything else';
$this->error_string['17'] = 'All dbReturn* methods work only with SELECT statements, '
. 'please use dbExec for everything else';
$this->error_string['18'] = 'Query not found in cache. Nothing has been reset';
$this->error_string['19'] = 'Wrong PK name given or no PK name given at all, can\'t get Insert ID';
$this->error_string['20'] = 'Found given Prepare Statement Name in array, Query not prepared, will use existing one';
$this->error_string['20'] = 'Found given Prepare Statement Name in array, '
. 'Query not prepared, will use existing one';
$this->error_string['21'] = 'Query Prepare failed';
$this->error_string['22'] = 'Query Execute failed';
$this->error_string['23'] = 'Query Execute failed, data array does not match placeholders';
$this->error_string['24'] = 'Missing prepared query entry for execute.';
$this->error_string['25'] = 'Prepare query data is not in array format.';
$this->error_string['30'] = 'Query call in a possible endless loop. Was called more than '.$this->MAX_QUERY_CALL.' times';
$this->error_string['30'] = 'Query call in a possible endless loop. '
. 'Was called more than ' . $this->MAX_QUERY_CALL . ' times';
$this->error_string['31'] = 'Could not fetch PK after query insert';
$this->error_string['32'] = 'Multiple PK return as array';
$this->error_string['33'] = 'Returning PK was not found';
@@ -412,7 +425,14 @@ class IO extends \CoreLibs\Basic
private function __connectToDB(): bool
{
// generate connect string
$this->dbh = $this->db_functions->__dbConnect($this->db_host, $this->db_user, $this->db_pwd, $this->db_name, $this->db_port, $this->db_ssl);
$this->dbh = $this->db_functions->__dbConnect(
$this->db_host,
$this->db_user,
$this->db_pwd,
$this->db_name,
$this->db_port,
$this->db_ssl
);
// if no dbh here, we couldn't connect to the DB itself
if (!$this->dbh) {
$this->error_id = 14;
@@ -515,13 +535,13 @@ class IO extends \CoreLibs\Basic
$array = [];
}
foreach ($array as $key => $value) {
$string .= $this->nbsp.'<b>'.$key.'</b> => ';
$string .= $this->nbsp . '<b>' . $key . '</b> => ';
if (is_array($value)) {
$this->nbsp .= '&nbsp;&nbsp;&nbsp;';
$string .= '<br>';
$string .= $this->__printArray($value);
} else {
$string .= $value.'<br>';
$string .= $value . '<br>';
}
}
$this->nbsp = substr_replace($this->nbsp, '', -18, 18);
@@ -540,10 +560,10 @@ class IO extends \CoreLibs\Basic
{
$prefix = '';
if ($id) {
$prefix .= '[<span style="color: #920069;">'.$id.'</span>] ';
$prefix .= '[<span style="color: #920069;">' . $id . '</span>] ';
}
if ($type) {
$prefix .= '{<span style="font-style: italic; color: #3f0092;">'.$type.'</span>} ';
$prefix .= '{<span style="font-style: italic; color: #3f0092;">' . $type . '</span>} ';
}
if ($prefix) {
$prefix .= '- ';
@@ -576,12 +596,26 @@ class IO extends \CoreLibs\Basic
// okay, an error occured
if ($this->error_id) {
// write error msg ...
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$this->error_id.': '.$this->error_string[$this->error_id].($msg ? ', '.$msg : '').'</span>', 'DB_ERROR', $where_called);
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $this->error_id . ': '
. $this->error_string[$this->error_id] . ($msg ? ', ' . $msg : '')
. '</span>',
'DB_ERROR',
$where_called
);
$this->had_error = $this->error_id;
// write detailed error log
}
if ($this->warning_id) {
$this->__dbDebug('db', '<span style="color: orange;"><b>DB-Warning</b> '.$this->warning_id.': '.$this->error_string[$this->warning_id].($msg ? ', '.$msg : '').'</span>', 'DB_WARNING', $where_called);
$this->__dbDebug(
'db',
'<span style="color: orange;"><b>DB-Warning</b> ' . $this->warning_id . ': '
. $this->error_string[$this->warning_id]
. ($msg ? ', ' . $msg : '') . '</span>',
'DB_WARNING',
$where_called
);
$this->had_warning = $this->warning_id;
}
// unset the error/warning vars
@@ -597,7 +631,8 @@ class IO extends \CoreLibs\Basic
private function __dbConvertEncoding($row)
{
// only do if array, else pass through row (can be false)
if (!is_array($row) || empty($this->to_encoding) || empty($this->db_encoding)
if (
!is_array($row) || empty($this->to_encoding) || empty($this->db_encoding)
) {
return $row;
}
@@ -623,8 +658,8 @@ class IO extends \CoreLibs\Basic
// get the keys from data array
$keys = array_keys($data);
// because the placeholders start with $ and at 1, we need to increase each key and prefix it with a $ char
for ($i = 0, $iMax = count($keys); $i < $iMax; $i ++) {
$keys[$i] = '$'.($keys[$i] + 1);
for ($i = 0, $iMax = count($keys); $i < $iMax; $i++) {
$keys[$i] = '$' . ($keys[$i] + 1);
}
// simply replace the $1, $2, ... with the actual data and return it
return str_replace(array_reverse($keys), array_reverse($data), $this->prepare_cursor[$stm_name]['query']);
@@ -660,7 +695,7 @@ class IO extends \CoreLibs\Basic
*/
private function __dbPrepareExec(string $query, string $pk_name)
{
$matches= [];
$matches = [];
// to either use the returning method or the guess method for getting primary keys
$this->returning_id = false;
// set the query
@@ -702,13 +737,13 @@ class IO extends \CoreLibs\Basic
if (!preg_match("/ returning /i", $this->query) && $this->pk_name && $this->pk_name != 'NULL') {
// check if this query has a ; at the end and remove it
$this->query = preg_replace("/(;\s*)$/", '', $this->query);
$this->query .= " RETURNING ".$this->pk_name;
$this->query .= " RETURNING " . $this->pk_name;
$this->returning_id = true;
} elseif (preg_match("/ returning (.*)/i", $this->query, $matches)) {
if ($this->pk_name && $this->pk_name != 'NULL') {
// add the primary key if it is not in the returning set
if (!preg_match("/$this->pk_name/", $matches[1])) {
$this->query .= " , ".$this->pk_name;
$this->query .= " , " . $this->pk_name;
}
}
$this->returning_id = true;
@@ -736,7 +771,8 @@ class IO extends \CoreLibs\Basic
}
// count up the run, if this is run more than the max_run then exit with error
// if set to -1, then ignore it
if ($this->MAX_QUERY_CALL != -1 &&
if (
$this->MAX_QUERY_CALL != -1 &&
$this->query_called[$md5] > $this->MAX_QUERY_CALL
) {
$this->error_id = 30;
@@ -775,14 +811,15 @@ class IO extends \CoreLibs\Basic
$this->num_fields = $this->db_functions->__dbNumFields($this->cursor);
// set field names
$this->field_names = [];
for ($i = 0; $i < $this->num_fields; $i ++) {
for ($i = 0; $i < $this->num_fields; $i++) {
$this->field_names[] = $this->db_functions->__dbFieldName($this->cursor, $i);
}
} elseif ($this->__checkQueryForInsert($this->query)) {
// if not select do here
// count affected rows
$this->num_rows = $this->db_functions->__dbAffectedRows($this->cursor);
if (($this->__checkQueryForInsert($this->query, true) && $this->pk_name != 'NULL') ||
if (
($this->__checkQueryForInsert($this->query, true) && $this->pk_name != 'NULL') ||
($this->__checkQueryForUpdate($this->query) && $this->returning_id)
) {
// set insert_id
@@ -798,22 +835,30 @@ class IO extends \CoreLibs\Basic
// echo "** PREPARE RETURNING FOR CURSOR: ".$this->cursor."<br>";
// we have returning, now we need to check if we get one or many returned
// we'll need to loop this, if we have multiple insert_id returns
while ($_insert_id = $this->db_functions->__dbFetchArray(
$this->cursor,
$this->db_functions->__dbResultType(true)
)) {
while (
$_insert_id = $this->db_functions->__dbFetchArray(
$this->cursor,
$this->db_functions->__dbResultType(true)
)
) {
// echo "*** RETURNING: ".print_r($_insert_id, true)."<br>";
$this->insert_id[] = $_insert_id;
$this->insert_id_arr[] = $_insert_id;
}
// if we have only one, revert from array to single
if (count($this->insert_id) == 1) {
// echo "* SINGLE DATA CONVERT: ".count($this->insert_id[0])." => ".array_key_exists($this->pk_name, $this->insert_id[0])."<br>";
// echo "* PK DIRECT: ".(isset($this->insert_id[0][$this->pk_name]) ? $this->insert_id[0][$this->pk_name] : '[NO PK NAME SET]' )."<Br>";
// if this has only the pk_name, then only return this, else array of all data (but without the position)
// example if insert_id[0]['foo'] && insert_id[0]['bar'] it will become insert_id['foo'] & insert_id['bar']
// if only ['foo_id'] and it is the PK then the PK is directly written to the insert_id
if (count($this->insert_id[0]) > 1 ||
// $this->log->debug('SINGLE DATA CONVERT', count($this->insert_id[0])." => "
// .array_key_exists($this->pk_name, $this->insert_id[0]));
// $this->log->debug('PK DIRECT', (isset($this->insert_id[0][$this->pk_name]) ?
// $this->insert_id[0][$this->pk_name] : '[NO PK NAME SET]' ));
// if this has only the pk_name, then only return this,
// else array of all data (but without the position)
// example if insert_id[0]['foo'] && insert_id[0]['bar']
// it will become insert_id['foo'] & insert_id['bar']
// if only ['foo_id'] and it is the PK then the
// PK is directly written to the insert_id
if (
count($this->insert_id[0]) > 1 ||
!array_key_exists($this->pk_name, $this->insert_id[0])
) {
$this->insert_id_ext = $this->insert_id[0];
@@ -916,7 +961,8 @@ class IO extends \CoreLibs\Basic
return false;
}
// ok entry, set
if ($max_calls == -1 ||
if (
$max_calls == -1 ||
$max_calls > 0
) {
$this->MAX_QUERY_CALL = $max_calls;
@@ -997,7 +1043,7 @@ class IO extends \CoreLibs\Basic
if (!$db_schema) {
return false;
}
$q = "SET search_path TO '".$this->dbEscapeString($db_schema)."'";
$q = "SET search_path TO '" . $this->dbEscapeString($db_schema) . "'";
return $this->dbExec($q);
}
@@ -1023,7 +1069,7 @@ class IO extends \CoreLibs\Basic
if (!$db_encoding) {
return false;
}
$q = "SET client_encoding TO '".$this->dbEscapeString($db_encoding)."'";
$q = "SET client_encoding TO '" . $this->dbEscapeString($db_encoding) . "'";
return $this->dbExec($q);
}
@@ -1067,18 +1113,18 @@ class IO extends \CoreLibs\Basic
public function dbInfo(bool $show = true): string
{
$string = '';
$string .= '{b}-DB-info->{/b} Connected to db {b}\''.$this->db_name.'\'{/b} ';
$string .= 'with schema {b}\''.$this->db_schema.'\'{/b} ';
$string .= 'as user {b}\''.$this->db_user.'\'{/b} ';
$string .= 'at host {b}\''.$this->db_host.'\'{/b} ';
$string .= 'on port {b}\''.$this->db_port.'\'{/b} ';
$string .= 'with ssl mode {b}\''.$this->db_ssl.'\'{/b}{br}';
$string .= '{b}-DB-info->{/b} DB IO Class debug output: {b}'.($this->db_debug ? 'Yes' : 'No').'{/b}';
$string .= '{b}-DB-info->{/b} Connected to db {b}\'' . $this->db_name . '\'{/b} ';
$string .= 'with schema {b}\'' . $this->db_schema . '\'{/b} ';
$string .= 'as user {b}\'' . $this->db_user . '\'{/b} ';
$string .= 'at host {b}\'' . $this->db_host . '\'{/b} ';
$string .= 'on port {b}\'' . $this->db_port . '\'{/b} ';
$string .= 'with ssl mode {b}\'' . $this->db_ssl . '\'{/b}{br}';
$string .= '{b}-DB-info->{/b} DB IO Class debug output: {b}' . ($this->db_debug ? 'Yes' : 'No') . '{/b}';
if ($show === true) {
// if debug, remove / change b
$this->__dbDebug('db', str_replace(['{b}', '{/b}', '{br}'], ['', '', ' **** '], $string), 'dbInfo');
} else {
$string = $string.'{br}';
$string = $string . '{br}';
}
// for direct print, change to html
return str_replace(['{b}', '{/b}', '{br}'], ['<b>', '</b>', '<br>'], $string);
@@ -1120,8 +1166,12 @@ class IO extends \CoreLibs\Basic
* - if set to 3, after EACH row, the data will be reset,
* no caching is done except for basic (count, etc)
* @param string $query Query string
* @param int $reset reset status: 1: read cache, clean at the end, 2: read new, clean at end, 3: never cache
* @param bool $assoc_only true to only returned the named and not index position ones
* @param int $reset reset status:
* 1: read cache, clean at the end
* 2: read new, clean at end
* 3: never cache
* @param bool $assoc_only true to only returned the named and not
* index position ones
* @return array|bool return array data or false on error/end
* @suppress PhanTypeMismatchDimFetch
*/
@@ -1161,7 +1211,9 @@ class IO extends \CoreLibs\Basic
if ($reset && !$this->cursor_ext[$md5]['pos']) {
$this->cursor_ext[$md5]['cursor'] = null;
}
// $this->debug('MENU', 'Reset: '.$reset.', Cursor: '.$this->cursor_ext[$md5]['cursor'].', Pos: '.$this->cursor_ext[$md5]['pos'].', Query: '.$query);
// $this->debug('MENU', 'Reset: '.$reset.', Cursor: '
// .$this->cursor_ext[$md5]['cursor'].', Pos: '.$this->cursor_ext[$md5]['pos']
// .', Query: '.$query);
// if no cursor yet, execute
if (!$this->cursor_ext[$md5]['cursor']) {
@@ -1203,12 +1255,18 @@ class IO extends \CoreLibs\Basic
if ($this->cursor_ext[$md5]['cursor']) {
if ($this->cursor_ext[$md5]['firstcall'] == 1) {
// count the rows returned (if select)
$this->cursor_ext[$md5]['num_rows'] = $this->db_functions->__dbNumRows($this->cursor_ext[$md5]['cursor']);
$this->cursor_ext[$md5]['num_rows'] =
$this->db_functions->__dbNumRows($this->cursor_ext[$md5]['cursor']);
// count the fields
$this->cursor_ext[$md5]['num_fields'] = $this->db_functions->__dbNumFields($this->cursor_ext[$md5]['cursor']);
$this->cursor_ext[$md5]['num_fields'] =
$this->db_functions->__dbNumFields($this->cursor_ext[$md5]['cursor']);
// set field names
for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i ++) {
$this->cursor_ext[$md5]['field_names'][] = $this->db_functions->__dbFieldName($this->cursor_ext[$md5]['cursor'], $i);
for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i++) {
$this->cursor_ext[$md5]['field_names'][] =
$this->db_functions->__dbFieldName(
$this->cursor_ext[$md5]['cursor'],
$i
);
}
// reset first call vars
$this->cursor_ext[$md5]['firstcall'] = 0;
@@ -1237,24 +1295,34 @@ class IO extends \CoreLibs\Basic
// check if end of output ...
if ($this->cursor_ext[$md5]['pos'] >= $this->cursor_ext[$md5]['num_rows']) {
$this->cursor_ext[$md5]['pos'] = 0;
# if not reset given, set the cursor to true, so in a cached call on a different page we don't get problems from DB connection (as those will be LOST)
// if not reset given, set the cursor to true, so in a cached
// call on a different page we don't get problems from
// DB connection (as those will be LOST)
$this->cursor_ext[$md5]['cursor'] = 1;
$return = false;
} else {
// unset return value ...
$return = [];
for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i ++) {
for ($i = 0; $i < $this->cursor_ext[$md5]['num_fields']; $i++) {
// create mixed return array
if ($assoc_only === false && isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])) {
if (
$assoc_only === false &&
isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])
) {
$return[$i] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i];
}
// named part
if (isset($this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i])) {
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$i];
$return[$this->cursor_ext[$md5]['field_names'][$i]] =
$this->cursor_ext[$md5]['data']
[$this->cursor_ext[$md5]['pos']][$i];
} else {
// throws PhanTypeMismatchDimFetch error, but in this case we know we will access only named array parts
// throws PhanTypeMismatchDimFetch error, but in this
// case we know we will access only named array parts
// @suppress PhanTypeMismatchDimFetch
$return[$this->cursor_ext[$md5]['field_names'][$i]] = $this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]['pos']][$this->cursor_ext[$md5]['field_names'][$i]];
$return[$this->cursor_ext[$md5]['field_names'][$i]] =
$this->cursor_ext[$md5]['data'][$this->cursor_ext[$md5]
['pos']][$this->cursor_ext[$md5]['field_names'][$i]];
}
}
$this->cursor_ext[$md5]['pos'] ++;
@@ -1393,7 +1461,12 @@ class IO extends \CoreLibs\Basic
} else {
// if no async running print error
$this->error_id = 42;
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> No async query has been started yet.</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> No async query '
. 'has been started yet.</span>',
'DB_ERROR'
);
return false;
}
}
@@ -1471,7 +1544,7 @@ class IO extends \CoreLibs\Basic
$rows = [];
while ($res = $this->dbFetchArray($cursor, $assoc_only)) {
$data = [];
for ($i = 0; $i < $this->num_fields; $i ++) {
for ($i = 0; $i < $this->num_fields; $i++) {
$data[$this->field_names[$i]] = $res[$this->field_names[$i]];
}
$rows[] = $data;
@@ -1519,7 +1592,7 @@ class IO extends \CoreLibs\Basic
*/
public function dbShowTableMetaData(string $table, string $schema = '')
{
$table = ($schema ? $schema.'.' : '').$table;
$table = ($schema ? $schema . '.' : '') . $table;
$array = $this->db_functions->__dbMetaData($table);
if (!is_array($array)) {
@@ -1580,12 +1653,15 @@ class IO extends \CoreLibs\Basic
}
// if no returning, then add it
if (!preg_match("/ returning /i", $query) && $this->prepare_cursor[$stm_name]['pk_name']) {
$query .= " RETURNING ".$this->prepare_cursor[$stm_name]['pk_name'];
$query .= " RETURNING " . $this->prepare_cursor[$stm_name]['pk_name'];
$this->prepare_cursor[$stm_name]['returning_id'] = true;
} elseif (preg_match("/ returning (.*)/i", $query, $matches) && $this->prepare_cursor[$stm_name]['pk_name']) {
} elseif (
preg_match("/ returning (.*)/i", $query, $matches) &&
$this->prepare_cursor[$stm_name]['pk_name']
) {
// if returning exists but not pk_name, add it
if (!preg_match("/{$this->prepare_cursor[$stm_name]['pk_name']}/", $matches[1])) {
$query .= " , ".$this->prepare_cursor[$stm_name]['pk_name'];
$query .= " , " . $this->prepare_cursor[$stm_name]['pk_name'];
}
$this->prepare_cursor[$stm_name]['returning_id'] = true;
}
@@ -1606,7 +1682,13 @@ class IO extends \CoreLibs\Basic
} else {
$this->error_id = 21;
$this->__dbError();
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Prepare field with: '.$stm_name.' | '.$query.'</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $stm_name
. ': Prepare field with: ' . $stm_name . ' | '
. $query . '</span>',
'DB_ERROR'
);
return $result;
}
} else {
@@ -1627,17 +1709,34 @@ class IO extends \CoreLibs\Basic
// if we do not have no prepare cursor array entry for this statement name, abort
if (!is_array($this->prepare_cursor[$stm_name])) {
$this->error_id = 24;
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': We do not have a prepared query entry for this statement name.</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $stm_name
. ': We do not have a prepared query entry for this statement name.</span>',
'DB_ERROR'
);
return false;
}
if (!is_array($data)) {
$this->error_id = 25;
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Prepared query Data has to be given in array form.</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $stm_name
. ': Prepared query Data has to be given in array form.</span>',
'DB_ERROR'
);
return false;
}
if ($this->prepare_cursor[$stm_name]['count'] != count($data)) {
$this->error_id = 23;
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Array data count does not match prepared fields. Need: '.$this->prepare_cursor[$stm_name]['count'].', has: '.count($data).'</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $stm_name
. ': Array data count does not match prepared fields. Need: '
. $this->prepare_cursor[$stm_name]['count'] . ', has: '
. count($data) . '</span>',
'DB_ERROR'
);
return false;
}
if ($this->db_debug) {
@@ -1645,17 +1744,28 @@ class IO extends \CoreLibs\Basic
}
$result = $this->db_functions->__dbExecute($stm_name, $data);
if (!$result) {
$this->log->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->log->prAr($data));
$this->log->debug('ExecuteData', 'ERROR in STM[' . $stm_name . '|'
. $this->prepare_cursor[$stm_name]['result'] . ']: '
. $this->log->prAr($data));
$this->error_id = 22;
$this->__dbError($this->prepare_cursor[$stm_name]['result']);
$this->__dbDebug('db', '<span style="color: red;"><b>DB-Error</b> '.$stm_name.': Execution failed</span>', 'DB_ERROR');
$this->__dbDebug(
'db',
'<span style="color: red;"><b>DB-Error</b> ' . $stm_name
. ': Execution failed</span>',
'DB_ERROR'
);
return false;
}
if ($this->__checkQueryForInsert($this->prepare_cursor[$stm_name]['query'], true) &&
if (
$this->__checkQueryForInsert($this->prepare_cursor[$stm_name]['query'], true) &&
$this->prepare_cursor[$stm_name]['pk_name'] != 'NULL'
) {
if (!$this->prepare_cursor[$stm_name]['returning_id']) {
$this->insert_id = $this->db_functions->__dbInsertId($this->prepare_cursor[$stm_name]['query'], $this->prepare_cursor[$stm_name]['pk_name']);
$this->insert_id = $this->db_functions->__dbInsertId(
$this->prepare_cursor[$stm_name]['query'],
$this->prepare_cursor[$stm_name]['pk_name']
);
$this->insert_id_ext = $this->insert_id;
$this->insert_id_arr[] = $this->insert_id;
} elseif ($result) {
@@ -1664,21 +1774,28 @@ class IO extends \CoreLibs\Basic
$this->insert_id_arr = [];
// we have returning, now we need to check if we get one or many returned
// we'll need to loop this, if we have multiple insert_id returns
while ($_insert_id = $this->db_functions->__dbFetchArray(
$result,
$this->db_functions->__dbResultType(true)
)) {
while (
$_insert_id = $this->db_functions->__dbFetchArray(
$result,
$this->db_functions->__dbResultType(true)
)
) {
$this->insert_id[] = $_insert_id;
$this->insert_id_arr[] = $_insert_id;
}
// if we have only one, revert from arry to single
if (count($this->insert_id) == 1) {
// echo "+ SINGLE DATA CONVERT: ".count($this->insert_id[0])." => ".array_key_exists($this->prepare_cursor[$stm_name]['pk_name'], $this->insert_id[0])."<br>";
// echo "+ PK DIRECT: ".$this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']]."<Br>";
// if this has only the pk_name, then only return this, else array of all data (but without the position)
// example if insert_id[0]['foo'] && insert_id[0]['bar'] it will become insert_id['foo'] & insert_id['bar']
// if only ['foo_id'] and it is the PK then the PK is directly written to the insert_id
if (count($this->insert_id[0]) > 1 ||
// $this->log->debug('SINGLE DATA CONVERT', count($this->insert_id[0])." => "
// .array_key_exists($this->prepare_cursor[$stm_name]['pk_name'], $this->insert_id[0]));
// $this->log->debug('PK DIRECT', $this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']]);
// if this has only the pk_name, then only return this,
// else array of all data (but without the position)
// example if insert_id[0]['foo'] && insert_id[0]['bar']
// it will become insert_id['foo'] & insert_id['bar']
// if only ['foo_id'] and it is the PK then the PK is directly
// written to the insert_id
if (
count($this->insert_id[0]) > 1 ||
!array_key_exists($this->prepare_cursor[$stm_name]['pk_name'], $this->insert_id[0])
) {
$this->insert_id_ext = $this->insert_id[0];
@@ -1691,19 +1808,34 @@ class IO extends \CoreLibs\Basic
$this->insert_id = '';
$this->warning_id = 33;
$this->__dbError();
$this->__dbDebug('db', '<span style="color: orange;"><b>DB-Warning</b> '.$stm_name.': insert id returned no data</span>', 'DB_WARNING');
$this->__dbDebug(
'db',
'<span style="color: orange;"><b>DB-Warning</b> ' . $stm_name
. ': insert id returned no data</span>',
'DB_WARNING'
);
}
}
// this error handling is only for pgsql
if (is_array($this->insert_id)) {
$this->warning_id = 32;
$this->__dbError();
$this->__dbDebug('db', '<span style="color: orange;"><b>DB-Warning</b> '.$stm_name.': insert id data returned as array</span>', 'DB_WARNING');
$this->__dbDebug(
'db',
'<span style="color: orange;"><b>DB-Warning</b> ' . $stm_name
. ': insert id data returned as array</span>',
'DB_WARNING'
);
} elseif (!$this->insert_id) {
// NOTE should we keep this inside
$this->warning_id = 31;
$this->__dbError();
$this->__dbDebug('db', '<span style="color: orange;"><b>DB-Warning</b> '.$stm_name.': Could not get insert id</span>', 'DB_WARNING');
$this->__dbDebug(
'db',
'<span style="color: orange;"><b>DB-Warning</b> ' . $stm_name
. ': Could not get insert id</span>',
'DB_WARNING'
);
}
}
return $result;
@@ -1765,14 +1897,14 @@ class IO extends \CoreLibs\Basic
if (!$compare || !$to_master || !$to_minor) {
return false;
} else {
$to_version = $to_master.($to_minor < 10 ? '0' : '').$to_minor;
$to_version = $to_master . ($to_minor < 10 ? '0' : '') . $to_minor;
}
// db_version can return X.Y.Z
// we only compare the first two
preg_match("/^(\d{1,})\.(\d{1,})\.?(\d{1,})?/", $this->dbVersion(), $matches);
$master = $matches[1];
$minor = $matches[2];
$version = $master.($minor < 10 ? '0' : '').$minor;
$version = $master . ($minor < 10 ? '0' : '') . $minor;
$return = false;
// compare
switch ($compare) {
@@ -1852,8 +1984,13 @@ class IO extends \CoreLibs\Basic
* @param array $data data array to override _POST data
* @return int|bool primary key
*/
public function dbWriteData(array $write_array, array $not_write_array, $primary_key, string $table, $data = [])
{
public function dbWriteData(
array $write_array,
array $not_write_array,
int $primary_key,
string $table,
array $data = []
) {
if (!is_array($write_array)) {
$write_array = [];
}
@@ -1864,7 +2001,14 @@ class IO extends \CoreLibs\Basic
return false;
}
$not_write_update_array = [];
return $this->dbWriteDataExt($write_array, $primary_key, $table, $not_write_array, $not_write_update_array, $data);
return $this->dbWriteDataExt(
$write_array,
$primary_key,
$table,
$not_write_array,
$not_write_update_array,
$data
);
}
/**
@@ -1890,7 +2034,7 @@ class IO extends \CoreLibs\Basic
) {
if (!is_array($primary_key)) {
$primary_key = [
'row' => $table.'_id',
'row' => $table . '_id',
'value' => $primary_key
];
} else {
@@ -1905,13 +2049,14 @@ class IO extends \CoreLibs\Basic
$q_sub_value = '';
$q_sub_data = '';
// get the table layout and row types
$table_data = $this->dbShowTableMetaData(($this->db_schema ? $this->db_schema.'.' : '').$table);
$table_data = $this->dbShowTableMetaData(($this->db_schema ? $this->db_schema . '.' : '') . $table);
// @phan HACK
$primary_key['value'] = $primary_key['value'] ?? '';
$primary_key['row'] = $primary_key['row'] ?? '';
// loop through the write array and each field to build the query
foreach ($write_array as $field) {
if ((!$primary_key['value'] ||
if (
(!$primary_key['value'] ||
($primary_key['value'] &&
!in_array($field, $not_write_update_array))
) &&
@@ -1936,8 +2081,11 @@ class IO extends \CoreLibs\Basic
}
// we detect bool, so we can force a write on "false"
$is_bool = $table_data[$field]['type'] == 'bool' ? true : false;
// write if the field has to be not null, or if there is no data and the field has no default values or if there is data or if this is an update and there is no data (set null)
if (($not_null && $_data) ||
// write if the field has to be not null, or if there is
// no data and the field has no default values or if there
// is data or if this is an update and there is no data (set null)
if (
($not_null && $_data) ||
(!$has_default && !$_data) ||
(is_numeric($_data) && $_data) ||
($primary_key['value'] && !$_data) ||
@@ -1946,11 +2094,13 @@ class IO extends \CoreLibs\Basic
if ($q_sub_value && !$primary_key['value']) {
$q_sub_value .= ', ';
}
if ($q_sub_data) { // && (!$primary_key || ($primary_key && !in_array($field, $not_write_array))))
if ($q_sub_data) {
// && (!$primary_key ||
// ($primary_key && !in_array($field, $not_write_array))))
$q_sub_data .= ', ';
}
if ($primary_key['value']) {
$q_sub_data .= $field.' = ';
$q_sub_data .= $field . ' = ';
} else {
$q_sub_value .= $field;
}
@@ -1963,7 +2113,13 @@ class IO extends \CoreLibs\Basic
$q_sub_data .= is_numeric($_data) ? $_data : 'NULL';
} else {
// if bool -> set bool, else write data
$q_sub_data .= isset($_data) ? "'".($is_bool ? $this->dbBoolean($_data, true) : $this->dbEscapeString($_data))."'" : 'NULL';
$q_sub_data .= isset($_data) ?
"'" . (
$is_bool ?
$this->dbBoolean($_data, true) :
$this->dbEscapeString($_data)
) . "'" :
'NULL';
}
}
}
@@ -1971,12 +2127,12 @@ class IO extends \CoreLibs\Basic
// first work contact itself (we need contact id for everything else)
if ($primary_key['value'] && $primary_key['row']) {
$q = 'UPDATE '.$table.' SET ';
$q .= $q_sub_data.' ';
$q .= 'WHERE '.$primary_key['row'].' = '.$primary_key['value'];
$q = 'UPDATE ' . $table . ' SET ';
$q .= $q_sub_data . ' ';
$q .= 'WHERE ' . $primary_key['row'] . ' = ' . $primary_key['value'];
$this->temp_sql = $q_sub_data;
} else {
$q = 'INSERT INTO '.$table.' (';
$q = 'INSERT INTO ' . $table . ' (';
$q .= $q_sub_value;
$q .= ') VALUES (';
$q .= $q_sub_data;
@@ -2013,7 +2169,11 @@ class IO extends \CoreLibs\Basic
$seconds = $matches[4] != '00' ? preg_replace('/^0/', '', $matches[4]) : '';
$milliseconds = $matches[6];
return $prefix.($hour ? $hour.'h ' : '').($minutes ? $minutes.'m ' : '').($seconds ? $seconds.'s' : '').($show_micro && $milliseconds? ' '.$milliseconds.'ms' : '');
return $prefix
. ($hour ? $hour . 'h ' : '')
. ($minutes ? $minutes . 'm ' : '')
. ($seconds ? $seconds . 's' : '')
. ($show_micro && $milliseconds ? ' ' . $milliseconds . 'ms' : '');
}
/**
@@ -2043,10 +2203,10 @@ class IO extends \CoreLibs\Basic
$value = $value === '' ? "NULL" : floatval($value);
break;
case 't':
$value = $value === '' ? "NULL" : "'".$this->dbEscapeString($value)."'";
$value = $value === '' ? "NULL" : "'" . $this->dbEscapeString($value) . "'";
break;
case 'd':
$value = $value === '' ? "NULL" : "'".$this->dbEscapeString($value)."'";
$value = $value === '' ? "NULL" : "'" . $this->dbEscapeString($value) . "'";
break;
case 'i2':
$value = $value === '' ? 0 : intval($value);
@@ -2156,7 +2316,7 @@ class IO extends \CoreLibs\Basic
*/
public function getInsertReturn($key = null)
{
trigger_error('Method '.__METHOD__.' is deprecated, use getReturningExt($key = null)', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use getReturningExt($key = null)', E_USER_DEPRECATED);
return $this->dbGetReturningExt($key);
}
@@ -2167,7 +2327,7 @@ class IO extends \CoreLibs\Basic
*/
public function getReturning()
{
trigger_error('Method '.__METHOD__.' is deprecated, use dbGetReturning()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetReturning()', E_USER_DEPRECATED);
return $this->dbGetReturning();
}
@@ -2178,7 +2338,7 @@ class IO extends \CoreLibs\Basic
*/
public function getInsertPK()
{
trigger_error('Method '.__METHOD__.' is deprecated, use dbGetInsertPK()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetInsertPK()', E_USER_DEPRECATED);
return $this->dbGetReturning();
}
@@ -2190,7 +2350,7 @@ class IO extends \CoreLibs\Basic
*/
public function getReturningExt($key = null)
{
trigger_error('Method '.__METHOD__.' is deprecated, use dbGetReturningExt($key = null)', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetReturningExt($key = null)', E_USER_DEPRECATED);
return $this->dbGetReturningExt($key);
}
@@ -2202,7 +2362,7 @@ class IO extends \CoreLibs\Basic
*/
public function getCursorExt($q = null)
{
trigger_error('Method '.__METHOD__.' is deprecated, use dbGetCursorExt($q = null)', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetCursorExt($q = null)', E_USER_DEPRECATED);
return $this->dbGetCursorExt($q);
}
@@ -2213,9 +2373,10 @@ class IO extends \CoreLibs\Basic
*/
public function getNumRows()
{
trigger_error('Method '.__METHOD__.' is deprecated, use dbGetNumRows()', E_USER_DEPRECATED);
trigger_error('Method ' . __METHOD__ . ' is deprecated, use dbGetNumRows()', E_USER_DEPRECATED);
return $this->dbGetNumRows();
}
} // end if db class
// end if db class
}
// __END__

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2003/04/09
@@ -11,7 +12,9 @@
* 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/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
@@ -41,6 +44,8 @@
*
*/
declare(strict_types=1);
namespace CoreLibs\DB\SQL;
class PgSQL
@@ -258,9 +263,9 @@ class PgSQL
// if (preg_match("/.*s$/i", $table))
// $table = substr($table, 0, -1);
// set pk_name to "id"
$pk_name = $table."_id";
$pk_name = $table . "_id";
}
$seq = ($schema ? $schema.'.' : '').$table."_".$pk_name."_seq";
$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 ...
if ($q = $this->__dbQuery($q)) {
@@ -288,27 +293,28 @@ class PgSQL
$cursor = $this->__dbQuery($q);
$search_path = $this->__dbFetchArray($cursor)['search_path'];
if ($search_path != $schema) {
$table_prefix = $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 ";
$q = "SELECT pg_attribute.attname AS column_name, "
. "format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type "
. "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 ";
$q .= "WHERE "
// regclass translates the OID to the name
. "pg_class.oid = '" . $table_prefix . $table . "'::regclass AND "
. "indrelid = pg_class.oid AND ";
if ($schema) {
$q .= "nspname = '".$schema."' AND ";
$q .= "pg_class.relnamespace = pg_namespace.oid AND ";
$q .= "nspname = '" . $schema . "' AND "
. "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";
$q .= "pg_attribute.attrelid = pg_class.oid AND "
. "pg_attribute.attnum = any(pg_index.indkey) "
. "AND indisprimary";
$cursor = $this->__dbQuery($q);
if ($cursor) {
return $this->__dbFetchArray($cursor)['column_name'] ?? false;
@@ -330,15 +336,23 @@ class PgSQL
* @param string $db_ssl SSL (allow is default)
* @return ?resource db handler resource or null on error
*/
public function __dbConnect(string $db_host, string $db_user, string $db_pass, string $db_name, int $db_port = 5432, string $db_ssl = 'allow')
{
public function __dbConnect(
string $db_host,
string $db_user,
string $db_pass,
string $db_name,
int $db_port = 5432,
string $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);
$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."] //-->");
die("<!-- Can't connect [host=" . $db_host . " port=" . $db_port . " user="
. $db_user . " password=XXXX dbname=" . $db_name . " sslmode=" . $db_ssl . "] //-->");
return null;
}
return $this->dbh;
@@ -359,7 +373,7 @@ class PgSQL
$cursor = pg_get_result($this->dbh);
}
if ($cursor && pg_result_error($cursor)) {
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> ".pg_result_error($cursor)."</span><br>";
return "<span style=\"color: red;\"><b>-PostgreSQL-Error-></b> " . pg_result_error($cursor) . "</span><br>";
} else {
return '';
}

View File

@@ -1,10 +1,12 @@
<?php declare(strict_types=1);
<?php
/*
* direct write to log file
* must have BASE folder and LOG foder defined
*/
declare(strict_types=1);
namespace CoreLibs\Debug;
class FileWriter
@@ -40,10 +42,10 @@ class FileWriter
if (!self::$debug_filename) {
return false;
}
if (!is_writeable(BASE.LOG)) {
if (!is_writeable(BASE . LOG)) {
return false;
}
$filename = BASE.LOG.self::$debug_filename;
$filename = BASE . LOG . self::$debug_filename;
$fh = fopen($filename, 'a');
if ($fh === false) {
return false;
@@ -51,7 +53,8 @@ class FileWriter
if ($enter === true) {
$string .= "\n";
}
$string = "[".\CoreLibs\Debug\Support::printTime()."] [".\CoreLibs\Get\System::getPageName(2)."] - ".$string;
$string = "[" . \CoreLibs\Debug\Support::printTime() . "] "
. "[" . \CoreLibs\Get\System::getPageName(2) . "] - " . $string;
fwrite($fh, $string);
fclose($fh);
return true;

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
* Debug support functions
@@ -20,6 +20,8 @@
 * print_output_not
*/
declare(strict_types=1);
namespace CoreLibs\Debug;
class Logging
@@ -63,11 +65,11 @@ class Logging
{
// check must set constants
if (defined('BASE') && defined('LOG')) {
$this->log_folder = BASE.LOG;
$this->log_folder = BASE . LOG;
} else {
// fallback + warning
trigger_error('constant BASE or LOG are not defined, fallback to getcwd()', E_USER_WARNING);
$this->log_folder = getcwd().DS;
$this->log_folder = getcwd() . DS;
}
// running time start for script
$this->script_starttime = microtime(true);
@@ -79,7 +81,7 @@ class Logging
list($this->host_name , $this->host_port) = \CoreLibs\Get\System::getHostName();
// add port to host name if not port 80
if ($this->host_port != 80) {
$this->host_name .= ':'.$this->host_port;
$this->host_name .= ':' . $this->host_port;
}
// can be overridden with basicSetLogFileId
if (isset($GLOBALS['LOG_FILE_ID'])) {
@@ -152,7 +154,8 @@ class Logging
// check if we do debug, echo or print
switch ($target) {
case 'debug':
if ((
if (
(
(isset($this->debug_output[$level]) && $this->debug_output[$level]) ||
$this->debug_output_all
) &&
@@ -164,7 +167,8 @@ class Logging
}
break;
case 'echo':
if ((
if (
(
(isset($this->echo_output[$level]) && $this->echo_output[$level]) ||
$this->echo_output_all
) &&
@@ -176,7 +180,8 @@ class Logging
}
break;
case 'print':
if ((
if (
(
(isset($this->print_output[$level]) && $this->print_output[$level]) ||
$this->print_output_all
) &&
@@ -200,7 +205,8 @@ class Logging
private function writeErrorMsg(string $level, string $error_string): bool
{
// only write if write is requested
if (!($this->doDebugTrigger('debug', $level) &&
if (
!($this->doDebugTrigger('debug', $level) &&
$this->doDebugTrigger('print', $level))
) {
return false;
@@ -214,10 +220,10 @@ class Logging
// init output variable
$output = $error_string; // output formated error string to output file
// init base file path
$fn = $this->log_folder.$this->log_print_file.'.'.$this->log_file_name_ext;
$fn = $this->log_folder . $this->log_print_file . '.' . $this->log_file_name_ext;
// log ID prefix settings, if not valid, replace with empty
if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) {
$rpl_string = '_'.$this->log_file_id;
$rpl_string = '_' . $this->log_file_id;
} else {
$rpl_string = '';
}
@@ -228,28 +234,33 @@ class Logging
$this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID'];
}
if (!$this->log_file_unique_id) {
$GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
$GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id =
date('Y-m-d_His') . '_U_'
. substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8);
}
$rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string
$rpl_string = '_' . $this->log_file_unique_id; // add 8 char unique string
} else {
$rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file
$rpl_string = !$this->log_print_file_date ? '' : '_' . date('Y-m-d'); // add date to file
}
$fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file
$rpl_string = !$this->log_per_level ? '' : '_' . $level; // if request to write to one file
$fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename
// set per class, but don't use get_class as we will only get self
$rpl_string = !$this->log_per_class ? '' : '_'.str_replace('\\', '-', \CoreLibs\Debug\Support::getCallerClass()); // set sub class settings
$rpl_string = !$this->log_per_class ? '' : '_'
// set sub class settings
. str_replace('\\', '-', \CoreLibs\Debug\Support::getCallerClass());
$fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename
$rpl_string = !$this->log_per_page ? '' : '_'.\CoreLibs\Get\System::getPageName(1); // if request to write to one file
// if request to write to one file
$rpl_string = !$this->log_per_page ? '' : '_' . \CoreLibs\Get\System::getPageName(1);
$fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename
// write to file
// first check if max file size is is set and file is bigger
if ($this->log_max_filesize > 0 && ((filesize($fn) / 1024) > $this->log_max_filesize)) {
// for easy purpose, rename file only to attach timestamp, nur sequence numbering
rename($fn, $fn.'.'.date("YmdHis"));
rename($fn, $fn . '.' . date("YmdHis"));
}
$fp = fopen($fn, 'a');
if ($fp !== false) {
@@ -302,7 +313,7 @@ class Logging
if (!in_array($type, ['debug', 'echo', 'print'])) {
return false;
}
return $this->{$type.'_output_all'};
return $this->{$type . '_output_all'};
}
/**
@@ -318,7 +329,7 @@ class Logging
if (!in_array($type, ['debug', 'echo', 'print'])) {
return;
}
$this->{$type.'_output_all'} = $set;
$this->{$type . '_output_all'} = $set;
}
/**
@@ -358,7 +369,7 @@ class Logging
array_shift($debug_on); // kick out flag (on/off)
if (count($debug_on) >= 1) {
foreach ($debug_on as $level) {
$switch = $type.'_output'.($flag == 'off' ? '_not' : '');
$switch = $type . '_output' . ($flag == 'off' ? '_not' : '');
$this->{$switch}[$level] = true;
}
}
@@ -382,7 +393,7 @@ class Logging
if (!in_array($flag, ['on', 'off'])) {
return false;
}
$switch = $type.'_output'.($flag == 'off' ? '_not' : '');
$switch = $type . '_output' . ($flag == 'off' ? '_not' : '');
// bool
if ($level !== null) {
return $this->{$switch}[$level] ?? false;
@@ -406,7 +417,7 @@ class Logging
if (!in_array($type, ['level', 'class', 'page', 'run'])) {
return;
}
$this->{'log_per_'.$type} = $set;
$this->{'log_per_' . $type} = $set;
}
/**
@@ -419,7 +430,7 @@ class Logging
if (!in_array($type, ['level', 'class', 'page', 'run'])) {
return false;
}
return $this->{'log_per_'.$type};
return $this->{'log_per_' . $type};
}
/**
@@ -433,7 +444,7 @@ class Logging
*/
public function prAr(array $a): string
{
return '##HTMLPRE##'.print_r($a, true).'##/HTMLPRE##';
return '##HTMLPRE##' . print_r($a, true) . '##/HTMLPRE##';
}
/**
@@ -461,25 +472,25 @@ class Logging
// write to file if set
$this->writeErrorMsg(
$level,
'['.$timestamp.'] '
.'['.$this->host_name.'] '
.'['.\CoreLibs\Get\System::getPageName(2).'] '
.'['.$this->running_uid.'] '
.'{'.$class.'} '
.'<'.$level.'> - '
'[' . $timestamp . '] '
. '[' . $this->host_name . '] '
. '[' . \CoreLibs\Get\System::getPageName(2) . '] '
. '[' . $this->running_uid . '] '
. '{' . $class . '} '
. '<' . $level . '> - '
// strip the htmlpre special tags if exist
.str_replace(
. str_replace(
['##HTMLPRE##', '##/HTMLPRE##'],
'',
// if stripping all html, etc is requested, only for write error msg
($strip ?
// find any <br> and replace them with \n
// strip rest of html elements (base only)
preg_replace("/(<\/?)(\w+)([^>]*>)/", '', str_replace('<br>', "\n", $prefix.$string)) :
$prefix.$string
preg_replace("/(<\/?)(\w+)([^>]*>)/", '', str_replace('<br>', "\n", $prefix . $string)) :
$prefix . $string
)
)
."\n"
. "\n"
);
// write to error level msg array if there is an echo request
if ($this->doDebugTrigger('echo', $level)) {
@@ -489,21 +500,21 @@ class Logging
}
// HTML string
$this->error_msg[$level][] = '<div>'
.'[<span style="font-weight: bold; color: #5e8600;">'.$timestamp.'</span>] '
.'[<span style="font-weight: bold; color: #c56c00;">'.$level.'</span>] '
.'[<span style="color: #b000ab;">'.$this->host_name.'</span>] '
.'[<span style="color: #08b369;">'.$this->page_name.'</span>] '
.'[<span style="color: #0062A2;">'.$this->running_uid.'</span>] '
.'{<span style="font-style: italic; color: #928100;">'.$class.'</span>} - '
. '[<span style="font-weight: bold; color: #5e8600;">' . $timestamp . '</span>] '
. '[<span style="font-weight: bold; color: #c56c00;">' . $level . '</span>] '
. '[<span style="color: #b000ab;">' . $this->host_name . '</span>] '
. '[<span style="color: #08b369;">' . $this->page_name . '</span>] '
. '[<span style="color: #0062A2;">' . $this->running_uid . '</span>] '
. '{<span style="font-style: italic; color: #928100;">' . $class . '</span>} - '
// as is prefix, allow HTML
.$prefix
. $prefix
// we replace special HTMLPRE with <pre> entries
.str_replace(
. str_replace(
['##HTMLPRE##', '##/HTMLPRE##'],
['<pre>', '</pre>'],
\CoreLibs\Convert\Html::htmlent($string)
)
."</div><!--#BR#-->";
. "</div><!--#BR#-->";
}
return true;
}
@@ -539,20 +550,25 @@ class Logging
if ($this->doDebugTrigger('debug', $level)) {
if ($this->doDebugTrigger('echo', $level)) {
$string_output .= '<div style="font-size: 12px;">'
.'[<span style="font-style: italic; color: #c56c00;">'.$level.'</span>] '
.($string ? "<b>**** ".\CoreLibs\Convert\Html::htmlent($string)." ****</br>\n" : "")
.'</div>'
.join('', $temp_debug_output);
. '[<span style="font-style: italic; color: #c56c00;">' . $level . '</span>] '
. ($string ? "<b>**** " . \CoreLibs\Convert\Html::htmlent($string) . " ****</br>\n" : "")
. '</div>'
. join('', $temp_debug_output);
} // echo it out
} // do printout
} // for each level
// create the output wrapper around, so we have a nice formated output per class
if ($string_output) {
$string_prefix = '<div style="text-align: left; padding: 5px; font-size: 10px; font-family: sans-serif; border-top: 1px solid black; border-bottom: 1px solid black; margin: 10px 0 10px 0; background-color: white; color: black;">'
.'<div style="font-size: 12px;">{<span style="font-style: italic; color: #928100;">'.\CoreLibs\Debug\Support::getCallerClass().'</span>}</div>';
$string_output = $string_prefix.$string_output
.'<div><span style="font-style: italic; color: #108db3;">Script Run Time:</span> '.$script_end.'</div>'
.'</div>';
$string_prefix = '<div style="text-align: left; padding: 5px; font-size: 10px; '
. 'font-family: sans-serif; border-top: 1px solid black; '
. 'border-bottom: 1px solid black; margin: 10px 0 10px 0; '
. 'background-color: white; color: black;">'
. '<div style="font-size: 12px;">{<span style="font-style: italic; color: #928100;">'
. \CoreLibs\Debug\Support::getCallerClass() . '</span>}</div>';
$string_output = $string_prefix . $string_output
. '<div><span style="font-style: italic; color: #108db3;">Script Run Time:</span> '
. $script_end . '</div>'
. '</div>';
}
}
return $string_output;

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* various running time checkers
*/
declare(strict_types=1);
namespace CoreLibs\Debug;
class RunningTime
@@ -93,11 +95,11 @@ class RunningTime
self::$runningtime_string .= $simple ? 'End: ' : "<b>Stopped at</b>: ";
}
self::$runningtime_string .= date('Y-m-d H:i:s', (int)$timestamp);
self::$runningtime_string .= ' '.$micro.($simple ? ', ' : '<br>');
self::$runningtime_string .= ' ' . $micro . ($simple ? ', ' : '<br>');
// if both are set
if (self::$starttime && self::$endtime) {
$running_time = self::$endtime - self::$starttime;
self::$runningtime_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ").$running_time." s";
self::$runningtime_string .= ($simple ? 'Run: ' : "<b>Script running time</b>: ") . $running_time . " s";
// reset start & end time after run
self::$starttime = 0;
self::$endtime = 0;

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* Debug support functions
*/
declare(strict_types=1);
namespace CoreLibs\Debug;
class Support
@@ -34,7 +36,7 @@ class Support
*/
public static function printAr(array $array): string
{
return "<pre>".print_r($array, true)."</pre>";
return "<pre>" . print_r($array, true) . "</pre>";
}
/**

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* system related functions to get self name, host name, error strings
*/
declare(strict_types=1);
namespace CoreLibs\Get;
class System

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
@@ -20,6 +20,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
declare(strict_types=1);
namespace CoreLibs\Language\Core;
// Preloads entire file in memory first, then creates a StringReader
@@ -27,7 +29,7 @@ namespace CoreLibs\Language\Core;
class CachedFileReader extends \CoreLibs\Language\Core\StringReader
{
public $error = 0;
public $_str = '';
public $fd_str = '';
public function __construct($filename)
{
@@ -39,7 +41,7 @@ class CachedFileReader extends \CoreLibs\Language\Core\StringReader
if (!$fd) {
$this->error = 3; // Cannot read file, probably permissions
}
$this->_str = fread($fd, $length);
$this->fd_str = fread($fd, $length);
fclose($fd);
} else {
$this->error = 2; // File doesn't exist

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
@@ -20,6 +20,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
declare(strict_types=1);
namespace CoreLibs\Language\Core;
class FileReader

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*
Copyright (c) 2003, 2009 Danilo Segan <danilo@kvota.net>.
Copyright (c) 2005 Nico Kaiser <nico@siriux.net>
@@ -20,6 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
declare(strict_types=1);
namespace CoreLibs\Language\Core;
/**
@@ -95,10 +98,10 @@ class GetTextReader
{
if ($this->BYTEORDER == 0) {
// low endian
return unpack('V'.$count, $this->STREAM->read(4 * $count));
return unpack('V' . $count, $this->STREAM->read(4 * $count));
} else {
// big endian
return unpack('N'.$count, $this->STREAM->read(4 * $count));
return unpack('N' . $count, $this->STREAM->read(4 * $count));
}
}
@@ -149,9 +152,11 @@ class GetTextReader
*/
private function load_tables()
{
if (is_array($this->cache_translations) &&
if (
is_array($this->cache_translations) &&
is_array($this->table_originals) &&
is_array($this->table_translations)) {
is_array($this->table_translations)
) {
return;
}
@@ -319,7 +324,7 @@ class GetTextReader
$res .= ') : (';
break;
case ';':
$res .= str_repeat(')', $p).';';
$res .= str_repeat(')', $p) . ';';
$p = 0;
break;
default:
@@ -448,7 +453,7 @@ class GetTextReader
*/
public function pgettext($context, $msgid)
{
$key = $context.chr(4).$msgid;
$key = $context . chr(4) . $msgid;
$ret = $this->translate($key);
if (strpos($ret, "\004") !== false) {
return $msgid;
@@ -467,7 +472,7 @@ class GetTextReader
*/
public function npgettext($context, $singular, $plural, $number)
{
$key = $context.chr(4).$singular;
$key = $context . chr(4) . $singular;
$ret = $this->ngettext($key, $plural, $number);
if (strpos($ret, "\004") !== false) {
return $singular;

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
@@ -20,6 +20,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
declare(strict_types=1);
namespace CoreLibs\Language\Core;
// Simple class to wrap file streams, string streams, etc.

View File

@@ -1,4 +1,4 @@
<?php declare(strict_types=1);
<?php
/*
Copyright (c) 2003, 2005, 2006, 2009 Danilo Segan <danilo@kvota.net>.
@@ -20,6 +20,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
declare(strict_types=1);
namespace CoreLibs\Language\Core;
class StringReader

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* hash wrapper functions for old problem fixes
*/
declare(strict_types=1);
namespace CoreLibs\Language;
class Encoding
@@ -91,11 +93,15 @@ class Encoding
if ($string != $compare) {
$failed = [];
// go through each character and find the ones that do not match
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i ++) {
for ($i = 0, $iMax = mb_strlen($string, $from_encoding); $i < $iMax; $i++) {
$char = mb_substr($string, $i, 1, $from_encoding);
$r_char = mb_substr($compare, $i, 1, $from_encoding);
// the ord 194 is a hack to fix the IE7/IE8 bug with line break and illegal character
if ((($char != $r_char && !self::$mb_error_char) || ($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) && ord($char) != 194) {
if (
(($char != $r_char && !self::$mb_error_char) ||
($char != $r_char && $r_char == self::$mb_error_char && self::$mb_error_char)) &&
ord($char) != 194
) {
$failed[] = $char;
}
}
@@ -119,15 +125,20 @@ class Encoding
* to what we sav the source is
* @return string encoding converted string
*/
public static function convertEncoding(string $string, string $to_encoding, string $source_encoding = '', bool $auto_check = true): string
{
public static function convertEncoding(
string $string,
string $to_encoding,
string $source_encoding = '',
bool $auto_check = true
): string {
// set if not given
if (!$source_encoding) {
$source_encoding = mb_detect_encoding($string);
} else {
$_source_encoding = mb_detect_encoding($string);
}
if ($auto_check === true &&
if (
$auto_check === true &&
isset($_source_encoding) &&
$_source_encoding == $source_encoding
) {

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2004/11/18
@@ -23,10 +24,12 @@
* 2005/10/17 (cs) made an on the fly switch method (reload of lang)
*********************************************************************/
declare(strict_types=1);
namespace CoreLibs\Language;
use \CoreLibs\Language\Core\FileReader;
use \CoreLibs\Language\Core\GetTextReader;
use CoreLibs\Language\Core\FileReader;
use CoreLibs\Language\Core\GetTextReader;
class L10n extends \CoreLibs\Basic
{
@@ -51,10 +54,10 @@ class L10n extends \CoreLibs\Basic
// override path check
if (!is_dir($path)) {
$path = BASE.INCLUDES.LANG.CONTENT_PATH;
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
}
$this->mofile = $path.$this->lang.".mo";
$this->mofile = $path . $this->lang . ".mo";
// check if get a readable mofile
if (is_readable($this->mofile)) {
@@ -81,10 +84,10 @@ class L10n extends \CoreLibs\Basic
// override path check
if (!is_dir($path)) {
$path = BASE.INCLUDES.LANG.CONTENT_PATH;
$path = BASE . INCLUDES . LANG . CONTENT_PATH;
}
$this->mofile = $path.$this->lang.".mo";
$this->mofile = $path . $this->lang . ".mo";
// check if get a readable mofile
if (is_readable($this->mofile)) {

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* elements for html output direct
*/
declare(strict_types=1);
namespace CoreLibs\Output\Form;
class Elements
@@ -15,24 +17,34 @@ class Elements
* @param int $day day d
* @param int $hour hour H
* @param int $min min i
* @param string $suffix additional info printed after the date time variable in the drop down
* @param string $suffix additional info printed after the date time
* variable in the drop down
* also used for ID in the on change JS call
* @param int $min_steps default is 1 (minute), can set to anything, is used as sum up from 0
* @param int $min_steps default is 1 (minute), can set to anything,
* is used as sum up from 0
* @param bool $name_pos_back default false, if set to true, the name will be printend
* after the drop down and not before the drop down
* @return string HTML formated strings for drop down lists of date and time
*/
public static function printDateTime($year, $month, $day, $hour, $min, string $suffix = '', int $min_steps = 1, bool $name_pos_back = false)
{
public static function printDateTime(
$year,
$month,
$day,
$hour,
$min,
string $suffix = '',
int $min_steps = 1,
bool $name_pos_back = false
) {
// if suffix given, add _ before
if ($suffix) {
$suffix = '_'.$suffix;
$suffix = '_' . $suffix;
}
if ($min_steps < 1 || $min_steps > 59) {
$min_steps = 1;
}
$on_change_call = 'dt_list(\''.$suffix.'\');';
$on_change_call = 'dt_list(\'' . $suffix . '\');';
// always be 1h ahead (for safety)
$timestamp = time() + 3600; // in seconds
@@ -47,15 +59,15 @@ class Elements
$hour = !$hour ? date('H', $timestamp) : $hour;
$min = !$min ? date('i', $timestamp) : $min; // add to five min?
// max days in selected month
$days_in_month = date('t', strtotime($year.'-'.$month.'-'.$day.' '.$hour.':'.$min.':0'));
$days_in_month = date('t', strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min . ':0'));
$string = '';
// from now to ?
if ($name_pos_back === false) {
$string = 'Year ';
}
$string .= '<select id="year'.$suffix.'" name="year'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = date("Y"); $i <= $max_year; $i ++) {
$string .= '<option value="'.$i.'" '.($year == $i ? 'selected' : '').'>'.$i.'</option>';
$string .= '<select id="year' . $suffix . '" name="year' . $suffix . '" onChange="' . $on_change_call . '">';
for ($i = date("Y"); $i <= $max_year; $i++) {
$string .= '<option value="' . $i . '" ' . ($year == $i ? 'selected' : '') . '>' . $i . '</option>';
}
$string .= '</select> ';
if ($name_pos_back === true) {
@@ -64,9 +76,10 @@ class Elements
if ($name_pos_back === false) {
$string .= 'Month ';
}
$string .= '<select id="month'.$suffix.'" name="month'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= 12; $i ++) {
$string .= '<option value="'.($i < 10 ? '0'.$i : $i).'" '.($month == $i ? 'selected' : '').'>'.$i.'</option>';
$string .= '<select id="month' . $suffix . '" name="month' . $suffix . '" onChange="' . $on_change_call . '">';
for ($i = 1; $i <= 12; $i++) {
$string .= '<option value="' . ($i < 10 ? '0' . $i : $i) . '" '
. ($month == $i ? 'selected' : '') . '>' . $i . '</option>';
}
$string .= '</select> ';
if ($name_pos_back === true) {
@@ -75,10 +88,12 @@ class Elements
if ($name_pos_back === false) {
$string .= 'Day ';
}
$string .= '<select id="day'.$suffix.'" name="day'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 1; $i <= $days_in_month; $i ++) {
$string .= '<select id="day' . $suffix . '" name="day' . $suffix . '" onChange="' . $on_change_call . '">';
for ($i = 1; $i <= $days_in_month; $i++) {
// set weekday text based on current month ($month) and year ($year)
$string .= '<option value="'.($i < 10 ? '0'.$i : $i).'" '.($day == $i ? 'selected' : '').'>'.$i.' ('.date('D', mktime(0, 0, 0, $month, $i, $year)).')</option>';
$string .= '<option value="' . ($i < 10 ? '0' . $i : $i) . '" '
. ($day == $i ? 'selected' : '') . '>' . $i
. ' (' . date('D', mktime(0, 0, 0, $month, $i, $year)) . ')</option>';
}
$string .= '</select> ';
if ($name_pos_back === true) {
@@ -87,9 +102,10 @@ class Elements
if ($name_pos_back === false) {
$string .= 'Hour ';
}
$string .= '<select id="hour'.$suffix.'" name="hour'.$suffix.'" onChange="'.$on_change_call.'">';
$string .= '<select id="hour' . $suffix . '" name="hour' . $suffix . '" onChange="' . $on_change_call . '">';
for ($i = 0; $i <= 23; $i += $min_steps) {
$string .= '<option value="'.($i < 10 ? '0'.$i : $i).'" '.($hour == $i ? 'selected' : '').'>'.$i.'</option>';
$string .= '<option value="' . ($i < 10 ? '0' . $i : $i)
. '" ' . ($hour == $i ? 'selected' : '') . '>' . $i . '</option>';
}
$string .= '</select> ';
if ($name_pos_back === true) {
@@ -98,9 +114,11 @@ class Elements
if ($name_pos_back === false) {
$string .= 'Minute ';
}
$string .= '<select id="min'.$suffix.'" name="min'.$suffix.'" onChange="'.$on_change_call.'">';
for ($i = 0; $i <= 59; $i ++) {
$string .= '<option value="'.($i < 10 ? '0'.$i : $i).'" '.($min == $i ? 'selected' : '').'>'.$i.'</option>';
$string .= '<select id="min' . $suffix . '" name="min'
. $suffix . '" onChange="' . $on_change_call . '">';
for ($i = 0; $i <= 59; $i++) {
$string .= '<option value="' . ($i < 10 ? '0' . $i : $i)
. '" ' . ($min == $i ? 'selected' : '') . '>' . $i . '</option>';
}
$string .= '</select>';
if ($name_pos_back === true) {
@@ -152,7 +170,15 @@ class Elements
$output = preg_replace_callback(
"/(href=\")?(\>)?\b($protRegex)([\w\.\-?&=+%#~,;\/]+)\b([\.\-?&=+%#~,;\/]*)(\|([^\||^#]+)(#([^\|]+))?\|)?/",
function ($matches) {
return self::createUrl($matches[1] ?? '', $matches[2] ?? '', $matches[3] ?? '', $matches[4] ?? '', $matches[5] ?? '', $matches[7] ?? '', $matches[9] ?? '');
return self::createUrl(
$matches[1] ?? '',
$matches[2] ?? '',
$matches[3] ?? '',
$matches[4] ?? '',
$matches[5] ?? '',
$matches[7] ?? '',
$matches[9] ?? ''
);
},
$output
);
@@ -160,7 +186,15 @@ class Elements
$output = preg_replace_callback(
"/(mailto:)?(\>)?\b([\w\.-]+)@([\w\.\-]+)\.([a-zA-Z]{2,4})\b(\|([^\||^#]+)(#([^\|]+))?\|)?/",
function ($matches) {
return self::createEmail($matches[1] ?? '', $matches[2] ?? '', $matches[3] ?? '', $matches[4] ?? '', $matches[5] ?? '', $matches[7] ?? '', $matches[9] ?? '');
return self::createEmail(
$matches[1] ?? '',
$matches[2] ?? '',
$matches[3] ?? '',
$matches[4] ?? '',
$matches[5] ?? '',
$matches[7] ?? '',
$matches[9] ?? ''
);
},
$output
);
@@ -201,11 +235,14 @@ class Elements
}
// if it is a link already just return the original link do not touch anything
if (!$href && !$atag) {
return "##LT##a href=##QUOT##".$_1.$_2.$_3."##QUOT##".($class ? ' class=##QUOT##'.$class.'##QUOT##' : '').($target ? " target=##QUOT##".$target."##QUOT##" : '')."##GT##".($name ? $name : $_2.$_3)."##LT##/a##GT##";
return "##LT##a href=##QUOT##" . $_1 . $_2 . $_3 . "##QUOT##"
. ($class ? ' class=##QUOT##' . $class . '##QUOT##' : '')
. ($target ? " target=##QUOT##" . $target . "##QUOT##" : '')
. "##GT##" . ($name ? $name : $_2 . $_3) . "##LT##/a##GT##";
} elseif ($href && !$atag) {
return "href=##QUOT##$_1$_2$_3##QUOT##";
} elseif ($atag) {
return $atag.$_2.$_3;
return $atag . $_2 . $_3;
} else {
return $href;
}
@@ -224,13 +261,15 @@ class Elements
*/
private static function createEmail($mailto, $atag, $_1, $_2, $_3, $title, $class)
{
$email = $_1."@".$_2.".".$_3;
$email = $_1 . "@" . $_2 . "." . $_3;
if (!$mailto && !$atag) {
return "##LT##a href=##QUOT##mailto:".$email."##QUOT##".($class ? ' class=##QUOT##'.$class.'##QUOT##' : '')."##GT##".($title ? $title : $email)."##LT##/a##GT##";
return "##LT##a href=##QUOT##mailto:" . $email . "##QUOT##"
. ($class ? ' class=##QUOT##' . $class . '##QUOT##' : '')
. "##GT##" . ($title ? $title : $email) . "##LT##/a##GT##";
} elseif ($mailto && !$atag) {
return "mailto:".$email;
return "mailto:" . $email;
} elseif ($atag) {
return $atag.$email;
return $atag . $email;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* sets a form token in the _SESSION variable
*/
declare(strict_types=1);
namespace CoreLibs\Output\Form;
class Token

View File

@@ -1,9 +1,11 @@
<?php declare(strict_types=1);
<?php
/*
* image thumbnail, rotate, etc
*/
declare(strict_types=1);
namespace CoreLibs\Output;
class Image
@@ -47,14 +49,14 @@ class Image
if (!empty($cache_source)) {
$tmp_src = $cache_source;
} else {
$tmp_src = BASE.TMP;
$tmp_src = BASE . TMP;
}
// check if pic has a path, and override next sets
if (strstr($pic, '/') === false) {
if (empty($path)) {
$path = BASE;
}
$filename = $path.MEDIA.PICTURES.$pic;
$filename = $path . MEDIA . PICTURES . $pic;
} else {
$filename = $pic;
// and get the last part for pic (the filename)
@@ -69,7 +71,7 @@ class Image
$delete_filename = '';
// check if we can skip the PDF creation: if we have size, if do not have type, we assume type png
if (!$type && is_numeric($size_x) && is_numeric($size_y)) {
$check_thumb = $tmp_src.'thumb_'.$pic.'_'.$size_x.'x'.$size_y.'.'.$image_types[3];
$check_thumb = $tmp_src . 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[3];
if (!is_file($check_thumb)) {
$create_file = true;
} else {
@@ -83,7 +85,7 @@ class Image
// is this a PDF, if no, return from here with nothing
$convert_prefix = 'png:';
# TEMP convert to PNG, we then override the file name
$convert_string = $CONVERT.' '.$filename.' '.$convert_prefix.$filename.'_TEMP';
$convert_string = $CONVERT . ' ' . $filename . ' ' . $convert_prefix . $filename . '_TEMP';
$status = exec($convert_string, $output, $return);
$filename .= '_TEMP';
// for delete, in case we need to glob
@@ -101,13 +103,13 @@ class Image
if (!$size_y || $size_y < 1 || !is_numeric($size_y)) {
$size_y = $height;
}
$thumb = 'thumb_'.$pic.'_'.$size_x.'x'.$size_y.'.'.$image_types[$type];
$thumbnail = $tmp_src.$thumb;
$thumb = 'thumb_' . $pic . '_' . $size_x . 'x' . $size_y . '.' . $image_types[$type];
$thumbnail = $tmp_src . $thumb;
// check if we already have this picture converted
if (!is_file($thumbnail) || $clear_cache == true) {
// convert the picture
if ($width > $size_x) {
$convert_string = $CONVERT.' -geometry '.$size_x.'x '.$filename.' '.$thumbnail;
$convert_string = $CONVERT . ' -geometry ' . $size_x . 'x ' . $filename . ' ' . $thumbnail;
$status = exec($convert_string, $output, $return);
// get the size of the converted data, if converted
if (is_file($thumbnail)) {
@@ -115,7 +117,7 @@ class Image
}
}
if ($height > $size_y) {
$convert_string = $CONVERT.' -geometry x'.$size_y.' '.$filename.' '.$thumbnail;
$convert_string = $CONVERT . ' -geometry x' . $size_y . ' ' . $filename . ' ' . $thumbnail;
$status = exec($convert_string, $output, $return);
}
}
@@ -125,12 +127,12 @@ class Image
$return_data = $thumb;
// if we have a delete filename, delete here with glob
if ($delete_filename) {
array_map('unlink', glob($delete_filename.'*'));
array_map('unlink', glob($delete_filename . '*'));
}
} else {
if ($dummy && strstr($dummy, '/') === false) {
// check if we have the "dummy" image flag set
$filename = PICTURES.ICONS.strtoupper($dummy).".png";
$filename = PICTURES . ICONS . strtoupper($dummy) . ".png";
if ($dummy && file_exists($filename) && is_file($filename)) {
$return_data = $filename;
} else {
@@ -175,36 +177,40 @@ class Image
int $jpeg_quality = 80
) {
$thumbnail = false;
// $this->debug('IMAGE PREPARE', "FILE: $filename (exists ".(string)file_exists($filename)."), WIDTH: $thumb_width, HEIGHT: $thumb_height");
// $this->debug('IMAGE PREPARE', "FILE: $filename (exists "
// .(string)file_exists($filename)."), WIDTH: $thumb_width, HEIGHT: $thumb_height");
// check that input image exists and is either jpeg or png
// also fail if the basic CACHE folder does not exist at all
if (file_exists($filename) &&
is_dir(BASE.LAYOUT.CONTENT_PATH.CACHE) &&
is_writable(BASE.LAYOUT.CONTENT_PATH.CACHE)
if (
file_exists($filename) &&
is_dir(BASE . LAYOUT . CONTENT_PATH . CACHE) &&
is_writable(BASE . LAYOUT . CONTENT_PATH . CACHE)
) {
// $this->debug('IMAGE PREPARE', "FILENAME OK, THUMB WIDTH/HEIGHT OK");
list($inc_width, $inc_height, $img_type) = getimagesize($filename);
$thumbnail_write_path = null;
$thumbnail_web_path = null;
// path set first
if ($img_type == IMAGETYPE_JPEG ||
if (
$img_type == IMAGETYPE_JPEG ||
$img_type == IMAGETYPE_PNG ||
$create_dummy === true
) {
// $this->debug('IMAGE PREPARE', "IMAGE TYPE OK: ".$inc_width.'x'.$inc_height);
// set thumbnail paths
$thumbnail_write_path = BASE.LAYOUT.CONTENT_PATH.CACHE.IMAGES;
$thumbnail_web_path = LAYOUT.CACHE.IMAGES;
$thumbnail_write_path = BASE . LAYOUT . CONTENT_PATH . CACHE . IMAGES;
$thumbnail_web_path = LAYOUT . CACHE . IMAGES;
// if images folder in cache does not exist create it, if failed, fall back to base cache folder
if (!is_dir($thumbnail_write_path)) {
if (false === mkdir($thumbnail_write_path)) {
$thumbnail_write_path = BASE.LAYOUT.CONTENT_PATH.CACHE;
$thumbnail_web_path = LAYOUT.CACHE;
$thumbnail_write_path = BASE . LAYOUT . CONTENT_PATH . CACHE;
$thumbnail_web_path = LAYOUT . CACHE;
}
}
}
// do resize or fall back on dummy run
if ($img_type == IMAGETYPE_JPEG ||
if (
$img_type == IMAGETYPE_JPEG ||
$img_type == IMAGETYPE_PNG
) {
// if missing width or height in thumb, use the set one
@@ -219,7 +225,8 @@ class Image
$thumb_width_r = 0;
$thumb_height_r = 0;
// we need to keep the aspect ration on longest side
if (($inc_height > $inc_width &&
if (
($inc_height > $inc_width &&
// and the height is bigger than thumb set
$inc_height > $thumb_height) ||
// or the height is smaller or equal width
@@ -240,9 +247,11 @@ class Image
}
// $this->debug('IMAGE PREPARE', "Ratio: $ratio, Target size $thumb_width_r x $thumb_height_r");
// set output thumbnail name
$thumbnail = 'thumb-'.pathinfo($filename)['filename'].'-'.$thumb_width_r.'x'.$thumb_height_r;
if ($use_cache === false ||
!file_exists($thumbnail_write_path.$thumbnail)
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-'
. $thumb_width_r . 'x' . $thumb_height_r;
if (
$use_cache === false ||
!file_exists($thumbnail_write_path . $thumbnail)
) {
// image, copy source image, offset in image, source x/y, new size, source image size
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
@@ -268,17 +277,39 @@ class Image
if ($source !== null) {
// resize no shift
if ($high_quality === true) {
imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumb_width_r, $thumb_height_r, $inc_width, $inc_height);
imagecopyresized(
$thumb,
$source,
0,
0,
0,
0,
$thumb_width_r,
$thumb_height_r,
$inc_width,
$inc_height
);
} else {
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $thumb_width_r, $thumb_height_r, $inc_width, $inc_height);
imagecopyresampled(
$thumb,
$source,
0,
0,
0,
0,
$thumb_width_r,
$thumb_height_r,
$inc_width,
$inc_height
);
}
// write file
switch ($img_type) {
case IMAGETYPE_JPEG:
imagejpeg($thumb, $thumbnail_write_path.$thumbnail, $jpeg_quality);
imagejpeg($thumb, $thumbnail_write_path . $thumbnail, $jpeg_quality);
break;
case IMAGETYPE_PNG:
imagepng($thumb, $thumbnail_write_path.$thumbnail);
imagepng($thumb, $thumbnail_write_path . $thumbnail);
break;
}
// free up resources (in case we are called in a loop)
@@ -290,16 +321,17 @@ class Image
}
} else {
// we just copy over the image as is, we never upscale
$thumbnail = 'thumb-'.pathinfo($filename)['filename'].'-'.$inc_width.'x'.$inc_height;
if ($use_cache === false ||
!file_exists($thumbnail_write_path.$thumbnail)
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $inc_width . 'x' . $inc_height;
if (
$use_cache === false ||
!file_exists($thumbnail_write_path . $thumbnail)
) {
copy($filename, $thumbnail_write_path.$thumbnail);
copy($filename, $thumbnail_write_path . $thumbnail);
}
}
// add output path
if ($thumbnail !== false) {
$thumbnail = $thumbnail_web_path.$thumbnail;
$thumbnail = $thumbnail_web_path . $thumbnail;
}
} elseif ($create_dummy === true) {
// create dummy image in the thumbnail size
@@ -311,9 +343,10 @@ class Image
$thumb_height = $thumb_width;
}
// do we have an image already?
$thumbnail = 'thumb-'.pathinfo($filename)['filename'].'-'.$thumb_width.'x'.$thumb_height;
if ($use_cache === false ||
!file_exists($thumbnail_write_path.$thumbnail)
$thumbnail = 'thumb-' . pathinfo($filename)['filename'] . '-' . $thumb_width . 'x' . $thumb_height;
if (
$use_cache === false ||
!file_exists($thumbnail_write_path . $thumbnail)
) {
// if both are unset, set to 250
if ($thumb_height == 0) {
@@ -335,7 +368,14 @@ class Image
} else {
$width = (int)round(imagesy($thumb) / 100 * 5);
}
imagefilledrectangle($thumb, 0 + $width, 0 + $width, imagesx($thumb) - $width, imagesy($thumb) - $width, $white);
imagefilledrectangle(
$thumb,
0 + $width,
0 + $width,
imagesx($thumb) - $width,
imagesy($thumb) - $width,
$white
);
// add "No valid images source"
// OR add circle
// * find center
@@ -348,10 +388,10 @@ class Image
$center_y = (int)round(imagesy($thumb) / 2);
imagefilledellipse($thumb, $center_x, $center_y, $cross_width, $cross_width, $gray);
// find top left and bottom left for first line
imagepng($thumb, $thumbnail_write_path.$thumbnail);
imagepng($thumb, $thumbnail_write_path . $thumbnail);
}
// add web path
$thumbnail = $thumbnail_web_path.$thumbnail;
$thumbnail = $thumbnail_web_path . $thumbnail;
}
}
// either return false or the thumbnail name + output path web

View File

@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
/*
* Class ProgressBar
*
@@ -13,6 +14,8 @@
*
*/
declare(strict_types=1);
namespace CoreLibs\Output;
class ProgressBar
@@ -30,7 +33,7 @@ class ProgressBar
];
public $clear_buffer_size = 1; // we need to send this before the lfush to get browser output
public $clear_buffer_size_init = 1024*1024; // if I don't send that junk, it won't send anything
public $clear_buffer_size_init = 1024 * 1024; // if I don't send that junk, it won't send anything
// public vars
@@ -313,7 +316,10 @@ class ProgressBar
'type' => $type, // either percent or percentlbl
'value' => $value,
'left' => false,
'top' => round(($this->height - $font_size) / log($this->height - $font_size, 7), 0) - $this->pedding,
'top' => round(
($this->height - $font_size) / log($this->height - $font_size, 7),
0
) - $this->pedding,
'width' => $this->width,
'height' => 0,
'align' => 'center',
@@ -368,8 +374,14 @@ class ProgressBar
* @param string $align alignment (left/right/etc), default empty
* @return void has no return
*/
public function setLabelPosition(string $name, int $left, int $top, int $width, int $height, string $align = ''): void
{
public function setLabelPosition(
string $name,
int $left,
int $top,
int $width,
int $height,
string $align = ''
): void {
// print "SET POSITION[$name]: $left<br>";
// if this is percent, we ignore anything, it is auto positioned
if ($this->label[$name]['type'] != 'percent') {
@@ -386,12 +398,17 @@ class ProgressBar
// init
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.top="'.$this->label[$name]['top'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.left="'.$this->label[$name]['left'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.width="'.$this->label[$name]['width'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.height="'.$this->label[$name]['height'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.align="'.$this->label[$name]['align'].'";';
$output .= '</script>'."\n";
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.top="' . $this->label[$name]['top'] . 'px";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.left="' . $this->label[$name]['left'] . 'px";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.width="' . $this->label[$name]['width'] . 'px";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.height="' . $this->label[$name]['height'] . 'px";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.align="' . $this->label[$name]['align'] . '";';
$output .= '</script>' . "\n";
echo $output;
$this->__flushCache();
}
@@ -407,7 +424,8 @@ class ProgressBar
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.color="'.$color.'";</script>'."\n";
echo '<script type="text/JavaScript">document.getElementById("plbl' . $name
. $this->code . '").style.color="' . $color . '";</script>' . "\n";
$this->__flushCache();
}
}
@@ -422,7 +440,8 @@ class ProgressBar
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("plbl'.$name.$this->code.'").style.background="'.$color.'";</script>'."\n";
echo '<script type="text/JavaScript">document.getElementById("plbl' . $name
. $this->code . '").style.background="' . $color . '";</script>' . "\n";
$this->__flushCache();
}
}
@@ -447,9 +466,14 @@ class ProgressBar
}
// position the label new if this is percent
if ($this->label[$name]['type'] == 'percent') {
$this->label[$name]['top'] = round(($this->height - intval($size)) / log($this->height - intval($size), 7), 0) - $this->pedding;
$this->label[$name]['top'] = round(
($this->height - intval($size)) / log($this->height - intval($size), 7),
0
) - $this->pedding;
}
// print "HEIGHT: ".$this->height.", Size: ".intval($size).", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size)).", Log: ".log($this->height - intval($size), 7)."<br>";
// print "HEIGHT: ".$this->height.", Size: ".intval($size)
// .", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size))
// .", Log: ".log($this->height - intval($size), 7)."<br>";
// then set like usual
$this->label[$name]['font-size'] = intval($size);
if ($family != '') {
@@ -461,10 +485,13 @@ class ProgressBar
if ($this->status != 'new') {
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-size="'.$this->label[$name]['font-size'].'px";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-family="'.$this->label[$name]['font-family'].'";';
$output .= 'document.getElementById("plbl'.$name.$this->code.'").style.font-weight="'.$this->label[$name]['font-weight'].'";';
$output .= '</script>'."\n";
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.font-size="' . $this->label[$name]['font-size'] . 'px";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.font-family="' . $this->label[$name]['font-family'] . '";';
$output .= 'document.getElementById("plbl' . $name
. $this->code . '").style.font-weight="' . $this->label[$name]['font-weight'] . '";';
$output .= '</script>' . "\n";
echo $output;
$this->__flushCache();
}
@@ -481,7 +508,8 @@ class ProgressBar
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."<Br>";
if ($this->status != 'new') {
echo '<script type="text/JavaScript">PBlabelText'.$this->code.'("'.$name.'","'.$this->label[$name]['value'].'");</script>'."\n";
echo '<script type="text/JavaScript">PBlabelText' . $this->code
. '("' . $name . '","' . $this->label[$name]['value'] . '");</script>' . "\n";
$this->__flushCache();
}
}
@@ -495,7 +523,8 @@ class ProgressBar
{
$this->color = $color;
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbar'.$this->code.'").style.background="'.$color.'";</script>'."\n";
echo '<script type="text/JavaScript">document.getElementById("pbar' . $this->code
. '").style.background="' . $color . '";</script>' . "\n";
$this->__flushCache();
}
}
@@ -509,7 +538,8 @@ class ProgressBar
{
$this->bgr_color = $color;
if ($this->status != 'new') {
echo '<script type="text/JavaScript">document.getElementById("pbrd'.$this->code.'").style.background="'.$color.'";</script>'."\n";
echo '<script type="text/JavaScript">document.getElementById("pbrd' . $this->code
. '").style.background="' . $color . '";</script>' . "\n";
$this->__flushCache();
}
}
@@ -527,11 +557,11 @@ class ProgressBar
$this->position = $this->__calculatePosition($this->step);
echo '<script type="text/JavaScript">';
echo 'PBposition'.$this->code.'("left",'.$this->position['left'].');';
echo 'PBposition'.$this->code.'("top",'.$this->position['top'].');';
echo 'PBposition'.$this->code.'("width",'.$this->position['width'].');';
echo 'PBposition'.$this->code.'("height",'.$this->position['height'].');';
echo '</script>'."\n";
echo 'PBposition' . $this->code . '("left",' . $this->position['left'] . ');';
echo 'PBposition' . $this->code . '("top",' . $this->position['top'] . ');';
echo 'PBposition' . $this->code . '("width",' . $this->position['width'] . ');';
echo 'PBposition' . $this->code . '("height",' . $this->position['height'] . ');';
echo '</script>' . "\n";
$this->__flushCache();
}
}
@@ -552,48 +582,67 @@ class ProgressBar
$style_master = '';
if ($this->top || $this->left) {
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
$style_master = 'position:relative;top:' . $this->top
. 'px;left:' . $this->left . 'px;width:' . ($this->width + 10) . 'px;';
}
$html = '<div id="pbm'.$this->code.'" style="'.$style_master.'background:'.$this->bgr_color_master.';">';
$style_brd = 'width:'.$this->width.'px;height:'.$this->height.'px;background:'.$this->bgr_color.';';
$html = '<div id="pbm' . $this->code . '" style="' . $style_master
. 'background:' . $this->bgr_color_master . ';">';
$style_brd = 'width:' . $this->width . 'px;height:' . $this->height
. 'px;background:' . $this->bgr_color . ';';
if ($this->border > 0) {
$style_brd .= 'border:'.$this->border.'px solid; border-color:'.$this->brd_color.'; -webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
$style_brd .= 'border:'
. $this->border . 'px solid; border-color:'
. $this->brd_color . '; -webkit-border-radius: 5px 5px 5px 5px; '
. 'border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; '
. 'box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
$style_bar = 'position:relative;width:'.$this->position['width'].'px;height:'.$this->position['height'].'px;background:'.$this->color.';';
$style_bar = 'position:relative;width:' . $this->position['width']
. 'px;height:' . $this->position['height'] . 'px;background:' . $this->color . ';';
if ($this->position['top'] !== false) {
$style_bar .= 'top:'.$this->position['top'].'px;';
$style_bar .= 'top:' . $this->position['top'] . 'px;';
}
if ($this->position['left'] !== false) {
$style_bar .= 'left:'.$this->position['left'].'px;';
$style_bar .= 'left:' . $this->position['left'] . 'px;';
}
if ($this->border > 0) {
$style_bar .= '-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
$style_bar .= '-webkit-border-radius: 5px 5px 5px 5px; '
. 'border-radius: 5px 5px 5px 5px; -webkit-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset; '
. 'box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.25) inset;';
}
if ($this->frame['show'] == true) {
$border = '';
if ($this->frame['border'] > 0) {
$border = 'border:'.$this->frame['border'].'px solid;border-color:'.$this->frame['brd_color'].';margin-top:2px;-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
$border = 'border:' . $this->frame['border']
. 'px solid;border-color:' . $this->frame['brd_color'] . ';margin-top:2px; '
. '-webkit-border-radius: 5px 5px 5px 5px; border-radius: 5px 5px 5px 5px;';
}
$html .= '<div id="pfrm'.$this->code.'" style="width:'.$this->frame['width'].'px;height:'.$this->frame['height'].'px;'.$border.'background:'.$this->frame['color'].';">'."\n";
$html .= '<div id="pfrm' . $this->code . '" style="width:'
. $this->frame['width'] . 'px;height:' . $this->frame['height'] . 'px;'
. $border . 'background:' . $this->frame['color'] . ';">' . "\n";
}
// temp write the bar here, we add that later, below all the html + progress %
$html_bar_top = '<div id="pbrd'.$this->code.'" style="'.$style_brd.($this->frame['show'] == true ? 'margin-left: 2px;margin-bottom:2px;' : '').'">'."\n";
$html_bar_top .= '<div id="pbar'.$this->code.'" style="'.$style_bar.'">';
$html_bar_top = '<div id="pbrd' . $this->code . '" style="' . $style_brd
. ($this->frame['show'] == true ? 'margin-left: 2px;margin-bottom:2px;' : '') . '">' . "\n";
$html_bar_top .= '<div id="pbar' . $this->code . '" style="' . $style_bar . '">';
// insert single percent there
$html_bar_bottom = '</div></div>'."\n";
$html_bar_bottom = '</div></div>' . "\n";
$js .= 'function PBposition'.$this->code.'(item,pixel) {'."\n";
$js .= ' pixel = parseInt(pixel);'."\n";
$js .= ' switch(item) {'."\n";
$js .= ' case "left": document.getElementById("pbar'.$this->code.'").style.left=(pixel) + \'px\'; break;'."\n";
$js .= ' case "top": document.getElementById("pbar'.$this->code.'").style.top=(pixel) + \'px\'; break;'."\n";
$js .= ' case "width": document.getElementById("pbar'.$this->code.'").style.width=(pixel) + \'px\'; break;'."\n";
$js .= ' case "height": document.getElementById("pbar'.$this->code.'").style.height=(pixel) + \'px\'; break;'."\n";
$js .= ' }'."\n";
$js .= '}'."\n";
$js .= 'function PBposition' . $this->code . '(item,pixel) {' . "\n";
$js .= ' pixel = parseInt(pixel);' . "\n";
$js .= ' switch(item) {' . "\n";
$js .= ' case "left": document.getElementById("pbar' . $this->code
. '").style.left=(pixel) + \'px\'; break;' . "\n";
$js .= ' case "top": document.getElementById("pbar' . $this->code
. '").style.top=(pixel) + \'px\'; break;' . "\n";
$js .= ' case "width": document.getElementById("pbar' . $this->code
. '").style.width=(pixel) + \'px\'; break;' . "\n";
$js .= ' case "height": document.getElementById("pbar' . $this->code
. '").style.height=(pixel) + \'px\'; break;' . "\n";
$js .= ' }' . "\n";
$js .= '}' . "\n";
// print "DUMP LABEL: <br><pre>".print_r($this->label, true)."</pre><br>";
foreach ($this->label as $name => $data) {
@@ -601,66 +650,80 @@ class ProgressBar
$move_prefix = $data['type'] == 'button' ? 'margin' : 'padding';
$style_lbl = 'position:relative;';
if ($data['top'] !== false) {
$style_lbl .= $move_prefix.'-top:'.$data['top'].'px;';
$style_lbl .= $move_prefix . '-top:' . $data['top'] . 'px;';
}
if ($data['left'] !== false) {
$style_lbl .= $move_prefix.'-left:'.$data['left'].'px;';
$style_lbl .= $move_prefix . '-left:' . $data['left'] . 'px;';
}
$style_lbl .= 'text-align:'.$data['align'].';';
$style_lbl .= 'text-align:' . $data['align'] . ';';
if ($data['width'] > 0) {
$style_lbl .= 'width:'.$data['width'].'px;';
$style_lbl .= 'width:' . $data['width'] . 'px;';
}
if ($data['height'] > 0) {
$style_lbl .= 'height:'.$data['height'].'px;';
$style_lbl .= 'height:' . $data['height'] . 'px;';
}
if (array_key_exists('font-size', $data)) {
$style_lbl .= 'font-size:'.$data['font-size'].'px;';
$style_lbl .= 'font-size:' . $data['font-size'] . 'px;';
}
if (array_key_exists('font-family', $data)) {
$style_lbl .= 'font-family:'.$data['font-family'].';';
$style_lbl .= 'font-family:' . $data['font-family'] . ';';
}
if (array_key_exists('font-weight', $data)) {
$style_lbl .= 'font-weight:'.$data['font-weight'].';';
$style_lbl .= 'font-weight:' . $data['font-weight'] . ';';
}
if (array_key_exists('bgr_color', $data) && ($data['bgr_color'] != '')) {
$style_lbl .= 'background:'.$data['bgr_color'].';';
$style_lbl .= 'background:' . $data['bgr_color'] . ';';
}
if (array_key_exists('type', $data)) {
switch ($data['type']) {
case 'text':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'margin-bottom:2px;">'.$data['value'].'</div>'."\n";
$html .= '<div id="plbl' . $name . $this->code . '" style="'
. $style_lbl . 'margin-bottom:2px;">' . $data['value'] . '</div>' . "\n";
break;
case 'button':
$html_button .= '<div><input id="plbl'.$name.$this->code.'" type="button" value="'.$data['value'].'" style="'.$style_lbl.'margin-bottom:5px;" onclick="'.$data['target'].'.location.href=\''.$data['action'].'\'" /></div>'."\n";
$html_button .= '<div><input id="plbl' . $name
. $this->code . '" type="button" value="' . $data['value'] . '" style="'
. $style_lbl . 'margin-bottom:5px;" onclick="' . $data['target'] . '.location.href=\''
. $data['action'] . '\'" /></div>' . "\n";
break;
case 'step':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'">'.$this->step.'</div>'."\n";
$html .= '<div id="plbl' . $name . $this->code . '" style="'
. $style_lbl . '">' . $this->step . '</div>' . "\n";
break;
case 'percent':
// only one inner percent
// print "STYLE[$name]: ".$style_lbl."<br>";
if (empty($html_percent)) {
$html_percent = '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;line-height:1;text-shadow: 0 0 .2em white, 0 0 .5em white;">'.$this->__calculatePercent($this->step).'%</div>'."\n";
$html_percent = '<div id="plbl' . $name . $this->code
. '" style="' . $style_lbl . 'width:' . $data['width']
. 'px;line-height:1;text-shadow: 0 0 .2em white, 0 0 .5em white;">'
. $this->__calculatePercent($this->step) . '%</div>' . "\n";
}
break;
case 'percentlbl':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'width:'.$data['width'].'px;">'.$this->__calculatePercent($this->step).'%</div>'."\n";
$html .= '<div id="plbl' . $name . $this->code . '" style="'
. $style_lbl . 'width:' . $data['width'] . 'px;">'
. $this->__calculatePercent($this->step) . '%</div>' . "\n";
break;
case 'crossbar':
$html .= '<div id="plbl'.$name.$this->code.'" style="'.$style_lbl.'">'.$data['value'].'</div>'."\n";
$html .= '<div id="plbl' . $name . $this->code . '" style="'
. $style_lbl . '">' . $data['value'] . '</div>' . "\n";
$js .= 'function PBrotaryCross'.$name.$this->code.'() {'."\n";
$js .= ' cross = document.getElementById("plbl'.$name.$this->code.'").firstChild.nodeValue;'."\n";
$js .= ' switch(cross) {'."\n";
$js .= ' case "--": cross = "\\\\"; break;'."\n";
$js .= ' case "\\\\": cross = "|"; break;'."\n";
$js .= ' case "|": cross = "/"; break;'."\n";
$js .= ' default: cross = "--"; break;'."\n";
$js .= ' }'."\n";
$js .= ' document.getElementById("plbl'.$name.$this->code.'").firstChild.nodeValue = cross;'."\n";
$js .= '}'."\n";
$js .= 'function PBrotaryCross' . $name . $this->code . '() {'
. "\n"
. ' cross = document.getElementById("plbl' . $name
. $this->code . '").firstChild.nodeValue;' . "\n"
. ' switch(cross) {' . "\n"
. ' case "--": cross = "\\\\"; break;' . "\n"
. ' case "\\\\": cross = "|"; break;' . "\n"
. ' case "|": cross = "/"; break;' . "\n"
. ' default: cross = "--"; break;' . "\n"
. ' }' . "\n"
. ' document.getElementById("plbl' . $name
. $this->code . '").firstChild.nodeValue = cross;' . "\n"
. '}' . "\n";
break;
}
}
@@ -673,19 +736,19 @@ class ProgressBar
$html .= $html_button; // any buttons on bottom
if (count($this->label) > 0) {
$js .= 'function PBlabelText'.$this->code.'(name,text) {'."\n";
$js .= ' name = "plbl" + name + "'.$this->code.'";'."\n";
$js .= ' document.getElementById(name).innerHTML=text;'."\n";
$js .= '}'."\n";
$js .= 'function PBlabelText' . $this->code . '(name,text) {' . "\n";
$js .= ' name = "plbl" + name + "' . $this->code . '";' . "\n";
$js .= ' document.getElementById(name).innerHTML=text;' . "\n";
$js .= '}' . "\n";
}
if ($this->frame['show'] == true) {
$html .= '</div>'."\n";
$html .= '</div>' . "\n";
}
$html .= '<script type="text/JavaScript">'."\n";
$html .= '<script type="text/JavaScript">' . "\n";
$html .= $js;
$html .= '</script>'."\n";
$html .= '</script>' . "\n";
$html .= '</div>';
@@ -716,17 +779,23 @@ class ProgressBar
$js = '';
$new_position = $this->__calculatePosition($this->step);
if ($new_position['width'] != $this->position['width'] && ($this->direction == 'right' || $this->direction == 'left')) {
if ($this->direction=='left') {
$js .= 'PBposition'.$this->code.'("left",'.$new_position['left'].');';
if (
$new_position['width'] != $this->position['width'] &&
($this->direction == 'right' || $this->direction == 'left')
) {
if ($this->direction == 'left') {
$js .= 'PBposition' . $this->code . '("left",' . $new_position['left'] . ');';
}
$js .= 'PBposition'.$this->code.'("width",'.$new_position['width'].');';
$js .= 'PBposition' . $this->code . '("width",' . $new_position['width'] . ');';
}
if ($new_position['height'] != $this->position['height'] && ($this->direction == 'up' || $this->direction == 'down')) {
if ($this->direction=='up') {
$js .= 'PBposition'.$this->code.'("top",'.$new_position['top'].');';
if (
$new_position['height'] != $this->position['height'] &&
($this->direction == 'up' || $this->direction == 'down')
) {
if ($this->direction == 'up') {
$js .= 'PBposition' . $this->code . '("top",' . $new_position['top'] . ');';
}
$js .= 'PBposition'.$this->code.'("height",'.$new_position['height'].');';
$js .= 'PBposition' . $this->code . '("height",' . $new_position['height'] . ');';
}
$this->position = $new_position;
foreach ($this->label as $name => $data) {
@@ -734,24 +803,25 @@ class ProgressBar
switch ($data['type']) {
case 'step':
if ($this->step != $last_step) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$this->step.'/'.$this->max.'");';
$js .= 'PBlabelText' . $this->code . '("'
. $name . '","' . $this->step . '/' . $this->max . '");';
}
break;
case 'percentlbl':
case 'percent':
$percent = $this->__calculatePercent($this->step);
if ($percent != $this->__calculatePercent($last_step)) {
$js .= 'PBlabelText'.$this->code.'("'.$name.'","'.$percent.'%");';
$js .= 'PBlabelText' . $this->code . '("' . $name . '","' . $percent . '%");';
}
break;
case 'crossbar':
$js .= 'PBrotaryCross'.$name.$this->code.'();';
$js .= 'PBrotaryCross' . $name . $this->code . '();';
break;
}
}
}
if ($js != '') {
echo '<script type="text/JavaScript">'.$js.'</script>'."\n";
echo '<script type="text/JavaScript">' . $js . '</script>' . "\n";
$this->__flushCache();
}
}
@@ -783,9 +853,11 @@ class ProgressBar
if ($this->status == 'show') {
$this->status = 'hide';
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="hidden";document.getElementById("pbm'.$this->code.'").style.display="none";';
$output .= '</script>'."\n";
$output = '<script type="text/JavaScript">'
. 'document.getElementById("pbm' . $this->code
. '").style.visibility="hidden";document.getElementById("pbm'
. $this->code . '").style.display="none";'
. '</script>' . "\n";
echo $output;
$this->__flushCache();
}
@@ -800,9 +872,11 @@ class ProgressBar
if ($this->status == 'hide') {
$this->status = 'show';
$output = '<script type="text/JavaScript">';
$output .= 'document.getElementById("pbm'.$this->code.'").style.visibility="visible";document.getElementById("pbm'.$this->code.'").style.visibility="block";';
$output .= '</script>'."\n";
$output = '<script type="text/JavaScript">'
. 'document.getElementById("pbm' . $this->code
. '").style.visibility="visible";document.getElementById("pbm'
. $this->code . '").style.visibility="block";'
. '</script>' . "\n";
echo $output;
$this->__flushCache();
}

View File

@@ -1,9 +1,13 @@
<?php declare(strict_types=1);
// because smarty is symlinked folder
<?php // phpcs:ignore PSR1.Files.SideEffects
/**
* @phan-file-suppress PhanRedefinedExtendedClass
*/
// because smarty is symlinked folder
declare(strict_types=1);
/********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2004/12/21
@@ -16,7 +20,7 @@
namespace CoreLibs\Template;
// I need to manually load Smarty BC here (it is not namespaced)
require_once(BASE.LIB.SMARTY.'SmartyBC.class.php');
require_once(BASE . LIB . SMARTY . 'SmartyBC.class.php');
// So it doesn't start looking around in the wrong naemspace as smarty doesn't have one
use SmartyBC;
@@ -149,7 +153,7 @@ class SmartyExtend extends SmartyBC
// create the char lang encoding
$this->lang_short = substr($this->lang, 0, 2);
// set the language folder
$this->lang_dir = BASE.INCLUDES.LANG.CONTENT_PATH;
$this->lang_dir = BASE . INCLUDES . LANG . CONTENT_PATH;
}
/**
@@ -159,45 +163,51 @@ class SmartyExtend extends SmartyBC
{
// core CS
$this->CSS_CORE_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_CORE_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_CORE_TEMPLATE_NAME)
if (
file_exists($this->CSS . $this->CSS_CORE_TEMPLATE_NAME) &&
is_file($this->CSS . $this->CSS_CORE_TEMPLATE_NAME)
) {
$this->CSS_CORE_INCLUDE = $this->CSS.$this->CSS_CORE_TEMPLATE_NAME;
$this->CSS_CORE_INCLUDE = $this->CSS . $this->CSS_CORE_TEMPLATE_NAME;
}
// core JS
$this->JS_CORE_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME)
if (
file_exists($this->JAVASCRIPT . $this->JS_CORE_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT . $this->JS_CORE_TEMPLATE_NAME)
) {
$this->JS_CORE_INCLUDE = $this->JAVASCRIPT.$this->JS_CORE_TEMPLATE_NAME;
$this->JS_CORE_INCLUDE = $this->JAVASCRIPT . $this->JS_CORE_TEMPLATE_NAME;
}
// additional per page Javascript include
$this->JS_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_TEMPLATE_NAME)
if (
file_exists($this->JAVASCRIPT . $this->JS_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT . $this->JS_TEMPLATE_NAME)
) {
$this->JS_INCLUDE = $this->JAVASCRIPT.$this->JS_TEMPLATE_NAME;
$this->JS_INCLUDE = $this->JAVASCRIPT . $this->JS_TEMPLATE_NAME;
}
// per page css file
$this->CSS_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_TEMPLATE_NAME)
if (
file_exists($this->CSS . $this->CSS_TEMPLATE_NAME) &&
is_file($this->CSS . $this->CSS_TEMPLATE_NAME)
) {
$this->CSS_INCLUDE = $this->CSS.$this->CSS_TEMPLATE_NAME;
$this->CSS_INCLUDE = $this->CSS . $this->CSS_TEMPLATE_NAME;
}
// optional CSS file
$this->CSS_SPECIAL_INCLUDE = '';
if (file_exists($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME)
if (
file_exists($this->CSS . $this->CSS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->CSS . $this->CSS_SPECIAL_TEMPLATE_NAME)
) {
$this->CSS_SPECIAL_INCLUDE = $this->CSS.$this->CSS_SPECIAL_TEMPLATE_NAME;
$this->CSS_SPECIAL_INCLUDE = $this->CSS . $this->CSS_SPECIAL_TEMPLATE_NAME;
}
// optional JS file
$this->JS_SPECIAL_INCLUDE = '';
if (file_exists($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME)
if (
file_exists($this->JAVASCRIPT . $this->JS_SPECIAL_TEMPLATE_NAME) &&
is_file($this->JAVASCRIPT . $this->JS_SPECIAL_TEMPLATE_NAME)
) {
$this->JS_SPECIAL_INCLUDE = $this->JAVASCRIPT.$this->JS_SPECIAL_TEMPLATE_NAME;
$this->JS_SPECIAL_INCLUDE = $this->JAVASCRIPT . $this->JS_SPECIAL_TEMPLATE_NAME;
}
}
@@ -215,7 +225,7 @@ class SmartyExtend extends SmartyBC
// set include & template names
if (!isset($this->CONTENT_INCLUDE)) {
$this->CONTENT_INCLUDE = str_replace('.php', '', $this->page_name).'.tpl';
$this->CONTENT_INCLUDE = str_replace('.php', '', $this->page_name) . '.tpl';
}
// strip tpl and replace it with php
// php include file per page
@@ -226,60 +236,63 @@ class SmartyExtend extends SmartyBC
$this->CSS_TEMPLATE_NAME = str_replace('.tpl', '.css', $this->CONTENT_INCLUDE);
// set basic template path (tmp)
$this->INCLUDES = BASE.INCLUDES; // no longer in templates, only global
$this->TEMPLATE_PATH = BASE.INCLUDES.TEMPLATES.CONTENT_PATH;
$this->INCLUDES = BASE . INCLUDES; // no longer in templates, only global
$this->TEMPLATE_PATH = BASE . INCLUDES . TEMPLATES . CONTENT_PATH;
$this->setTemplateDir($this->TEMPLATE_PATH);
$this->JAVASCRIPT = LAYOUT.JS;
$this->CSS = LAYOUT.CSS;
$this->FONT = LAYOUT.FONT;
$this->PICTURES = LAYOUT.IMAGES;
$this->CACHE_PICTURES = LAYOUT.CACHE;
$this->CACHE_PICTURES_ROOT = ROOT.$this->CACHE_PICTURES;
$this->JAVASCRIPT = LAYOUT . JS;
$this->CSS = LAYOUT . CSS;
$this->FONT = LAYOUT . FONT;
$this->PICTURES = LAYOUT . IMAGES;
$this->CACHE_PICTURES = LAYOUT . CACHE;
$this->CACHE_PICTURES_ROOT = ROOT . $this->CACHE_PICTURES;
// check if we have an external file with the template name
if (file_exists($this->INCLUDES.$this->INC_TEMPLATE_NAME) &&
is_file($this->INCLUDES.$this->INC_TEMPLATE_NAME)
if (
file_exists($this->INCLUDES . $this->INC_TEMPLATE_NAME) &&
is_file($this->INCLUDES . $this->INC_TEMPLATE_NAME)
) {
include($this->INCLUDES.$this->INC_TEMPLATE_NAME);
include($this->INCLUDES . $this->INC_TEMPLATE_NAME);
}
// check for template include
if ($this->USE_INCLUDE_TEMPLATE === true &&
if (
$this->USE_INCLUDE_TEMPLATE === true &&
!$this->TEMPLATE_NAME
) {
$this->TEMPLATE_NAME = $this->CONTENT_INCLUDE;
// add to cache & compile id
$this->COMPILE_ID .= '_'.$this->TEMPLATE_NAME;
$this->CACHE_ID .= '_'.$this->TEMPLATE_NAME;
$this->COMPILE_ID .= '_' . $this->TEMPLATE_NAME;
$this->CACHE_ID .= '_' . $this->TEMPLATE_NAME;
}
// set all the additional CSS/JS parths
$this->setSmartCoreIncludeCssJs();
// check if template names exist
if (!$this->MASTER_TEMPLATE_NAME) {
exit('MASTER TEMPLATE is not set');
} elseif (!file_exists($this->getTemplateDir()[0].DS.$this->MASTER_TEMPLATE_NAME)) {
} elseif (!file_exists($this->getTemplateDir()[0] . DS . $this->MASTER_TEMPLATE_NAME)) {
// abort if master template could not be found
exit('MASTER TEMPLATE: '.$this->MASTER_TEMPLATE_NAME.' could not be found');
exit('MASTER TEMPLATE: ' . $this->MASTER_TEMPLATE_NAME . ' could not be found');
}
if ($this->TEMPLATE_NAME &&
!file_exists($this->getTemplateDir()[0].DS.$this->TEMPLATE_NAME)
if (
$this->TEMPLATE_NAME &&
!file_exists($this->getTemplateDir()[0] . DS . $this->TEMPLATE_NAME)
) {
exit('INCLUDE TEMPLATE: '.$this->TEMPLATE_NAME.' could not be found');
exit('INCLUDE TEMPLATE: ' . $this->TEMPLATE_NAME . ' could not be found');
}
// javascript translate data as template for auto translate
if (empty($this->TEMPLATE_TRANSLATE)) {
$this->TEMPLATE_TRANSLATE = 'jsTranslate_'.$this->lang.'.tpl';
$this->TEMPLATE_TRANSLATE = 'jsTranslate_' . $this->lang . '.tpl';
} else {
// we assume we have some fixed set
// we must add _<$this->lang>
// if .tpl, put before .tpl
// if not .tpl, add _<$this->lang>.tpl
if (strpos($this->TEMPLATE_TRANSLATE, '.tpl')) {
$this->TEMPLATE_TRANSLATE = str_replace('.tpl', '_'.$this->lang.'.tpl', $this->TEMPLATE_TRANSLATE);
$this->TEMPLATE_TRANSLATE = str_replace('.tpl', '_' . $this->lang . '.tpl', $this->TEMPLATE_TRANSLATE);
} else {
$this->TEMPLATE_TRANSLATE .= '_'.$this->lang.'.tpl';
$this->TEMPLATE_TRANSLATE .= '_' . $this->lang . '.tpl';
}
}
// if we can't find it, dump it
if (!file_exists($this->getTemplateDir()[0].DS.$this->TEMPLATE_TRANSLATE)) {
if (!file_exists($this->getTemplateDir()[0] . DS . $this->TEMPLATE_TRANSLATE)) {
$this->TEMPLATE_TRANSLATE = null;
}
}
@@ -385,7 +398,8 @@ class SmartyExtend extends SmartyBC
// html title
// set local page title
$this->HEADER['HTML_TITLE'] = !$this->L_TITLE ?
ucfirst(str_replace('_', ' ', \CoreLibs\Get\System::getPageName(1))).(defined(G_TITLE) ? ' - '.$this->l10n->__(G_TITLE) : '') :
ucfirst(str_replace('_', ' ', \CoreLibs\Get\System::getPageName(1)))
. (defined(G_TITLE) ? ' - ' . $this->l10n->__(G_TITLE) : '') :
$this->l10n->__($this->L_TITLE);
// LANG
@@ -405,7 +419,7 @@ class SmartyExtend extends SmartyBC
$this->DATA['TEMPLATE_NAME'] = $this->TEMPLATE_NAME;
$this->DATA['CONTENT_INCLUDE'] = $this->CONTENT_INCLUDE;
$this->DATA['TEMPLATE_TRANSLATE'] = $this->TEMPLATE_TRANSLATE ?? null;
$this->DATA['PAGE_FILE_NAME'] = str_replace('.php', '', $this->page_name).'.tpl';
$this->DATA['PAGE_FILE_NAME'] = str_replace('.php', '', $this->page_name) . '.tpl';
// render page
$this->renderSmarty();
}
@@ -419,7 +433,8 @@ class SmartyExtend extends SmartyBC
{
// array merge HEADER, DATA, DEBUG DATA
foreach (['HEADER', 'DATA', 'DEBUG_DATA'] as $ext_smarty) {
if (isset($cms->{$ext_smarty}) &&
if (
isset($cms->{$ext_smarty}) &&
is_array($cms->{$ext_smarty})
) {
$this->{$ext_smarty} = array_merge($this->{$ext_smarty}, $cms->{$ext_smarty});
@@ -439,16 +454,16 @@ class SmartyExtend extends SmartyBC
foreach ($this->CONTENT_DATA as $key => $value) {
$this->assign($key, $value);
}
if (is_dir(BASE.TEMPLATES_C)) {
$this->setCompileDir(BASE.TEMPLATES_C);
if (is_dir(BASE . TEMPLATES_C)) {
$this->setCompileDir(BASE . TEMPLATES_C);
}
if (is_dir(BASE.CACHE)) {
$this->setCacheDir(BASE.CACHE);
if (is_dir(BASE . CACHE)) {
$this->setCacheDir(BASE . CACHE);
}
$this->display(
$this->MASTER_TEMPLATE_NAME,
$this->CACHE_ID.($this->CACHE_ID ? '_' : '').$this->lang,
$this->COMPILE_ID.($this->COMPILE_ID ? '_' : '').$this->lang
$this->CACHE_ID . ($this->CACHE_ID ? '_' : '') . $this->lang,
$this->COMPILE_ID . ($this->COMPILE_ID ? '_' : '') . $this->lang
);
}
}

View File

@@ -1,11 +1,14 @@
<?php declare(strict_types=1);
<?php
/*********************************************************************
* AUTHOR: Clemens Schwaighofer
* CREATED: 2011/2/8
* DESCRIPTION: pre function to collect all non critical errors into a log file if possible
* include this file at the very beginning of the script to get the notices, strict, etc messages.
* error etc will still be written to the log/display
*********************************************************************/
* AUTHOR: Clemens Schwaighofer
* CREATED: 2011/2/8
* DESCRIPTION: pre function to collect all non critical errors into a log file if possible
* include this file at the very beginning of the script to get the notices, strict, etc messages.
* error etc will still be written to the log/display
*********************************************************************/
declare(strict_types=1);
// define the base working directory outside because in the function it might return undefined
// if we have config set BASE use this
@@ -62,23 +65,25 @@ function MyErrorHandler(int $type, string $message, string $file, int $line, arr
// <> the line number in this file
// [|] error name and error number
// : the php error message
$output = '{'.array_pop($page_temp).'} ['.$file.'] <'.$line.'> ['.$error_level[$type].'|'.$type.']: '.$message;
$output = '{' . array_pop($page_temp) . '} [' . $file . '] '
. '<' . $line . '> [' . $error_level[$type] . '|' . $type . ']: ' . $message;
# try to open file
$ROOT = CURRENT_WORKING_DIR;
$LOG = 'log'.DIRECTORY_SEPARATOR;
$LOG = 'log' . DIRECTORY_SEPARATOR;
// if the log folder is not found, try to create it
if (!is_dir($ROOT.$LOG) && !is_file($ROOT.LOG)) {
$ok = mkdir($ROOT.$LOG);
if (!is_dir($ROOT . $LOG) && !is_file($ROOT . LOG)) {
$ok = mkdir($ROOT . $LOG);
}
$error = 0;
// again, if the folder now exists, else set error flag
if (is_dir($ROOT.$LOG)) {
$fn = $ROOT.$LOG.'php_errors-'.date('Y-m-d').'.log';
// when opening, surpress the warning so we can catch the no file pointer below without throwing a warning for this
if (is_dir($ROOT . $LOG)) {
$fn = $ROOT . $LOG . 'php_errors-' . date('Y-m-d') . '.log';
// when opening, surpress the warning so we can catch
// the no file pointer below without throwing a warning for this
$fp = @fopen($fn, 'a');
// write if we have a file pointer, else set error flag
if ($fp) {
fwrite($fp, '['.date("Y-m-d H:i:s").'] '.$output."\n");
fwrite($fp, '[' . date("Y-m-d H:i:s") . '] ' . $output . "\n");
fclose($fp);
} else {
$error = 1;
@@ -92,9 +97,10 @@ function MyErrorHandler(int $type, string $message, string $file, int $line, arr
// if the display errors is on
// pretty print output for HTML
if (ini_get("display_errors")) {
echo "<div style='border: 1px dotted red; background-color: #ffffe5; color: #000000; padding: 5px; margin-bottom: 2px;'>";
echo "<div style='color: orange; font-weight: bold;'>".$error_level[$type].":</div>";
echo "<b>".$message."</b> on line <b>".$line."</b> in <b>".$file."</b>";
echo "<div style='border: 1px dotted red; background-color: #ffffe5; "
. "color: #000000; padding: 5px; margin-bottom: 2px;'>";
echo "<div style='color: orange; font-weight: bold;'>" . $error_level[$type] . ":</div>";
echo "<b>" . $message . "</b> on line <b>" . $line . "</b> in <b>" . $file . "</b>";
echo "</div>";
}
// if write to log is on

View File

@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);
namespace Autoloader;
@@ -17,7 +19,7 @@ if (class_exists('Autoload', false) === false) {
// set directory seperator (we need to replace from namespace)
$DS = defined('DS') ? DS : DIRECTORY_SEPARATOR;
// base lib
$LIB = defined('LIB') ? LIB : 'lib'.$DS;
$LIB = defined('LIB') ? LIB : 'lib' . $DS;
// if lib is in path at the end, do not add lib again
// note that $LIB can have a directory seperator at the end
// strip that out before we do a match
@@ -38,9 +40,9 @@ if (class_exists('Autoload', false) === false) {
// set default extension
$extension = '.php';
// set full include path
$path = __DIR__.$DS.$LIB.substr($class, $len);
$path = __DIR__ . $DS . $LIB . substr($class, $len);
// replace namespace \ with dir sepeator
$path = str_replace('\\', $DS, $path).$extension;
$path = str_replace('\\', $DS, $path) . $extension;
// print "(2) Class clean: $path<br>";
// if path is set and a valid file
if ($path !== false && is_file($path)) {
@@ -52,7 +54,8 @@ if (class_exists('Autoload', false) === false) {
}
return false;
}
} // end class define
// end class define
}
spl_autoload_register('Autoloader\Autoload::load', true, true);
} // end check for already defined