From 94dfc84e957b11b3a653f30ef56c1f5fea8b36af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 9 Sep 2024 04:07:41 +0200 Subject: [PATCH] Continued: - added primitive type-hints for string, int - each() has been removed in 8.0.0, let's use foreach() instead which is even much simplier code than while(), list() and each() calls MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- libs/lib_general.php | 24 ++++++++++++------------ libs/lib_updates.php | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/libs/lib_general.php b/libs/lib_general.php index ad4f25b..c7c6e93 100644 --- a/libs/lib_general.php +++ b/libs/lib_general.php @@ -25,7 +25,7 @@ // Implode recursive a multi-dimension array, taken from www.php.net function implode_r (string $glue, array $array, string $array_name = NULL) { $return = []; - while (list($key,$value) = @each($array)) { + foreach ($array as $key => $value) { if (is_array($value)) { // Is an array again, so call recursive $return[] = implode_r($glue, $value, (string) $key); @@ -280,7 +280,7 @@ function crackerTrackerSecured () { } // Secures a string by escaping it and passing it through strip_tags,htmlentities-chain -function crackerTrackerSecureString ($str) { +function crackerTrackerSecureString (string $str) { // First escape it $str = crackerTrackerEscapeString($str); @@ -292,13 +292,13 @@ function crackerTrackerSecureString ($str) { } // Is the file there and readable? -function isCrackerTrackerFileFound ($FQFN) { +function isCrackerTrackerFileFound (string $FQFN) { // Simply check it return ((file_exists($FQFN)) && (is_readable($FQFN))); } // Loads a given "template" (this is more an include file) -function crackerTrackerLoadTemplate ($template) { +function crackerTrackerLoadTemplate (string $template) { // Create the full-qualified filename (FQFN) $FQFN = sprintf('%s/libs/templates/%s.tpl.php', $GLOBALS['ctracker_base_path'], @@ -319,7 +319,7 @@ function crackerTrackerLoadTemplate ($template) { } // Loads a given "template" (this is more an include file) -function crackerTrackerLoadLocalizedTemplate ($template) { +function crackerTrackerLoadLocalizedTemplate (string $template) { // Create the full-qualified filename (FQFN) $FQFN = sprintf('%s/libs/templates/%s/%s.tpl.php', $GLOBALS['ctracker_base_path'], @@ -379,7 +379,7 @@ function crackerTrackerLanguage () { } // Loads a given email template and passes through $content -function crackerTrackerLoadEmailTemplate ($template, array $content = [], $language = NULL) { +function crackerTrackerLoadEmailTemplate (string $template, array $content = [], string $language = NULL) { // Init language crackerTrackerLanguage(); @@ -408,7 +408,7 @@ function crackerTrackerLoadEmailTemplate ($template, array $content = [], $langu } // Getter for message -function getCrackerTrackerLocalized ($message) { +function getCrackerTrackerLocalized (string $message) { // Default message $output = '!' . $message . '!'; @@ -423,13 +423,13 @@ function getCrackerTrackerLocalized ($message) { } // Tries to find a message and outputs it -function crackerTrackerOutputLocalized ($message) { +function crackerTrackerOutputLocalized (string $message) { // Output it print getCrackerTrackerLocalized($message); } // Compiles the given code -function crackerTrackerCompileCode ($code) { +function crackerTrackerCompileCode (string $code) { // Find all $content[foo] preg_match_all('/\$(content|GLOBALS)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches); @@ -453,7 +453,7 @@ function crackerTrackerCompileCode ($code) { } // "Getter" for language -function getCrackerTrackerLanguage ($lang = NULL) { +function getCrackerTrackerLanguage (string $lang = NULL) { // Default is from browser $language = $GLOBALS['ctracker_language']; @@ -516,7 +516,7 @@ function crackerTrackerRedirectSameUrl () { * @link http://support.microsoft.com/kb/q176113/ * @author Andreas Gohr */ -function crackerTrackerSendRawRedirect ($url) { +function crackerTrackerSendRawRedirect (string $url) { // Better remove any data by ctracker unsetCtrackerData(); @@ -577,7 +577,7 @@ function unsetCtrackerData () { } // Sanitizes string -function crackerTrackerSanitize ($str) { +function crackerTrackerSanitize (string $str) { return str_replace(array('//', '/./'), array('/', '/'), $str); } diff --git a/libs/lib_updates.php b/libs/lib_updates.php index df87a9c..2a84cd9 100644 --- a/libs/lib_updates.php +++ b/libs/lib_updates.php @@ -139,7 +139,7 @@ FOREIGN KEY ( `ctracker_data_id` ) REFERENCES `' . $GLOBALS['ctracker_dbname'] . } // Runs the given updates at number X -function runCrackerTrackerUpdates ($update) { +function runCrackerTrackerUpdates (int $update) { // We assume it is set foreach ($GLOBALS['ctracker_updates'][$update] as $sql) { // Run the SQL command -- 2.39.5