<?php
/***************************************************************************
- * Copyright (C) 2003-2011 Polytechnique.org *
+ * Copyright (C) 2003-2014 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
function handlers()
{
return array(
- 'url' => $this->make_hook('url', AUTH_COOKIE),
- 'admin/url' => $this->make_hook('admin_url', AUTH_MDP, 'admin')
+ 'url' => $this->make_hook('url', AUTH_PUBLIC),
+ 'admin/url' => $this->make_hook('admin_url', AUTH_PASSWD, 'admin')
);
}
function handler_url($page, $alias)
{
- $url = XDB::fetchOneCell('SELECT url
- FROM url_shortener
- WHERE alias = {?}',
- $alias);
-
- if (is_null($url)) {
- return PL_NOT_FOUND;
- }
- http_redirect($url);
+ http_redirect(Platal::globals()->core->base_url_shortener . $alias);
}
function handler_admin_url($page)
$alias = Post::t('alias');
$url_regex = '{^(https?|ftp)://[a-zA-Z0-9._%#+/?=&~-]+$}i';
- if (!preg_match($url_regex, $url)) {
+ if (strlen($url) > 255 || !preg_match($url_regex, $url)) {
$page->trigError("L'url donnée n'est pas valide.");
return;
}
$page->assign('url', $url);
if ($alias != '') {
- if (!preg_match('/^[a-zA-Z0-9\-]{6}$/i', $alias)) {
+ if (!preg_match('/^[a-zA-Z0-9\-\/]+$/i', $alias)) {
$page->trigError("L'alias proposé n'est pas valide.");
return;
}
+ if (preg_match('/^a\//i', $alias)) {
+ $page->trigError("L'alias commence par le préfixe 'a/' qui est réservé et donc non autorisé.");
+ return;
+ }
$page->assign('alias', $alias);
$used = XDB::fetchOneCell('SELECT COUNT(*)
}
} else {
do {
- $alias = rand_token(6);
+ $alias = 'a/' . rand_token(6);
$used = XDB::fetchOneCell('SELECT COUNT(*)
FROM url_shortener
WHERE alias = {?}',
XDB::execute('INSERT INTO url_shortener (url, alias)
VALUES ({?}, {?})',
$url, $alias);
- $page->trigSuccess("L'url « " . $url . ' » est maintenant accessible depuis « ' . Platal::globals()->baseurl . '/url/' . $alias . ' ».');
+ $page->trigSuccess("L'url « " . $url . ' » est maintenant accessible depuis « http://u.w4x.org/' . $alias . ' ».');
}
}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
?>