home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / HTML / Menu / SigmaTreeRenderer.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  5.6 KB  |  167 lines

  1. <?php
  2. /**
  3.  * HTML_Template_Sigma-based renderer for 'tree' and 'sitemap' type menus,
  4.  * where menu level is represented by tag nesting.
  5.  * 
  6.  * PHP versions 4 and 5
  7.  *
  8.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  9.  * that is available through the world-wide-web at the following URI:
  10.  * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11.  * the PHP License and are unable to obtain it through the web, please
  12.  * send a note to license@php.net so we can mail you a copy immediately.
  13.  *
  14.  * @category    HTML
  15.  * @package     HTML_Menu
  16.  * @author      Alexey Borzov <avb@php.net>
  17.  * @copyright   2001-2007 The PHP Group
  18.  * @license     http://www.php.net/license/3_01.txt PHP License 3.01
  19.  * @version     CVS: $Id: SigmaTreeRenderer.php,v 1.3 2007/05/18 20:54:33 avb Exp $
  20.  * @link        http://pear.php.net/package/HTML_Menu
  21.  */
  22.  
  23. /**
  24.  * Abstract base class for HTML_Menu renderers
  25.  */ 
  26. require_once 'HTML/Menu/Renderer.php';
  27.  
  28. /**
  29.  * HTML_Template_Sigma-based renderer for 'tree' and 'sitemap' type menus,
  30.  * where menu level is represented by tag nesting.
  31.  *
  32.  * @category    HTML
  33.  * @package     HTML_Menu
  34.  * @author      Alexey Borzov <avb@php.net>
  35.  * @version     Release: 2.1.4
  36.  */
  37. class HTML_Menu_SigmaTreeRenderer extends HTML_Menu_Renderer
  38. {
  39.    /**#@+
  40.     * @access private
  41.     */
  42.    /**
  43.     * Template object used for output
  44.     * @var HTML_Template_Sigma
  45.     */
  46.     var $_tpl;
  47.  
  48.    /**
  49.     * Prefix for template blocks and placeholders
  50.     * @var string
  51.     */
  52.     var $_prefix;
  53.  
  54.    /**
  55.     *  
  56.     *
  57.     */
  58.     var $_level = -1;
  59.  
  60.    /**
  61.     * Mapping from HTML_MENU_ENTRY_* constants to template block names
  62.     * @var array
  63.     */
  64.     var $_typeNames = array(
  65.         HTML_MENU_ENTRY_INACTIVE    => 'inactive',
  66.         HTML_MENU_ENTRY_ACTIVE      => 'active',
  67.         HTML_MENU_ENTRY_ACTIVEPATH  => 'activepath'
  68.     );
  69.     /**#@-*/
  70.  
  71.    /**
  72.     * Class constructor.
  73.     * 
  74.     * Sets the template object to use and sets prefix for template blocks
  75.     * and placeholders. We use prefix to avoid name collisions with existing 
  76.     * template blocks and it is customisable to allow output of several menus 
  77.     * into one template.
  78.     *
  79.     * @access public
  80.     * @param  HTML_Template_Sigma   template object to use for output
  81.     * @param  string                prefix for template blocks and placeholders
  82.     */
  83.     function HTML_Menu_SigmaTreeRenderer(&$tpl, $prefix = 'mu_')
  84.     {
  85.         $this->_tpl    =& $tpl;
  86.         $this->_prefix =  $prefix;
  87.     }
  88.  
  89.  
  90.     function setMenuType($menuType)
  91.     {
  92.         if ('tree' == $menuType || 'sitemap' == $menuType) {
  93.             $this->_menuType = $menuType;
  94.         } else {
  95.             require_once 'PEAR.php';
  96.             return PEAR::raiseError("HTML_Menu_SigmaTreeRenderer: unable to render '$menuType' type menu");
  97.         }
  98.         $this->_level = -1;
  99.     }
  100.  
  101.  
  102.     function finishLevel($level)
  103.     {
  104.         // Close the previous entry
  105.         if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_close')) {
  106.             $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_close');
  107.         } else {
  108.             $this->_tpl->touchBlock($this->_prefix . 'entry_close');
  109.         }
  110.         $this->_tpl->parse($this->_prefix . 'tree_loop');
  111.         // Close the level
  112.         if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_level_close')) {
  113.             $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_level_close');
  114.         } else {
  115.             $this->_tpl->touchBlock($this->_prefix . 'level_close');
  116.         }
  117.         $this->_tpl->parse($this->_prefix . 'tree_loop');
  118.     }
  119.  
  120.  
  121.     function renderEntry($node, $level, $type)
  122.     {
  123.         // Close the entry if previous was on same or higher level
  124.         if ($this->_level >= $level) {
  125.             if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_close')) {
  126.                 $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_close');
  127.             } else {
  128.                 $this->_tpl->touchBlock($this->_prefix . 'entry_close');
  129.             }
  130.             $this->_tpl->parse($this->_prefix . 'tree_loop');
  131.  
  132.         // If the new level is higher then open the level
  133.         } else {
  134.             if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_level_open')) {
  135.                 $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_level_open');
  136.             } else {
  137.                 $this->_tpl->touchBlock($this->_prefix . 'level_open');
  138.             }
  139.             $this->_tpl->parse($this->_prefix . 'tree_loop');
  140.         }
  141.         // Open the entry
  142.         if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_open')) {
  143.             $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_open');
  144.         } else {
  145.             $this->_tpl->touchBlock($this->_prefix . 'entry_open');
  146.         }
  147.         $this->_tpl->parse($this->_prefix . 'tree_loop');
  148.  
  149.         if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_' . $this->_typeNames[$type])) {
  150.             $blockName = $this->_prefix . ($level + 1) . '_' . $this->_typeNames[$type];
  151.         } else {
  152.             $blockName = $this->_prefix . $this->_typeNames[$type];
  153.         }
  154.  
  155.         foreach ($node as $k => $v) {
  156.             if ('sub' != $k && $this->_tpl->placeholderExists($this->_prefix . $k, $blockName)) {
  157.                 $this->_tpl->setVariable($this->_prefix . $k, $v);
  158.             }
  159.         }
  160.         $this->_tpl->parse($blockName);
  161.         $this->_tpl->parse($this->_prefix . 'tree_loop');
  162.  
  163.         $this->_level = $level;
  164.     }
  165. }
  166. ?>
  167.