Fix for output to bots, 'slurp' is now detected
authorRoland Häder <roland@mxchange.org>
Sun, 22 Nov 2009 19:29:12 +0000 (19:29 +0000)
committerRoland Häder <roland@mxchange.org>
Sun, 22 Nov 2009 19:29:12 +0000 (19:29 +0000)
inc/classes/rdf.class.php
inc/functions.php
inc/wrapper-functions.php
index.php

index 4ae354b7028c73e0ba913fe99aba6b4173792a13..95190ff85bdafb28e2185127d6f4cd56266a8a60 100644 (file)
@@ -419,7 +419,6 @@ class fase4_rdf {
                } else {
                        return $this->out;
                }
                } else {
                        return $this->out;
                }
-               flush();
                $this->_garbage_collection();
        }
 
                $this->_garbage_collection();
        }
 
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
                                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();
 
                // 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('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
        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
 
                $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']));
        // Add final length
        sendHeader('Content-Length: ' . strlen($GLOBALS['output']));
+
+       // Flush all headers
+       flushHeaders();
 }
 
 // Output the raw HTML code
 }
 
 // Output the raw HTML code
@@ -918,14 +921,6 @@ function redirectToUrl ($URL) {
                $rel = '';
        } // END - if
 
                $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);
        // 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() != '') {
 
                // Add it to URL
                if (session_id() != '') {
+                       die($url);
                        $url .= $seperator . session_name() . '=' . session_id();
                } // END - if
        } // END - if
                        $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 () {
 
 // 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
        // 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?
 
        // 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));
 }
 
 //////////////////////////////////////////////////
 }
 
 //////////////////////////////////////////////////
index de2d8c0fdb9c613f1c536a6b6047d13474174ccf..d3369e758f78a10f6dcbbbf750394c2aa1e88e34 100644 (file)
@@ -379,14 +379,22 @@ function copyFileVerified ($source, $dest, $chmod = '') {
 // Wrapper function for header()
 // Send a header but checks before if we can do so
 function sendHeader ($header) {
 // Wrapper function for header()
 // Send a header but checks before if we can do so
 function sendHeader ($header) {
+       // Send the header
+       $GLOBALS['header'][] = trim($header);
+}
+
+// Flushes all headers
+function flushHeaders () {
        // Is the header already sent?
        if (headers_sent()) {
                // Then abort here
                debug_report_bug('Headers already sent!');
        } // END - if
 
        // Is the header already sent?
        if (headers_sent()) {
                // Then abort here
                debug_report_bug('Headers already sent!');
        } // END - if
 
-       // Send the header
-       header(trim($header));
+       // Flush all headers
+       foreach ($GLOBALS['header'] as $header) {
+               header($header);
+       } // END - foreach
 }
 
 // Wrapper function for chmod()
 }
 
 // Wrapper function for chmod()
index 4c859b6e3bd957111e0efedac2df685c8075226e..df23da6814c7eb4e87303f571dbbab9fb274e48d 100644 (file)
--- a/index.php
+++ b/index.php
@@ -55,15 +55,15 @@ require('inc/config-global.php');
 // Set content type
 setContentType('text/html');
 
 // Set content type
 setContentType('text/html');
 
-// Header
-loadIncludeOnce('inc/header.php');
-
 // Fix missing array elements here
 if (!isConfigEntrySet('index_delay'))  setConfigEntry('index_delay' , 0);
 if (!isConfigEntrySet('index_cookie')) setConfigEntry('index_cookie', 0);
 
 // Check for cookies
 if ((isSessionVariableSet('visited')) || (getConfig('index_delay') > -1)) {
 // Fix missing array elements here
 if (!isConfigEntrySet('index_delay'))  setConfigEntry('index_delay' , 0);
 if (!isConfigEntrySet('index_cookie')) setConfigEntry('index_cookie', 0);
 
 // Check for cookies
 if ((isSessionVariableSet('visited')) || (getConfig('index_delay') > -1)) {
+       // Header
+       loadIncludeOnce('inc/header.php');
+
        // Is the index page configured for redirect pr not?
        if (getConfig('index_cookie') > 0) {
                // Set cookie and remeber it for specified time
        // Is the index page configured for redirect pr not?
        if (getConfig('index_cookie') > 0) {
                // Set cookie and remeber it for specified time
@@ -85,13 +85,13 @@ if ((isSessionVariableSet('visited')) || (getConfig('index_delay') > -1)) {
                // Load template
                loadTemplate('index_forward', false, $content);
        } // END - if
                // Load template
                loadTemplate('index_forward', false, $content);
        } // END - if
+
+       // Footer
+       loadIncludeOnce('inc/footer.php');
 } else {
        // Redirect to main page
        redirectToUrl('modules.php?module=index');
 }
 
 } else {
        // Redirect to main page
        redirectToUrl('modules.php?module=index');
 }
 
-// Footer
-loadIncludeOnce('inc/footer.php');
-
 // [EOF]
 ?>
 // [EOF]
 ?>