{"id":284,"date":"2011-12-23T07:40:04","date_gmt":"2011-12-23T12:40:04","guid":{"rendered":"http:\/\/littlesvr.ca\/grumble\/?p=284"},"modified":"2012-12-05T00:48:34","modified_gmt":"2012-12-05T05:48:34","slug":"linux-stuff-notifications-on-this-wordpress-blog","status":"publish","type":"post","link":"http:\/\/littlesvr.ca\/grumble\/2011\/12\/23\/linux-stuff-notifications-on-this-wordpress-blog\/","title":{"rendered":"Linux Stuff notifications on this wordpress blog"},"content":{"rendered":"<p>I have this silly little website called <a href=\"http:\/\/littlesvr.ca\/linux-stuff\/\">Linux Stuff<\/a>, where I post things I learn about Linux that I think might be useful for other people as well.<\/p>\n<p>When a new article is posted I get an email about it, piece of cake using the PHP mail() function.<\/p>\n<p>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.<\/p>\n<p>First I found a file on the internet called remotepost.class.php, and edited that to look like this:<\/p>\n<blockquote>\n<pre>&lt;?php\r\nclass remotePost\r\n{\r\n  private $client;\r\n  private $wpURL = 'http:\/\/localhost\/grumble\/xmlrpc.php ';\r\n  private $ixrPath = '..\/grumble\/wp-includes\/class-IXR.php';\r\n  private $uname = 'newuser';\r\n  private $pass = 'newpass';\r\n  public $postID;\r\n  function __construct($content)\r\n  {\r\n    if(!is_array($content)) throw new Exception('Invalid Argument');\r\n    include $this-&gt;ixrPath;\r\n    $this-&gt;client = new IXR_Client($this-&gt;wpURL);\r\n\r\n    $this-&gt;postID = $this-&gt;postContent($content);\r\n  }\r\n  private function postContent($content)\r\n  {\r\n    $content['description'] =  $content['description'];\r\n    if(!$this-&gt;client-&gt;query('metaWeblog.newPost','',$this-&gt;uname,$this-&gt;pass,$content,true)) throw new Exception($this-&gt;client-&gt;getErrorMessage());\r\n    return $this-&gt;client-&gt;getResponse();\r\n  }\r\n}\r\n?&gt;<\/pre>\n<\/blockquote>\n<p>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.<\/p>\n<p>Then in my Linux Stuff PHP on submit I added these few lines of code:<\/p>\n<blockquote>\n<pre>    \/* Send it to Grumble Grumble too *\/\r\n    $content['title'] = $got_articlename;\r\n    $content['categories'] = array('Open Source');\r\n    $content['description'] = \"New post added to Linux Stuff: <a href=\"http:\/\/littlesvr.ca\/linux-stuff\/articles\/$got_filename\/$got_filename.php\">$got_articlename<\/a>.\";\r\n    try\r\n    {\r\n      $posted = new remotePost($content);\r\n      $pid = $posted-&gt;postID;\r\n    }\r\n    catch(Exception $e)\r\n    {\r\n      echo $e-&gt;getMessage();\r\n    }<\/pre>\n<\/blockquote>\n<p>Piece of cake! Now I can post interesting things either here in wordpress or on Linux Stuff, and LuckyYou can learn about them :)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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) &hellip; <\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-andrew","4":"post-284","6":"format-standard","7":"category-opensource","8":"category-safeforseneca"},"_links":{"self":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/comments?post=284"}],"version-history":[{"count":10,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/284\/revisions"}],"predecessor-version":[{"id":574,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/posts\/284\/revisions\/574"}],"wp:attachment":[{"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/media?parent=284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/categories?post=284"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/littlesvr.ca\/grumble\/wp-json\/wp\/v2\/tags?post=284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}