How to Post to Drupal using Windows Live Writer

I wrote this series on how to post to Drupal using Windows Live Writer because I saw a lot of questions and issues about this on the Drupal forums. I had previously gone through the trial and error process to set this up for a number of people who work for me. We now use Live Writer for initial posts and quick updates to a large site we manage.

I'd like other developers and Drupal service providers to see they can provide this option for clients and that Drupal communicates and does well with modern and useful web technologies such as blogging APIs.

Configuring Drupal for Posting from External Blogging Applications

An external blogging application like Windows Live Writer will allow you to create and publish posts from your desktop to your Drupal site. But, before you can post via one of these applications you’ll need to enable and configure your Blog API module and a few additional settings.

Step 1: Enable the Modules

Enable your Blog and Blog API modules here: admin/build/modules

Enable the Modules

Step 2: Make Content Types Available to External Clients

Select the content types you’d like to make available to external blogging clients: admin/settings/blogapi

Make Content Types Available to External Clients

Step 3: Create Roles to Post Content via the API

Create the roles you’d like to give external blogging privileges to: admin/user/roles

Create Roles to Post Content via the API

Notice, in the screen shot example, I have created two roles. One called, “blog user” and another called, “jot user”. This will allow me to assign separate permissions for two different content types.  Yes, you are not stuck with just adding blog posts via an external client.

In this example, I’ll allow some users to post jots and other users to post blog entries. I can also give some users permissions to post to either content type.

Step 4: Set Up Your Permissions, Don’t Forget the Blog API Permission

Now assign posting permissions to your roles:admin/user/permissions

Set Up Your Permissions

I have given both the “blog user” role and the “jot user” role permission to administer content with the blog API. Don’t forget this step.

I have given the “blog user” role permissions to:

  1. create blog entries
  2. delete own blog entries
  3. edit own blog entries

I have also given the “blog user” permission to upload files.

permission to upload files

However, I have not given these permissions to the “jot user”.

I want to allow both users to post content via an external blogging application but I want to separate my permissions for posting blog entries and posting jots, so I may assign them separately to various users.

In the node module section of the permissions page I can manage role permissions for my custom content type called, “jot”.

role permissions for my custom content type called jot

role permissions for my custom content type called jot

I have given my “jot user” role permissions to:

  1. create jot content
  2. delete own jot content
  3. edit own jot content

Step 5: Assign Permissions to Users through Roles

Now, let’s give a user permission to post blog entries.

Edit the user’s account:user/<user id>/edit
Where <user id> is the user id number for the specific user you want to edit.

Assign Permissions to Users through Roles 

Check the “blog user” check box under the “Roles” section to assign your user to that role.

To give a user permission to post jots, select the “jot user” check box.

Tip

You can get to a user’s account edit page, by starting from: admin/user/user

View your table of users, sort by username, status, or other dimensions and then click “edit” in the “Operations” column to edit the user’s account.

Success

And that’s it. You have successfully Configured Drupal for posting from external blogging applications.

AttachmentSize
Configuring Drupal for Posting from External Blogging Applications.pdf552.36 KB

Configuring Windows Live Writer to Post to Drupal, Blogs and Custom Content Type

Shows how to add weblog accounts to post to Drupal with the blog content type and a custom content type.

Screencast Summary

Add Weblog Account

Let's begin by adding a new Weblog account from within Windows Live Writer.

From the Weblog button or Weblog menu, choose "add Weblog account".

From the Weblog button or Weblog menu, choose "add Weblog account".

Choose Weblog Type

Next, select the option labeled, “Another Weblog service".

Choose Weblog Type  

Weblog Homepage and Login

In the “Add Weblog Account” dialogue box, enter the user’s Weblog Homepage URL, Username, and Password. For the Weblog Homepage URL, enter the user’s Drupal account URL. For example, http://yourblogurl.com/user/<userid> (replace <userid> with the user’s id number).

Weblog Homepage and Login

Select Provider (Blog API)

Next, Windows Live Writer will try to detect your Weblog settings.

Most likely Windows Live Writer will not automatically detect your Drupal blog settings. Live Writer will then ask you to select a provider, which is simply what Blog API you would like to use. I’ve tested several Blog APIs with Drupal. The Movable Type API seems to work well for my client’s needs. We’ll select this option from the drop down menu.

Now, you will be asked to enter the “Remote posting URL for your Weblog”. This is the URL to your Drupal installation's XML-RPC file. It is usually located in Drupal’s main install directory at: http://yourblogurl.com/xmlrpc.php.

Select Provider (Blog API)

Select Weblog

Note: Windows Live Writer has detected more than one Weblog. The user I am adding has been assigned two roles. One role gives permission to manage a blog. The second role gives permission to post a custom content type called, “jots”. Drupal's Blog API module has been set to allow both content types to be managed remotely. Thus Windows Live Writer has let us know it detected more than one Weblog and asks us to select a Weblog (content type) from the list. Note that both the blog content type and the jot content type are each called a “Weblog” by Windows Live Writer.

If the user had permission to post to only one content type, then just the one content type would be automatically selected by Live Writer.

We’ll select the blog content type.

Select Weblog  

Detecting Blog Theme

Next, Live Writer may ask to detect your blog's theme (style sheets). This would allow you to see what your blog post will look like on-line while you write it in Live Writer. If you click yes and it fails, everything will still function correctly. Even if it does not fail, the display in the editor will most likely NOT look exactly like your post will look on-line.

Weblog Configuration Complete

Upon completion, you should see the message, “Weblog Configuration Complete”. Congratulations, you have successfully configured Windows Live Writer to post to a Drupal powered blog.

Weblog Configuration Complete

Creating a Weblog for a Custom Content Type

Now, let’s create a second Weblog account for the same user to post to our custom “jot” content type.

A second content type appears as a second Weblog account to the end-user.

We’ll repeat the previous process, using the same information as before, since we are adding the same user.

Note: Still using the URL for user 4. Same remote posting URL: http://yourblogurl.com/xmlrpc.php

Again, Live Writer detects more than one Weblog, because our user has permission to post to both, and both were made available in Drupal’s Blog API settings. This time, we add the “jot” content type, so we select the Weblog titled, "Test Blog and Jot User: jot”. The format is, Drupal Username: Drupal Content type.

Notice this time, Live Writer failed to detect the theme settings. This happens usually when a second Weblog account is added for the same user, or when posting to a second content type other than the blog type. If you really want Windows Live Writer’s to display your blog theme in the editor, there is a registry edit you can do in Live Writer to fix this issue. See http://drupal.org/node/221677#comment-755721 . I don’t rely on Windows Live Writer’s display of my theme.

Creating a Weblog for a Custom Content Type

Congratulations

Upon completion, you should see the message, “Weblog Configuration Complete”. Again, Congratulations! We have seen how to successfully configure Windows Live Writer to post to a Drupal powered website with a custom content type.

AttachmentSize
Configuring Windows Live Writer to Post to Drupal, Blogs and Custom Content Type.pdf365.73 KB

Posting to Drupal 6 with Windows Live Writer

Demonstrates using Windows Live Writer to post to a Drupal 6 powered blog. Includes adding a photo, and adding terms to a post.


Screencast Summary

We’ll begin from within Windows Live Writer.

Make sure you have already selected the Weblog account for your Drupal site and for your desired content type. In Windows Live Writer, each content type which Drupal makes available through the Blog API appears as a different Weblog account.

Within the Live Writer editor, begin by entering the title of your post in the section labeled, “Enter Post Title Here”.

Enter Post Title Here

Then use the rest of the text area to enter your body text.

To add a picture to your post click, “Insert Picture” on the Windows Live Writer sidebar at the right side of the application.

You have the option to select an image from your computer or insert a picture from the web.

 In this example, I’ll browse to a photo on my desktop and select it for insert.

In this example, I’ll browse to a photo on my desktop and select it for insert.

Et viola, nous avons une image .

We have an image in our post

Now let’s select some terms for our post.

Click the “Set categories” bar at the bottom of the Live Writer application window.

Select terms for your post

Note: Drupal provides Live Writer with a list of terms available for blog posts.

If you do not see a list of terms available for your content type then check the following:

  1. Confirm your taxonomy settings at /admin/content/taxonomy. You’ll want to make sure your content type is listed as one of the content types to categorize using your vocabulary.
  2. Verify your Blog API module has this patch: http://drupal.org/node/224006

After selecting your terms, you can click back to the editor, and the category selection box will close.

Now let’s post to our blog. Click the “Publish” button on the Live Writer Menu Bar. Again, make sure you are publishing to the correct Weblog account.

Click the “Publish” button on the Live Writer Menu Bar

After posting to Drupal, Windows Live Writer opens a browser window to view the post on the Drupal site.

We have a successful post!

Verify:

We have a successful post!

AttachmentSize
Posting to Drupal 6 with Windows Live Writer.pdf270.59 KB

Modules and Tips Useful for Posting to Your Drupal Site with a Blogging Application

Proper Configuration Checks for External Applications to Use Taxonomy Terms

If you want your users to be able to assign terms to their content when they are using an external blogging application, like Windows Live Writer, make sure you have the Taxonomy module enabled, and that you have selected the appropriate content types, those available to the Blog API. I have forgotten to do this a few times when adding a new content type to use with the Blogging API. Each time a new content type is created, taxonomy requires you to go back and specify whether your new content type can use a vocabulary.

Content types section: admin/content/taxonomy/edit/vocabulary/<vocab id>

Getting Good URL Names by Using Pathauto

If you have Drupal’s Path Module enabled to allow users to rename URLs (custom URLs), I recommend using the “Pathauto” module in combination with your external blogging client. You can set it to give the content a URL based on the post title.

http://drupal.org/project/pathauto

HTML Filter Considerations

Use Case: You want blog users to post content that uses more HTML than the default Filtered HTML input format.

  1. Create an input format allowing your chosen extra HTML tags
  2. Then from the “Input Formats” page at: admin/settings/filters
  3. Click the “configure” link for your new filter in the “Operations” column.
  4. At the URL admin/settings/filters/<filter id> where <filter id> is the filter number, choose which roles may use the extra HTML filter, for example, the “blog user” role.

Now, unless your extra HTML or Full HTML filters are your default filters for your content, which I do not recommend, then when your “blog user” posts from Windows Live Writer, their posts will be submitted and displayed with the default “Filtered” HTML Input format (with no pictures or other html elements).

To overcome this issue, I recommend the Preferred Format module

http://drupal.org/project/preferred_format

Once enabled and configured you’ll see a new permission at: admin/user/permissions titled, “can set preferred format”. 

Select which roles can choose their preferred (default) input format.

Note: The user will also have to be in a user group which is allowed to user other input formats than the default Filtered HTML format.

If you want to set the preferred default format for a user go back to the user’s edit screen at: user/<user id>/edit

You’ll see a new section titled, “Preferred Input Formats”. In this section, assign the default input format for each content type.

Preferred Input Formats

Note in the example screen shot I have selected the Full HTML option as the preferred input format for blog entries. Now, even when the post is via Live Writer, the post will display in full html.

Note, some external blog editors like “Ecto” allow you to set the input format within their software.

Free Tagging from Windows Live Writer to Drupal

Allowing Tags to be Added in the Post Body Text

Free Tagging when the Blog API Does Not Support It

The following is a quick code sample showing the start of a Drupal module which lets a user add new tags to a post by placing the tags in the body of the post in a format like so:

[tags]blog, blog api, blogging, Drupal 6, weblog, windows live writer, wlw[/tags]

Jump to the Source Code

Use Case

I’m only using code like this for one use case.  It’s for clients who do a lot of editing and posting of their Drupal content through Windows Live Writer.

With Windows Live Writer and Drupal, my clients use the “Movable Type API”.  Without extending the API, it does not yet support adding new vocabulary terms.  Thus, from Windows Live Writer to Drupal sites, one can only tag content with existing terms.  This code allows new tags to be added.

The terms are added to a specified vocabulary id and associated with the new or updated content node.

The inline tags are removed from the body of the text before insert or update.

Inline Tags Sample Module Code

<?php
/**
 * Module implementing Drupal's hook_nodeapi
 * @see http://api.drupal.org/api/function/hook_nodeapi/6
 * Important Note: This is sample code.  You'll need to modify this code to just use the inline tags on your choice of content types
 * and to check if the user has permission to use inline tags
 */
function inlinetags_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'submit':
      break;
      //before stuff makes it into the database (before update or insert)
    case 'presave':
      //parse out any inline tags within body
      $bd = _parseinlinetags( $node->body );
      //parse out any inline tags that may have made it into the teaser
      $ts = _parseinlinetags( $node->teaser );
      //replace the body with a version that has removed the inline tags code
      $node->body = $bd[0];
      //replace the teaser with a version that has removed the inline tags code
      $node->teaser = $ts[0];
      //if there were any preexisting tags then add them to the tag string
      if ($bd[1] !=''){
        //note my tags vocabulary id is just hard coded here
        $vid = 1;
        $tagstring = $bd[1];
        //if there were pre-existing tags, add them to the tag string
        if ($node->taxonomy['tags'][1]!='') {
          //prepend the new tags to any old ones
          $tagstring .= ','.$node->taxonomy['tags'][1];
        }
        //now add them to the tags vocab for the insert or update operation
        $node->taxonomy['tags'] = array($vid => $tagstring);
      }
      break;
    case 'insert':
    case 'update':
      break;
    case 'view':
      break;
  }
}
/**
 * A private function to parse out placeholder tags
 * This version has been stripped to parse out just placeholders with a format like:
 *
 *
 * @param string $page_contents
 * @return array an array with $return[0] the tags parsed out and $return[1] as a string with the tags
 */
function _parseinlinetags( $page_contents )
{
  $matches = explode( '' ) );
    $pageplaceholder = str_replace( '[/tags]', '', $placeholder );
  }
  $search = '';
  $page_contents = str_replace ( $search, '', $page_contents );
   
  $return[] = $page_contents;
  $return[] = $pageplaceholder;
  return $return;
}
?>