better rss handling
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Mon, 17 Jan 2005 08:30:29 +0000 (08:30 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:45 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-369

hooks/tmp.inc.php
htdocs/images/rssicon.gif [new file with mode: 0644]
htdocs/preferences.php
htdocs/rss.php
include/rss.inc.php
include/xorg/session.inc.php
templates/login.tpl
upgrade/0.9.4/30_auth_user_quick.sql

index 7ab7913..7e294e6 100644 (file)
@@ -57,9 +57,15 @@ function tmp_prefs()
             Array(
                 'url'    => 'preferences.php?mail_fmt='.$fmt,
                 'title'  => 'Recevoir les mails en format '.$fmt2,
-                'text'   => 'Tu recois es mails envoyés par le site (lettre mensuelle, carnet, ...) de préférence <strong>sous forme de '
+                'text'   => 'Tu recois les mails envoyés par le site (lettre mensuelle, carnet, ...) de préférence <strong>sous forme de '
                             .Session::get('mail_fmt', 'html').'</strong>',
                 'weight' => 30
+            ),
+            Array(
+                'url'    => 'preferences.php?rss='.(intval(Session::get('core_rss_hash')=='')),
+                'title'  => (Session::get('core_rss_hash') ? 'désactiver' : 'activer').' les fils rss',
+                'text'   => 'Ceci te permet d\'utiliser les fils rss du site. Attention, désactiver puis réactiver les fils en change les URL !',
+                'weight' => 40
             )
         );
 }
diff --git a/htdocs/images/rssicon.gif b/htdocs/images/rssicon.gif
new file mode 100644 (file)
index 0000000..c81ac37
Binary files /dev/null and b/htdocs/images/rssicon.gif differ
index f74f1b6..0c84ded 100644 (file)
@@ -44,8 +44,21 @@ if (Env::has('mail_fmt')) {
     if ($fmt != 'texte') $fmt = 'html';
     $globals->xdb->execute("REPLACE INTO auth_user_quick
                                      SET core_mail_fmt = '$fmt'
-                                   WHERE user_id = {?}", Session::get('uid'));
+                                   WHERE user_id = {?}", Session::getInt('uid'));
     $_SESSION['mail_fmt'] = $fmt;
+    header('Location: preferences.php');
+}
+
+if (Env::has('rss')) {
+    if (Env::getBool('rss')) {
+        $_SESSION['core_rss_hash'] = rand_url_id(16);
+        $globals->xdb->execute('UPDATE auth_user_quick SET core_rss_hash={?} WHERE user_id={?}',
+                Session::get('core_rss_hash'), Session::getInt('uid'));
+    } else {
+        $globals->xdb->execute('UPDATE auth_user_quick SET core_rss_hash="" WHERE user_id={?}', Session::getInt('uid'));
+        Session::kill('core_rss_hash');
+    }
+    header('Location: preferences.php');
 }
 
 $page->assign('prefs', $globals->hook->prefs());
index 8d98b07..d2e0f51 100644 (file)
  ***************************************************************************/
 
 require_once('xorg.inc.php');
-new_nonhtml_page('rss.tpl', AUTH_PUBLIC);
-
 require_once('rss.inc.php');
 
+list($alias, $hash) = init_rss('rss.tpl');
+
 $rss = $globals->xdb->iterator(
         'SELECT  e.id, e.titre, e.texte, e.creation_date
-           FROM  evenements AS e
-          WHERE  FIND_IN_SET(flags, "valide") AND peremption >= NOW()
-                 AND (e.promo_min = 0 || e.promo_min <= {?})
-                 AND (e.promo_max = 0 || e.promo_max >= {?})
-       ORDER BY  (e.promo_min != 0 AND e.promo_max != 0) DESC, e.peremption',
-       Env::getInt('promo', 3000), Env::getInt('promo'));
+           FROM  evenements      AS e
+     INNER JOIN  aliases         AS a ON ( a.alias = {?} AND a.type != "homonyme" )
+     INNER JOIN  auth_user_quick AS q ON ( a.id = q.user_id AND core_rss_hash = {?} )
+     INNER JOIN  auth_user_md5   AS u USING(user_id)
+          WHERE  FIND_IN_SET(e.flags, "valide") AND peremption >= NOW()
+                 AND (e.promo_min = 0 || e.promo_min <= u.promo)
+                 AND (e.promo_max = 0 || e.promo_max >= u.promo)',
+        $alias, $hash);
 $page->assign('rss', $rss);
 
-header('Content-Type: text/xml; charset=utf-8');
 $page->run();
 ?> 
index f2366e1..a37fc54 100644 (file)
@@ -32,10 +32,24 @@ function to_rss ($s)
     }
 }
 
-$page->register_modifier('rss_date', '_rss_encode_date');
-$page->default_modifiers = Array('@to_rss');
 
-header('Content-Type: text/xml; charset=utf-8');
+function init_rss($template)
+{
+    global $page;
+    new_nonhtml_page($template, AUTH_PUBLIC);
+    $page->register_modifier('rss_date', '_rss_encode_date');
+    $page->default_modifiers = Array('@to_rss');
+
+    if (preg_match(',^/([^/]+)/([^/]+)\.xml$,', $_SERVER['PATH_INFO'], $m)) {
+        $alias = $m[1];
+        $hash  = $m[2];
+    } else {
+        exit;
+    }
+
+    header('Content-Type: application/rss+xml; charset=utf8');
+    return Array($alias, $hash);
+}
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 5541a66..d9e9252 100644 (file)
@@ -326,9 +326,9 @@ function start_connexion ($uid, $identified)
 {
     global $globals;
     $res  = $globals->xdb->query("
-       SELECT  u.user_id AS uid, prenom, nom, perms, promo, matricule, UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, q.core_mail_fmt AS mail_fmt,
-                a.alias AS forlife, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last,
-               a2.alias AS bestalias, password, FIND_IN_SET('femme', u.flags) AS femme
+       SELECT  u.user_id AS uid, prenom, nom, perms, promo, matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
+                UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, a.alias AS forlife, a2.alias AS bestalias,
+                q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash
           FROM  auth_user_md5   AS u
     INNER JOIN  auth_user_quick AS q  USING(user_id)
     INNER JOIN aliases         AS a  ON (u.user_id = a.id AND a.type='a_vie')
index 4477896..99c5823 100644 (file)
@@ -110,6 +110,11 @@ Bienvenue {$smarty.session.prenom}
   <p>
   <a href="evenements.php">Proposer une information événementielle</a>
   </p>
+  {if $smarty.session.core_rss_hash}
+  <div class="right">
+    <a href='{rel}/rss.php/{$smarty.session.forlife}/{$smarty.session.core_rss_hash}.xml'><img src='{rel}/images/rssicon.gif' alt='fil rss' /></a>
+  </div>
+  {/if}
 {/if}
 
 {* vim:set et sw=2 sts=2 sws=2: *}
index 572d274..950a153 100644 (file)
@@ -7,3 +7,4 @@ alter table auth_user_quick add column core_mail_fmt enum('html', 'texte') not n
 alter table auth_user_quick add column profile_nick varchar(64) not null;
 alter table auth_user_quick add index(profile_nick);
 
+alter table auth_user_quick add column core_rss_hash char(32) not null default '';