]> dev.renevier.net Git - syp.git/blobdiff - items.php
web interface to add co-administrators
[syp.git] / items.php
index f816cfbeb25f1f8b060779ea105bef8afed77095..a2a04464e398110e1cd1e2bc71f66b3d87a9e3c8 100644 (file)
--- a/items.php
+++ b/items.php
@@ -2,9 +2,20 @@
 /* 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");
+function headers_callback ($output) {
+    $etag = md5 ($output);
+    if ((isset ($_SERVER ["HTTP_IF_NONE_MATCH"])) && 
+         ($_SERVER ["HTTP_IF_NONE_MATCH"] == $etag)) {
+         header ("HTTP/1.1 304 Not Modified");
+         exit ();
+    }
+
+    header ("Content-type: application/vnd.google-earth.kml+xml");
+    header ("Cache-control: must-revalidate");
+    header (sprintf ("ETag: %s", $etag));
+
+    return $output;
+}
 
 function main ($features) {
 
@@ -14,49 +25,68 @@ function main ($features) {
 ';
 
     if (SITETITLE) {
-        printf ('    <name>%s</name>', SITETITLE);
+        printf ('    <name>%s</name>', htmlspecialchars (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 ? 
+                    image_url_from_imgpath ($feature->imgpath)
+                    : "");
+        $thumburl = ($feature->imgpath ? 
+                    thumb_url_from_imgpath ($feature->imgpath)
+                    : "");
         $lon = $feature->lon;
         $lat = $feature->lat;
         $alt = (strlen ($title) > 60) ?
                     (substr ($title, 0, 57) . '...') :
                     $title;
 
+        if ($imgurl) {
+            $imgurlHTML = sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
+        } 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>
     </kml>';
 }
 
+if (!@include_once ("./inc/settings.php")) {
+    exit ("server error");
+}
+require_once ("./inc/utils.php");
+require_once ("./inc/db/mysql.php");
+
 try {
     $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
-    $features = $connection->listfeatures ();
+    $features = $connection->listfeatures ($_GET ['from_user']);
 } catch (Exception $e) {
-    server_error ();
+    exit ("server error");
 }
-header ("Content-type: application/vnd.google-earth.kml+xml");
+
+ob_start ("headers_callback");
 main ($features);
+ob_end_flush ()
 ?>