From 3deb4216cd947c4eb14b0a9e3b9f637ca25e77d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 22 Nov 2009 19:29:12 +0000 Subject: [PATCH] Fix for output to bots, 'slurp' is now detected --- inc/classes/rdf.class.php | 1 - inc/functions.php | 41 +++++++++++++++++++-------------------- inc/wrapper-functions.php | 12 ++++++++++-- index.php | 12 ++++++------ 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/inc/classes/rdf.class.php b/inc/classes/rdf.class.php index 4ae354b702..95190ff85b 100644 --- a/inc/classes/rdf.class.php +++ b/inc/classes/rdf.class.php @@ -419,7 +419,6 @@ class fase4_rdf { } else { return $this->out; } - flush(); $this->_garbage_collection(); } diff --git a/inc/functions.php b/inc/functions.php index 8b57a86193..d818478002 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -85,16 +85,7 @@ function outputHtml ($htmlCode, $newLine = true) { app_die(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--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)); } ////////////////////////////////////////////////// diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index de2d8c0fdb..d3369e758f 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -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) { + // 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 - // Send the header - header(trim($header)); + // Flush all headers + foreach ($GLOBALS['header'] as $header) { + header($header); + } // END - foreach } // Wrapper function for chmod() diff --git a/index.php b/index.php index 4c859b6e3b..df23da6814 100644 --- a/index.php +++ b/index.php @@ -55,15 +55,15 @@ require('inc/config-global.php'); // 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)) { + // 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 @@ -85,13 +85,13 @@ if ((isSessionVariableSet('visited')) || (getConfig('index_delay') > -1)) { // Load template loadTemplate('index_forward', false, $content); } // END - if + + // Footer + loadIncludeOnce('inc/footer.php'); } else { // Redirect to main page redirectToUrl('modules.php?module=index'); } -// Footer -loadIncludeOnce('inc/footer.php'); - // [EOF] ?> -- 2.39.2