Add banner and background

This commit is contained in:
Kazhnuz 2025-07-15 14:09:04 +02:00
parent af0b8e9fb7
commit 072728b5c7
3 changed files with 81 additions and 1 deletions

View file

@ -42,4 +42,27 @@ class PluginSettings
return $html;
}
public static function medias($plugin, $settingName, $title, $description = "")
{
global $L;
global $medias;
$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="" ' . ($plugin->getValue($settingName) == '' ? 'selected' : '') . '>' . $L->get('None') . '</option>';
foreach ($medias->content() as $key=>$media) {
$html .= '<option value="'.$key.'" ' . ($plugin->getValue($settingName) == $key ? 'selected' : '') . '>' . $media->name() . '</option>';
}
$html .= '</select>';
if ($description != "") {
$html .= '<div class="form-text">' . $L->get($description) . '</div>';
}
$html .= '</div>';
return $html;
}
}

View file

@ -17,5 +17,29 @@
<?php echo Theme::css('css/'.$themePlugin->getValue('accentColor').'.css'); ?>
<?php endif ?>
<style>
<?php if ($themePlugin->haveBanner()): ?>
#main-header {
background-image: url("<?php echo $themePlugin->bannerURI(); ?>");
text-shadow: 0px 1px 1px rgba(0,0,0,0.8);
<?php if ($themePlugin->getValue('bannerTiled') == false) : ?>
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
<?php endif ?>
}
<?php endif ?>
<?php if ($themePlugin->haveBackground()): ?>
html {
background-image: url("<?php echo $themePlugin->backgroundURI(); ?>");
<?php if ($themePlugin->getValue('backgroundTiled') == false) : ?>
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
<?php endif ?>
}
<?php endif ?>
</style>
<!-- Load Koblog Plugins: Site head -->
<?php Theme::plugins('siteHead'); ?>

View file

@ -8,7 +8,11 @@ class defaultTheme extends Plugin
$this->dbFields = array(
'showPostInformation' => false,
'dateFormat' => 'relative',
'accentColor' => 'default'
'accentColor' => 'default',
'background' => '',
'backgroundTiled' => true,
'banner' => '',
'bannerTiled' => false
);
}
@ -16,6 +20,11 @@ class defaultTheme extends Plugin
{
$html = '';
$html .= PluginSettings::medias($this, 'background', 'Blog background');
$html .= PluginSettings::bool($this, 'backgroundTiled', 'Tiled blog background');
$html .= PluginSettings::medias($this, 'banner', 'Banner background');
$html .= PluginSettings::bool($this, 'bannerTiled', 'Tiled Banner background');
$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.');
$html .= PluginSettings::values($this,'accentColor', 'Accent Color', [
@ -45,4 +54,28 @@ class defaultTheme extends Plugin
{
return $this->getValue('dateFormat');
}
public function haveBanner() {
return ($this->getValue('banner') != '');
}
public function haveBackground() {
return ($this->getValue('background') != '');
}
public function bannerURI()
{
if ($this->getValue('banner') == '') {
return '';
}
return new Media($this->getValue('banner'))->permalink();
}
public function backgroundURI()
{
if ($this->getValue('background') == '') {
return '';
}
return new Media($this->getValue('background'))->permalink();
}
}