From aba5ad38a6974361fa42811fedf08c62c3059430 Mon Sep 17 00:00:00 2001
From: Matthieu Marcillaud <marcimat@rezo.net>
Date: Wed, 15 Dec 2021 18:27:51 +0100
Subject: [PATCH] =?UTF-8?q?PHP=208.1=20#4968=20:=20Deprecated--=20sur=20le?=
 =?UTF-8?q?s=20crit=C3=A8res=20optionnels=20{truc=20=3F}.=20On=20passe=20p?=
 =?UTF-8?q?ar=20une=20fonction=20(is=5Fwhereable)=20pour=20d=C3=A9terminer?=
 =?UTF-8?q?=20si=20on=20doit=20appliquer=20le=20where.=20On=20pourra=20tro?=
 =?UTF-8?q?uver=20un=20nommage=20plus=20adapt=C3=A9.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 ecrire/public/criteres.php | 12 ++++++------
 ecrire/public/quete.php    | 17 +++++++++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/ecrire/public/criteres.php b/ecrire/public/criteres.php
index b131264f1a..c446e723cd 100644
--- a/ecrire/public/criteres.php
+++ b/ecrire/public/criteres.php
@@ -1941,13 +1941,13 @@ function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) {
 	// traiter a part la date, elle est mise d'office par SPIP,
 	if ($crit->cond) {
 		$pred = calculer_argument_precedent($idb, $col, $boucles);
-		if ($col == 'date' or $col == 'date_redac') {
-			if ($pred == "\$Pile[0]['" . $col . "']") {
+		if ($col === 'date' or $col === 'date_redac') {
+			if ($pred === "\$Pile[0]['" . $col . "']") {
 				$pred = "(\$Pile[0]['{$col}_default']?'':$pred)";
 			}
 		}
 
-		if ($op == '=' and !$crit->not) {
+		if ($op === '=' and !$crit->not) {
 			$where = [
 				"'?'",
 				"(is_array($pred))",
@@ -1955,10 +1955,10 @@ function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) {
 				$where
 			];
 		}
-		$where = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where];
-		if ($where_complement) {
+		$where = ["'?'", "!is_whereable($pred)", "''", $where];
+		if ($where_complement) { 
 			// condition annexe du type "AND (objet='article')"
-			$where_complement = ["'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement];
+			$where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement];
 		}
 	}
 
diff --git a/ecrire/public/quete.php b/ecrire/public/quete.php
index c87b7f30e5..b3be5e86d2 100644
--- a/ecrire/public/quete.php
+++ b/ecrire/public/quete.php
@@ -707,3 +707,20 @@ function quete_debut_pagination($primary, $valeur, $pas, $iter) {
 	// sinon, calculer le bon numero de page
 	return floor($pos / $pas) * $pas;
 }
+
+/**
+ * Retourne true si ce where doit être appliqué,
+ * dans le cas des critères avec ? tel que `{id_article ?}`
+ *
+ * @param mixed $value
+ * @return boolean
+ */
+function is_whereable($value) : bool {
+	if (is_array($value) && count($value)) {
+		return true;
+	}
+	if (is_scalar($value) && strlen($value)) {
+		return true;
+	}
+	return false;
+}
\ No newline at end of file
-- 
GitLab