Skip to content

Commit 42c38fe

Browse files
committed
Configuration patch.
Changelog excerpt: - Reworked how the configuration page deals with volume-based configuration.
1 parent 17b4d25 commit 42c38fe

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
115115
[2022.10.22; Maikuolan]: Added L10N for Persian/Farsi.
116116

117117
[2022.10.25; Maikuolan]: Hardened some configuration constraints.
118+
119+
[2022.10.28; Maikuolan]: Reworked how the configuration page deals with volume-based configuration.

src/FrontEnd.php

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Front-end handler (last modified: 2022.10.25).
11+
* This file: Front-end handler (last modified: 2022.10.28).
1212
*/
1313

1414
namespace phpMussel\FrontEnd;
@@ -1132,33 +1132,9 @@ public function view(string $Page = ''): void
11321132
}
11331133
}
11341134
if (isset($DirValue['preview'])) {
1135-
$ThisDir['Preview'] = ($DirValue['preview'] === 'allow_other') ? '' : sprintf(
1136-
$DirValue['preview_default_fill'] ?? ' = <span id="%s_preview"></span>',
1137-
$ThisDir['DirLangKey']
1138-
);
1135+
$ThisDir['Preview'] = ($DirValue['preview'] === 'allow_other') ? '' : sprintf(' = <span id="%s_preview"></span>', $ThisDir['DirLangKey']);
11391136
$ThisDir['Trigger'] = ' onchange="javascript:' . $ThisDir['DirLangKey'] . '_function();" onkeyup="javascript:' . $ThisDir['DirLangKey'] . '_function();"';
1140-
if ($DirValue['preview'] === 'kb') {
1141-
$ThisDir['Preview'] .= sprintf(
1142-
'<script type="text/javascript">function %1$s_function(){var e=%7$s?%7$s(' .
1143-
'\'%1$s_field\').value:%8$s&&!%7$s?%8$s.%1$s_field.value:\'\',z=e.replace' .
1144-
'(/o$/i,\'b\').substr(-2).toLowerCase(),y=\'kb\'==z?1:\'mb\'==z?1024:\'gb' .
1145-
'\'==z?1048576:\'tb\'==z?1073741824:\'b\'==e.substr(-1)?.0009765625:1,e=e' .
1146-
'.replace(/[^0-9]*$/i,\'\'),e=isNaN(e)?0:e*y,t=0>e?\'0 %2$s\':1>e?nft((10' .
1147-
'24*e).toFixed(0))+\' %2$s\':1024>e?nft((1*e).toFixed(2))+\' %3$s\':10485' .
1148-
'76>e?nft((e/1024).toFixed(2))+\' %4$s\':1073741824>e?nft((e/1048576).toF' .
1149-
'ixed(2))+\' %5$s\':nft((e/1073741824).toFixed(2))+\' %6$s\';%7$s?%7$s(\'' .
1150-
'%1$s_preview\').innerHTML=t:%8$s&&!%7$s?%8$s.%1$s_preview.innerHTML=t:\'' .
1151-
'\'};%1$s_function();</script>',
1152-
$ThisDir['DirLangKey'],
1153-
$this->Loader->L10N->getPlural(0, 'field_size_bytes'),
1154-
$this->Loader->L10N->getString('field_size_KB'),
1155-
$this->Loader->L10N->getString('field_size_MB'),
1156-
$this->Loader->L10N->getString('field_size_GB'),
1157-
$this->Loader->L10N->getString('field_size_TB'),
1158-
'document.getElementById',
1159-
'document.all'
1160-
);
1161-
} elseif ($DirValue['preview'] === 'seconds') {
1137+
if ($DirValue['preview'] === 'seconds') {
11621138
$ThisDir['Preview'] .= sprintf(
11631139
'<script type="text/javascript">function %1$s_function(){var t=%9$s?%9$s(' .
11641140
'\'%1$s_field\').value:%10$s&&!%9$s?%10$s.%1$s_field.value:\'\',e=isNaN(t' .
@@ -1245,6 +1221,35 @@ public function view(string $Page = ''): void
12451221
$ThisDir['DirLangKey']
12461222
) . '</script>';
12471223
}
1224+
} elseif ($DirValue['type'] === 'kb') {
1225+
$ThisDir['Preview'] = sprintf(' = <span id="%s_preview"></span>', $ThisDir['DirLangKey']);
1226+
$ThisDir['Trigger'] = ' onchange="javascript:' . $ThisDir['DirLangKey'] . '_function();" onkeyup="javascript:' . $ThisDir['DirLangKey'] . '_function();"';
1227+
$ThisDir['Preview'] .= sprintf(
1228+
'<script type="text/javascript">function %1$s_function(){const bytesPerUnit={' .
1229+
'B:1,K:1024,M:1048576,G:1073741824,T:1099511627776,P:1125899906842620},unitNa' .
1230+
'mes=["%2$s","%3$s","%4$s","%5$s","%6$s","%7$s"];var e=%8$s?%8$s(\'%1$s_field' .
1231+
'\').value:%9$s&&!%8$s?%9$s.%1$s_field.value:\'\';if((Unit=e.match(/(?<Unit>[' .
1232+
'KkMmGgTtPpOoBb]|К|к|М|м|Г|г|Т|т|П|п|K|k|M|m|G|g|T|t|P|p|Б|б|B|b)(?:[OoBb]|Б|' .
1233+
'б|B|b)?$/))&&void 0!==Unit.groups.Unit)if((Unit=Unit.groups.Unit).match(/^(?' .
1234+
':[OoBb]|Б|б|B|b)$/))var Unit=\'B\';else if(Unit.match(/^(?:[Mm]|М|м)$/))Unit' .
1235+
'=\'M\';else if(Unit.match(/^(?:[Gg]|Г|г)$/))Unit=\'G\';else if(Unit.match(/^' .
1236+
'(?:[Tt]|Т|т)$/))Unit=\'T\';else if(Unit.match(/^(?:[Pp]|П|п)$/))Unit=\'P\';e' .
1237+
'lse Unit=\'K\';else Unit=\'K\';var e=parseFloat(e);if(isNaN(e))var fixed=0;e' .
1238+
'lse{if(void 0!==bytesPerUnit[Unit])fixed=e*bytesPerUnit[Unit];else fixed=e;f' .
1239+
'ixed=Math.floor(fixed)}for(var i=0,p=unitNames[i];fixed>=1024;){fixed=fixed/' .
1240+
'1024;i++;p=unitNames[i];if(i>=5)break}t=nft(fixed.toFixed(i===0?0:2))+\' \'+' .
1241+
'p;%8$s?%8$s(\'%1$s_preview\').innerHTML=t:%9$s&&!%8$s?%9$s.%1$s_preview.inne' .
1242+
'rHTML=t:\'\';};%1$s_function();</script>',
1243+
$ThisDir['DirLangKey'],
1244+
$this->Loader->L10N->getPlural(0, 'field_size_bytes'),
1245+
$this->Loader->L10N->getString('field_size_KB'),
1246+
$this->Loader->L10N->getString('field_size_MB'),
1247+
$this->Loader->L10N->getString('field_size_GB'),
1248+
$this->Loader->L10N->getString('field_size_TB'),
1249+
$this->Loader->L10N->getString('field_size_PB'),
1250+
'document.getElementById',
1251+
'document.all'
1252+
);
12481253
}
12491254
if ($DirValue['type'] === 'timezone') {
12501255
$DirValue['choices'] = ['SYSTEM' => $this->Loader->L10N->getString('field_system_timezone')];
@@ -1491,6 +1496,8 @@ public function view(string $Page = ''): void
14911496
$ThisDir['FieldAppend'] = $ThisDir['autocomplete'] . $ThisDir['Trigger'];
14921497
if (isset($DirValue['pattern'])) {
14931498
$ThisDir['FieldAppend'] .= ' pattern="' . $DirValue['pattern'] . '"';
1499+
} elseif ($DirValue['type'] === 'kb') {
1500+
$ThisDir['FieldAppend'] .= ' pattern="^\d+(\.\d+)?\s*(?:[KkMmGgTtPpOoBb]|К|к|М|м|Г|г|Т|т|П|п|K|k|M|m|G|g|T|t|P|p|Б|б|B|b)(?:[OoBb]|Б|б|B|b)?$"';
14941501
}
14951502
$ThisDir['FieldOut'] = sprintf(
14961503
'<input type="text" name="%1$s" id="%1$s_field" value="%2$s"%3$s />',

0 commit comments

Comments
 (0)