getLang('menu'); } public function getMenuSort() { // keep near other plugin tools return 1011; } public function forAdminOnly() { return true; } public function handle() { global $INPUT; if ($INPUT->str('luxtools_cmd') !== 'save') return; if (!checkSecurityToken()) { msg($this->getLang('err_security'), -1); return; } $newConf = []; // Normalize newlines to "\n" for consistent parsing $paths = $INPUT->str('paths'); $paths = str_replace(["\r\n", "\r"], "\n", $paths); $newConf['paths'] = $paths; $newConf['allow_in_comments'] = (int)$INPUT->bool('allow_in_comments'); $newConf['defaults'] = $INPUT->str('defaults'); $newConf['extensions'] = $INPUT->str('extensions'); $newConf['thumb_placeholder'] = $INPUT->str('thumb_placeholder'); $newConf['gallery_thumb_scale'] = $INPUT->str('gallery_thumb_scale'); $newConf['open_service_url'] = $INPUT->str('open_service_url'); if ($this->savePluginLocalConf($newConf)) { msg($this->getLang('saved'), 1); } else { msg($this->getLang('err_save'), -1); } } public function html() { global $ID; echo '
'; echo '

' . hsc($this->getLang('settings')) . '

'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo formSecurityToken(); echo '
'; echo '' . hsc($this->getLang('legend')) . ''; // paths: multiline textarea $paths = (string)$this->getConf('paths'); echo '
'; // allow_in_comments $checked = $this->getConf('allow_in_comments') ? ' checked="checked"' : ''; echo '
'; // defaults echo '
'; // extensions echo '
'; // thumb_placeholder echo '
'; // gallery_thumb_scale echo '
'; // open_service_url echo '
'; echo ''; echo '
'; echo '
'; echo '
'; } /** * Persist plugin settings to conf/plugins/luxtools.local.php. * * @param array $newConf * @return bool */ protected function savePluginLocalConf(array $newConf) { if (!defined('DOKU_CONF')) return false; $plugin = 'luxtools'; $confDir = DOKU_CONF . 'plugins/'; $file = $confDir . $plugin . '.local.php'; if (function_exists('io_mkdir_p')) { io_mkdir_p($confDir); } elseif (!@is_dir($confDir)) { @mkdir($confDir, 0777, true); } // Only write known keys; ignore extras. $lines = ["configKeys as $key) { if (!array_key_exists($key, $newConf)) continue; $value = $newConf[$key]; $lines[] = '$conf[' . var_export($key, true) . '] = ' . $this->exportPhpValue($value, $key) . ';'; } $lines[] = ''; $content = implode("\n", $lines); if (function_exists('io_saveFile')) { return (bool)io_saveFile($file, $content); } return @file_put_contents($file, $content, LOCK_EX) !== false; } /** * Export a value to PHP code. * * We use nowdoc for multiline strings to safely preserve newlines. * * @param mixed $value * @param string $key * @return string */ protected function exportPhpValue($value, string $key): string { if (is_bool($value) || is_int($value) || is_float($value) || $value === null) { return var_export($value, true); } $value = (string)$value; if (str_contains($value, "\n") || str_contains($value, "\r")) { $marker = strtoupper('LUXTOOLS_' . preg_replace('/[^A-Z0-9_]/i', '_', $key) . '_EOT'); // Extremely unlikely, but avoid delimiter collision. while (str_contains($value, $marker)) { $marker .= '_X'; } return "<<<'$marker'\n" . $value . "\n$marker"; } return var_export($value, true); } }