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');
?>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
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 <a href='http://$url'>$url</a>");
- } 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 <a href='http://$url'>$url</a>");
+ }
+ } 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.
<h1>
Mise en place de la redirection
</h1>
-<p>
-{if $carva}
- Actuellement, les adresses
- <a href="http://www.carva.org/{$bestalias}">http://www.carva.org/{$bestalias}</a> et
- <a href="http://www.carva.org/{$smarty.session.hruid}">http://www.carva.org/{$smarty.session.hruid}</a>
- sont redirigées sur <a href="http://{$carva}">http://{$carva}</a>
-{else}
- La redirection n'est pas utilisée ...
-{/if}
-</p>
<p>
- Pour modifier cette redirection remplis le champ suivant et clique sur <strong>Valider</strong>.
+ Pour modifier ta redirection remplis le champ suivant et clique sur <strong>Valider</strong>.
{if $carva}
Si tu veux annuler ta redirection, clique sur <strong>Supprimer</strong>.
{/if}
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',
--- /dev/null
+create table carvas (
+ uid int(6) not null,
+ url varchar(255) not null,
+
+ primary key uid (uid)
+);
+
+# vim:set syntax=mysql:
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,