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

GetSystemSummary.php « Widgets « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 362fc6817cba6f1363ba35dc379f34f004ed1636 (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
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
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */
namespace Piwik\Plugins\CoreHome\Widgets;

use Piwik\API\Request;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\CoreHome\SystemSummary\Item;
use Piwik\Plugins\SegmentEditor\Services\StoredSegmentService;
use Piwik\Version;
use Piwik\Widget\Widget;
use Piwik\Widget\WidgetConfig;

class GetSystemSummary extends Widget
{
    const TEST_MYSQL_VERSION = 'mysql-version-redacted';
    /**
     * @var StoredSegmentService
     */
    private $storedSegmentService;

    /**
     * @var Plugin\Manager
     */
    private $pluginManager;

    public function __construct(StoredSegmentService $storedSegmentService, Plugin\Manager $pluginManager)
    {
        $this->storedSegmentService = $storedSegmentService;
        $this->pluginManager = $pluginManager;
    }

    public static function configure(WidgetConfig $config)
    {
        $config->setCategoryId('About Matomo');
        $config->setName('CoreHome_SystemSummaryWidget');
        $config->setOrder(15);
        $config->setIsEnabled(Piwik::hasUserSuperUserAccess());
    }

    public function render()
    {
        $mysqlVersion = $this->getMySqlVersion();

        $systemSummary = array();

        /**
         * Triggered to add system summary items that are shown in the System Summary widget.
         *
         * **Example**
         *
         *     public function addSystemSummaryItem(&$systemSummary)
         *     {
         *         $numUsers = 5;
         *         $systemSummary[] = new SystemSummary\Item($key = 'users', Piwik::translate('General_NUsers', $numUsers), $value = null, array('module' => 'UsersManager', 'action' => 'index'), $icon = 'icon-user');
         *     }
         *
         * @param Item[] &$systemSummary An array containing system summary items.
         */
        Piwik::postEvent('System.addSystemSummaryItems', array(&$systemSummary));

        $systemSummary[] = new Item($key = 'piwik-version', Piwik::translate('CoreHome_SystemSummaryPiwikVersion'), Version::VERSION, $url = null, $icon = '', $order = 21);
        $systemSummary[] = new Item($key = 'mysql-version', Piwik::translate('CoreHome_SystemSummaryMysqlVersion'), $mysqlVersion, $url = null, $icon = '', $order = 22);
        $systemSummary[] = new Item($key = 'php-version', Piwik::translate('CoreHome_SystemSummaryPhpVersion'), phpversion(), $url = null, $icon = '', $order = 23);

        $systemSummary = array_filter($systemSummary);
        usort($systemSummary, function ($itemA, $itemB) {
            if ($itemA->getOrder() == $itemB->getOrder()) {
                return 0;
            }
            if ($itemA->getOrder() > $itemB->getOrder()) {
                return 1;
            }
            return -1;
        });

        /**
         * Triggered to filter system summary items that are shown in the System Summary widget. A plugin might also
         * sort the system summary items differently.
         *
         * **Example**
         *
         *     public function filterSystemSummaryItems(&$systemSummary)
         *     {
         *         foreach ($systemSummaryItems as $index => $item) {
         *             if ($item && $item->getKey() === 'users') {
         *                 $systemSummaryItems[$index] = null;
         *             }
         *         }
         *     }
         *
         * @param Item[] &$systemSummary An array containing system summary items.
         */
        Piwik::postEvent('System.filterSystemSummaryItems', array(&$systemSummary));

        $systemSummary = array_filter($systemSummary);

        return $this->renderTemplate('getSystemSummary', array(
            'items' => $systemSummary
        ));
    }

    private function getMySqlVersion()
    {
        if (defined('PIWIK_TEST_MODE')) {
            return self::TEST_MYSQL_VERSION;
        }

        $db = Db::get();
        return $db->getServerVersion();
    }

}