Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions admin/forms/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@
description="PLG_SYSTEM_BFSTOP_PROXY_IP_DESC" />
</fieldset>
<fieldset name="advanced">
<field name="enabledForOrigin" type="list" validate="options" default="3"
<!-- a checkbox per part; stored as their sum, a bitmask (1 frontend,
2 backend, 4 Web Services API, see the plugin's Bfstop::Origin*):
SettingsModel converts between the two -->
<field name="enabledForOrigin" type="checkboxes" validate="options" required="true"
default="1,2,4"
label="PLG_SYSTEM_BFSTOP_ENABLED_FOR_ORIGIN_LABEL"
description="PLG_SYSTEM_BFSTOP_ENABLED_FOR_ORIGIN_DESC">
<option value="1">PLG_SYSTEM_BFSTOP_ENABLED_FOR_FRONTEND</option>
<option value="2">PLG_SYSTEM_BFSTOP_ENABLED_FOR_BACKEND</option>
<option value="3">PLG_SYSTEM_BFSTOP_ENABLED_FOR_BOTH</option>
<option value="4">PLG_SYSTEM_BFSTOP_ENABLED_FOR_API</option>
</field>
<field name="progressiveBlockDuration" type="list" validate="options" default="0"
label="COM_BFSTOP_SETTINGS_PROGRESSIVE_BLOCK_DURATION_LABEL"
Expand Down
42 changes: 41 additions & 1 deletion admin/src/Model/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,55 @@ protected function loadFormData()
if (empty($data))
{
$data = $this->getItem();
if (is_object($data) && isset($data->params) && is_array($data->params))
{
$data->params = self::paramsForForm($data->params);
}
}
return $data;
}

/**
* The stored params as the form shows them: "enabledForOrigin" is a
* bitmask (what the plugin reads, and what 1.x stored), the form has a
* checkbox for each of its bits.
*/
public static function paramsForForm(array $params)
{
$params['enabledForOrigin'] = Bfstop::originList(
$params['enabledForOrigin'] ?? Bfstop::DefaultSettings['enabledForOrigin']);
return $params;
}

/**
* The form's params as they are stored, see paramsForForm(). The form
* requires a part to be ticked; should a request come without any (or
* only with values which are none), the setting is left out, which makes
* the plugin use its default - active for all parts, not for none.
*/
public static function paramsForStorage(array $params)
{
if (array_key_exists('enabledForOrigin', $params))
{
$mask = Bfstop::originMask($params['enabledForOrigin']);
if ($mask === 0)
{
unset($params['enabledForOrigin']);
}
else
{
$params['enabledForOrigin'] = $mask;
}
}
return $params;
}

public function save($data)
{
$id = $this->resolvePluginExtensionId();
$data[$this->getTable()->getKeyName()] = $id;
$data['params'] = self::keepInternalSettings($data['params'] ?? array(), $this->loadStoredParams($id));
$data['params'] = self::keepInternalSettings(self::paramsForStorage($data['params'] ?? array()),
$this->loadStoredParams($id));
return parent::save($data);
}

Expand Down
11 changes: 10 additions & 1 deletion admin/src/View/Failedloginlist/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ function display($tpl = null)

function getOriginName($origin)
{
return ($origin == 0) ? 'Frontend' : 'Backend';
// the client id of the application: site 0, administrator 1, api 3
switch ((int) $origin)
{
case 0:
return 'Frontend';
case 3:
return 'API';
default:
return 'Backend';
}
}

protected function addToolBar()
Expand Down
Loading