Archive for November, 2006

PHP Interface to the W3 HTML Validator

November 28th, 2006

Last night a co-worker mentioned the W3’s new API for their HTML Validator, which sounded pretty handy.

I searched around on the Internet and found a few people who had scratched some things together to read the SOAP 1.2 response data, but nothing object oriented and re-usable the way I would need it to be. So I went ahead and coded up a simple PEAR Package which will connect to the W3’s validator and check if a given URI is valid.

In our office we have talked about developing a tool that would automatically crawl a site to do simple blind validation, and this tool will be a starting point for that system.

Today I proposed the package to pear.php.net, and plan on continuing development if not on pear.php.net at least on my own channel pear.saltybeagle.com.

Wish me luck… this is my first pepr proposal in about 2 years… and a PEAR package which might actually be worthwhile for others.

Check out my proposal for Services_W3C_HTMLValidator.

Output Controllers — What are they? [Updated]

November 28th, 2006

2006-11-09 23:38:02
In many web applications you need to send the same data in various different formats. Some examples we run into every day are web pages that offer a RSS feed, or a calendar that supports an iCalendar export. Many recent web services provide API’s in various formats such as JSON, PHP serialized objects, XML etc etc.
In each of these cases, the data remains the same – only the output format has changed. This presents a programming challenge to maintain the data’s independence from the output format. In modern programming the technique is commonly referred to as MVC: model, view, controller. The model represents the data we have, the view an output format or view of the data, and the controller which handles much of the logic between the data and the view.

This is where an output controller can help programmers keep their views separate from their models, but bridge the two together when necessary.

When I refer to an output controller, I’m referring to a tool or system of tools that understand how to connect data with views or output; a bridge between the two independent portions of the MVC paradigm.

Why are Output Controllers important?

For programmers, having a well defined output controller can speed up development by providing a naming scheme, or systematic way to organize your models and your views so that both can be easily connected and easy to understand. The output controller can also offer very important functionality for a web application. This bridge can offer important features for every view such as data caching or pre-compiled templates to improve performance.
On the other hand, having a poorly constructed output controller can prevent rapid application development and lead to intermixed models and views.

The first step to following the MVC paradigm is utilizing a template system for building all of the views of your data. Many templating systems exist for web languages, a couple well known systems would be Smarty and Savant.

Continued on Nov 28th, 2006.

This problem led me to developing an output controller for Savant. The
Savant template system is similar to many other template engines in
that you have to populate an object or template before it is sent to
the client. While not a very time consuming process, this is very
repetetive when you have to set a title for the html template, the rss
template, the iCalendar template etc etc.

To facilitate the need to populate every template with the same common information I use public member variables for my classes which correspond to the fields used in the template. This makes linking the two portions together very easy.

I now create every model completely independent of the view it will be
rendered in, but utilize public member variables for every field of
data each template will need.

A class to model a web page might be something like this:

class WebPage
{
   public $title;
   public $content;
}

Now lets examine two templates we would want to build, html and rss:

<html>
<title><?php echo $this->title; ?></title>
<body><?php echo $this->content; ?></body>
</html>
<rss>
   <channel>
       <title><?php echo $this->title; ?></title>
       <description><?php echo $this->content; ?></description>
   </channel>
</rss>

Now to output the object with the HTML template, normally one would create an instance of the template and populate variables within the template prior to output like this:

...
$template =& new Savant3();
$template->title = $webpage->title;
$template->content = $webpage->content;
$template->display('WebPage.tpl.php');
...

Fairly quick with only two member variables but when objects get larger this is a time consuming step. Instead of using this, with the output controller you can simply say:

...
Salty_Savant_OutputControl::displayRegion($webpage);
...

This automatically populates the WebPage.tpl.php template file with all the public member variables and displays the template. Very simple.

Likewise, to send the output using the WebPage_RSS.tpl.php template file:

...
Salty_Savant_OutputControl::outputTemplate('WebPage','WebPage_RSS');
Salty_Savant_OutputControl::displayRegion($webpage);
...

Jump in to an output controller Salty_Savant_OutputControl

New Calendar Releases

November 9th, 2006

New releases are out for the UNL Event Publisher.

This release has some cool features Alvin Woon added in to the frontend — AJAX next & previous day buttons, as well as month widget navigation, which all gracefully degrade when users don’t have javascript.

Also some bug fixes thanks to the bug reports we’re receiving from some end users (thanks Adam).

The calendar is shaping up nicely, and the frontend is basically out of beta. There are a few features I’d like to implement after seeing a few other university calendar systems out there, but the feature set is improving and fewer and fewer bug reports are coming in.

Pick up the new releases at http://pear.unl.edu/:
UNL_UCBCN
UNL_UCBCN_Frontend
UNL_UCBCN_Manager

Scripting Releases to Chiara_PEAR_Server

November 6th, 2006

I’ve been working on some ways to automate release deployment to my PEAR Channel Servers (pear.unl.edu, pear.saltybeagle.com) running Chiara_PEAR_Server.
Right now I have scripts that automatically create the package.xml file using PFM2 and the package tgz files but uploading the release was still a manual process.
The process isn’t that complicated, you log in to the channel server, and upload a file…. the server handles the rest (haha, so punny).

So finally I got friendly with HTTP_Request and wrote a simple class/script to remotely release a pear package to a Chiara_PEAR_Server.

Now it’s even easier to release early, release often.

<?php
/**
 * sample usage of the Salty_PEAR_Server_RemoteReleaseDeployer
 */

require_once 'Salty/PEAR/Server/RemoteReleaseDeployer.php';

$d = new Salty_PEAR_Server_RemoteReleaseDeployer();

$d->adminuri = 'http://pear.saltybeagle.com/admin.php';
$d->username = 'adminhandle';
$d->password = '1234';

if ($d->deployRelease('/home/bbieber/workspace/Salty_PEAR_Server_RemoteReleaseDeployer/Salty_PEAR_Server_RemoteReleaseDeployer-0.0.1.tgz')) {
    echo 'Success!';
} else {
    echo 'Something went terribly wrong.';
}

So what the heck, I made it into a PEAR package.

Salty_PEAR_Server_RemoteReleaseDeployer

Hooray for PEAR Channels!

Things to check out, when the Ruby on Rails site comes back up.

November 6th, 2006

I wanted to read up on Capistrano, but the RoR website was down today.

Capistrano was referenced in Matthew Weier O’Phinney’s “PHP Development Best Practices” for open source application deployment tools.

The slides from his talk offer a good broad stroke introduction to best practices for application development – not too many things applicable only to PHP, most could be applied to software development in general.

The slides are an OK read, but a podcast would be excellent.

Boomschwacky

November 3rd, 2006

Boomschwacky, the new word is synonymous with widget.