Maybe now better, but a simple wget still gives HTTP/1.0 :(
[mailer.git] / inc / functions.php
index b56975ac61db9bcb3363abeb9040fef5b690466b..69477a7dc847bc199728c6894e5948d69559cee1 100644 (file)
@@ -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}<br />");
 
        // 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('$', '&#36;', compileRawCode(escapeQuotes($message)))."\";");
+       eval('$message = "' . str_replace('$', '&#36;', compileRawCode(escapeQuotes($message))) . '";');
 
        // Fix HTML parameter (default is no!)
        if (empty($isHtml)) $isHtml = 'N';
@@ -598,13 +599,13 @@ Message : ' . htmlentities(utf8_decode($message)) . '
 </pre>');
        } 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);
        }
 }
 
@@ -1461,38 +1474,38 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"timebox_table dashed\">\n";
                $OUT .= "<tr>\n";
 
-               if (ereg('Y', $display) || (empty($display))) {
+               if (isInString('Y', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_YEARS--}</strong></td>\n";
                }
 
-               if (ereg('M', $display) || (empty($display))) {
+               if (isInString('M', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MONTHS--}</strong></td>\n";
                }
 
-               if (ereg('W', $display) || (empty($display))) {
+               if (isInString('W', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_WEEKS--}</strong></td>\n";
                }
 
-               if (ereg('D', $display) || (empty($display))) {
+               if (isInString('D', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_DAYS--}</strong></td>\n";
                }
 
-               if (ereg('h', $display) || (empty($display))) {
+               if (isInString('h', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_HOURS--}</strong></td>\n";
                }
 
-               if (ereg('m', $display) || (empty($display))) {
+               if (isInString('m', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_MINUTES--}</strong></td>\n";
                }
 
-               if (ereg('s', $display) || (empty($display))) {
+               if (isInString('s', $display) || (empty($display))) {
                        $OUT .= "  <td align=\"center\" class=\"timebox_column bottom\"><div class=\"tiny\">{--_SECONDS--}</strong></td>\n";
                }
 
                $OUT .= "</tr>\n";
                $OUT .= "<tr>\n";
 
-               if (ereg('Y', $display) || (empty($display))) {
+               if (isInString('Y', $display) || (empty($display))) {
                        // Generate year selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ye\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 10; $idx++) {
@@ -1505,7 +1518,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_ye" value="0" />';
                }
 
-               if (ereg('M', $display) || (empty($display))) {
+               if (isInString('M', $display) || (empty($display))) {
                        // Generate month selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mo\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 11; $idx++)
@@ -1519,7 +1532,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_mo" value="0" />';
                }
 
-               if (ereg('W', $display) || (empty($display))) {
+               if (isInString('W', $display) || (empty($display))) {
                        // Generate week selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_we\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 4; $idx++) {
@@ -1532,7 +1545,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_we" value="0" />';
                }
 
-               if (ereg('D', $display) || (empty($display))) {
+               if (isInString('D', $display) || (empty($display))) {
                        // Generate day selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_da\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 31; $idx++) {
@@ -1545,7 +1558,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_da" value="0" />';
                }
 
-               if (ereg('h', $display) || (empty($display))) {
+               if (isInString('h', $display) || (empty($display))) {
                        // Generate hour selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_ho\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 23; $idx++)    {
@@ -1558,7 +1571,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_ho" value="0" />';
                }
 
-               if (ereg('m', $display) || (empty($display))) {
+               if (isInString('m', $display) || (empty($display))) {
                        // Generate minute selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_mi\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 59; $idx++) {
@@ -1571,7 +1584,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
                        $OUT .= '<input type="hidden" name="' . $prefix . '_mi" value="0" />';
                }
 
-               if (ereg('s', $display) || (empty($display))) {
+               if (isInString('s', $display) || (empty($display))) {
                        // Generate second selection
                        $OUT .= "  <td align=\"center\"><select class=\"mini_select\" name=\"" . $prefix . "_se\" size=\"1\">\n";
                        for ($idx = '0'; $idx <= 59; $idx++) {
@@ -1715,7 +1728,7 @@ function extractHostnameFromUrl (&$script) {
 
        // Extract host name
        $host = str_replace('http://', '', $url);
-       if (ereg('/', $host)) $host = substr($host, 0, strpos($host, '/'));
+       if (isInString('/', $host)) $host = substr($host, 0, strpos($host, '/'));
 
        // Generate relative URL
        //* DEBUG: */ print("SCRIPT=" . $script.'<br />');
@@ -1836,14 +1849,26 @@ function sendRawRequest ($host, $request) {
                $useProxy = true;
        } // END - if
 
+       // Load include
+       loadIncludeOnce('inc/classes/resolver.class.php');
+
+       // Get resolver instance
+       $resolver = new HostnameResolver();
+
        // Open connection
        //* DEBUG: */ die("SCRIPT=" . $script.'<br />');
        if ($useProxy === true) {
+               // Resolve hostname into IP address
+               $ip = $resolver->resolveHostname(compileRawCode(getConfig('proxy_host')));
+
                // Connect to host through proxy connection
-               $fp = fsockopen(compileRawCode(getConfig('proxy_host')), bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
+               $fp = fsockopen($ip, bigintval(getConfig('proxy_port')), $errno, $errdesc, 30);
        } else {
+               // Resolve hostname into IP address
+               $ip = $resolver->resolveHostname($host);
+
                // Connect to host directly
-               $fp = fsockopen($host, 80, $errno, $errdesc, 30);
+               $fp = fsockopen($ip, 80, $errno, $errdesc, 30);
        }
 
        // Is there a link?
@@ -1859,35 +1884,13 @@ function sendRawRequest ($host, $request) {
 
        // Do we use proxy?
        if ($useProxy === true) {
-               // Generate CONNECT request header
-               $proxyTunnel  = 'CONNECT ' . $host . ':80 HTTP/1.1' . getConfig('HTTP_EOL');
-               $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL');
-
-               // Use login data to proxy? (username at least!)
-               if (getConfig('proxy_username') != '') {
-                       // Add it as well
-                       $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . getConfig('ENCRYPT_SEPERATOR') . compileRawCode(getConfig('proxy_password')));
-                       $proxyTunnel .= 'Proxy-Authorization: Basic ' . $encodedAuth . getConfig('HTTP_EOL');
-               } // END - if
-
-               // Add last new-line
-               $proxyTunnel .= getConfig('HTTP_EOL');
-               //* DEBUG: */ print('<strong>proxyTunnel=</strong><pre>' . $proxyTunnel.'</pre>');
-
-               // Write request
-               fwrite($fp, $proxyTunnel);
+               // Setup proxy tunnel
+               $response = setupProxyTunnel($host, $fp);
 
-               // Got response?
-               if (feof($fp)) {
-                       // No response received
-                       return $response;
-               } // END - if
-
-               // Read the first line
-               $resp = trim(fgets($fp, 10240));
-               $respArray = explode(' ', $resp);
-               if ((strtolower($respArray[0]) !== 'http/1.0') || ($respArray[1] != '200')) {
+               // If the response is invalid, abort
+               if ((count($response) == 3) && (empty($response[0])) && (empty($response[1])) && (empty($response[2]))) {
                        // Invalid response!
+                       logDebugMessage(__FUNCTION__, __LINE__, 'Proxy tunnel not working?');
                        return $response;
                } // END - if
        } // END - if
@@ -1934,7 +1937,7 @@ function sendRawRequest ($host, $request) {
        // Time request if debug-mode is enabled
        if (isDebugModeEnabled()) {
                // Add debug message...
-               logDebugMessage(__FUNCTION__, __LINE__, 'Request took ' . (microtime(true) - $start) . ' seconds.');
+               logDebugMessage(__FUNCTION__, __LINE__, 'Request took ' . (microtime(true) - $start) . ' seconds and returned ' . count($response) . ' line(s).');
        } // END - if
 
        // Skip first empty lines
@@ -1960,6 +1963,7 @@ function sendRawRequest ($host, $request) {
        if (!isset($response[0])) {
                // No response, maybe timeout
                $response = array('', '', '');
+               logDebugMessage(__FUNCTION__, __LINE__, 'Invalid empty response array, maybe timed out?');
        } elseif ((substr(strtolower($response[0]), 0, 11) == 'proxy-agent') && ($useProxy === true)) {
                // Proxy header detected, so remove two lines
                array_shift($response);
@@ -1967,8 +1971,9 @@ function sendRawRequest ($host, $request) {
        } // END - if
 
        // Was the request successfull?
-       if ((!eregi('200 OK', $response[0])) || (empty($response[0]))) {
+       if ((!isInStringIgnoreCase('200 OK', $response[0])) || (empty($response[0]))) {
                // Not found / access forbidden
+               logDebugMessage(__FUNCTION__, __LINE__, 'Unexpected status code ' . $response[0] . ' detected. "200 OK" was expected.');
                $response = array('', '', '');
        } // END - if
 
@@ -1976,7 +1981,48 @@ function sendRawRequest ($host, $request) {
        return $response;
 }
 
-// Taken from www.php.net eregi() user comments
+// Sets up a proxy tunnel for given hostname and through resource
+function setupProxyTunnel ($host, $resource) {
+       // Initialize array
+       $response = array('', '', '');
+
+       // Generate CONNECT request header
+       $proxyTunnel  = 'CONNECT ' . $host . ':80 HTTP/1.1' . getConfig('HTTP_EOL');
+       $proxyTunnel .= 'Host: ' . $host . getConfig('HTTP_EOL');
+
+       // Use login data to proxy? (username at least!)
+       if (getConfig('proxy_username') != '') {
+               // Add it as well
+               $encodedAuth = base64_encode(compileRawCode(getConfig('proxy_username')) . ':' . compileRawCode(getConfig('proxy_password')));
+               $proxyTunnel .= 'Proxy-Authorization: Basic ' . $encodedAuth . getConfig('HTTP_EOL');
+       } // END - if
+
+       // Add last new-line
+       $proxyTunnel .= getConfig('HTTP_EOL');
+       //* DEBUG: */ print('<strong>proxyTunnel=</strong><pre>' . $proxyTunnel.'</pre>');
+
+       // Write request
+       fwrite($fp, $proxyTunnel);
+
+       // Got response?
+       if (feof($fp)) {
+               // No response received
+               return $response;
+       } // END - if
+
+       // Read the first line
+       $resp = trim(fgets($fp, 10240));
+       $respArray = explode(' ', $resp);
+       if ((strtolower($respArray[0]) !== 'http/1.0') || ($respArray[1] != '200')) {
+               // Invalid response!
+               return $response;
+       } // END - if
+
+       // All fine!
+       return $respArray;
+}
+
+// Taken from www.php.net isInStringIgnoreCase() user comments
 function isEmailValid ($email) {
        // Check first part of email address
        $first = '[-a-z0-9!#$%&\'*+/=?^_<{|}~]+(\.[-a-zA-Z0-9!#$%&\'*+/=?^_<{|}~]+)*';
@@ -1991,7 +2037,7 @@ function isEmailValid ($email) {
        return preg_match($regex, $email);
 }
 
-// Function taken from user comments on www.php.net / function eregi()
+// Function taken from user comments on www.php.net / function isInStringIgnoreCase()
 function isUrlValid ($URL, $compile=true) {
        // Trim URL a little
        $URL = trim(urldecode($URL));
@@ -2236,22 +2282,22 @@ function encodeHashForCookie ($passHash) {
        $ret = $passHash;
 
        // Is a secret key and master salt already initialized?
-       //* DEBUG: */ outputHtml(__FUNCTION__.':'.intval(isExtensionInstalled('sql_patches')).'/'.intval(isConfigEntrySet('_PRIME')).'/'.intval(isConfigEntrySet('secret_key')).'/'.intval(isConfigEntrySet('master_salt')).'<br />');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, intval(isExtensionInstalled('sql_patches')) . '/' . intval(isConfigEntrySet('_PRIME')) . '/' . intval(isConfigEntrySet('secret_key')) . '/' . intval(isConfigEntrySet('master_salt')));
        if ((isExtensionInstalled('sql_patches')) && (isConfigEntrySet('_PRIME')) && (isConfigEntrySet('secret_key')) && (isConfigEntrySet('master_salt'))) {
                // Only calculate when the secret key is generated
-               //* DEBUG: */ outputHtml(__FUNCTION__.':'.strlen($passHash).'/'.strlen(getConfig('secret_key')).'<br />');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '/' . strlen(getConfig('secret_key')));
                if ((strlen($passHash) != 49) || (strlen(getConfig('secret_key')) != 40)) {
                        // Both keys must have same length so return unencrypted
-                       logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash).'!=49/'.strlen(getConfig('secret_key')).'!=40');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, strlen($passHash) . '!=49/' . strlen(getConfig('secret_key')) . '!=40');
                        return $ret;
                } // END - if
 
                $newHash = ''; $start = 9;
-               //* DEBUG: */ outputHtml('passHash=' . $passHash . '(' . strlen($passHash) . ')<br />');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'passHash=' . $passHash . '(' . strlen($passHash) . ')');
                for ($idx = 0; $idx < 20; $idx++) {
                        $part1 = hexdec(substr($passHash, ($idx * 2) + (strlen($passHash) - strlen(getConfig('secret_key'))), 2));
                        $part2 = hexdec(substr(getConfig('secret_key'), $start, 2));
-                       //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'<br />');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2);
                        $mod = dechex($idx);
                        if ($part1 > $part2) {
                                $mod = dechex(sqrt(($part1 - $part2) * getConfig('_PRIME') / pi()));
@@ -2259,19 +2305,19 @@ function encodeHashForCookie ($passHash) {
                                $mod = dechex(sqrt(($part2 - $part1) * getConfig('_PRIME') / pi()));
                        }
                        $mod = substr($mod, 0, 2);
-                       //* DEBUG: */ outputHtml('part1='.$part1.'/part2='.$part2.'/mod=' . $mod . '('.strlen($mod).')<br />');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'part1=' . $part1 . '/part2=' . $part2 . '/mod=' . $mod . '(' . strlen($mod) . ')');
                        $mod = str_repeat(0, (2 - strlen($mod))) . $mod;
-                       //* DEBUG: */ outputHtml('mod(' . ($idx * 2) . ')=' . $mod . '*<br />');
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'mod(' . ($idx * 2) . ')=' . $mod . '*');
                        $start += 2;
                        $newHash .= $mod;
                } // END - for
 
-               //* DEBUG: */ outputHtml($passHash . '<br />' . $newHash . ' (' . strlen($newHash) . ')<br />');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $passHash . ',' . $newHash . ' (' . strlen($newHash) . ')');
                $ret = generateHash($newHash, getConfig('master_salt'));
-               //* DEBUG: */ outputHtml('ret=' . $ret . '<br />');
        } // END - if
 
        // Return result
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ret=' . $ret . '');
        return $ret;
 }
 
@@ -2547,6 +2593,7 @@ function getMessageFromErrorCode ($code) {
                case getCode('MORE_RECEIVERS2')    : $message = getMessage('MEMBER_NO_MORE_RECEIVERS_FOUND'); break;
                case getCode('MORE_RECEIVERS3')    : $message = getMessage('MEMBER_ENTER_MORE_MIN_RECEIVERS'); break;
                case getCode('INVALID_URL')        : $message = getMessage('MEMBER_ENTER_INVALID_URL'); break;
+               case getCode('NO_MAIL_TYPE')       : $message = getMessage('MEMBER_NO_MAIL_TYPE_SELECTED'); break;
                case getCode('UNKNOWN_ERROR')      : $message = getMessage('LOGIN_UNKNOWN_ERROR'); break;
                case getCode('UNKNOWN_STATUS')     : $message = getMessage('LOGIN_UNKNOWN_STATUS'); break;
 
@@ -2631,7 +2678,7 @@ function compileUriCode ($code, $simple = true) {
        return $code;
 }
 
-// Function taken from user comments on www.php.net / function eregi()
+// Function taken from user comments on www.php.net / function isInStringIgnoreCase()
 function isUrlValidSimple ($url) {
        // Prepare URL
        $url = secureString(str_replace("\\", '', compileRawCode(urldecode($url))));
@@ -2674,11 +2721,12 @@ function isUrlValidSimple ($url) {
        $pattern['d1g12']  = $http . $domain1 . $getstring1;
        $pattern['d2g12']  = $http . $domain2 . $getstring1;
        $pattern['ipg12']  = $http . $ip . $getstring1;
+
        // Test all patterns
        $reg = false;
        foreach ($pattern as $key => $pat) {
                // Debug regex?
-               if (isDebugRegExpressionEnabled()) {
+               if (isDebugRegularExpressionEnabled()) {
                        // @TODO Are these convertions still required?
                        $pat = str_replace('.', "&#92;&#46;", $pat);
                        $pat = str_replace('@', "&#92;&#64;", $pat);
@@ -2686,7 +2734,7 @@ function isUrlValidSimple ($url) {
                } // END - if
 
                // Check if expression matches
-               $reg = ($reg || preg_match(('^' . $pat.'^'), $url));
+               $reg = ($reg || preg_match(('^' . $pat . '^'), $url));
 
                // Does it match?
                if ($reg === true) break;
@@ -2893,14 +2941,14 @@ function handleLoginFailures ($accessLevel) {
        $OUT = '';
 
        // Is the session data set?
-       if ((isSessionVariableSet('mxchange_' . $accessLevel . '_failures')) && (isSessionVariableSet('mxchange_' . $accessLevel . '_last_failure'))) {
+       if ((isSessionVariableSet('mailer_' . $accessLevel . '_failures')) && (isSessionVariableSet('mailer_' . $accessLevel . '_last_failure'))) {
                // Ignore zero values
-               if (getSession('mxchange_' . $accessLevel . '_failures') > 0) {
+               if (getSession('mailer_' . $accessLevel . '_failures') > 0) {
                        // Non-guest has login failures found, get both data and prepare it for template
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "accessLevel={$accessLevel}<br />");
                        $content = array(
-                               'login_failures' => getSession('mxchange_' . $accessLevel . '_failures'),
-                               'last_failure'   => generateDateTime(getSession('mxchange_' . $accessLevel . '_last_failure'), 2)
+                               'login_failures' => getSession('mailer_' . $accessLevel . '_failures'),
+                               'last_failure'   => generateDateTime(getSession('mailer_' . $accessLevel . '_last_failure'), 2)
                        );
 
                        // Load template
@@ -2908,8 +2956,8 @@ function handleLoginFailures ($accessLevel) {
                } // END - if
 
                // Reset session data
-               setSession('mxchange_' . $accessLevel . '_failures', '');
-               setSession('mxchange_' . $accessLevel . '_last_failure', '');
+               setSession('mailer_' . $accessLevel . '_failures', '');
+               setSession('mailer_' . $accessLevel . '_last_failure', '');
        } // END - if
 
        // Return rendered content
@@ -3686,7 +3734,7 @@ function sendModeMails ($mod, $modes) {
 }
 
 // Generates a 'selection box' from given array
-function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent) {
+function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionContent='') {
        // Start the output
        $OUT = '<select name="' . $name . '" size="1" class="admin_select">
 <option value="X" disabled="disabled">{--PLEASE_SELECT--}</option>';
@@ -3694,7 +3742,13 @@ function generateSelectionBoxFromArray ($options, $name, $optionValue, $optionCo
        // Walk through all options
        foreach ($options as $option) {
                // Add the <option> entry
-               $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
+               if (empty($optionContent)) {
+                       // ... from template
+                       $OUT .= loadTemplate('select_' . $name . '_option', true, $option);
+               } else {
+                       // Direct HTML code
+                       $OUT .= '<option value="' . $option[$optionValue] . '">' . $option[$optionContent] . '</option>';
+               }
        } // END - foreach
 
        // Finish selection box
@@ -3780,37 +3834,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'] .= '</head>';
+       runFilterChain('post_page_header');
 }
 
 // Adds page header and footer to output array element
@@ -3892,6 +3932,21 @@ 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;
+}
+
 //////////////////////////////////////////////////
 // AUTOMATICALLY RE-GENERATED MISSING FUNCTIONS //
 //////////////////////////////////////////////////