blob: 200f853eb5225e6de1a9416f3e4719f882d78a41 (
plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
<?php
header('Content-type: text/html; charset=utf-8');
$dir = '/home/luke/j1-uploads';
if (!isset($_POST['filename'])) {
echo '<form method="post" action="make-post.php">';
echo '<ul>';
if ($handle = opendir($dir)) {
$id=0;
while (false !== ($file = readdir($handle))) {
$filename = htmlentities(rawurldecode($file));
echo '<li>';
echo "<input type='radio' name='filename' value='$file' id='$id' />";
echo "<label for='$id'>$filename</label>";
echo '</li>';
$id++;
}
}
echo '</ul>';
echo '<input type="submit" value="submit" />';
echo '</form>';
exit();
}
$filename = $dir.'/'.rawurlencode($_POST['filename']);
$lines = explode("\n", file_get_contents($filename));
$reporters = array();
$reporter = '';
$cite = '';
foreach ($lines as $line) {
preg_match('/^(\**) +(.*)/', $line, $matches);
$base = $matches[1];
$content = $matches[2];
switch ($base) {
case '*': break;
case '**':
$reporter = $content;
$reporters[$reporter] = array();
break;
case '***':
$cite = $content;
break;
case '':
$reporters[$reporter][] =
array('cite'=>$cite,
'text'=>$content);
break;
}
}
if (!isset($_POST['q'])) {
echo '<form method="post" action="make-post.php">';
echo '<input type="hidden" name="filename" value="'.htmlentities($_POST['filename']).'" />';
echo '<textarea name="open"></textarea>';
$i = 0;
foreach ($reporters as $name => $quotes) {
if (count($quotes)>1) {
echo '<fieldset>';
echo '<legend>'.$name.'</legend>';
echo '<ul>';
foreach ($quotes as $key => $quote) {
echo '<li>';
echo '<input '.
'type="radio" '.
"name='q[$name]' ".
"value='$key' ".
"id='id$i' ".
'/>';
echo "<label for='id$i'>";
echo "<blockquote>";
echo $quote['text'];
echo "<footer>— <cite>".$quote['cite']."</cite></footer></blockquote>";
echo '</label>';
echo '</li>';
}
} else {
foreach ($quotes as $key => $quote) {
echo '<input '.
'type="hidden" '.
"name='q[$name]' ".
"value='$key' ".
'/>';
break;
}
}
echo '</ul>';
echo '</fieldset>';
}
echo '<input type="submit" value="submit" />';
echo '</form>';
} else {
$quotes = array();
foreach ($_POST['q'] as $reporter => $quote_id) {
$quote = $reporters[$reporter][$quote_id];
$quote['reporter'] = $reporter;
$quotes[] = $quote;
}
echo htmlentities($_POST['open']);
echo "\n<!--more-->\n";
$reporter_names = array();
foreach ($quotes as $quote) {
$reporter_names[] = $quote['reporter'];
echo "<blockquote>";
echo $quote['text'];
echo "<footer>— <cite>".$quote['cite']."</cite></footer></blockquote>\n";
}
$last_reporter = array_pop($reporter_names);
echo "\nQuotes gathered by ".(count($reporter_names)>0?implode(', ', $reporter_names).' and ':'').$last_reporter.'.';
}
|