forked from spip/spip
37 changed files with 236 additions and 1651 deletions
@ -1,45 +0,0 @@
|
||||
<?php |
||||
|
||||
// |
||||
// Lit un document 'doc' et extrait son contenu en texte brut |
||||
// |
||||
|
||||
// NOTE : l'extracteur n'est pas oblige de convertir le contenu dans |
||||
// le charset du site, mais il *doit* signaler le charset dans lequel |
||||
// il envoie le contenu, de facon a ce qu'il soit converti au moment |
||||
// voulu ; dans le cas contraire le document sera lu comme s'il etait |
||||
// dans le charset iso-8859-1 |
||||
|
||||
// http://doc.spip.org/@extracteur_doc |
||||
function extracteur_doc($fichier, &$charset) { |
||||
|
||||
$charset = 'iso-8859-1'; |
||||
|
||||
@exec('metamail -d -q -b -c application/msword '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
|
||||
# wvText |
||||
# http://wvware.sourceforge.net/ |
||||
$temp = tempnam(_DIR_CACHE, 'doc'); |
||||
@exec('wvText '.escapeshellarg($fichier).'> '.$temp, $r, $e); |
||||
lire_fichier($temp, $contenu); |
||||
@unlink($temp); |
||||
if (!$e) return $contenu; |
||||
|
||||
# antiword |
||||
# http://www.winfield.demon.nl/ |
||||
@exec('antiword '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
|
||||
# catdoc |
||||
# http://www.45.free.net/~vitus/ice/catdoc/ |
||||
@exec('catdoc '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
|
||||
} |
||||
|
||||
// Sait-on extraire ce format ? |
||||
// TODO: ici tester si les binaires fonctionnent |
||||
$GLOBALS['extracteur']['doc'] = 'extracteur_doc'; |
||||
|
||||
?> |
@ -1,319 +0,0 @@
|
||||
<?php |
||||
|
||||
// |
||||
// Lit un document 'pdf' et extrait son contenu en texte brut |
||||
// |
||||
|
||||
// NOTE : l'extracteur n'est pas oblige de convertir le contenu dans |
||||
// le charset du site, mais il *doit* signaler le charset dans lequel |
||||
// il envoie le contenu, de facon a ce qu'il soit converti au moment |
||||
// voulu ; dans le cas contraire le document sera lu comme s'il etait |
||||
// dans le charset iso-8859-1 |
||||
|
||||
// http://doc.spip.org/@extracteur_pdf |
||||
function extracteur_pdf($fichier, &$charset) { |
||||
|
||||
/* methode tout PHP |
||||
$pdf = new Format_PDF; |
||||
$texte = $pdf->extraire_texte($fichier); |
||||
echo $texte; |
||||
exit; |
||||
*/ |
||||
|
||||
$charset = 'iso-8859-1'; |
||||
|
||||
# metamail |
||||
@exec('metamail -d -q -b -c application/pdf '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
|
||||
# pdftotext |
||||
# http://www.glyphandcog.com/Xpdf.html |
||||
# l'option "-enc utf-8" peut echouer ... dommage ! |
||||
@exec('pdftotext '.escapeshellarg($fichier).' -', $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
} |
||||
|
||||
// Sait-on extraire ce format ? |
||||
// TODO: ici tester si les binaires fonctionnent |
||||
$GLOBALS['extracteur']['pdf'] = 'extracteur_pdf'; |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// |
||||
// Methode tout PHP (a tester) |
||||
// |
||||
|
||||
// http://doc.spip.org/@Format_PDF |
||||
class Format_PDF { |
||||
var $trans_chars; |
||||
var $flag_mono, $flag_brut; |
||||
|
||||
// http://doc.spip.org/@convertir_caracteres |
||||
function convertir_caracteres($texte) { |
||||
if (!$this->trans_chars) { |
||||
// Caracteres speciaux |
||||
$this->trans_chars = array( |
||||
// ligatures typographiques (!) |
||||
chr(2) => 'fi', |
||||
chr(3) => 'fl', |
||||
chr(174) => 'fi', |
||||
chr(175) => 'fl', |
||||
// "e" accent aigu |
||||
chr(0) => chr(233) |
||||
); |
||||
} |
||||
$texte = strtr($texte, $this->trans_chars); |
||||
// Caracteres non-ascii codes en octal |
||||
while (preg_match(',\\\\([0-7][0-7][0-7]),', $texte, $regs)) { |
||||
$c = chr(octdec($regs[1])); |
||||
$texte = str_replace($regs[0], $c, $texte); |
||||
$this->trans_chars[$regs[0]] = $c; |
||||
} |
||||
return $texte; |
||||
} |
||||
|
||||
// http://doc.spip.org/@recoller_texte |
||||
function recoller_texte($stream) { |
||||
static $chars_voyelles, $chars_fusion, $chars_caps, $chars_nums, $bichars_fusion; |
||||
if (!$chars_voyelles) { |
||||
$chars_voyelles = array('a'=>1, 'e'=>1, 'i'=>1, 'o'=>1, 'u'=>1, 'y'=>1); |
||||
$chars_fusion = array('v'=>1, 'w'=>1, 'x'=>1, 'V'=>1, 'W'=>1, 'T'=>1); |
||||
$chars_caps = array('A'=>1, 'B'=>1, 'C'=>1, 'D'=>1, 'E'=>1, 'F'=>1, 'G'=>1, |
||||
'H'=>1, 'I'=>1, 'J'=>1, 'K'=>1, 'L'=>1, 'M'=>1, 'N'=>1, |
||||
'O'=>1, 'P'=>1, 'Q'=>1, 'R'=>1, 'S'=>1, 'T'=>1, 'U'=>1, |
||||
'V'=>1, 'W'=>1, 'X'=>1, 'Y'=>1, 'Z'=>1); |
||||
$chars_nums = array('0'=>1, '1'=>1, '2'=>1, '3'=>1, '4'=>1, '5'=>1, '6'=>1, '7'=>1, '8'=>1, '9'=>1); |
||||
$bichars_fusion = array('ve'=>1, 'vo'=>1, 'ev'=>1, 'ov'=>1, |
||||
'xe'=>1, 'xo'=>1, 'ox'=>1, 'ex'=>1, |
||||
'we'=>1, 'wo'=>1, 'ow'=>1, 'ew'=>1, 'ff'=>1); |
||||
} |
||||
// Longueur max pour limiter les erreurs d'extraction |
||||
$chaine_len = 140; |
||||
|
||||
$stream = preg_split(",\)[^(]*\(,", $stream); |
||||
$extrait = ''; |
||||
$fini = false; |
||||
$this->flag_brut = false; |
||||
// Cette boucle est capable de basculer entre deux trois d'execution : |
||||
// - normal (plusieurs caracteres par chaine avec fusion) |
||||
// - brut (plusieurs caracteres par chaine sans fusion) |
||||
// - mono (un caractere par chaine) |
||||
while (1) { |
||||
if ($this->flag_mono) { |
||||
// Un caractere par chaine : fusion rapide |
||||
while (list(, $s) = each($stream)) { |
||||
if (strlen($s) != 1) { |
||||
if (strlen($s) < $chaine_len) $extrait .= $s; |
||||
$this->flag_mono = false; |
||||
break; |
||||
} |
||||
$extrait .= $s; |
||||
} |
||||
if ($this->flag_mono) break; |
||||
} |
||||
else if ($this->flag_brut) { |
||||
// Concatenation sans fusion |
||||
while (list(, $s) = each($stream)) $extrait .= $s; |
||||
break; |
||||
} |
||||
$prev_s = ''; |
||||
$prev_c = ''; |
||||
$prev_l = 0; |
||||
$nb_mono = 0; |
||||
$nb_brut = 0; |
||||
// Cas general : appliquer les regles de fusion |
||||
while (list(, $s) = each($stream)) { |
||||
$l = strlen($s); |
||||
if ($l >= $chaine_len) continue; |
||||
$c = $s{0}; |
||||
// Annulation de la cesure |
||||
if ($prev_c == '-') { |
||||
$extrait .= substr($prev_s, 0, -1); |
||||
} |
||||
else { |
||||
$extrait .= $prev_s; |
||||
$len_w = strpos($s.' ', ' '); |
||||
$prev_len_w = $prev_l - strrpos($prev_s, ' '); |
||||
$court = ($prev_len_w < 3 OR $len_w < 3); |
||||
// Heuristique pour separation des mots |
||||
if (/*$len_w == 1 OR $prev_len_w == 1 |
||||
OR */($court AND ($chars_fusion[$prev_c] OR $chars_fusion[$c] |
||||
OR ($chars_caps[$prev_c] AND ($chars_caps[$c] OR $chars_nums[$c])))) |
||||
OR ($prev_c == 'f' AND $chars_voyelles[$c]) |
||||
OR $bichars_fusion[$prev_c.$c]) { |
||||
} |
||||
else $extrait .= ' '; |
||||
} |
||||
$prev_c = $s{$l - 1}; |
||||
$prev_s = $s; |
||||
$prev_l = $l; |
||||
// Detection du format mono-caractere |
||||
if ($l == 1) { |
||||
if (++$nb_mono >= 3) { |
||||
$this->flag_mono = true; |
||||
break; |
||||
} |
||||
} |
||||
else { |
||||
$nb_mono = 0; |
||||
if ($c == ' ' OR $prev_c == ' ') { |
||||
$this->flag_brut = true; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
$extrait .= $prev_s; |
||||
if (!$this->flag_mono && !$this->flag_brut) break; |
||||
} |
||||
return $extrait; |
||||
} |
||||
|
||||
// http://doc.spip.org/@extraire_texte |
||||
function extraire_texte($fichier) { |
||||
|
||||
$source_len = 1024*1024; |
||||
$stream_len = 20*1024; |
||||
$texte_len = 40*1024; |
||||
|
||||
$f = fopen($fichier, "rb"); |
||||
if (!$f) die ("Fichier $fichier impossible a ouvrir"); |
||||
|
||||
$in_stream = false; |
||||
|
||||
// Decouper le fichier en objets |
||||
unset($objs); |
||||
$objs = fread($f, $source_len); |
||||
$objs = preg_split('/[\s>]endobj\s+/', $objs); |
||||
# echo "<h3>".count($objs)." objets prรฉsents dans le buffer</h3>"; |
||||
|
||||
// Parcourir le fichier pour trouver les streams |
||||
reset($objs); |
||||
$n = count($objs); |
||||
for ($i = 0; $i < $n; $i++) { |
||||
$obj = $objs[$i]; |
||||
|
||||
if (!$in_stream) { |
||||
// Stream (eviter les commentaires) |
||||
$ok = preg_match("/stream(\r\n?|\n)/", $obj); // version rapide d'abord |
||||
if ($ok) $ok = preg_match("/[\r\n](([^\r\n%]*[ \t>])*stream(\r\n?|\n))/", $obj, $regs); |
||||
if (!$ok) continue; |
||||
$p = strpos($obj, $regs[1]); |
||||
$t = substr($obj, $p + strlen($regs[1])); |
||||
$stream = ""; |
||||
$in_stream = true; |
||||
|
||||
$obj_text = substr($obj, 0, $p + strlen($regs[1])); |
||||
|
||||
// Parasites avant et apres |
||||
//$obj_text = preg_replace("/^\s+obj\s+/", "", $obj_text); |
||||
//$obj_text = preg_replace("/(\s+endobj)\s+.*$/", "\\1", $obj_text); |
||||
|
||||
// Commentaires |
||||
$obj_text = preg_replace("/\\\\%/", ' ', $obj_text); |
||||
$obj_text = preg_replace("/%[^\r\n]*[\r\n]+/", '', $obj_text); |
||||
|
||||
// Dictionnaire |
||||
$obj_dict = ""; |
||||
//if (ereg("<<(.*)>>", $obj_text, $regs)) |
||||
if (preg_match("/<<(.*)>>/s", $obj_text, $regs)) // bug ?! |
||||
$obj_dict = $regs[1]; |
||||
|
||||
# echo "<hr>"; |
||||
# echo "Objet numรฉro $i<p>"; |
||||
# echo "<pre>".htmlspecialchars($obj_text)."</pre>"; |
||||
} |
||||
else { |
||||
$t = " endobj ".$obj; // approximation |
||||
} |
||||
unset($obj); |
||||
|
||||
// Recoller les morceaux du stream (au cas ou un "obj" se trouvait en clair dans un stream) |
||||
if ($in_stream) { |
||||
if (!($p = strpos($t, "endstream")) && !($q = strpos($t, "endobj"))) { |
||||
$stream .= $t; |
||||
# echo "<span style='color: red'>Stream continuรฉ</span><p>"; |
||||
continue; |
||||
} |
||||
$in_stream = false; |
||||
if ($p) $stream .= substr($t, 0, $p); |
||||
else $stream .= substr($t, 0, $q); |
||||
unset($t); |
||||
|
||||
// Decoder le contenu du stream |
||||
$encoding = ''; |
||||
if (preg_match(",/Filter\s*/([A-Za-z]+),", $obj_dict, $regs)) |
||||
$encoding = $regs[1]; |
||||
switch($encoding) { |
||||
case 'FlateDecode': |
||||
$stream = gzuncompress($stream); // pb avec certains PDFs !? |
||||
break; |
||||
case '': |
||||
break; |
||||
default: |
||||
$stream = ''; |
||||
} |
||||
/*if (preg_match("/\(d.marrage:\)/", $stream, $regs)) { |
||||
$fs = fopen("demarrage.txt", "w"); |
||||
fwrite($fs, $regs[0]); |
||||
fclose($fs); |
||||
exit; |
||||
}*/ |
||||
} |
||||
|
||||
if (!$stream) continue; |
||||
|
||||
# echo "Stream : ".strlen($stream)." octets<p>"; |
||||
|
||||
// Eviter les fontes embarquees, etc. |
||||
if (preg_match(',^%!,', $stream)) { |
||||
unset($stream); |
||||
continue; |
||||
} |
||||
// Detection texte / binaire |
||||
$stream = substr($stream, 0, $stream_len); |
||||
$stream = str_replace('\\(', ",", $stream); |
||||
$stream = str_replace('\\)', ",", $stream); |
||||
$n1 = substr_count($stream, '('); |
||||
$n2 = substr_count($stream, ')'); |
||||
$freq = (substr_count($stream, ' ') + $n1 + $n2) / strlen($stream); |
||||
if ($freq < 0.04 || (!$n1 && !$n2)) { |
||||
# echo "no text (1)<p>"; |
||||
//echo htmlspecialchars($stream); |
||||
unset($stream); |
||||
continue; |
||||
} |
||||
$dev = abs($n1 - $n2) / ($n1 + $n2); |
||||
if ($dev > 0.05) { |
||||
# echo "no text (2)<p>"; |
||||
unset($stream); |
||||
continue; |
||||
} |
||||
// Extraction des chaines |
||||
if (strpos($stream, '<<') && strpos($stream, '>>')) |
||||
$stream = preg_replace(',<<.*?'.'>>,s', '', $stream); // bug avec preg |
||||
$stream = substr($stream, strpos($stream, '(') + 1); |
||||
$stream = substr($stream, 0, strrpos($stream, ')')); // ici un bug occasionnel... |
||||
$stream = $this->convertir_caracteres($stream); |
||||
$extrait = $this->recoller_texte($stream); |
||||
unset($stream); |
||||
$texte .= $extrait; |
||||
|
||||
// Se limiter a une certaine taille de texte en sortie |
||||
if (strlen($texte) > $texte_len) { |
||||
$texte = substr($texte, 0, strrpos(substr($texte, 0, $texte_len), ' ')); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
fclose($f); |
||||
|
||||
return $texte; |
||||
} |
||||
|
||||
} // class |
||||
|
||||
|
||||
?> |
@ -1,47 +0,0 @@
|
||||
<?php |
||||
|
||||
// |
||||
// Lit un document 'rtf' et extrait son contenu en texte brut |
||||
// |
||||
|
||||
// NOTE : l'extracteur n'est pas oblige de convertir le contenu dans |
||||
// le charset du site, mais il *doit* signaler le charset dans lequel |
||||
// il envoie le contenu, de facon a ce qu'il soit converti au moment |
||||
// voulu ; dans le cas contraire le document sera lu comme s'il etait |
||||
// dans le charset iso-8859-1 |
||||
|
||||
// http://doc.spip.org/@extracteur_rtf |
||||
function extracteur_rtf($fichier, &$charset) { |
||||
|
||||
$charset = 'iso-8859-1'; |
||||
|
||||
@exec('metamail -d -q -b -c application/rtf '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return @join(' ', $r); |
||||
|
||||
# wvText |
||||
# http://wvware.sourceforge.net/ |
||||
$temp = tempnam(_DIR_CACHE, 'rtf'); |
||||
@exec('wvText '.escapeshellarg($fichier).'> '.$temp, $r, $e); |
||||
lire_fichier($temp, $contenu); |
||||
@unlink($temp); |
||||
if (!$e) return $contenu; |
||||
|
||||
|
||||
# unrtf |
||||
# http://www.gnu.org/software/unrtf/unrtf.html |
||||
# --html car avec --text les accents sont perdus :( |
||||
@exec('unrtf --html '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return join(' ', $r); |
||||
|
||||
# catdoc |
||||
# http://www.45.free.net/~vitus/ice/catdoc/ |
||||
@exec('catdoc '.escapeshellarg($fichier), $r, $e); |
||||
if (!$e) return join(' ', $r); |
||||
|
||||
} |
||||
|
||||
// Sait-on extraire ce format ? |
||||
// TODO: ici tester si les binaires fonctionnent |
||||
$GLOBALS['extracteur']['rtf'] = 'extracteur_rtf'; |
||||
|
||||
?> |
@ -1,991 +0,0 @@
|
||||
<?php |
||||
|
||||
/***************************************************************************\ |
||||
* SPIP, Systeme de publication pour l'internet * |
||||
* * |
||||
* Copyright (c) 2001-2007 * |
||||
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * |
||||
* * |
||||
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. * |
||||
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. * |
||||
\***************************************************************************/ |
||||
|
||||
if (!defined("_ECRIRE_INC_VERSION")) return; |
||||
include_spip('inc/meta'); |
||||
include_spip('base/create'); |
||||
include_spip('base/abstract_sql'); |
||||
include_spip('public/interfaces'); |
||||
|
||||
// Quels formats sait-on extraire ? |
||||
$GLOBALS['extracteur'] = array ( |
||||
'txt' => 'extracteur_txt', |
||||
'pas' => 'extracteur_txt', |
||||
'c' => 'extracteur_txt', |
||||
'css' => 'extracteur_txt', |
||||
'html' => 'extracteur_html' |
||||
); |
||||
|
||||
// tables que l'on ne doit pas indexer |
||||
global $INDEX_tables_interdites; |
||||
$INDEX_tables_interdites=array(); |
||||
|
||||
// Indexation des elements de l'objet principal |
||||
// 'champ'=>poids, ou 'champ'=>array(poids,min_long) |
||||
$reindex = false; |
||||
global $INDEX_elements_objet; |
||||
$INDEX_elements_objet = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_elements_objet'])) |
||||
$INDEX_elements_objet = unserialize($GLOBALS['meta']['INDEX_elements_objet']); |
||||
if (!$INDEX_elements_objet) { |
||||
$INDEX_elements_objet['spip_articles'] = array('titre'=>8,'soustitre'=>5,'surtitre'=>5,'descriptif'=>4,'chapo'=>3,'texte'=>1,'ps'=>1,'nom_site'=>1,'extra|unserialize_join'=>1); |
||||
$INDEX_elements_objet['spip_breves'] = array('titre'=>8,'texte'=>2,'extra|unserialize_join'=>1); |
||||
$INDEX_elements_objet['spip_rubriques'] = array('titre'=>8,'descriptif'=>5,'texte'=>1,'extra|unserialize_join'=>1); |
||||
$INDEX_elements_objet['spip_auteurs'] = array('nom'=>array(5,2),'bio'=>1,'extra|unserialize_join'=>1); |
||||
$INDEX_elements_objet['spip_mots'] = array('titre'=>8,'descriptif'=>5,'texte'=>1,'extra|unserialize_join'=>1); |
||||
$INDEX_elements_objet['spip_signatures'] = array('nom_email'=>array(2,2),'ad_email'=>2,'nom_site'=>2,'url_site'=>1,'message'=>1); |
||||
$INDEX_elements_objet['spip_syndic'] = array('nom_site'=>50,'descriptif'=>30,'url_site|contenu_page_accueil'=>1); |
||||
$INDEX_elements_objet['spip_syndic_articles'] = array('titre'=>5); |
||||
$INDEX_elements_objet['spip_forum'] = array('titre'=>3,'texte'=>2,'auteur'=>array(2,2),'email_auteur'=>2,'nom_site'=>2,'url_site'=>1); |
||||
$INDEX_elements_objet['spip_documents'] = array('titre'=>20,'descriptif'=>10,'fichier|nettoie_nom_fichier'=>1); |
||||
ecrire_meta('INDEX_elements_objet',serialize($INDEX_elements_objet)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
|
||||
// Indexation des objets associes |
||||
// 'objet'=>poids |
||||
global $INDEX_objet_associes; |
||||
$INDEX_objet_associes = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_objet_associes'])) |
||||
$INDEX_objet_associes = unserialize($GLOBALS['meta']['INDEX_objet_associes']); |
||||
if (!$INDEX_objet_associes) { |
||||
$INDEX_objet_associes['spip_articles'] = array('spip_documents'=>1,'spip_auteurs'=>10,'spip_mots'=>3); |
||||
$INDEX_objet_associes['spip_breves'] = array('spip_documents'=>1,'spip_mots'=>3); |
||||
$INDEX_objet_associes['spip_rubriques'] = array('spip_documents'=>1,'spip_mots'=>3); |
||||
$INDEX_objet_associes['spip_documents'] = array('spip_mots'=>3); |
||||
ecrire_meta('INDEX_objet_associes',serialize($INDEX_objet_associes)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
|
||||
// Indexation des elements des objets associes |
||||
// 'champ'=>poids, ou 'champ'=>array(poids,min_long) |
||||
global $INDEX_elements_associes; |
||||
$INDEX_elements_associes = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_elements_associes'])) |
||||
$INDEX_elements_associes = unserialize($GLOBALS['meta']['INDEX_elements_associes']); |
||||
if (!$INDEX_elements_associes){ |
||||
$INDEX_elements_associes['spip_documents'] = array('titre'=>2,'descriptif'=>1); |
||||
$INDEX_elements_associes['spip_auteurs'] = array('nom'=>1); |
||||
$INDEX_elements_associes['spip_mots'] = array('titre'=>4,'descriptif'=>1); |
||||
ecrire_meta('INDEX_elements_associes',serialize($INDEX_elements_associes)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
// Criteres d'indexation |
||||
global $INDEX_critere_indexation; |
||||
$INDEX_critere_indexation = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_critere_indexation'])) |
||||
$INDEX_critere_indexation = unserialize($GLOBALS['meta']['INDEX_critere_indexation']); |
||||
if (!$INDEX_critere_indexation){ |
||||
$INDEX_critere_indexation['spip_articles']="statut='publie'"; |
||||
$INDEX_critere_indexation['spip_breves']="statut='publie'"; |
||||
$INDEX_critere_indexation['spip_rubriques']="statut='publie'"; |
||||
$INDEX_critere_indexation['spip_syndic']="statut='publie'"; |
||||
$INDEX_critere_indexation['spip_forum']="statut='publie'"; |
||||
$INDEX_critere_indexation['spip_signatures']="statut='publie'"; |
||||
ecrire_meta('INDEX_critere_indexation',serialize($INDEX_critere_indexation)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
|
||||
// Criteres de des-indexation (optimisation dans base/optimiser) |
||||
global $INDEX_critere_optimisation; |
||||
$INDEX_critere_optimisation = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_critere_optimisation'])) |
||||
$INDEX_critere_optimisation = unserialize($GLOBALS['meta']['INDEX_critere_optimisation']); |
||||
if (!$INDEX_critere_optimisation) { |
||||
$INDEX_critere_optimisation['spip_articles']="statut<>'publie'"; |
||||
$INDEX_critere_optimisation['spip_breves']="statut<>'publie'"; |
||||
$INDEX_critere_optimisation['spip_rubriques']="statut<>'publie'"; |
||||
$INDEX_critere_optimisation['spip_syndic']="statut<>'publie'"; |
||||
$INDEX_critere_optimisation['spip_forum']="statut<>'publie'"; |
||||
$INDEX_critere_optimisation['spip_signatures']="statut<>'publie'"; |
||||
ecrire_meta('INDEX_critere_optimisation',serialize($INDEX_critere_optimisation)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
|
||||
// Nombre d'elements maxi a indexer a chaque iteration |
||||
global $INDEX_iteration_nb_maxi; |
||||
$INDEX_iteration_nb_maxi = FALSE; |
||||
if (isset($GLOBALS['meta']['INDEX_iteration_nb_maxi'])) |
||||
$INDEX_iteration_nb_maxi = unserialize($GLOBALS['meta']['INDEX_iteration_nb_maxi']); |
||||
if (!$INDEX_iteration_nb_maxi) { |
||||
$INDEX_iteration_nb_maxi['spip_documents']=10; |
||||
$INDEX_iteration_nb_maxi['spip_syndic']=1; |
||||
ecrire_meta('INDEX_iteration_nb_maxi',serialize($INDEX_iteration_nb_maxi)); |
||||
ecrire_metas(); |
||||
$reindex = true; |
||||
} |
||||
if ($reindex) creer_liste_indexation(); |
||||
|
||||
|
||||
// Filtres d'indexation |
||||
// http://doc.spip.org/@unserialize_join |
||||
function unserialize_join($extra){ |
||||
return @join(' ', unserialize($extra)); |
||||
} |
||||
// http://doc.spip.org/@contenu_page_accueil |
||||
function contenu_page_accueil($url){ |
||||
$texte = ''; |
||||
if ($GLOBALS['meta']["visiter_sites"] == "oui") { |
||||
include_spip('inc/distant'); |
||||
spip_log ("indexation contenu syndic $url"); |
||||
$texte = supprimer_tags(recuperer_page($url, true, false, 50000)); |
||||
} |
||||
return $texte; |
||||
} |
||||
// http://doc.spip.org/@nettoie_nom_fichier |
||||
function nettoie_nom_fichier($fichier){ |
||||
return preg_replace(',^(IMG/|.*://),', '', $fichier); |
||||
} |
||||
|
||||
// Renvoie la liste des "mots" d'un texte (ou d'une requete adressee au moteur) |
||||
// http://doc.spip.org/@mots_indexation |
||||
function mots_indexation($texte, $min_long = 3) { |
||||
include_spip('inc/charsets'); |
||||
include_spip('inc/texte'); |
||||
|
||||
// Recuperer les parametres des modeles |
||||
$texte = traiter_modeles($texte, true); |
||||
|
||||
// Supprimer les tags HTML |
||||
$texte = preg_replace(',<.*>,Ums',' ',$texte); |
||||
|
||||
// Translitterer (supprimer les accents, recuperer les é etc) |
||||
// la translitteration complexe (vietnamien, allemand) duplique |
||||
// le texte, en mettant bout a bout une translitteration simple + |
||||
// une translitteration riche |
||||
if ($GLOBALS['translitteration_complexe']) |
||||
$texte_c = ' '.translitteration_complexe ($texte, 'AUTO', true); |
||||
else |
||||
$texte_c = ''; |
||||
$texte = translitteration($texte); |
||||
if($texte!=trim($texte_c)) $texte .= $texte_c; |
||||
# NB. tous les caracteres non translitteres sont retournes en utf-8 |
||||
|
||||
// OPTIONNEL // Gestion du tiret '-' : |
||||
// "vice-president" => "vice"+"president"+"vicepresident" |
||||
# $texte = preg_replace(',(\w+)-(\w+),', '\1 \2 \1\2', $texte); |
||||
|
||||
// Supprimer les caracteres de ponctuation, les guillemets... |
||||
$e = "],:;*\"!\r\n\t\\/)}{[|@<>$%'`?\~.^("; |
||||
$texte = strtr($texte, $e, preg_replace('/./', ' ', $e)); |
||||
|
||||
//delete +\- not at the beginning of a word |
||||
$texte = preg_replace(",(?:\S)[\-+],"," ",$texte); |
||||
// Cas particulier : sigles d'au moins deux lettres |
||||
$texte = preg_replace("/ ([A-Z][0-9A-Z]{1,".($min_long - 1)."}) /", |
||||
' \\1___ ', $texte.' '); |
||||
|
||||
// Tout passer en bas de casse |
||||
$texte = strtolower($texte); |
||||
|
||||
// Retourner sous forme de table |
||||
return pipeline('mots_indexation',array('args'=>array('min_long'=>$min_long),'data'=>preg_split("/ +/", trim($texte)))); |
||||
} |
||||
|
||||
// http://doc.spip.org/@indexer_chaine |
||||
function indexer_chaine($texte, $val = 1, $min_long = 3) { |
||||
global $index, $mots; |
||||
global $translitteration_complexe; |
||||
|
||||
// Point d'entree pour traiter le texte avant indexation |
||||
$texte = pipeline('pre_indexation', $texte); |
||||
|
||||
$table = mots_indexation($texte, $min_long); |
||||
|
||||
foreach ($table as $mot) { |
||||
if (strlen($mot) > $min_long) { |
||||
$h = substr(md5($mot), 0, 16); |
||||
if (!isset($index[$h])) |
||||
$index[$h] = 0; |
||||
$index[$h] += $val/(1+$translitteration_complexe); |
||||
$mots .= ",(0x$h,'$mot')"; |
||||
} |
||||
} |
||||
} |
||||
|
||||
// id_table = 1...9 pour les tables spip, et ensuite 100, 101, 102... |
||||
// pour les tables additionnelles, selon l'ordre dans lequel |
||||
// elles sont reperees. On stocke le tableau de conversion table->id_table |
||||
// dans spip_meta |
||||
// http://doc.spip.org/@update_index_tables |
||||
function update_index_tables(){ |
||||
global $tables_principales; |
||||
global $INDEX_tables_interdites; |
||||
|
||||
$old_liste_tables = liste_index_tables(); |
||||
$rev_old_liste_tables = array_flip($old_liste_tables); |
||||
|
||||
$liste_tables = array(); |
||||
// les tables SPIP conventionnelles en priorite |
||||
$liste_tables[1]='spip_articles'; |
||||
$liste_tables[2]='spip_auteurs'; |
||||
$liste_tables[3]='spip_breves'; |
||||
$liste_tables[4]='spip_documents'; |
||||
$liste_tables[5]='spip_forum'; |
||||
$liste_tables[6]='spip_mots'; |
||||
$liste_tables[7]='spip_rubriques'; |
||||
$liste_tables[8]='spip_signatures'; |
||||
$liste_tables[9]='spip_syndic'; |
||||
|
||||
// detection des nouvelles tables |
||||
$id_autres = 100; |
||||
foreach(array_keys($tables_principales) as $new_table){ |
||||
if ( (!in_array($new_table,$INDEX_tables_interdites)) |
||||
&&(!in_array($new_table,$liste_tables)) |
||||
&&($id_autres<254) ){ |
||||
// on utilise abstract_showtable car cela permet d'activer l'indexation |
||||
// en ajoutant simplement le champ idx, sans toucher au core |
||||
$desc = spip_abstract_showtable($new_table, '', true); |
||||
if (isset($desc['field']['idx'])){ |
||||
// la table a un champ idx pour gerer l'indexation |
||||
if ( (isset($rev_old_liste_tables[$new_table])) |
||||
&&(!isset($liste_tables[$rev_old_liste_tables[$new_table]])) ) |
||||
$liste_tables[$rev_old_liste_tables[$new_table]] = $new_table; // id conserve |
||||
else{ |
||||
while (isset($liste_tables[$id_autres])&&($id_autres<254)) $id_autres++; |
||||
$liste_tables[$id_autres] = $new_table; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// Cas de l'ajout d'une nouvelle table a indexer : |
||||
// mise en coherence de la table d'indexation avec les nouveaux id |
||||
$rev_old_liste_tables = array_flip($old_liste_tables); |
||||
foreach($liste_tables as $new_id=>$new_table){ |
||||
if (isset($rev_old_liste_tables[$new_table])){ |
||||
if ( ($old_id = ($rev_old_liste_tables[$new_table])) |
||||
&&($old_id!=$new_id)){ |
||||
$temp_id = 254; |
||||
// liberer le nouvel id |
||||
spip_query("UPDATE spip_index SET id_table=$temp_id WHERE id_table=$new_id"); |
||||
// deplacer les indexation de l'ancien id sous le nouvel id |
||||
spip_query("UPDATE spip_index SET id_table=$new_id WHERE id_table=$old_id"); |
||||
// remettre les indexation deplacees sous l'id qui vient d'etre libere |
||||
spip_query("UPDATE spip_index SET id_table=$old_id WHERE id_table=$temp_id"); |
||||
|
||||
$old_liste_tables[$old_id] = $old_liste_tables[$new_id]; |
||||
unset($old_liste_tables[$new_id]); |
||||
$rev_old_liste_tables = array_flip($old_liste_tables); |
||||
} |
||||
|