From e51ea9a9f0120a2a4ce929189139a097d7add047 Mon Sep 17 00:00:00 2001
From: JamesRezo <james@rezo.net>
Date: Sun, 30 May 2021 15:25:12 +0200
Subject: [PATCH] remplacement de recuperer_page() par recuperer_url()

---
 ecrire/inc/distant.php                    | 10 ++++++----
 ecrire/inc/filtres.php                    |  6 ++++--
 ecrire/inc/filtres_mime.php               |  4 +++-
 ecrire/inc/math.php                       |  2 +-
 ecrire/inc/xml.php                        |  3 ++-
 ecrire/iterateur/data.php                 |  3 ++-
 ecrire/xml/analyser_dtd.php               |  4 +++-
 prive/formulaires/configurer_relayeur.php |  3 ++-
 8 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/ecrire/inc/distant.php b/ecrire/inc/distant.php
index da7b2b2465..95796b66db 100644
--- a/ecrire/inc/distant.php
+++ b/ecrire/inc/distant.php
@@ -1070,9 +1070,10 @@ function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image =
 	// On va directement charger le debut des images et des fichiers html,
 	// de maniere a attrapper le maximum d'infos (titre, taille, etc). Si
 	// ca echoue l'utilisateur devra les entrer...
-	if ($headers = recuperer_page($source, false, true, $max, '', '', true)) {
-		list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2);
-
+	$reponse = recuperer_url($source, ['taille_max' => $max, 'refuser_gz' => true]);
+	$headers = $reponse['headers'] ?? '';
+	$a['body'] = $reponse['page'] ?? '';
+	if ($headers) {
 		if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) {
 			$mime_type = (trim($regs[1]));
 		} else {
@@ -1184,7 +1185,8 @@ function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image =
 
 	if ($mime_type == 'text/html') {
 		include_spip('inc/filtres');
-		$page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE);
+		$page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]);
+		$page = $page['page'] ?? '';
 		if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) {
 			$a['titre'] = corriger_caracteres(trim($regs[1]));
 		}
diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php
index 578cc8c570..dc59de1f3f 100644
--- a/ecrire/inc/filtres.php
+++ b/ecrire/inc/filtres.php
@@ -2986,7 +2986,7 @@ function direction_css($css, $voulue = '') {
  * Le calcul n'est pas refait si le fichier cache existe déjà et que
  * la source n'a pas été modifiée depuis.
  *
- * @uses recuperer_page() si l'URL source n'est pas sur le même site
+ * @uses recuperer_url() si l'URL source n'est pas sur le même site
  * @uses urls_absolues_css()
  *
  * @param string $css
@@ -3016,7 +3016,9 @@ function url_absolue_css($css) {
 			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
 		) {
 			include_spip('inc/distant');
-			if (!$contenu = recuperer_page($css)) {
+			$contenu = recuperer_url($css);
+			$contenu = $contenu['page'] ?? '';
+			if (!$contenu) {
 				return $css;
 			}
 		}
diff --git a/ecrire/inc/filtres_mime.php b/ecrire/inc/filtres_mime.php
index 6c07c9c1d9..75b417bca8 100644
--- a/ecrire/inc/filtres_mime.php
+++ b/ecrire/inc/filtres_mime.php
@@ -180,8 +180,10 @@ function filtre_text_html_dist($t) {
 	if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) {
 		foreach ($r[0] as $l) {
 			preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m);
+			$page = recuperer_url($m[1]);
+			$page = $page['page'] ?? '';
 			$style .= "\n/* $l */\n"
-				. str_replace('<', '', recuperer_page($m[1]));
+				. str_replace('<', '', $page);
 		}
 	}
 	// Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ?
diff --git a/ecrire/inc/math.php b/ecrire/inc/math.php
index b3e8059ba1..67c11b0e1d 100644
--- a/ecrire/inc/math.php
+++ b/ecrire/inc/math.php
@@ -49,7 +49,7 @@ function produire_image_math($tex) {
 		if ($server) {
 			spip_log($url = $server . '?' . rawurlencode($tex));
 			include_spip('inc/distant');
-			recuperer_page($url, $fichier);
+			recuperer_url($url, ['file' => $fichier]);
 		}
 	}
 
diff --git a/ecrire/inc/xml.php b/ecrire/inc/xml.php
index 6421c86bce..076aa5bb69 100644
--- a/ecrire/inc/xml.php
+++ b/ecrire/inc/xml.php
@@ -50,7 +50,8 @@ function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 10
 	$contenu = "";
 	if (tester_url_absolue($fichier)) {
 		include_spip('inc/distant');
-		$contenu = recuperer_page($fichier, false, false, $taille_max, $datas);
+		$contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]);
+		$contenu = $contenu['page'] ?? '';
 	} else {
 		lire_fichier($fichier, $contenu);
 	}
diff --git a/ecrire/iterateur/data.php b/ecrire/iterateur/data.php
index da8c7231d4..5a6dd54b1c 100644
--- a/ecrire/iterateur/data.php
+++ b/ecrire/iterateur/data.php
@@ -314,7 +314,8 @@ class IterateurDATA implements Iterator {
 					if (is_string($src)) { 
 						if (tester_url_absolue($src)) {
 							include_spip('inc/distant');
-							$data = recuperer_page($src, false, false, _DATA_SOURCE_MAX_SIZE);
+							$data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]);
+							$data = $data['page'] ?? '';
 							if (!$data) {
 								throw new Exception("404");
 							}
diff --git a/ecrire/xml/analyser_dtd.php b/ecrire/xml/analyser_dtd.php
index 057a6d6542..6fd9996c6f 100644
--- a/ecrire/xml/analyser_dtd.php
+++ b/ecrire/xml/analyser_dtd.php
@@ -109,7 +109,9 @@ function analyser_dtd($loc, $avail, &$dtc) {
 	} else {
 		if ($avail == 'PUBLIC') {
 			include_spip('inc/distant');
-			if ($dtd = trim(recuperer_page($loc))) {
+			$dtd = recuperer_url($loc);
+			$dtd = trim($dtd['page'] ?? '');
+			if ($dtd) {
 				ecrire_fichier($file, $dtd, true);
 			}
 		}
diff --git a/prive/formulaires/configurer_relayeur.php b/prive/formulaires/configurer_relayeur.php
index df2c43f266..714720f9ee 100644
--- a/prive/formulaires/configurer_relayeur.php
+++ b/prive/formulaires/configurer_relayeur.php
@@ -56,7 +56,8 @@ function formulaires_configurer_relayeur_verifier_dist() {
 				$cur_http_noproxy = $GLOBALS['meta']['http_noproxy'];
 				$GLOBALS['meta']['http_proxy'] = $http_proxy;
 				$GLOBALS['meta']['http_noproxy'] = $http_noproxy;
-				$page = recuperer_page($test_proxy, true);
+				$page = recuperer_url($test_proxy, ['transcoder' => true]);
+				$page = $page['page'] ?? '';
 				$GLOBALS['meta']['http_proxy'] = $cur_http_proxy;
 				$GLOBALS['meta']['http_noproxy'] = $cur_http_noproxy;
 				if ($page) {
-- 
GitLab