From 11d8a1833f6316effdbca817b8210b1c0dbeeb58 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Mon, 23 Oct 2006 16:35:47 +0000 Subject: [PATCH] Can get an iCal version of the events (it works but is not finished) git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1019 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 1 + modules/carnet/smarty.php | 4 +++- modules/xnetevents.php | 24 +++++++++++++++++++ modules/xnetevents/xnetevents.inc.php | 2 +- templates/xnetevents/calendar.tpl | 43 +++++++++++++++++++++++++++++++++++ templates/xnetevents/index.tpl | 4 +++- 6 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 templates/xnetevents/calendar.tpl diff --git a/ChangeLog b/ChangeLog index a1c5ba4..ae1c150 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,7 @@ New: * Xnet/Events: - Events can be archived -FRU + - Can get iCal version of the events -FRU Bug/Wish: diff --git a/modules/carnet/smarty.php b/modules/carnet/smarty.php index 4a709f7..09d5504 100644 --- a/modules/carnet/smarty.php +++ b/modules/carnet/smarty.php @@ -27,7 +27,9 @@ function display_ical($param) { $txt .= ';'.$param['param']; if (isset($param['value'])) { if ($txt) $txt .= ':'; - $txt .= utf8_encode($param['value']); + $txt .= utf8_encode( + preg_replace('/[,;:]/', '\\\\$0', + preg_replace("/(\r\n|\r|\n)/", '\n', $param['value']))); } $length = strlen($txt); $endline = "\r\n"; diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 5e3d31b..3ffa2eb 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -29,6 +29,7 @@ class XnetEventsModule extends PLModule '%grp/events' => $this->make_hook('events', AUTH_MDP), '%grp/events/sub' => $this->make_hook('sub', AUTH_MDP), '%grp/events/csv' => $this->make_hook('csv', AUTH_MDP), + '%grp/events/ical' => $this->make_hook('ical', AUTH_MDP), '%grp/events/edit' => $this->make_hook('edit', AUTH_MDP), '%grp/events/admin' => $this->make_hook('admin', AUTH_MDP), ); @@ -277,6 +278,29 @@ class XnetEventsModule extends PLModule $page->assign('tout', !Env::v('item_id', false)); } + function handler_ical(&$page, $eid = null) + { + global $globals; + + require_once dirname(__FILE__).'/xnetevents/xnetevents.inc.php'; + $evt = get_event_detail($eid); + if (!$evt) { + return PL_NOT_FOUND; + } + $evt['debut'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['debut']); + $evt['fin'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['fin']); + + $page->changeTpl('xnetevents/calendar.tpl', NO_SKIN); + + require_once(dirname(__FILE__).'/carnet/smarty.php'); + $page->assign('asso', $globals->asso()); + $page->assign('timestamp', time()); + $page->register_function('display_ical', 'display_ical'); + $page->assign_by_ref('e', $evt); + + header('Content-Type: text/calendar; charset=utf-8'); + } + function handler_edit(&$page, $eid = null) { global $globals; diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index c71b83d..aa3682d 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -48,7 +48,7 @@ function get_event_detail($eid, $item_id = false) $evt = $res->fetchOneAssoc(); - if (!$evt) { + if (!$evt || ($evt['accept_nonmembre'] == 0 && !is_member() && !may_update())) { return null; } diff --git a/templates/xnetevents/calendar.tpl b/templates/xnetevents/calendar.tpl new file mode 100644 index 0000000..85d62c3 --- /dev/null +++ b/templates/xnetevents/calendar.tpl @@ -0,0 +1,43 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2006 Polytechnique.org *} +{* http://opensource.polytechnique.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 *} +{* *} +{**************************************************************************} +BEGIN:VCALENDAR +{display_ical name="prodid" value="-//Polytechnique.org//Plat-al//FR"} +VERSION:2.0 +CALSCALE:GREGORIAN +X-WR-TIMEZONE:Europe/Paris +METHOD:PUBLISH +{display_ical name="x-wr-calname" value=$asso.nom} +BEGIN:VEVENT +DSTAMP:{$timestamp|date_format:"%Y%m%dT%H%M%SZ"} +DTSTART;VALUE=DATE;TZID=Europe/Paris:{$e.debut} +DTEND;VALUE=DATE;TZID=Europe/Paris:{$e.fin} +ORGANIZER:CN="{$e.prenom} {$e.nom}":MAILTO:{$e.alias}@polytechnique.org +UID:event-{$asso.diminutif}-{$e.short_name}@polytechnique.org +{if $e.accept_nonmembre} +CLASS:PUBLIC +{else} +CLASS:PRIVATE +{/if} +{display_ical name="summary" value=$e.intitule} +{display_ical name="description" value=$e.descriptif} +END:VEVENT +END:VCALENDAR diff --git a/templates/xnetevents/index.tpl b/templates/xnetevents/index.tpl index 54187c9..5a47665 100644 --- a/templates/xnetevents/index.tpl +++ b/templates/xnetevents/index.tpl @@ -42,7 +42,9 @@ - {$e.intitule} + + {icon name=calendar_view_day} {$e.intitule} + {if !$e.inscr_open} (Inscriptions closes) {/if} -- 2.1.4