217 |
jpm |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.1 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of Papyrus. |
|
|
|
9 |
// | |
|
|
|
10 |
// | Foobar is free software; you can redistribute it and/or modify |
|
|
|
11 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
12 |
// | the Free Software Foundation; either version 2 of the License, or |
|
|
|
13 |
// | (at your option) any later version. |
|
|
|
14 |
// | |
|
|
|
15 |
// | Foobar is distributed in the hope that it will be useful, |
|
|
|
16 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
17 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
18 |
// | GNU General Public License for more details. |
|
|
|
19 |
// | |
|
|
|
20 |
// | You should have received a copy of the GNU General Public License |
|
|
|
21 |
// | along with Foobar; if not, write to the Free Software |
|
|
|
22 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
23 |
// +------------------------------------------------------------------------------------------------------+
|
1025 |
jp_milcent |
24 |
// CVS : $Id: moteur_recherche.php,v 1.13 2006-10-10 12:02:30 jp_milcent Exp $
|
217 |
jpm |
25 |
/**
|
|
|
26 |
* Applette : moteur de recherche
|
|
|
27 |
*
|
|
|
28 |
* Génère un formulaire contenant une zone de saisie permettant de taper un texte à rechercher sur l'ensemble
|
|
|
29 |
* des sites gérés par Papyrus.
|
339 |
jpm |
30 |
* Utilisation des bibliothèques inclue par Papyrus :
|
|
|
31 |
* - Papyrus pap_meta.fonct.php
|
|
|
32 |
* - PEAR NET_URL
|
217 |
jpm |
33 |
*
|
|
|
34 |
*@package Applette
|
|
|
35 |
*@subpackage Moteur_recherche
|
|
|
36 |
//Auteur original :
|
|
|
37 |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
38 |
//Autres auteurs :
|
|
|
39 |
*@author Aucun
|
|
|
40 |
*@copyright Tela-Botanica 2000-2004
|
1025 |
jp_milcent |
41 |
*@version $Revision: 1.13 $ $Date: 2006-10-10 12:02:30 $
|
217 |
jpm |
42 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
43 |
*/
|
|
|
44 |
|
|
|
45 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
46 |
// | ENTETE du PROGRAMME |
|
|
|
47 |
// +------------------------------------------------------------------------------------------------------+
|
339 |
jpm |
48 |
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherMoteurRecherche';
|
|
|
49 |
$GLOBALS['_GEN_commun']['info_applette_balise'] = 'MOTEUR_RECHERCHE';
|
217 |
jpm |
50 |
|
|
|
51 |
// --------------------------------------------------------------------------------------------------------
|
339 |
jpm |
52 |
//Utilisation de la bibliothèque Papyrus pap_meta.fonct.php inclue par Papyrus
|
|
|
53 |
//Utilisation de la bibliothèque PEAR NET_URL inclue par Papyrus
|
217 |
jpm |
54 |
/** Inclusion du fichier de configuration de cette application.*/
|
|
|
55 |
require_once GEN_CHEMIN_APPLETTE.'moteur_recherche/configuration/more_configuration.inc.php';
|
846 |
jp_milcent |
56 |
/** Inclusion du fichier de configuration des Spip.*/
|
|
|
57 |
require_once GEN_CHEMIN_APPLETTE.'moteur_recherche/configuration/more_config_spip.inc.php';
|
217 |
jpm |
58 |
/** Inclusion de la bibliothèque PEAR de conception de formulaire.*/
|
|
|
59 |
require_once MORE_CHEMIN_BIBLIOTHEQUE_PEAR.'HTML/QuickForm.php';
|
|
|
60 |
|
|
|
61 |
// Inclusion des fichiers de traduction de l'appli ADME dePapyrus
|
339 |
jpm |
62 |
if (file_exists(MORE_CHEMIN_LANGUE.'more_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
|
217 |
jpm |
63 |
/** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
|
339 |
jpm |
64 |
require_once MORE_CHEMIN_LANGUE.'more_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
|
217 |
jpm |
65 |
} else {
|
|
|
66 |
/** Inclusion du fichier de traduction par défaut.*/
|
|
|
67 |
require_once MORE_CHEMIN_LANGUE.'more_langue_'.MORE_I18N_DEFAUT.'.inc.php';
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
71 |
// | CORPS du PROGRAMME |
|
|
|
72 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
73 |
|
|
|
74 |
if (isset($_POST['more_motif']) && $_POST['more_motif'] != '') {
|
|
|
75 |
// Initialisation de variable extérieures
|
846 |
jp_milcent |
76 |
$GLOBALS['_VEI_']['usurpation'] = MORE_LG_USURPATION.htmlentities(stripslashes($_POST['more_motif']));
|
217 |
jpm |
77 |
$GLOBALS['_PAPYRUS_']['general']['application_chemin'] = null;
|
|
|
78 |
// Modification des meta de l'entête de la page
|
846 |
jp_milcent |
79 |
GEN_modifierMetaHttpEquiv('Content-Type', 'text/html; charset=ISO-8859-15');
|
217 |
jpm |
80 |
GEN_modifierMetaHttpEquiv('Content-style-type', 'text/css');
|
|
|
81 |
GEN_modifierMetaHttpEquiv('Content-script-type', 'text/javascript');
|
339 |
jpm |
82 |
GEN_modifierMetaHttpEquiv('Content-language', $GLOBALS['_GEN_commun']['i18n']);
|
217 |
jpm |
83 |
|
|
|
84 |
GEN_modifierMetaName('revisit-after', '15 days');
|
|
|
85 |
GEN_modifierMetaName('robots', 'index,follow');
|
|
|
86 |
GEN_modifierMetaName('author', 'Tela Botanica');
|
|
|
87 |
GEN_modifierMetaName('keywords', 'Recherche, résultat.');
|
|
|
88 |
GEN_modifierMetaName('description', 'Page de résultats du moteur de recherche de Papyrus.');
|
|
|
89 |
|
|
|
90 |
GEN_viderMeta('dc');
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
94 |
// | LISTE de FONCTIONS |
|
|
|
95 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
96 |
|
850 |
florian |
97 |
/** Fonction afficherMoteurRecherche() - Fournit un formulaire de recherche.
|
217 |
jpm |
98 |
*
|
|
|
99 |
* Renvoie un formulaire permettant de rechercher une chaine de caractères dans les sites
|
|
|
100 |
* gérés par Papyrus.
|
|
|
101 |
* Necessite l'utilisation de Pear Net_URL par le programme appelant cette fonction.
|
|
|
102 |
*
|
|
|
103 |
* @param array tableau d'éventuel arguments présent dans la balise transmis à la fonction.
|
|
|
104 |
* @param array tableau global de Papyrus.
|
|
|
105 |
* @return string formulaire XHTML de recherche.
|
|
|
106 |
*/
|
|
|
107 |
function afficherMoteurRecherche($tab_applette_arguments, $_GEN_commun)
|
|
|
108 |
{
|
|
|
109 |
// --------------------------------------------------------------------------------------------------------
|
|
|
110 |
// Initialisation de variable de configuration.
|
|
|
111 |
$liste_type_site = '102, 103';// Les id des types des sites pouvant apparaître dans le sélecteur
|
339 |
jpm |
112 |
$objet_pear_db =& $_GEN_commun['pear_db'];//objet Pear créé par DB contenant la connexion à la base de données.
|
|
|
113 |
$GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'] =& $_GEN_commun['pear_db'];// Connexion à la BD de Papyrus
|
|
|
114 |
$code_site = $_GEN_commun['url_site'];// identifiant du site courant.
|
217 |
jpm |
115 |
$url = $_GEN_commun['url'];
|
|
|
116 |
$url_base = PAP_URL;
|
|
|
117 |
$url_id_type_site = GEN_URL_ID_TYPE_SITE;
|
|
|
118 |
$indent_origine = 12;// Indentation de départ en nombre d'espace
|
|
|
119 |
$indent_pas = 4;// Pas d'indentation en nombre d'espace
|
|
|
120 |
$retour = '';
|
|
|
121 |
$retour_resultats = '';
|
846 |
jp_milcent |
122 |
// Titre de la page
|
850 |
florian |
123 |
if (isset($_POST['more_motif'])) {
|
|
|
124 |
$GLOBALS['_PAPYRUS_']['rendu']['TITRE_PAGE'] = MORE_LG_TITRE.htmlentities(stripslashes($_POST['more_motif']));
|
|
|
125 |
}
|
217 |
jpm |
126 |
|
|
|
127 |
// --------------------------------------------------------------------------------------------------------
|
|
|
128 |
// Lancement de la recherche si nécessaire
|
|
|
129 |
|
|
|
130 |
$_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = '';
|
|
|
131 |
if (!isset($_POST['more_motif']) || $_POST['more_motif'] == '') {
|
|
|
132 |
$_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = MORE_LG_FORM_MOTIF_VALUE;
|
|
|
133 |
} else {
|
|
|
134 |
$_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = $_POST['more_motif'];
|
|
|
135 |
/** Inclusion de la classe Recherche.*/
|
|
|
136 |
require_once MORE_CHEMIN_BIBLIO.'more_recherche.class.php';
|
846 |
jp_milcent |
137 |
/** Inclusion de la classe Recherche_Papyrus_Menu.*/
|
217 |
jpm |
138 |
require_once MORE_CHEMIN_BIBLIO.'more_recherche_papyrus_menu.class.php';
|
846 |
jp_milcent |
139 |
/** Inclusion de la classe Recherche_Spip_Article.*/
|
|
|
140 |
require_once MORE_CHEMIN_BIBLIO.'more_recherche_spip_article.class.php';
|
217 |
jpm |
141 |
$moteur = new Recherche($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
|
|
|
142 |
$recherche_papyrus_menu = new Recherche_Papyrus_Menu($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
|
846 |
jp_milcent |
143 |
$recherche_spip_article = new Recherche_Spip_Article($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
|
217 |
jpm |
144 |
$moteur->ajouterRecherche($recherche_papyrus_menu);
|
846 |
jp_milcent |
145 |
$moteur->ajouterRecherche($recherche_spip_article);
|
217 |
jpm |
146 |
$aso_resultats = $moteur->rechercherMotif();
|
|
|
147 |
//$GLOBALS['_DEBOGAGE_'] = '<pre>'.print_r($aso_resultats, true).'</pre>';
|
846 |
jp_milcent |
148 |
$nbre_pages = count($aso_resultats);
|
|
|
149 |
if ($nbre_pages <= 1) {
|
|
|
150 |
$retour_resultats .= '<h1>'.sprintf(MORE_LG_RESULTAT_TITRE, $nbre_pages).'</h1>'."\n";
|
|
|
151 |
} else {
|
|
|
152 |
$retour_resultats .= '<h1>'.sprintf(MORE_LG_RESULTAT_TITRE_PLURIEL, $nbre_pages).'</h1>'."\n";
|
|
|
153 |
}
|
|
|
154 |
if ($nbre_pages == 0) {
|
373 |
jpm |
155 |
$retour_resultats .= '<p class="information">'.MORE_LG_RESULTAT_VIDE.'</p>'."\n";
|
|
|
156 |
} else {
|
|
|
157 |
$retour_resultats .= '<ul id="more_resultat">'."\n";
|
|
|
158 |
foreach ($aso_resultats as $val) {
|
|
|
159 |
if (!empty($val['url'])) {
|
|
|
160 |
$retour_resultats .= '<li>'."\n";
|
|
|
161 |
$retour_resultats .= '<h2><a href="'.$val['url'].'" ';
|
|
|
162 |
if ($val['hreflang'] != '') {
|
|
|
163 |
$retour_resultats .= 'hreflang="'.$val['hreflang'].'" ';
|
|
|
164 |
}
|
|
|
165 |
if ($val['accesskey'] != '') {
|
|
|
166 |
$retour_resultats .= 'accesskey="'.$val['accesskey'].'" ';
|
|
|
167 |
}
|
|
|
168 |
if ($val['title'] != '') {
|
|
|
169 |
$retour_resultats .= 'title="'.$val['title'].'" ';
|
|
|
170 |
}
|
|
|
171 |
$retour_resultats .= '>'.$val['titre'].'</a></h2>';
|
|
|
172 |
$retour_resultats .= '<dl>'."\n";
|
|
|
173 |
//if (trim($val['poids']) != '') {
|
|
|
174 |
// $retour_resultats .= '<dt>'.MORE_LG_RESULTAT_POIDS.'</dt>'."\n";
|
|
|
175 |
// $retour_resultats .= '<dd>'.$val['poids'].'</dd>'."\n";
|
|
|
176 |
//}
|
|
|
177 |
if (trim($val['score']) != '') {
|
|
|
178 |
$retour_resultats .= '<dt>'.MORE_LG_RESULTAT_SCORE.'</dt>'."\n";
|
|
|
179 |
$retour_resultats .= '<dd>'.$val['score'].MORE_LG_RESULTAT_POURCENT.'</dd>'."\n";
|
|
|
180 |
}
|
|
|
181 |
if (trim($val['date_creation']) != '') {
|
|
|
182 |
$retour_resultats .= '<dt>'.MORE_LG_RESULTAT_DATE_CREATION.'</dt>'."\n";
|
|
|
183 |
$retour_resultats .= '<dd>'.$val['date_creation'].'</dd>'."\n";
|
|
|
184 |
}
|
|
|
185 |
if (trim($val['description']) != '') {
|
|
|
186 |
$retour_resultats .= '<dt>'.MORE_LG_RESULTAT_DESCRIPTION.'</dt>'."\n";
|
|
|
187 |
$retour_resultats .= '<dd>'.$val['description'].'</dd>'."\n";
|
|
|
188 |
}
|
|
|
189 |
$retour_resultats .= '</dl>'."\n";
|
|
|
190 |
$retour_resultats .= '</li>'."\n";
|
339 |
jpm |
191 |
}
|
217 |
jpm |
192 |
}
|
373 |
jpm |
193 |
$retour_resultats .= '</ul>'."\n";
|
217 |
jpm |
194 |
}
|
|
|
195 |
$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_NAVIGATION'] = '';
|
|
|
196 |
$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_TETE'] = '';
|
|
|
197 |
$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_CORPS'] = $retour_resultats;
|
|
|
198 |
$GLOBALS['_PAPYRUS_']['rendu']['CONTENU_PIED'] = '';
|
|
|
199 |
$GLOBALS['_GEN_commun']['info_menu'] = '';
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
// --------------------------------------------------------------------------------------------------------
|
|
|
203 |
// Création du formulaire de l'applette
|
|
|
204 |
|
|
|
205 |
// Notes : Quickform semble remplacer les & des & à nouveau par des & solution utiliser str_replace()...
|
272 |
jpm |
206 |
$more_form = new HTML_QuickForm('form_more_recherche', 'post', str_replace('&', '&', $url->getUrl()));
|
217 |
jpm |
207 |
$tab_index = MORE_FORM_MOTIF_TAB;
|
272 |
jpm |
208 |
$more_squelette =& $more_form->defaultRenderer();
|
|
|
209 |
$more_squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>');
|
|
|
210 |
$more_squelette->setElementTemplate( '{label}'."\n".
|
217 |
jpm |
211 |
'{element}'."\n".
|
|
|
212 |
'<!-- BEGIN required --><span class="symbole_obligatoire">'.MORE_LG_FORM_SYMBOLE_OBLIGATOIRE.'</span><!-- END required -->'."\n".
|
|
|
213 |
'<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n");
|
272 |
jpm |
214 |
$more_form->accept($more_squelette);
|
|
|
215 |
$more_form->removeAttribute('name');
|
217 |
jpm |
216 |
|
|
|
217 |
$partie_menu_debut = '<fieldset>'."\n".'<legend>'.MORE_LG_FORM_TITRE.'</legend>'."\n";
|
272 |
jpm |
218 |
$more_form->addElement('html', $partie_menu_debut);
|
217 |
jpm |
219 |
|
|
|
220 |
$id = 'more_motif';
|
467 |
ddelon |
221 |
$aso_attributs = array( 'id'=>$id, 'tabindex' => $tab_index++, 'maxlength' => MORE_FORM_MOTIF_MAXLENGTH,
|
846 |
jp_milcent |
222 |
'accesskey' => MORE_LG_FORM_ACCESSKEY);
|
217 |
jpm |
223 |
$label = '<label for="'.$id.'">'.MORE_LG_FORM_MOTIF.'</label>';
|
272 |
jpm |
224 |
$more_form->addElement('text', $id, $label, $aso_attributs);
|
217 |
jpm |
225 |
|
|
|
226 |
$id = 'more_ok';
|
|
|
227 |
$aso_attributs = array('id'=> $id, 'tabindex' => $tab_index++);
|
272 |
jpm |
228 |
$more_form->addElement('submit', $id, MORE_LG_FORM_VALIDER, $aso_attributs);
|
217 |
jpm |
229 |
|
|
|
230 |
$partie_entete_fin = "\n".'</fieldset>';
|
272 |
jpm |
231 |
$more_form->addElement('html', $partie_entete_fin);
|
217 |
jpm |
232 |
|
|
|
233 |
// Instanciation avec les valeur par défaut
|
272 |
jpm |
234 |
$more_form->setDefaults($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']);
|
217 |
jpm |
235 |
|
|
|
236 |
// Transformation en XHTML du formulaire
|
272 |
jpm |
237 |
$retour .= $more_form->toHTML()."\n";
|
217 |
jpm |
238 |
// --------------------------------------------------------------------------------------------------------
|
|
|
239 |
|
|
|
240 |
return $retour;
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
244 |
// | PIED du PROGRAMME |
|
|
|
245 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
249 |
*
|
|
|
250 |
* $Log: not supported by cvs2svn $
|
1025 |
jp_milcent |
251 |
* Revision 1.12 2006/06/16 09:45:10 jp_milcent
|
|
|
252 |
* Correction bogue lié à la suppression de l'objet info_menu.
|
|
|
253 |
*
|
862 |
jp_milcent |
254 |
* Revision 1.11 2006/05/23 13:39:13 florian
|
|
|
255 |
* corection bug notice de jean pascal ;-)
|
|
|
256 |
*
|
850 |
florian |
257 |
* Revision 1.10 2006/05/19 10:04:55 jp_milcent
|
|
|
258 |
* Ajout d'un moteur de recherche analysant les articles des sites sous Spip.
|
|
|
259 |
*
|
846 |
jp_milcent |
260 |
* Revision 1.9 2006/04/28 12:41:49 florian
|
|
|
261 |
* corrections erreurs chemin
|
|
|
262 |
*
|
832 |
florian |
263 |
* Revision 1.8 2006/03/02 10:49:49 ddelon
|
|
|
264 |
* Fusion branche multilinguisme dans branche principale
|
|
|
265 |
*
|
754 |
ddelon |
266 |
* Revision 1.7.2.2 2005/12/27 15:56:00 ddelon
|
|
|
267 |
* Fusion Head vers multilinguisme (wikini double clic)
|
|
|
268 |
*
|
|
|
269 |
* Revision 1.7.2.1 2005/12/20 14:40:25 ddelon
|
|
|
270 |
* Fusion Head vers Livraison
|
|
|
271 |
*
|
|
|
272 |
* Revision 1.7 2005/09/27 09:07:32 ddelon
|
|
|
273 |
* size applette et squelettes
|
|
|
274 |
*
|
467 |
ddelon |
275 |
* Revision 1.6 2005/05/25 13:49:22 jpm
|
|
|
276 |
* Corection erreur pour la recherche dans le contenu.
|
|
|
277 |
*
|
373 |
jpm |
278 |
* Revision 1.5 2005/05/19 12:46:12 jpm
|
|
|
279 |
* Correction bogue accesskey.
|
|
|
280 |
* Ajout d'un id à la liste.
|
|
|
281 |
* Arrondissement des score.
|
|
|
282 |
*
|
368 |
jpm |
283 |
* Revision 1.4 2005/04/14 17:39:34 jpm
|
|
|
284 |
* Amélioration du moteur de rechercher :
|
|
|
285 |
* - pourcentage
|
|
|
286 |
* - ajout d'info
|
|
|
287 |
*
|
339 |
jpm |
288 |
* Revision 1.3 2005/02/22 19:27:21 jpm
|
|
|
289 |
* Changement de nom de variables.
|
|
|
290 |
* Suppression de l'attribut nam de la balise form via une méthode de HTML_Common.
|
|
|
291 |
*
|
272 |
jpm |
292 |
* Revision 1.2 2005/02/22 17:44:03 jpm
|
|
|
293 |
* Suppression de référence posant problème.
|
|
|
294 |
*
|
268 |
jpm |
295 |
* Revision 1.1 2004/12/07 10:24:01 jpm
|
|
|
296 |
* Moteur de recherche version de départ.
|
217 |
jpm |
297 |
*
|
268 |
jpm |
298 |
*
|
217 |
jpm |
299 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
300 |
*/
|
|
|
301 |
?>
|