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

Settings.php « ExampleSettingsPlugin « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89afa86b375b1cb031bb5dcdd22d8a8f160231fa (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?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_Plugins
 * @package ExampleSettingsPlugin
 */
namespace Piwik\Plugins\ExampleSettingsPlugin;

use Piwik\Piwik;
use Piwik\Plugin\Settings as PluginSettings;
use Piwik\Settings\SystemSetting;
use Piwik\Settings\UserSetting;

/**
 * Settings
 *
 * @package ExampleSettingsPlugin
 */
class Settings extends PluginSettings
{
    protected function init()
    {
        $this->setIntroduction('Here you can specify the settings for this plugin.');

        // User setting --> checkbox converted to bool
        $this->addSetting($this->getAutoRefreshSetting());

        // User setting --> textbox converted to int defining a validator and filter
        $this->addSetting($this->getRefreshIntervalSetting());

        // System setting --> allows selection of a single value
        $this->addSetting($this->getMetricSetting());

        // System setting --> allows selection of multiple values
        $this->addSetting($this->getBrowsersSetting());

        // System setting --> textarea
         $this->addSetting($this->getDescriptionSetting());

        // System setting --> textarea
         $this->addSetting($this->getPasswordSetting());
    }

    public function isAutoRefreshEnabled()
    {
        return $this->getSettingValue($this->getAutoRefreshSetting());
    }

    public function getRefreshInterval()
    {
        return $this->getSettingValue($this->getRefreshIntervalSetting());
    }

    public function getMetric()
    {
        return $this->getSettingValue($this->getMetricSetting());
    }

    private function getAutoRefreshSetting()
    {
        $autoRefresh        = new UserSetting('autoRefresh', 'Auto refresh');
        $autoRefresh->type  = static::TYPE_BOOL;
        $autoRefresh->field = static::FIELD_CHECKBOX;
        $autoRefresh->description  = 'If enabled, the value will be automatically refreshed depending on the specified interval';
        $autoRefresh->defaultValue = false;

        return $autoRefresh;
    }

    private function getRefreshIntervalSetting()
    {
        $refreshInterval        = new UserSetting('refreshInterval', 'Refresh Interval');
        $refreshInterval->type  = static::TYPE_INT;
        $refreshInterval->field = static::FIELD_TEXT;
        $refreshInterval->fieldAttributes = array('size' => 3);
        $refreshInterval->description     = 'Defines how often the value should be updated';
        $refreshInterval->inlineHelp      = 'Enter a number which is >= 15';
        $refreshInterval->defaultValue    = '30';
        $refreshInterval->validate = function ($value, $setting) {
            if ($value < 15) {
                throw new \Exception('Value is invalid');
            }
        };
        $refreshInterval->filter = function ($value, $setting) {
            if ($value > 30) {
                $value = 30;
            }

            return $value;
        };

        return $refreshInterval;
    }

    private function getMetricSetting()
    {
        $metric        = new SystemSetting('metric', 'Metric to display');
        $metric->type  = static::TYPE_STRING;
        $metric->field = static::FIELD_SINGLE_SELECT;
        $metric->fieldOptions = array('nb_visits' => 'Visits', 'nb_actions' => 'Actions', 'visitors' => 'Visitors');
        $metric->introduction = 'Only super users can change the following settings:';
        $metric->description  = 'Choose the metric that should be displayed in the browser tab';
        $metric->defaultValue = 'nb_visits';

        return $metric;
    }

    private function getBrowsersSetting()
    {
        $browsers        = new SystemSetting('browsers', 'Supported Browsers');
        $browsers->type  = static::TYPE_ARRAY;
        $browsers->field = static::FIELD_MULTI_SELECT;
        $browsers->fieldOptions = array('firefox' => 'Firefox', 'chromium' => 'Chromium', 'safari' => 'safari');
        $browsers->description  = 'The value will be only displayed in the following browsers';
        $browsers->defaultValue = array('firefox', 'chromium', 'safari');

        return $browsers;
    }

    private function getDescriptionSetting()
    {
        $description        = new SystemSetting('description', 'Description for value');
        $description->field = static::FIELD_TEXTAREA;
        $description->description  = 'This description will be displayed next to the value';
        $description->defaultValue = "This is the value: \nAnother line";

        return $description;
    }

    private function getPasswordSetting()
    {
        $description        = new SystemSetting('password', 'API password');
        $description->field = static::FIELD_PASSWORD;
        $description->description = 'Password for the 3rd API where we fetch the value';
        $description->filter = function ($value) {
            return sha1($value . 'salt');
        };

        return $description;
    }
}