X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=0d6c9889ec38148166358b4b6eb37e57ce176566;hb=27689ac6ea690dba2f65452c4360c9dd429c47f7;hp=86027cf9de575646a601befcc36351e397ed1b30;hpb=3d9e10c043644977bec99d3926b0fe20ded0b084;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 86027cf9de..0d6c9889ec 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -11,7 +11,7 @@ * Kurzbeschreibung : Viele Nicht-Datenbank-Funktionen * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2013 by Mailer Developer Team * + * Copyright (c) 2009 - 2016 by Mailer Developer Team * * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * @@ -224,12 +224,7 @@ function translateActivationStatus ($status) { // OPPOMENT: convertCommaToDot() function translateComma ($dotted, $cut = TRUE, $max = '0') { // First, cast all to double, due to PHP changes - $dotted = (double) $dotted; - - // Default is 3 you can change this in admin area "Settings -> Misc Options" - if (!isConfigEntrySet('max_comma')) { - setConfigEntry('max_comma', 3); - } // END - if + $double = (double) $dotted; // Use from config is default $maxComma = getConfig('max_comma'); @@ -242,7 +237,7 @@ function translateComma ($dotted, $cut = TRUE, $max = '0') { // Cut zeros off? if (($cut === TRUE) && ($max == '0')) { // Test for commata if in cut-mode - $com = explode('.', $dotted); + $com = explode('.', $double); if (count($com) < 2) { // Don't display commatas even if there are none... ;-) $maxComma = '0'; @@ -252,19 +247,19 @@ function translateComma ($dotted, $cut = TRUE, $max = '0') { // Debug log // Translate it now - $translated = $dotted; + $translated = $double; switch (getLanguage()) { case 'de': // German language - $translated = number_format($dotted, $maxComma, ',', '.'); + $translated = number_format($double, $maxComma, ',', '.'); break; default: // All others - $translated = number_format($dotted, $maxComma, '.', ','); + $translated = number_format($double, $maxComma, '.', ','); break; } // END - switch // Return translated value - //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dotted=' . $dotted . ',translated=' . $translated . ',maxComma=' . $maxComma); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'double=' . $double . ',translated=' . $translated . ',maxComma=' . $maxComma); return $translated; } @@ -322,6 +317,9 @@ function translateUserStatus ($status) { // "Translates" 'visible' and 'locked' to a CSS class function translateMenuVisibleLocked ($content, $prefix = '') { + // 1st parameter should be an array + assert(is_array($content)); + // Default is 'menu_unknown' $content['visible_css'] = $prefix . 'menu_unknown'; @@ -373,7 +371,12 @@ function generateDereferrerUrl ($url) { //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'url=' . $url . ',hash=' . $hash . '(' . strlen($hash) . ')'); // De-refer this URL - $url = '{%url=modules.php?module=loader&url=' . $encodedUrl . '&hash=' . encodeHashForCookie($hash) . '&salt=' . substr($hash, 0, getSaltLength()) . '%}'; + $url = sprintf( + '{%%url=modules.php?module=loader&url=%s&hash=%s&salt=%s%%}', + $encodedUrl, + encodeHashForCookie($hash), + substr($hash, 0, getSaltLength()) + ); } // END - if // Return link @@ -403,7 +406,7 @@ function countSelection ($array) { $ret = '0'; // Count all entries - foreach ($array as $key => $selected) { + foreach ($array as $selected) { // Is it checked? if (!empty($selected)) { // Yes, then count it @@ -434,7 +437,8 @@ function makeTime ($hours, $minutes, $seconds, $stamp) { } // Redirects to an URL and if neccessarry extends it with own base URL -function redirectToUrl ($url, $allowSpider = TRUE) { +// @TODO $allowSpider is unused +function redirectToUrl ($url, $allowSpider = TRUE, $compileCode = TRUE) { // Is the output mode -2? if (isAjaxOutputMode()) { // This is always (!) an AJAX request and shall not be redirected @@ -446,8 +450,11 @@ function redirectToUrl ($url, $allowSpider = TRUE) { $url = substr($url, 6, -2); } // END - if - // Compile out codes - eval('$url = "' . compileRawCode(encodeUrl($url)) . '";'); + // Compile codes out? + if ($compileCode === TRUE) { + // Compile out codes + eval('$url = "' . compileRawCode(encodeUrl($url)) . '";'); + } // END - if // Default 'rel' value is external, nofollow is evil from Google and hurts the Internet $rel = ' rel="external"'; @@ -461,12 +468,18 @@ 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: */ die(__METHOD__ . ':url=' . $url . '
compileCode=' . intval($compileCode)); // We should not sent a redirect if headers are already sent if (!headers_sent()) { + // Compile again? + if ($compileCode === TRUE) { + // Do final compilation + $url = doFinalCompilation(str_replace('&', '&', $url), FALSE); + } // END - if + // Load URL when headers are not sent - sendRawRedirect(doFinalCompilation(str_replace('&', '&', $url), FALSE)); + sendRawRedirect($url); } else { // Output error message loadPageHeader(); @@ -512,7 +525,7 @@ function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums if ($match) { // We have found two different values, so let's sort whole array foreach ($temporaryArray as $sort_key => $sort_val) { - $t = $temporaryArray[$sort_key][$key]; + $t = $temporaryArray[$sort_key][$key]; $temporaryArray[$sort_key][$key] = $temporaryArray[$sort_key][$key2]; $temporaryArray[$sort_key][$key2] = $t; unset($t); @@ -536,7 +549,7 @@ function array_pk_sort (&$array, $a_sort, $primary_key = '0', $order = -1, $nums // function generateRandomCode ($length, $code, $userid, $extraData = '') { // Build server string - $server = $_SERVER['PHP_SELF'] . getEncryptSeparator() . detectUserAgent() . getEncryptSeparator() . getenv('SERVER_SOFTWARE') . getEncryptSeparator() . detectRealIpAddress() . getEncryptSeparator() . detectRemoteAddr(); + $server = $_SERVER['REQUEST_URI'] . getEncryptSeparator() . detectUserAgent() . getEncryptSeparator() . getenv('SERVER_SOFTWARE') . getEncryptSeparator() . detectRealIpAddress() . getEncryptSeparator() . detectRemoteAddr(); // Build key string $keys = getSiteKey() . getEncryptSeparator() . getDateKey(); @@ -772,7 +785,7 @@ function generateHash ($plainText, $salt = '', $hash = TRUE) { // When the salt is empty build a new one, else use the first x configured characters as the salt if (empty($salt)) { // Build server string for more entropy - $server = $_SERVER['PHP_SELF'] . getEncryptSeparator() . detectUserAgent() . getEncryptSeparator() . getenv('SERVER_SOFTWARE') . getEncryptSeparator() . detectRealIpAddress() . getEncryptSeparator() . detectRemoteAddr(); + $server = $_SERVER['REQUEST_URI'] . getEncryptSeparator() . detectUserAgent() . getEncryptSeparator() . getenv('SERVER_SOFTWARE') . getEncryptSeparator() . detectRealIpAddress() . getEncryptSeparator() . detectRemoteAddr(); // Build key string $keys = getSiteKey() . getEncryptSeparator() . getDateKey() . getEncryptSeparator() . getFileHash() . getEncryptSeparator() . getMasterSalt(); @@ -2074,7 +2087,7 @@ function encodeUrl ($url, $outputMode = '0') { } // END - if // Add {?URL?} ? - if ((substr($url, 0, strlen(getUrl())) != getUrl()) && (substr($url, 0, 7) != '{?URL?}') && (substr($url, 0, 7) != 'http://') && (substr($url, 0, 8) != 'https://')) { + if ((substr($url, 0, strlen(getUrl())) != getUrl()) && (substr($url, 0, 7) != '{?URL?}') && (!isFullQualifiedUrl($url))) { // Add it $url = '{?URL?}/' . $url; } // END - if @@ -2703,25 +2716,6 @@ 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))), 2); - } // END - if - - // Make sure 'length modulo 2' = 0 - assert((strlen($hex) % 2) == 0); - - // Return it - return $hex; -} - // ---------------------------------------------------------------------------- // "Translatation" functions for points_data table // ---------------------------------------------------------------------------- @@ -2825,62 +2819,6 @@ 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); @@ -2931,5 +2869,101 @@ function translatePhpExtension ($extension) { return '{--PHP_EXTENSION_' . strtoupper($extension) . '--}'; } +// Loads stylesheet files in different ways, depending on output mode +function loadStyleSheets () { + // Default styles + $stylesList = array( + 'general.css', + 'ajax.css', + ); + + // Add stylesheet for installation + if ((isInstaller())) { + array_push($stylesList, 'install.css'); + } // END - if + + // When no CSS output-mode is set, set it to file-output + if (!isConfigEntrySet('css_php')) { + setConfigEntry('css_php', 'FILE'); + } // END - if + + // Get current theme + $currentTheme = getCurrentTheme(); + + // Has the theme changed? + if ($currentTheme != getSession('mailer_theme')) { + // Then set it + setMailerTheme($currentTheme); + } // END - if + + // Output CSS files or content or link to css.php ? + if ((isCssOutputMode()) || (getCssPhp() == 'DIRECT')) { + // Load CSS files + $stylesList = merge_array($stylesList, getExtensionCssFiles()); + + // Generate base path + $basePath = getBasePathFromTheme($currentTheme); + + // Output inclusion lines + foreach ($stylesList as $value) { + // Only include found CSS files (to reduce 404 requests) + $FQFN = $basePath . '/' . $value; + + // Do include only existing files and whose are not empty + if ((isFileReadable($FQFN)) && (filesize($FQFN) > 0)) { + switch (getCssPhp()) { + case 'DIRECT': // Just link them (unsupported) + $GLOBALS['__page_header'] .= ''; + break; + + case 'FILE': // Output contents + $GLOBALS['__page_header'] .= removeDeprecatedComment(readFromFile($FQFN)); + break; + + default: // Invalid mode! + reportBug(__FILE__, __LINE__, sprintf('Invalid css_php value %s detected.', getCssPhp())); + break; + } // END - switch + } // END - if + } // END - foreach + } elseif ((isHtmlOutputMode()) || (getCssPhp() == 'INLINE')) { + // Load CSS files + $stylesList = merge_array($stylesList, getExtensionCssFiles()); + + // Generate base path + $basePath = getBasePathFromTheme(getCurrentTheme()); + + // Output inclusion lines + $OUT = ''; + foreach ($stylesList as $value) { + // Only include found CSS files (to reduce 404 requests) + $FQFN = $basePath . '/' . $value; + + // Do include only existing files and whose are not empty + if ((isFileReadable($FQFN)) && (filesize($FQFN) > 0)) { + // Load CSS content + $OUT .= readFromFile($FQFN); + } // END - if + } // END - foreach + + // Load template + $GLOBALS['__page_header'] .= loadTemplate('css_inline', TRUE, removeDeprecatedComment($OUT)); + } else { + // Now we load all CSS files from css.php! + $OUT = ''; + } +} + // [EOF] ?>