Merge pull request 'Social Network handling' (#76) from social-network into koblog2

Reviewed-on: #76
This commit is contained in:
Lake Kazhnuz 2025-07-02 21:08:24 +02:00
commit e2c8cb7201
18 changed files with 206 additions and 124 deletions

View file

@ -17,6 +17,8 @@ First forked version from bludit
- Site: Add support for author view
- Site: Add support for IndieWeb post kinds
- Site: Add a source URL (usefull for some post kinds)
- Theme: Add emoji for social network
- Sidebar: Add a social network widget
### Changed
@ -24,3 +26,4 @@ First forked version from bludit
- Icons: replaced linearicons by fontawesome
- Admin: reworked the theme
- Admin/content: The sidebar is now always visible
- Replace social network by a better list and make them more configurable

View file

@ -249,104 +249,18 @@ echo Bootstrap::formInputHidden(array(
<div class="tab-pane fade" id="social" role="tabpanel" aria-labelledby="nav-social-tab">
<?php
echo Bootstrap::cardBegin($L->g('Social Networks'));
echo Bootstrap::formInputText(array(
'name' => 'twitter',
'label' => 'Twitter',
'value' => $user->twitter(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'facebook',
'label' => 'Facebook',
'value' => $user->facebook(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'codepen',
'label' => 'CodePen',
'value' => $user->codepen(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'instagram',
'label' => 'Instagram',
'value' => $user->instagram(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'gitlab',
'label' => 'GitLab',
'value' => $user->gitlab(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'github',
'label' => 'GitHub',
'value' => $user->github(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'linkedin',
'label' => 'LinkedIn',
'value' => $user->linkedin(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'xing',
'label' => 'Xing',
'value' => $user->xing(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'telegram',
'label' => 'Telegram',
'value' => $user->telegram(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'mastodon',
'label' => 'Mastodon',
'value' => $user->mastodon(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'vk',
'label' => 'VK',
'value' => $user->vk(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $value) {
echo Bootstrap::formInputText(array(
'name' => Text::cleanUrl($value),
'label' => $value,
'value' => $user->getSocialNetwork($value),
'class' => '',
'placeholder' => '',
'tip' => ''
));
}
echo Bootstrap::cardEnd();
?>
</div>

View file

@ -19,7 +19,7 @@
<a class="nav-item nav-link active" id="nav-general-tab" data-bs-toggle="tab" data-bs-target="#general" role="tab" aria-controls="nav-general" aria-selected="false"><?php $L->p('General') ?></a>
<a class="nav-item nav-link" id="nav-advanced-tab" data-bs-toggle="tab" data-bs-target="#advanced" role="tab" aria-controls="nav-advanced" aria-selected="false"><?php $L->p('Advanced') ?></a>
<a class="nav-item nav-link" id="nav-seo-tab" data-bs-toggle="tab" data-bs-target="#seo" role="tab" aria-controls="nav-seo" aria-selected="false"><?php $L->p('SEO') ?></a>
<?php //<a class="nav-item nav-link" id="nav-social-tab" data-bs-toggle="tab" data-bs-target="#social" role="tab" aria-controls="nav-social" aria-selected="false"><?php $L->p('Social Networks') ></a>; ?>
<a class="nav-item nav-link" id="nav-social-tab" data-bs-toggle="tab" data-bs-target="#social" role="tab" aria-controls="nav-social" aria-selected="false"><?php $L->p('Social Networks') ?></a>
<a class="nav-item nav-link" id="nav-images-tab" data-bs-toggle="tab" data-bs-target="#images" role="tab" aria-controls="nav-images" aria-selected="false"><?php $L->p('Images') ?></a>
<a class="nav-item nav-link" id="nav-language-tab" data-bs-toggle="tab" data-bs-target="#language" role="tab" aria-controls="nav-language" aria-selected="false"><?php $L->p('Language') ?></a>
<a class="nav-item nav-link" id="nav-logo-tab" data-bs-toggle="tab" data-bs-target="#logo" role="tab" aria-controls="nav-logo" aria-selected="false"><?php $L->p('Logo') ?></a>
@ -400,6 +400,25 @@ echo Bootstrap::formInputHidden(array(
?>
</div>
<div class="tab-pan fade" id="social" role="tabpanel" aria-labelledby="social-tab">
<?php
echo Bootstrap::cardBegin($L->g('Social Networks'));
foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $value) {
echo Bootstrap::formInputText(array(
'name' => Text::cleanUrl($value),
'label' => $value,
'value' => $site->getSocialNetwork($value),
'class' => '',
'placeholder' => '',
'tip' => ''
));
}
echo Bootstrap::cardEnd();
?>
</div>
<!-- Images tab -->
<div class="tab-pane fade" id="images" role="tabpanel" aria-labelledby="images-tab">
<?php

View file

@ -106,6 +106,7 @@ include(PATH_KERNEL . 'url.class.php');
include(PATH_KERNEL . 'login.class.php');
include(PATH_KERNEL . 'parsedown.class.php');
include(PATH_KERNEL . 'security.class.php');
include(PATH_KERNEL . 'social.class.php');
// Include functions
include(PATH_KERNEL . 'functions.php');

View file

@ -129,4 +129,22 @@ $GLOBALS['POST_KINDS_EMOJI'] = array(
'review'=>'⭐️',
'chicken'=>'🐔',
'literature'=>'📕'
);
$GLOBALS['SOCIAL_NETWORKS'] = array('Mastodon', 'Fediverse', 'Pixelfed', 'Status Cafe', 'SpaceHey', 'Bluesky', 'Git', 'Github', 'Sheezy', 'Diaspora', 'Youtube', 'Peertube', 'Furaffinity');
$GLOBALS['SOCIAL_NETWORKS_EMOJI'] = array(
'mastodon'=>'🦣',
'fediverse'=>'⁂',
'pixelfed'=>'📷',
'status-cafe'=>'☕',
'spacehey'=>'🌌',
'bluesky'=>'🦋',
'git'=>'🧑‍💻',
'github'=>'🧑‍💻',
'sheezy'=>'🎨',
'diaspora'=>'*',
'youtube'=>'📽️',
'peertube'=>'📽️',
'furaffinity'=>'🐾'
);

View file

@ -719,6 +719,13 @@ function editSettings($args)
$pages->setCustomFields($args['customFields']);
}
foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $social) {
$socialKey = Text::cleanUrl($social);
if (isset($args[$socialKey])) {
$site->setSocialNetwork($socialKey, $args[$socialKey]);
}
}
if ($site->set($args)) {
// Check current order-by if changed it reorder the content
if ($site->orderBy() != ORDER_BY) {

View file

@ -6,29 +6,36 @@ class Theme
public static function socialNetworks()
{
global $site;
$socialNetworks = array(
'github' => 'Github',
'gitlab' => 'GitLab',
'twitter' => 'Twitter',
'facebook' => 'Facebook',
'instagram' => 'Instagram',
'codepen' => 'Codepen',
'linkedin' => 'Linkedin',
'xing' => 'Xing',
'telegram' => 'Telegram',
'mastodon' => 'Mastodon',
'vk' => 'VK',
'dribbble' => 'Dribbble'
);
$socialNetworks = array();
foreach ($socialNetworks as $key => $label) {
if (!$site->{$key}()) {
unset($socialNetworks[$key]);
foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $label) {
if ($site->getSocialNetwork($label) != "") {
$socialNetworks[Text::cleanUrl($label)] = $label;
}
}
return $socialNetworks;
}
public static function socialNetworkEmoji($socialNetwork) {
return $GLOBALS['SOCIAL_NETWORKS_EMOJI'][Text::cleanUrl($socialNetwork)];
}
public static function listSiteSocials($list = true, $emoji = false) {
global $site;
$socialList = Theme::socialNetworks();
$socialString = ($list == true) ? "<ul class='social-networks'>" : "";
foreach ($socialList as $key => $name) {
$social = new Social($name, $site->getSocialNetwork($name));
$socialString .= (($list == true) ? "<li class='social'>" : "");
$socialString = $socialString . $social->getLink($emoji);
$socialString .= (($list == true) ? "</li>" : "");
}
$socialString .= (($list == true) ? "</ul>" : "");
return $socialString;
}
public static function title()
{
global $site;

View file

@ -58,7 +58,8 @@ class Site extends dbJSON
'avatarQuality' => 100,
'logo' => '',
'markdownParser' => true,
'customFields' => '{}'
'customFields' => '{}',
'socials' => array()
);
function __construct()
@ -479,4 +480,16 @@ class Site extends dbJSON
$customFields = Sanitize::htmlDecode($this->getField('customFields'));
return json_decode($customFields, true);
}
public function setSocialNetwork($social, $url) {
$key = Text::cleanUrl($social);
if ($this->getField('socials') == NULL) {
$this->db['socials'] = array();
}
$this->db['socials'][$key] = $url;
}
public function getSocialNetwork($social) {
return $this->getField('socials')[Text::cleanUrl($social)];
}
}

View file

@ -0,0 +1,22 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Social {
public $slug;
public $url;
public $emoji;
public $name;
function __construct($name, $url)
{
$this->name = $name;
$this->slug = Text::cleanUrl($name);
$this->emoji = $GLOBALS['SOCIAL_NETWORKS_EMOJI'][$this->slug];
$this->url = $url;
}
function getLink($useEmoji = false) {
return "<a href='". $this->url ."' rel='me'>".($useEmoji ? '<span aria-hidden="true">'.$this->emoji."</span>" : ""). " " . $this->name."</a>";
}
}

View file

@ -205,6 +205,10 @@ class User
return $this->getValue('vk');
}
public function getSocialNetwork($social) {
return $this->getValue('socials')[Text::cleanUrl($social)];
}
public function profilePicture()
{
$filename = $this->getValue('username') . '.png';

View file

@ -26,7 +26,8 @@ class Users extends dbJSON {
'gitlab'=>'',
'linkedin'=>'',
'mastodon'=>'',
'vk'=>''
'vk'=>'',
'socials' => array()
);
function __construct()
@ -128,6 +129,14 @@ class Users extends dbJSON {
$row['tokenAuth'] = $this->generateAuthToken();
}
$row['socials'] = array();
foreach ($GLOBALS['SOCIAL_NETWORKS'] as $key => $social) {
$socialKey = Text::cleanUrl($social);
if (isset($args[$socialKey])) {
$row['socials'][$socialKey] = $args[$socialKey];
}
}
// Save the database
$this->db[$username] = $row;
return $this->save();

View file

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Social Networks",
"description": "Shows the social network list in the sidebar."
}
}

View file

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Réseaux sociaux",
"description": "Affiche la liste des réseaux sociaux dans la barre latérale."
}
}

View file

@ -0,0 +1,11 @@
{
"author": "Koblog",
"email": "",
"website": "https://plugins.koblog.com",
"version": "kb_0.0.1",
"releaseDate": "2024-08-23",
"license": "MIT",
"compatible": "kb_0.0.1",
"notes": "",
"type": "widget"
}

View file

@ -0,0 +1,40 @@
<?php
class pluginSocials extends Plugin {
public function init()
{
$this->dbFields = array(
'label' => 'Social Networks',
);
}
public function form()
{
global $L;
$html = '<div>';
$html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>';
return $html;
}
// Method called on the sidebar of the website
public function siteSidebar()
{
global $L;
global $url;
$html = '<div class="plugin plugin-archives">';
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">';
$html .= Theme::listSiteSocials(true, true);
$html .= '</div>';
$html .= '</div>';
return $html;
}
}

View file

@ -20,9 +20,9 @@
<!-- Social Networks -->
<?php foreach (Theme::socialNetworks() as $key=>$label): ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $site->{$key}(); ?>" target="_blank">
<img class="d-none d-sm-block nav-svg-icon" src="<?php echo DOMAIN_THEME.'img/'.$key.'.svg' ?>" alt="<?php echo $label ?>" />
<span class="d-inline d-sm-none"><?php echo $label; ?></span>
<a class="nav-link" href="<?php echo $site->getSocialNetwork($label); ?>" target="_blank" rel="me">
<span aria-hidden="true"><?php echo Theme::socialNetworkEmoji($label); ?></span>
<span class="visually-hidden"><?php echo $label; ?></span>
</a>
</li>
<?php endforeach; ?>

View file

@ -19,9 +19,9 @@
<!-- Social Networks -->
<?php foreach (Theme::socialNetworks() as $key => $label) : ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo $site->{$key}(); ?>" target="_blank">
<img class="d-none d-sm-block nav-svg-icon" src="<?php echo DOMAIN_THEME . 'img/' . $key . '.svg' ?>" alt="<?php echo $label ?>" />
<span class="d-inline d-sm-none"><?php echo $label; ?></span>
<a class="nav-link" href="<?php echo $site->getSocialNetwork($label); ?>" target="_blank" rel="me">
<span aria-hidden="true"><?php echo Theme::socialNetworkEmoji($label); ?></span>
<span class="visually-hidden"><?php echo $label; ?></span>
</a>
</li>
<?php endforeach; ?>

View file

@ -2,7 +2,7 @@
<div class="container">
<ul class="footer-links pl-0 mb-1">
<?php foreach (Theme::socialNetworks() as $key => $name) {
echo '<a class="color-blue" href="' . $site->{$key}() . '"><li class="d-inline-block pr-4">' . $name . '</li></a>';
echo '<a class="color-blue" href="' . $site->getSocialNetwork($name); . '"><li class="d-inline-block pr-4">' . $name . '</li></a>';
}
?>
</ul>