<?php include('header_music.php');?>
<div class="container">
<div class="left">
<?php

$i=1;

$mp3name = preg_replace("![^a-z0-9]+!i", "_", $search);
$mp3name = strtolower($mp3name); 

include('includes/simple_html_dom.php');

$html = file_get_html('http://mp3skull.com/mp3/'.$mp3name.'.html');
$list = array();

foreach ( $html->find('div#song_html ') as $e ) {

    $song = array();
    $song['bit'] = preg_replace('!\s+!', ' ',$e->find('div', 0)->plaintext);
    $song['title'] = preg_replace('!\s+!', ' ',$e->find('div', 1)->plaintext);
    $song['url'] = preg_replace('!\s+!', ' ',$e->find('a', 0)->href);
    $list[] = $song;
}
echo'<div class="search-title">'.stripslashes(ucfirst($search)).'</div>';
echo'<ul id="items">';

if ($list==NULL){
echo '<div class="song-list">';	
echo '<div class="error">We could not find any music for the term <strong>'.stripslashes($search).'</strong>. This content maybe removed due to copyright owners request.</div>';
echo '</div>';
}else{

$remove = array("mp3", "Download", "Play", "Embed", "Send Ringtone");
foreach ($list as $p){
	
	$mTitle = str_replace($remove, "", $p['title']);
	$str = strlen ($mTitle);
	if ($str > 50) {
	$MusicTitle = substr($mTitle,0,50).'...';
	}else{
	$MusicTitle = $mTitle;}	
	
?>

<li>
<div class="song-list">
<div class="songInfo"><?php echo $p['bit'];?></div>
<div class="songTitle"><?php echo $MusicTitle;?></div>

<div class="bttomBar">
<div class="btns">
<a class="orange" href="<?php echo $p['url'];?>">Download</a>
</div>
<div class="mplayer">
<object type="application/x-shockwave-flash" data="dewplayer.swf?mp3=<?php echo $p['url'];?>" width="200" height="20" id="dewplayer-<?php echo $i++;?>"><param name="wmode" value="transparent" /><param name="movie" value="dewplayer.swf?mp3=<?php echo $p['url'];?>" /></object>
</div>
</div><!--bttomBar-->
</div><!--song-list-->
</li>
<?php }

}

$addSearch = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $search);


if($CheckMusic = $mysqli->query("SELECT * FROM search WHERE term='$addSearch'")){
	
	$CheckRow = mysqli_fetch_array($CheckMusic);
	
	$CheckId = $CheckRow['id'];
	
	$CheckCnt = $CheckMusic->num_rows;
	
    $CheckMusic->close();

}else{
	
     printf("Error: %s\n", $mysqli->error);
}

$Now = strtotime("now");


$addSearch = $mysqli->escape_string($addSearch);


if ($CheckCnt<1){

	
	$mysqli->query("INSERT INTO search (term, datetime) VALUES('$addSearch','$Now') ") or die (mysqli_error());
	
}else{
	
	$mysqli->query("UPDATE search SET datetime='$Now' WHERE id='$CheckId'") or die (mysqli_error());
}
  

?>
</ul>
<script type="text/javascript">
  
 jQuery(function($){
  
  $('ul#items').easyPaginate({
  step:15
  });
  
});
</script>

</div><!--left-->
<div class="right">
<?php include('right_bar_music.php');?>
</div><!--end right-->
</div><!--container-->
<?php include('footer.php');?>