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