]> dev.renevier.net Git - syp.git/blob - news.php
fix broken script in wizard.php
[syp.git] / news.php
1 <?php
2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
3    license. */
4
5 require_once ("./inc/settings.php");
6 require_once ("./inc/db/mysql.php");
7 require_once ("./inc/utils.php");
8
9 header ("Content-type: application/atom+xml; charset=UTF-8");
10 header("Cache-control: no-cache");
11
12 function date3339 ($feature) {
13     $date = date ('Y-m-d\TH:i:s', $feature->date);
14
15     $matches = array();
16     if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
17                     date ('O', $feature->date), $matches)) {
18         $date .= $matches [1] . $matches [2] . ':' . $matches [3];
19     } else {
20         $date .= 'Z';
21     }
22     return $date;
23 }
24
25 // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
26 function unique_id_from_feature ($feature) {
27     $date = date('Y-m-d', $feature->date);
28     $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
29     return $res;
30 }
31
32 function unique_id_from_site () {
33     $id = md5 (full_url_from_path (""));
34     $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
35     return $res;
36 }
37
38 function main ($features) {
39     printf ("<?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");
42
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());
48
49     if (count ($features) > 0) {
50         printf("  <updated>%s</updated>\n", date3339 ($features[0]));
51     }
52
53     if (SITETITLE) {
54         printf ("  <title>%s</title>\n", SITETITLE);
55     }
56
57     if (WEBMASTERMAIL) {
58         printf ("  <author>\n");
59         printf ("    <email>%s</email>\n", WEBMASTERMAIL);
60         printf("   </author>\n");
61     }
62
63     printf ("\n");
64
65     foreach ($features as $feature) {
66         printf ("    <entry>\n");
67
68         if ($feature->title) {
69             $title = htmlspecialchars ($feature->title, ENT_QUOTES);
70         } else {
71             $title = $feature->id;
72         }
73         printf ("      <title>%s</title>\n", $title);
74
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);
79
80         printf ("      <id>%s</id>\n", unique_id_from_feature ($feature));
81
82         printf ("      <updated>%s</updated>\n", date3339 ($feature));
83
84         if ($feature->description) {
85             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
86         } else {
87             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
88         }
89
90         if (strlen ($contentHTML) != 0) {
91             printf ("       <content type=\"html\">
92                 %s
93        </content>\n", htmlspecialchars ($contentHTML));
94         }
95
96         printf("      <georss:point>%.18F %.18F</georss:point>\n",
97                     $feature->lat, $feature->lon);
98
99         printf("    </entry>\n\n");
100     }
101     printf ("</feed>");
102 }
103
104 try {
105     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
106     $features = $connection->mostrecentfeatures (10);
107 } catch (Exception $e) {
108     exit ("server error");
109 }
110 main ($features);
111 ?>