Subversion Repositories Applications.papyrus

Rev

Rev 268 | Rev 339 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
// +------------------------------------------------------------------------------------------------------+
272 jpm 24
// CVS : $Id: moteur_recherche.php,v 1.3 2005-02-22 19:27:21 jpm 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.
30
*
31
*@package Applette
32
*@subpackage Moteur_recherche
33
//Auteur original :
34
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
35
//Autres auteurs :
36
*@author        Aucun
37
*@copyright     Tela-Botanica 2000-2004
272 jpm 38
*@version       $Revision: 1.3 $ $Date: 2005-02-22 19:27:21 $
217 jpm 39
// +------------------------------------------------------------------------------------------------------+
40
*/
41
 
42
// +------------------------------------------------------------------------------------------------------+
43
// |                                            ENTETE du PROGRAMME                                       |
44
// +------------------------------------------------------------------------------------------------------+
45
$_GEN_commun['info_applette_nom_fonction'] = 'afficherMoteurRecherche';
46
$_GEN_commun['info_applette_balise'] = 'MOTEUR_RECHERCHE';
47
 
48
// --------------------------------------------------------------------------------------------------------
49
/** Inclusion du fichier de configuration de cette application.*/
50
require_once GEN_CHEMIN_APPLETTE.'moteur_recherche/configuration/more_configuration.inc.php';
51
/** Inclusion de la bibliotheque permettant d'accéder aux fonctions sur les balises Meta.*/
52
//require_once GEN_CHEMIN_BIBLIO.'pap_meta.fonct.php';
53
//Utilisation de la bibliothèque PEAR NET_URL
54
/** Inclusion de la bibliothèque PEAR de conception de formulaire.*/
55
require_once MORE_CHEMIN_BIBLIOTHEQUE_PEAR.'HTML/QuickForm.php';
272 jpm 56
/** Inclusion de la bibliothèque PEAR de modification des squelettes des formulaires QuickForm.*/
57
require_once 'HTML/QuickForm/Renderer/Default.php';
217 jpm 58
 
59
// Inclusion des fichiers de traduction de l'appli ADME dePapyrus
60
if (file_exists(MORE_CHEMIN_LANGUE.'more_langue_'.$_GEN_commun['i18n'].'.inc.php')) {
61
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
62
    require_once MORE_CHEMIN_LANGUE.'more_langue_'.$_GEN_commun['i18n'].'.inc.php';
63
} else {
64
    /** Inclusion du fichier de traduction par défaut.*/
65
    require_once MORE_CHEMIN_LANGUE.'more_langue_'.MORE_I18N_DEFAUT.'.inc.php';
66
}
67
 
68
// +------------------------------------------------------------------------------------------------------+
69
// |                                            CORPS du PROGRAMME                                        |
70
// +------------------------------------------------------------------------------------------------------+
71
 
72
if (isset($_POST['more_motif']) && $_POST['more_motif'] != '') {
73
    // Initialisation de variable extérieures
74
    $GLOBALS['_VEI_']['usurpation'] = 'Recherche de '.$_POST['more_motif'];
75
    $GLOBALS['_GEN_commun']['info_menu'] = null;
76
    $GLOBALS['_PAPYRUS_']['general']['application_chemin'] = null;
77
    // Titre de la page
78
    $GLOBALS['_PAPYRUS_']['rendu']['TITRE_PAGE'] = 'Résultat de la recherche de '.$_POST['more_motif'];
79
    // Modification des meta de l'entête de la page
80
    GEN_modifierMetaHttpEquiv('Content-Type', 'text/html; charset=iso-8859-15');
81
    GEN_modifierMetaHttpEquiv('Content-style-type', 'text/css');
82
    GEN_modifierMetaHttpEquiv('Content-script-type', 'text/javascript');
83
    GEN_modifierMetaHttpEquiv('Content-language', $_GEN_commun['i18n']);
84
 
85
    GEN_modifierMetaName('revisit-after', '15 days');
86
    GEN_modifierMetaName('robots', 'index,follow');
87
    GEN_modifierMetaName('author', 'Tela Botanica');
88
    GEN_modifierMetaName('keywords', 'Recherche, résultat.');
89
    GEN_modifierMetaName('description', 'Page de résultats du moteur de recherche de Papyrus.');
90
 
91
    GEN_viderMeta('dc');
92
}
93
 
94
// +------------------------------------------------------------------------------------------------------+
95
// |                                           LISTE de FONCTIONS                                         |
96
// +------------------------------------------------------------------------------------------------------+
97
 
98
/** Fonnction afficherMoteurRecherche() - Fournit un formulaire de recherche.
99
*
100
* Renvoie un formulaire permettant de rechercher une chaine de caractères dans les sites
101
* gérés par Papyrus.
102
* Necessite l'utilisation de Pear Net_URL par le programme appelant cette fonction.
103
*
104
* @param  array  tableau d'éventuel arguments présent dans la balise transmis à la fonction.
105
* @param  array  tableau global de Papyrus.
106
* @return string  formulaire XHTML de recherche.
107
*/
108
function afficherMoteurRecherche($tab_applette_arguments, $_GEN_commun)
109
{
110
    // --------------------------------------------------------------------------------------------------------
111
    // Initialisation de variable de configuration.
112
    $liste_type_site = '102, 103';// Les id des types des sites pouvant apparaître dans le sélecteur
113
    $objet_pear_db = $_GEN_commun['pear_db'];//objet Pear créé par DB contenant la connexion à la base de données.
114
    $code_site = $_GEN_commun['url_site'];//identifiant du site courant.
115
    $id_langue = $_GEN_commun['url_i18n'];//identifiant de la langue principale du site courant.
116
    $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'] = $_GEN_commun['pear_db'];// Connexion à la BD de Papyrus
117
    $url = $_GEN_commun['url'];
118
    $url_base = PAP_URL;
119
    $url_cle_site = GEN_URL_CLE_SITE;
120
    $url_cle_i18n = GEN_URL_CLE_I18N;
121
    $url_id_type_site = GEN_URL_ID_TYPE_SITE;
122
    $indent_origine = 12;// Indentation de départ en nombre d'espace
123
    $indent_pas     = 4;// Pas d'indentation en nombre d'espace
124
    $retour = '';
125
    $retour_resultats = '';
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';
137
        /** Inclusion de la classe Recherche_Menu_Meta.*/
138
        require_once MORE_CHEMIN_BIBLIO.'more_recherche_papyrus_menu.class.php';
139
        $moteur = new Recherche($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
140
        $recherche_papyrus_menu = new Recherche_Papyrus_Menu($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
141
        $moteur->ajouterRecherche($recherche_papyrus_menu);
142
        $aso_resultats = $moteur->rechercherMotif();
143
        //$GLOBALS['_DEBOGAGE_'] = '<pre>'.print_r($aso_resultats, true).'</pre>';
144
        $retour_resultats .= '<h1>'.MORE_LG_RESULTAT_TITRE.'</h1>'."\n";
145
        $retour_resultats .= '<ul>'."\n";
146
        foreach ($aso_resultats as $val) {
147
            if (!empty($val['url'])) {
148
                $retour_resultats .= '<li>'."\n";
149
                $retour_resultats .= '<a href="'.$val['url'].'">'.$val['titre'].'</a> '.MORE_LG_RESULTAT_SEPARATEUR.' ';
150
                $retour_resultats .= MORE_LG_RESULTAT_POIDS.$val['poids']."\n";
151
                $retour_resultats .= '</li>'."\n";
152
            }
153
        }
154
        $retour_resultats .= '</ul>'."\n";
155
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_NAVIGATION'] = '';
156
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_TETE'] = '';
157
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_CORPS'] = $retour_resultats;
158
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_PIED'] = '';
159
        $GLOBALS['_GEN_commun']['info_menu'] = '';
160
    }
161
 
162
    // --------------------------------------------------------------------------------------------------------
163
    // Création du formulaire de l'applette
164
 
165
    // Notes : Quickform semble remplacer les & des &amp; à nouveau par des &amp; solution utiliser str_replace()...
272 jpm 166
    $more_form = new HTML_QuickForm('form_more_recherche', 'post', str_replace('&amp;', '&', $url->getUrl()));
217 jpm 167
    $tab_index = MORE_FORM_MOTIF_TAB;
272 jpm 168
    $more_squelette =& $more_form->defaultRenderer();
169
    $more_squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>');
170
    $more_squelette->setElementTemplate( '{label}'."\n".
217 jpm 171
                                    '{element}'."\n".
172
                                    '<!-- BEGIN required --><span class="symbole_obligatoire">'.MORE_LG_FORM_SYMBOLE_OBLIGATOIRE.'</span><!-- END required -->'."\n".
173
                                    '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n");
272 jpm 174
    $more_form->accept($more_squelette);
175
    $more_form->removeAttribute('name');
217 jpm 176
 
177
    $partie_menu_debut = '<fieldset>'."\n".'<legend>'.MORE_LG_FORM_TITRE.'</legend>'."\n";
272 jpm 178
    $more_form->addElement('html', $partie_menu_debut);
217 jpm 179
 
180
    $id = 'more_motif';
181
    $aso_attributs = array( 'id'=>$id, 'tabindex' => $tab_index++, 'size' => MORE_FORM_MOTIF_SIZE, 'maxlength' => MORE_FORM_MOTIF_MAXLENGTH,
182
                            'onclick' => "javascript: this.value='';");
183
    $label = '<label for="'.$id.'">'.MORE_LG_FORM_MOTIF.'</label>';
272 jpm 184
    $more_form->addElement('text', $id, $label, $aso_attributs);
217 jpm 185
 
186
    $id = 'more_ok';
187
    $aso_attributs = array('id'=> $id, 'tabindex' => $tab_index++);
272 jpm 188
    $more_form->addElement('submit', $id, MORE_LG_FORM_VALIDER, $aso_attributs);
217 jpm 189
 
190
    $partie_entete_fin = "\n".'</fieldset>';
272 jpm 191
    $more_form->addElement('html', $partie_entete_fin);
217 jpm 192
 
193
    // Instanciation avec les valeur par défaut
272 jpm 194
    $more_form->setDefaults($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']);
217 jpm 195
 
196
    // Transformation en XHTML du formulaire
272 jpm 197
    $retour .= $more_form->toHTML()."\n";
217 jpm 198
    // --------------------------------------------------------------------------------------------------------
199
 
200
    return $retour;
201
}
202
 
203
// +------------------------------------------------------------------------------------------------------+
204
// |                                            PIED du PROGRAMME                                         |
205
// +------------------------------------------------------------------------------------------------------+
206
 
207
 
208
/* +--Fin du code ----------------------------------------------------------------------------------------+
209
*
210
* $Log: not supported by cvs2svn $
272 jpm 211
* Revision 1.2  2005/02/22 17:44:03  jpm
212
* Suppression de référence posant problème.
213
*
268 jpm 214
* Revision 1.1  2004/12/07 10:24:01  jpm
215
* Moteur de recherche version de départ.
217 jpm 216
*
268 jpm 217
*
217 jpm 218
* +-- Fin du code ----------------------------------------------------------------------------------------+
219
*/
220
?>