X-Git-Url: https://dev.renevier.net/gitweb.cgi?p=syp.git;a=blobdiff_plain;f=news.php;h=886b00e5ff2f6cbb2dea20191cf1b7f56bf90b8e;hp=9bdefd18cc54da0821569ad5a97956d75804b080;hb=4414f33ecd172ea188660a45c8d8fb3469416d4f;hpb=4acc8da49e3d4083fd9906388dd8fe0212bb9f42 diff --git a/news.php b/news.php index 9bdefd1..886b00e 100644 --- a/news.php +++ b/news.php @@ -2,12 +2,20 @@ /* 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); @@ -51,7 +59,7 @@ function main ($features) { } if (SITETITLE) { - printf (" %s\n", SITETITLE); + printf (" %s\n", htmlspecialchars (SITETITLE)); } if (WEBMASTERMAIL) { @@ -87,6 +95,17 @@ 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 (" %s @@ -101,11 +120,20 @@ function main ($features) { printf (""); } +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"); } + +ob_start ("headers_callback"); main ($features); +ob_end_flush () ?>