, license GNU/GPL, www.gnu.org // v0.4b2 class wiki { // Tags gérés par le wiki, à modifier si besoin var $tags = array( "{{{"=>"
",$texte);
$pos = strpos($texte,"[code]");
$i++;
}
$texte = eregi_replace("(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero):[A-Za-z0-9/](([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2})+)","\\0",$texte);
$texte = eregi_replace("(^|[ \t\r\n])([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+)", "\\0", $texte);
$texte = ereg_replace("(^|[ \t\r\n])(([A-Z]+[a-z]+){2,})","\\1\\2",$texte);
$texte = strtr($texte,$this->tags);
for($i=1;$i <= count($code); $i++) {
$code[$i] = ereg_replace("(\n| ) ","\\1 ",$code[$i]);
$texte = str_replace("",''.trim($code[$i]).'
',$texte);
}
$texte = str_replace("@","@",$texte);
return nl2br($texte);
}
// Affichage d'une page (template)
// Array( "titre", "texte", "form" => "action du formulaire", "bouton" => "intitulé du bouton",
// "infos" => "Infos bas de page", "page" => "nom de la page");
function affiche_page($rec) { //$titre,$texte,$form,$bouton,$infos,$page) {
$template = <<
#TITRE
#TRANSITION
#TITRE
ENDOFFILE;
if($rec[page] == "PageDaccueil") $rec[titre] = $this->conf[nom_wiki];
if(file_exists($this->chemin."page.html")) { $f = file($this->chemin."page.html"); $template = implode($f); }
if(empty($rec[transition])) $rec[transition] = "\n";
$template = str_replace("#TITRE",htmlentities(stripslashes($rec[titre])),$template);
$template = str_replace("#INFOS",$rec[infos],$template);
$template = str_replace("#FORM",$rec[form],$template);
$template = str_replace("#BOUTON",htmlentities(stripslashes($rec[bouton])),$template);
$template = str_replace("#TEXTE",$rec[texte],$template);
$template = str_replace("#NOM_WIKI",$this->conf[nom_wiki],$template);
$template = str_replace("#TRANSITION",$rec[transition],$template);
return $template;
}
function show_conf() {
if($this->conf[type] == "prive") $prive = "checked=\"checked\"";
else $libre = "checked=\"checked\"";
if(!empty($this->conf[ip])) $ip = "checked=\"checked\"";
if(!empty($this->conf[pass])) $pass = "checked=\"checked\"";
$this->conf[nom_wiki] = htmlentities(stripslashes($this->conf[nom_wiki]));
$t.= <<
Type de wiki:
Authentification du wiki pour l'administration:
END;
$rec = array("titre"=>"Configuration","texte"=>$t,"form"=>"./configuration","bouton"=>"Enregistrer","page"=>"configuration",
"infos"=>"Aide de WikiKubbe");
echo $this->affiche_page($rec);
}
function do_conf() {
if(empty($_POST[nom])) return $this->show_error("Vous n'avez pas spécifié le nom de votre wiki.","configuration");
elseif($_POST[pass1] == "oui" && empty($_POST[pass2])) return $this->show_error("Vous n'avez pas spécifié de mot de passe alors que vous avez coché la se correspondante.","configuration");
elseif($_POST[ip1] == "oui" && empty($_POST[ip2])) return $this->show_error("Vous n'avez pas spécifié d'adresse IP alors que vous avez coché la se correspondante.","configuration");
$fp = @fopen($this->datas."config.inc.php","w");
if(!$fp) return $this->show_error($this->txt[inconnu]);
$cont = "";
fputs($fp,$cont);
fclose($fp);
return TRUE;
}
function show_error($t,$p="") {
$t = nl2br(htmlentities(stripslashes($t)));
$rec = array("titre"=>"Erreur","texte"=>$t,"form"=>"./{$p}","bouton"=>"Retour","page"=>"rien",
"infos"=>"Aide de WikiKubbe");
echo $this->affiche_page($rec);
return FALSE;
}
function do_inst() {
$perms = decoct(fileperms(".")) % 1000;
if($perms < 755) return $this->show_error(str_replace("[perms]",$perms,$this->txt[perms]));
$r = @mkdir(substr($this->datas,0,-1),0777);
$r = @mkdir(substr($this->public,0,-1),0777);
if(!$r) return $this->show_error($this->txt[mkdir]);
$fp = @fopen($this->datas."version","w");
if(!$fp) return $this->show_error($this->txt[inconnu]);
fputs($fp,$this->version);
fclose($fp);
$fp = @fopen($this->datas.".htaccess","w");
if(!$fp) return $this->show_error($this->txt[inconnu]);
fputs($fp,"Allow from none\nDeny from All\n");
fclose($fp);
return TRUE;
}
function show_maj($ver) {
$t = $this->txt[maj][$ver];
$t = nl2br(htmlentities(stripslashes($t)));
$rec = array("titre"=>"Mise à jour","texte"=>$t,"form"=>"./maj","bouton"=>"Effectuer la mise à jour","page"=>"maj",
"infos"=>"Aide de WikiKubbe");
echo $this->affiche_page($rec);
}
function lire($page) {
$f = @file($this->datas.$page.".kub");
if(!$f) return FALSE;
$out = implode("",$f);
$rec[date] = filemtime($this->datas.$page.".kub");
if(file_exists($this->datas.$page.".mod")) {
$rec[modif] = filemtime($this->datas.$page.".mod");
$tmp = @file($this->datas.$page.".mod");
$rec[ip] = $tmp[0];
} else $rec[modif] = "1";
$rec[texte] = $out;
return $rec;
}
function do_save($p,$txt) {
$fp = @fopen($this->datas.$p.".kub","w");
if(!$fp) return FALSE;
fputs($fp,$txt);
fclose($fp);
return TRUE;
}
function show_page($p) {
$rec = $this->lire($p);
if($rec === FALSE) $rec = array(
"texte"=>"Pour écrire dans cette page cliquez sur le bouton Editer.",
"date"=>"Page inexistante","infos"=>"Page inexistante");
else {
$rec[texte] = $this->filtre($rec[texte]);
if($this->auth == "oui") $rec[infos] = "MàJ le ".date("d/m/Y H:i",$rec[date])." - Administration";
else $rec[infos] = "Dernière mise à jour le ".date("d/m/Y H:i",$rec[date]);
}
$rec[form] = "./editer~".$p;
$rec[bouton] = "Editer";
$rec[page] = $p;
$rec[titre] = strtr($p,array("_"=>" ","."=>" / "));
echo $this->affiche_page($rec);
}
function edit_page($p) {
if(file_exists($this->datas.$p.".lock")) $lock=TRUE;
if(file_exists($this->datas.$p.".unlock")) $unlock=TRUE;
if(($this->conf[type] == "prive" || $lock) && ($this->auth != "oui") && !$unlock) {
$this->show_error("Cette page est protégée contre l'édition.",$p);
exit;
}
$rec = $this->lire($p);
if((($rec[modif] > 1) && ($rec[modif] > time()-3600) && ($_SERVER[REMOTE_ADDR] != $rec[ip])) && $this->auth != "oui")
return $this->show_error("Cette page est déjà en train d'être modifiée par une autre personne.",$p);
if($rec !== FALSE) {
$fp = @fopen($this->datas.$p.".mod","w");
if($fp) { fputs($fp,$_SERVER[REMOTE_ADDR]); fclose($fp); }
}
$rec[texte] = "
";
if($this->auth == "oui") {
$t.= '';
if($this->conf[type] == "libre") {
$t.= ' ';
} else {
$t.= ' ';
}
$t.= ' Administration
';
}
$rec[titre] = "Edition de {$p}";
$rec[form] = "./enregistrer~{$p}";
$rec[bouton] = "Enregistrer";
$rec[infos] = "Retour";
if(file_exists($this->datas."module.wysiwyg"))
$rec[transition] = '