Alpha Wordpress Plugin for Delicious with Zend Framework’s Zend_Service_Delicious
I have Wordpress set up on PHP5. While Wordpress is largely a PHP4 entity, I wanted to see if it could play nicely with the Zend Framework, which is a PHP5-only entity. With some careful fiddling, it works pretty well.
With my Zend Framework code set up in my PHP include path, the first thing I needed to do to create a Wordpress Plugin was to enable my plugin to call the Zend Framework classes. First I tried this towards the end of my wp-config.php file:
-
require_once 'Zend/Loader.php';
-
function __autoload($class)
-
{
-
Zend_Loader::loadClass($class);
-
}
This caused Wordpress to freak out like a chihuahua on speed. Not good. I figured we'd have to do something special because we don't want ALL the classes to autoload, just the Zend ones. So I scrapped my previous __autoload and tried this instead:
-
require_once 'Zend/Loader.php';
-
function __autoload($class)
-
{
-
if ($pos !== false)
-
{
-
Zend_Loader::loadClass($class);
-
}
-
}
Ahh, success. Sweeter then a brownie sundae with extra chocolate sauce.
From there, the rest is easy. Here's some basic code for the rz_delicious plugin, a basic PHP file you can drop into your Wordpress Plugins dir. It uses Zend_Cache and Zend_Service_Delicious to put your del.icio.us bookmarks onto your Wordpress blog. It first checks to see if there's a cached version already, if not, it uses the del.icio.us API to fetch your latest bookmarks. It does some list formatting there too because I didn't feel like handling that in my theme.
-
<?php
-
/*
-
Plugin Name: RZ Delicious
-
Plugin URI: http://www.boringuys.com/
-
Description: YADelicious Plugin
-
Author: Rich Zygler
-
Version: 1.0
-
Author URI: http://www.boringguys.com/
-
*/
-
-
/*
-
called from theme via:
-
get_rz_delicious()
-
*/
-
-
function get_rz_delicious()
-
{
-
$output = '';
-
$username = 'username';
-
$password = 'password';
-
$tag = 'tagname';
-
$numPosts = 15;
-
$cacheTime = 3600; // seconds
-
$cacheDir = '/tmp/';
-
-
'lifetime' => $cacheTime, // in seconds
-
'automatic_serialization' => false // this is default anyway
-
);
-
-
-
$cache = Zend_Cache::factory('Output', 'File', $frontendOptions, $backendOptions);
-
-
// we pass a unique identifier to the start() method
-
if(!$cache->start('rz_delicious'))
-
{
-
try
-
{
-
$delicious = new Zend_Service_Delicious($username, $password);
-
$posts = $delicious->getRecentPosts($tag,$numPosts); //$tag
-
-
{
-
$output .= '<ul id="delicious">';
-
}
-
foreach ($posts as $post)
-
{
-
$output .= '<li><a href="' . $post->getUrl() . '" title="' . $post->getNotes() . '">';
-
$output .= $post->getTitle() . '</a> ';
-
-
$strTags = '<br />( tags: ';
-
foreach ($post->getTags() as $tag)
-
{
-
if ($tag != 'boringguys.com')
-
{
-
$strTags .= '<a href="http://del.icio.us/' . $username . '/' . $tag . '" title="' . $tag . '">';
-
$strTags .= $tag . '</a> | ';
-
}
-
}
-
$output .= $strTags . ' )</li>';
-
-
}
-
{
-
$output .= '</ul>';
-
}
-
}
-
catch (Zend_Service_Delicious_Exception $e)
-
{
-
// largely ignore the delicious service error
-
$output .= '<ul id="delicious">';
-
$output .= '<li>del.icio.us service unavailable</li>';
-
$output .= '';
-
}
-
echo $output;
-
$cache->end(); // the output is saved and sent to the browser
-
}
-
-
}
-
-
-
?>
Share this via del.icio.us, digg, email, etc.
Trackback for "Alpha Wordpress Plugin for Delicious with Zend Framework’s Zend_Service_Delicious"
1 Trackback(s)