Файл: onlinepoisk.wm-scripts.ru/controller/index.php
Строк: 227
<?php
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRedirectResponse;
use PagerfantaPagerfanta;
use PagerfantaViewDefaultView;
$app->error(function ($code) use($app){
$seo = Reg::get('seo');
$seo['title'] = "Error 404";
Reg::set('seo', $seo);
return $app['view']->render('layout.phtml', 'index/404.phtml', array(
));
});
$app->get('/', function(Request $request) use($app) {
if ( $q = $request->get('q') ) {
$query = $app->escape($q);
return new RedirectResponse("./search/{$query}");
}
$lastfmdata = ArtLastFM::request($app['conf'], "chart.getTopArtists", array(
"limit" => $app['conf']->getOption('app', 'catalogLimit', 50)
));
$similars = array();
if ( substr_count($artist, " ") <= 4 ) {
$lastfmdatae = ArtLastFM::request($app['conf'], "tag.getTopAlbums", array(
'tag' => 'russia',
'limit' =>12
));
if ( isset($lastfmdatae->topalbums) ) {
$similars = $lastfmdatae->topalbums->album;
}
}
return $app['view']->render('layout.phtml', 'index/index.phtml', array(
'artists' => $lastfmdata,
'similars' => $similars
));
});
$app->get('/charts', function() use ($app) {
set_time_limit('90');
$key = 'moskvafm_stations';
$radios = SearchMusicCache::get($key);
if ( !$radios ) {
require_once ROOT . '/vendor/simple_html_dom.php';
$html = file_get_html("http://www.moskva.fm/stations");
$radios = array();
foreach( $html->find('.msk-thumbnail-station') as $element ) {
$radios[] = array(
'href' => $element->find('.logo', 0)->href,
'src' => $element->find('.logo img', 0)->src,
'name' => $element->find('h4 .station b', 0)->plaintext,
'href2' => str_replace('http://www.moskva.fm/stations/', '', $element->find('.logo', 0)->href)
);
}
SearchMusicCache::set($key, serialize($radios), 60*60*24*365);
} else {
$radios = unserialize($radios);
}
// array_slice($radios, 40);
$seo = Reg::get('seo');
$seo['title'] = "Хит-парады радиостанций";
$seo['description'] = "Топ хиты московских радио станций";
$seo['keywords'] = "Хит-парады, хиты 2013, слушать радио, скачать мп3, бесплатно";
Reg::set('seo', $seo);
return $app['view']->render('layout.phtml', 'index/radio.phtml', array(
'radios' => $radios
));
});
$app->get('/charts/{name}/{alias}', function($name, $alias) use ($app) {
$seo = Reg::get('seo');
$seo['title'] = "Топ 10 {$name}";
$seo['description'] = "Топ 10 {$name}";
$seo['keywords'] = "{$name}";
Reg::set('seo', $seo);
set_time_limit('180');
$cachekey = "moskvafm_station_{$alias}";
$tracks = SearchMusicCache::get($cachekey);
if ( !$tracks ) {
require_once ROOT . '/vendor/simple_html_dom.php';
$url = "http://www.moskva.fm/stations/{$alias}/top100";
$html = file_get_html($url);
$tracks = array();
foreach ( $html->find('.js-song') as $key => $element ) {
$artist = $element->find('.artist', 0)->plaintext;
$song = $element->find('.song', 0)->plaintext;
$q = "{$artist} {$song}";
$vtrack = $app['searchmusic']->audioSearch( $q, 0, 1 );
$vtrack = reset($vtrack['result']);
$tracks[] = array(
'vkid' => "{$vtrack['owner_id']}_{$vtrack['aid']}",
'lyrics_id' => isset($vtrack['lyrics_id']) ? $vtrack['lyrics_id'] : null,
'artist' => $artist,
'title' => $song,
'duration' => $vtrack['duration']
);
if ( $key+1 >= 10 ) {
break;
usleep(200000);
}
}
SearchMusicCache::set($cachekey, serialize($tracks), 60*60*24*7);
} else {
$tracks = unserialize($tracks);
}
foreach ( $tracks as $key => $track ) {
if ( !$track['duration'] ) {
$q = "{$track['artist']} {$track['title']}";
$vtrack = $app['searchmusic']->audioSearch($q, 0, 1);
$vtrack = reset($vtrack['result']);
$tracks[$key] = array(
'vkid' => "{$vtrack['owner_id']}_{$vtrack['aid']}",
'lyrics_id' => isset($vtrack['lyrics_id']) ? $vtrack['lyrics_id'] : null,
'artist' => $track['artist'],
'title' => $track['title'],
'duration' => $vtrack['duration']
);
}
usleep(200000);
}
return $app['view']->render('layout.phtml', 'index/radio-item.phtml', array(
'tracks' => $tracks,
'name' => $name,
'alias' => $alias
));
});
$app->get('/genre', function() use ($app) {
$seo = Reg::get('seo');
$seo['title'] = "Жанры";
$seo['description'] = "Жанры всех музыкальных направлений";
$seo['keywords'] = "Жанры, теги, исполнители, певец, слушать, альбомы";
Reg::set('seo', $seo);
$tags = ArtLastFM::request($app['conf'], "tag.getTopTags", array(
));
return $app['view']->render('layout.phtml', 'index/tags.phtml', array(
'tags' => $tags
));
});
$app->get('/genre/{tag}', function($tag) use ($app) {
$tag = html_entity_decode($tag);
$tag = str_replace('+', ' ', $tag);
$seo = Reg::get('seo');
$seo['title'] = "Музыкальное направление";
$seo['description'] = "музыкальное направление";
$seo['keywords'] = "скачать, бесплатно";
Reg::set('seo', $seo);
$lastfmdata = ArtLastFM::request($app['conf'], "tag.getTopArtists", array(
'tag' => $tag,
"limit" => $app['conf']->getOption('app', 'catalogLimit', 100)
));
// hack
$data = new stdClass;
$data->artists = $lastfmdata ? $lastfmdata->topartists : null;
$similar = ArtLastFM::request($app['conf'], "tag.getSimilar", array(
'tag' => $tag,
));
$tag = ArtLastFM::request($app['conf'], "tag.getInfo", array(
'tag' => $tag,
'lang' => 'ru'
));
return $app['view']->render('layout.phtml', 'index/index.phtml', array(
'tag' => $tag,
'artists' => $data,
'similar' => $similar
));
});
$app->get('/{artist}/album/{album}', function($artist, $album) use ($app) {
$album = str_replace('+', ' ', $album);
$seo = Reg::get('seo');
$seo['title'] = "{$artist} скачать альбом {$album} mp3";
$seo['description'] = "прослушать онлайн";
$seo['keywords'] = "скачать";
Reg::set('seo', $seo);
$app = Reg::get('app');
$lastfmdata = ArtLastFM::request($app['conf'], "album.getInfo", array(
'album' => $album,
'artist' => $artist,
'lang' => 'ru',
'autocorrect' => 1
));
set_time_limit('180');
$cachekey = "album_{$album}";
$tracks = SearchMusicCache::get($cachekey);
if ( !$tracks ) {
require_once ROOT . '/vendor/simple_html_dom.php';
$tracks = array();
if ( isset($lastfmdata->album->tracks) ) {
$tracks = $lastfmdata->album->tracks->track;
}
if ( !is_array($tracks) ) {
$tracks = array($tracks);
}
$rtracks = array();
foreach ( $tracks as $track ) {
$artist = $track->artist->name;
$name = $track->name;
$q = "{$artist} {$name}";
$vtrack = $app['searchmusic']->audioSearch( $q, 0, 1 );
$vtrack = reset($vtrack['result']);
$rtracks[] = array(
'vkid' => "{$vtrack['owner_id']}_{$vtrack['aid']}",
'lyrics_id' => isset($vtrack['lyrics_id']) ? $vtrack['lyrics_id'] : null,
'artist' => $artist,
'title' => $name,
'duration' => $vtrack['duration']
);
usleep(200000);
}
SearchMusicCache::set($cachekey, serialize($tracks), 60*60*24*7);
} else {
$tracks = unserialize($tracks);
}
foreach ( $tracks as $key => $track ) {
$artist = $track->artist->name;
$name = $track->name;
$q = "{$artist} {$name}";
$vtrack = $app['searchmusic']->audioSearch( $q, 0, 1 );
$vtrack = reset($vtrack['result']);
$rtracks[$key] = array(
'vkid' => "{$vtrack['owner_id']}_{$vtrack['aid']}",
'lyrics_id' => isset($vtrack['lyrics_id']) ? $vtrack['lyrics_id'] : null,
'artist' => $artist,
'title' => $name,
'duration' => $vtrack['duration']
);
}
Reg::set('artist', $artist);
$artists = ArtLastFM::request($app['conf'], "artist.getInfo", array(
"artist" => $artist,
'lang' => 'ru'
));
Reg::set('artist', $artist);
$albums = ArtLastFM::request($app['conf'], "album.getInfo", array(
'album' => $album,
'artist' => $artist,
'lang' => 'ru',
'autocorrect' => 1
));
$similars = array();
if ( substr_count($artist, " ") <= 4 ) {
$lastfmdata = ArtLastFM::request($app['conf'], "artist.getTopAlbums", array(
"limit" => 30,
"artist" => $artist,
" autocorrect" => 1
));
if ( isset($lastfmdata->topalbums) ) {
$similars = $lastfmdata->topalbums->album;
}
}
return $app['view']->render('layout.phtml', 'part/album.phtml', array(
'artist' => $artist,
'album' => $album,
'tracks' => $rtracks,
'albums' => $albums,
'artists' => $artists,
'similars' => $similars
));
});
$app->get('toptracks/{artist}', function($artist) use ($app) {
$seo = Reg::get('seo');
$seo['title'] = "топ популярных треков {$artist}";
$seo['description'] = "топ популярных треков";
$seo['keywords'] = "популярные mp3, слушать, скачать, бесплатно";
Reg::set('seo', $seo);
$app = Reg::get('app');
$lastfmdata = ArtLastFM::request($app['conf'], "artist.getTopTracks", array(
'limit' => 20,
'artist' => $artist,
'autocorrect' => 1
));
$toptracks = array();
if ( isset($lastfmdata->toptracks) ) {
$toptracks = $lastfmdata->toptracks->track;
}
$rtracks = array();
foreach ( $toptracks as $track ) {
$artist = $track->artist->name;
$name = $track->name;
$q = "{$artist} {$name}";
$vtrack = $app['searchmusic']->audioSearch( $q, 0, 1 );
$vtrack = reset($vtrack['result']);
$rtracks[] = array(
'vkid' => "{$vtrack['owner_id']}_{$vtrack['aid']}",
'lyrics_id' => isset($vtrack['lyrics_id']) ? $vtrack['lyrics_id'] : null,
'artist' => $artist,
'title' => $name,
'duration' => $vtrack['duration']
);
usleep(200000);
}
$similars = array();
if ( substr_count($artist, " ") <= 4 ) {
$lastfmdata = ArtLastFM::request($app['conf'], "artist.getTopAlbums", array(
"limit" => 30,
"artist" => $artist,
" autocorrect" => 1
));
if ( isset($lastfmdata->topalbums) ) {
$similars = $lastfmdata->topalbums->album;
}
}
Reg::set('artist', $artist);
$artists = ArtLastFM::request($app['conf'], "artist.getInfo", array(
"artist" => $artist,
'lang' => 'ru'
));
return $app['view']->render('layout.phtml', 'part/toptracks.phtml', array(
'artist' => $artist,
'toptracks' => $rtracks,
'album' => $album,
'similars' => $similars,
'artists' => $artists
));
});
$app->get('/{artist}/allalbum', function($artist) use ($app) {
$seo = Reg::get('seo');
$seo['title'] = "все альбомы {$artist}";
$seo['description'] = "прослушать онлайн";
$seo['keywords'] = " бесплатно";
Reg::set('seo', $seo);
$similars = array();
if ( substr_count($artist, " ") <= 4 ) {
$lastfmdata = ArtLastFM::request($app['conf'], "artist.getTopAlbums", array(
"limit" => 50,
"artist" => $artist,
" autocorrect" => 1
));
if ( isset($lastfmdata->topalbums) ) {
$similars = $lastfmdata->topalbums->album;
}
}
return $app['view']->render('layout.phtml', 'part/allalbum.phtml', array(
'artist' => $artist,
'album' => $album,
'tracks' => $rtracks,
'albums' => $albums,
'artists' => $artists,
'similars' => $similars
));
});
$app->get('/playlist/{id}', function($id) use($app) {
$seo = Reg::get('seo');
$seo['title'] = "Плейлист {$id} ";
$seo['description'] = "Плейлист № {$id}";
$seo['keywords'] = " бесплатно, Плейлист";
Reg::set('seo', $seo);
$pl = ModelPl::find_by_id($id);
$pl_tracks = ModelPlTrack::find_all_by_plid($id);
return $app['view']->render('layout.phtml', 'index/playlist.phtml', array(
'tracks' => $pl_tracks,
'pl' => $pl,
'id' => $id
));
});
$app->get('/about', function() use($app) {
return $app['view']->render('layout.phtml', 'index/about.phtml', array(
));
});
$app->get('/contact', function() use($app) {
return $app['view']->render('layout.phtml', 'index/contact.phtml', array(
));
});
$app->get('/tag', function() use($app) {
return $app['view']->render('layout.phtml', 'index/tag.phtml', array(
));
});
$app->get('/radio', function() use($app) {
$seo = Reg::get('seo');
$seo['title'] = "Слушать онлайн радио";
$seo['description'] = "Бесплатное онлайн радио";
$seo['keywords'] = " бесплатно, радио";
Reg::set('seo', $seo);
return $app['view']->render('layout.phtml', 'part/radio.phtml', array(
));
});
/*
Техническая поддержка и обновления
http://wm-scripts.ru
*/