Rev 432 | Rev 499 | 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 | |||
486 | muzer | 48 | $pageName = str_replace("../", "/", $pageName); |
49 | |||
225 | tom | 50 | $filename = 'pages/' . $pageName . '.txt'; |
51 | |||
230 | tom | 52 | $fp = @fopen($filename, 'r'); |
221 | tom | 53 | if ($fp) |
54 | { |
||
226 | tom | 55 | write('<p>' . $page->replaceBBCode(fread($fp, filesize($filename))) . '</p>'); |
221 | tom | 56 | fclose($fp); |
57 | } |
||
58 | else |
||
59 | { |
||
60 | write('<p>This page is empty.</p>'); |
||
61 | } |
||
62 | |||
486 | muzer | 63 | if(is_dir('pages/' . $pageName)) |
64 | { |
||
65 | write('<p>Directory listing of ' . $pageName . ':</p>'); |
||
66 | write('<ul>'); |
||
67 | $dir = opendir('pages/' . $pageName); |
||
68 | if($dir) |
||
69 | { |
||
70 | while (($file = readdir($dir)) !== false) |
||
71 | { |
||
72 | if($file != '.' && $file != '..' && (preg_match('/\.txt$/', $file) || is_dir('pages/' . $pageName . '/' . $file))) |
||
73 | { |
||
74 | $file = preg_replace('/\.txt$/', '', $file); |
||
75 | write('<li><a href="index.php?page=' . $pageName . '/' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</a></li>'); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | write('</ul>'); |
||
80 | write('<p>End of directory listing</p>'); |
||
81 | } |
||
82 | |||
169 | tom | 83 | $page->drawFooter(); |
84 | |||
85 | ?> |
||
86 |