Location: PHPKode > projects > PHP SiteBuilder > include/class.XML_Menu.php
<?php
/*
 * +--------------------------------------------------------------------------+
 * |                                                                          |
 * |  Class XML_Menu definition                                               |
 * |                                                                          |
 * +--------------------------------------------------------------------------+
 * | Copyright (c) 2001, Tobias H. Michaelsen <hide@address.com>                  |
 * +--------------------------------------------------------------------------+
 *
 *	$Id: class.XML_Menu.php,v 1.8 2001/10/21 15:10:07 zaiborg Exp $
 */

require_once("XML/Parser.php");

/**
* Class for accessing XML-Menu data.
*
* @link      http://www.w3.org/TR/xml W3C XML Recommendation
* @copyright Copyright (c) 2001 Tobias H. Michaelsen. All rights reserved.
* @author    Tobias H. Michaelsen <hide@address.com>
* @version   1.0 (2001-06-13)
* @access    public
*/
class XML_Menu extends XML_Parser
{
	/**
	 * @var  boolean  Whether to do case folding
	 */
	var $folding = 0;

	/**
	 * Mapping from expat handler function to class method.
	 *
	 * @var  array
	 */
	var $handler = array(
		"character_data_handler"            => "cdataHandler"
	);

	/**
	* Constructor funtion; load file and parse...
	*
	* @param	string	$filename	Name of XML file containing menu structure.
	*/
	function XML_Menu($filename) {
		$this->XML_Parser(); // call parent constructor
		$this->setInputFile($filename);
		$this->parse();
	}

    /**
    * Handles opening XML tags while parsing.
    *
    * While parsing a XML document for each opening tag this method is
    * called.
    *
    * @access  private
    * @author  Tobias H. Michaelsen <hide@address.com>
    * @param   int     $parser      Handler for accessing the current XML parser.
    * @param   string  $name        Name of the opening tag found in the document.
    * @param   array   $attributes  Associative array containing a list of all
    *                               attributes of the tag found in the document.
    * @see     endHandler(), cdataHandler()
    */
    function startHandler($parser, $name, $attributes)
    {
        switch ($name) {
        	case "menu":
        		$this->html = '<div class="menu">';
        		break;
        	case "section":
        		$this->html .= '<div class="menu-section">';
        		break;
        	case "title":
        		$this->html .= '<b>';
        		# Notice: The attribute 'href' is #IMPLIED
        		if (is_array($attributes) and isset($attributes['href'])) {
        			$this->html .= '<a href="'.htmlspecialchars($attributes['href']).'">';
				} else {
					$this->html .= '<a>';
				}
        		break;
        	case "items":
        		$this->html .= '<ul>';
        		break;
        	case "item":
        		# Notice: The attribute 'href' is #REQUIRED
        		$this->html .= '<li><a href="'.htmlspecialchars($attributes['href']).'">';
        		break;
        	default:
        		break;
        }
    }

    /**
    * Handles closing XML tags while parsing.
    *
    * While parsing a XML document for each closing tag this method is
    * called.
    *
    * @access    private
    * @author    Michael P. Mehl <hide@address.com>
    * @edited    Tobias H. Michaelsen <hide@address.com>
    * @param     int $parser Handler for accessing the current XML parser.
    * @param     string $name Name of the closing tag found in the document.
    * @see       startHandler(), cdataHandler()
    */
    function endHandler($parser, $name)
    {
		switch ($name) {
			case "item":
				$this->html .= '</a></li>';
				break;
			case "items":
				$this->html .= '</ul>';
				break;
			case "title":
				$this->html .= '</a></b>';
				break;
			case "section":
				$this->html .= '</div>';
				break;
			case "menu":
				$this->html .= '</div>';
				break;
			default:
				break;
		}
    }

    /**
    * Handles character data while parsing.
    *
    * While parsing a XML document for each character data this method
    * is called.
    *
    * @access  private
    * @author  Tobias H. Michaelsen <hide@address.com>
    * @param   int     $parser  Handler for accessing the current XML parser.
    * @param   string  $text    Character data found in the document.
    * @see     handle_start_element(), handle_end_element()
    */
    function cdataHandler($parser, $text)
    {
        $this->html .= $text;
    }

	/**
	 * Free the xml parser.
	 */
	function free()
	{
		xml_parser_free($this->parser);
	}

}

?>
Return current item: PHP SiteBuilder