Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class EMenu extends CMenu
- {
- /**
- * Checks whether a menu item is active.
- * This is done by checking if the currently requested URL is generated by the 'url' option
- * of the menu item. Note that the GET parameters not specified in the 'url' option will be ignored.
- * @param array $item the menu item to be checked
- * @param string $route the route of the current request
- * @return boolean whether the menu item is active
- */
- protected function isItemActive($item,$route)
- {
- $uri = Yii::app()->request->requestUri;
- $subitem = substr($item['url'], 0, -1);
- if(!strcasecmp($item['url'], $uri) || ($subitem && (strpos($uri, $subitem) !== false)))
- return true;
- else
- return parent::isItemActive($item,$route);
- }
- /**
- * Normalizes the {@link items} property so that the 'active' state is properly identified for every menu item.
- * @param array $items the items to be normalized.
- * @param string $route the route of the current request.
- * @param boolean $active whether there is an active child menu item.
- * @return array the normalized menu items
- */
- protected function normalizeItems($items, $route, &$active)
- {
- foreach($items as $i=>$item)
- {
- if(isset($item['visible']) && !$item['visible'])
- {
- unset($items[$i]);
- continue;
- }
- if(!isset($item['label']))
- {
- $item['label']='';
- }
- if($this->encodeLabel)
- {
- $items[$i]['label']=CHtml::encode($item['label']);
- }
- $hasActiveChild=false;
- if(isset($item['items']))
- {
- $items[$i]['items']=$this->normalizeItems($item['items'],$route,$hasActiveChild);
- if(empty($items[$i]['items']) && $this->hideEmptyItems)
- {
- unset($items[$i]['items']);
- if(!isset($item['url']))
- {
- unset($items[$i]);
- continue;
- }
- }
- }
- if(!isset($item['active']))
- {
- if($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item,$route))
- {
- $active = $items[$i]['active'] = true;
- if (!$hasActiveChild)
- {
- $items[$i]['linkOptions']['rel'] = 'nofollow';
- }
- }
- else
- {
- $items[$i]['active'] = false;
- }
- }
- elseif($item['active'])
- {
- $active = true;
- }
- }
- return array_values($items);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement