]> dev.renevier.net Git - syp.git/blob - items.php
initial commit
[syp.git] / items.php
1 <?php
2 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
3    license. */
4
5 require ("./inc/settings.php");
6 require ("./inc/errors.php");
7 require ("./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         $title = htmlspecialchars ($feature->title, ENT_QUOTES);
21         $description = htmlspecialchars ($feature->description, ENT_QUOTES);
22         if (strpos ($feature->imgurl, "http://") === 0) {
23             $imgurl = "http://" . rawurlencode (substr($feature->imgurl, 7));
24         } else if (strpos ($feature->imgurl, "https://") === 0) {
25             $imgurl = "https://" . rawurlencode (substr ($feature->imgurl, 8));
26         } else {
27             $imgurl = rawurlencode ($feature->imgurl);
28         }
29         $imgurl = str_replace ('%2F', '/', $imgurl);
30         $lon = $feature->lon;
31         $lat = $feature->lat;
32         $alt = (strlen ($title) > 60) ?
33                     (substr ($title, 0, 57) . '...') :
34                     $title;
35
36         printf ('
37         <Placemark>
38             <name>%s</name>
39             <description><![CDATA[
40                 <p>%s</p>
41                 <img alt="%s" src="%s">
42             ]]></description>
43             <Point>
44                 <coordinates>%s,%s</coordinates>
45             </Point>
46         </Placemark>
47 ', $title, $description, $alt, $imgurl, $lon, $lat);
48     }
49
50     echo' </Document>
51     </kml>';
52 }
53
54 try {
55     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
56     $features = $connection->listfeatures ();
57 } catch (Exception $e) {
58     server_error ();
59 }
60 header ("Content-type: application/vnd.google-earth.kml+xml");
61 main ($features);
62 ?>