Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/amazon.php
<?php
require_once("lib/com/sergids/common/Xml.php");
require_once("lib/com/sergids/topmusic/model/AlbumO.php");

//include "data.php";      //static data about Amazon (servers, search fields)
//include "language.php";  //translate the output to the prefered language of the user

$title=$_GET['title'];
$artist=$_GET['artist'];

$language  ='en';
$locale    ='us';
$mode      ='music';
$page      ='1';
$search    =$title." ".$artist;
$searchtype='KeywordSearch';
$show_url  =false;
$show_xml  =false;
$show_array=false;
$type      ='lite';
$associate_id='sergidscom02-20';

$f_user_search=true;  //add a user search form and allow user searches?

//use which servers?
$norserver='http://www.amazon.com';
$xmlserver='http://xml.amazon.com';

$dev_token='0TXD3K93572Y2SWFJV02';

$file="$xmlserver/onca/xml3?". 
      "$searchtype"  .'='.urlencode($search)      .'&'.
      'dev-t'        .'='.$dev_token              .'&'.
      'f'            .'='.'xml'                   .'&'.
      'locale'       .'='.$locale                 .'&'.
      'mode'         .'='.$mode                   .'&'.
      'page'         .'='.$page                   .'&'.
      't'            .'='.$associate_id			  .'&'.
      'type'         .'='.$type                   ;


if ($show_url) {
  echo "<hr />\n";
  echo "Debugging:<br />\n";
  echo "Asking Amazon's XML interface for:<br />\n";
  echo $file."<br />\n";
  echo "<hr />\n";
}
$data = new XMLParser($file);
$data = $data->data[0]['child'];
print_r($data);
function getAlbums($data){
	foreach($data as $item){
		switch($item['name']){
			case "DETAILS":
				$album=new AlbumO();
				foreach($item['child'] as $item2){
					switch($item2['name']){
						case "PRODUCTNAME":
							$album->title=$item2['content'];
							break;
						case "ARTISTS":
							foreach($item2['child'] as $item3){
								$album->artistname.=$item3['content']." ";
							}
							break;
						case "IMAGEURLMEDIUM":
							$album->frontcover_url=$item2['content'];
							break;
					}
				}
				if($album->frontcover_url!="")
					$albums[]=$album;	
				break;	
		}
	}
	return $albums;
}
function printAlbums($albums,$title,$artist){
	echo "<script language=\"javascript\">\n";
	echo "function setCover(url){\n";
	echo "  window.opener.document.albumEditForm.frontcover_url.value=url;\n";
	echo "	window.close();\n";
	echo "}\n";
	echo "</script>\n";
	echo "<table cellspacing=\"2\" cellpadding=\"1\" width=\"100%\">\n";
	if(count($albums)>0){
		foreach($albums as $album){
			echo "<tr><td><a href=\"#\" onClick=\"setCover('".$album->frontcover_url."')\"><img src=\"".$album->frontcover_url."\" border=\"0\"></a></td><td>".$album->getTitle()." (".$album->artistname.")</td></tr>\n";
		}
	}else{
	?>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr><td colspan="2"><center><br>No results found</center></td></tr>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr><td colspan="2">Refine search:</td></tr>
		<tr><td colspan="2">&nbsp;</td></tr>
		<form name="searchCover" method="get" action="">
		<tr>
			<td>Album title</td>
			<td><input type="text" name="title" value="<?=$title?>"></td>
		</tr>
		<tr>
			<td>Artist/Band name</td>
			<td><input type="text" name="artist" value="<?=$artist?>"></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td><input type="submit" name="submit" value="Search again"></td>
		</tr>
		</form>
		<tr><td colspan="2">&nbsp;</td></tr>
		<tr><td colspan="2"><a href="#" onClick="window.close()">Close</a></td></tr>
		
	<?php 
	}
	echo "</table>\n";
}
$albums=getAlbums($data);
printAlbums($albums,$title,$artist);

?>

Return current item: Top Music module