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 / DirectRenderer.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  5.6 KB  |  186 lines

  1. <?php
  2. /**
  3.  * The renderer that generates HTML for the menu all by itself.
  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      Ulf Wendel <ulf.wendel@phpdoc.de>
  16.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  17.  * @author      Alexey Borzov <avb@php.net>
  18.  * @copyright   2001-2007 The PHP Group
  19.  * @license     http://www.php.net/license/3_01.txt PHP License 3.01
  20.  * @version     CVS: $Id: DirectRenderer.php,v 1.5 2007/05/18 20:54:33 avb Exp $
  21.  * @link        http://pear.php.net/package/HTML_Menu
  22.  */
  23.  
  24. /**
  25.  * Abstract base class for HTML_Menu renderers
  26.  */ 
  27. require_once 'HTML/Menu/Renderer.php';
  28.  
  29. /**
  30.  * The renderer that generates HTML for the menu all by itself.
  31.  * 
  32.  * Inspired by HTML_Menu 1.0 code
  33.  * 
  34.  * @category    HTML
  35.  * @package     HTML_Menu
  36.  * @author      Ulf Wendel <ulf.wendel@phpdoc.de>
  37.  * @author      Alexey Borzov <avb@php.net>
  38.  * @version     Release: 2.1.4
  39.  */
  40. class HTML_Menu_DirectRenderer extends HTML_Menu_Renderer
  41. {
  42.    /**#@+
  43.     * @access private
  44.     */
  45.    /**
  46.     * Generated HTML for the menu
  47.     * @var string
  48.     */
  49.     var $_html = '';
  50.  
  51.    /**
  52.     * Generated HTML for the current menu "table"
  53.     * @var string
  54.     */
  55.     var $_tableHtml = '';
  56.     
  57.    /**
  58.     * Generated HTML for the current menu "row"
  59.     * @var string
  60.     */
  61.     var $_rowHtml = '';
  62.  
  63.    /**
  64.     * The HTML that will wrap around menu "table"
  65.     * @see setMenuTemplate()
  66.     * @var array
  67.     */
  68.     var $_menuTemplate = array('<table border="1">', '</table>');
  69.  
  70.    /**
  71.     * The HTML that will wrap around menu "row"
  72.     * @see setRowTemplate()
  73.     * @var array
  74.     */
  75.     var $_rowTemplate = array('<tr>', '</tr>');
  76.  
  77.    /**
  78.     * Templates for menu entries
  79.     * @see setEntryTemplate()
  80.     * @var array
  81.     */
  82.     var $_entryTemplates = array(
  83.         HTML_MENU_ENTRY_INACTIVE    => '<td>{indent}<a href="{url}">{title}</a></td>',
  84.         HTML_MENU_ENTRY_ACTIVE      => '<td>{indent}<b>{title}</b></td>',
  85.         HTML_MENU_ENTRY_ACTIVEPATH  => '<td>{indent}<b><a href="{url}">{title}</a></b></td>',
  86.         HTML_MENU_ENTRY_PREVIOUS    => '<td><a href="{url}"><< {title}</a></td>',
  87.         HTML_MENU_ENTRY_NEXT        => '<td><a href="{url}">{title} >></a></td>',
  88.         HTML_MENU_ENTRY_UPPER       => '<td><a href="{url}">^ {title} ^</a></td>',
  89.         HTML_MENU_ENTRY_BREADCRUMB  => '<td><a href="{url}">{title}</a> >> </td>'
  90.     );
  91.     /**#@-*/
  92.  
  93.     function finishMenu($level)
  94.     {
  95.         $this->_html     .=  $this->_menuTemplate[0] . $this->_tableHtml . $this->_menuTemplate[1];
  96.         $this->_tableHtml = '';
  97.     }
  98.  
  99.     function finishRow($level)
  100.     {
  101.         $this->_tableHtml .= $this->_rowTemplate[0] . $this->_rowHtml . $this->_rowTemplate[1];
  102.         $this->_rowHtml    = '';
  103.     }
  104.  
  105.     function renderEntry($node, $level, $type)
  106.     {
  107.         $keys = array('{indent}');
  108.         if ('tree' == $this->_menuType || 'sitemap' == $this->_menuType) {
  109.             $values = array(str_repeat('   ', $level));
  110.         } else {
  111.             $values = array('');
  112.         }
  113.         foreach ($node as $k => $v) {
  114.             if ('sub' != $k && is_scalar($v)) {
  115.                 $keys[]   = '{' . $k . '}';
  116.                 $values[] = $v;
  117.             }
  118.         }
  119.         $this->_rowHtml .= str_replace($keys, $values, $this->_entryTemplates[$type]);
  120.     }
  121.  
  122.  
  123.    /**
  124.     * returns the HTML generated for the menu
  125.     *
  126.     * @access public
  127.     * @return string
  128.     */
  129.     function toHtml()
  130.     {
  131.         return $this->_html;
  132.     } // end func toHtml
  133.  
  134.  
  135.    /**
  136.     * Sets the menu template (HTML that wraps around rows)
  137.     *  
  138.     * @access public
  139.     * @param  string    this will be prepended to the rows HTML
  140.     * @param  string    this will be appended to the rows HTML
  141.     */
  142.     function setMenuTemplate($prepend, $append)
  143.     {
  144.         $this->_menuTemplate = array($prepend, $append);
  145.     }
  146.  
  147.  
  148.    /**
  149.     * Sets the row template (HTML that wraps around entries)
  150.     *  
  151.     * @access public
  152.     * @param  string    this will be prepended to the entries HTML
  153.     * @param  string    this will be appended to the entries HTML
  154.     */
  155.     function setRowTemplate($prepend, $append)
  156.     {
  157.         $this->_rowTemplate = array($prepend, $append);
  158.     }
  159.  
  160.  
  161.    /**
  162.     * Sets the template for menu entry.
  163.     * 
  164.     * The template should contain at least the {title} placeholder, can also contain
  165.     * {url} and {indent} placeholders, depending on entry type.
  166.     * 
  167.     * @access public
  168.     * @param  mixed     either type (one of HTML_MENU_ENTRY_* constants) or an array 'type' => 'template'
  169.     * @param  string    template for this entry type if $type is not an array
  170.     */
  171.     function setEntryTemplate($type, $template = null)
  172.     {
  173.         if (is_array($type)) {
  174.             // array_merge() will not work here: the keys are numeric
  175.             foreach ($type as $typeId => $typeTemplate) {
  176.                 if (isset($this->_entryTemplates[$typeId])) {
  177.                     $this->_entryTemplates[$typeId] = $typeTemplate;
  178.                 }
  179.             }
  180.         } else {
  181.             $this->_entryTemplates[$type] = $template;
  182.         }
  183.     }
  184. }
  185. ?>
  186.