[Devel] r420 - trunk

svn at agendadulibre.org svn at agendadulibre.org
Mar 17 Fév 23:55:04 CET 2009


Author: thomas
Date: Tue Feb 17 23:55:03 2009
New Revision: 420

Log:
Ajout d'une action "Ajouter à mon calendrier" sur chaque évènement.

Cette idée m'a été donnée par Quesh, d'Ubuntu-fr, rencontré lors de
l'AG de l'April. L'idée est d'avoir un lien sur chaque évènement qui
permet d'enregistrer juste cet évènement dans son calendrier. A
priori, un simple fichier ICS suffit, avec un type MIME text/calendar.

Je n'ai pas pu tester moi-même, car Sunbird n'a pas l'air de supporter
ce genre de chose.



Added:
   trunk/ical.inc.php
   trunk/icalevent.php
Modified:
   trunk/ical.php
   trunk/showevent.php

Added: trunk/ical.inc.php
==============================================================================
--- (empty file)
+++ trunk/ical.inc.php	Tue Feb 17 23:55:03 2009
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * Copyright 2004-2009
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+function ical_start_calendar ($calname, $caldesc)
+{
+  echo "BEGIN:VCALENDAR\n";
+  echo "VERSION:2.0\n";
+  echo "PRODID:-//AgendaDuLibre.org\n";
+  echo "X-WR-CALNAME:" . $calname . "\n";
+  echo "X-WR-TIMEZONE:Europe/Paris\n";
+  echo "CALSCALE:GREGORIAN\n";
+  echo "X-WR-CALDESC:" . $caldesc . "\n";
+}
+
+function ical_end_calendar()
+{
+  echo "END:VCALENDAR";
+}
+
+function ical_display_event ($id, $city, $start, $end, $title, $url, $description)
+{
+  global $timezone;
+
+  echo "BEGIN:VEVENT\n";
+  echo "DTSTART:" .  date ('Ymd\THi\0\0', $start) . "\n";
+  echo "DTEND:"   .  date ('Ymd\THi\0\0', $end) . "\n";
+  echo "UID:" . $id . "@agendadulibre.org\n";
+  echo "SUMMARY:" .  $title . "\n";
+  echo "URL:" .  $url . "\n";
+  echo "DESCRIPTION:" .  $description . "\n";
+  echo "LOCATION:" . $city . "\n";
+  echo "END:VEVENT\n";
+}
+
+?>
\ No newline at end of file

Modified: trunk/ical.php
==============================================================================
--- trunk/ical.php	(original)
+++ trunk/ical.php	Tue Feb 17 23:55:03 2009
@@ -22,6 +22,7 @@
 include("bd.inc.php");
 include("bd-private.inc.php");
 include("funcs.inc.php");
+include("ical.inc.php");
 
 $db = new db();
 
@@ -29,49 +30,6 @@
 
 calendar_setlocale();
 
-$timezone = "Europe/Paris";
-
-function ical_start_calendar ($region, $tag)
-{
-  echo "BEGIN:VCALENDAR\n";
-  echo "VERSION:2.0\n";
-  echo "PRODID:-//AgendaDuLibre.org\n";
-  echo "X-WR-CALNAME:Agenda du Libre";
-  if ($region != "all")
-    echo " - région " . $region;
-  if ($tag != '')
-    echo " - tag " . $tag;
-  echo "\n";
-  echo "X-WR-TIMEZONE:Europe/Paris\n";
-  echo "CALSCALE:GREGORIAN\n";
-  echo "X-WR-CALDESC:L'Agenda des évènements autour du Libre";
-  if ($region != "all")
-    echo " en région " . $region;
-  if ($tag != '')
-    echo ", tag " . $tag;
-  echo "\n";
-}
-
-function ical_end_calendar()
-{
-  echo "END:VCALENDAR";
-}
-
-function ical_display_event ($id, $city, $start, $end, $title, $url, $description)
-{
-  global $timezone;
-
-  echo "BEGIN:VEVENT\n";
-  echo "DTSTART:" .  date ('Ymd\THi\0\0', $start) . "\n";
-  echo "DTEND:"   .  date ('Ymd\THi\0\0', $end) . "\n";
-  echo "UID:" . $id . "@agendadulibre.org\n";
-  echo "SUMMARY:" .  $title . "\n";
-  echo "URL:" .  $url . "\n";
-  echo "DESCRIPTION:" .  $description . "\n";
-  echo "LOCATION:" . $city . "\n";
-  echo "END:VEVENT\n";
-}
-
 function get_events ($db, $region, $tag)
 {
   $start = mktime() - (12 * 30 * 24 * 60 *60);
@@ -102,10 +60,23 @@
   exit;
 }
 
+$calname = "Agenda du Libre";
+$caldesc = "L'Agenda des évènements autour du Libre";
+
 if ($region != "all")
-  ical_start_calendar(region_find($db, $region), $tag);
-else
-  ical_start_calendar($region, $tag);
+{
+  $region = region_find($db, $region);
+  $calname .= " - " . $region;
+  $caldesc .= " en région " . $region;
+}
+
+if ($tag != '')
+{
+  $calname .= " - tag " . $tag;
+  $caldesc .= ", tag " . $tag;
+}
+
+ical_start_calendar($calname, $caldesc);
 
 while ($event = mysql_fetch_object($list))
 {

Added: trunk/icalevent.php
==============================================================================
--- (empty file)
+++ trunk/icalevent.php	Tue Feb 17 23:55:03 2009
@@ -0,0 +1,52 @@
+<?php
+
+/* Copyright 2009
+ * - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix 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
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+include("bd.inc.php");
+include("funcs.inc.php");
+include("session.inc.php");
+
+$db = new db();
+$session = new session();
+
+$id = get_safe_integer('id', 0);
+
+header("Content-Type: text/calendar");
+header("Content-Disposition: attachment; filename=adl-event-" . $id . ".ics");
+
+calendar_setlocale();
+
+$event = fetch_event($db, $id);
+if (! $event)
+{
+  exit;
+}
+
+ical_start_calendar("Agenda du Libre", "Agenda du Libre");
+
+ical_display_event ($event->id, strip_tags($event->city),
+		    date_mysql2timestamp ($event->start_time),
+		    date_mysql2timestamp ($event->end_time),
+		    strip_tags($event->title),
+		    calendar_absolute_url("showevent.php?id=" . $event->id),
+		    "Un évènement de l'Agenda du Libre");
+
+ical_end_calendar();
+?>
\ No newline at end of file

Modified: trunk/showevent.php
==============================================================================
--- trunk/showevent.php	(original)
+++ trunk/showevent.php	Tue Feb 17 23:55:03 2009
@@ -93,9 +93,11 @@
   echo "</p>";
 }
 
+echo "<h1>Actions</h1>";
+echo "<a href=\"icalevent.php?id=" . $event_id . "\">Ajouter à mon calendrier</a><br/>";
+
 if ($session->exists("agenda_libre_id"))
 {
-  echo "<h1>Actions</h1>";
   echo "<a href=\"editevent.php?id=" . $event_id . "\">Éditer évènement</a><br/>";
   echo "<a href=\"cancelevent.php?id=" . $event_id . "\">Annuler évènement</a>";
 }


Plus d'informations sur la liste de diffusion Devel