Rev 368 | Rev 486 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
169 | tom | 1 | <?php |
2 | |||
365 | tom | 3 | function endswith($string, $test) { |
4 | $strlen = strlen($string); |
||
5 | $testlen = strlen($test); |
||
6 | if ($testlen > $strlen) return false; |
||
7 | return substr_compare($string, $test, -$testlen) === 0; |
||
8 | } |
||
9 | |||
169 | tom | 10 | require '../_taios.php'; |
11 | |||
224 | tom | 12 | $pageName = $_GET['page']; |
225 | tom | 13 | if (empty($pageName)) |
221 | tom | 14 | { |
224 | tom | 15 | $pageName = 'Index'; |
221 | tom | 16 | } |
169 | tom | 17 | |
227 | tom | 18 | $page = new Taios_Page('Wiki - ' . $pageName, '../'); |
365 | tom | 19 | |
20 | if (isset($_GET['random'])) |
||
21 | { |
||
22 | $results = array(); |
||
366 | tom | 23 | $handler = opendir('pages/'); |
365 | tom | 24 | while ($file = readdir($handler)) |
25 | { |
||
26 | if ($file != '.' && $file != '..' && endswith($file, ".txt")) |
||
27 | { |
||
367 | tom | 28 | $results[] = substr($file, 0, count($file) - 5); |
365 | tom | 29 | } |
30 | } |
||
31 | |||
32 | $index = rand() % count($results); |
||
33 | $result = $results[$index]; |
||
34 | $page->redirect('index.php?page=' . $result); |
||
35 | } |
||
36 | |||
227 | tom | 37 | $page->drawHeader(); |
361 | tom | 38 | write('<h3>Wiki</h3>'); |
364 | tom | 39 | $page->drawMenuItem('Index', 'wiki/index.php'); |
40 | $page->drawMenuItem('Random Page', 'wiki/index.php?random'); |
||
227 | tom | 41 | $page->drawMiddle(); |
42 | |||
228 | tom | 43 | if ($page->isUserGM($page->getLoggedInUser())) |
44 | { |
||
432 | tom | 45 | write('<p class="bold"><a href="edit.php?page=' . $pageName . '">Edit Page</a></p><br />'); |
228 | tom | 46 | } |
47 | |||
225 | tom | 48 | $filename = 'pages/' . $pageName . '.txt'; |
49 | |||
230 | tom | 50 | $fp = @fopen($filename, 'r'); |
221 | tom | 51 | if ($fp) |
52 | { |
||
226 | tom | 53 | write('<p>' . $page->replaceBBCode(fread($fp, filesize($filename))) . '</p>'); |
221 | tom | 54 | fclose($fp); |
55 | } |
||
56 | else |
||
57 | { |
||
58 | write('<p>This page is empty.</p>'); |
||
59 | } |
||
60 | |||
169 | tom | 61 | $page->drawFooter(); |
62 | |||
63 | ?> |
||
64 |