[ PHPXref.com ] [ Generated: Sun Jul 20 20:38:17 2008 ] [ TigerWiki 2.14 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> index.php (source)

   1  <?php
   2      // TigerWiki 2 (Version 2.14 - 2006-05-03)
   3      // Copyleft (C) Arsenic 2005-2006, licence GNU/GPL (disponible sur www.gnu.org)
   4      // http://chabel.org/ - root chez chabel point org
   5     
   6  // Configuration du mot de passe
   7      $PASSWORD            =    "";
   8  // Nom de ce fichier
   9      $NAMEFILE           =   "index.php";
  10  // Paramètres divers
  11      $TIME_FORMAT        =    "%Y/%m/%d %R";
  12      $LOCAL_HOUR            =    "-6";
  13      $PAGES_DIR            =     "pages/";
  14      $BACKUP_DIR            =    "historique/";
  15  // Variables de configuration de langues
  16      $WIKI_TITLE            =    "TigerWiki 2";
  17      $START_PAGE            =    "Accueil";
  18      $HOME_BUTTON        =    "Accueil";
  19      $HELP_BUTTON        =    "Aide";
  20      $DEFAULT_CONTENT    =    "La page ". $_GET["page"]." est vide.";
  21      $EDIT_BUTTON        =    "&Eacute;diter";
  22      $DONE_BUTTON        =    "Enregistrer";
  23      $PROTECTED_BUTTON     =    "Page verrouill&eacute;e";
  24      $SEARCH_BUTTON        =    "Rechercher";
  25      $SEARCH_RESULTS        =    "R&eacute;sultats de recherche pour";
  26      $LIST                =    "Liste des pages";
  27      $RECENT_CHANGES        =    "Changements r&eacute;cents";
  28      $LAST_CHANGES        =    "Derni&egrave;re modification";
  29      $HISTORY_BUTTON        =    "Historique";
  30      $NO_HISTORY            =    "Aucun historique existant.";
  31      $RESTORE            =   "Restaurer";
  32      $ANONYMOUS          =   "-Anonyme-";
  33      $MDP                =   "Mot de passe";
  34      $ERROR                =    $MDP." sp&eacute;cifi&eacute; incorrect.";
  35      $ERASE_COOKIE       =   "Eff. cookie";
  36  // Trouver la page à afficher
  37      if (! $PAGE_TITLE = stripslashes($_GET["page"])) {
  38          if ($_GET["action"] == "search")
  39              if ($_GET["query"] != "")
  40                  $PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\"";
  41              else
  42                  $PAGE_TITLE = $LIST;
  43          elseif ($_GET["action"] == "recent")
  44              $PAGE_TITLE = "$RECENT_CHANGES";
  45          else
  46              $PAGE_TITLE = "$START_PAGE";
  47      }
  48      $action = $_GET["action"];
  49      $gtime = $_GET["time"];
  50      $datetw = date("Y/m/d H:i", mktime(date("H") + $LOCAL_HOUR));
  51  // Arrêter les accès malicieux via répertoire
  52      if (preg_match("/\//", $PAGE_TITLE))
  53          $PAGE_TITLE = $START_PAGE;
  54      if (preg_match("/\//", $gtime))
  55          $gtime = '';
  56  // Écrire les modifications, s'il y a lieu
  57         if ($_POST["content"] != "") {
  58          if ($_SERVER["REQUEST_METHOD"] == "POST") {    
  59              if ($_POST["sc"] == $PASSWORD || $_COOKIE['AutorisationTigerWiki'] == md5($PASSWORD)) {
  60                  setcookie('AutorisationTigerWiki', md5($PASSWORD), time() + 365*24*3600);
  61                  if (! $file = @fopen($PAGES_DIR . stripslashes($_POST["page"]) . ".txt", "w"))
  62                      die("Could not write page!");
  63                  if (get_magic_quotes_gpc())
  64                      fputs($file, trim(stripslashes($_POST["content"])));
  65                  else
  66                      fputs($file, trim($_POST["content"]));        
  67                  fclose($file);        
  68                  if ($BACKUP_DIR <> '') {
  69                      $complete_dir_s = $BACKUP_DIR . $_POST["page"] . "/";
  70                      if (! $dir = @opendir($complete_dir_s))
  71                          mkdir($complete_dir_s);
  72                      if (! $file = @fopen($complete_dir_s . date("Ymd-Hi", mktime(date("H") + $LOCAL_HOUR)) . ".bak", "a"))
  73                          die("Could not write backup of page!");
  74                       fputs($file, "\n// " . $datetw . " / " . " " . $_SERVER['REMOTE_ADDR'] . "\n");
  75                      if (get_magic_quotes_gpc())
  76                           fputs($file, trim(stripslashes($_POST["content"])));
  77                      else
  78                           fputs($file, trim($_POST["content"]) . "\n\n");            
  79                       fclose($file);
  80                  }
  81                  header("location: ".$NAMEFILE."?page=" . stripslashes($_POST[page]));
  82              }
  83              else { header("location: ".$NAMEFILE."?page=" . $_POST[page]."&action=edit&error=1"); }
  84      }
  85      }
  86      elseif (isset($_POST["content"]) && $_POST["content"] == "") {
  87          if ($_POST["sc"] == $PASSWORD || $_COOKIE['AutorisationTigerWiki'] == md5($PASSWORD)) {
  88              setcookie('AutorisationTigerWiki', md5($PASSWORD), time() + 365*24*3600);
  89              unlink($PAGES_DIR . stripslashes($_POST["page"]) . ".txt");
  90          }
  91          else
  92              header("location: ".$NAMEFILE."?page=".$_POST["page"]."&action=edit&error=1");
  93      }
  94  // Lecture et analyse du modèle de page
  95      if (! $file = @fopen("template.html", "r"))
  96          die("'template.html' is missing!");
  97      $template = fread($file, filesize("template.html"));
  98      fclose($file);
  99  // Lecture du contenu et de la date de modification de la page
 100      if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $action <> "") {
 101          if (file_exists($PAGES_DIR . $PAGE_TITLE . ".txt"))
 102              $TIME = date("Y/m/d H:i", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt") + $LOCAL_HOUR * 3600);
 103      $CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n";
 104          // Restaurer une page
 105          if (isset($_GET["page"]) && isset($gtime) && $_GET["restore"] == 1)
 106              if ($file = @fopen($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime, "r"))
 107                  $CONTENT = "\n" . @fread($file, @filesize($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime)) . "\n";
 108          @fclose($file);
 109          $CONTENT = preg_replace("/\\$/Umsi", "&#036;", $CONTENT);
 110          $CONTENT = preg_replace("/\\\/Umsi", "&#092;", $CONTENT);
 111      }
 112      else {
 113          if (!file_exists($PAGES_DIR . $PAGE_TITLE . ".txt"))
 114              $CONTENT = "\n" . $DEFAULT_CONTENT;
 115          else
 116              $action = "edit";
 117      }
 118  // Déterminer le mode d'accès
 119      if ($action == "edit" || $action == "search" || $action == "recent")
 120          $html = preg_replace('/{EDIT}/', $EDIT_BUTTON, $template);
 121      elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt") || !file_exists($PAGES_DIR . $PAGE_TITLE . ".txt"))
 122          $html = preg_replace('/{EDIT}/', "<a href=\"".$NAMEFILE."?page=".$_GET["page"]."&amp;action=edit\" accesskey=\"5\">$EDIT_BUTTON</a>", $template);
 123      else
 124          $html = preg_replace('/{EDIT}/', $PROTECTED_BUTTON, $template);
 125      if ($action == "recent")
 126          $html = preg_replace('/{RECENT_CHANGES}/', $RECENT_CHANGES, $html);
 127      else
 128          $html = preg_replace('/{RECENT_CHANGES}/', "<a href=\"".$NAMEFILE."?action=recent\" accesskey=\"3\">$RECENT_CHANGES</a>", $html);
 129  // Remplacer les variables par des valeurs (dans le style de page)
 130      $html = preg_replace('/{PAGE_TITLE_BRUT}/', $PAGE_TITLE, $html);
 131      if ($action != "" && $action != "recent" && $action != "search")
 132         $html = preg_replace('/{PAGE_TITLE}/', "<a href=\"".$NAMEFILE."?page=".$PAGE_TITLE."\">".$PAGE_TITLE."</a>", $html);
 133      else
 134          $html = preg_replace('/{PAGE_TITLE}/', $PAGE_TITLE, $html);
 135      if ($PAGE_TITLE == $START_PAGE && $action <> "search")
 136          $html = preg_replace('/{HOME}/', $HOME_BUTTON, $html);
 137      else
 138          $html = preg_replace('/{HOME}/', "<a href=\"".$NAMEFILE."?page=".$START_PAGE."\" accesskey=\"1\">$HOME_BUTTON</a>", $html);
 139      $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html);
 140      $html = preg_replace('/{LAST_CHANGE}/', $LAST_CHANGES." :", $html);
 141      if ($PAGE_TITLE == $HELP_BUTTON)
 142          $html = preg_replace('/{HELP}/', $HELP_BUTTON, $html);    
 143      else
 144          $html = preg_replace('/{HELP}/', "<a href=\"".$NAMEFILE."?page=$HELP_BUTTON\" accesskey=\"2\">$HELP_BUTTON</a>", $html);
 145      $html = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"".$NAMEFILE."?page=".$_GET[page]."\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$_GET[query]\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" accesskey=\"q\" /></form>", $html);
 146      if ($action == "edit") {
 147          $html = preg_replace('/{HISTORY}/', "/ <a href=\"?page=".$PAGE_TITLE."&action=history\" accesskey=\"6\">".$HISTORY_BUTTON."</a><br />", $html);
 148          $CONTENT = "<form method=\"post\" action=\"".$NAMEFILE."\"><textarea name=\"content\" cols=\"83\" rows=\"30\" style=\"width: 100%;\">$CONTENT</textarea><input type=\"hidden\" name=\"page\" value=\"".$_GET[page]."\" /><br /><p align=\"right\">";
 149          if ($PASSWORD != "" && $_COOKIE['AutorisationTigerWiki'] != md5($PASSWORD))
 150              $CONTENT .= $MDP." : <input type=\"password\" name=\"sc\">";
 151          $CONTENT .= " <input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></p></form>";
 152      }
 153      elseif ($action != "history")
 154          $html = preg_replace('/{HISTORY}/', "", $html);
 155  // Liste des versions historiques d'une page
 156      if ($action == "history" && !isset($gtime)) {
 157          $html = preg_replace('/{HISTORY}/', "/ ".$HISTORY_BUTTON, $html);
 158          $complete_dir = $BACKUP_DIR . $_GET["page"] . "/";
 159          if ($opening_dir = @opendir($complete_dir)) {
 160              while (false !== ($filename = @readdir($opening_dir)))
 161                  $files[] = $filename;
 162              sort ($files);
 163                 for($cptfiles = 2; $files[$cptfiles] != ''; $cptfiles++)
 164                  $affichage = $affichage."<a href=\"?page=".$_GET["page"]."&action=history&time=".$files[$cptfiles]."\">".$files[$cptfiles]."</a><br />";
 165              $html = preg_replace('/{CONTENT}/', $affichage, $html);
 166          }
 167          else
 168              $html = preg_replace('/{CONTENT}/', $NO_HISTORY, $html);
 169      }
 170  // Affichage d'un fichier historique
 171      if ($action == "history" && isset($gtime)) {
 172          $complete_dir = $BACKUP_DIR . $PAGE_TITLE . "/";
 173          if ($file = @fopen($BACKUP_DIR . $PAGE_TITLE . "/" . $gtime, "r")) {
 174              $html = preg_replace('/{HISTORY}/', "/ <a href=\"?page=".$PAGE_TITLE."&action=history\">".$HISTORY_BUTTON."</a> (<a href=\"?page=".$PAGE_TITLE."&action=edit&time=".$gtime."&restore=1\">".$RESTORE."</a>)", $html);
 175              $CONTENT = @fread($file, @filesize($complete_dir . $gtime)) . "\n";
 176            }
 177            else
 178              $html = preg_replace('/{HISTORY}/', "/ <a href=\"?page=".$PAGE_TITLE."&action=history\">".$HISTORY_BUTTON."</a> (-)", $html);
 179      }
 180  // Erreur du mot de passe
 181      if ($_GET['error'] == 1)
 182          $html = preg_replace('/{ERROR}/', $ERROR, $html);
 183      else
 184          $html = preg_replace('/{ERROR}/', "", $html);
 185  // Effacement du cookie
 186      if ($_GET['erasecookie'] == 1)
 187          setcookie('AutorisationTigerWiki');
 188  // Page de recherche
 189      if ($action == "search") {
 190          $dir = opendir(getcwd() . "/$PAGES_DIR");
 191          while ($file = readdir($dir)) {
 192              if (preg_match("/.txt/", $file)) {
 193                  $handle = fopen($PAGES_DIR . $file, "r");
 194                  @$content = fread($handle, filesize($PAGES_DIR . $file));
 195                  fclose($handle);
 196                  if (preg_match("/$_GET[query]/i", $content) || preg_match("/$_GET[query]/i", "$PAGES_DIR/$file")) {
 197                      $file = substr($file, 0, strlen($file) - 4);
 198                      $CONTENT .= "<a href=\"".$NAMEFILE."?page=$file\">$file</a><br />";
 199                  }
 200              }
 201          }
 202      }
 203  // Changements récents
 204      elseif ($action == "recent") {
 205          $dir = opendir(getcwd() . "/$PAGES_DIR");
 206          while ($file = readdir($dir))
 207              if (preg_match("/.txt/", $file))
 208                  $filetime[$file] = filemtime($PAGES_DIR . $file);
 209          arsort($filetime);
 210          $filetime = array_slice($filetime, 0, 10);
 211          foreach ($filetime as $filename => $timestamp) {
 212              $filename = substr($filename, 0, strlen($filename) - 4);
 213              $CONTENT .= "<a href=\"".$NAMEFILE."?page=$filename\">$filename</a> (" . strftime("$TIME_FORMAT", $timestamp + $LOCAL_HOUR * 3600) . ")<br />";
 214          }
 215      }
 216  // Formatage de page
 217      elseif ($action <> "edit") {
 218          if (preg_match("/%html%\s/", $CONTENT))     
 219              $CONTENT = preg_replace("/%html%\s/", "", $CONTENT);
 220          else {
 221              $CONTENT = htmlentities($CONTENT);
 222              $CONTENT = preg_replace("/&amp;#036;/Umsi", "&#036;", $CONTENT);
 223              $CONTENT = preg_replace("/&amp;#092;/Umsi", "&#092;", $CONTENT);
 224              $CONTENT = preg_replace("/\^(.)/Umsie", "'&#'.ord('\\1').';'", $CONTENT);
 225              $CONTENT = preg_replace('#\[(.+)\|([0-9a-zA-Z\.\'\s\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="$2" class="url">$1</a>', $CONTENT);
 226              $CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="xx$2" class="url">$1</a>', $CONTENT);
 227              $CONTENT = preg_replace('#\[([0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))\]#i', '<img src="$1" />', $CONTENT);
 228              $CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
 229              $CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0" class="url">$1</a>', $CONTENT);
 230              $CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
 231              preg_match_all("/\[([^\/]+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER); //Pour bloquer les liens accentués : "/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U"
 232              foreach ($matches[1] as $match)
 233                  if (file_exists(html_entity_decode($PAGES_DIR."$match.txt")))
 234                      $CONTENT = str_replace("[$match]", "<a href=\"".$NAMEFILE."?page=".$match."\">$match</a>", $CONTENT);
 235                  else
 236                      $CONTENT = str_replace("[$match]", "<a class=\"pending\" href=\"".$NAMEFILE."?page=".$match."\">$match</a>", $CONTENT);
 237              $CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $CONTENT);
 238              $CONTENT = preg_replace('/^\*\*\*(.*)(\n)/Um', "<ul><ul><ul><li>$1</li></ul></ul></ul>$2", $CONTENT);
 239              $CONTENT = preg_replace('/^\*\*(.*)(\n)/Um', "<ul><ul><li>$1</li></ul></ul>$2", $CONTENT);
 240              $CONTENT = preg_replace('/^\*(.*)(\n)/Um', "<ul><li>$1</li></ul>$2", $CONTENT);
 241              $CONTENT = preg_replace('/^\#\#\#(.*)(\n)/Um', "<ol><ol><ol><li>$1</li></ol></ol></ol>$2", $CONTENT);
 242              $CONTENT = preg_replace('/^\#\#(.*)(\n)/Um', "<ol><ol><li>$1</li></ol></ol>$2", $CONTENT);
 243              $CONTENT = preg_replace('/^\#(.*)(\n)/Um', "<ol><li>$1</li></ol>$2", $CONTENT);
 244              $CONTENT = preg_replace('/(<\/ol>\n*<ol>|<\/ul>\n*<ul>)/', "", $CONTENT);
 245              $CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
 246              $CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
 247              $CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);
 248              while (preg_match('/^  /Um', $CONTENT))
 249                  $CONTENT = preg_replace('/^( +) ([^ ])/Um', '$1&nbsp;&nbsp;&nbsp;&nbsp;$2', $CONTENT);
 250              $CONTENT = preg_replace('/^ /Um', '&nbsp;&nbsp;&nbsp;&nbsp;', $CONTENT);
 251              $CONTENT = preg_replace('/----*(\r\n|\r|\n)/m', '<hr />', $CONTENT);
 252              $CONTENT = preg_replace('/\n/', '<br />', $CONTENT);
 253              $CONTENT = preg_replace('#</ul>(<br />)*#', "</ul>", $CONTENT);
 254              $CONTENT = preg_replace('#</ol>(<br />)*#', "</ol>", $CONTENT);
 255              $CONTENT = preg_replace('#(</h[123]>)<br />#', "$1", $CONTENT);
 256              $CONTENT = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $CONTENT);
 257              $CONTENT = preg_replace("/'''(.*)'''/Um", '<b>$1</b>', $CONTENT);
 258              $CONTENT = preg_replace("/''(.*)''/Um", '<i>$1</i>', $CONTENT); 
 259              $CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);
 260              $CONTENT = html_entity_decode($CONTENT);
 261          }
 262      }
 263      if ($action != "" && $action != "edit" || (!file_exists($PAGES_DIR . $PAGE_TITLE . ".txt")))
 264          $TIME = "-";
 265      $html = preg_replace("/{CONTENT}/", $CONTENT, $html);
 266      $html = preg_replace('/{TIME}/', $TIME, $html);
 267      $html = preg_replace('/{DATE}/', $datetw, $html);
 268      $html = preg_replace('/{IP}/', $_SERVER['REMOTE_ADDR'], $html);
 269      if ($_COOKIE['AutorisationTigerWiki'] != "")
 270          $html = preg_replace('/{COOKIE}/', '-- <a href="'.$NAMEFILE.'?erasecookie=1">'.$ERASE_COOKIE.'</a>', $html);
 271      else
 272          $html = preg_replace('/{COOKIE}/', '', $html);
 273  // Affichage de la page
 274      echo $html;
 275  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]