1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
* @version $Id$
*
* @category Piwik
* @package Piwik_Menu
*/
/**
* @package Piwik_Menu
*/
class Piwik_Menu_Main extends Piwik_Menu_Abstract
{
static private $instance = null;
/**
* @return Piwik_Menu_Abstract
*/
static public function getInstance()
{
if (self::$instance == null)
{
self::$instance = new self;
}
return self::$instance;
}
/**
* Returns if the URL was found in the menu.
*
* @param string $url
* @return boolean
*/
public function isUrlFound($url)
{
$menu = Piwik_Menu_Main::getInstance()->get();
foreach($menu as $mainMenuName => $subMenus)
{
foreach($subMenus as $subMenuName => $menuUrl)
{
if(strpos($subMenuName, '_') !== 0 && $menuUrl['_url'] == $url)
{
return true;
}
}
}
return false;
}
/**
* Triggers the Menu.add hook and returns the menu.
*
* @return Array
*/
public function get()
{
// We trigger the Event only once!
if(!$this->menu)
{
Piwik_PostEvent('Menu.add');
}
return parent::get();
}
}
/**
* Checks if an entry uses the URL $url.
*
* @param string $url
* @return boolean
*/
function Piwik_IsMenuUrlFound($url)
{
return Piwik_Menu_Main::getInstance()->isUrlFound($url);
}
/**
* Returns the MainMenu as array.
*
* @return array
*/
function Piwik_GetMenu()
{
return Piwik_Menu_Main::getInstance()->get();
}
/**
* Adds a new entry to the MainMenu.
*
* @param string $mainMenuName
* @param string $subMenuName
* @param string $url
* @param boolean $displayedForCurrentUser
* @param int $order
*/
function Piwik_AddMenu( $mainMenuName, $subMenuName, $url, $displayedForCurrentUser = true, $order = 10)
{
Piwik_Menu_Main::getInstance()->add($mainMenuName, $subMenuName, $url, $displayedForCurrentUser, $order);
}
/**
* Renames a menu entry.
*
* @param string $mainMenuOriginal
* @param string $subMenuOriginal
* @param string $mainMenuRenamed
* @param string $subMenuRenamed
*/
function Piwik_RenameMenuEntry($mainMenuOriginal, $subMenuOriginal,
$mainMenuRenamed, $subMenuRenamed)
{
Piwik_Menu_Main::getInstance()->rename($mainMenuOriginal, $subMenuOriginal, $mainMenuRenamed, $subMenuRenamed);
}
/**
* Edits the URL of a menu entry.
*
* @param string $mainMenuToEdit
* @param string $subMenuToEdit
* @param string $newUrl
*/
function Piwik_EditMenuUrl( $mainMenuToEdit, $subMenuToEdit, $newUrl )
{
Piwik_Menu_Main::getInstance()->editUrl($mainMenuToEdit, $subMenuToEdit, $newUrl);
}
|