} // END - if
// Test if we can append data
- $fp = @fopen($fqfn, 'a');
+ $fp = fopen($fqfn, 'a');
if ($inc == "dummy") {
// Remove dummy file
fclose($fp);
// Output cached HTML code
$OUTPUT = ob_get_contents();
- // Clear output buffer for later output
- clearOutputBuffer();
+ // Clear output buffer for later output if output is found
+ if (!empty($OUTPUT)) {
+ clearOutputBuffer();
+ } // END - if
// Send HTTP header
header("HTTP/1.1 200");
while (strpos($OUTPUT, '{!') > 0) {
// Prepare the content and eval() it...
$newContent = "";
- $eval = "\$newContent = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
- @eval($eval);
+ $eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
+ eval($eval);
// Was that eval okay?
if (empty($newContent)) {
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
- $eval = "\$OUTPUT = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
+ $eval = "\$OUTPUT = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
eval($eval);
} // END - while
}
// Add a fatal error message to the queue array
-function addFatalMessage ($message, $extra="") {
+function addFatalMessage ($F, $L, $message, $extra="") {
if (is_array($extra)) {
// Multiple extras for a message with masks
$message = call_user_func_array('sprintf', $extra);
$GLOBALS['fatal_messages'][] = $message;
// Log fatal messages away
- DEBUG_LOG(__FUNCTION__, __LINE__, " message={$message}");
+ DEBUG_LOG($F, $L, " message={$message}");
}
// Getter for total fatal message count
if ($template == "member_support_form") {
// Support request of a member
$result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array($GLOBALS['userid']), __FILE__, __LINE__);
+ array($GLOBALS['userid']), __FUNCTION__, __LINE__);
// Is content an array?
if (is_array($content)) {
$ret = "";
if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
// Okay, compile it!
- $tmpl_file = "\$ret=\"".COMPILE_CODE(SQL_ESCAPE($tmpl_file))."\";";
+ $tmpl_file = "\$ret=\"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";";
eval($tmpl_file);
} else {
// Simply return loaded code
// Add surrounding HTML comments to help finding bugs faster
$ret = "<!-- Template ".$template." - Start -->\n".$ret."<!-- Template ".$template." - End -->\n";
- } elseif ((IS_ADMIN()) || ((isBooleanConstantAndTrue('mxchange_installing')) && (!isBooleanConstantAndTrue('mxchange_installed')))) {
+ } 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 />
(".basename($FQFN).")<br />
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):TO={$TO},SUBJECT={$SUBJECT}<br />\n";
// Compile subject line (for POINTS constant etc.)
- $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(SQL_ESCAPE($SUBJECT))."\");";
+ $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(smartAddSlashes($SUBJECT))."\");";
eval($eval);
// Set from header
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__);
+ $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($TO)), __FUNCTION__, __LINE__);
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):numRows=".SQL_NUMROWS($result_email)."<br />\n";
// Does the user exist?
}
// Compile "TO"
- $eval = "\$TO = \"".COMPILE_CODE(SQL_ESCAPE($TO))."\";";
+ $eval = "\$TO = \"".COMPILE_CODE(smartAddSlashes($TO))."\";";
eval($eval);
// Compile "MSG"
- $eval = "\$MSG = \"".COMPILE_CODE(SQL_ESCAPE($MSG))."\";";
+ $eval = "\$MSG = \"".COMPILE_CODE(smartAddSlashes($MSG))."\";";
eval($eval);
// Fix HTML parameter (default is no!)
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NICKNAME!<br />\n";
// Load nickname
$result = SQL_QUERY_ESC("SELECT surname, family, gender, email, nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array(bigintval($UID)), __FILE__, __LINE__);
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
} else {
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):NO-NICK!<br />\n";
/// Load normal data
$result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array(bigintval($UID)), __FILE__, __LINE__);
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
}
// Fetch and merge data
// Run code
$tmpl_file = "\$newContent = decodeEntities(\"".COMPILE_CODE($tmpl_file)."\");";
- @eval($tmpl_file);
+ eval($tmpl_file);
} elseif (!empty($template)) {
// Template file not found!
$newContent = "{--TEMPLATE_404--}: ".$template."<br />
return COMPILE_CODE($newContent);
}
//
-function MAKE_TIME($H, $M, $S, $stamp) {
+function MAKE_TIME ($H, $M, $S, $stamp) {
// Extract day, month and year from given timestamp
$DAY = date("d", $stamp);
$MONTH = date("m", $stamp);
return mktime($H, $M, $S, $MONTH, $DAY, $YEAR);
}
//
-function LOAD_URL($URL, $addUrlData=true) {
+function LOAD_URL ($URL, $addUrlData=true) {
// Compile out URI codes
$URL = compileUriCode($URL);
}
// Get output buffer
- //* DEBUG: */ debug_report_bug();
+ //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, $URL);
$OUTPUT = ob_get_contents();
// Clear it only if there is content
} // END - if
// Add some data to URL if cookies are not accepted
- if (((!defined('__COOKIES')) || (!__COOKIES)) && ($addUrlData)) $URL = ADD_URL_DATA($URL);
+ if (((!defined('__COOKIES')) || (!constant('__COOKIES'))) && ($addUrlData)) $URL = ADD_URL_DATA($URL);
// Probe for bot from search engine
if ((eregi("spider", GET_USER_AGENT())) || (eregi("bot", GET_USER_AGENT()))) {
}
//
-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;
}
//
// 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",
- array($template), __FILE__, __LINE__);
+ array($template), __FUNCTION__, __LINE__);
if (SQL_NUMROWS($result) == 0) {
// Create new entry (to all admins)
SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_mails` (admin_id, mail_template) VALUES (0, '%s')",
- array($template), __FILE__, __LINE__);
+ array($template), __FUNCTION__, __LINE__);
} else {
// Load admin IDs...
$aids = array();
}
} elseif ($aid == "0") {
// Select all email adresses
- $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FILE__, __LINE__);
+ $result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FUNCTION__, __LINE__);
} else {
// If Admin-ID is not "to-all" select
- $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FILE__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` WHERE id IN (%s) ORDER BY `id`", array($aid), __FUNCTION__, __LINE__);
}
}
// 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
// Failed by default
$res = false;
if (isset($GLOBALS['cache_array']['const'][$constName])) {
// Use cache
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-CACHE!<br />\n";
- $res = $GLOBALS['cache_array']['const'][$constName];
+ $res = ($GLOBALS['cache_array']['const'][$constName] === true);
} else {
// Check constant
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-RESOLVE!<br />\n";
- if (defined($constName)) $res = (constant($constName) === true);
+ if (defined($constName)) {
+ // Found!
+ //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$constName."-FOUND!<br />\n";
+ $res = (constant($constName) === true);
+ } // END - if
// Set cache
$GLOBALS['cache_array']['const'][$constName] = $res;
// Fix it to default
$ret = "default";
} // END - if
- } elseif ((!isBooleanConstantAndTrue('mxchange_installed')) && ((isBooleanConstantAndTrue('mxchange_installing')) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
+ } elseif ((!isInstalled()) && ((isInstalling()) || ($GLOBALS['output_mode'] == true)) && ((REQUEST_ISSET_GET(('theme'))) || (REQUEST_ISSET_POST(('theme'))))) {
// Prepare FQFN for checking
- $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_GET('theme')));
+ $theme = sprintf("%stheme/%s/theme.php", constant('PATH'), REQUEST_GET(('theme')));
// Installation mode active
if ((REQUEST_ISSET_GET(('theme'))) && (FILE_READABLE($theme))) {
// Set cookie from URL data
- set_session('mxchange_theme', SQL_ESCAPE(REQUEST_GET('theme')));
+ set_session('mxchange_theme', REQUEST_GET(('theme')));
} elseif (FILE_READABLE(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) {
// Set cookie from posted data
set_session('mxchange_theme', SQL_ESCAPE(REQUEST_POST('theme')));
} elseif (GET_EXT_VERSION("cache") != "0.1.8") {
// Check if current theme is already imported or not
$result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_themes` WHERE theme_path='%s' LIMIT 1",
- array($name), __FILE__, __LINE__);
+ array($name), __FUNCTION__, __LINE__);
// Entry found?
if (SQL_NUMROWS($result) == 1) {
// 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)) {
// Loads an include file once
function LOAD_INC_ONCE ($INC) {
// Is it not loaded?
- if (!isset($GLOBALS['cache_array']['load_once'][$INC])) {
+ if (!isset($GLOBALS['load_once'][$INC])) {
// Then try to load it
LOAD_INC($INC);
// And mark it as loaded
- $GLOBALS['cache_array']['load_once'][$INC] = "loaded";
+ $GLOBALS['load_once'][$INC] = "loaded";
} // END - if
}
// Get and prepare backtrace for output
$backtraceArray = debug_backtrace();
foreach ($backtraceArray as $key => $trace) {
- if (!isset($trace['file'])) $trace['file'] = __FILE__;
+ if (!isset($trace['file'])) $trace['file'] = __FUNCTION__;
if (!isset($trace['line'])) $trace['line'] = __LINE__;
if (!isset($trace['args'])) $trace['args'] = array();
$backtrace .= "<li class=\"debug_list\"><span class=\"backtrace_file\">".basename($trace['file'])."</span>:".$trace['line'].", <span class=\"backtrace_function\">".$trace['function']."(".count($trace['args']).")</span></li>\n";
case constant('CODE_EXTENSION_PROBLEM'):
if (REQUEST_ISSET_GET(('ext'))) {
- $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), SQL_ESCAPE(REQUEST_GET('ext')));
+ $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), REQUEST_GET(('ext')));
} else {
$msg = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
}
// Generate a "link" for the given admin id (aid)
function GENERATE_AID_LINK ($aid) {
// No assigned admin is default
- $admin = "<div class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</div>";
+ $admin = "<span class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</span>";
// Zero? = Not assigned
if ($aid == "0") {
$tmp = $FQFN.".tmp";
// Open the source file
- $fp = @fopen($FQFN, 'r') or OUTPUT_HTML("<strong>READ:</strong> ".$FQFN."<br />");
+ $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 />");
+ $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML("<strong>WRITE:</strong> ".$tmp."<br />");
// Is the resource again valid?
if (is_resource($fp_tmp)) {
if (($done) && ($found)) {
// Copy back tmp file and delete tmp :-)
- @copy($tmp, $FQFN);
- @unlink($tmp);
- define('_FATAL', false);
+ copy($tmp, $FQFN);
+ return unlink($tmp);
} elseif (!$found) {
OUTPUT_HTML("<strong>CHANGE:</strong> 404!");
- define('_FATAL', true);
} else {
OUTPUT_HTML("<strong>TMP:</strong> UNDONE!");
- define('_FATAL', true);
}
}
} else {
// File not found, not readable or writeable
OUTPUT_HTML("<strong>404:</strong> ".$FQFN."<br />");
}
+
+ // An error was detected!
+ return false;
}
// Send notification to admin
function SEND_ADMIN_NOTIFICATION($subject, $templateName, $content=array(), $uid="0") {
$INCs = array();
// Open directory
- $dirPointer = opendir($baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
+ $dirPointer = opendir(constant('PATH') . $baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
// Read all entries
while ($baseFile = readdir($dirPointer)) {
// Load file only if extension is active
- // Make full path
- $FQFN = $baseDir.$baseFile;
+ $INC = $baseDir.$baseFile;
+ $FQFN = constant('PATH') . $INC;
// Is this a valid reset file?
//* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
// Is the extension valid and active?
if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
// Then add this file
- $INCs[] = $FQFN;
+ $INCs[] = $INC;
} elseif ($extId == 0) {
// Add non-extension files as well
- $INCs[] = $FQFN;
+ $INCs[] = $INC;
}
} // END - if
} // END - while
} // END - if
// Get more daily reset scripts
- $INC_POOL = GET_DIR_AS_ARRAY(constant('PATH')."inc/reset/", "reset_");
+ $INC_POOL = GET_DIR_AS_ARRAY("inc/reset/", "reset_");
// Update database
if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
// Has it changed?
if (getConfig('last_week') != $currWeek) {
// Include weekly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/weekly/", "weekly_"));
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/weekly/", "weekly_"));
// Update config
if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
// Has it changed?
if (getConfig('last_month') != $currMonth) {
// Include monthly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/monthly/", "monthly_"));
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY("inc/monthly/", "monthly_"));
// Update config
if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
return $GLOBALS['refid'];
}
+// Check wether we are installing
+function isInstalling () {
+ return (isset($GLOBALS['mxchange_installing']));
+}
+
+// Check wether this script is installed
+function isInstalled () {
+ return isBooleanConstantAndTrue('mxchange_installed');
+}
+
+// Check wether an admin is registered
+function isAdminRegistered () {
+ return isBooleanConstantAndTrue('admin_registered');
+}
+
//////////////////////////////////////////////////
// AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
//////////////////////////////////////////////////