Файл: adultscript-2.0.3-pro/files/modules/photo/components/category.php
Строк: 79
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_photo_category extends VModule_photo
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$args = $this->get_query(TRUE, 1);
$slug = $args['slug'];
$order = $args['order'];
$timeline = $args['timeline'];
$page = $args['page'];
$categories = $this->get_photo_categories();
foreach ($categories as $category) {
if ($slug == $category['slug']) {
$cat_id = (int) $category['cat_id'];
$name = ' '.$category['name'];
$desc = $category['description'];
break;
}
}
if (!isset($cat_id)) {
VModule::load('404', TRUE);
}
$url = 'photo/'.$slug.'/';
if ($order != 'recent' or $timeline or $page > 1) {
$url .= $order.'/';
}
if ($timeline) {
$url .= $timeline.'/';
}
if ($page > 1) {
$url .= $page.'/';
}
if (!VUri::match($url)) {
VModule::load('404', TRUE);
}
VLanguage::load('frontend.photo');
$sql_count = "SELECT COUNT(*) AS total_albums
FROM #__photo_category
WHERE cat_id = ".$cat_id;
$sql = "SELECT a.album_id, a.title, a.slug, a.rating, a.likes, a.rated_by, a.total_views,
a.total_photos, a.add_time, a.type, u.username
FROM #__photo_category AS pc
LEFT JOIN #__photo_albums AS a ON (a.album_id = pc.album_id AND a.status = '1')
LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
WHERE pc.cat_id = ".$cat_id;
$time_name = '';
if ($timeline) {
switch ($timeline) {
case 'today':
$sql .= " AND DATE_FORMAT(a.add_date, '%y-%m-%d') = DATE_FORMAT(NOW(), '%y-%m-%d')";
$sql_count .= " AND DATE_FORMAT(a.add_date, '%y-%m-%d') = DATE_FORMAT(NOW(), '%y-%m-%d')";
$time_name = __('todays').' ';
break;
case 'yesterday':
$sql .= " AND DATE_FORMAT(a.add_date, '%y-%m-%d') = DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
$sql_count .= " AND DATE_FORMAT(a.add_date, '%y-%m-%d') = DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
$time_name = __('yesterdays').' ';
break;
case 'week':
$time_name = __('this-weeks').' ';
break;
case 'month':
$sql .= " AND DATE_FORMAT(a.add_date, '%y-%m') = DATE_FORMAT(NOW(), '%y-%m')";
$sql_count .= " AND DATE_FORMAT(a.add_date, '%y-%m') = DATE_FORMAT(NOW(), '%y-%m')";
$time_name = __('this-months').' ';
break;
case 'year':
$sql .= " AND DATE_FORMAT(a.add_date, '%y') = DATE_FORMAT(NOW(), '%y')";
$sql_count .= " AND DATE_FORMAT(a.add_date, '%y') = DATE_FORMAT(NOW(), '%y')";
$time_name = __('this-years').' ';
break;
}
}
switch ($order) {
case 'recent':
$sql .= ' ORDER BY a.album_id DESC';
$order_name = ' '.__('most-recent');
break;
case 'popular':
$sql .= ' ORDER BY a.total_views DESC';
$order_name = ' '.__('popular');
break;
case 'discussed':
$sql .= ' ORDER BY a.total_comments DESC';
$order_name = ' '.__('most-discussed');
break;
case 'rated':
$sql .= ' ORDER BY (a.rating+a.rated_by) DESC';
$order_name = ' '.__('top-rated');
break;
case 'favorited':
$sql .= ' ORDER BY a.total_favorites DESC';
$order_name = ' '.__('most-favorites');
break;
default:
VModule::load('404', TRUE);
}
$total_albums = $this->db->get_field($sql_count, 'total_albums');
$pagination = VPagination::get($page, $total_albums, VCfg::get('photo.browse_per_page'));
$sql = $sql. ' LIMIT '.$pagination['limit'];
if (!$albums = $this->cache->get($sql, 3600)) {
$albums = $this->db->get_rows($sql);
$this->cache->store($sql, $albums, 3600);
}
$tpl = VF::factory('template');
$tpl->menu = 'photo';
$tpl->title = __('category-title', array(strtoupper($time_name.$order_name.$name)));
$tpl->meta_title = __('albums-meta-title', array($time_name.$order_name.$name, $page, $tpl->cfg['site_name']));
$tpl->css = array(TPL_REL.'/css/style_photo.css');
$tpl->canonical = BASE_URL.'/'.$url;
$tpl->canonicalm = MOBILE_URL.'/'.$url;
$tpl->slug = $slug;
$tpl->order = $order;
$tpl->timeline = $timeline;
$tpl->timename = $time_name;
$tpl->page = $page;
$tpl->albums = $albums;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'photo_albums', 'footer'));
$tpl->display();
}
}