Rewrite Amazon product links using jQuery, RegEx and PHP

Over at Gamers With Jobs we wanted to rewrite any outbound Amazon product links so that they include the GWJ affiliate ID (every little bit counts when you're a community site). Deciphering Amazon's generally bloated URLs can be tricky, as can knowing what exactly is required when building a link to a product page. So, I cobbled together a couple different pieces of info into a pretty simple solution that I thought I'd share.

First, we wanted a redirect page that would allow us to get metrics on how many product links are followed on our end. This was super-easy to implement in PHP, thanks to a script from Blogthority.

$asin = htmlspecialchars($_GET['asin']);
if ($asin) {
  $link = "http://www.amazon.com/gp/product/" . $asin . "?tag=your-affiliate-id-here";
  header("Location:".$link);
  exit();
}

The trickier part was getting any pre-existing Amazon links, along with any links that users don't enter in the local redirect format, to be rewritten. A bit of jQuery and a JavaScript regular expression, inspired by a post over on MusicBrainz, made a quick solution.

Note: If you're using the latest jQuery, you'll want to drop the @ symbol from the initial selector.

$('a[ @href *= "amazon.com" ]').each(function() {  
  var href = $(this).attr('href');
  var re = /\/([A-Z0-9]{10})(\/|\?|\b)/i
  var asin = re.exec(href);
  if (asin[1]) {
    var shorturl = '/go/amazon?asin='+asin[1];
    $(this).attr('href', shorturl);
  }
});

The script grabs any links with "amazon.com" in the URL and rewrites them to follow our redirect page using the 10 digit ASIN that it pulls using a regular expression. That's it!

(Finally) rid of that ugly theme

in

I've hated my personal site's theme for a couple of years now. Cleaning it up has been sitting a few items down on my todo list for a long time, and I finally decided to stop waiting for a good time and just move it up the stack this week.

Old site design
Eww.

I tried out a couple of starter Drupal themes (Ninesixty and Blueprint) but found them light on documentation and simply not as "complete" as my stand-by on nearly every site, Zen. I was adventurous and went for the 6.x-2.x-dev version of Zen, which has some really nice changes under the hood. The dev branch's documentation still needs some updating, but my familiarity with the theme helped me quickly overcome any issues I encountered.

New site design
Fewer viewers report wanting to throw up in their mouths when viewing this theme.

My main goal with the new theme was to get a more clean, readable, and more timeless look. I essentially don't want to have to update my site's theme anymore... at least, not unless one of my far-more-talented-than-me graphic designer friends want to help me out with it. *wink-wink* *nudge-nudge*

I'll be going through old posts and cleaning them up as-needed to make everything fit within the new size restrictions, but that may take a few days.

[Updated] Upgrading your site to Drupal 6.x: Handout for July 2009 ASU Drupal Users Group

[Update] I've updated the handout to be a single page, cleaned-up a lot of the instruction, and fixed several typos. Please see the revised handout below.

An additional note: If you use the handout to assist your site upgrade process, please do me a favor and fill out a brief survey.

Original post:

Attached below is the handout from the July 2009 ASU Drupal Users Group workshop. Use this handout to help you cover all the steps necessary to upgrade your site from Drupal 5.x to 6.x. It contains a module inventory worksheet and a site review checklist that can be used to help you make sure your site is fully functional after the upgrade.

Note: I created this handout for the ASU DUG workshop as well as an assignment for one of the courses I'm in at ASU. If you use the handout as an aid when performing a site upgrade, please let me know so that I can send you a link to a brief survey about your experience with it. The survey will help me get a better understanding of how you used the handout and how it can be improved.

Slides for April 2009 ASU Drupal Users Group

Attached below are the slides for the April, 2009 ASU Drupal Users Group presentation I gave on maintaining sites using a combination of CVS (to checkout Drupal core and contrib modules) and Subversion (for backing up your site's code base and integrating with locally maintained modules and themes).

Here's a quick rundown of links mentioned in the presentation:

Read on after the break for code samples.

ASU-style custom Gmail theme

ASU Gmail theme

I thought I'd share my recipe for a nice, clean Gmail theme with Arizona State University colors that you can use on your ASU Gmail account. Open up your Gmail (especially your ASU Gmail if you're at ASU) and go to Settings > Themes > Choose your own colors. In the window that pops up, enter the following:

Main Background
Background color: #FFFFFF
Text color: #666666
Link color: #990033

Frame
Background color: #990033
Text color: #FFFFFF
Link color: #FFCC00

Box
Background color: #666666
Text color: #000000

Messages
Background color: #FFFFFF
Text color: #000000
Snippet text color: #999999

Selected Message
Background color: #FFCC00

Slides for March 2009 ASU Drupal Users Group

Attached below are the slides for the March, 2009 ASU Drupal Users Group presentation I gave. The presentation contains info on the following topics:

DrupalCon 2009: Washington, DC

CAS

FeedAPI

Miscellaneous Links

Spring 2009 Video Games, Learning and Literacy

I've been really quiet for the last several months, but just wanted to drop a quick line and say I'm helping out with the Video Games, Learning and Literacy class I took last spring. Among other things, I've setup a site for the class that we're using in place of Blackboard. I used Drupal and, while it's still under pretty heavy construction theme-wise, the site should prove to be a great resource for the students. Check out the Spring 2009 VGLL site, if you're interested.

PHP Gamercard API released on Google Code

I've put up on Google Code a small new project that I'm working on called the PHP Gamercard API. It's basically a set of classes for working with Xbox Live Gamercard data. It takes advantage of a web service provided by Duncan Mackenzie for retrieving structured data about individual Gamertags. You can expect to see something in Drupal that takes advantage of this, once I've got some time to write a module that utilizes it.

Upgraded to Drupal 6.x

I've upgrade to Drupal 6. In spite of being tagged for 6, the theme I was using, Deco, doesn't work right due to CSS caching issues, so I'm sticking with Zen Classic for now. It'll be good motivation to finally design my own.

Wordle + Delicious = Awesome

Found via Laura Scott's blog entry on the same subject, Wordle is a neat little tool for creating word clouds. This one is my Delicious tag cloud.

Syndicate content