Connecting your blog server

To post entries to your blog, you first need to obtain an instance of the Services_Blogging_Driver suitable for your blog. You need to either find out which API your blog system supports, or let Services_Blogging magically autodiscover those settings.

Creating a driver is done using Services_Blogging's factory() method. It requires five parameters: The driver name, username, password, server URL and the path of the API on the server.

Instantiating a driver using Services_Blogging::factory()

<?php
require_once 'Services/Blogging.php';
$bl Services_Blogging::factory(
    
'metaWeblog'//driver name
    
'username',
    
'password',
    
'http://blog.example.com',
    
'/xmlrpc.php'
);
?>

Some blog drivers don't need server and path variables, just fill in null in this case.

Autodiscovering settings

Since it can be tedious to find out which settings are needed for your own blog, this package has a feature called autodiscovery. You either can automatically detect the settings needed to create an instance of the driver needed, or let the class automatically detect and return an instance of the driver needed for your blog system.

Autodiscovering the settings of your blog can be done via Services_Blogging's discoverSettings(), passing the URL of your blog as only parameter. It returns an array with all the needed settings.

Most of the blogging softwares today support multiple blogging APIs. After getting a list of supported APIs via autodiscovery, you need to choose which one fits you best; it's usually the one supporting the most features. Services_Blogging also helps you with this task by providing a method called getBestAvailableDriver(), just passing the array of recently discovered settings to it. Now you have all data needed to instantiate the driver itself.

Auto-discovering settings

<?php
require_once 'Services/Blogging.php';

$settings Services_Blogging::discoverSettings('http://blog.example.com');
var_dump($settings);
echo 
Services_Blogging::getBestAvailableDriver($settings) . "\r\n";
//go on with factory()
?>

If that all is still too much work for you, you can let do Services_Blogging everything by calling discoverDriver(), passing the URL of your blog, your username and password to it. It returns a the driver object.

Creating a driver automatically

<?php
require_once 'Services/Blogging.php';

$bl Services_Blogging::discoverDriver(
    
'http://blog.example.com',
    
'username',
    
'password'
);
?>

The autodiscovery methods throw an exception of type Services_Blogging_Exception if something goes wrong (either autodiscovery fails because your blog software does not support it, or there is no suitable driver for your blog).

    Поддержать сайт на родительском проекте КГБ