Provide filters for additional Amazon information (detailpageurl, various images)
peterx - October 7, 2009 - 22:05
| Project: | Amazon Module |
| Version: | 6.x-1.0-beta7 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Having tested the filter, I need for a filter that can be wrapped around other text and HTML. <amazon asin="123">jkhkjhdkjhfhjd</amazon> is the format I used in a previous filter. [amazon 123 start]jkhkjhdkjhfhjd[amazon 123 end] could work.
The most common use would be to get a link around my own image or text and that could use the format:
[amazon 123 link '<img src="ffdfd" alt="example" />']
[amazon 123 link 'Buy the new and improved Dummies guide to the numbers 1, 2, and 3.']
[amazon 123 link 'jkhkjhdkjhfhjd'] would be difficult for more complex examples because the string could contain text, including single quotes, HTML, including double quotes, and possibly other filter tags.

#1
Please give an exact example of what the input would look like and what the resulting HTML would look like.
Are you just looking for the link to the Amazon.com item, or the link to the Amazon Store item? Because those are available using views.
Also, we could make a filter that was just the link to the Amazon.com item, for example. Then you could do [amazon_com_link YOURASIN] and you could use it like something.
Anyway, please give very specific examples of what you want to do.
#2
The first and simplest case is to produce a link the same as
[amazon 123]but replace the text. The following could work.[amazon_link 123 'Buy the new and improved Dummies guide to the numbers 1, 2, and 3.']The second case is to produce a link the same as
[amazon 123]but replace the text with my own image. The following would work.[amazon_link 123 '<img src="example.png" alt="example" />']The next case is to get the title without a link.
[amazon_title 123]There are more complicated examples I have used but they could be handled by using the above filters in combination with the existing filter.
The following example could create a problem because of the single quote in the alt text.
[amazon_link 123 '<img src="example.png" alt="John's book" />']The following example could create a problem because of the filter with the filter.
[amazon_link 123 '<img src="example.png" alt="[example_filter]" />']The last example might fit something like this:
[amazon_link_start 123]<img src="example.png" alt="[example_filter]" />[amazon_link_end 123]#3
Sorry, @peterx:
I don't even understand yet what you're trying to accomplish.
Please show example input (something that would look like [amazon_link XXX] or whatever
and OUTPUT, the html that would be generated as a result.
You're going to have to say what the link is a link to; I asked a bit about that in my previous posting. The amazon.com page?
#4
[amazon 0156029022]and[amazon 0156029022 inline]both produce: A Drink Before the War<span class="amazon-item amazon-item-book amazon-item-inline"><a href="http://www.amazon.com/Drink-Before-War-Dennis-Lehane/dp/0156029022%3FSubscriptionId%3DAKIAJJUUSARDMYEYYJZQ%26tag%3Dpetermoulding-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0156029022">A Drink Before the War</a></span>What I would like in case one is to replace the text within the link using something like
[amazon_link 123 'Buy this book']: Buy this book<span class="amazon-item amazon-item-book amazon-item-inline"><a href="http://www.amazon.com/Drink-Before-War-Dennis-Lehane/dp/0156029022%3FSubscriptionId%3DAKIAJJUUSARDMYEYYJZQ%26tag%3Dpetermoulding-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0156029022">Buy this book</a></span>What I would like in case two is to replace the text within the link with an image:
<span class="amazon-item amazon-item-book amazon-item-inline"><a href="http://www.amazon.com/Drink-Before-War-Dennis-Lehane/dp/0156029022%3FSubscriptionId%3DAKIAJJUUSARDMYEYYJZQ%26tag%3Dpetermoulding-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0156029022"><img src="/images/books/a-drink-before-the-war.jpg" height="340" width="600" alt="The cover of A Drink Before the War featuring shadowy figures crossing a dark city street" /></a></span>I make the first use of a book title link to Amazon. Subsequent uses need the title but not the link. Given that the title is cached,
[amazon_title 0156029022]could easily produce: A Drink Before the War<span class="amazon-item amazon-item-book amazon-item-inline">A Drink Before the War</span>The last case is to replace the text within the link and allow for filters within the text: Buy this book and get a free [example_filter]
<span class="amazon-item amazon-item-book amazon-item-inline"><a href="http://www.amazon.com/Drink-Before-War-Dennis-Lehane/dp/0156029022%3FSubscriptionId%3DAKIAJJUUSARDMYEYYJZQ%26tag%3Dpetermoulding-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0156029022">Buy this book and get a free [example_filter]</a></span>The last example has a filter within the replacement text and the filter could run before or after the Amazon filter. The example filter might be wiki markup or anything else provided by add on modules. For that reason, it would be useful to have a filter that provides the start of the link:
<span class="amazon-item amazon-item-book amazon-item-inline"><a href="http://www.amazon.com/Drink-Before-War-Dennis-Lehane/dp/0156029022%3FSubscriptionId%3DAKIAJJUUSARDMYEYYJZQ%26tag%3Dpetermoulding-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0156029022">and a filter that provides the end of the link:
</a></span>#5
As an example of replacing text, Amazon supply A Drink Before the War as the title of
A Drink Before the Warbut supply Darkness, Take My Hand (Patrick Kenzie/Angela Gennaro Novels) as the title ofDarkness, Take My Hand. There are times when the Amazon title is wrong because some books are issued in America with a different title. A review has to provide the original title and the American title. The text of the link has to be something like:Northern Lights (with the American title of The Golden Compass)#6
Thanks for your perserverance. I'll try to do the link when I get some good time on the module.
What I'll probably do is just give you two new filters, [amazon_link ASINHERE] and [amazon_image s ASINHERE] or [amazon_image m ASINHERE], something like that. Then you can use that information any way you want.
I guess in #5 you're saying that you want to manually create the link and text. That would work with the approach here.
I should point out that you can already do this in Views. But that probably doesn't meet your exact need here, since you're manually massaging text.
#7
If you request everything for an ASIN the first time you find it, you should have it in memory for the remaining uses of the ASIN on the page. On pages where the product image, title, price, etc are listed across the top of the page then at the bottom of the page and sprinkled throughout the page, I expect there would be just one request for the information. Subsequent use could be supplied from an array in your code. That should minimise requests and keep pages fast. If some of the information travels through Views and other code, that would mean extra requests for the information. Views could be nice for producing a list of products. I expect it would not be nice for providing multiple references to different product information within a product page.
I looked in amazon_item_lookup. It could have a static $item_cache and return items from there using code something like the following code. The first lookup should be from the db or web then subsequent lookups would be from $item_cache.
function amazon_item_lookup($item_ids = array(), $force_lookup = FALSE) {
if (empty($item_ids)) {
return array();
}
if (is_string($item_ids)) {
$item_ids = array($item_ids);
}
static $item_cache;
if(!isset($item_cache))
{
$item_cache = array();
}
$items = array();
$items_to_fetch_from_db = array();
foreach($item_ids as $item_id)
{
if(isset($item_cache[$item_id]))
{
$items[$item_id] = $item_cache[$item_id]);
}
else
{
$items_to_fetch_from_db[] = $item_id;
}
if($force_lookup)
{
$items_to_fetch = $items_to_fetch_from_db;
}
else
{
$items_to_fetch = array();
$items_from_db = amazon_item_lookup_from_db($items_to_fetch_from_db);
foreach($items_to_fetch_from_db as $item_id)
{
if(isset($items_from_db[$item_id]))
{
$items[$item_id] = $items_from_db[$item_id]);
$item_cache[$item_id] = $items_from_db[$item_id]);
}
else
{
$items_to_fetch[] = $item_id;
}
}
}
}
$items_from_web = amazon_item_lookup_from_web($items_to_fetch);
foreach($items_from_web as $item_id => $item)
{
$item_cache[$item_id] = $item);
}
return $items + $items_from_web;
}
#8
Hi-
patches that you have tested may be submitted. To see how, drupal.org/patch.
But it needs to go in it's own issue.
#9
Changing title to add additional filters.
I recommend at least:
- detailpageurl
- small/medium/large images
#10
I've just committed support for an enormous number of new filters.
The filters are now available through [amazon ASIN detail].
Everything that is preprocessed in amazon_preprocess_amazon_item() is available for use. For example,
[amazon 0596515804 detailpageurl]
[amazon 0596515804 largeimage]
[amazon 0596515804 largeimageurl]
[amazon 0596515804 largeimageheight]
[amazon 0596515804 largeimagewidth]
[amazon 0596515804 smallimage]
[amazon 0596515804 mediumimage]
[amazon 0596515804 editorialreview]
This behavior can be themed through amazon-item-detail.tpl.php.
I hope to have documentation up today on http://drupal.org/node/595464
#11
Automatically closed -- issue fixed for 2 weeks with no activity.