♻️ Start adding stuff to simplify plugin settings

This commit is contained in:
Kazhnuz 2025-07-14 10:56:30 +02:00
parent 5af15e40f8
commit a3ad3ccc8f
3 changed files with 48 additions and 19 deletions

View file

@ -129,6 +129,7 @@ include(PATH_HELPERS . 'image.class.php');
include(PATH_HELPERS . 'tcp.class.php');
include(PATH_HELPERS . 'dom.class.php');
include(PATH_HELPERS . 'cookie.class.php');
include(PATH_HELPERS . 'pluginsettings.class.php');
// Objects
$pages = new Pages();

View file

@ -0,0 +1,45 @@
<?php
class PluginSettings
{
public static function bool($plugin,$settingName, $title, $description = "")
{
global $L;
$html = '<div class="mb-3">';
$html .= '<label class="form-label" for="'.$settingName.'">' . $L->get($title) . '</label>';
$html .= '<select class="form-select" id="'.$settingName.'" name="'.$settingName.'">';
$html .= '<option value="false" ' . ($plugin->getValue($settingName) === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '<option value="true" ' . ($plugin->getValue($settingName) === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '</select>';
if ($description != "") {
$html .= '<div class="form-text">' . $L->get($description) . '</div>';
}
$html .= '</div>';
return $html;
}
public static function values($plugin, $settingName, $title, $values, $description = "")
{
global $L;
$html = '<div class="mb-3">';
$html .= '<label class="form-label" for="'.$settingName.'">' . $L->get($title) . '</label>';
$html .= '<select class="form-select" id="'.$settingName.'" name="'.$settingName.'">';
foreach ($values as $key => $value) {
$html .= '<option value="'.$key.'" ' . ($plugin->getValue($settingName) == $key ? 'selected' : '') . '>' . $L->get($value) . '</option>';
}
$html .= '</select>';
if ($description != "") {
$html .= '<div class="form-text">' . $L->get($description) . '</div>';
}
$html .= '</div>';
return $html;
}
}

View file

@ -13,27 +13,10 @@ class defaultTheme extends Plugin
public function form()
{
global $L;
$html = '';
$html .= '<div class="mb-3">';
$html .= '<label class="form-label" for="showPostInformation">' . $L->get('Show Post Information') . '</label>';
$html .= '<select class="form-select" id="showPostInformation" name="showPostInformation">';
$html .= '<option value="false" ' . ($this->getValue('showPostInformation') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '<option value="true" ' . ($this->getValue('showPostInformation') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div class="mb-3">';
$html .= '<label class="form-label" for="dateFormat">' . $L->get('Date format') . '</label>';
$html .= '<select class="form-select" id="dateFormat" name="dateFormat">';
$html .= '<option value="noshow" ' . ($this->getValue('dateFormat') == 'noshow' ? 'selected' : '') . '>' . $L->get('No show') . '</option>';
$html .= '<option value="relative" ' . ($this->getValue('dateFormat') == 'relative' ? 'selected' : '') . '>' . $L->get('Relative') . '</option>';
$html .= '<option value="absolute" ' . ($this->getValue('dateFormat') == 'absolute' ? 'selected' : '') . '>' . $L->get('Absolute') . '</option>';
$html .= '</select>';
$html .= '<div class="form-text">' . $L->get('Change the date format for the main page.') . '</div>';
$html .= '</div>';
$html .= PluginSettings::bool($this, 'showPostInformation', 'Show Post Information');
$html .= PluginSettings::values($this,'dateFormat', 'Date format', ['noshow'=>'No show', 'relative'=>'Relative', 'absolute'=>'Absolute'], 'Change the date format for the main page.');
return $html;
}