From 9042fe48d22ecd3686e6dfd546c63922e5fbfcaf Mon Sep 17 00:00:00 2001 From: "Pierre Habouzit (MadCoder" Date: Mon, 17 Jan 2005 08:30:29 +0000 Subject: [PATCH] better rss handling git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-369 --- hooks/tmp.inc.php | 8 +++++++- htdocs/images/rssicon.gif | Bin 0 -> 451 bytes htdocs/preferences.php | 15 ++++++++++++++- htdocs/rss.php | 19 ++++++++++--------- include/rss.inc.php | 20 +++++++++++++++++--- include/xorg/session.inc.php | 6 +++--- templates/login.tpl | 5 +++++ upgrade/0.9.4/30_auth_user_quick.sql | 1 + 8 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 htdocs/images/rssicon.gif diff --git a/hooks/tmp.inc.php b/hooks/tmp.inc.php index 7ab7913..7e294e6 100644 --- a/hooks/tmp.inc.php +++ b/hooks/tmp.inc.php @@ -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 sous forme de ' + 'text' => 'Tu recois les mails envoyés par le site (lettre mensuelle, carnet, ...) de préférence sous forme de ' .Session::get('mail_fmt', 'html').'', '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 index 0000000000000000000000000000000000000000..c81ac37573dd930467aae63f60e52fa6eeff10c3 GIT binary patch literal 451 zcmV;!0X+UkNk%w1VI%+!0M!5h|7HOH|NlQ40sqLPeKP|8npfpk0O6Z=#zX+{T>#Z~ zME{RO`(yy{&Ab14BIsBE_+kM6_3r=R%*s#^@uheB^X~tJGx55a*@9KwQUKIf5&zb^ z|8NoX+RXjInca_O{@~2%pm+bHX8*W|{I-b7MgZ4iBLA&-+hro>VG-6%0Op@}|LfiV znN{R>F723R?RhinmuCOw)t^BF*mp!B4gvi0?&!3c>{|fzUjY5|?)sKh&Rrq^00000 z00000A^8LV00000EC2ui03-ko000KyK-pkOEEtJzTSQ+zm70xtk7uu^;)2M>FFe}QpUPGSfK6aj%^7%2%4C@kjw2B|JO&$MASVD2qhh6}n{#S3B@i4T9b*&#v$bNkt%(5$4FNX^01gZW8V3Ol z2FA$B%)L#D4mJTX01+fD3m%Rt+T7j;D$)Ro06PH{Fll2K69(>L@S0C@PY4K2I0z*< tCKM=`fFJ_{009RUJa`Y$6(0gA1ZdpIv7^V29%}>v06VhAx-kF% literal 0 HcmV?d00001 diff --git a/htdocs/preferences.php b/htdocs/preferences.php index f74f1b6..0c84ded 100644 --- a/htdocs/preferences.php +++ b/htdocs/preferences.php @@ -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()); diff --git a/htdocs/rss.php b/htdocs/rss.php index 8d98b07..d2e0f513 100644 --- a/htdocs/rss.php +++ b/htdocs/rss.php @@ -20,20 +20,21 @@ ***************************************************************************/ 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(); ?> diff --git a/include/rss.inc.php b/include/rss.inc.php index f2366e1..a37fc54 100644 --- a/include/rss.inc.php +++ b/include/rss.inc.php @@ -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: ?> diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index 5541a66..d9e9252 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -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') diff --git a/templates/login.tpl b/templates/login.tpl index 4477896..99c5823 100644 --- a/templates/login.tpl +++ b/templates/login.tpl @@ -110,6 +110,11 @@ Bienvenue {$smarty.session.prenom}

Proposer une information événementielle

+ {if $smarty.session.core_rss_hash} +
+ fil rss +
+ {/if} {/if} {* vim:set et sw=2 sts=2 sws=2: *} diff --git a/upgrade/0.9.4/30_auth_user_quick.sql b/upgrade/0.9.4/30_auth_user_quick.sql index 572d274..950a153 100644 --- a/upgrade/0.9.4/30_auth_user_quick.sql +++ b/upgrade/0.9.4/30_auth_user_quick.sql @@ -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 ''; -- 2.1.4