From a86eaf0f020c242c49b5fdc4d52f3f6b943f305c Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Thu, 27 Feb 2020 15:42:32 +0900 Subject: [PATCH] Add aelxar js method, fixes for core libs, edit base file aelxar is like aelx but it uses an array and does not use objects directly fixed various possible empty array access issues in various core lib & edit base files --- .phan/config.php | 3 ++- www/configs/config.master.php | 2 ++ www/includes/edit_base.php | 24 ++++++++++++++---------- www/layout/admin/javascript/edit.jq.js | 18 ++++++++++++++++-- www/layout/admin/javascript/edit.pt.js | 18 ++++++++++++++++-- www/lib/CoreLibs/ACL/Login.php | 3 +-- www/lib/CoreLibs/Admin/Backend.php | 7 ++----- www/lib/CoreLibs/Basic.php | 3 +++ www/lib/CoreLibs/DB/IO.php | 7 ++++++- 9 files changed, 62 insertions(+), 23 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 79bae302..900f9ef8 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -109,8 +109,9 @@ return [ // ignore the old qq tests 'www/admin/qq_file_upload_front.php', 'www/admin/qq_file_upload_ajax.php', - // symlink files for msarty + // symlink ignore 'www/lib/smarty-3.1.30/SmartyBC.class.php', + 'www/lib/htmlMimeMail-2.5.1/HtmlMimeMailCreate.php', ], // what not to show as problem diff --git a/www/configs/config.master.php b/www/configs/config.master.php index 4e48b752..6ff5d447 100644 --- a/www/configs/config.master.php +++ b/www/configs/config.master.php @@ -169,6 +169,8 @@ define('PUBLIC_SCHEMA', 'public'); define('DEV_SCHEMA', 'public'); define('TEST_SCHEMA', 'public'); define('LIVE_SCHEMA', 'public'); +define('GLOBAL_DB_SCHEMA', ''); +define('LOGIN_DB_SCHEMA', ''); /************* CORE HOST SETTINGS *****************/ if (file_exists(BASE.CONFIGS.'config.host.php')) { diff --git a/www/includes/edit_base.php b/www/includes/edit_base.php index aa14083b..c81ed40b 100644 --- a/www/includes/edit_base.php +++ b/www/includes/edit_base.php @@ -102,7 +102,7 @@ if ($form->my_page_name == 'edit_order') { if (!isset($position)) { $position = array(); } - $row_data_id = $_POST['row_data_id']; + $row_data_id = $_POST['row_data_id'] ?? []; $original_id = $row_data_id; if (count($position)) { $row_data_order = $_POST['row_data_order']; @@ -116,8 +116,8 @@ if ($form->my_page_name == 'edit_order') { // this gets the old before (moves one "up") // is done for every element in row // echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")
"; - $temp_id = $row_data_id[$position[$i]]; - $row_data_id[$position[$i]] = $row_data_id[$position[$i] - 1]; + $temp_id = $row_data_id[$position[$i]] ?? null; + $row_data_id[$position[$i]] = $row_data_id[$position[$i] - 1] ?? null; $row_data_id[$position[$i] - 1] = $temp_id; // echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")
"; } // for @@ -129,8 +129,8 @@ if ($form->my_page_name == 'edit_order') { // same as up, just up in other way, starts from bottom (last element) and moves "up" // element before actuel gets temp, this element, becomes element after this, // element after this, gets this - $temp_id = $row_data_id[$position[$i] + 1]; - $row_data_id[$position[$i] + 1] = $row_data_id[$position[$i]]; + $temp_id = $row_data_id[$position[$i] + 1] ?? null; + $row_data_id[$position[$i] + 1] = $row_data_id[$position[$i]] ?? null; $row_data_id[$position[$i]] = $temp_id; } // for } // if down @@ -140,8 +140,10 @@ if ($form->my_page_name == 'edit_order') { (isset($down) && ($position[count($position) - 1] != (count($row_data_id) - 1))) ) { for ($i = 0; $i < count($row_data_id); $i ++) { - $q = "UPDATE ".$table_name." SET order_number = ".$row_data_order[$i]." WHERE ".$table_name."_id = ".$row_data_id[$i]; - $q = $form->dbExec($q); + if (isset($row_data_order[$i]) && isset($row_data_id[$i])) { + $q = "UPDATE ".$table_name." SET order_number = ".$row_data_order[$i]." WHERE ".$table_name."_id = ".$row_data_id[$i]; + $q = $form->dbExec($q); + } } // for all article ids ... } // if write } // if there is something to move @@ -187,7 +189,9 @@ if ($form->my_page_name == 'edit_order') { // list of points to order for ($j = 0; $j < count($position); $j++) { // if matches, put into select array - if ($original_id[$position[$j]] == $row_data[$i]['id']) { + if (isset($original_id[$position[$j]]) && isset($row_data[$i]['id']) && + $original_id[$position[$j]] == $row_data[$i]['id'] + ) { $options_selected[] = $i; } } @@ -301,7 +305,7 @@ if ($form->my_page_name == 'edit_order') { (!$data['hostname'] || strstr($data['hostname'], CONTENT_PATH) !== false) )) ) { - $position = $j; + $position = $i; $menu_data[$i]['position'] = 1; $menu_data[$i]['popup'] = 0; } else { @@ -326,7 +330,7 @@ if ($form->my_page_name == 'edit_order') { } // for // $form->debug('MENU ARRAY', $form->printAr($menu_data)); $DATA['menu_data'] = $menu_data; - $DATA['page_name'] = $menuarray[$position]['page_name']; + $DATA['page_name'] = $menuarray[$position]['page_name'] ?? '-Undefined ['.$position.'] -'; $L_TITLE = $DATA['page_name']; // html title $HEADER['HTML_TITLE'] = $form->l->__($L_TITLE); diff --git a/www/layout/admin/javascript/edit.jq.js b/www/layout/admin/javascript/edit.jq.js index 43512c83..cba2e6cd 100644 --- a/www/layout/admin/javascript/edit.jq.js +++ b/www/layout/admin/javascript/edit.jq.js @@ -121,8 +121,7 @@ function setCenter(id, left, top) function goToPos(element, offset = 0) { try { - if ($('#' + element).length) - { + if ($('#' + element).length) { $('body,html').animate({ scrollTop: $('#' + element).offset().top - offset }, 500); @@ -558,6 +557,21 @@ function aelx(base, ...attach) return base; } +/** + * same as aelx, but instead of using objects as parameters + * get an array of objects to attach + * @param {Object} base object to where we attach the elements + * @param {Array} attach array of objects to attach + * @return {Object} "none", technically there is no return needed, global attach + */ +function aelxar(base, attach) +{ + for (var i = 0; i < attach.length; i ++) { + base.sub.push(Object.assign({}, attach[i])); + } + return base; +} + /** * resets the sub elements of the base element given * @param {Object} base cel created element diff --git a/www/layout/admin/javascript/edit.pt.js b/www/layout/admin/javascript/edit.pt.js index 4fb9b1e8..e39d09a1 100644 --- a/www/layout/admin/javascript/edit.pt.js +++ b/www/layout/admin/javascript/edit.pt.js @@ -201,8 +201,7 @@ function setCenter(id, left, top) function goToPos(element, offset = 0) { try { - if ($(element)) - { + if ($(element)) { // get the element pos var pos = $(element).cumulativeOffset(); // if not top element and no offset given, set auto offset for top element @@ -618,6 +617,21 @@ function aelx(base, ...attach) return base; } +/** + * same as aelx, but instead of using objects as parameters + * get an array of objects to attach + * @param {Object} base object to where we attach the elements + * @param {Array} attach array of objects to attach + * @return {Object} "none", technically there is no return needed, global attach + */ +function aelxar(base, attach) +{ + attach.each(function(t) { + base.sub.push(Object.assign({}, t)); + }); + return base; +} + /** * resets the sub elements of the base element given * @param {Object} base cel created element diff --git a/www/lib/CoreLibs/ACL/Login.php b/www/lib/CoreLibs/ACL/Login.php index ca3ce821..988ce6ab 100644 --- a/www/lib/CoreLibs/ACL/Login.php +++ b/www/lib/CoreLibs/ACL/Login.php @@ -161,8 +161,7 @@ class Login extends \CoreLibs\DB\IO // 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 - if (defined('LOGIN_DB_SCHEMA')) { - /** @phan-suppress-next-line PhanUndeclaredConstant */ + if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) { $SCHEMA = LOGIN_DB_SCHEMA; } elseif (isset($db_config['db_schema']) && $db_config['db_schema']) { $SCHEMA = $db_config['db_schema']; diff --git a/www/lib/CoreLibs/Admin/Backend.php b/www/lib/CoreLibs/Admin/Backend.php index f4a65bcb..0c49d891 100644 --- a/www/lib/CoreLibs/Admin/Backend.php +++ b/www/lib/CoreLibs/Admin/Backend.php @@ -169,8 +169,7 @@ class Backend extends \CoreLibs\DB\IO } // check schema - if (defined('LOGIN_DB_SCHEMA')) { - /** @phan-suppress-next-line PhanUndeclaredConstant */ + if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) { $SCHEMA = LOGIN_DB_SCHEMA; } elseif ($this->dbGetSchema()) { $SCHEMA = $this->dbGetSchema(); @@ -256,7 +255,6 @@ class Backend extends \CoreLibs\DB\IO $type = 'popup'; } else { $type = 'normal'; - /** @phan-suppress-next-line PhanTypeArraySuspicious */ $data['popup'] = 0; } $query_string = ''; @@ -443,8 +441,7 @@ class Backend extends \CoreLibs\DB\IO string $associate = null, string $file = null ): void { - if (defined('GLOBAL_DB_SCHEMA')) { - /** @phan-suppress-next-line PhanUndeclaredConstant */ + if (defined('GLOBAL_DB_SCHEMA') && GLOBAL_DB_SCHEMA) { $SCHEMA = GLOBAL_DB_SCHEMA; } elseif ($this->dbGetSchema()) { $SCHEMA = $this->dbGetSchema(); diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 3f60413d..418084f8 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -1808,6 +1808,7 @@ class Basic */ public static function stringByteFormat($number, bool $dot_thousand = false) { + $matches = []; // detects up to exo bytes preg_match("/([\d.,]*)\s?(eb|pb|tb|gb|mb|kb|e|p|t|g|m|k|b)$/", strtolower($number), $matches); if (isset($matches[1]) && isset($matches[2])) { @@ -2181,6 +2182,8 @@ class Basic } // if type is not in the list, but returns as PDF, we need to convert to JPEG before if (!$type) { + $output = []; + $return = null; // is this a PDF, if no, return from here with nothing $convert_prefix = 'png:'; # TEMP convert to PNG, we then override the file name diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 874a71e9..8f9fabca 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -633,6 +633,7 @@ class IO extends \CoreLibs\Basic */ private function __dbReturnTable(string $query): array { + $matches = []; if (preg_match("/^SELECT /i", $query)) { preg_match("/ (FROM) (([\w_]+)\.)?([\w_]+) /i", $query, $matches); } else { @@ -655,6 +656,7 @@ class IO extends \CoreLibs\Basic */ private function __dbPrepareExec(string $query, string $pk_name) { + $matches= []; // to either use the returning method or the guess method for getting primary keys $this->returning_id = false; // set the query @@ -1454,6 +1456,7 @@ class IO extends \CoreLibs\Basic */ public function dbPrepare(string $stm_name, string $query, string $pk_name = '') { + $matches = []; if (!$query) { $this->error_id = 11; $this->__dbError(); @@ -1507,6 +1510,7 @@ class IO extends \CoreLibs\Basic $this->prepare_cursor[$stm_name]['pk_name'] = $pk_name; } } + $match = []; // search for $1, $2, in the query and push it into the control array preg_match_all('/(\$[0-9]{1,})/', $query, $match); $this->prepare_cursor[$stm_name]['count'] = count($match[1]); @@ -1665,6 +1669,7 @@ class IO extends \CoreLibs\Basic */ public function dbCompareVersion(string $compare): bool { + $matches = []; // compare has =, >, < prefix, and gets stripped, if the rest is not X.Y format then error preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches); $compare = $matches[1]; @@ -1909,10 +1914,10 @@ class IO extends \CoreLibs\Basic */ public function dbTimeFormat(string $age, bool $show_micro = false): string { + $matches = []; // in string (datetime diff): 1786 days 22:11:52.87418 // or (age): 4 years 10 mons 21 days 12:31:11.87418 // also -09:43:54.781021 or without - prefix - preg_match("/(.*)?(\d{2}):(\d{2}):(\d{2})(\.(\d+))/", $age, $matches); $prefix = $matches[1] != '-' ? $matches[1] : '';