fogbound.net




Thu, 3 Mar 2005

Feedback Form Module, Newbie Software Engineering

— SjG @ 12:12 am

So I’ve just finished version 0.4 of a module for handling user feedback for CMS Made Simple. It allows users with administrator rights to create reasonably complex forms, with all the user interface objects that we’ve come to expect, and handle the submission of those forms in a variety of ways.

It’s been an interesting experience. Version 0.1 was your standard naive PHP implementation of an application within a framework. It was all one big script in one big file. It would do fairly simple database queries, stuff all the results into a big array, and then process array elements with big switch statements when it needed to customize output based upon UI object type.

Version 0.2 ported this basic functionality into an Object Oriented model. I found that there were a couple of complex decisions to make — should I handle the database storage and retrieval in an OO manner? And if I query a bunch of Input Objects from the database, how do I know what specific kind of object to instantiate since that data is contained in the database record? I guess the truly OO approach would be to use an OO database, or, next best approach, to have a separate table in the database for each kind of input object. But that’s not how I did it, probably to the detriment of my code (I instantiate a superclass object, then use the type details from the general object to create a new object which is the correct specific class.)

Still, this showed how a procedural approach could save a lot of database activity over an OO approach. The data model comprises forms, which contain one or more fields, which have one or more options. In the procedural approach, I denormalize the database so that fields contain the form id, and field options contain both the field id and the form id. I could then grab everything I needed for a form in three queries. With the OO model, the number of queries is proportional to the number of fields. What’s more, there’s been a massive proliferation in the number of files required. While I worry about the web server having to load and parse all that stuff each time, I should probably have more faith in the PHP engine and the OS caching. As a number of people have said to me, I’m not playing on a TRS-80 with 4k RAM anymore. But I still feel like I should be programming as if resources were seriously limited.

Similarly, when it came time (for version 0.4) to add localization of the code, it required some somewhat unpleasant contortions: each Input object needs to have access to a global collection of text strings (stored in a big hash) so they can present localized versions of messages. And I still need to go in and make sure that I’m actually handing around references rather than the copies that PHP likes to pass.

Maybe this is just the yammerings of someone who should understand software design better. Clearly, there were some bad decisions made in the code, although I could argue about how bad they really are.

Another aspect that took me by surprise was how I could test code and have it perform perfectly, while other users reported errors and bugs immediately. In this case, the main culprit was not inattentiveness (in testing, anyway), but my PHP configuration. If you allow output buffering, PHP gracefully handles output before the headers have been sent. Not so, if output buffering is disabled. So when my code would generate errors, my test configuration would blithely allow error codes to be output but then clobber that output with the expected page output. So while I thought output buffering was only involved in performance, it seems that for development, it should be disabled. That way, those bugs cannot be so easily overlooked.

Filed in:

Tue, 22 Feb 2005

Why Tritton NAS sucks

— SjG @ 5:15 pm

Gonna buy a Network Storage Device?

Here’s my recommendation: avoid Tritton’s NAS at pretty much all costs.

The device is flaky at best, even with the latest firmware. Samba-mounted connections don’t always get properly updated when there are filesystem changes. User permission settings seem to work based on the values you enter … but only when the moons of Jupiter are aligned.

Some people claim that they’ve been able to get the NFS implementation to work; I have failed from both Mac OS and from Linux. I don’t claim to be an NFS wizard, but I’ve been able to get it to work with many an operating system in the past. No dice here.

Tritton’s tech support is useless (but does contain priceless FAQs like “You may notice that folders begin to reproduce, disappear, or rename themselves on the storage device. This may also result in data loss that is unrecoverable,” with the solution to upgrade the firmware).

The device is only configurable through a web interface, which would be OK if they didn’t use a lot of un-necessary proprietary crap that prevents it from working with anything other than IE 5 or 6 on a Windows PC. Got a network with only Macs and Unix machines? Sorry, you’re just out of luck.

To make matters worse, they’re violating the GPL, and not releasing the source to their kernel modifications. So even if you want to fix the problems yourself, you can’t.

Getting a Snap appliance is certainly more expensive than a Tritton. But at least it’ll support RAID (and you should use raid. Really. Trust the sad voice of experience.). And Snap appliances actually work as advertised.


Sat, 19 Feb 2005

Content Management

— SjG @ 6:56 pm

Content Management. Seems like that’s what everyone wants for their web sites these days, and it’s no wonder. You can keep your site up to date. You can change things in response to your users, your boss, or that fellow with all the crazy ideas over in marketing. You can change things according to the season, or according to your mood. And lastly, at least in theory, you don’t get “locked in” to a specific vendor for maintenance.

So Content Management’s a good thing. But people mean different things when they use these words.

  • If you’re a gamer and want a portal site for your gaming group, you mean one thing: a place where you can post news and images, list members, hook in a discussion board, and maybe post game rankings; this is also probably what you want if you have a web site for your cooking club, your neighborhood, or perhaps your local political organization.
  • In the other extreme, you’ll mean something else entirely. If you’re, say, the marketing director for a publicly-traded company, you want each department head to be able to edit the section of the company web site that pertains to their work, but you want work-flow management so that the marketing and legal departments can have final say on what goes live. You’d probably like revision control, fine-grained access control (who gets to upload or edit what, and who can reject or approve it), and other similar features. You may well want the site to be able to get content from other back-end business systems.
  • Then there’s the middle ground, which includes some of the features from each of the former. If you run a small agency, you’ll want to be able to post comps and scripts to your clients, you want to update your awards page each time you win something, and you probably want to put those award-winning ads online for people to view. You might want some access control, but you don’t need revision control or interfacing with back-end systems.

For the first case, the community site, there are dozens of PHP-based Open Source solutions. There’s PHP-Nuke, Post-Nuke, Drupal, Mambo, Xoops, Typo3, Xaraya, and countless others. All of them are well adapted for this specific niche, and most of them are pretty horrible if you want to extend them or use in a way that’s not part of the original design. Call me an elitist, but the bar to entry here is very low; there are a lot of programmers who don’t know what they’re doing, and they’re doing it very publicly. There’s a strong emphasis on cool and futuristic visuals, and something of a shortage of solid architecture. Few of them create HTML that will validate, and even fewer make proper use of cascading style sheets (CSS). Fortunately, you can road test them all at OpenSourceCMS.com, and see if any work for you.

For the second case, the corporate solution, there are a multitude of commercial packages which vary in price from the low 5-figures on up to as far as you want to go. We use Enonic VerticalSite for this kind of corporate site. It’s Java/EJB based, and uses widely-accepted standards like LDAP, XML, and XSLT, so it can integrate into a vast array of other back-end systems. XSLT allows the developer total freedom in the templating so, page sizes can be reduced through the use of CSS. It’s a solid solution, and affordable for its class.

I’m pleased to say that there is finally a reasonable contender for the last case, the middle option. In the past, we’d tried to adapt projects from the PHP Portal group to serve in this capacity, and, frankly it was not a very good experience. Now, however, there is CMS Made Simple. It’s a straightforward framework, that provides a developer with a lot of basic functionality: group-based permission system, hierarchical content management, and support for XHTML templates and CSS. But what’s best about CMSMS is that it’s a lightweight framework that doesn’t come with a lot of unnecessary extras, yet it supports an object-oriented API for adding modules, so you can add in any functions you find lacking.

I’ve been madly developing menuing systems and a flexible Feedback Form submission system for CMSMS (you can find ’em on the Project Wiki). The new API seems pretty solid, and it’s certainly easy to develop for. I’ve found the developers to be personable, helpful, and very positive when I’ve communicated with them on IRC.

My next project, which I plan to implement using CMSMS, is a portfolio tool for artists. The tool should enable artists to create web sites to showcase their work.


Tue, 18 Jan 2005

Slow POP connections

— SjG @ 12:29 pm

OK, this is an esoteric one, but I’m happy to report there is a simple solution.

We migrated Stacy over to using Thunderbird (from Outlook Express) on her Mac to cut down on the spam. In the process, we upgraded her to OS X.
Strangely, while POP connections to our local QMail server are nearly instantaneous on the Windows machines, there would be a 30-40 second delay for her. It wasn’t a Thunderbird problem — we could replicate the problem by telnetting to port 110 — and only from the Mac OS X machines.

Karl finally succeeded in diagnosing the problem. QMail uses tcpserver to wrap connections. tcpserver, in turn, checks back via ident. The Mac OS machines don’t have identd running by default. By running tcpserver with the “-R” option (disabling the ident lookup), everything works brilliantly as it should.


Sat, 15 Jan 2005

WordPress Publish by Email

— SjG @ 5:09 pm

So I was playing with the cool wp-mail mod by John Blade, and trying to moblog from my Treo 650 and Versamail. It works impressively.

But I’m never quite satisfied with any software — I wanted a few new features, and I wanted a fix for a weird VersaMail bug. So I added some features, and tweaked some code.

This version adds the following:

  • Allow uploaded articles to specify status (e.g., draft, publish, static, private).
  • Fixes a weird encoding issue introduced by VersaMail, which sends encoded images with a MIME type of “application/octet-stream”. Huh?
  • Creates thumbnails of the uploaded images, and includes them as links to the actual images

Status Code
To specify status for an article, you use John’s subject syntax to specify a category, then follow it up with the code for the status:

  • d – draft
  • p – publish
  • s – static
  • P – private

So, for example, to upload an article as a draft into category 6 with a title “My Article”, you would use the subject:

[6d]My Article

If you’d wanted that to be immediately published instead of posted as a draft, you could just omit the “d” in the category specifier, or explicitly add a “p”.

If you don’t know which category you want, you can still use this status hack; assign the posting to category 1, and change it later from your admin console.

Thumbnails
This functionality depends on Thomas Boetell’s popular GD lib being installed. Many PHP installations come with it prebuilt; otherwise you’ll need to bug your ISP to add it (or rebuild your PHP if you run your own server).

By default, thumbnails are created with the maximum dimension of 100 pixels; that means the longest side of the thumbnail will be 100 pixels, regardless of the aspect ratio (if your original image is 640 x 480, the thumbnail will be 100 x 75, but if your original image was 480 x 640, your thumbnail will be 75 x 100). You can change this maximum dimension; simply edit line 49, and change
$thumb_max = 100;
to the value you prefer.

Download
I’m sending my changes to John, so he can incorporate them into whatever he’s doing with wp-mail. In the meantime, you can download ’em here. Simply expand the archive, and replace your wp-mail.php with the file from the archive.

wp-mail.tgz Oooooh! A single file in a tar archive!
wp-mail.zip For those of you who prefer zip format.

Filed in: