Port Xnet feed to PlFeed.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 19 Aug 2008 19:33:37 +0000 (21:33 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 19 Aug 2008 19:33:37 +0000 (21:33 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/xnetgrp.php
modules/xnetgrp/feed.inc.php [new file with mode: 0644]
templates/xnetgrp/announce-rss.tpl

index 56da844..a7a47e2 100644 (file)
@@ -1183,29 +1183,11 @@ class XnetGrpModule extends PLModule
     function handler_rss(&$page, $user = null, $hash = null)
     {
         global $globals;
-        require_once('rss.inc.php');
-        $uid = init_rss('xnetgrp/announce-rss.tpl', $user, $hash, false);
-
-        if ($uid) {
-            $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date,
-                                         IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo,
-                                         FIND_IN_SET('photo', a.flags) AS photo
-                                   FROM auth_user_md5 AS u
-                             INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
-                                                                  AND (a.promo_max = 0 OR a.promo_max <= u.promo))
-                             INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
-                             WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
-                                   $uid, $globals->asso('id'));
-        } else {
-            $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date,
-                                         IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo
-                                    FROM groupex.announces AS a
-                             INNER JOIN auth_user_md5 AS u USING(user_id)
-                             WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
-                                  $globals->asso('id'));
-        }
         $page->assign('asso', $globals->asso());
-        $page->assign('rss', $rss);
+
+        require_once dirname(__FILE__) . '/xnetgrp/feed.inc.php';
+        $feed = new XnetGrpEventFeed();
+        return $feed->run($page, $user, $hash, false);
     }
 
     private function upload_image(PlPage &$page, PlUpload &$upload)
diff --git a/modules/xnetgrp/feed.inc.php b/modules/xnetgrp/feed.inc.php
new file mode 100644 (file)
index 0000000..caee580
--- /dev/null
@@ -0,0 +1,66 @@
+<?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                *
+ ***************************************************************************/
+
+class XnetGrpEventFeed extends PlFeed
+{
+    public function __construct()
+    {
+        global $globals;
+        $name = $globals->asso('nom');
+        $url = $globals->baseurl . '/' . $globals->asso('diminutif');
+        parent::__construct('Polytechnique.net :: ' . $name . ' :: News',
+                            $url,
+                            'L\'actualité du groupe ' . $name,
+                            $url . '/logo',
+                            'xnetgrp/announce-rss.tpl');
+    }
+
+    protected function fetch($user)
+    {
+        global $globals;
+        if (!is_null($user)) {
+            return XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.contacts,
+                                         a.create_date AS publication,
+                                         CONCAT(u2.prenom, ' ', IF(u2.nom_usage != '', u2.nom_usage, u2.nom), ' (X',  u2.promo, ')') AS author,
+                                         FIND_IN_SET('photo', a.flags) AS photo,
+                                         CONCAT({?}, '/#art', a.id) AS link
+                                   FROM auth_user_md5 AS u
+                             INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo)
+                                                                  AND (a.promo_max = 0 OR a.promo_max <= u.promo))
+                             INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id)
+                             WHERE u.user_id = {?} AND peremption >= NOW() AND a.asso_id = {?}",
+                                   $this->link, $user, $globals->asso('id'));
+        } else {
+            return  XDB::iterator("SELECT a.id, a.titre AS title, a.texte, a.create_date AS publication,
+                                         CONCAT(u.prenom, ' ', IF(u.nom_usage != '', u.nom_usage, u.nom), ' (X',  u.promo, ')') AS author,
+                                         CONCAT({?}, '/#art', a.id) AS link,
+                                         NULL AS photo, NULL AS contacts
+                                    FROM groupex.announces AS a
+                              INNER JOIN auth_user_md5 AS u USING(user_id)
+                                   WHERE FIND_IN_SET('public', a.flags) AND peremption >= NOW() AND a.asso_id = {?}",
+                                  $this->link, $globals->asso('id'));
+        }
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+
+?>
index caec126..e1172d7 100644 (file)
 {*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
 {*                                                                        *}
 {**************************************************************************}
-
-<?xml version="1.0"?>
-<rss version="2.0">
-  <channel>
-    <title>Polytechnique.net :: {$asso.nom} :: News</title>
-    <language>fr</language>
-    <link>{#globals.baseurl#}/{$asso.diminutif}/</link>
-    <description>L'actualite polytechnicienne...</description>
-    <image>
-      <title>{#globals.core.sitename#}</title>
-      <url>{#globals.baseurl#}/images/logo.png</url>
-      <link>{#globals.baseurl#}/{$asso.diminutif}/</link>
-    </image>
-    {iterate item=line from=$rss}
-    <item>
-      <title>{$line.titre|strip_tags}</title>
-      <guid isPermaLink="false">{$line.id}</guid>
-      <link>{#globals.baseurl#}/{$asso.diminutif}/#art{$line.id}</link>
-      <description><![CDATA[
-        {if $line.photo}
-        <div style="float: left; padding-right: 0.5em">
-          <img src="{#globals.baseurl#}/{$asso.diminutif}/announce/photo/{$line.id}" alt="{$line.titre|strip_tags}" />
-        </div>
-        {/if}
-        <div>{$line.texte|miniwiki}{if $line.contacts}<br/><br/><strong>Contacts&nbsp;:</strong><br/>{$line.contacts|miniwiki}{/if}</div>]]></description>
-      <author>{$line.prenom} {$line.nom} (X{$line.promo})</author>
-      <pubDate>{$line.create_date|rss_date}</pubDate>
-    </item>
-    {/iterate}
-  </channel>
-</rss>
+{if $article->photo}
+<div style="float: left; padding-right: 0.5em">
+  <img src="{#globals.baseurl#}/{$asso.diminutif}/announce/photo/{$article->id}" alt="{$article->titre|strip_tags}" />
+</div>
+{/if}
+<div>{$article->texte|miniwiki}{if $article->contacts}<br/><br/><strong>Contacts&nbsp;:</strong><br/>{$article->contacts|miniwiki}{/if}</div>
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}