Valider 9acebfe8 rédigé par marcimat's avatar marcimat
Parcourir les fichiers

Notice PHP en moins lors de l’utilisation de la recherche sur le «plongeur»...

Notice PHP en moins lors de l’utilisation de la recherche sur le «plongeur» (sélecteur de rubrique lorsqu’elles sont nombreuses) lors de l’édition d’un article.

Petite réorganisation de ce code pour éviter de lancer les 3 requêtes si on sait qu’il n’y aura pas de résultat au passage.
parent a415b0db
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+25 −42
Numéro de ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -62,6 +62,8 @@ function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
		$do = 'aff';
	}

	$points = $rub = array();

	$where = preg_split(",\s+,", $type);
	if ($where) {
		foreach ($where as $k => $v) {
@@ -70,11 +72,6 @@ function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
		$where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
		$where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
		$where_id = ("(id_rubrique = " . intval($type) . ")");
	} else {
		$where_titre = " 1=2";
		$where_desc = " 1=2";
		$where_id = " 1=2";
	}

		if ($exclus) {
			include_spip('inc/rubriques');
@@ -83,38 +80,24 @@ function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
			$where_exclus = '';
		}

	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");

	$points = $rub = array();

		foreach (array(
			3 => $where_titre,
			2 => $where_desc,
			1 => $where_id,
		) as $point => $recherche) {
			$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
			while ($row = sql_fetch($res)) {
				$id_rubrique = $row["id_rubrique"];
		$rub[$id_rubrique]["titre"] = typo($row["titre"]);
		$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
		$points[$id_rubrique] = $points[$id_rubrique] + 3;
				if (!isset($rub[$id_rubrique])) {
					$rub[$id_rubrique] = array();
				}
	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus");

	while ($row = sql_fetch($res)) {
		$id_rubrique = $row["id_rubrique"];
				$rub[$id_rubrique]["titre"] = typo($row["titre"]);
				$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
		if (isset($points[$id_rubrique])) {
			$points[$id_rubrique] += 2;
		} else {
				if (!isset($points[$id_rubrique])) {
					$points[$id_rubrique] = 0;
				}
				$points[$id_rubrique] = $points[$id_rubrique] + $point;
			}
	$res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus");

	while ($row = sql_fetch($res)) {
		$id_rubrique = $row["id_rubrique"];
		$rub[$id_rubrique]["titre"] = typo($row["titre"]);
		$rub[$id_rubrique]["id_parent"] = $row["id_parent"];
		if (isset($points[$id_rubrique])) {
			$points[$id_rubrique] += 1;
		} else {
			$points[$id_rubrique] = 0;
		}
	}