1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| <?php
/*
roWiki
Author: Marc Rohlfing <rowiki@rowlff.de>
Version: 1.05 (2005-06-04)
Home/Docs/Licensing: www.rowlff.de/rowiki/
*/
// Configuration and language variables. Set these to your values:
$WIKI_TITLE = "roWiki";
$START_PAGE = "Accueil";
$HOME_BUTTON = "Accueil";
$HELP_BUTTON = "Aide";
$EDIT_BUTTON = "Edit Page";
$DEFAULT_CONTENT = "This is an empty page";
$DONE_BUTTON = "Done";
$PROTECTED_BUTTON = "Locked Page";
$SEARCH_BUTTON = "Search";
$SEARCH_RESULTS = "Search results for";
$NEW_PAGE = "New Page";
$RECENT_CHANGES = "Recent Changes";
$LAST_CHANGE = "Last change:";
$TIME_FORMAT = "%m/%d/%y %R";
$PAGES_DIR = "pages/";
$BACKUP_DIR = "history/";
$CONTENT = "";
$PAGE_ISSET = isset($_GET['page']) ? $_GET['page'] : '';
$ACTION_ISSET = isset($_GET['action']) ? $_GET['action'] : '';
$QUERY_ISSET = isset($_GET['query']) ? $_GET['query'] : '';
// Determine page to display
if (! $PAGE_TITLE = $PAGE_ISSET) {
if ($ACTION_ISSET == "search")
$PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\"";
elseif ($ACTION_ISSET == "recent")
$PAGE_TITLE = "$RECENT_CHANGES";
else
$PAGE_TITLE = "$START_PAGE";
}
// Catch malicious paths
if (preg_match("/\//", $PAGE_TITLE))
$PAGE_TITLE = $START_PAGE;
// Write changes to page, if there are any
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (! $file = @fopen($PAGES_DIR . stripslashes($_POST["page"]) . ".txt", "w"))
die("Could not write page!");
if (get_magic_quotes_gpc())
fputs($file, trim(stripslashes($_POST["content"])));
else
fputs($file, trim($_POST["content"]));
fclose($file);
if ($BACKUP_DIR <> '') {
if (! $file = @fopen($BACKUP_DIR . $_POST["page"] . ".bak", "a"))
die("Could not write backup of page!");
fputs($file, "\n\n\n--------------------\n" . strftime("$TIME_FORMAT", time()) . " / " . $_SERVER['REMOTE_ADDR'] . "\n--------------------\n");
if (get_magic_quotes_gpc())
fputs($file, trim(stripslashes($_POST["content"])));
else
fputs($file, trim($_POST["content"]));
fclose($file);
}
header("location: index.php?page=" . urlencode(stripslashes($_POST[page])));
}
// Read and parse template
if (! $file = @fopen("Template.html", "r"))
die("'Template.html' is missing!");
$template = fread($file, filesize("Template.html"));
fclose($file);
// Read page contents and time of last change
if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $ACTION_ISSET <> "") {
$TIME = strftime("$TIME_FORMAT", @filemtime($PAGES_DIR . $PAGE_TITLE . ".txt"));
$CONTENT = "\n" . @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")) . "\n";
@fclose($file);
$CONTENT = preg_replace("/\\$/Umsi", "$", $CONTENT);
$CONTENT = preg_replace("/\\\/Umsi", "\", $CONTENT);
}
else {
$ACTION_ISSET = "edit";
$TIME = "$NEW_PAGE";
}
// Determine access mode
if ($ACTION_ISSET == "edit" || $ACTION_ISSET <> "")
$html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template);
elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt"))
$html = preg_replace('/{EDIT}/', "<a href=\"index.php?page=$PAGE_TITLE&action=edit\">$EDIT_BUTTON</a>", $template);
else
$html = preg_replace('/{EDIT}/', "$PROTECTED_BUTTON", $template);
if ($ACTION_ISSET == "recent")
$html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html);
else
$html = preg_replace('/{RECENT_CHANGES}/', "<a href=\"index.php?action=recent\">$RECENT_CHANGES</a>", $html);
// Put values into template
$html = preg_replace('/{PAGE_TITLE}/', "$PAGE_TITLE", $html);
if ($PAGE_TITLE == $START_PAGE && $ACTION_ISSET <> "search")
$html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html);
else
$html = preg_replace('/{HOME}/', "<a href=\"index.php\">$HOME_BUTTON</a>", $html);
$html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html);
$html = preg_replace('/{LAST_CHANGE}/', $LAST_CHANGE, $html);
if ($PAGE_TITLE == $HELP_BUTTON)
$html = preg_replace('/{HELP}/', "$HELP_BUTTON", $html);
else
$html = preg_replace('/{HELP}/', "<a href=\"index.php?page=$HELP_BUTTON\">$HELP_BUTTON</a>", $html);
$html = preg_replace('/{SEARCH}/', "<form method=\"get\" action=\"index.php\"><input type=\"hidden\" name=\"action\" value=\"search\" /><input type=\"text\" name=\"query\" value=\"$QUERY_ISSET\" /> <input type=\"submit\" value=\"$SEARCH_BUTTON\" /></form>", $html);
if ($ACTION_ISSET == "edit") {
if ($CONTENT == '')
$CONTENT = $DEFAULT_CONTENT;
$CONTENT = "<form method=\"post\" action=\"index.php\"><textarea name=\"content\" cols=\"90\" rows=\"30\">$CONTENT</textarea><input type=\"hidden\" name=\"page\" value=\"$PAGE_TITLE\" /><br /><input type=\"submit\" value=\"$DONE_BUTTON\" accesskey=\"s\" /></form>";
}
// Search pages
if ($ACTION_ISSET == "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 .= "<p><a href=\"index.php?page=$file\">$file</a></p>";
}
}
}
$TIME = "-";
}
// Recent changes
elseif ($ACTION_ISSET == "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 .= "<p><a href=\"index.php?page=$filename\">$filename</a> (" . strftime("$TIME_FORMAT", $timestamp) . ")</p>";
}
$TIME = "-";
}
// Prepare page formatting
elseif ($ACTION_ISSET <> "edit") {
$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('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&,\+]*)\]#U', '<a href="xx$2" class="url">$1</a>', $CONTENT);
$CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
$CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&\#\:/~\-_%=?]*)#i', '<a href="$0" class="url">$1</a>', $CONTENT);
$CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
// preg_match_all("/\[([0-9a-zA-Z\- :\.,\(\)\']+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
preg_match_all("/\[([^\/]+)\]/U", $CONTENT, $matches, PREG_PATTERN_ORDER);
foreach ($matches[1] as $match)
if (file_exists("$PAGES_DIR/$match.txt"))
$CONTENT = str_replace("[$match]", "<a href=\"index.php?page=$match\">$match</a>", $CONTENT);
else
$CONTENT = str_replace("[$match]", "<a class=\"pending\" href=\"index.php?page=$match\">$match</a>", $CONTENT);
$CONTENT = preg_replace('#([0-9a-zA-Z\./~\-_]+@[0-9a-z\./~\-_]+)#i', '<a href="mailto:$0">$0</a>', $CONTENT);
$CONTENT = preg_replace('/^\*\*\*(.*)(\n)/Um', "<ul><ul><ul><li>$1</li></ul></ul></ul>$2", $CONTENT);
$CONTENT = preg_replace('/^\*\*(.*)(\n)/Um', "<ul><ul><li>$1</li></ul></ul>$2", $CONTENT);
$CONTENT = preg_replace('/^\*(.*)(\n)/Um', "<ul><li>$1</li></ul>$2", $CONTENT);
$CONTENT = preg_replace('/^\#\#\#(.*)(\n)/Um', "<ol><ol><ol><li>$1</li></ol></ol></ol>$2", $CONTENT);
$CONTENT = preg_replace('/^\#\#(.*)(\n)/Um', "<ol><ol><li>$1</li></ol></ol>$2", $CONTENT);
$CONTENT = preg_replace('/^\#(.*)(\n)/Um', "<ol><li>$1</li></ol>$2", $CONTENT);
$CONTENT = preg_replace('/(<\/ol>\n*<ol>|<\/ul>\n*<ul>)/', "", $CONTENT);
$CONTENT = preg_replace('/^!!!(.*)(\n)/Um', '<h1>$1</h1>$2', $CONTENT);
$CONTENT = preg_replace('/^!!(.*)(\n)/Um', '<h2>$1</h2>$2', $CONTENT);
$CONTENT = preg_replace('/^!(.*)(\n)/Um', '<h3>$1</h3>$2', $CONTENT);
while (preg_match('/^ /Um', $CONTENT))
$CONTENT = preg_replace('/^( +) ([^ ])/Um', '$1 $2', $CONTENT);
$CONTENT = preg_replace('/^ /Um', ' ', $CONTENT);
$CONTENT = preg_replace('/----(\r\n|\r|\n)/m', '<hr />', $CONTENT);
$CONTENT = preg_replace('/\n/', '<br />', $CONTENT);
$CONTENT = preg_replace('#</ul>(<br />)*#', "</ul>", $CONTENT);
$CONTENT = preg_replace('#</ol>(<br />)*#', "</ol>", $CONTENT);
$CONTENT = preg_replace('#(</h[123]>)<br />#', "$1", $CONTENT);
$CONTENT = preg_replace("/{(.+)}/Ue", "'<code><pre>' . preg_replace('#<br />#', '', '\\1') . '</pre></code>'", $CONTENT);
$CONTENT = preg_replace("/'''(.*)'''/Um", '<b>$1</b>', $CONTENT);
$CONTENT = preg_replace("/''(.*)''/Um", '<i>$1</i>', $CONTENT);
$CONTENT = substr($CONTENT, 6, strlen($CONTENT) - 6);
}
// Print page
$html = preg_replace("/{CONTENT}/", "$CONTENT", $html);
$html = preg_replace('/{TIME}/', $TIME, $html);
echo $html;
?> |
Partager