X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=473c494382dfc52f9e3d88e2e1781bc076e9099b;hp=0dbe4ae0d2d9d5a42584d474a7022b02888eda26;hb=4836fdd88165b4d32f5b826a93467d2bb293e3ad;hpb=a28637f0eb7975f2240c42d349e5f08a9722d9bb diff --git a/inc/functions.php b/inc/functions.php index 0dbe4ae0d2..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 @@ -442,25 +443,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 +470,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 +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! @@ -532,13 +533,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 +559,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 +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); @@ -922,7 +938,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)) . '";'); @@ -941,7 +957,7 @@ 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); @@ -1059,10 +1075,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 +1090,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; } @@ -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 { @@ -1263,7 +1279,7 @@ function addSelectionBox ($type, $default, $prefix = '', $id = '0', $class = 're // function generateRandomCode ($length, $code, $userid, $DATA = '') { // Build server string - $server = $_SERVER['PHP_SELF'] . getConfig('ENCRYPT_SEPERATOR') . detectUserAgent() . getConfig('ENCRYPT_SEPERATOR') . getenv('SERVER_SOFTWARE') . getConfig('ENCRYPT_SEPERATOR') . detectRemoteAddr().":'.':".filemtime(getConfig('PATH').'inc/databases.php'); + $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'); @@ -1314,7 +1330,7 @@ function generateRandomCode ($length, $code, $userid, $DATA = '') { } // Does only allow numbers -function bigintval ($num, $castValue = true) { +function bigintval ($num, $castValue = true, $abortOnMismatch = true) { // Filter all numbers out $ret = preg_replace('/[^0123456789]/', '', $num); @@ -1322,7 +1338,7 @@ function bigintval ($num, $castValue = true) { if ($castValue === true) $ret = (double)$ret; // Has the whole value changed? - if ('' . $ret . '' != '' . $num . '') { + if (('' . $ret . '' != '' . $num . '') && ($abortOnMismatch === true)) { // Log the values debug_report_bug('Problem with number found. ret=' . $ret . ', num='. $num); } // END - if @@ -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 .= " '; @@ -3866,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 @@ -3911,8 +3794,8 @@ function getModuleFromFileName ($file, $accessLevel) { // Encodes an URL for adding session id, etc. function encodeUrl ($url, $outputMode = '0') { - // Do we have already have a PHPSESSID inside? Then it is already converted... - if (strpos($url, session_name()) !== false) return $url; + // Do we have already have a PHPSESSID inside or view.php is called? Then abort here + if ((strpos($url, session_name()) !== false) || (getOutputMode() == -3)) return $url; // Do we have a valid session? if (((!isset($GLOBALS['valid_session'])) || ($GLOBALS['valid_session'] === false) || (!isset($_COOKIE[session_name()]))) && (isSpider() === false)) { @@ -3952,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(); + // Run two filters: + // 1.) pre_page_header (mainly loads the page_header template and includes + // meta description) + runFilterChain('pre_page_header'); - // 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); - - // 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 @@ -4027,6 +3896,80 @@ function generateCacheFqfn ($template) { return $GLOBALS['template_cache_fqfn'][$template]; } +// Function to search for the last modified file +function searchDirsRecursive ($dir, &$last_changed, $lookFor = 'Date') { + // Get dir as array + //* DEBUG: */ logDebugMessage(__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, '', false, true, array(), '.php', $excludePattern); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count(ds)='.count($ds)); + + // Walk through all entries + foreach ($ds as $d) { + // Generate proper FQFN + $FQFN = str_replace('//', '/', getConfig('PATH') . $dir . '/' . $d); + + // Is it a file and readable? + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'dir=' . $dir . ',d=' . $d); + if (isFileReadable($FQFN)) { + // $FQFN is a readable file so extract the requested data from it + $check = extractRevisionInfoFromFile($FQFN, $lookFor); + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' found. check=' . $check); + + // Is the file more recent? + if ((!isset($last_changed[$lookFor])) || ($last_changed[$lookFor] < $check)) { + // This file is newer as the file before + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'NEWER!'); + $last_changed['path_name'] = $FQFN; + $last_changed[$lookFor] = $check; + } // END - if + } else { + // Not readable + /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'File: ' . $d . ' not readable or directory.'); + } + } // 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 // //////////////////////////////////////////////////