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