2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 function headers_callback ($output) {
7 if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) &&
8 ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
9 header ("HTTP/1.1 304 Not Modified");
13 header ("Content-type: application/atom+xml; charset=UTF-8");
14 header ("Cache-control: must-revalidate");
15 header (sprintf ("ETag: %s", $etag));
20 function date3339 ($feature) {
21 $date = date ('Y-m-d\TH:i:s', $feature->date);
24 if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
25 date ('O', $feature->date), $matches)) {
26 $date .= $matches [1] . $matches [2] . ':' . $matches [3];
33 // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
34 function unique_id_from_feature ($feature) {
35 $date = date('Y-m-d', $feature->date);
36 $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
40 function unique_id_from_site () {
41 $id = md5 (full_url_from_path (""));
42 $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
46 function main ($features) {
47 printf ("<?xml version=\"1.0\" encoding=\"utf-8\"?>
48 <feed xmlns=\"http://www.w3.org/2005/Atom\"
49 xmlns:georss=\"http://www.georss.org/georss\">\n");
51 printf(" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
52 full_url_from_path (""));
53 printf(" <link rel=\"self\" href=\"%s\" type=\"application/atom+xml\"/>\n",
54 full_url_from_path (basename ($_SERVER ["PHP_SELF"])));
55 printf(" <id>%s</id>\n", unique_id_from_site());
57 if (count ($features) > 0) {
58 printf(" <updated>%s</updated>\n", date3339 ($features[0]));
62 printf (" <title>%s</title>\n", htmlspecialchars (SITETITLE));
66 printf (" <author>\n");
67 printf (" <email>%s</email>\n", WEBMASTERMAIL);
68 printf(" </author>\n");
73 foreach ($features as $feature) {
74 printf (" <entry>\n");
76 if ($feature->title) {
77 $title = htmlspecialchars ($feature->title, ENT_QUOTES);
79 $title = $feature->id;
81 printf (" <title>%s</title>\n", $title);
83 $rel_url = sprintf ("index.php?lat=%.18F&lon=%.18F&zoom=12",
84 $feature->lat, $feature->lon);
85 $link = htmlspecialchars (full_url_from_path ($rel_url), ENT_QUOTES);
86 printf (" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", $link);
88 printf (" <id>%s</id>\n", unique_id_from_feature ($feature));
90 printf (" <updated>%s</updated>\n", date3339 ($feature));
92 if ($feature->description) {
93 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
95 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
98 // FIXME: we consider thumbnail are correctly sized if gd library is
99 // installed. That may not always be true. For example if gd was installed
100 // after images were initially uploaded.
101 if (function_exists ("imagecreatefromjpeg")) {
102 if ($feature->imgpath) {
103 $imgurl = image_url_from_imgpath ($feature->imgpath);
104 $thumburl = thumb_url_from_imgpath ($feature->imgpath);
105 $contentHTML .= sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
109 if (strlen ($contentHTML) != 0) {
110 printf (" <content type=\"html\">
112 </content>\n", htmlspecialchars ($contentHTML));
115 printf(" <georss:point>%.18F %.18F</georss:point>\n",
116 $feature->lat, $feature->lon);
118 printf(" </entry>\n\n");
123 if (!@include_once ("./inc/settings.php")) {
124 exit ("server error");
126 require_once ("./inc/db/mysql.php");
127 require_once ("./inc/utils.php");
130 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
131 $features = $connection->mostrecentfeatures (10);
132 } catch (Exception $e) {
133 exit ("server error");
136 ob_start ("headers_callback");