Basic: resurcive array search, IO unset fix

Basic: recusrive array search has correct parameter declarations &
checks for null/empty/not string

IO: all unset are removed and null or init to array is used to reset

Update for other include pages with some missing default data
This commit is contained in:
Clemens Schwaighofer
2019-09-30 15:52:14 +09:00
parent 20c44694e8
commit 0cdf003752
7 changed files with 54 additions and 32 deletions

View File

@@ -82,17 +82,17 @@ return [
// A list of directories holding code that we want
// to parse, but not analyze
"exclude_analysis_directory_list" => [
'www/vendor',
'www/lib/FileUpload',
'www/lib/pChart',
'www/lib/pChart2.1.4',
'www/lib/Smarty',
'www/lib/smarty-3.1.30',
'www/templates_c',
'www/log',
'www/tmp',
'www/cache',
'www/media',
'www/vendor',
'www/lib/FileUpload',
'www/lib/pChart',
'www/lib/pChart2.1.4',
'www/lib/Smarty',
'www/lib/smarty-3.1.30',
'www/templates_c',
'www/log',
'www/tmp',
'www/cache',
'www/media',
],
'exclude_file_list' => [
// ignore all symlink files to edit

View File

@@ -7,8 +7,7 @@
* - DB access name (array group from config.db)
* - location (test/stage/live)
* - debug flag (true/false)
* - DB path (eg PUBLIC_SCHEMA)
* - stie lang
* - site lang
* HISTORY:
*********************************************************************/

View File

@@ -27,6 +27,12 @@ $SET_SESSION_NAME = EDIT_SESSION_NAME;
//------------------------------ library include end
//------------------------------ basic variable settings start
if (!isset($AJAX_PAGE)) {
$AJAX_PAGE = false;
}
if (!isset($ZIP_STREAM)) {
$ZIP_STREAM = false;
}
// set encoding
if (!isset($encoding)) {
$encoding = DEFAULT_ENCODING;
@@ -38,10 +44,10 @@ if (session_id() && $_SESSION['DEFAULT_LANG']) {
$lang = defined('SITE_LANG') ? SITE_LANG : DEFAULT_LANG;
}
// end the stop of the output flow, but only if we didn't request a csv file download
if (array_key_exists('action', $_POST) && $_POST['action'] != 'download_csv') {
if (isset($_POST['action']) && $_POST['action'] != 'download_csv' && !$AJAX_PAGE) {
header("Content-type: text/html; charset=".$encoding);
}
if (isset($AJAX_PAGE) && isset($ZIP_STREAM) && $AJAX_PAGE && !$ZIP_STREAM) {
if ($AJAX_PAGE && !$ZIP_STREAM) {
header("Content-Type: application/json; charset=UTF-8");
}
//------------------------------ basic variable settings start

View File

@@ -29,21 +29,21 @@ if (isset($_SESSION['DEFAULT_LANG'])) {
$lang_short = substr($lang, 0, 2);
// set include & template names
$PAGE_FILE_NAME = str_replace(".php", "", $cms->page_name);
$PAGE_FILE_NAME = str_replace('.php', '', $cms->page_name);
// set include & template names
if (!isset($CONTENT_INCLUDE)) {
$CONTENT_INCLUDE = $PAGE_FILE_NAME.'.tpl';
}
$FORM_NAME = !isset($FORM_NAME) || !$FORM_NAME ? str_replace(".php", "", $cms->page_name) : $FORM_NAME;
$FORM_NAME = !isset($FORM_NAME) || !$FORM_NAME ? str_replace('.php', '', $cms->page_name) : $FORM_NAME;
// set local page title
$L_TITLE = ucfirst(str_replace('_', ' ', $cms->getPageName(1))).(defined(G_TITLE) ? ' - '.G_TITLE : '');
// strip tpl and replace it with php
// php include file per page
$cms->INC_TEMPLATE_NAME = str_replace(".tpl", ".php", $CONTENT_INCLUDE);
$cms->INC_TEMPLATE_NAME = str_replace('.tpl', '.php', $CONTENT_INCLUDE);
// javascript include per page
$cms->JS_TEMPLATE_NAME = str_replace(".tpl", ".js", $CONTENT_INCLUDE);
$cms->JS_TEMPLATE_NAME = str_replace('.tpl', '.js', $CONTENT_INCLUDE);
// css per page
$cms->CSS_TEMPLATE_NAME = str_replace(".tpl", ".css", $CONTENT_INCLUDE);
$cms->CSS_TEMPLATE_NAME = str_replace('.tpl', '.css', $CONTENT_INCLUDE);
// special CSS file
$cms->CSS_SPECIAL_TEMPLATE_NAME = isset($CSS_NAME) ? $CSS_NAME : '';
// special JS file

View File

@@ -69,16 +69,23 @@ $cms->DATA['messages'] = $cms->messages;
// top menu
$cms->DATA['nav_menu'] = $cms->adbTopMenu();
$cms->DATA['nav_menu_count'] = is_array($cms->DATA['nav_menu']) ? count($cms->DATA['nav_menu']) : 0;
// the page name
$cms->DATA['page_name'] = $cms->page_name;
// user name
$cms->DATA['USER_NAME'] = $_SESSION['USER_NAME'];
$cms->DATA['ADMIN'] = $login->acl['admin'];
// the template part to include into the body
$cms->DATA['TEMPLATE_NAME'] = $TEMPLATE_NAME;
$cms->DATA['CONTENT_INCLUDE'] = $CONTENT_INCLUDE;
$cms->DATA['TEMPLATE_TRANSLATE'] = $TEMPLATE_TRANSLATE;
$cms->DATA['PAGE_FILE_NAME'] = $PAGE_FILE_NAME;
// LANG
$cms->DATA['LANG'] = $lang;
$cms->DATA['TINYMCE_LANG'] = $lang_short;
// form name
$cms->DATA['FORM_NAME'] = $FORM_NAME;
// include flags
$cms->DATA['USE_TINY_MCE'] = isset($USE_TINY_MCE) ? $USE_TINY_MCE : false;
$cms->DATA['JS_DATEPICKR'] = isset($JS_DATEPICKR) ? $JS_DATEPICKR : false;
$cms->DATA['JS_FLATPICKR'] = isset($JS_FLATPICKR) ? $JS_FLATPICKR : false;

View File

@@ -471,13 +471,22 @@ class Basic
* if strict mode is set, throws an error if the class variable is not set
* default is strict mode false
* @param mixed $name class variable name
* @return void
* @return mixed return set variable content
*/
public function __get($name): void
public function &__get($name)
{
if ($this->set_strict_mode === true && !property_exists($this, $name)) {
trigger_error('Undefined property via __get(): '.$name, E_USER_NOTICE);
}
// on set return
if (property_exists($this, $name)) {
return $this->$name;
} elseif ($this->set_compatible === true && !property_exists($this, $name)) {
// if it is not set, and we are in compatible mode we need to init.
// This is so that $class->array['key'] = 'bar'; works
$this->{$name} = null;
return $this->$name;
}
}
// *************************************************************
@@ -1164,18 +1173,19 @@ class Basic
/**
* searches key = value in an array / array
* only returns the first one found
* @param string|int $needle needle (search for)
* @param array $haystack haystack (search in)
* @param string $key_lookin the key to look out for, default empty
* @return ?array array with the elements where the needle can be found in the haystack array
* @param string|int $needle needle (search for)
* @param array $haystack haystack (search in)
* @param string|null $key_lookin the key to look out for, default empty
* @return array array with the elements where the needle can be
* found in the haystack array
*/
public static function arraySearchRecursive($needle, array $haystack, $key_lookin = ''): ?array
public static function arraySearchRecursive($needle, array $haystack, ?string $key_lookin = null): array
{
$path = array();
if (!is_array($haystack)) {
$haystack = array();
}
if (!is_array($key_lookin) &&
if ($key_lookin != null &&
!empty($key_lookin) &&
array_key_exists($key_lookin, $haystack) &&
$needle === $haystack[$key_lookin]

View File

@@ -305,8 +305,8 @@ class IO extends \CoreLibs\Basic
/**
* main DB concstructor with auto connection to DB and failure set on failed connection
* @param array $db_config DB configuration array
* @param int|integer $set_control_flag Class set control flag
* @param array $db_config DB configuration array
* @param int $set_control_flag 0/1/2/3 to set internal class parameter check
*/
public function __construct(array $db_config, int $set_control_flag = 0)
{
@@ -1056,7 +1056,7 @@ class IO extends \CoreLibs\Basic
// if it is a call with reset in it we reset the cursor, so we get an uncached return
// but only for the FIRST call (pos == 0)
if ($reset && !$this->cursor_ext[$md5]['pos']) {
unset($this->cursor_ext[$md5]['cursor']);
$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);
@@ -1156,7 +1156,7 @@ class IO extends \CoreLibs\Basic
// return row, if last && reset, then unset the hole md5 array
if (!$return && ($reset == 1 || $reset == 3) && $this->cursor_ext[$md5]['pos']) {
// unset only the field names here of course
unset($this->cursor_ext[$md5]['field_names']);
$this->cursor_ext[$md5]['field_names'] = array();
$this->cursor_ext[$md5]['pos'] = 0;
} elseif (!$return && $reset == 2 && $this->cursor_ext[$md5]['pos']) {
// at end of read reset pos & set cursor to 1 (so it does not get lost in session transfer)