From: Pierre Habouzit (MadCoder
Date: Fri, 7 Jan 2005 15:55:43 +0000 (+0000)
Subject: rework banana A LOT
X-Git-Tag: xorg/old~521
X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=27c49531895908607cdf9ee5bbdf949847ab0546;p=platal.git
rework banana A LOT
git-archimport-id: opensource@polytechnique.org--2005/platal--mainline--0.9--patch-229
---
diff --git a/htdocs/banana/article.php b/htdocs/banana/article.php
deleted file mode 100644
index 449ede7..0000000
--- a/htdocs/banana/article.php
+++ /dev/null
@@ -1,18 +0,0 @@
-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
index 449ede7..0000000
--- a/htdocs/banana/disconnect.php
+++ /dev/null
@@ -1,18 +0,0 @@
-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
index 44027be..0000000
--- a/htdocs/banana/include/.arch-inventory
+++ /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
index acb6c35..0000000
--- a/htdocs/banana/include/footer.inc.php
+++ /dev/null
@@ -1,2 +0,0 @@
-
diff --git a/htdocs/banana/include/hack.inc.php b/htdocs/banana/include/hack.inc.php
deleted file mode 100644
index f2089b3..0000000
--- a/htdocs/banana/include/hack.inc.php
+++ /dev/null
@@ -1,155 +0,0 @@
-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 '[Liste des forums] [Profil] ';
- break;
-
- case 'index.php' :
- case 'thread.php' :
- case 'article.php' :
- case 'post.php' :
- $res = '';
- if (!$banana->profile['autoup']) {
- $res .= '[Mettre à jour] ';
- }
- return $res . '[Profil] ';
- break;
- }
-}
-
-function hook_formatDisplayHeader($_header,$_text) {
- global $banana;
- switch ($_header) {
- case "x-org-id":
- return "$_text".(preg_match("/[\w]+\.[\w\d]+/",$_text)?" []":"");
-
- 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
index acb6c35..0000000
--- a/htdocs/banana/include/header.inc.php
+++ /dev/null
@@ -1,2 +0,0 @@
-
diff --git a/htdocs/banana/include/subscribe.inc.php b/htdocs/banana/include/subscribe.inc.php
deleted file mode 100644
index 6e86c65..0000000
--- a/htdocs/banana/include/subscribe.inc.php
+++ /dev/null
@@ -1,41 +0,0 @@
-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);
- }
-}
-
-?>
diff --git a/htdocs/banana/index.php b/htdocs/banana/index.php
index 449ede7..bf0433d 100644
--- a/htdocs/banana/index.php
+++ b/htdocs/banana/index.php
@@ -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();
?>
diff --git a/htdocs/banana/install.sh b/htdocs/banana/install.sh
index f7007ed..a2003c2 100755
--- a/htdocs/banana/install.sh
+++ b/htdocs/banana/install.sh
@@ -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
index 449ede7..0000000
--- a/htdocs/banana/post.php
+++ /dev/null
@@ -1,18 +0,0 @@
-caching = false;
-require_once('hack.inc.php');
-
-$page->register_function('banana', 'banana', false);
-
-$page->run();
-?>
diff --git a/htdocs/confbanana.php b/htdocs/banana/profile.tpl
similarity index 98%
rename from htdocs/confbanana.php
rename to htdocs/banana/profile.tpl
index c387f44..61996f4 100644
--- a/htdocs/confbanana.php
+++ b/htdocs/banana/profile.tpl
@@ -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
index 820ab7d..0000000
--- a/htdocs/banana/scripts/spoolgen.php
+++ /dev/null
@@ -1,47 +0,0 @@
-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
index 449ede7..0000000
--- a/htdocs/banana/subscribe.php
+++ /dev/null
@@ -1,18 +0,0 @@
-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
index 449ede7..0000000
--- a/htdocs/banana/thread.php
+++ /dev/null
@@ -1,18 +0,0 @@
-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
index 0000000..f5f27cd
--- /dev/null
+++ b/include/banana
@@ -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
index 0000000..fdd249c
--- /dev/null
+++ b/include/banana.inc.php
@@ -0,0 +1,110 @@
+fiche]";
+ }
+}
+
+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;
+ }
+ }
+}
+
+?>
diff --git a/templates/banana.head.tpl b/templates/banana/index.head.tpl
similarity index 100%
rename from templates/banana.head.tpl
rename to templates/banana/index.head.tpl
diff --git a/templates/banana.tpl b/templates/banana/index.tpl
similarity index 89%
rename from templates/banana.tpl
rename to templates/banana/index.tpl
index 9973d49..822e6a5 100644
--- a/templates/banana.tpl
+++ b/templates/banana/index.tpl
@@ -18,6 +18,15 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************}
-{banana}
+Options
+
+{if !$banana->profile.autoup}
+[Mettre à jour]
+{/if}
+[Profil]
+
+
+
+{$banana_res|smarty:nodefaults}
{* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/templates/confbanana.tpl b/templates/banana/profile.tpl
similarity index 97%
rename from templates/confbanana.tpl
rename to templates/banana/profile.tpl
index 17bc21f..9617f4b 100644
--- a/templates/confbanana.tpl
+++ b/templates/banana/profile.tpl
@@ -37,7 +37,7 @@
n'afficher que les fils de discussion contenant des messages lus.
- Retour aux forums
+Retour aux forums