PHP » Quellcode betrachten

Download

<?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: 27.05.2022