From 6544d0e1de719d31db03a7c7fddfe4c0301d9d6d Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Sun, 25 Feb 2007 17:25:09 +0000 Subject: [PATCH] Close #407: RSS feed for Forums and MLs git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1515 839d8a87-29fc-0310-9880-83ba4fa771e5 --- ChangeLog | 4 ++++ bin/banana.feedgen.php | 19 ++++++++++++++++++ bin/banana.spoolgen.php | 1 + bin/connect.db.inc.php | 1 + bin/cron/banana.feedgen.php | 1 + configs/platal.cron.in | 3 +++ include/banana/forum.inc.php | 25 +++--------------------- include/banana/hooks.inc.php | 43 +++++++++++++++++++++++++++++++++++++++++ include/banana/ml.inc.php | 14 +++----------- include/banana/moderate.inc.php | 1 + include/rss.inc.php | 2 +- modules/banana.php | 37 +++++++++++++++++++++++++++++------ modules/lists.php | 33 +++++++++++++++++++++++++++++++ 13 files changed, 144 insertions(+), 40 deletions(-) create mode 100755 bin/banana.feedgen.php create mode 120000 bin/cron/banana.feedgen.php diff --git a/ChangeLog b/ChangeLog index 290a5f4..63227bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,10 +12,14 @@ New: Bug/Wish: + * Banana: + - #407: RSS feed -FRU + * Profile: - Better checks on image type for photos -FRU * Lists: + - #407: RSS feed -FRU - #636: Remove non-X from trombi -FRU - #638: Sort trombi by promo then name -FRU diff --git a/bin/banana.feedgen.php b/bin/banana.feedgen.php new file mode 100755 index 0000000..f1dc65a --- /dev/null +++ b/bin/banana.feedgen.php @@ -0,0 +1,19 @@ +#!/usr/bin/php5 +banana->spool_root; +Banana::$nntp_host = "news://{$globals->banana->web_user}:{$globals->banana->web_pass}@{$globals->banana->server}:{$globals->banana->port}/"; +Banana::refreshAllFeeds(array('NNTP', 'MLArchive')); + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/bin/banana.spoolgen.php b/bin/banana.spoolgen.php index 07ceda8..c81ff44 100755 --- a/bin/banana.spoolgen.php +++ b/bin/banana.spoolgen.php @@ -11,6 +11,7 @@ require_once 'connect.db.inc.php'; require_once dirname(__FILE__).'/../include/banana/ml.inc.php'; +Banana::$spool_root = $globals->banana->spool_root; Banana::$nntp_host = "news://{$globals->banana->web_user}:{$globals->banana->web_pass}@{$globals->banana->server}:{$globals->banana->port}/"; Banana::createAllSpool(array('NNTP', 'MLArchive')); system("chown -R www-data:www-data /var/spool/banana"); diff --git a/bin/connect.db.inc.php b/bin/connect.db.inc.php index 3e61ba1..1cade25 100644 --- a/bin/connect.db.inc.php +++ b/bin/connect.db.inc.php @@ -26,5 +26,6 @@ require_once('xorg.misc.inc.php'); require_once 'xdb.php'; +$globals->baseurl = "https://www.polytechnique.org"; // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/bin/cron/banana.feedgen.php b/bin/cron/banana.feedgen.php new file mode 120000 index 0000000..355e1d0 --- /dev/null +++ b/bin/cron/banana.feedgen.php @@ -0,0 +1 @@ +../banana.feedgen.php \ No newline at end of file diff --git a/configs/platal.cron.in b/configs/platal.cron.in index 546d3b3..10ebba3 100644 --- a/configs/platal.cron.in +++ b/configs/platal.cron.in @@ -18,6 +18,9 @@ WD=/home/web/prod/platal/bin/cron # validations 0 */3 * * * web cd $WD; ./cron_validations.php +# flux rss de banana +*/5 * * * * web cd $WD; ./banana.feedgen.php > /dev/null + # AX spammer 15 * * * * web cd $WD; ./axletter.send.php | mail -e -s "envoi d'un mail de l'AX" br@staff.m4x.org diff --git a/include/banana/forum.inc.php b/include/banana/forum.inc.php index bd8ea66..3061c7a 100644 --- a/include/banana/forum.inc.php +++ b/include/banana/forum.inc.php @@ -27,28 +27,6 @@ function hook_checkcancel($_headers) return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms()); } -function hook_makeLink($params) -{ - global $globals; - $base = $globals->baseurl . '/banana'; - if (isset($params['page'])) { - return $base . '/' . $params['page']; - } - if (@$params['action'] == 'subscribe') { - return $base . '/subscription'; - } - - if (!isset($params['group'])) { - return $base; - } - $base .= '/' . $params['group']; - $base = $base . hook_platalMessageLink($params); - if (@$params['action'] == 'showext') { - $base .= '?action=showext'; - } - return $base; -} - class ForumsBanana extends Banana { function __construct($params = null) @@ -63,6 +41,9 @@ class ForumsBanana extends Banana Banana::$msgshow_mimeparts[] = 'source'; } Banana::$debug_nntp = ($globals->debug & 1); + if (!S::v('core_rss_hash')) { + Banana::$feed_active = false; + } parent::__construct($params); } diff --git a/include/banana/hooks.inc.php b/include/banana/hooks.inc.php index 1ce979d..493e560 100644 --- a/include/banana/hooks.inc.php +++ b/include/banana/hooks.inc.php @@ -69,6 +69,16 @@ function hook_formatDisplayHeader($_header, $_text, $in_spool = false) return null; } +function hook_platalRSS($group) +{ + if ($group) { + $group .= '/'; + } else { + $group = ''; + } + return '/rss/' . $group . S::v('forlife') . '/' . S::v('core_rss_hash') . '/rss.xml'; +} + function hook_platalMessageLink($params) { $base = ''; @@ -115,5 +125,38 @@ function hook_makeImg($img, $alt, $height, $width) return '' . $alt . ''; } +function hook_makeLink($params) +{ + global $globals, $platal; + if (Banana::$protocole->name() == 'NNTP') { + $base = $globals->baseurl . '/banana'; + if (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom') { + return $base . hook_platalRSS(@$params['group']); + } + if (isset($params['page'])) { + return $base . '/' . $params['page']; + } + if (@$params['action'] == 'subscribe') { + return $base . '/subscription'; + } + + if (!isset($params['group'])) { + return $base; + } + $base .= '/' . $params['group']; + } else if (Banana::$protocole->name() == 'MLArchives') { + $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives'; + if (@$params['action'] == 'rss' || @$params['action'] == 'rss2' || @$params['action'] == 'atom') { + return $base . hook_platalRSS(MLBanana::$listname); + } + $base .= '/' . MLBanana::$listname; + } + $base = $base . hook_platalMessageLink($params); + if (@$params['action'] == 'showext') { + $base .= '?action=showext'; + } + return $base; +} + // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?> diff --git a/include/banana/ml.inc.php b/include/banana/ml.inc.php index 9cc5ec0..b635346 100644 --- a/include/banana/ml.inc.php +++ b/include/banana/ml.inc.php @@ -22,17 +22,6 @@ require_once 'banana/banana.inc.php'; require_once 'banana/hooks.inc.php'; -function hook_makeLink($params) -{ - global $globals, $platal; - $base = $globals->baseurl . '/' . $platal->ns . 'lists/archives/' . MLBanana::$listname; - $base = $base . hook_platalMessageLink($params); - if (@$params['action'] == 'showext') { - $base .= '?action=showext'; - } - return $base; -} - class MLBanana extends Banana { static public $listname; @@ -50,6 +39,9 @@ class MLBanana extends Banana Banana::$msgshow_mimeparts[] = 'source'; } array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail'); + if (!S::v('core_rss_hash')) { + Banana::$feed_active = false; + } MLBanana::$listname = $params['listname']; MLBanana::$domain = $params['domain']; diff --git a/include/banana/moderate.inc.php b/include/banana/moderate.inc.php index 138c653..e4c03af 100644 --- a/include/banana/moderate.inc.php +++ b/include/banana/moderate.inc.php @@ -69,6 +69,7 @@ class ModerationBanana extends Banana Banana::$withtabs = false; Banana::$msgshow_externalimages = false; Banana::$msgshow_mimeparts[] = 'source'; + Banana::$feed_active = false; array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail'); parent::__construct($params, 'MLInterface', 'ModerationPage'); } diff --git a/include/rss.inc.php b/include/rss.inc.php index dfa0c43..a52bfbe 100644 --- a/include/rss.inc.php +++ b/include/rss.inc.php @@ -25,7 +25,7 @@ function _rss_encode_date($d) { } else { $t = strtotime($d); } - return utf8_encode(date('r', $t)); + return date('r', $t); } function to_rss ($s) diff --git a/modules/banana.php b/modules/banana.php index 2bf9797..85f8db7 100644 --- a/modules/banana.php +++ b/modules/banana.php @@ -27,7 +27,7 @@ class BananaModule extends PLModule 'banana' => $this->make_hook('banana', AUTH_COOKIE), 'banana/profile' => $this->make_hook('profile', AUTH_MDP), 'banana/subscription' => $this->make_hook('subscription', AUTH_COOKIE), - 'banana/xface' => $this->make_hook('xface', AUTH_COOKIE), + 'banana/rss' => $this->make_hook('rss', AUTH_PUBLIC), ); } @@ -136,12 +136,29 @@ class BananaModule extends PLModule return $this->run_banana($page, Array('action' => 'subscribe')); } - function handler_xface(&$page, $face = null) + function handler_rss(&$page, $group, $alias, $hash, $file = null) { - header('Content-Type: image/gif'); - passthru('echo ' . escapeshellarg(base64_decode(strtr($face, '.:', '+/'))) - . '| uncompface -X ' - . '| convert -transparent white xbm:- gif:-'); + if (is_null($file)) { + if (is_null($hash)) { + exit; + } + $this->handler_rss($page, null, $group, $alias, $hash); + } + require_once('rss.inc.php'); + $uid = init_rss(null, $alias, $hash); + if (!$uid) { + exit; + } + $res = XDB::query("SELECT id AS uid, alias AS forlife + FROM aliases + WHERE type = 'a_vie' AND id = {?}", $uid); + $row = $res->fetchOneAssoc(); + $_SESSION = array_merge($row, $_SESSION); + + require_once 'banana/forum.inc.php'; + $banana = new ForumsBanana(array('group' => $group, 'action' => 'rss2')); + echo $banana->run(); + exit; } static function run_banana(&$page, $params = null) @@ -157,6 +174,14 @@ class BananaModule extends PLModule $page->assign('banana_res', $res); $page->addCssInline($banana->css()); $page->addCssLink('banana.css'); + $rss = $banana->feed(); + if ($rss) { + if (@$params['group']) { + $page->setRssLink('Banana :: ' . $params['group'], $rss); + } else { + $page->setRssLink('Banana :: Abonnements', $rss); + } + } new PlBacktrace('NNTP', $banana->backtrace(), 'response', 'time'); } } diff --git a/modules/lists.php b/modules/lists.php index 24a63a3..9ae5ce2 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -33,6 +33,7 @@ class ListsModule extends PLModule 'lists/members' => $this->make_hook('members', AUTH_COOKIE), 'lists/trombi' => $this->make_hook('trombi', AUTH_COOKIE), 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE), + 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC), 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP), 'lists/admin' => $this->make_hook('admin', AUTH_MDP), @@ -383,12 +384,44 @@ class ListsModule extends PLModule $page->assign('banana', $banana->run()); $page->addCssInline($banana->css()); $page->addCssLink('banana.css'); + $rss = $banana->feed(); + if ($rss) { + $page->setRssLink('Banana :: ' . $list, $rss); + } new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time'); } else { $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter"); } } + function handler_rss(&$page, $liste = null, $alias = null, $hash = null) + { + require_once('rss.inc.php'); + $uid = init_rss(null, $alias, $hash); + if (!$uid || !$liste) { + exit; + } + + $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife + FROM auth_user_md5 AS u + INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie') + WHERE u.user_id = {?}", $uid); + $row = $res->fetchOneAssoc(); + $_SESSION = array_merge($row, $_SESSION); + + $domain = $this->prepare_client($page); + if (list($det) = $this->client->get_members($liste)) { + if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) + && !$det['own'] && ($det['sub'] < 2)) { + exit; + } + require_once('banana/ml.inc.php'); + $banana = new MLBanana(Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2')); + echo $banana->run(); + } + exit; + } + function moderate_mail($domain, $liste, $mid) { $mail = $this->client->get_pending_mail($liste, $mid); -- 2.1.4