Fix IMG_PNG constant error, jquery update, other minor fixes

Big fix with IMG_PNG constant use. Switched to IMAGETYPE_*

Some code cleanup in config files (array, DEFINE->define, etc)

Code cleanup in DB:IO class, especially for consistent returning
array/single data blocks

Some javascript core lib update
This commit is contained in:
Clemens Schwaighofer
2021-04-28 11:03:26 +09:00
parent b6c6d76b43
commit 6059b83637
12 changed files with 1017 additions and 687 deletions

View File

@@ -107,25 +107,46 @@ while ($res = $basic->dbReturn("SELECT * FROM max_test")) {
print "[CACHED] TIME: ".$res['time']."<br>";
}
print "<pre>";
$status = $basic->dbExec("INSERT INTO foo (test) VALUES ('FOO TEST ".time()."') RETURNING test");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->dbGetInsertPK()." | PRIMARY KEY EXT: ".print_r($basic->insert_id_ext, true)." => ".print_r($basic->dbGetReturningExt(), true)."<br>";
print "DIRECT INSERT STATUS: $status | "
."PRIMARY KEY: ".$basic->dbGetInsertPK()." | "
."RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)." | "
."RETURNING ARRAY: ".print_r($basic->dbGetReturningArray(), true)."<br>";
// should throw deprecated error
// $basic->getReturningExt();
print "DIRECT INSERT PREVIOUS INSERTED: ".print_r($basic->dbReturnRow("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->dbGetInsertPK()), true)."<br>";
$basic->dbPrepare("ins_foo", "INSERT INTO foo (test) VALUES ($1)");
$status = $basic->dbExecute("ins_foo", array('BAR TEST '.time()));
print "PREPARE INSERT STATUS: $status | PRIMARY KEY: ".$basic->dbGetInsertPK()." | PRIMARY KEY EXT: ".print_r($basic->dbGetReturningExt(), true)."<br>";
print "PREPARE INSERT STATUS: $status | "
."PRIMARY KEY: ".$basic->dbGetInsertPK()." | "
."RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)." | "
."RETURNING RETURN: ".print_r($basic->dbGetReturningArray(), true)."<br>";
print "PREPARE INSERT PREVIOUS INSERTED: ".print_r($basic->dbReturnRow("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->dbGetInsertPK()), true)."<br>";
// returning test with multiple entries
// $status = $basic->db_exec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id");
$status = $basic->dbExec("INSERT INTO foo (test) values ('BAR 1 ".time()."'), ('BAR 2 ".time()."'), ('BAR 3 ".time()."') RETURNING foo_id, test");
print "DIRECT MULTIPLE INSERT STATUS: $status | PRIMARY KEYS: ".print_r($basic->dbGetInsertPK(), true)." | PRIMARY KEY EXT: ".print_r($basic->dbGetReturningExt(), true)."<br>";
print "DIRECT MULTIPLE INSERT STATUS: $status | "
."PRIMARY KEYS: ".print_r($basic->dbGetInsertPK(), true)." | "
."RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)." | "
."RETURNING ARRAY: ".print_r($basic->dbGetReturningArray(), true)."<br>";
// no returning, but not needed ;
$status = $basic->dbExec("INSERT INTO foo (test) VALUES ('FOO; TEST ".time()."');");
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->dbGetInsertPK()." | PRIMARY KEY EXT: ".print_r($basic->dbGetReturningExt(), true)."<br>";
print "DIRECT INSERT STATUS: $status | "
."PRIMARY KEY: ".$basic->dbGetInsertPK()." | "
."RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)." | "
."RETURNING ARRAY: ".print_r($basic->dbGetReturningArray(), true)."<br>";
// UPDATE WITH RETURNING
$status = $basic->dbExec("UPDATE foo SET test = 'SOMETHING DIFFERENT' WHERE foo_id = 3688452 RETURNING test");
print "UPDATE STATUS: $status | RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)."<br>";
print "UPDATE STATUS: $status | "
."RETURNING EXT: ".print_r($basic->dbGetReturningExt(), true)." | "
."RETURNING ARRAY: ".print_r($basic->dbGetReturningArray(), true)."<br>";
print "</pre>";
// REEAD PREPARE
if ($basic->dbPrepare('sel_foo', "SELECT foo_id, test, some_bool, string_a, number_a, number_a_numeric, some_time FROM foo ORDER BY foo_id DESC LIMIT 5") === false) {
print "Error in sel_foo prepare<br>";

View File

@@ -12,13 +12,13 @@
*********************************************************************/
// other master config to attach
// $__LOCAL_CONFIG = array(
// $__LOCAL_CONFIG = [
// 'db_host' => '',
// 'location' => '',
// 'debug_flag' => true,
// 'site_lang' => 'en_utf8',
// 'login_enabled' => true
// );
// ];
// each host has a different db_host
$SITE_CONFIG = [

View File

@@ -26,7 +26,7 @@ define('LIBS', 'lib'.DS);
define('CONFIGS', 'configs'.DS);
// includes (strings, arrays for static, etc)
define('INCLUDES', 'includes'.DS);
// data folder (mostly in includes)
// data folder (mostly in includes, or root for internal data)
define('DATA', 'data'.DS);
// layout base path
define('LAYOUT', 'layout'.DS);
@@ -36,20 +36,22 @@ define('PICTURES', 'images'.DS);
define('IMAGES', 'images'.DS);
// icons (below the images/ folder)
define('ICONS', 'icons'.DS);
// media
// media (accessable from outside)
define('MEDIA', 'media'.DS);
// flash-root (below media)
// flash-root (below media or data)
define('FLASH', 'flash'.DS);
// uploads (anything to keep)
// uploads (anything to keep or data)
define('UPLOADS', 'uploads'.DS);
// files (binaries) (below media)
// files (binaries) (below media or data)
define('BINARIES', 'binaries'.DS);
// files (videos) (below media)
// files (videos) (below media or data)
define('VIDEOS', 'videos'.DS);
// files (documents) (below media)
// files (documents) (below media or data)
define('DOCUMENTS', 'documents'.DS);
// files (pdfs) (below media)
// files (pdfs) (below media or data)
define('PDFS', 'documents'.DS);
// files (general) (below media or data)
define('FILES', 'files'.DS);
// CSV
define('CSV', 'csv'.DS);
// css
@@ -104,15 +106,15 @@ define('PASSWORD_FORGOT', false);
define('PASSWORD_MIN_LENGTH', 9);
define('PASSWORD_MAX_LENGTH', 255);
// defines allowed special characters
DEFINE('PASSWORD_SPECIAL_RANGE', '@$!%*?&');
define('PASSWORD_SPECIAL_RANGE', '@$!%*?&');
// password must have upper case, lower case, number, special
// comment out for not mandatory
DEFINE('PASSWORD_LOWER', '(?=.*[a-z])');
DEFINE('PASSWORD_UPPER', '(?=.*[A-Z])');
DEFINE('PASSWORD_NUMBER', '(?=.*\d)');
DEFINE('PASSWORD_SPECIAL', "(?=.*[".PASSWORD_SPECIAL_RANGE."])");
define('PASSWORD_LOWER', '(?=.*[a-z])');
define('PASSWORD_UPPER', '(?=.*[A-Z])');
define('PASSWORD_NUMBER', '(?=.*\d)');
define('PASSWORD_SPECIAL', "(?=.*[".PASSWORD_SPECIAL_RANGE."])");
// define full regex
DEFINE('PASSWORD_REGEX', "/^".
define('PASSWORD_REGEX', "/^".
(defined('PASSWORD_LOWER') ? PASSWORD_LOWER : '').
(defined('PASSWORD_UPPER') ? PASSWORD_UPPER : '').
(defined('PASSWORD_NUMBER') ? PASSWORD_NUMBER : '').

View File

@@ -16,6 +16,6 @@
'perl_bin' => '',
'other_url' => '',
]
]*/
];*/
// __END__

View File

@@ -119,16 +119,18 @@ function setCenter(id, left, top)
/**
* goes to an element id position
* @param {String} element element id to move to
* @param {Number} offset offset from top, default is 0 (px)
* @param {String} element element id to move to
* @param {Number} [offset=0] offset from top, default is 0 (px)
* @param {Number} [duration=500] animation time, default 500ms
* @param {String} [base='body,html'] base element for offset scroll
*/
function goToPos(element, offset = 0)
function goToPos(element, offset = 0, duration = 500, base = 'body,html')
{
try {
if ($('#' + element).length) {
$('body,html').animate({
$(base).animate({
scrollTop: $('#' + element).offset().top - offset
}, 500);
}, duration);
}
} catch (err) {
errorCatch(err);
@@ -190,9 +192,9 @@ if (Number.prototype.round) {
*/
function numberWithCommas(x)
{
var parts = x.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return parts.join(".");
var parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
}
/**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
jquery-3.4.1.js
jquery-3.6.0.js

View File

@@ -1 +1 @@
jquery-3.4.1.min.js
jquery-3.6.0.min.js

View File

@@ -1701,6 +1701,10 @@ class Basic
// label name, including leading space if flagged
$pre = ($space ? ' ' : '').($labels[$exp] ?? '>E').($si ? 'i' : '').'B';
$bytes_calc = $abs_bytes / pow($unit, $exp);
// if original is negative, reverse
if ($bytes < 0) {
$bytes_calc *= -1;
}
if ($adjust) {
return sprintf("%.2f%sB", $bytes_calc, $pre);
} else {
@@ -2179,8 +2183,8 @@ class Basic
$thumbnail_write_path = null;
$thumbnail_web_path = null;
// path set first
if ($img_type == IMG_JPG ||
$img_type == IMG_PNG ||
if ($img_type == IMAGETYPE_JPEG ||
$img_type == IMAGETYPE_PNG ||
$create_dummy === true
) {
// $this->debug('IMAGE PREPARE', "IMAGE TYPE OK: ".$inc_width.'x'.$inc_height);
@@ -2196,8 +2200,8 @@ class Basic
}
}
// do resize or fall back on dummy run
if ($img_type == IMG_JPG ||
$img_type == IMG_PNG
if ($img_type == IMAGETYPE_JPEG ||
$img_type == IMAGETYPE_PNG
) {
// if missing width or height in thumb, use the set one
if ($thumb_width == 0) {
@@ -2238,7 +2242,7 @@ class Basic
) {
// image, copy source image, offset in image, source x/y, new size, source image size
$thumb = imagecreatetruecolor($thumb_width_r, $thumb_height_r);
if ($img_type == IMG_PNG) {
if ($img_type == IMAGETYPE_PNG) {
// preservere transaprency
imagecolortransparent(
$thumb,
@@ -2249,10 +2253,10 @@ class Basic
}
$source = null;
switch ($img_type) {
case IMG_JPG:
case IMAGETYPE_JPEG:
$source = imagecreatefromjpeg($filename);
break;
case IMG_PNG:
case IMAGETYPE_PNG:
$source = imagecreatefrompng($filename);
break;
}
@@ -2266,10 +2270,10 @@ class Basic
}
// write file
switch ($img_type) {
case IMG_JPG:
case IMAGETYPE_JPEG:
imagejpeg($thumb, $thumbnail_write_path.$thumbnail, $jpeg_quality);
break;
case IMG_PNG:
case IMAGETYPE_PNG:
imagepng($thumb, $thumbnail_write_path.$thumbnail);
break;
}
@@ -2371,10 +2375,10 @@ class Basic
if ($orientation != 1) {
$this->debug('IMAGE FILE ROTATE', 'Need to rotate image ['.$filename.'] from: '.$orientation);
switch ($img_type) {
case IMG_JPG:
case IMAGETYPE_JPEG:
$img = imagecreatefromjpeg($filename);
break;
case IMG_PNG:
case IMAGETYPE_PNG:
$img = imagecreatefrompng($filename);
break;
}
@@ -2397,10 +2401,10 @@ class Basic
}
// then rewrite the rotated image back to the disk as $filename
switch ($img_type) {
case IMG_JPG:
case IMAGETYPE_JPEG:
imagejpeg($img, $filename);
break;
case IMG_PNG:
case IMAGETYPE_PNG:
imagepng($img, $filename);
break;
}
@@ -3394,6 +3398,7 @@ class Basic
// Indesign
'application/x-indesign' => 'Adobe InDesign',
// Photoshop
'image/vnd.adobe.photoshop' => 'Adobe Photoshop',
'application/photoshop' => 'Adobe Photoshop',
// Illustrator
'application/illustrator' => 'Adobe Illustrator',

View File

@@ -273,6 +273,7 @@ class IO extends \CoreLibs\Basic
public $field_names = []; // array with the field names of the current query
public $insert_id; // last inserted ID
public $insert_id_ext; // extended insert ID (for data outside only primary key)
public $insert_id_arr; // always return as array, even if only one
private $temp_sql;
// other vars
private $nbsp = ''; // used by print_array recursion function
@@ -595,16 +596,16 @@ class IO extends \CoreLibs\Basic
private function __dbConvertEncoding($row)
{
// only do if array, else pass through row (can be false)
if (is_array($row)) {
if ($this->to_encoding && $this->db_encoding) {
// go through each row and convert the encoding if needed
foreach ($row as $key => $value) {
$from_encoding = mb_detect_encoding($value);
// convert only if encoding doesn't match and source is not pure ASCII
if ($from_encoding != $this->to_encoding && $from_encoding != 'ASCII') {
$row[$key] = mb_convert_encoding($value, $this->to_encoding, $from_encoding);
}
}
if (!is_array($row) || empty($this->to_encoding) || empty($this->db_encoding)
) {
return $row;
}
// go through each row and convert the encoding if needed
foreach ($row as $key => $value) {
$from_encoding = mb_detect_encoding($value);
// convert only if encoding doesn't match and source is not pure ASCII
if ($from_encoding != $this->to_encoding && $from_encoding != 'ASCII') {
$row[$key] = mb_convert_encoding($value, $this->to_encoding, $from_encoding);
}
}
return $row;
@@ -787,9 +788,12 @@ class IO extends \CoreLibs\Basic
// if we do not have a returning, we try to get it via the primary key and another select
if (!$this->returning_id) {
$this->insert_id = $this->db_functions->__dbInsertId($this->query, $this->pk_name);
$this->insert_id_ext = $this->insert_id;
$this->insert_id_arr[] = $this->insert_id;
} else {
$this->insert_id = [];
$this->insert_id_ext = [];
$this->insert_id_arr = [];
// 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
@@ -799,6 +803,7 @@ class IO extends \CoreLibs\Basic
)) {
// 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) {
@@ -1613,71 +1618,74 @@ class IO extends \CoreLibs\Basic
$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');
return false;
} else {
if ($this->db_debug) {
$this->__dbDebug('db', $this->__dbDebugPrepare($stm_name, $data), 'dbExecPrep', 'Q');
}
$result = $this->db_functions->__dbExecute($stm_name, $data);
if (!$result) {
$this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->printAr($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');
return false;
}
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']);
} elseif ($result) {
$this->insert_id = [];
$this->insert_id_ext = [];
// 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)
)) {
$this->insert_id[] = $_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 ||
!array_key_exists($this->prepare_cursor[$stm_name]['pk_name'], $this->insert_id[0])
) {
$this->insert_id_ext = $this->insert_id[0];
$this->insert_id = $this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']];
} elseif ($this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']]) {
$this->insert_id = $this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']];
}
} elseif (count($this->insert_id) == 0) {
// failed to get insert id
$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 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');
} 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');
}
}
return $result;
}
if ($this->db_debug) {
$this->__dbDebug('db', $this->__dbDebugPrepare($stm_name, $data), 'dbExecPrep', 'Q');
}
$result = $this->db_functions->__dbExecute($stm_name, $data);
if (!$result) {
$this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[$stm_name]['result'].']: '.$this->printAr($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');
return false;
}
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_ext = $this->insert_id;
$this->insert_id_arr[] = $this->insert_id;
} elseif ($result) {
$this->insert_id = [];
$this->insert_id_ext = [];
$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)
)) {
$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 ||
!array_key_exists($this->prepare_cursor[$stm_name]['pk_name'], $this->insert_id[0])
) {
$this->insert_id_ext = $this->insert_id[0];
$this->insert_id = $this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']];
} elseif ($this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']]) {
$this->insert_id = $this->insert_id[0][$this->prepare_cursor[$stm_name]['pk_name']];
}
} elseif (count($this->insert_id) == 0) {
// failed to get insert id
$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 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');
} 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');
}
}
return $result;
}
/**
@@ -2076,6 +2084,15 @@ class IO extends \CoreLibs\Basic
return $this->insert_id_ext;
}
/**
* Always returns the returning block as an array
* @return array All returning data as array. even if one row only
*/
public function dbGetReturningArray(): array
{
return $this->insert_id_arr;
}
/**
* returns the full array for cursor ext
* @param string|null $q Query string, if not null convert to md5