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 / ArrayRenderer.php next >
Encoding:
PHP Script  |  2008-07-02  |  3.0 KB  |  115 lines

  1. <?php
  2. /**
  3.  * The renderer that creates an array of visible menu entries.
  4.  * 
  5.  * PHP versions 4 and 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.01 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_01.txt If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @category    HTML
  14.  * @package     HTML_Menu
  15.  * @author      Alexey Borzov <avb@php.net>
  16.  * @copyright   2001-2007 The PHP Group
  17.  * @license     http://www.php.net/license/3_01.txt PHP License 3.01
  18.  * @version     CVS: $Id: ArrayRenderer.php,v 1.3 2007/05/18 20:54:33 avb Exp $
  19.  * @link        http://pear.php.net/package/HTML_Menu
  20.  */
  21.  
  22. /**
  23.  * Abstract base class for HTML_Menu renderers
  24.  */ 
  25. require_once 'HTML/Menu/Renderer.php';
  26.  
  27. /**
  28.  * The renderer that creates an array of visible menu entries.
  29.  * 
  30.  * The resultant array can be used with e.g. a template engine to produce
  31.  * a completely custom menu look.
  32.  * All menu types except 'rows' are "rendered" into a one-dimensional array
  33.  * of entries:
  34.  * <pre>
  35.  * array(
  36.  *    'entry1',
  37.  *    ...
  38.  *    'entryN'
  39.  * )
  40.  * </pre>
  41.  * while 'rows' produce a two-dimensional array:
  42.  * <pre>
  43.  * array(
  44.  *    array('entry 1 for row 1', ..., 'entry M_1 for row 1'),
  45.  *    ...
  46.  *    array('entry 1 for row N', ..., 'entry M_N for row 1')
  47.  * )
  48.  * </pre>
  49.  * Here entry is
  50.  * <pre> 
  51.  * array(
  52.  *    'url'    => url element of menu entry
  53.  *    'title'  => title element of menu entry
  54.  *    'level'  => entry's depth in the tree structure
  55.  *    'type'   => type of entry, one of HTML_MENU_ENTRY_* constants
  56.  *    // if the nodes in the original menu array contained keys other
  57.  *    // than 'url', 'title' and 'sub', they will be copied here, too
  58.  * )
  59.  * </pre>
  60.  * 
  61.  * @category    HTML
  62.  * @package     HTML_Menu
  63.  * @author      Alexey Borzov <avb@php.net>
  64.  * @version     Release: 2.1.4
  65.  */
  66. class HTML_Menu_ArrayRenderer extends HTML_Menu_Renderer
  67. {
  68.    /**
  69.     * Generated array
  70.     * @var array
  71.     * @access private
  72.     */
  73.     var $_ary = array();
  74.  
  75.    /**
  76.     * Array for the current "menu", that is moved into $_ary by finishMenu(), 
  77.     * makes sense mostly for 'rows
  78.     * @var array
  79.     * @access private
  80.     */
  81.     var $_menuAry = array();
  82.  
  83.     function finishMenu($level)
  84.     {
  85.         if ('rows' == $this->_menuType) {
  86.             $this->_ary[] = $this->_menuAry;
  87.         } else {
  88.             $this->_ary   = $this->_menuAry;
  89.         }
  90.         $this->_menuAry = array();
  91.     }
  92.  
  93.  
  94.     function renderEntry($node, $level, $type)
  95.     {
  96.         unset($node['sub']);
  97.         $node['level'] = $level;
  98.         $node['type']  = $type;
  99.         $this->_menuAry[] = $node;
  100.     }
  101.  
  102.  
  103.    /**
  104.     * Returns the resultant array
  105.     * 
  106.     * @access public
  107.     * @return array
  108.     */
  109.     function toArray()
  110.     {
  111.         return $this->_ary;
  112.     }
  113. }
  114. ?>
  115.