protected function init()
 {
     $this->userTrackingEnabled = $this->createUsersOptOutSetting();
     if (!$this->systemSettings->canUserOptOut->getValue()) {
         // we show this setting only when a user can actually opt out
         $this->userTrackingEnabled->setIsWritableByCurrentUser(false);
     }
 }
 protected function assertSettingHasValue(Setting $setting, $expectedValue, $expectedType = null)
 {
     $value = $setting->getValue($setting);
     $this->assertEquals($expectedValue, $value);
     if (!is_null($expectedType)) {
         $this->assertInternalType($expectedType, $value);
     }
 }
Exemple #3
0
 private function formatMetadata(Setting $setting)
 {
     $config = $setting->configureField();
     $availableValues = $config->availableValues;
     if (is_array($availableValues)) {
         $availableValues = (object) $availableValues;
     }
     return array('name' => $setting->getName(), 'title' => $config->title, 'value' => $setting->getValue(), 'defaultValue' => $setting->getDefaultValue(), 'type' => $setting->getType(), 'uiControl' => $config->uiControl, 'uiControlAttributes' => $config->uiControlAttributes, 'availableValues' => $availableValues, 'description' => $config->description, 'inlineHelp' => $config->inlineHelp, 'introduction' => $config->introduction, 'condition' => $config->condition);
 }
Exemple #4
0
 protected function init()
 {
     $this->title = Piwik::translate('CoreAdminHome_UpdateSettings');
     $isWritable = Piwik::hasUserSuperUserAccess() && CoreAdminController::isGeneralSettingsAdminEnabled();
     $this->releaseChannel = $this->createReleaseChannel();
     $this->releaseChannel->setIsWritableByCurrentUser($isWritable);
     $isWritable = $isWritable && PluginUpdateCommunication::canBeEnabled();
     $this->sendPluginUpdateEmail = $this->createSendPluginUpdateEmail();
     $this->sendPluginUpdateEmail->setIsWritableByCurrentUser($isWritable);
 }
 /**
  * Constructor.
  *
  * @param string $name The setting's persisted name.
  * @param string $title The setting's display name.
  * @param null|string $userLogin The user this setting applies to. Will default to the current user login.
  */
 public function __construct($name, $title, $userLogin = null)
 {
     parent::__construct($name, $title);
     $this->setUserLogin($userLogin);
     $this->writableByCurrentUser = Piwik::isUserHasSomeViewAccess();
     $this->readableByCurrentUser = Piwik::isUserHasSomeViewAccess();
 }
Exemple #6
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);
 }
Exemple #7
0
 /**
  * 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);
 }
Exemple #8
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 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);
 }
 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;
 }
Exemple #10
0
 protected function init()
 {
     $this->urls = new Urls($this->idSite);
     $this->addSetting($this->urls);
     $this->excludeKnownUrls = $this->makeExcludeUnknownUrls();
     $this->keepPageUrlFragments = $this->makeKeepUrlFragments($this->sitesManagerApi);
     $this->excludedIps = $this->makeExcludeIps();
     $this->excludedParameters = $this->makeExcludedParameters();
     $this->excludedUserAgents = $this->makeExcludedUserAgents();
     /**
      * SiteSearch
      */
     $this->siteSearch = $this->makeSiteSearch();
     $this->useDefaultSiteSearchParams = $this->makeUseDefaultSiteSearchParams($this->sitesManagerApi);
     $this->siteSearchKeywords = $this->makeSiteSearchKeywords();
     $siteSearchKeywords = $this->siteSearchKeywords->getValue();
     $this->useDefaultSiteSearchParams->setDefaultValue(empty($siteSearchKeywords));
     $this->siteSearchCategory = $this->makeSiteSearchCategory($this->pluginManager);
     /**
      * SiteSearch End
      */
     $this->ecommerce = $this->makeEcommerce();
 }
 /**
  * @param $setting
  * @throws \Exception
  */
 private function checkHasEnoughPermission(Setting $setting)
 {
     if (!$setting->canBeDisplayedForCurrentUser()) {
         $errorMsg = Piwik::translate('CoreAdminHome_PluginSettingChangeNotAllowed', array($setting->getName(), $this->pluginName));
         throw new \Exception($errorMsg);
     }
 }
Exemple #12
0
 public function setValue(Setting $setting, $value)
 {
     $this->toBeDeleted[$setting->getName()] = false;
     // prevent from deleting this setting, we will create/update it
     parent::setValue($setting, $value);
 }
 /**
  * Constructor.
  * 
  * @param string $name The persisted name of the setting.
  * @param string $title The display name of the setting.
  */
 public function __construct($name, $title)
 {
     parent::__construct($name, $title);
     $this->displayedForCurrentUser = Piwik::isUserIsSuperUser();
 }
Exemple #14
0
 /**
  * Constructor.
  * 
  * @param string $name The persisted name of the setting.
  * @param string $title The display name of the setting.
  */
 public function __construct($name, $title)
 {
     parent::__construct($name, $title);
     $this->writableByCurrentUser = Piwik::hasUserSuperUserAccess();
     $this->readableByCurrentUser = $this->writableByCurrentUser;
 }
Exemple #15
0
 /**
  * @param $setting
  * @throws \Exception
  */
 private function checkHasEnoughReadPermission(Setting $setting)
 {
     // When the request is a Tracker request, allow plugins to read settings
     if (SettingsServer::isTrackerApiRequest()) {
         return;
     }
     if (!$setting->isReadableByCurrentUser()) {
         $errorMsg = Piwik::translate('CoreAdminHome_PluginSettingReadNotAllowed', array($setting->getName(), $this->pluginName));
         throw new \Exception($errorMsg);
     }
 }
Exemple #16
0
 /**
  * Makes a new plugin setting available.
  *
  * @param Setting $setting
  * @throws \Exception       If there is a setting with the same name that already exists.
  *                          If the name contains non-alphanumeric characters.
  */
 protected function addSetting(Setting $setting)
 {
     $name = $setting->getName();
     if (!ctype_alnum($name)) {
         $msg = sprintf('The setting name "%s" in plugin "%s" is not valid. Only alpha and numerical characters are allowed', $setting->getName(), $this->pluginName);
         throw new \Exception($msg);
     }
     if (array_key_exists($name, $this->settings)) {
         throw new \Exception(sprintf('A setting with name "%s" does already exist for plugin "%s"', $setting->getName(), $this->pluginName));
     }
     $this->setDefaultTypeAndFieldIfNeeded($setting);
     $this->addValidatorIfNeeded($setting);
     $setting->setStorage($this->storage);
     $setting->setPluginName($this->pluginName);
     $this->settings[$name] = $setting;
 }
Exemple #17
0
 /**
  * Unsets a setting value in memory. To persist the change, {@link save()} must be
  * called afterwards, otherwise the change has no effect.
  *
  * @param Setting $setting
  */
 public function deleteValue(Setting $setting)
 {
     $this->loadSettingsIfNotDoneYet();
     $key = $setting->getKey();
     if (array_key_exists($key, $this->settingsValues)) {
         unset($this->settingsValues[$key]);
     }
 }
 /**
  * Constructor.
  * 
  * @param string $name The setting's persisted name.
  * @param string $title The setting's display name.
  * @param null|string $userLogin The user this setting applies to. Will default to the current user login.
  */
 public function __construct($name, $title, $userLogin = null)
 {
     parent::__construct($name, $title);
     $this->setUserLogin($userLogin);
     $this->displayedForCurrentUser = Piwik::isUserHasSomeViewAccess();
 }
Exemple #19
0
 /**
  * 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->storage = $factory->getConfigStorage($configSectionName);
 }
 /**
  * Constructor.
  *
  * @param string $name The persisted name of the setting.
  * @param string $title The display name of the setting.
  */
 public function __construct($name, $title)
 {
     parent::__construct($name, $title);
     $this->writableByCurrentUser = Piwik::isUserHasSomeAdminAccess();
     $this->readableByCurrentUser = Piwik::isUserHasSomeViewAccess();
 }
Exemple #21
0
 /**
  * Constructor.
  *
  * @param string $name The setting's persisted name.
  * @param string $title The setting's display name.
  * @param null|string $userLogin The user this setting applies to. Will default to the current user login.
  */
 public function __construct($name, $title, $userLogin = null)
 {
     parent::__construct($name, $title);
     $this->setUserLogin($userLogin);
 }