Location: PHPKode > projects > Top Music module > Top Music 3.0.7/html/modules/topMusic/admin/lib/com/sergids/topmusic/model/AmazonAdminDAO.php
<?php
require_once("lib/com/sergids/common/Xml.php");
require_once("AlbumAdminO.php");
require_once("AlbumAdminDAO.php");
class AmazonAdminDAO{
	var $language;
	var $locale;
	var $mode;
	var $page;
	var $search;
	var $searchtype;
	var $show_url;
	var $show_xml;
	var $show_array;
	var $type;
	var $associate_id;
	var $dev_token;
	var $norserver='http://www.amazon.com';
	var $xmlserver='http://xml.amazon.com';
	var $url;
	var $prefix;
	var $db;
	
	function AmazonAdminDAO($db,$prefix){
		$this->language='en';
		$this->locale    ='us';
		$this->mode      ='music';
		$this->page      ='1';
		$this->searchtype='KeywordSearch';
		$this->show_url  =false;
		$this->show_xml  =false;
		$this->show_array=false;
		$this->type      ='lite';
		$this->associate_id='sergidscom02-20';
		$this->dev_token='0TXD3K93572Y2SWFJV02';
		$this->prefix=$prefix;
		$this->db=$db;
	}
	function setUrl(){
		$this->url=$this->xmlserver.'/onca/xml3?';
		$this->url.=$this->searchtype.'='.urlencode($this->search).'&';
      	$this->url.='dev-t='.$this->dev_token.'&';
      	$this->url.='f=xml&';
      	$this->url.='locale='.$this->locale.'&';
      	$this->url.='mode='.$this->mode.'&';
      	$this->url.='page='.$this->page.'&';
      	$this->url.='t='.$this->associate_id.'&';
      	$this->url.='type='.$this->type;
	}
	function searchAlbumCover($artist,$title){
		$this->search=$title.' '.$artist;
		$this->setUrl();
      	$data = new XMLParser($this->url);
		$data = $data->data[0]['child'];
		foreach($data as $item){
			switch($item['name']){
				case "DETAILS":
					$album=new AlbumAdminO();
					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 "IMAGEURLSMALL":
								$small_cover=$item2['content'];
								break;
							case "IMAGEURLSMALL":
								$medium_cover=$item2['content'];
								break;
							case "IMAGEURLLARGE":
								$large_cover=$item2['content'];
								break;
						}
					}
					if($large_cover!=""){
						$album->frontcover_url=$large_cover;
						$large_cover="";
					}
					if($medium_cover!="" && $album->frontcover_url==""){
						$album->frontcover_url=$medium_cover;
						$medium_cover="";
					}
					if($small_cover!="" && $album->frontcover_url==""){
						$album->frontcover_url=$small_cover;
						$msmall_cover="";
					}
					if($album->frontcover_url!="")
						$albums[]=$album;	
					break;	
			}
		}
		return $albums;
	}
	function getAlbumCover($artist,$title){
		$this->search=$title.' '.$artist;
		$this->setUrl();
      	$data = new XMLParser($this->url);
		$data = $data->data[0]['child'];
		$item=$data[0];
		$album=new AlbumAdminO();
		$done=false;
		foreach($data as $item){
			switch($item['name']){
				case "DETAILS":
					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!="")
						$done=true;
					break;	
			}
			if($done)
				break;
		}
		return $album;
	}
	function setAlbumsCover($idartist,$language){
		$albumDAO=new AlbumAdminDAO($this->db,$this->prefix);
		$albums=$albumDAO->getAlbumList($idartist,$language);
		foreach($albums as $album){
			if($album->frontcover_file=="" && $album->frontcover_url==""){
				$title=$album->title;
				$artist=$album->artistname;
				$album2=$this->getAlbumCover($artist,$title);
				$album->title=addslashes($album->title);
				$album->frontcover_url=$album2->frontcover_url;
				$albumDAO->updateAlbum($album,$language);
			}
		}
	}
}
?>
Return current item: Top Music module