[Devel] r432 - branches/dui

svn at agendadulibre.org svn at agendadulibre.org
Dim 1 Mar 18:44:54 CET 2009


Author: ldayot
Date: Sun Mar  1 18:44:53 2009
New Revision: 432

Log:
Correction de bugs dans le choix des exports rss, ical et javascript.
Prise en compte de la geolocalisation des evenements.

Modified:
   branches/dui/ical.php
   branches/dui/icallist.php
   branches/dui/javascript.php
   branches/dui/javascriptlist.php
   branches/dui/rss.php
   branches/dui/rsslist.php

Modified: branches/dui/ical.php
==============================================================================
--- branches/dui/ical.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/ical.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -1,7 +1,8 @@
 <?php
 /*
- * Copyright 2004-2007
+ * Copyright 2004-2009
  * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -17,16 +18,14 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
- *
- * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
  */
 
 include("text.inc.php");
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("bd-private.inc.php");
 include("funcs.inc.php");
-
 $db = new db();
+include("class.event.inc.php");
 
 header("Content-Type: application/octet-stream; charset=utf-8");
 
@@ -82,8 +81,9 @@
   $start = mktime() - (12 * 30 * 24 * 60 *60);
 
   $sql = "select events.* from events ".
-    ($tag != "" ? "LEFT JOIN tags_events ON event_id=events.id LEFT JOIN tags ON tags.id=tag_id ".
-    "WHERE (tags.name='{$tag}') AND " : "WHERE " ).
+    ($tag != "" ? 
+      "LEFT JOIN tags_events ON event_id=events.id LEFT JOIN tags ON tags.id=tag_id ".
+      "WHERE (tags.name='{$tag}') AND " : "WHERE " ).
     "(end_time   >= '" . date_timestamp2mysql($start) . "') AND (moderated=1)";
 
   if ($region != "all")
@@ -97,9 +97,14 @@
   return $db->query ($sql);
 }
 
+
+
+
+
+
 $region = get_safe_integer('region', 'all');
 
-if ($_GET['tag'] && ereg("^[a-z0-9\-]*$", $_GET['tag']))
+if (isset($_GET['tag']) && ereg("^[a-z0-9\-]*$", $_GET['tag']))
   $tag = $_GET['tag'];
 else
   $tag = '';

Modified: branches/dui/icallist.php
==============================================================================
--- branches/dui/icallist.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/icallist.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -22,7 +22,7 @@
  * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
  */
 
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("funcs.inc.php");
 
 $db = new db();
@@ -34,6 +34,7 @@
 echo $adl_ical_intro;
 
 // Purpose url
+$tagsE = array();
 
 echo "<fieldset><legend>". _("Sélection"). "</legend>";
 if (isset($_GET["tags"]) && is_array($_GET["tags"]))
@@ -41,7 +42,10 @@
   $urltags="";
   foreach ($_GET["tags"] AS $category=>$tag)
   {
-    $urltags .= "&$category=$tag";
+    if (is_array($tag) || $tag>"") {
+      $urltags .= "&$category=". (is_array($tag) ? implode("+", $tag) : $tag);
+      if (is_array($tag)) foreach($tag as $tag1) $tagsE[]=$tag1; else $tagsE[]=$tag;
+    }
   }
 }
 $url = calendar_absolute_url("ical.php?region=". (isset($_GET["region"]) ? $_GET["region"] : "all"). (isset($_GET["daylimit"]) && $_GET["daylimit"]!="30" ? "&daylimit=". $_GET["daylimit"] : ""). (isset($urltags) ? $urltags : ""), "webcal");
@@ -58,7 +62,7 @@
 echo selectDurationHTML(isset($_GET["daylimit"]) ? $_GET["daylimit"] : "30"). "<br />\n";
 
 // Select tags
-echo selectTagsHTML(isset($_GET["tags"]) ? $_GET["tags"] : array());
+echo selectTagsHTML($tagsE);
 
 echo "  <input type=\"submit\" name=\"submit\" value=\"". _("Mettre à jour la sélection"). "\" /> <input type=\"reset\" name=\"reset\" value=\"". _("Réinitialise"). "\" />\n";
 echo "</fieldset>";

Modified: branches/dui/javascript.php
==============================================================================
--- branches/dui/javascript.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/javascript.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -1,6 +1,6 @@
 <?php
 
-/* Copyright 2008
+/* Copyright 2008-2009
  * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
  *
  * This program is free software; you can redistribute it and/or
@@ -24,10 +24,10 @@
  * Export Agenda in javascrit file
  */
 
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("funcs.inc.php");
-
 $db = new db();
+include("class.event.inc.php");
 
 if (isset($_GET['region']) &&
     ($_GET['region'] == "all" ||
@@ -44,20 +44,22 @@
 
 function calendar_js($db, $region, $count)
   {
-    $sql = "SELECT * FROM events WHERE start_time>CURRENT_DATE()";
+    $sql = "SELECT id FROM events WHERE start_time>CURRENT_DATE()";
     $sql .= " AND moderated = 1";
-    $sql .= ($region!="all" ? " AND ((region = " . $db->quote_smart($region) . ") OR (locality>=1))" : "");
+    $sql .= ($region!="all" ? " AND ((region = " . 
+      $db->quote_smart($region) . ") OR (locality>=1))" : "");
     $sql .= " ORDER BY start_time LIMIT 0, {$count}";
     $result = $db->query ($sql);
 
     // start javascript
     echo "document.write(\"<ul>\");\n";
-    while ($record = mysql_fetch_object($result)) 
+    while ($record = $db->fetchObject($result)) 
       {
-        $event = fetch_event($db, $record->id);
+        $event = new event($db, $record->id);
         echo "document.write(\"";
-        echo "  <li>". strftime ("%d/%m/%Y", date_mysql2timestamp($event->start_time));
-        echo " <a href='". calendar_absolute_url("showevent.php?id={$event->id}", "http"). "'>";
+        echo "  <li>". strftime ("%d/%m/%Y", $event->start);
+        echo " <a href='". 
+          calendar_absolute_url("showevent.php?id={$event->id}", "http"). "'>";
         echo "<b>" . htmlentities(substr(utf8_decode(stripslashes($event->city)),0,15)) . "</b>: ";
         echo htmlentities(substr(utf8_decode(stripslashes($event->title)),0,35));
         echo "</a>". "</li>\\n\");\n";
@@ -69,5 +71,4 @@
 
 calendar_js($db, $region, $count);
 
-
 ?>

Modified: branches/dui/javascriptlist.php
==============================================================================
--- branches/dui/javascriptlist.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/javascriptlist.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -1,8 +1,6 @@
 <?php
 
-/* Copyright 2004-2008
- * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
- * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+/* Copyright 2004-2009
  * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
  *
  * This program is free software; you can redistribute it and/or
@@ -19,12 +17,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
- *
- * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
  */
 
 include("text.inc.php");
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("funcs.inc.php");
 
 $db = new db();

Modified: branches/dui/rss.php
==============================================================================
--- branches/dui/rss.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/rss.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -1,8 +1,9 @@
 <?php
 
-/* Copyright 2004-2007
+/* Copyright 2004-2009
  * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
  * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -23,11 +24,11 @@
  */
 
 include("text.inc.php");
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("bd-private.inc.php");
 include("funcs.inc.php");
-
 $db = new db();
+include("class.event.inc.php");
 
 calendar_setlocale();
 
@@ -42,7 +43,7 @@
 
 function get_city_coordinates ($db, $city)
 {
-  $sql = "SELECT longitude, latitude FROM cities WHERE namemaj='" . $city . "'";
+  $sql = "SELECT longitude, latitude FROM cities WHERE majname='" . $city . "'";
   $ret = $db->query($sql);
 
   if (mysql_num_rows($ret) == 1)
@@ -58,7 +59,7 @@
 {
   $start = mktime();
 
-  $sql = "SELECT events.* FROM events";
+  $sql = "SELECT events.id as id FROM events";
   $sqlWhere = " WHERE (end_time >= '" . date_timestamp2mysql($start) . "') AND (moderated=1)";
 
   if ($daylimit != 0)
@@ -68,7 +69,7 @@
     }
     
   if ($tag != "" )
-    $sql .= "LEFT JOIN tags_events ON event_id=events.id LEFT JOIN tags ON tags.id=tag_id";
+    $sql .= " LEFT JOIN tags_events ON event_id=events.id LEFT JOIN tags ON tags.id=tag_id";
 
   if ($tag != "")
     $sqlWhere .= " AND (tags.name='{$tag}')";
@@ -125,6 +126,8 @@
 $db->freeResult($ret);
 $map = get_safe_integer('map', 0);
 
+$event_id = get_safe_integer('id', 0);
+
 Header("Content-type: text/xml; charset=utf-8");
 
 echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
@@ -150,7 +153,14 @@
 echo "  <rdf:Seq>\n";
 
 /* Generate item list */
-$list = get_events ($db, $region_num, $tag, $daylimit, $aTags);
+if ($event_id==0)
+  $list = get_events ($db, $region_num, $tag, $daylimit, $aTags);
+else
+  {
+    $sql = "SELECT events.id as id FROM events WHERE id=". $db->quote_smart($event_id);
+    $list = $db->query($sql);
+  }
+    
 if ($list == FALSE)
 {
   error ("Erreur lors de la récupération des évènements");
@@ -167,21 +177,28 @@
 echo "</channel>\n\n\n";
 
 /* Generate items */
-$list = get_events ($db, $region_num, $tag, $daylimit, $aTags);
+if ($event_id==0)
+  $list = get_events ($db, $region_num, $tag, $daylimit, $aTags);
+else
+  {
+    $list = $db->query($sql);
+  }
+
 if ($list == FALSE)
 {
   echo "Erreur lors de la récupération des évènements";
   exit;
 }
 
-while ($event = $db->fetchObject($list))
+while ($event_id = $db->fetchObject($list))
 {
-  $start_timestamp = date_mysql2timestamp($event->start_time);
-  $start_day = onlyday_timestamp2humanreadable($start_timestamp);
-  $end_day   = onlyday_timestamp2humanreadable(date_mysql2timestamp($event->end_time));
-  list($longitude, $latitude) = get_city_coordinates($db, $event->city);
+  $event = new event($db, $event_id->id);
+  $start_day = onlyday_timestamp2humanreadable($event->start);
+  $end_day   = onlyday_timestamp2humanreadable($event->end);
+  //list($longitude, $latitude) = get_city_coordinates($db, $event->city);
   
-  echo "  <item rdf:about=\"" . calendar_absolute_url("showevent.php?id=" . $event->id) . "\">\n";
+  echo "  <item rdf:about=\"" . 
+    calendar_absolute_url("showevent.php?id=" . $event->id) . "\">\n";
 
   echo "  <title>";
   echo xmlentities($event->city) . " : " . xmlentities($event->title);
@@ -191,38 +208,28 @@
     echo ", du " . $start_day . " au " . $end_day;
   echo "</title>\n";
 
-  echo "   <link>" . calendar_absolute_url("showevent.php?id=" . $event->id) . "</link>\n";
-  echo "   <dc:identifier>" . $event->id . "@agendadulibre.org</dc:identifier>\n";
+  echo "   <link>" . 
+    calendar_absolute_url("showevent.php?id=" . $event->id) . "</link>\n";
+  echo "   <dc:identifier>" . $event->id . 
+    "@agendadulibre.org</dc:identifier>\n";
   $evt_timezone = ereg_replace("^\+([0-9][0-9])([0-9][0-9])$", "+\\1:\\2",
-			       date('O', $start_timestamp));
-  $evt_date     = date('Y-m-d\TH:i', $start_timestamp);
+			       date('O', $event->start));
+  $evt_date     = date('Y-m-d\TH:i', $event->start);
   echo "   <dc:date>" . $evt_date . $evt_timezone . "</dc:date>\n";
-  if ($longitude && $latitude)
-    echo "   <georss:point>" . $latitude . " " . $longitude . "</georss:point>\n";
+  if ($event->longitude && $event->latitude)
+    echo "   <georss:point>" . $event->latitude . " " . $event->longitude . "</georss:point>\n";
   echo "   <description>\n";
 
-  echo xmlentities(strip_tags(format_event($db, $event->title,
-					    date_mysql2timestamp($event->start_time),
-					    date_mysql2timestamp($event->end_time),
-					    $event->description, $event->city,
-					    $event->region, $event->locality,
-					    $event->url, $event->contact,
-					    $event->submitter, eventTagsList($event->id))));
+  echo xmlentities(strip_tags($event->formatHTML()));
 
   echo "   </description>\n";
   if (! $map)
     {
       echo "   <content:encoded>\n";
-      echo xmlentities(format_event ($db, $event->title,
-				 date_mysql2timestamp($event->start_time),
-				 date_mysql2timestamp($event->end_time),
-				 $event->description, $event->city,
-				 $event->region, $event->locality,
-				 $event->url, $event->contact,
-				 $event->submitter, eventTagsList($event->id)));
+      echo xmlentities($event->formatHTML());
       echo "   </content:encoded>\n";
     }
   echo "  </item>\n\n";
-}
+} // end while
 
 echo "</rdf:RDF>\n";

Modified: branches/dui/rsslist.php
==============================================================================
--- branches/dui/rsslist.php	Sun Mar  1 18:42:50 2009	(r431)
+++ branches/dui/rsslist.php	Sun Mar  1 18:44:53 2009	(r432)
@@ -1,8 +1,9 @@
 <?php
 
-/* Copyright 2004
+/* Copyright 2004-2009
  * - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
  * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
+ * - Loic Dayot <ldayot CHEZ ouvaton POINT org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -18,12 +19,10 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  * 02111-1307, USA.
- *
- * $Id: top.inc.php,v 1.51 2007/03/10 16:22:12 ldayot Exp $
  */
 
 include("text.inc.php");
-include("bd.inc.php");
+include("class.bd.inc.php");
 include("funcs.inc.php");
 
 $db = new db();
@@ -42,7 +41,8 @@
 }
 
 echo $adl_rss_intro;
-
+ 
+$tagsE = array();
 // Purpose url
 
 echo "<fieldset><legend>". _("Sélection"). "</legend>";
@@ -53,11 +53,16 @@
   foreach ($_GET["tags"] AS $category=>$tag)
   {
     if (is_array($tag) || $tag>"") {
-      $urltags .= "&$category=". (is_array($tag) ? implode("+", $tag) : $tags);
+      $urltags .= "&$category=". (is_array($tag) ? implode("+", $tag) : $tag);
+      if (is_array($tag)) foreach($tag as $tag1) $tagsE[]=$tag1; else $tagsE[]=$tag;
     }
   }
 }
-$url = calendar_absolute_url("rss.php?region=". (isset($_GET["region"]) ? $_GET["region"] : "all"). (isset($_GET["daylimit"]) && $_GET["daylimit"]!="30" ? "&daylimit=". $_GET["daylimit"] : ""). (isset($urltags) ? $urltags : "")). (isset($_GET['map']) && $_GET['map']==1 ? "&map=1":"");
+$url = calendar_absolute_url("rss.php?region=". 
+  (isset($_GET["region"]) ? $_GET["region"] : "all"). 
+  (isset($_GET["daylimit"]) && $_GET["daylimit"]!="30" ? "&daylimit=". $_GET["daylimit"] : ""). 
+  (isset($urltags) ? $urltags : "")). 
+  (isset($_GET['map']) && $_GET['map']==1 ? "&map=1":"");
 echo "<a href=\"$url\">$url</a>\n";
 echo "</fieldset>\n";
 
@@ -71,7 +76,7 @@
 echo selectDurationHTML(isset($_GET["daylimit"]) ? $_GET["daylimit"] : "30"). "<br />\n";
 
 // Select tags
-echo selectTagsHTML(isset($_GET["tags"]) ? $_GET["tags"] : array());
+echo selectTagsHTML($tagsE);
 
 // Select map or not
 echo "<strong>". _("Type de flux"). "</strong>&nbsp;: ".


Plus d'informations sur la liste de diffusion Devel