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