PHP » Quellcode betrachten

Download

<?php
/* xml_extension class
 * (C) 2006 Julian von Mendel (http://derjulian.net)
 * License: LGPL
 */

class xml_hyperlink 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;
        }

        
$parse      $this->xml->parseNode($this->nodeTrueTrueTrue, array("extern""page""anchor""blank""class"));
        
$attributes $parse["attributes_array"];

        if (
$attributes["page"] != "")
        {
            
$url $this->xml->getDataItem("hyperlink_url");
            if (
$url == "")
            {
                
$page $attributes["page"];
            }
            else
            {
                
$page str_replace("%s"$attributes["page"], $url);
            }
            
$extern False;
        }
        else
        {
            
$page $attributes["extern"];
            
$extern True;
        }

        if (
$attributes["anchor"] != "")
        {
            
$anchor "#".$attributes["anchor"];
        }
        else
        {
            
$anchor "";
        }

        if (
$parse["content_string"] == "")
        {
            
            
$content xml::mask(($this->xml->getDataItem("hyperlink_title")) ? call_user_func($this->xml->getDataItem("hyperlink_title"), $attributes["page"], $extern) : "no title.");
        }
        else
        {
            
$content $parse["content_string"];
        }

        
$exists = ($extern || !$this->xml->getDataItem("hyperlink_exists")) ? True call_user_func($this->xml->getDataItem("hyperlink_exists"), $attributes["page"]);
        
$blank = ($attributes["blank"] == "force" || $attributes["blank"] == "blank" && $this->xml->getDataItem("hyperlink_blank"));

        
$classes = array();
        if (
$attributes["class"] != "")
            
$classes[] = $attributes["class"];
        if (
$blank)
            
$classes[] = "blank";
        if (!
$exists)
            
$classes[] = "error404";
        if (
$extern)
            
$classes[] = "extern";

        return 
call_user_func(array($this$returntype), $page.$anchor$content$classes$parse["attributes_string"]);
    }

    private function 
xhtml($url$content$classes$attributes)
    {
        if (
in_array("blank"$classes))
            
$blank " target=\"_blank\"";
        else
            
$blank "";
        
$classes implode(" "$classes);
        if (
$classes != "")
            
$classes " class=\"".$classes."\"";
        return 
"<a href=\"".xml::mask_xml($url)."\"".$classes.$attributes."".$blank.">".$content."</a>";
    }
}
?>

© 2009 Julian von Mendel (http://derjulian.net) | Datum: 26.04.2024