Global thumbnail support

This commit is contained in:
Kazhnuz 2025-07-15 19:13:34 +02:00
parent 6b6baab945
commit 5b9b7bea85
8 changed files with 57 additions and 23 deletions

View file

@ -455,6 +455,15 @@ echo Bootstrap::formInputHidden(array(
'tip' => ''
));
echo Bootstrap::formSelectGallery(array(
'name' => 'defaultThumbnail',
'label' => $L->g('Default Thumbnail'),
'selected' => $site->defaultThumbnail(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::cardEnd();
echo Bootstrap::cardBegin($L->g('Thumbnails'));

View file

@ -23,4 +23,19 @@ class MediaHelper {
return MediaHelper::getImage($site->favicon());
}
public static function getDefaultThumbnail()
{
global $site;
return MediaHelper::getImage($site->defaultThumbnail());
}
public static function toHTML($media, $classes = "")
{
if ($media != null) {
return $media->toHTML($classes);
} else {
return "";
}
}
}

View file

@ -59,6 +59,7 @@ class Site extends dbJSON
'avatarQuality' => 100,
'logo' => '',
'favicon' => '',
'defaultThumbnail' => '',
'markdownParser' => true,
'customFields' => '{}',
'socials' => array()
@ -354,6 +355,11 @@ class Site extends dbJSON
return $this->getField('favicon');
}
public function defaultThumbnail()
{
return $this->getField('defaultThumbnail');
}
// Returns the full domain and base url
// For example, https://www.domain.com/koblog
public function url()

View file

@ -5,23 +5,6 @@ class pluginOpenGraph extends Plugin
public function init()
{
// Fields and default values for the database of this plugin
$this->dbFields = array(
'defaultImage' => ''
);
}
public function form()
{
global $L;
$html = '<div>';
$html .= '<label>' . $L->get('Default image') . '</label>';
$html .= '<input id="jsdefaultImage" name="defaultImage" type="text" dir="auto" value="' . $this->getValue('defaultImage') . '" placeholder="https://">';
$html .= '<span class="tip">' . $L->g('set-a-default-image-for-content') . '</span>';
$html .= '</div>';
return $html;
}
public function siteHead()
@ -88,8 +71,9 @@ class pluginOpenGraph extends Plugin
if ($src !== false) {
$og['image'] = $src;
} else {
if (Text::isNotEmpty($this->getValue('defaultImage'))) {
$og['image'] = $this->getValue('defaultImage');
$thumb = MediaHelper::getDefaultThumbnail();
if ($thumb != null) {
$og['image'] = $site->url() . "/" . $thumb->permalink();
}
}
}

View file

@ -513,9 +513,11 @@ table tbody tr:last-child th:last-child {
}
.cover-image {
display: block;
max-width: 100%;
border-radius: 16px;
height: auto;
margin: auto;
}
.article-metadata {

View file

@ -39,6 +39,13 @@
<?php endif ?>
}
<?php endif ?>
<?php if ($themePlugin->smallThumb()): ?>
.cover-image {
max-height:200px;
width: 100%;
object-fit: cover;
}
<?php endif ?>
</style>
<!-- Load Koblog Plugins: Site head -->

View file

@ -22,6 +22,10 @@
<!-- Cover image -->
<?php if ($page->coverImage()) : ?>
<img class="cover-image" alt="" src="<?php echo $page->coverImage(); ?>" />
<?php else : ?>
<?php if ($themePlugin->showDefaultThumbnail() == true): ?>
<?php echo MediaHelper::toHTML(MediaHelper::getDefaultThumbnail(), "cover-image"); ?>
<?php endif ?>
<?php endif ?>
<!-- Creation date -->

View file

@ -6,12 +6,13 @@ class defaultTheme extends Plugin
public function init()
{
$this->dbFields = array(
'showPostInformation' => false,
'showDefaultThumbnail' => false,
'dateFormat' => 'relative',
'accentColor' => 'default',
'background' => '',
'backgroundTiled' => true,
'banner' => '',
'smallThumb' => false,
'bannerTiled' => false
);
}
@ -25,7 +26,8 @@ class defaultTheme extends Plugin
$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::bool($this, 'showDefaultThumbnail', 'Show Default Thumbnail');
$html .= PluginSettings::bool($this, 'smallThumb', 'Small Thumbnail');
$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', [
'default'=>'Blue',
@ -45,9 +47,14 @@ class defaultTheme extends Plugin
return $html;
}
public function showPostInformation()
public function smallThumb()
{
return $this->getValue('showPostInformation');
return $this->getValue('smallThumb');
}
public function showDefaultThumbnail()
{
return $this->getValue('showDefaultThumbnail');
}
public function dateFormat()