X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Ffunctions.php;h=eec116f9c7cd0c52b9a87f25ef4dd13ff2a8f696;hb=0715fa7aa8e5e70bcf1d957fb09ae655c3896c4e;hp=ee75b3a0d2c0e3c098b30175aad2cc8e380061b6;hpb=0366eb054abf51874a4272fc9b89673af1fb793b;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index ee75b3a0d2..eec116f9c7 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -18,6 +18,7 @@
* svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -44,7 +45,9 @@ if (!defined('__SECURITY')) {
// Output HTML code directly or 'render' it. You addionally switch the new-line character off
function outputHtml ($htmlCode, $newLine = true) {
// Init output
- if (!isset($GLOBALS['output'])) $GLOBALS['output'] = '';
+ if (!isset($GLOBALS['output'])) {
+ $GLOBALS['output'] = '';
+ } // END - if
// Transfer username
$username = getMessage('USERNAME_UNKNOWN');
@@ -133,7 +136,7 @@ function sendHttpHeaders () {
$now = gmdate('D, d M Y H:i:s') . ' GMT';
// Send HTTP header
- sendHeader('HTTP/1.1 200');
+ sendHeader('HTTP/1.1 200 OK');
// General headers for no caching
sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21
@@ -148,19 +151,21 @@ function sendHttpHeaders () {
// Compiles the final output
function compileFinalOutput () {
// Init counter
- $cnt = '0';
+ $cnt = 0;
// Add page header and footer
addPageHeaderFooter();
// Compile all out
- while (((strpos($GLOBALS['output'], '{--') > 0) || (strpos($GLOBALS['output'], '{!') > 0) || (strpos($GLOBALS['output'], '{?') > 0)) && ($cnt < 3)) {
+ while (((strpos($GLOBALS['output'], '{--') !== false) || (strpos($GLOBALS['output'], '{!') !== false) || (strpos($GLOBALS['output'], '{?') !== false) || (strpos($GLOBALS['output'], '{%') !== false)) && ($cnt < 3)) {
// Init common variables
$content = array();
$newContent = '';
// Compile it
- $eval = "\$newContent = \"".compileCode(escapeQuotes($GLOBALS['output']))."\";";
+ //* DEBUG: */ print '
'.htmlentities($GLOBALS['output']).'
';
+ $eval = '$newContent = "' . compileCode(escapeQuotes($GLOBALS['output'])) . '";';
+ //* DEBUG: */ die(''.htmlentities($eval).'
');
eval($eval);
// Was that eval okay?
@@ -168,6 +173,8 @@ function compileFinalOutput () {
// Something went wrong!
debug_report_bug('Evaluation error:' . linenumberCode($eval) . '
', false);
} // END - if
+
+ // Use it again
$GLOBALS['output'] = $newContent;
// Count round
@@ -442,25 +449,25 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') {
} // END - if
// Load user's data
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):UID={$userid},template={$template},content[]=".gettype($content).'
');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UID={$userid},template={$template},content[]=".gettype($content).'
');
if (($userid > 0) && (is_array($content))) {
// If nickname extension is installed, fetch nickname as well
if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):NICKNAME!
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NICKNAME!
");
// Load by nickname
fetchUserData($userid, 'nickname');
} else {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):NO-NICK!
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NO-NICK!
");
/// Load by userid
fetchUserData($userid);
}
// Merge data if valid
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):content()=".count($content)." - PRE
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - PRE
");
if (isUserDataValid()) {
$content = merge_array($content, getUserDataArray());
} // END - if
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):content()=".count($content)." - AFTER
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "content()=".count($content)." - AFTER
");
} // END - if
// Translate M to male or F to female if present
@@ -469,7 +476,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') {
// Overwrite email from data if present
if (isset($content['email'])) $email = $content['email'];
- // Store email for some functions in global data array
+ // Store email for some functions in global $DATA array
// @TODO Do only use $content, not $DATA or raw variables
$DATA['email'] = $email;
@@ -495,7 +502,7 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') {
$GLOBALS['tpl_content'] = readFromFile($FQFN);
// Run code
- $GLOBALS['tpl_content'] = "\$newContent = decodeEntities(\"".compileRawCode(escapeQuotes($GLOBALS['tpl_content']))."\");";
+ $GLOBALS['tpl_content'] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'])) . '");';
eval($GLOBALS['tpl_content']);
} elseif (!empty($template)) {
// Template file not found!
@@ -532,13 +539,13 @@ function loadEmailTemplate ($template, $content = array(), $userid = '0') {
// Send mail out to an email address
function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '') {
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):TO={$toEmail},SUBJECT={$subject}
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail},SUBJECT={$subject}
");
// Compile subject line (for POINTS constant etc.)
- eval("\$subject = decodeEntities(\"".compileRawCode(escapeQuotes($subject))."\");");
+ eval('$subject = decodeEntities("' . compileRawCode(escapeQuotes($subject)) . '");');
// Set from header
- if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
+ if ((!isInStringIgnoreCase('@', $toEmail)) && ($toEmail > 0)) {
// Value detected, is the message extension installed?
// @TODO Extension 'msg' does not exist
if (isExtensionActive('msg')) {
@@ -558,7 +565,7 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
// Is the webmaster!
$toEmail = getConfig('WEBMASTER');
}
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):TO={$toEmail}
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "TO={$toEmail}
");
// Check for PHPMailer or debug-mode
if (!checkPhpMailerUsage()) {
@@ -581,10 +588,10 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
}
// Compile "TO"
- eval("\$toEmail = \"".compileRawCode(escapeQuotes($toEmail))."\";");
+ eval('$toEmail = "' . compileRawCode(escapeQuotes($toEmail)) . '";');
// Compile "MSG"
- eval("\$message = \"".str_replace('$', '$', compileRawCode(escapeQuotes($message)))."\";");
+ eval('$message = "' . str_replace('$', '$', compileRawCode(escapeQuotes($message))) . '";');
// Fix HTML parameter (default is no!)
if (empty($isHtml)) $isHtml = 'N';
@@ -598,13 +605,13 @@ Message : ' . htmlentities(utf8_decode($message)) . '
');
} elseif (($isHtml == 'Y') && (isExtensionActive('html_mail'))) {
// Send mail as HTML away
- sendHtmlEmail($toEmail, $subject, $message, $mailHeader);
+ return sendHtmlEmail($toEmail, $subject, $message, $mailHeader);
} elseif (!empty($toEmail)) {
// Send Mail away
- sendRawEmail($toEmail, $subject, $message, $mailHeader);
+ return sendRawEmail($toEmail, $subject, $message, $mailHeader);
} elseif ($isHtml != 'Y') {
// Problem found!
- sendRawEmail(getConfig('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
+ return sendRawEmail(getConfig('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
}
}
@@ -633,7 +640,7 @@ function sendRawEmail ($toEmail, $subject, $message, $from) {
$mail = new PHPMailer();
// Set charset to UTF-8
- $mail->CharSet('UTF-8');
+ $mail->CharSet = 'UTF-8';
// Path for PHPMailer
$mail->PluginDir = sprintf("%sinc/phpmailer/", getConfig('PATH'));
@@ -664,9 +671,21 @@ function sendRawEmail ($toEmail, $subject, $message, $from) {
$mail->AddCustomHeader('Errors-To:' . getConfig('WEBMASTER'));
$mail->AddCustomHeader('X-Loop:' . getConfig('WEBMASTER'));
$mail->Send();
+
+ // Has an error occured?
+ if (!empty($mail->ErrorInfo)) {
+ // Log message
+ logDebugMessage(__FUNCTION__, __LINE__, 'Error while sending mail: ' . $mail->ErrorInfo);
+
+ // Raise an error
+ return false;
+ } else {
+ // All fine!
+ return true;
+ }
} else {
// Use legacy mail() command
- mail($toEmail, $subject, decodeEntities($message), $from);
+ return mail($toEmail, $subject, decodeEntities($message), $from);
}
}
@@ -772,6 +791,9 @@ function translatePoolType ($type) {
// Translates the american decimal dot into a german comma
function translateComma ($dotted, $cut = true, $max = '0') {
+ // First, cast all to double, due to PHP changes
+ $dotted = (double) $dotted;
+
// Default is 3 you can change this in admin area "Misc -> Misc Options"
if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', 3);
@@ -1059,10 +1081,10 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
$test = substr($found, 0, strlen($match));
// Does this entry exist?
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):found={$found},match={$match},set={$set}
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "found={$found},match={$match},set={$set}
");
if ($test == $match) {
// Match found!
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):fuzzyFound!
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "fuzzyFound!
");
$fuzzyFound = true;
break;
} // END - if
@@ -1074,14 +1096,14 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
// Take all string elements
if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_" . $matches[4][$key]]))) {
// Replace it in the code
- //* DEBUG: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):key={$key},match={$match}
");
+ //* DEBUG: */ logDebugMessage(__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: */ outputHtml(__FUNCTION__ . '(' . __LINE__."):match={$match}
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "match={$match}
");
$code = str_replace($match, '".' . $match . '."', $code);
$matchesFound[$match] = 1;
}
@@ -1149,30 +1171,30 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're
if ($type == 'yn') {
// This is a yes/no selection only!
- if ($id > 0) $prefix .= "[" . $id."]";
- $OUT .= "