update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
31
www/analytics/core/Menu/Group.php
Normal file
31
www/analytics/core/Menu/Group.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Menu;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
class Group
|
||||
{
|
||||
private $items;
|
||||
|
||||
public function add($subTitleMenu, $url, $tooltip = false)
|
||||
{
|
||||
$this->items[] = array(
|
||||
'name' => $subTitleMenu,
|
||||
'url' => $url,
|
||||
'tooltip' => $tooltip
|
||||
);
|
||||
}
|
||||
|
||||
public function getItems()
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,17 +8,17 @@
|
|||
*/
|
||||
namespace Piwik\Menu;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\Plugins\SitesManager\API;
|
||||
use Piwik\Singleton;
|
||||
use Piwik\Plugin\Manager as PluginManager;
|
||||
|
||||
/**
|
||||
* Base class for classes that manage one of Piwik's menus.
|
||||
*
|
||||
*
|
||||
* There are three menus in Piwik, the main menu, the top menu and the admin menu.
|
||||
* Each menu has a class that manages the menu's content. Each class invokes
|
||||
* a different event to allow plugins to add new menu items.
|
||||
*
|
||||
*
|
||||
* @static \Piwik\Menu\MenuAbstract getInstance()
|
||||
*/
|
||||
abstract class MenuAbstract extends Singleton
|
||||
|
|
@ -30,6 +30,8 @@ abstract class MenuAbstract extends Singleton
|
|||
protected $edits = array();
|
||||
protected $renames = array();
|
||||
protected $orderingApplied = false;
|
||||
protected $menuIcons = array();
|
||||
protected static $menus = array();
|
||||
|
||||
/**
|
||||
* Builds the menu, applies edits, renames
|
||||
|
|
@ -47,6 +49,43 @@ abstract class MenuAbstract extends Singleton
|
|||
return $this->menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Let's you register a menu icon for a certain menu category to replace the default arrow icon.
|
||||
*
|
||||
* @param string $menuName The translation key of a main menu category, eg 'Dashboard_Dashboard'
|
||||
* @param string $iconCssClass The css class name of an icon, eg 'icon-user'
|
||||
*/
|
||||
public function registerMenuIcon($menuName, $iconCssClass)
|
||||
{
|
||||
$this->menuIcons[$menuName] = $iconCssClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of available plugin menu instances.
|
||||
*
|
||||
* @return \Piwik\Plugin\Menu[]
|
||||
*/
|
||||
protected function getAllMenus()
|
||||
{
|
||||
if (!empty(self::$menus)) {
|
||||
return self::$menus;
|
||||
}
|
||||
|
||||
self::$menus = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');
|
||||
|
||||
return self::$menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* To use only for tests.
|
||||
*
|
||||
* @deprecated The whole $menus cache should be replaced by a real transient cache
|
||||
*/
|
||||
public static function clearMenus()
|
||||
{
|
||||
self::$menus = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry to the menu.
|
||||
*
|
||||
|
|
@ -57,8 +96,9 @@ abstract class MenuAbstract extends Singleton
|
|||
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
|
||||
* current user. If false, the entry will not be added.
|
||||
* @param int $order The order hint.
|
||||
* @param false|string $tooltip An optional tooltip to display.
|
||||
* @api
|
||||
* @param bool|string $tooltip An optional tooltip to display or false to display the tooltip.
|
||||
*
|
||||
* @deprecated since 2.7.0 Use {@link addItem() instead}. Method will be removed in Piwik 3.0
|
||||
*/
|
||||
public function add($menuName, $subMenuName, $url, $displayedForCurrentUser = true, $order = 50, $tooltip = false)
|
||||
{
|
||||
|
|
@ -66,8 +106,25 @@ abstract class MenuAbstract extends Singleton
|
|||
return;
|
||||
}
|
||||
|
||||
$this->addItem($menuName, $subMenuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new entry to the menu.
|
||||
*
|
||||
* @param string $menuName The menu's category name. Can be a translation token.
|
||||
* @param string $subMenuName The menu item's name. Can be a translation token.
|
||||
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
|
||||
* that can be used to build the URL.
|
||||
* @param int $order The order hint.
|
||||
* @param bool|string $tooltip An optional tooltip to display or false to display the tooltip.
|
||||
* @since 2.7.0
|
||||
* @api
|
||||
*/
|
||||
public function addItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
// make sure the idSite value used is numeric (hack-y fix for #3426)
|
||||
if (!is_numeric(Common::getRequestVar('idSite', false))) {
|
||||
if (isset($url['idSite']) && !is_numeric($url['idSite'])) {
|
||||
$idSites = API::getInstance()->getSitesIdWithAtLeastViewAccess();
|
||||
$url['idSite'] = reset($idSites);
|
||||
}
|
||||
|
|
@ -81,6 +138,13 @@ abstract class MenuAbstract extends Singleton
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an existing entry from the menu.
|
||||
*
|
||||
* @param string $menuName The menu's category name. Can be a translation token.
|
||||
* @param bool|string $subMenuName The menu item's name. Can be a translation token.
|
||||
* @api
|
||||
*/
|
||||
public function remove($menuName, $subMenuName = false)
|
||||
{
|
||||
$this->menuEntriesToRemove[] = array(
|
||||
|
|
@ -100,21 +164,34 @@ abstract class MenuAbstract extends Singleton
|
|||
*/
|
||||
private function buildMenuItem($menuName, $subMenuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
if (!isset($this->menu[$menuName]) || empty($subMenuName)) {
|
||||
$this->menu[$menuName]['_url'] = $url;
|
||||
if (empty($subMenuName)) {
|
||||
$this->menu[$menuName]['_order'] = $order;
|
||||
}
|
||||
$this->menu[$menuName]['_name'] = $menuName;
|
||||
$this->menu[$menuName]['_hasSubmenu'] = false;
|
||||
if (!isset($this->menu[$menuName])) {
|
||||
$this->menu[$menuName] = array(
|
||||
'_hasSubmenu' => false,
|
||||
'_order' => $order
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($subMenuName)) {
|
||||
$this->menu[$menuName]['_url'] = $url;
|
||||
$this->menu[$menuName]['_order'] = $order;
|
||||
$this->menu[$menuName]['_name'] = $menuName;
|
||||
$this->menu[$menuName]['_tooltip'] = $tooltip;
|
||||
if (!empty($this->menuIcons[$menuName])) {
|
||||
$this->menu[$menuName]['_icon'] = $this->menuIcons[$menuName];
|
||||
} else {
|
||||
$this->menu[$menuName]['_icon'] = '';
|
||||
}
|
||||
}
|
||||
if (!empty($subMenuName)) {
|
||||
$this->menu[$menuName][$subMenuName]['_url'] = $url;
|
||||
$this->menu[$menuName][$subMenuName]['_order'] = $order;
|
||||
$this->menu[$menuName][$subMenuName]['_name'] = $subMenuName;
|
||||
$this->menu[$menuName][$subMenuName]['_tooltip'] = $tooltip;
|
||||
$this->menu[$menuName]['_hasSubmenu'] = true;
|
||||
$this->menu[$menuName]['_tooltip'] = $tooltip;
|
||||
|
||||
if (!array_key_exists('_tooltip', $this->menu[$menuName])) {
|
||||
$this->menu[$menuName]['_tooltip'] = $tooltip;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +212,7 @@ abstract class MenuAbstract extends Singleton
|
|||
* @param $subMenuOriginal
|
||||
* @param $mainMenuRenamed
|
||||
* @param $subMenuRenamed
|
||||
* @api
|
||||
*/
|
||||
public function rename($mainMenuOriginal, $subMenuOriginal, $mainMenuRenamed, $subMenuRenamed)
|
||||
{
|
||||
|
|
@ -148,6 +226,7 @@ abstract class MenuAbstract extends Singleton
|
|||
* @param $mainMenuToEdit
|
||||
* @param $subMenuToEdit
|
||||
* @param $newUrl
|
||||
* @api
|
||||
*/
|
||||
public function editUrl($mainMenuToEdit, $subMenuToEdit, $newUrl)
|
||||
{
|
||||
|
|
@ -161,13 +240,21 @@ abstract class MenuAbstract extends Singleton
|
|||
{
|
||||
foreach ($this->edits as $edit) {
|
||||
$mainMenuToEdit = $edit[0];
|
||||
$subMenuToEdit = $edit[1];
|
||||
$newUrl = $edit[2];
|
||||
$subMenuToEdit = $edit[1];
|
||||
$newUrl = $edit[2];
|
||||
|
||||
if ($subMenuToEdit === null) {
|
||||
$menuDataToEdit = @$this->menu[$mainMenuToEdit];
|
||||
if (isset($this->menu[$mainMenuToEdit])) {
|
||||
$menuDataToEdit = &$this->menu[$mainMenuToEdit];
|
||||
} else {
|
||||
$menuDataToEdit = null;
|
||||
}
|
||||
} else {
|
||||
$menuDataToEdit = @$this->menu[$mainMenuToEdit][$subMenuToEdit];
|
||||
if (isset($this->menu[$mainMenuToEdit][$subMenuToEdit])) {
|
||||
$menuDataToEdit = &$this->menu[$mainMenuToEdit][$subMenuToEdit];
|
||||
} else {
|
||||
$menuDataToEdit = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($menuDataToEdit)) {
|
||||
|
|
@ -180,16 +267,15 @@ abstract class MenuAbstract extends Singleton
|
|||
|
||||
private function applyRemoves()
|
||||
{
|
||||
foreach($this->menuEntriesToRemove as $menuToDelete) {
|
||||
|
||||
if(empty($menuToDelete[1])) {
|
||||
foreach ($this->menuEntriesToRemove as $menuToDelete) {
|
||||
if (empty($menuToDelete[1])) {
|
||||
// Delete Main Menu
|
||||
if(isset($this->menu[$menuToDelete[0]])) {
|
||||
if (isset($this->menu[$menuToDelete[0]])) {
|
||||
unset($this->menu[$menuToDelete[0]]);
|
||||
}
|
||||
} else {
|
||||
// Delete Sub Menu
|
||||
if(isset($this->menu[$menuToDelete[0]][$menuToDelete[1]])) {
|
||||
if (isset($this->menu[$menuToDelete[0]][$menuToDelete[1]])) {
|
||||
unset($this->menu[$menuToDelete[0]][$menuToDelete[1]]);
|
||||
}
|
||||
}
|
||||
|
|
@ -202,9 +288,10 @@ abstract class MenuAbstract extends Singleton
|
|||
{
|
||||
foreach ($this->renames as $rename) {
|
||||
$mainMenuOriginal = $rename[0];
|
||||
$subMenuOriginal = $rename[1];
|
||||
$mainMenuRenamed = $rename[2];
|
||||
$subMenuRenamed = $rename[3];
|
||||
$subMenuOriginal = $rename[1];
|
||||
$mainMenuRenamed = $rename[2];
|
||||
$subMenuRenamed = $rename[3];
|
||||
|
||||
// Are we changing a submenu?
|
||||
if (!empty($subMenuOriginal)) {
|
||||
if (isset($this->menu[$mainMenuOriginal][$subMenuOriginal])) {
|
||||
|
|
@ -214,7 +301,7 @@ abstract class MenuAbstract extends Singleton
|
|||
$this->menu[$mainMenuRenamed][$subMenuRenamed] = $save;
|
||||
}
|
||||
} // Changing a first-level element
|
||||
else if (isset($this->menu[$mainMenuOriginal])) {
|
||||
elseif (isset($this->menu[$mainMenuOriginal])) {
|
||||
$save = $this->menu[$mainMenuOriginal];
|
||||
$save['_name'] = $mainMenuRenamed;
|
||||
unset($this->menu[$mainMenuOriginal]);
|
||||
|
|
@ -238,7 +325,7 @@ abstract class MenuAbstract extends Singleton
|
|||
foreach ($this->menu as $key => &$element) {
|
||||
if (is_null($element)) {
|
||||
unset($this->menu[$key]);
|
||||
} else if ($element['_hasSubmenu']) {
|
||||
} elseif ($element['_hasSubmenu']) {
|
||||
uasort($element, array($this, 'menuCompare'));
|
||||
}
|
||||
}
|
||||
|
|
@ -255,15 +342,36 @@ abstract class MenuAbstract extends Singleton
|
|||
*/
|
||||
protected function menuCompare($itemOne, $itemTwo)
|
||||
{
|
||||
if (!is_array($itemOne) || !is_array($itemTwo)
|
||||
|| !isset($itemOne['_order']) || !isset($itemTwo['_order'])
|
||||
) {
|
||||
if (!is_array($itemOne) && !is_array($itemTwo)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($itemOne['_order'] == $itemTwo['_order']) {
|
||||
return strcmp($itemOne['_name'], $itemTwo['_name']);
|
||||
if (!is_array($itemOne) && is_array($itemTwo)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_array($itemOne) && !is_array($itemTwo)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isset($itemOne['_order']) && isset($itemTwo['_order'])) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (isset($itemOne['_order']) && !isset($itemTwo['_order'])) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($itemOne['_order'] == $itemTwo['_order']) {
|
||||
return strcmp(
|
||||
@$itemOne['_name'],
|
||||
@$itemTwo['_name']);
|
||||
}
|
||||
|
||||
return ($itemOne['_order'] < $itemTwo['_order']) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -11,15 +11,15 @@ namespace Piwik\Menu;
|
|||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Contains menu entries for the Admin menu. Plugins can subscribe to the
|
||||
* {@hook Menu.Admin.addItems} event to add new pages to the admin menu.
|
||||
*
|
||||
* Contains menu entries for the Admin menu.
|
||||
* Plugins can implement the `configureAdminMenu()` method of the `Menu` plugin class to add, rename of remove
|
||||
* items. If your plugin does not have a `Menu` class yet you can create one using `./console generate:menu`.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* // add a new page in an observer to Menu.Admin.addItems
|
||||
* public function addAdminMenuItem()
|
||||
*
|
||||
* public function configureAdminMenu(MenuAdmin $menu)
|
||||
* {
|
||||
* MenuAdmin::getInstance()->add(
|
||||
* $menu->add(
|
||||
* 'MyPlugin_MyTranslatedAdminMenuCategory',
|
||||
* 'MyPlugin_MyTranslatedAdminPageName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
|
|
@ -27,25 +27,79 @@ use Piwik\Piwik;
|
|||
* $order = 2
|
||||
* );
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @method static \Piwik\Menu\MenuAdmin getInstance()
|
||||
*/
|
||||
class MenuAdmin extends MenuAbstract
|
||||
{
|
||||
/**
|
||||
* Adds a new AdminMenu entry under the 'Settings' category.
|
||||
*
|
||||
* @param string $adminMenuName The name of the admin menu entry. Can be a translation token.
|
||||
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
|
||||
* that can be used to build the URL.
|
||||
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
|
||||
* current user. If false, the entry will not be added.
|
||||
* @param int $order The order hint.
|
||||
* See {@link add()}. Adds a new menu item to the development section of the admin menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public static function addEntry($adminMenuName, $url, $displayedForCurrentUser = true, $order = 20)
|
||||
public function addDevelopmentItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
self::getInstance()->add('General_Settings', $adminMenuName, $url, $displayedForCurrentUser, $order);
|
||||
$this->addItem('CoreAdminHome_MenuDevelopment', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the diagnostic section of the admin menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addDiagnosticItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('CoreAdminHome_MenuDiagnostic', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the platform section of the admin menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addPlatformItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('CorePluginsAdmin_MenuPlatform', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the settings section of the admin menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addSettingsItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('General_Settings', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the manage section of the admin menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addManageItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('CoreAdminHome_Administration', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -58,56 +112,16 @@ class MenuAdmin extends MenuAbstract
|
|||
if (!$this->menu) {
|
||||
|
||||
/**
|
||||
* Triggered when collecting all available admin menu items. Subscribe to this event if you want
|
||||
* to add one or more items to the Piwik admin menu.
|
||||
*
|
||||
* Menu items should be added via the {@link add()} method.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* use Piwik\Menu\MenuAdmin;
|
||||
*
|
||||
* public function addMenuItems()
|
||||
* {
|
||||
* MenuAdmin::getInstance()->add(
|
||||
* 'MenuName',
|
||||
* 'SubmenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
|
||||
* $order = 6
|
||||
* );
|
||||
* }
|
||||
* @ignore
|
||||
* @deprecated
|
||||
*/
|
||||
Piwik::postEvent('Menu.Admin.addItems');
|
||||
}
|
||||
return parent::getMenu();
|
||||
}
|
||||
Piwik::postEvent('Menu.Admin.addItems', array());
|
||||
|
||||
/**
|
||||
* Returns the current AdminMenu name
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCurrentAdminMenuName()
|
||||
{
|
||||
$menu = MenuAdmin::getInstance()->getMenu();
|
||||
$currentModule = Piwik::getModule();
|
||||
$currentAction = Piwik::getAction();
|
||||
foreach ($menu as $submenu) {
|
||||
foreach ($submenu as $subMenuName => $parameters) {
|
||||
if (strpos($subMenuName, '_') !== 0 &&
|
||||
$parameters['_url']['module'] == $currentModule
|
||||
&& $parameters['_url']['action'] == $currentAction
|
||||
) {
|
||||
return $subMenuName;
|
||||
}
|
||||
foreach ($this->getAllMenus() as $menu) {
|
||||
$menu->configureAdminMenu($this);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function removeEntry($menuName, $subMenuName = false)
|
||||
{
|
||||
MenuAdmin::getInstance()->remove($menuName, $subMenuName);
|
||||
return parent::getMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,91 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Menu;
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Contains menu entries for the Main menu (the menu displayed under the Piwik logo).
|
||||
* Plugins can subscribe to the {@hook Menu.Reporting.addItems} event to add new pages to
|
||||
* the main menu.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* // add a new page in an observer to Menu.Admin.addItems
|
||||
* public function addMainMenuItem()
|
||||
* {
|
||||
* MenuMain::getInstance()->add(
|
||||
* 'MyPlugin_MyTranslatedMenuCategory',
|
||||
* 'MyPlugin_MyTranslatedMenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* Piwik::isUserHasSomeAdminAccess(),
|
||||
* $order = 2
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* @api
|
||||
* @method static \Piwik\Menu\MenuMain getInstance()
|
||||
* @deprecated since 2.4.0
|
||||
* @see MenuReporting
|
||||
* @method static MenuMain getInstance()
|
||||
* @ignore
|
||||
*/
|
||||
class MenuMain extends MenuAbstract
|
||||
class MenuMain extends MenuReporting
|
||||
{
|
||||
/**
|
||||
* Returns if the URL was found in the menu.
|
||||
*
|
||||
* @param string $url
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUrlFound($url)
|
||||
{
|
||||
$menu = MenuMain::getInstance()->getMenu();
|
||||
|
||||
foreach ($menu as $subMenus) {
|
||||
foreach ($subMenus as $subMenuName => $menuUrl) {
|
||||
if (strpos($subMenuName, '_') !== 0 && $menuUrl['_url'] == $url) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the Menu.Reporting.addItems hook and returns the menu.
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getMenu()
|
||||
{
|
||||
// We trigger the Event only once!
|
||||
if (!$this->menu) {
|
||||
|
||||
/**
|
||||
* Triggered when collecting all available reporting menu items. Subscribe to this event if you
|
||||
* want to add one or more items to the Piwik reporting menu.
|
||||
*
|
||||
* Menu items should be added via the {@link add()} method.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* use Piwik\Menu\Main;
|
||||
*
|
||||
* public function addMenuItems()
|
||||
* {
|
||||
* Main::getInstance()->add(
|
||||
* 'CustomMenuName',
|
||||
* 'CustomSubmenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
|
||||
* $order = 6
|
||||
* );
|
||||
* }
|
||||
*/
|
||||
Piwik::postEvent('Menu.Reporting.addItems');
|
||||
}
|
||||
return parent::getMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
143
www/analytics/core/Menu/MenuReporting.php
Normal file
143
www/analytics/core/Menu/MenuReporting.php
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Menu;
|
||||
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\Report;
|
||||
|
||||
/**
|
||||
* Contains menu entries for the Reporting menu (the menu displayed under the Piwik logo).
|
||||
* Plugins can implement the `configureReportingMenu()` method of the `Menu` plugin class to add, rename of remove
|
||||
* items. If your plugin does not have a `Menu` class yet you can create one using `./console generate:menu`.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* public function configureReportingMenu(MenuReporting $menu)
|
||||
* {
|
||||
* $menu->add(
|
||||
* 'MyPlugin_MyTranslatedMenuCategory',
|
||||
* 'MyPlugin_MyTranslatedMenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* Piwik::isUserHasSomeAdminAccess(),
|
||||
* $order = 2
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* @api
|
||||
* @method static \Piwik\Menu\MenuReporting getInstance()
|
||||
*/
|
||||
class MenuReporting extends MenuAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the visitors section of the reporting menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addVisitorsItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('General_Visitors', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the actions section of the reporting menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addActionsItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('General_Actions', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should not be a public API yet. We probably have to change the API once we have another use case.
|
||||
* @ignore
|
||||
*/
|
||||
public function addGroup($menuName, $defaultTitle, Group $group, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->menuEntries[] = array(
|
||||
$menuName,
|
||||
$defaultTitle,
|
||||
$group,
|
||||
$order,
|
||||
$tooltip
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the referrers section of the reporting menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addReferrersItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('Referrers_Referrers', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the URL was found in the menu.
|
||||
*
|
||||
* @param string $url
|
||||
* @return boolean
|
||||
*/
|
||||
public function isUrlFound($url)
|
||||
{
|
||||
$menu = $this->getMenu();
|
||||
|
||||
foreach ($menu as $subMenus) {
|
||||
foreach ($subMenus as $subMenuName => $menuUrl) {
|
||||
if (strpos($subMenuName, '_') !== 0 && $menuUrl['_url'] == $url) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the Menu.Reporting.addItems hook and returns the menu.
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getMenu()
|
||||
{
|
||||
if (!$this->menu) {
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
* @deprecated
|
||||
*/
|
||||
Piwik::postEvent('Menu.Reporting.addItems', array());
|
||||
|
||||
foreach (Report::getAllReports() as $report) {
|
||||
if ($report->isEnabled()) {
|
||||
$report->configureReportingMenu($this);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->getAllMenus() as $menu) {
|
||||
$menu->configureReportingMenu($this);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getMenu();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +1,25 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Menu;
|
||||
use Piwik\Piwik;
|
||||
|
||||
use Piwik\Piwik;
|
||||
|
||||
/**
|
||||
* Contains menu entries for the Top menu (the menu at the very top of the page).
|
||||
* Plugins can subscribe to the {@hook Menu.Top.addItems} event to add new pages to
|
||||
* the top menu.
|
||||
*
|
||||
* Plugins can implement the `configureTopMenu()` method of the `Menu` plugin class to add, rename of remove
|
||||
* items. If your plugin does not have a `Menu` class yet you can create one using `./console generate:menu`.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* // add a new page in an observer to Menu.Admin.addItems
|
||||
* public function addTopMenuItem()
|
||||
*
|
||||
* public function configureTopMenu(MenuTop $menu)
|
||||
* {
|
||||
* MenuTop::getInstance()->add(
|
||||
* $menu->add(
|
||||
* 'MyPlugin_MyTranslatedMenuCategory',
|
||||
* 'MyPlugin_MyTranslatedMenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
|
|
@ -28,40 +27,11 @@ use Piwik\Piwik;
|
|||
* $order = 2
|
||||
* );
|
||||
* }
|
||||
*
|
||||
*
|
||||
* @method static \Piwik\Menu\MenuTop getInstance()
|
||||
*/
|
||||
class MenuTop extends MenuAbstract
|
||||
{
|
||||
/**
|
||||
* Adds a new entry to the TopMenu.
|
||||
*
|
||||
* @param string $topMenuName The menu item name. Can be a translation token.
|
||||
* @param string|array $url The URL the admin menu entry should link to, or an array of query parameters
|
||||
* that can be used to build the URL. If `$isHTML` is true, this can be a string with
|
||||
* HTML that is simply embedded.
|
||||
* @param boolean $displayedForCurrentUser Whether this menu entry should be displayed for the
|
||||
* current user. If false, the entry will not be added.
|
||||
* @param int $order The order hint.
|
||||
* @param bool $isHTML Whether `$url` is an HTML string or a URL that will be rendered as a link.
|
||||
* @param bool|string $tooltip Optional tooltip to display.
|
||||
* @api
|
||||
*/
|
||||
public static function addEntry($topMenuName, $url, $displayedForCurrentUser = true, $order = 10, $isHTML = false, $tooltip = false)
|
||||
{
|
||||
if ($isHTML) {
|
||||
MenuTop::getInstance()->addHtml($topMenuName, $url, $displayedForCurrentUser, $order, $tooltip);
|
||||
} else {
|
||||
MenuTop::getInstance()->add($topMenuName, null, $url, $displayedForCurrentUser, $order, $tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
public static function removeEntry($menuName, $subMenuName = false)
|
||||
{
|
||||
MenuTop::getInstance()->remove($menuName, $subMenuName);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Directly adds a menu entry containing html.
|
||||
*
|
||||
|
|
@ -70,11 +40,13 @@ class MenuTop extends MenuAbstract
|
|||
* @param boolean $displayedForCurrentUser
|
||||
* @param int $order
|
||||
* @param string $tooltip Tooltip to display.
|
||||
* @api
|
||||
*/
|
||||
public function addHtml($menuName, $data, $displayedForCurrentUser, $order, $tooltip)
|
||||
{
|
||||
if ($displayedForCurrentUser) {
|
||||
if (!isset($this->menu[$menuName])) {
|
||||
$this->menu[$menuName]['_name'] = $menuName;
|
||||
$this->menu[$menuName]['_html'] = $data;
|
||||
$this->menu[$menuName]['_order'] = $order;
|
||||
$this->menu[$menuName]['_hasSubmenu'] = false;
|
||||
|
|
@ -93,29 +65,16 @@ class MenuTop extends MenuAbstract
|
|||
if (!$this->menu) {
|
||||
|
||||
/**
|
||||
* Triggered when collecting all available menu items that are be displayed on the very top of every
|
||||
* page, next to the login/logout links.
|
||||
*
|
||||
* Subscribe to this event if you want to add one or more items to the top menu.
|
||||
*
|
||||
* Menu items should be added via the {@link addEntry()} method.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* use Piwik\Menu\MenuTop;
|
||||
*
|
||||
* public function addMenuItems()
|
||||
* {
|
||||
* MenuTop::addEntry(
|
||||
* 'TopMenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* $showOnlyIf = Piwik::hasUserSuperUserAccess(),
|
||||
* $order = 6
|
||||
* );
|
||||
* }
|
||||
* @ignore
|
||||
* @deprecated
|
||||
*/
|
||||
Piwik::postEvent('Menu.Top.addItems');
|
||||
Piwik::postEvent('Menu.Top.addItems', array());
|
||||
|
||||
foreach ($this->getAllMenus() as $menu) {
|
||||
$menu->configureTopMenu($this);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
91
www/analytics/core/Menu/MenuUser.php
Executable file
91
www/analytics/core/Menu/MenuUser.php
Executable file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*
|
||||
*/
|
||||
namespace Piwik\Menu;
|
||||
|
||||
/**
|
||||
* Contains menu entries for the User menu (the menu at the very top of the page).
|
||||
* Plugins can implement the `configureUserMenu()` method of the `Menu` plugin class to add, rename of remove
|
||||
* items. If your plugin does not have a `Menu` class yet you can create one using `./console generate:menu`.
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
* public function configureUserMenu(MenuUser $menu)
|
||||
* {
|
||||
* $menu->add(
|
||||
* 'MyPlugin_MyTranslatedMenuCategory',
|
||||
* 'MyPlugin_MyTranslatedMenuName',
|
||||
* array('module' => 'MyPlugin', 'action' => 'index'),
|
||||
* Piwik::isUserHasSomeAdminAccess(),
|
||||
* $order = 2
|
||||
* );
|
||||
* }
|
||||
*
|
||||
* @method static MenuUser getInstance()
|
||||
*/
|
||||
class MenuUser extends MenuAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the manage section of the user menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addPersonalItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('UsersManager_MenuPersonal', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the manage section of the user menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addManageItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('CoreAdminHome_MenuManage', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link add()}. Adds a new menu item to the platform section of the user menu.
|
||||
* @param string $menuName
|
||||
* @param array $url
|
||||
* @param int $order
|
||||
* @param bool|string $tooltip
|
||||
* @api
|
||||
* @since 2.5.0
|
||||
*/
|
||||
public function addPlatformItem($menuName, $url, $order = 50, $tooltip = false)
|
||||
{
|
||||
$this->addItem('CorePluginsAdmin_MenuPlatform', $menuName, $url, $order, $tooltip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers the Menu.User.addItems hook and returns the menu.
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function getMenu()
|
||||
{
|
||||
if (!$this->menu) {
|
||||
foreach ($this->getAllMenus() as $menu) {
|
||||
$menu->configureUserMenu($this);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getMenu();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue