X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=a5a92f5ecfbdefd42ee0cd601595e16afbe1a21c;hp=f08e83420ed3fa27698613111e3aa40f341d8442;hb=261f8bb5b097dfafb28d151867fff3ded1974bbe;hpb=87229cb5d7b5396793e85fd0b4172d473195835c diff --git a/inc/functions.php b/inc/functions.php index f08e83420e..a5a92f5ecf 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -10,11 +10,6 @@ * -------------------------------------------------------------------- * * Kurzbeschreibung : Viele Nicht-Datenbank-Funktionen * * -------------------------------------------------------------------- * - * $Revision:: $ * - * $Date:: $ * - * $Tag:: 0.2.1-FINAL $ * - * $Author:: $ * - * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * * Copyright (c) 2009 - 2013 by Mailer Developer Team * * For more information visit: http://mxchange.org * @@ -466,7 +461,7 @@ function redirectToUrl ($url, $allowSpider = TRUE) { // Three different ways to debug... //* DEBUG: */ reportBug(__FUNCTION__, __LINE__, 'URL=' . $url); //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $url); - /* DEBUG: */ die($url); + //* DEBUG: */ die($url); // We should not sent a redirect if headers are already sent if (!headers_sent()) { @@ -474,9 +469,9 @@ function redirectToUrl ($url, $allowSpider = TRUE) { sendRawRedirect(doFinalCompilation(str_replace('&', '&', $url), FALSE)); } else { // Output error message - loadInclude('inc/header.php'); + loadPageHeader(); loadTemplate('redirect_url', FALSE, str_replace('&', '&', $url)); - loadInclude('inc/footer.php'); + loadPageFooter(); } // Shut the mailer down here @@ -551,7 +546,7 @@ function generateRandomCode ($length, $code, $userid, $extraData = '') { if (isConfigEntrySet('file_hash')) { $keys .= getEncryptSeparator() . getFileHash(); } // END - if - $keys .= getEncryptSeparator() . getDateFromRepository(); + if (isConfigEntrySet('master_salt')) { $keys .= getEncryptSeparator() . getMasterSalt(); } // END - if @@ -780,7 +775,7 @@ 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() . getFileHash() . getEncryptSeparator() . getDateFromRepository() . getEncryptSeparator() . getMasterSalt(); + $keys = getSiteKey() . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . getFileHash() . getEncryptSeparator() . getMasterSalt(); // Is the secret_key config entry set? if (isConfigEntrySet('secret_key')) { @@ -837,14 +832,17 @@ function scrambleString ($str) { if (strlen($str) > 40) { // The string is to long return $str; - } elseif (strlen($str) == 40) { + } elseif ((strlen($str) == 40) && (getPassScramble() != '')) { // From database - $scrambleNums = explode(':', getPassScramble()); + $scramble = getPassScramble(); } else { // Generate new numbers - $scrambleNums = explode(':', genScrambleString(strlen($str))); + $scramble = genScrambleString(strlen($str)); } + // Convert it into an array + $scrambleNums = explode(':', $scramble); + // Assert on both lengths assert(strlen($str) == count($scrambleNums)); @@ -1801,12 +1799,12 @@ function isExtraTitleSet () { * * @param $baseDir Relative base directory to PATH to scan from * @param $prefix Prefix for all positive matches (which files should be found) - * @param $fileIncludeDirs whether to include directories in the final output array - * @param $addBaseDir whether to add $baseDir to all array entries + * @param $fileIncludeDirs Whether to include directories in the final output array + * @param $addBaseDir Whether to add $baseDir to all array entries * @param $excludeArray Excluded files and directories, these must be full files names, e.g. 'what-' will exclude all files named 'what-' but won't exclude 'what-foo.php' * @param $extension File extension for all positive matches * @param $excludePattern Regular expression to exclude more files (preg_match()) - * @param $recursive whether to scan recursively + * @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 @@ -2114,43 +2112,6 @@ function isSpider () { return ((isInStringIgnoreCase('spider', $userAgent)) || (isInStringIgnoreCase('slurp', $userAgent)) || (isInStringIgnoreCase('bot', $userAgent)) || (isInStringIgnoreCase('archiver', $userAgent))); } -// Function to search for the last modified file -function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') { - // Get dir as array - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dir=' . $dir); - // Does it match what we are looking for? (We skip a lot files already!) - // RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames - $excludePattern = '@(\.revision|\.svn|debug\.log|\.cache|config\.php)$@'; - - $ds = getArrayFromDirectory($dir, '', FALSE, TRUE, array(), '.php', $excludePattern); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count(ds)='.count($ds)); - - // Walk through all entries - foreach ($ds as $d) { - // Generate proper FQFN - $FQFN = str_replace('//', '/', getPath() . $dir . '/' . $d); - - // Is it a file and readable? - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dir=' . $dir . ',d=' . $d); - if (isFileReadable($FQFN)) { - // $FQFN is a readable file so extract the requested data from it - $check = extractRevisionInfoFromFile($FQFN, $lookFor); - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' found. check=' . $check); - - // Is the file more recent? - if ((!isset($last_changed[$lookFor])) || ($last_changed[$lookFor] < $check)) { - // This file is newer as the file before - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'NEWER!'); - $last_changed['path_name'] = $FQFN; - $last_changed[$lookFor] = $check; - } // END - if - } else { - // Not readable - /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' not readable or directory.'); - } - } // END - foreach -} - // Handles the braces [] of a field (e.g. value of 'name' attribute) function handleFieldWithBraces ($field) { // Are there braces [] at the end? @@ -2192,6 +2153,18 @@ function convertZeroToNull ($number) { return $number; } +// Converts an empty string to NULL, else leaves it untouched +function convertEmptyToNull ($str) { + // Is the string empty? + if (strlen($str) == 0) { + // Is really empty + $str = NULL; + } // END - if + + // Return it + return $str; +} + // Converts a NULL|empty string|< 1 to zero function convertNullToZero ($number) { // Is it a valid username? @@ -2925,5 +2898,31 @@ function isThemeReadable ($theme) { return $GLOBALS[__FUNCTION__][$theme]; } +// Checks whether a given PHP extension is loaded or can be loaded at runtime +// +// Supported OS: Windows, Linux, (Mac?) +function isPhpExtensionLoaded ($extension) { + // Is the extension loaded? + if (extension_loaded($extension)) { + // All fine + return TRUE; + } // END - if + + // Try to load the extension + return loadLibrary($extension); +} + +// Loads given library (aka. PHP extension) +// Credits: shaunspiller at spammenot-gmail dot com ( http://de.php.net/dl#88566 ) +function loadLibrary ($n, $f = NULL) { + return extension_loaded($n) or dl(((PHP_SHLIB_SUFFIX === 'dll') ? 'php_' : '') . ($f ? $f : $n) . '.' . PHP_SHLIB_SUFFIX); +} + +// "Translates" given PHP extension name into a readable version +function translatePhpExtension ($extension) { + // Return the language element + return '{--PHP_EXTENSION_' . strtoupper($extension) . '--}'; +} + // [EOF] ?>