May 20, 2009

Add Syndication to symfony-driven Blog

If you have a standalone blog powered by symfony framework, and would like to add syndication with major blog services like Blogger or LiveJournal, you could use a PEAR “Services_Blogging” package.


First, you download it and then install following this tutorial.

Extract the archive and put the contents in your symphony's lib/vendor/serviceblogging directory. You will also have to add the XML-RPC PEAR package. Download it, extract, then put XML_RPC_x.x.x folder in the servicesblogging directory (there must be a Services folder there) and rename from “XML_RPC_x.x.x” to “XML


Now, install the package as a symfony plugin. For this, edit the config/ProjectConfiguration.php:

class ProjectConfiguration extends sfProjectConfiguration

static protected $sbLoaded = false;

static public function registerServicesBlogging() {
if (self::$sbLoaded) {

require_once sfConfig::get('sf_lib_dir').'/vendor/servicesblogging/Services/Blogging.php';
self::$sbLoaded = true;

public function setup()


Now in your php code you can do the following to add a new post:

$bl = Services_Blogging::factory(
"username", "password",

$post = $bl->createNewPost();
$post->title = $title;
$post->content = $text;

Disable Auto-formatting

A little something for livejournal users: you can disable auto-formatting if you pass a special parameter to livejournal XML-RPC service. To do this the dirty, way, edit Services/Blogging/Driver/LiveJournal.php file of the Services_Blogging package.

Specifically, in the the Driver.savePost() method, add props parameter to the RPC call value:

$value = new XML_RPC_Value(
'username' => $this->userdata['rpc_user'],
'auth_method' => new XML_RPC_Value('challenge', 'string'),
'auth_challenge' => new XML_RPC_Value(
$authdata['challenge'], 'string'
'auth_response' => new XML_RPC_Value(
$authdata['response'] , 'string'

'subject' => new XML_RPC_Value(
'event' => new XML_RPC_Value(
'lineendings' => new XML_RPC_Value('pc'),

'year' => new XML_RPC_Value(date('Y', $time), 'int'),
'mon' => new XML_RPC_Value(date('n', $time), 'int'),
'day' => new XML_RPC_Value(date('j', $time), 'int'),
'hour' => new XML_RPC_Value(date('G', $time), 'int'),
'min' => new XML_RPC_Value(date('i', $time), 'int'),

'props' => new XML_RPC_Value(
array('opt_preformatted' => new XML_RPC_VALUE(true, 'boolean')),


That's it.

No comments: