Subversion Repositories taios

Rev

Rev 499 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

function endswith($string, $test) {
    $strlen = strlen($string);
    $testlen = strlen($test);
    if ($testlen > $strlen) return false;
    return substr_compare($string, $test, -$testlen) === 0;
}

require '../_taios.php';
if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}
$pageName = $_GET['page'];
if (empty($pageName))
{
    $pageName = 'Index';
}

$page = new Taios_Page('Wiki &middot; ' . htmlentities($pageName, ENT_QUOTES), '../');

if (isset($_GET['random']))
{
    $results = array();
    $handler = opendir('pages/');
    while ($file = readdir($handler))
    {
        if ($file != '.' && $file != '..' && endswith($file, ".txt"))
        {
            $results[] = substr($file, 0, count($file) - 5);
        }
    }
   
    $index = rand() % count($results);
    $result = $results[$index];
    $page->redirect('index.php?page=' . $result);    
}

$page->drawHeader();
write('<h3>Wiki</h3>');
$page->drawMenuItem('Index', 'wiki/index.php');
$page->drawMenuItem('Random Page', 'wiki/index.php?random');
$page->drawMiddle();

if ($page->isUserGM($page->getLoggedInUser()))
{
    write('<p class="bold"><a href="edit.php?page=' . htmlentities($pageName, ENT_QUOTES) . '">Edit Page</a></p><br />');
}

while (strpos($pageName, '../') !== false) {
    $pageName = str_replace("../", "/", $pageName);
}

$filename = 'pages/' . $pageName . '.txt';

$fp = @fopen($filename, 'r');
if ($fp)
{
    write('<p>' . $page->replaceBBCode(fread($fp, filesize($filename))) . '</p>');
    fclose($fp);
}
else
{
    write('<p>This page is empty.</p>');
}

if(is_dir('pages/' . $pageName))
{
    write('<p>Directory listing of ' . htmlentities($pageName, ENT_QUOTES) . ':</p>');
    write('<ul>');
    $dir = opendir('pages/' . $pageName);
    if($dir)
    {
        while (($file = readdir($dir)) !== false)
        {
            if($file != '.' && $file != '..' && (preg_match('/\.txt$/', $file) || is_dir('pages/' . $pageName . '/' . $file)))
            {
                $file = preg_replace('/\.txt$/', '', $file);
                write('<li><a href="index.php?page=' . htmlentities($pageName, ENT_QUOTES) . '/' . htmlentities($file, ENT_QUOTES) . '">' . htmlentities($file, ENT_QUOTES) . '</a></li>');
            }
        }
    }
    write('</ul>');
    write('<p>End of directory listing</p>');
}

$page->drawFooter();

?>