7.24.2007

Zend Framework, Google APIs, Google Reader issue

I've been playing around with the Zend Framework and the Google API. I'm pretty bummed out that there doesn't seem to be any API for Google Reader. I was hoping to use Zend_GData_Query to suck in my starred and/or shared feeds. You can do this using getFeed() but I wanted to include the tags I've put on the entries. But I don't see my tags anywhere in the data, only the original "category terms" if specified by the feed author.

I even tried to do a login authorization with Google using Zend_Gdata_ClientLogin, but the public and private Google Reader URIs threw a hissy fit on me.

7.20.2007

Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

Ran into this error recently... here's how to fix it, assuming you have OpenSSL already installed on your system.  For OpenSSL your PHP config values look like this:

--with-openssl[=DIR]    Include OpenSSL support (requires OpenSSL >= 0.9.6)

So, if you've compiled from scratch, you can just recompile adding this flag to your configure command.

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) 
{ 
  $pos = strpos($class, 'Zend'); 
  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/'; 

$frontendOptions = array( 
  'lifetime' => $cacheTime,                  // in seconds 
  'automatic_serialization' => false  // this is default anyway 
); 

$backendOptions = array('cache_dir' => $cacheDir); 

$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 

    if (count($posts) > 0) 
    { 
      $output .= '
    '; } foreach ($posts as $post) { $output .= '
  • ';
    $output .= $post->getTitle() . '
    ';

    $strTags = ' ( tags: ';
    foreach ($post->getTags() as $tag)
    {
    if ($tag != 'boringguys.com')
    {
    $strTags .= '';
    $strTags .= $tag . '
    | ';
    }
    }
    $strTags = trim($strTags, '| ');
    $output .= $strTags . ' ) ';
    }
    if (count($posts) > 0)
    {
    $output .= '
'; } } catch (Zend_Service_Delicious_Exception $e) { // largely ignore the delicious service error $output .= '
    '; $output .= '
  • del.icio.us service unavailable
  • '; $output .= ''; } echo $output; $cache->end(); // the output is saved and sent to the browser } }

7.17.2007

To PHP5 or not to PHP5

I consider myself an Open Source Developer but I very rarely develop for the open source community. I create apps for businesses, where I work, and some side projects. I share code with those I work with obviously, but generally not with the PHP community as a whole. I share some items on this site that I think are helpful to people.

I'm not sure yet where I stand on the goPHP5 movement. I tend to use PHP5 on my newer development but still have to use PHP4 for legacy stuff. And by "legacy," I'm talking internet time here, so about 4 years is "legacy."

I'd like most of the common PHP apps to move to PHP5. I've got some PHP5 Wordpress plugins in my code repo right now. And heaven knows that Drupal could really use PHP5 (or even the namespace support in PHP6). But I think forcing their hand is a little harsh.

Photo Matt isn't moving Wordpress towards a PHP5 model any time soon. And this is a bummer. But I understand the point of not leaving users of your product in the dust. I don't really have that problem with my code.

As for my opinion, I feel like learning PHP5 was one of the best things I've done in my career. It helped the other object-oriented languages like Java and C# to seep into my head a little bit more. Knowing more then one language is always a good thing.

I love the object model in PHP5, as well as PDO, and the JSON extension is nice. But I find that I use the improved DOM handling of XML in PHP5 the most. It still really shocks me that more people aren't interested in using this. And it still shocks me that more people aren't interested in using XSLT and PHP.

7.05.2007

Create your own Simpson character

I dub thee Rich Zimpson.  It's scary how similar this is to what I really look like.

rich zimpson avatar

Make your own at http://www.simpsonsmovie.com/

7.03.2007

Book Review of Pro Drupal Development by John K. VanDyk and Matt Westgate, published by Apress

Quite often web developers are faced with having to overcome problems quickly and efficiently without having much background in the problem area. Good tools and good documentation are your best friends in a situation like this. Recently, I was tasked with whipping up a website driven by Drupal in only a few days. I had used Drupal once before but this new site required going under the hood of Drupal and I hadn't done that previously. The project required creating some custom Drupal modules for content-types and blocks as the basic pages of the site needed some extra stuff in them besides the normal title, content, and categories. Clicking around the vast Drupal site was a bit of a help on the issue but my savior was the copy of "Pro Drupal Development" by John K. VanDyk and Matt Westgate, published by Apress, that landed on my desk.

The book isn't for Drupal beginners but it doesn't really claim to be either. It's helpful to have a Drupal site or two under your belt as the authors give a quick overview of the Drupal workflow and then they dive right into the guts of building custom modules complete with code examples. Building modules from scratch looked pretty daunting but this book takes you through step-by-step in various scenarios of why and how you'd need to create custom modules, complete with storing additional data in the database, creating admin screens, and utilizing the forms API. Once you go through about half of this book, you'll be able to bend Drupal to your will through the creation of custom code modules.

A few more high points of the book include the great descriptions of nodes and taxonomy which tend to trip up quite a few people using Drupal. Also, the authors show you right away how to uninstall your test modules easily which is a great help. It's this kind of extremely useful tip that pops up every few pages that make this book a MUST HAVE for every serious Drupal developer.

7.02.2007

Drupal for single hierarchy corporate website

We needed a content management system (CMS) for a website at work for 3 reasons:


  • So the developers could be out of the content maintenance loop.
  • So the developers could be out of the content maintenance loop.
  • So the developers could be out of the content maintenance loop.

I remember when I first started web development years ago (gosh, has it been 10 years already?), that the “web guy” was called upon to make every little edit to the website. It could be a typo, a broken link, or an add-on to an existing application. Obviously, some of these things are not like the others. Fixing typos and broken links shouldn’t really be done by the programmers. They’re making too much money to deal with such minor issues. The people in charge of creating that content should be in charge of that stuff (ie, the marketing people).

There are a lot of companies where this is still the norm, the web development folks have to take care of a lot of minor issues like this. My current company was like that. But I’m trying to change the culture there. I’m trying to make the content creators responsible for the content and the programmers responsible for the programming. Enter stage left… use of a CMS for our new website.

After looking at a bunch of open source CMS apps (in PHP if you please) and also a handful of commercial CMS apps, I’ve come to the conclusion that CMS apps suck. ;-) No, really they do. Well, it’s not that they suck, it’s that you are never going to find one CMS that does every single thing that you want it to do. You’re just not. So give up now. I did.

So instead, putting my open source hat on, I tried to find the CMS that looked to be the most extensible or hackable. Drupal won this round hands down. There aren’t a lot of of examples out there about using Drupal for a fairly static corporate website, so I had to create some new modules to do things that I wanted but all in all the coding on the project went very quickly and we launched a successful site. I’ll be posting a few things that we learned along the way about using Drupal in this way in subsequent entries.

But for now, just know that we did keep the developers out of the content maintenance loop. And if you have any specific questions about the process, just holler.