]> dev.renevier.net Git - syp.git/blob - items.php
popup contains link to original image
[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                     full_url_from_imgpath ($feature->imgpath)
27                     : "");
28         $lon = $feature->lon;
29         $lat = $feature->lat;
30         $alt = (strlen ($title) > 60) ?
31                     (substr ($title, 0, 57) . '...') :
32                     $title;
33
34         if ($imgurl) {
35             $imgurlHTML = sprintf ('<a href="%s"><img alt="%s" src="%s"></a>',
36                                     $imgurl, $alt, $imgurl);
37         } else {
38             $imgurlHTML = "";
39         }
40
41         if ($description) {
42             $descriptionHTML = sprintf ('<p>%s</p>', $description) ;
43         } else {
44             $descriptionHTML = "";
45         }
46
47         printf ('
48         <Placemark id="%s">
49             <name>%s</name>
50             <description><![CDATA[
51                 %s
52                 %s
53             ]]></description>
54             <Point>
55                 <coordinates>%s,%s</coordinates>
56             </Point>
57         </Placemark>
58 ', $id, $title, $descriptionHTML, $imgurlHTML, $lon, $lat);
59     }
60
61     echo' </Document>
62     </kml>';
63 }
64
65 try {
66     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
67     $features = $connection->listfeatures ();
68 } catch (Exception $e) {
69     exit ("server error");
70 }
71 header ("Content-type: application/vnd.google-earth.kml+xml");
72 main ($features);
73 ?>