ebabx/site/plugins/promote-button/index.php
isUnknown 22299c30d0 Restructure section École, évolution champs date news-item, traduction promote-button
- Renomme content/presentation en content/ecole avec titre et blueprint mis à jour
- Ajoute les 3 sous-sections (l-ecole, equipe-et-instances, ressources) et leurs 14 sous-pages
- Met à jour la navigation dans site.txt avec l'arborescence complète de École
- Remplace le champ date par startDate/endDate/startHour/endHour dans news-item
- Ajoute page model news-item.php avec categoryLabel() et eventDateInfo()
- Traduit les labels "Text" et "Post To" du plugin promote-button en français

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:23:34 +02:00

179 lines
5.1 KiB
PHP

<?php
load(['scottboms\Promote\PlatformPromoter' => __DIR__ . '/classes/PlatformPromoter.php']);
use ScottBoms\Promote\PlatformPromoter;
use Kirby\Http\Remote;
use Kirby\Cms\App;
// shamelessly borrowed from distantnative/retour-for-kirby
if (
version_compare(App::version() ?? '0.0.0', '5.0.0', '<') === true ||
version_compare(App::version() ?? '0.0.0', '6.0.0', '>=') === true
) {
throw new Exception('Promote Button requires Kirby v4 or v5');
}
Kirby::plugin('scottboms/promote-button', [
'areas' => [
'site' => function () {
return [
'buttons' => [
'promote' => function ($page) {
return [
'icon' => 'megaphone',
'text' => 'Promouvoir',
'theme' => 'pink-icon',
'title' => 'Share this Page',
'dialog' => 'promote/?page=' . $page->uuid()->toString(),
];
},
'profiles' => function () {
$services = option('scottboms.promote.services', []);
$items = [];
foreach ($services as $service) {
if ($service === 'mastodon') {
$host = trim((string) option('scottboms.promote.mastodon.url'));
$user = trim((string) option('scottboms.promote.mastodon.username'));
if ($host && $user) {
$items[] = [
'text' => 'Mastodon',
'icon' => 'mastodon', // keep generic to rule out custom icon issues
'link' => 'https://' . $host . '/@' . $user,
'target' => '_blank',
];
}
} elseif ($service === 'bluesky') {
$handle = trim((string) option('scottboms.promote.bluesky.handle'));
if ($handle) {
$items[] = [
'text' => 'Bluesky',
'icon' => 'bluesky',
'link' => 'https://bsky.app/profile/' . $handle,
'target' => '_blank',
];
}
} elseif ($service === 'linkedin') {
$username = trim((string) option('scottboms.promote.linkedin.username'));
if ($username) {
$items[] = [
'text' => 'LinkedIn',
'icon' => 'linkedin',
'link' => 'https://linkedin.com/in/' . $username,
'target' => '_blank',
];
}
} elseif ($service === 'instagram') {
$username = trim((string) option('scottboms.promote.instagram.username'));
if ($username) {
$items[] = [
'text' => 'Instagram',
'icon' => 'instagram',
'link' => 'https://instagram.com/' . $username,
'target' => '_blank',
];
}
}
}
if (!$items) {
$items[] = [
'text' => 'No profiles configured',
'icon' => 'alert',
'disabled' => true,
];
}
return [
'component' => 'k-profiles-button',
'props' => [
'text' => 'Profiles',
'icon' => 'account',
'theme' => 'pink-icon',
'title' => 'Profiles',
'items' => $items,
],
];
},
],
'dialogs' => [
'promote' => [
'load' => function () {
$page = page(get('page'));
return [
'component' => 'k-form-dialog',
'props' => [
'size' => 'large',
'fields' => [
'text' => [
'label' => 'Texte',
'type' => 'textarea',
'buttons' => false,
'size' => 'small',
'required' => true,
],
'platforms' => [
'label' => 'Publier sur',
'type' => 'checkboxes',
'columns' => max(1, min(3, count(option('scottboms.promote.services', [])))),
'options' => array_map(function ($service) {
$labelMap = [
'mastodon' => 'Mastodon',
'bluesky' => 'Bluesky',
'linkedin' => 'LinkedIn',
'instagram' => 'Instagram',
];
return [
'value' => $service,
'text' => $labelMap[$service] ?? ucfirst($service)
];
}, option('scottboms.promote.services', []))
],
],
'value' => [
'text' => 'Just posted ' . $page->title()->value() . ' ' . (
option('scottboms.promote.host_url')
? rtrim(option('scottboms.promote.host_url'), '/') . '/' . $page->uri()
: $page->url()
),
'platforms' => ['mastodon','bluesky','linkedin'],
],
'submitButton' => [
'icon' => 'megaphone',
'text' => 'Poster',
'theme' => 'pink'
],
],
];
},
'submit' => function () {
$text = get('text');
$enabled = option('scottboms.promote.services', []);
$platforms = array_intersect(get('platforms', []), $enabled);
if (!is_array($platforms)) return false;
$promoter = new ScottBoms\Promote\PlatformPromoter();
foreach ($platforms as $platform) {
$promoter->post($platform, $text);
}
return true;
},
],
],
];
},
],
'info' => [
'homepage' => 'https://github.com/scottboms/kirby-promote-button',
'version' => '1.1.1',
'license' => 'MIT',
'authors' => [[ 'name' => 'Scott Boms' ]],
],
]);