]> dev.renevier.net Git - syp.git/blobdiff - items.php
real api and clearer separation between server and client
[syp.git] / items.php
index f816cfbeb25f1f8b060779ea105bef8afed77095..bcf5f1fc9757c50b33097c72bec649a0c9f738f4 100644 (file)
--- a/items.php
+++ b/items.php
@@ -2,9 +2,9 @@
 /* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
    license. */
 
-require ("./inc/settings.php");
-require ("./inc/errors.php");
-require ("./inc/db/mysql.php");
+require_once ("./inc/settings.php");
+require_once ("./inc/utils.php");
+require_once ("./inc/db/mysql.php");
 
 function main ($features) {
 
@@ -17,34 +17,42 @@ function main ($features) {
         printf ('    <name>%s</name>', SITETITLE);
     }
     foreach ($features as $feature) {
+        $id = $feature->id;
         $title = htmlspecialchars ($feature->title, ENT_QUOTES);
         $description = htmlspecialchars ($feature->description, ENT_QUOTES);
-        if (strpos ($feature->imgurl, "http://") === 0) {
-            $imgurl = "http://" . rawurlencode (substr($feature->imgurl, 7));
-        } else if (strpos ($feature->imgurl, "https://") === 0) {
-            $imgurl = "https://" . rawurlencode (substr ($feature->imgurl, 8));
-        } else {
-            $imgurl = rawurlencode ($feature->imgurl);
-        }
-        $imgurl = str_replace ('%2F', '/', $imgurl);
+        $imgurl = ($feature->imgpath ? 
+                    full_url_from_filename ($feature->imgpath)
+                    : "");
         $lon = $feature->lon;
         $lat = $feature->lat;
         $alt = (strlen ($title) > 60) ?
                     (substr ($title, 0, 57) . '...') :
                     $title;
 
+        if ($imgurl) {
+            $imgurlHTML = sprintf ('<img alt="%s" src="%s">', $alt, $imgurl);
+        } else {
+            $imgurlHTML = "";
+        }
+
+        if ($description) {
+            $descriptionHTML = sprintf ('<p>%s</p>', $description) ;
+        } else {
+            $descriptionHTML = "";
+        }
+
         printf ('
-        <Placemark>
+        <Placemark id="%s">
             <name>%s</name>
             <description><![CDATA[
-                <p>%s</p>
-                <img alt="%s" src="%s">
+                %s
+                %s
             ]]></description>
             <Point>
                 <coordinates>%s,%s</coordinates>
             </Point>
         </Placemark>
-', $title, $description, $alt, $imgurl, $lon, $lat);
+', $id, $title, $descriptionHTML, $imgurlHTML, $lon, $lat);
     }
 
     echo' </Document>
@@ -55,7 +63,7 @@ try {
     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
     $features = $connection->listfeatures ();
 } catch (Exception $e) {
-    server_error ();
+    exit ("server error");
 }
 header ("Content-type: application/vnd.google-earth.kml+xml");
 main ($features);