]> dev.renevier.net Git - syp.git/blobdiff - news.php
implements ETag caching for items.php and news.php
[syp.git] / news.php
index 9bdefd18cc54da0821569ad5a97956d75804b080..6eb78e63efe9e10ff3258fb9c7f3407d4b8b59bb 100644 (file)
--- a/news.php
+++ b/news.php
@@ -6,8 +6,20 @@ require_once ("./inc/settings.php");
 require_once ("./inc/db/mysql.php");
 require_once ("./inc/utils.php");
 
-header ("Content-type: application/atom+xml; charset=UTF-8");
-header("Cache-control: no-cache");
+function headers_callback ($output) {
+    $etag = md5 ($output);
+    if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && 
+         ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
+         header ("HTTP/1.1 304 Not Modified");
+         exit ();
+    }
+
+    header ("Content-type: application/atom+xml; charset=UTF-8");
+    header ("Cache-control: must-revalidate");
+    header (sprintf ("ETag: %s", $etag));
+
+    return $output;
+}
 
 function date3339 ($feature) {
     $date = date ('Y-m-d\TH:i:s', $feature->date);
@@ -87,6 +99,17 @@ function main ($features) {
             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
         }
 
+        // FIXME: we consider thumbnail are correctly sized if gd library is
+        // installed. That may not always be true. For example if gd was installed
+        // after images were initially uploaded.
+        if (function_exists ("imagecreatefromjpeg")) { 
+            if ($feature->imgpath) {
+                $imgurl = image_url_from_imgpath ($feature->imgpath);
+                $thumburl = thumb_url_from_imgpath ($feature->imgpath);
+                $contentHTML .= sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
+            }
+        }
+
         if (strlen ($contentHTML) != 0) {
             printf ("       <content type=\"html\">
                 %s
@@ -107,5 +130,8 @@ try {
 } catch (Exception $e) {
     exit ("server error");
 }
+
+ob_start ("headers_callback");
 main ($features);
+ob_end_flush ()
 ?>