X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=eec116f9c7cd0c52b9a87f25ef4dd13ff2a8f696;hp=aa691935e1f452796adb75cae04fdce88fbf1e81;hb=0715fa7aa8e5e70bcf1d957fb09ae655c3896c4e;hpb=6a545ced209c14b75d2dc04f43ee010e9ae9b47c diff --git a/inc/functions.php b/inc/functions.php index aa691935e1..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,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? @@ -165,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 @@ -439,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 @@ -466,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; @@ -492,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! @@ -529,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')) { @@ -555,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()) { @@ -578,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'; @@ -595,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); } } @@ -630,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')); @@ -661,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); } } @@ -769,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); @@ -817,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; @@ -842,8 +867,8 @@ function translateUserStatus ($status) { break; default: - logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status)); - $ret = getMaskedMessage('UNKNOWN_STATUS', $status); + // Please report all unknown status + debug_report_bug(sprintf("Unknown status %s detected.", $status)); break; } // END - switch @@ -919,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,10 +963,13 @@ function redirectToUrl ($URL) { //* DEBUG: */ die($URL); // Simple probe for bots/spiders from search engines - if (isSpider()) { + 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()) { @@ -1053,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 @@ -1068,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; } @@ -1143,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 .= " '; } else { // Begin with regular selection box here if (!empty($prefix)) $prefix .= "_"; $type2 = $type; - if ($id > 0) $type2 .= "[" . $id."]"; - $OUT .= " '; } switch ($type) { case 'day': // Day for ($idx = 1; $idx < 32; $idx++) { - $OUT .= "'; } // END - for break; case 'month': // Month - foreach ($GLOBALS['month_descr'] as $month => $descr) { - $OUT .= "'; } // END - for } elseif ($default == -1) { // Current year minus 1 - for ($idx = $startYear; $idx <= ($year + 1); $idx++) - { - $OUT .= "\n"; - } + for ($idx = $startYear; $idx <= ($year + 1); $idx++) { + $OUT .= ''; + } // END - for } else { // Get current year and subtract the configured minimum age - $OUT .= "\n"; + $OUT .= ''; // Calculate earliest year depending on extension version - if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) { + if (isExtensionInstalledAndNewer('order', '0.2.1')) { // Use configured minimum age $year = date('Y', time()) - getConfig('min_age'); } else { @@ -1213,41 +1240,41 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're // Construct year selection list for ($idx = $minYear; $idx <= $year; $idx++) { - $OUT .= "'; } // END - for } break; case 'sec': case 'min': - for ($idx = '0'; $idx < 60; $idx+=5) { + for ($idx = 0; $idx < 60; $idx+=5) { if (strlen($idx) == 1) $idx = '0' . $idx; - $OUT .= "'; } // END - for break; case 'hour': - for ($idx = '0'; $idx < 24; $idx++) { + for ($idx = 0; $idx < 24; $idx++) { if (strlen($idx) == 1) $idx = '0' . $idx; - $OUT .= "'; } // END - for break; case 'yn': - $OUT .= "