Subversion Repositories Applications.papyrus

Rev

Rev 1898 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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