Файл: adultscript-2.0.3-pro/files/modules/video/components/playlists.php
Строк: 117
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_video_playlists extends VModule_video
{
public function __construct()
{
parent::__construct();
}
public function render()
{
if (!VCfg::get('video.playlists')) {
VModule::load('404', true);
}
$errors = array();
$messages = array();
$query = $this->get_playlists_query();
$order = $query['order'];
$timeline = $query['timeline'];
$page = $query['page'];
$url = 'playlists/'.$order.'/';
if ($timeline != 'all') {
$url .= $timeline.'/';
}
if ($page > 1) {
$url .= $page.'/';
}
if ($order == 'recent' && $timeline == 'all' && $page === 1) {
$url = 'playlists/';
}
if (!VUri::match($url)) {
VModule::load('404', true);
}
VLanguage::load('frontend.video');
$sql = "SELECT p.playlist_id, p.user_id, p.name, p.type, p.slug, p.likes, p.rated_by,
p.total_videos, p.duration, p.thumb_id, v.thumb, v.slug as vslug
FROM #__playlist AS p
LEFT JOIN #__video AS v ON (v.video_id = p.thumb_id AND v.status = 1)";
$sql_count = "SELECT COUNT(*) AS total_playlists
FROM #__playlist AS p";
$time_name = '';
if ($timeline) {
switch ($timeline) {
case 'today':
$start_time = strtotime('today');
$end_time = $start_time+86400;
$sql .= " WHERE p.add_time > ".$start_time." AND p.add_time < ".$end_time;
$sql_count .= " WHERE p.add_time > ".$start_time." AND p.add_time < ".$end_time;
$time_name = __('todays').' ';
break;
case 'yesterday':
$start_time = strtotime('yesterday');
$end_time = $start_time+86400;
$sql .= " WHERE p.add_time > ".$start_time." AND p.add_time < ".$end_time;
$sql_count .= " WHERE p.add_time > ".$start_time." AND p.add_time < ".$end_time;
$time_name = __('yesterdays').' ';
break;
case 'week':
$now = time();
$start_time = (date('w', $now) === 1) ? strtotime('today', $now) : strtotime('last Monday', $now);
$sql .= " WHERE p.add_time > ".$start_time;
$sql_count .= " WHERE p.add_time > ".$start_time;
$time_name = __('this-weeks').' ';
break;
case 'month':
$start_time = strtotime('first day of '.date('F Y'));
$sql .= " WHERE p.add_time > ".$start_time;
$sql_count .= " WHERE p.add_time > ".$start_time;
$time_name = __('this-months').' ';
break;
case 'year':
$start_time = strtotime(date('Y').'-01-01');
$sql .= " WHERE p.add_time > ".$start_time;
$sql_count .= " WHERE p.add_time > ".$start_time;
$time_name = __('this-years').' ';
break;
}
}
$order_name = '';
if ($order == 'recent') {
$sql .= " ORDER BY p.add_time DESC";
$order_name = __('recent');
} elseif ($order == 'popular') {
$sql .= " ORDER BY p.total_views DESC";
$order_name = __('popular');
} elseif ($order == 'rated') {
$sql .= " ORDER BY p.likes DESC";
$order_name = __('rated');
} elseif ($order == 'favorited') {
$sql .= " ORDER BY p.total_favorites DESC";
$order_name = __('favorited');
}
$total_playlists = $this->db->get_field($sql_count, 'total_playlists');
$pagination = VPagination::get($page, $total_playlists, VCfg::get('video.playlists_per_page'));
$sql = $sql. ' LIMIT '.$pagination['limit'];
if (!$playlists = $this->cache->get($sql, 3600)) {
$playlists = $this->db->get_rows($sql);
$this->cache->store($sql, $playlists, 3600);
}
$page_name = ($page > 1 ) ? ' - '.__('page').' '.$page : '';
$this->tpl->menu = 'playlist';
$this->tpl->title = __('playlists-title', array($time_name.$order_name, $page_name));
$this->tpl->meta_title = __('playlists-meta-title', array($time_name.$order_name, $page_name, VF::cfg_item('site_name')));
$this->tpl->meta_desc = $this->tpl->meta_title.'. '.VF::cfg_item('meta_desc');
$this->tpl->canonical = BASE_URL.'/'.$url;
$this->tpl->mcanonical = ($page > 1) ? MOBILE_URL.'/playlists/'.$page.'/' : MOBILE_URL.'/playlists/';
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->order = $order;
$this->tpl->timeline = $timeline;
$this->tpl->page = $page;
if ($page > 1) {
$this->tpl->prev_url = build_playlists_url($order, $timeline, $page-1, true);
}
if ($page < $pagination['total_pages']) {
$this->tpl->next_url = build_playlists_url($order, $timeline, $page+1, true);
}
$this->tpl->playlists = $playlists;
$this->tpl->pagination = $pagination;
$this->tpl->load(array('header', 'video_playlists', 'footer'));
$this->tpl->display();
}
private function get_playlists_query()
{
$options = array(
'order' => 'recent',
'timeline' => 'all',
'page' => 1,
'clean' => false
);
$query = array_slice(VUri::query(), 1);
$orders = array('recent' => 1, 'rated' => 1, 'popular' => 1, 'favorited' => 1);
$timelines = array('today' => 1, 'yesterday' => 1, 'week' => 1, 'month' => 1, 'year' => 1, 'all' => 1);
$arg = (isset($query['0']) && $query['0'] != '') ? $query['0'] : null;
if (isset($arg)) {
if (isset($orders[$arg])) {
$options['order'] = $arg;
array_shift($query);
} else {
VModule::load('404', true);
}
}
$arg = (isset($query['0']) && $query['0'] != '') ? $query['0'] : null;
if (isset($arg)) {
if (ctype_digit($arg)) {
$options['page'] = (int) $arg;
} elseif (isset($timelines[$arg])) {
$options['timeline'] = $arg;
array_shift($query);
} else {
VModule::load('404', true);
}
}
if (isset($query['0']) && ctype_digit($query['0'])) {
$options['page'] = (int) $query['0'];
}
if ($options['page'] === 0) {
VModule::load('404', true);
}
return $options;
}
}
function build_playlists_url($order, $timeline = '', $page = 1, $base = false)
{
$url = ($base) ? BASE_URL.'/playlists/' : REL_URL.'/playlists/';
if ($order != '') {
$url .= $order.'/';
}
if ($timeline != 'all') {
$url .= $timeline.'/';
}
if ($page === true) {
$url .= '#PAGE#/';
} elseif ($page !== 1) {
$url .= $page.'/';
}
return $url;
}