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' => '' 'tip' => ''
)); ));
echo Bootstrap::formSelectGallery(array(
'name' => 'defaultThumbnail',
'label' => $L->g('Default Thumbnail'),
'selected' => $site->defaultThumbnail(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::cardEnd(); echo Bootstrap::cardEnd();
echo Bootstrap::cardBegin($L->g('Thumbnails')); echo Bootstrap::cardBegin($L->g('Thumbnails'));

View file

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

View file

@ -5,23 +5,6 @@ class pluginOpenGraph extends Plugin
public function init() 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() public function siteHead()
@ -88,8 +71,9 @@ class pluginOpenGraph extends Plugin
if ($src !== false) { if ($src !== false) {
$og['image'] = $src; $og['image'] = $src;
} else { } else {
if (Text::isNotEmpty($this->getValue('defaultImage'))) { $thumb = MediaHelper::getDefaultThumbnail();
$og['image'] = $this->getValue('defaultImage'); 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 { .cover-image {
display: block;
max-width: 100%; max-width: 100%;
border-radius: 16px; border-radius: 16px;
height: auto; height: auto;
margin: auto;
} }
.article-metadata { .article-metadata {

View file

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

View file

@ -22,6 +22,10 @@
<!-- Cover image --> <!-- Cover image -->
<?php if ($page->coverImage()) : ?> <?php if ($page->coverImage()) : ?>
<img class="cover-image" alt="" src="<?php echo $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 ?> <?php endif ?>
<!-- Creation date --> <!-- Creation date -->

View file

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