X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Ffunctions.php;h=318af2c2262240efe73ee8b02eeda1682c680d58;hb=e6e3183f794b385f5acc38b371c220cc35cdac38;hp=59e8c8c4a9d556b0bdd13fc09e0daa10003af04b;hpb=2ed1fa148954934a37ce31342c90cb2d90b80ecd;p=mailer.git diff --git a/inc/functions.php b/inc/functions.php index 59e8c8c4a9..318af2c226 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -32,7 +32,7 @@ ************************************************************************/ // Some security stuff... -if (ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) { +if (!defined('__SECURITY')) { $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php"; require($INC); } @@ -133,9 +133,10 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) { // Clear output buffer for later output ob_end_clean(); + // Extension "rewrite" installed? if ((EXT_IS_ACTIVE("rewrite", true)) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) { $OUTPUT = REWRITE_LINKS($OUTPUT); - } + } // END - if // Compile and run finished rendered HTML code while (strpos($OUTPUT, '{!') > 0) { @@ -144,12 +145,13 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) { $eval = "\$newContent = \"".COMPILE_CODE(addslashes($OUTPUT))."\";"; @eval($eval); + // Was that eval okay? if (empty($newContent)) { // Something went wrong! die("Evaluation error:
".htmlentities($eval)."
"); - } + } // END - if $OUTPUT = $newContent; - } + } // END - while // Output code here, DO NOT REMOVE! ;-) OUTPUT_RAW($OUTPUT); @@ -157,13 +159,13 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) { // Rewrite links when rewrite extension is active if ((EXT_IS_ACTIVE("rewrite", true)) && (function_exists('REWRITE_LINKS')) && ($CSS != "1") && ($CSS != "-1")) { $OUTPUT = REWRITE_LINKS($OUTPUT); - } + } // END - if // Compile and run finished rendered HTML code while (strpos($OUTPUT, '{!') > 0) { $eval = "\$OUTPUT = \"".COMPILE_CODE(addslashes($OUTPUT))."\";"; eval($eval); - } + } // END - while // Output code here, DO NOT REMOVE! ;-) OUTPUT_RAW($OUTPUT); @@ -173,13 +175,13 @@ function OUTPUT_HTML($HTML, $NEW_LINE = true) { // Output the raw HTML code function OUTPUT_RAW ($HTML) { // Output stripped HTML code to avoid broken JavaScript code, etc. - echo stripslashes($HTML); + echo stripslashes(stripslashes($HTML)); // Flush the output if only _OB_CACHING is not "on" if (_OB_CACHING != "on") { // Flush it flush(); - } + } // END - if } // Add a fatal error message to the queue array @@ -207,17 +209,16 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { $_CONFIG['num_templates']++; // Init some data - $ACTION = SQL_ESCAPE($GLOBALS['action']); - $WHAT = SQL_ESCAPE($GLOBALS['what']); $ret = ""; if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0; - $REFID = $GLOBALS['refid']; - // DEPRECATED!!! + // @DEPRECATED Try to remove this if() block if ($template == "member_support_form") { // Support request of a member $result = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array($GLOBALS['userid']), __FILE__, __LINE__); + + // @TODO Merge this data into $content list($gender, $surname, $family, $email) = SQL_FETCHROW($result); // Translate gender @@ -320,7 +321,7 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { // Add surrounding HTML comments to help finding bugs faster $ret = "\n".$ret."\n"; - } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!isBooleanConstantAndTrue('mxchange_installed')))) { + } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!defined('mxchange_installed')))) { // Only admins shall see this warning or when installation mode is active $ret = "
".TEMPLATE_404."
(".basename($file).")
@@ -349,11 +350,10 @@ function LOAD_TEMPLATE($template, $return=false, $content="") { } // Send mail out to an email address -function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") { +function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = 'N', $FROM = "") { // Compile subject line (for POINTS constant etc.) - $eval = "\$SUBJECT = \"".COMPILE_CODE(addslashes($SUBJECT))."\";"; + $eval = "\$SUBJECT = html_entity_decode(\"".COMPILE_CODE(addslashes($SUBJECT))."\");"; eval($eval); - $SUBJECT = html_entity_decode($SUBJECT); // Set from header if ((!eregi("@", $TO)) && ($TO > 0)) { @@ -362,17 +362,29 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") { ADD_MESSAGE_TO_BOX($TO, $SUBJECT, $MSG, $HTML); return; } else { + // Load email address $result_email = SQL_QUERY_ESC("SELECT email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1", array(bigintval($TO)), __FILE__, __LINE__); - list($TO) = SQL_FETCHROW($result_email); + + // Does the user exist? + if (SQL_NUMROWS($result_email)) { + // Load email address + list($TO) = SQL_FETCHROW($result_email); + } else { + // Set webmaster + $TO = WEBMASTER; + } + + // Free result SQL_FREERESULT($result_email); } - } elseif ($TO == 0) { + } elseif ("$TO" == "0") { // Is the webmaster! $TO = WEBMASTER; } - // Not in PHPMailer-Mode + // Check for PHPMailer or debug-mode if (!CHECK_PHPMAILER_USAGE()) { + // Not in PHPMailer-Mode if (empty($FROM)) { // Load email header template $FROM = LOAD_EMAIL_TEMPLATE("header"); @@ -390,6 +402,10 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML='N', $FROM="") { } } + // Compile "TO" + $eval = "\$TO = \"".COMPILE_CODE(addslashes($TO))."\";"; + eval($eval); + // Fix HTML parameter (default is no!) if (empty($HTML)) $HTML = "N"; if (isBooleanConstantAndTrue('DEBUG_MODE')) { @@ -404,9 +420,6 @@ Message : ".$MSG." // Send mail as HTML away SEND_HTML_EMAIL($TO, $SUBJECT, $MSG, $FROM); } elseif (!empty($TO)) { - // Compile email - $TO = COMPILE_CODE($TO); - // Send Mail away SEND_RAW_EMAIL($TO, COMPILE_CODE($SUBJECT), COMPILE_CODE($MSG), $FROM); } elseif ($HTML == "N") { @@ -738,15 +751,6 @@ function LOAD_EMAIL_TEMPLATE($template, $content="", $UID="0") { $content['expiration'] = $EXPIRATION; } // END - if - // @TODO Try to rewrite this part - if ($template == "add-points") { - if (isset($_POST['points'])) { - $points = bigintval($_POST['points']); - } else { - $points = __POINTS_VALUE; - } - } // END - if - // Load user's data if ($UID > 0) { if (EXT_IS_ACTIVE("nickname")) { @@ -899,7 +903,7 @@ function LOAD_URL($URL, $addUrlData=true) { print("
");
 		debug_print_backtrace();
 		die("
URL={$URL}"); - */ + /**/ @header ("Location: ".str_replace("&", "&", $URL)); } else { // Output error message @@ -1261,8 +1265,8 @@ function GENERATE_IMAGE($img_code, $header=true) { } // Create selection box or array of splitted timestamp function CREATE_TIME_SELECTIONS($timestamp, $prefix="", $display="", $align="center", $return_array=false) { - // Calculate 15-seconds timestamp (15-seconds-steps shall be fine ;) ) - $stamp = round($timestamp / 15) * 15; + // Calculate 2-seconds timestamp + $stamp = round($timestamp / 2) * 2; // Do we have a leap year? $SWITCH = 0; @@ -1291,7 +1295,7 @@ function CREATE_TIME_SELECTIONS($timestamp, $prefix="", $display="", $align="cen // Is seconds zero and time is < 60 seconds? if (($s == 0) && ($stamp < 60)) { // Fix seconds - $s = $timestamp; + $s = round($timestamp); } // END - if // @@ -1479,10 +1483,10 @@ function SEND_ADMIN_EMAILS_PRO($subj, $template, $content, $UID) { // Load email template $msg = LOAD_EMAIL_TEMPLATE($template, $content, $UID); - if (GET_EXT_VERSION("admins") < "0.4.0") { + if (EXT_VERSION_IS_OLDER("admins", "0.4.0")) { // Older version detected! return SEND_ADMIN_EMAILS($subj, $msg); - } + } // END - if // Check which admin shall receive this mail $result = SQL_QUERY_ESC("SELECT DISTINCT admin_id FROM "._MYSQL_PREFIX."_admins_mails WHERE mail_template='%s' ORDER BY admin_id", @@ -1538,8 +1542,14 @@ function CREATE_FANCY_TIME($stamp) { } // END - if } // END - foreach - // Remove leading commata and space - $ret = substr($ret, 2); + // Do we have something there? + if (strlen($ret) > 0) { + // Remove leading commata and space + $ret = substr($ret, 2); + } else { + // Zero seconds + $ret = "0 "._SECONDS; + } // Return fancy time string return $ret; @@ -1911,7 +1921,7 @@ function generateHash ($plainText, $salt = "") { global $_CONFIG, $_SERVER; // Is the required extension "sql_patches" there and a salt is not given? - if (((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == "")) && (empty($salt))) { + if (((EXT_VERSION_IS_OLDER("sql_patches", "0.3.6")) || (GET_EXT_VERSION("sql_patches") == "")) && (empty($salt))) { // Extension sql_patches is missing/outdated so we return the plain text return $plainText; } // END - if @@ -1940,11 +1950,11 @@ function generateHash ($plainText, $salt = "") { // Generate SHA1 sum from modula of number and the prime number $sha1 = sha1(($a % _PRIME).$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a); - //* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).")
"; + //* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).")
"; $sha1 = scrambleString($sha1); - //* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).")
"; + //* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).")
"; //* DEBUG: */ $sha1b = descrambleString($sha1); - //* DEBUG: */ echo "Descrambled=".$sha1b." (".strlen($sha1b).")
"; + //* DEBUG: */ echo "Descrambled=".$sha1b." (".strlen($sha1b).")
"; // Generate the password salt string $salt = substr($sha1, 0, $_CONFIG['salt_length']); @@ -2097,12 +2107,12 @@ function generatePassString($passHash) { } $mod = substr(round($mod), 0, 4); $mod = str_repeat('0', 4-strlen($mod)).$mod; - //* DEBUG: */ echo "*".$start."=".$mod."*
"; + //* DEBUG: */ echo "*".$start."=".$mod."*
"; $start += 4; $newHash .= $mod; } // END - for - //* DEBUG: */ print($passHash."
".$newHash." (".strlen($newHash).")"); + //* DEBUG: */ print($passHash."
".$newHash." (".strlen($newHash).")"); $ret = generateHash($newHash, $_CONFIG['master_salt']); //* DEBUG: */ print($ret."
\n"); } else { @@ -2196,39 +2206,62 @@ function set_session ($var, $value) { return session_register($var); } elseif (!empty($value)) { // Update session + //* DEBUG: */ echo "UPDATE:".$var."=".$value."
\n"; $_SESSION[$var] = $value; - } else { - // Something bad happens! - return false; // Hope this doesn't make so much trouble??? + return true; } - // Return always true if the session variable is already set. - // Keept me busy for a longer while... + // Ignored (but valid) //* DEBUG: */ echo "IGNORED:".$var."=".$value."
\n"; return true; } // Check wether a boolean constant is set // Taken from user comments in PHP documentation for function constant() -function isBooleanConstantAndTrue($constname) { // : Boolean +function isBooleanConstantAndTrue($constName) { // : Boolean + global $constCache; + + // Failed by default $res = false; - if (defined($constname)) $res = (constant($constname) === true); - return($res); + + // In cache? + if (isset($constCache[$constName])) { + // Use cache + $res = $constCache[$constName]; + } else { + // Check constant + if (defined($constName)) $res = (constant($constName) === true); + + // Set cache + $constCache[$constName] = $res; + } + + // Return value + return $res; } // Check wether a session variable is set function isSessionVariableSet($var) { + //* DEBUG: */ echo __FUNCTION__.":var={$var}
\n"; return (isset($_SESSION[$var])); } // Returns wether the value of the session variable or NULL if not set function get_session($var) { + global $cacheArray; + // Default is not found! ;-) $value = null; - // Is the variable there? - if (isSessionVariableSet($var)) { + // Is the variable there or cached values? + if (isset($cacheArray['session'][$var])) { + // Get cached value (skips a lot SQL_ESCAPE() calles! + $value = $cacheArray['session'][$var]; + } elseif (isSessionVariableSet($var)) { // Then get it secured! $value = SQL_ESCAPE($_SESSION[$var]); + + // Cache the value + $cacheArray['session'][$var] = $value; } // END - if // Return the value @@ -2290,6 +2323,7 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) { $file = $baseDir.$baseFile; // Is this a valid reset file? + //* DEBUG: */ echo __FUNCTION__.":baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}
\n"; if ((is_file($file)) && (is_readable($file)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) { // Remove both for extension name $extName = substr($baseFile, strlen($prefix), -4); @@ -2301,6 +2335,9 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) { if (($extId > 0) && (EXT_IS_ACTIVE($extName))) { // Then add this file $INCs[] = $file; + } elseif ($extId == 0) { + // Add non-extension files as well + $INCs[] = $file; } } // END - if } // END - while @@ -2316,9 +2353,9 @@ function RESET_ADD_INCLUDES () { global $_CONFIG; // Is the reset set or old sql_patches? - if ((!isBooleanConstantAndTrue('__DAILY_RESET')) || (GET_EXT_VERSION("sql_patches") < "0.4.5")) { + if ((!defined('__DAILY_RESET')) || (EXT_VERSION_IS_OLDER("sql_patches", "0.4.5"))) { // Then abort here - return; + return array(); } // END - if // Get more daily reset scripts @@ -2420,9 +2457,95 @@ function CONVERT_SELECTIONS_TO_TIMESTAMP(&$POST, &$DATA, &$id, &$skip) { } // Reverts the german decimal comma into Computer decimal dot function REVERT_COMMA ($str) { - $float = (float)str_replace(",", ".", $str); + // Default float is not a float... ;-) + $float = false; + + // Which language is selected? + switch (GET_LANGUAGE()) { + case "de": // German language + // Remove german thousand dots first + $str = str_replace(".", "", $str); + + // Replace german commata with decimal dot and cast it + $float = (float)str_replace(",", ".", $str); + break; + + default: // US and so on + // Remove thousand dots first and cast + $float = (float)str_replace(",", "", $str); + break; + } + + // Return float return $float; } +// Handle menu-depending failed logins and return the rendered content +function HANDLE_LOGIN_FAILTURES ($accessLevel) { + // Default output is empty ;-) + $OUT = ""; + + // Is the session data set? + if ((isSessionVariableSet('mxchange_'.$accessLevel.'_failtures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) { + // Ignore zero values + if (get_session('mxchange_'.$accessLevel.'_failtures') > 0) { + // Non-guest has login failtures found, get both data and prepare it for template + //* DEBUG: */ echo __FUNCTION__.":accessLevel={$accessLevel}
\n"; + $content = array( + 'login_failtures' => get_session('mxchange_'.$accessLevel.'_failtures'), + 'last_failture' => MAKE_DATETIME(get_session('mxchange_'.$accessLevel.'_last_fail'), "2") + ); + + // Load template + $OUT = LOAD_TEMPLATE("login_failtures", true, $content); + } // END - if + + // Reset session data + set_session('mxchange_'.$accessLevel.'_failtures', ""); + set_session('mxchange_'.$accessLevel.'_last_fail', ""); + } // END - if + + // Return rendered content + return $OUT; +} +// Rebuild cache +function REBUILD_CACHE ($cache, $inc="") { + global $cacheInstance; + + // Shall I remove the cache file? + if ((EXT_IS_ACTIVE("cache")) && (is_object($cacheInstance))) { + // Rebuild cache + if ($cacheInstance->cache_file($cache, true)) { + // Destroy it + $cacheInstance->cache_destroy(); + + // Include file given? + if (!empty($inc)) { + // And rebuild it from scratch + require_once(PATH."inc/loader/load_cache-".$inc.".php"); + } // END - if + } // END - if + } // END - if +} +// Purge admin menu cache +function CACHE_PURGE_ADMIN_MENU ($id=0, $action="", $what="", $str="") { + global $_CONFIG, $cacheInstance; + + // Is the cache extension enabled or no cache instance or admin menu cache disabled? + if (!EXT_IS_ACTIVE("cache")) { + // Cache extension not active + return false; + } elseif (!is_object($cacheInstance)) { + // No cache instance! + DEBUG_LOG(__FUNCTION__.": No cache instance found."); + return false; + } elseif ((!isset($_CONFIG['cache_admin_menu'])) || ($_CONFIG['cache_admin_menu'] == "N")) { + // Caching disabled (currently experiemental!) + return false; + } + + // Experiemental feature! + trigger_error("You have to delete the admin_*.cache files by yourself at this point."); +} // ////////////////////////////////////////////////// // //