2 /***************************************************************************\
3 * SPIP, Systeme de publication pour l'internet *
5 * Copyright (c) 2001-2014 *
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 \***************************************************************************/
12 if (!defined('_ECRIRE_INC_VERSION')) return;
14 include_spip('inc/actions');
15 include_spip('inc/texte');
17 // http://doc.spip.org/@exec_rechercher_dist
18 function exec_rechercher_dist(){
19 $id = intval(_request('id'));
20 $exclus = intval(_request('exclus'));
21 $rac = spip_htmlentities(_request('rac'));
22 $type = _request('type');
24 if (preg_match('/^\w*$/', $do))
25 $r = exec_rechercher_args($id, $type, $exclus, $rac, $do);
30 // http://doc.spip.org/@exec_rechercher_args
31 function exec_rechercher_args($id, $type, $exclus, $rac, $do){
32 if (!$do) $do = 'aff';
34 $where = preg_split(",\s+,", $type);
36 foreach ($where as $k => $v){
37 $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v,'','string')), 1, -1) . "%'";
39 $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")");
40 $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")");
41 $where_id = ("(id_rubrique = " . intval($type) . ")");
43 $where_titre = " 1=2";
49 include_spip('inc/rubriques');
50 $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT');
51 } else $where_exclus = '';
53 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_id$where_exclus");
55 $points = $rub = array();
57 while ($row = sql_fetch($res)){
58 $id_rubrique = $row["id_rubrique"];
59 $rub[$id_rubrique]["titre"] = typo($row["titre"]);
60 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
61 $points[$id_rubrique] = $points[$id_rubrique]+
3;
63 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_titre$where_exclus");
65 while ($row = sql_fetch($res)){
66 $id_rubrique = $row["id_rubrique"];
67 $rub[$id_rubrique]["titre"] = typo($row["titre"]);
68 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
69 if (isset($points[$id_rubrique]))
70 $points[$id_rubrique] +
= 2;
71 else $points[$id_rubrique] = 0;
73 $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$where_desc$where_exclus");
75 while ($row = sql_fetch($res)){
76 $id_rubrique = $row["id_rubrique"];
77 $rub[$id_rubrique]["titre"] = typo($row["titre"]);
78 $rub[$id_rubrique]["id_parent"] = $row["id_parent"];
79 if (isset($points[$id_rubrique]))
80 $points[$id_rubrique] +
= 1;
81 else $points[$id_rubrique] = 0;
86 $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'";
87 foreach ($rub as $k => $v){
88 $rub[$k]['atts'] = ($v["id_parent"] ?
$style : '')
89 . " class='petite-rubrique'";
93 return (proposer_item($points, $rub, $rac, $type, $do));
96 // Resultat de la recherche interactive demandee par la fonction JS
97 // onkey_rechercher qui testera s'il comporte une seule balise au premier niveau
98 // car cela qui indique qu'un seul resultat a ete trouve.
99 // ==> attention a composer le message d'erreur avec au moins 2 balises
101 // http://doc.spip.org/@proposer_item
102 function proposer_item($ids, $titles, $rac, $type, $do){
105 return "<br /><br /><div style='padding: 5px; color: red;'><b>"
106 . spip_htmlentities($type)
107 . "</b> : " . _T('avis_aucun_resultat') . "</div>";
110 $info = generer_url_ecrire('informer', "type=rubrique&rac=$rac&id=");
112 $onClick = "aff_selection(this.firstChild.title,'$rac" . "_selection','$info', event)";
114 $ondbClick = "$do(this.firstChild.firstChild.nodeValue,this.firstChild.title,'selection_rubrique', 'id_parent');";
116 foreach ($ids as $id => $bof){
118 $titre = strtr(str_replace("'", "’", str_replace('"', """, textebrut($titles[$id]["titre"]))), "\n\r", " ");
120 $ret .= "<div class='highlight off'\nonclick=\"changerhighlight(this); "
122 . "\"\nondblclick=\""
126 . $titles[$id]["atts"]
127 . " title='$id'> "