Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1935
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of Papyrus.                                                                        |
8
// | This file is part of Papyrus.                                                                        |
9
// |                                                                                                      |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
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                                 |
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                                    |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
23
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id: more_recherche.class.php,v 1.12 2007-10-29 18:29:30 jp_milcent Exp $
24
// CVS : $Id: more_recherche.class.php,v 1.12.2.1 2008-10-22 07:45:46 aperonnet Exp $
25
/**
25
/**
26
* Classe permettant d'effectuer des recherches sur les métas informations des menus.
26
* Classe permettant d'effectuer des recherches sur les métas informations des menus.
27
*
27
*
28
* Permet de rechercher et classer les menus en fonction d'une chaine.
28
* Permet de rechercher et classer les menus en fonction d'une chaine.
29
*
29
*
30
*@package Applette
30
*@package Applette
31
*@subpackage Moteur_Recherche
31
*@subpackage Moteur_Recherche
32
//Auteur original :
32
//Auteur original :
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
34
//Autres auteurs :
34
//Autres auteurs :
35
*@author        aucun
35
*@author        aucun
36
*@copyright     Tela-Botanica 2000-2004
36
*@copyright     Tela-Botanica 2000-2004
37
*@version       $Revision: 1.12 $ $Date: 2007-10-29 18:29:30 $
37
*@version       $Revision: 1.12.2.1 $ $Date: 2008-10-22 07:45:46 $
38
// +------------------------------------------------------------------------------------------------------+
38
// +------------------------------------------------------------------------------------------------------+
39
*/
39
*/
40
 
40
 
41
// +------------------------------------------------------------------------------------------------------+
41
// +------------------------------------------------------------------------------------------------------+
42
// |                                            ENTETE du PROGRAMME                                       |
42
// |                                            ENTETE du PROGRAMME                                       |
43
// +------------------------------------------------------------------------------------------------------+
43
// +------------------------------------------------------------------------------------------------------+
44
 
44
 
45
 
45
 
46
// +------------------------------------------------------------------------------------------------------+
46
// +------------------------------------------------------------------------------------------------------+
47
// |                                            CORPS du PROGRAMME                                        |
47
// |                                            CORPS du PROGRAMME                                        |
48
// +------------------------------------------------------------------------------------------------------+
48
// +------------------------------------------------------------------------------------------------------+
49
 
49
 
50
class More_Recherche {
50
class More_Recherche {
51
    var $motif = '';
51
    var $motif = '';
52
    var $moteurs_recherches = array();
52
    var $moteurs_recherches = array();
53
    var $resultats = array();
53
    var $resultats = array();
54
    
54
    
55
    // Constructeur
55
    // Constructeur
56
    function More_Recherche($motif) {
56
    function More_Recherche($motif) {
57
        $this->setMotif($motif);
57
        $this->setMotif($motif);
58
    }
58
    }
59
    
59
    
60
    // Accesseurs
60
    // Accesseurs
61
    function getMotif() {
61
    function getMotif() {
62
        return $this->motif;
62
        return $this->motif;
63
    }
63
    }
64
    function setMotif($motif) {
64
    function setMotif($motif) {
65
        $this->motif = $motif;
65
        $this->motif = $motif;
66
    }
66
    }
67
    function getMoteurs() {
67
    function getMoteurs() {
68
        return $this->moteurs_recherches;
68
        return $this->moteurs_recherches;
69
    }
69
    }
70
    function getMoteur($id) {
70
    function getMoteur($id) {
71
        return $this->moteurs_recherches[$id];
71
        return $this->moteurs_recherches[$id];
72
    }
72
    }
73
    function setMoteur($val) {
73
    function setMoteur($val) {
74
        $id_nouveau = count($this->moteurs_recherches);
74
        $id_nouveau = count($this->moteurs_recherches);
75
        $this->moteurs_recherches[$id_nouveau] = $val;
75
        $this->moteurs_recherches[$id_nouveau] = $val;
76
    }
76
    }
77
    function getResultats() {
77
    function getResultats() {
78
        return $this->resultats;
78
        return $this->resultats;
79
    }
79
    }
80
    function setResultats($val) {
80
    function setResultats($val) {
81
        $this->resultats = $val;
81
        $this->resultats = $val;
82
    }
82
    }
83
    function setResultat($aso_page) {
83
    function setResultat($aso_page) {
84
        $id_nouveau = count($this->resultats);
84
        $id_nouveau = count($this->resultats);
85
        $this->resultats[$id_nouveau] = $aso_page;
85
        $this->resultats[$id_nouveau] = $aso_page;
86
    }
86
    }
87
    
87
    
88
    // Méthodes
88
    // Méthodes
89
    
89
    
90
    function ajouterRecherche(&$objet_recherche) {
90
    function ajouterRecherche(&$objet_recherche) {
91
        return $this->setMoteur($objet_recherche);
91
        return $this->setMoteur($objet_recherche);
92
    }
92
    }
93
 
93
 
94
    function rechercherMotif() {
94
    function rechercherMotif() {
95
        foreach ($this->getMoteurs() as $cle => $val) {
95
        foreach ($this->getMoteurs() as $cle => $val) {
96
            $this->setResultats(array_merge((array)$this->getResultats(),(array)$val->rechercherMotif($this->getMotif())));
96
            $this->setResultats(array_merge((array)$this->getResultats(),(array)$val->rechercherMotif($this->getMotif())));
97
        }
97
        }
98
        $aso_resultats = $this->getResultats();
98
        $aso_resultats = $this->getResultats();
-
 
99
        if(!function_exists('comparer'))
-
 
100
        {
99
        function comparer($a, $b) {
101
	        function comparer($a, $b) {
100
            if ($a['poids'] > $b['poids']) {
102
	            if ($a['poids'] > $b['poids']) {
101
                return -1;
103
	                return -1;
102
            }
104
	            }
103
            if ($a['poids'] < $b['poids']) {
105
	            if ($a['poids'] < $b['poids']) {
104
                return +1;
106
	                return +1;
105
            }
107
	            }
106
            if ($a['poids'] = $b['poids']) {
108
	            if ($a['poids'] = $b['poids']) {
107
                return 0;
109
	                return 0;
108
            }
110
	            }
-
 
111
	        }
109
        }
112
        }
110
        usort($aso_resultats, 'comparer');
113
        usort($aso_resultats, 'comparer');
111
        $pds_max = 0;
114
        $pds_max = 0;
112
        if (isset($aso_resultats[0]['poids'])) {
115
        if (isset($aso_resultats[0]['poids'])) {
113
            $pds_max = $aso_resultats[0]['poids'];
116
            $pds_max = $aso_resultats[0]['poids'];
114
        }
117
        }
115
        for ($i = 0 ; $i < count($aso_resultats) ; $i++) {
118
        for ($i = 0 ; $i < count($aso_resultats) ; $i++) {
116
            $aso_resultats[$i]['score'] = round((100 / $pds_max) * $aso_resultats[$i]['poids'], 1);
119
            $aso_resultats[$i]['score'] = round((100 / $pds_max) * $aso_resultats[$i]['poids'], 1);
117
        }
120
        }
118
        
121
        
119
        return $aso_resultats;
122
        return $aso_resultats;
120
    }
123
    }
121
    
124
    
122
    /** Renvoie le nombre d'occurences total de la présence de chaque mot.
125
    /** Renvoie le nombre d'occurences total de la présence de chaque mot.
123
	*
126
	*
124
	* @param  string	le motif à rechercher.
127
	* @param  string	le motif à rechercher.
125
	* @param  string	le texte dans lequel effectuer la recherche. 
128
	* @param  string	le texte dans lequel effectuer la recherche. 
126
	* @return integer	le nombre de fois où les mots sont trouvés.
129
	* @return integer	le nombre de fois où les mots sont trouvés.
127
	*/
130
	*/
128
	function retournerOccurenceMotif($motif, &$texte, $mode = MORE_MODE)
131
	function retournerOccurenceMotif($motif, &$texte, $mode = MORE_MODE)
129
	{
132
	{
130
		$nbre_correspondance = 0;
133
		$nbre_correspondance = 0;
131
		$nbre_correspondance_total = 0;
134
		$nbre_correspondance_total = 0;
132
		$motif = $this->traiterMotif($motif, 'simple');
135
		$motif = $this->traiterMotif($motif, 'simple');
133
		// Si demande de recherche d'expression complète
136
		// Si demande de recherche d'expression complète
134
		if (preg_match('/^".+"$/', $motif)) {
137
		if (preg_match('/^".+"$/', $motif)) {
135
			$mode = 2;
138
			$mode = 2;
136
			
139
			
137
		}
140
		}
138
		$motif = $this->traiterMotif($motif, 'recherche');
141
		$motif = $this->traiterMotif($motif, 'recherche');
139
		switch ($mode) {
142
		switch ($mode) {
140
			case '1' :
143
			case '1' :
141
				// Découpage en mot
144
				// Découpage en mot
142
				$tab_motif = explode(' ', $motif);
145
				$tab_motif = explode(' ', $motif);
143
				break;
146
				break;
144
			case '2' :
147
			case '2' :
145
				// La chaine saisie par l'utilisateur est recherchée tel quel
148
				// La chaine saisie par l'utilisateur est recherchée tel quel
146
				$tab_motif[] = $motif;
149
				$tab_motif[] = $motif;
147
				break;
150
				break;
148
			default:
151
			default:
149
				$e = 'Mode pour le moteur de recherche inconnu : '.$mode.
152
				$e = 'Mode pour le moteur de recherche inconnu : '.$mode.
150
				trigger_error($e, E_USER_ERROR);
153
				trigger_error($e, E_USER_ERROR);
151
		}
154
		}
152
		// Nous recherchons chaque mot
155
		// Nous recherchons chaque mot
153
		$compteur_mot = 0;
156
		$compteur_mot = 0;
154
		foreach ($tab_motif as $mot) {
157
		foreach ($tab_motif as $mot) {
155
			//$nbre_correspondance += preg_match_all('/'.$mot.'/i', $texte, $tab_morceaux);
158
			//$nbre_correspondance += preg_match_all('/'.$mot.'/i', $texte, $tab_morceaux);
156
			$nbre_correspondance = substr_count(strtolower($texte), strtolower($mot));
159
			$nbre_correspondance = substr_count(strtolower($texte), strtolower($mot));
157
			if ($nbre_correspondance > 0) {
160
			if ($nbre_correspondance > 0) {
158
				$compteur_mot++;
161
				$compteur_mot++;
159
			}
162
			}
160
			$nbre_correspondance_total += $nbre_correspondance; 
163
			$nbre_correspondance_total += $nbre_correspondance; 
161
		}
164
		}
162
		// Si tous les mots recherchés sont présents nous renvoyons le poids de la page.
165
		// Si tous les mots recherchés sont présents nous renvoyons le poids de la page.
163
		if ($compteur_mot == count($tab_motif)) {
166
		if ($compteur_mot == count($tab_motif)) {
164
			return $nbre_correspondance_total;
167
			return $nbre_correspondance_total;
165
		} else {
168
		} else {
166
			return 0;
169
			return 0;
167
		}
170
		}
168
	}
171
	}
169
	
172
	
170
	function traiterMotif($motif, $type = 0)
173
	function traiterMotif($motif, $type = 0)
171
    {
174
    {
172
    	switch ($type) {
175
    	switch ($type) {
173
			case 'simple' :
176
			case 'simple' :
174
				return trim(stripslashes($motif));
177
				return trim(stripslashes($motif));
175
				break;
178
				break;
176
			case 'recherche' :
179
			case 'recherche' :
177
				if (preg_match('/^"(.+)"$/', $motif, $match)) {
180
				if (preg_match('/^"(.+)"$/', $motif, $match)) {
178
					$motif = $match[1];
181
					$motif = $match[1];
179
				}
182
				}
180
				return $motif;
183
				return $motif;
181
				break;
184
				break;
182
			case 'url' :
185
			case 'url' :
183
				$motif = trim(stripslashes($motif));
186
				$motif = trim(stripslashes($motif));
184
				if (preg_match('/^"(.+)"$/', $motif, $match)) {
187
				if (preg_match('/^"(.+)"$/', $motif, $match)) {
185
					$motif = $match[1];
188
					$motif = $match[1];
186
				}
189
				}
187
				return urlencode($motif);
190
				return urlencode($motif);
188
				break;
191
				break;
189
			default:
192
			default:
190
				return $motif;
193
				return $motif;
191
		}
194
		}
192
    }
195
    }
193
    
196
    
194
    function traduireMois($mois_numerique)
197
    function traduireMois($mois_numerique)
195
    {
198
    {
196
        switch ($mois_numerique) {
199
        switch ($mois_numerique) {
197
            case '01' :
200
            case '01' :
198
                return 'janvier';              
201
                return 'janvier';              
199
            case '02' :
202
            case '02' :
200
                return 'février';              
203
                return 'février';              
201
            case '03' :
204
            case '03' :
202
                return 'mars';
205
                return 'mars';
203
            case '04' :
206
            case '04' :
204
                return 'avril';
207
                return 'avril';
205
            case '05' :
208
            case '05' :
206
                return 'mai';
209
                return 'mai';
207
            case '06' :
210
            case '06' :
208
                return 'juin';
211
                return 'juin';
209
            case '07' :
212
            case '07' :
210
                return 'juillet';
213
                return 'juillet';
211
            case '08' :
214
            case '08' :
212
                return 'août';
215
                return 'août';
213
            case '09' :
216
            case '09' :
214
                return 'septembre';
217
                return 'septembre';
215
            case '10' :
218
            case '10' :
216
                return 'octobre';
219
                return 'octobre';
217
            case '11' :
220
            case '11' :
218
                return 'novembre';
221
                return 'novembre';
219
            case '12' :
222
            case '12' :
220
                return 'décembre';
223
                return 'décembre';
221
            default:
224
            default:
222
                return '';
225
                return '';
223
        }
226
        }
224
    }
227
    }
225
}
228
}
226
 
229
 
227
/* +--Fin du code ----------------------------------------------------------------------------------------+
230
/* +--Fin du code ----------------------------------------------------------------------------------------+
228
*
231
*
229
* $Log: not supported by cvs2svn $
232
* $Log: not supported by cvs2svn $
-
 
233
* Revision 1.12  2007-10-29 18:29:30  jp_milcent
-
 
234
* Ajout d'un préfixe devant les classes de l'applette pour éviter les conflits avec d'autres classes provenant des applis clientes.
-
 
235
*
230
* Revision 1.11  2007-01-02 18:49:22  jp_milcent
236
* Revision 1.11  2007-01-02 18:49:22  jp_milcent
231
* Amélioration de la gestion du motif.
237
* Amélioration de la gestion du motif.
232
* Ajout de la gestion des expressions complête via l'utilisation de guillemets.
238
* Ajout de la gestion des expressions complête via l'utilisation de guillemets.
233
*
239
*
234
* Revision 1.10  2006/12/12 13:54:41  jp_milcent
240
* Revision 1.10  2006/12/12 13:54:41  jp_milcent
235
* Correction bogue : variable non initialisée.
241
* Correction bogue : variable non initialisée.
236
*
242
*
237
* Revision 1.9  2006/10/17 09:21:40  jp_milcent
243
* Revision 1.9  2006/10/17 09:21:40  jp_milcent
238
* Mise en commun des spécifications de la recherche.
244
* Mise en commun des spécifications de la recherche.
239
*
245
*
240
* Revision 1.8  2006/05/23 14:18:19  jp_milcent
246
* Revision 1.8  2006/05/23 14:18:19  jp_milcent
241
* Ajout de la gestion du mode de recherche au moteur de recherche de Papyrus.
247
* Ajout de la gestion du mode de recherche au moteur de recherche de Papyrus.
242
* Soit on recherche chaque mot du motif, soit le motif entier.
248
* Soit on recherche chaque mot du motif, soit le motif entier.
243
*
249
*
244
* Revision 1.7  2006/05/19 10:04:55  jp_milcent
250
* Revision 1.7  2006/05/19 10:04:55  jp_milcent
245
* Ajout d'un moteur de recherche analysant les articles des sites sous Spip.
251
* Ajout d'un moteur de recherche analysant les articles des sites sous Spip.
246
*
252
*
247
* Revision 1.6  2006/04/28 12:41:49  florian
253
* Revision 1.6  2006/04/28 12:41:49  florian
248
* corrections erreurs chemin
254
* corrections erreurs chemin
249
*
255
*
250
* Revision 1.5  2005/09/20 17:01:22  ddelon
256
* Revision 1.5  2005/09/20 17:01:22  ddelon
251
* php5 et bugs divers
257
* php5 et bugs divers
252
*
258
*
253
* Revision 1.4  2005/05/25 13:49:22  jpm
259
* Revision 1.4  2005/05/25 13:49:22  jpm
254
* Corection erreur pour la recherche dans le contenu.
260
* Corection erreur pour la recherche dans le contenu.
255
*
261
*
256
* Revision 1.3  2005/05/19 12:46:12  jpm
262
* Revision 1.3  2005/05/19 12:46:12  jpm
257
* Correction bogue accesskey.
263
* Correction bogue accesskey.
258
* Ajout d'un id à la liste.
264
* Ajout d'un id à la liste.
259
* Arrondissement des score.
265
* Arrondissement des score.
260
*
266
*
261
* Revision 1.2  2005/04/14 17:39:34  jpm
267
* Revision 1.2  2005/04/14 17:39:34  jpm
262
* Amélioration du moteur de rechercher :
268
* Amélioration du moteur de rechercher :
263
*  - pourcentage
269
*  - pourcentage
264
*  - ajout d'info
270
*  - ajout d'info
265
*
271
*
266
* Revision 1.1  2004/12/07 10:24:06  jpm
272
* Revision 1.1  2004/12/07 10:24:06  jpm
267
* Moteur de recherche version de départ.
273
* Moteur de recherche version de départ.
268
*
274
*
269
* 
275
* 
270
* +-- Fin du code ----------------------------------------------------------------------------------------+
276
* +-- Fin du code ----------------------------------------------------------------------------------------+
271
*/
277
*/
272
?>
278
?>