]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Parser error fixed + some empty lines added between table rows (tr)
[mailer.git] / inc / functions.php
index b9c3f1f699efe2dc8825a78f367cb7d057d63b55..983af617efee24b6cf516f10eacfea54b8253fc4 100644 (file)
@@ -146,7 +146,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 +162,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
@@ -185,7 +185,7 @@ function translateYesNo ($yn) {
                        case 'N': $GLOBALS[__FUNCTION__][$yn] = '{--NO--}'; break;
                        default:
                                // Log unknown value
-                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected: Y/N", $yn));
+                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown value %s. Expected: Y/N', $yn));
                                break;
                } // END - switch
        } // END - if
@@ -205,7 +205,7 @@ function translateActivationStatus ($status) {
                        case 'N': $GLOBALS[__FUNCTION__][$status] = '{--DEACTIVATED--}'; break;
                        default:
                                // Log unknown value
-                               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected: Y/N", $status));
+                               logDebugMessage(__FUNCTION__, __LINE__, sprintf('Unknown value %s. Expected: Y/N', $status));
                                break;
                } // END - switch
        } // END - if
@@ -278,7 +278,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 +296,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 +306,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
 
@@ -766,7 +766,13 @@ function generateHash ($plainText, $salt = '', $hash = TRUE) {
                $server = $_SERVER['PHP_SELF'] . getEncryptSeparator() . detectUserAgent() . getEncryptSeparator() . getenv('SERVER_SOFTWARE') . getEncryptSeparator() . detectRealIpAddress() . getEncryptSeparator() . detectRemoteAddr();
 
                // Build key string
-               $keys   = getSiteKey() . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . getSecretKey() . getEncryptSeparator() . getFileHash() . getEncryptSeparator() . getDateFromRepository() . getEncryptSeparator() . getMasterSalt();
+               $keys = getSiteKey() . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . getFileHash() . getEncryptSeparator() . getDateFromRepository() . getEncryptSeparator() . getMasterSalt();
+
+               // Is the secret_key config entry set?
+               if (isConfigEntrySet('secret_key')) {
+                       // Add it
+                       $keys .= getEncryptSeparator() . getSecretKey();
+               } // END - if
 
                // Additional data
                $data = $plainText . getEncryptSeparator() . uniqid(mt_rand(), TRUE) . getEncryptSeparator() . time();
@@ -933,7 +939,7 @@ function encodeHashForCookie ($passHash) {
 
                        $mod = substr($mod, 0, 2);
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'idx=' . $idx . ',part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')');
-                       $mod = padLeftZero($mod);
+                       $mod = padLeftZero($mod, 2);
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*');
                        $start += 2;
                        $newHash .= $mod;
@@ -978,13 +984,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();
        }
@@ -1005,7 +1011,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)) {
@@ -1013,7 +1019,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
@@ -1530,7 +1536,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("cache=%s, inc=%s, force=%s", $cache, $inc, intval($force)));
 
        // Shall I remove the cache file?
-       if ((isExtensionInstalled('cache')) && (isCacheInstanceValid()) && (isHtmlOutputMode())) {
+       if ((isExtensionInstalled('cache')) && (isValidCacheInstance()) && (isHtmlOutputMode())) {
                // Rebuild cache only in HTML output-mode
                // @TODO This should be rewritten not to load the cache file for just checking if it is there for save removal.
                if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
@@ -1541,7 +1547,7 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) {
                // Include file given?
                if (!empty($inc)) {
                        // Construct FQFN
-                       $inc = sprintf("inc/loader/load-%s.php", $inc);
+                       $inc = sprintf('inc/loader/load-%s.php', $inc);
 
                        // Is the include there?
                        if (isIncludeReadable($inc)) {
@@ -1549,8 +1555,8 @@ function rebuildCache ($cache, $inc = '', $force = FALSE) {
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'inc=' . $inc . ' - LOADED!');
                                loadInclude($inc);
                        } else {
-                               // Include not found
-                               logDebugMessage(__FUNCTION__, __LINE__, 'Include ' . $inc . ' not found. cache=' . $cache);
+                               // Include not found, which needs now tracing
+                               reportBug(__FUNCTION__, __LINE__, 'Include ' . $inc . ' not found. cache=' . $cache);
                        }
                } // END - if
        } // END - if
@@ -2042,7 +2048,7 @@ function encodeUrl ($url, $outputMode = '0') {
        } // END - if
 
        // Is there a valid session?
-       if ((!isSessionValid()) && (!isSpider())) {
+       if ((!isValidSession()) && (!isSpider())) {
                // Determine right separator
                $separator = '&';
                if (!isInString('?', $url)) {
@@ -2718,7 +2724,7 @@ function hashSha256 ($str) {
        $hex = '';
        for ($i = 0; $i < strlen($hash); $i++) {
                // Encode char to decimal, pad it with zero, add it
-               $hex .= padLeftZero(dechex(ord(substr($hash, $i, 1))));
+               $hex .= padLeftZero(dechex(ord(substr($hash, $i, 1))), 2);
        } // END - if
 
        // Return it
@@ -2889,5 +2895,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]
 ?>