Been sick, nothing much happened for a couple of weeks. Then I picked up some code I had stashed in the “next version” folder, which like most of the code I find, had some problems. After the cron debacle I wasn’t sure I wanted to put much time into it, but it turned out there were two lines of code I had to change and now I have a working implementation of hooks and filters and I only spent a few hours on it.
Hooks and filters? I don’t know if they were the first, but it’s basically the same system used by WordPress to allow extensibility since about version 1.5. Hooks are places in the code where plugins can interact with TightURL. Filters are pretty much the same thing, except specifically intended to allow plugins to alter something, usually output displayed to the user.
What exactly does this mean?
Initially, I plan on adding three hooks to TightURL. ‘Squish’, ‘Squisher’, and ‘Squished’. Squish will run prior to shortening a URL and will be passed the URL to shorten, the IP of the submitter, and the User-Agent from the browser. The Squish hook allows for the creation of anti-abuse/policy plugins.
Squisher will run instead of the “native” URL shortener. It receives the URL to shorten, IP, and User-Agent. The Squisher hook allows for the creation of new URL shortening engines. Squishers will return the shortened URL.
Squished will run immediately following URL shortening. It receives the URL, the output from whatever squisher ran, the IP, and the User-Agent. The Squished hook allows for the creation of post-shortening tasks.
Developers should take care, as all three hooks lengthen the amount of time it takes for your TightURL installation to return a shortened URL. I have found even slight delays generate complaints. In particular, resist the temptation to create complex Squish plugins, or Squished plugins that perform maintenance tasks. Maintenance tasks should be run by the the internal job scheduling system, and complex, involved, pre-shortening processing simply is not viable. You may be able to convert this instead into a small bit of code that runs with the Squish hook, and the rest runs as a scheduled job. And finally, Squishers as well, need to run quickly and return a result to the user. As with the Squish and Squished hooks, you should use the job scheduler for processing that takes more than a fraction of a second to run.