I have this silly little website called Linux Stuff, where I post things I learn about Linux that I think might be useful for other people as well.
When a new article is posted I get an email about it, piece of cake using the PHP mail() function.
For some reason (I already forgot why) I now want a new post on this blog whenever a new article on Linux Stuff was added. It turned out to be not so hard.
First I found a file on the internet called remotepost.class.php, and edited that to look like this:
<?php
class remotePost
{
private $client;
private $wpURL = 'http://localhost/grumble/xmlrpc.php ';
private $ixrPath = '../grumble/wp-includes/class-IXR.php';
private $uname = 'newuser';
private $pass = 'newpass';
public $postID;
function __construct($content)
{
if(!is_array($content)) throw new Exception('Invalid Argument');
include $this->ixrPath;
$this->client = new IXR_Client($this->wpURL);
$this->postID = $this->postContent($content);
}
private function postContent($content)
{
$content['description'] = $content['description'];
if(!$this->client->query('metaWeblog.newPost','',$this->uname,$this->pass,$content,true)) throw new Exception($this->client->getErrorMessage());
return $this->client->getResponse();
}
}
?>
I made that file only readable by Apache, just in case, even though this is not a multi-user server. The newuser I created in the wordpress Users panel.
Then in my Linux Stuff PHP on submit I added these few lines of code:
/* Send it to Grumble Grumble too */
$content['title'] = $got_articlename;
$content['categories'] = array('Open Source');
$content['description'] = "New post added to Linux Stuff: $got_articlename.";
try
{
$posted = new remotePost($content);
$pid = $posted->postID;
}
catch(Exception $e)
{
echo $e->getMessage();
}
Piece of cake! Now I can post interesting things either here in wordpress or on Linux Stuff, and LuckyYou can learn about them :)