'') { $complete_dir_s = $BACKUP_DIR . $_POST["page"] . "/"; if (! $dir = @opendir($complete_dir_s)) mkdir($complete_dir_s); if (! $file = @fopen($complete_dir_s . date("Ymd-Hi", mktime(date("H") + $LOCAL_HOUR)) . ".bak", "a")) die("Could not write backup of page!"); fputs($file, "\n// " . $datetw . " / " . " " . $_SERVER['REMOTE_ADDR'] . "\n"); if (get_magic_quotes_gpc()) fputs($file, trim(stripslashes($_POST["content"]))); else fputs($file, trim($_POST["content"]) . "\n\n"); fclose($file); } header("location: ".$NAMEFILE."?page=" . stripslashes($_POST[page])); } else { header("location: ".$NAMEFILE."?page=" . $_POST[page]."&action=edit&error=1"); } } } elseif (isset($_POST["content"]) && $_POST["content"] == "") { if ($_POST["sc"] == $PASSWORD || $_COOKIE['AutorisationTigerWiki'] == md5($PASSWORD)) { setcookie('AutorisationTigerWiki', md5($PASSWORD), time() + 365*24*3600); unlink($PAGES_DIR . stripslashes($_POST["page"]) . ".txt"); } else header("location: ".$NAMEFILE."?page=".$_POST["page"]."&action=edit&error=1"); } // Lecture et analyse du modèle de page if (! $file = @fopen("template.html", "r")) die("'template.html' is missing!"); $template = fread($file, filesize("template.html")); fclose($file); // Lecture du contenu et de la date de modification de la page if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $action <> "") { if (file_exists($PAGES_DIR . $PAGE_TITLE . ".txt")) $TIME = date("Y/m/d H:i", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt") + $LOCAL_HOUR * 3600); $CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n"; // Restaurer une page if (isset($_GET["page"]) && isset($gtime) && $_GET["restore"] == 1) if ($file = @fopen($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime, "r")) $CONTENT = "\n" . @fread($file, @filesize($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime)) . "\n"; @fclose($file); $CONTENT = preg_replace("/\\$/Umsi", "$", $CONTENT); $CONTENT = preg_replace("/\\\/Umsi", "\", $CONTENT); } else { if (!file_exists($PAGES_DIR . $PAGE_TITLE . ".txt")) $CONTENT = "\n" . $DEFAULT_CONTENT; else $action = "edit"; } // Déterminer le mode d'accès if ($action == "edit" || $action == "search" || $action == "recent") $html = preg_replace('/{EDIT}/', $EDIT_BUTTON, $template); elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt") || !file_exists($PAGES_DIR . $PAGE_TITLE . ".txt")) $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template); else $html = preg_replace('/{EDIT}/', $PROTECTED_BUTTON, $template); if ($action == "recent") $html = preg_replace('/{RECENT_CHANGES}/', $RECENT_CHANGES, $html); else $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html); // Remplacer les variables par des valeurs (dans le style de page) $html = preg_replace('/{PAGE_TITLE_BRUT}/', $PAGE_TITLE, $html); if ($action != "" && $action != "recent" && $action != "search") $html = preg_replace('/{PAGE_TITLE}/', "".$PAGE_TITLE."", $html); else $html = preg_replace('/{PAGE_TITLE}/', $PAGE_TITLE, $html); if ($PAGE_TITLE == $START_PAGE && $action <> "search") $html = preg_replace('/{HOME}/', $HOME_BUTTON, $html); else $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html); $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html); $html = preg_replace('/{LAST_CHANGE}/', $LAST_CHANGES." :", $html); if ($PAGE_TITLE == $HELP_BUTTON) $html = preg_replace('/{HELP}/', $HELP_BUTTON, $html); else $html = preg_replace('/{HELP}/', "$HELP_BUTTON", $html); $html = preg_replace('/{SEARCH}/', "
", $html); if ($action == "edit") { $html = preg_replace('/{HISTORY}/', "/ ".$HISTORY_BUTTON."
", $html); $CONTENT = "

"; if ($PASSWORD != "" && $_COOKIE['AutorisationTigerWiki'] != md5($PASSWORD)) $CONTENT .= $MDP." : "; $CONTENT .= "

"; } elseif ($action != "history") $html = preg_replace('/{HISTORY}/', "", $html); // Liste des versions historiques d'une page if ($action == "history" && !isset($gtime)) { $html = preg_replace('/{HISTORY}/', "/ ".$HISTORY_BUTTON, $html); $complete_dir = $BACKUP_DIR . $_GET["page"] . "/"; if ($opening_dir = @opendir($complete_dir)) { while (false !== ($filename = @readdir($opening_dir))) $files[] = $filename; sort ($files); for($cptfiles = 2; $files[$cptfiles] != ''; $cptfiles++) $affichage = $affichage."".$files[$cptfiles]."
"; $html = preg_replace('/{CONTENT}/', $affichage, $html); } else $html = preg_replace('/{CONTENT}/', $NO_HISTORY, $html); } // Affichage d'un fichier historique if ($action == "history" && isset($gtime)) { $complete_dir = $BACKUP_DIR . $PAGE_TITLE . "/"; if ($file = @fopen($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime, "r")) { $html = preg_replace('/{HISTORY}/', "/ ".$HISTORY_BUTTON." (".$RESTORE.")", $html); $CONTENT = @fread($file, @filesize($complete_dir . $gtime)) . "\n"; } else $html = preg_replace('/{HISTORY}/', "/ ".$HISTORY_BUTTON." (-)", $html); } // Erreur du mot de passe if ($_GET['error'] == 1) $html = preg_replace('/{ERROR}/', $ERROR, $html); else $html = preg_replace('/{ERROR}/', "", $html); // Effacement du cookie if ($_GET['erasecookie'] == 1) setcookie('AutorisationTigerWiki'); // Page de recherche if ($action == "search") { $dir = opendir(getcwd() . "/$PAGES_DIR"); while ($file = readdir($dir)) { if (preg_match("/.txt/", $file)) { $handle = fopen($PAGES_DIR . $file, "r"); @$content = fread($handle, filesize($PAGES_DIR . $file)); fclose($handle); if (preg_match("/$_GET[query]/i", $content) || preg_match("/$_GET[query]/i", "$PAGES_DIR/$file")) { $file = substr($file, 0, strlen($file) - 4); $CONTENT .= "$file
"; } } } } // Changements récents elseif ($action == "recent") { $dir = opendir(getcwd() . "/$PAGES_DIR"); while ($file = readdir($dir)) if (preg_match("/.txt/", $file)) $filetime[$file] = filemtime($PAGES_DIR . $file); arsort($filetime); $filetime = array_slice($filetime, 0, 10); foreach ($filetime as $filename => $timestamp) { $filename = substr($filename, 0, strlen($filename) - 4); $CONTENT .= "$filename (" . strftime("$TIME_FORMAT", $timestamp + $LOCAL_HOUR * 3600) . ")
"; } } // Formatage de page elseif ($action <> "edit") { if (preg_match("/%html%\s/", $CONTENT)) $CONTENT = preg_replace("/%html%\s/", "", $CONTENT); else { $CONTENT = htmlentities($CONTENT); $CONTENT = preg_replace("/&#036;/Umsi", "$", $CONTENT); $CONTENT = preg_replace("/&#092;/Umsi", "\", $CONTENT); $CONTENT = preg_replace("/\^(.)/Umsie", "'&#'.ord('\\1').';'", $CONTENT); $CONTENT = preg_replace('#\[(.+)\|([0-9a-zA-Z\.\'\s\#/~\-_%=\?\&,\+]*)\]#U', '$1', $CONTENT); $CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&,\+]*)\]#U', '$1', $CONTENT); $CONTENT = preg_replace('#\[([0-9a-zA-Z\.\&\#\:/~\-_%=?]*\.(jpg|gif|png))\]#i', '', $CONTENT); $CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '', $CONTENT); $CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*)#i', '$1', $CONTENT); $CONTENT = preg_replace('#xxttp#', 'http', $CONTENT); preg_match_all("/\[([^\/]+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER); //Pour bloquer les liens accentués : "/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U" foreach ($matches[1] as $match) if (file_exists(html_entity_decode($PAGES_DIR."$match.txt"))) $CONTENT = str_replace("[$match]", "$match", $CONTENT); else $CONTENT = str_replace("[$match]", "$match", $CONTENT); $CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '$0', $CONTENT); $CONTENT = preg_replace('/^\*\*\*(.*)(\n)/Um', "$2", $CONTENT); $CONTENT = preg_replace('/^\*\*(.*)(\n)/Um', "$2", $CONTENT); $CONTENT = preg_replace('/^\*(.*)(\n)/Um', "$2", $CONTENT); $CONTENT = preg_replace('/^\#\#\#(.*)(\n)/Um', "
      1. $1
$2", $CONTENT); $CONTENT = preg_replace('/^\#\#(.*)(\n)/Um', "
    1. $1
$2", $CONTENT); $CONTENT = preg_replace('/^\#(.*)(\n)/Um', "
  1. $1
$2", $CONTENT); $CONTENT = preg_replace('/(<\/ol>\n*
    |<\/ul>\n*(
    )*#', "", $CONTENT); $CONTENT = preg_replace('#
(
)*#', "", $CONTENT); $CONTENT = preg_replace('#()
#', "$1", $CONTENT); $CONTENT = preg_replace("/{(.+)}/Ue", "'
' . preg_replace('#
#', '', '\\1') . '
'", $CONTENT); $CONTENT = preg_replace("/'''(.*)'''/Um", '$1', $CONTENT); $CONTENT = preg_replace("/''(.*)''/Um", '$1', $CONTENT); $CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6); $CONTENT = html_entity_decode($CONTENT); } } if ($action != "" && $action != "edit" || (!file_exists($PAGES_DIR . $PAGE_TITLE . ".txt"))) $TIME = "-"; $html = preg_replace("/{CONTENT}/", $CONTENT, $html); $html = preg_replace('/{TIME}/', $TIME, $html); $html = preg_replace('/{DATE}/', $datetw, $html); $html = preg_replace('/{IP}/', $_SERVER['REMOTE_ADDR'], $html); if ($_COOKIE['AutorisationTigerWiki'] != "") $html = preg_replace('/{COOKIE}/', '-- '.$ERASE_COOKIE.'', $html); else $html = preg_replace('/{COOKIE}/', '', $html); // Affichage de la page echo $html; ?>