Last update: 31.03.2008 | © 2023 Julian von Mendel | Datenschutz
<?php
/* xml_extension class
* (C) 2006 Julian von Mendel (http://derjulian.net)
* License: LGPL
*/
class xml_toc implements xml_widget
{
public $node;
public $xml ;
function __construct($node, $xml)
{
$this->node = $node;
$this->xml = $xml ;
}
public static function dtd()
{
return <<<DTD
DTD;
}
public function output($returntype = "xhtml")
{
if (!method_exists($this, $returntype))
{
return False;
}
return $this->xml->addReplacement(array($this, $returntype));
}
public function xhtml($toc)
{
$toc = $this->xml->getDataItem("headlines");
if (!is_array($toc["anchor-title"])) return "";
$ret = "<ul>";
$open = 1;
foreach($toc["anchor-title"] as $key => $headline)
{
$ret .= "<li><a href=\"#".$headline["anchor"]."\">".$headline["content"]."</a>";
if (isset($toc["anchor-title"][$key+1]["level"]))
{
if ($toc["anchor-title"][$key+1]["level"] > $headline["level"])
{
$open++;
$ret .= "<ul>";
}
else if ($toc["anchor-title"][$key+1]["level"] < $headline["level"])
{
$open--;
$ret .= "</li></ul></li>";
}
else
{
$ret .= "</li>";
}
}
}
for($i = 0; $i <= $open; $i++)
{
$open--;
$ret .= "</li></ul>";
}
return $ret;
}
}
?>
© 2009 Julian von Mendel (http://derjulian.net) | Datum: 07.12.2023