]> git.mxchange.org Git - mailer.git/blobdiff - inc/functions.php
Fixed bug 'sprintf() too few arguments':
[mailer.git] / inc / functions.php
index 01f21ce86940b7ff2c8b24a4e84984f211fff6ba..bc7aa6bad76029a765d1aedc32cb1c281c7ac4ec 100644 (file)
@@ -88,7 +88,7 @@ function getTotalFatalErrors () {
 function generatePassword ($length = '0', $exclude = array()) {
        // Auto-fix invalid length of zero
        if ($length == '0') {
-               $length = getPassLen();
+               $length = getMinPasswordLength();
        } // END - if
 
        // Exclude some entries
@@ -952,7 +952,7 @@ function encodeHashForCookie ($passHash) {
 // Fix "deleted" cookies
 function fixDeletedCookies ($cookies) {
        // Is this an array with entries?
-       if ((is_array($cookies)) && (count($cookies) > 0)) {
+       if (isFilledArray($cookies)) {
                // Then check all cookies if they are marked as deleted!
                foreach ($cookies as $cookieName) {
                        // Is the cookie set to "deleted"?
@@ -1530,7 +1530,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 +1541,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 +1549,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
@@ -1682,6 +1682,21 @@ function doMonthly () {
        } // END - if
 }
 
+// Enables the yearly reset mode and runs it
+function doYearly () {
+       // Enable the reset mode
+       $GLOBALS['yearly_enabled'] = TRUE;
+
+       // Run filters
+       runFilterChain('yearly');
+
+       // Do not update in yearly debug mode
+       if ((!isConfigEntrySet('DEBUG_YEARLY')) || (!isDebugYearlyEnabled())) {
+               // Update database
+               updateConfiguration('last_yearly', getYear());
+       } // END - if
+}
+
 // Shuts down the mailer (e.g. closing database link, flushing output/filters, etc.)
 function doShutdown () {
        // Call the filter chain 'shutdown'
@@ -1691,7 +1706,7 @@ function doShutdown () {
        if (isSqlLinkUp()) {
                // Close link
                sqlCloseLink(__FUNCTION__, __LINE__);
-       } elseif (!isInstallationPhase()) {
+       } elseif (!isInstaller()) {
                // No database link
                reportBug(__FUNCTION__, __LINE__, 'Database link is already down, while shutdown is running.');
        }
@@ -1772,9 +1787,10 @@ function isExtraTitleSet () {
  * @param      $excludePattern         Regular expression to exclude more files (preg_match())
  * @param      $recursive                      whether to scan recursively
  * @param      $suffix                         Suffix for positive matches ($extension will be appended, too)
+ * @param      $withPrefixSuffix       Whether to include prefix/suffix in found entries
  * @return     $foundMatches           All found positive matches for above criteria
  */
-function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '') {
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $addBaseDir = TRUE, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = TRUE, $suffix = '', $withPrefixSuffix = TRUE) {
        // Add default entries we should always exclude
        array_unshift($excludeArray, '.', '..', '.svn', '.htaccess');
 
@@ -1853,6 +1869,9 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                if ($addBaseDir === TRUE) {
                                        // With base path
                                        array_push($foundMatches, $fileName);
+                               } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                                       // No prefix/suffix
+                                       array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
                                } else {
                                        // No base path
                                        array_push($foundMatches, $baseFile);
@@ -1861,9 +1880,18 @@ function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = FALSE, $ad
                                // We found .php file but should not search for them, why?
                                reportBug(__FUNCTION__, __LINE__, 'We should find files with extension=' . $extension . ', but we found a PHP script. (baseFile=' . $baseFile . ')');
                        }
-               } elseif ($fileExtension == $extension) {
+               } elseif ((($fileExtension == $extension) || (empty($extension))) && (isFileReadable($FQFN))) {
                        // Other, generic file found
-                       array_push($foundMatches, $fileName);
+                       if ($addBaseDir === TRUE) {
+                               // With base path
+                               array_push($foundMatches, $fileName);
+                       } elseif (($withPrefixSuffix === FALSE) && (!empty($extension))) {
+                               // No prefix/suffix
+                               array_push($foundMatches, substr($baseFile, strlen($prefix), -strlen($suffix . $extension)));
+                       } else {
+                               // No base path
+                               array_push($foundMatches, $baseFile);
+                       }
                }
        } // END - while
 
@@ -2014,7 +2042,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)) {
@@ -2131,7 +2159,7 @@ function handleFieldWithBraces ($field) {
 // Converts a zero or NULL to word 'NULL'
 function convertZeroToNull ($number) {
        // Is it a valid username?
-       if ((!is_null($number)) && (!empty($number)) && ($number > 0)) {
+       if (isValidNumber($number)) {
                // Always secure it
                $number = bigintval($number);
        } else {
@@ -2146,7 +2174,7 @@ function convertZeroToNull ($number) {
 // Converts a NULL|empty string|< 1 to zero
 function convertNullToZero ($number) {
        // Is it a valid username?
-       if ((is_null($number)) || (empty($number)) || ($number < 1)) {
+       if (!isValidNumber($number)) {
                // Is not valid or zero
                $number = '0';
        } // END - if
@@ -2681,6 +2709,22 @@ function convertCharsetToUtf8 ($str, $charset) {
        return $str;
 }
 
+// Hash string with SHA256 and encode it to hex
+function hashSha256 ($str) {
+       /// Hash string
+       $hash = mhash(MHASH_SHA256, $str);
+
+       // Encode it to hexadecimal
+       $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))));
+       } // END - if
+
+       // Return it
+       return $hex;
+}
+
 // ----------------------------------------------------------------------------
 //              "Translatation" functions for points_data table
 // ----------------------------------------------------------------------------
@@ -2784,5 +2828,66 @@ if (!function_exists('html_entity_decode')) {
        }
 } // END - if
 
+// "Calculates" password strength
+function calculatePasswordStrength ($password, $configEntry = 'min_password_length') {
+       // Default score
+       $score = 1;
+
+       if ((strlen($password) < 1) || (strlen($password) < getConfig($configEntry))) {
+               // Is to weak
+               return 0;
+       } // END - if
+
+       // At least 8 chars long?
+       if (strlen($password) >= 8) {
+               // Add score
+               $score++;
+       } // END - if
+
+       // At least 10 chars long?
+       if (strlen($password) >= 10) {
+               // Add score
+               $score++;
+       } // END - if
+
+       // Lower and upper cases?
+       if ((preg_match('/[a-z]/', $password)) && (preg_match('/[A-Z]/', $password))) {
+               // Add score
+               $score++;
+       } // END - if
+
+       // Also numbers?
+       if (preg_match('/[0-9]/', $password))  {
+               // Add score
+               $score++;
+       } // END - if
+
+       // Special characters?
+       if (preg_match('/.[!,@,#,$,%,^,&,*,?,\/,_,~,+,-,(,)]/', $password)) {
+               // Add score
+               $score++;
+       } // END - if
+
+       // Return password score
+       return $score;
+}
+
+// "Translates" password strength/score
+function translatePasswordStrength ($strength) {
+       // Return it translated
+       return '{--PASSWORD_SCORE_' . bigintval($strength) . '--}';
+}
+
+// Checks whether given password is strong enough
+function isStrongPassword ($password) {
+       // Determine it
+       return (calculatePasswordStrength($password) >= getConfig('min_password_score'));
+}
+
+// "Getter" for base path from theme
+function getBasePathFromTheme ($theme) {
+       return sprintf('%stheme/%s/css/', getPath(), $theme);
+}
+
 // [EOF]
 ?>