-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Menu/trunk@140189 c90b9560-bf6c-de11-be94-00142212c4b1
- Loading branch information
1 parent
9710b03
commit 6f6cd67
Showing
3 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
// | ||
// +----------------------------------------------------------------------+ | ||
// | PHP Version 4 | | ||
// +----------------------------------------------------------------------+ | ||
// | Copyright (c) 1997-2003 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. | | ||
// +----------------------------------------------------------------------+ | ||
// | Author: Alexey Borzov <avb@php.net> | | ||
// +----------------------------------------------------------------------+ | ||
// | ||
// $Id$ | ||
// | ||
|
||
require_once 'HTML/Menu/Renderer.php'; | ||
|
||
/** | ||
* The renderer that uses HTML_Template_Sigma instance for menu output. | ||
* | ||
* @version $Revision$ | ||
* @author Alexey Borzov <avb@php.net> | ||
* @access public | ||
* @package HTML_Menu | ||
*/ | ||
class HTML_Menu_SigmaRenderer extends HTML_Menu_Renderer | ||
{ | ||
/** | ||
* Template object used for output | ||
* @var object HTML_Template_Sigma | ||
*/ | ||
var $_tpl; | ||
|
||
/** | ||
* 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', | ||
HTML_MENU_ENTRY_PREVIOUS => 'previous', | ||
HTML_MENU_ENTRY_NEXT => 'next', | ||
HTML_MENU_ENTRY_UPPER => 'upper', | ||
HTML_MENU_ENTRY_BREADCRUMB => 'breadcrumb' | ||
); | ||
|
||
/** | ||
* Prefix for template blocks and placeholders | ||
* @var string | ||
*/ | ||
var $_prefix; | ||
|
||
/** | ||
* 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_SigmaRenderer(&$tpl, $prefix = 'mu_') | ||
{ | ||
$this->_tpl =& $tpl; | ||
$this->_prefix = $prefix; | ||
} | ||
|
||
function finishMenu($level) | ||
{ | ||
if ('rows' == $this->_menuType && $this->_tpl->blockExists($this->_prefix . ($level + 1) . '_menu_loop')) { | ||
$this->_tpl->parse($this->_prefix . ($level + 1) . '_menu_loop'); | ||
} elseif ($this->_tpl->blockExists($this->_prefix . 'menu_loop')) { | ||
$this->_tpl->parse($this->_prefix . 'menu_loop'); | ||
} | ||
} | ||
|
||
function finishRow($level) | ||
{ | ||
if ('rows' == $this->_menuType && $this->_tpl->blockExists($this->_prefix . ($level + 1) . '_row_loop')) { | ||
$this->_tpl->parse($this->_prefix . ($level + 1) . '_row_loop'); | ||
} elseif ($this->_tpl->blockExists($this->_prefix . 'row_loop')) { | ||
$this->_tpl->parse($this->_prefix . 'row_loop'); | ||
} | ||
} | ||
|
||
function renderEntry(&$node, $level, $type) | ||
{ | ||
if (in_array($this->_menuType, array('tree', 'sitemap', 'rows')) | ||
&& $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 (('tree' == $this->_menuType || 'sitemap' == $this->_menuType) && | ||
$this->_tpl->blockExists($blockName . '_indent')) { | ||
|
||
for ($i = 0; $i < $level; $i++) { | ||
$this->_tpl->touchBlock($blockName . '_indent'); | ||
$this->_tpl->parse($blockName . '_indent'); | ||
} | ||
} | ||
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); | ||
if ('rows' == $this->_menuType | ||
&& $this->_tpl->blockExists($this->_prefix . ($level + 1) . '_entry_loop')) { | ||
|
||
$this->_tpl->parse($this->_prefix . ($level + 1) . '_entry_loop'); | ||
} else { | ||
$this->_tpl->parse($this->_prefix . 'entry_loop'); | ||
} | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/** | ||
* Usage example for HTML_Menu with Sigma renderer | ||
* | ||
* $Id$ | ||
* | ||
* @package HTML_Menu | ||
* @author Alexey Borzov <avb@php.net> | ||
*/ | ||
|
||
require_once 'HTML/Menu.php'; | ||
require_once 'HTML/Template/Sigma.php'; | ||
require_once 'HTML/Menu/SigmaRenderer.php'; | ||
|
||
$data = array( | ||
1 => array( | ||
'title' => 'Menu item 1', | ||
'url' => '/item1.php', | ||
'sub' => array( | ||
11 => array('title' => 'Menu item 1.1', 'url' => '/item1.1.php'), | ||
12 => array( | ||
'title' => 'Menu item 1.2', | ||
'url' => '/item1.2.php', | ||
'sub' => array( | ||
121 => array('title' => 'Menu item 1.2.1', 'url' => '/item1.2.1.php'), | ||
122 => array( | ||
'title' => 'Menu item 1.2.2', | ||
'url' => '/item1.2.2.php', | ||
'sub' => array( | ||
1221 => array('title' => 'Menu item 1.2.2.1', 'url' => '/item1.2.2.1.php'), | ||
1222 => array('title' => 'Menu item 1.2.2.2', 'url' => '/item1.2.2.2.php') | ||
) | ||
), | ||
123 => array('title' => 'Menu item 1.2.3', 'url' => '/item1.2.3.php'), | ||
) | ||
), | ||
13 => array( | ||
'title' => 'Menu item 1.3', | ||
'url' => '/item1.3.php', | ||
'sub' => array( | ||
131 => array('title' => 'Menu item 1.3.1', 'url' => '/item1.3.1.php'), | ||
132 => array('title' => 'Menu item 1.3.2', 'url' => '/item1.3.2.php'), | ||
) | ||
) | ||
) | ||
), | ||
2 => array( | ||
'title' => 'Menu item 2', | ||
'url' => '/item2.php', | ||
'sub' => array( | ||
21 => array('title' => 'Menu item 2.1', 'url' => '/item2.1.php'), | ||
22 => array( | ||
'title' => 'Menu item 2.2', | ||
'url' => '/item2.2.php', | ||
'sub' => array( | ||
221 => array('title' => 'Menu item 2.2.1', 'url' => '/item2.2.1.php') | ||
) | ||
) | ||
) | ||
), | ||
3 => array('title' => 'Menu item 3', 'url' => '/item3.php'), | ||
4 => array( | ||
'title' => 'Menu item 4', | ||
'url' => '/item4.php', | ||
'sub' => array( | ||
41 => array('title' => 'Menu item 4.1', 'url' => '/item4.1.php'), | ||
42 => array('title' => 'Menu item 4.2', 'url' => '/item4.2.php'), | ||
43 => array('title' => 'Menu item 4.3', 'url' => '/item4.3.php') | ||
) | ||
) | ||
); | ||
|
||
$types = array('tree', 'urhere', 'prevnext', 'rows', 'sitemap'); | ||
|
||
$menu =& new HTML_Menu($data); | ||
$menu->forceCurrentUrl('/item1.2.2.2.php'); | ||
|
||
$tpl =& new HTML_Template_Sigma('./templates'); | ||
$tpl->loadTemplateFile('sigma.html'); | ||
$renderer =& new HTML_Menu_SigmaRenderer($tpl); | ||
|
||
foreach ($types as $type) { | ||
$tpl->setVariable('type', $type); | ||
$menu->render($renderer, $type); | ||
$tpl->parse('type_loop'); | ||
} | ||
|
||
$treeRenderer =& new HTML_Menu_SigmaRenderer($tpl, 'tree_'); | ||
$menu->render($treeRenderer, 'tree'); | ||
|
||
$rowsRenderer =& new HTML_Menu_SigmaRenderer($tpl, 'rows_'); | ||
$menu->render($rowsRenderer, 'rows'); | ||
|
||
$tpl->show(); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<!-- $Id$ --> | ||
<html> | ||
<head> | ||
<title>HTML_Menu_SigmaRenderer demo</title> | ||
<style type="text/css"> | ||
.treetable { | ||
font-family: sans-serif; | ||
border : thin dashed #D0D0D0; | ||
background-color : #EEE; | ||
} | ||
.rowstable { | ||
font-family: sans-serif; | ||
background-color : #F0F0F0; | ||
} | ||
.rows1 { | ||
background-color : #AAA; | ||
} | ||
.rows2 { | ||
background-color : #CCC; | ||
} | ||
.small { | ||
font-size: 85%; | ||
} | ||
.smaller { | ||
font-size: 70%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<!-- BEGIN type_loop --> | ||
<h1>Trying menu type "{type}" </h1> | ||
<!-- BEGIN mu_menu_loop --> | ||
<table cellpadding="2" cellspacing="0" border="1"> | ||
<!-- BEGIN mu_row_loop --> | ||
<tr> | ||
<!-- BEGIN mu_entry_loop --> | ||
<!-- BEGIN mu_inactive --> | ||
<td><!-- BEGIN mu_inactive_indent --> <!-- END mu_inactive_indent --><a href="{mu_url}">{mu_title}</a></td> | ||
<!-- END mu_inactive --> | ||
<!-- BEGIN mu_active --> | ||
<td><!-- BEGIN mu_active_indent --> <!-- END mu_active_indent --><strong>{mu_title}</strong></td> | ||
<!-- END mu_active --> | ||
<!-- BEGIN mu_activepath --> | ||
<td><!-- BEGIN mu_activepath_indent --> <!-- END mu_activepath_indent --><a href="{mu_url}"><strong>{mu_title}</strong></a></td> | ||
<!-- END mu_activepath --> | ||
<!-- BEGIN mu_previous --> | ||
<td><a href="{mu_url}"><<< {mu_title}</a></td> | ||
<!-- END mu_previous --> | ||
<!-- BEGIN mu_next --> | ||
<td><a href="{mu_url}">{mu_title} >>></a></td> | ||
<!-- END mu_next --> | ||
<!-- BEGIN mu_upper --> | ||
<td><a href="{mu_url}">^ {mu_title} ^</a></td> | ||
<!-- END mu_upper --> | ||
<!-- BEGIN mu_breadcrumb --> | ||
<td><a href="{mu_url}">{mu_title}</a> >>></td> | ||
<!-- END mu_breadcrumb --> | ||
<!-- END mu_entry_loop --> | ||
</tr> | ||
<!-- END mu_row_loop --> | ||
</table> | ||
<!-- END mu_menu_loop --> | ||
<!-- END type_loop --> | ||
|
||
<h1>Customizing the "tree" output</h1> | ||
|
||
<table cellpadding="2" cellspacing="0" border="0" class="treetable"> | ||
<!-- BEGIN tree_entry_loop --> | ||
<tr> | ||
<!-- BEGIN tree_1_inactive --> | ||
<td><a href="{tree_url}">{tree_title}</a></td> | ||
<!-- END tree_1_inactive --> | ||
<!-- BEGIN tree_1_active --> | ||
<td><strong>{tree_title}</strong></td> | ||
<!-- END tree_1_active --> | ||
<!-- BEGIN tree_1_activepath --> | ||
<td><a href="{tree_url}"><strong>{tree_title}</strong></a></td> | ||
<!-- END tree_1_activepath --> | ||
|
||
<!-- BEGIN tree_2_inactive --> | ||
<td> <a href="{tree_url}" class="small">{tree_title}</a></td> | ||
<!-- END tree_2_inactive --> | ||
<!-- BEGIN tree_2_active --> | ||
<td> <strong class="small">{tree_title}</strong></td> | ||
<!-- END tree_2_active --> | ||
<!-- BEGIN tree_2_activepath --> | ||
<td> <a href="{tree_url}" class="small"><strong>{tree_title}</strong></a></td> | ||
<!-- END tree_2_activepath --> | ||
|
||
<!-- BEGIN tree_inactive --> | ||
<td><!-- BEGIN tree_inactive_indent --> <!-- END tree_inactive_indent --><a href="{tree_url}" class="smaller">• {tree_title}</a></td> | ||
<!-- END tree_inactive --> | ||
<!-- BEGIN tree_active --> | ||
<td><!-- BEGIN tree_active_indent --> <!-- END tree_active_indent --><strong class="smaller">• {tree_title}</strong></td> | ||
<!-- END tree_active --> | ||
<!-- BEGIN tree_activepath --> | ||
<td><!-- BEGIN tree_activepath_indent --> <!-- END tree_activepath_indent --><a href="{tree_url}" class="smaller"><strong>• {tree_title}</strong></a></td> | ||
<!-- END tree_activepath --> | ||
</tr> | ||
<!-- END tree_entry_loop --> | ||
</table> | ||
|
||
<h1>Customizing the "rows" output</h1> | ||
<!-- BEGIN rows_menu_loop --> | ||
<table cellpadding="2" cellspacing="0" border="0" class="rowstable"> | ||
<!-- BEGIN rows_1_row_loop --> | ||
<tr class="rows1"> | ||
<td> | </td> | ||
<!-- BEGIN rows_1_entry_loop --> | ||
<!-- BEGIN rows_1_inactive --> | ||
<td><a href="{rows_url}">{rows_title}</a></td> | ||
<!-- END rows_1_inactive --> | ||
<!-- BEGIN rows_1_active --> | ||
<td><strong>{rows_title}</strong></td> | ||
<!-- END rows_1_active --> | ||
<!-- BEGIN rows_1_activepath --> | ||
<td><a href="{rows_url}"><strong>{rows_title}</strong></a></td> | ||
<!-- END rows_1_activepath --> | ||
<td> | </td> | ||
<!-- END rows_1_entry_loop --> | ||
</tr> | ||
<!-- END rows_1_row_loop --> | ||
|
||
<!-- BEGIN rows_2_row_loop --> | ||
<tr class="rows2"> | ||
<td> | </td> | ||
<!-- BEGIN rows_2_entry_loop --> | ||
<!-- BEGIN rows_2_inactive --> | ||
<td><a href="{rows_url}" class="small">{rows_title}</a></td> | ||
<!-- END rows_2_inactive --> | ||
<!-- BEGIN rows_2_active --> | ||
<td><strong class="small">{rows_title}</strong></td> | ||
<!-- END rows_2_active --> | ||
<!-- BEGIN rows_2_activepath --> | ||
<td><a href="{rows_url}" class="small"><strong>{rows_title}</strong></a></td> | ||
<!-- END rows_2_activepath --> | ||
<td> | </td> | ||
<!-- END rows_2_entry_loop --> | ||
</tr> | ||
<!-- END rows_2_row_loop --> | ||
|
||
<!-- BEGIN rows_row_loop --> | ||
<tr> | ||
<td> | </td> | ||
<!-- BEGIN rows_entry_loop --> | ||
<!-- BEGIN rows_inactive --> | ||
<td><a href="{rows_url}" class="smaller">{rows_title}</a></td> | ||
<!-- END rows_inactive --> | ||
<!-- BEGIN rows_active --> | ||
<td><strong class="smaller">{rows_title}</strong></td> | ||
<!-- END rows_active --> | ||
<!-- BEGIN rows_activepath --> | ||
<td><a href="{rows_url}" class="smaller"><strong>{rows_title}</strong></a></td> | ||
<!-- END rows_activepath --> | ||
<td> | </td> | ||
<!-- END rows_entry_loop --> | ||
</tr> | ||
<!-- END rows_row_loop --> | ||
</table> | ||
<!-- END rows_menu_loop --> | ||
</body> | ||
</html> | ||
|