[PLUGINS] +set de base
[lhc/web/www.git] / www / plugins / odt2spip_30 / inc / odt2spip_traiter_mathml.php
diff --git a/www/plugins/odt2spip_30/inc/odt2spip_traiter_mathml.php b/www/plugins/odt2spip_30/inc/odt2spip_traiter_mathml.php
new file mode 100644 (file)
index 0000000..9fd6797
--- /dev/null
@@ -0,0 +1,54 @@
+<?php\r
+/**\r
+ * Créer un article à partir d'un fichier au format odt\r
+ *\r
+ * @author cy_altern\r
+ * @license GNU/LGPL\r
+ *\r
+ * @package plugins\r
+ * @subpackage odt2spip\r
+ * @category import\r
+ *\r
+ *\r
+ */\r
+if (!defined("_ECRIRE_INC_VERSION")) return;\r
+\r
+/**\r
+ * appliquer la transformation XSLT spécifique des <maths> sur le fichier content.xml extrait du .ODT\r
+ *\r
+ * @internal XSLT pour la transformation MathML 2.0 to LaTeX :\r
+ *             Vasil Yaroshevich, <yarosh@raleigh.ru>\r
+ *             http://www.raleigh.ru/MathML/mmltex/index.php?lang=en\r
+ * @param string $chemin_fichier Le chemin du fichier contenant le MathML\r
+ * @return string Le LateX de sortie\r
+ * \r
+ */\r
+function odt2spip_traiter_mathml($chemin_fichier) {\r
+       // recuperer le contenu du fichier\r
+       if (!$mathml = file_get_contents($chemin_fichier))\r
+               return(_T('odtspip:err_transformation_xslt_mathml'));\r
+\r
+       // virer le DOCTYPE qui plante le parseur vu que la dtd n'est pas disponible\r
+       $mathml = preg_replace('/<!DOCTYPE.*?>/i', '', $mathml);\r
+\r
+       // appliquer la transformation XSLT sur le fichier content.xml\r
+       // chemin du fichier xslt a utiliser pour les maths\r
+       $xslt_texte = _DIR_PLUGIN_ODT2SPIP.'inc/xsltml/mmltex.xsl';\r
+       \r
+       // on est php5: utiliser les fonctions de la classe XSLTProcessor\r
+       $proc = new XSLTProcessor();\r
+\r
+       $xml = new DOMDocument();\r
+       $xml->loadXML($mathml);\r
+       $xsl = new DOMDocument();\r
+       $xsl->load($xslt_texte);\r
+       $proc->importStylesheet($xsl); // attachement des règles xsl\r
+\r
+       // lancer le parseur\r
+       if (!$latex_sortie = $proc->transformToXml($xml))\r
+               return(_T('odtspip:err_transformation_xslt_mathml'));\r
+  \r
+    return $latex_sortie;\r
+}\r
+\r
+?>\r