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 { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Checking URL {$url}
"; } $pattern = '~^https?://(?:www\.)?(?:workchronicles\.com|workchronicles\.substack\.com)/\S+~i'; if (preg_match($pattern, $url, $m)) { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Matched workchronicles URL {$m[0]}
"; } return $m[0]; } if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Not a workchronicles URL
"; } return ''; } function hook_workchronicles_render_linklist(array $data): array { $GLOBALS['WC_DEBUG'] = !empty($data['is_admin']) || !empty($data['is_loggedin']); if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: hook_workchronicles_render_linklist start
"; } if (empty($data['links']) || !is_array($data['links'])) { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Aucun lien à traiter
"; } return $data; } foreach ($data['links'] as &$link) { $url = $link['url'] ?? ''; if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Processing link {$url}
"; } $page = workchronicles_url($url); if ('' === $page) { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Skipping non-workchronicles
"; } continue; } if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Fetching page content from {$page}
"; } list($headers, $content) = get_http_response($page); if (empty($content)) { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Empty content
"; } continue; } if (!empty($GLOBALS['WC_DEBUG'])) { 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]; if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Fallback found 
img src {$imgUrl}
"; } } if ('' !== $imgUrl) { $html = '
'; $html .= 'DEBUG: Injected thumbnail into description"; } } else { if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: No image found (og:image nor 
img)
"; } } } unset($link); if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: hook_workchronicles_render_linklist end
"; } return $data; } function hook_workchronicles_render_includes(array $data): array { $GLOBALS['WC_DEBUG'] = !empty($data['is_admin']) || !empty($data['is_loggedin']); if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: hook_workchronicles_render_includes
"; } $css = ''; $data['includes'][] = $css; if (!empty($GLOBALS['WC_DEBUG'])) { echo "
DEBUG: Injected CSS
"; } return $data; } function workchronicles_dummy_translation() { t('WorkChronicles thumbnail plugin'); }