Home » HTML » HTML_Menu » Bug #2935
combine duplicate code into _prefixUrl method
Details
| Request #2935 | combine duplicate code into _prefixUrl method |
|---|---|
| Submitted | 2004-12-09 16:02 UTC |
| From | aaron dot hawley at uvm dot edu |
| Assigned | avb |
| Status | Closed |
| Package | HTML_Menu |
| PHP Version | 4.3.4 |
| OS | GNU/Linux |
| Roadmaps | (Not assigned) |
Comments
[2004-12-09 16:02 UTC] aaron dot hawley at uvm dot edu
Description:
------------
The code that prefixes URLs at each node in the _buildUrlMap and _findNodeType methods, should be consolidated. The patch below contains a method _prefixUrl. This makes it easier to create a sub-class which can modify the URL prefixing behavior.
Reproduce code:
---------------
===================================================================
RCS file: RCS/Menu.php,v
retrieving revision 1.1
diff -u -r1.1 Menu.php
--- Menu.php 2004/12/08 19:29:28 1.1
+++ Menu.php 2004/12/09 15:40:53
@@ -101,7 +101,7 @@
/**
* Prefix for menu URLs
* @var string
- * @see setUrlPrefix()
+ * @see setUrlPrefix(), _prefixUrl()
*/
var $_urlPrefix = '';
@@ -279,7 +279,7 @@
*/
function _findNodeType($nodeId, &$nodeUrl, $level)
{
- $nodeUrl = $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $nodeUrl{0})? $nodeUrl: substr($nodeUrl, 1));
+ $nodeUrl = $this->_prefixUrl($nodeUrl);
if ($this->_currentUrl == $nodeUrl) {
// menu item that fits to this url - 'active' menu item
return HTML_MENU_ENTRY_ACTIVE;
@@ -292,6 +292,11 @@
}
}
+ function _prefixUrl($nodeUrl)
+ {
+ return $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $nodeUrl{0}) ? $nodeUrl : substr($nodeUrl, 1));
+ }
+
/**
* Renders the tree menu ('tree' and 'sitemap')
*
@@ -474,7 +479,7 @@
function _buildUrlMap($menu, $path)
{
foreach ($menu as $nodeId => $node) {
- $url = $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $node['url']{0})? $node['url']: substr($node['url'], 1));
+ $url = $this->_prefixUrl($node['url']);
$this->_urlMap[$url] = $path;
if ($url == $this->_currentUrl) {
http://www.uvm.edu/~ashawley/php/HTML_Menu.php-prefixUrl.diff-u