3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2011 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/actions');
16 include_spip('inc/texte');
18 // http://doc.spip.org/@exec_rechercher_dist
19 function exec_rechercher_dist()
21 $id = intval(_request('id'));
22 $exclus = intval(_request('exclus'));
23 $rac = htmlentities(_request('rac'));
24 $type = _request('type');
26 if (preg_match('/^\w*$/', $do))
27 $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
32 // http://doc.spip.org/@exec_rechercher_args
33 function exec_rechercher_args($id, $type, $exclus, $rac, $do)
35 if (!$do) $do = 'aff';
37 $where = preg_split(",\s+,", $type);
39 foreach ($where as $k => $v)
40 $where[$k] = "'%" . substr(str_replace("%","\%", sql_quote($v)),1,-1) . "%'";
41 $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
42 $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
43 $where_id = ("(id_rubrique = " . join(" AND id_rubrique = ", $where) . ")");
45 $where_titre = " 1=2";
51 include_spip('inc/rubriques');
52 $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
53 } else $where_exclus = '';
55 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");
57 $points = $rub = array();
59 while ($row = sql_fetch($res)) {
60 $id_rubrique = $row["id_rubrique"];
61 $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
62 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
63 $points[$id_rubrique] = $points[$id_rubrique] +
3;
65 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus");
67 while ($row = sql_fetch($res)) {
68 $id_rubrique = $row["id_rubrique"];
69 $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
70 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
71 if (isset($points[$id_rubrique]))
72 $points[$id_rubrique] +
= 2;
73 else $points[$id_rubrique] = 0;
75 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus");
77 while ($row = sql_fetch($res)) {
78 $id_rubrique = $row["id_rubrique"];
79 $rub[$id_rubrique]["titre"] = typo ($row["titre"]);
80 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
81 if (isset($points[$id_rubrique]))
82 $points[$id_rubrique] +
= 1;
83 else $points[$id_rubrique] = 0;
88 $style = " style='background-image: url(" . chemin_image('secteur-12.gif') . ")'";
89 foreach($rub as $k => $v) {
90 $rub[$k]['atts'] = ($v["id_parent"] ?
$style : '')
91 . " class='arial11 petite-rubrique'";
95 return (proposer_item($points, $rub, $rac, $type, $do));
98 // Resultat de la recherche interactive demandee par la fonction JS
99 // onkey_rechercher qui testera s'il comporte une seule balise au premier niveau
100 // car cela qui indique qu'un seul resultat a ete trouve.
101 // ==> attention a composer le message d'erreur avec au moins 2 balises
103 // http://doc.spip.org/@proposer_item
104 function proposer_item ($ids, $titles, $rac, $type, $do)
108 return "<br /><br /><div style='padding: 5px; color: red;'><b>"
110 ."</b> : "._T('avis_aucun_resultat')."</div>";
113 $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
115 $onClick = "aff_selection(this.firstChild.title,'$rac". "_selection','$info', event)";
117 $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
119 foreach($ids as $id => $bof) {
121 $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", " ");
123 $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
125 . "\"\nondblclick=\""
129 . $titles[$id]["atts"]
130 . " title='$id'> "