fix: import URL interne sans cURL (self-reference)
This commit is contained in:
+31
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user