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 header ("Content-type: application/atom+xml; charset=UTF-8");
10 header("Cache-control: no-cache");
12 function date3339 ($feature) {
13 $date = date ('Y-m-d\TH:i:s', $feature->date);
16 if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
17 date ('O', $feature->date), $matches)) {
18 $date .= $matches [1] . $matches [2] . ':' . $matches [3];
25 function unique_id_from_feature ($feature) {
26 // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
27 $date = date('Y-m-d', $feature->date);
28 $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
32 function unique_id_from_site () {
33 $id = md5 (full_url_from_path (""));
34 $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
38 function main ($features) {
39 print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
40 <feed xmlns=\"http://www.w3.org/2005/Atom\"
41 xmlns:georss=\"http://www.georss.org/georss\">\n";
43 printf(" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
44 full_url_from_path (""));
45 printf(" <link rel=\"self\" href=\"%s\" type=\"application/atom+xml\"/>\n",
46 full_url_from_path (basename ($_SERVER ["PHP_SELF"])));
47 printf(" <id>%s</id>\n", unique_id_from_site());
49 if (count ($features) > 0) {
50 printf(" <updated>%s</updated>\n", date3339 ($features[0]));
54 printf (" <title>%s</title>\n", SITETITLE);
58 printf (" <author>\n");
59 printf (" <email>%s</email>\n", WEBMASTERMAIL);
60 printf(" </author>\n");
65 foreach ($features as $feature) {
68 if ($feature->title) {
69 $title = htmlspecialchars ($feature->title, ENT_QUOTES);
71 $title = $feature->id;
73 printf (" <title>%s</title>\n", $title);
75 $rel_url = sprintf ("index.php?lat=%.18F&lon=%.18F&zoom=12",
76 $feature->lat, $feature->lon);
77 $link = htmlspecialchars (full_url_from_path ($rel_url), ENT_QUOTES);
78 printf (" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", $link);
80 printf (" <id>%s</id>\n", unique_id_from_feature ($feature));
82 printf (" <updated>%s</updated>\n", date3339 ($feature));
84 if ($feature->description) {
85 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
87 $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
90 if (strlen ($contentHTML) != 0) {
91 printf(" <content type=\"html\">
93 </content>\n", htmlspecialchars ($contentHTML));
96 printf(" <georss:point>%.18F %.18F</georss:point>\n",
97 $feature->lat, $feature->lon);
99 printf(" </entry>\n\n");
105 $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
106 $features = $connection->mostrecentfeatures (10);
107 } catch (Exception $e) {
108 exit ("server error");