]> git.mxchange.org Git - ctracker.git/commitdiff
Continued: master
authorRoland Häder <roland@mxchange.org>
Mon, 7 Jul 2025 02:24:19 +0000 (04:24 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 7 Jul 2025 02:24:19 +0000 (04:24 +0200)
- added more returned types

libs/lib_general.php

index f5aca950391cf75cf22f6aa230ff615d75b89e66..bc284d31d253789b4235cf0dbc4a798068a368d9 100644 (file)
@@ -23,7 +23,7 @@
  */
 
 // Implode recursive a multi-dimension array, taken from www.php.net
-function implode_r (string $glue, array $array, string $array_name = NULL) {
+function implode_r (string $glue, array $array, string $array_name = NULL): string {
        $return = [];
        foreach ($array as $key => $value) {
                if (is_array($value)) {
@@ -43,7 +43,7 @@ function implode_r (string $glue, array $array, string $array_name = NULL) {
 }
 
 // Implode a simple array with a 'call-back' to our escaper function
-function implode_secure (array $array) {
+function implode_secure (array $array): string {
        // Return string
        $return = '';
 
@@ -70,7 +70,7 @@ function implode_secure (array $array) {
 }
 
 // Load configuration, if found
-function crackerTrackerLoadConfiguration () {
+function crackerTrackerLoadConfiguration (): void {
        // FQFN
        $fqfn = sprintf('%s/config/db_config.php', $GLOBALS['ctracker_base_path']);
 
@@ -88,7 +88,7 @@ function crackerTrackerLoadConfiguration () {
 }
 
 // Getter for ctracker_debug_enabled
-function isCrackerTrackerDebug () {
+function isCrackerTrackerDebug (): bool {
        // Is it set?
        $result = ((isset($GLOBALS['ctracker_debug_enabled'])) && ($GLOBALS['ctracker_debug_enabled'] === true));
 
@@ -100,7 +100,7 @@ function isCrackerTrackerDebug () {
 }
 
 // Determines the real remote address
-function determineCrackerTrackerRealRemoteAddress () {
+function determineCrackerTrackerRealRemoteAddress (): string {
        // Initial value
        $address = '0.0.0.0';
 
@@ -130,7 +130,7 @@ function determineCrackerTrackerRealRemoteAddress () {
 }
 
 // Determine if a proxy was used
-function isCrackerTrackerProxyUsed () {
+function isCrackerTrackerProxyUsed (): bool {
        // Check if specific entries are set
        $proxyUsed = ((isset($_SERVER['HTTP_X_FORWARDED_FOR'])) || (isset($_SERVER['HTTP_CLIENT_IP'])));
 
@@ -139,7 +139,7 @@ function isCrackerTrackerProxyUsed () {
 }
 
 // Detects the user-agent string
-function crackerTrackerUserAgent (bool $sanitize = false) {
+function crackerTrackerUserAgent (bool $sanitize = false): string {
        // Default is 'unknown'
        $ua = 'unknown';
 
@@ -160,7 +160,7 @@ function crackerTrackerUserAgent (bool $sanitize = false) {
 }
 
 // Detects the script name
-function crackerTrackerScriptName (bool $sanitize = false) {
+function crackerTrackerScriptName (bool $sanitize = false): string {
        // Default is NULL
        $scriptName = NULL;
 
@@ -181,7 +181,7 @@ function crackerTrackerScriptName (bool $sanitize = false) {
 }
 
 // Detects the query string
-function crackerTrackerQueryString (bool $sanitize = false) {
+function crackerTrackerQueryString (bool $sanitize = false): string {
        // Default is NULL
        $query = NULL;
 
@@ -205,7 +205,7 @@ function crackerTrackerQueryString (bool $sanitize = false) {
 }
 
 // Detects the server's name
-function crackerTrackerServerName (bool $sanitize = false) {
+function crackerTrackerServerName (bool $sanitize = false): string {
        // Default is NULL
        $serverName = NULL;
 
@@ -226,7 +226,7 @@ function crackerTrackerServerName (bool $sanitize = false) {
 }
 
 // Detects the referer
-function crackerTrackerReferer (bool $sanitize = false) {
+function crackerTrackerReferer (bool $sanitize = false): string {
        // Default is a dash
        $referer = '-';
 
@@ -247,7 +247,7 @@ function crackerTrackerReferer (bool $sanitize = false) {
 }
 
 // Detects request method
-function crackerTrackerRequestMethod () {
+function crackerTrackerRequestMethod (): string {
        // Default is NULL
        $method = NULL;
 
@@ -262,7 +262,7 @@ function crackerTrackerRequestMethod () {
 }
 
 // Detects the scripts path
-function crackerTrackerScriptPath () {
+function crackerTrackerScriptPath (): string {
        // Should always be there!
        $path = dirname(crackerTrackerScriptName()) . '/';
 
@@ -271,7 +271,7 @@ function crackerTrackerScriptPath () {
 }
 
 // Detects wether we have SSL
-function crackerTrackerSecured () {
+function crackerTrackerSecured (): bool {
        // Detect it
        $ssl = ((isset($_SERVER['HTTPS'])) && ($_SERVER['HTTPS'] != 'off'));
 
@@ -280,7 +280,7 @@ function crackerTrackerSecured () {
 }
 
 // Secures a string by escaping it and passing it through strip_tags,htmlentities-chain
-function crackerTrackerSecureString (string $str) {
+function crackerTrackerSecureString (string $str): string {
        // First escape it
        $str = crackerTrackerEscapeString($str);
 
@@ -292,13 +292,13 @@ function crackerTrackerSecureString (string $str) {
 }
 
 // Is the file there and readable?
-function isCrackerTrackerFileFound (string $FQFN) {
+function isCrackerTrackerFileFound (string $FQFN): bool {
        // Simply check it
        return ((file_exists($FQFN)) && (is_readable($FQFN)));
 }
 
 // Loads a given "template" (this is more an include file)
-function crackerTrackerLoadTemplate (string $template) {
+function crackerTrackerLoadTemplate (string $template): void {
        // Create the full-qualified filename (FQFN)
        $FQFN = sprintf('%s/libs/templates/%s.tpl.php',
                $GLOBALS['ctracker_base_path'],
@@ -311,7 +311,7 @@ function crackerTrackerLoadTemplate (string $template) {
                crackerTrackerLanguage();
 
                // Load it
-               require_once($FQFN);
+               require_once $FQFN;
        } else {
                // Not found, so die here
                crackerTrackerDie();
@@ -319,7 +319,7 @@ function crackerTrackerLoadTemplate (string $template) {
 }
 
 // Loads a given "template" (this is more an include file)
-function crackerTrackerLoadLocalizedTemplate (string $template) {
+function crackerTrackerLoadLocalizedTemplate (string $template): void {
        // Create the full-qualified filename (FQFN)
        $FQFN = sprintf('%s/libs/templates/%s/%s.tpl.php',
                $GLOBALS['ctracker_base_path'],
@@ -330,7 +330,7 @@ function crackerTrackerLoadLocalizedTemplate (string $template) {
        // Is this template found?
        if (isCrackerTrackerFileFound($FQFN)) {
                // Load it
-               require_once($FQFN);
+               require_once $FQFN;
        } else {
                // Not found, so die here
                crackerTrackerDie();
@@ -338,7 +338,7 @@ function crackerTrackerLoadLocalizedTemplate (string $template) {
 }
 
 // Detects the browser's language file and tries to load it, fall-back on english!
-function crackerTrackerLanguage () {
+function crackerTrackerLanguage (): void {
        // Default is English
        $GLOBALS['ctracker_language'] = 'en';
        $weight = 1;
@@ -375,11 +375,11 @@ function crackerTrackerLanguage () {
        }
 
        // Load the language file
-       require($FQFN);
+       require $FQFN;
 }
 
 // Loads a given email template and passes through $content
-function crackerTrackerLoadEmailTemplate (string $template, array $content = [], string $language = NULL) {
+function crackerTrackerLoadEmailTemplate (string $template, array $content = [], string $language = NULL): string {
        // Init language
        crackerTrackerLanguage();
 
@@ -408,7 +408,7 @@ function crackerTrackerLoadEmailTemplate (string $template, array $content = [],
 }
 
 // Getter for message
-function getCrackerTrackerLocalized (string $message) {
+function getCrackerTrackerLocalized (string $message): string {
        // Default message
        $output = '!' . $message . '!';
 
@@ -423,13 +423,13 @@ function getCrackerTrackerLocalized (string $message) {
 }
 
 // Tries to find a message and outputs it
-function crackerTrackerOutputLocalized (string $message) {
+function crackerTrackerOutputLocalized (string $message): void {
        // Output it
        print getCrackerTrackerLocalized($message);
 }
 
 // Compiles the given code
-function crackerTrackerCompileCode (string $code) {
+function crackerTrackerCompileCode (string $code): string {
        // Find all $content[foo]
        preg_match_all('/\$(content|GLOBALS)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
 
@@ -453,7 +453,7 @@ function crackerTrackerCompileCode (string $code) {
 }
 
 // "Getter" for language
-function getCrackerTrackerLanguage (string $lang = NULL) {
+function getCrackerTrackerLanguage (string $lang = NULL): string {
        // Default is from browser
        $language = $GLOBALS['ctracker_language'];
 
@@ -468,7 +468,7 @@ function getCrackerTrackerLanguage (string $lang = NULL) {
 }
 
 // "Getter" for ticket id
-function getCrackerTrackerTicketId () {
+function getCrackerTrackerTicketId (): int {
        // Default is zero
        $id = 0;
 
@@ -483,7 +483,7 @@ function getCrackerTrackerTicketId () {
 }
 
 // Sends a cookie to the user that he would not see this security warning again
-function sendCrackerTrackerCookie () {
+function sendCrackerTrackerCookie (): void {
        // Set the cookie
        // @TODO Why can't domain be set to value from crackerTrackerServerName() ?
        setcookie('ctracker_ticket', getCrackerTrackerTicketId(), (time() + 60*60*24), '/', '', crackerTrackerSecured(), true);
@@ -491,13 +491,13 @@ function sendCrackerTrackerCookie () {
 }
 
 // Is the cookie set?
-function ifCrackerTrackerCookieIsSet () {
+function ifCrackerTrackerCookieIsSet (): bool {
        // Is it set and valid?
        return ((isset($_COOKIE['ctracker_ticket'])) && ($_COOKIE['ctracker_ticket'] > 0));
 }
 
 // Redirects to the same URL
-function crackerTrackerRedirectSameUrl () {
+function crackerTrackerRedirectSameUrl (): void {
        // Construct and redirect to same URL
        crackerTrackerSendRawRedirect(sprintf('%s://%s%s?%s',
                (crackerTrackerSecured() ? 'https' : 'http'),