Subversion Repositories Applications.papyrus

Rev

Rev 754 | Rev 846 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1                                                                                      |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
// +------------------------------------------------------------------------------------------------------+
// | This file is part of Papyrus.                                                                        |
// |                                                                                                      |
// | Foobar is free software; you can redistribute it and/or modify                                       |
// | it under the terms of the GNU General Public License as published by                                 |
// | the Free Software Foundation; either version 2 of the License, or                                    |
// | (at your option) any later version.                                                                  |
// |                                                                                                      |
// | Foobar is distributed in the hope that it will be useful,                                            |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
// | GNU General Public License for more details.                                                         |
// |                                                                                                      |
// | You should have received a copy of the GNU General Public License                                    |
// | along with Foobar; if not, write to the Free Software                                                |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: moteur_recherche.php,v 1.9 2006-04-28 12:41:49 florian Exp $
/**
* Applette : moteur de recherche
*
* Génère un formulaire contenant une zone de saisie permettant de taper un texte à rechercher sur l'ensemble
* des sites gérés par Papyrus.
* Utilisation des bibliothèques inclue par Papyrus :
* - Papyrus pap_meta.fonct.php
* - PEAR NET_URL
*
*@package Applette
*@subpackage Moteur_recherche
//Auteur original :
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
//Autres auteurs :
*@author        Aucun
*@copyright     Tela-Botanica 2000-2004
*@version       $Revision: 1.9 $ $Date: 2006-04-28 12:41:49 $
// +------------------------------------------------------------------------------------------------------+
*/

// +------------------------------------------------------------------------------------------------------+
// |                                            ENTETE du PROGRAMME                                       |
// +------------------------------------------------------------------------------------------------------+
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherMoteurRecherche';
$GLOBALS['_GEN_commun']['info_applette_balise'] = 'MOTEUR_RECHERCHE';

// --------------------------------------------------------------------------------------------------------
//Utilisation de la bibliothèque Papyrus pap_meta.fonct.php inclue par Papyrus
//Utilisation de la bibliothèque PEAR NET_URL inclue par Papyrus
/** Inclusion du fichier de configuration de cette application.*/
require_once GEN_CHEMIN_APPLETTE.'moteur_recherche/configuration/more_configuration.inc.php';
/** Inclusion de la bibliothèque PEAR de conception de formulaire.*/
require_once MORE_CHEMIN_BIBLIOTHEQUE_PEAR.'HTML/QuickForm.php';
/** Inclusion de la bibliothèque PEAR de modification des squelettes des formulaires QuickForm.*/
require_once PAP_CHEMIN_API_PEAR.'HTML/QuickForm/Renderer/Default.php';

// Inclusion des fichiers de traduction de l'appli ADME dePapyrus
if (file_exists(MORE_CHEMIN_LANGUE.'more_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
    require_once MORE_CHEMIN_LANGUE.'more_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
} else {
    /** Inclusion du fichier de traduction par défaut.*/
    require_once MORE_CHEMIN_LANGUE.'more_langue_'.MORE_I18N_DEFAUT.'.inc.php';
}

// +------------------------------------------------------------------------------------------------------+
// |                                            CORPS du PROGRAMME                                        |
// +------------------------------------------------------------------------------------------------------+

if (isset($_POST['more_motif']) && $_POST['more_motif'] != '') {
    // Initialisation de variable extérieures
    $GLOBALS['_VEI_']['usurpation'] = MORE_LG_USURPATION.$_POST['more_motif'];
    $GLOBALS['_GEN_commun']['info_menu'] = null;
    $GLOBALS['_PAPYRUS_']['general']['application_chemin'] = null;
    // Titre de la page
    $GLOBALS['_PAPYRUS_']['rendu']['TITRE_PAGE'] = MORE_LG_TITRE.$_POST['more_motif'];
    // Modification des meta de l'entête de la page
    GEN_modifierMetaHttpEquiv('Content-Type', 'text/html; charset=iso-8859-15');
    GEN_modifierMetaHttpEquiv('Content-style-type', 'text/css');
    GEN_modifierMetaHttpEquiv('Content-script-type', 'text/javascript');
    GEN_modifierMetaHttpEquiv('Content-language', $GLOBALS['_GEN_commun']['i18n']);
    
    GEN_modifierMetaName('revisit-after', '15 days');
    GEN_modifierMetaName('robots', 'index,follow');
    GEN_modifierMetaName('author', 'Tela Botanica');
    GEN_modifierMetaName('keywords', 'Recherche, résultat.');
    GEN_modifierMetaName('description', 'Page de résultats du moteur de recherche de Papyrus.');
    
    GEN_viderMeta('dc');
}

// +------------------------------------------------------------------------------------------------------+
// |                                           LISTE de FONCTIONS                                         |
// +------------------------------------------------------------------------------------------------------+

/** Fonnction afficherMoteurRecherche() - Fournit un formulaire de recherche.
*
* Renvoie un formulaire permettant de rechercher une chaine de caractères dans les sites
* gérés par Papyrus.
* Necessite l'utilisation de Pear Net_URL par le programme appelant cette fonction.
*
* @param  array  tableau d'éventuel arguments présent dans la balise transmis à la fonction. 
* @param  array  tableau global de Papyrus.
* @return string  formulaire XHTML de recherche.
*/
function afficherMoteurRecherche($tab_applette_arguments, $_GEN_commun)
{
    // --------------------------------------------------------------------------------------------------------
    // Initialisation de variable de configuration.
    $liste_type_site = '102, 103';// Les id des types des sites pouvant apparaître dans le sélecteur
    $objet_pear_db =& $_GEN_commun['pear_db'];//objet Pear créé par DB contenant la connexion à la base de données.
    $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'] =& $_GEN_commun['pear_db'];// Connexion à la BD de Papyrus
    $code_site = $_GEN_commun['url_site'];// identifiant du site courant.
    $url = $_GEN_commun['url'];
    $url_base = PAP_URL;
    $url_id_type_site = GEN_URL_ID_TYPE_SITE;
    $indent_origine = 12;// Indentation de départ en nombre d'espace
    $indent_pas     = 4;// Pas d'indentation en nombre d'espace
    $retour = '';
    $retour_resultats = '';
    
    // --------------------------------------------------------------------------------------------------------
    // Lancement de la recherche si nécessaire
    
    $_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = '';
    if (!isset($_POST['more_motif']) || $_POST['more_motif'] == '') {
        $_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = MORE_LG_FORM_MOTIF_VALUE;
    } else {
        $_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif'] = $_POST['more_motif'];
        /** Inclusion de la classe Recherche.*/
        require_once MORE_CHEMIN_BIBLIO.'more_recherche.class.php';
        /** Inclusion de la classe Recherche_Menu_Meta.*/
        require_once MORE_CHEMIN_BIBLIO.'more_recherche_papyrus_menu.class.php';
        $moteur = new Recherche($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
        $recherche_papyrus_menu = new Recherche_Papyrus_Menu($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']['more_motif']);
        $moteur->ajouterRecherche($recherche_papyrus_menu);
        $aso_resultats = $moteur->rechercherMotif();
        //$GLOBALS['_DEBOGAGE_'] = '<pre>'.print_r($aso_resultats, true).'</pre>';
        $retour_resultats .= '<h1>'.MORE_LG_RESULTAT_TITRE.'</h1>'."\n";
        if (count($aso_resultats) == 0) {
            $retour_resultats .= '<p class="information">'.MORE_LG_RESULTAT_VIDE.'</p>'."\n";
        } else {
            $retour_resultats .= '<ul id="more_resultat">'."\n";
            foreach ($aso_resultats as $val) {
                if (!empty($val['url'])) {
                    $retour_resultats .= '<li>'."\n";
                    $retour_resultats .=    '<h2><a href="'.$val['url'].'" ';
                    if ($val['hreflang'] != '') {
                        $retour_resultats .= 'hreflang="'.$val['hreflang'].'" ';
                    }
                    if ($val['accesskey'] != '') {
                        $retour_resultats .= 'accesskey="'.$val['accesskey'].'" ';
                    }
                    if ($val['title'] != '') {
                        $retour_resultats .= 'title="'.$val['title'].'" ';
                    }
                    $retour_resultats .= '>'.$val['titre'].'</a></h2>';
                    $retour_resultats .= '<dl>'."\n";
                    //if (trim($val['poids']) != '') {
                    //    $retour_resultats .= '<dt>'.MORE_LG_RESULTAT_POIDS.'</dt>'."\n";
                    //    $retour_resultats .= '<dd>'.$val['poids'].'</dd>'."\n";
                    //}
                    if (trim($val['score']) != '') {
                        $retour_resultats .= '<dt>'.MORE_LG_RESULTAT_SCORE.'</dt>'."\n";
                        $retour_resultats .= '<dd>'.$val['score'].MORE_LG_RESULTAT_POURCENT.'</dd>'."\n";
                    }
                    if (trim($val['date_creation']) != '') {
                        $retour_resultats .= '<dt>'.MORE_LG_RESULTAT_DATE_CREATION.'</dt>'."\n";
                        $retour_resultats .= '<dd>'.$val['date_creation'].'</dd>'."\n";
                    }
                    if (trim($val['description']) != '') {
                        $retour_resultats .= '<dt>'.MORE_LG_RESULTAT_DESCRIPTION.'</dt>'."\n";
                        $retour_resultats .= '<dd>'.$val['description'].'</dd>'."\n";
                    }
                    $retour_resultats .= '</dl>'."\n";
                    $retour_resultats .= '</li>'."\n";
                }
            }
            $retour_resultats .= '</ul>'."\n";
        }
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_NAVIGATION'] = '';
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_TETE'] = '';
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_CORPS'] = $retour_resultats;
        $GLOBALS['_PAPYRUS_']['rendu']['CONTENU_PIED'] = '';
        $GLOBALS['_GEN_commun']['info_menu'] = '';
    }
    
    // --------------------------------------------------------------------------------------------------------
    // Création du formulaire de l'applette
    
    // Notes : Quickform semble remplacer les & des &amp; à nouveau par des &amp; solution utiliser str_replace()...
    $more_form = new HTML_QuickForm('form_more_recherche', 'post', str_replace('&amp;', '&', $url->getUrl()));
    $tab_index = MORE_FORM_MOTIF_TAB;
    $more_squelette =& $more_form->defaultRenderer();
    $more_squelette->setFormTemplate("\n".'<form{attributes}>'."\n".'{content}'."\n".'</form>');
    $more_squelette->setElementTemplate( '{label}'."\n".
                                    '{element}'."\n".
                                    '<!-- BEGIN required --><span class="symbole_obligatoire">'.MORE_LG_FORM_SYMBOLE_OBLIGATOIRE.'</span><!-- END required -->'."\n".
                                    '<!-- BEGIN error --><span class="erreur">{error}</span><!-- END error -->'."\n");
    $more_form->accept($more_squelette);
    $more_form->removeAttribute('name');
    
    $partie_menu_debut = '<fieldset>'."\n".'<legend>'.MORE_LG_FORM_TITRE.'</legend>'."\n";
    $more_form->addElement('html', $partie_menu_debut);
    
    $id = 'more_motif';
    $aso_attributs = array( 'id'=>$id, 'tabindex' => $tab_index++, 'maxlength' => MORE_FORM_MOTIF_MAXLENGTH,
                            'accesskey' => MORE_LG_FORM_ACCESSKEY, 'onclick' => "javascript: this.value='';");
    $label = '<label for="'.$id.'">'.MORE_LG_FORM_MOTIF.'</label>';
    $more_form->addElement('text', $id, $label, $aso_attributs);
    
    $id = 'more_ok';
    $aso_attributs = array('id'=> $id, 'tabindex' => $tab_index++);
    $more_form->addElement('submit', $id, MORE_LG_FORM_VALIDER, $aso_attributs);
    
    $partie_entete_fin = "\n".'</fieldset>';
    $more_form->addElement('html', $partie_entete_fin);
    
    // Instanciation avec les valeur par défaut
    $more_form->setDefaults($_SESSION['_MOTEUR_RECHERCHE_']['rechercher']);
    
    // Transformation en XHTML du formulaire
    $retour .= $more_form->toHTML()."\n";
    // --------------------------------------------------------------------------------------------------------
    
    return $retour;
}

// +------------------------------------------------------------------------------------------------------+
// |                                            PIED du PROGRAMME                                         |
// +------------------------------------------------------------------------------------------------------+


/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.8  2006/03/02 10:49:49  ddelon
* Fusion branche multilinguisme dans branche principale
*
* Revision 1.7.2.2  2005/12/27 15:56:00  ddelon
* Fusion Head vers multilinguisme (wikini double clic)
*
* Revision 1.7.2.1  2005/12/20 14:40:25  ddelon
* Fusion Head vers Livraison
*
* Revision 1.7  2005/09/27 09:07:32  ddelon
* size applette et squelettes
*
* Revision 1.6  2005/05/25 13:49:22  jpm
* Corection erreur pour la recherche dans le contenu.
*
* Revision 1.5  2005/05/19 12:46:12  jpm
* Correction bogue accesskey.
* Ajout d'un id à la liste.
* Arrondissement des score.
*
* Revision 1.4  2005/04/14 17:39:34  jpm
* Amélioration du moteur de rechercher :
*  - pourcentage
*  - ajout d'info
*
* Revision 1.3  2005/02/22 19:27:21  jpm
* Changement de nom de variables.
* Suppression de l'attribut nam de la balise form via une méthode de HTML_Common.
*
* Revision 1.2  2005/02/22 17:44:03  jpm
* Suppression de référence posant problème.
*
* Revision 1.1  2004/12/07 10:24:01  jpm
* Moteur de recherche version de départ.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>