]> dev.renevier.net Git - syp.git/blob - news.php
interface to change password
[syp.git] / news.php
1 <?php
2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
3    license. */
4
5 function headers_callback ($output) {
6     $etag = md5 ($output);
7     if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && 
8          ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
9          header ("HTTP/1.1 304 Not Modified");
10          exit ();
11     }
12
13     header ("Content-type: application/atom+xml; charset=UTF-8");
14     header ("Cache-control: must-revalidate");
15     header (sprintf ("ETag: %s", $etag));
16
17     return $output;
18 }
19
20 function date3339 ($feature) {
21     $date = date ('Y-m-d\TH:i:s', $feature->date);
22
23     $matches = array();
24     if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
25                     date ('O', $feature->date), $matches)) {
26         $date .= $matches [1] . $matches [2] . ':' . $matches [3];
27     } else {
28         $date .= 'Z';
29     }
30     return $date;
31 }
32
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);
37     return $res;
38 }
39
40 function unique_id_from_site () {
41     $id = md5 (full_url_from_path (""));
42     $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
43     return $res;
44 }
45
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");
50
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());
56
57     if (count ($features) > 0) {
58         printf("  <updated>%s</updated>\n", date3339 ($features[0]));
59     }
60
61     if (SITETITLE) {
62         printf ("  <title>%s</title>\n", htmlspecialchars (SITETITLE));
63     }
64
65     if (WEBMASTERMAIL) {
66         printf ("  <author>\n");
67         printf ("    <email>%s</email>\n", WEBMASTERMAIL);
68         printf("   </author>\n");
69     }
70
71     printf ("\n");
72
73     foreach ($features as $feature) {
74         printf ("    <entry>\n");
75
76         if ($feature->title) {
77             $title = htmlspecialchars ($feature->title, ENT_QUOTES);
78         } else {
79             $title = $feature->id;
80         }
81         printf ("      <title>%s</title>\n", $title);
82
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);
87
88         printf ("      <id>%s</id>\n", unique_id_from_feature ($feature));
89
90         printf ("      <updated>%s</updated>\n", date3339 ($feature));
91
92         if ($feature->description) {
93             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
94         } else {
95             $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
96         }
97
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);
106             }
107         }
108
109         if (strlen ($contentHTML) != 0) {
110             printf ("       <content type=\"html\">
111                 %s
112        </content>\n", htmlspecialchars ($contentHTML));
113         }
114
115         printf("      <georss:point>%.18F %.18F</georss:point>\n",
116                     $feature->lat, $feature->lon);
117
118         printf("    </entry>\n\n");
119     }
120     printf ("</feed>");
121 }
122
123 if (!@include_once ("./inc/settings.php")) {
124     exit ("server error");
125 }
126 require_once ("./inc/db/mysql.php");
127 require_once ("./inc/utils.php");
128
129 try {
130     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
131     $features = $connection->mostrecentfeatures (10);
132 } catch (Exception $e) {
133     exit ("server error");
134 }
135
136 ob_start ("headers_callback");
137 main ($features);
138 ob_end_flush ()
139 ?>