From: Florent Bruneau Date: Sun, 28 Dec 2008 20:08:47 +0000 (+0100) Subject: Carva. X-Git-Tag: xorg/1.0.0~332^2~454 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=c1e98576e7de93ff40910bf7061bfcdfb1316ccb;p=platal.git Carva. Signed-off-by: Florent Bruneau --- diff --git a/htdocs/webredirect.php b/htdocs/webredirect.php index dc7e761..311ae97 100644 --- a/htdocs/webredirect.php +++ b/htdocs/webredirect.php @@ -21,28 +21,27 @@ require_once 'xorg.inc.php'; -new Xorg('core'); +$platal = new Xorg('core'); global $globals; -list($username, $path) = preg_split('/\//', $_SERVER["REQUEST_URI"], 2, PREG_SPLIT_NO_EMPTY); -$res = XDB::query( - "SELECT redirecturl - FROM auth_user_quick AS a - INNER JOIN aliases AS al ON (al.id = a.user_id AND (al.type='a_vie' OR al.type='alias')) - WHERE al.alias = {?} - GROUP BY redirecturl", $username); +$path = ltrim($platal->pl_self(), '/'); +@list($username, $path) = explode('/', $path, 2); -if ($url = $res->fetchOneCell()) { - $url = preg_replace('@/+$@', '', $url); - if ($path) { - http_redirect("http://$url/$path"); - } else { - http_redirect("http://$url"); +if ($username && !is_null($user = User::getSilent($username))) { + $url = XDB::fetchOneCell('SELECT url + FROM carvas + WHERE uid = {?}', $user->id()); + if ($url) { + $url = preg_replace('@/+$@', '', $url); + if ($path) { + http_redirect("http://$url/$path"); + } else { + http_redirect("http://$url"); + } } } -header("HTTP/1.0 404 Not Found"); - +header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); ?> diff --git a/modules/platal.php b/modules/platal.php index 23031f5..8146055 100644 --- a/modules/platal.php +++ b/modules/platal.php @@ -162,33 +162,31 @@ class PlatalModule extends PLModule function handler_webredir(&$page) { $page->changeTpl('platal/webredirect.tpl'); - $page->setTitle('Redirection de page WEB'); - $log =& S::v('log'); - $url = Env::v('url'); - - if (Env::v('submit') == 'Valider' and Env::has('url')) { - XDB::execute('UPDATE auth_user_quick - SET redirecturl = {?} WHERE user_id = {?}', - $url, S::i('uid')); - S::logger()->log('carva_add', 'http://'.Env::v('url')); - $page->trigSuccess("Redirection activée vers $url"); - } elseif (Env::v('submit') == "Supprimer") { - XDB::execute("UPDATE auth_user_quick - SET redirecturl = '' - WHERE user_id = {?}", - S::i('uid')); - S::logger()->log("carva_del", $url); + if (Env::v('submit') == 'Valider' && !Env::blank('url')) { + if (Env::blank('url')) { + $page->trigError('URL invalide'); + } else { + $url = Env::t('url'); + XDB::execute('REPLACE INTO carvas (uid, url) + VALUES ({?}, {?})', + S::i('uid'), $url); + S::logger()->log('carva_add', 'http://' . $url); + $page->trigSuccess("Redirection activée vers $url"); + } + } elseif (Env::v('submit') == 'Supprimer') { + XDB::execute('DELETE FROM carvas + WHERE uid = {?}', S::i('uid')); Post::kill('url'); + S::logger()->log('carva_del'); $page->trigSuccess('Redirection supprimée'); } - $res = XDB::query('SELECT redirecturl - FROM auth_user_quick - WHERE user_id = {?}', - S::i('uid')); - $page->assign('carva', $res->fetchOneCell()); + $url = XDB::fetchOneCell('SELECT url + FROM carvas + WHERE uid = {?}', S::i('uid')); + $page->assign('carva', $url); # FIXME: this code is not multi-domain compatible. We should decide how # carva will extend to users not in the main domain. diff --git a/templates/platal/webredirect.tpl b/templates/platal/webredirect.tpl index fa9b58a..9a207bf 100644 --- a/templates/platal/webredirect.tpl +++ b/templates/platal/webredirect.tpl @@ -44,19 +44,9 @@

Mise en place de la redirection

-

-{if $carva} - Actuellement, les adresses - http://www.carva.org/{$bestalias} et - http://www.carva.org/{$smarty.session.hruid} - sont redirigées sur http://{$carva} -{else} - La redirection n'est pas utilisée ... -{/if} -

- Pour modifier cette redirection remplis le champ suivant et clique sur Valider. + Pour modifier ta redirection remplis le champ suivant et clique sur Valider. {if $carva} Si tu veux annuler ta redirection, clique sur Supprimer. {/if} diff --git a/upgrade/account/03_carnet.sql b/upgrade/account/03_carnet.sql index 3d3d4fd..707fe01 100644 --- a/upgrade/account/03_carnet.sql +++ b/upgrade/account/03_carnet.sql @@ -1,5 +1,5 @@ create table watch ( - uid int(6) not null auto_increment, + uid int(6) not null, flags set('contacts', 'mail') not null default 'contacts', last timestamp not null default '0000-00-00', diff --git a/upgrade/account/04_carva.sql b/upgrade/account/04_carva.sql new file mode 100644 index 0000000..b583fc0 --- /dev/null +++ b/upgrade/account/04_carva.sql @@ -0,0 +1,8 @@ +create table carvas ( + uid int(6) not null, + url varchar(255) not null, + + primary key uid (uid) +); + +# vim:set syntax=mysql: diff --git a/upgrade/account/99_insertion.sql b/upgrade/account/99_insertion.sql index 0c87792..1b1d464 100644 --- a/upgrade/account/99_insertion.sql +++ b/upgrade/account/99_insertion.sql @@ -28,6 +28,12 @@ insert into watch select user_id as uid, watch_flags as flags, watch_last as last from auth_user_quick; +# Insert carvas +insert into carvas + select user_id, redirecturl + from auth_user_quick + where LENGTH(redirecturl) > 0; + # Insert all existing profiles insert into profiles select user_id AS pid, hruid AS hrpid, matricule AS xorg_id,