function handler_rss(&$page, $user = null, $hash = null)
{
- require_once 'rss.inc.php';
- require_once 'notifs.inc.php';
-
- $uid = init_rss('carnet/rss.tpl', $user, $hash);
- $notifs = new Notifs($uid, false);
- $page->assign('notifs', $notifs);
+ require_once dirname(__FILE__) . '/carnet/feed.inc.php';
+ $page->assign('rss_hash', $hash);
+ $feed = new CarnetFeed();
+ return $feed->run($page, $user, $hash);
}
function handler_ical(&$page, $alias = null, $hash = null)
--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2008 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 'notifs.inc.php';
+
+class CarnetFeedIterator implements PlIterator
+{
+ private $notifs;
+
+ private $start;
+ private $stop;
+ private $pos;
+ private $count;
+
+ private $p1;
+ private $p2;
+
+ public function __construct(Notifs& $notifs)
+ {
+ $this->notifs =& $notifs;
+ foreach ($notifs->_data as $c) {
+ foreach ($c as $promo) {
+ $this->count += count($promo);
+ }
+ }
+ $this->pos = 0;
+ reset($notifs->_data);
+ if ($this->count > 0) {
+ $this->p1 = current($notifs->_data);
+ reset($this->p1);
+ $this->p2 = current($this->p1);
+ reset($this->p2);
+ }
+ }
+
+ public function next()
+ {
+ $this->pos++;
+ $this->first = ($this->count > 0 && $this->pos == 1);
+ $this->last = ($this->count > 0 && $this->pos == $this->count);
+ if ($this->count == 0) {
+ return null;
+ }
+
+ $x = current($this->p2);
+ if ($x === false) {
+ $this->p2 = next($this->p1);
+ if ($this->p2 === false) {
+ $this->p1 = next($this->notifs->_data);
+ if ($this->p1 === false) {
+ return null;
+ }
+ reset($this->p1);
+ $this->p2 = current($this->p1);
+ }
+ reset($this->p2);
+ $x = current($this->p2);
+ }
+ $cid = key($this->notifs->_data);
+ next($this->p2);
+
+ global $globals;
+ $author = $x['prenom'] . ' ' . $x['nom'] . ' (X' . $x['promo'] . ')';
+
+ @require_once 'Date.php';
+ @$date = new Date($x['date']);
+ @$date = $date->format('%e %B %Y');
+ return array_merge($x,
+ array('author' => $author,
+ 'publication' => $x['known'],
+ 'id' => 'carnet' . $x['known'] . $cid . $x['bestalias'],
+ 'link' => $globals->baseurl . '/profile/private/'
+ . $x['bestalias'],
+ 'title' => '[' . $this->notifs->_cats[$cid]['short'] . '] '
+ . $author . ' - le ' . $date));
+ }
+
+ public function total()
+ {
+ return $this->count;
+ }
+
+ public function first()
+ {
+ return $this->start;
+ }
+
+ public function last()
+ {
+ return $this->stop;
+ }
+}
+
+class CarnetFeed extends PlFeed
+{
+ public function __construct()
+ {
+ global $globals;
+ parent::__construct($globals->core->sitename . ' :: Carnet',
+ $globals->baseurl . '/carnet/panel',
+ 'Ton carnet polytechnicien',
+ $globals->baseurl . '/images/logo.png',
+ 'carnet/rss.tpl');
+ }
+
+ protected function fetch($user)
+ {
+ return new CarnetFeedIterator(new Notifs($user, false));
+ }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
{* *}
{**************************************************************************}
-<?xml version="1.0"?>
-<rss version="2.0">
- <channel>
- <title>Polytechnique.org :: Carnet</title>
- <language>fr</language>
- <link>{#globals.baseurl#}/carnet/panel</link>
- <description>Ton carnet polytechnicien...</description>
- <image>
- <title>Polytechnique.org</title>
- <url>{#globals.baseurl#}/images/logo.png</url>
- <link>{#globals.baseurl#}/</link>
- </image>
- {foreach from=$notifs->_data item=c key=cid}
- {foreach from=$c item=promo}
- {foreach from=$promo item=x}
- <item>
- <title>
- [{$notifs->_cats[$cid].short}] {$x.prenom} {$x.nom} ({$x.promo}) - le {$x.date|date_format}
- </title>
- <link>{#globals.baseurl#}/profile/private/{$x.bestalias}</link>
- <guid isPermaLink="false">carnet{$x.known}{$cid}{$x.bestalias}</guid>
- <description><![CDATA[
- {if $x.data}{$x.prenom} {$x.nom} a mis à jours les données suivantes :<br />{$x.data}<br />{/if}
- {if !$x.contact and !$x.dcd}
- <a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&user={$x.bestalias}&token={$rss_hash}">
- {icon name=add title="Ajouter" full=true} Ajouter à mes contacts
- </a><br />
- {/if}
- {if !$x.dcd}
- <a href="{#globals.baseurl#}/vcard/{$x.bestalias}.vcf">
- {icon name=vcard title="Carte de visite" full=true} Télécharger la carte de visite électronique
- </a>
- {/if}
- ]]></description>
- <author>{$x.prenom} {$x.nom} (X{$x.promo})</author>
- <pubDate>{$x.known|rss_date}</pubDate>
- </item>
- {/foreach}
- {/foreach}
- {/foreach}
- </channel>
-</rss>
+{if $article->data}{$article->prenom} {$article->nom} a mis à jours les données suivantes :<br />{$article->data}<br />{/if}
+{if !$article->contact and !$article->dcd}
+<a href="{#globals.baseurl#}/carnet/contacts?action=ajouter&user={$article->bestalias}&token={$rss_hash}">
+ {icon name=add title="Ajouter" full=true} Ajouter à mes contacts
+</a><br />
+{/if}
+{if !$article->dcd}
+<a href="{#globals.baseurl#}/vcard/{$article->bestalias}.vcf">
+ {icon name=vcard title="Carte de visite" full=true} Télécharger la carte de visite électronique
+</a>
+{/if}
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}