//
// This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. //
// To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ //
// or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. //
// Francais (brouillon): http://creativecommons.org/projects/international/fr/translated-license //
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Gestion des URLs
// v0.2.4
// Classe qui gère les URLs
class redirection
{
// Type d'URLS à gérer
// "dom" => http://login.monsite.com/
// "dir" => http://www.monsite.com/login/
var $type_url = "dom";
var $cache_urls = array();
var $cache_urls_loaded = FALSE;
function _getIDfromURL($url) {
if(!$this->cache_urls_loaded) $this->_loadCacheUrls();
if(array_key_exists($url,$this->cache_urls)) return $this->cache_urls[$url];
return FALSE;
}
function _loadCacheUrls() {
$file = file("datas/cache/urls.txt");
$this->cache_urls = unserialize(implode("",$file));
}
// On récupère l'id unique du journal
function get_id()
{
#$id = $this->_getIDfromURL($this->domain);
if(!$id)
{
if($this->type_url == "dom")
{
$url = $this->domain;
$id = substr($url,0,strpos($url,"."));
}
else
{
$id = substr($this->url,1);
$id = substr($id,0,strpos($id,"/"));
}
}
$this->id = $id;
if(!file_exists("datas/cache/".$id)) return FALSE;
return $id;
}
// On récupère l'URL demandée
function get_url() {
if($this->type_url == "dom") return $this->url;
else {
$url = substr($this->url,1);
$url = substr($url,strpos($url,"/"));
return $url;
}
}
// Si la page existe en cache on renvoie son URI
function is_cache($id,$url) {
if(substr($url,-1) == "/") $url = substr($url,0,-1);
$url = strtr(substr($url,1),array("/"=>"_","~"=>"-"));
$uri = "datas/cache/".$id."/".$url;
if(file_exists($uri)) return $uri;
return FALSE;
}
// Message d'erreur
function erreur($statut)
{
$url = $this->url;
$id = $this->id;
include_once("erreur.php");
exit;
}
function what_is($url)
{
if(substr($url,0,1) == "/") $url = substr($url,1);
if(substr($url,-1) == "/") $url = substr($url,0,-1);
$url = explode("/",$url);
if($url[0] == "backend" && $url[1] == "forum") {
$rec['type'] = "rss_forum";
}
elseif($url[0] == "rss" || $url[0] == "backend") {
$rec['type'] = "rss";
}
elseif(($url[0] == "forum") && empty($url[1])) {
$rec['type'] = "forum_page";
$rec['id'] = "0";
}
elseif(($url[0] == "forum") && strpos($url[1],"-")) {
$rec['type'] = "forum_message";
$rec['id'] = $url[1];
}
elseif(($url[0] == "forum") && substr($url[1],0,1) == "+") {
$rec['type'] = "forum_page";
$rec['id'] = substr($url[1],1);
}
elseif(is_numeric($url[0]) && is_numeric($url[1]) && (strlen($url[2]) >= 2)) {
$rec['type'] = "ecrit";
$rec['id'] = implode("/",$url);
}
elseif(is_numeric($url[0]) && is_numeric($url[1])) {
$rec['type'] = "mois";
$rec['id'] = $url[0].$url[1];
#if(substr($url[1],0,1) == "~") $rec['debut'] = substr($url[1],1);
}
elseif(empty($url[0])) {
$rec['type'] = "accueil";
}
return $rec;
}
function show_toolbar($texte)
{
$tag = '';
$f = str_replace("",$tag,$texte);
$tag = '