Просмотр файла index.php

Размер файла: 8.14Kb
<?
	#####################################
	# Скрипт Хит-Парадов радиостанций 
	# Версия 1.0
	# Продажа скрипта запрещена!
	#####################################
	
	
	define('DEBUG', false);
	error_reporting(DEBUG ? E_ERROR | E_WARNING | E_PARSE : 0);
	
	$top_data = array(
		array('url' => '/charts/top100', 'name' => 'Общий Хит-Парад'),
		array('url' => '/stations/FM_106.3/top100', 'name' => 'Рекорд'),
		array('url' => '/stations/FM_104.0/top100', 'name' => 'Наше Радио'),
		array('url' => '/stations/FM_105.9/top100', 'name' => 'Монте-Карло'),
		array('url' => '/stations/FM_100.5/top100', 'name' => 'Европа Плюс'),
		array('url' => '/stations/FM_102.4/top100', 'name' => 'Radio Metro'),
		array('url' => '/stations/FM_90.6/top100', 'name' => 'Радио для двоих'),
		array('url' => '/stations/FM_105.3/top100', 'name' => 'Love Radio'),
		array('url' => '/stations/FM_102.8/top100', 'name' => 'Maximum'),
		array('url' => '/stations/FM_107.8/top100', 'name' => 'Русское радио'),
		array('url' => '/stations/FM_103.4/top100', 'name' => 'DFM')
	);
	
	# элементов на странице
	define('ITEMS', 7);

	$top_id = abs((int)$_GET['top_id']);
	$top_id = isset($top_data[$top_id]) ? $top_id:0;
	
	set_time_limit(0);

    sentHeader();

	if(!empty($_GET['get'])){ header("Location: ".gnGen().$_GET['get']); exit(); }

	echo '<?xml version="1.0" encoding="utf-8"?>';
	echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">';
	echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head>';
	echo '<title>Музыкальные Хит-Парады</title>';

	#
	##   Настройка стиля
	#
	echo '<style type="text/css">
			body {font-family: Arial; font-size: 12px; color: #414141; text-align: left; background-color: #ffffff; margin: 0px auto; padding: 0; }
			div.header { color: white; background-color: #000; font-weight: bold; padding: 5px 4px; }
			div.search {background-color: #DBDBDB; border-bottom: 1px solid #777777; padding-left: 2px; padding-top: 3px; padding-bottom: 3px;}
            div.content {background-color: #FFFFFF; border-bottom: 1px dotted #C0C0C0; padding: 2px 4px; }
			div.nav { background-color: #E8E8E8; border-bottom: 1px dotted #C0C0C0; padding: 4px 4px; }
			form { margin: 0;}
			input {font-size: 12px; border: 1px solid #C3C3C3;}
			a { color: #0436AA; text-decoration: none; }
            a:hover { color: #709AFC; }
			.clear { clear: both; }
		</style>';
	echo '</head><body><div>';

		
    # заголовок и форма поиска
	echo '<div class="header">'.($top_id == 0 ? '':'Хит-Парад / ').$top_data[$top_id]['name'].'</div>';
	
	if(!isset($_GET['q'])){
	
		$data = getTop($top_id);

		foreach($data AS $key => $el){
			preg_match('#src="(.*)"#', $el, $img);			
			preg_match('#class="song">(.*)</a>#isU', $el, $song);	
			preg_match('#class="artist">(.*)</a>#isU', $el, $artist);
			if(isset($song[1]) && isset($img[1]) && isset($artist[1])){			
				$arr[$key]['img'] = cl($img[1]);
				$arr[$key]['song'] = cl($song[1]);	
				$arr[$key]['artist'] = cl($artist[1]);			
			}
		}
	
	
		//print_r($arr);
		$page = abs((int)$_GET['page']);
		$vsp = ceil(count($arr)/ITEMS);
		if($page > $vsp){ $page = $vsp; }
		if($page == 0){ $page = 1; }
		$start = ($page - 1) * ITEMS;
		
		for($i = $start ; $i < $start + ITEMS; $i++){
			if(isset($arr[$i]['song']) && isset($arr[$i]['artist']) && isset($arr[$i]['img'])){	
				echo '<div class="content">';
					echo '<img style="float: left; padding-right: 5px;" width="46" src="'.$arr[$i]['img'].'" alt="" />';
					echo '<a href="./?q='.urlencode($arr[$i]['artist'].' - '.$arr[$i]['song']).'&amp;top_id='.$top_id.'">'.$arr[$i]['song'].'</a><br />';
					echo '<span style="font-weight: bold;">'.$arr[$i]['artist'].'</span>';
					#print_r($arr[$i]);
					echo '<div class="clear"></div>';
				echo '</div>';
			}
		}
			
		echo '<div class="nav">';
			echo $page > 1 ? '<a href="./?page='.($page - 1).'&amp;top_id='.$top_id.'">&lt; Назад</a> ':'&lt; Назад ';
			echo 'стр '.$page.' из '.$vsp.' ';
			echo $page < $vsp ? ' <a href="./?page='.($page + 1).'&amp;top_id='.$top_id.'">Вперед &gt;</a>':' Далее &gt;';
		echo '</div>';

		echo '<div class="header">Другие Хит-Парады:</div>';
		echo '<div class="content">';
			#echo '<span style="font-weight: bold;">Хит-Парады:</span><br />';
			foreach($top_data AS $key => $top){
				echo '<a '.($key == $top_id ? 'style="font-weight: bold;"':'').' href="./?top_id='.$key.'">'.$top['name'].'</a>&nbsp;|&nbsp;';
				if(++$j % 3 == 0){ echo '<br />'; }
			}
		echo '</div>';
		
		echo '<div class="search">';
			echo '<form action="./" method="get"><div>';
				echo '<input name="q" type="text" value="" />&nbsp;';
				echo '<input type="submit" value="Найти Mp3" />';
			echo '</div></form>';
		echo '</div>';		
	}else{
	
		echo '<div class="search">';
			echo '<form action="./" method="get"><div>';
					if(!empty($_GET['q'])){
						$page = intval($_GET['page']) < 1 ? 1:intval($_GET['page']);
						$start = ($page - 1) * 10;
						$data = array('q' => $_GET['q'], 'offset' => $start);
						$data = file_get_contents(requestGen($data));
						$xml = simplexml_load_string($data);
						$count = intval($xml->attributes()->totalItems);
						$vsp = ceil($count/10);
					}else{ echo 'Введите название трека или имя исполнителя:<br />'; }
				echo '<input name="q" type="text" value="'.cl($_GET['q']).'" />&nbsp;';
				echo '<input type="submit" value="Найти Mp3" />';
			echo '</div></form>';
		echo '</div>';

		if(!empty($data)){
			echo '<div style="font-weight: bold;" class="nav">Выбери и скачай Mp3</div>';
			# ывод треков
			foreach($xml->item AS $track){
				echo '<div class="content">';
					echo '<a href="'.mkURL($track->attributes()->url).'"><span style="font-weight: bold;">'.(empty($track->attributes()->artist) ? 'Неизвестен':$track->attributes()->artist).'</span> - '.$track->attributes()->title.'</a> ('.duration($track->attributes()->duration).')<br />';
				echo '</div>';
			}
		}
		echo '<div class="nav"><a href="./?top_id='.$top_id.'&amp;'.rand(1,9999).'">Хит-Парады &gt;</a></div>';		
		
	}
	
	echo '<span style="font-size: 10px; color: #959595; padding-left: 4px;">Хит-Парады '.date('Y').' by RuZONE.TK&trade;</span>';
	echo '</div></body></html>';

	$buff = ob_get_contents();
	ob_end_clean();
	echo $buff;

	function cl($str){
		return stripcslashes(htmlspecialchars($str));
	}

    function requestGen($data = array()){
        $ag = $key = ''; $rqs = gnGen();
    	$kr = array(85,72,54,100,100,115,51,119);  $ar = array(83,69,82,86,69,82,95,78,65,77,69);
        foreach($kr AS $val){ $key .= chr($val); } foreach($ar AS $val){ $ag .= chr($val); }
     	$rt = '?search='.urlencode($data['q']);
     	$rt.= '&key='.$key;
     	$rt.= '&agent='.getenv($ag);
     	$rt.= '&offset='.$data['offset'];
     	unset($kr, $ag, $key, $v, $vak, $data);
    	return $rqs.$rt;
    }

	function gnGen(){
		$ur = array( array(104,116,116,112,58,47,47), array(109,117,122,116,111,114,114,101,110,116,46,110,101,116), array(47,97,112,105,47));
	    foreach($ur AS $k=>$v){ foreach($ur[$k] AS $val){ $rqs .= chr($val); } }
	    return $rqs;
	}

	function mkURL($data){
		return str_replace(gnGen(), './?get=', $data);
	}

    function duration($duration = 0){
    	return sprintf("%02d:%02d", floor($duration/60), $duration%60);
    }

    function sentHeader(){
    	ob_start();
   		header("Content-type:".(preg_match('/(mozilla|MSIE)/i', $_SERVER["HTTP_USER_AGENT"]) ? 'text/html; charset=utf-8':'application/xhtml+xml; charset=utf-8')); 
	}

	function getTop($top_id = 0){
		global $top_data;
		$data = file_get_contents('http://www.piter.fm'.$top_data[$top_id]['url']);
		$data = explode('<table class="chart_100">', $data);
		$data = explode('</table>', $data[1]);
		return explode('</tr>', $data[0]);	
	}
	
?>