<?php
require_once 'inc/cached.php';
cachedTOP(18000);

require_once 'inc/mysqli.php';
include 'inc/functions.php';

if($_SERVER['REQUEST_URI'] == '/singer-song.php?name='.$_GET['name'].(isset($_GET['page']) ? '&page='.$_GET['page'] : null)){
	header("HTTP/1.1 301 Moved Permanently"); 
	header('Location: /singer-song/'.$_GET['name'].'/'.(isset($_GET['page']) ? $_GET['page'].'/' : null));
	exit;
}

if($_GET['page'] == 1){
	header("HTTP/1.1 301 Moved Permanently"); 
	header('Location: /singer-song/'.$_GET['name'].'/');
	exit;
}

function singerConvert($string) {

    $converter = array(

        'aRU' => 'а',   'bRU' => 'б',   'vRU' => 'в',

        'gRU' => 'г',   'dRU' => 'д',   'eRU' => 'е',

        'zhRU' => 'ж',  'zRU' => 'з',

        'iRU' => 'и',   'kRU' => 'к',

        'lRU' => 'л',   'mRU' => 'м',   'nRU' => 'н',

        'oRU' => 'о',   'pRU' => 'п',   'rRU' => 'р',

        'sRU' => 'с',   'tRU' => 'т',   'uRU' => 'у',

        'fRU' => 'ф',   'hRU' => 'х',   'cRU' => 'ц',

        'chRU' => 'ч',  'shRU' => 'ш',  'schRU' => 'щ',

        'eeRU' => 'э',   'yuRU' => 'ю',  'yaRU' => 'я');

    return strtr($string, $converter);

}

$title = 'Популярная музыка на букву '.mb_strtoupper(singerConvert(htmlspecialchars($_GET['name'])), 'UTF-8').' » музыкальные новинки 2018 бесплатно на телефон в хорошем качестве'.(!empty($_GET['page']) ? ' | Страница '.$_GET['page'] : null);
$desc = 'Скачать музыку бесплатно по алфавиту на мобильный телефон или слушать онлайн в хорошем качестве в mp3 формате';
$key = 'музыка по алфавиту, мобильный, телефон, скачать, бесплатно, слушать, mp3, формате, качестве, исполнители, без регистрации';

$singer_list = true;
$singer_type = 'song';

if($_GET['page'] >= 2){
	$canonical = 'singer-song/'.$_GET['name'].'/';
}

include 'inc/head.php';

?>

<div class="left-menu">
<div class="blok-speedbar">  
<span id="speedbar">
  <span itemscope itemtype="https://www.schema.org/SiteNavigationElement">
	<span itemprop="name"><a href="/" itemprop="url">Главная</a></span> 
	  <?php
		echo ' » Музыка на букву '.mb_strtoupper(singerConvert(htmlspecialchars($_GET['name'])), 'UTF-8').(!empty($_GET['page']) ? ' | Страница '.intval($_GET['page']) : null);
	   ?>
	</span>
</span>
</div>
  <div class="main-block">
    <div class="block-title"><h1>Музыка на букву <?=mb_strtoupper(singerConvert(htmlspecialchars($_GET['name'])), 'UTF-8')?></h1><img src="<?=URL?>style/img/title.png" alt="<?=mb_strtoupper(singerConvert(htmlspecialchars($_GET['name'])), 'UTF-8')?>"></div>
	  <ul class="playlist" itemscope itemtype="https://schema.org/MusicGroup">

			<?php 
				$num = set('pages', $db);  
				$posts  = $db->query("SELECT `id` FROM `files` WHERE `first_letter_t` = ?s", singerConvert($_GET['name']));
				$total = intval(($db->numRows($posts) - 1) / $num) + 1; 
				$page = (isset($_GET['page']) ? intval($_GET['page']) : 1);
				if(empty($page) or $page < 0) $page = 1;  
				if($page > $total) $page = $total; 
				$start = $page * $num - $num;
				total_page($_GET['page'],$total,'/singer-song/'.$_GET['name'].'/'.$total.'/');
				
				$data = $db->getAll("SELECT * FROM `files` WHERE `first_letter_t` = ?s ORDER BY `date_add` DESC LIMIT ?i, ?i", singerConvert($_GET['name']), $start, $num);
				foreach($data as $file){
					
				$time_schema = explode(':', $file['playtime_string']);
					
			?>
			
				<li itemprop="track" itemscope itemtype="https://schema.org/MusicRecording">
				<meta itemprop="name" content="<?=$file['artist']?> - <?=$file['title']?>">
				
                    <div class="playlist-btn">
						<a rel="nofollow" href="javascript:void(0);" class="playlist-play no-ajax" data-url="<?=URL?>play/<?=base64_encode($file['filename'])?>/" title="Слушать <?=$file['name_full']?>">(Слушать <?=$file['name_full']?>)</a>
                    </div>

                    <div class="playlist-right">
                        <span class="playlist-duration" itemprop="duration" content="PT<?=$time_schema[0]?>M<?=$time_schema[1]?>S"><?=$file['playtime_string']?></span>
                    </div>
					<a itemprop="url" href="/song/<?=$file['id']?>/<?=rus2eng(str2url($file['artist'].' '.$file['title']))?>/">
						<div class="playlist-name marquee">
							<span class="playlist-name-artist"><b><?=$file['artist']?></b></span><br />
							<span class="playlist-name-title"><em><?=$file['title']?></em></span>
						</div>
					</a>
                </li>
			
			<?php
				}
			?>

        </ul>
<?=page('/singer-song/'.$_GET['name'].'/',$total,$page);?>
</div>
<div style="clear: both;"></div>
</div>

<?php include 'inc/right.php'; ?>
<?php include 'inc/foot.php'; ?>