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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ upload-msword.php | 31 +++++++++++++++ upload-org.php | 18 +++++++++ word2org.sh | 32 +++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 make-post.php create mode 100644 upload-msword.php create mode 100644 upload-org.php create mode 100755 word2org.sh 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 "
".$quote['cite']."
\n"; + } + $last_reporter = array_pop($reporter_names); + echo "\nQuotes gathered by ".(count($reporter_names)>0?implode(', ', $reporter_names).' and ':'').$last_reporter.'.'; +} diff --git a/upload-msword.php b/upload-msword.php new file mode 100644 index 0000000..b234381 --- /dev/null +++ b/upload-msword.php @@ -0,0 +1,31 @@ +&1 > '$filename'"; + echo '
'.htmlentities($cmd).'
'; + echo '
';
+	system($cmd, $status);
+	echo '
'; + unlink($tmp); + if ($status != 0) { + unlink($filename); + echo '

error

'; + } +} else { + ?> +
+ + + +
+ +
+ + +
+ >/dev/stderr + exit 1;; + esac +done -- cgit v1.1-4-g5e80