\n";
$OUT .= "\n";
- if (ereg('Y', $display) || (empty($display)))
- {
+
+ if (ereg('Y', $display) || (empty($display))) {
$OUT .= " "._YEARS." | \n";
}
- if (ereg("M", $display) || (empty($display)))
- {
+
+ if (ereg("M", $display) || (empty($display))) {
$OUT .= " "._MONTHS." | \n";
}
- if (ereg("W", $display) || (empty($display)))
- {
+
+ if (ereg("W", $display) || (empty($display))) {
$OUT .= " "._WEEKS." | \n";
}
- if (ereg("D", $display) || (empty($display)))
- {
+
+ if (ereg("D", $display) || (empty($display))) {
$OUT .= " "._DAYS." | \n";
}
- if (ereg("h", $display) || (empty($display)))
- {
+
+ if (ereg("h", $display) || (empty($display))) {
$OUT .= " "._HOURS." | \n";
}
- if (ereg("m", $display) || (empty($display)))
- {
+
+ if (ereg("m", $display) || (empty($display))) {
$OUT .= " "._MINUTES." | \n";
}
- if (ereg("s", $display) || (empty($display)))
- {
+
+ if (ereg("s", $display) || (empty($display))) {
$OUT .= " "._SECONDS." | \n";
}
+
$OUT .= "
\n";
$OUT .= "\n";
- if (ereg('Y', $display) || (empty($display)))
- {
+
+ if (ereg('Y', $display) || (empty($display))) {
// Generate year selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("M", $display) || (empty($display)))
- {
+
+ if (ereg("M", $display) || (empty($display))) {
// Generate month selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("W", $display) || (empty($display)))
- {
+
+ if (ereg("W", $display) || (empty($display))) {
// Generate week selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("D", $display) || (empty($display)))
- {
+
+ if (ereg("D", $display) || (empty($display))) {
// Generate day selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("h", $display) || (empty($display)))
- {
+
+ if (ereg("h", $display) || (empty($display))) {
// Generate hour selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("m", $display) || (empty($display)))
- {
+
+ if (ereg("m", $display) || (empty($display))) {
// Generate minute selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
- if (ereg("s", $display) || (empty($display)))
- {
+
+ if (ereg("s", $display) || (empty($display))) {
// Generate second selection
$OUT .= " | \n";
- }
- else
- {
+ } else {
$OUT .= "\n";
}
$OUT .= "
\n";
@@ -1495,7 +1449,8 @@ function CREATE_TIME_SELECTIONS($timestamp, $prefix="", $display="", $align="cen
}
//
function CREATE_TIMESTAMP_FROM_SELECTIONS($prefix, $POST) {
- $ret = "0";
+ $ret = 0;
+
// Do we have a leap year?
$SWITCH = 0;
$TEST = date('Y', time()) / 4;
@@ -1528,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",
@@ -1578,17 +1533,25 @@ function CREATE_FANCY_TIME($stamp) {
// Get data array with years/months/weeks/days/...
$data = CREATE_TIME_SELECTIONS($stamp, "", "", "", true);
$ret = "";
- foreach($data as $k=>$v) {
+ foreach($data as $k => $v) {
if ($v > 0) {
// Value is greater than 0 "eval" data to return string
$eval = "\$ret .= \", \".\$v.\" \"._".strtoupper($k).";";
eval($eval);
break;
- }
+ } // END - if
+ } // END - foreach
+
+ // Do we have something there?
+ if (strlen($ret) > 0) {
+ // Remove leading commata and space
+ $ret = substr($ret, 2);
+ } else {
+ // Zero seconds
+ $ret = "0 "._SECONDS;
}
- // Remove first "comma,null" string
- $ret = substr($ret, 2);
+ // Return fancy time string
return $ret;
}
//
@@ -1958,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
@@ -1966,7 +1929,7 @@ function generateHash ($plainText, $salt = "") {
// Do we miss an arry element here?
if (!isset($_CONFIG['file_hash'])) {
// Stop here
- print(__FUNCTION__.":");
+ print("Missing file_hash in ".__FUNCTION__.". Backtrace:");
debug_print_backtrace();
die("
");
} // END - if
@@ -1977,7 +1940,7 @@ function generateHash ($plainText, $salt = "") {
$server = $_SERVER['PHP_SELF'].":".getenv('HTTP_USER_AGENT').":".getenv('SERVER_SOFTWARE').":".getenv('REMOTE_ADDR').":".":".filemtime(PATH."inc/databases.php");
// Build key string
- $keys = SITE_KEY.":".DATE_KEY.":".$_CONFIG['secret_key'].":".$_CONFIG['file_hash'].":".date("d-m-Y (l-F-T)", $_CONFIG['patch_ctime']).":".$_CONFIG['master_salt'];
+ $keys = SITE_KEY.":".DATE_KEY.":".$_CONFIG['secret_key'].":".$_CONFIG['file_hash'].":".date("d-m-Y (l-F-T)", bigintval($_CONFIG['patch_ctime'])).":".$_CONFIG['master_salt'];
// Additional data
$data = $plainText.":".uniqid(rand(), true).":".time();
@@ -1987,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']);
@@ -2144,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 {
@@ -2243,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
@@ -2337,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);
@@ -2348,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
@@ -2360,16 +2350,16 @@ function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
}
// Load more reset scripts
function RESET_ADD_INCLUDES () {
- global $_CONFIG, $INC_POOL;
+ 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
- $INC_POOL = array_merge($INC_POOL, GET_DIR_AS_ARRAY(PATH."inc/reset/", "reset_"));
+ $INC_POOL = GET_DIR_AS_ARRAY(PATH."inc/reset/", "reset_");
// Create current week mark
$currWeek = date("W", time());
@@ -2394,6 +2384,9 @@ function RESET_ADD_INCLUDES () {
// Update config
UPDATE_CONFIG("last_month", $currMonth);
} // END - if
+
+ // Return array
+ return $INC_POOL;
}
// Handle extra values
function HANDLE_EXTRA_VALUES ($filterFunction, $value, $extraValue) {
@@ -2402,23 +2395,26 @@ function HANDLE_EXTRA_VALUES ($filterFunction, $value, $extraValue) {
// Do we have a special filter function?
if (!empty($filterFunction)) {
- // Do we have extra parameters here?
- if (!empty($extraValue)) {
- // Put both parameters in one new array by default
- $args = array($value, $extraValue);
-
- // If we have an array simply use it and pre-extend it with our value
- if (is_array($extraValue)) {
- // Make the new args array
- $args = array_merge(array($vaue), $extraValue);
- } // END - if
-
- // Call the multi-parameter call-back
- $ret = call_user_func_array($filterFunction, $args);
- } else {
- // One parameter call
- $ret = call_user_func($filterFunction, $value);
- }
+ // Does the filter function exist?
+ if (function_exists($filterFunction)) {
+ // Do we have extra parameters here?
+ if (!empty($extraValue)) {
+ // Put both parameters in one new array by default
+ $args = array($value, $extraValue);
+
+ // If we have an array simply use it and pre-extend it with our value
+ if (is_array($extraValue)) {
+ // Make the new args array
+ $args = array_merge(array($value), $extraValue);
+ } // END - if
+
+ // Call the multi-parameter call-back
+ $ret = call_user_func_array($filterFunction, $args);
+ } else {
+ // One parameter call
+ $ret = call_user_func($filterFunction, $value);
+ }
+ } // END - if
} // END - if
// Return the value
@@ -2459,6 +2455,97 @@ function CONVERT_SELECTIONS_TO_TIMESTAMP(&$POST, &$DATA, &$id, &$skip) {
$skip = false; $TEST2 = "";
}
}
+// Reverts the german decimal comma into Computer decimal dot
+function REVERT_COMMA ($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.");
+}
//
//////////////////////////////////////////////////
// //