]> dev.renevier.net Git - syp.git/blobdiff - news.php
bump to version 0.4
[syp.git] / news.php
index 615989f0fb3d00318808ecea45fe3487b02c2ae6..886b00e5ff2f6cbb2dea20191cf1b7f56bf90b8e 100644 (file)
--- a/news.php
+++ b/news.php
@@ -2,12 +2,20 @@
 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
    license. */
 
 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
    license. */
 
-require_once ("./inc/settings.php");
-require_once ("./inc/db/mysql.php");
-require_once ("./inc/utils.php");
+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));
 
 
-header ("Content-type: application/atom+xml; charset=UTF-8");
-header("Cache-control: no-cache");
+    return $output;
+}
 
 function date3339 ($feature) {
     $date = date ('Y-m-d\TH:i:s', $feature->date);
 
 function date3339 ($feature) {
     $date = date ('Y-m-d\TH:i:s', $feature->date);
@@ -22,8 +30,8 @@ function date3339 ($feature) {
     return $date;
 }
 
     return $date;
 }
 
+// method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
 function unique_id_from_feature ($feature) {
 function unique_id_from_feature ($feature) {
-    // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
     $date = date('Y-m-d', $feature->date);
     $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
     return $res;
     $date = date('Y-m-d', $feature->date);
     $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
     return $res;
@@ -36,9 +44,9 @@ function unique_id_from_site () {
 }
 
 function main ($features) {
 }
 
 function main ($features) {
-    print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
+    printf ("<?xml version=\"1.0\" encoding=\"utf-8\"?>
 <feed xmlns=\"http://www.w3.org/2005/Atom\"
 <feed xmlns=\"http://www.w3.org/2005/Atom\"
-      xmlns:georss=\"http://www.georss.org/georss\">\n";
+      xmlns:georss=\"http://www.georss.org/georss\">\n");
 
     printf("  <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
             full_url_from_path (""));
 
     printf("  <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
             full_url_from_path (""));
@@ -51,7 +59,7 @@ function main ($features) {
     }
 
     if (SITETITLE) {
     }
 
     if (SITETITLE) {
-        printf ("  <title>%s</title>\n", SITETITLE);
+        printf ("  <title>%s</title>\n", htmlspecialchars (SITETITLE));
     }
 
     if (WEBMASTERMAIL) {
     }
 
     if (WEBMASTERMAIL) {
@@ -60,10 +68,10 @@ function main ($features) {
         printf("   </author>\n");
     }
 
         printf("   </author>\n");
     }
 
-    print "\n";
+    printf ("\n");
 
     foreach ($features as $feature) {
 
     foreach ($features as $feature) {
-        print ("    <entry>\n");
+        printf ("    <entry>\n");
 
         if ($feature->title) {
             $title = htmlspecialchars ($feature->title, ENT_QUOTES);
 
         if ($feature->title) {
             $title = htmlspecialchars ($feature->title, ENT_QUOTES);
@@ -87,8 +95,19 @@ function main ($features) {
             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
         }
 
             $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) {
         if (strlen ($contentHTML) != 0) {
-            printf("       <content type=\"html\">
+            printf ("       <content type=\"html\">
                 %s
        </content>\n", htmlspecialchars ($contentHTML));
         }
                 %s
        </content>\n", htmlspecialchars ($contentHTML));
         }
@@ -98,14 +117,23 @@ function main ($features) {
 
         printf("    </entry>\n\n");
     }
 
         printf("    </entry>\n\n");
     }
-    print '</feed>';
+    printf ("</feed>");
 }
 
 }
 
+if (!@include_once ("./inc/settings.php")) {
+    exit ("server error");
+}
+require_once ("./inc/db/" . (defined ("DBTYPE")? DBTYPE: "mysql") . ".php");
+require_once ("./inc/utils.php");
+
 try {
     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
     $features = $connection->mostrecentfeatures (10);
 } catch (Exception $e) {
     exit ("server error");
 }
 try {
     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
     $features = $connection->mostrecentfeatures (10);
 } catch (Exception $e) {
     exit ("server error");
 }
+
+ob_start ("headers_callback");
 main ($features);
 main ($features);
+ob_end_flush ()
 ?>
 ?>