PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,73 @@
<?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\Settings\Plugin;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Setting;
use Piwik\Settings\Storage;
/**
* Describes a system wide setting. Only the Super User can change this type of setting by d efault and
* the value of this setting will affect all users.
*
* See {@link \Piwik\Settings\Setting}.
*
* @api
*/
class SystemConfigSetting extends Setting
{
protected $configSection = null;
/**
* Constructor.
*
* @param string $name The setting's persisted name.
* @param mixed $defaultValue Default value for this setting if no value was specified.
* @param string $type Eg an array, int, ... see TYPE_* constants
* @param string $pluginName The name of the plugin the system setting belongs to.
*/
public function __construct($name, $defaultValue, $type, $pluginName, $configSectionName)
{
parent::__construct($name, $defaultValue, $type, $pluginName);
$factory = StaticContainer::get('Piwik\Settings\Storage\Factory');
$this->configSection = $configSectionName;
$this->storage = $factory->getConfigStorage($configSectionName);
}
/**
* 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 isWritableByCurrentUser()
{
if (isset($this->hasWritePermission)) {
return $this->hasWritePermission;
}
// performance improvement, do not detect this in __construct otherwise likely rather "big" query to DB.
$this->hasWritePermission = Piwik::hasUserSuperUserAccess();
return $this->hasWritePermission;
}
/**
* Returns the config section the setting is for
*
* @return string
*/
public function getConfigSectionName()
{
return $this->configSection;
}
}

View File

@ -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\Settings\Plugin;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Setting;
use Piwik\Settings\Storage;
/**
* Describes a system wide setting. Only the Super User can change this type of setting by default and
* the value of this setting will affect all users.
*
* See {@link \Piwik\Settings\Setting}.
*
* @api
*/
class SystemSetting extends Setting
{
/**
* Constructor.
*
* @param string $name The setting's persisted name.
* @param mixed $defaultValue Default value for this setting if no value was specified.
* @param string $type Eg an array, int, ... see TYPE_* constants
* @param string $pluginName The name of the plugin the system setting belongs to.
*/
public function __construct($name, $defaultValue, $type, $pluginName)
{
parent::__construct($name, $defaultValue, $type, $pluginName);
$factory = StaticContainer::get('Piwik\Settings\Storage\Factory');
$this->storage = $factory->getPluginStorage($this->pluginName, $userLogin = '');
}
/**
* 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 isWritableByCurrentUser()
{
if ($this->hasConfigValue()) {
return false;
}
if (isset($this->hasWritePermission)) {
return $this->hasWritePermission;
}
// performance improvement, do not detect this in __construct otherwise likely rather "big" query to DB.
$this->hasWritePermission = Piwik::hasUserSuperUserAccess();
return $this->hasWritePermission;
}
/**
* @inheritdoc
*/
public function getValue()
{
$defaultValue = parent::getValue(); // we access value first to make sure permissions are checked
$configValue = $this->getValueFromConfig();
if (isset($configValue)) {
$defaultValue = $configValue;
settype($defaultValue, $this->type);
}
return $defaultValue;
}
private function hasConfigValue()
{
$value = $this->getValueFromConfig();
return isset($value);
}
private function getValueFromConfig()
{
$config = Config::getInstance()->{$this->pluginName};
if (!empty($config) && array_key_exists($this->name, $config)) {
return $config[$this->name];
}
}
}

View File

@ -0,0 +1,110 @@
<?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\Settings\Plugin;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Settings\Settings;
use Piwik\Settings\Storage;
/**
* Base class of all system settings providers. Plugins that define their own configuration settings
* can extend this class to easily make their system settings available to Piwik users.
*
* Descendants of this class should implement the {@link init()} method and call the
* {@link makeSetting()} method to create a system setting for this plugin.
*
* For an example, see {@link Piwik\Plugins\ExampleSettingsPlugin\SystemSettings}.
*
* $systemSettings = new Piwik\Plugins\ExampleSettingsPlugin\SystemSettings(); // get instance via dependency injection
* $systemSettings->yourSetting->getValue();
*
* @api
*/
abstract class SystemSettings extends Settings
{
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->init();
}
/**
* Creates a new system setting.
*
* Settings will be displayed in the UI depending on the order of `makeSetting` calls. This means you can define
* the order of the displayed settings by calling makeSetting first for more important settings.
*
* @param string $name The name of the setting that shall be created
* @param mixed $defaultValue The default value for this setting. Note the value will not be converted to the
* specified type.
* @param string $type The PHP internal type the value of this setting should have.
* Use one of FieldConfig::TYPE_* constancts
* @param \Closure $fieldConfigCallback A callback method to configure the field that shall be displayed in the
* UI to define the value for this setting
* @return SystemSetting Returns an instance of the created measurable setting.
*/
protected function makeSetting($name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemSetting($name, $defaultValue, $type, $this->pluginName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
}
/**
* This is only meant for some core features used by some core plugins that are shipped with Piwik
* @internal
* @ignore
* @param string $configSectionName
* @param $name
* @param $defaultValue
* @param $type
* @param $fieldConfigCallback
* @return SystemSetting
* @throws \Exception
*/
protected function makeSettingManagedInConfigOnly($configSectionName, $name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new SystemConfigSetting($name, $defaultValue, $type, $this->pluginName, $configSectionName);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
}
/**
* Saves (persists) the current setting values in the database.
*
* Will trigger an event to notify plugins that a value has been changed.
*/
public function save()
{
parent::save();
/**
* Triggered after system settings have been updated.
*
* **Example**
*
* Piwik::addAction('SystemSettings.updated', function (SystemSettings $settings) {
* if ($settings->getPluginName() === 'PluginName') {
* $value = $settings->someSetting->getValue();
* // Do something with the new setting value
* }
* });
*
* @param Settings $settings The plugin settings object.
*/
Piwik::postEvent('SystemSettings.updated', array($this));
}
}

View File

@ -0,0 +1,73 @@
<?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\Settings\Plugin;
use Piwik\Container\StaticContainer;
use Piwik\Db;
use Piwik\Piwik;
use Exception;
use Piwik\Settings\Setting;
use Piwik\Settings\Storage;
/**
* Describes a per user setting. Each user will be able to change this setting for themselves,
* but not for other users.
*
* See {@link \Piwik\Settings\Setting}.
*/
class UserSetting extends Setting
{
/**
* @var null|string
*/
private $userLogin = null;
/**
* Constructor.
*
* @param string $name The setting's persisted name.
* @param mixed $defaultValue Default value for this setting if no value was specified.
* @param string $type Eg an array, int, ... see TYPE_* constants
* @param string $pluginName The name of the plugin the setting belongs to
* @param string $userLogin The name of the user the value should be set or get for
* @throws Exception
*/
public function __construct($name, $defaultValue, $type, $pluginName, $userLogin)
{
parent::__construct($name, $defaultValue, $type, $pluginName);
if (empty($userLogin)) {
throw new Exception('No userLogin given to create setting ' . $name);
}
$this->userLogin = $userLogin;
$factory = StaticContainer::get('Piwik\Settings\Storage\Factory');
$this->storage = $factory->getPluginStorage($this->pluginName, $this->userLogin);
}
/**
* Returns `true` if this setting can be displayed for the current user, `false` if otherwise.
*
* @return bool
*/
public function isWritableByCurrentUser()
{
if (isset($this->hasWritePermission)) {
return $this->hasWritePermission;
}
// performance improvement, do not detect this in __construct otherwise likely rather "big" query to DB.
$this->hasWritePermission = Piwik::isUserHasSomeViewAccess();
return $this->hasWritePermission;
}
}

View File

@ -0,0 +1,93 @@
<?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\Settings\Plugin;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Settings\Settings;
use Piwik\Settings\Storage;
/**
* Base class of all plugin settings providers. Plugins that define their own configuration settings
* can extend this class to easily make their settings available to Piwik users.
*
* Descendants of this class should implement the {@link init()} method and call the
* {@link addSetting()} method for each of the plugin's settings.
*
* For an example, see {@link Piwik\Plugins\ExampleSettingsPlugin\UserSettings}.
*
* $userSettings = new Piwik\Plugins\ExampleSettingsPlugin\UserSettings(); // get instance via dependency injection
* $userSettings->yourSetting->getValue();
*
* @api
*/
abstract class UserSettings extends Settings
{
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->init();
}
/**
* Creates a new user setting.
*
* Settings will be displayed in the UI depending on the order of `makeSetting` calls. This means you can define
* the order of the displayed settings by calling makeSetting first for more important settings.
*
* @param string $name The name of the setting that shall be created
* @param mixed $defaultValue The default value for this setting. Note the value will not be converted to the
* specified type.
* @param string $type The PHP internal type the value of this setting should have.
* Use one of FieldConfig::TYPE_* constancts
* @param \Closure $fieldConfigCallback A callback method to configure the field that shall be displayed in the
* UI to define the value for this setting
* @return UserSetting Returns an instance of the created measurable setting.
*/
protected function makeSetting($name, $defaultValue, $type, $configureCallback)
{
$userLogin = Piwik::getCurrentUserLogin();
$setting = new UserSetting($name, $defaultValue, $type, $this->pluginName, $userLogin);
$setting->setConfigureCallback($configureCallback);
$this->addSetting($setting);
return $setting;
}
/**
* Saves (persists) the current setting values in the database.
*
* Will trigger an event to notify plugins that a value has been changed.
*/
public function save()
{
parent::save();
/**
* Triggered after user settings have been updated.
*
* **Example**
*
* Piwik::addAction('UserSettings.updated', function (UserSettings $settings) {
* if ($settings->getPluginName() === 'PluginName') {
* $value = $settings->someSetting->getValue();
* // Do something with the new setting value
* }
* });
*
* @param Settings $settings The plugin settings object.
*/
Piwik::postEvent('UserSettings.updated', array($this));
}
}