2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
5 require_once ("./inc/settings.php");
6 require_once ("./inc/db/mysql.php");
7 require_once ("./inc/utils.php");
9 function headers_callback ($output) {
10 $etag = md5 ($output);
11 if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) &&
12 ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
13 header ("HTTP/1.1 304 Not Modified");
17 header ("Content-type: application/atom+xml; charset=UTF-8");
18 header ("Cache-control: must-revalidate");
19 header (sprintf ("ETag: %s", $etag));
24 function date3339 ($feature) {
25 $date = date ('Y-m-d\TH:i:s', $feature->date);
28 if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
29 date ('O', $feature->date), $matches)) {
30 $date .= $matches [1] . $matches [2] . ':' . $matches [3];
37 // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
38 function unique_id_from_feature ($feature) {
39 $date = date('Y-m-d', $feature->date);
40 $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
44 function unique_id_from_site () {
45 $id = md5 (full_url_from_path (""));
46 $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
50 function main ($features) {
51 printf ("<?xml version=\"1.0\" encoding=\"utf-8\"?>
52 <feed xmlns=\"http://www.w3.org/2005/Atom\"
53 xmlns:georss=\"http://www.georss.org/georss\">\n");
55 printf(" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
56 full_url_from_path (""));
57 printf(" <link rel=\"self\" href=\"%s\" type=\"application/atom+xml\"/>\n",
58 full_url_from_path (basename ($_SERVER ["PHP_SELF"])));
59 printf(" <id>%s</id>\n", unique_id_from_site());
61 if (count ($features) > 0) {
62 printf(" <updated>%s</updated>\n", date3339 ($features[0]));
66 printf (" <title>%s</title>\n", SITETITLE);
70 printf (" <author>\n");
71 printf (" <email>%s</email>\n", WEBMASTERMAIL);
72 printf(" </author>\n");
77 foreach ($features as $feature) {
78 printf (" <entry>\n");
80 if ($feature->title) {
81 $title = htmlspecialchars ($feature->title, ENT_QUOTES);
83 $title = $feature->id;
85 printf (" <title>%s</title>\n", $title);
87 $rel_url = sprintf ("index.php?lat=%.18F&lon=%.18F&zoom=12",
88 $feature->lat, $feature->lon);
89 $link = htmlspecialchars (full_url_from_path ($rel_url), ENT_QUOTES);
90 printf (" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", $link);
92 printf (" <id>%s</id>\n", unique_id_from_feature ($feature));
94 printf (" <updated>%s</updated>\n", date3339 ($feature));
96 if ($feature->description) {
97 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
99 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
102 // FIXME: we consider thumbnail are correctly sized if gd library is
103 // installed. That may not always be true. For example if gd was installed
104 // after images were initially uploaded.
105 if (function_exists ("imagecreatefromjpeg")) {
106 if ($feature->imgpath) {
107 $imgurl = image_url_from_imgpath ($feature->imgpath);
108 $thumburl = thumb_url_from_imgpath ($feature->imgpath);
109 $contentHTML .= sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
113 if (strlen ($contentHTML) != 0) {
114 printf (" <content type=\"html\">
116 </content>\n", htmlspecialchars ($contentHTML));
119 printf(" <georss:point>%.18F %.18F</georss:point>\n",
120 $feature->lat, $feature->lon);
122 printf(" </entry>\n\n");
128 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
129 $features = $connection->mostrecentfeatures (10);
130 } catch (Exception $e) {
131 exit ("server error");
134 ob_start ("headers_callback");