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

Размер файла: 8.14Kb
  1. <?
  2. #####################################
  3. # Скрипт Хит-Парадов радиостанций
  4. # Версия 1.0
  5. # Продажа скрипта запрещена!
  6. #####################################
  7. define('DEBUG', false);
  8. error_reporting(DEBUG ? E_ERROR | E_WARNING | E_PARSE : 0);
  9. $top_data = array(
  10. array('url' => '/charts/top100', 'name' => 'Общий Хит-Парад'),
  11. array('url' => '/stations/FM_106.3/top100', 'name' => 'Рекорд'),
  12. array('url' => '/stations/FM_104.0/top100', 'name' => 'Наше Радио'),
  13. array('url' => '/stations/FM_105.9/top100', 'name' => 'Монте-Карло'),
  14. array('url' => '/stations/FM_100.5/top100', 'name' => 'Европа Плюс'),
  15. array('url' => '/stations/FM_102.4/top100', 'name' => 'Radio Metro'),
  16. array('url' => '/stations/FM_90.6/top100', 'name' => 'Радио для двоих'),
  17. array('url' => '/stations/FM_105.3/top100', 'name' => 'Love Radio'),
  18. array('url' => '/stations/FM_102.8/top100', 'name' => 'Maximum'),
  19. array('url' => '/stations/FM_107.8/top100', 'name' => 'Русское радио'),
  20. array('url' => '/stations/FM_103.4/top100', 'name' => 'DFM')
  21. );
  22. # элементов на странице
  23. define('ITEMS', 7);
  24.  
  25. $top_id = abs((int)$_GET['top_id']);
  26. $top_id = isset($top_data[$top_id]) ? $top_id:0;
  27. set_time_limit(0);
  28.  
  29. sentHeader();
  30.  
  31. if(!empty($_GET['get'])){ header("Location: ".gnGen().$_GET['get']); exit(); }
  32.  
  33. echo '<?xml version="1.0" encoding="utf-8"?>';
  34. echo '<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">';
  35. echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru"><head>';
  36. echo '<title>Музыкальные Хит-Парады</title>';
  37.  
  38. #
  39. ## Настройка стиля
  40. #
  41. echo '<style type="text/css">
  42. body {font-family: Arial; font-size: 12px; color: #414141; text-align: left; background-color: #ffffff; margin: 0px auto; padding: 0; }
  43. div.header { color: white; background-color: #000; font-weight: bold; padding: 5px 4px; }
  44. div.search {background-color: #DBDBDB; border-bottom: 1px solid #777777; padding-left: 2px; padding-top: 3px; padding-bottom: 3px;}
  45. div.content {background-color: #FFFFFF; border-bottom: 1px dotted #C0C0C0; padding: 2px 4px; }
  46. div.nav { background-color: #E8E8E8; border-bottom: 1px dotted #C0C0C0; padding: 4px 4px; }
  47. form { margin: 0;}
  48. input {font-size: 12px; border: 1px solid #C3C3C3;}
  49. a { color: #0436AA; text-decoration: none; }
  50. a:hover { color: #709AFC; }
  51. .clear { clear: both; }
  52. </style>';
  53. echo '</head><body><div>';
  54.  
  55. # заголовок и форма поиска
  56. echo '<div class="header">'.($top_id == 0 ? '':'Хит-Парад / ').$top_data[$top_id]['name'].'</div>';
  57. if(!isset($_GET['q'])){
  58. $data = getTop($top_id);
  59.  
  60. foreach($data AS $key => $el){
  61. preg_match('#src="(.*)"#', $el, $img);
  62. preg_match('#class="song">(.*)</a>#isU', $el, $song);
  63. preg_match('#class="artist">(.*)</a>#isU', $el, $artist);
  64. if(isset($song[1]) && isset($img[1]) && isset($artist[1])){
  65. $arr[$key]['img'] = cl($img[1]);
  66. $arr[$key]['song'] = cl($song[1]);
  67. $arr[$key]['artist'] = cl($artist[1]);
  68. }
  69. }
  70. //print_r($arr);
  71. $page = abs((int)$_GET['page']);
  72. $vsp = ceil(count($arr)/ITEMS);
  73. if($page > $vsp){ $page = $vsp; }
  74. if($page == 0){ $page = 1; }
  75. $start = ($page - 1) * ITEMS;
  76. for($i = $start ; $i < $start + ITEMS; $i++){
  77. if(isset($arr[$i]['song']) && isset($arr[$i]['artist']) && isset($arr[$i]['img'])){
  78. echo '<div class="content">';
  79. echo '<img style="float: left; padding-right: 5px;" width="46" src="'.$arr[$i]['img'].'" alt="" />';
  80. echo '<a href="./?q='.urlencode($arr[$i]['artist'].' - '.$arr[$i]['song']).'&amp;top_id='.$top_id.'">'.$arr[$i]['song'].'</a><br />';
  81. echo '<span style="font-weight: bold;">'.$arr[$i]['artist'].'</span>';
  82. #print_r($arr[$i]);
  83. echo '<div class="clear"></div>';
  84. echo '</div>';
  85. }
  86. }
  87. echo '<div class="nav">';
  88. echo $page > 1 ? '<a href="./?page='.($page - 1).'&amp;top_id='.$top_id.'">&lt; Назад</a> ':'&lt; Назад ';
  89. echo 'стр '.$page.' из '.$vsp.' ';
  90. echo $page < $vsp ? ' <a href="./?page='.($page + 1).'&amp;top_id='.$top_id.'">Вперед &gt;</a>':' Далее &gt;';
  91. echo '</div>';
  92.  
  93. echo '<div class="header">Другие Хит-Парады:</div>';
  94. echo '<div class="content">';
  95. #echo '<span style="font-weight: bold;">Хит-Парады:</span><br />';
  96. foreach($top_data AS $key => $top){
  97. echo '<a '.($key == $top_id ? 'style="font-weight: bold;"':'').' href="./?top_id='.$key.'">'.$top['name'].'</a>&nbsp;|&nbsp;';
  98. if(++$j % 3 == 0){ echo '<br />'; }
  99. }
  100. echo '</div>';
  101. echo '<div class="search">';
  102. echo '<form action="./" method="get"><div>';
  103. echo '<input name="q" type="text" value="" />&nbsp;';
  104. echo '<input type="submit" value="Найти Mp3" />';
  105. echo '</div></form>';
  106. echo '</div>';
  107. }else{
  108. echo '<div class="search">';
  109. echo '<form action="./" method="get"><div>';
  110. if(!empty($_GET['q'])){
  111. $page = intval($_GET['page']) < 1 ? 1:intval($_GET['page']);
  112. $start = ($page - 1) * 10;
  113. $data = array('q' => $_GET['q'], 'offset' => $start);
  114. $data = file_get_contents(requestGen($data));
  115. $xml = simplexml_load_string($data);
  116. $count = intval($xml->attributes()->totalItems);
  117. $vsp = ceil($count/10);
  118. }else{ echo 'Введите название трека или имя исполнителя:<br />'; }
  119. echo '<input name="q" type="text" value="'.cl($_GET['q']).'" />&nbsp;';
  120. echo '<input type="submit" value="Найти Mp3" />';
  121. echo '</div></form>';
  122. echo '</div>';
  123.  
  124. if(!empty($data)){
  125. echo '<div style="font-weight: bold;" class="nav">Выбери и скачай Mp3</div>';
  126. # ывод треков
  127. foreach($xml->item AS $track){
  128. echo '<div class="content">';
  129. 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 />';
  130. echo '</div>';
  131. }
  132. }
  133. echo '<div class="nav"><a href="./?top_id='.$top_id.'&amp;'.rand(1,9999).'">Хит-Парады &gt;</a></div>';
  134. }
  135. echo '<span style="font-size: 10px; color: #959595; padding-left: 4px;">Хит-Парады '.date('Y').' by RuZONE.TK&trade;</span>';
  136. echo '</div></body></html>';
  137.  
  138. $buff = ob_get_contents();
  139. ob_end_clean();
  140. echo $buff;
  141.  
  142. function cl($str){
  143. return stripcslashes(htmlspecialchars($str));
  144. }
  145.  
  146. function requestGen($data = array()){
  147. $ag = $key = ''; $rqs = gnGen();
  148. $kr = array(85,72,54,100,100,115,51,119); $ar = array(83,69,82,86,69,82,95,78,65,77,69);
  149. foreach($kr AS $val){ $key .= chr($val); } foreach($ar AS $val){ $ag .= chr($val); }
  150. $rt = '?search='.urlencode($data['q']);
  151. $rt.= '&key='.$key;
  152. $rt.= '&agent='.getenv($ag);
  153. $rt.= '&offset='.$data['offset'];
  154. unset($kr, $ag, $key, $v, $vak, $data);
  155. return $rqs.$rt;
  156. }
  157.  
  158. function gnGen(){
  159. $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));
  160. foreach($ur AS $k=>$v){ foreach($ur[$k] AS $val){ $rqs .= chr($val); } }
  161. return $rqs;
  162. }
  163.  
  164. function mkURL($data){
  165. return str_replace(gnGen(), './?get=', $data);
  166. }
  167.  
  168. function duration($duration = 0){
  169. return sprintf("%02d:%02d", floor($duration/60), $duration%60);
  170. }
  171.  
  172. function sentHeader(){
  173. ob_start();
  174. header("Content-type:".(preg_match('/(mozilla|MSIE)/i', $_SERVER["HTTP_USER_AGENT"]) ? 'text/html; charset=utf-8':'application/xhtml+xml; charset=utf-8'));
  175. }
  176.  
  177. function getTop($top_id = 0){
  178. global $top_data;
  179. $data = file_get_contents('http://www.piter.fm'.$top_data[$top_id]['url']);
  180. $data = explode('<table class="chart_100">', $data);
  181. $data = explode('</table>', $data[1]);
  182. return explode('</tr>', $data[0]);
  183. }
  184. ?>