forked from capnrefsmmat/seuss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
poetry.php
90 lines (83 loc) · 2.91 KB
/
poetry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
$defaultScheme = "aabba";
$defaultBrains = "bbbjj";
$defaultLen = 7;
$defaultLines = 2;
$brainChoices = array('b', 'e', 'c', 'w', 'u', 'j', 'l', 'k', 't', 'k',
'x', 's', 'n', 'f');
if (isset($_POST['rhymescheme']) && isset($_POST['brains']) && isset($_POST['linelen'])
&& isset($_POST['numlines']))
{
foreach(str_split($_POST['brains']) as $brain)
{
if (array_search($brain, $brainChoices, true) === false)
{
die("pick a real brain, buster");
}
}
if (!ctype_alnum($_POST['rhymescheme']))
{
die("pick a real rhymescheme, buster");
}
if (!ctype_digit($_POST['linelen']) || !ctype_digit($_POST['numlines']))
{
die('pick real numbers, buster');
}
if ($_POST['numlines'] > 5)
{
die('dude, do you want to kill my server or something? use less poems!');
}
$output = shell_exec("./rhyme.py " . escapeshellcmd($_POST['brains'] . " " . $_POST['rhymescheme'] . " " . $_POST['linelen'] . " " . $_POST['numlines']));
$poem = nl2br(htmlentities($output));
$defaultScheme = htmlentities($_POST['rhymescheme']);
$defaultBrains = htmlentities($_POST['brains']);
$defaultLen = htmlentities($_POST['linelen']);
$defaultLines = htmlentities($_POST['numlines']);
}
?>
<html>
<head>
<title>Poetry Generator of Doooom</title>
<style type="text/css">
p
{
font-family: verdana, helvetica, sans-serif;
}
</style>
</head>
<body>
<h1>Carnac the Magnificent Poetry Generator</h1>
<h3>Your Poem</h3>
<?php if (isset($poem)) { ?>
<p>
<?php echo $poem; ?>
</p>
<?php } ?>
<div style="float:right">
<h3>Sources</h3>
<ul>
<li>b: Bible</li>
<li>w: Weeping Cock</li>
<li>e: Erotica</li>
<li>n: Henri Bergson</li>
<li>f: Fanny Hill</li>
<li>j: James Joyce</li>
<li>t: Mark Twain</li>
<li>x: Wikipedia on sex</li>
<li>k: Franz Kafka</li>
<li>s: Kamasutra</li>
<li>c: Lewis Carroll</li>
<li>l: Legalese</li>
<li>u: Unabomber manifesto</li>
</ul>
</div>
<h3>Make a Poem</h3>
<form method="post" action="poetry.php">
Rhymescheme: <input type="text" name="rhymescheme" value="<?php echo $defaultScheme ?>" /> <br/>
Brains: <input type="text" name="brains" value="<?php echo $defaultBrains ?>" /> <br/>
Line length (in words): <input type="text" name="linelen" value="<?php echo $defaultLen ?>" /><br/>
Number of poems: <input type="text" name="numlines" value="<?php echo $defaultLines ?>" /><br/>
<input type="submit" value="Poetify!" />
</form>
</body>
</html>