Exemplo n.º 1
0
$data = $_SESSION['data'];
$color = isset($_SESSION['color']) ? $_SESSION['color'] : 0;
$triangles = isset($_SESSION['triangles']) ? $_SESSION['triangles'] : FALSE;
$antialias = isset($_SESSION['antialias']) ? $_SESSION['antialias'] : 0;
$autosub = isset($_SESSION['autosub']) ? $_SESSION['autosub'] : 0;
$font = isset($_SESSION['font']) ? $_SESSION['font'] : 'Vera.ttf';
$fontsize = isset($_SESSION['fontsize']) ? $_SESSION['fontsize'] : 8;
// Validate the phrase and draw the tree
$sp = new CStringParser($data);
if ($sp->Validate()) {
    // If all is well, go ahead and draw the graph ...
    $sp->Parse();
    if ($autosub) {
        $sp->AutoSubscript();
    }
    $elist = $sp->GetElementList();
    // Draw the graph into a file
    $tmpfile = tempnam('var/', 'stgraph');
    $fontpath = dirname($_SERVER['SCRIPT_FILENAME']) . '/ttf/';
    $graph = new CTreegraph($elist, $color, $antialias, $triangles, $fontpath . $font, $fontsize);
    $graph->Save($tmpfile);
    $size = filesize($tmpfile);
    header("Content-Type: application/octet-stream");
    // header( "Content-Type: image/png" );
    header("Content-Disposition: attachment; filename=syntax_tree.png");
    header(sprintf("Content-Length: %ld", $size));
    readfile($tmpfile);
    unlink($tmpfile);
} else {
    printf("Error: Phrase could not be parsed correctly.");
}