From 2ae2539ad94e8a91b5485dfe7d30423316d7c7d0 Mon Sep 17 00:00:00 2001
From: Matthieu Marcillaud <marcimat@rezo.net>
Date: Tue, 8 Feb 2022 09:28:26 +0100
Subject: [PATCH] Ticket #5024 : Deprecated-- en PHP 8.1

---
 ecrire/inc/distant.php      | 6 ++----
 ecrire/inc/filtres.php      | 2 +-
 ecrire/inc/utils.php        | 4 ++--
 ecrire/public/aiguiller.php | 5 +++++
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/ecrire/inc/distant.php b/ecrire/inc/distant.php
index c14ffe65bc..38f3fb4001 100644
--- a/ecrire/inc/distant.php
+++ b/ecrire/inc/distant.php
@@ -1317,10 +1317,8 @@ function lance_requete(
 		}
 		$t2 = @parse_url($http_proxy);
 		$first_host = $t2['host'];
-		if (!($port = $t2['port'])) {
-			$port = 80;
-		}
-		if ($t2['user']) {
+		$port = ($t2['port'] ?? null) ?: 80;
+		if ($t2['user'] ?? null) {
 			$proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']);
 		}
 	} else {
diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php
index c8ce7f150d..1b980369da 100644
--- a/ecrire/inc/filtres.php
+++ b/ecrire/inc/filtres.php
@@ -1217,7 +1217,7 @@ function liens_nofollow($texte) {
 
 	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
 		foreach ($regs[0] as $a) {
-			$rel = extraire_attribut($a, 'rel');
+			$rel = extraire_attribut($a, 'rel') ?? '';
 			if (strpos($rel, 'nofollow') === false) {
 				$rel = 'nofollow' . ($rel ? " $rel" : '');
 				$anofollow = inserer_attribut($a, 'rel', $rel);
diff --git a/ecrire/inc/utils.php b/ecrire/inc/utils.php
index 16259c1dc1..823055688a 100644
--- a/ecrire/inc/utils.php
+++ b/ecrire/inc/utils.php
@@ -532,8 +532,8 @@ function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_
  * @return bool
  */
 function tester_url_absolue($url) {
-	$url = trim($url);
-	if (preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
+	$url = trim($url ?? '');
+	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
 		if (
 			isset($m[1])
 			and $p = strtolower(rtrim($m[1], ':'))
diff --git a/ecrire/public/aiguiller.php b/ecrire/public/aiguiller.php
index dea288b570..c13cf32785 100644
--- a/ecrire/public/aiguiller.php
+++ b/ecrire/public/aiguiller.php
@@ -14,7 +14,12 @@ if (!defined('_ECRIRE_INC_VERSION')) {
 	return;
 }
 
+/**
+ * @param string $redirect
+ * @return string
+ */
 function securiser_redirect_action($redirect) {
+	$redirect ??= '';
 	// cas d'un double urlencode : si un urldecode de l'url n'est pas secure, on retient ca comme redirect
 	if (strpos($redirect, '%') !== false) {
 		$r2 = urldecode($redirect);
-- 
GitLab