cvs: pear /HTML_Menu/Menu SigmaTreeRenderer.php /HTML_Menu/examples directtree.php sigmatree.php /HTML_Menu/examples/templates sigmatree.html

From: Date: Sat, 17 Jan 2004 12:34:16 +0000
Subject: cvs: pear /HTML_Menu/Menu SigmaTreeRenderer.php /HTML_Menu/examples directtree.php sigmatree.php /HTML_Menu/examples/templates sigmatree.html
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15724@lists.php.net to get a copy of this message
avb Sat Jan 17 07:34:16 2004 EDT Added files: /pear/HTML_Menu/examples directtree.php sigmatree.php /pear/HTML_Menu/examples/templates sigmatree.html /pear/HTML_Menu/Menu SigmaTreeRenderer.php Log: A new SigmaTree renderer with example Example for previously added DirectTree renderer

Index: pear/HTML_Menu/examples/directtree.php +++ pear/HTML_Menu/examples/directtree.php <?php /** * Usage example for HTML_Menu, DirectTree renderer * * $Id: directtree.php,v 1.1 2004/01/17 12:34:14 avb Exp $ * * @package HTML_Menu * @author Alexey Borzov <avb@php.net> */ require_once 'HTML/Menu.php'; require_once 'HTML/Menu/DirectTreeRenderer.php'; require_once './data/menu.php'; $types = array('tree', 'sitemap'); $menu =& new HTML_Menu($data); $menu->forceCurrentUrl('/item1.2.2.php'); foreach ($types as $type) { echo "\n<h1>Trying menu type &quot;{$type}&quot;</h1>\n"; $renderer =& new HTML_Menu_DirectTreeRenderer(); $menu->render($renderer, $type); echo $renderer->toHtml(); } ?> Index: pear/HTML_Menu/examples/sigmatree.php +++ pear/HTML_Menu/examples/sigmatree.php <?php /** * Usage example for HTML_Menu with SigmaTree renderer * * $Id: sigmatree.php,v 1.1 2004/01/17 12:34:14 avb Exp $ * * @package HTML_Menu * @author Alexey Borzov <avb@php.net> */ require_once 'HTML/Menu.php'; require_once 'HTML/Menu/SigmaTreeRenderer.php'; require_once 'HTML/Template/Sigma.php'; require_once './data/menu.php'; $menu =& new HTML_Menu($data); $menu->forceCurrentUrl('/item1.2.2.php'); $types = array('tree', 'sitemap'); $tpl =& new HTML_Template_Sigma('./templates'); $tpl->loadTemplateFile('sigmatree.html', true, true); $renderer =& new HTML_Menu_SigmaTreeRenderer($tpl); foreach ($types as $type) { $tpl->setVariable('type', $type); $menu->render($renderer, $type); $tpl->parse('type_loop'); } $rendererCustom =& new HTML_Menu_SigmaTreeRenderer($tpl, 'tree_'); $menu->forceCurrentUrl('/item1.2.2.2.php'); $menu->render($rendererCustom, 'tree'); $tpl->show(); ?> Index: pear/HTML_Menu/examples/templates/sigmatree.html +++ pear/HTML_Menu/examples/templates/sigmatree.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!-- $Id: sigmatree.html,v 1.1 2004/01/17 12:34:15 avb Exp $ --> <html> <head> <title>HTML_Menu_SigmaTreeRenderer demo</title> <style type="text/css"> tree { font-family: sans-serif; font-size: 12pt; } tree a { text-decoration: none; } tree a:active, .tree a:hover { text-decoration: underline; } small { font-size: 10pt; } smaller { font-size: 8pt; } red { color: #804040; } </style> </head> <body> <!-- BEGIN type_loop --> <h1>Trying menu type &quot;{type}&quot;</h1> <!-- BEGIN mu_tree_loop --> <!-- BEGIN mu_level_open --> <ul> <!-- END mu_level_open --> <!-- BEGIN mu_entry_open --> <li> <!-- END mu_entry_open --> <!-- BEGIN mu_active --> <strong>{mu_title}</strong> <!-- END mu_active --> <!-- BEGIN mu_inactive --> <a href="{mu_url}">{mu_title}</a> <!-- END mu_inactive --> <!-- BEGIN mu_activepath --> <a href="{mu_url}"><em>{mu_title}</em></a> <!-- END mu_activepath --> <!-- BEGIN mu_entry_close --> </li> <!-- END mu_entry_close --> <!-- BEGIN mu_level_close --> </ul> <!-- END mu_level_close --> <!-- END mu_tree_loop --> <!-- END type_loop --> <h1>Customizing the &quot;tree&quot; output</h1> <!-- BEGIN tree_tree_loop --> <!-- BEGIN tree_1_level_open --> <ol class="tree"> <!-- END tree_1_level_open --> <!-- BEGIN tree_level_open --> <ul class="tree"> <!-- END tree_level_open --> <!-- BEGIN tree_1_entry_open --> <li> <!-- END tree_1_entry_open --> <!-- BEGIN tree_2_entry_open --> <li class="small"> <!-- END tree_2_entry_open --> <!-- BEGIN tree_entry_open --> <li class="smaller"> <!-- END tree_entry_open --> <!-- BEGIN tree_active --> <strong class="red">{tree_title}</strong> <!-- END tree_active --> <!-- BEGIN tree_inactive --> <a href="{tree_url}">{tree_title}</a> <!-- END tree_inactive --> <!-- BEGIN tree_activepath --> <a href="{tree_url}"><em>{tree_title}</em></a> <!-- END tree_activepath --> <!-- BEGIN tree_entry_close --> </li> <!-- END tree_entry_close --> <!-- BEGIN tree_level_close --> </ul> <!-- END tree_level_close --> <!-- BEGIN tree_1_level_close --> </ol> <!-- END tree_1_level_close --> <!-- END tree_tree_loop --> </body> </html> Index: pear/HTML_Menu/Menu/SigmaTreeRenderer.php +++ pear/HTML_Menu/Menu/SigmaTreeRenderer.php <?php // // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2004 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alexey Borzov <avb@php.net> | // +----------------------------------------------------------------------+ // // $Id: SigmaTreeRenderer.php,v 1.1 2004/01/17 12:34:15 avb Exp $ // require_once 'HTML/Menu/Renderer.php'; /** * HTML_Template_Sigma-based renderer for 'tree' and 'sitemap' type menus, * where menu level is represented by tag nesting. * * @version $Revision: 1.1 $ * @author Alexey Borzov <avb@php.net> * @access public * @package HTML_Menu */ class HTML_Menu_SigmaTreeRenderer extends HTML_Menu_Renderer { /** * Template object used for output * @var object HTML_Template_Sigma */ var $_tpl; /** * Prefix for template blocks and placeholders * @var string */ var $_prefix; /** * * */ var $_level = -1; /** * Mapping from HTML_MENU_ENTRY_* constants to template block names * @var array */ var $_typeNames = array( HTML_MENU_ENTRY_INACTIVE => 'inactive', HTML_MENU_ENTRY_ACTIVE => 'active', HTML_MENU_ENTRY_ACTIVEPATH => 'activepath' ); /** * Class constructor. * * Sets the template object to use and sets prefix for template blocks * and placeholders. We use prefix to avoid name collisions with existing * template blocks and it is customisable to allow output of several menus * into one template. * * @access public * @param object HTML_Template_Sigma template object to use for output * @param string prefix for template blocks and placeholders */ function HTML_Menu_SigmaTreeRenderer(&$tpl, $prefix = 'mu_') { $this->_tpl =& $tpl; $this->_prefix = $prefix; } function setMenuType($menuType) { if ('tree' == $menuType || 'sitemap' == $menuType) { $this->_menuType = $menuType; } else { require_once 'PEAR.php'; return PEAR::raiseError("HTML_Menu_SigmaTreeRenderer: unable to render '$menuType' type menu"); } $this->_level = -1; } function finishLevel($level) { // Close the previous entry if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_close')) { $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_close'); } else { $this->_tpl->touchBlock($this->_prefix . 'entry_close'); } $this->_tpl->parse($this->_prefix . 'tree_loop'); // Close the level if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_level_close')) { $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_level_close'); } else { $this->_tpl->touchBlock($this->_prefix . 'level_close'); } $this->_tpl->parse($this->_prefix . 'tree_loop'); } function renderEntry($node, $level, $type) { // Close the entry if previous was on same or higher level if ($this->_level >= $level) { if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_close')) { $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_close'); } else { $this->_tpl->touchBlock($this->_prefix . 'entry_close'); } $this->_tpl->parse($this->_prefix . 'tree_loop'); // If the new level is higher then open the level } else { if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_level_open')) { $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_level_open'); } else { $this->_tpl->touchBlock($this->_prefix . 'level_open'); } $this->_tpl->parse($this->_prefix . 'tree_loop'); } // Open the entry if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_open')) { $this->_tpl->touchBlock($this->_prefix . ($level + 1) . '_entry_open'); } else { $this->_tpl->touchBlock($this->_prefix . 'entry_open'); } $this->_tpl->parse($this->_prefix . 'tree_loop'); if ($this->_tpl->blockExists($this->_prefix . ($level + 1) . '_' . $this->_typeNames[$type])) { $blockName = $this->_prefix . ($level + 1) . '_' . $this->_typeNames[$type]; } else { $blockName = $this->_prefix . $this->_typeNames[$type]; } if ($this->_tpl->placeholderExists($this->_prefix . 'url', $blockName)) { $this->_tpl->setVariable($this->_prefix . 'url', $node['url']); } $this->_tpl->setVariable($this->_prefix . 'title', $node['title']); $this->_tpl->parse($blockName); $this->_tpl->parse($this->_prefix . 'tree_loop'); $this->_level = $level; } } ?>
« previous php.pear.cvs (#15724) next »