What’s this about?
Blame Ozh. It all started with this tweet: “On planetOzh: Backup and Archive Twitter To WordPress http://ozh.in/tr”
In short, it’s a way to archive your tweets on your own WordPress blog. If you want to browse your own tweet history, Twitter sucks. If you have published more than 3200 tweets, Twitter lost the older ones. On the other hand, WordPress does all this fine, so he made a plugin to archive all your tweets in WordPress. Then he developed a theme to accompany the plugin, in which he added some nice statistics in the sidebar.
The problem was that I had way more tweets (over 8200 at that moment) than the odd 3200 that Twitter was willing to retrieve. Fortunately I had saved them in time via backupmytweets.com. All I needed was a routine to import those too. Again Ozh to the rescue, he provided me with a small PHP module that I could load in my web root and execute from there. Problem solved? Not really, WordPress, PHP or Apache (dunno which one) majestically choked on the 1 line gigantic JSON file (10.5MB) that backupmytweets.com provided. The solution I chose was maybe not an elegant one but it worked for me: I sliced up the 8200 tweet JSON file in smaller chunks, each containing about 800 tweets. Even then I got an error message from my hosting platform, saying that the maximum execution time of 30 seconds had been exceeded. A trip to my control panel later, the maximum execution time was set to 300 seconds. From then on all the input files passed and I was set to go.
Then I fiddled with it some more…
Modifications I made to the original plugin and theme:
- Modified the header graphic to make it more generic;
- Changed all the static text in the header with variables taken from the input stream;
- Modified the URL which Twitter provided to retrieve the avatar into one that gave a better quality .png file. I don’t know why Twitter choses to point to an inferior quality avatar picture in their JSON stream;
- Added a dynamic left sidebar where I could put some widgets;
- Include the source of the tweet (a.k.a. Twitter client) as a (dynamically generated) category;
- Added the source of the tweet to each posting (“via …”)
- Included a right sidebar widget to show the categories, with tally;
- A lot of little CSS modifications to make everything fit and to suit my taste.
A word of warning about the hashtags, taken from a comment by Ozh on his own blog:
“…the tags are actually generated when the post is viewed (I elected to do this to save lots of queries at importing time). So after first import, yes, you have to browse the archive (or give googlebot a few days to do it for you). After the initial import, bots and yourself will visit the site regularly so hashtags will be converted on the fly. So basically bot visits will both trigger the cron job and the hashtag importing.”
I will clean up the source of the plugin and theme and – with Ozh’ permission – make it available here to whoever wants it. Don’t expect code poetry, this is the first time I dabbled in both PHP and/or WordPress. Suggestions and comments are welcome.
Leave a Reply