<?php
/**
 * Implementation of anchor helper
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * Helper for a generating a "a href" element
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class HomeWebApp_View_Helper_Anchor extends Zend_View_Helper_FormElement
{
    /**
     * Generates a 'a href' element.
     * 
     * @param string $href the URL target
     * @param string $linkname a hyperlinked text, which is seen as link
     * @param array $attribs hash with other attributes for the element tag
     * @return string The element XHTML
     */ 
    public function anchor($href,$linkName,$attribs = null)
    {
        $info = $this->_getInfo($href,$linkName,$attribs);
        extract($info); // href, linkname, attribs 

        // make sure attribs don't overwrite href
        unset($attribs['href']);

        //begin of anchor
        $xhtml = '<a'
            . ' href="' . htmlspecialchars($href, ENT_COMPAT, 'UTF-8') . '"';
        //add attributes and close
        $xhtml .= $this->_htmlAttribs($attribs).'>';            
        //add linkname
        $xhtml .= $linkName."</a>";

        return $xhtml;
    }

}

