Convert miniwiki of the freetext to text in the vcards.
[platal.git] / include / banana / forum.inc.php
index 8b72904..3e14a78 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -27,38 +27,32 @@ 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'];
-
-    return $base . hook_platalMessageLink($params);
-}
-
 class ForumsBanana extends Banana
 {
-    function __construct($params = null)
+    private $forlife;
+
+    public function __construct($forlife, $params = null)
     {
+        $this->forlife = $forlife;
+
         global $globals;
         Banana::$msgedit_canattach = false;
+        Banana::$spool_root = $globals->banana->spool_root;
         array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
-        Banana::$nntp_host = 'news://web_'.S::v('forlife')
+        Banana::$nntp_host = 'news://web_'.$forlife
                            . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
         if (S::has_perms()) {
             Banana::$msgshow_mimeparts[] = 'source';
         }
-        parent::__construct($params);
+        Banana::$debug_nntp = ($globals->debug & DEBUG_BT);
+        Banana::$debug_smarty = ($globals->debug & DEBUG_SMARTY);
+        if (!S::v('core_rss_hash')) {
+            Banana::$feed_active = false;
+        }
+        parent::__construct($params, 'NNTP', 'PlatalBananaPage');
+        if (@$params['action'] == 'profile') {
+            Banana::$action = 'profile';
+        }
     }
 
     public function run()
@@ -74,35 +68,40 @@ class ForumsBanana extends Banana
 
         // Get user profile from SQL
         $req = XDB::query("SELECT  nom, mail, sig,
-                                   FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
+                                   FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags),
+                                   tree_unread, tree_read
                              FROM  {$globals->banana->table_prefix}profils
                             WHERE  uid={?}", S::i('uid'));
-        if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
+        if (!(list($nom, $mail, $sig, $disp, $maj, $unread, $read) = $req->fetchOneRow())) {
             $nom  = S::v('prenom')." ".S::v('nom');
-            $mail = S::v('forlife')."@polytechnique.org";
+            $mail = S::v('forlife')."@" . $globals->mail->domain;
             $sig  = $nom." (".S::v('promo').")";
             $disp = 0;
             $maj  = 1;
+            $unread = 'o';
+            $read   = 'dg';
         }
         if ($maj) {
             $time = time();
         }
 
         // Build user profile
-        $req = XDB::query("      
-                 SELECT  nom     
+        $req = XDB::query("
+                 SELECT  nom
                    FROM  {$globals->banana->table_prefix}abos
               LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
                   WHERE  uid={?}", S::i('uid'));
-        Banana::$profile['headers']['From']         = utf8_encode("$nom <$mail>");
-        Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
-        Banana::$profile['signature']               = utf8_encode($sig);
+        Banana::$profile['headers']['From']         = "$nom <$mail>";
+        Banana::$profile['headers']['Organization'] = make_Organization();
+        Banana::$profile['signature']               = $sig;
         Banana::$profile['display']                 = $disp;
         Banana::$profile['autoup']                  = $maj;
         Banana::$profile['lastnews']                = S::v('banana_last');
         Banana::$profile['subscribe']               = $req->fetchColumn();
+        Banana::$tree_unread = $unread;
+        Banana::$tree_read = $read;
 
-        // Update the "unread limit" 
+        // Update the "unread limit"
         if (!is_null($time)) {
             XDB::execute("UPDATE  auth_user_quick
                              SET  banana_last = FROM_UNIXTIME({?})
@@ -110,18 +109,42 @@ class ForumsBanana extends Banana
                          $time, S::i('uid'));
         }
 
-        // Register custom Banana links and tabs
-        if (!Banana::$profile['autoup']) {
-            Banana::$page->registerAction('<a href=\'javascript:dynpostkv("'
-                                . $platal->path . '", "updateall", ' . time() . ')\'>'
-                                . 'Marquer tous les messages comme lus'
-                                . '</a>', array('forums', 'thread', 'message'));
-        }   
-        Banana::$page->registerPage('profile', utf8_encode('Préférences'), null);
-        
+        if (!empty($GLOBALS['IS_XNET_SITE'])) {
+            Banana::$page->killPage('forums');
+            Banana::$page->killPage('subscribe');
+            Banana::$spool_boxlist = false;
+        } else {
+            // Register custom Banana links and tabs
+            if (!Banana::$profile['autoup']) {
+                Banana::$page->registerAction('<a href=\'javascript:dynpostkv("'
+                                    . $platal->path . '", "updateall", ' . time() . ')\'>'
+                                    . 'Marquer tous les messages comme lus'
+                                    . '</a>', array('forums', 'thread', 'message'));
+            }
+            Banana::$page->registerPage('profile', 'Préférences', null);
+        }
+
+        // Run Bananai
+        if (Banana::$action == 'profile') {
+            Banana::$page->run();
+            return $this->action_updateProfile();
+        } else {
+            return parent::run();
+        }
+    }
 
-        // Run Banana
-        return parent::run();
+    public function post($dest, $reply, $subject, $body)
+    {
+        global $globals;
+        $res = XDB::query('SELECT  nom, prenom, promo, b.alias AS bestalias
+                             FROM  auth_user_md5 AS u
+                       INNER JOIN  aliases       AS a ON (a.id = u.user_id)
+                       INNER JOIN  aliases       AS b ON (b.id = a.id AND FIND_IN_SET(\'bestalias\', b.flags))
+                            WHERE  a.alias = {?}', $this->forlife);
+        list($nom, $prenom, $promo, $bestalias) = $res->fetchOneRow();
+        Banana::$profile['headers']['From']         = "$prenom $nom ($promo) <$bestalias@{$globals->mail->domain}>";
+        Banana::$profile['headers']['Organization'] = make_Organization();
+        return parent::post($dest, $reply, $subject, $body);
     }
 
     protected function action_saveSubs($groups)
@@ -153,6 +176,75 @@ class ForumsBanana extends Banana
             Banana::$profile['subscribe'][] = $g;
         }
     }
+
+    protected function action_updateProfile()
+    {
+        global $page, $globals;
+
+        $colors = glob(dirname(__FILE__) . '/../../htdocs/images/banana/m2*.gif');
+        foreach ($colors as $key=>$path) {
+            $path = basename($path, '.gif');
+            $colors[$key] = substr($path, 2);
+        }
+        $page->assign('colors', $colors);
+
+        if (Post::has('action') && Post::v('action') == 'Enregistrer') {
+            S::assert_xsrf_token();
+            $flags = new FlagSet();
+            if (Post::b('bananadisplay')) {
+                $flags->addFlag('threads');
+            }
+            if (Post::b('bananaupdate')) {
+                $flags->addFlag('automaj');
+            }
+            if (Post::b('bananaxface')) {
+                $flags->addFlag('xface');
+            }
+            $unread = Post::s('unread');
+            $read = Post::s('read');
+            if (!in_array($unread, $colors) || !in_array($read, $colors)) {
+                $page->trigError('Le choix de type pour l\'arborescence est invalide');
+            } elseif (XDB::execute("REPLACE INTO  forums.profils (uid, sig, mail, nom, flags, tree_unread, tree_read)
+                                           VALUES  ({?}, {?}, {?}, {?}, {?}, {?}, {?})",
+                                    S::v('uid'), Post::v('bananasig'),
+                                    Post::v('bananamail'), Post::v('banananame'),
+                                    $flags, $unread, $read)) {
+                $page->trigSuccess("Ton profil a été enregistré avec succès.");
+            } else {
+                $page->trigError("Une erreur s'est produite lors de l'enregistrement de ton profil");
+            }
+        }
+
+        $req = XDB::query("
+            SELECT  nom, mail, sig,
+                    FIND_IN_SET('threads', flags),
+                    FIND_IN_SET('automaj', flags),
+                    FIND_IN_SET('xface', flags),
+                    tree_unread,
+                    tree_read
+              FROM  forums.profils
+             WHERE  uid = {?}", S::v('uid'));
+        if (!(list($nom, $mail, $sig, $disp, $maj, $xface, $unread, $read) = $req->fetchOneRow())) {
+            $nom   = S::v('prenom').' '.S::v('nom');
+            $mail  = S::v('forlife').'@'.$globals->mail->domain;
+            $sig   = $nom.' ('.S::v('promo').')';
+            $disp  = 0;
+            $maj   = 0;
+            $xface = 0;
+            $unread = 'o';
+            $read  = 'dg';
+        }
+        $page->assign('nom' ,  $nom);
+        $page->assign('mail',  $mail);
+        $page->assign('sig',   $sig);
+        $page->assign('disp',  $disp);
+        $page->assign('maj',   $maj);
+        $page->assign('xface', $xface);
+        $page->assign('unread', $unread);
+        $page->assign('read', $read);
+        return null;
+    }
 }
 
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>