1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Sergey Glagolev <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2014 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
* @package frontend.widgets
|
8
|
|
|
*/
|
9
|
|
|
|
10
|
1 |
|
Yii::import('zii.widgets.CMenu');
|
11
|
|
|
|
12
|
|
|
class FMenu extends CMenu
|
13
|
|
|
{
|
14
|
|
|
public $route;
|
15
|
|
|
|
16
|
|
|
public $onlyActiveItems = false;
|
17
|
|
|
|
18
|
7 |
|
public function init()
|
19
|
|
|
{
|
20
|
7 |
|
$this->htmlOptions['id'] = $this->getId();
|
21
|
|
|
|
22
|
7 |
|
$routes = !empty($this->controller->activeUrl) ? $this->controller->activeUrl : $this->controller->route;
|
23
|
|
|
|
24
|
7 |
|
if( !is_array($routes) || !is_array(Arr::reset($routes)) )
|
25
|
7 |
|
$routes = array($routes);
|
26
|
|
|
|
27
|
7 |
|
$this->items = $this->normalizeItems($this->items, $routes, $hasActiveChild);
|
|
|
|
|
28
|
7 |
|
}
|
29
|
|
|
|
30
|
7 |
|
protected function isItemActive($item, $routes)
|
31
|
|
|
{
|
32
|
7 |
|
foreach($routes as $route)
|
33
|
|
|
{
|
34
|
7 |
|
if( $this->isItemActiveOne($item, $route) )
|
35
|
7 |
|
return true;
|
36
|
7 |
|
}
|
37
|
|
|
|
38
|
7 |
|
return false;
|
39
|
|
|
}
|
40
|
|
|
|
41
|
7 |
|
protected function isItemActiveOne($item, $route)
|
42
|
|
|
{
|
43
|
7 |
|
if( is_array($route) )
|
44
|
7 |
|
{
|
45
|
|
|
$params = array_slice($route, 1);
|
46
|
|
|
$route = $route[0];
|
47
|
|
|
}
|
48
|
|
|
else
|
49
|
7 |
|
$params = $_GET;
|
50
|
|
|
|
51
|
7 |
|
if( isset($item['url']) && is_array($item['url']) && !strcasecmp(trim($item['url'][0], '/'), $route) )
|
52
|
7 |
|
{
|
53
|
2 |
|
if( isset($item['url']['#']) )
|
54
|
2 |
|
unset($item['url']['#']);
|
55
|
2 |
|
if( count($item['url']) > 1 )
|
56
|
2 |
|
{
|
57
|
|
|
$url = $item['url'];
|
58
|
|
|
|
59
|
|
|
foreach(array_splice($url, 1) as $name => $value)
|
60
|
|
|
{
|
61
|
|
|
if( !isset($params[$name]) || $params[$name] != $value )
|
62
|
|
|
return false;
|
63
|
|
|
}
|
64
|
|
|
}
|
65
|
2 |
|
return true;
|
66
|
|
|
}
|
67
|
|
|
|
68
|
7 |
|
return false;
|
69
|
|
|
}
|
70
|
|
|
|
71
|
7 |
|
protected function renderMenuRecursive($items)
|
72
|
|
|
{
|
73
|
7 |
|
if( $this->onlyActiveItems )
|
74
|
7 |
|
{
|
75
|
|
|
foreach($items as $i => $item)
|
76
|
|
|
if( !$item['active'] )
|
77
|
|
|
$items[$i]['items'] = array();
|
78
|
|
|
}
|
79
|
|
|
|
80
|
7 |
|
parent::renderMenuRecursive($items);
|
81
|
|
|
}
|
82
|
|
|
} |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.