X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=03376db72e20103835833c2b16695e5e1b336895;hb=b5f5bab2513e56082e977eb534ddd3ceb00a770e;hp=5557b88024ad1605fc245b8157f3d51856d2f639;hpb=bdd8949ee8b336ef33a7c83ae2c00ac0134dad0f;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index 5557b88024..03376db72e 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');
@@ -85,16 +88,7 @@ function outputHtml ($htmlCode, $newLine = true) {
app_die(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}');
break;
} // END - switch
- } elseif ((getPhpCaching() == 'on') && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
- // Headers already sent?
- if (headers_sent()) {
- // Log this error
- logDebugMessage(__FUNCTION__, __LINE__, 'Headers already sent! We need debug backtrace here.');
-
- // Trigger an user error
- debug_report_bug('Headers are already sent!');
- } // END - if
-
+ } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['header'])) || (count($GLOBALS['header']) == 0))) {
// Output cached HTML code
$GLOBALS['output'] = ob_get_contents();
@@ -108,12 +102,12 @@ function outputHtml ($htmlCode, $newLine = true) {
$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
} // END - if
- // Compile and run finished rendered HTML code
- compileFinalOutput();
-
// Send all HTTP headers
sendHttpHeaders();
+ // Compile and run finished rendered HTML code
+ compileFinalOutput();
+
// Output code here, DO NOT REMOVE! ;-)
outputRawCode($GLOBALS['output']);
} elseif ((getConfig('OUTPUT_MODE') == 'render') && (!empty($GLOBALS['output']))) {
@@ -122,14 +116,17 @@ function outputHtml ($htmlCode, $newLine = true) {
$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
} // END - if
- // Compile and run finished rendered HTML code
- compileFinalOutput();
-
// Send all HTTP headers
sendHttpHeaders();
+ // Compile and run finished rendered HTML code
+ compileFinalOutput();
+
// Output code here, DO NOT REMOVE! ;-)
outputRawCode($GLOBALS['output']);
+ } else {
+ // And flush all headers
+ flushHeaders();
}
}
@@ -139,10 +136,10 @@ 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('Expired: ' . $now); // RFC2616 - Section 14.21
+ sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21
sendHeader('Last-Modified: ' . $now);
sendHeader('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
sendHeader('Pragma: no-cache'); // HTTP/1.0
@@ -154,16 +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?
@@ -171,14 +173,34 @@ function compileFinalOutput () {
// Something went wrong!
debug_report_bug('Evaluation error:' . linenumberCode($eval) . '
', false);
} // END - if
+
+ // Use it again
$GLOBALS['output'] = $newContent;
// Count round
$cnt++;
} // END - while
+ // Compress it?
+ if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
+ // Compress it for HTTP gzip
+ $GLOBALS['output'] = gzencode($GLOBALS['output'], 9, true);
+
+ // Add header
+ sendHeader('Content-Encoding: gzip');
+ } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
+ // Compress it for HTTP deflate
+ $GLOBALS['output'] = gzcompress($GLOBALS['output'], 9);
+
+ // Add header
+ sendHeader('Content-Encoding: deflate');
+ }
+
// Add final length
sendHeader('Content-Length: ' . strlen($GLOBALS['output']));
+
+ // Flush all headers
+ flushHeaders();
}
// Output the raw HTML code
@@ -217,7 +239,6 @@ function addFatalMessage ($F, $L, $message, $extra = '') {
$GLOBALS['fatal_messages'][] = $message;
// Log fatal messages away
- debug_report_bug($message);
logDebugMessage($F, $L, 'Fatal error message: ' . $message);
}
@@ -284,7 +305,7 @@ function loadTemplate ($template, $return = false, $content = array()) {
// Do we have to compile the code?
$ret = '';
- if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false)) {
+ if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false) || (strpos($GLOBALS['tpl_content'], '{%') !== false)) {
// Normal HTML output?
if (getOutputMode() == '0') {
// Add surrounding HTML comments to help finding bugs faster
@@ -400,7 +421,7 @@ function detectExtraTemplatePath ($template) {
}
// Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $UID = '0') {
+function loadEmailTemplate ($template, $content = array(), $userid = '0') {
global $DATA;
// Make sure all template names are lowercase!
@@ -409,61 +430,44 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
// Default 'nickname' if extension is not installed
$nick = '---';
- // Prepare IP number and User Agent
- $REMOTE_ADDR = detectRemoteAddr();
- $HTTP_USER_AGENT = detectUserAgent();
-
- // Default admin
- $ADMIN = getConfig('MAIN_TITLE');
-
- // Is the admin logged in?
- if (isAdmin()) {
- // Get admin id
- $adminId = getCurrentAdminId();
-
- // Load Admin data
- $ADMIN = getAdminEmail($adminId);
- } // END - if
-
// Neutral email address is default
$email = getConfig('WEBMASTER');
- // Expiration in a nice output format
- // NOTE: Use $content[expiration] in your templates instead of $EXPIRATION
- if (getConfig('auto_purge') == '0') {
- // Will never expire!
- $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE');
- } else {
- // Create nice date string
- $EXPIRATION = createFancyTime(getConfig('auto_purge'));
- }
-
// Is content an array?
if (is_array($content)) {
- // Add expiration to array, $EXPIRATION is now deprecated!
- $content['expiration'] = $EXPIRATION;
+ // Add expiration to array
+ if ((isConfigEntrySet('auto_purge')) && (getConfig('auto_purge') == '0')) {
+ // Will never expire!
+ $content['expiration'] = getMessage('MAIL_WILL_NEVER_EXPIRE');
+ } elseif (isConfigEntrySet('auto_purge')) {
+ // Create nice date string
+ $content['expiration'] = createFancyTime(getConfig('auto_purge'));
+ } else {
+ // Missing entry
+ $content['expiration'] = getMessage('MAIL_NO_CONFIG_AUTO_PURGE');
+ }
} // END - if
// Load user's data
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):UID={$UID},template={$template},content[]=".gettype($content).'
');
- if (($UID > 0) && (is_array($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($UID))) {
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NICKNAME!
");
+ if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NICKNAME!
");
// Load by nickname
- fetchUserData($UID, 'nickname');
+ fetchUserData($userid, 'nickname');
} else {
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NO-NICK!
");
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "NO-NICK!
");
/// Load by userid
- fetchUserData($UID);
+ 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
@@ -472,8 +476,8 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
// Overwrite email from data if present
if (isset($content['email'])) $email = $content['email'];
- // Store email for some functions in global data array
- // @TODO Do only use $contentn, not $DATA or raw variables
+ // Store email for some functions in global $DATA array
+ // @TODO Do only use $content, not $DATA or raw variables
$DATA['email'] = $email;
// Base directory
@@ -498,7 +502,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '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!
@@ -519,7 +523,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
// Is there some content?
if (empty($newContent)) {
// Compiling failed
- $newContent = "Compiler error for template {$template}!\nUncompiled content:\n" . $GLOBALS['tpl_content'];
+ $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'];
// 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.";
@@ -535,13 +539,13 @@ function loadEmailTemplate ($template, $content = array(), $UID = '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')) {
@@ -561,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()) {
@@ -584,30 +588,30 @@ 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';
if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
outputHtml('
-Headers : ' . str_replace('<', '<', str_replace('>', '>', secureString(trim($mailHeader)))) . '
-To : ' . $toEmail . '
-Subject : ' . $subject . '
-Message : ' . $message . '
+Headers : ' . htmlentities(utf8_decode(trim($mailHeader))) . '
+To : ' . htmlentities(utf8_decode($toEmail)) . '
+Subject : ' . htmlentities(utf8_decode($subject)) . '
+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);
}
}
@@ -636,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'));
@@ -667,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);
}
}
@@ -758,7 +774,7 @@ function translateYesNo ($yn) {
// Translates the "pool type" into human-readable
function translatePoolType ($type) {
// Default?type is unknown
- $translated = sprintf(getMessage('POOL_TYPE_UNKNOWN'), $type);
+ $translated = getMaskedMessage('POOL_TYPE_UNKNOWN', $type);
// Generate constant
$constName = sprintf("POOL_TYPE_%s", $type);
@@ -775,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);
@@ -823,10 +842,10 @@ function translateGender ($gender) {
case 'F': $ret = getMessage('GENDER_F'); break;
case 'C': $ret = getMessage('GENDER_C'); break;
default:
- // Log unknown gender
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender));
+ // Please report bugs on unknown genders
+ debug_report_bug(sprintf("Unknown gender %s detected.", $gender));
break;
- }
+ } // END - switch
// Return translated gender
return $ret;
@@ -848,8 +867,8 @@ function translateUserStatus ($status) {
break;
default:
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
- $ret = sprintf(getMessage('UNKNOWN_STATUS'), $status);
+ // Please report all unknown status
+ debug_report_bug(sprintf("Unknown status %s detected.", $status));
break;
} // END - switch
@@ -925,7 +944,7 @@ function makeTime ($hours, $minutes, $seconds, $stamp) {
}
// Redirects to an URL and if neccessarry extends it with own base URL
-function redirectToUrl ($URL) {
+function redirectToUrl ($URL, $allowSpider = true) {
// Compile out codes
eval('$URL = "' . compileRawCode(encodeUrl($URL)) . '";');
@@ -938,28 +957,22 @@ function redirectToUrl ($URL) {
$rel = '';
} // END - if
- // Get output buffer
- $GLOBALS['output'] = ob_get_contents();
-
- // Clear it only if there is content
- if (!empty($GLOBALS['output'])) {
- clearOutputBuffer();
- } // END - if
-
// Three different ways to debug...
//* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
//* DEBUG: */ die($URL);
// Simple probe for bots/spiders from search engines
- if ((strpos(detectUserAgent(), 'spider') !== false) || (strpos(detectUserAgent(), 'bot') !== false)) {
+ if ((isSpider()) && ($allowSpider === true)) {
// Secure the URL against bad things such als HTML insertions and so on...
$URL = secureString($URL);
+ // Set content-type here to fix a missing array element
+ setContentType('text/html');
+
// Output new location link as anchor
outputHtml('' . $URL . '');
} elseif (!headers_sent()) {
- //* DEBUG: */ debug_report_bug("URL={$URL}");
// Clear own output buffer
$GLOBALS['output'] = '';
@@ -1068,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
@@ -1083,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;
}
@@ -1158,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 .= "