[ Index ]
 

Code source de SPIP 1.9.2c

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/ecrire/inc/ -> math.php (source)

   1  <?php
   2  
   3  /***************************************************************************\
   4   *  SPIP, Systeme de publication pour l'internet                           *
   5   *                                                                         *
   6   *  Copyright (c) 2001-2007                                                *
   7   *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
   8   *                                                                         *
   9   *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
  10   *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
  11  \***************************************************************************/
  12  
  13  
  14  //
  15  if (!defined("_ECRIRE_INC_VERSION")) return;
  16  
  17  //
  18  // Gestion du raccourci <math>...</math> en client-serveur
  19  //
  20  
  21  // http://doc.spip.org/@image_math
  22  function image_math($tex) {
  23      global $traiter_math;
  24      switch ($traiter_math) {
  25          // Attention: mathml desactiv'e pour l'instant
  26          case 'mathml':
  27              $ext = '.xhtml';
  28              $server = $GLOBALS['mathml_server'];
  29              break;
  30          case 'tex':
  31              $ext = '.png';
  32              $server = $GLOBALS['tex_server'];
  33              break;
  34          default:
  35              return $tex;
  36      }
  37  
  38      // Regarder dans le repertoire local des images TeX et blocs MathML
  39      if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/'))
  40          @mkdir ($dir_tex, _SPIP_CHMOD);
  41      $fichier = $dir_tex .md5(trim($tex)).$ext;
  42      
  43  
  44      if (!@file_exists($fichier)) {
  45          // Aller chercher l'image sur le serveur
  46          if ($server) {
  47              spip_log($url = $server.'?'.rawurlencode($tex));
  48              include_spip('inc/distant');
  49              if ($image = recuperer_page($url)) {
  50                  if ($f = @fopen($fichier, 'w')) {
  51                      @fwrite($f, $image);
  52                      @fclose($f);
  53                  }
  54              }
  55          }
  56      }
  57  
  58  
  59      // Composer la reponse selon presence ou non de l'image
  60      $tex = entites_html($tex);
  61      if (@file_exists($fichier)) {
  62  
  63          // MathML
  64          if ($traiter_math == 'mathml') {
  65              return join(file("$fichier"),"");
  66          }
  67  
  68          // TeX
  69          else {
  70              list(,,,$size) = @getimagesize($fichier);
  71              $alt = "alt=\"$tex\" title=\"$tex\""; 
  72              return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />";
  73          }
  74  
  75      }
  76      else // pas de fichier
  77          return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>";
  78  
  79  }
  80  
  81  
  82  // Fonction appelee par propre() s'il repere un mode <math>
  83  // http://doc.spip.org/@traiter_math
  84  function traiter_math($letexte, $source='') {
  85  
  86      $texte_a_voir = $letexte;
  87      while (($debut = strpos($texte_a_voir, "<math>")) !== false) {
  88          if (!$fin = strpos($texte_a_voir,"</math>"))
  89              $fin = strlen($texte_a_voir);
  90  
  91          $texte_debut = substr($texte_a_voir, 0, $debut);
  92          $texte_milieu = substr($texte_a_voir,
  93              $debut+strlen("<math>"), $fin-$debut-strlen("<math>"));
  94          $texte_fin = substr($texte_a_voir,
  95              $fin+strlen("</math>"), strlen($texte_a_voir));
  96  
  97          // Les doubles $$x^2$$ en mode 'div'
  98          while((ereg("[$][$]([^$]+)[$][$]",$texte_milieu, $regs))) {
  99              $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".image_math($regs[1])."</p>\n";
 100              $pos = strpos($texte_milieu, $regs[0]);
 101              $texte_milieu = substr($texte_milieu,0,$pos)
 102                  . code_echappement($echap, $source)
 103                  . substr($texte_milieu,$pos+strlen($regs[0]));
 104          }
 105  
 106          // Les simples $x^2$ en mode 'span'
 107          while((ereg("[$]([^$]+)[$]",$texte_milieu, $regs))) {
 108              $echap = image_math($regs[1]);
 109              $pos = strpos($texte_milieu, $regs[0]);
 110              $texte_milieu = substr($texte_milieu,0,$pos)
 111                  . code_echappement($echap, $source)
 112                  . substr($texte_milieu,$pos+strlen($regs[0]));
 113          }
 114  
 115          $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin;
 116      }
 117  
 118      return $texte_a_voir;
 119  }
 120  
 121  ?>


Généré le : Wed Nov 21 10:20:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics