<?php
/*
Plugin Name: PHP Math Publisher
Plugin URI: http://www.slug.it/naufraghi/programmazione-web/wpmathpublisher
Description: Finds ASCII formulas in posts between [pmath][/pmath] tags and converts the ASCII to images using the <a href="http://www.xm1math.net/phpmathpublisher/">PHP Math Publisher</a>.
Version: 1.0.3
Author: Matteo Bertini
Author URI: http://www.slug.it/naufraghi/
*/

//######## CONFIG START ########

$basedir "/naufraghi/wp-content/plugins/phpmathpublisher";

//######## CONFIG  END  ########


// Include the PHP Math Publisher library
// See: http://www.xm1math.net/phpmathpublisher/
include_once("mathpublisher.php") ;

//Overwrite dir locations
$dirfonts=$_SERVER["DOCUMENT_ROOT"].$basedir."/fonts";
$dirimg=$_SERVER["DOCUMENT_ROOT"].$basedir."/img";

function 
wpmathfilter($ascii_math)
{
    global 
$basedir;
    
//mathfilter($text, $size, $pathtoimg)
    
$phpmath mathfilter("<m>".$ascii_math."</m>"12$basedir."/img/");
    return 
$phpmath;
}

function 
to_phpmath($content)
{
    
$content preg_replace('#\[pmath\](.*?)\[/pmath\]#sie''wpmathfilter(\'\\1\');'$content);
    return 
$content;
}

// Register this filter before Markdown (index=6)
add_filter('the_content''to_phpmath'5);

?>