]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Commented out noisy debug line
[mailer.git] / inc / functions.php
index 1054326b7870dc11b961c847297fc0996220dba6..3ee3d3b1ae1cb86fc6b745d4c96b40b5460094dd 100644 (file)
@@ -104,8 +104,9 @@ function generatePassword ($length = '0', $exclude = array()) {
        } // END - while
 
        /*
-        * When the size is below 40 we can also add additional security by
-        * scrambling it. Otherwise the hash may corrupted..
+        * When the length of the password is below 40 characters additional
+        * security can be added by scrambling it. Otherwise the hash may
+        * corrupted.
         */
        if (strlen($password) <= 40) {
                // Also scramble the password
@@ -146,7 +147,7 @@ function generateDateTime ($time, $mode = '0') {
                                case '6': $ret = date('Ymd', $timeSecured); break;
                                case '7': $ret = date('Y-m-d H:i:s', $timeSecured); break; // Compatible with MySQL TIMESTAMP
                                default:
-                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
+                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf('Invalid date mode %s detected.', $mode));
                                        break;
                        } // END - switch
                        break;
@@ -162,7 +163,7 @@ function generateDateTime ($time, $mode = '0') {
                                case '6': $ret = date('Ymd', $timeSecured); break;
                                case '7': $ret = date('Y-m-d H:i:s', $timeSecured); break; // Compatible with MySQL TIMESTAMP
                                default:
-                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
+                                       logDebugMessage(__FUNCTION__, __LINE__, sprintf('Invalid date mode %s detected.', $mode));
                                        break;
                        } // END - switch
        } // END - switch
@@ -181,11 +182,16 @@ function translateYesNo ($yn) {
                // Default
                $GLOBALS[__FUNCTION__][$yn] = '??? (' . $yn . ')';
                switch ($yn) {
-                       case 'Y': $GLOBALS[__FUNCTION__][$yn] = '{--YES--}'; break;
-                       case 'N': $GLOBALS[__FUNCTION__][$yn] = '{--NO--}'; break;
-                       default:
-                               // Log unknown value
-                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected: Y/N", $yn));
+                       case 'Y': // Yes
+                               $GLOBALS[__FUNCTION__][$yn] = '{--YES--}';
+                               break;
+
+                       case 'N': // No
+                               $GLOBALS[__FUNCTION__][$yn] = '{--NO--}';
+                               break;
+
+                       default: // Log unknown value
+                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown value %s. Expected: Y/N', $yn));
                                break;
                } // END - switch
        } // END - if
@@ -201,11 +207,16 @@ function translateActivationStatus ($status) {
                // Default
                $GLOBALS[__FUNCTION__][$status] = '??? (' . $status . ')';
                switch ($status) {
-                       case 'Y': $GLOBALS[__FUNCTION__][$status] = '{--ACTIVATED--}'; break;
-                       case 'N': $GLOBALS[__FUNCTION__][$status] = '{--DEACTIVATED--}'; break;
-                       default:
-                               // Log unknown value
-                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected: Y/N", $status));
+                       case 'Y': // Activated
+                               $GLOBALS[__FUNCTION__][$status] = '{--ACTIVATED--}';
+                               break;
+
+                       case 'N': // Deactivated
+                               $GLOBALS[__FUNCTION__][$status] = '{--DEACTIVATED--}';
+                               break;
+
+                       default: // Log unknown value
+                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown value %s. Expected: Y/N', $status));
                                break;
                } // END - switch
        } // END - if
@@ -278,7 +289,7 @@ function translateGender ($gender) {
 
                default:
                        // Please report bugs on unknown genders
-                       reportBug(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender));
+                       reportBug(__FUNCTION__, __LINE__, sprintf('Unknown gender %s detected.', $gender));
                        break;
        } // END - switch
 
@@ -296,7 +307,7 @@ function translateUserStatus ($status) {
                case 'UNCONFIRMED':
                case 'CONFIRMED':
                case 'LOCKED':
-                       // Use generic function for all "normal" cases"
+                       // Use generic function for all "normal" cases
                        $ret = translateGeneric('ACCOUNT_STATUS', $status);
                        break;
 
@@ -306,7 +317,7 @@ function translateUserStatus ($status) {
                        break;
 
                default: // Please report all unknown status
-                       reportBug(__FUNCTION__, __LINE__, sprintf("Unknown status %s(%s) detected.", $status, gettype($status)));
+                       reportBug(__FUNCTION__, __LINE__, sprintf('Unknown status %s(%s) detected.', $status, gettype($status)));
                        break;
        } // END - switch
 
@@ -377,7 +388,7 @@ function generateDereferrerUrl ($url) {
 // Generates an URL for the frametester
 function generateFrametesterUrl ($url) {
        // Prepare frametester URL
-       $frametesterUrl = sprintf("{%%url=modules.php?module=frametester&amp;url=%s%%}",
+       $frametesterUrl = sprintf('{%%url=modules.php?module=frametester&amp;url=%s%%}',
                encodeString(compileUriCode($url))
        );
 
@@ -618,13 +629,16 @@ function bigintval ($num, $castValue = TRUE, $abortOnMismatch = TRUE) {
 
 // Creates a Uni* timestamp from given selection data and prefix
 function createEpocheTimeFromSelections ($prefix, $postData) {
+       // Assert on typical array element (maybe all?)
+       assert(isset($postData[$prefix . '_ye']));
+
        // Initial return value
        $ret = '0';
 
        // Is there a leap year?
        $SWITCH = '0';
-       $TEST = getYear() / 4;
-       $M1   = getMonth();
+       $TEST   = getYear() / 4;
+       $M1     = getMonth();
 
        // If so and if current time is before 02/29 and estimated time is after 02/29 then add 86400 seconds (one day)
        // 01     2     2         1    1           1    123     4                          43    3                                 32    233    4                          43    3                                 3210
@@ -708,7 +722,7 @@ function isEmailValid ($email) {
 
        // Return check result
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'email=' . $email . ',isValid=' . intval($GLOBALS[__FUNCTION__][$email]) . ' - EXIT!');
-       return $GLOBALS[__FUNCTION__][$email];;
+       return $GLOBALS[__FUNCTION__][$email];
 }
 
 // Function taken from user comments on www.php.net / function isInStringIgnoreCase()
@@ -831,10 +845,8 @@ function scrambleString ($str) {
                $scrambleNums = explode(':', genScrambleString(strlen($str)));
        }
 
-       // Compare both lengths and abort if different
-       if (strlen($str) != count($scrambleNums)) {
-               return $str;
-       } // END - if
+       // Assert on both lengths
+       assert(strlen($str) == count($scrambleNums));
 
        // Scramble string here
        //* DEBUG: */ debugOutput('***Original=' . $str.'***<br />');
@@ -900,6 +912,8 @@ function genScrambleString ($len) {
 
        // So let's create the string for storing it in database
        $scrambleString = implode(':', $scrambleNumbers);
+
+       // Return it
        return $scrambleString;
 }
 
@@ -928,6 +942,7 @@ function encodeHashForCookie ($passHash) {
 
                        // Default is hexadecimal of index if both are same
                        $mod = dechex($idx);
+
                        // Is part1 larger or part2 than its counter part?
                        if ($part1 > $part2) {
                                // part1 is larger
@@ -984,13 +999,13 @@ function getCurrentTheme () {
        if (isExtensionActive('theme')) {
                // Call inner method
                $ret = getActualTheme();
-       } elseif ((isPostRequestElementSet('theme')) && (isIncludeReadable(sprintf("theme/%s/theme.php", postRequestElement('theme'))))) {
+       } elseif ((isPostRequestElementSet('theme')) && (isThemeReadable(postRequestElement('theme')))) {
                // Use value from POST data
                $ret = postRequestElement('theme');
-       } elseif ((isGetRequestElementSet('theme')) && (isIncludeReadable(sprintf("theme/%s/theme.php", getRequestElement('theme'))))) {
+       } elseif ((isGetRequestElementSet('theme')) && (isThemeReadable(getRequestElement('theme')))) {
                // Use value from GET data
                $ret = getRequestElement('theme');
-       } elseif ((isMailerThemeSet()) && (isIncludeReadable(sprintf("theme/%s/theme.php", getMailerTheme())))) {
+       } elseif ((isMailerThemeSet()) && (isThemeReadable(getMailerTheme()))) {
                // Use value from GET data
                $ret = getMailerTheme();
        }
@@ -1011,7 +1026,7 @@ function generateErrorCodeFromUserStatus ($status = '') {
        $errorCode = getCode('ACCOUNT_UNKNOWN');
 
        // Generate constant name
-       $codeName = sprintf("ACCOUNT_%s", strtoupper($status));
+       $codeName = sprintf('ACCOUNT_%s', strtoupper($status));
 
        // Is the constant there?
        if (isCodeSet($codeName)) {
@@ -1019,7 +1034,7 @@ function generateErrorCodeFromUserStatus ($status = '') {
                $errorCode = getCode($codeName);
        } else {
                // Unknown status
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown error status %s detected.", $status));
+               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown error status %s detected.', $status));
        }
 
        // Return error code
@@ -2727,6 +2742,9 @@ function hashSha256 ($str) {
                $hex .= padLeftZero(dechex(ord(substr($hash, $i, 1))), 2);
        } // END - if
 
+       // Make sure 'length modulo 2' = 0
+       assert((strlen($hex) % 2) == 0);
+
        // Return it
        return $hex;
 }
@@ -2895,5 +2913,17 @@ function getBasePathFromTheme ($theme) {
        return sprintf('%stheme/%s/css/', getPath(), $theme);
 }
 
+// Wrapper to check whether given theme is readable
+function isThemeReadable ($theme) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$theme])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__][$theme] = (isIncludeReadable(sprintf('theme/%s/theme.php', $theme)));
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$theme];
+}
+
 // [EOF]
 ?>