Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.2.0

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)    
Subscription  


 [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

Comments

 [2006-06-01 18:18 UTC] avb (Alexey Borzov)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.