[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / plugins / odt2spip_32 / inc / odt2spip_traiter_mathml.php
1 <?php
2 /**
3 * Créer un article à partir d'un fichier au format odt
4 *
5 * @author cy_altern
6 * @license GNU/LGPL
7 *
8 * @package plugins
9 * @subpackage odt2spip
10 * @category import
11 *
12 *
13 */
14 if (!defined('_ECRIRE_INC_VERSION')) {
15 return;
16 }
17
18 /**
19 * appliquer la transformation XSLT spécifique des <maths> sur le fichier content.xml extrait du .ODT
20 *
21 * @internal XSLT pour la transformation MathML 2.0 to LaTeX :
22 * Vasil Yaroshevich, <yarosh@raleigh.ru>
23 * http://www.raleigh.ru/MathML/mmltex/index.php?lang=en
24 * @param string $chemin_fichier Le chemin du fichier contenant le MathML
25 * @return string Le LateX de sortie
26 *
27 */
28 function odt2spip_traiter_mathml($chemin_fichier) {
29 // recuperer le contenu du fichier
30 if (!$mathml = file_get_contents($chemin_fichier)) {
31 return(_T('odtspip:err_transformation_xslt_mathml'));
32 }
33
34 // virer le DOCTYPE qui plante le parseur vu que la dtd n'est pas disponible
35 $mathml = preg_replace('/<!DOCTYPE.*?>/i', '', $mathml);
36
37 // appliquer la transformation XSLT sur le fichier content.xml
38 // chemin du fichier xslt a utiliser pour les maths
39 $xslt_texte = _DIR_PLUGIN_ODT2SPIP.'inc/xsltml/mmltex.xsl';
40
41 // on est php5: utiliser les fonctions de la classe XSLTProcessor
42 $proc = new XSLTProcessor();
43
44 $xml = new DOMDocument();
45 $xml->loadXML($mathml);
46 $xsl = new DOMDocument();
47 $xsl->load($xslt_texte);
48 $proc->importStylesheet($xsl); // attachement des règles xsl
49
50 // lancer le parseur
51 if (!$latex_sortie = $proc->transformToXml($xml)) {
52 return(_T('odtspip:err_transformation_xslt_mathml'));
53 }
54
55 return $latex_sortie;
56 }