]> dev.renevier.net Git - syp.git/blob - items.php
do not allow empty passwords
[syp.git] / items.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/vnd.google-earth.kml+xml");
14     // no-cache is needed otherwise IE does not try to get new version.
15     header ("Cache-control: no-cache, must-revalidate");
16     header (sprintf ("ETag: %s", $etag));
17
18     return $output;
19 }
20
21 function main ($features) {
22
23     echo '<?xml version="1.0" encoding="UTF-8"?>
24 <kml xmlns="http://www.opengis.net/kml/2.2">
25   <Document>
26 ';
27
28     if (SITETITLE) {
29         printf ('    <name>%s</name>', htmlspecialchars (SITETITLE));
30     }
31     foreach ($features as $feature) {
32         $id = $feature->id;
33         $title = htmlspecialchars ($feature->title, ENT_QUOTES);
34         $description = htmlspecialchars ($feature->description, ENT_QUOTES);
35         $imgurl = ($feature->imgpath ? 
36                     image_url_from_imgpath ($feature->imgpath)
37                     : "");
38         $thumburl = ($feature->imgpath ? 
39                     thumb_url_from_imgpath ($feature->imgpath)
40                     : "");
41         $lon = $feature->lon;
42         $lat = $feature->lat;
43         $alt = (strlen ($title) > 60) ?
44                     (substr ($title, 0, 57) . '...') :
45                     $title;
46
47         if ($imgurl) {
48             $imgurlHTML = sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
49         } else {
50             $imgurlHTML = "";
51         }
52
53         if ($description) {
54             $descriptionHTML = sprintf ('<p>%s</p>', $description) ;
55         } else {
56             $descriptionHTML = "";
57         }
58
59         printf ('
60         <Placemark id="%s">
61             <name>%s</name>
62             <description><![CDATA[
63                 %s
64                 %s
65             ]]></description>
66             <Point>
67                 <coordinates>%s,%s</coordinates>
68             </Point>
69         </Placemark>
70 ', $id, $title, $descriptionHTML, $imgurlHTML, $lon, $lat);
71     }
72
73     echo' </Document>
74     </kml>';
75 }
76
77 if (!@include_once ("./inc/settings.php")) {
78     exit ("server error");
79 }
80 require_once ("./inc/utils.php");
81 require_once ("./inc/db/mysql.php");
82
83 try {
84     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
85     $features = $connection->listfeatures ($_GET ['from_user']);
86 } catch (Exception $e) {
87     exit ("server error");
88 }
89
90 ob_start ("headers_callback");
91 main ($features);
92 ob_end_flush ()
93 ?>