blob: 2feff1c855a92cc5d952ad0e5743a74c5622bebc (
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
116
117
118
119
|
<?php
require('config.php');
global $dir;
if (!isset($_POST['filename'])) {
include('header.php');
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>';
include('footer.php');
}
$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'])) {
include('header.php');
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>';
include('footer.php');
} else {
header('Content-type: text/plain; charset=utf-8');
$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.'.';
}
|