From f24e77857c4af0c53ac4c7db7e671c3fbf9dc67b Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 28 Aug 2011 23:12:10 -0400 Subject: 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 --- make-post.php | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 make-post.php (limited to 'make-post.php') 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 @@ +'; + echo ''; + echo ''; + echo ''; + 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 '
'; + echo ''; + echo ''; + $i = 0; + foreach ($reporters as $name => $quotes) { + if (count($quotes)>1) { + echo '
'; + echo ''.$name.''; + echo '
    '; + + foreach ($quotes as $key => $quote) { + echo '
  • '; + echo ''; + echo "'; + echo '
  • '; + } + } else { + foreach ($quotes as $key => $quote) { + echo ''; + break; + } + } + echo '
'; + echo '
'; + } + echo ''; + echo '
'; +} 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\n"; + $reporter_names = array(); + foreach ($quotes as $quote) { + $reporter_names[] = $quote['reporter']; + echo "
"; + echo $quote['text']; + echo "
\n"; + } + $last_reporter = array_pop($reporter_names); + echo "\nQuotes gathered by ".(count($reporter_names)>0?implode(', ', $reporter_names).' and ':'').$last_reporter.'.'; +} -- cgit v1.2.3