X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=news.php;h=6eb78e63efe9e10ff3258fb9c7f3407d4b8b59bb;hp=615989f0fb3d00318808ecea45fe3487b02c2ae6;hb=41c341624c16607ac710aac446cc0ead3c53671b;hpb=e4a4e5149d55cf01a86f26392c52fdca803654ce diff --git a/news.php b/news.php index 615989f..6eb78e6 100644 --- 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); @@ -22,8 +34,8 @@ function date3339 ($feature) { return $date; } +// method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other 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; @@ -36,9 +48,9 @@ function unique_id_from_site () { } function main ($features) { - print " + printf (" \n"; + xmlns:georss=\"http://www.georss.org/georss\">\n"); printf(" \n", full_url_from_path ("")); @@ -60,10 +72,10 @@ function main ($features) { printf(" \n"); } - print "\n"; + printf ("\n"); foreach ($features as $feature) { - print (" \n"); + printf (" \n"); if ($feature->title) { $title = htmlspecialchars ($feature->title, ENT_QUOTES); @@ -87,8 +99,19 @@ function main ($features) { $contentHTML = sprintf ("

%s

", 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 ('%s', $imgurl, $alt, $thumburl); + } + } + if (strlen ($contentHTML) != 0) { - printf(" + printf (" %s \n", htmlspecialchars ($contentHTML)); } @@ -98,7 +121,7 @@ function main ($features) { printf("
\n\n"); } - print '
'; + printf (""); } try { @@ -107,5 +130,8 @@ try { } catch (Exception $e) { exit ("server error"); } + +ob_start ("headers_callback"); main ($features); +ob_end_flush () ?>