mxchange_die("<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}");
break;
}
- } elseif ((constant('_OB_CACHING') == "on") && ($GLOBALS['footer_sent'] == 1)) {
+ } elseif ((constant('_OB_CACHING') == "on") && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
// Headers already sent?
if (headers_sent()) {
// Log this error
// Output direct
OUTPUT_HTML($ret);
}
- } elseif (isBooleanConstantAndTrue('DEBUG_MODE')) {
+ } elseif (isDebugModeEnabled()) {
// Warning, empty output!
return "E:".$template."<br />\n";
}
// Append header
$FROM .= LOAD_EMAIL_TEMPLATE("header");
}
- } elseif (isBooleanConstantAndTrue('DEBUG_MODE')) {
+ } elseif (isDebugModeEnabled()) {
if (empty($FROM)) {
// Load email header template
$FROM = LOAD_EMAIL_TEMPLATE("header");
// Fix HTML parameter (default is no!)
if (empty($HTML)) $HTML = "N";
- if (isBooleanConstantAndTrue('DEBUG_MODE')) {
+ if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
print("<pre>
".htmlentities(trim($FROM))."
}
// Check if legacy or PHPMailer command
+// @TODO Rewrite this to an extension 'smtp'
// @private
function CHECK_PHPMAILER_USAGE() {
- return ((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD')) && (SMTP_HOSTNAME != "") && (SMTP_USER != ""));
+ return ((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD')) && (constant('SMTP_HOSTNAME') != "") && (constant('SMTP_USER') != ""));
}
/*
function SELECTION_COUNT ($array) {
$ret = 0;
if (is_array($array)) {
- foreach ($array as $key => $sel) {
- if (!empty($sel)) $ret++;
+ foreach ($array as $key => $selected) {
+ if (!empty($selected)) $ret++;
}
}
return $ret;
<br /><br />";
// Debug mode not active? Then remove the HTML tags
- if (!isBooleanConstantAndTrue('DEBUG_MODE')) $newContent = strip_tags($newContent);
+ if (!isDebugModeEnabled()) $newContent = strip_tags($newContent);
} else {
// No template name supplied!
$newContent = getMessage('NO_TEMPLATE_SUPPLIED');
}
//
-function TRANSLATE_YESNO($yn) {
+function TRANSLATE_YESNO ($yn) {
// Default
- $yn = "??? (".$yn.")";
+ $translated = "??? (".$yn.")";
switch ($yn) {
- case "Y": $yn = getMessage('YES'); break;
- case "N": $yn = getMessage('NO'); break;
+ case "Y": $translated = getMessage('YES'); break;
+ case "N": $translated = getMessage('NO'); break;
default:
// Log unknown value
DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown value %s. Expected Y/N!", $yn));
}
// Return it
- return $yn;
+ return $translated;
}
//
// Deprecated : $length
// Optional : $DATA
//
-function GEN_RANDOM_CODE ($length, $code, $uid, $DATA="") {
+function generateRandomCodde ($length, $code, $uid, $DATA="") {
// Fix missing _MAX constant
+ // @TODO Rewrite this unnice code
if (!defined('_MAX')) define('_MAX', 15235);
// Build server string
$keys = constant('SITE_KEY').":".constant('DATE_KEY');
if (isConfigEntrySet('secret_key')) $keys .= ":".getConfig('secret_key');
if (isConfigEntrySet('file_hash')) $keys .= ":".getConfig('file_hash');
- $keys .= ":".date("d-m-Y (l-F-T)", bigintval(getConfig('patch_ctime')));
+ $keys .= ":".date("d-m-Y (l-F-T)", getConfig(('patch_ctime')));
if (isConfigEntrySet('master_salt')) $keys .= ":".getConfig('master_salt');
// Build string from misc data
// Add more additional data
if (isSessionVariableSet('u_hash')) $data .= ":".get_session('u_hash');
if (isset($GLOBALS['userid'])) $data .= ":".$GLOBALS['userid'];
- if (isSessionVariableSet('mxchange_theme')) $data .= ":".get_session('mxchange_theme');
- if (isSessionVariableSet('mx_lang')) $data .= ":".GET_LANGUAGE();
- if (isset($GLOBALS['refid'])) $data .= ":".$GLOBALS['refid'];
+ if (isSessionVariableSet('mxchange_theme')) $data .= ":".get_session('mxchange_theme');
+ if (isSessionVariableSet('mx_lang')) $data .= ":".GET_LANGUAGE();
+ if (isset($GLOBALS['refid'])) $data .= ":".$GLOBALS['refid'];
// Calculate number for generating the code
$a = $code + constant('_ADD') - 1;
$rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(constant('_MAX') - $a + sqrt(constant('_ADD'))) / pi();
} else {
// Generate hash with "hash of site key" from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % constant('_PRIME')).":".$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a, substr(sha1(SITE_KEY), 0, 8));
+ $saltedHash = generateHash(($a % constant('_PRIME')).":".$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a, substr(sha1(constant('SITE_KEY')), 0, 8));
// Create number from hash
$rcode = hexdec(substr($saltedHash, 8, 9)) / abs(constant('_MAX') - $a + sqrt(constant('_ADD'))) / pi();
return isUrlValid($URL);
}
-//
+// Generate a list of administrative links to a given userid
function MEMBER_ACTION_LINKS ($uid, $status = "") {
// Define all main targets
$TARGETS = array("del_user", "edit_user", "lock_user", "add_points", "sub_points");
return $OUT;
}
-// Function for backward-compatiblity
-// @TODO Can this function be deprecated?
-function ADD_CATEGORY_TABLE ($MODE, $return=false) {
- // Load it from the register extension
- return REGISTER_ADD_CATEGORY_TABLE ($MODE, $return);
-}
-
// Generate an email link
function CREATE_EMAIL_LINK ($email, $table = "admins") {
// Default email link (INSECURE! Spammer can read this by harvester programs)
// Return email link
return $EMAIL;
}
+
// Generate a hash for extra-security for all passwords
function generateHash ($plainText, $salt = "") {
global $_SERVER;
$server = $_SERVER['PHP_SELF'].":".GET_USER_AGENT().":".getenv('SERVER_SOFTWARE').":".GET_REMOTE_ADDR().":".":".filemtime(constant('PATH')."inc/databases.php");
// Build key string
- $keys = constant('SITE_KEY').":".constant('DATE_KEY').":".getConfig('secret_key').":".getConfig('file_hash').":".date("d-m-Y (l-F-T)", bigintval(getConfig('patch_ctime'))).":".getConfig('master_salt');
+ $keys = constant('SITE_KEY').":".constant('DATE_KEY').":".getConfig('secret_key').":".getConfig('file_hash').":".date("d-m-Y (l-F-T)", getConfig(('patch_ctime'))).":".getConfig('master_salt');
// Additional data
$data = $plainText.":".uniqid(mt_rand(), true).":".time();
// Return hash
return $salt.sha1($salt.$plainText);
}
-//
+
+// Scramble a string
function scrambleString($str) {
// Init
$scrambled = "";
//* DEBUG: */ echo "***Scrambled=".$scrambled."***<br />";
return $scrambled;
}
-//
+
+// De-scramble a string scrambled by scrambleString()
function descrambleString($str) {
// Scramble only 40 chars long strings
if (strlen($str) != 40) return $str;
//* DEBUG: */ echo "+++Original=".$orig."+++<br />";
return $orig;
}
-//
+
+// Generated a "string" for scrambling
function genScrambleString ($len) {
// Prepare array for the numbers
$scrambleNumbers = array();
// Loads an include file and logs any missing files for debug purposes
function LOAD_INC ($INC) {
- // Get constant path
- $PATH = constant('PATH');
-
- // Use the include file name directly
- // @TODO Try to find all locations where an FQFN is given to these two
- // @TODO functions and avoid it.
- $FQFN = $INC;
-
- // Check if PATH is in $INC
- if (substr($INC, 0, $PATH) != $PATH) {
- // Add it. This is why we need a trailing slash in config.php
- $FQFN = $PATH . $INC;
- } // END - if
+ // Add the path. This is why we need a trailing slash in config.php
+ $FQFN = constant('PATH') . $INC;
// Is the include file there?
if (!FILE_READABLE($FQFN)) {
// Not there so log it
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Include file %s not found.", basename($INC)));
+ debug_report_bug(sprintf("Include file %s not found.", $INC));
return false;
} // END - if
// Debug message logger
function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
// Is debug mode enabled?
- if ((isBooleanConstantAndTrue('DEBUG_MODE')) || ($force === true)) {
+ if ((isDebugModeEnabled()) || ($force === true)) {
// Log this message away
$fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
fwrite($fp, date("d.m.Y|H:i:s", time())."|".basename($funcFile)."|".$line."|".strip_tags($message)."\n");
}
// Load more reset scripts
-function RESET_ADD_INCLUDES () {
+function runResetIncludes () {
// Is the reset set or old sql_patches?
- if ((!defined('__DAILY_RESET')) || (EXT_VERSION_IS_OLDER("sql_patches", "0.4.5"))) {
+ if ((!isResetModeEnabled()) || (EXT_VERSION_IS_OLDER("sql_patches", "0.4.5"))) {
// Then abort here
- return array();
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot run reset! Please report this bug. Thanks");
} // END - if
// Get more daily reset scripts
// Update database
if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
- // Create current week mark
- $currWeek = date("W", time());
+ // Is the config entry set?
+ if (GET_EXT_VERSION("sql_patches") >= "0.4.2") {
+ // Create current week mark
+ $currWeek = date("W", time());
- // Has it changed?
- if (getConfig('last_week') != $currWeek) {
- // Include weekly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_"));
+ // Has it changed?
+ if (getConfig('last_week') != $currWeek) {
+ // Include weekly reset scripts
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_"));
- // Update config
- if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
- } // END - if
+ // Update config
+ if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
+ } // END - if
- // Create current month mark
- $currMonth = date("m", time());
+ // Create current month mark
+ $currMonth = date("m", time());
- // Has it changed?
- if (getConfig('last_month') != $currMonth) {
- // Include monthly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_"));
+ // Has it changed?
+ if (getConfig('last_month') != $currMonth) {
+ // Include monthly reset scripts
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_"));
- // Update config
- if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
+ // Update config
+ if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
+ } // END - if
} // END - if
- // Return array
- return $INC_POOL;
+ // Run the filter
+ runFilterChain('load_includes', $INC_POOL);
}
// Handle extra values
} // END - if
} else {
// Process this entry
- $skip = false; $test2 = "";
+ $skip = false;
+ $test2 = "";
}
}
}
// Rebuild cache
-function REBUILD_CACHE ($cache, $inc="") {
+function rebuildCacheFiles ($cache, $inc="") {
// Shall I remove the cache file?
- if ((EXT_IS_ACTIVE("cache")) && (is_object($GLOBALS['cache_instance']))) {
+ if ((EXT_IS_ACTIVE("cache")) && (isCacheInstanceValid())) {
// Rebuild cache
if ($GLOBALS['cache_instance']->loadCacheFile($cache)) {
// Destroy it
if (!EXT_IS_ACTIVE("cache")) {
// Cache extension not active
return false;
- } elseif (!is_object($GLOBALS['cache_instance'])) {
+ } elseif (!isCacheInstanceValid()) {
// No cache instance!
DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
return false;
$GLOBALS['refid'] = bigintval(get_session('refid'));
} elseif ((GET_EXT_VERSION("sql_patches") != "") && (getConfig('def_refid') > 0)) {
// Set default refid as refid in URL
- $GLOBALS['refid'] = bigintval(getConfig('def_refid'));
+ $GLOBALS['refid'] = getConfig(('def_refid'));
} elseif ((GET_EXT_VERSION("user") >= "0.3.4") && (getConfig('select_user_zero_refid')) == "Y") {
// Select a random user which has confirmed enougth mails
$GLOBALS['refid'] = SELECT_RANDOM_REFID();
return isBooleanConstantAndTrue('admin_registered');
}
+// Enables the reset mode. Only call this function if you really want the
+// reset to be run!
+function enableResetMode () {
+ // Enable the reset mode
+ $GLOBALS['reset_enabled'] = true;
+
+ // Run filters
+ runFilterChain('reset_enabled');
+}
+
+// Checks wether the reset mode is active
+function isResetModeEnabled () {
+ // Now simply check it
+ return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
+}
+
+// Checks wether the debug mode is enabled
+function isDebugModeEnabled () {
+ // Simply check it
+ return isBooleanConstantAndTrue('DEBUG_MODE');
+}
+
+// Checks wether the cache instance is valid
+function isCacheInstanceValid () {
+ return ((isset($GLOBALS['cache_instance'])) && (is_object($GLOBALS['cache_instance'])));
+}
+
//////////////////////////////////////////////////
// AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
//////////////////////////////////////////////////