{"id":37,"date":"2005-11-16T21:06:40","date_gmt":"2005-11-16T13:06:40","guid":{"rendered":"http:\/\/www.darkmirage.com\/2005\/11\/16\/recommendations\/"},"modified":"2006-07-27T01:25:37","modified_gmt":"2006-07-26T17:25:37","slug":"recommendations","status":"publish","type":"post","link":"http:\/\/www.darkmirage.com\/2005\/11\/16\/recommendations\/","title":{"rendered":"Recommendations"},"content":{"rendered":"<p>I have created a recommedations section at the right. It displays selected CDs and books I like using the <a href=\"http:\/\/www.amazon.co.jp\/\">Amazon.co.jp<\/a> database. (They do ship overseas for most printed materials and music CDs, so it&#8217;s a pretty good site to get stuff from) It took me damn long to get the script working right.<\/p>\n<p>Stop reading here if you are not interested in technical fluff.<\/p>\n<p><!--more--><\/p>\n<p>First of all, I have to confess that I <strike>was<\/strike> am totally clueless about PHP, so it took me a lot longer than necessary to write this simple script&#8230; \u00ef\u00bc\u00bf|\u00ef\u00bf\u00a3|O<\/p>\n<p>Basically Amazon Affliate links allow you to link to individual items and adds thumbnail and item information. I noticed that these links are actually webpages nested in an iframe, which makes the actual URL of the page known. The code given looks something like this:<\/p>\n<p><code style=\"text-align:left;\">&lt;iframe src=\"URL IS HERE\" style=\"width:120px;height:240px;\" scrolling=\"no\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\"&gt;<\/code><\/p>\n<p>The URL itself is seriously long and it will break my layout if I typed it here. Clicky for a <a href=\"http:\/\/rcm-jp.amazon.co.jp\/e\/cm?t=ramblingsofda-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=B000ANY1HA&#038;=1&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000ff&#038;bc1=000000&#038;bg1=ffffff&#038;f=ifr\">sample<\/a> of one (btw, that&#8217;s KOTOKO&#8217;s new single).<\/p>\n<p>As you can see from the iframe code and the URL, Amazon has already provided the user with some levels of customizability. The <code>bg1=ffffff<\/code> parameter in the URL allows you to set the background colour, <code>lc1=<\/code> for the link colour, <code>bc1=<\/code> for the border colour, etc. The most important parameter is <code>asins=B000ANY1HA<\/code>, which tells Amazon&#8217;s script which item you are trying to display, with &#8220;B000ANY1HA&#8221; being the ASIN (Amazon Serial Identification Number) of the item, which can be found on the page of all items listed on Amazon.<\/p>\n<p>Well, being able to customize the colour is great, but it&#8217;s not enough. The links are all underlined and there&#8217;s this grey &#8220;\u00e3\u0192\u2014\u00e3\u0192\u00a9\u00e3\u201a\u00a4\u00e3\u0192\u0090\u00e3\u201a\u00b7\u00e3\u0192\u00bc\u00e3\u0081\u00ab\u00e3\u0081\u00a4\u00e3\u0081\u201e\u00e3\u0081\u00a6&#8221; (Privacy policy) text at the bottom which is pretty distracting. The default table and iframe size also cause a tiny white margin to overflow and makes the iframe scroll slightly when you turn the mousewheel. This annoys me greatly.<\/p>\n<p>Since, unlike with Google Adsense which uses Javascript to cloak everything, I now have the URL of the actual page, I decided to reformat it using PHP to fit my layout. Originally, my intention was to do away with the iframe completely and using <code>include()<\/code> to insert the content directly. The benefit of this is that the CSS formatting will all be applied automatically as the whole thing because effectively part of this page. But I soon realized that the idea stinked because Amazon codes like drunkens and introducing the HTML codes in directly will make my site to contain invalid XHTML.<\/p>\n<p>So I decided to <code>file_get_contents()<\/code> the thing into a variable, reformat it however I like, echo the result and finally put <em>that<\/em> into the iframe instead (making sure that there isn&#8217;t any overflow). Normally the script retrieves and formats an indexed page (specified using <code>indexed=<\/code>) instead of a live feed so as to speed things up. The other display method is to input a specific ASIN using the <code>url=<\/code> parameter, through which the script can display even non-indexed items by downloading the live feed. It cycles through the indexed links randomly by default if neither parameter is present. Source code is <a href=\"http:\/\/darkmirage.com\/stuff\/amazon.phps\">here<\/a>. It&#8217;s hardly optimized in anyway, but it works.<\/p>\n<p>The results for comparison: KOTOKO&#8217;s <strong>421 -a will-<\/strong> in three versions.<\/p>\n<ul>\n<li><a href=\"http:\/\/rcm-jp.amazon.co.jp\/e\/cm?t=ramblingsofda-22&#038;o=9&#038;p=8&#038;l=as1&#038;asins=B000ANY1HA&#038;=1&#038;fc1=000000&#038;IS2=1&#038;lt1=_blank&#038;lc1=0000ff&#038;bc1=000000&#038;bg1=ffffff&#038;f=ifr\">Original<\/a><\/li>\n<li><a href=\"http:\/\/www.darkmirage.com\/blog\/wp-content\/plugins\/amazon\/?url=B000ANY1HA\">Formatted from live feed<\/a><\/li>\n<li><a href=\"http:\/\/www.darkmirage.com\/blog\/wp-content\/plugins\/amazon\/?indexed=kotoko\">Formatted from indexed page<\/a><\/li>\n<\/ul>\n<p>Pretty good considering I started this thing not knowing any PHP syntax at all&#8230; It took me damn long to find out that <code>iconv()<\/code> lets me convert Shift-JIS (used by 99% of Japanese sites) to UTF-8 (used by my blog).<\/p>\n<p>Thanks to everyone from #php (irc.freenode.net) and #nipponsei (irc.rizon.net) for their help.<\/p>\n<p><b>EDIT<\/b>: Seems like my host is acting up again&#8230; I swear I&#8217;m moving somewhere else once my current term is over.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have created a recommedations section at the right. It displays selected CDs and books I like using the Amazon.co.jp database. (They do ship overseas for most printed materials and music CDs, so it&#8217;s a pretty good site to get &hellip; <a href=\"http:\/\/www.darkmirage.com\/2005\/11\/16\/recommendations\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,4],"tags":[21,99,33,32],"_links":{"self":[{"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/posts\/37"}],"collection":[{"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/comments?post=37"}],"version-history":[{"count":0,"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/posts\/37\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/media?parent=37"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/categories?post=37"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.darkmirage.com\/wp-json\/wp\/v2\/tags?post=37"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}