From 8b00e0e0c6f303762f6740c853e7065b1471d245 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Sat, 22 Jul 2006 13:59:34 +0000 Subject: [PATCH] rename redirect function into http_redirect. 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 --- classes/Xnet.php | 2 +- htdocs/admin/newsletter.php | 2 +- htdocs/admin/newsletter_edit.php | 4 ++-- htdocs/admin/utilisateurs.php | 6 +++--- htdocs/wiki.php | 1 - include/platal.inc.php | 44 +++++++++++++++++++++++----------------- include/wiki.inc.php | 7 +++---- include/xnet/session.inc.php | 3 +-- modules/auth.php | 6 +++--- modules/carnet.php | 4 +--- modules/core.php | 2 +- modules/lists.php | 20 +++++++++--------- modules/platal.php | 8 ++++---- modules/profile.php | 3 +-- modules/register.php | 2 +- modules/xnet.php | 2 +- modules/xnetevents.php | 2 +- modules/xnetgrp.php | 6 +++--- modules/xnetlists.php | 14 ++++++------- plugins/insert.getUserName.php | 4 ++-- scripts/webredirect.php | 4 ++-- 21 files changed, 72 insertions(+), 74 deletions(-) diff --git a/classes/Xnet.php b/classes/Xnet.php index 36f679e..9435a9d 100644 --- a/classes/Xnet.php +++ b/classes/Xnet.php @@ -51,7 +51,7 @@ class Xnet extends Platal function force_login(&$page) { - redirect(S::v('loginX')); + http_redirect(S::v('loginX')); } } diff --git a/htdocs/admin/newsletter.php b/htdocs/admin/newsletter.php index 2820acb..a72e1d7 100644 --- a/htdocs/admin/newsletter.php +++ b/htdocs/admin/newsletter.php @@ -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()); diff --git a/htdocs/admin/newsletter_edit.php b/htdocs/admin/newsletter_edit.php index 9e5dd97..f740486 100644 --- a/htdocs/admin/newsletter_edit.php +++ b/htdocs/admin/newsletter_edit.php @@ -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')) { diff --git a/htdocs/admin/utilisateurs.php b/htdocs/admin/utilisateurs.php index 3f17653..2b81fd9 100644 --- a/htdocs/admin/utilisateurs.php +++ b/htdocs/admin/utilisateurs.php @@ -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("../"); } } diff --git a/htdocs/wiki.php b/htdocs/wiki.php index 490e261..1fbf9e3 100644 --- a/htdocs/wiki.php +++ b/htdocs/wiki.php @@ -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 diff --git a/include/platal.inc.php b/include/platal.inc.php index 6662e9d..93cf3cb 100644 --- a/include/platal.inc.php +++ b/include/platal.inc.php @@ -19,42 +19,48 @@ * 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: ?> diff --git a/include/wiki.inc.php b/include/wiki.inc.php index 04a43a1..2aa2dd2 100644 --- a/include/wiki.inc.php +++ b/include/wiki.inc.php @@ -20,11 +20,11 @@ ***************************************************************************/ 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() { diff --git a/include/xnet/session.inc.php b/include/xnet/session.inc.php index 8dedafd..8e00856 100644 --- a/include/xnet/session.inc.php +++ b/include/xnet/session.inc.php @@ -109,8 +109,7 @@ class XnetSession $args[] = urlencode($key).'='.urlencode($val); } - redirect($globals->baseurl . '/' . $path - . rtrim('?' . join('&', $args), '?')); + pl_redirect($path, join('&', $args)); } // }}} diff --git a/modules/auth.php b/modules/auth.php index 8f2f9b3..afdf1c8 100644 --- a/modules/auth.php +++ b/modules/auth.php @@ -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/'); } } diff --git a/modules/carnet.php b/modules/carnet.php index 9726946..c13d1a9 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -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'; diff --git a/modules/core.php b/modules/core.php index ed55458..787e236 100644 --- a/modules/core.php +++ b/modules/core.php @@ -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']); } } diff --git a/modules/lists.php b/modules/lists.php index 95c2ec8..19b6c07 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -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)) { diff --git a/modules/platal.php b/modules/platal.php index 9e13663..896374c 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -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'); } diff --git a/modules/profile.php b/modules/profile.php index 63b40b6..36f5205 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -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"; diff --git a/modules/register.php b/modules/register.php index 52f7892..93575fe 100644 --- a/modules/register.php +++ b/modules/register.php @@ -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); } diff --git a/modules/xnet.php b/modules/xnet.php index 22cdf7f..85835ea 100644 --- a/modules/xnet.php +++ b/modules/xnet.php @@ -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'); diff --git a/modules/xnetevents.php b/modules/xnetevents.php index f083f6b..6dfb3f5 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -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); } } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 650d903..d4a713f 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -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("« $email » n'est pas une adresse mail valide"); } diff --git a/modules/xnetlists.php b/modules/xnetlists.php index 47aca97..6d2f110 100644 --- a/modules/xnetlists.php +++ b/modules/xnetlists.php @@ -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); } } diff --git a/plugins/insert.getUserName.php b/plugins/insert.getUserName.php index 56e02b3..fc17ee8 100644 --- a/plugins/insert.getUserName.php +++ b/plugins/insert.getUserName.php @@ -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; - } + ?> diff --git a/scripts/webredirect.php b/scripts/webredirect.php index 68322d2..f834e07 100644 --- a/scripts/webredirect.php +++ b/scripts/webredirect.php @@ -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(); } -- 2.1.4