summaryrefslogtreecommitdiff
path: root/make-post.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-08-28 23:12:10 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-08-28 23:12:10 -0400
commitf24e77857c4af0c53ac4c7db7e671c3fbf9dc67b (patch)
tree4e3f0fe3f6d0c2ab7492a06b82918d879eb7b70c /make-post.php
A neat little weekend (well, two Fridays and a Sunday) project to 1) generate org-mode files from copy/pasted data from MS-word 2) generate Wordpress posts from such org-mode files
Diffstat (limited to 'make-post.php')
-rw-r--r--make-post.php115
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>&mdash; <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>&mdash; <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.'.';
+}