rework banana A LOT
authorPierre Habouzit (MadCoder <pierre.habouzit@m4x.org>
Fri, 7 Jan 2005 15:55:43 +0000 (15:55 +0000)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 26 Jun 2008 21:27:13 +0000 (23:27 +0200)
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-229

19 files changed:
htdocs/banana/article.php [deleted file]
htdocs/banana/disconnect.php [deleted file]
htdocs/banana/include/.arch-inventory [deleted file]
htdocs/banana/include/footer.inc.php [deleted file]
htdocs/banana/include/hack.inc.php [deleted file]
htdocs/banana/include/header.inc.php [deleted file]
htdocs/banana/include/subscribe.inc.php [deleted file]
htdocs/banana/index.php
htdocs/banana/install.sh
htdocs/banana/post.php [deleted file]
htdocs/banana/profile.tpl [moved from htdocs/confbanana.php with 98% similarity]
htdocs/banana/scripts/spoolgen.php [deleted file]
htdocs/banana/subscribe.php [deleted file]
htdocs/banana/thread.php [deleted file]
include/banana [new symlink]
include/banana.inc.php [new file with mode: 0644]
templates/banana/index.head.tpl [moved from templates/banana.head.tpl with 100% similarity]
templates/banana/index.tpl [moved from templates/banana.tpl with 89% similarity]
templates/banana/profile.tpl [moved from templates/confbanana.tpl with 97% similarity]

diff --git a/htdocs/banana/article.php b/htdocs/banana/article.php
deleted file mode 100644 (file)
index 449ede7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-/********************************************************************************
-* index.php : main page (newsgroups list)
-* -----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
diff --git a/htdocs/banana/disconnect.php b/htdocs/banana/disconnect.php
deleted file mode 100644 (file)
index 449ede7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-/********************************************************************************
-* index.php : main page (newsgroups list)
-* -----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
diff --git a/htdocs/banana/include/.arch-inventory b/htdocs/banana/include/.arch-inventory
deleted file mode 100644 (file)
index 44027be..0000000
+++ /dev/null
@@ -1 +0,0 @@
-precious ^(misc|groups|NetNNTP|post|spool|banana).inc.php
diff --git a/htdocs/banana/include/footer.inc.php b/htdocs/banana/include/footer.inc.php
deleted file mode 100644 (file)
index acb6c35..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php
-?>
diff --git a/htdocs/banana/include/hack.inc.php b/htdocs/banana/include/hack.inc.php
deleted file mode 100644 (file)
index f2089b3..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-<?php
-    
-switch (basename($_SERVER['SCRIPT_NAME'])) {
-    case 'index.php':
-        if (Get::get('banana') == 'updateall') {
-            $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
-            $_SESSION['banana_last'] = time();
-        }
-}
-
-function hook_banana(&$banana) {
-    global $globals;
-
-    array_splice($banana->show_hdr,  count($banana->show_hdr)  - 2, 0, 'x-org-id');
-    array_splice($banana->parse_hdr, count($banana->parse_hdr) - 2, 0, 'x-org-id');
-
-
-    $serv  = "{$globals->banana->server}:{$globals->banana->port}/";
-    $sname = basename($_SERVER['SCRIPT_NAME']);
-    if ($sname == "spoolgen.php") {
-        $banana->host = "news://{$globals->banana->web_user}:{$globals->banana->web_pass}@$serv";
-    } elseif (Session::has('forlife')) {
-        $banana->host = 'news://web_'.Session::get('forlife').":{$globals->banana->password}@$serv";
-    }
-}
-
-function url($string)
-{
-    if(strpos($string, "http://")!==false)
-       return $string;
-    $chemins = Array('', '../', '../../');
-    foreach ($chemins as $ch) {
-        if (file_exists($ch.'../htdocs/')) {
-            return $ch.$string;
-        }
-    }
-    return '';
-}
-
-function hook_displayshortcuts($sname, $first = -1) {
-    global $banana,$css;
-    
-    switch ($sname) {
-        case 'subscribe.php' :
-            return '[<a href="index.php">Liste des forums</a>] [<a href="'.url("confbanana.php").'">Profil</a>] ';
-            break;
-
-        case 'index.php' :
-        case 'thread.php' :
-        case 'article.php' :
-        case 'post.php' :
-            $res = '';
-            if (!$banana->profile['autoup']) { 
-                $res .= '[<a href="index.php?banana=updateall">Mettre à jour</a>] ';
-            }
-            return $res . '[<a href="'.url("confbanana.php").'">Profil</a>] ';
-            break;
-    }
-}
-
-function hook_formatDisplayHeader($_header,$_text) {
-    global $banana;
-    switch ($_header) {
-        case "x-org-id":
-            return "$_text".(preg_match("/[\w]+\.[\w\d]+/",$_text)?" [<a href=\"".url("fiche.php")."?user=$_text\" class='popup2'>fiche</a>]":"");
-
-        default:
-            return htmlentities($_text);
-    }
-}
-
-function hook_header_translate($hdr) {
-    switch ($hdr) {
-        case 'x-org-id': return 'Identité';
-            
-        default:      
-            return $hdr;
-    }
-}
-
-function hook_checkcancel($_headers) {
-    return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
-}
-
-function hook_getprofile() {
-    if (logged()) {
-        global $globals;
-        
-        $uid = Session::getInt('uid');
-       $req = $globals->xdb->query(
-                "SELECT  nom,mail,sig,if(FIND_IN_SET('threads',flags),'1','0'),
-                         IF(FIND_IN_SET('automaj',flags),'1','0') 
-                   FROM  {$globals->banana->table_prefix}profils
-                  WHERE  uid={?}", $uid);
-       if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
-           $nom  = Session::get('prenom')." ".Session::get('nom');
-           $mail = Session::get('forlife')."@polytechnique.org";
-           $sig  = $nom." (".Session::getInt('promo').")";
-           $disp = 0;
-           $maj  = 1;
-       }
-       $array['name']      = "$nom <$mail>";
-       $array['sig']       = $sig;
-       $array['org']       = "Utilisateur de Polytechnique.org";
-       $array['customhdr'] = "";
-       $array['display']   = $disp;
-       $array['autoup']    = $maj;
-       $array['lastnews']  = Session::get('banana_last');
-       if ($maj) {
-            $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
-       }
-       $req = $globals->xdb->query(
-                "SELECT  nom
-                   FROM  {$globals->banana->table_prefix}abos
-              LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
-                  WHERE  uid={?}", $uid);
-       $array['subscribe'] = $req->fetchColumn();
-    } else {
-       $array = array();
-    }
-    $array['locale'] = 'fr';
-    return $array;
-}
-
-$css = array(
- 'bananashortcuts' => 'bananashortcuts',
- 'bicol' => 'bicol',
- 'bicoltitre' => 'bicoltitre',
- 'bicolvpadd' => 'bicolvpadd',
- 'pair' => 'pair',
- 'impair' => 'impair',
- 'bouton' => 'bouton',
- 'error' => 'erreur',
- 'normal' => 'normal',
- 'total' => 'bananatotal',
- 'unread' => 'bananaunread',
- 'group' => 'bananagroup',
- 'description' => 'bananadescription',
- 'date' => 'bananadate',
- 'subject' => 'bananasubject',
- 'from' => 'bananafrom',
- 'author' => 'author',
- 'nopadd' => 'banananopadd',
- 'overview' => 'bananaoverview',
- 'tree' => 'bananatree'
-);
-
-function banana($params) {
-    global $globals, $page;
-    global $banana,$css;
-    $sname = basename($_SERVER['SCRIPT_NAME']);
-    require_once("../../../banana/$sname");
-}
-
-?>
diff --git a/htdocs/banana/include/header.inc.php b/htdocs/banana/include/header.inc.php
deleted file mode 100644 (file)
index acb6c35..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<?php
-?>
diff --git a/htdocs/banana/include/subscribe.inc.php b/htdocs/banana/include/subscribe.inc.php
deleted file mode 100644 (file)
index 6e86c65..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-<?php
-
-  /** mise à jour des abonnements
-   * @param $_subscriptions ARRAY liste des forums auxquel l'utilisateur est abonné
-   */
-
-function update_subscriptions($_subscriptions) {
-    global $globals;
-    $uid = Session::getInt('uid');
-
-    $globals->xdb->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
-    if (!count($_subscriptions)) {
-        return true;
-    }
-    
-    // Récupération des fid
-    $req  = $globals->xdb->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
-    $fids =array();
-    while (list($fid,$fnom) = $req->next()) {
-        $fids[$fnom] = $fid;
-    }
-
-    // MAJ table de forums
-    if (count(array_keys($fids))) {
-        $diff = array_diff($_subscriptions,array_keys($fids));
-    } else {
-        $diff = $_subscriptions;
-    }
-    if (count($diff)) {
-        foreach ($diff as $g) {
-            $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
-            $fids[$g] = mysql_insert_id();
-        }
-    }
-    // MAJ Abonnements
-    foreach ($_subscriptions as $g) {
-        $globals->xdb->execute("REPLACE INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
-    }
-}
-
-?>
index 449ede7..bf0433d 100644 (file)
@@ -8,11 +8,11 @@
 ********************************************************************************/
 
 require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
+new_skinned_page('banana/index.tpl', AUTH_COOKIE, 'banana/index.head.tpl');
+require_once('banana.inc.php');
 
+$res = PlatalBanana::run();
+$page->assign_by_ref('banana', $banana);
+$page->assign('banana_res', $res);
 $page->run();
 ?>
index f7007ed..a2003c2 100755 (executable)
@@ -1,9 +1,3 @@
 #!/bin/bash
-ln -sf ../../../banana/{img,spool} .
-
-pushd include &> /dev/null
-ln -sf ../../../../banana/include/{groups,NetNNTP,post,spool,banana}.inc.php .
-popd &> /dev/null
-
-ln -sf ../../../banana/xface.php .
+ln -sf ../../../banana/{img,xface.php} .
 ln -sf ../../../banana/css/style.css banana.css
diff --git a/htdocs/banana/post.php b/htdocs/banana/post.php
deleted file mode 100644 (file)
index 449ede7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-/********************************************************************************
-* index.php : main page (newsgroups list)
-* -----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
similarity index 98%
rename from htdocs/confbanana.php
rename to htdocs/banana/profile.tpl
index c387f44..61996f4 100644 (file)
@@ -20,7 +20,7 @@
  ***************************************************************************/
 
 require_once("xorg.inc.php");
-new_skinned_page('confbanana.tpl', AUTH_MDP);
+new_skinned_page('banana/profile.tpl', AUTH_MDP);
 
 if (!(Post::has('action') && Post::has('banananame') && Post::has('bananasig') && Post::has('bananadisplay')
             && Post::has('bananamail') && Post::has('bananaupdate') && Post::get('action')=="OK" ))
diff --git a/htdocs/banana/scripts/spoolgen.php b/htdocs/banana/scripts/spoolgen.php
deleted file mode 100755 (executable)
index 820ab7d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-/********************************************************************************
-* spoolgen.php : spool generation
-* --------------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-ini_set('max_execution_time','300');
-ini_set('include_path', '..:../include:../../include:../../../include');
-
-require_once("include/encoding.inc.php");
-require_once("include/config.inc.php");
-require_once("include/NetNNTP.inc.php");
-require_once("include/post.inc.php");
-require_once("include/groups.inc.php");
-require_once("include/spool.inc.php");
-require_once("include/password.inc.php");
-
-
-$nntp = new nntp($news['server']);
-if (!$nntp) {
-  print "cannot connect to server\n";
-  exit;
-}
-
-if ($news['user']!="anonymous") {
-  $result = $nntp->authinfo($news["user"],$news["pass"]);
-  if (!$result) {
-    print "authentication error\n";
-    exit;
-  }
-}
-unset($result);
-
-$groups = new groups($nntp,2);
-$list = array_keys($groups->overview);
-unset($groups);
-foreach ($list as $g) {
-  print "Generating spool for $g : ";
-  $spool = new spool($nntp,$g);
-  print "done.\n";
-  unset($spool);
-}
-$nntp->quit();
-?>
diff --git a/htdocs/banana/subscribe.php b/htdocs/banana/subscribe.php
deleted file mode 100644 (file)
index 449ede7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-/********************************************************************************
-* index.php : main page (newsgroups list)
-* -----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
diff --git a/htdocs/banana/thread.php b/htdocs/banana/thread.php
deleted file mode 100644 (file)
index 449ede7..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-/********************************************************************************
-* index.php : main page (newsgroups list)
-* -----------
-*
-* This file is part of the banana distribution
-* Copyright: See COPYING files that comes with this distribution
-********************************************************************************/
-
-require_once('xorg.inc.php');
-new_skinned_page('banana.tpl', AUTH_COOKIE, 'banana.head.tpl');
-$page->caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
diff --git a/include/banana b/include/banana
new file mode 120000 (symlink)
index 0000000..f5f27cd
--- /dev/null
@@ -0,0 +1 @@
+../../banana/include
\ No newline at end of file
diff --git a/include/banana.inc.php b/include/banana.inc.php
new file mode 100644 (file)
index 0000000..fdd249c
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+require_once('banana/banana.inc.php');
+
+function hook_formatDisplayHeader($_header,$_text) {
+    global $banana;
+    if ($_header == 'x-org-id') {
+        return "$_text [<a href=\"../fiche.php?user=$_text\" class='popup2'>fiche</a>]";
+    }
+}
+
+function hook_headerTranslate($hdr) {
+    if ($hdr == 'x-org-id') {
+        return 'Identité';
+    }
+}
+
+function hook_checkcancel($_headers) {
+    return ($_headers['x-org-id'] == Session::get('forlife') or has_perms());
+}
+
+class PlatalBanana extends Banana
+{
+    var $profile   = Array( 'name' => '', 'sig'  => '', 'org'  => 'Utilisateur de Polytechnique.org',
+            'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale'  => 'fr_FR', 'subscribe' => array());
+
+    function PlatalBanana()
+    {
+        global $globals;
+    
+        $uid = Session::getInt('uid');
+        $req = $globals->xdb->query(
+                "SELECT  nom, mail, sig, FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
+                   FROM  {$globals->banana->table_prefix}profils
+                  WHERE  uid={?}", $uid);
+
+        if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
+            $nom  = Session::get('prenom')." ".Session::get('nom');
+            $mail = Session::get('forlife')."@polytechnique.org";
+            $sig  = $nom." (".Session::getInt('promo').")";
+            $disp = 0;
+            $maj  = 1;
+        }
+        $this->profile['name']      = "$nom <$mail>";
+        $this->profile['sig']       = $sig;
+        $this->profile['display']   = $disp;
+        $this->profile['autoup']    = $maj;
+        $this->profile['lastnews']  = Session::get('banana_last');
+        
+        if ($maj) {
+            $globals->xdb->execute("UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}", gmdate("YmdHis"), $uid);
+        }
+
+        $req = $globals->xdb->query(
+                "SELECT  nom
+                   FROM  {$globals->banana->table_prefix}abos
+              LEFT JOIN  {$globals->banana->table_prefix}list ON list.fid=abos.fid
+                  WHERE  uid={?}", $uid);
+        $this->profile['subscribe'] = $req->fetchColumn();
+
+        array_splice($this->show_hdr,  count($this->show_hdr)  - 2, 0, 'x-org-id');
+        array_splice($this->parse_hdr, count($this->parse_hdr) - 2, 0, 'x-org-id');
+
+        $this->host = 'news://web_'.Session::get('forlife')
+            .":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
+
+        parent::Banana();
+    }
+
+    function run()
+    {
+        global $banana;
+
+        if (Get::get('banana') == 'updateall') {
+            $globals->xdb->execute('UPDATE auth_user_quick SET banana_last={?} WHERE user_id={?}', gmdate('YmdHis'), Session::getInt('uid'));
+            $_SESSION['banana_last'] = time();
+        }
+        return Banana::run('PlatalBanana');
+    }
+
+    function action_saveSubs()
+    {
+        global $globals;
+        $uid = Session::getInt('uid');
+
+        $this->profile['subscribe'] = Array();
+        $globals->xdb->execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
+        if (!count($_POST['subscribe'])) {
+            return true;
+        }
+        
+        $req  = $globals->xdb->iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
+        $fids = array();
+        while (list($fid,$fnom) = $req->next()) {
+            $fids[$fnom] = $fid;
+        }
+
+        $diff = array_diff($_POST['subscribe'], array_keys($fids));
+        foreach ($diff as $g) {
+            $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
+            $fids[$g] = mysql_insert_id();
+        }
+
+        foreach ($_POST['subscribe'] as $g) {
+            $globals->xdb->execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})", $fids[$g], $uid);
+            $this->profile['subscribe'][] = $g;
+        }
+    }
+}
+
+?>
similarity index 89%
rename from templates/banana.tpl
rename to templates/banana/index.tpl
index 9973d49..822e6a5 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************}
 
-{banana}
+<h1>Options</h1>
+
+{if !$banana->profile.autoup}
+[<a href="?banana=updateall">Mettre à jour</a>]
+{/if}
+[<a href="profile.php">Profil</a>]
+
+<br />
+
+{$banana_res|smarty:nodefaults}
  
 {* vim:set et sw=2 sts=2 sws=2: *}
similarity index 97%
rename from templates/confbanana.tpl
rename to templates/banana/profile.tpl
index 17bc21f..9617f4b 100644 (file)
@@ -37,7 +37,7 @@
   n'afficher que les fils de discussion contenant des messages lus.
 </p>
 <p class="normal">
-  Retour aux <a href="banana/index.php">forums</a>
+Retour aux <a href="{rel}/banana/">forums</a>
 </p>
 
 <form action="{$smarty.server.PHP_SELF}" method="post">
   Ton profil est enregistré !!!
 </p>
 <p class="normal">
-  Retour aux <a href="banana/index.php">forums</a>
+Retour aux <a href="{rel}/banana/">forums</a>
 </p>
 {/if}