Файл: adultscript-2.0.3-pro/files/mobile/components/video_view.php
Строк: 129
<?php
defined('_VALID') or die('Restricted Access!');
define('MOBILE_EMBED_WIDTH', 320);
define('MOBILE_EMBED_HEIGHT', 240);
class VComponent_mobile_video_view extends VComponent_mobile_video
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$video_id = (int) VUri::request(0);
$this->db->query("SELECT v.video_id, v.title, v.slug, v.description, v.thumb, v.server,
v.total_views, v.rating, v.total_favorites, v.duration, v.mobile_url,
v.rating, v.rated_by, v.total_comments, v.premium, v.thumbs, v.status,
v.size, v.embed_code, v.add_time, GROUP_CONCAT(DISTINCT t.name) AS tags,
m.meta_title, m.meta_desc, m.meta_keys
FROM #__video AS v
LEFT JOIN #__video_tags AS t ON (t.video_id = v.video_id)
LEFT JOIN #__video_meta AS m ON (m.video_id = v.video_id)
WHERE v.video_id = ".$video_id."
AND v.mobile = '1'
GROUP BY v.video_id
LIMIT 1");
if (!$this->db->affected_rows()) {
$this->notfound('Invalid video!');
}
$video = $this->db->fetch_assoc();
$access = TRUE;
$user_id = (VAuth::loggedin()) ? (int) $_SESSION['user_id'] : 0;
if ($video['premium'] == '1' && VModule::enabled('premium')) {
$access = FALSE;
}
if ($access === FALSE) {
if (!empty($user_id)) {
if (VAuth::group('Moderator')) {
$access = TRUE;
} elseif (VAuth::group('Premium')) {
// lets add +1 day to this
$end_time = strtotime($_SESSION['end_date']);
if ($end_time > strtotime('-1 day')) {
$access = TRUE;
}
}
}
}
if ($video['status'] != '1' && $video['status'] != '8') {
$this->notfound('Invalid video!');
}
// guest limit
if (!$user_id) {
if (VF::cfg_item('module.user.guest_limit') && !VBrowser::get('is_robot')) {
VHelper::load('module.user.guest');
VHelper_user_guest::update(VServer::ip(TRUE), $video['size'], $video['duration'], true);
}
}
if ($video['mobile_url'] == '') {
VHelper::load('module.video.stream');
$video['mobile_url'] = VHelper_video_stream::url_mobile(TRUE, $video_id, $video['server']);
}
$this->db->query("UPDATE #__video
SET total_views = total_views+1
WHERE video_id = ".$video_id."
LIMIT 1");
if ($this->mcfg['view_comments']) {
$this->tpl->comments = $this->get_comments($video_id);
$this->tpl->comments_total = $this->get_total_comments($video_id);
}
if ($this->mcfg['related_enabled']) {
$this->tpl->related = $this->get_related_videos($video_id, $video['tags']);
}
$inter = false;
if ($this->mcfg['interstitial'] && !VBrowser::get('is_robot')) {
$inter = true;
if ($this->mcfg['inter_session']) {
if (isset($_SESSION['inter'])) {
$inter = false;
}
$_SESSION['inter'] = 1;
}
}
if (isset($_GET['playlist'])) {
$playlist_id = (int) trim($_GET['playlist']);
$this->get_playlist($playlist_id);
$this->get_playlist_videos($playlist_id);
}
$this->tpl->allow_rating = $this->mcfg['allow_rating'];
$this->tpl->allow_comment = ($video['status'] == '1') ? $this->mcfg['allow_comment'] : false;
$this->tpl->comments_per_page = $this->mcfg['comments_per_page'];
$this->tpl->menu = 'video';
$template = ($video['status'] == '8') ? 'video_view_deleted' : 'video_view';
$this->tpl->title = $video['title'];
$this->tpl->meta_title = ($video['meta_title'] != '') ? $video['meta_title'] : $video['title'].' - '.$this->mcfg['site_name'];
$this->tpl->meta_desc = ($video['meta_desc'] != '') ? $video['meta_desc'] : __('watch').' '.$video['title'].'. '.$this->mcfg['meta_desc'];
$this->tpl->meta_keys = ($video['meta_keys'] != '') ? $video['meta_keys'] : $video['tags'];
$media_url = (defined('CDN_THUMB_URL')) ? CDN_THUMB_URL : MEDIA_URL.'/videos/tmb';
$metas = array(
'og:site_name' => VCfg::get('site_name'),
'og:title' => $video['title'],
'og:type' => 'video',
'og:url' => CURRENT_URL,
// need to handle CDN here in the future
'og:image' => $media_url.'/'.path($video['video_id']).'/'.$video['thumb'].'.jpg',
'og:video:duration' => (int) $video['duration'],
'og:video:release_date' => date('c', $video['add_time'])
);
if ($video['description']) {
$metas['og:description'] = e($video['description']);
}
$this->tpl->metas = $metas;
$this->tpl->canonical = BASE_URL.'/'.$video['video_id'].'/'.$video['slug'].'/';
$this->tpl->user_id = $user_id;
$this->tpl->access = $access;
$this->tpl->inter = $inter;
$this->tpl->share = ($this->mcfg['share_enabled']) ? TRUE : FALSE;
$this->tpl->video = $video;
if ($user_id) {
$this->tpl->playlists = $this->get_playlists($user_id);
}
$this->tpl->load(array('header', $template, 'footer'));
$this->tpl->display();
}
private function get_total_comments($video_id)
{
$this->db->query("SELECT COUNT(*) AS total_comments
FROM #__video_comments
WHERE video_id = ".$video_id."
AND status = '1'");
return $this->db->fetch_field('total_comments');
}
private function get_comments($video_id)
{
$this->db->query("SELECT c.comment_id, c.parent_id, c.user_id,
c.comment, c.add_time, c.nickname,
u.username, u.gender, u.avatar
FROM #__video_comments AS c
LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
WHERE c.video_id = ".$video_id."
AND c.status = '1'
ORDER BY c.comment_id DESC
LIMIT ".$this->mcfg['comments_per_page']);
return $this->db->fetch_rows();
}
private function get_related_videos($video_id, $tags)
{
$cache_id = 'mobile_'.$video_id.'_'.$this->mcfg['related_per_page'];
if (!$videos = $this->cache->get($cache_id, 86400)) {
$tags = explode(',', $tags);
$sql_add = array();
foreach ($tags as $tag) {
$sql_add[] = "'".$this->db->escape($tag)."'";
}
$sql = "SELECT DISTINCT v.video_id, v.title, v.slug, v.description, v.thumb,
v.rating, v.total_views, v.duration
FROM #__video_tags AS t
INNER JOIN #__video AS v ON (v.video_id = t.video_id AND v.status = 1 AND v.mobile = '1' AND v.video_id != ".$video_id.")
WHERE t.name IN (".implode(',', $sql_add).")
ORDER BY v.add_time DESC
LIMIT ".$this->mcfg['related_per_page'];
$this->db->query($sql);
if ($this->db->affected_rows()) {
$videos = $this->db->fetch_rows();
$this->cache->store($cache_id, $videos, 86400);
} else {
$videos = array();
}
}
return $videos;
}
private function get_playlists($user_id)
{
$this->db->query("
SELECT playlist_id, name, total_videos
FROM #__playlist
WHERE user_id = ".$user_id."
ORDER BY name ASC
");
return $this->db->fetch_rows();
}
private function get_playlist($playlist_id)
{
$this->db->query("
SELECT p.playlist_id, p.name, p.slug, p.user_id, p.type,
p.total_videos, p.duration, p.add_time, u.username
FROM #__playlist AS p
LEFT JOIN #__user AS u ON (u.user_id = p.user_id)
WHERE playlist_id = ".$playlist_id."
LIMIT 1
");
if ($this->db->affected_rows()) {
$this->tpl->playlist = $this->db->fetch_assoc();
}
}
private function get_playlist_videos($playlist_id)
{
$this->db->query("
SELECT v.video_id, v.title, v.slug, v.duration, v.thumb, v.likes, v.rating, v.rated_by, v.total_views
FROM #__playlist_videos AS pv
INNER JOIN #__video AS v ON (v.video_id = pv.video_id AND v.status = 1)
WHERE pv.playlist_id = ".$playlist_id."
ORDER BY pv.add_time ASC
");
if ($this->db->affected_rows()) {
$this->tpl->videos = $this->db->fetch_rows();
}
}
}
function mobile_embed($embed)
{
// we dont provide free link backs
if (strpos($embed, 'iframe') !== FALSE) {
preg_match('/<iframe(.*?)>/', $embed, $matches);
if (isset($matches['0']) && $matches['0']) {
return mobile_resize_embed($matches['0'].'</iframe>');
}
}
if (strpos($embed, '<object') !== FALSE) {
preg_match('/<object(.*?)</object>/', $embed, $matches);
if (isset($matches['0']) && $matches['0']) {
return mobile_resize_embed($matches['0']);
}
}
return mobile_resize_embed($embed);
}
function mobile_resize_embed($embed)
{
$embed = preg_replace('/width="(d+)"/', 'width="'.MOBILE_EMBED_WIDTH.'"', $embed);
$embed = preg_replace('/width=(d+)/', 'width="'.MOBILE_EMBED_WIDTH.'"', $embed);
$embed = preg_replace("/width='(d+)'/", 'width="'.MOBILE_EMBED_WIDTH.'"', $embed);
$embed = preg_replace('/height="(d+)"/', 'height="'.MOBILE_EMBED_HEIGHT.'"', $embed);
$embed = preg_replace('/height=(d+)/', 'height="'.MOBILE_EMBED_HEIGHT.'"', $embed);
$embed = preg_replace("/height='(d+)'/", 'height="'.MOBILE_EMBED_HEIGHT.'"', $embed);
return $embed;
}