fix: import URL interne sans cURL (self-reference)

This commit is contained in:
Cedric Abonnel
2026-05-12 23:14:26 +02:00
parent 98ec65f800
commit 0e2a6466a0
+31 -3
View File
@@ -1004,14 +1004,42 @@ switch ($action) {
header('Location: /import/' . rawurlencode($uuid) . '?error=1'); header('Location: /import/' . rawurlencode($uuid) . '?error=1');
exit; 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)) { if (!($step2Meta['ok'] ?? false)) {
header('Location: /import/' . rawurlencode($uuid) . '?error=1'); header('Location: /import/' . rawurlencode($uuid) . '?error=1');
exit; exit;
} }
// Capture d'écran pour prévisualisation (pages HTML uniquement) // Capture d'écran pour prévisualisation (pages HTML uniquement, URL externes uniquement)
$step2Screenshot = null; $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'; $filesDir = BASE_PATH . '/data/' . $uuid . '/files';
if (!is_dir($filesDir)) { if (!is_dir($filesDir)) {
mkdir($filesDir, 0755, true); mkdir($filesDir, 0755, true);