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
This commit is contained in:
Clemens Schwaighofer
2020-02-27 15:42:32 +09:00
parent 3e29073664
commit a86eaf0f02
9 changed files with 62 additions and 23 deletions

View File

@@ -109,8 +109,9 @@ return [
// ignore the old qq tests // ignore the old qq tests
'www/admin/qq_file_upload_front.php', 'www/admin/qq_file_upload_front.php',
'www/admin/qq_file_upload_ajax.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/smarty-3.1.30/SmartyBC.class.php',
'www/lib/htmlMimeMail-2.5.1/HtmlMimeMailCreate.php',
], ],
// what not to show as problem // what not to show as problem

View File

@@ -169,6 +169,8 @@ define('PUBLIC_SCHEMA', 'public');
define('DEV_SCHEMA', 'public'); define('DEV_SCHEMA', 'public');
define('TEST_SCHEMA', 'public'); define('TEST_SCHEMA', 'public');
define('LIVE_SCHEMA', 'public'); define('LIVE_SCHEMA', 'public');
define('GLOBAL_DB_SCHEMA', '');
define('LOGIN_DB_SCHEMA', '');
/************* CORE HOST SETTINGS *****************/ /************* CORE HOST SETTINGS *****************/
if (file_exists(BASE.CONFIGS.'config.host.php')) { if (file_exists(BASE.CONFIGS.'config.host.php')) {

View File

@@ -102,7 +102,7 @@ if ($form->my_page_name == 'edit_order') {
if (!isset($position)) { if (!isset($position)) {
$position = array(); $position = array();
} }
$row_data_id = $_POST['row_data_id']; $row_data_id = $_POST['row_data_id'] ?? [];
$original_id = $row_data_id; $original_id = $row_data_id;
if (count($position)) { if (count($position)) {
$row_data_order = $_POST['row_data_order']; $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") // this gets the old before (moves one "up")
// is done for every element in row // 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].")<br>"; // echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")<br>";
$temp_id = $row_data_id[$position[$i]]; $temp_id = $row_data_id[$position[$i]] ?? null;
$row_data_id[$position[$i]] = $row_data_id[$position[$i] - 1]; $row_data_id[$position[$i]] = $row_data_id[$position[$i] - 1] ?? null;
$row_data_id[$position[$i] - 1] = $temp_id; $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].")<br>"; // echo "A: ".$row_data_id[$position[$i]]." (".$row_data_order[$position[$i]].") -- ".$row_data_id[$position[$i]-1]." (".$row_data_order[$position[$i]-1].")<br>";
} // for } // 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" // 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 before actuel gets temp, this element, becomes element after this,
// element after this, gets this // element after this, gets this
$temp_id = $row_data_id[$position[$i] + 1]; $temp_id = $row_data_id[$position[$i] + 1] ?? null;
$row_data_id[$position[$i] + 1] = $row_data_id[$position[$i]]; $row_data_id[$position[$i] + 1] = $row_data_id[$position[$i]] ?? null;
$row_data_id[$position[$i]] = $temp_id; $row_data_id[$position[$i]] = $temp_id;
} // for } // for
} // if down } // if down
@@ -140,8 +140,10 @@ if ($form->my_page_name == 'edit_order') {
(isset($down) && ($position[count($position) - 1] != (count($row_data_id) - 1))) (isset($down) && ($position[count($position) - 1] != (count($row_data_id) - 1)))
) { ) {
for ($i = 0; $i < count($row_data_id); $i ++) { 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]; if (isset($row_data_order[$i]) && isset($row_data_id[$i])) {
$q = $form->dbExec($q); $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 ... } // for all article ids ...
} // if write } // if write
} // if there is something to move } // if there is something to move
@@ -187,7 +189,9 @@ if ($form->my_page_name == 'edit_order') {
// list of points to order // list of points to order
for ($j = 0; $j < count($position); $j++) { for ($j = 0; $j < count($position); $j++) {
// if matches, put into select array // 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; $options_selected[] = $i;
} }
} }
@@ -301,7 +305,7 @@ if ($form->my_page_name == 'edit_order') {
(!$data['hostname'] || strstr($data['hostname'], CONTENT_PATH) !== false) (!$data['hostname'] || strstr($data['hostname'], CONTENT_PATH) !== false)
)) ))
) { ) {
$position = $j; $position = $i;
$menu_data[$i]['position'] = 1; $menu_data[$i]['position'] = 1;
$menu_data[$i]['popup'] = 0; $menu_data[$i]['popup'] = 0;
} else { } else {
@@ -326,7 +330,7 @@ if ($form->my_page_name == 'edit_order') {
} // for } // for
// $form->debug('MENU ARRAY', $form->printAr($menu_data)); // $form->debug('MENU ARRAY', $form->printAr($menu_data));
$DATA['menu_data'] = $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']; $L_TITLE = $DATA['page_name'];
// html title // html title
$HEADER['HTML_TITLE'] = $form->l->__($L_TITLE); $HEADER['HTML_TITLE'] = $form->l->__($L_TITLE);

View File

@@ -121,8 +121,7 @@ function setCenter(id, left, top)
function goToPos(element, offset = 0) function goToPos(element, offset = 0)
{ {
try { try {
if ($('#' + element).length) if ($('#' + element).length) {
{
$('body,html').animate({ $('body,html').animate({
scrollTop: $('#' + element).offset().top - offset scrollTop: $('#' + element).offset().top - offset
}, 500); }, 500);
@@ -558,6 +557,21 @@ function aelx(base, ...attach)
return base; 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 * resets the sub elements of the base element given
* @param {Object} base cel created element * @param {Object} base cel created element

View File

@@ -201,8 +201,7 @@ function setCenter(id, left, top)
function goToPos(element, offset = 0) function goToPos(element, offset = 0)
{ {
try { try {
if ($(element)) if ($(element)) {
{
// get the element pos // get the element pos
var pos = $(element).cumulativeOffset(); var pos = $(element).cumulativeOffset();
// if not top element and no offset given, set auto offset for top element // if not top element and no offset given, set auto offset for top element
@@ -618,6 +617,21 @@ function aelx(base, ...attach)
return base; 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 * resets the sub elements of the base element given
* @param {Object} base cel created element * @param {Object} base cel created element

View File

@@ -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 // 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')) { if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = LOGIN_DB_SCHEMA; $SCHEMA = LOGIN_DB_SCHEMA;
} elseif (isset($db_config['db_schema']) && $db_config['db_schema']) { } elseif (isset($db_config['db_schema']) && $db_config['db_schema']) {
$SCHEMA = $db_config['db_schema']; $SCHEMA = $db_config['db_schema'];

View File

@@ -169,8 +169,7 @@ class Backend extends \CoreLibs\DB\IO
} }
// check schema // check schema
if (defined('LOGIN_DB_SCHEMA')) { if (defined('LOGIN_DB_SCHEMA') && LOGIN_DB_SCHEMA) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = LOGIN_DB_SCHEMA; $SCHEMA = LOGIN_DB_SCHEMA;
} elseif ($this->dbGetSchema()) { } elseif ($this->dbGetSchema()) {
$SCHEMA = $this->dbGetSchema(); $SCHEMA = $this->dbGetSchema();
@@ -256,7 +255,6 @@ class Backend extends \CoreLibs\DB\IO
$type = 'popup'; $type = 'popup';
} else { } else {
$type = 'normal'; $type = 'normal';
/** @phan-suppress-next-line PhanTypeArraySuspicious */
$data['popup'] = 0; $data['popup'] = 0;
} }
$query_string = ''; $query_string = '';
@@ -443,8 +441,7 @@ class Backend extends \CoreLibs\DB\IO
string $associate = null, string $associate = null,
string $file = null string $file = null
): void { ): void {
if (defined('GLOBAL_DB_SCHEMA')) { if (defined('GLOBAL_DB_SCHEMA') && GLOBAL_DB_SCHEMA) {
/** @phan-suppress-next-line PhanUndeclaredConstant */
$SCHEMA = GLOBAL_DB_SCHEMA; $SCHEMA = GLOBAL_DB_SCHEMA;
} elseif ($this->dbGetSchema()) { } elseif ($this->dbGetSchema()) {
$SCHEMA = $this->dbGetSchema(); $SCHEMA = $this->dbGetSchema();

View File

@@ -1808,6 +1808,7 @@ class Basic
*/ */
public static function stringByteFormat($number, bool $dot_thousand = false) public static function stringByteFormat($number, bool $dot_thousand = false)
{ {
$matches = [];
// detects up to exo bytes // 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); 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])) { 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 is not in the list, but returns as PDF, we need to convert to JPEG before
if (!$type) { if (!$type) {
$output = [];
$return = null;
// is this a PDF, if no, return from here with nothing // is this a PDF, if no, return from here with nothing
$convert_prefix = 'png:'; $convert_prefix = 'png:';
# TEMP convert to PNG, we then override the file name # TEMP convert to PNG, we then override the file name

View File

@@ -633,6 +633,7 @@ class IO extends \CoreLibs\Basic
*/ */
private function __dbReturnTable(string $query): array private function __dbReturnTable(string $query): array
{ {
$matches = [];
if (preg_match("/^SELECT /i", $query)) { if (preg_match("/^SELECT /i", $query)) {
preg_match("/ (FROM) (([\w_]+)\.)?([\w_]+) /i", $query, $matches); preg_match("/ (FROM) (([\w_]+)\.)?([\w_]+) /i", $query, $matches);
} else { } else {
@@ -655,6 +656,7 @@ class IO extends \CoreLibs\Basic
*/ */
private function __dbPrepareExec(string $query, string $pk_name) private function __dbPrepareExec(string $query, string $pk_name)
{ {
$matches= [];
// to either use the returning method or the guess method for getting primary keys // to either use the returning method or the guess method for getting primary keys
$this->returning_id = false; $this->returning_id = false;
// set the query // set the query
@@ -1454,6 +1456,7 @@ class IO extends \CoreLibs\Basic
*/ */
public function dbPrepare(string $stm_name, string $query, string $pk_name = '') public function dbPrepare(string $stm_name, string $query, string $pk_name = '')
{ {
$matches = [];
if (!$query) { if (!$query) {
$this->error_id = 11; $this->error_id = 11;
$this->__dbError(); $this->__dbError();
@@ -1507,6 +1510,7 @@ class IO extends \CoreLibs\Basic
$this->prepare_cursor[$stm_name]['pk_name'] = $pk_name; $this->prepare_cursor[$stm_name]['pk_name'] = $pk_name;
} }
} }
$match = [];
// search for $1, $2, in the query and push it into the control array // search for $1, $2, in the query and push it into the control array
preg_match_all('/(\$[0-9]{1,})/', $query, $match); preg_match_all('/(\$[0-9]{1,})/', $query, $match);
$this->prepare_cursor[$stm_name]['count'] = count($match[1]); $this->prepare_cursor[$stm_name]['count'] = count($match[1]);
@@ -1665,6 +1669,7 @@ class IO extends \CoreLibs\Basic
*/ */
public function dbCompareVersion(string $compare): bool public function dbCompareVersion(string $compare): bool
{ {
$matches = [];
// compare has =, >, < prefix, and gets stripped, if the rest is not X.Y format then error // 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); preg_match("/^([<>=]{1,})(\d{1,})\.(\d{1,})/", $compare, $matches);
$compare = $matches[1]; $compare = $matches[1];
@@ -1909,10 +1914,10 @@ class IO extends \CoreLibs\Basic
*/ */
public function dbTimeFormat(string $age, bool $show_micro = false): string public function dbTimeFormat(string $age, bool $show_micro = false): string
{ {
$matches = [];
// in string (datetime diff): 1786 days 22:11:52.87418 // in string (datetime diff): 1786 days 22:11:52.87418
// or (age): 4 years 10 mons 21 days 12:31:11.87418 // or (age): 4 years 10 mons 21 days 12:31:11.87418
// also -09:43:54.781021 or without - prefix // also -09:43:54.781021 or without - prefix
preg_match("/(.*)?(\d{2}):(\d{2}):(\d{2})(\.(\d+))/", $age, $matches); preg_match("/(.*)?(\d{2}):(\d{2}):(\d{2})(\.(\d+))/", $age, $matches);
$prefix = $matches[1] != '-' ? $matches[1] : ''; $prefix = $matches[1] != '-' ? $matches[1] : '';