36 protected $cfg = null;
44 protected $lang = null;
52 protected $metaLangFile;
59 if (is_readable($this->metaLangFile)) {
61 include $this->metaLangFile;
64 $this->lang = array();
77 if (function_exists(
'opcache_invalidate')) {
78 opcache_invalidate($this->filename);
92 $altKey = str_replace(
' ',
'_', $key);
93 if (isset($this->lang[$key])) {
94 $result = $this->lang[$key];
95 } elseif (isset($this->lang[$altKey])) {
96 $result = $this->lang[$altKey];
112 if (strpos($key,
'_') !==
false) {
113 list($first, $rest) = explode(
'_', $key, 2);
118 return array($first, $rest);
131 foreach ($options as $opt) {
132 if ($opt[
'type'] !=
'hidden' && $opt[
'type'] !=
'random' 133 && $advanced == $opt[
'isAdvanced']
157 switch ($opt[
'type']) {
159 $class =
'xh_setting';
161 $class .=
' xh_setting_short';
163 return '<textarea name="' . $iname .
'" rows="1" cols="50"' 164 .
' class="' . $class .
'">' 168 return '<input type="checkbox" name="' . $iname .
'"' 169 . ($opt[
'val'] ?
' checked="checked"' :
'') .
'>';
171 $o =
'<select name="' . $iname .
'">';
172 foreach ($opt[
'vals'] as $val) {
173 $sel = ($val == $opt[
'val']) ?
' selected="selected"' :
'';
174 $label = ($val ==
'')
175 ?
' label="' . $tx[
'label'][
'empty'] .
'"' 177 $o .=
'<option' . $sel . $label .
'>' .
XH_hsc($val) .
'</option>';
182 $o =
'<input type="text" name="' . $iname .
'" value="' 183 .
XH_hsc($opt[
'val']) .
'" class="xh_setting" list="' 184 . $iname .
'_DATA">';
185 $o .=
'<datalist id="' . $iname .
'_DATA">';
186 foreach ($opt[
'vals'] as $val) {
187 $label = ($val ==
'')
188 ?
' label="' . $tx[
'label'][
'empty'] .
'"' 190 $o .=
'<option' . $label .
' value="' .
XH_hsc($val) .
'">';
196 return '<input type="hidden" name="' . $iname .
'" value="' 197 .
XH_hsc($opt[
'val']) .
'">';
199 return '<input type="text" name="' . $iname .
'" value="' 201 .
'" class="xh_setting">';
219 $title = $this->caption;
220 $action = isset($this->plugin) ? $sn .
'?&' . $this->plugin :
$sn;
222 $button =
'<input type="submit" class="submit" value="' . $value .
'">';
223 if (isset($_GET[
'xh_success'])) {
225 $message =
XH_message(
'success', $tx[
'message'][
'saved'], $filetype);
229 $o =
'<h1>' . $this->caption .
'</h1>' . $message
230 .
'<form id="xh_config_form" action="' .
$action 231 .
'" method="post" accept-charset="UTF-8">' 233 . $this->renderFormFields(
false)
234 .
'<div id="xh_config_form_advanced">' 235 . $this->renderFormFields(
true) .
'</div>';
236 foreach ($this->params as $param => $value) {
237 $o .=
'<input type="hidden" name="' . $param .
'" value="' 240 $o .= $_XH_csrfProtection->tokenInput();
241 $o .= $button .
'</form>';
256 foreach ($this->cfg as $category => $options) {
257 $hasVisibleFields = $this->hasVisibleFields($options, $advanced);
258 if ($hasVisibleFields) {
259 $o .=
'<fieldset><legend>' . $this->translate($category)
262 foreach ($options as $name => $opt) {
263 if ($opt[
'isAdvanced'] != $advanced) {
266 $info = isset($opt[
'hint']) ?
XH_helpIcon($opt[
'hint']) .
' ' :
'';
267 if ($opt[
'type'] ==
'hidden' || $opt[
'type'] ==
'random') {
268 $o .= $this->formField($category, $name, $opt);
270 $displayName = $name !=
'' 271 ? str_replace(
'_',
' ', $name)
273 $o .=
'<div class="xh_label">' 274 . $info .
'<span class="xh_label">' 275 . $this->translate($displayName) .
'</span>';
276 if ($category ==
'meta' && $name ==
'description') {
277 $o .=
' <span id="xh_description_length">[' 281 .
'<div class="xh_field">' 282 . $this->formField($category, $name, $opt) .
'</div>' 286 if ($hasVisibleFields) {
309 $_XH_csrfProtection->check();
311 foreach ($this->cfg as $cat => $opts) {
312 foreach ($opts as $name => $opt) {
314 $val = isset($_POST[$iname]) ?
stsl($_POST[$iname]) :
'';
315 if ($opt[
'type'] ==
'bool') {
316 $val = isset($_POST[$iname]) ?
'true' :
'';
317 } elseif ($opt[
'type'] ==
'random') {
318 $val = bin2hex(random_bytes(12));
320 $this->cfg[$cat][$name][
'val'] = $val;
325 return $this->form();
326 } elseif ($this->save()) {
327 header(
'Location: ' .
CMSIMPLE_URL . $this->redir,
true, 303);
330 e(
'cntsave',
'file', $this->filename);
331 return $this->form();
344 protected function option($mcf, $val, $hint)
346 $type = isset($mcf) ? $mcf :
'string';
347 list($typeTag) = explode(
':', $type);
348 if (strpos($typeTag,
'+') === 0) {
349 $type = substr($type, 1);
350 $typeTag = substr($typeTag, 1);
358 $vals = explode(
',', substr($type, strlen($typeTag) + 1));
363 $func = substr($type, strlen($typeTag) + 1);
364 if (function_exists($func)) {
369 $type = ($typeTag ==
'function') ?
'enum' :
'xenum';
374 $co = compact(
'val',
'type',
'vals',
'isAdvanced');
option($mcf, $val, $hint)
hasVisibleFields(array $options, $advanced)
if($cf['site']['compat']) $errors
renderFormFields($advanced)
foreach(XH_plugins() as $plugin) $_XH_csrfProtection
XH_message($type, $message)
formField($cat, $name, array $opt)