A better preview page for YOURLS

This morning I set up YOURLS on one of my other shorter domains (l0ke) and added short links to all of my posts here using a custom plugin I’m going to release soon. In the midst of all this tinkering I decided to try and “improve” upon the YOURLS code for viewing a shortlink preview. YOURLS provides two view options for previews, it can show a detailed breakdown of the link and all traffic or nothing at all. What I wanted was a simple overview without all the fuss (and loading times) of the full-featured option.

Here is an example of the result both before and after.

I don’t normally publicly admonish other developers but YOURLS looks like it was written in an awful hurry by blind monkeys. Inconsistent function naming (no classes here), global variables throughout, and just a general hodge-podge of PHP and HTML. It all works well enough, but it’s not a codebase I’d ideally ever want to maintain.

Instead of being able to hook into or overload any methods I’ve had to manually update core files which means if a future version is released it’s very likely this code will break. Simply download the file below and overwrite the yourls-infos.php file in the root YOURLS directory. Now if a logged-in user visits the preview page they will get all of their stats while a regular visitor will instead see a much reduced set of information including the full URL, number of clicks and the date the shortlink was created.

Download yourls-infos.php for YOURLS 1.4.3