X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=34e1aa54fedfbc70905ed34f53126602dfc21d7b;hb=66b91ce490ab549425619c95fc12086e126d541b;hp=637412fc66ae8626244eebb5df5c42150225fc59;hpb=3203112d9be14c2df49bd6b3b618b17fd950cc09;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index 637412fc66..34e1aa54fe 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -44,7 +44,11 @@ if (!defined('__SECURITY')) {
// Output HTML code directly or 'render' it. You addionally switch the new-line character off
function OUTPUT_HTML ($HTML, $newLine = true) {
// Some global variables
- global $OUTPUT;
+ global $OUTPUT, $username;
+
+ // Prepare IP number and User Agent
+ $REMOTE_ADDR = detectRemoteAddr();
+ $HTTP_USER_AGENT = detectUserAgent();
// Do we have HTML-Code here?
if (!empty($HTML)) {
@@ -58,7 +62,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
outputRawCode($HTML);
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($newLine) echo "\n";
+ if ($newLine) print("\n");
} else {
// Render mode for old or lame servers...
$OUTPUT .= $HTML;
@@ -74,22 +78,22 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// The same as above... ^
outputRawCode($HTML);
- if ($newLine) echo "\n";
+ if ($newLine) print("\n");
break;
default:
// Huh, something goes wrong or maybe you have edited config.php ???
- app_die(__FUNCTION__, __LINE__, "{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}");
+ app_die(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}');
break;
}
} elseif ((constant('_OB_CACHING') == 'on') && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
// Headers already sent?
if (headers_sent()) {
// Log this error
- DEBUG_LOG(__FUNCTION__, __LINE__, "Headers already sent! We need debug backtrace here.");
+ DEBUG_LOG(__FUNCTION__, __LINE__, 'Headers already sent! We need debug backtrace here.');
// Trigger an user error
- debug_report_bug("Headers are already sent!");
+ debug_report_bug('Headers are already sent!');
} // END - if
// Output cached HTML code
@@ -114,12 +118,15 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
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))."\";";
@@ -128,7 +135,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- app_die(__FUNCTION__, __LINE__, "Evaluation error:
".htmlentities($eval)." ");
+ app_die(__FUNCTION__, __LINE__, 'Evaluation error:' . htmlentities($eval) . ' ');
} // END - if
$OUTPUT = $newContent;
} // END - while
@@ -137,7 +144,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
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
@@ -155,7 +162,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// Output the raw HTML code
function outputRawCode ($HTML) {
// Output stripped HTML code to avoid broken JavaScript code, etc.
- echo stripslashes(stripslashes($HTML));
+ print(stripslashes(stripslashes($HTML)));
// Flush the output if only constant('_OB_CACHING') is not 'on'
if (constant('_OB_CACHING') != 'on') {
@@ -208,32 +215,37 @@ function getTotalFatalErrors () {
// Load a template file and return it's content (only it's name; do not use ' or ")
function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
+ // @TODO Remove this sanity-check if all is fine
+ if (!is_bool($return)) debug_report_bug('return is not bool (' . gettype($return) . ')');
+
+ // Prepare IP number and User Agent
+ $REMOTE_ADDR = detectRemoteAddr();
+ $HTTP_USER_AGENT = detectUserAgent();
+
// Add more variables which you want to use in your template files
global $DATA, $username;
- // Get whole config array
- $_CONFIG = getConfigArray();
-
// Make all template names lowercase
$template = strtolower($template);
// Count the template load
incrementConfigEntry('num_templates');
- // Prepare IP number and User Agent
- $REMOTE_ADDR = detectRemoteAddr();
- if (!defined('REMOTE_ADDR')) define('REMOTE_ADDR', $REMOTE_ADDR);
- $HTTP_USER_AGENT = detectUserAgent();
-
// Init some data
$ret = '';
if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
+ // Generate date/time string
+ $date_time = generateDateTime(time(), '1');
+
+ // Is content an array
+ if (is_array($content)) $content['date_time'] = $date_time;
+
// @DEPRECATED Try to rewrite the if() condition
- if ($template == "member_support_form") {
+ 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(getUserId()), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(getUserId()), __FUNCTION__, __LINE__);
// Is content an array?
if (is_array($content)) {
@@ -244,66 +256,66 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$content['gender'] = translateGender($content['gender']);
} else {
// @DEPRECATED
- // @TODO Fine all templates which are using these direct variables and rewrite them.
+ // @TODO Find all templates which are using these direct variables and rewrite them.
// @TODO After this step is done, this else-block is history
list($gender, $surname, $family, $email) = SQL_FETCHROW($result);
// Translate gender
$gender = translateGender($gender);
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array (%s).", gettype($content)));
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array [%s], template=%s.", gettype($content), $template));
}
// Free result
SQL_FREERESULT($result);
} // END - if
- // Generate date/time string
- $date_time = generateDateTime(time(), '1');
-
// Base directory
- $basePath = sprintf("%stemplates/%s/html/", constant('PATH'), getLanguage());
+ $basePath = sprintf("%stemplates/%s/html/", getConfig('PATH'), getLanguage());
$mode = '';
// Check for admin/guest/member templates
- if (strpos($template, "admin_") > -1) {
+ if (strpos($template, 'admin_') > -1) {
// Admin template found
- $mode = "admin/";
- } elseif (strpos($template, "guest_") > -1) {
+ $mode = 'admin/';
+ } elseif (strpos($template, 'guest_') > -1) {
// Guest template found
- $mode = "guest/";
- } elseif (strpos($template, "member_") > -1) {
+ $mode = 'guest/';
+ } elseif (strpos($template, 'member_') > -1) {
// Member template found
- $mode = "member/";
- } elseif (strpos($template, "install_") > -1) {
+ $mode = 'member/';
+ } elseif (strpos($template, 'install_') > -1) {
// Installation template found
- $mode = "install/";
- } elseif (strpos($template, "ext_") > -1) {
+ $mode = 'install/';
+ } elseif (strpos($template, 'ext_') > -1) {
// Extension template found
- $mode = "ext/";
- } elseif (strpos($template, "la_") > -1) {
- // "Logical-area" template found
- $mode = "la/";
+ $mode = 'ext/';
+ } 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, "_"));
+ $test = substr($template, 0, strpos($template, '_'));
if (EXT_IS_ACTIVE($test)) {
// Set extra path to extension's name
- $mode = $test.'/';
- }
+ $mode = $test . '/';
+ } // END - if
}
////////////////////////
// Generate file name //
////////////////////////
- $FQFN = $basePath.$mode.$template.".tpl";
+ $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'])
+ $basePath,
+ $mode,
+ $template,
+ getWhat()
);
// Probe for it...
@@ -311,12 +323,12 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
// Remove variable from memory
unset($file2);
- }
+ } // END - if
// Does the special template exists?
if (!isFileReadable($FQFN)) {
// Reset to default template
- $FQFN = $basePath.$template.".tpl";
+ $FQFN = $basePath . $template . '.tpl';
} // END - if
// Now does the final template exists?
@@ -330,16 +342,23 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
// Do we have to compile the code?
$ret = '';
if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
- // Okay, compile it!
- $tmpl_file = "\$ret=\"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";";
- eval($tmpl_file);
+ // Compile it
+ $eval = "\$ret = \"".COMPILE_CODE(smartAddSlashes($tmpl_file))."\";";
+ eval($eval);
+ // NEW WAY: $ret = str_replace("\$content", "\$GLOBALS[compile][".$template."]", $tmpl_file);
+ // NEW WAY: $ret = str_replace("\$DATA", "\$GLOBALS[data][".$template."]", $ret);
+ // NEW WAY: $GLOBALS['compile'][$template] = $content;
+ // NEW WAY: $GLOBALS['data'][$template] = $DATA;
} else {
// Simply return loaded code
$ret = $tmpl_file;
}
- // Add surrounding HTML comments to help finding bugs faster
- $ret = "\n".$ret."\n";
+ // Normal HTML output?
+ if ($GLOBALS['output_mode'] == 0) {
+ // Add surrounding HTML comments to help finding bugs faster
+ $ret = "\n" . $ret . "\n";
+ } // END - if
} elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
$ret = "{--TEMPLATE_404--}
@@ -368,28 +387,30 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
}
} elseif (isDebugModeEnabled()) {
// Warning, empty output!
- return "E:".$template." \n";
+ return "E:" . $template." \n";
}
}
// Send mail out to an email address
-function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '') {
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):TO={$toEmail},SUBJECT={$subject} \n";
+function sendEmail ($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '') {
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):TO={$toEmail},SUBJECT={$subject} ");
// Compile subject line (for POINTS constant etc.)
$eval = "\$subject = decodeEntities(\"".COMPILE_CODE(smartAddSlashes($subject))."\");";
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__);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):numRows=".SQL_NUMROWS($result_email)." \n";
+ $result_email = SQL_QUERY_ESC("SELECT `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($toEmail)), __FUNCTION__, __LINE__);
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):numRows=".SQL_NUMROWS($result_email)." ");
// Does the user exist?
if (SQL_NUMROWS($result_email)) {
@@ -397,35 +418,35 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
list($toEmail) = SQL_FETCHROW($result_email);
} else {
// Set webmaster
- $toEmail = constant('WEBMASTER');
+ $toEmail = getConfig('WEBMASTER');
}
// Free result
SQL_FREERESULT($result_email);
}
- } elseif ("$toEmail" == '0') {
+ } elseif ($toEmail == '0') {
// Is the webmaster!
- $toEmail = constant('WEBMASTER');
+ $toEmail = getConfig('WEBMASTER');
}
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):TO={$toEmail} \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):TO={$toEmail} ");
// Check for PHPMailer or debug-mode
if (!checkPhpMailerUsage()) {
// Not in PHPMailer-Mode
if (empty($mailHeader)) {
// Load email header template
- $mailHeader = LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader = LOAD_EMAIL_TEMPLATE('header');
} else {
// Append header
- $mailHeader .= LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader .= LOAD_EMAIL_TEMPLATE('header');
}
} elseif (isDebugModeEnabled()) {
if (empty($mailHeader)) {
// Load email header template
- $mailHeader = LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader = LOAD_EMAIL_TEMPLATE('header');
} else {
// Append header
- $mailHeader .= LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader .= LOAD_EMAIL_TEMPLATE('header');
}
}
@@ -441,11 +462,11 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
if (empty($HTML)) $HTML = 'N';
if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
- print("
+ OUTPUT_HTML("
".htmlentities(trim($mailHeader))."
-To : ".$toEmail."
-Subject : ".$subject."
-Message : ".$message."
+To : " . $toEmail."
+Subject : " . $subject."
+Message : " . $message."
\n");
} elseif (($HTML == 'Y') && (EXT_IS_ACTIVE('html_mail'))) {
// Send mail as HTML away
@@ -455,7 +476,7 @@ Message : ".$message."
sendRawEmail($toEmail, $subject, $message, $mailHeader);
} elseif ($HTML == 'N') {
// Problem found!
- sendRawEmail(constant('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
+ sendRawEmail(getConfig('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
}
}
@@ -467,7 +488,7 @@ function checkPhpMailerUsage() {
}
// Send out a raw email with PHPMailer class or legacy mail() command
-function sendRawEmail ($toEmail, $subject, $msg, $from) {
+function sendRawEmail ($toEmail, $subject, $message, $from) {
// Shall we use PHPMailer class or legacy mode?
if (checkPhpMailerUsage()) {
// Use PHPMailer class with SMTP enabled
@@ -476,7 +497,7 @@ function sendRawEmail ($toEmail, $subject, $msg, $from) {
// get new instance
$mail = new PHPMailer();
- $mail->PluginDir = sprintf("%sinc/phpmailer/", constant('PATH'));
+ $mail->PluginDir = sprintf("%sinc/phpmailer/", getConfig('PATH'));
$mail->IsSMTP();
$mail->SMTPAuth = true;
@@ -485,42 +506,42 @@ function sendRawEmail ($toEmail, $subject, $msg, $from) {
$mail->Username = getConfig('SMTP_USER');
$mail->Password = getConfig('SMTP_PASSWORD');
if (empty($from)) {
- $mail->From = constant('WEBMASTER');
+ $mail->From = getConfig('WEBMASTER');
} else {
$mail->From = $from;
}
- $mail->FromName = constant('MAIN_TITLE');
+ $mail->FromName = getConfig('MAIN_TITLE');
$mail->Subject = $subject;
- if ((EXT_IS_ACTIVE('html_mail')) && (strip_tags($msg) != $msg)) {
- $mail->Body = $msg;
+ if ((EXT_IS_ACTIVE('html_mail')) && (strip_tags($message) != $message)) {
+ $mail->Body = $message;
$mail->AltBody = 'Your mail program required HTML support to read this mail!';
$mail->WordWrap = 70;
$mail->IsHTML(true);
} else {
- $mail->Body = decodeEntities($msg);
+ $mail->Body = decodeEntities($message);
}
$mail->AddAddress($toEmail, '');
- $mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE'));
- $mail->AddCustomHeader('Errors-To:' . constant('WEBMASTER'));
- $mail->AddCustomHeader('X-Loop:' . constant('WEBMASTER'));
+ $mail->AddReplyTo(getConfig('WEBMASTER'), getConfig('MAIN_TITLE'));
+ $mail->AddCustomHeader('Errors-To:' . getConfig('WEBMASTER'));
+ $mail->AddCustomHeader('X-Loop:' . getConfig('WEBMASTER'));
$mail->Send();
} else {
// Use legacy mail() command
- @mail($toEmail, $subject, decodeEntities($msg), $from);
+ mail($toEmail, $subject, decodeEntities($message), $from);
}
}
// 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
@@ -577,7 +598,7 @@ function generateDateTime ($time, $mode = '0') {
// Translates Y/N to yes/no
function translateYesNo ($yn) {
// Default
- $translated = "??? (".$yn.')';
+ $translated = "??? (" . $yn.')';
switch ($yn) {
case 'Y': $translated = getMessage('YES'); break;
case 'N': $translated = getMessage('NO'); break;
@@ -696,7 +717,7 @@ function translateUserStatus ($status) {
// Generates an URL for the dereferer
function DEREFERER ($URL) {
// Don't de-refer our own links!
- if (substr($URL, 0, strlen(constant('URL'))) != constant('URL')) {
+ if (substr($URL, 0, strlen(getConfig('URL'))) != getConfig('URL')) {
// De-refer this link
$URL = 'modules.php?module=loader&url=' . encodeString(compileUriCode($URL));
} // END - if
@@ -708,7 +729,7 @@ function DEREFERER ($URL) {
// Generates an URL for the frametester
function FRAMETESTER ($URL) {
// Prepare frametester URL
- $frametesterUrl = sprintf("{!URL!}/modules.php?module=frametester&url=%s",
+ $frametesterUrl = sprintf("{?URL?}/modules.php?module=frametester&url=%s",
encodeString(compileUriCode($URL))
);
return $frametesterUrl;
@@ -727,12 +748,15 @@ function countSelection ($array) {
// Generate XHTML code for the CAPTCHA
function generateCaptchaCode ($code, $type, $DATA, $uid) {
- return ' ';
+ return ' ';
}
// 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);
@@ -745,7 +769,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
$HTTP_USER_AGENT = detectUserAgent();
// Default admin
- $ADMIN = constant('MAIN_TITLE');
+ $ADMIN = getConfig('MAIN_TITLE');
// Is the admin logged in?
if (IS_ADMIN()) {
@@ -757,7 +781,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
} // END - if
// Neutral email address is default
- $email = constant('WEBMASTER');
+ $email = getConfig('WEBMASTER');
// Expiration in a nice output format
// NOTE: Use $content[expiration] in your templates instead of $EXPIRATION
@@ -776,25 +800,25 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
} // END - if
// Load user's data
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):UID={$UID},template={$template},content[]=".gettype($content)." \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):UID={$UID},template={$template},content[]=".gettype($content)." ");
if (($UID > 0) && (is_array($content))) {
// If nickname extension is installed, fetch nickname as well
if (EXT_IS_ACTIVE('nickname')) {
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):NICKNAME! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):NICKNAME! ");
// 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)), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email`, `nickname` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
} else {
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):NO-NICK! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):NO-NICK! ");
/// 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)), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
}
// Fetch and merge data
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):content()=".count($content)." - PRE \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):content()=".count($content)." - PRE ");
$content = merge_array($content, SQL_FETCHARRAY($result));
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):content()=".count($content)." - AFTER \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):content()=".count($content)." - AFTER ");
// Free result
SQL_FREERESULT($result);
@@ -810,34 +834,34 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
$DATA['email'] = $email;
// Base directory
- $basePath = sprintf("%stemplates/%s/emails/", constant('PATH'), getLanguage());
+ $basePath = sprintf("%stemplates/%s/emails/", getConfig('PATH'), getLanguage());
// Check for admin/guest/member templates
if (strpos($template, 'admin_') > -1) {
// Admin template found
- $FQFN = $basePath.'admin/'.$template.'.tpl';
+ $FQFN = $basePath.'admin/' . $template.'.tpl';
} elseif (strpos($template, 'guest_') > -1) {
// Guest template found
- $FQFN = $basePath.'guest/'.$template.'.tpl';
+ $FQFN = $basePath.'guest/' . $template.'.tpl';
} elseif (strpos($template, 'member_') > -1) {
// Member template found
- $FQFN = $basePath.'member/'.$template.'.tpl';
+ $FQFN = $basePath.'member/' . $template.'.tpl';
} else {
// Test for extension
$test = substr($template, 0, strpos($template, '_'));
if (EXT_IS_ACTIVE($test)) {
// Set extra path to extension's name
- $FQFN = $basePath.$test.'/'.$template.'.tpl';
+ $FQFN = $basePath . $test.'/' . $template.'.tpl';
} else {
// No special filename
- $FQFN = $basePath.$template.'.tpl';
+ $FQFN = $basePath . $template.'.tpl';
}
}
// Does the special template exists?
if (!isFileReadable($FQFN)) {
// Reset to default template
- $FQFN = $basePath.$template.'.tpl';
+ $FQFN = $basePath . $template.'.tpl';
} // END - if
// Now does the final template exists?
@@ -852,7 +876,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
eval($tmpl_file);
} elseif (!empty($template)) {
// Template file not found!
- $newContent = "{--TEMPLATE_404--}: ".$template."
+ $newContent = "{--TEMPLATE_404--}: " . $template."
{--TEMPLATE_CONTENT--}
".print_r($content, true)."
{--TEMPLATE_DATA--}
@@ -869,7 +893,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
// Is there some content?
if (empty($newContent)) {
// Compiling failed
- $newContent = "Compiler error for template {$template}!\nUncompiled content:\n".$tmpl_file;
+ $newContent = "Compiler error for template {$template}!\nUncompiled content:\n" . $tmpl_file;
// Add last error if the required function exists
if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
} // END - if
@@ -901,7 +925,7 @@ function redirectToUrl ($URL) {
// Check if http(s):// is there
if ((substr($URL, 0, 7) != 'http://') && (substr($URL, 0, 8) != 'https://')) {
// Make all URLs full-qualified
- $URL = constant('URL') . '/' . $URL;
+ $URL = getConfig('URL') . '/' . $URL;
} // END - if
// Three different debug ways...
@@ -913,7 +937,7 @@ function redirectToUrl ($URL) {
$rel = ' rel="external"';
// Do we have internal or external URL?
- if (substr($URL, 0, strlen(constant('URL'))) == constant('URL')) {
+ if (substr($URL, 0, strlen(getConfig('URL'))) == getConfig('URL')) {
// Own (=internal) URL
$rel = '';
} // END - if
@@ -926,11 +950,11 @@ function redirectToUrl ($URL) {
clearOutputBuffer();
} // END - if
- // Secure the URL against bad things such als HTML insertions and so on...
- $URL = htmlentities(strip_tags($URL), ENT_QUOTES);
-
// Simple probe for bots/spiders from search engines
if ((strpos(detectUserAgent(), 'spider') !== false) || (strpos(detectUserAgent(), 'bot') !== false)) {
+ // Secure the URL against bad things such als HTML insertions and so on...
+ $URL = htmlentities(strip_tags($URL), ENT_QUOTES);
+
// Output new location link as anchor
OUTPUT_HTML('' . $URL . ' ');
} elseif (!headers_sent()) {
@@ -981,11 +1005,11 @@ function COMPILE_CODE ($code, $simple = false, $constants = true, $full = true)
if ($constants === true) {
// BEFORE 0.2.1 : Language and data constants
// WITH 0.2.1+ : Only language constants
- $code = str_replace('{--','".', str_replace('--}','."', $code));
+ $code = str_replace('{--', "\".getMessage('", str_replace('--}', "').\"", $code));
// BEFORE 0.2.1 : Not used
// WITH 0.2.1+ : Data constants
- $code = str_replace('{!','".', str_replace("!}", '."', $code));
+ $code = str_replace('{!', "\".constant('", str_replace("!}", "').\"", $code));
} // END - if
// Compile QUOT and other non-HTML codes
@@ -997,8 +1021,22 @@ function COMPILE_CODE ($code, $simple = false, $constants = true, $full = true)
// But shall I keep simple quotes for later use?
if ($simple) $code = str_replace("'", '{QUOT}', $code);
+ // Compile {?some_var?} to getConfig('some_var')
+ preg_match_all('/\{\?(([a-zA-Z0-9-_]+)*)\?\}/', $code, $matches);
+
+ // Some entries found?
+ if ((count($matches) > 0) && (count($matches[0]) > 0)) {
+ // Replace all matches
+ foreach ($matches[0] as $key => $match) {
+ // Replace it
+ //* DEBUG: */ if ($key == 0) { print ''; debug_print_backtrace(); print ' '; }
+ //* DEBUG: */ print $match.'='.$matches[1][$key].' ('.$key.') ';
+ $code = str_replace($match, getConfig($matches[1][$key]), $code);
+ } // END - foreach
+ } // END - if
+
// Find $content[bla][blub] entries
- preg_match_all('/\$(content|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
+ preg_match_all('/\$(content|GLOBALS|DATA)((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
// Are some matches found?
if ((count($matches) > 0) && (count($matches[0]) > 0)) {
@@ -1014,30 +1052,30 @@ function COMPILE_CODE ($code, $simple = false, $constants = true, $full = true)
$test = substr($found, 0, strlen($match));
// Does this entry exist?
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):found={$found},match={$match},set={$set} \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):found={$found},match={$match},set={$set} ");
if ($test == $match) {
// Match found!
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):fuzzyFound! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):fuzzyFound! ");
$fuzzyFound = true;
break;
} // END - if
} // END - foreach
// Skip this entry?
- if ($fuzzyFound) continue;
+ if ($fuzzyFound === true) continue;
// Take all string elements
- if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
+ if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_" . $matches[4][$key]]))) {
// Replace it in the code
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):key={$key},match={$match} \n";
- $newMatch = str_replace("[".$matches[4][$key]."]", "['".$matches[4][$key]."']", $match);
- $code = str_replace($match, "\".".$newMatch.".\"", $code);
- $matchesFound[$key."_".$matches[4][$key]] = 1;
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):key={$key},match={$match} ");
+ $newMatch = str_replace('[', "['", str_replace(']', "']", $match));
+ $code = str_replace($match, "\"." . $newMatch.".\"", $code);
+ $matchesFound[$key . '_' . $matches[4][$key]] = 1;
$matchesFound[$match] = 1;
} elseif (!isset($matchesFound[$match])) {
// Not yet replaced!
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):match={$match} \n";
- $code = str_replace($match, "\".".$match.".\"", $code);
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):match={$match} ");
+ $code = str_replace($match, "\"." . $match.".\"", $code);
$matchesFound[$match] = 1;
}
} // END - foreach
@@ -1104,30 +1142,30 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
if ($type == 'yn') {
// This is a yes/no selection only!
- if ($id > 0) $prefix .= "[".$id."]";
- $OUT .= " \n";
+ if ($id > 0) $prefix .= "[" . $id."]";
+ $OUT .= " \n";
} else {
// Begin with regular selection box here
if (!empty($prefix)) $prefix .= "_";
$type2 = $type;
- if ($id > 0) $type2 .= "[".$id."]";
- $OUT .= " \n";
+ if ($id > 0) $type2 .= "[" . $id."]";
+ $OUT .= " \n";
}
switch ($type) {
case "day": // Day
for ($idx = 1; $idx < 32; $idx++) {
- $OUT .= "\n";
+ $OUT .= ">" . $idx." \n";
} // END - for
break;
case "month": // Month
foreach ($GLOBALS['month_descr'] as $month => $descr) {
- $OUT .= "\n";
+ $OUT .= ">" . $descr." \n";
} // END - for
break;
@@ -1150,19 +1188,19 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
// Check if the default value is larger than minimum and bigger than actual year
if (($default > $minYear) && ($default >= $year)) {
for ($idx = $year; $idx < ($year + 11); $idx++) {
- $OUT .= "\n";
+ $OUT .= ">" . $idx." \n";
} // END - for
} elseif ($default == -1) {
// Current year minus 1
for ($idx = $startYear; $idx <= ($year + 1); $idx++)
{
- $OUT .= "".$idx." \n";
+ $OUT .= "" . $idx." \n";
}
} else {
// Get current year and subtract the configured minimum age
- $OUT .= "<".$minYear." \n";
+ $OUT .= "<" . $minYear." \n";
// Calculate earliest year depending on extension version
if (GET_EXT_VERSION('other') >= '0.2.1') {
// Use configured minimum age
@@ -1174,9 +1212,9 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
// Construct year selection list
for ($idx = $minYear; $idx <= $year; $idx++) {
- $OUT .= "\n";
+ $OUT .= ">" . $idx." \n";
} // END - for
}
break;
@@ -1184,19 +1222,19 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
case "sec":
case "min":
for ($idx = 0; $idx < 60; $idx+=5) {
- if (strlen($idx) == 1) $idx = '0'.$idx;
- $OUT .= "\n";
+ $OUT .= ">" . $idx." \n";
} // END - for
break;
case "hour":
for ($idx = 0; $idx < 24; $idx++) {
- if (strlen($idx) == 1) $idx = '0'.$idx;
- $OUT .= "\n";
+ $OUT .= ">" . $idx." \n";
} // END - for
break;
@@ -1216,46 +1254,42 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
// Deprecated : $length
// Optional : $DATA
//
-function generateRandomCodde ($length, $code, $uid, $DATA = '') {
- // Fix missing _MAX constant
- // @TODO Rewrite this unnice code
- if (!defined('_MAX')) define('_MAX', 15235);
-
+function generateRandomCode ($length, $code, $uid, $DATA = '') {
// Build server string
- $server = $_SERVER['PHP_SELF'].getConfig('ENCRYPT_SEPERATOR').detectUserAgent().getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_SOFTWARE').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr().":'.':".filemtime(constant('PATH').'inc/databases.php');
+ $server = $_SERVER['PHP_SELF'].getConfig('ENCRYPT_SEPERATOR').detectUserAgent().getConfig('ENCRYPT_SEPERATOR').getenv('SERVER_SOFTWARE').getConfig('ENCRYPT_SEPERATOR').detectRemoteAddr().":'.':".filemtime(getConfig('PATH').'inc/databases.php');
// Build key string
$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
- $data = $code.getConfig('ENCRYPT_SEPERATOR').$uid.getConfig('ENCRYPT_SEPERATOR').$DATA;
+ $data = $code.getConfig('ENCRYPT_SEPERATOR') . $uid.getConfig('ENCRYPT_SEPERATOR') . $DATA;
// Add more additional data
if (isSessionVariableSet('u_hash')) $data .= getConfig('ENCRYPT_SEPERATOR').getSession('u_hash');
if (isUserIdSet()) $data .= getConfig('ENCRYPT_SEPERATOR').getUserId();
if (isSessionVariableSet('mxchange_theme')) $data .= getConfig('ENCRYPT_SEPERATOR').getSession('mxchange_theme');
if (isSessionVariableSet('mx_lang')) $data .= getConfig('ENCRYPT_SEPERATOR').getLanguage();
- if (isset($GLOBALS['refid'])) $data .= getConfig('ENCRYPT_SEPERATOR').$GLOBALS['refid'];
+ if (isset($GLOBALS['refid'])) $data .= getConfig('ENCRYPT_SEPERATOR') . $GLOBALS['refid'];
// Calculate number for generating the code
$a = $code + getConfig('_ADD') - 1;
if (isConfigEntrySet('master_hash')) {
// Generate hash with master salt from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % getConfig('_PRIME')).getConfig('ENCRYPT_SEPERATOR').$server.getConfig('ENCRYPT_SEPERATOR').$keys.getConfig('ENCRYPT_SEPERATOR').$data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').$a, getConfig('master_salt'));
+ $saltedHash = generateHash(($a % getConfig('_PRIME')).getConfig('ENCRYPT_SEPERATOR') . $server.getConfig('ENCRYPT_SEPERATOR') . $keys.getConfig('ENCRYPT_SEPERATOR') . $data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR') . $a, getConfig('master_salt'));
// Create number from hash
- $rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(constant('_MAX') - $a + sqrt(getConfig('_ADD'))) / pi();
+ $rcode = hexdec(substr($saltedHash, strlen(getConfig('master_salt')), 9)) / abs(getConfig('_MAX') - $a + sqrt(getConfig('_ADD'))) / pi();
} else {
// Generate hash with "hash of site key" from modula of number with the prime number and other data
- $saltedHash = generateHash(($a % getConfig('_PRIME')).getConfig('ENCRYPT_SEPERATOR').$server.getConfig('ENCRYPT_SEPERATOR').$keys.getConfig('ENCRYPT_SEPERATOR').$data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').$a, substr(sha1(getConfig('SITE_KEY')), 0, 8));
+ $saltedHash = generateHash(($a % getConfig('_PRIME')).getConfig('ENCRYPT_SEPERATOR') . $server.getConfig('ENCRYPT_SEPERATOR') . $keys.getConfig('ENCRYPT_SEPERATOR') . $data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR') . $a, substr(sha1(getConfig('SITE_KEY')), 0, 8));
// Create number from hash
- $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(constant('_MAX') - $a + sqrt(getConfig('_ADD'))) / pi();
+ $rcode = hexdec(substr($saltedHash, 8, 9)) / abs(getConfig('_MAX') - $a + sqrt(getConfig('_ADD'))) / pi();
}
// At least 10 numbers shall be secure enought!
@@ -1280,9 +1314,9 @@ function bigintval ($num, $castValue = true) {
// 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
@@ -1296,11 +1330,11 @@ function GENERATE_IMAGE ($img_code, $headerSent=true) {
return;
} elseif (!$headerSent) {
// Return in an HTML code code
- return " \n";
+ return " \n";
}
// Load image
- $img = sprintf("%s/theme/%s/images/code_bg.%s", constant('PATH'), getCurrentTheme(), getConfig('img_type'));
+ $img = sprintf("%s/theme/%s/images/code_bg.%s", getConfig('PATH'), getCurrentTheme(), getConfig('img_type'));
if (isFileReadable($img)) {
// Switch image type
switch (getConfig('img_type'))
@@ -1343,7 +1377,7 @@ function GENERATE_IMAGE ($img_code, $headerSent=true) {
function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $return_array=false) {
// Calculate 2-seconds timestamp
$stamp = round($timestamp);
- //* DEBUG: */ print("*".$stamp.'/'.$timestamp."* ");
+ //* DEBUG: */ print("*" . $stamp.'/' . $timestamp."* ");
// Do we have a leap year?
$SWITCH = 0;
@@ -1356,25 +1390,25 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
// First of all years...
$Y = abs(floor($timestamp / (31536000 + $SWITCH)));
- //* DEBUG: */ print("Y={$Y} \n");
+ //* DEBUG: */ print("Y={$Y} ");
// Next months...
$M = abs(floor($timestamp / 2628000 - $Y * 12));
- //* DEBUG: */ print("M={$M} \n");
+ //* DEBUG: */ print("M={$M} ");
// Next weeks
$W = abs(floor($timestamp / 604800 - $Y * ((365 + $SWITCH / getConfig('one_day')) / 7) - ($M / 12 * (365 + $SWITCH / getConfig('one_day')) / 7)));
- //* DEBUG: */ print("W={$W} \n");
+ //* DEBUG: */ print("W={$W} ");
// Next days...
$D = abs(floor($timestamp / 86400 - $Y * (365 + $SWITCH / getConfig('one_day')) - ($M / 12 * (365 + $SWITCH / getConfig('one_day'))) - $W * 7));
- //* DEBUG: */ print("D={$D} \n");
+ //* DEBUG: */ print("D={$D} ");
// Next hours...
$h = abs(floor($timestamp / 3600 - $Y * (365 + $SWITCH / getConfig('one_day')) * 24 - ($M / 12 * (365 + $SWITCH / getConfig('one_day')) * 24) - $W * 7 * 24 - $D * 24));
- //* DEBUG: */ print("h={$h} \n");
+ //* DEBUG: */ print("h={$h} ");
// Next minutes..
$m = abs(floor($timestamp / 60 - $Y * (365 + $SWITCH / getConfig('one_day')) * 24 * 60 - ($M / 12 * (365 + $SWITCH / getConfig('one_day')) * 24 * 60) - $W * 7 * 24 * 60 - $D * 24 * 60 - $h * 60));
- //* DEBUG: */ print("m={$m} \n");
+ //* DEBUG: */ print("m={$m} ");
// And at last seconds...
$s = abs(floor($timestamp - $Y * (365 + $SWITCH / getConfig('one_day')) * 24 * 3600 - ($M / 12 * (365 + $SWITCH / getConfig('one_day')) * 24 * 3600) - $W * 7 * 24 * 3600 - $D * 24 * 3600 - $h * 3600 - $m * 60));
- //* DEBUG: */ print("s={$s} \n");
+ //* DEBUG: */ print("s={$s} ");
// Is seconds zero and time is < 60 seconds?
if (($s == 0) && ($timestamp < 60)) {
@@ -1398,7 +1432,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
);
} else {
// Generate table
- $OUT = "\n";
+ $OUT = "
\n";
$OUT .= "
\n";
$OUT .= "\n";
@@ -1406,7 +1440,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
$OUT .= " {--_YEARS--}
\n";
}
- if (ereg("M", $display) || (empty($display))) {
+ if (ereg('M', $display) || (empty($display))) {
$OUT .= " {--_MONTHS--}
\n";
}
@@ -1435,94 +1469,94 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
if (ereg('Y', $display) || (empty($display))) {
// Generate year selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 10; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
- if (ereg("M", $display) || (empty($display))) {
+ if (ereg('M', $display) || (empty($display))) {
// Generate month selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 11; $idx++)
{
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
if (ereg("W", $display) || (empty($display))) {
// Generate week selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 4; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
if (ereg("D", $display) || (empty($display))) {
// Generate day selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 31; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
if (ereg("h", $display) || (empty($display))) {
// Generate hour selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 23; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
if (ereg('m', $display) || (empty($display))) {
// Generate minute selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 59; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
if (ereg("s", $display) || (empty($display))) {
// Generate second selection
- $OUT .= " \n";
+ $OUT .= " \n";
for ($idx = 0; $idx <= 59; $idx++) {
- $OUT .= " \n";
+ $OUT .= ">" . $idx." \n";
}
$OUT .= " \n";
} else {
- $OUT .= " \n";
+ $OUT .= " \n";
}
$OUT .= " \n";
$OUT .= "
\n";
@@ -1568,7 +1602,7 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
$template = trim($template);
// Load email template
- $msg = LOAD_EMAIL_TEMPLATE($template, $content, $UID);
+ $message = LOAD_EMAIL_TEMPLATE($template, $content, $UID);
// 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",
@@ -1596,7 +1630,7 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
if ($aid == '-1') {
if (EXT_IS_ACTIVE('events')) {
// Add line to user events
- EVENTS_ADD_LINE($subj, $msg, $UID);
+ EVENTS_ADD_LINE($subj, $message, $UID);
} else {
// Log error for debug
DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension 'events' missing: tpl=%s,subj=%s,UID=%s",
@@ -1618,7 +1652,7 @@ function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
// Load email addresses and send away
while ($content = SQL_FETCHARRAY($result)) {
- sendEmail($content['email'], $subj, $msg);
+ sendEmail($content['email'], $subj, $message);
} // END - while
// Free memory
@@ -1657,7 +1691,7 @@ function ADD_EMAIL_NAV ($PAGES, $offset, $show_form, $colspan, $return=false) {
$SEP = ''; $TOP = '';
if (!$show_form) {
$TOP = " top2";
- $SEP = "
";
+ $SEP = "
";
}
$NAV = '';
@@ -1668,7 +1702,7 @@ function ADD_EMAIL_NAV ($PAGES, $offset, $show_form, $colspan, $return=false) {
$NAV .= "
-";
} else {
// Open anchor tag and add base URL
- $NAV .= " 0)) $NAV .= "&uid=".bigintval(REQUEST_GET('uid'));
@@ -1712,10 +1746,10 @@ function ADD_EMAIL_NAV ($PAGES, $offset, $show_form, $colspan, $return=false) {
// Extract host from script name
function extractHostnameFromUrl (&$script) {
// Use default SERVER_URL by default... ;) So?
- $url = constant('SERVER_URL');
+ $url = getConfig('SERVER_URL');
// Is this URL valid?
- if (substr($script, 0, 7) == "http://") {
+ if (substr($script, 0, 7) == 'http://') {
// Use the hostname from script URL as new hostname
$url = substr($script, 7);
$extract = explode('/', $url);
@@ -1724,12 +1758,12 @@ function extractHostnameFromUrl (&$script) {
} // END - if
// Extract host name
- $host = str_replace("http://", '', $url);
+ $host = str_replace('http://', '', $url);
if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/'));
// Generate relative URL
- //* DEBUG: */ print("SCRIPT=".$script." \n");
- if (substr(strtolower($script), 0, 7) == "http://") {
+ //* DEBUG: */ print("SCRIPT=" . $script." ");
+ if (substr(strtolower($script), 0, 7) == 'http://') {
// But only if http:// is in front!
$script = substr($script, (strlen($url) + 7));
} elseif (substr(strtolower($script), 0, 8) == "https://") {
@@ -1737,7 +1771,7 @@ function extractHostnameFromUrl (&$script) {
$script = substr($script, (strlen($url) + 8));
}
- //* DEBUG: */ print("SCRIPT=".$script." \n");
+ //* DEBUG: */ print("SCRIPT=" . $script." ");
if (substr($script, 0, 1) == '/') $script = substr($script, 1);
// Return host name
@@ -1755,12 +1789,8 @@ function sendGetRequest ($script) {
// Generate GET request header
$request = "GET /" . trim($script) . " HTTP/1.1" . getConfig('HTTP_EOL');
$request .= "Host: " . $host . getConfig('HTTP_EOL');
- $request .= "Referer: " . constant('URL') . "/admin.php" . getConfig('HTTP_EOL');
- if (defined('FULL_VERSION')) {
- $request .= "User-Agent: " . constant('TITLE') . '/' . constant('FULL_VERSION') . getConfig('HTTP_EOL');
- } else {
- $request .= "User-Agent: " . constant('TITLE') . "/?.?.?" . getConfig('HTTP_EOL');
- }
+ $request .= "Referer: " . getConfig('URL') . "/admin.php" . getConfig('HTTP_EOL');
+ $request .= "User-Agent: " . getConfig('TITLE') . '/' . getConfig('FULL_VERSION') . getConfig('HTTP_EOL');
$request .= "Content-Type: text/plain" . getConfig('HTTP_EOL');
$request .= "Cache-Control: no-cache" . getConfig('HTTP_EOL');
$request .= "Connection: Close" . getConfig('HTTP_EOL') . getConfig('HTTP_EOL');
@@ -1793,8 +1823,8 @@ function sendPostRequest ($script, $postData) {
// Generate POST request header
$request = "POST /" . trim($script) . " HTTP/1.1" . getConfig('HTTP_EOL');
$request .= "Host: " . $host . getConfig('HTTP_EOL');
- $request .= "Referer: " . constant('URL') . "/admin.php" . getConfig('HTTP_EOL');
- $request .= "User-Agent: " . constant('TITLE') . '/' . constant('FULL_VERSION') . getConfig('HTTP_EOL');
+ $request .= "Referer: " . getConfig('URL') . "/admin.php" . getConfig('HTTP_EOL');
+ $request .= "User-Agent: " . getConfig('TITLE') . '/' . getConfig('FULL_VERSION') . getConfig('HTTP_EOL');
$request .= "Content-type: application/x-www-form-urlencoded" . getConfig('HTTP_EOL');
$request .= "Content-length: " . strlen($data) . getConfig('HTTP_EOL');
$request .= "Cache-Control: no-cache" . getConfig('HTTP_EOL');
@@ -1826,10 +1856,12 @@ function sendRawRequest ($host, $request) {
} // END - if
// Open connection
- //* DEBUG: */ die("SCRIPT=".$script." \n");
- if ($useProxy) {
- $fp = @fsockopen(COMPILE_CODE(getConfig('proxy_host')), getConfig('proxy_port'), $errno, $errdesc, 30);
+ //* DEBUG: */ die("SCRIPT=" . $script." ");
+ if ($useProxy === true) {
+ // Connect to host through proxy connection
+ $fp = @fsockopen(COMPILE_CODE(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
} else {
+ // Connect to host directly
$fp = @fsockopen($host, 80, $errno, $errdesc, 30);
}
@@ -1840,7 +1872,7 @@ function sendRawRequest ($host, $request) {
} // END - if
// Do we use proxy?
- if ($useProxy) {
+ if ($useProxy === true) {
// Generate CONNECT request header
$proxyTunnel = "CONNECT " . $host . ":80 HTTP/1.1" . getConfig('HTTP_EOL');
$proxyTunnel .= "Host: " . $host . getConfig('HTTP_EOL');
@@ -1848,13 +1880,13 @@ function sendRawRequest ($host, $request) {
// Use login data to proxy? (username at least!)
if (getConfig('proxy_username') != '') {
// Add it as well
- $encodedAuth = base64_encode(COMPILE_CODE(getConfig('proxy_username')).getConfig('ENCRYPT_SEPERATOR').COMPILE_CODE(getConfig('proxy_password')));
+ $encodedAuth = base64_encode(COMPILE_CODE(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . COMPILE_CODE(getConfig('proxy_password')));
$proxyTunnel .= "Proxy-Authorization: Basic " . $encodedAuth . getConfig('HTTP_EOL');
} // END - if
// Add last new-line
$proxyTunnel .= getConfig('HTTP_EOL');
- //* DEBUG: */ print("proxyTunnel= ".$proxyTunnel." ");
+ //* DEBUG: */ print("proxyTunnel= " . $proxyTunnel." ");
// Write request
fputs($fp, $proxyTunnel);
@@ -1904,7 +1936,7 @@ function sendRawRequest ($host, $request) {
//* DEBUG: */ print("Response: ".print_r($response, true)." ");
// Proxy agent found?
- if ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy)) {
+ if ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy === true)) {
// Proxy header detected, so remove two lines
array_shift($response);
array_shift($response);
@@ -1935,7 +1967,6 @@ function isEmailValid ($email) {
$regex = '@^' . $first . '\@' . $domain . '$@iU';
// Return check result
- // @NOTE altered the regex-pattern and added modificator i (match both upper and lower case letters) and U (PCRE_UNGREEDY) to work with preg_match the same way as eregi
return preg_match($regex, $email);
}
@@ -1943,16 +1974,16 @@ function isEmailValid ($email) {
function isUrlValid ($URL, $compile=true) {
// Trim URL a little
$URL = trim(urldecode($URL));
- //* DEBUG: */ echo $URL." ";
+ //* DEBUG: */ OUTPUT_HTML($URL." ");
// Compile some chars out...
- if ($compile) $URL = compileUriCode($URL, false, false, false);
- //* DEBUG: */ echo $URL." ";
+ if ($compile === true) $URL = compileUriCode($URL, false, false, false);
+ //* DEBUG: */ OUTPUT_HTML($URL." ");
// Check for the extension filter
if (EXT_IS_ACTIVE('filter')) {
// Use the extension's filter set
- return FILTER_isUrlValid($URL, false);
+ return FILTER_VALIDATE_URL($URL, false);
} // END - if
// If not installed, perform a simple test. Just make it sure there is always a http:// or
@@ -1969,8 +2000,8 @@ function generateMemberAdminActionLinks ($uid, $status = '') {
$eval = "\$OUT = \"[ ";
foreach ($TARGETS as $tar) {
- $eval .= " \n";
+ $eval .= " ");
if (($tar == "lock_user") && ($status == 'LOCKED')) {
// Locked accounts shall be unlocked
$eval .= "UNLOCK_USER";
@@ -1998,20 +2029,20 @@ function generateMemberAdminActionLinks ($uid, $status = '') {
}
// 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 = generateUserEmailLink($email, 'admin');
} 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 = generateSponsorEmailLink($email, 'sponsor_data');
}
// Shall I close the link when there is no admin?
@@ -2041,7 +2072,7 @@ function generateHash ($plainText, $salt = '') {
$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();
@@ -2050,24 +2081,24 @@ function generateHash ($plainText, $salt = '') {
$a = time() + getConfig('_ADD') - 1;
// Generate SHA1 sum from modula of number and the prime number
- $sha1 = sha1(($a % getConfig('_PRIME')).$server.getConfig('ENCRYPT_SEPERATOR').$keys.getConfig('ENCRYPT_SEPERATOR').$data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR').$a);
- //* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).") ";
+ $sha1 = sha1(($a % getConfig('_PRIME')) . $server.getConfig('ENCRYPT_SEPERATOR') . $keys.getConfig('ENCRYPT_SEPERATOR') . $data.getConfig('ENCRYPT_SEPERATOR').getConfig('DATE_KEY').getConfig('ENCRYPT_SEPERATOR') . $a);
+ //* DEBUG: */ OUTPUT_HTML("SHA1=" . $sha1." (".strlen($sha1).") ");
$sha1 = scrambleString($sha1);
- //* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).") ";
+ //* DEBUG: */ OUTPUT_HTML("Scrambled=" . $sha1." (".strlen($sha1).") ");
//* DEBUG: */ $sha1b = descrambleString($sha1);
- //* DEBUG: */ echo "Descrambled=".$sha1b." (".strlen($sha1b).") ";
+ //* DEBUG: */ OUTPUT_HTML("Descrambled=" . $sha1b." (".strlen($sha1b).") ");
// Generate the password salt string
$salt = substr($sha1, 0, getConfig('salt_length'));
- //* DEBUG: */ echo $salt." (".strlen($salt).") ";
+ //* DEBUG: */ OUTPUT_HTML($salt." (".strlen($salt).") ");
} else {
// Use given salt
$salt = substr($salt, 0, getConfig('salt_length'));
- //* DEBUG: */ echo "GIVEN={$salt} \n";
+ //* DEBUG: */ OUTPUT_HTML("GIVEN={$salt} ");
}
// Return hash
- return $salt.sha1($salt.$plainText);
+ return $salt.sha1($salt . $plainText);
}
// Scramble a string
@@ -2088,7 +2119,7 @@ function scrambleString($str) {
}
// Scramble string here
- //* DEBUG: */ echo "***Original=".$str."*** ";
+ //* DEBUG: */ OUTPUT_HTML("***Original=" . $str."*** ");
for ($idx = 0; $idx < strlen($str); $idx++) {
// Get char on scrambled position
$char = substr($str, $scrambleNums[$idx], 1);
@@ -2098,7 +2129,7 @@ function scrambleString($str) {
} // END - for
// Return scrambled string
- //* DEBUG: */ echo "***Scrambled=".$scrambled."*** ";
+ //* DEBUG: */ OUTPUT_HTML("***Scrambled=" . $scrambled."*** ");
return $scrambled;
}
@@ -2114,15 +2145,15 @@ function descrambleString($str) {
if (count($scrambleNums) != 40) return $str;
// Begin descrambling
- $orig = str_repeat(" ", 40);
- //* DEBUG: */ echo "+++Scrambled=".$str."+++ ";
+ $orig = str_repeat(' ', 40);
+ //* DEBUG: */ OUTPUT_HTML("+++Scrambled=" . $str."+++ ");
for ($idx = 0; $idx < 40; $idx++) {
$char = substr($str, $idx, 1);
$orig = substr_replace($orig, $char, $scrambleNums[$idx], 1);
} // END - for
// Return scrambled string
- //* DEBUG: */ echo "+++Original=".$orig."+++ ";
+ //* DEBUG: */ OUTPUT_HTML("+++Original=" . $orig."+++ ");
return $orig;
}
@@ -2169,20 +2200,20 @@ function generatePassString ($passHash) {
$mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
}
$mod = substr(round($mod), 0, 4);
- $mod = str_repeat('0', 4-strlen($mod)).$mod;
- //* DEBUG: */ echo "*".$start.'='.$mod."* ";
+ $mod = str_repeat('0', 4-strlen($mod)) . $mod;
+ //* DEBUG: */ OUTPUT_HTML("*" . $start.'=' . $mod."* ");
$start += 4;
$newHash .= $mod;
} // END - for
- //* DEBUG: */ print($passHash." ".$newHash." (".strlen($newHash).')');
+ //* DEBUG: */ print($passHash." " . $newHash." (".strlen($newHash).')');
$ret = generateHash($newHash, getConfig('master_salt'));
- //* DEBUG: */ print($ret." \n");
+ //* DEBUG: */ print($ret." ");
} else {
// Hash it simple
- //* DEBUG: */ echo "--".$passHash."-- \n";
+ //* DEBUG: */ OUTPUT_HTML("--" . $passHash."-- ");
$ret = md5($passHash);
- //* DEBUG: */ echo "++".$ret."++ \n";
+ //* DEBUG: */ OUTPUT_HTML("++" . $ret."++ ");
}
// Return result
@@ -2204,7 +2235,7 @@ function fixDeletedCookies ($cookies) {
}
// Output error messages in a fasioned way and die...
-function app_die ($F, $L, $msg) {
+function app_die ($F, $L, $message) {
// Check if Script is already dieing and not let it kill itself another 1000 times
if (!isset($GLOBALS['app_died'])) {
// Make sure, that the script realy realy diese here and now
@@ -2213,17 +2244,20 @@ function app_die ($F, $L, $msg) {
// Load header
loadIncludeOnce('inc/header.php');
- // Prepare message for output
- $msg = sprintf(getMessage('MXCHANGE_HAS_DIED'), basename($F), $L, $msg);
+ // 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, $msg);
+ LOAD_TEMPLATE('admin_settings_saved', false, $message);
// Load footer
loadIncludeOnce('inc/footer.php');
} else {
// Script tried to kill itself twice
- debug_report_bug('Script wanted to kill itself more than once! Raw message=' . $msg . ', file/function=' . $F . ', line=' . $L);
+ debug_report_bug('Script wanted to kill itself more than once! Raw message=' . $message . ', file/function=' . $F . ', line=' . $L);
}
}
@@ -2265,14 +2299,14 @@ function isBooleanConstantAndTrue ($constName) { // : Boolean
// In cache?
if (isset($GLOBALS['cache_array']['const'][$constName])) {
// Use cache
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ): ".$constName."-CACHE! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ): " . $constName."-CACHE! ");
$res = ($GLOBALS['cache_array']['const'][$constName] === true);
} else {
// Check constant
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ): ".$constName."-RESOLVE! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ): " . $constName."-RESOLVE! ");
if (defined($constName)) {
// Found!
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ): ".$constName."-FOUND! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ): " . $constName."-FOUND! ");
$res = (constant($constName) === true);
} // END - if
@@ -2312,15 +2346,15 @@ function getCurrentTheme() {
// 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'));
+ $theme = sprintf("%stheme/%s/theme.php", getConfig('PATH'), REQUEST_GET('theme'));
// Installation mode active
if ((REQUEST_ISSET_GET('theme')) && (isFileReadable($theme))) {
// Set cookie from URL data
setSession('mxchange_theme', REQUEST_GET('theme'));
- } elseif (isFileReadable(sprintf("%stheme/%s/theme.php", constant('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) {
+ } elseif (isFileReadable(sprintf("%stheme/%s/theme.php", getConfig('PATH'), SQL_ESCAPE(REQUEST_POST('theme'))))) {
// Set cookie from posted data
setSession('mxchange_theme', SQL_ESCAPE(REQUEST_POST('theme')));
}
@@ -2381,6 +2415,12 @@ function getThemeId ($name) {
// 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');
@@ -2403,33 +2443,33 @@ function generateErrorCodeFromUserStatus ($status) {
// Function to search for the last modifified file
function searchDirsRecursive ($dir, &$last_changed) {
// Get dir as array
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):dir=".$dir." \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):dir=" . $dir." ");
// Does it match what we are looking for? (We skip a lot files already!)
// RegexPattern to exclude ., .., .revision, .svn, debug.log or .cache in the filenames
- $excludePattern = '@(\.|\.\.|\.revision|\.svn|debug\.log|\.cache|config\.php)$@';
- $ds = getArrayFromDirectory($dir, '', true, false, $excludePattern);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):ds[]=".count($ds)." \n";
+ $excludePattern = '@(\.revision|debug\.log|\.cache|config\.php)$@';
+ $ds = getArrayFromDirectory($dir, '', true, false, array(), '.php', $excludePattern);
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):ds[]=".count($ds)." ");
// Walk through all entries
foreach ($ds as $d) {
// Generate proper FQFN
- $FQFN = str_replace("//", '/', constant('PATH') . $dir. '/'. $d);
+ $FQFN = str_replace('//', '/', getConfig('PATH') . $dir. '/'. $d);
// Is it a file and readable?
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):FQFN={$FQFN} \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):FQFN={$FQFN} ");
if (isDirectory($FQFN)) {
// $FQFN is a directory so also crawl into this directory
$newDir = $d;
if (!empty($dir)) $newDir = $dir . '/'. $d;
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):DESCENT: ".$newDir." \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):DESCENT: " . $newDir." ");
searchDirsRecursive($newDir, $last_changed);
} elseif (isFileReadable($FQFN)) {
// $FQFN is a filename and no directory
$time = filemtime($FQFN);
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):File: ".$d." found. (".($last_changed['time'] - $time).") \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):File: " . $d." found. (".($last_changed['time'] - $time).") ");
if ($last_changed['time'] < $time) {
// This file is newer as the file before
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ) - NEWER! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ) - NEWER! ");
$last_changed['path_name'] = $FQFN;
$last_changed['time'] = $time;
} // END - if
@@ -2444,34 +2484,49 @@ function getActualVersion ($type = 'Revision') {
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 ?)
// FQFN of revision file
- $FQFN = sprintf("%sinc/cache/.revision", constant('PATH'));
+ $FQFN = sprintf("%sinc/cache/.revision", getConfig('PATH'));
// 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
@@ -2517,13 +2572,19 @@ function getSearchFor () {
// @TODO Please describe this function
function getArrayFromActualVersion () {
// Init variables
- $next_dir = ''; // Directory to start with search
+ $next_dir = '';
+
+ // Directory to start with search
$last_changed = array(
'path_name' => '',
'time' => 0
);
- $akt_vers = array(); // Init return array
- $res = 0; // Init value for counting the founded keywords
+
+ // Init return array
+ $akt_vers = array();
+
+ // Init value for counting the founded keywords
+ $res = 0;
// Searches all Files and there date of the last modifikation and puts the newest File in $last_changed.
searchDirsRecursive($next_dir, $last_changed); // @TODO small change to API to $last_changed = searchDirsRecursive($next_dir, $time);
@@ -2537,7 +2598,7 @@ function getArrayFromActualVersion () {
// This foreach loops the $searchFor-Tags (array('Revision', 'Date', 'Tag', 'Author') --> could easaly extended in the future)
foreach ($searchFor as $search) {
// Searches for "$search-tag:VALUE$" or "$search-tag::VALUE$"(the stylish keywordversion ;-)) in the lates modified file
- $res += preg_match('@\$'.$search.'(:|::) (.*) \$@U', $last_file, $t);
+ $res += preg_match('@\$' . $search.'(:|::) (.*) \$@U', $last_file, $t);
// This trimms the search-result and puts it in the $akt_vers-return array
if (isset($t[2])) $akt_vers[$search] = trim($t[2]);
} // END - foreach
@@ -2588,7 +2649,7 @@ function debug_get_printable_backtrace () {
if (!isset($trace['file'])) $trace['file'] = __FUNCTION__;
if (!isset($trace['line'])) $trace['line'] = __LINE__;
if (!isset($trace['args'])) $trace['args'] = array();
- $backtrace .= "".basename($trace['file'])." :".$trace['line'].", ".$trace['function'].'('.count($trace['args']).") \n";
+ $backtrace .= "".basename($trace['file'])." :" . $trace['line'].", " . $trace['function'].'('.count($trace['args']).") \n";
} // END - foreach
// Close it
@@ -2606,7 +2667,7 @@ function debug_report_bug ($message = '') {
if (!empty($message)) {
// Use and log it
$debug = sprintf("Note: %s \n",
- $message
+ $message
);
// @TODO Add a little more infos here
@@ -2614,9 +2675,9 @@ function debug_report_bug ($message = '') {
} // END - if
// Add output
- $debug .= "Please report this bug at bugs.mxchange.org and include the logfile from inc/cache/debug.log in your report (you cannot attach files!):";
+ $debug .= "Please report this bug at bugs.mxchange.org and include the logfile from inc/cache/debug.log in your report (you can now attach files):";
$debug .= debug_get_printable_backtrace();
- $debug .= " \nRequest-URI: ".$_SERVER['REQUEST_URI']." \n";
+ $debug .= " \nRequest-URI: " . $_SERVER['REQUEST_URI']." \n";
$debug .= "Thank you for finding bugs.";
// And abort here
@@ -2626,55 +2687,56 @@ function debug_report_bug ($message = '') {
// 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
function convertCodeToMessage ($code) {
- $msg = '';
+ $message = '';
switch ($code) {
- case getCode('LOGOUT_DONE') : $msg = getMessage('LOGOUT_DONE'); break;
- case getCode('LOGOUT_FAILED') : $msg = "{--LOGOUT_FAILED--} "; break;
- case getCode('DATA_INVALID') : $msg = getMessage('MAIL_DATA_INVALID'); break;
- case getCode('POSSIBLE_INVALID') : $msg = getMessage('MAIL_POSSIBLE_INVALID'); break;
- case getCode('ACCOUNT_LOCKED') : $msg = getMessage('MEMBER_ACCOUNT_LOCKED_UNC'); break;
- case getCode('USER_404') : $msg = getMessage('USER_NOT_FOUND'); break;
- case getCode('STATS_404') : $msg = getMessage('MAIL_STATS_404'); break;
- case getCode('ALREADY_CONFIRMED'): $msg = getMessage('MAIL_ALREADY_CONFIRMED'); break;
+ case getCode('LOGOUT_DONE') : $message = getMessage('LOGOUT_DONE'); break;
+ case getCode('LOGOUT_FAILED') : $message = "{--LOGOUT_FAILED--} "; break;
+ case getCode('DATA_INVALID') : $message = getMessage('MAIL_DATA_INVALID'); break;
+ case getCode('POSSIBLE_INVALID') : $message = getMessage('MAIL_POSSIBLE_INVALID'); break;
+ case getCode('ACCOUNT_LOCKED') : $message = getMessage('MEMBER_ACCOUNT_LOCKED_UNC'); break;
+ case getCode('USER_404') : $message = getMessage('USER_NOT_FOUND'); break;
+ case getCode('STATS_404') : $message = getMessage('MAIL_STATS_404'); break;
+ case getCode('ALREADY_CONFIRMED'): $message = getMessage('MAIL_ALREADY_CONFIRMED'); break;
case getCode('ERROR_MAILID'):
if (EXT_IS_ACTIVE($ext, true)) {
- $msg = getMessage('ERROR_CONFIRMING_MAIL');
+ $message = getMessage('ERROR_CONFIRMING_MAIL');
} else {
- $msg = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'mailid');
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'mailid');
}
break;
case getCode('EXTENSION_PROBLEM'):
if (REQUEST_ISSET_GET('ext')) {
- $msg = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), REQUEST_GET('ext'));
+ $message = generateExtensionInactiveNotInstalledMessage(REQUEST_GET('ext'));
} else {
- $msg = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
+ $message = getMessage('EXTENSION_PROBLEM_UNSET_EXT');
}
break;
- case getCode('COOKIES_DISABLED') : $msg = getMessage('LOGIN_NO_COOKIES'); break;
- case getCode('BEG_SAME_AS_OWN') : $msg = getMessage('BEG_SAME_UID_AS_OWN'); break;
- case getCode('LOGIN_FAILED') : $msg = getMessage('LOGIN_FAILED_GENERAL'); break;
- case getCode('MODULE_MEM_ONLY') : $msg = sprintf(getMessage('MODULE_MEM_ONLY'), REQUEST_GET('mod')); break;
+ case getCode('COOKIES_DISABLED') : $message = getMessage('LOGIN_NO_COOKIES'); break;
+ case getCode('BEG_SAME_AS_OWN') : $message = getMessage('BEG_SAME_UID_AS_OWN'); break;
+ case getCode('LOGIN_FAILED') : $message = getMessage('LOGIN_FAILED_GENERAL'); break;
+ case getCode('MODULE_MEM_ONLY') : $message = sprintf(getMessage('MODULE_MEM_ONLY'), REQUEST_GET('mod')); break;
default:
// Missing/invalid code
- $msg = sprintf(getMessage('UNKNOWN_MAILID_CODE'), $code);
+ $message = sprintf(getMessage('UNKNOWN_MAILID_CODE'), $code);
// Log it
- DEBUG_LOG(__FUNCTION__, __LINE__, $msg);
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
break;
} // END - switch
// Return the message
- return $msg;
+ return $message;
}
// Generate a "link" for the given admin id (aid)
@@ -2692,7 +2754,7 @@ function generateAdminLink ($aid) {
// Is the extension there?
if (EXT_IS_ACTIVE('admins')) {
// Admin found
- $admin = "".$login." ";
+ $admin = "" . $login." ";
} else {
// Extension not found
$admin = sprintf(getMessage('EXTENSION_PROBLEM_NOT_INSTALLED'), 'admins');
@@ -2708,21 +2770,21 @@ function generateAdminLink ($aid) {
}
// 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));
+ if (!$simple) $code = str_replace('{--', '".', str_replace('--}', '."', $code));
// Compile QUOT and other non-HTML codes
$code = str_replace('{DOT}', '.',
- str_replace('{SLASH}', '/',
- str_replace('{QUOT}', "'",
- str_replace('{DOLLAR}', '$',
- str_replace('{OPEN_ANCHOR}', '(',
- str_replace('{CLOSE_ANCHOR}', ')',
- str_replace('{OPEN_SQR}', '[',
- str_replace('{CLOSE_SQR}', ']',
- str_replace('{PER}', '%',
- $code
+ str_replace('{SLASH}', '/',
+ str_replace('{QUOT}', "'",
+ str_replace('{DOLLAR}', '$',
+ str_replace('{OPEN_ANCHOR}', '(',
+ str_replace('{CLOSE_ANCHOR}', ')',
+ str_replace('{OPEN_SQR}', '[',
+ str_replace('{CLOSE_SQR}', ']',
+ str_replace('{PER}', '%',
+ $code
)))))))));
// Return compiled code
@@ -2732,7 +2794,7 @@ function compileUriCode ($code, $simple=true) {
// Function taken from user comments on www.php.net / function eregi()
function isUrlValidSimple ($url) {
// Prepare URL
- $url = strip_tags(str_replace("\\", '', compileUriCode(urldecode($url))));
+ $url = strip_tags(str_replace("\\", '', COMPILE_CODE(urldecode($url))));
// Allows http and https
$http = "(http|https)+(:\/\/)";
@@ -2749,44 +2811,42 @@ function isUrlValidSimple ($url) {
// ... and the string after and including question character
$getstring1 = "([\?/]([[:alnum:]][-\._%[:alnum:]]*(=)?([-\@\._:%[:alnum:]])+)(&([[:alnum:]]([-_%[:alnum:]])*(=)?([-\@\[\._:%[:alnum:]])+(\])*))*)?";
// Pattern for URLs like http://url/dir/doc.html?var=value
- $pattern['d1dpg1'] = $http.$domain1.$dir.$page.$getstring1;
- $pattern['d2dpg1'] = $http.$domain2.$dir.$page.$getstring1;
- $pattern['ipdpg1'] = $http.$ip.$dir.$page.$getstring1;
+ $pattern['d1dpg1'] = $http . $domain1 . $dir . $page . $getstring1;
+ $pattern['d2dpg1'] = $http . $domain2 . $dir . $page . $getstring1;
+ $pattern['ipdpg1'] = $http . $ip . $dir . $page . $getstring1;
// Pattern for URLs like http://url/dir/?var=value
- $pattern['d1dg1'] = $http.$domain1.$dir.'/'.$getstring1;
- $pattern['d2dg1'] = $http.$domain2.$dir.'/'.$getstring1;
- $pattern['ipdg1'] = $http.$ip.$dir.'/'.$getstring1;
+ $pattern['d1dg1'] = $http . $domain1 . $dir.'/' . $getstring1;
+ $pattern['d2dg1'] = $http . $domain2 . $dir.'/' . $getstring1;
+ $pattern['ipdg1'] = $http . $ip . $dir.'/' . $getstring1;
// Pattern for URLs like http://url/dir/page.ext
- $pattern['d1dp'] = $http.$domain1.$dir.$page;
- $pattern['d1dp'] = $http.$domain2.$dir.$page;
- $pattern['ipdp'] = $http.$ip.$dir.$page;
+ $pattern['d1dp'] = $http . $domain1 . $dir . $page;
+ $pattern['d1dp'] = $http . $domain2 . $dir . $page;
+ $pattern['ipdp'] = $http . $ip . $dir . $page;
// Pattern for URLs like http://url/dir
- $pattern['d1d'] = $http.$domain1.$dir;
- $pattern['d2d'] = $http.$domain2.$dir;
- $pattern['ipd'] = $http.$ip.$dir;
+ $pattern['d1d'] = $http . $domain1 . $dir;
+ $pattern['d2d'] = $http . $domain2 . $dir;
+ $pattern['ipd'] = $http . $ip . $dir;
// Pattern for URLs like http://url/?var=value
- $pattern['d1g1'] = $http.$domain1.'/'.$getstring1;
- $pattern['d2g1'] = $http.$domain2.'/'.$getstring1;
- $pattern['ipg1'] = $http.$ip.'/'.$getstring1;
+ $pattern['d1g1'] = $http . $domain1 . '/' . $getstring1;
+ $pattern['d2g1'] = $http . $domain2 . '/' . $getstring1;
+ $pattern['ipg1'] = $http . $ip . '/' . $getstring1;
// Pattern for URLs like http://url?var=value
- $pattern['d1g12'] = $http.$domain1.$getstring1;
- $pattern['d2g12'] = $http.$domain2.$getstring1;
- $pattern['ipg12'] = $http.$ip.$getstring1;
+ $pattern['d1g12'] = $http . $domain1 . $getstring1;
+ $pattern['d2g12'] = $http . $domain2 . $getstring1;
+ $pattern['ipg12'] = $http . $ip . $getstring1;
// Test all patterns
$reg = false;
- foreach ($pattern as $key=>$pat) {
+ foreach ($pattern as $key => $pat) {
// Debug regex?
- if (defined('DEBUG_REGEX')) {
- $pat = str_replace("[:alnum:]", "0-9a-zA-Z", $pat);
- $pat = str_replace("[:alpha:]", "a-zA-Z", $pat);
- $pat = str_replace("[:digit:]", "0-9", $pat);
- $pat = str_replace('.', "\.", $pat);
- $pat = str_replace("@", "\@", $pat);
- echo $key."= ".$pat." ";
- }
+ if (isDebugRegExpressionEnabled()) {
+ // @TODO Are these convertions still required?
+ $pat = str_replace('.', "\.", $pat);
+ $pat = str_replace('@', "\@", $pat);
+ //* DEBUG: */ OUTPUT_HTML($key."= " . $pat . " ");
+ } // END - if
// Check if expression matches
- $reg = ($reg || preg_match(("^".$pat."^"), $url));
+ $reg = ($reg || preg_match(('^' . $pat.'^'), $url));
// Does it match?
if ($reg === true) break;
@@ -2811,12 +2871,12 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
$tmp = $FQFN . '.tmp';
// Open the source file
- $fp = fopen($FQFN, 'r') or OUTPUT_HTML('READ: ' . $FQFN . " \n");
+ $fp = fopen($FQFN, 'r') or OUTPUT_HTML('READ: ' . $FQFN . ' ');
// Is the resource valid?
if (is_resource($fp)) {
// Open temporary file
- $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('WRITE: ' . $tmp . " \n");
+ $fp_tmp = fopen($tmp, 'w') or OUTPUT_HTML('WRITE: ' . $tmp . ' ');
// Is the resource again valid?
if (is_resource($fp_tmp)) {
@@ -2833,7 +2893,7 @@ function changeDataInFile ($FQFN, $comment, $prefix, $suffix, $DATA, $seek=0) {
} else {
$next++;
}
- }
+ } // END - if
// Write to temp file
fputs($fp_tmp, $line);
@@ -2874,8 +2934,8 @@ function sendAdminNotification ($subject, $templateName, $content=array(), $uid
SEND_ADMIN_EMAILS_PRO($subject, $templateName, $content, $uid);
} else {
// Send out out-dated way
- $msg = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
- SEND_ADMIN_EMAILS($subject, $msg);
+ $message = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
+ SEND_ADMIN_EMAILS($subject, $message);
}
}
@@ -2886,9 +2946,9 @@ function DEBUG_LOG ($funcFile, $line, $message, $force=true) {
// 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(getConfig('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
}
@@ -2898,7 +2958,7 @@ function runResetIncludes () {
// 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
@@ -2990,7 +3050,7 @@ function convertSelectionsToTimestamp (&$POST, &$DATA, &$id, &$skip) {
// Remove data from array
foreach (array('ye', 'mo', 'we', 'da', 'ho', 'mi', 'se') as $rem) {
- unset($POST[$test.'_'.$rem]);
+ unset($POST[$test.'_' . $rem]);
} // END - foreach
// Skip adding
@@ -3034,14 +3094,14 @@ function HANDLE_LOGIN_FAILTURES ($accessLevel) {
$OUT = '';
// Is the session data set?
- if ((isSessionVariableSet('mxchange_'.$accessLevel.'_failures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) {
+ if ((isSessionVariableSet('mxchange_' . $accessLevel.'_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel.'_last_fail'))) {
// Ignore zero values
- if (getSession('mxchange_'.$accessLevel.'_failures') > 0) {
+ if (getSession('mxchange_' . $accessLevel.'_failures') > 0) {
// Non-guest has login failures found, get both data and prepare it for template
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ):accessLevel={$accessLevel} \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ):accessLevel={$accessLevel} ");
$content = array(
- 'login_failures' => getSession('mxchange_'.$accessLevel.'_failures'),
- 'last_failure' => generateDateTime(getSession('mxchange_'.$accessLevel.'_last_fail'), '2')
+ 'login_failures' => getSession('mxchange_' . $accessLevel.'_failures'),
+ 'last_failure' => generateDateTime(getSession('mxchange_' . $accessLevel.'_last_fail'), '2')
);
// Load template
@@ -3049,8 +3109,8 @@ function HANDLE_LOGIN_FAILTURES ($accessLevel) {
} // END - if
// Reset session data
- setSession('mxchange_'.$accessLevel.'_failures', '');
- setSession('mxchange_'.$accessLevel.'_last_fail', '');
+ setSession('mxchange_' . $accessLevel.'_failures', '');
+ setSession('mxchange_' . $accessLevel.'_last_fail', '');
} // END - if
// Return rendered content
@@ -3075,7 +3135,7 @@ function rebuildCacheFiles ($cache, $inc = '') {
// Is the include there?
if (isIncludeReadable($INC)) {
// And rebuild it from scratch
- //* DEBUG: */ print __FUNCTION__."(".__LINE__." ): inc={$inc} - LOADED! \n";
+ //* DEBUG: */ OUTPUT_HTML(__FUNCTION__."(".__LINE__." ): inc={$inc} - LOADED! ");
loadInclude($INC);
} else {
// Include not found!
@@ -3093,7 +3153,7 @@ function cachePurgeAdminMenu ($id=0, $action = '', $what = '', $str = '') {
return false;
} elseif (!isCacheInstanceValid()) {
// No cache instance!
- DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
+ DEBUG_LOG(__FUNCTION__, __LINE__, 'No cache instance found.');
return false;
} elseif ((!isConfigEntrySet('cache_admin_menu')) || (getConfig('cache_admin_menu') != 'Y')) {
// Caching disabled (currently experiemental!)
@@ -3159,34 +3219,34 @@ function addNewBonusMail ($data, $mode = '', $output=true) {
LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_MORE_SELECTED'));
} else {
// Debug log
- DEBUG_LOG(__FUNCTION__, __LINE__, " cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
+ DEBUG_LOG(__FUNCTION__, __LINE__, "cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
}
}
// Determines referal id and sets it
function DETERMINE_REFID () {
// Check if refid is set
- if ((!empty($_GET['user'])) && (basename($_SERVER['PHP_SELF']) == "click.php")) {
+ if ((REQUEST_ISSET_GET('user')) && (basename($_SERVER['PHP_SELF']) == 'click.php')) {
// The variable user comes from the click-counter script click.php and we only accept this here
- $GLOBALS['refid'] = bigintval($_GET['user']);
- } elseif (!empty($_POST['refid'])) {
+ $GLOBALS['refid'] = bigintval(REQUEST_GET('user'));
+ } elseif (REQUEST_ISSET_POST('refid')) {
// Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_POST['refid']));
- } elseif (!empty($_GET['refid'])) {
+ $GLOBALS['refid'] = strip_tags(REQUEST_POST('refid'));
+ } elseif (REQUEST_ISSET_GET('refid')) {
// Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['refid']));
- } elseif (!empty($_GET['ref'])) {
+ $GLOBALS['refid'] = strip_tags(REQUEST_GET('refid'));
+ } elseif (REQUEST_ISSET_GET('ref')) {
// Set refid=ref (the referal link uses such variable)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['ref']));
+ $GLOBALS['refid'] = strip_tags(REQUEST_GET('ref'));
} elseif ((isSessionVariableSet('refid')) && (getSession('refid') != 0)) {
// Set session refid als global
$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'));
} 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();
+ } elseif ((GET_EXT_VERSION('sql_patches') != '') && (getConfig('def_refid') > 0)) {
+ // Set default refid as refid in URL
+ $GLOBALS['refid'] = getConfig('def_refid');
} else {
// No default ID when sql_patches is not installed or none set
$GLOBALS['refid'] = 0;
@@ -3257,17 +3317,17 @@ function isUserIdSet () {
// 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?
if (REQUEST_ISSET_GET('ext')) $ext = REQUEST_GET('ext');
// Convert the 'msg' parameter from URL to a human-readable message
- $msg = convertCodeToMessage(REQUEST_GET('msg'));
+ $message = convertCodeToMessage(REQUEST_GET('msg'));
// Load message template
- LOAD_TEMPLATE('message', false, $msg);
+ LOAD_TEMPLATE('message', false, $message);
} // END - if
}
@@ -3293,6 +3353,181 @@ function isExtraTitleSet () {
return ((isset($GLOBALS['extra_title'])) && (!empty($GLOBALS['extra_title'])));
}
+// Generates a 'extension foo inactive' message
+function generateExtensionInactiveMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ trigger_error(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), $ext_name);
+
+ // Is an admin logged in?
+ if (IS_ADMIN()) {
+ // Then output admin message
+ $message = sprintf(getMessage('ADMIN_EXTENSION_PROBLEM_EXT_INACTIVE'), $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a 'extension foo not installed' message
+function generateExtensionNotInstalledMessage ($ext_name) {
+ // Is the extension empty?
+ if (empty($ext_name)) {
+ // This should not happen
+ trigger_error(__FUNCTION__ . ': Parameter ext is empty. This should not happen.');
+ } // END - if
+
+ // Default message
+ $message = sprintf(getMessage('EXTENSION_PROBLEM_EXT_NOT_INSTALLED'), $ext_name);
+
+ // Is an admin logged in?
+ if (IS_ADMIN()) {
+ // Then output admin message
+ $message = sprintf(getMessage('ADMIN_EXTENSION_PROBLEM_EXT_NOT_INSTALLED'), $ext_name);
+ } // END - if
+
+ // Return prepared message
+ return $message;
+}
+
+// Generates a message depending on if the extension is not installed or not
+// just activated
+function generateExtensionInactiveNotInstalledMessage ($ext_name) {
+ // Init message
+ $message = '';
+
+ // Is the extension not installed or just deactivated?
+ switch (isExtensionInstalled($ext_name)) {
+ case true; // Deactivated!
+ $message = generateExtensionInactiveMessage($ext_name);
+ break;
+
+ case false; // Not installed!
+ $message = generateExtensionNotInstalledMessage($ext_name);
+ break;
+
+ default: // Should not happen!
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name));
+ $message = sprintf("Invalid state of extension %s detected.", $ext_name);
+ break;
+ } // END - switch
+
+ // Return the message
+ return $message;
+}
+
+// Reads a directory recursively by default and searches for files not matching
+// an exclusion pattern. You can now keep the exclusion pattern empty for reading
+// a whole directory.
+function getArrayFromDirectory ($baseDir, $prefix, $fileIncludeDirs = false, $addBaseDir = true, $excludeArray = array(), $extension = '.php', $excludePattern = '@(\.|\.\.)$@', $recursive = true) {
+ // Add default entries we should exclude
+ $excludeArray[] = '.';
+ $excludeArray[] = '..';
+ $excludeArray[] = '.svn';
+ $excludeArray[] = '.htaccess';
+
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix} - Entered!");
+ // Init includes
+ $files = array();
+
+ // Open directory
+ $dirPointer = opendir(getConfig('PATH') . $baseDir) or app_die(__FUNCTION__, __LINE__, 'Cannot read directory ' . basename($baseDir) . '.');
+
+ // Read all entries
+ while ($baseFile = readdir($dirPointer)) {
+ // Exclude '.', '..' and entries in $excludeArray automatically
+ if (in_array($baseFile, $excludeArray, true)) {
+ // Exclude them
+ //* DEBUG: */ OUTPUT_HTML('excluded=' . $baseFile . " ");
+ continue;
+ } // END - if
+
+ // Construct include filename and FQFN
+ $fileName = $baseDir . '/' . $baseFile;
+ $FQFN = getConfig('PATH') . $fileName;
+
+ // Remove double slashes
+ $FQFN = str_replace('//', '/', $FQFN);
+
+ // Check if the base filename matches an exclusion pattern and if the pattern is not empty
+ if ((!empty($excludePattern)) && (preg_match($excludePattern, $baseFile, $match))) {
+ // These Lines are only for debugging!!
+ //* DEBUG: */ OUTPUT_HTML('baseDir:' . $baseDir . " ");
+ //* DEBUG: */ OUTPUT_HTML('baseFile:' . $baseFile . " ");
+ //* DEBUG: */ OUTPUT_HTML('FQFN:' . $FQFN . " ");
+
+ // Exclude this one
+ continue;
+ } // END - if
+
+ // Skip also files with non-matching prefix genericly
+ if (($recursive === true) && (isDirectory($FQFN))) {
+ // Is a redirectory so read it as well
+ $files = merge_array($files, getArrayFromDirectory ($baseDir . $baseFile . '/', $prefix, $fileIncludeDirs, $addBaseDir, $excludeArray, $extension, $excludePattern, $recursive));
+
+ // And skip further processing
+ continue;
+ } elseif (substr($baseFile, 0, strlen($prefix)) != $prefix) {
+ // Skip this file
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Invalid prefix in file " . $baseFile . ", prefix=" . $prefix);
+ continue;
+ } elseif (!isFileReadable($FQFN)) {
+ // Not readable so skip it
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "File " . $FQFN . " is not readable!");
+ continue;
+ }
+
+ // Is the file a PHP script or other?
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}");
+ if ((substr($baseFile, -4, 4) == '.php') || (($fileIncludeDirs === true) && (isDirectory($FQFN)))) {
+ // Is this a valid include file?
+ if ($extension == '.php') {
+ // Remove both for extension name
+ $extName = substr($baseFile, strlen($prefix), -4);
+
+ // Try to find it
+ $extId = GET_EXT_ID($extName);
+
+ // Is the extension valid and active?
+ if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
+ // Then add this file
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Extension entry ' . $baseFile . ' added.');
+ $files[] = $fileName;
+ } elseif ($extId == 0) {
+ // Add non-extension files as well
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, 'Regular entry ' . $baseFile . ' added.');
+ if ($addBaseDir === true) {
+ $files[] = $fileName;
+ } else {
+ $files[] = $baseFile;
+ }
+ }
+ } else {
+ // We found .php file but should not search for them, why?
+ debug_report_bug('We should find files with extension=' . $extension . ', but we found a PHP script.');
+ }
+ } else {
+ // Other, generic file found
+ $files[] = $fileName;
+ }
+ } // END - while
+
+ // Close directory
+ closedir($dirPointer);
+
+ // Sort array
+ asort($files);
+
+ // Return array with include files
+ //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, '- Left!');
+ return $files;
+}
+
//////////////////////////////////////////////////
// AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
//////////////////////////////////////////////////