X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=eb0ba63455b268642061309e2d03b24b16963fac;hp=aec4292947292056a13ef0e07a90f79f041aee33;hb=2c0f5aabd4c866f67705f36f7878dbc223daa9d8;hpb=60ded7280bf6c95a24ec14aa64de083dc4234d43 diff --git a/inc/functions.php b/inc/functions.php index aec4292947..eb0ba63455 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 * @@ -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; @@ -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))."\");"); // 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()) { @@ -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); } } @@ -1059,10 +1072,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 +1087,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; } @@ -1263,7 +1276,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 +1327,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 +1335,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 +1474,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 +3741,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 +3792,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 +3833,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); + // Run two filters: + // 1.) pre_page_header (mainly loads the page_header template and includes + // meta description) + runFilterChain('pre_page_header'); - // 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 +3894,43 @@ 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 +} + ////////////////////////////////////////////////// // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS // //////////////////////////////////////////////////