diff --git a/core/Plugin/Settings.php b/core/Plugin/Settings.php index 9fc7fa9f3bb7ed55bc981e012aaa7f15452d8b25..691224d6620b4082838a2e83cdf19f0ade613e0e 100644 --- a/core/Plugin/Settings.php +++ b/core/Plugin/Settings.php @@ -159,7 +159,8 @@ class Settings $setting = $this->getSetting($name); if (empty($setting)) { - throw new \Exception('This setting does not exist'); + // TODO escape $name? or is it automatically escaped? + throw new \Exception(sprintf('The setting %s does not exist', $name)); } if (!$setting['displayedForCurrentUser']) { diff --git a/core/Settings/Manager.php b/core/Settings/Manager.php index 045ae4e49b697dcd9481852157d3724e9d6b0d5d..a79c672a38019d068b9c46377c8e172f852e64cc 100644 --- a/core/Settings/Manager.php +++ b/core/Settings/Manager.php @@ -30,10 +30,10 @@ class Manager { if (empty(static::$settings)) { - $pluginSettings = array('Login' => 'Piwik\\Plugins\\Login\\Settings'); + $pluginSettings = array(); // TODO: document hook and think about better name - Piwik::postEvent('Plugin.addSettings', $pluginSettings); + Piwik::postEvent('Plugin.addSettings', array(&$pluginSettings)); $settings = array(); foreach ($pluginSettings as $pluginName => $pluginSetting) { diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php index ddc71608bf201c76d372247d47885c74a165aa8c..f1e641a3672ed093d57ca727625787af94043aeb 100644 --- a/plugins/CoreAdminHome/Controller.php +++ b/plugins/CoreAdminHome/Controller.php @@ -110,13 +110,12 @@ class Controller extends \Piwik\Plugin\ControllerAdmin Piwik::checkUserIsNotAnonymous(); Json::sendHeaderJSON(); - $updateSettings = Common::getRequestVar('settings', null, 'json'); + $changedPluginSettings = Common::getRequestVar('settings', null, 'array'); $pluginSettings = SettingsManager::getAllPluginSettings(); try { - foreach ($updateSettings as $pluginName => $serializedSetting) { - $unserializedSettings = UrlHelper::getArrayFromQueryString($serializedSetting); + foreach ($changedPluginSettings as $pluginName => $changedPluginSetting) { if (!array_key_exists($pluginName, $pluginSettings)) { // this plugin is not using settings, skip it @@ -125,8 +124,8 @@ class Controller extends \Piwik\Plugin\ControllerAdmin $pluginSetting = $pluginSettings[$pluginName]; - foreach ($unserializedSettings as $key => $value) { - $pluginSetting->setSettingValue($key, $value); + foreach ($changedPluginSetting as $changedSetting) { + $pluginSetting->setSettingValue($changedSetting['name'], $changedSetting['value']); } } diff --git a/plugins/CoreAdminHome/javascripts/pluginSettings.js b/plugins/CoreAdminHome/javascripts/pluginSettings.js index 9a6048b280ebde919deabe69eb10c4539d904903..14c63914b5e5ea0a3d995368e9b274486f2eb983 100644 --- a/plugins/CoreAdminHome/javascripts/pluginSettings.js +++ b/plugins/CoreAdminHome/javascripts/pluginSettings.js @@ -22,7 +22,7 @@ $(document).ready(function () { module: 'CoreAdminHome', action: 'setPluginSettings' }, 'GET'); - ajaxHandler.addParams({settings: JSON.stringify(getSettings())}, 'POST'); + ajaxHandler.addParams({settings: getSettings()}, 'POST'); ajaxHandler.redirectOnSuccess(); ajaxHandler.setLoadingElement(getLoadingElement()); ajaxHandler.setErrorElement(getErrorElement()); @@ -39,7 +39,7 @@ $(document).ready(function () { $pluginSection = $(pluginSection); var pluginName = $pluginSection.attr('data-pluginname'); - var serialized = $('input, textarea, select', $pluginSection ).serialize(); + var serialized = $('input, textarea, select', $pluginSection ).serializeArray(); values[pluginName] = serialized; });