Ejemplo n.º 1
0
function mathfilter($text, $size)
{
    $text = stripslashes($text);
    $size = max($size, 10);
    $size = min($size, 24);
    return mathimage(trim($text), $size);
}
Ejemplo n.º 2
0
function mathfilter($text, $size, $pathtoimg)
{
    if (!function_exists('imagettfbbox')) {
        // Skip mathfilter if PHP GD doesn't support FreeType
        return $text;
    }
    /* THE MAIN FUNCTION
          1) the content of the math tags (<m></m>) are extracted in the $t variable (you can replace <m></m> by your own tag).
          2) the "mathimage" function replaces the $t code by <img src=...></img> according to this method :
          - if the image corresponding to the formula doesn't exist in the $dirimg cache directory (detectimg($nameimg)=0), the script creates the image and returns the "<img src=...></img>" code.
          - otherwise, the script returns only the <img src=...></img>" code.
          To align correctly the formula image with the text, the "valign" parameter of the image is required.
          That's why a parameter (1000+valign) is recorded in the name of the image file (the "detectimg" function returns this parameter if the image exists in the cache directory)
          To be sure that the name of the image file is unique and to allow the script to retrieve the valign parameter without re-creating the image, the syntax of the image filename is :
          math_(1000+valign)_md5(formulatext.size).png.
          (1000+valign is used instead of valign directly to avoid a negative number)
       */
    // $text=stripslashes($text);
    $size = max($size, 10);
    $size = min($size, 24);
    //preg_match_all("|<m>(.*?)</m>|", $text, $regs, PREG_SET_ORDER);
    preg_match_all("#(<m>.*?</m>|\\[m].*?\\[/m])#", $text, $regs, PREG_SET_ORDER);
    foreach ($regs as $math) {
        //	$t=str_replace('<m>','',$math[0]);
        //	$t=str_replace('</m>','',$t);
        $t = str_replace(array('<m>', '</m>', '[m]', '[/m]'), '', $math[0]);
        $code = mathimage(trim($t), $size, $pathtoimg);
        $text = str_replace($math[0], $code, $text);
    }
    return $text;
}
function mathfilter($text, $size, $pathtoimg)
{
    $text = stripslashes($text);
    $size = max($size, 10);
    $size = min($size, 24);
    preg_match_all("|\\[math\\](.*?)\\[/math\\]|", $text, $regs, PREG_SET_ORDER);
    foreach ($regs as $math) {
        $t = str_replace('[math]', '', $math[0]);
        $t = str_replace('[/math]', '', $t);
        $code = mathimage(trim($t), $size, $pathtoimg);
        $text = str_replace($math[0], $code, $text);
    }
    return $text;
}
 private function replacer(&$matches)
 {
     global $dirfonts, $dirimg;
     // used by mathpublisher
     $args = $matches[2];
     $size = 14;
     // default size
     if (preg_match("/size\\s*=\\s*(\\d+)/", $args, $arg_match)) {
         $size = $arg_match[1];
     }
     $text = $matches[3];
     # make sure the string is url encoded. Some Joomla editors pass in the raw code points
     $text = fix_encoding(html_entity_decode($text));
     # decode all html entities in string first.
     $text = htmlentities($text, ENT_COMPAT, 'UTF-8');
     # encode again in UTF-8
     # now look for entities we want to process in a special way
     # euro not in ISO 8859-1 so use epsilon in formula
     $text = str_replace('&euro;', '{epsilon}', $text);
     $text = str_replace('&#8364;', '{epsilon}', $text);
     # use special tage for other code points that would otherwise become Greek characters
     $text = str_replace('&pound;', '{pound}', $text);
     $text = str_replace('&#163;', '{pound}', $text);
     $text = str_replace('&copy;', '{copy}', $text);
     $text = str_replace('&#169;', '{copy}', $text);
     $text = str_replace('&reg;', '{reg}', $text);
     $text = str_replace('&#174;', '{reg}', $text);
     $text = str_replace('&cent;', '{cent}', $text);
     $text = str_replace('&#162;', '{cent}', $text);
     $text = str_replace('&deg;', '{deg}', $text);
     $text = str_replace('&#176;', '{deg}', $text);
     # now decode html entities again ready for converting to image
     $text = fix_encoding(html_entity_decode($text));
     # decode all html entities before converting to an image. e.g. &lt; => <
     # change quotes to {prime} so they don't cause problems and look OK in the formula
     $text = str_replace("'", '{prime}', $text);
     $text = str_replace('"', '{prime}{prime}', $text);
     $joomla_url_root = $this->params->def('joomla_url_root', '');
     # clean up slashes and spaces around the path
     if (preg_match('/^[\\/\\s]*(.*?)[\\/\\s]*$/', $joomla_url_root, $arg_match)) {
         $joomla_url_root = $arg_match[1];
         # add one leading slash UNLESS empty (joomla is in root)
         if ($joomla_url_root != '') {
             $joomla_url_root = '/' . $joomla_url_root;
         }
     }
     $color = $this->params->def('color', '#000000');
     $bg_color = $this->params->def('bg_color', '#ffffff');
     # override colours if they are on the mathpublisher tag
     if (preg_match("/^(?:.*[^_])?color\\s*=\\s*([^,\\s]+)/", $args, $arg_match)) {
         $color = $arg_match[1];
     }
     if (preg_match("/bg_color\\s*=\\s*([^,\\s]+)/", $args, $arg_match)) {
         $bg_color = $arg_match[1];
     }
     $vf = get_plugin_version_folder();
     if ($vf != '') {
         $vf = '/' . $vf;
     }
     if ($this->config_ok) {
         $text = mathimage($text, $size, "{$joomla_url_root}/plugins/content{$vf}/mathpublisher/img/", $color, $bg_color);
     } else {
         $text = "{$text}<br />MathPublisher config error!<br />Chek your MathPublisher path configuration.<br />Expecting:<br />" . "mathpublisher.php (lowercase) in '" . $this->mp_inc_file . "'<br />" . "fonts in '" . $dirfonts . "'<br />" . "images in '" . $dirimg . "'<br />" . "image url '{$joomla_url_root}/plugins/content{$vf}/mathpublisher/img/*.png<br />";
     }
     return $text;
 }
 /**
  * @static
  * @desc Parses the latex code and replaces it by an image containing the mathematic formula.
  * @param string[] $matches 0 => the whole tag, 1 => the latex code to parse.
  * @return string The code of the image containing the formula.
  */
 private function math_code($matches)
 {
     $matches[1] = str_replace('<br />', '', $matches[1]);
     $code = mathimage($matches[1], 12, '/images/maths/');
     return $code;
 }