Esempio n. 1
1
require_once 'toolbox.php';
removeMagicQuotes($_POST);
removeMagicQuotes($_GET);
$commands = isset($_POST['commands']) ? $_POST['commands'] : '';
if (!$commands) {
    $example = isset($_GET['example']) ? $_GET['example'] : 'complex';
    $example = filter_var($example, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
    $filename = "examples/{$example}.logo";
    if (file_exists($filename)) {
        $commands = file_get_contents($filename);
    }
}
$error = false;
try {
    $turtle = new Turtle($commands);
} catch (Exception $e) {
    $error = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Simple Turtle Graphics Parser (written in PHP)</title>
        <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.4.1/build/reset-fonts-grids/reset-fonts-grids.css">
        <style type="text/css">
        html {
            font-family: Arial, sans-serif;
            background: #101010;
            color: #cfcfcf;
        }
Esempio n. 2
0
<?php

require_once 'toolbox.php';
removeMagicQuotes($_GET);
$turtle = new Turtle($_GET['commands'], 350, 350);
$maxFilenameLength = 20;
$filename = str_replace(array(' ', ':', '"', '?'), array('-', 'c', 'q', 'p'), $_GET['commands']);
if (strlen($filename) > $maxFilenameLength) {
    $filenameMd5 = md5($filename);
    $filename = substr($filename, 0, $maxFilenameLength) . '_' . $filenameMd5;
}
header("Content-Disposition: Attachment;filename={$filename}.png");
header('Content-Type: image/png');
echo $turtle->getImage();
Esempio n. 3
0
 /**
  * @dataProvider validMultiLineCommandsProvider
  **/
 public function testCommandsAreNormalisedToASingleLine($input, $expected)
 {
     $turtle = new Turtle($input);
     $this->assertFalse(strpos("\n", $turtle->getNormalisedTokens()), 'Normalised string should not contain any newlines.');
 }