<?php
/**
 * Created by PhpStorm.
 * User: ValekS
 * Date: 16.02.14
 * Time: 18:11
 */
define('_IN_JOHNCMS', 1);

require('../incfiles/core.php');

// подключение языкового файла
$lng_yt = core::load_lng('you_tube');
// вывод титлов страницы
$textl = isset($_REQUEST['n']) ? functions::checkout(trim($_REQUEST['n'])) : false;

require('../incfiles/head.php');

require('classes/youtube.php');

$vid = isset($_REQUEST['v']) ? trim($_REQUEST['v']) : false;

echo '<div class="phdr">'.$lng_yt['search_v'].'</div>';

if ($vid) {
    
	if (preg_match('/[^\dA-Za-z\_\-\#]+/', $vid)) {
        echo '<div class="rmenu">'.$lng_yt['error_watch1'].'</div>';
    } else {
			
		// Инициализируем видео, запрашиваем инфу о нём
		$youtube = new YouTube($vid, 1, 'relevance', '');
		$info = $youtube->search();
	
		if ($info) {
			echo '<div class="list1">';
				
			if (!$is_mobile) {
				echo '<p><iframe width="420" height="315" src="http://www.youtube.com/embed/'.$vid.'?rel=0" frameborder="0" allowfullscreen="true"></iframe></p>';
			} else {
				echo '<p><iframe width="305" height="200" src="http://www.youtube.com/embed/'.$vid.'?rel=0" frameborder="0" allowfullscreen="true"></iframe></p>';
			}
				
			echo '</div><div class="list2"><b>'.$lng_yt['src'].'</b><p>';
			echo '<img src="http://img.youtube.com/vi/'.$vid.'/1.jpg" alt="1" /> <img src="http://img.youtube.com/vi/'.$vid.'/2.jpg" alt="2" /> <img src="http://img.youtube.com/vi/'.$vid.'/3.jpg" alt="3" />';
			echo '</p></div><div class="list1">';
			echo '<h3>'.htmlspecialchars($info[0]['title']).'</h3>';
			echo '<b>'.$lng_yt['add'].'</b> '.$info[0]['date'].' | <b>'.$lng_yt['time'].'</b> '.$info[0]['time'].' | <b>'.$lng_yt['view'].'</b> '.$info[0]['views'].' | <b>'.$lng_yt['like'].'</b> '.$info[0]['likeCount'].' | <b>'.$lng_yt['dislike'].'</b> '.$info[0]['dislikeCount'].'';
			echo '<br/><br/>'.functions::checkout($info[0]['description'], 1, 1).'';
			echo '</div>';

			echo '<div class="list1">'.$lng_yt['downl_video'].'<br/>';
	
			$copy = str_replace('http://', '', $home);
	
			// Получаем ссылки на скачку видео
			$download = new Download();
			$links = $download->getDownloadLinks($vid);

			if ($links != NULL) {
				
				foreach ($links as $a => $b) {
					
					$size = size($b['2']);

					echo '>> <a href="'.htmlspecialchars($b['2'].'&title='.$copy.'-'.urlencode($info[0]['title'])).'">'.$b['0'].'('.$b['1'].')</a> '.$size.'<br/>';
				
				}
				
			} else {
				echo $lng_yt['error_watch2'];
			}
				
			echo '</div>';
			
		} else {
			echo '<div class="rmenu">'.$lng_yt['error_watch3'].'</div>';
		}
		
    }
	
} else {
    echo '<div class="rmenu">'.$lng_yt['error_watch4'].'</div>';
}

echo '<div class="phdr"><a href="'.($_SERVER['HTTP_REFERER'] ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index').'">'.$lng_yt['back'].'</a></div>';

require('../incfiles/end.php');