<?php

class Plugin_ls extends Plugin
{
	function do_block($pagename, $param1, $param2)
	{
		$prefix = resolvepath(trim($param1));
		if($prefix == ''){
			$prefix = $pagename;
		}
		$prefix .= '/';
		
		$db = DataBase::getinstance();
		$query  = "SELECT pagename FROM page";
		$query .= " WHERE (pagename like '${prefix}%' AND pagename not like '%/:%')";
		$query .= " ORDER BY pagename ASC";
		$result = $db->query($query);
		
		$len = strlen($prefix);
		$list = array();
		while($row = $db->fetch($result)){
			$link = makelink($row['pagename'], substr($row['pagename'], $len));
			$list[] = '<li>' . $link . '</li>';
		}
		
		return "<ul>\n" . join("\n", $list) . "\n</ul>\n";
	}
}

?>