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,89 @@
<?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\Measurable;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Storage;
use Exception;
/**
* Describes a Measurable property for a measurable type such as a website, a mobile app, ....
*
* The difference to {@link MeasurableSetting} is that these fields will be stored in the actual site table whereas
* MeasurableSetting will be stored in a site_settings table. For this reasons MeasurableProperty can be used only
* for some specific fields that already exist in site table such as "ecommerce", "sitesearch" etc.
*
* See {@link \Piwik\Settings\Setting}.
*/
class MeasurableProperty extends \Piwik\Settings\Setting
{
/**
* @var int
*/
private $idSite = 0;
private $allowedNames = array(
'ecommerce', 'sitesearch', 'sitesearch_keyword_parameters',
'sitesearch_category_parameters',
'exclude_unknown_urls', 'excluded_ips', 'excluded_parameters',
'excluded_user_agents', 'keep_url_fragment', 'urls', 'group'
);
/**
* Constructor.
*
* @param string $name The persisted name of the setting.
* @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 int $idSite The idSite this property belongs to.
* @throws Exception
*/
public function __construct($name, $defaultValue, $type, $pluginName, $idSite)
{
if (!in_array($name, $this->allowedNames)) {
throw new Exception(sprintf('Name "%s" is not allowed to be used with a MeasurableProperty, use a MeasurableSetting instead.', $name));
}
parent::__construct($name, $defaultValue, $type, $pluginName);
$this->idSite = $idSite;
$storageFactory = StaticContainer::get('Piwik\Settings\Storage\Factory');
$this->storage = $storageFactory->getSitesTable($idSite);
}
/**
* 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.
if ($this->hasSiteBeenCreated()) {
$this->hasWritePermission = Piwik::isUserHasAdminAccess($this->idSite);
} else {
$this->hasWritePermission = Piwik::hasUserSuperUserAccess();
}
return $this->hasWritePermission;
}
private function hasSiteBeenCreated()
{
return !empty($this->idSite);
}
}

View File

@ -0,0 +1,72 @@
<?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\Measurable;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Storage;
/**
* Describes a Measurable setting for a measurable type such as a website, a mobile app, ...
*
* See {@link \Piwik\Settings\Setting}.
*/
class MeasurableSetting extends \Piwik\Settings\Setting
{
/**
* @var int
*/
private $idSite = 0;
/**
* Constructor.
*
* @param string $name The persisted name of the setting.
* @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 int $idSite The idSite this setting belongs to.
*/
public function __construct($name, $defaultValue, $type, $pluginName, $idSite)
{
parent::__construct($name, $defaultValue, $type, $pluginName);
$this->idSite = $idSite;
$storageFactory = StaticContainer::get('Piwik\Settings\Storage\Factory');
$this->storage = $storageFactory->getMeasurableSettingsStorage($idSite, $this->pluginName);
}
/**
* 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.
if ($this->hasSiteBeenCreated()) {
$this->hasWritePermission = Piwik::isUserHasAdminAccess($this->idSite);
} else {
$this->hasWritePermission = Piwik::hasUserSuperUserAccess();
}
return $this->hasWritePermission;
}
private function hasSiteBeenCreated()
{
return !empty($this->idSite);
}
}

View File

@ -0,0 +1,141 @@
<?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\Measurable;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Settings\Settings;
use Piwik\Settings\Storage;
use Piwik\Site;
use Exception;
/**
* Base class of all measurable settings providers. Plugins that define their own configuration settings
* can extend this class to easily make their measurable settings available to Piwik users.
*
* Descendants of this class should implement the {@link init()} method and call the
* {@link makeSetting()} method for each of the measurable's settings.
*
* For an example, see the {@link Piwik\Plugins\ExampleSettingsPlugin\MeasurableSettings} plugin.
*
* $settingsProvider = new Piwik\Plugin\SettingsProvider(); // get this instance via dependency injection
* $measurableSettings = $settingProvider->getMeasurableSettings($yourPluginName, $idsite, $idType = null);
* $measurableSettings->yourSetting->getValue();
*
* @api
*/
abstract class MeasurableSettings extends Settings
{
/**
* @var int
*/
protected $idSite;
/**
* @var string
*/
protected $idMeasurableType;
/**
* Constructor.
* @param int $idSite If creating settings for a new site that is not created yet, use idSite = 0
* @param string|null $idMeasurableType If null, idType will be detected from idSite
* @throws Exception
*/
public function __construct($idSite, $idMeasurableType = null)
{
parent::__construct();
$this->idSite = (int) $idSite;
if (!empty($idMeasurableType)) {
$this->idMeasurableType = $idMeasurableType;
} elseif (!empty($idSite)) {
$this->idMeasurableType = Site::getTypeFor($idSite);
} else {
throw new Exception('No idType specified for ' . get_class($this));
}
$this->init();
}
protected function hasMeasurableType($typeId)
{
return $typeId === $this->idMeasurableType;
}
/**
* Creates a new measurable 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 MeasurableSetting Returns an instance of the created measurable setting.
* @throws Exception
*/
protected function makeSetting($name, $defaultValue, $type, $fieldConfigCallback)
{
$setting = new MeasurableSetting($name, $defaultValue, $type, $this->pluginName, $this->idSite);
$setting->setConfigureCallback($fieldConfigCallback);
$this->addSetting($setting);
return $setting;
}
/**
* @internal
* @param $name
* @param $defaultValue
* @param $type
* @param $configureCallback
* @return MeasurableProperty
* @throws Exception
*/
protected function makeProperty($name, $defaultValue, $type, $configureCallback)
{
$setting = new MeasurableProperty($name, $defaultValue, $type, $this->pluginName, $this->idSite);
$setting->setConfigureCallback($configureCallback);
$this->addSetting($setting);
return $setting;
}
/**
* Saves (persists) the current measurable 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 a plugin settings have been updated.
*
* **Example**
*
* Piwik::addAction('MeasurableSettings.updated', function (MeasurableSettings $settings) {
* $value = $settings->someSetting->getValue();
* // Do something with the new setting value
* });
*
* @param Settings $settings The plugin settings object.
*/
Piwik::postEvent('MeasurableSettings.updated', array($this, $this->idSite));
}
}