sendHeader('Connection: Close');
// Extension 'rewrite' installed?
- if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
+ if ((EXT_IS_ACTIVE('rewrite')) && (getOutputMode() != '1') && (getOutputMode() != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
+ // Replace _MYSQL_PREFIX
+ $OUTPUT = str_replace("{!_MYSQL_PREFIX!}", getConfig('_MYSQL_PREFIX'), $OUTPUT);
+
// Prepare the content and eval() it...
$newContent = '';
$eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- app_die(__FUNCTION__, __LINE__, "Evaluation error:<pre>".htmlentities($eval)."</pre>");
+ app_die(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . htmlentities($eval) . '</pre>');
} // END - if
$OUTPUT = $newContent;
} // END - while
outputRawCode($OUTPUT);
} elseif ((getConfig('OUTPUT_MODE') == 'render') && (!empty($OUTPUT))) {
// Rewrite links when rewrite extension is active
- if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
+ if ((EXT_IS_ACTIVE('rewrite')) && (getOutputMode() != '1') && (getOutputMode() != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
} elseif (strpos($template, 'la_') > -1) {
// 'Logical-area' template found
$mode = 'la/';
+ } elseif (strpos($template, 'js_') > -1) {
+ // JavaScript template found
+ $mode = 'js/';
} else {
// Test for extension
$test = substr($template, 0, strpos($template, '_'));
if (EXT_IS_ACTIVE($test)) {
// Set extra path to extension's name
- $mode = $test.'/';
- }
+ $mode = $test . '/';
+ } // END - if
}
////////////////////////
////////////////////////
$FQFN = $basePath . $mode . $template . '.tpl';
- if ((!empty($GLOBALS['what'])) && ((strpos($template, '_header') > 0) || (strpos($template, '_footer') > 0)) && (($mode == 'guest/') || ($mode == 'member/') || ($mode == 'admin/'))) {
+ if ((isWhatSet()) && ((strpos($template, '_header') > 0) || (strpos($template, '_footer') > 0)) && (($mode == 'guest/') || ($mode == 'member/') || ($mode == 'admin/'))) {
// Select what depended header/footer template file for admin/guest/member area
$file2 = sprintf("%s%s%s_%s.tpl",
$basePath,
$mode,
$template,
- SQL_ESCAPE($GLOBALS['what'])
+ getWhat()
);
// Probe for it...
$ret = $tmpl_file;
}
- // Add surrounding HTML comments to help finding bugs faster
- $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+ // Normal HTML output?
+ if ($GLOBALS['output_mode'] == 0) {
+ // Add surrounding HTML comments to help finding bugs faster
+ $ret = "<!-- Template " . $template . " - Start -->\n" . $ret . "<!-- Template " . $template . " - End -->\n";
+ } // END - if
} elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
$ret = "<br /><span class=\"guest_failed\">{--TEMPLATE_404--}</span><br />
eval($eval);
// Set from header
- if ((!eregi("@", $toEmail)) && ($toEmail > 0)) {
+ if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
// Value detected, is the message extension installed?
- if (EXT_IS_ACTIVE("msg")) {
+ // @TODO Extension 'msg' does not exist
+ if (EXT_IS_ACTIVE('msg')) {
ADD_MESSAGE_TO_BOX($toEmail, $subject, $message, $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($toEmail)), __FUNCTION__, __LINE__);
+ $result_email = SQL_QUERY_ESC("SELECT `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($toEmail)), __FUNCTION__, __LINE__);
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result_email)."<br />\n";
// Does the user exist?
}
// Generate a password in a specified length or use default password length
-function generatePassword ($LEN = 0) {
+function generatePassword ($length = 0) {
// Auto-fix invalid length of zero
- if ($LEN == 0) $LEN = getConfig('pass_len');
+ if ($length == 0) $length = getConfig('pass_len');
// Initialize array with all allowed chars
- $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/');
+ $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/,.');
// Start creating password
$PASS = '';
- for ($i = 0; $i < $LEN; $i++) {
+ for ($i = 0; $i < $length; $i++) {
$PASS .= $ABC[mt_rand(0, count($ABC) -1)];
} // END - for
// Loads an email template and compiles it
function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
- global $DATA, $_CONFIG;
+ global $DATA;
+
+ // Our configuration is kept non-global here
+ $_CONFIG = getConfigArray();
// Make sure all template names are lowercase!
$template = strtolower($template);
$keys = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY');
if (isConfigEntrySet('secret_key')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key');
if (isConfigEntrySet('file_hash')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash');
- $keys .= getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig(('patch_ctime')));
+ $keys .= getConfig('ENCRYPT_SEPERATOR') . date("d-m-Y (l-F-T)", getConfig('patch_ctime'));
if (isConfigEntrySet('master_salt')) $keys .= getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
// Build string from misc data
// Has the whole value changed?
// @TODO Remove this if() block if all is working fine
- if ("" . $ret."" != '' . $num."") {
+ if ('' . $ret . '' != '' . $num . '') {
// Log the values
- debug_report_bug("{$ret}<>{$num}");
+ //debug_report_bug("{$ret}<>{$num}");
} // END - if
// Return result
$OUT .= " <td align=\"center\" class=\"admin_title bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
}
- if (ereg("M", $display) || (empty($display))) {
+ if (ereg('M', $display) || (empty($display))) {
$OUT .= " <td align=\"center\" class=\"admin_title bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
}
$OUT .= "<INPUT type=\"hidden\" name=\"" . $prefix."_ye\" value=\"0\" />\n";
}
- if (ereg("M", $display) || (empty($display))) {
+ if (ereg('M', $display) || (empty($display))) {
// Generate month selection
$OUT .= " <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix."_mo\" size=\"1\">\n";
for ($idx = 0; $idx <= 11; $idx++)
$NAV .= "<strong>-";
} else {
// Open anchor tag and add base URL
- $NAV .= "<a href=\"{!URL!}/modules.php?module=admin&what=" . $GLOBALS['what']."&page=" . $page."&offset=" . $offset;
+ $NAV .= "<a href=\"{!URL!}/modules.php?module=admin&what=" . getWhat()."&page=" . $page."&offset=" . $offset;
// Add userid when we shall show all mails from a single member
if ((REQUEST_ISSET_GET('uid')) && (bigintval(REQUEST_GET('uid')) > 0)) $NAV .= "&uid=".bigintval(REQUEST_GET('uid'));
}
// Generate an email link
-function generateMemberEmailLink ($email, $table = 'admins') {
+function generateEmailLink ($email, $table = 'admins') {
// Default email link (INSECURE! Spammer can read this by harvester programs)
$EMAIL = 'mailto:' . $email;
// Check for several extensions
if ((EXT_IS_ACTIVE('admins')) && ($table == 'admins')) {
// Create email link for contacting admin in guest area
- $EMAIL = adminsCreateEmailLink($email);
+ $EMAIL = generateAdminEmailLink($email);
} elseif ((EXT_IS_ACTIVE('user')) && (GET_EXT_VERSION('user') >= '0.3.3') && ($table == 'user_data')) {
// Create email link for contacting a member within admin area (or later in other areas, too?)
- $EMAIL = USER_generateMemberEmailLink($email);
+ $EMAIL = generateEmailLink($email, 'user_data');
} elseif ((EXT_IS_ACTIVE('sponsor')) && ($table == 'sponsor_data')) {
// Create email link to contact sponsor within admin area (or like the link above?)
- $EMAIL = SPONSOR_generateMemberEmailLink($email);
+ $EMAIL = generateEmailLink($email, 'sponsor_data');
}
// Shall I close the link when there is no admin?
$server = $_SERVER['PHP_SELF'].getConfig('ENCRYPT_SEPERATOR').detectUserAgent().getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_SOFTWARE').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr();
// Build key string
- $keys = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key').getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash').getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig(('patch_ctime'))).getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
+ $keys = getConfig('SITE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').getConfig('secret_key').getConfig('ENCRYPT_SEPERATOR').getConfig('file_hash').getConfig('ENCRYPT_SEPERATOR').date("d-m-Y (l-F-T)", getConfig('patch_ctime')).getConfig('ENCRYPT_SEPERATOR').getConfig('master_salt');
// Additional data
$data = $plainText.getConfig('ENCRYPT_SEPERATOR').uniqid(mt_rand(), true).getConfig('ENCRYPT_SEPERATOR').time();
// Load header
loadIncludeOnce('inc/header.php');
- // Prepare message for output
+ // Rewrite message for output
$message = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $message);
+ // Better log this message away
+ DEBUG_LOG($F, $L, $message);
+
// Load the message template
LOAD_TEMPLATE('admin_settings_saved', false, $message);
// Fix it to default
$ret = 'default';
} // END - if
- } elseif ((!isInstalled()) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET('theme')) || (REQUEST_ISSET_POST('theme')))) {
+ } elseif ((!isInstalled()) && ((isInstalling()) || (getOutputMode() == true)) && ((REQUEST_ISSET_GET('theme')) || (REQUEST_ISSET_POST('theme')))) {
// Prepare FQFN for checking
$theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET('theme'));
// Generates an error code from given account status
function generateErrorCodeFromUserStatus ($status) {
+ // @TODO The status should never be empty
+ if (empty($status)) {
+ // Something really bad happend here
+ debug_report_bug(__FUNCTION__ . ': status is empty.');
+ } // END - if
+
// Default error code if unknown account status
$errorCode = getCode('UNKNOWN_STATUS');
if (EXT_IS_ACTIVE('cache')) {
// Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
- if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') $new = true;
- if (!isset($GLOBALS['cache_array']['revision'][$type])
- || count($GLOBALS['cache_array']['revision']) < 3
- || !$GLOBALS['cache_instance']->loadCacheFile('revision')) $new = true;
+ if (REQUEST_ISSET_GET('check_revision_data') && REQUEST_GET('check_revision_data') == 'yes') {
+ // Force rebuild by URL parameter
+ $new = true;
+ } elseif ((
+ !isset($GLOBALS['cache_array']['revision'][$type])
+ ) || (
+ count($GLOBALS['cache_array']['revision']) < 3
+ ) || (
+ !$GLOBALS['cache_instance']->loadCacheFile('revision')
+ )) {
+ // Out-dated cache
+ $new = true;
+ } // END - if
// Is the cache file outdated/invalid?
- if ($new === true){
- $GLOBALS['cache_instance']->destroyCacheFile(); // @TODO isn't it better to do $GLOBALS['cache_instance']->destroyCacheFile('revision')?
+ if ($new === true) {
+ // Reload the cache file
+ $GLOBALS['cache_instance']->loadCacheFile('revision');
+
+ // Destroy cache file
+ $GLOBALS['cache_instance']->destroyCacheFile(false, true);
// @TODO shouldn't do the unset and the reloading $GLOBALS['cache_instance']->destroyCacheFile() Or a new methode like forceCacheReload('revision')?
unset($GLOBALS['cache_array']['revision']);
// Reload load_cach-revison.php
loadInclude('inc/loader/load_cache-revision.php');
+
+ // Abort here
+ return;
} // END - if
// Return found value
return $GLOBALS['cache_array']['revision'][$type][0];
-
} else {
// Old Version without ext-cache active (deprecated ?)
// Check if REQUEST_GET('check_revision_data') is setted (switch for manually rewrite the .revision-File)
if ((REQUEST_ISSET_GET('check_revision_data')) && (REQUEST_GET('check_revision_data') == 'yes')) {
- // Has changed!
+ // Forced rebuild of .revision file
$new = true;
} else {
// Check for revision file
} // END - if
// Add output
- $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>inc/cache/debug.log</strong> in your report (you cannot attach files!):<pre>";
+ $debug .= "Please report this bug at <a title=\"Direct link to the bug-tracker\" href=\"http://bugs.mxchange.org\" rel=\"external\" target=\"_blank\">bugs.mxchange.org</a> and include the logfile from <strong>inc/cache/debug.log</strong> in your report (you can now attach files):<pre>";
$debug .= debug_get_printable_backtrace();
$debug .= "</pre>\nRequest-URI: " . $_SERVER['REQUEST_URI']."<br />\n";
$debug .= "Thank you for finding bugs.";
// Generates a ***weak*** seed (taken from de.php.net/mt_srand)
function generateSeed () {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$sec + (float)$usec);
+ list($usec, $sec) = explode(' ', microtime());
+ $microTime = (((float)$sec + (float)$usec)) * 100000;
+ return $microTime;
}
// Converts a message code to a human-readable message
// Is the extension there?
if (EXT_IS_ACTIVE('admins')) {
// Admin found
- $admin = "<a href=\"".adminsCreateEmailLink(getAdminEmail($aid))."\">" . $login."</a>";
+ $admin = "<a href=\"".generateEmailLink(getAdminEmail($aid), 'admins')."\">" . $login."</a>";
} else {
// Extension not found
$admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
}
// Compile characters which are allowed in URLs
-function compileUriCode ($code, $simple=true) {
+function compileUriCode ($code, $simple = true) {
// Compile constants
if (!$simple) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
$tmp = $FQFN . '.tmp';
// Open the source file
- $fp = fopen($FQFN, 'r') or OUTPUT_HTML('<strong>READ:</strong> ' . $FQFN . "<br />\n");
+ $fp = fopen($FQFN, 'r') or OUTPUT_HTML('<strong>READ:</strong> ' . $FQFN . '<br />');
// Is the resource valid?
if (is_resource($fp)) {
// Open temporary file
- $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('<strong>WRITE:</strong> ' . $tmp . "<br />\n");
+ $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('<strong>WRITE:</strong> ' . $tmp . '<br />');
// Is the resource again valid?
if (is_resource($fp_tmp)) {
} else {
$next++;
}
- }
+ } // END - if
// Write to temp file
fputs($fp_tmp, $line);
// Remove CRLF
$message = str_replace("\r", '', str_replace("\n", '', $message));
- // Log this message away
- $fp = fopen(constant('PATH')."inc/cache/debug.log", 'a') or app_die(__FUNCTION__, __LINE__, "Cannot write logfile debug.log!");
- fwrite($fp, date("d.m.Y|H:i:s", time())."|" . $GLOBALS['module']."|".basename($funcFile)."|" . $line."|".strip_tags($message)."\n");
+ // Log this message away, we better don't call app_die() here to prevent an endless loop
+ $fp = fopen(constant('PATH') . 'inc/cache/debug.log', 'a') or die(__FUNCTION__.'['.__LINE__.']: Cannot write logfile debug.log!');
+ fwrite($fp, date('d.m.Y|H:i:s', time()) . '|' . getModule() . '|' . basename($funcFile) . '|' . $line . '|' . strip_tags($message) . "\n");
fclose($fp);
} // END - if
}
// Is the reset set or old sql_patches?
if ((!isResetModeEnabled()) || (EXT_VERSION_IS_OLDER('sql_patches', '0.4.5'))) {
// Then abort here
- DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot run reset! Please report this bug. Thanks");
+ DEBUG_LOG(__FUNCTION__, __LINE__, 'Cannot run reset! Please report this bug. Thanks');
} // END - if
// Get more daily reset scripts
$GLOBALS['refid'] = bigintval(getSession('refid'));
} elseif ((GET_EXT_VERSION('sql_patches') != '') && (getConfig('def_refid') > 0)) {
// Set default refid as refid in URL
- $GLOBALS['refid'] = 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'] = determineRandomReferalId();
// Handle message codes from URL
function handleCodeMessage () {
if (REQUEST_ISSET_GET('msg')) {
- // Default extension is "unknown"
+ // Default extension is 'unknown'
$ext = 'unknown';
// Is extension given?