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