diff options
Diffstat (limited to 'make-post.php')
-rw-r--r-- | make-post.php | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/make-post.php b/make-post.php new file mode 100644 index 0000000..200f853 --- /dev/null +++ b/make-post.php @@ -0,0 +1,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.'.'; +} |