| 4 | david | 1 | <?php
 | 
        
           |  |  | 2 |   | 
        
           |  |  | 3 | //
 | 
        
           |  |  | 4 | // Lit un document 'doc' et extrait son contenu en texte brut
 | 
        
           |  |  | 5 | //
 | 
        
           |  |  | 6 |   | 
        
           |  |  | 7 | // NOTE : l'extracteur n'est pas oblige de convertir le contenu dans
 | 
        
           |  |  | 8 | // le charset du site, mais il *doit* signaler le charset dans lequel
 | 
        
           |  |  | 9 | // il envoie le contenu, de facon a ce qu'il soit converti au moment
 | 
        
           |  |  | 10 | // voulu ; dans le cas contraire le document sera lu comme s'il etait
 | 
        
           |  |  | 11 | // dans le charset iso-8859-1
 | 
        
           |  |  | 12 |   | 
        
           |  |  | 13 | function extracteur_doc($fichier, &$charset) {
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | 	$charset = 'iso-8859-1';
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | 	exec('metamail -d -q -b -c application/msword '.escapeshellarg($fichier), $r, $e);
 | 
        
           |  |  | 18 | 	if (!$e) return join(' ', $r);
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 | 	# wvText
 | 
        
           |  |  | 21 | 	# http://wvware.sourceforge.net/
 | 
        
           |  |  | 22 | 	$temp = tempnam(_DIR_CACHE, 'doc');
 | 
        
           |  |  | 23 | 	exec('wvText '.escapeshellarg($fichier).'> '.$temp, $r, $e);
 | 
        
           |  |  | 24 | 	lire_fichier($temp, $contenu);
 | 
        
           |  |  | 25 | 	@unlink($temp);
 | 
        
           |  |  | 26 | 	if (!$e) return $contenu;
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | 	# antiword
 | 
        
           |  |  | 29 | 	# http://www.winfield.demon.nl/
 | 
        
           |  |  | 30 | 	exec('antiword '.escapeshellarg($fichier), $r, $e);
 | 
        
           |  |  | 31 | 	if (!$e) return join(' ', $r);
 | 
        
           |  |  | 32 |   | 
        
           |  |  | 33 | 	# catdoc
 | 
        
           |  |  | 34 | 	# http://www.45.free.net/~vitus/ice/catdoc/
 | 
        
           |  |  | 35 | 	exec('catdoc '.escapeshellarg($fichier), $r, $e);
 | 
        
           |  |  | 36 | 	if (!$e) return join(' ', $r);
 | 
        
           |  |  | 37 |   | 
        
           |  |  | 38 | }
 | 
        
           |  |  | 39 |   | 
        
           |  |  | 40 | // Sait-on extraire ce format ?
 | 
        
           |  |  | 41 | // TODO: ici tester si les binaires fonctionnent
 | 
        
           |  |  | 42 | $GLOBALS['extracteur']['doc'] = 'extracteur_doc';
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 | ?>
 |