migrate calendar, no more PATH_INFO is needed
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 11 Jul 2006 01:55:57 +0000 (01:55 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 11 Jul 2006 01:55:57 +0000 (01:55 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@429 839d8a87-29fc-0310-9880-83ba4fa771e5

htdocs/carnet/calendar.php [deleted file]
modules/carnet.php
templates/carnet/mescontacts.tpl

diff --git a/htdocs/carnet/calendar.php b/htdocs/carnet/calendar.php
deleted file mode 100644 (file)
index f443df4..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/***************************************************************************
- *  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                *
- ***************************************************************************/
-
-require_once("xorg.inc.php");
-new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
-
-if (preg_match(',^/([^/]+)/([^/_]+)(_all)?\.ics$,', $_SERVER['PATH_INFO'], $m)) {
-    $alias = $m[1];
-    $hash  = $m[2];
-    $all = $m[3];
-} else {
-    $alias = Env::get('alias');
-    $hash = Env::get('hash');
-    $all = Env::has('all');
-}
-if ($alias && $hash) {
-    $res = $globals->xdb->query(
-        'SELECT  a.id
-           FROM  aliases         AS a
-     INNER JOIN  auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
-          WHERE  a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
-    $uid = $res->fetchOneCell();
-}
-
-require_once('notifs.inc.php');
-$notifs = new Notifs($uid, true);
-
-$annivcat = false;
-foreach ($notifs->_cats as $cat)
-    if (preg_match('/anniv/i', $cat['short']))
-        $annivcat = $cat['id'];
-
-if ($annivcat !== false) {
-    $annivs = array();
-    foreach ($notifs->_data[$annivcat] as $promo) foreach ($promo as $notif)
-    if ($all || $notif['contact']) {
-        $annivs[] = array(
-            'timestamp' => $notif['known'],
-            'date' => strtotime($notif['date']),
-            'tomorrow' => strtotime("+1 day", strtotime($notif['date'])),
-            'bestalias' => $notif['bestalias'],
-            'summary' => 'Anniversaire de '.$notif['prenom'].' '.$notif['nom'].' - x '.$notif['promo'],
-        );        
-    }
-    $page->assign('events', $annivs);
-}
-
-header('Content-Type: text/calendar; charset=utf-8');
-
-$page->run();
-?>
\ No newline at end of file
index 9cbb8d0..b07cd19 100644 (file)
@@ -24,7 +24,8 @@ class CarnetModule extends PLModule
     function handlers()
     {
         return array(
-            'carnet/rss' => $this->make_hook('rss', AUTH_PUBLIC),
+            'carnet/rss'  => $this->make_hook('rss', AUTH_PUBLIC),
+            'carnet/ical' => $this->make_hook('ical', AUTH_PUBLIC),
         );
     }
 
@@ -39,6 +40,54 @@ class CarnetModule extends PLModule
 
         return PL_OK;
     }
+
+    function handler_ical(&$page, $user = null, $hash = null, $all = null)
+    {
+        global $globals;
+
+        new_nonhtml_page('carnet/calendar.tpl', AUTH_PUBLIC);
+
+        if ($alias && $hash) {
+            $res = $globals->xdb->query(
+                'SELECT  a.id
+                   FROM  aliases         AS a
+             INNER JOIN  auth_user_quick AS q ON ( a.id = q.user_id AND q.core_rss_hash = {?} )
+                  WHERE  a.alias = {?} AND a.type != "homonyme"', $hash, $alias);
+            $uid = $res->fetchOneCell();
+        }
+
+        require_once 'notifs.inc.php';
+        $notifs = new Notifs($uid, true);
+
+        $annivcat = false;
+        foreach ($notifs->_cats as $cat) {
+            if (preg_match('/anniv/i', $cat['short']))
+                $annivcat = $cat['id'];
+        }
+
+        if ($annivcat !== false) {
+            $annivs = array();
+            foreach ($notifs->_data[$annivcat] as $promo) {
+                foreach ($promo as $notif) {
+                    if ($all == 'all' || $notif['contact']) {
+                        $annivs[] = array(
+                            'timestamp' => $notif['known'],
+                            'date'      => strtotime($notif['date']),
+                            'tomorrow'  => strtotime("+1 day", strtotime($notif['date'])),
+                            'bestalias' => $notif['bestalias'],
+                            'summary'   => 'Anniversaire de '.$notif['prenom']
+                                           .' '.$notif['nom'].' - x '.$notif['promo'],
+                         );
+                    }
+                }
+            }
+            $page->assign('events', $annivs);
+        }
+
+        header('Content-Type: text/calendar; charset=utf-8');
+
+        return PL_OK;
+    }
 }
 
 ?>
index d2212ff..47986d6 100644 (file)
@@ -59,7 +59,7 @@ Pour r
   Tu peux récupérer un calendrier iCal avec l'anniversaire de tes contacts.
 </p>
   <div class="right">
-    <a href='{rel}/carnet/calendar/{$smarty.session.forlife}/{$smarty.session.core_rss_hash}.ics'><img src='{rel}/images/icalicon.gif' alt='fichier ical' title='Anniversaires'/></a>
+    <a href='{rel}/carnet/ical/{$smarty.session.forlife}/{$smarty.session.core_rss_hash}/cal.ics'><img src='{rel}/images/icalicon.gif' alt='fichier ical' title='Anniversaires'/></a>
   </div>
 {else}
 <p>