Muschamp Rd

Quotation Collection Mashup

September 8th, 2012
PHP logo

I’m a collector. I’m not a hoarder because I display my collections. One of the things I’ve steadily collected over the last 15 or 20 years is quotations. Not “quotes”, quotes is a verb…

These quotations were spread over journals, webpages, .sig files, and blog postings. As I had a lot of time on my hands I collected the best of the best of the best quotations into a single .csv (text) file. From this file and using quite a lot of ever more carefully written PHP I created my favourite quotation mashup.


This bit of PHP code which is actually built on top of a lot of other PHP code which I’ve written while unemployed, recently got some minor recognition as one of the Best New Flickr Mashups. Sadly I don’t use the Flickr API all that much, it is my fall back image search API. I use Rotten Tomatoes as my first choice for movies, as my first choice for musicians, and I think Amazon Product API as my first choice for everything else. Only for a few cases does Flickr’s API get used by this mashup.

I’ve continued to add to my quotation collection, refine and refactor my PHP code, and hopefully make the collection usable and accessible for me and others. I’ve tried to make it easy to tweet, like, pin, and otherwise share the quotations if you find them amusing, informative, or otherwise interesting.

If you just want a widget to display a random quotation in the sidebar of your blog, I built that too at some point. However considering all the work I’ve now put into it, I hope someone who actually likes PHP takes my code and builds something with it, perhaps first checking it into an actual code repository. Considering some people’s obsession with all things sharing and social media, methods/functions that create fancy sharing buttons or that pull data from half a dozen different APIs and web services must be useful to someone.

I’ve made pretty much all the code available and unlike some of the PHP code I’ve downloaded online it is actually documented and tested fairly well for a personal side project written by someone who is both rusty and doesn’t like coding in PHP. Perhaps someone who curses less when they code in PHP can make something better of it.

How It Works

The quotations and authors are in a text file (.csv) which I use as the input for more than just the mashup. Each line of the file has three pieces of data, the source/author of the quotation, the quotation itself, and basically a hint where the quotations comes from. Many of my quotations are from songs or films so knowing this I can look for related data from different sources online. I actually added a fourth bit of data at some point.

Everything else on the screen that isn’t part of the standard layout and navigation for is fetched from somewhere else using various APIs.

The buttons and badges below the quotations are made with PHP, though the fanciest Facebook button required a lot of work, to satisfy the full requirements of Facebook’s Open Graph. By linking to Amazon and in many cases the iTunes Store people can buy the book, movie, or possibly the album or song the quotation is from.

All the information that is fetched from an API should be cached locally. This helps with performance. Images are not cached or stored locally, I switched to smaller images at some point to decrease the load time of the page. The Amazon Product API makes you jump through a lot of hoops and recently changed their terms of service, I know as a result Goodreads stopped using it, but having invested so much time and effort into the Amazon Product API, I still rely on it a lot in my mashup codebase for things like CD and DVD covers.

The short bio comes from the Rotten Tomatoes for films, from for songs, and everything else is pulled from the Wikipedia. For movies and songs I try to find the trailer or a performance by the artist in YouTube. For long dead authors it is best not to display their most popular video, as things can get strange.

Unlike most of the stuff I do online, this collection, the mashup, the PHP code, the sharing buttons, the tweets might help my Klout score. With all this infrastructure in place and working access to so many APIs it is easy to add new quotations to the collection and make minor improvements. I may make a few more behind the scenes changes to my recently updated WordPress install, but I really wish Opera would work better. It has become very memory hungry and ultimately crashes due to Flash or watching too many videos online. Then there is the bug where I go to cut n’ paste something and it switches to full screen mode…

It is going to make me switch browsers after a decade or more of using Opera. I even paid for Opera, twice, once for my home computer and once for my then employer’s computer.

Related Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.