@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | // |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | // |
@@ -23,56 +23,56 @@ discard block |
||
| 23 | 23 | // https://code.spip.net/@image_math |
| 24 | 24 | function produire_image_math($tex) { |
| 25 | 25 | |
| 26 | - switch ($GLOBALS['traiter_math']) { |
|
| 27 | - // Attention: mathml desactiv'e pour l'instant |
|
| 28 | - case 'mathml': |
|
| 29 | - $ext = '.xhtml'; |
|
| 30 | - $server = $GLOBALS['mathml_server']; |
|
| 31 | - break; |
|
| 32 | - case 'tex': |
|
| 33 | - $ext = '.png'; |
|
| 34 | - $server = $GLOBALS['tex_server']; |
|
| 35 | - break; |
|
| 36 | - default: |
|
| 37 | - return $tex; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 41 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 42 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 43 | - } |
|
| 44 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - if (!@file_exists($fichier)) { |
|
| 48 | - // Aller chercher l'image sur le serveur |
|
| 49 | - if ($server) { |
|
| 50 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 51 | - include_spip('inc/distant'); |
|
| 52 | - recuperer_page($url, $fichier); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - // Composer la reponse selon presence ou non de l'image |
|
| 58 | - $tex = entites_html($tex); |
|
| 59 | - if (@file_exists($fichier)) { |
|
| 60 | - |
|
| 61 | - // MathML |
|
| 62 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 63 | - return implode("", file($fichier)); |
|
| 64 | - } // TeX |
|
| 65 | - else { |
|
| 66 | - list(, , , $size) = @spip_getimagesize($fichier); |
|
| 67 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 68 | - |
|
| 69 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - } else // pas de fichier |
|
| 73 | - { |
|
| 74 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 75 | - } |
|
| 26 | + switch ($GLOBALS['traiter_math']) { |
|
| 27 | + // Attention: mathml desactiv'e pour l'instant |
|
| 28 | + case 'mathml': |
|
| 29 | + $ext = '.xhtml'; |
|
| 30 | + $server = $GLOBALS['mathml_server']; |
|
| 31 | + break; |
|
| 32 | + case 'tex': |
|
| 33 | + $ext = '.png'; |
|
| 34 | + $server = $GLOBALS['tex_server']; |
|
| 35 | + break; |
|
| 36 | + default: |
|
| 37 | + return $tex; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 41 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 42 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 43 | + } |
|
| 44 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + if (!@file_exists($fichier)) { |
|
| 48 | + // Aller chercher l'image sur le serveur |
|
| 49 | + if ($server) { |
|
| 50 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 51 | + include_spip('inc/distant'); |
|
| 52 | + recuperer_page($url, $fichier); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + // Composer la reponse selon presence ou non de l'image |
|
| 58 | + $tex = entites_html($tex); |
|
| 59 | + if (@file_exists($fichier)) { |
|
| 60 | + |
|
| 61 | + // MathML |
|
| 62 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 63 | + return implode("", file($fichier)); |
|
| 64 | + } // TeX |
|
| 65 | + else { |
|
| 66 | + list(, , , $size) = @spip_getimagesize($fichier); |
|
| 67 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 68 | + |
|
| 69 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + } else // pas de fichier |
|
| 73 | + { |
|
| 74 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -108,46 +108,46 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 110 | 110 | |
| 111 | - $texte_a_voir = $letexte; |
|
| 112 | - while (($debut = strpos($texte_a_voir, "<math>")) !== false) { |
|
| 113 | - if (!$fin = strpos($texte_a_voir, "</math>")) { |
|
| 114 | - $fin = strlen($texte_a_voir); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 118 | - $texte_milieu = substr($texte_a_voir, |
|
| 119 | - $debut + strlen("<math>"), $fin - $debut - strlen("<math>")); |
|
| 120 | - $texte_fin = substr($texte_a_voir, |
|
| 121 | - $fin + strlen("</math>"), strlen($texte_a_voir)); |
|
| 122 | - |
|
| 123 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 124 | - while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) { |
|
| 125 | - $expression = $regs[1]; |
|
| 126 | - if ($defaire_amp) { |
|
| 127 | - $expression = str_replace('&', '&', $expression); |
|
| 128 | - } |
|
| 129 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 130 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 131 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 132 | - . code_echappement($echap, $source) |
|
| 133 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // Les simples $x^2$ en mode 'span' |
|
| 137 | - while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) { |
|
| 138 | - $expression = $regs[1]; |
|
| 139 | - if ($defaire_amp) { |
|
| 140 | - $expression = str_replace('&', '&', $expression); |
|
| 141 | - } |
|
| 142 | - $echap = produire_image_math($expression); |
|
| 143 | - $pos = strpos($texte_milieu, $regs[0]); |
|
| 144 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 145 | - . code_echappement($echap, $source) |
|
| 146 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $texte_a_voir; |
|
| 111 | + $texte_a_voir = $letexte; |
|
| 112 | + while (($debut = strpos($texte_a_voir, "<math>")) !== false) { |
|
| 113 | + if (!$fin = strpos($texte_a_voir, "</math>")) { |
|
| 114 | + $fin = strlen($texte_a_voir); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 118 | + $texte_milieu = substr($texte_a_voir, |
|
| 119 | + $debut + strlen("<math>"), $fin - $debut - strlen("<math>")); |
|
| 120 | + $texte_fin = substr($texte_a_voir, |
|
| 121 | + $fin + strlen("</math>"), strlen($texte_a_voir)); |
|
| 122 | + |
|
| 123 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 124 | + while ((preg_match(",[$][$]([^$]+)[$][$],", $texte_milieu, $regs))) { |
|
| 125 | + $expression = $regs[1]; |
|
| 126 | + if ($defaire_amp) { |
|
| 127 | + $expression = str_replace('&', '&', $expression); |
|
| 128 | + } |
|
| 129 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 130 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 131 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 132 | + . code_echappement($echap, $source) |
|
| 133 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // Les simples $x^2$ en mode 'span' |
|
| 137 | + while ((preg_match(",[$]([^$]+)[$],", $texte_milieu, $regs))) { |
|
| 138 | + $expression = $regs[1]; |
|
| 139 | + if ($defaire_amp) { |
|
| 140 | + $expression = str_replace('&', '&', $expression); |
|
| 141 | + } |
|
| 142 | + $echap = produire_image_math($expression); |
|
| 143 | + $pos = strpos($texte_milieu, $regs[0]); |
|
| 144 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 145 | + . code_echappement($echap, $source) |
|
| 146 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $texte_a_voir; |
|
| 153 | 153 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 41 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 41 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 42 | 42 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 43 | 43 | } |
| 44 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 44 | + $fichier = $dir_tex.md5(trim($tex)).$ext; |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | if (!@file_exists($fichier)) { |
| 48 | 48 | // Aller chercher l'image sur le serveur |
| 49 | 49 | if ($server) { |
| 50 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 50 | + spip_log($url = $server.'?'.rawurlencode($tex)); |
|
| 51 | 51 | include_spip('inc/distant'); |
| 52 | 52 | recuperer_page($url, $fichier); |
| 53 | 53 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | return implode("", file($fichier)); |
| 64 | 64 | } // TeX |
| 65 | 65 | else { |
| 66 | - list(, , , $size) = @spip_getimagesize($fichier); |
|
| 66 | + list(,,, $size) = @spip_getimagesize($fichier); |
|
| 67 | 67 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 68 | 68 | |
| 69 | 69 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | if ($defaire_amp) { |
| 127 | 127 | $expression = str_replace('&', '&', $expression); |
| 128 | 128 | } |
| 129 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 129 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 130 | 130 | $pos = strpos($texte_milieu, $regs[0]); |
| 131 | 131 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 132 | 132 | . code_echappement($echap, $source) |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 149 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return $texte_a_voir; |