X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=473c494382dfc52f9e3d88e2e1781bc076e9099b;hp=5b30f4f795174e15a0dd36501aa36651104efcd9;hb=4836fdd88165b4d32f5b826a93467d2bb293e3ad;hpb=de5910b8e5deb9285a7ac57c26ebd894f4e1afbf diff --git a/inc/functions.php b/inc/functions.php index 5b30f4f795..473c494382 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 * @@ -133,7 +134,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 @@ -495,7 +496,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! @@ -535,10 +536,10 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = ' //* 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')) { @@ -581,10 +582,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 +599,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 +634,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 +665,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 +785,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); @@ -1181,7 +1197,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're $year = date('Y', time()); // Use configured min age or fixed? - if ((isExtensionActive('other')) && (getExtensionVersion('other') >= '0.2.1')) { + if (isExtensionInstalledAndNewer('order', '0.2.1')) { // Configured $startYear = $year - getConfig('min_age'); } else { @@ -1209,7 +1225,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're // Get current year and subtract the configured minimum age $OUT .= "\n"; // 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 { @@ -1461,38 +1477,38 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = $OUT .= "\n"; $OUT .= "\n"; - if (ereg('Y', $display) || (empty($display))) { + if (isInString('Y', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('M', $display) || (empty($display))) { + if (isInString('M', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('W', $display) || (empty($display))) { + if (isInString('W', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('D', $display) || (empty($display))) { + if (isInString('D', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('h', $display) || (empty($display))) { + if (isInString('h', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('m', $display) || (empty($display))) { + if (isInString('m', $display) || (empty($display))) { $OUT .= " \n"; } - if (ereg('s', $display) || (empty($display))) { + if (isInString('s', $display) || (empty($display))) { $OUT .= " \n"; } $OUT .= "\n"; $OUT .= "\n"; - if (ereg('Y', $display) || (empty($display))) { + if (isInString('Y', $display) || (empty($display))) { // Generate year selection $OUT .= "
{--_YEARS--}
{--_MONTHS--}
{--_WEEKS--}
{--_DAYS--}
{--_HOURS--}
{--_MINUTES--}
{--_SECONDS--}
'; } - if (ereg('M', $display) || (empty($display))) { + if (isInString('M', $display) || (empty($display))) { // Generate month selection $OUT .= " '; } - if (ereg('W', $display) || (empty($display))) { + if (isInString('W', $display) || (empty($display))) { // Generate week selection $OUT .= " '; } - if (ereg('D', $display) || (empty($display))) { + if (isInString('D', $display) || (empty($display))) { // Generate day selection $OUT .= " '; } - if (ereg('h', $display) || (empty($display))) { + if (isInString('h', $display) || (empty($display))) { // Generate hour selection $OUT .= " '; } - if (ereg('m', $display) || (empty($display))) { + if (isInString('m', $display) || (empty($display))) { // Generate minute selection $OUT .= " '; } - if (ereg('s', $display) || (empty($display))) { + if (isInString('s', $display) || (empty($display))) { // Generate second selection $OUT .= " '; @@ -3692,7 +3743,13 @@ function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionCo // Walk through all options foreach ($options as $option) { // Add the '; + if (empty($optionContent)) { + // ... from template + $OUT .= loadTemplate('select_' . $name . '_option', true, $option); + } else { + // Direct HTML code + $OUT .= ''; + } } // END - foreach // Finish selection box @@ -3778,37 +3835,23 @@ function isSpider () { if (empty($userAgent)) return true; // Is it a spider? - return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false)); + return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false) || (strpos($userAgent, 'archiver') !== false)); } // Prepares the header for HTML output function loadHtmlHeader () { - // Determine the page title - $content['header_title'] = determinePageTitle(); - - // Output page header code - $GLOBALS['page_header'] = loadTemplate('page_header', true, $content); - - // Include meta data in 'guest' module - if (getModule() == 'index') { - // Load meta data template - $GLOBALS['page_header'] .= loadTemplate('metadata', true); + // Run two filters: + // 1.) pre_page_header (mainly loads the page_header template and includes + // meta description) + runFilterChain('pre_page_header'); - // Add meta description to header - if ((isInstalled()) && (isAdminRegistered()) && (SQL_IS_LINK_UP())) { - // Add meta description not in admin and login module and when the script is installed - generateMetaDescriptionCode(); - } // END - if - } // END - if + // Here can be something be added, but normally one of the two filters + // around this line should do the job for you. + // 2.) post_page_header (mainly to load stylesheet, extra JavaScripts and + // to close the head-tag) // Include more header data here - $GLOBALS['page_header'] .= loadTemplate('header', true); - - // Include stylesheet - loadIncludeOnce('inc/stylesheet.php'); - - // Closing HEAD tag - $GLOBALS['page_header'] .= ''; + runFilterChain('post_page_header'); } // Adds page header and footer to output array element @@ -3890,6 +3933,43 @@ function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') { } // END - foreach } +// "Fixes" null or empty string to count of dashes +function fixNullEmptyToDashes ($str, $num) { + // Use str as default + $return = $str; + + // Is it empty? + if ((is_null($str)) || (trim($str) == '')) { + // Set it + $return = str_repeat('-', $num); + } // END - if + + // Return final string + return $return; +} + +// Handles the braces [] of a field (e.g. value of 'name' attribute) +function handleFieldWithBraces ($field) { + // Are there braces [] at the end? + if (substr($field, -2, 2) == '[]') { + // Try to find one and replace it. I do it this way to allow easy + // extending of this code. + foreach (array('admin_list_builder_id_value') as $key) { + // Is the cache entry set? + if (isset($GLOBALS[$key])) { + // Insert it + $field = str_replace('[]', '[' . $GLOBALS[$key] . ']', $field); + + // And abort + break; + } // END - if + } // END - foreach + } // END - if + + // Return it + return $field; +} + ////////////////////////////////////////////////// // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS // //////////////////////////////////////////////////