From bb5276ee44aedd98a463e5fef1e7e553eba6e6fc Mon Sep 17 00:00:00 2001 From: Clemens Schwaighofer Date: Wed, 1 Jul 2020 07:12:06 +0900 Subject: [PATCH] Smarty test, Basic class debug function upate Write out debug data had two nested ifs that are combined into one if Smarty test update with loop --- www/admin/smarty_test.php | 1 + www/includes/templates/admin/smarty_test.tpl | 8 +- www/lib/CoreLibs/Basic.php | 102 +++++++++---------- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/www/admin/smarty_test.php b/www/admin/smarty_test.php index 056328f4..6be829e4 100755 --- a/www/admin/smarty_test.php +++ b/www/admin/smarty_test.php @@ -52,6 +52,7 @@ $options = array ( if (is_object($smarty)) { $smarty->DATA['drop_down_test'] = $options; + $smarty->DATA['loop_start'] = 2; // require BASE.INCLUDES.'admin_smarty.php'; $smarty->setSmartyVarsAdmin(); } diff --git a/www/includes/templates/admin/smarty_test.tpl b/www/includes/templates/admin/smarty_test.tpl index 4b864299..002e9fae 100755 --- a/www/includes/templates/admin/smarty_test.tpl +++ b/www/includes/templates/admin/smarty_test.tpl @@ -12,13 +12,19 @@
+
+
LOOP TEST
+{section name=page_list start=1 loop=$loop_start+1} +
LOOP OUTPUT: {$smarty.section.page_list.index}
+{/section} +
{* progresss indicator *}
{* the action confirm box *} diff --git a/www/lib/CoreLibs/Basic.php b/www/lib/CoreLibs/Basic.php index 479e05dd..3554bb4b 100644 --- a/www/lib/CoreLibs/Basic.php +++ b/www/lib/CoreLibs/Basic.php @@ -866,64 +866,64 @@ class Basic */ private function writeErrorMsg(string $level, string $error_string): void { - if ($this->doDebugTrigger('debug', $level)) { - // only write if write is requested - if ($this->doDebugTrigger('print', $level)) { - // replace all html tags - // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string); - // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string); - // replace special line break tag - // $error_string = str_replace('', "\n", $error_string); + // only write if write is requested + if ($this->doDebugTrigger('debug', $level) && + $this->doDebugTrigger('print', $level) + ) { + // replace all html tags + // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "##\\2##", $error_string); + // $error_string = preg_replace("/(<\/?)(\w+)([^>]*>)/", "", $error_string); + // replace special line break tag + // $error_string = str_replace('', "\n", $error_string); - // init output variable - $output = $error_string; // output formated error string to output file - // init base file path - $fn = BASE.LOG.$this->log_print_file.'.'.$this->log_file_name_ext; - // log ID prefix settings, if not valid, replace with empty - if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) { - $rpl_string = '_'.$this->log_file_id; - } else { - $rpl_string = ''; + // init output variable + $output = $error_string; // output formated error string to output file + // init base file path + $fn = BASE.LOG.$this->log_print_file.'.'.$this->log_file_name_ext; + // log ID prefix settings, if not valid, replace with empty + if (preg_match("/^[A-Za-z0-9]+$/", $this->log_file_id)) { + $rpl_string = '_'.$this->log_file_id; + } else { + $rpl_string = ''; + } + $fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix) + + if ($this->log_per_run) { + if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) { + $this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID']; } - $fn = str_replace('##LOGID##', $rpl_string, $fn); // log id (like a log file prefix) - - if ($this->log_per_run) { - if (isset($GLOBALS['LOG_FILE_UNIQUE_ID'])) { - $this->log_file_unique_id = $GLOBALS['LOG_FILE_UNIQUE_ID']; - } - if (!$this->log_file_unique_id) { - $GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8); - } - $rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string - } else { - $rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file + if (!$this->log_file_unique_id) { + $GLOBALS['LOG_FILE_UNIQUE_ID'] = $this->log_file_unique_id = date('Y-m-d_His').'_U_'.substr(hash('sha1', uniqid((string)mt_rand(), true)), 0, 8); } - $fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename + $rpl_string = '_'.$this->log_file_unique_id; // add 8 char unique string + } else { + $rpl_string = !$this->log_print_file_date ? '' : '_'.date('Y-m-d'); // add date to file + } + $fn = str_replace('##DATE##', $rpl_string, $fn); // create output filename - $rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file - $fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename + $rpl_string = !$this->log_per_level ? '' : '_'.$level; // if request to write to one file + $fn = str_replace('##LEVEL##', $rpl_string, $fn); // create output filename - $rpl_string = !$this->log_per_class ? '' : '_'.str_replace('\\', '-', get_class($this)); // set sub class settings - $fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename + $rpl_string = !$this->log_per_class ? '' : '_'.str_replace('\\', '-', get_class($this)); // set sub class settings + $fn = str_replace('##CLASS##', $rpl_string, $fn); // create output filename - $rpl_string = !$this->log_per_page ? '' : '_'.$this->getPageName(1); // if request to write to one file - $fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename + $rpl_string = !$this->log_per_page ? '' : '_'.$this->getPageName(1); // if request to write to one file + $fn = str_replace('##PAGENAME##', $rpl_string, $fn); // create output filename - // write to file - // first check if max file size is is set and file is bigger - if ($this->log_max_filesize > 0 && ((filesize($fn) / 1024) > $this->log_max_filesize)) { - // for easy purpose, rename file only to attach timestamp, nur sequence numbering - rename($fn, $fn.'.'.date("YmdHis")); - } - $fp = fopen($fn, 'a'); - if ($fp !== false) { - fwrite($fp, $output); - fclose($fp); - } else { - echo ""; - } - } // do write to file - } + // write to file + // first check if max file size is is set and file is bigger + if ($this->log_max_filesize > 0 && ((filesize($fn) / 1024) > $this->log_max_filesize)) { + // for easy purpose, rename file only to attach timestamp, nur sequence numbering + rename($fn, $fn.'.'.date("YmdHis")); + } + $fp = fopen($fn, 'a'); + if ($fp !== false) { + fwrite($fp, $output); + fclose($fp); + } else { + echo ""; + } + } // do write to file } /**