[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Ce fichier ne sera execute qu'une fois 20 if (defined("_ECRIRE_INC_INDEX")) 21 return; 22 23 define("_ECRIRE_INC_INDEX", "1"); 24 25 require_once(dirname(__FILE__). "/include/indexer/inc_indexer_factory.php"); 26 27 function indexer_objet ($type, $id_objet, $forcer_reset = true, $full = true) { 28 //echo 'type = ' . $type .'<br />'; 29 //echo 'id_objet = ' . $id_objet .'<br />'; 30 31 $indexer = &recuperer_instance_indexer($type); 32 33 if (PEAR::isError($indexer)) { 34 die($indexer->getMessage()); 35 } 36 37 $indexer->setFull($full); 38 39 $indexer->index($id_objet, $forcer_reset); 40 } 41 42 // API pour l'espace prive 43 function marquer_indexer ($objet, $id_objet) { 44 global $dir_ecrire; 45 $fichier_index = $dir_ecrire . 'data/.index'; 46 47 if (!$f = @fopen($fichier_index, 'a')) { 48 spip_log("impossible d'ecrire dans $fichier_index !"); 49 @unlink($fichier_index); // on essaie de forcer 50 $f = @fopen($fichier_index, 'a'); 51 } 52 53 spip_log("demande indexation $objet $id_objet"); 54 fputs($f, "$objet $id_objet 1\n"); // 1 = forcer reindexation 55 fclose($f); 56 } 57 58 function indexer_article ($id_article) { 59 marquer_indexer('article', $id_article); 60 } 61 62 function indexer_auteur ($id_auteur) { 63 marquer_indexer('auteur', $id_auteur); 64 } 65 66 function indexer_breve ($id_breve) { 67 marquer_indexer('breve', $id_breve); 68 } 69 70 function indexer_mot ($id_mot) { 71 marquer_indexer('mot', $id_mot); 72 } 73 74 function indexer_rubrique ($id_rubrique) { 75 marquer_indexer('rubrique', $id_rubrique); 76 } 77 78 function indexer_syndic ($id_syndic) { 79 marquer_indexer('syndic', $id_syndic); 80 } 81 82 function effectuer_une_indexation () { 83 $fichier_index = dirname(__FILE__). '/data/.index'; 84 $suite = @file($fichier_index); 85 $s = @sizeof($suite); 86 87 if ($suite && $s) { 88 include_once(dirname(__FILE__). "/inc_texte.php"); 89 include_once(dirname(__FILE__). "/inc_filtres.php"); 90 91 $n = rand(0, $s - 1); 92 $s = $suite[$n]; 93 unset($suite[$n]); 94 95 $f = fopen($fichier_index, 'wb'); 96 fwrite($f, join("", $suite)); 97 fclose($f); 98 99 $s = explode(' ', trim($s)); 100 indexer_objet($s[0], $s[1], $s[2]); 101 } 102 else { 103 @unlink($fichier_index); 104 } 105 } 106 107 function executer_une_indexation_syndic () { 108 $visiter_sites = lire_meta("visiter_sites"); 109 110 if ($visiter_sites == "oui") { 111 //----------Modification Clever Age elebescond------------- 112 $syndicMetier = &recuperer_instance_syndic(); 113 $allSyndicIds = $syndicMetier->getSyndicIdsForStatutAndDateIndex('publie'); 114 115 if (PEAR::isError($allSyndicIds)) { 116 //die($allSyndicIds->getMessage()); 117 } 118 while (list(, $id_syndic) = each($allSyndicIds)) { 119 $loadOK = $syndicMetier->load($id_syndic); 120 121 if (PEAR::isError($loadOK)) { 122 die($loadOK->getMessage()); 123 } 124 else { 125 $maDate = new Date(); 126 $syndicMetier->setDateIndex($maDate->getDate()); 127 $updateOK = $syndicMetier->update(); 128 if (PEAR::isError($updateOK)) { 129 //die($updateOK->getMessage()); 130 } 131 } 132 indexer_syndic($id_syndic); 133 } 134 } 135 } 136 137 function creer_liste_indexation () { 138 require_once(dirname(__FILE__). "/include/bd/inc_article_factory.php"); 139 require_once(dirname(__FILE__). "/include/bd/inc_breve_factory.php"); 140 require_once(dirname(__FILE__). "/include/bd/inc_syndic_factory.php"); 141 require_once(dirname(__FILE__). "/include/bd/inc_auteur_factory.php"); 142 require_once(dirname(__FILE__). "/include/bd/inc_profil_factory.php"); 143 require_once(dirname(__FILE__). "/include/bd/inc_rubrique_factory.php"); 144 $fichier_index = dirname(__FILE__). '/data/.index'; 145 $elements = array('article', 'breve', 'mot', 'auteur', 'rubrique', 'syndic'); 146 147 while (list(, $element) = each($elements)) { 148 $table = $GLOBALS['table_prefix']. "_" . $element . "s"; 149 150 if ($element == 'syndic') 151 $table = $GLOBALS['table_prefix']. '_syndic'; 152 switch ($element) { 153 case 'rubrique': 154 $rubriqueMetier = &recuperer_instance_rubrique(); 155 //$allRubriqueIds = $rubriqueMetier->getRubriqueidsForStatut('publie'); 156 $allRubriqueIds = $rubriqueMetier->getAllRubriqueId(); 157 if (PEAR::isError($allRubriqueIds)) { 158 die($allRubriqueIds->getMessage()); 159 } 160 while (list(, $rubriqueId) = each($allRubriqueIds)) { 161 $liste .= "$element " . $rubriqueId . "\n"; 162 } 163 break; 164 165 case 'article': 166 $articleMetier = &recuperer_instance_article(); 167 $allArticleIds = $articleMetier->getAllArticleIds(); 168 // $allArticleIds = $articleMetier->getAllArticleForStatutsOrderBy('publie, archive'); 169 if (PEAR::isError($allArticleIds)) { 170 die($allArticleIds->getMessage()); 171 } 172 while (list(, $articleId) = each($allArticleIds)) { 173 $liste .= "$element " . $articleId . "\n"; 174 } 175 break; 176 177 case 'breve': 178 $breveMetier = &recuperer_instance_breve(); 179 $allBreveIds = $breveMetier->getAllBreveId(); 180 if (PEAR::isError($allBreveIds)) { 181 die($allBreveIds->getMessage()); 182 } 183 while (list(, $breveId) = each($allBreveIds)) { 184 $liste .= "$element " . $breveId . "\n"; 185 } 186 break; 187 188 case 'syndic': 189 //$statut = "WHERE statut='publie'"; 190 $syndicMetier = &recuperer_instance_syndic(); 191 $allSyndicIds = $syndicMetier->getAllSyndicIdsForStatut('publie'); 192 if (PEAR::isError($allSyndicIds)) { 193 die($allSyndicIds->getMessage()); 194 } 195 while (list(, $syndicId) = each($allSyndicIds)) { 196 $liste .= "$element " . $syndicId . "\n"; 197 } 198 break; 199 200 case 'auteur': 201 //----------modification Clever Age elebescond--------- 202 $profilMetier = &recuperer_instance_profil(); 203 $allProfils = $profilMetier->getAllProfils(); 204 if (PEAR::isError($allProfils)) { 205 die($allprofils->getMessage); 206 } 207 while (list(, $monProfil) = each($allProfils)) { 208 $poids[] = $monProfil->getPoids(); 209 } 210 211 //$statut = "WHERE profil IN (" . join(",", $poids) . ")"; 212 /* 213 $statut = "WHERE statut IN ('minirezo', 'comite')"; 214 */ 215 //----------Fin modification Clever Age--------- 216 $auteurMetier = &recuperer_instance_auteur(); 217 $allAuteurIds = $auteurMetier->getAllAuteurIdForProfils($poids); 218 if (PEAR::isError($allAuteurIds)) { 219 die($allAuteurIds->getMessage()); 220 } 221 while (list(, $auteurId) = each($allAuteurIds)) { 222 $liste .= "$element " . $auteurId . "\n"; 223 } 224 break; 225 226 default: 227 $statut = ''; 228 } 229 } 230 231 if ($f = @fopen("$fichier_index", "w")) { 232 @fputs($f, $liste); 233 @fclose($f); 234 } 235 } 236 237 function purger_index () { 238 require_once dirname(__FILE__). "/include/bd/inc_index_articles_factory.php"; 239 require_once dirname(__FILE__). "/include/bd/inc_index_auteurs_factory.php"; 240 require_once dirname(__FILE__). "/include/bd/inc_index_breves_factory.php"; 241 require_once dirname(__FILE__). "/include/bd/inc_index_dico_factory.php"; 242 require_once dirname(__FILE__). "/include/bd/inc_index_mots_factory.php"; 243 require_once dirname(__FILE__). "/include/bd/inc_index_rubriques_factory.php"; 244 require_once dirname(__FILE__). "/include/bd/inc_index_syndic_factory.php"; 245 246 //----------Modification Clever Age jguillot---------- 247 $indexArticleMetier = &recuperer_instance_index_articles(); 248 $indexArticleMetier->delete(); 249 $indexAuteurMetier = &recuperer_instance_index_auteurs(); 250 $indexAuteurMetier->delete(); 251 $indexBreveMetier = &recuperer_instance_index_breves(); 252 $indexBreveMetier->delete(); 253 $indexMotMetier = &recuperer_instance_index_mots(); 254 $indexMotMetier->delete(); 255 $indexRubriqueMetier = &recuperer_instance_index_rubriques(); 256 $indexRubriqueMetier->delete(); 257 $indexSyndicMetier = &recuperer_instance_index_syndic(); 258 $indexSyndicMetier->delete(); 259 $indexDicoMetier = &recuperer_instance_index_dico(); 260 $indexDicoMetier->delete(); 261 } 262 263 // cree la requete pour une recherche en txt integral 264 function requete_txt_integral ($objet, $hash_recherche) { 265 if ($objet == 'syndic') { 266 $table = $GLOBALS['table_prefix']. "_" . $objet; 267 $index_table = $GLOBALS['table_prefix']. "_index_" . $objet; 268 } 269 else { 270 $table = $GLOBALS['table_prefix']. "_" . $objet . "s"; 271 $index_table = $GLOBALS['table_prefix']. "_" . $objet . "s"; 272 } 273 274 $id_objet = "id_" . $objet; 275 return "SELECT objet.*, SUM(idx.points) AS points 276 FROM $table AS objet, $index_table AS idx 277 WHERE objet.$id_objet = idx.$id_objet 278 AND idx.hash IN ($hash_recherche) 279 GROUP BY objet.$id_objet 280 ORDER BY points DESC 281 LIMIT 0,10"; 282 } 283 284 // rechercher un mot dans le dico 285 function requete_dico ($val) { 286 $min_long = 3; 287 288 // cas particulier translitteration vietnamien 289 if (lire_meta('langue_site') == 'vi') { 290 // 1. recuperer des accents passes sous la forme a` 291 $val = strtr($val, "'`?~.^+(-", "123456789"); 292 // 2. translitterer les accents passes en unicode 293 $val = nettoyer_chaine_indexation($val); 294 295 // 3. composer la regexp pour les caracteres accentuables mais non accentues 296 while (ereg("([aeiouyd])([a-z])", $val . ' ', $match)) 297 $val = str_replace($match[0], $match[1]. '[-1-9]?[-1-9]?' . $match[2], $val); 298 return "dico REGEXP '^$val'"; 299 } 300 301 // cas normal 302 if (strlen($val) > $min_long) 303 return "dico LIKE '$val%'"; 304 else 305 return "dico = '" . $val . "___'"; 306 } 307 308 // decode la chaine recherchee et la traduit en hash 309 function requete_hash ($rech) { 310 require_once dirname(__FILE__). "/include/indexer/Indexer_Utils.php"; 311 require_once dirname(__FILE__). "/include/bd/inc_index_dico_factory.php"; 312 // recupere les mots de la recherche 313 $rech = Indexer_Utils::nettoyer_chaine_indexation($rech); 314 $regs = Indexer_Utils::separateurs_indexation(true). " "; 315 $rech = strtr($rech, $regs, ereg_replace('.', ' ', $regs)); 316 $s = Indexer_Utils::spip_split(" +", $rech); 317 unset($dico); 318 unset($h); 319 320 // cherche les mots dans le dico 321 while (list(, $val) = each($s)) 322 if ($rq = requete_dico($val)) 323 $dico[] = $rq; 324 325 // compose la recherche dans l'index 326 if ($dico) { 327 328 //----------Modification Clever Age jguillot---------- 329 330 $indexDicoMetier = &recuperer_instance_index_dico(); 331 $h = $indexDicoMetier->composeResearchInIndex($dico); 332 } 333 334 if ($h) 335 $hash_recherche = join(",", $h); 336 else 337 $hash_recherche = "'0'"; 338 339 return $hash_recherche; 340 } 341 342 // ajoute des lignes au fichier contenant les donnees a indexer en fonction du contexte 343 function alimenter_fichier_index ($connect = true) { 344 $elementList = array('id_article', 'id_auteur', 'id_breve', 'id_mot', 'id_rubrique'); 345 $fichier_index = dirname(__FILE__). '/data/.index'; 346 $tab = array(); 347 348 while (list(, $val) = each($elementList)) { 349 global $$val; 350 $type = str_replace('id_', '', $val); 351 352 if ($$val == "-1") { // protection pour les valeurs fixees a -1 353 $$val = false; 354 } 355 if ($$val > 0) { 356 if ($connect) { 357 $indexer = &recuperer_instance_indexer($type); 358 if ($$val AND !$indexer->alreadyIndex($$val)) 359 //if ($$val AND !deja_indexe($type, $$val)) 360 $tab[] = $type . ' ' . $$val . "\n"; 361 } 362 else { 363 if (((@filesize($fichier_index) < 2048) 364 and ((time() - @filemtime($fichier_index)) < 60)) 365 or (!file_exists($fichier_index))) { // bof bof 366 $tab[] = $type . ' ' . $$val . "\n"; 367 } 368 } 369 } 370 } 371 372 $tab = array_unique($tab); 373 374 if (count($tab) > 0) { 375 if ($f = @fopen($fichier_index, 'a')) { 376 foreach ($tab as $s) { 377 fwrite($f, $s); 378 } 379 fclose($f); 380 } 381 } 382 } 383 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |