org-mode

Publishing to drupal with org2blog

org2blog is an org-mode plugin which allows to publish an org file to a wordpress blog. The connection between org-mode and wordpress is achived through an xmlrpc call using the metaweblog api.

My blog is powered by drupal which supports xmlrpc calls and the metaweblog api. The setup although was not straightforward. In this post I'm going to show the steps that I followed in order to make it work.

Drupal

First of all in order to enable xmlrpc calls to our drupal blog we need to install the blog api:

root@mazinga:/var/www# drush dl blogapi
Project blogapi (7.x-2.0-rc1) downloaded to /var/www/sites/all/modules/blogapi.                                                                     [success]
Project blogapi contains 4 modules: blogapi_movabletype, blogapi_blogger, blogapi_metaweblog, blogapi.
root@mazinga:/var/www# 

root@mazinga:/var/www# drush en blogapi
The following projects have unmet dependencies:
blogapi requires services
Would you like to download them? (y/n): y
Project services (7.x-3.19) downloaded to /var/www/sites/all/modules/services. [success]
Project services contains 4 modules: services_oauth, rest_server, xmlrpc_server, services.
The following projects have unmet dependencies:
blogapi requires ctools
Would you like to download them? (y/n): y
Project ctools (7.x-1.12) downloaded to /var/www/sites/all/modules/ctools.     [success]
Project ctools contains 10 modules: ctools_ajax_sample, page_manager, views_content, bulk_export, 
ctools_plugin_example, ctools_custom_content, ctools_access_ruleset, term_depth, stylizer, ctools.
file_put_contents(/root/.drush/cache/default/5.4-commandfiles--14588496b4e561311940398d5ea7851d.cache): 
failed to open stream: No such file or                                         [warning]
directory cache.inc:433
The following extensions will be enabled: blogapi, ctools, services
Do you really want to continue? (y/n): y
blogapi was enabled successfully.                                              [ok]
ctools was enabled successfully.                                               [ok]
services was enabled successfully.                                             [ok]
root@mazinga:/var/www#

Then we need to enable some stuff, so we have to log in as user/1 on our site, go to modules section and check:

  • BlogAPI
  • MetaWeblog Provider for BlogAPI
  • Services
  • XMLRPC Server

The services module has to be configured so go to Modules/services/Configure and select Edit Resources. Here we can choose which methods we would like to enable. I selected all the methods.

In Configuration/Web services/BlogAPI enable MetaWeblog as the default provider for xmlrpc APIs.

Configuration in drupal is almost done, the last step is to write down the endpoint of the xmlrpc service. This information is in: Modules/services/Configure/Modify/Path to endpoint

Emacs

We need to install org2blog and enable it, then we define the handle to our blog:

(require 'org2blog-autoloads)
;;; org2blog
(setq org2blog/wp-blog-alist
      '(("my-blog"
         :url "http://www.example.org/blogapi/xmlrpc"
         :default-categories ("linux")
         :tags-as-categories nil
         :id "blog"
         :username "XXXX"
         :password "YYYY" )))

The relevant parts here are:

  • url is composed by site_url plus xmlrpc path end point
  • id is the id our blog, we must specify this option otherwise org2blog defaults to id 1 which is not present in drupal

org2blog uses some wordpress apis which are not compatible with drupal: if we try to connect to our blog we get an error. We have to redefine two functions to bypass those errors:

(eval-after-load "metaweblog"
  '(defun wp-get-tags (blog-xmlrpc user-name password blog-id)
     "Retrieves list of tags from the weblog system. Uses wp.getTags"
     (xml-rpc-method-call blog-xmlrpc
                          "taxonomy_term.index")))

(eval-after-load "metaweblog"
  '(defun wp-get-pagelist (blog-xmlrpc user-name password blog-id)
     (xml-rpc-method-call blog-xmlrpc
                          "node.index")))

That should be all that is needed.

What's next

I have to understand how to upload images (I receive a SQL error when I publish a post with an image inside) and how to attach categories to a post, but I'm pretty satisfied with the actual integration: this post for example is published using org2blog!

Blog: 

Programmazione: 

Subscribe to RSS - org-mode