Hey, is it possible to achieve the same effect you have with your input filter in the php, I'm designing up a node template, I've defined a cck text field that has the ISBN code, nabbed the code to convert 13 digit ISBNs to 10 from somewhere else.
Now in the node template I want to define the areas where the picture, the price, link all appear separately.
Is that possible using your module or could you point me at how I might either use it to, or a php-amazon library to lean on that'd do the leg work for me?
Ideally what I want to ultimately achieve is something similar to amazonfunction($ISBN, thumbnail);
Many thanks in advance for any support/thoughts.

Comments

chrisns’s picture

Title: Usable functions » Functions for node templates
chrisns’s picture

Status: Active » Closed (fixed)

hopefully this should help someone in my shoes at least, this will do the isbn13->10 conversion for you and then lookup the details on amazon, the basis is stolen from the php shop library on the amazon web services site. hope this of use to someone

<?php

function ISBN_ASIN($ISBN) {
	switch (strlen(str_replace("-","",str_replace(" ","",$ISBN)))) {
	case 10:
		return $ISBN;
		break;
	case 13:
		$ISBN = trim($ISBN);
		$ISBN = str_replace("-","",$ISBN);
		$ISBN = str_replace(" ","",$ISBN);
		$isbn10 = substr($ISBN,3,9);
		$checksum = 0;
		$weight = 10;
		$isbnCharArray = str_split($isbn10);
		foreach($isbnCharArray as $char) {
			$checksum += $char * $weight;
			$weight--;
		}
		$checksum = 11-($checksum % 11);
		if ($checksum == 10)
			$isbn10 .= "X";
		else if ($checksum == 11)
			$isbn10 .= "0k";
		else
			$isbn10 .= $checksum;
		return $isbn10;
		break;
	}
}

	define('KEYID','1Q32H5DNDSNDHX08H3R2');
	define('AssocTag','test0425-20');
	ItemLookup(ISBN_ASIN("978 140-53220-8-9"));

function ItemLookup($asin){
	$request = "http://ecs.amazonaws.co.uk/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$asin&ResponseGroup=Medium,Offers";
	//The use of `file_get_contents` may not work on all servers because it relies on the ability to open remote URLs using the file manipulation functions. 
	//PHP gives you the ability to disable this functionality in your php.ini file and many administrators do so for security reasons.
	//If your administrator has not done so, you can comment out the following 5 lines of code and uncomment the 6th.  
	$session = curl_init($request);
	curl_setopt($session, CURLOPT_HEADER, false);
	curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($session);
	curl_close($session);
	//$response = file_get_contents($request);
	$parsed_xml = simplexml_load_string($response);
	printDetails($parsed_xml, $SearchIndex);
}
function printDetails($parsed_xml){
	global $amazon_item_LargeImage, $amazon_item_MediumImage, $amazon_item_SmallImage, $amazon_item_SwatchImage, $amazon_item_Binding, $amazon_item_EAN, $amazon_item_NumberOfPages, $amazon_item_Price, $amazon_item_Title, $amazon_item_Publisher, $amazon_item_PublicationDate, $amazon_item_DetailPageURL, $amazon_item_SalesRank, $amazon_item_ASIN;
	$amazon_item_LargeImage			= $parsed_xml->Items->Item->LargeImage->URL;
	$amazon_item_MediumImage		= $parsed_xml->Items->Item->MediumImage->URL;
	$amazon_item_SmallImage			= $parsed_xml->Items->Item->SmallImage	->URL;
	$amazon_item_SwatchImage		= $parsed_xml->Items->Item->ImageSets->ImageSet->SwatchImage->URL;
	$amazon_item_Binding			= $parsed_xml->Items->Item->ItemAttributes->Binding;
	$amazon_item_EAN 				= $parsed_xml->Items->Item->ItemAttributes->EAN;
	$amazon_item_NumberOfPages		= $parsed_xml->Items->Item->ItemAttributes->NumberOfPages;
	$amazon_item_Price				= (intval($parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->Amount)/100);
	$amazon_item_Title				= $parsed_xml->Items->Item->ItemAttributes->Title;
	$amazon_item_Publisher			= $parsed_xml->Items->Item->ItemAttributes->Publisher;
	$amazon_item_PublicationDate	= $parsed_xml->Items->Item->ItemAttributes->PublicationDate;
	$amazon_item_DetailPageURL 		= $parsed_xml->Items->Item->DetailPageURL;
	$amazon_item_ASIN				= $parsed_xml->Items->Item->ASIN;
	$amazon_item_SalesRank			= $parsed_xml->Items->Item->SalesRank;
}
print "large".$amazon_item_LargeImage."<br>";
print "medium".$amazon_item_MediumImage."<br>";
print "small".$amazon_item_SmallImage."<br>";
print "swatch".$amazon_item_SwatchImage."<br>";
print "binding".$amazon_item_Binding."<br>";
print "ean".$amazon_item_EAN."<br>";
print "pages".$amazon_item_NumberOfPages."<br>";
print "price".$amazon_item_Price."<br>";
print "title".$amazon_item_Title."<br>";
print "publisher".$amazon_item_Publisher."<br>";
print "publcation".$amazon_item_PublicationDate."<br>";
print "url".$amazon_item_DetailPageURL."<br>";
print "asin".$amazon_item_ASIN."<br>";
print "salesrank".$amazon_item_SalesRank."<br>";
?>