I figured the first thing to do in order to get my book reviews online was to set up the functionality to get them from Amazon and display them on my site. This way I can write reviews on Amazon and have them automatically added to my own site.

Amazon offers an RSS feed of your reviews under your profile, see the link in the "Public Reviews Written by You" heading on "Your Profile". What we will do is use this RSS to create a new site.

Get Simplepie (and CodeIgniter, if you want to)

I am going to set up the site using the CodeIgniter MVC framework and the SimplePie RSS reader library. You don't really need to use CodeIgniter, but I wanted to give it a try. First download SimplePie and move the simplepie.inc file under /application/libraries and rename it to "simplepie.php". Set up CodeIgniter as instructed in the user guide.

Controller code

In your controller:

function index($start = 0, $length = 5)
{
    $this->load->library('simplepie');
    $this->simplepie->set_cache_location('./system/cache');

    // amazon uses class and id attributes in their review, which are useful for styling the content inside CDATA - so allow those two, and the rest is default.
    $attribs = $this->simplepie->strip_attributes;
    // unset class and id
    if (($key = array_search('class', $attribs)) !== null) {
        unset($attribs[$key]);
    }
    if (($key = array_search('id', $attribs)) !== null) {
        unset($attribs[$key]);
    }
    $this->simplepie->strip_attributes($attribs);
    // change this to your Amazon book review RSS feed address
    $this->simplepie->set_feed_url('http://www.amazon.com/rss/people/A31F72N3CBFDG2/reviews/ref=cm_rss_member_rev_manlink');
    $this->simplepie->init();
    $data['feed'] = $this->simplepie;
    $data['start'] = $start;
    $data['length'] = $length;
    $this->load->view('show_rss', $data);
}

View code

After that, create the view (show_rss in my case). Create code to process the feed. I used the pagination code from the SimplePie documentation as the basis so that you can have separate pages for the items:

foreach ($feed->get_items($start + 1, $length) as $item) {
    $feed2 = $item->get_feed();
    echo '<div class="latest-post">
          <h1 class="title"><a href="' . $item->get_permalink() . '">' . $item->get_title(true) . '</a></h1>
          <p class="meta">Source: <a href="' . $feed2->get_permalink() . '">' . $feed2->get_title() . '</a> | ' . $item->get_date('j M Y, g:i a') . '</p>
          <div class="entry">
            <p>' . $item->get_content() . '</p>
            <span class="comments">' . $item->get_date('j M Y, g:i a') . '</span>
          </div>
        </div>';
}

// Let's do our paging controls
$next = (int)$start + (int)$length;
$prev = (int)$start - (int)$length;

// Create the NEXT link
$nextlink = '<a href="' . site_url(array('welcome', 'index', 'start' => $next, 'length' => $length)) . '">Next &raquo;</a>';
if ($next > $max) {
    $nextlink = 'Next &raquo;';
}

// Create the PREVIOUS link
$prevlink = '<a href="' . site_url(array('welcome', 'index', 'start' => $prev, 'length' => $length)) . '">&laquo; Previous</a>';
if ($prev < 0 && (int)$start > 0) {
    $prevlink = '<a href="' . site_url(array('welcome', 'index', 'start' => $next, 'length' => $length)) . '">&laquo; Previous</a>';
} elseif ($prev < 0) {
    $prevlink = '&laquo; Previous';
}

// Normalize the numbering for humans
$begin = (int)$start + 1;
$end = ($next > $max) ? $max : $next;

echo '<div class="latest-post">
<p>Showing ' . $begin . '&ndash;' . $end . ' out of ' . $max . ' | ' . $prevlink . ' | ' . $nextlink . ' | <a href="' . site_url(array('welcome', 'index', 'start' => $start, 'length' => '5')) . '">5</a>, <a href="' . site_url(array('welcome', 'index', 'start' => $start, 'length' => '10')) . '">10</a>, or <a href="' . site_url(array('welcome', 'index', 'start' => $start, 'length' => '20')) . '">20</a> at a time.</p>
</div>';

CSS stylesheet

Finally, add a stylesheet. I used one from Free CSS Templates. I also made the following minor tweaks:

span.amzRssByline {
  / Adds newline before the by line in reviews /
  display: block;
}

div.entry img {
  / Floats the review picture /
 float: left;
 display: block;

}
div.entry table div {
  / Adds a margin after the review heading /
 margin-bottom: 10px;
}

Here is the result: http://books.mixu.net/