<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

<channel>
<title>My Messy Workbench: Toolbox</title>
<link>http://www.synaptic.bc.ca/MyMessyWorkbench/archives/toolbox.xml</link>
<description>A disorganised shambles
obscuring the occasional gem.</description>
<dc:language>en-us</dc:language>
<dc:creator>eBlog@synaptic.bc.ca</dc:creator>
<dc:date>2004-06-21T00:36:59-08:00</dc:date>
<admin:generatorAgent rdf:resource="http://www.movabletype.org/?v=2.661" />
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase>

<item>
<title>Amazon Products Feed: Display the Most Popular Items</title>
<link>http://www.synaptic.bc.ca/MyMessyWorkbench/archives/2004/06/amazon_products_feed_display_the_most_popular_items.php</link>
<description>About apf_pop.cgi
MrRat&apos;s amazon_product_feeds.cgi script (APF) is a marvellously useful script. It&apos;s robust and nimble interface provides rich opportunities for exploitation. Here&apos;s a script most webmasters of APF sites will find useful.

The apf_pop.cgi script searches your website&apos;s access log for specific kinds of APF calls that indicate a user clilcking on an item and grabs the Amazon ASIN&apos;s from them. The ASINs are counted and sorted, then one or more documents are constructed to display them. 

In addition to the data formatting templates available through APF, apf_pop adds an additional templating layer with its own variables. The type of document apf_pop can generate is virtually unlimited: HTML, SHTML, PHP, CGI, even output an APF template, if you like. As this implies, through apf_pop you can display data generated by APF in either dynamic or static documents. 
&lt;br /&gt;&lt;br /&gt;<![CDATA[          Templates

First, things first: design an apf_pop template. It can be based on any type of 
          document. Several template variables are available to help. We'll begin 
          with the core variables. 
          ASIN Data
There are two options for determining how ASIN data is to be placed in your files. 
          Only one or the other of these variables can appear in a template file. 
          %%Popular_ASIN%%
In the output file, this variable is replaced by a comma-delimited list of ASINs suitable for an APF AsinSearch. Examples:

            &lt;!--apf &amp;apf_include=amazon_products_feed.cgi?
			&nbsp;&nbsp;&nbsp;&nbsp;search_type=AsinSearch&item_id=%%Popular_ASIN%%!--&gt;
             &lt;!--#include virtual="/cgi-bin/amazon_products_feed.cgi?&nbsp;&nbsp;&nbsp;&nbsp;search_type=AsinSearch&item_id=%%Popular_ASIN%%" 
              --&gt;
             &lt;a href="/cgi-bin/amazon_products_feed.cgi?
			&nbsp;&nbsp;&nbsp;&nbsp;search_type=AsinSearch&item_id=%%Popular_ASIN%%&gt;The 
              Top 10!&lt;/a&gt; 
          
The first example is, of course, useful for APF templates. It will expand to a formatted list each time the template is parsed. The second can be placed in any SSI parsed file. The list of Amazon items will be generated each time the file is accessed. The third is a simple link you can place anywhere.
%%Popular_HTML%%
When apf_pop encounters this template variable it calls APF,  passing it the ASINs. APF returns data formatted by the APF template set you specify in apf_pop. Finally, apf_pop parses the data, performing some error-checking and data reformatting, before writing the refined formatted data to the output file. PHEW!This one requires a bit of tricky configuration to setup, but %%Popular_HTML%% offers some distinct advantages over %%Popular_ASIN%%.
Static Pages: Unless your APF templates are doing something unusual, the resulting formatted output is suitable for static HTML pages. This will reduce server overhead, bandwidth and user frustration. Yay!
Heavy data: You can use a 'heavy' version of APF rather than the default 'lite' version to generate these static pages. If your site has  heavy traffic in DVDs and Videos, your users may appreciate the Director and Starring links apf_pop provides via APF 'heavy' calls.
Error checking: apf_pop pulls those annoying "There are no exact matches" and "Invalid Asin" messages right out of the data stream and discards them so your visitors never see them.
There is a niggly drawback to %%Popular_HTML%%
Multiple APF scripts: Whether you elect to create a 'heavy' APF for apf_pop's use or not, you'll want apf_pop to call a copy of the  APF script with a different name than the one called when users click on your site's links. This is due to the way apf_pop gathers ASINs from the log file. I'll explain why in some detail later on. The distribution zip contains some tools for diminishing the burden.

The remaining template variables can be used in both the ASIN and HTML context.

%%see_prev_popular%% and %%see_next_popular%%
These will place Next and Back buttons for navigating between pages created by the call to apf_pop.
%%Popular_Page_Count%%
This is replaced by a "Page 3 of 4" message.

More template variables are coming in future versions of this script.

Configuring apf_pop for %%Popular_ASIN%%

We'll begin with the simpler case, configuring apf_pop for a %%Popular_ASIN%% template. There are several variables which must be defined in the script.

General script setup
$max_pages = 20
$items_per_page = 5;

Pretty straightforward. In this example apf_pop will create up to 20 pages listing 5 items per page.

$Popular_var_type = "ASIN";

Tells apf_pop to look for %%Popular_ASIN%% in the template file and replace it with a string of comma delimited ASINs in the output files.

logfile parsing
;
$logfile =  "/home/username/logs/access.log"
Specifies is the log file apf_pop will scan for ASINs. Include the full server directory path as necessary so the script knows where to find it.

$logfile_get_string = "\"get /cgi-bin/Amazon/amazon_products_feed.cgi"

This character string identifies the lines in your logfile representing APF activity. apf_pop will parse these lines for AsinSearch. It's important that this string ignores the log entry's referrer data, so that only user activity to view an ASIN is counted, and not all the times the user clicks another link on that page. $logfile_get_string can be a regular expression; apf_pop will give the string a once-over to assure special characters have been escaped properly.

Logfiles can be quite large so keep this string short to minimise the amount of processing apf_pop must do. The format of the string in the example above will work fine in most instances. "\"get" identifies the opening of a page and is followed by the URL of the page to be opened. Folks on unix servers can test this out using grep. EG:


grep "\"get /your/path/amazon_products_feed.cgi" access.log &gt; apf.log


The file "apf.log" will contain the results. It's likely to be big, so don't forget to delete it.

apf_pop template setup
$template_file = "/home/bv126070/public_html/cgi-bin/Amazon/popular_list.template.html";

Identifies the template used by apf_pop to generate the output pages. Include directory path as necessary.

$nav_target = "_top";
Specifies the link "target" for links generated  for %%see_prev_popular%% and %%see_prev_popular%%,  $nav_target = "_self" is useful for popular pages placed within FRAMESETS or IFRAMES, otherwise, "_top" works well. If you specify an empty string, then the links will have no target.



apf_pop scans the access log for entries containing an APF AsinSearch. If the item_id field contains only one ASIN, then apf_pop counts it as a click and grabs the ASIN.]]></description>
<guid isPermaLink="false">294@http://www.synaptic.bc.ca/MyMessyWorkbench/</guid>
<dc:subject>Instruction Manual</dc:subject>
<dc:date>2004-06-21T00:36:59-08:00</dc:date>
</item>
<item>
<title>IFRAME and Amazon Product Feed:</title>
<link>http://www.synaptic.bc.ca/MyMessyWorkbench/archives/2004/06/iframe_and_amazon_product_feed.php</link>
<description><![CDATA[How to display inline searches in your templates and pagesA Newbie Tutorial

On my HTML pages I figured out how to use SSI to display the results of amazon_product_feed searches on my web pages. However, Neither the SSI or PHP methods described in the documentation will work if placed within the templates.  I've got this great sidebar in my page design but very few of the useful Amazon Product Feed variables are available at the page template level. What to do?

There are two HTML options &lt;OBJECT&gt; and &lt;IFRAME&gt;.  These are fairly well supported on the more popular browsers, though OBJECT is the only one of the two specified in the HTML 4.0 standards. Nonetheless, I went with IFRAME for some of its more useful features.
]]>&lt;br /&gt;&lt;br /&gt;<![CDATA[
Two HTML options &lt;OBJECT&gt; and &lt;IFRAME&gt;.  These are fairly well supported on the more popular browsers, though OBJECT is the only one of the two specified in the HTML 4.0 standards. Nonetheless, I went with IFRAME for some of its more useful features.

It took some immersion in HTML references and some code from additional sources to get all this working, but it's not rocket science. An IFRAME is just a window layered on top of your main window. You can display stuff in it in much the same way you would the main browser. We're going to make it as transparent and flexible as possible. It's quite amazing the results a couple lines of code can produce!  Well, there is a bit more to it than that...

Setting Up the Frame


&lt;iframe name="sidebar" id="sidebar" align="top" allowtransparency="true" 
    marginwidth="4" width="100%" height="750" 
    scrolling="auto" frameborder="0" 
    src="/cgi-bin/Amazon/amazon_heavy_products_feed.cgi?
    mode=blended&search_type=SimilaritySearch&input_string=%%Asin%%
    &templates=4&link_templates=1&max_results=6&link_max_results=10"&gt;
    
          Sorry, your browser does not support IFRAMEs

&lt;/iframe&gt;


So we have a child frame appearing in the parent window with the following configuration

An IFRAME named "sidebar" (we'll be using that later),
that will hopefully force itself to display at the top of the sidebar 
it's transparent so whatever colour our sidebar is will show through
as wide as the parent sidebar (less 4 pixel margins on each side)
will automatically put up scroll bars if there's more data than fits in the frame.
won't have a border because we already have one in the parent sidebar.
browsers which don't support IFRAMES will display the message instead.


Nifty. Now inside that IFRAME is a call to the APF script. This call will perform a similarity search on the current value for %%Asin%%. It's calling a special 'heavy' version of the script which I've lightly hacked in order to get the "heavy" data from AWS, in order to display %%Director%% and %%Starring%% information when available. There's more to this call, but we'll get back to that.

For now, let's finish off the IFRAME implementation.

Resizable IFRAMEs

We've configured our IFRAME to be 750 pixels in height. That's fine when you know how much data the search will return, but we don't. In order to make it resizable, we have to get the IFRAME window and its parent window to have a conversation. "Hey Dad!" "Yes, son?" "I need to be T H I S  B I G !!!" Except they're going to talk in javascript. There's a simple example of this here found on this page. I'd save you all the digging, but the code's Terms of Use prevent me from redistributing it. Instead, I'll tell you what you need to do.

First, view the source code of this page and find the line 


&lt;script type="text/javascript"&gt;


Copy that line and everything following it until you get to 


&lt;/head&gt;


and paste the whole block into your parent page somewhere inside the the &lt;head&gt; container.


]]></description>
<guid isPermaLink="false">289@http://www.synaptic.bc.ca/MyMessyWorkbench/</guid>
<dc:subject>Gems</dc:subject>
<dc:date>2004-06-04T21:46:25-08:00</dc:date>
</item>
<item>
<title>Getting more from your Amazon.ca/com/de/co.uk affiliations.</title>
<link>http://www.synaptic.bc.ca/MyMessyWorkbench/archives/2004/06/getting_more_from_your_amazoncacomdecouk_affiliations.php</link>
<description>I have been providing links to Amazon.com on this site (www.synaptic.bc.ca) for a few years now and have been trying to figure out a way to expand the utility so folks from parts of the world outside the US could take advantage of the links.  

Completely altruistic of me, of course. Has nothing to do with the fact that I don&apos;t earn a thing if I send users to the US site and they end up buying from Amazon.co.uk (United Kingdom) or Amazon.de (Germany) or Amazon.ca (Canada). No way. 

So the question has been, &quot;How do I provide multiple links to the other Amazon sites without having to do a whole lot of work?&quot;

A: amazon_products_feed.cgi, (AFP) a free CGI script from MrRat @ AbsoluteFreebies.com

This is one of those no-brainer decisions. Installs in minutes and the generic interface works straight out of the box. Add some custom templating and you get something that looks like this! Well, actually, that took a fair bit of work, but it looked pretty similar to that on the very first go.

Using Amazon Web Services (AWS), the script natively supports US, UK and German affiliations, and with a little templating it&apos;s a cinch to add product links for Amazonia to your Canadian, French and Japanese affiliations as well.

I&apos;ve not incorporated it into my blogspace yet, but I will, and will also update the macros I wrote to call MTAmazon. It may be possible to sidestep MTAmazon completely. I run multiple blogs which share templates, so there are some issues I need to work out regarding how to to get the macros to tell (AFP) which template to use, but it ain&apos;t rocket science.

In the meantime, I&apos;ll share a couple tidbits for cool AFP implementation tricks in the comments below. (&apos;cause one of them is already marked-up for phpBB anyway.)&lt;br /&gt;&lt;br /&gt;</description>
<guid isPermaLink="false">286@http://www.synaptic.bc.ca/MyMessyWorkbench/</guid>
<dc:subject>Toolbox</dc:subject>
<dc:date>2004-06-04T19:15:51-08:00</dc:date>
</item>


</channel>
</rss>