rename redirect function into http_redirect.
authorx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 13:59:34 +0000 (13:59 +0000)
committerx2000habouzit <x2000habouzit@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 22 Jul 2006 13:59:34 +0000 (13:59 +0000)
create pl_url that create a platal url from a path and things like that.

create pl_redirect that redirects to the right pl_url, handle platal->ns
magically

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

21 files changed:
classes/Xnet.php
htdocs/admin/newsletter.php
htdocs/admin/newsletter_edit.php
htdocs/admin/utilisateurs.php
htdocs/wiki.php
include/platal.inc.php
include/wiki.inc.php
include/xnet/session.inc.php
modules/auth.php
modules/carnet.php
modules/core.php
modules/lists.php
modules/platal.php
modules/profile.php
modules/register.php
modules/xnet.php
modules/xnetevents.php
modules/xnetgrp.php
modules/xnetlists.php
plugins/insert.getUserName.php
scripts/webredirect.php

index 36f679e..9435a9d 100644 (file)
@@ -51,7 +51,7 @@ class Xnet extends Platal
 
     function force_login(&$page)
     {
-        redirect(S::v('loginX'));
+        http_redirect(S::v('loginX'));
     }
 }
 
index 2820acb..a72e1d7 100644 (file)
@@ -26,7 +26,7 @@ require_once("newsletter.inc.php");
 
 if(Get::has('new')) {
    insert_new_nl();
-   redirect("newsletter.php");
+   http_redirect("newsletter.php");
 }
 
 $page->assign_by_ref('nl_list', get_nl_slist());
index 9e5dd97..f740486 100644 (file)
@@ -29,7 +29,7 @@ $nl  = new NewsLetter($nid);
 
 if(Get::has('del_aid')) {
     $nl->delArticle(Get::get('del_aid'));
-    redirect("{$_SERVER['PHP_SELF']}?nid=$nid");
+    http_redirect("{$_SERVER['PHP_SELF']}?nid=$nid");
 }
 
 if(Post::get('update')) {
@@ -43,7 +43,7 @@ if(Post::get('save')) {
     $art  = new NLArticle(Post::get('title'), Post::get('body'), Post::get('append'),
             Get::get('edit_aid'), Post::get('cid'), Post::get('pos'));
     $nl->saveArticle($art);
-    redirect("{$_SERVER['PHP_SELF']}?nid=$nid");
+    http_redirect("{$_SERVER['PHP_SELF']}?nid=$nid");
 }
 
 if(Get::has('edit_aid')) {
index 3f17653..2b81fd9 100644 (file)
@@ -38,11 +38,11 @@ if (Env::has('user_id')) {
 }
 
 if(Env::has('logs_button') && $login) {
-    redirect("logger.php?loguser=$login&year=".date('Y')."&month=".date('m'));
+    http_redirect("logger.php?loguser=$login&year=".date('Y')."&month=".date('m'));
 }
 
 if (Env::has('ax_button') && $login) {
-    redirect("synchro_ax.php?user=$login");
+    http_redirect("synchro_ax.php?user=$login");
 }
 
 if(Env::has('suid_button') && $login) {
@@ -51,7 +51,7 @@ if(Env::has('suid_button') && $login) {
     $r = XDB::query("SELECT id FROM aliases WHERE alias={?}", $login);
     if($uid = $r->fetchOneCell()) {
        start_connexion($uid,true);
-       redirect("../");
+       http_redirect("../");
     }
 }
 
index 490e261..1fbf9e3 100644 (file)
@@ -35,7 +35,6 @@ if ($n = wiki_pagename()) {
     if (Env::get('action') || !$tmpfile_exists) {
         if ($tmpfile_exists) {
             @unlink($wiki_template);
-            $page->clear_compiled_tpl($wiki_template);
         }
 
         // we leave pmwiki do whatever it wants and store everything
index 6662e9d..93cf3cb 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-function microtime_float() 
-{ 
-    list($usec, $sec) = explode(" ", microtime()); 
-    return ((float)$usec + (float)$sec); 
-} 
+function microtime_float()
+{
+    list($usec, $sec) = explode(' ', microtime());
+    return ((float)$usec + (float)$sec);
+}
 $TIME_BEGIN = microtime_float();
 
-// {{{ defines
+define('AUTH_PUBLIC', 0);
+define('AUTH_COOKIE', 1);
+define('AUTH_MDP',    2);
 
-$i=0;
-define("AUTH_PUBLIC", $i++);
-define("AUTH_COOKIE", $i++);
-define("AUTH_MDP", $i++);
-
-define("PERMS_EXT", "ext");
-define("PERMS_USER", "user");
-define("PERMS_ADMIN", "admin");
+define('PERMS_EXT',   'ext');
+define('PERMS_USER',  'user');
+define('PERMS_ADMIN', 'admin');
 
 define('SKINNED', 0);
 define('NO_SKIN', 1);
 
 require_once('platal/env.inc.php');
 
-// }}}
-// {{{ function redirect
+function pl_url($path, $query = null, $fragment = null)
+{
+    global $platal;
+
+    $base = $platal->ns . $path . ($query ? '?'.$query : '');
+    return $fragment ? $base.'#'.$fragment : $base;
+}
 
-function redirect($page)
+function http_redirect($fullurl)
 {
     if (count($_SESSION)) {
         session_write_close();
     }
-    header("Location: $page");
+    header('Location: '.$fullurl);
     exit;
 }
 
-// }}}
+function pl_redirect($path, $query = null, $fragment = null)
+{
+    global $globals;
+    http_redirect($globals->baseurl . '/' . pl_url($path, $query, $fragment));
+}
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker:
 ?>
index 04a43a1..2aa2dd2 100644 (file)
  ***************************************************************************/
 
 function wiki_pagename() {
-    if (!Env::get('n')) {
+    if (!Get::get('n')) {
         return null;
     }
 
-    $words = explode('/', trim(Env::get('n'), '/'));
+    $words = explode('/', trim(Get::get('n'), '/'));
     if (count($words) == 2) {
         return join('.', $words);
     }
@@ -33,8 +33,7 @@ function wiki_pagename() {
     $b = array_pop($words);
     $a = array_pop($words);
 
-    global $globals;
-    redirect($globals->baseurl.'/'.$a.'/'.$b);
+    pl_redirect($a.'/'.$b);
 }
 
 function wiki_work_dir() {
index 8dedafd..8e00856 100644 (file)
@@ -109,8 +109,7 @@ class XnetSession
             $args[] = urlencode($key).'='.urlencode($val);
         }
 
-        redirect($globals->baseurl . '/' . $path
-                 . rtrim('?' . join('&', $args), '?'));
+        pl_redirect($path, join('&', $args));
     }
 
     // }}}
index 8f2f9b3..afdf1c8 100644 (file)
@@ -120,7 +120,7 @@ class AuthModule extends PLModule
 
     function handler_redirect(&$page)
     {
-        redirect(Env::get('dest', '/'));
+        http_redirect(Env::get('dest', '/'));
     }
 
     function handler_groupex(&$page)
@@ -154,12 +154,12 @@ class AuthModule extends PLModule
         while (list($privkey,$name,$datafields) = $res->next()) {
             if (md5($gpex_challenge.$privkey) == $gpex_pass) {
                 $returl = $gpex_url.gpex_make_params($gpex_challenge,$privkey,$datafields);
-                redirect($returl);
+                http_redirect($returl);
             }
         }
 
         /* si on n'a pas trouvé, on renvoit sur x.org */
-        redirect('https://www.polytechnique.org/');
+        http_redirect('https://www.polytechnique.org/');
     }
 }
 
index 9726946..c13d1a9 100644 (file)
@@ -60,10 +60,8 @@ class CarnetModule extends PLModule
         $page->changeTpl('carnet/panel.tpl');
 
         if (Get::has('read')) {
-            global $globals;
-
             $_SESSION['watch_last'] = Get::get('read');
-            redirect($globals->baseurl.'/carnet/panel');
+            pl_redirect('carnet/panel');
         }
 
         require_once 'notifs.inc.php';
index ed55458..787e236 100644 (file)
@@ -57,7 +57,7 @@ class CoreModule extends PLModule
         $page->clear_compiled_tpl();
         wiki_clear_all_cache();
 
-        redirect(empty($_SERVER['HTTP_REFERER']) ? './' : $_SERVER['HTTP_REFERER']);
+        http_redirect(empty($_SERVER['HTTP_REFERER']) ? './' : $_SERVER['HTTP_REFERER']);
     }
 }
 
index 95c2ec8..19b6c07 100644 (file)
@@ -60,11 +60,11 @@ class ListsModule extends PLModule
 
         if (Get::has('del')) {
             $this->client->unsubscribe(Get::get('del'));
-            redirect('lists');
+            pl_redirect('lists');
         }
         if (Get::has('add')) {
             $this->client->subscribe(Get::get('add'));
-            redirect('lists');
+            pl_redirect('lists');
         }
         if (Post::has('promo_add')) {
             $promo = Post::getInt('promo_add');
@@ -172,12 +172,12 @@ class ListsModule extends PLModule
 
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
-            redirect($liste);
+            pl_redirect('lists/members/'.$liste);
         }
 
         if (Get::has('add')) {
             $this->client->subscribe($liste);
-            redirect($liste);
+            pl_redirect('lists/members/'.$liste);
         }
 
         $members = $this->client->get_members($liste);
@@ -231,11 +231,11 @@ class ListsModule extends PLModule
 
         if (Get::has('del')) {
             $this->client->unsubscribe($liste);
-            redirect($liste);
+            pl_redirect('lists/tromi/'.$liste);
         }
         if (Get::has('add')) {
             $this->client->subscribe($liste);
-            redirect($liste);
+            pl_redirect('lists/tromi/'.$liste);
         }
 
         $owners = $this->client->get_owners($liste);
@@ -312,7 +312,7 @@ class ListsModule extends PLModule
 
         if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
             $this->client->handle_request($liste,Env::get('sadd'),4,'');
-            redirect($liste);
+            pl_redirect('lists/moderate/'.$liste);
         }
 
         if (Post::has('sdel')) { /* 2 = REJECT */
@@ -434,7 +434,7 @@ class ListsModule extends PLModule
             } else {
                 $this->client->mass_unsubscribe($liste, array(Env::get('del_member')));
             }
-            redirect($liste);
+            pl_redirect('lists/admin/'.$liste);
         }
 
         if (Env::has('add_owner')) {
@@ -459,7 +459,7 @@ class ListsModule extends PLModule
             } else {
                 $this->client->del_owner($liste, Env::get('del_owner'));
             }
-            redirect($liste);
+            pl_redirect('lists/admin/'.$liste);
         }
 
         if (list($det,$mem,$own) = $this->client->get_members($liste)) {
@@ -516,7 +516,7 @@ class ListsModule extends PLModule
             $this->client->add_to_wl($liste, Post::get('atn_add'));
         } elseif (Get::has('atn_del')) {
             $this->client->del_from_wl($liste, Get::get('atn_del'));
-            redirect("{$_SERVER['PHP_SELF']}?liste=$liste");
+            pl_redirect('lists/options/'.$liste);
         }
 
         if (list($details,$options) = $this->client->get_owner_options($liste)) {
index 9e13663..896374c 100644 (file)
@@ -64,7 +64,7 @@ class PlatalModule extends PLModule
     function handler_index(&$page)
     {
         if (S::logged()) {
-            redirect("events");
+            pl_redirect('events');
         }
     }
 
@@ -345,9 +345,9 @@ Mail envoy
                 $log->log("suid_stop", S::v('forlife') . " by " . $suid['forlife']);
                 $_SESSION = $suid;
                 S::kill('suid');
-                redirect($globals->baseurl.'/admin/utilisateurs.php?login='.$a4l);
+                pl_redirect('admin/utilisateurs.php', 'login='.$a4l);
             } else {
-                redirect("events");
+                pl_redirect('events');
             }
         }
 
@@ -373,7 +373,7 @@ Mail envoy
         XorgSession::destroy();
 
         if (Get::has('redirect')) {
-            redirect(rawurldecode(Get::get('redirect')));
+            http_redirect(rawurldecode(Get::get('redirect')));
         } else {
             $page->changeTpl('exit.tpl');
         }
index 63b40b6..36f5205 100644 (file)
@@ -332,8 +332,7 @@ class ProfileModule extends PLModule
         }
 
         if (Env::has('suivant')) {
-            redirect($globals->baseurl . '/profile/edit/' .
-                     get_next_tab($opened_tab));
+            pl_redirect('profile/edit/' . get_next_tab($opened_tab));
         }
 
         require_once "profil/get_{$opened_tab}.inc.php";
index 52f7892..93575fe 100644 (file)
@@ -269,7 +269,7 @@ class RegisterModule extends PLModule
 
         XDB::execute("DELETE FROM register_marketing WHERE uid = {?}", $uid);
 
-        redirect($globals->baseurl.'/register/success');
+        pl_redirect('register/success');
         $page->assign('uid', $uid);
     }
 
index 22cdf7f..85835ea 100644 (file)
@@ -133,7 +133,7 @@ class XnetModule extends PLModule
         if (Post::has('diminutif')) {
             XDB::query('INSERT INTO groupex.asso (id,diminutif)
                                  VALUES(NULL,{?})', Post::get('diminutif'));
-            redirect(Post::get('diminutif').'/edit');
+            pl_redirect('../'.Post::get('diminutif').'/edit');
         }
 
         $res = XDB::query('SELECT nom,diminutif FROM groupex.asso ORDER by NOM');
index f083f6b..6dfb3f5 100644 (file)
@@ -347,7 +347,7 @@ class XnetEventsModule extends PLModule
 
             if (is_null($evt['eid'])) {
                 global $platal;
-                redirect($globals->baseurl.'/'.$platal->path.'/'.$eid);
+                pl_redirect($platal->path.'/'.$eid);
             }
         }
 
index 650d903..d4a713f 100644 (file)
@@ -183,7 +183,7 @@ class XnetGrpModule extends PLModule
                                         $globals->asso('id'));
             }
 
-            redirect('../'.Post::get('diminutif', $globals->asso('diminutif')).'/edit');
+            pl_redirect('../'.Post::get('diminutif', $globals->asso('diminutif')).'/edit');
         }
 
         if (S::has_perms()) {
@@ -592,7 +592,7 @@ class XnetGrpModule extends PLModule
                       INNER JOIN  aliases       AS a ON (u.user_id = a.id)
                            WHERE  a.alias={?}', $globals->asso('id'), $forlife);
                 global $platal;
-                redirect("{$globals->baseurl}/{$platal->ns}member/$email");
+                pl_redirect("member/$email");
             } else {
                 $page->trig($email." n'est pas un alias polytechnique.org valide");
             }
@@ -604,7 +604,7 @@ class XnetGrpModule extends PLModule
                                         VALUES({?},{?},"ext",{?})', $uid,
                                         $globals->asso('id'), $email);
                 global $platal;
-                redirect("{$globals->baseurl}/{$platal->ns}member/$email");
+                pl_redirect("member/$email");
             } else {
                 $page->trig("« <strong>$email</strong> » n'est pas une adresse mail valide");
             }
index 47aca97..6d2f110 100644 (file)
@@ -75,11 +75,11 @@ class XnetListsModule extends ListsModule
 
         if (Get::has('del')) {
             $this->client->unsubscribe(Get::get('del'));
-            redirect('lists');
+            pl_redirect('lists');
         }
         if (Get::has('add')) {
             $this->client->subscribe(Get::get('add'));
-            redirect('lists');
+            pl_redirect('lists');
         }
 
         if (Post::has('del_alias') && may_update()) {
@@ -178,8 +178,7 @@ class XnetListsModule extends ListsModule
                                 VALUES ({?}, {?})', mysql_insert_id(),
                                 "$red+bounces@listes.polytechnique.org");
 
-        global $platal;
-        redirect($globals->baseurl.'/'.$platal->ns.'lists/admin/'.$liste);
+        pl_redirect('lists/admin/'.$liste);
     }
 
     function handler_sync(&$page, $liste = null)
@@ -274,7 +273,7 @@ class XnetListsModule extends ListsModule
                            USING  x4dat.virtual_redirect
                       INNER JOIN  x4dat.virtual USING(vid)
                            WHERE  redirect={?} AND alias={?}", Env::get('del_member'), $lfull);
-            redirect("?liste=$lfull");
+            pl_redirect('alias/admin/'.$lfull);
         }
 
         $res = XDB::iterator(
@@ -317,13 +316,12 @@ class XnetListsModule extends ListsModule
 
         XDB::query('INSERT INTO x4dat.virtual (alias,type) VALUES({?}, "user")', $new);
 
-        global $platal;
-        redirect("{$globals->baseurl}/{$platal->ns}alias/admin/$new");
+        pl_redirect("alias/admin/$new");
     }
 
     function handler_profile(&$page, $user = null)
     {
-        redirect('https://www.polytechnique.org/profile/'.$user);
+        http_redirect('https://www.polytechnique.org/profile/'.$user);
     }
 }
 
index 56e02b3..fc17ee8 100644 (file)
@@ -25,7 +25,7 @@ function smarty_insert_getUsername()
 
     $id = Cookie::getInt('ORGuid', -1);
     $id = S::v($_SESSION['uid'], $id);
-    
+
     if ($id<0) {
         return "";
     }
@@ -48,6 +48,6 @@ function smarty_insert_getUsername()
      }
 
      return $login;
-     
 }
+
 ?>
index 68322d2..f834e07 100644 (file)
@@ -35,9 +35,9 @@ $res = XDB::query(
 if ($url = $res->fetchOneCell()) {
     $url = preg_replace('@/+$@', '', $url);
     if($path) {
-        redirect("http://$url/$path");
+        http_redirect("http://$url/$path");
     } else {
-        redirect("http://$url");
+        http_redirect("http://$url");
     }
     exit();
 }