Файл: adultscript-2.0.3-pro/files/modules/channel/components/view.php
Строк: 207
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_channel_view extends VModule_channel
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$slug = VUri::request(1);
$url = 'channel/'.$slug.'/';
if (!VUri::match($url)) {
VModule::load('404', true);
}
$this->db->query("
SELECT channel_id, name, slug, description, url, thumb,
total_views, total_videos, total_likes, total_votes,
total_subscribers, last_add_time, adv_bottom_id, adv_right_id
FROM #__channel
WHERE slug = '".$this->db->escape($slug)."'
LIMIT 1
");
if (!$this->db->affected_rows()) {
VModule::load('404', true);
}
$channel = $this->db->fetch_assoc();
$channel_id = (int) $channel['channel_id'];
$user_id = (isset($_SESSION['user_id'])) ? (int) $_SESSION['user_id'] : 0;
VLanguage::load('frontend.channel');
if (!VBrowser::get('is_robot')) {
$this->db->query("
UPDATE #__channel
SET total_views = total_views+1
WHERE channel_id = ".$channel_id."
LIMIT 1
");
}
$order = (isset($_GET['o'])) ? trim($_GET['o']) : 'recent';
$orders = array('recent' => 1, 'popular' => 1, 'discussed' => 1, 'rating' => 1, 'watched' => 1, 'downloaded' => 1, 'longest' => 1);
if (!isset($orders[$order])) {
VModule::load('404', true);
}
$timeline = (isset($_GET['t'])) ? trim($_GET['t']) : 'all';
$timelines = array('today' => 1, 'yesterday' => 1, 'week' => 1, 'month' => 1, 'year' => 1);
if ($timeline != 'all' && !isset($timelines[$timeline])) {
VModule::load('404', true);
}
$duration = (isset($_GET['d'])) ? trim($_GET['d']) : 'all';
$durations = array('short' => 1, 'medium' => 1, 'long' => 1);
if ($duration != 'all' && !isset($durations[$duration])) {
VModule::load('404', true);
}
$page = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$sql = "SELECT v.video_id, v.title, v.slug, v.likes, v.rating, v.rated_by, v.duration, v.thumb,
v.thumbs, v.total_views, v.add_time, v.ext, v.hd, v.premium, v.hd,
u.username
FROM #__video AS v
LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
WHERE v.channel_id = ".$channel_id."
AND v.status = 1";
$sql_count = "SELECT COUNT(*) AS total_videos
FROM #__video AS v
WHERE v.channel_id = ".$channel_id."
AND v.status = 1";
$time_name = '';
if ($timeline == 'today') {
$sql .= " AND v.add_time > ".strtotime('12:00:00');
$sql_count .= " AND v.add_time > ".strtotime('12:00:00');
$time_name = __('todays').' ';
} elseif ($timeline == 'yesterday') {
$sql .= " AND v.add_time > ".strtotime("-1 day", strtotime('12:00:00'));
$sql_count .= " AND v.add_time > ".strtotime("-1 day", strtotime('12:00:00'));
$time_name = __('yesterdays').' ';
} elseif ($timeline == 'week') {
$start = mktime(0, 0, 0, date("n"), date("j") - date("N") + 1);
$sql .= " AND v.add_time > ".$start;
$sql_count .= " AND v.add_time > ".$start;
$time_name = __('this-weeks').' ';
} elseif ($timeline == 'month') {
$start = mktime(0, 0, 0, date("n"), 1);
$sql .= " AND v.add_time > ".$start;
$sql_count .= " AND v.add_time > ".$start;
$time_name = __('this-months').' ';
} elseif ($timeline == 'year') {
$start = mktime(0, 0, 0, 1, 1, date('Y'));
$sql .= " AND v.add_time > ".$start;
$sql_count .= " AND v.add_time > ".$start;
$time_name = __('this-years').' ';
}
$duration_name = '';
if ($duration == 'short') {
$sql .= " AND v.duration < 300";
$sql_count .= " AND v.duration < 300";
$duration_name = __('short').' ';
} elseif ($duration == 'medium') {
$sql .= " AND (v.duration > 300 AND v.duration < 1200)";
$sql_count .= " AND (v.duration > 300 AND v.duration < 1200)";
$duration_name = __('medium').' ';
} elseif ($duration == 'long') {
$sql .= " AND v.duration > 1200";
$sql_count .= " AND v.duration > 1200";
$duration_name = __('long').' ';
}
$order_name = '';
if ($order == 'recent') {
$sql .= " ORDER BY v.add_time DESC";
$order_name = __('most-recent');
} elseif ($order == 'popular') {
$sql .= " ORDER BY v.total_views DESC";
$order_name = __('most-popular');
} elseif ($order == 'discussed') {
$sql .= " ORDER BY v.total_comments DESC";
$order_name = __('most-discussed');
} elseif ($order == 'rated') {
$sql .= " ORDER BY v.rating DESC";
$order_name = __('most-rated');
} elseif ($order == 'downloaded') {
$sql .= " ORDER BY v.total_downloads DESC";
$order_name = __('most-downloads');
} elseif ($order == 'longest') {
$sql .= " ORDER BY v.duration DESC";
$order_name = __('longest');
} elseif ($order == 'watched') {
$sql .= " ORDER BY v.view_time DESC";
$order_name = __('watched');
}
$total_videos = $this->db->get_field($sql_count, 'total_videos');
$pagination = VPagination::get($page, $total_videos, VF::cfg_item('module.channel.videos_per_page'));
$videos = $this->db->get_rows($sql.' LIMIT '.$pagination['limit']);
$page_add = ($page > 1) ? ' - '.__('page').' '.$page : '';
$add = $channel['name'].' '.__('channel').$page_add;
$this->tpl->menu = 'channel';
$this->tpl->css = array(TPL_REL.'/css/style_channel.css');
$this->tpl->meta_title = __('channel-meta-title', array($add, VF::cfg_item('site_name')));
$this->tpl->meta_desc = __('channel-meta-desc', array($add, VF::cfg_item('meta_desc')));
$this->tpl->canonical = BASE_URL.'/'.$url;
$this->tpl->canonicalm = MOBILE_URL.'/'.$url;
$this->tpl->order = $order;
$this->tpl->orders = $orders;
$this->tpl->timeline = $timeline;
$this->tpl->timelines = $timelines;
$this->tpl->duration = $duration;
$this->tpl->durations = $durations;
$this->tpl->page = $page;
$this->tpl->channel = $channel;
$this->tpl->videos = $videos;
$this->tpl->pagination = $pagination;
$this->tpl->is_subscribed = ($user_id) ? $this->is_subscribed($channel_id, $user_id) : false;
$this->tpl->load(array('header', 'channel_view', 'footer'));
$this->tpl->display();
}
private function is_subscribed($channel_id, $user_id)
{
$this->db->query("
SELECT channel_id
FROM #__channel_subscribers
WHERE channel_id = ".$channel_id."
AND user_id = ".$user_id."
LIMIT 1
");
return $this->db->affected_rows();
}
}
function build_url($slug, $order, $timeline = 'all', $page = 1)
{
$url = RELATIVE_URL.'/channel/'.$slug.'/';
$query = array();
if ($order != '') {
$query['o'] = $order;
}
if ($timeline != 'all') {
$query['t'] = $timeline;
}
if ($page > 1) {
$query['page'] = $page;
}
return ($query)
? $url.'?'.http_build_query($query)
: $url;
}