HTML_Menu
[ class tree: HTML_Menu ] [ index: HTML_Menu ] [ all elements ]

Source for file SigmaTreeRenderer.php

Documentation is available at SigmaTreeRenderer.php

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

Documentation generated on Mon, 11 Mar 2019 14:46:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.