Subversion Repositories Applications.papyrus

Rev

Rev 1898 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1898 alexandre_ 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
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id: more_recherche_projet.class.php,v 1.1 2008-08-26 15:31:31 alexandre_tb Exp $
25
/**
26
* Classe permettant d'effectuer des recherches sur les informations des articles de Spip.
27
*
28
* Permet de rechercher et classer les articles en fonction d'une chaine.
29
* Utilisation des bibliothèques inclue par Papyrus :
30
* - Papyrus pap_meta.fonct.php
31
* - Papyrus pap_menu.fonct.php
32
* - Papyrus pap_url.class.php
33
*
34
*@package Applette
35
*@subpackage Moteur_Recherche
36
//Auteur original :
37
*@author        Alexandre Granier <alexandre@tela-botanica.org>
38
//Autres auteurs :
39
*@author        aucun
40
*@copyright     Tela-Botanica 2000-2006
41
*@version       $Revision: 1.1 $ $Date: 2008-08-26 15:31:31 $
42
// +------------------------------------------------------------------------------------------------------+
43
*/
44
 
45
// +------------------------------------------------------------------------------------------------------+
46
// |                                            ENTETE du PROGRAMME                                       |
47
// +------------------------------------------------------------------------------------------------------+
48
 
49
// +------------------------------------------------------------------------------------------------------+
50
// |                                            CORPS du PROGRAMME                                        |
51
// +------------------------------------------------------------------------------------------------------+
52
 
53
class More_Recherche_Projet extends More_Recherche {
54
 
55
    // Constructeur
56
    function Recherche_Menu_Meta($motif) {
57
        $this->setMotif($motif);
58
    }
59
 
60
    // Accesseurs
61
    function getMotif() {
62
        return $this->motif;
63
    }
64
    function setMotif($motif) {
65
        $this->motif = $motif;
66
    }
67
 
68
    // Méthodes
69
    function rechercherMotif($motif) {
70
 
71
        $db = $GLOBALS['_MOTEUR_RECHERCHE_']['bd']['papyrus'];
72
 
73
        $url_base = $GLOBALS['_MOTEUR_RECHERCHE_']['projet']['url'];
74
        $tab_articles = $this->retournerProjets($db);
75
 
76
        foreach ($tab_articles as $article_id => $Article) {
77
            // Initialisation du tableau de résultat vide
78
            $aso_resultat = array(  'poids' => 0, 'url' => '', 'titre' => '',
79
                                    'hreflang' => '', 'accesskey' => '', 'title' => '',
80
                                    'date_creation' => '', 'description' => '');
81
 
82
            // Analyse du poids de cette page vis à vis des données
83
            $tab_champs_a_visiter = array('p_id', 'p_titre', 'p_resume', 'p_description', 'pd_nom', 'pd_description');
84
            foreach ($tab_champs_a_visiter as $val) {
85
                // Vérification que le champ existe et contient quelque chose
86
                if (isset($Article->$val) && $Article->$val != '') {
87
					$aso_resultat['poids'] += $this->retournerOccurenceMotif($motif, $Article->$val);
88
                }
89
            }
90
 
91
            if ($aso_resultat['poids'] > 0) {
92
                // Création de l'url
93
	            $aso_resultat['url_simple'] = $url_base.'?id_projet='.$article_id;
94
	            $aso_resultat['url'] = $aso_resultat['url_simple'];
95
 
96
	            // Récupération du titre de la page
2109 drzraf 97
	            if (trim($Article->p_titre)) {
98
	                $aso_resultat['titre'] = htmlentities($Article->p_titre, ENT_COMPAT|ENT_HTML401, 'ISO8859-15');
1898 alexandre_ 99
	            }
2109 drzraf 100
	            $aso_resultat['id'] = htmlentities($Article->p_id, ENT_COMPAT|ENT_HTML401, 'ISO8859-15');
1898 alexandre_ 101
 
102
	            $aso_resultat['description'] = $this->couper($Article->p_description, MORE_RESULTAT_TAILLE_DESCRIPTION);
103
 
104
	            if (($jour = date('d', strtotime($Article->p_date_creation)) ) != 0 ) {
105
	                $aso_resultat['date_creation'] .= '<span class="page_modification_jour"> '.$jour.'</span>'."\n";
106
	            }
107
	            if (($mois = $this->traduireMois(date('m', strtotime($Article->p_date_creation))) ) != '' ) {
108
	                $aso_resultat['date_creation'] .= '<span class="page_modification_mois"> '.$mois.'</span>'."\n";
109
	            }
110
	            if (($annee = date('Y', strtotime($Article->p_date_creation)) ) != 0 ) {
111
	                $aso_resultat['date_creation'] .= '<span class="page_modification_annee"> '.$annee.'</span>'."\n";
112
	            }
113
                $this->setResultat($aso_resultat);
114
            }
115
        }
116
 
117
        return $this->getResultats();
118
    }
119
 
120
    /** Renvoie un tableau contenant les infos sur les articles
121
	*
122
	* @param  mixed		une instance de la classse Pear DB.
123
	* @param  string	le préfixe pour les tables spip.
124
	* @return array		tableau contenant les articles.
125
	*/
126
	function retournerProjets(&$db)
127
	{
128
	    //----------------------------------------------------------------------------
129
	    // Recherche des informations sur le menu
130
	    $requete =  'SELECT * '.
131
	                'FROM projet ';
132
 
133
	    $resultat = $db->query($requete);
134
	    (DB::isError($resultat)) ? die (BOG_afficherErreurSql(__FILE__, __LINE__, $resultat->getMessage(), $requete)) : '';
135
 
136
	    //----------------------------------------------------------------------------
137
	    // Récupération des infos
138
	    $tab_retour = array();
139
	    while ($info_article = $resultat->fetchRow(DB_FETCHMODE_OBJECT)) {
140
	        $tab_retour[$info_article->p_id] = $info_article;
141
	    }
142
	    $resultat->free();
143
 
144
	    return $tab_retour;
145
	}
146
 
147
	// Fichier : inc_texte.php3
148
	function couper($texte, $taille = 50)
149
	{
150
		$texte = substr($texte, 0, 400 + 2*$taille); /* eviter de travailler sur 10ko pour extraire 150 caracteres */
151
 
152
		// on utilise les \r pour passer entre les gouttes
153
		$texte = str_replace("\r\n", "\n", $texte);
154
		$texte = str_replace("\r", "\n", $texte);
155
 
156
		// sauts de ligne et paragraphes
157
		$texte = ereg_replace("\n\n+", "\r", $texte);
158
		$texte = ereg_replace("<(p|br)( [^>]*)?".">", "\r", $texte);
159
 
160
		// supprimer les traits, lignes etc
161
		$texte = ereg_replace("(^|\r|\n)(-[-#\*]*|_ )", "\r", $texte);
162
 
163
		// supprimer les tags
164
		$texte = $this->supprimer_tags($texte);
165
		$texte = trim(str_replace("\n"," ", $texte));
166
		$texte .= "\n";	// marquer la fin
167
 
168
		// travailler en accents charset
169
		// On supprime dans Papyrus car cela tire trop de fonctions...
170
		//$texte = $this->filtrer_entites($texte);
171
 
172
		// supprimer les liens
173
		$texte = ereg_replace("\[->([^]]*)\]","\\1", $texte); // liens sans texte
174
		$texte = ereg_replace("\[([^\[]*)->([^]]*)\]","\\1", $texte);
175
 
176
		// supprimer les notes
177
		$texte = ereg_replace("\[\[([^]]|\][^]])*\]\]", "", $texte);
178
 
179
		// supprimer les codes typos
180
		$texte = ereg_replace("[}{]", "", $texte);
181
 
182
		// supprimer les tableaux
183
		$texte = ereg_replace("(^|\r)\|.*\|\r", "\r", $texte);
184
 
185
		// couper au mot precedent
186
		$long = $this->spip_substr($texte, 0, max($taille-4,1));
187
		$court = ereg_replace("([^[:space:]][[:space:]]+)[^[:space:]]*\n?$", "\\1", $long);
188
		$points = MORE_LG_RESULTAT_ETC;
189
 
190
		// trop court ? ne pas faire de (...)
191
		if (strlen($court) < max(0.75 * $taille,2)) {
192
			$points = '';
193
			$long = $this->spip_substr($texte, 0, $taille);
194
			$texte = ereg_replace("([^[:space:]][[:space:]]+)[^[:space:]]*$", "\\1", $long);
195
			// encore trop court ? couper au caractere
196
			if (strlen($texte) < 0.75 * $taille)
197
				$texte = $long;
198
		} else
199
			$texte = $court;
200
 
201
		if (strpos($texte, "\n"))	// la fin est encore la : c'est qu'on n'a pas de texte de suite
202
			$points = '';
203
 
204
		// remettre les paragraphes
205
		$texte = ereg_replace("\r+", "\n\n", $texte);
206
 
207
		// supprimer l'eventuelle entite finale mal coupee
208
		$texte = preg_replace('/&#?[a-z0-9]*$/', '', $texte);
209
 
210
		return trim($texte).$points;
211
	}
212
 
213
	// Gerer les outils mb_string
214
	// Fichier : inc_texte.php3
215
	function spip_substr($c, $start=0, $end='')
216
	{
217
		// methode substr normale
218
		if ($end) {
219
			return substr($c, $start, $end);
220
		} else {
221
			return substr($c, $start);
222
		}
223
	}
224
 
225
	// Suppression basique et brutale de tous les <...>
226
	// Fichier : inc_filtres.php3
227
	function supprimer_tags($texte, $rempl = "")
228
	{
229
		$texte = preg_replace(",<[^>]*>,U", $rempl, $texte);
230
		// ne pas oublier un < final non ferme
231
		$texte = str_replace('<', ' ', $texte);
232
		return $texte;
233
	}
234
 
235
}
236
 
237
/* +--Fin du code ----------------------------------------------------------------------------------------+
238
*
239
* $Log: not supported by cvs2svn $
240
*
241
* +-- Fin du code ----------------------------------------------------------------------------------------+
242
*/
243
?>