PDF rausgenommen
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
<?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\Plugins\ExampleSettingsPlugin;
|
||||
|
||||
use Piwik\Plugins\MobileAppMeasurable\Type as MobileAppType;
|
||||
use Piwik\Settings\Setting;
|
||||
use Piwik\Settings\FieldConfig;
|
||||
|
||||
/**
|
||||
* Defines Settings for ExampleSettingsPlugin.
|
||||
*
|
||||
* Usage like this:
|
||||
* // require Piwik\Plugin\SettingsProvider via Dependency Injection eg in constructor of your class
|
||||
* $settings = $settingsProvider->getMeasurableSettings('ExampleSettingsPlugin', $idSite);
|
||||
* $settings->appId->getValue();
|
||||
* $settings->contactEmails->getValue();
|
||||
*/
|
||||
class MeasurableSettings extends \Piwik\Settings\Measurable\MeasurableSettings
|
||||
{
|
||||
/** @var Setting|null */
|
||||
public $appId;
|
||||
|
||||
/** @var Setting */
|
||||
public $contactEmails;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
if ($this->hasMeasurableType(MobileAppType::ID)) {
|
||||
// this setting will be only shown for mobile apps
|
||||
$this->appId = $this->makeAppIdSetting();
|
||||
}
|
||||
|
||||
$this->contactEmails = $this->makeContactEmailsSetting();
|
||||
}
|
||||
|
||||
private function makeAppIdSetting()
|
||||
{
|
||||
$defaultValue = '';
|
||||
$type = FieldConfig::TYPE_STRING;
|
||||
|
||||
return $this->makeSetting('mobile_app_id', $defaultValue, $type, function (FieldConfig $field) {
|
||||
$field->title = 'App ID';
|
||||
$field->inlineHelp = 'Enter the id of the mobile app eg "org.domain.example"';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
|
||||
});
|
||||
}
|
||||
|
||||
private function makeContactEmailsSetting()
|
||||
{
|
||||
$defaultValue = array();
|
||||
$type = FieldConfig::TYPE_ARRAY;
|
||||
|
||||
return $this->makeSetting('contact_email', $defaultValue, $type, function (FieldConfig $field) {
|
||||
$field->title = 'Contact email addresses';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
<?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\Plugins\ExampleSettingsPlugin;
|
||||
|
||||
use Piwik\Settings\Setting;
|
||||
use Piwik\Settings\FieldConfig;
|
||||
use Piwik\Validators\NotEmpty;
|
||||
|
||||
/**
|
||||
* Defines Settings for ExampleSettingsPlugin.
|
||||
*
|
||||
* Usage like this:
|
||||
* $settings = new SystemSettings();
|
||||
* $settings->metric->getValue();
|
||||
* $settings->description->getValue();
|
||||
*/
|
||||
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
|
||||
{
|
||||
/** @var Setting */
|
||||
public $metric;
|
||||
|
||||
/** @var Setting */
|
||||
public $browsers;
|
||||
|
||||
/** @var Setting */
|
||||
public $description;
|
||||
|
||||
/** @var Setting */
|
||||
public $password;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
// System setting --> allows selection of a single value
|
||||
$this->metric = $this->createMetricSetting();
|
||||
|
||||
// System setting --> allows selection of multiple values
|
||||
$this->browsers = $this->createBrowsersSetting();
|
||||
|
||||
// System setting --> textarea
|
||||
$this->description = $this->createDescriptionSetting();
|
||||
|
||||
// System setting --> textarea
|
||||
$this->password = $this->createPasswordSetting();
|
||||
}
|
||||
|
||||
private function createMetricSetting()
|
||||
{
|
||||
return $this->makeSetting('metric', $default = 'nb_visits', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
|
||||
$field->title = 'Metric to display';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
|
||||
$field->availableValues = array('nb_visits' => 'Visits', 'nb_actions' => 'Actions', 'visitors' => 'Visitors');
|
||||
$field->description = 'Choose the metric that should be displayed in the browser tab';
|
||||
$field->validators[] = new NotEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private function createBrowsersSetting()
|
||||
{
|
||||
$default = array('firefox', 'chromium', 'safari');
|
||||
|
||||
return $this->makeSetting('browsers', $default, FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
|
||||
$field->title = 'Supported Browsers';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_MULTI_SELECT;
|
||||
$field->availableValues = array('firefox' => 'Firefox', 'chromium' => 'Chromium', 'safari' => 'safari');
|
||||
$field->description = 'The value will be only displayed in the following browsers';
|
||||
});
|
||||
}
|
||||
|
||||
private function createDescriptionSetting()
|
||||
{
|
||||
$default = "This is the value: \nAnother line";
|
||||
|
||||
return $this->makeSetting('description', $default, FieldConfig::TYPE_STRING, function (FieldConfig $field) {
|
||||
$field->title = 'Description for value';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
|
||||
$field->description = 'This description will be displayed next to the value';
|
||||
$field->validators[] = new NotEmpty();
|
||||
});
|
||||
}
|
||||
|
||||
private function createPasswordSetting()
|
||||
{
|
||||
return $this->makeSetting('password', $default = null, FieldConfig::TYPE_STRING, function (FieldConfig $field) {
|
||||
$field->title = 'API password';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_PASSWORD;
|
||||
$field->description = 'Password for the 3rd API where we fetch the value';
|
||||
$field->transform = function ($value) {
|
||||
return sha1($value . 'salt');
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
<?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\Plugins\ExampleSettingsPlugin;
|
||||
|
||||
use Piwik\Settings\Setting;
|
||||
use Piwik\Settings\FieldConfig;
|
||||
|
||||
/**
|
||||
* Defines Settings for ExampleSettingsPlugin.
|
||||
*
|
||||
* Usage like this:
|
||||
* $settings = new UserSettings();
|
||||
* $settings->autoRefresh->getValue();
|
||||
* $settings->color->getValue();
|
||||
*/
|
||||
class UserSettings extends \Piwik\Settings\Plugin\UserSettings
|
||||
{
|
||||
/** @var Setting */
|
||||
public $autoRefresh;
|
||||
|
||||
/** @var Setting */
|
||||
public $refreshInterval;
|
||||
|
||||
/** @var Setting */
|
||||
public $color;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
// User setting --> checkbox converted to bool
|
||||
$this->autoRefresh = $this->createAutoRefreshSetting();
|
||||
|
||||
// User setting --> textbox converted to int defining a validator and filter
|
||||
$this->refreshInterval = $this->createRefreshIntervalSetting();
|
||||
|
||||
// User setting --> radio
|
||||
$this->color = $this->createColorSetting();
|
||||
}
|
||||
|
||||
private function createAutoRefreshSetting()
|
||||
{
|
||||
return $this->makeSetting('autoRefresh', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
|
||||
$field->title = 'Auto refresh';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
|
||||
$field->description = 'If enabled, the value will be automatically refreshed depending on the specified interval';
|
||||
});
|
||||
}
|
||||
|
||||
private function createRefreshIntervalSetting()
|
||||
{
|
||||
return $this->makeSetting('refreshInterval', $default = '30', FieldConfig::TYPE_INT, function (FieldConfig $field) {
|
||||
$field->title = 'Refresh Interval';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_TEXT;
|
||||
$field->uiControlAttributes = array('size' => 3);
|
||||
$field->description = 'Defines how often the value should be updated';
|
||||
$field->inlineHelp = 'Enter a number which is >= 15';
|
||||
$field->validate = function ($value, $setting) {
|
||||
if ($value < 15) {
|
||||
throw new \Exception('Value is invalid');
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private function createColorSetting()
|
||||
{
|
||||
return $this->makeSetting('color', $default = 'red', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
|
||||
$field->title = 'Color';
|
||||
$field->uiControl = FieldConfig::UI_CONTROL_RADIO;
|
||||
$field->description = 'Pick your favourite color';
|
||||
$field->availableValues = array('red' => 'Red', 'blue' => 'Blue', 'green' => 'Green');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "ExampleSettingsPlugin",
|
||||
"version": "0.1.0",
|
||||
"description": "Matomo Platform showcase: how to define and how to access plugin settings.",
|
||||
"theme": false
|
||||
}
|
Reference in New Issue
Block a user