From 0e2a6466a02be50829e0f7f8906b639562d1ea3a Mon Sep 17 00:00:00 2001 From: Cedric Abonnel Date: Tue, 12 May 2026 23:14:26 +0200 Subject: [PATCH] fix: import URL interne sans cURL (self-reference) --- public/index.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/public/index.php b/public/index.php index 15fc7f4..246f9be 100644 --- a/public/index.php +++ b/public/index.php @@ -1004,14 +1004,42 @@ switch ($action) { header('Location: /import/' . rawurlencode($uuid) . '?error=1'); exit; } - $step2Meta = fetchUrlMeta($step2Url); + // Détection URL interne (même hostname que APP_URL → lecture directe sans cURL) + $step2Meta = null; + $step2IsInternal = false; + $_iHost = parse_url(APP_URL, PHP_URL_HOST) ?? ''; + $_uHost = parse_url($step2Url, PHP_URL_HOST) ?? ''; + $_uPath = parse_url($step2Url, PHP_URL_PATH) ?? ''; + if ($_iHost !== '' && $_uHost === $_iHost && preg_match('#^/post/([a-z0-9][a-z0-9-]*)/?$#', $_uPath, $_sm)) { + $_ia = $articles->getBySlug($_sm[1]); + if ($_ia) { + $step2IsInternal = true; + $step2Meta = ['ok' => true, 'title' => $_ia['title'] ?? '', 'mime' => 'text/html']; + if (!empty($_ia['seo_description'])) { + $step2Meta['description'] = $_ia['seo_description']; + } elseif (!empty($_ia['content'])) { + require_once BASE_PATH . '/src/Parsedown.php'; + $_plain = strip_tags((new Parsedown())->text($_ia['content'])); + $step2Meta['description'] = mb_strimwidth(trim(preg_replace('/\s+/', ' ', $_plain)), 0, 155, '…'); + unset($_plain); + } + if (!empty($_ia['cover'])) { + $step2Meta['og_image'] = '/file?uuid=' . rawurlencode($_ia['uuid']) . '&name=' . rawurlencode($_ia['cover']); + } + } + unset($_ia); + } + unset($_iHost, $_uHost, $_uPath, $_sm); + if ($step2Meta === null) { + $step2Meta = fetchUrlMeta($step2Url); + } if (!($step2Meta['ok'] ?? false)) { header('Location: /import/' . rawurlencode($uuid) . '?error=1'); exit; } - // Capture d'écran pour prévisualisation (pages HTML uniquement) + // Capture d'écran pour prévisualisation (pages HTML uniquement, URL externes uniquement) $step2Screenshot = null; - if (str_starts_with($step2Meta['mime'] ?? '', 'text/html')) { + if (!$step2IsInternal && str_starts_with($step2Meta['mime'] ?? '', 'text/html')) { $filesDir = BASE_PATH . '/data/' . $uuid . '/files'; if (!is_dir($filesDir)) { mkdir($filesDir, 0755, true);