Subversion Repositories taios

Rev

Rev 499 | 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';
496 muzer 11
if (get_magic_quotes_gpc()) {
12
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
13
    while (list($key, $val) = each($process)) {
14
        foreach ($val as $k => $v) {
15
            unset($process[$key][$k]);
16
            if (is_array($v)) {
17
                $process[$key][stripslashes($k)] = $v;
18
                $process[] = &$process[$key][stripslashes($k)];
19
            } else {
20
                $process[$key][stripslashes($k)] = stripslashes($v);
21
            }
22
        }
23
    }
24
    unset($process);
25
}
224 tom 26
$pageName = $_GET['page'];
225 tom 27
if (empty($pageName))
221 tom 28
{
224 tom 29
    $pageName = 'Index';
221 tom 30
}
169 tom 31
 
522 muzer 32
$page = new Taios_Page('Wiki &middot; ' . htmlentities($pageName, ENT_QUOTES), '../');
365 tom 33
 
34
if (isset($_GET['random']))
35
{
36
    $results = array();
366 tom 37
    $handler = opendir('pages/');
365 tom 38
    while ($file = readdir($handler))
39
    {
40
        if ($file != '.' && $file != '..' && endswith($file, ".txt"))
41
        {
367 tom 42
            $results[] = substr($file, 0, count($file) - 5);
365 tom 43
        }
44
    }
45
 
46
    $index = rand() % count($results);
47
    $result = $results[$index];
48
    $page->redirect('index.php?page=' . $result);    
49
}
50
 
227 tom 51
$page->drawHeader();
361 tom 52
write('<h3>Wiki</h3>');
364 tom 53
$page->drawMenuItem('Index', 'wiki/index.php');
54
$page->drawMenuItem('Random Page', 'wiki/index.php?random');
227 tom 55
$page->drawMiddle();
56
 
228 tom 57
if ($page->isUserGM($page->getLoggedInUser()))
58
{
522 muzer 59
    write('<p class="bold"><a href="edit.php?page=' . htmlentities($pageName, ENT_QUOTES) . '">Edit Page</a></p><br />');
228 tom 60
}
61
 
522 muzer 62
while (strpos($pageName, '../') !== false) {
63
    $pageName = str_replace("../", "/", $pageName);
64
}
486 muzer 65
 
225 tom 66
$filename = 'pages/' . $pageName . '.txt';
67
 
230 tom 68
$fp = @fopen($filename, 'r');
221 tom 69
if ($fp)
70
{
226 tom 71
    write('<p>' . $page->replaceBBCode(fread($fp, filesize($filename))) . '</p>');
221 tom 72
    fclose($fp);
73
}
74
else
75
{
76
    write('<p>This page is empty.</p>');
77
}
78
 
486 muzer 79
if(is_dir('pages/' . $pageName))
80
{
522 muzer 81
    write('<p>Directory listing of ' . htmlentities($pageName, ENT_QUOTES) . ':</p>');
486 muzer 82
    write('<ul>');
83
    $dir = opendir('pages/' . $pageName);
84
    if($dir)
85
    {
86
        while (($file = readdir($dir)) !== false)
87
        {
88
            if($file != '.' && $file != '..' && (preg_match('/\.txt$/', $file) || is_dir('pages/' . $pageName . '/' . $file)))
89
            {
90
                $file = preg_replace('/\.txt$/', '', $file);
522 muzer 91
                write('<li><a href="index.php?page=' . htmlentities($pageName, ENT_QUOTES) . '/' . htmlentities($file, ENT_QUOTES) . '">' . htmlentities($file, ENT_QUOTES) . '</a></li>');
486 muzer 92
            }
93
        }
94
    }
95
    write('</ul>');
96
    write('<p>End of directory listing</p>');
97
}
98
 
169 tom 99
$page->drawFooter();
100
 
101
?>
102