mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-25 22:44:44 +08:00
Resolve #741
This commit is contained in:
parent
cb2a265373
commit
605ee88041
5 changed files with 80 additions and 53 deletions
|
@ -614,65 +614,34 @@ class ActionsAdmin extends Actions
|
||||||
{
|
{
|
||||||
$this->IsAdminLoggined();
|
$this->IsAdminLoggined();
|
||||||
|
|
||||||
$mResult = false;
|
|
||||||
$sId = (string) $this->GetActionParam('Id', '');
|
$sId = (string) $this->GetActionParam('Id', '');
|
||||||
|
|
||||||
if (!empty($sId))
|
if (!empty($sId)) {
|
||||||
{
|
|
||||||
$oPlugin = $this->Plugins()->CreatePluginByName($sId);
|
$oPlugin = $this->Plugins()->CreatePluginByName($sId);
|
||||||
if ($oPlugin)
|
if ($oPlugin) {
|
||||||
{
|
|
||||||
$oConfig = $oPlugin->Config();
|
$oConfig = $oPlugin->Config();
|
||||||
$aMap = $oPlugin->ConfigMap(true);
|
$aMap = $oPlugin->ConfigMap(true);
|
||||||
if (\is_array($aMap))
|
if (\is_array($aMap)) {
|
||||||
{
|
|
||||||
$aSettings = (array) $this->GetActionParam('Settings', []);
|
$aSettings = (array) $this->GetActionParam('Settings', []);
|
||||||
foreach ($aMap as $oItem)
|
foreach ($aMap as $oItem) {
|
||||||
{
|
|
||||||
$sKey = $oItem->Name();
|
$sKey = $oItem->Name();
|
||||||
$sValue = $aSettings[$sKey] ?? $oConfig->Get('plugin', $sKey);
|
$sValue = $aSettings[$sKey] ?? $oConfig->Get('plugin', $sKey);
|
||||||
if (PluginPropertyType::PASSWORD !== $oItem->Type() || static::APP_DUMMY !== $sValue)
|
if (PluginPropertyType::PASSWORD !== $oItem->Type() || static::APP_DUMMY !== $sValue) {
|
||||||
{
|
$oItem->SetValue($sValue);
|
||||||
$mResultValue = null;
|
$mResultValue = $oItem->Value();
|
||||||
switch ($oItem->Type()) {
|
if (null !== $mResultValue) {
|
||||||
case PluginPropertyType::INT:
|
|
||||||
$mResultValue = (int) $sValue;
|
|
||||||
break;
|
|
||||||
case PluginPropertyType::BOOL:
|
|
||||||
$mResultValue = '1' === (string) $sValue;
|
|
||||||
break;
|
|
||||||
case PluginPropertyType::SELECTION:
|
|
||||||
if (is_array($oItem->DefaultValue()) && in_array($sValue, $oItem->DefaultValue()))
|
|
||||||
{
|
|
||||||
$mResultValue = (string) $sValue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case PluginPropertyType::PASSWORD:
|
|
||||||
case PluginPropertyType::STRING:
|
|
||||||
case PluginPropertyType::STRING_TEXT:
|
|
||||||
case PluginPropertyType::URL:
|
|
||||||
$mResultValue = (string) $sValue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $mResultValue)
|
|
||||||
{
|
|
||||||
$oConfig->Set('plugin', $sKey, $mResultValue);
|
$oConfig->Set('plugin', $sKey, $mResultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($oConfig->Save()) {
|
||||||
$mResult = $oConfig->Save();
|
return $this->DefaultResponse(__FUNCTION__, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$mResult)
|
throw new ClientException(Notifications::CantSavePluginSettings);
|
||||||
{
|
|
||||||
throw new ClientException(Notifications::CantSavePluginSettings);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->DefaultResponse(__FUNCTION__, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DoAdminQRCode() : array
|
public function DoAdminQRCode() : array
|
||||||
|
|
|
@ -80,6 +80,9 @@ abstract class AbstractConfig implements \JsonSerializable
|
||||||
{
|
{
|
||||||
if (isset($this->aData[$sSectionKey][$sParamKey][0]))
|
if (isset($this->aData[$sSectionKey][$sParamKey][0]))
|
||||||
{
|
{
|
||||||
|
if (!\is_scalar($mParamValue)) {
|
||||||
|
$mParamValue = null;
|
||||||
|
}
|
||||||
switch (\gettype($this->aData[$sSectionKey][$sParamKey][0]))
|
switch (\gettype($this->aData[$sSectionKey][$sParamKey][0]))
|
||||||
{
|
{
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
|
|
|
@ -4,10 +4,7 @@ namespace RainLoop\Config;
|
||||||
|
|
||||||
class Plugin extends \RainLoop\Config\AbstractConfig
|
class Plugin extends \RainLoop\Config\AbstractConfig
|
||||||
{
|
{
|
||||||
/**
|
private array $aMap = array();
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $aMap = array();
|
|
||||||
|
|
||||||
public function __construct(string $sPluginName, array $aMap = array())
|
public function __construct(string $sPluginName, array $aMap = array())
|
||||||
{
|
{
|
||||||
|
@ -15,8 +12,9 @@ class Plugin extends \RainLoop\Config\AbstractConfig
|
||||||
$aResultMap = array();
|
$aResultMap = array();
|
||||||
foreach ($aMap as $oProperty) {
|
foreach ($aMap as $oProperty) {
|
||||||
if ($oProperty instanceof \RainLoop\Plugins\Property) {
|
if ($oProperty instanceof \RainLoop\Plugins\Property) {
|
||||||
|
$mDefaultValue = $oProperty->DefaultValue();
|
||||||
$aResultMap[$oProperty->Name()] = array(
|
$aResultMap[$oProperty->Name()] = array(
|
||||||
$oProperty->DefaultValue(),
|
\is_array($mDefaultValue) ? '' : $mDefaultValue,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace RainLoop\Plugins;
|
namespace RainLoop\Plugins;
|
||||||
|
|
||||||
|
use \RainLoop\Enumerations\PluginPropertyType;
|
||||||
|
|
||||||
class Property implements \JsonSerializable
|
class Property implements \JsonSerializable
|
||||||
{
|
{
|
||||||
private string $sName;
|
private string $sName;
|
||||||
|
@ -15,7 +17,7 @@ class Property implements \JsonSerializable
|
||||||
|
|
||||||
private string $sDesc = '';
|
private string $sDesc = '';
|
||||||
|
|
||||||
private int $iType = \RainLoop\Enumerations\PluginPropertyType::STRING;
|
private int $iType = PluginPropertyType::STRING;
|
||||||
|
|
||||||
private bool $bAllowedInJs = false;
|
private bool $bAllowedInJs = false;
|
||||||
|
|
||||||
|
@ -24,6 +26,8 @@ class Property implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
private $mDefaultValue = '';
|
private $mDefaultValue = '';
|
||||||
|
|
||||||
|
private array $aOptions = [];
|
||||||
|
|
||||||
private string $sPlaceholder = '';
|
private string $sPlaceholder = '';
|
||||||
|
|
||||||
function __construct(string $sName)
|
function __construct(string $sName)
|
||||||
|
@ -48,7 +52,35 @@ class Property implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function SetValue($mValue) : void
|
public function SetValue($mValue) : void
|
||||||
{
|
{
|
||||||
$this->mValue = $mValue;
|
$this->mValue = null;
|
||||||
|
switch ($this->iType) {
|
||||||
|
case PluginPropertyType::INT:
|
||||||
|
$this->mValue = (int) $mValue;
|
||||||
|
break;
|
||||||
|
case PluginPropertyType::BOOL:
|
||||||
|
$this->mValue = !empty($mValue);
|
||||||
|
break;
|
||||||
|
case PluginPropertyType::SELECT:
|
||||||
|
foreach ($this->aOptions as $option) {
|
||||||
|
if ($mValue == $option['id']) {
|
||||||
|
$this->mValue = (string) $mValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PluginPropertyType::SELECTION:
|
||||||
|
if ($this->aOptions && \in_array($mValue, $oItem->Options())) {
|
||||||
|
$this->mValue = (string) $mValue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PluginPropertyType::PASSWORD:
|
||||||
|
case PluginPropertyType::STRING:
|
||||||
|
case PluginPropertyType::STRING_TEXT:
|
||||||
|
case PluginPropertyType::URL:
|
||||||
|
$this->mValue = (string) $mValue;
|
||||||
|
break;
|
||||||
|
// case PluginPropertyType::GROUP:
|
||||||
|
// throw new \Exception('Not allowed to set group value');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +88,18 @@ class Property implements \JsonSerializable
|
||||||
*/
|
*/
|
||||||
public function SetDefaultValue($mDefaultValue) : self
|
public function SetDefaultValue($mDefaultValue) : self
|
||||||
{
|
{
|
||||||
$this->mDefaultValue = $mDefaultValue;
|
if (\is_array($mDefaultValue)) {
|
||||||
|
$this->aOptions = $mDefaultValue;
|
||||||
|
} else {
|
||||||
|
$this->mDefaultValue = $mDefaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetOptions(array $aOptions) : self
|
||||||
|
{
|
||||||
|
$this->aOptions = $aOptions;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -122,11 +165,24 @@ class Property implements \JsonSerializable
|
||||||
return $this->mDefaultValue;
|
return $this->mDefaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function Options() : array
|
||||||
|
{
|
||||||
|
return $this->aOptions;
|
||||||
|
}
|
||||||
|
|
||||||
public function Placeholder() : string
|
public function Placeholder() : string
|
||||||
{
|
{
|
||||||
return $this->sPlaceholder;
|
return $this->sPlaceholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function Value()
|
||||||
|
{
|
||||||
|
return $this->mValue;
|
||||||
|
}
|
||||||
|
|
||||||
#[\ReturnTypeWillChange]
|
#[\ReturnTypeWillChange]
|
||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
|
@ -138,6 +194,7 @@ class Property implements \JsonSerializable
|
||||||
'Type' => $this->iType,
|
'Type' => $this->iType,
|
||||||
'Label' => $this->sLabel,
|
'Label' => $this->sLabel,
|
||||||
'Default' => $this->mDefaultValue,
|
'Default' => $this->mDefaultValue,
|
||||||
|
'Options' => $this->aOptions,
|
||||||
'Desc' => $this->sDesc
|
'Desc' => $this->sDesc
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
data-bind="value: value, attr: {placeholder: placeholder }"></textarea>
|
data-bind="value: value, attr: {placeholder: placeholder }"></textarea>
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
<!-- ko if: 4 === Type -->
|
<!-- ko if: 4 === Type -->
|
||||||
<select data-bind="options: Default, value: value"></select>
|
<select data-bind="options: Options, value: value"></select>
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
<!-- ko if: 5 === Type -->
|
<!-- ko if: 5 === Type -->
|
||||||
<div data-bind="component: {
|
<div data-bind="component: {
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
data-bind="value: value, attr: {placeholder: placeholder}">
|
data-bind="value: value, attr: {placeholder: placeholder}">
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
<!-- ko if: 8 === Type -->
|
<!-- ko if: 8 === Type -->
|
||||||
<select data-bind="options: Default, optionsText: 'name', optionsValue: 'id', value: value"></select>
|
<select data-bind="options: Options, optionsText: 'name', optionsValue: 'id', value: value"></select>
|
||||||
<!-- /ko -->
|
<!-- /ko -->
|
||||||
<!-- ko if: '' !== Desc -->
|
<!-- ko if: '' !== Desc -->
|
||||||
<span tabindex="0" class="help-block"><span data-bind="text: Desc"></span></span>
|
<span tabindex="0" class="help-block"><span data-bind="text: Desc"></span></span>
|
||||||
|
|
Loading…
Add table
Reference in a new issue