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
|
|
@ -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
|
||||
|
|
@ -9,6 +9,9 @@
|
|||
|
||||
namespace Piwik\Settings;
|
||||
|
||||
use Piwik\Piwik;
|
||||
use Piwik\SettingsServer;
|
||||
|
||||
/**
|
||||
* Base setting type class.
|
||||
*
|
||||
|
|
@ -19,7 +22,7 @@ abstract class Setting
|
|||
/**
|
||||
* Describes the setting's PHP data type. When saved, setting values will always be casted to this
|
||||
* type.
|
||||
*
|
||||
*
|
||||
* See {@link Piwik\Plugin\Settings} for a list of supported data types.
|
||||
*
|
||||
* @var string
|
||||
|
|
@ -30,7 +33,7 @@ abstract class Setting
|
|||
* Describes what HTML element should be used to manipulate the setting through Piwik's UI.
|
||||
*
|
||||
* See {@link Piwik\Plugin\Settings} for a list of supported control types.
|
||||
*
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $uiControlType = null;
|
||||
|
|
@ -38,22 +41,22 @@ abstract class Setting
|
|||
/**
|
||||
* Name-value mapping of HTML attributes that will be added HTML form control, eg,
|
||||
* `array('size' => 3)`. Attributes will be escaped before outputting.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $uiControlAttributes = array();
|
||||
|
||||
/**
|
||||
* The list of all available values for this setting. If null, the setting can have any value.
|
||||
*
|
||||
*
|
||||
* If supplied, this field should be an array mapping available values with their prettified
|
||||
* display value. Eg, if set to `array('nb_visits' => 'Visits', 'nb_actions' => 'Actions')`,
|
||||
* the UI will display **Visits** and **Actions**, and when the user selects one, Piwik will
|
||||
* set the setting to **nb_visits** or **nb_actions** respectively.
|
||||
*
|
||||
*
|
||||
* The setting value will be validated if this field is set. If the value is not one of the
|
||||
* available values, an error will be triggered.
|
||||
*
|
||||
*
|
||||
* _Note: If a custom validator is supplied (see {@link $validate}), the setting value will
|
||||
* not be validated._
|
||||
*
|
||||
|
|
@ -63,7 +66,7 @@ abstract class Setting
|
|||
|
||||
/**
|
||||
* Text that will appear above this setting's section in the _Plugin Settings_ admin page.
|
||||
*
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $introduction = null;
|
||||
|
|
@ -71,7 +74,7 @@ abstract class Setting
|
|||
/**
|
||||
* Text that will appear directly underneath the setting title in the _Plugin Settings_ admin
|
||||
* page. If set, should be a short description of the setting.
|
||||
*
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $description = null;
|
||||
|
|
@ -80,20 +83,20 @@ abstract class Setting
|
|||
* Text that will appear next to the setting's section in the _Plugin Settings_ admin page. If set,
|
||||
* it should contain information about the setting that is more specific than a general description,
|
||||
* such as the format of the setting value if it has a special format.
|
||||
*
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $inlineHelp = null;
|
||||
|
||||
/**
|
||||
* A closure that does some custom validation on the setting before the setting is persisted.
|
||||
*
|
||||
*
|
||||
* The closure should take two arguments: the setting value and the {@link Setting} instance being
|
||||
* validated. If the value is found to be invalid, the closure should throw an exception with
|
||||
* a message that describes the error.
|
||||
*
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
*
|
||||
* $setting->validate = function ($value, Setting $setting) {
|
||||
* if ($value > 60) {
|
||||
* throw new \Exception('The time limit is not allowed to be greater than 60 minutes.');
|
||||
|
|
@ -107,13 +110,13 @@ abstract class Setting
|
|||
/**
|
||||
* A closure that transforms the setting value. If supplied, this closure will be executed after
|
||||
* the setting has been validated.
|
||||
*
|
||||
*
|
||||
* _Note: If a transform is supplied, the setting's {@link $type} has no effect. This means the
|
||||
* transformation function will be responsible for casting the setting value to the appropriate
|
||||
* data type._
|
||||
*
|
||||
* **Example**
|
||||
*
|
||||
*
|
||||
* $setting->transform = function ($value, Setting $setting) {
|
||||
* if ($value > 30) {
|
||||
* $value = 30;
|
||||
|
|
@ -128,7 +131,7 @@ abstract class Setting
|
|||
|
||||
/**
|
||||
* Default value of this setting.
|
||||
*
|
||||
*
|
||||
* The default value is not casted to the appropriate data type. This means _**you**_ have to make
|
||||
* sure the value is of the correct type.
|
||||
*
|
||||
|
|
@ -145,12 +148,12 @@ abstract class Setting
|
|||
|
||||
protected $key;
|
||||
protected $name;
|
||||
protected $displayedForCurrentUser = false;
|
||||
|
||||
/**
|
||||
* @var StorageInterface
|
||||
*/
|
||||
private $storage;
|
||||
protected $pluginName;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
|
@ -168,7 +171,7 @@ abstract class Setting
|
|||
|
||||
/**
|
||||
* Returns the setting's persisted name, eg, `'refreshInterval'`.
|
||||
*
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
|
|
@ -177,46 +180,142 @@ abstract class Setting
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this setting can be displayed for the current user, `false` if otherwise.
|
||||
*
|
||||
* Returns `true` if this setting is writable for the current user, `false` if otherwise. In case it returns
|
||||
* writable for the current user it will be visible in the Plugin settings UI.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canBeDisplayedForCurrentUser()
|
||||
public function isWritableByCurrentUser()
|
||||
{
|
||||
return $this->displayedForCurrentUser;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if this setting can be displayed for the current user, `false` if otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isReadableByCurrentUser()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the object used to persist settings.
|
||||
*
|
||||
* @return StorageInterface
|
||||
*
|
||||
* @param StorageInterface $storage
|
||||
*/
|
||||
public function setStorage(StorageInterface $storage)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @ignore
|
||||
* @return StorageInterface
|
||||
*/
|
||||
public function getStorage()
|
||||
{
|
||||
return $this->storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets th name of the plugin the setting belongs to
|
||||
*
|
||||
* @param string $pluginName
|
||||
*/
|
||||
public function setPluginName($pluginName)
|
||||
{
|
||||
$this->pluginName = $pluginName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previously persisted setting value. If no value was set, the default value
|
||||
* is returned.
|
||||
*
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception If the current user is not allowed to change the value of this setting.
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->storage->getSettingValue($this);
|
||||
$this->checkHasEnoughReadPermission();
|
||||
|
||||
return $this->storage->getValue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the previously persisted setting value. If no value was set, the default value
|
||||
* is returned.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \Exception If the current user is not allowed to change the value of this setting.
|
||||
*/
|
||||
public function removeValue()
|
||||
{
|
||||
$this->checkHasEnoughWritePermission();
|
||||
|
||||
return $this->storage->deleteValue($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets and persists this setting's value overwriting any existing value.
|
||||
*
|
||||
*
|
||||
* @param mixed $value
|
||||
* @throws \Exception If the current user is not allowed to change the value of this setting.
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
return $this->storage->setSettingValue($this, $value);
|
||||
$this->validateValue($value);
|
||||
|
||||
if ($this->transform && $this->transform instanceof \Closure) {
|
||||
$value = call_user_func($this->transform, $value, $this);
|
||||
} elseif (isset($this->type)) {
|
||||
settype($value, $this->type);
|
||||
}
|
||||
|
||||
return $this->storage->setValue($this, $value);
|
||||
}
|
||||
|
||||
private function validateValue($value)
|
||||
{
|
||||
$this->checkHasEnoughWritePermission();
|
||||
|
||||
if ($this->validate && $this->validate instanceof \Closure) {
|
||||
call_user_func($this->validate, $value, $this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function checkHasEnoughWritePermission()
|
||||
{
|
||||
// When the request is a Tracker request, allow plugins to write settings
|
||||
if (SettingsServer::isTrackerApiRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isWritableByCurrentUser()) {
|
||||
$errorMsg = Piwik::translate('CoreAdminHome_PluginSettingChangeNotAllowed', array($this->getName(), $this->pluginName));
|
||||
throw new \Exception($errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function checkHasEnoughReadPermission()
|
||||
{
|
||||
// When the request is a Tracker request, allow plugins to read settings
|
||||
if (SettingsServer::isTrackerApiRequest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isReadableByCurrentUser()) {
|
||||
$errorMsg = Piwik::translate('CoreAdminHome_PluginSettingReadNotAllowed', array($this->getName(), $this->pluginName));
|
||||
throw new \Exception($errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -231,7 +330,7 @@ abstract class Setting
|
|||
|
||||
/**
|
||||
* Returns the display order. The lower the return value, the earlier the setting will be displayed.
|
||||
*
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue