| 1 | <?php |
|---|
| 2 | ############################################################################### |
|---|
| 3 | # Gregarius - A PHP based RSS aggregator. |
|---|
| 4 | # Copyright (C) 2003 - 2006 Marco Bonetti |
|---|
| 5 | # |
|---|
| 6 | ############################################################################### |
|---|
| 7 | # This program is free software and open source software; you can redistribute |
|---|
| 8 | # it and/or modify it under the terms of the GNU General Public License as |
|---|
| 9 | # published by the Free Software Foundation; either version 2 of the License, |
|---|
| 10 | # or (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 14 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 15 | # more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License along |
|---|
| 18 | # with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 19 | # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit |
|---|
| 20 | # http://www.gnu.org/licenses/gpl.html |
|---|
| 21 | # |
|---|
| 22 | ############################################################################### |
|---|
| 23 | # E-mail: mbonetti at gmail dot com |
|---|
| 24 | # Web page: http://gregarius.net/ |
|---|
| 25 | # |
|---|
| 26 | ############################################################################### |
|---|
| 27 | |
|---|
| 28 | if (!defined('GREGARIUS_HOME')) { |
|---|
| 29 | define('GREGARIUS_HOME',dirname(__FILE__) . "/"); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function rss_bootstrap($withDB = true, $etag_prefix= "", $cacheValidity=0) { |
|---|
| 33 | require_once(GREGARIUS_HOME . 'constants.php'); |
|---|
| 34 | if ($withDB) { |
|---|
| 35 | require_once(GREGARIUS_HOME . 'db.php'); |
|---|
| 36 | } |
|---|
| 37 | if (!defined('RSS_NO_CACHE')) { |
|---|
| 38 | checkETag($withDB,$etag_prefix,$cacheValidity); |
|---|
| 39 | } |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | function checkETag($withDB = true, $keyPrefix= "", $cacheValidity = 0) { |
|---|
| 44 | $key = $keyPrefix.'$Revision$'.$_SERVER["REQUEST_URI"]; |
|---|
| 45 | if ($withDB) { |
|---|
| 46 | list($dt) = rss_fetch_row(rss_query('select timestamp from ' .getTable('cache') . " where cachekey='data_ts'")); |
|---|
| 47 | $key .= $dt; |
|---|
| 48 | } |
|---|
| 49 | if (array_key_exists(RSS_USER_COOKIE,$_REQUEST)) { |
|---|
| 50 | $key .= $_REQUEST[RSS_USER_COOKIE]; |
|---|
| 51 | } |
|---|
| 52 | $key = md5($key); |
|---|
| 53 | |
|---|
| 54 | if (array_key_exists('HTTP_IF_NONE_MATCH',$_SERVER) && $_SERVER['HTTP_IF_NONE_MATCH'] == $key) { |
|---|
| 55 | header("HTTP/1.1 304 Not Modified"); |
|---|
| 56 | header("X-RSS-CACHE-STATUS: HIT"); |
|---|
| 57 | header("ETag: $key"); |
|---|
| 58 | flush(); |
|---|
| 59 | exit(); |
|---|
| 60 | } else { |
|---|
| 61 | header("ETag: $key"); |
|---|
| 62 | header("X-RSS-CACHE-STATUS: MISS"); |
|---|
| 63 | if ($cacheValidity) { |
|---|
| 64 | header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $cacheValidity*3600) . 'GMT'); |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | ?> |
|---|