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'); }