2 /***************************************************************************\
3 * SPIP, Systeme de publication pour l'internet *
5 * Copyright (c) 2001-2017 *
6 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
8 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
9 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
10 \***************************************************************************/
13 * Gestion de la recherche ajax du mini navigateur de rubriques
15 * Cette possibilité de recherche apparaît s'il y a beaucoup de rubriques dans le site.
17 * @package SPIP\Core\Rechercher
20 if (!defined('_ECRIRE_INC_VERSION')) {
24 include_spip('inc/actions');
25 include_spip('inc/texte');
28 * Prépare la fonction de recherche ajax du mini navigateur de rubriques
30 * @uses exec_rechercher_args() Formate le rendu de la recherche.
33 function exec_rechercher_dist() {
34 $id = intval(_request('id'));
35 $exclus = intval(_request('exclus'));
36 $rac = spip_htmlentities(_request('rac'));
37 $type = _request('type');
39 if (preg_match('/^\w*$/', $do)) {
40 $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
48 * Formate le rendu de la recherche ajax du mini navigateur de rubriques
50 * @see calcul_branche_in()
51 * @see proposer_item()
55 * @param string|int|array $exclus
56 * @param string|bool $rac
60 function exec_rechercher_args($id, $type, $exclus, $rac, $do) {
65 $points = $rub = array();
67 $where = preg_split(",\s+,", $type);
69 foreach ($where as $k => $v) {
70 $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'";
72 $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
73 $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
74 $where_id = ("(id_rubrique = " . intval($type) . ")");
77 include_spip('inc/rubriques');
78 $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
87 ) as $point => $recherche) {
88 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus");
89 while ($row = sql_fetch($res)) {
90 $id_rubrique = $row["id_rubrique"];
91 if (!isset($rub[$id_rubrique])) {
92 $rub[$id_rubrique] = array();
94 $rub[$id_rubrique]["titre"] = typo($row["titre"]);
95 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
96 if (!isset($points[$id_rubrique])) {
97 $points[$id_rubrique] = 0;
99 $points[$id_rubrique] = $points[$id_rubrique] +
$point;
106 $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
107 foreach ($rub as $k => $v) {
108 $rub[$k]['atts'] = ($v["id_parent"] ?
$style : '')
109 . " class='petite-rubrique'";
113 return (proposer_item($points, $rub, $rac, $type, $do));
118 * Résultat de la recherche intéractive demandée par la fonction JS
122 * `onkey_rechercher()` testera s'il comporte une seule balise au premier niveau
123 * car cela qui indique qu'un seul résultat a été trouvé.
125 * Attention donc à composer le message d'erreur avec au moins 2 balises.
128 * @param array|string $titles
129 * @param string|bool $rac
130 * @param string $type
134 function proposer_item($ids, $titles, $rac, $type, $do) {
137 return "<br /><br /><div style='padding: 5px; color: red;'><b>"
138 . spip_htmlentities($type)
139 . "</b> : " . _T('avis_aucun_resultat') . "</div>";
143 $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
145 $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
147 $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
149 foreach ($ids as $id => $bof) {
151 $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r",
154 $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
156 . "\"\nondblclick=\""
160 . $titles[$id]["atts"]
161 . " title='$id'> "