create new function to generate a simily PHP_SELF var.
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 22:12:55 +0000 (22:12 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 22:12:55 +0000 (22:12 +0000)
use it where it's better than the current soup

also make pseudo token be %grp which cannot happen in an url for Xnet

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@574 839d8a87-29fc-0310-9880-83ba4fa771e5

18 files changed:
classes/Platal.php
classes/Xnet.php
include/platal.inc.php
include/xorg.plugin.inc.php
modules/xnetevents.php
modules/xnetgrp.php
modules/xnetlists.php
templates/listes/admin.tpl
templates/listes/archives.tpl
templates/listes/check.tpl
templates/listes/delete.tpl
templates/listes/members.tpl
templates/listes/moderate.tpl
templates/listes/moderate_mail.tpl
templates/listes/moderate_sub.tpl
templates/listes/options.tpl
templates/listes/soptions.tpl
templates/listes/trombi.tpl

index a052193..43cf776 100644 (file)
@@ -46,6 +46,20 @@ class Platal
         }
     }
 
+    function pl_self($n = null)
+    {
+        if (is_null($n))
+            return $this->path;
+
+        if ($n >= 0)
+            return join('/', array_slice($this->argv, 0, $n + 1));
+
+        if ($n <= -count($this->argv))
+            return $this->argv[0];
+
+        return join('/', array_slice($this->argv, 0, $n));
+    }
+
     function find_hook()
     {
         $p = $this->path;
index 9435a9d..3d5dbb1 100644 (file)
@@ -32,10 +32,10 @@ class Xnet extends Platal
         if ($globals->asso()) {
             if ($p = strpos($this->path, '/')) {
                 $this->ns   = substr($this->path, 0, $p).'/';
-                $this->path = 'grp'.substr($this->path, $p);
+                $this->path = '%grp'.substr($this->path, $p);
             } else {
                 $this->ns   = $this->path.'/';
-                $this->path = 'grp';
+                $this->path = '%grp';
             }
         }
     }
@@ -44,7 +44,8 @@ class Xnet extends Platal
     {
         $ans = parent::find_hook();
         if ($ans && $this->ns) {
-            $this->path = $this->ns . substr($this->path, 4);
+            $this->path    = $this->ns . substr($this->path, 5);
+            $this->argv[0] = $this->ns . substr($this->argv[0], 5);
         }
         return $ans;
     }
index b4d0491..f3fbe94 100644 (file)
@@ -48,6 +48,11 @@ function pl_url($path, $query = null, $fragment = null)
     return $fragment ? $base.'#'.$fragment : $base;
 }
 
+function pl_self($n = null) {
+    global $platal;
+    return $platal->pl_self($n);
+}
+
 function http_redirect($fullurl)
 {
     if (count($_SESSION)) {
index 3723ee4..445e340 100644 (file)
@@ -101,8 +101,7 @@ class XOrgPlugin
            }
        }
 
-        global $platal;
-       return $platal->path . '?' . join('&amp;', $get);
+       return pl_self() . '?' . join('&amp;', $get);
     }
 
     // }}}
index 6dfb3f5..24f1182 100644 (file)
@@ -26,11 +26,11 @@ class XnetEventsModule extends PLModule
     function handlers()
     {
         return array(
-            'grp/events'       => $this->make_hook('events',  AUTH_MDP),
-            'grp/events/sub'   => $this->make_hook('sub',     AUTH_MDP),
-            'grp/events/csv'   => $this->make_hook('csv',     AUTH_MDP),
-            'grp/events/edit'  => $this->make_hook('edit',    AUTH_MDP),
-            'grp/events/admin' => $this->make_hook('admin',   AUTH_MDP),
+            '%grp/events'       => $this->make_hook('events',  AUTH_MDP),
+            '%grp/events/sub'   => $this->make_hook('sub',     AUTH_MDP),
+            '%grp/events/csv'   => $this->make_hook('csv',     AUTH_MDP),
+            '%grp/events/edit'  => $this->make_hook('edit',    AUTH_MDP),
+            '%grp/events/admin' => $this->make_hook('admin',   AUTH_MDP),
         );
     }
 
@@ -346,8 +346,7 @@ class XnetEventsModule extends PLModule
             }
 
             if (is_null($evt['eid'])) {
-                global $platal;
-                pl_redirect($platal->path.'/'.$eid);
+                pl_redirect(url_self().'/'.$eid);
             }
         }
 
index d4a713f..bb52952 100644 (file)
@@ -65,23 +65,23 @@ class XnetGrpModule extends PLModule
     function handlers()
     {
         return array(
-            'grp'            => $this->make_hook('index',     AUTH_PUBLIC),
-            'grp/asso.php'   => $this->make_hook('index',     AUTH_PUBLIC),
-            'grp/logo'       => $this->make_hook('logo',      AUTH_PUBLIC),
-            'grp/edit'       => $this->make_hook('edit',      AUTH_MDP),
-            'grp/mail'       => $this->make_hook('mail',      AUTH_MDP),
-            'grp/annuaire'   => $this->make_hook('annuaire',  AUTH_MDP),
-            'grp/subscribe'  => $this->make_hook('subscribe', AUTH_MDP),
-            'grp/paiement'   => $this->make_hook('paiement',  AUTH_MDP),
-
-            'grp/admin/annuaire'
+            '%grp'            => $this->make_hook('index',     AUTH_PUBLIC),
+            '%grp/asso.php'   => $this->make_hook('index',     AUTH_PUBLIC),
+            '%grp/logo'       => $this->make_hook('logo',      AUTH_PUBLIC),
+            '%grp/edit'       => $this->make_hook('edit',      AUTH_MDP),
+            '%grp/mail'       => $this->make_hook('mail',      AUTH_MDP),
+            '%grp/annuaire'   => $this->make_hook('annuaire',  AUTH_MDP),
+            '%grp/subscribe'  => $this->make_hook('subscribe', AUTH_MDP),
+            '%grp/paiement'   => $this->make_hook('paiement',  AUTH_MDP),
+
+            '%grp/admin/annuaire'
                  => $this->make_hook('admin_annuaire', AUTH_MDP),
 
-            'grp/member'
+            '%grp/member'
                  => $this->make_hook('admin_member', AUTH_MDP),
-            'grp/member/new'
+            '%grp/member/new'
                  => $this->make_hook('admin_member_new', AUTH_MDP),
-            'grp/member/del'
+            '%grp/member/del'
                  => $this->make_hook('admin_member_del', AUTH_MDP),
         );
     }
index 6d2f110..c32b934 100644 (file)
@@ -28,23 +28,23 @@ class XnetListsModule extends ListsModule
     function handlers()
     {
         return array(
-            'grp/lists'           => $this->make_hook('lists',     AUTH_MDP),
-            'grp/lists/create'    => $this->make_hook('create',    AUTH_MDP),
+            '%grp/lists'           => $this->make_hook('lists',     AUTH_MDP),
+            '%grp/lists/create'    => $this->make_hook('create',    AUTH_MDP),
 
-            'grp/lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
-            'grp/lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
+            '%grp/lists/members'   => $this->make_hook('members',   AUTH_COOKIE),
+            '%grp/lists/archives'  => $this->make_hook('archives',  AUTH_COOKIE),
 
-            'grp/lists/moderate'  => $this->make_hook('moderate',  AUTH_MDP),
-            'grp/lists/admin'     => $this->make_hook('admin',     AUTH_MDP),
-            'grp/lists/options'   => $this->make_hook('options',   AUTH_MDP),
-            'grp/lists/delete'    => $this->make_hook('delete',    AUTH_MDP),
+            '%grp/lists/moderate'  => $this->make_hook('moderate',  AUTH_MDP),
+            '%grp/lists/admin'     => $this->make_hook('admin',     AUTH_MDP),
+            '%grp/lists/options'   => $this->make_hook('options',   AUTH_MDP),
+            '%grp/lists/delete'    => $this->make_hook('delete',    AUTH_MDP),
 
-            'grp/lists/soptions'  => $this->make_hook('soptions',  AUTH_MDP),
-            'grp/lists/check'     => $this->make_hook('check',     AUTH_MDP),
-            'grp/lists/sync'      => $this->make_hook('sync',      AUTH_MDP),
+            '%grp/lists/soptions'  => $this->make_hook('soptions',  AUTH_MDP),
+            '%grp/lists/check'     => $this->make_hook('check',     AUTH_MDP),
+            '%grp/lists/sync'      => $this->make_hook('sync',      AUTH_MDP),
 
-            'grp/alias/admin'     => $this->make_hook('aadmin',    AUTH_MDP),
-            'grp/alias/create'    => $this->make_hook('acreate',   AUTH_MDP),
+            '%grp/alias/admin'     => $this->make_hook('aadmin',    AUTH_MDP),
+            '%grp/alias/create'    => $this->make_hook('acreate',   AUTH_MDP),
 
             /* hack: lists uses that */
             'profile' => $this->make_hook('profile', AUTH_PUBLIC),
index 1455cda..ec10594 100644 (file)
@@ -52,7 +52,7 @@ qui y 
         {else}
         {$x.l}
         {/if}
-        <a href='{$platal->ns}lists/admin/{$platal->argv[1]}?del_owner={$x.l}'><img src='images/retirer.gif' alt='retirer modérateur' title='retirer modérateur' /></a>
+        <a href='{$platal->pl_self(1)}?del_owner={$x.l}'><img src='images/retirer.gif' alt='retirer modérateur' title='retirer modérateur' /></a>
         <br />
         {/foreach}
       </td>
@@ -86,7 +86,7 @@ qui y 
         {else}
         {$x.l}
         {/if}
-        <a href='{$platal->ns}lists/admin/{$platal->argv[1]}?del_member={$x.l}'><img src='images/retirer.gif' alt='retirer membre' title='retirer membre' /></a>
+        <a href='{$platal->pl_self(1)}?del_member={$x.l}'><img src='images/retirer.gif' alt='retirer membre' title='retirer membre' /></a>
         <br />
         {/foreach}
       </td>
index bfac627..daaa12a 100644 (file)
@@ -42,7 +42,7 @@
     {foreach from=$range item=i}
     <td>
       {if $m[$i]}
-      <a href="{$platal->ns}lists/archives/{$platal->argv[1]}?rep={$y}/{$i|string_format:"%02u"}&amp;file=threads.html">{"0000-$i-01"|date_format:"%B"}</a>
+      <a href="{$platal->pl_self(1)}?rep={$y}/{$i|string_format:"%02u"}&amp;file=threads.html">{"0000-$i-01"|date_format:"%B"}</a>
       {else}
       &nbsp;
       {/if}
@@ -68,7 +68,7 @@
     {foreach from=$range item=i}
     <td>
       {if $m[$i]}
-      <a href="{$platal->ns}lists/archives/{$platal->argv[1]}?rep={$y}/{$i|string_format:"%02u"}&amp;file=dates.html">{"0000-$i-01"|date_format:"%B"}</a>
+      <a href="{$platal->pl_self(1)}?rep={$y}/{$i|string_format:"%02u"}&amp;file=dates.html">{"0000-$i-01"|date_format:"%B"}</a>
       {else}
       &nbsp;
       {/if}
index 9a1a0bb..8e01569 100644 (file)
@@ -35,7 +35,7 @@
   </tr>
   {/foreach}
 </table>
-<form action='{$platal->ns}lists/check/{$platal->argv[1]}' method='post'>
+<form action='{$platal->pl_self(1)}' method='post'>
   <div class='center'>
     <br />
     <input type='submit' name='correct' value='Corriger les valeurs !' />
index 1e4ffc0..17fc13c 100644 (file)
@@ -40,7 +40,7 @@ Tu n'es pas administrateur de la liste, mais du site.
   Détruire la liste {$details.addr} ?
 </h1>
 
-<form method='post' action='{$platal->ns}lists/delete/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='tinybicol' cellpadding='2' cellspacing='0'>
     <tr class='impair'>
       <td>
index 5975f66..c88b2ae 100644 (file)
       {if $details.sub>1}
       Tu es inscrit sur la liste.<br />
       Te désinscrire :
-      <a href='{$platal->ns}lists/members/{$platal->argv[1]}?del=1'><img src="images/retirer.gif" alt="[me désinsiscrire]" /></a>
+      <a href='{$platal->pl_self(1)}?del=1'><img src="images/retirer.gif" alt="[me désinsiscrire]" /></a>
       {elseif $details.sub eq 1}
       Ta demande d'inscription est en cours de validation.
       {else}
       Tu n'es pas inscrit.<br />
       Demander ton inscription :
-      <a href="{$platal->ns}lists/members/{$platal->argv[1]}?add=1"><img src="images/ajouter.gif" alt="[demander mon inscription]" /></a>
+      <a href="{$platal->pl_self(1)}?add=1"><img src="images/ajouter.gif" alt="[demander mon inscription]" /></a>
       {/if}
     </td>
   </tr>
 <h1>
   membres de la liste
   {if $smarty.get.alpha}
-  (<a href='{$platal->ns}lists/members/{$platal->argv[1]}'>trier par promo</a>)
+  (<a href='{$platal->pl_self(1)}'>trier par promo</a>)
   {else}
-  (<a href='{$platal->ns}lists/members/{$platal->argv[1]}?alpha=1'>trier par nom</a>)
+  (<a href='{$platal->pl_self(1)}?alpha=1'>trier par nom</a>)
   {/if}
 </h1>
 
index 2e3626d..bef65e1 100644 (file)
@@ -42,8 +42,8 @@
     </td>
     <td>{$s.addr}</td>
     <td class='action'>
-      <a href='{$platal->ns}lists/moderate/{$platal->argv[1]}?sadd={$s.id}'>ajouter</a>
-      <a href='{$platal->ns}lists/moderate/{$platal->argv[1]}?sid={$s.id}'>refuser</a>
+      <a href='{$platal->pl_self(1)}?sadd={$s.id}'>ajouter</a>
+      <a href='{$platal->pl_self(1)}?sid={$s.id}'>refuser</a>
     </td>
   </tr>
   {/foreach}
@@ -89,8 +89,8 @@
     <td class='right'>{$m.size}o</td>
     <td class='right'>{$m.stamp|date_format:"%X<br />%x"}</td>
     <td class='action'>
-      <a href='{$platal->ns}lists/moderate/{$platal->argv[1]}?mid={$m.id}'>voir</a><br/>
-      <a href='{$platal->ns}lists/moderate/{$platal->argv[1]}?mid={$m.id}&amp;mok=1'>accepter</a>&nbsp;<a href='{$platal->ns}lists/moderate/{$platal->argv[1]}?mid={$m.id}&amp;mdel=1'>détruire</a></td>
+      <a href='{$platal->pl_self(1)}?mid={$m.id}'>voir</a><br/>
+      <a href='{$platal->pl_self(1)}?mid={$m.id}&amp;mok=1'>accepter</a>&nbsp;<a href='{$platal->pl_self(1)}?mid={$m.id}&amp;mdel=1'>détruire</a></td>
   </tr>
   {/foreach}
 </table>
index ba34562..c72e312 100644 (file)
@@ -60,7 +60,7 @@
 <br />
 {/if}
 
-<form method='post' action='{$platal->ns}lists/moderate/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='tinybicol' cellpadding='0' cellspacing='0'>
     <tr>
       <th class='titre'>Modérer le mail</th>
index 36c4a39..1c0fa8e 100644 (file)
@@ -22,7 +22,7 @@
 
 <h1>Refuser l'inscription d'un utilisateur</h1>
 
-<form method='post' action='{$platal->ns}lists/moderate/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='tinybicol' cellpadding='0' cellspacing='0'>
     <tr>
       <th class='titre'>refuser l'inscription de :</th>
index 8d281e5..7c4a4a5 100644 (file)
@@ -33,7 +33,7 @@ Tu n'es pas administrateur de la liste, mais du site.
   Changer les options de la liste {$details.addr}
 </h1>
 
-<form method='post' action='{$platal->ns}lists/options/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='bicol' cellpadding='2' cellspacing='0'>
     <tr><th colspan='2'>Options de la liste {$details.addr}</th></tr>
     <tr class='impair'>
@@ -159,14 +159,14 @@ les X inscrits 
 redirection en mode 'inactif'. le logiciel de mailing list saura se débrouiller tout seul.
 </p>
 
-<form method='post' action='{$platal->ns}lists/options/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='tinybicol' cellpadding='2' cellspacing='0'>
     <tr><th>Addresses non modérées</th></tr>
     <tr>
       <td>
         {if $options.accept_these_nonmembers|@count}
         {foreach from=$options.accept_these_nonmembers item=addr}
-        {$addr}<a href='{$platal->ns}lists/options/{$platal->argv[1]}&amp;atn_del={$addr}'>
+        {$addr}<a href='{$platal->pl_self(1)}&amp;atn_del={$addr}'>
           <img src="images/retirer.gif" alt='retirer de la whitelist' title="retirer {$addr} de la whitelist" />
         </a><br />
         {/foreach}
index 00fcdf8..d358d69 100644 (file)
@@ -27,7 +27,7 @@
   Changer les options de la liste {$details.addr}
 </h1>
 
-<form method='post' action='{$platal->ns}lists/soptions/{$platal->argv[1]}'>
+<form method='post' action='{$platal->pl_self(1)}'>
   <table class='bicol' cellpadding='2' cellspacing='0'>
     <tr><th colspan='2'>Options de la liste {$details.addr}</th></tr>
     <tr class='impair'>
index dba1460..08adcab 100644 (file)
       {if $details.sub>1}
       Tu es inscrit sur la liste.<br />
       Te désinscrire :
-      <a href='{$platal->ns}trombi/{$platal->argv[1]}?del=1'><img src="images/retirer.gif" alt="[me désinsiscrire]" /></a>
+      <a href='{$platal->pl_self(1)}?del=1'><img src="images/retirer.gif" alt="[me désinsiscrire]" /></a>
       {elseif $details.sub eq 1}
       Ta demande d'inscription est en cours de validation.
       {else}
       Tu n'es pas inscrit.<br />
       Demander ton inscription :
-      <a href="{$platal->ns}trombi/{$platal->argv[1]}?add=1"><img src="images/ajouter.gif" alt="[demander mon inscription]" /></a>
+      <a href="{$platal->pl_self(1)}?add=1"><img src="images/ajouter.gif" alt="[demander mon inscription]" /></a>
       {/if}
     </td>
   </tr>