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] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!