]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Speed improvement, TODOs.txt updated:
[mailer.git] / inc / functions.php
index 4b25ba977704ed82f709b48713f0e574d5c634f6..f4c11ee73f7b3bc559a875973ec415f12911a926 100644 (file)
@@ -1931,7 +1931,9 @@ function addNewBonusMail ($data, $mode = '', $output = true) {
 // Determines referal id and sets it
 function determineReferalId () {
        // Skip this in non-html-mode and outside ref.php
-       if ((!isHtmlOutputMode()) && (basename($_SERVER['PHP_SELF']) != 'ref.php')) return false;
+       if ((!isHtmlOutputMode()) && (basename($_SERVER['PHP_SELF']) != 'ref.php')) {
+               return false;
+       } // END - if
 
        // Check if refid is set
        if ((isset($GLOBALS['refid'])) && ($GLOBALS['refid'] > 0)) {
@@ -2126,7 +2128,7 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
 
                        // And skip further processing
                        continue;
-               } elseif (substr($baseFile, 0, strlen($prefix)) != $prefix) {
+               } elseif (!isFilePrefixFound($baseFile, $prefix)) {
                        // Skip this file
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Invalid prefix in file ' . $baseFile . ', prefix=' . $prefix);
                        continue;
@@ -2140,9 +2142,12 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
                        continue;
                }
 
+               // Get file' extension (last 4 chars)
+               $fileExtension = substr($baseFile, -4, 4);
+
                // Is the file a PHP script or other?
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'baseDir=' . $baseDir . ',prefix=' . $prefix . ',baseFile=' . $baseFile);
-               if ((substr($baseFile, -4, 4) == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) {
+               if (($fileExtension == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) {
                        // Is this a valid include file?
                        if ($extension == '.php') {
                                // Remove both for extension name
@@ -2158,9 +2163,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
                                }
                        } else {
                                // We found .php file but should not search for them, why?
-                               debug_report_bug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script.');
+                               debug_report_bug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')');
                        }
-               } elseif (substr($baseFile, -4, 4) == $extension) {
+               } elseif ($fileExtension == $extension) {
                        // Other, generic file found
                        $files[] = $fileName;
                }
@@ -2177,6 +2182,12 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $ad
        return $files;
 }
 
+// Checks wether $prefix is found in $fileName
+function isFilePrefixFound ($fileName, $prefix) {
+       // @TODO Find a way to cache this
+       return (substr($fileName, 0, strlen($prefix)) == $prefix);
+}
+
 // Maps a module name into a database table name
 function mapModuleToTable ($moduleName) {
        // Map only these, still lame code...
@@ -2298,7 +2309,10 @@ function getModuleFromFileName ($file, $accessLevel) {
 // Encodes an URL for adding session id, etc.
 function encodeUrl ($url, $outputMode = '0') {
        // Do we have already have a PHPSESSID inside or view.php is called? Then abort here
-       if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) return $url;
+       if ((strpos($url, session_name()) !== false) || (isRawOutputMode())) {
+               // Raw output mode detected or session_name() found in URL
+               return $url;
+       } // END - if
 
        // Do we have a valid session?
        if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === false) || (!isset($_COOKIE[session_name()]))) && (isSpider() === false)) {
@@ -2309,7 +2323,7 @@ function encodeUrl ($url, $outputMode = '0') {
                        // No question mark
                        $seperator = '?';
                } elseif ((!isHtmlOutputMode()) || ($outputMode != '0')) {
-                       // Non-HTML mode
+                       // Non-HTML mode (or forced non-HTML mode
                        $seperator = '&';
                }