From: Florent Bruneau Date: Mon, 18 Aug 2008 21:11:42 +0000 (+0200) Subject: Switch carnet's RSS to the PlFeed structure. X-Git-Tag: xorg/0.10.0~126 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=4e9a7a6d9161e1281004142bdc373d167f6b4274;p=platal.git Switch carnet's RSS to the PlFeed structure. Signed-off-by: Florent Bruneau --- diff --git a/modules/carnet.php b/modules/carnet.php index 56f0580..57bae84 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -313,12 +313,10 @@ class CarnetModule extends PLModule 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) diff --git a/modules/carnet/feed.inc.php b/modules/carnet/feed.inc.php new file mode 100644 index 0000000..0a24f6b --- /dev/null +++ b/modules/carnet/feed.inc.php @@ -0,0 +1,131 @@ +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: +?> diff --git a/templates/carnet/rss.tpl b/templates/carnet/rss.tpl index 0ec701e..b1b468a 100644 --- a/templates/carnet/rss.tpl +++ b/templates/carnet/rss.tpl @@ -20,46 +20,15 @@ {* *} {**************************************************************************} - - - - Polytechnique.org :: Carnet - fr - {#globals.baseurl#}/carnet/panel - Ton carnet polytechnicien... - - Polytechnique.org - {#globals.baseurl#}/images/logo.png - {#globals.baseurl#}/ - - {foreach from=$notifs->_data item=c key=cid} - {foreach from=$c item=promo} - {foreach from=$promo item=x} - - - [{$notifs->_cats[$cid].short}] {$x.prenom} {$x.nom} ({$x.promo}) - le {$x.date|date_format} - - {#globals.baseurl#}/profile/private/{$x.bestalias} - carnet{$x.known}{$cid}{$x.bestalias} - {$x.data}
{/if} - {if !$x.contact and !$x.dcd} - - {icon name=add title="Ajouter" full=true} Ajouter à mes contacts -
- {/if} - {if !$x.dcd} - - {icon name=vcard title="Carte de visite" full=true} Télécharger la carte de visite électronique - - {/if} - ]]>
- {$x.prenom} {$x.nom} (X{$x.promo}) - {$x.known|rss_date} -
- {/foreach} - {/foreach} - {/foreach} -
-
+{if $article->data}{$article->prenom} {$article->nom} a mis à jours les données suivantes :
{$article->data}
{/if} +{if !$article->contact and !$article->dcd} + + {icon name=add title="Ajouter" full=true} Ajouter à mes contacts +
+{/if} +{if !$article->dcd} + + {icon name=vcard title="Carte de visite" full=true} Télécharger la carte de visite électronique + +{/if} {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}