Permalink
Browse files

Added kpm support to the exporters

  • Loading branch information...
1 parent 694a270 commit fa669d8f0b91c96876914ac575812b9d8402cb84 vis7mac committed Oct 4, 2012
@@ -5,5 +5,14 @@
"stable": true,
"description": "Export articles from a Posterous blog and import them into Kirby",
"author": "Bastian Allgeier",
- "url": "http://getkirby.com/"
+ "url": "http://getkirby.com/",
+
+ "params": {
+ "blog": "Your Posterous blog",
+ "username": "Your Posterous username (email)",
+ "password": "Your Posterous password",
+ "token": "Your Posterous API token",
+ "template": "The desired name for your content files (for example article.txt)",
+ "dateformat": "Setup the date format to use in content files (default 2012-02-09 16:00)"
+ }
}
@@ -65,16 +65,37 @@
// DON'T TOUCH THE LINES BELOW
// ===========================
-set_time_limit(0);
+// Stuff to run it with kpm
+if(isset($kpm)) {
+ @extract($kpm['options']);
+ $root = $kpm['contentdir'];
+
+ function puterror($error) {
+ kpmerror($error);
+ }
+
+ function putmessage($message) {
+ kpmlog($message);
+ }
+} else {
+ require('kirby/lib/kirby.php');
+ function puterror($error) {
+ dir($error);
+ }
+
+ function putmessage($message) {
+ echo $message;
+ }
+}
-require('kirby/lib/kirby.php');
+set_time_limit(0);
if($username == 'your@email-address.com' && $password == 'yourpassword' && $blog == 'yourblog') {
- die('Please setup the credentials for your Posterous blog. <br />Open <strong>posterous.php</strong> in your favorite editor and follow the instructions.');
+ puterror('Please setup the credentials for your Posterous blog. <br />Open <strong>posterous.php</strong> in your favorite editor and follow the instructions.');
}
-if(!is_dir($root)) die('The blog directory does not exist');
-if(!is_writable($root)) die('The blog directory is not writable');
+if(!is_dir($root)) puterror('The blog directory does not exist');
+if(!is_writable($root)) puterror('The blog directory is not writable');
$posts = array();
$page = 1;
@@ -93,7 +114,7 @@
}
-if(!$posts) die('The posts couldn\'t be found');
+if(!$posts) puterror('The posts couldn\'t be found');
$cnt = count($posts);
$len = str::length($cnt);
@@ -141,14 +162,14 @@
}
-echo 'Exported ' . $n . ' articles to ' . $root . '<br /><br />';
+putmessage('Exported ' . $n . ' articles to ' . $root . '<br /><br />');
if(!empty($errors)) {
- echo count($errors) . ' article(s) could not be imported<br /><br />';
+ putmessage(count($errors) . ' article(s) could not be imported<br /><br />');
}
if(!empty($skipped)) {
- echo 'The following folders have been skipped, because they already existed:' . a::show($skipped, false);
+ putmessage('The following folders have been skipped, because they already existed:' . a::show($skipped, false));
}
// padding zero function
@@ -5,5 +5,13 @@
"stable": true,
"description": "Export articles from a Wordpress blog and import them into Kirby",
"author": "Bastian Allgeier",
- "url": "http://getkirby.com/"
+ "url": "http://getkirby.com/",
+
+ "params": {
+ "blog": "Your Wordpress blog URL",
+ "username": "Your Wordpress username",
+ "password": "Your Wordpress password",
+ "template": "The desired name for your content files (for example article.txt)",
+ "dateformat": "Setup the date format to use in content files (default 2012-02-09 16:00)"
+ }
}
@@ -60,22 +60,49 @@
// DON'T TOUCH THE LINES BELOW
// ===========================
-require('kirby/lib/kirby.php');
+// Stuff to run it with kpm
+if(isset($kpm)) {
+ @extract($kpm['options']);
+ $root = $kpm['contentdir'];
+
+ function puterror($error) {
+ kpmerror($error);
+ }
+
+ function putmessage($message) {
+ kpmlog($message);
+ }
+
+ function putweb() {}
+} else {
+ require('kirby/lib/kirby.php');
+ function puterror($error) {
+ dir($error);
+ }
+
+ function putmessage($message) {
+ echo $message;
+ }
+
+ function putweb($message) {
+ echo $message;
+ }
+}
if($username == 'admin' && $password == 'yourpassword' && $blog == 'http://yourdomain.com/blog') {
- die('Please setup the credentials for your Wordpress blog. <br />Open <strong>wordpress.php</strong> in your favorite editor and follow the instructions.');
+ puterror('Please setup the credentials for your Wordpress blog. <br />Open <strong>wordpress.php</strong> in your favorite editor and follow the instructions.');
}
-if(!is_dir($root)) die('The blog directory does not exist');
-if(!is_writable($root)) die('The blog directory is not writable');
+if(!is_dir($root)) puterror('The blog directory does not exist');
+if(!is_writable($root)) puterror('The blog directory is not writable');
$rpc = new IXR_Client($blog . '/xmlrpc.php');
$status = $rpc->query('metaWeblog.getRecentPosts', 1, $username, $password, 9999);
$posts = array();
$response = $rpc->getResponse();
-if(!$status) die('An error occurred - '.$rpc->getErrorMessage());
-if(empty($response)) die('No articles could be found');
+if(!$status) puterror('An error occurred - '.$rpc->getErrorMessage());
+if(empty($response)) puterror('No articles could be found');
foreach($response as $post) {
@@ -92,7 +119,7 @@
}
-if(empty($posts)) die('No articles have been found');
+if(empty($posts)) puterror('No articles have been found');
function pad($number,$n) {
return str_pad((int) $number,$n,"0",STR_PAD_LEFT);
@@ -140,14 +167,14 @@ function pad($number,$n) {
}
-echo 'Exported ' . $n . ' articles to ' . $root . '<br /><br />';
+putmessage('Exported ' . $n . ' articles to ' . $root . '<br /><br />');
if(!empty($errors)) {
- echo count($errors) . ' article(s) could not be imported<br /><br />';
+ putmessage(count($errors) . ' article(s) could not be imported<br /><br />');
}
if(!empty($skipped)) {
- echo 'The following folders have been skipped, because they already existed:' . a::show($skipped, false);
+ putmessage('The following folders have been skipped, because they already existed:' . a::show($skipped, false));
}
@@ -463,7 +490,7 @@ function serve($data = false) {
global $HTTP_RAW_POST_DATA;
if (!$HTTP_RAW_POST_DATA) {
header( 'Content-Type: text/plain' );
- die('XML-RPC server accepts POST requests only.');
+ puterror('XML-RPC server accepts POST requests only.');
}
$data = &$HTTP_RAW_POST_DATA;
}
@@ -550,7 +577,7 @@ function output($xml) {
header('Content-Length: '.$length);
header('Content-Type: text/xml');
header('Date: '.date('r'));
- echo $xml;
+ putweb($xml);
exit;
}
function hasMethod($method) {
@@ -705,7 +732,7 @@ function query() {
$request .= $xml;
// Now send the request
if ($this->debug) {
- echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n";
+ putweb('<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n");
}
if ($this->timeout) {
$fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout);
@@ -743,7 +770,7 @@ function query() {
}
}
if ($this->debug) {
- echo '<pre class="ixr_response">'.htmlspecialchars($debug_contents)."\n</pre>\n\n";
+ putweb('<pre class="ixr_response">'.htmlspecialchars($debug_contents)."\n</pre>\n\n");
}
// Now parse what we've got back
$this->message = new IXR_Message($contents);

0 comments on commit fa669d8

Please sign in to comment.