From c60a8bbed084e4cb22d50fe676a02f0ce114ea07 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Thu, 7 Aug 2025 11:22:27 +0000 Subject: [PATCH] add(workchronicles): plugin for rendering comics renders comics (for now only workchronicles) directly in Shaarli UI without opening external link --- workchronicles/workchronicles.php | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 workchronicles/workchronicles.php diff --git a/workchronicles/workchronicles.php b/workchronicles/workchronicles.php new file mode 100644 index 0000000..f15c88c --- /dev/null +++ b/workchronicles/workchronicles.php @@ -0,0 +1,96 @@ + Fallback + * + * Pour chaque lien vers workchronicles (site principal ou substack), + * on récupère soit la balise og:image, soit la première
contenant un , + * et on l’affiche inline juste sous le titre, avec une taille de 728×728. + */ + +use Shaarli\Config\ConfigManager; +use Shaarli\Plugin\PluginManager; + +function workchronicles_url(string $url): string +{ + echo "
DEBUG: Checking URL {$url}
"; + $pattern = '~^https?://(?:www\.)?(?:workchronicles\.com|workchronicles\.substack\.com)/\S+~i'; + if (preg_match($pattern, $url, $m)) { + echo "
DEBUG: Matched workchronicles URL {$m[0]}
"; + return $m[0]; + } + echo "
DEBUG: Not a workchronicles URL
"; + return ''; +} + +function hook_workchronicles_render_linklist(array $data): array +{ + echo "
DEBUG: hook_workchronicles_render_linklist start
"; + if (empty($data['links']) || !is_array($data['links'])) { + echo "
DEBUG: Aucun lien à traiter
"; + return $data; + } + + foreach ($data['links'] as &$link) { + $url = $link['url'] ?? ''; + echo "
DEBUG: Processing link {$url}
"; + $page = workchronicles_url($url); + if ('' === $page) { + echo "
DEBUG: Skipping non-workchronicles
"; + continue; + } + + echo "
DEBUG: Fetching page content from {$page}
"; + list($headers, $content) = get_http_response($page); + if (empty($content)) { + echo "
DEBUG: Empty content
"; + continue; + } + + echo "
DEBUG: Page content length: " . strlen($content) . "
"; + + $imgUrl = ''; + if (preg_match('/DEBUG: Found og:image {$imgUrl}"; + } + if ('' === $imgUrl && preg_match('#]*>.*?]+src="([^"]+)"#is', $content, $m2)) { + $imgUrl = $m2[1]; + echo "
DEBUG: Fallback found 
img src {$imgUrl}
"; + } + + if ('' !== $imgUrl) { + $html = '
'; + $html .= 'DEBUG: Injected thumbnail into description"; + } else { + echo "
DEBUG: No image found (og:image nor 
img)
"; + } + } + unset($link); + + echo "
DEBUG: hook_workchronicles_render_linklist end
"; + return $data; +} + +function hook_workchronicles_render_includes(array $data): array +{ + echo "
DEBUG: hook_workchronicles_render_includes
"; + $css = ''; + $data['includes'][] = $css; + echo "
DEBUG: Injected CSS
"; + return $data; +} + +function workchronicles_dummy_translation() +{ + t('WorkChronicles thumbnail plugin'); +}