Subversion Repositories taios

Rev

Rev 496 | 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';
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
 
499 muzer 32
$page = new Taios_Page('Wiki &middot; ' . $pageName, '../');
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
{
432 tom 59
    write('<p class="bold"><a href="edit.php?page=' . $pageName . '">Edit Page</a></p><br />');
228 tom 60
}
61
 
486 muzer 62
$pageName = str_replace("../", "/", $pageName);
63
 
225 tom 64
$filename = 'pages/' . $pageName . '.txt';
65
 
230 tom 66
$fp = @fopen($filename, 'r');
221 tom 67
if ($fp)
68
{
226 tom 69
    write('<p>' . $page->replaceBBCode(fread($fp, filesize($filename))) . '</p>');
221 tom 70
    fclose($fp);
71
}
72
else
73
{
74
    write('<p>This page is empty.</p>');
75
}
76
 
486 muzer 77
if(is_dir('pages/' . $pageName))
78
{
79
    write('<p>Directory listing of ' . $pageName . ':</p>');
80
    write('<ul>');
81
    $dir = opendir('pages/' . $pageName);
82
    if($dir)
83
    {
84
        while (($file = readdir($dir)) !== false)
85
        {
86
            if($file != '.' && $file != '..' && (preg_match('/\.txt$/', $file) || is_dir('pages/' . $pageName . '/' . $file)))
87
            {
88
                $file = preg_replace('/\.txt$/', '', $file);
89
                write('<li><a href="index.php?page=' . $pageName . '/' . htmlspecialchars($file) . '">' . htmlspecialchars($file) . '</a></li>');
90
            }
91
        }
92
    }
93
    write('</ul>');
94
    write('<p>End of directory listing</p>');
95
}
96
 
169 tom 97
$page->drawFooter();
98
 
99
?>
100