blob: 7d29a0e2bec282c57fc1fd7ffda526c5b977866e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
namespace dokuwiki\plugin\config\core\Setting;
/**
* Class setting_multichoice
*/
class SettingMultichoice extends SettingString
{
protected $choices = [];
public $lang; //some custom language strings are stored in setting
/** @inheritdoc */
public function html(\admin_plugin_config $plugin, $echo = false)
{
$disable = '';
$nochoice = '';
if ($this->isProtected()) {
$value = $this->protected;
$disable = ' disabled="disabled"';
} else {
$value = is_null($this->local) ? $this->default : $this->local;
}
// ensure current value is included
if (!in_array($value, $this->choices)) {
$this->choices[] = $value;
}
// disable if no other choices
if (!$this->isProtected() && count($this->choices) <= 1) {
$disable = ' disabled="disabled"';
$nochoice = $plugin->getLang('nochoice');
}
$key = htmlspecialchars($this->key);
$label = '<label for="config___' . $key . '">' . $this->prompt($plugin) . '</label>';
$input = "<div class=\"input\">\n";
$input .= '<select class="edit" id="config___' . $key . '" name="config[' . $key . ']"' . $disable . '>' . "\n";
foreach ($this->choices as $choice) {
$selected = ($value == $choice) ? ' selected="selected"' : '';
$option = $plugin->getLang($this->key . '_o_' . $choice);
if (!$option && isset($this->lang[$this->key . '_o_' . $choice])) {
$option = $this->lang[$this->key . '_o_' . $choice];
}
if (!$option) $option = $choice;
$choice = htmlspecialchars($choice);
$option = htmlspecialchars($option);
$input .= ' <option value="' . $choice . '"' . $selected . ' >' . $option . '</option>' . "\n";
}
$input .= "</select> $nochoice \n";
$input .= "</div>\n";
return [$label, $input];
}
/** @inheritdoc */
public function update($input)
{
if (is_null($input)) return false;
if ($this->isProtected()) return false;
$value = is_null($this->local) ? $this->default : $this->local;
if ($value == $input) return false;
if (!in_array($input, $this->choices)) return false;
$this->local = $input;
return true;
}
}
|