Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Admin.php « Menu « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8d67d2d61a49159ec71edf9d5388f5aef6371508 (plain)
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
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Piwik
 * @package Piwik_Menu
 */
namespace Piwik\Menu;


use Piwik\Piwik;

/**
 * @package Piwik_Menu
 */
class Admin extends MenuAbstract
{
    static private $instance = null;

    /**
     * @return \Piwik\Menu\Admin
     */
    static public function getInstance()
    {
        if (self::$instance == null) {
            self::$instance = new self;
        }
        return self::$instance;
    }

    /**
     * Triggers the Menu.Admin.addItems hook and returns the menu.
     *
     * @return Array
     */
    public function get()
    {
        if (!$this->menu) {

            /**
             * This event is triggered to collect all available admin menu items. Subscribe to this event if you want
             * to add one or more items to the Piwik admin menu. It's fairly easy. Just define the name of your menu
             * item as well as a controller and an action that should be executed once a user selects your menu item.
             * It is also possible to display the item only for users having a specific role.
             *
             * Example:
             * ```
             * public function addMenuItems()
             * {
             *     Piwik_AddAdminSubMenu(
             *         'MenuName',
             *         'SubmenuName',
             *         array('module' => 'MyPlugin', 'action' => 'index'),
             *         Piwik::isUserIsSuperUser(),
             *         $order = 6
             *     );
             * }
             * ```
             */
            Piwik_PostEvent('Menu.Admin.addItems');
        }
        return parent::get();
    }

    /**
     * Returns the current AdminMenu name
     *
     * @return boolean
     */
    function getCurrentAdminMenuName()
    {
        $menu = Piwik_GetAdminMenu();
        $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;
                }
            }
        }
        return false;
    }
}