From b6a35d15cf028063af19294001a322f1c31a0593 Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Mon, 30 Sep 2019 15:52:14 +0900 Subject: [PATCH] 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 --- .phan/config.php | 22 +++++++++++----------- www/configs/config.host.php | 3 +-- www/includes/admin_header.php | 10 ++++++++-- www/includes/admin_set_paths.php | 10 +++++----- www/includes/admin_smarty.php | 7 +++++++ www/lib/CoreLibs/Basic.php | 26 ++++++++++++++++++-------- www/lib/CoreLibs/DB/IO.php | 8 ++++---- 7 files changed, 54 insertions(+), 32 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 50101bc2..9770b8ef 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -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 diff --git a/www/configs/config.host.php b/www/configs/config.host.php index 8a09209f..d4f1d925 100755 --- a/www/configs/config.host.php +++ b/www/configs/config.host.php @@ -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: *********************************************************************/ diff --git a/www/includes/admin_header.php b/www/includes/admin_header.php index 73ba338c..ec99cf5d 100644 --- a/www/includes/admin_header.php +++ b/www/includes/admin_header.php @@ -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 diff --git a/www/includes/admin_set_paths.php b/www/includes/admin_set_paths.php index edb32f9c..25dabf07 100644 --- a/www/includes/admin_set_paths.php +++ b/www/includes/admin_set_paths.php @@ -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 diff --git a/www/includes/admin_smarty.php b/www/includes/admin_smarty.php index 2cc4d056..cc64eadd 100644 --- a/www/includes/admin_smarty.php +++ b/www/includes/admin_smarty.php @@ -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; diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 913a52c3..544747d4 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -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] diff --git a/www/lib/CoreLibs/DB/IO.php b/www/lib/CoreLibs/DB/IO.php index 3dec54d7..7bc748ad 100644 --- a/www/lib/CoreLibs/DB/IO.php +++ b/www/lib/CoreLibs/DB/IO.php @@ -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)