Esempio n. 1
0
/**
*RenderWikiPlot CallBack function
*
*This is the function that handles MediaWiki callbacks, and renders the actual plot.
*
*@access private
*@param string $input The content of the wikiplot tag
*@param array $argv Hash-array of the parameters of the wikiplot tag, with parameter-name as key and parameter-value as value.
*@param Parser $parser The parser of MediaWiki, if null parser is obtained from global variable
*@uses WikiPlotDeserializeBoolean()
*@uses WikiPlotDeserializeString()
*@uses WikiPlotDeserializeMixed()
*@uses WikiPlotDeserializeInteger()
*@uses WikiPlotDeserializeColor()
*@uses XMLParser
*@uses Plot
*@uses Graph
*@uses Cache
*@return string HTML that can be directly inserted into any website.
*/
function RenderWikiPlot($input, $argv, $parser = null)
{
    //Get parser if not given as parameter
    if (!$parser) {
        $parser =& $GLOBALS['wgParser'];
    }
    /*Currently the parser*/
    //Creating instance of plot
    $Plot = new Plot();
    //Getting and deserializing parameters
    WikiPlotDeserializeBoolean($argv["grid"], $Plot->EnableGrid);
    WikiPlotDeserializeBoolean($argv["axis"], $Plot->EnableAxis);
    WikiPlotDeserializeString($argv["caption"], $Plot->Caption);
    WikiPlotDeserializeMixed($argv["xspan"], $Plot->MinX, $Plot->MaxX);
    WikiPlotDeserializeMixed($argv["yspan"], $Plot->MinY, $Plot->MaxY);
    WikiPlotDeserializeMixed($argv["gridspace"], $Plot->XGridSpace, $Plot->YGridSpace);
    WikiPlotDeserializeInteger($argv["height"], $Plot->Height);
    WikiPlotDeserializeInteger($argv["width"], $Plot->Width);
    WikiPlotDeserializeInteger($argv["captionfont"], $Plot->CaptionFont);
    WikiPlotDeserializeInteger($argv["gridfont"], $Plot->GridFont);
    WikiPlotDeserializeColor($argv["gridcolor"], $Plot->GridColor);
    //Parsing Xml
    $XmlParser = new XMLParser($input);
    $Graphs = $XmlParser->CreateInputArray();
    foreach ($Graphs as $Graph) {
        $G = new Graph();
        if (!is_array($Graph[1])) {
            $G->Exp = $Graph[1];
            WikiPlotDeserializeString($Graph[0]["label"], $G->Label);
            WikiPlotDeserializeColor($Graph[0]["color"], $G->Color);
        } else {
            $G->Exp = $Graph[0];
        }
        array_push($Plot->Graphs, $G);
    }
    //Render the plot
    //Get instance of cache
    $cache = new cache();
    //Url of the current plot
    $PlotURL = "";
    $PlotFileName = $Plot->GetHash() . ".png";
    if (!$cache->FileExist($PlotFileName)) {
        $Plot->SaveAs($cache->CachePath($PlotFileName));
    } else {
        $PlotURL = $cache->FileURL($PlotFileName);
    }
    $output = "<a href='{$PlotURL}' class='image' title='See the plot'><img src='{$PlotURL}'></a>";
    return $output;
}