Fix for output to bots, 'slurp' is now detected
[mailer.git] / inc / functions.php
index 8b57a86193d01dc66057c3f842a76b04404fe358..d81847800247afa6b9d8babb914eee11fe86bf88 100644 (file)
@@ -85,16 +85,7 @@ function outputHtml ($htmlCode, $newLine = true) {
                                app_die(__FUNCTION__, __LINE__, '<strong>{--FATAL_ERROR--}:</strong> {--LANG_NO_RENDER_DIRECT--}');
                                break;
                } // END - switch
-       } elseif ((getPhpCaching() == 'on') && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
-               // Headers already sent?
-               if (headers_sent()) {
-                       // Log this error
-                       logDebugMessage(__FUNCTION__, __LINE__, 'Headers already sent! We need debug backtrace here.');
-
-                       // Trigger an user error
-                       debug_report_bug('Headers are already sent!');
-               } // END - if
-
+       } elseif (getPhpCaching() == 'on') {
                // Output cached HTML code
                $GLOBALS['output'] = ob_get_contents();
 
@@ -142,7 +133,7 @@ function sendHttpHeaders () {
        sendHeader('HTTP/1.1 200');
 
        // General headers for no caching
-       sendHeader('Expired: ' . $now); // RFC2616 - Section 14.21
+       sendHeader('Expires: ' . $now); // RFC2616 - Section 14.21
        sendHeader('Last-Modified: ' . $now);
        sendHeader('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
        sendHeader('Pragma: no-cache'); // HTTP/1.0
@@ -177,8 +168,20 @@ function compileFinalOutput () {
                $cnt++;
        } // END - while
 
+       // Compress it?
+       if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
+               // Compress it
+               $GLOBALS['output'] = gzencode($GLOBALS['output'], 9, true);
+
+               // Add header
+               sendHeader('Content-Encoding: gzip');
+       } // END - if
+
        // Add final length
        sendHeader('Content-Length: ' . strlen($GLOBALS['output']));
+
+       // Flush all headers
+       flushHeaders();
 }
 
 // Output the raw HTML code
@@ -918,14 +921,6 @@ function redirectToUrl ($URL) {
                $rel = '';
        } // END - if
 
-       // Get output buffer
-       $GLOBALS['output'] = ob_get_contents();
-
-       // Clear it only if there is content
-       if (!empty($GLOBALS['output'])) {
-               clearOutputBuffer();
-       } // END - if
-
        // Three different ways to debug...
        //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
@@ -3828,6 +3823,7 @@ function encodeUrl ($url, $outputMode = '0') {
 
                // Add it to URL
                if (session_id() != '') {
+                       die($url);
                        $url .= $seperator . session_name() . '=' . session_id();
                } // END - if
        } // END - if
@@ -3844,11 +3840,14 @@ function encodeUrl ($url, $outputMode = '0') {
 
 // Simple check for spider
 function isSpider () {
+       // Get the UA
+       $userAgent = strtolower(detectUserAgent(true));
+
        // It should not be empty, if so it is better a spider/bot
-       if (detectUserAgent(true) == '') return true;
+       if (empty($userAgent)) return true;
 
        // Is it a spider?
-       return ((strpos('spider', strtolower(detectUserAgent(true))) !== false) || (strpos('bot', strtolower(detectUserAgent(true))) !== false));
+       return ((strpos($userAgent, 'spider') !== false) || (strpos($userAgent, 'slurp') !== false) || (strpos($userAgent, 'bot') !== false));
 }
 
 //////////////////////////////////////////////////