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