Convert to class

The biggest change from the last posted version is that it's now encapsulated within a PHP class, so it doesn't pollute the global namespace. This is very much a breaking change; I've been making the transition by having both around for a while and converting pages one at a time.