From 90a5e8c8718792ec05285e967aae13f3a685bc8b Mon Sep 17 00:00:00 2001
From: x2000habouzit
Date: Thu, 28 Oct 2004 20:28:40 +0000
Subject: [PATCH] huge piece of code to abstract the notion of Trombino ...
Closes FS#135
The classe XOrgPlugin has been invented to provide some support for big plugins that we want everywhere (like a trombi)
and that are \$_GET driven. The class is made only to manage the $_GET args atm
Note that one restriction (current) is that for a given instance of the class, the plugin cannot been used more that once
(some prefix mechanism should been implemented, but since the need is not here, and that it complicates the code a lot ... not done atm
---
ChangeLog | 7 +++++
htdocs/listes/trombi.php | 45 ++++++++++++++---------------
htdocs/mescontacts.php | 32 ++++++++++++++++++++-
htdocs/trombipromo.php | 64 ++++++++++++++++++++++-------------------
include/trombi.inc.php | 59 ++++++++++++++++++++++++++++++++++++++
include/xorg.plugin.inc.php | 62 ++++++++++++++++++++++++++++++++++++++++
scripts/mailman/mailman-rpc.py | 14 +++++++--
templates/include/trombi.tpl | 65 ++++++++++++++++++++++++++++++++++++++++++
templates/listes/trombi.tpl | 33 ++-------------------
templates/mescontacts.tpl | 27 +++++++++++++++---
templates/trombipromo.tpl | 51 ++-------------------------------
11 files changed, 318 insertions(+), 141 deletions(-)
create mode 100644 include/trombi.inc.php
create mode 100644 include/xorg.plugin.inc.php
create mode 100644 templates/include/trombi.tpl
diff --git a/ChangeLog b/ChangeLog
index 24d82cc..2604273 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,10 @@ VERSION 0.9.2 ~20 Nov 2004
Changes :
+ * Core :
+ - Creation of the Plugin class. -MC
+ - First instance of the plugin class : class Trombi. (FS#135) -MC
+
* Lists :
- Refusal message is shown on mail moderation page. (FS#138) -MC
@@ -11,6 +15,9 @@ Changes :
- Women now have a • (no more dirty gender icons). (FS#122) -MC
- Nicer icons. -MC
+ * Contacts :
+ - Trombino of the contacts is available ! (FS#138) -MC
+
Fixes (from 0.9.1 branch) :
* Lists :
diff --git a/htdocs/listes/trombi.php b/htdocs/listes/trombi.php
index d69dc43..64440a4 100644
--- a/htdocs/listes/trombi.php
+++ b/htdocs/listes/trombi.php
@@ -18,43 +18,50 @@
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: trombi.php,v 1.7 2004-10-15 09:47:32 x2000habouzit Exp $
+ $Id: trombi.php,v 1.8 2004-10-28 20:28:41 x2000habouzit Exp $
***************************************************************************/
if(empty($_REQUEST['liste'])) header('Location: index.php');
$liste = $_REQUEST['liste'];
-$npage = isset($_REQUEST['npage']) ? $_REQUEST['npage'] : 1;
require("auto.prepend.inc.php");
new_skinned_page('listes/trombi.tpl', AUTH_COOKIE, true);
include('xml-rpc-client.inc.php');
+require("trombi.inc.php");
$res = $globals->db->query("SELECT password FROM auth_user_md5 WHERE user_id={$_SESSION['uid']}");
list($pass) = mysql_fetch_row($res);
mysql_free_result($res);
$client = new xmlrpc_client("http://{$_SESSION['uid']}:$pass@localhost:4949");
-$members = $client->get_members_limit('polytechnique.org',$liste,$npage,30);
-if(is_array($members)) {
+function getList($offset,$limit) {
+ global $client, $globals;
+ $liste = $_REQUEST['liste'];
+ list($total,$members) = $client->get_members_limit('polytechnique.org',$liste,$offset,$limit);
+
$membres = Array();
- foreach($members[1] as $member) {
+ foreach($members as $member) {
list($m) = split('@',$member[1]);
- $res = $globals->db->query("SELECT IF(epouse='', CONCAT(prenom, ' ', nom), CONCAT(prenom, ' ', epouse)), promo
+ $res = $globals->db->query("SELECT prenom,IF(epouse='', nom, epouse) AS nom, promo, a.alias AS forlife
FROM auth_user_md5 AS u
INNER JOIN aliases AS a ON u.user_id = a.id
WHERE a.alias = '$m'");
- if(list($nom, $promo) = mysql_fetch_row($res)) {
- $membres[$promo][] = Array('n' => $nom, 'l' => $m);
+ if($tmp = mysql_fetch_assoc($res)) {
+ $membres[$tmp['nom']] = $tmp;
} else {
- $membres[0][] = Array('l' => $member[0]);
+ $membres[$member[0]] = Array('addr' => $member[0]);
}
mysql_free_result($res);
}
- ksort($membres);
+ return Array($total,$membres);
+}
+
+$owners = $client->get_owners('polytechnique.org',$liste);
+if(is_array($owners)) {
$moderos = Array();
- foreach($members[2] as $owner) {
+ foreach($owners[1] as $owner) {
list($m) = split('@',$owner);
$res = $globals->db->query("SELECT IF(epouse='', CONCAT(prenom, ' ', nom), CONCAT(prenom, ' ', epouse)), promo
FROM auth_user_md5 AS u
@@ -69,19 +76,11 @@ if(is_array($members)) {
}
ksort($moderos);
- $page->assign_by_ref('details', $members[0]);
- $page->assign_by_ref('members', $membres);
+ $page->assign_by_ref('details', $owners[0]);
$page->assign_by_ref('owners', $moderos);
- $links = Array();
- if($npage>1)
- $links[] = Array('i'=>$npage - 1, 'text' => 'Précédent');
- for($i=1; $i<=$members[3]; $i++)
- $links[] = Array('i'=>$i, 'text' => $i);
- if($npage<$members[3])
- $links[] = Array('i'=>$npage + 1, 'text' => 'Suivant');
- $page->assign('links', $links);
- $page->assign('npage', $npage);
-
+
+ $trombi = new Trombi('getList');
+ $page->assign_by_ref('trombi',$trombi);
} else
$page->assign('no_list',true);
diff --git a/htdocs/mescontacts.php b/htdocs/mescontacts.php
index 8e0fa88..cba0fb8 100644
--- a/htdocs/mescontacts.php
+++ b/htdocs/mescontacts.php
@@ -18,13 +18,43 @@
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: mescontacts.php,v 1.18 2004-10-28 12:20:59 x2000habouzit Exp $
+ $Id: mescontacts.php,v 1.19 2004-10-28 20:28:41 x2000habouzit Exp $
***************************************************************************/
require("auto.prepend.inc.php");
new_skinned_page("mescontacts.tpl",AUTH_COOKIE,true);
require("applis.func.inc.php");
+
+if(isset($_GET['trombi'])) {
+ require_once('trombi.inc.php');
+ function getList($offset,$limit) {
+ global $globals;
+ $res = $globals->db->query("SELECT COUNT(*) FROM contacts WHERE uid = {$_SESSION['uid']}");
+ list($total) = mysql_fetch_row($res);
+ mysql_free_result($res);
+
+ $res = $globals->db->query("
+ SELECT u.prenom, IF(u.epouse='',u.nom,u.epouse) AS nom, a.alias AS forlife, u.promo
+ FROM contacts AS c
+ INNER JOIN auth_user_md5 AS u ON (u.user_id = c.contact)
+ INNER JOIN aliases AS a ON (u.user_id = a.id AND a.type='a_vie')
+ WHERE c.uid = {$_SESSION['uid']}
+ ORDER BY nom
+ LIMIT ".$offset*$limit.",$limit");
+ $list = Array();
+ while($tmp = mysql_fetch_assoc($res)) $list[] = $tmp;
+ mysql_free_result($res);
+
+ return Array($total, $list);
+ }
+
+ $trombi = new Trombi('getList');
+ $trombi->setNbRows(4);
+ $page->assign_by_ref('trombi',$trombi);
+ $page->run();
+}
+
// si l'utilisateur demande le retrait de qqun de sa liste
if (isset($_REQUEST['action'])) {
if($_REQUEST['action']=='retirer') {
diff --git a/htdocs/trombipromo.php b/htdocs/trombipromo.php
index 8839341..59bbce4 100644
--- a/htdocs/trombipromo.php
+++ b/htdocs/trombipromo.php
@@ -18,49 +18,53 @@
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: trombipromo.php,v 1.6 2004-10-08 19:38:37 x2000habouzit Exp $
+ $Id: trombipromo.php,v 1.7 2004-10-28 20:28:41 x2000habouzit Exp $
***************************************************************************/
require("auto.prepend.inc.php");
new_skinned_page('trombipromo.tpl', AUTH_COOKIE, true);
+require("trombi.inc.php");
-$limit = 30;
+function getList($offset,$limit) {
+ global $globals;
-$page->assign('limit', $limit);
+ $xpromo = intval($_REQUEST['xpromo']);
+ $where = ( $xpromo>0 ? "WHERE promo='$xpromo'" : "" );
-if(!isset($_REQUEST['xpromo'])) $page->run();
+ $res = $globals->db->query("SELECT COUNT(*)
+ FROM auth_user_md5 AS u
+ RIGHT JOIN photo AS p ON u.user_id=p.uid
+ $where");
+ list($pnb) = mysql_fetch_row($res);
+ mysql_free_result($res);
-$xpromo = intval($_REQUEST['xpromo']);
+ $sql = "SELECT promo,user_id,a.alias AS forlife,nom,prenom
+ FROM photo AS p
+ INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
+ INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
+ $where
+ ORDER BY promo,nom,prenom LIMIT ".($offset*$limit).",$limit";
-if ( $xpromo<1900 || $xpromo>date('Y') || ($xpromo == -1 && $_SESSION['perms']!="admin") ) {
- $page->assign('erreur', "Promotion incorrecte (saisir au format YYYY). Recommence.");
-}
-
-$offset = (empty($_REQUEST['offset']) ? 0 : $_REQUEST['offset']);
-
-$where = ( $xpromo>0 ? "WHERE promo='$xpromo'" : "" );
+ $res = $globals->db->query($sql);
+ $list = Array();
+ while($tmp = mysql_fetch_assoc($res)) $list[] = $tmp;
+ mysql_free_result($res);
-$res = $globals->db->query("SELECT COUNT(*)
- FROM auth_user_md5 AS u
- RIGHT JOIN photo AS p ON u.user_id=p.uid
- $where");
-list($pnb) = mysql_fetch_row($res);
-$page->assign('pnb', $pnb);
+ return Array($pnb, $list);
+}
-$sql = "SELECT promo,user_id,a.alias AS forlife,nom,prenom
- FROM photo AS p
- INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
- INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
- $where
- ORDER BY promo,nom,prenom LIMIT $offset,$limit";
+if(isset($_REQUEST['xpromo'])) {
+ $xpromo = intval($_REQUEST['xpromo']);
-$links = Array();
-if($offset>0) { $links[] = Array($offset-$limit, 'précédent'); }
-for($i = 0; $i < $pnb / $limit ; $i++) $links[] = Array($i*$limit, $i+1);
-if($offset+$limit < $pnb) { $links[] = Array ($offset+$limit, 'suivant'); }
-$page->assign('links',$links);
+ if ( $xpromo<1900 || $xpromo>date('Y') || ($xpromo == -1 && $_SESSION['perms']!="admin") ) {
+ $page->assign('erreur', "Promotion incorrecte (saisir au format YYYY). Recommence.");
+ } else {
+ $trombi = new Trombi('getList');
+ $trombi->setAdmin();
+ $page->assign_by_ref('trombi',$trombi);
+ }
+}
-$page->mysql_assign($sql,'photos');
$page->run();
?>
diff --git a/include/trombi.inc.php b/include/trombi.inc.php
new file mode 100644
index 0000000..98f4ace
--- /dev/null
+++ b/include/trombi.inc.php
@@ -0,0 +1,59 @@
+limit = $row*3; }
+ function setAdmin() { $this->admin = true; }
+
+ function show() {
+ global $page;
+
+ $offset = empty($_GET['offset']) ? 0 : intval($_GET['offset']);
+ list($total, $list) = call_user_func($this->_callback, $offset, $this->limit);
+ $page_max = intval(($total-1)/$this->limit);
+
+ $links = Array();
+ if($offset) {
+ $links[] = Array('u'=> $this->make_url($offset-1), 'i' => $offset-1, 'text' => 'précédent');
+ }
+ for($i = 0; $i <= $page_max ; $i++)
+ $links[] = Array('u'=>$this->make_url($i), 'i' => $i, 'text' => $i+1);
+
+ if($offset < $page_max) {
+ $links[] = Array ('u' => $this->make_url($offset+1), 'i' => $offset+1, 'text' => 'suivant');
+ }
+
+ $page->assign_by_ref('trombi_list', $list);
+ $page->assign_by_ref('trombi_links', $links);
+ $page->assign('trombi_admin', $this->admin);
+ return $page->fetch('include/trombi.tpl');
+ }
+}
+
+?>
diff --git a/include/xorg.plugin.inc.php b/include/xorg.plugin.inc.php
new file mode 100644
index 0000000..5185fd6
--- /dev/null
+++ b/include/xorg.plugin.inc.php
@@ -0,0 +1,62 @@
+_callback = $funcname;
+ }
+
+ function make_url($params) {
+ $get = Array();
+ $args = empty($params) ? Array() : $params;
+
+ if(!is_array($args)) {
+ if(count($this->_get_vars)!=1) {
+ return "params should be an array
";
+ } else {
+ $args = Array($this->_get_vars[0]=>$params);
+ }
+ }
+
+ foreach($_GET as $key=>$val) {
+ if(in_array($key,$this->_get_vars) && array_key_exists($key,$args)) continue;
+ $get[] = urlencode($key) . '=' . urlencode($val);
+ }
+
+ foreach($this->_get_vars as $key) {
+ if(array_key_exists($key,$args)) {
+ if($args[$key]) $get[] = urlencode($key) . '=' . urlencode($args[$key]);
+ } elseif(isset($_GET['key'])) {
+ $get[] = urlencode($key) . '=' . urlencode($_GET[$key]);
+
+ }
+ }
+
+ return $_SERVER['PHP_SELF'] . '?' . join('&',$get);
+ }
+}
+
+?>
diff --git a/scripts/mailman/mailman-rpc.py b/scripts/mailman/mailman-rpc.py
index ae6a06a..0cc625e 100755
--- a/scripts/mailman/mailman-rpc.py
+++ b/scripts/mailman/mailman-rpc.py
@@ -18,7 +18,7 @@
#* Foundation, Inc., *
#* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
#***************************************************************************
-# $Id: mailman-rpc.py,v 1.66 2004-10-27 09:54:29 x2000habouzit Exp $
+# $Id: mailman-rpc.py,v 1.67 2004-10-28 20:28:42 x2000habouzit Exp $
#***************************************************************************
import base64, MySQLdb, os, getopt, sys, MySQLdb.converters, sha, signal
@@ -295,11 +295,18 @@ def get_members((userdesc,perms),vhost,listname):
def get_members_limit((userdesc,perms),vhost,listname,page,nb_per_page):
try:
+ members = get_members((userdesc,perms),vhost,listname)[1]
+ except:
+ return 0
+ i = int(page) * int(nb_per_page)
+ return (len(members), members[i:i+int(nb_per_page)])
+
+def get_owners((userdesc,perms),vhost,listname):
+ try:
details,members,owners = get_members((userdesc,perms),vhost,listname)
except:
return 0
- i = (int(page)-1) * int(nb_per_page)
- return (details,members[i:i+int(nb_per_page)],owners,(len(members)-1)/int(nb_per_page)+1)
+ return (details,owners)
#-------------------------------------------------------------------------------
# owners procedures [ admin.php ]
@@ -793,6 +800,7 @@ server.register_function(unsubscribe)
server.register_function(get_members)
# trombi.php
server.register_function(get_members_limit)
+server.register_function(get_owners)
# admin.php
server.register_function(mass_subscribe)
server.register_function(mass_unsubscribe)
diff --git a/templates/include/trombi.tpl b/templates/include/trombi.tpl
new file mode 100644
index 0000000..74e9cfc
--- /dev/null
+++ b/templates/include/trombi.tpl
@@ -0,0 +1,65 @@
+{***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************
+ $Id: trombi.tpl,v 1.1 2004-10-28 20:28:43 x2000habouzit Exp $
+ ***************************************************************************}
+
+{dynamic}
+
+
+ {foreach from=$trombi_list item=p}
+ {cycle values="1,2,3" assign="loop"}
+ {if $loop eq "1"}
+
+ {/if}
+
+
+
+
+ {$p.prenom} {$p.nom} ({$p.promo})
+
+ {if $trombi_admin && $smarty.session.perms eq 'admin'}
+ [admin]
+ {/if}
+ |
+ {if $loop eq "3"}
+
+ {/if}
+ {/foreach}
+ {if $loop eq "1"}
+ | |
+ {elseif $loop eq "2"}
+ |
+ {/if}
+
+
+ {foreach from=$trombi_links item=l}
+ {if $l.i eq $smarty.request.offset}
+ {$l.text}
+ {else}
+ {$l.text}
+ {/if}
+ {/foreach}
+ |
+
+
+
+{/dynamic}
+
+{* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/templates/listes/trombi.tpl b/templates/listes/trombi.tpl
index 315349a..b23fdfa 100644
--- a/templates/listes/trombi.tpl
+++ b/templates/listes/trombi.tpl
@@ -17,7 +17,7 @@
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: trombi.tpl,v 1.9 2004-10-24 14:41:13 x2000habouzit Exp $
+ $Id: trombi.tpl,v 1.10 2004-10-28 20:28:43 x2000habouzit Exp $
***************************************************************************}
{dynamic}
@@ -107,36 +107,7 @@
membres de la liste
-
- {foreach from=$members item=xs key=promo}
- {foreach from=$xs item=x}
- {if $promo}
- {cycle values="1,2,3" assign="loop"}
- {if $loop eq "1"}{/if}
-
-
-
-
- {$x.n} ({$promo})
-
- |
- {if $loop eq "3"}
{/if}
- {/if}
- {/foreach}
- {/foreach}
- {if $loop eq "1"} | | {elseif $loop eq "2"} | {/if}
-
-
- {foreach from=$links item=l}
- {if $l.i eq $npage}
- {$l.text}
- {else}
- {$l.text}
- {/if}
- {/foreach}
- |
-
-
+{$trombi->show()|smarty:nodefaults}
{/if}
diff --git a/templates/mescontacts.tpl b/templates/mescontacts.tpl
index 2acb356..79be830 100644
--- a/templates/mescontacts.tpl
+++ b/templates/mescontacts.tpl
@@ -17,13 +17,26 @@
* Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
***************************************************************************
- $Id: mescontacts.tpl,v 1.10 2004-10-24 14:41:11 x2000habouzit Exp $
+ $Id: mescontacts.tpl,v 1.11 2004-10-28 20:28:42 x2000habouzit Exp $
***************************************************************************}
{dynamic}
{$erreur}
-{/dynamic}
+
+{if $trombi}
+
+
+ Mon trombino de contacts
+
+
+
+[vue classique]
+
+
+{$trombi->show()|smarty:nodefaults}
+
+{else}
Ma liste personnelle de contacts
@@ -40,9 +53,8 @@
Tu peux également rajouter des camarades dans tes contacts lors d'une recherche dans l'annuaire :
il te suffit de cliquer sur l'icône
en face de son nom dans les résultats !
-
+
-{dynamic}
{if $nb_contacts}
Pour récupérer ta liste de contacts dans un PDF imprimable :
@@ -50,6 +62,10 @@
[Triée par noms]
+
+Pour afficher le trombi de tes contacts : [vue sous forme de trombi]
+
+