Файл: adultscript-2.0.3-pro/files/modules/news/components/browse.php
Строк: 94
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_news_browse extends VModule_news
{
public function __construct()
{
parent::__construct();
}
public function render()
{
VLanguage::load('frontend.news');
$args = $this->get_args(array_slice(VUri::query(), 1));
$page = (isset($args['page']) && $args['page'] >= 2) ? $args['page'] : 1;
$url = 'news/';
if (isset($args['year']) && isset($args['month'])) {
$url .= $args['year'].'/'.$args['month'].'/';
}
if ($page > 1) {
$url .= $page.'/';
}
if (!VUri::match($url)) {
VModule::load('404', true);
}
$sql_add = NULL;
$sql_delim = ' WHERE';
$date_name = '';
if (isset($args['year']) && isset($args['month'])) {
$timestamp = strtotime($args['year'].'-'.$args['month'].'-01 00:00:00');
$sql_add = " WHERE DATE_FORMAT(n.add_date, '%y-%m') = DATE_FORMAT(FROM_UNIXTIME(".$timestamp."), '%y-%m')";
$sql_delim = ' AND';
$date_name = $args['year'].'-'.$args['month'].' ';
}
$sql_count = "SELECT COUNT(*) AS total_articles
FROM #__news AS n".$sql_add.$sql_delim." n.status = '1'";
$total_articles = $this->db->get_field($sql_count, 'total_articles');
$pagination = VPagination::get($page, $total_articles, 5);
$sql = "SELECT n.news_id, n.user_id, n.title, n.slug, n.content,
n.add_date, n.total_views, u.username
FROM #__news AS n
INNER JOIN #__user AS u ON (u.user_id = n.user_id)
".$sql_add.$sql_delim." n.status = '1'
ORDER BY n.add_date DESC
LIMIT ".$pagination['limit'];
$articles = $this->db->get_rows($sql);
$page_name = ($page > 1)? ' - '.__('page').' '.$page : '';
$tpl = VF::factory('template');
$tpl->menu = 'home';
$tpl->meta_title = $date_name.__('news').$page_name.' - '.VF::cfg_item('site_name');
$tpl->meta_desc = $date_name.__('news').$page_name.'. '.VF::cfg_item('meta_desc');
$tpl->canonical = BASE_URL.'/'.$url;
$tpl->canonicalm = MOBILE_URL.'/'.$url;
$tpl->year = (isset($args['year'])) ? $args['year'].'/' : '';
$tpl->month = (isset($args['month'])) ? $args['month'].'/' : '';
$tpl->dates = $this->get_archive();
$tpl->articles = $articles;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'news_browse', 'footer'));
$tpl->display();
}
private function get_args($query)
{
$year = null;
$month = null;
$page = null;
$arg = (isset($query['0'])) ? (int) $query['0'] : null;
if (isset($arg)) {
if (strlen($arg) === 4) {
$year = $arg;
} else {
$page = $arg;
}
array_shift($query);
$arg = (isset($query['0'])) ? (string) $query['0'] : null;
if (isset($arg)) {
if (strlen($arg) === 2) {
$month = $arg;
}
array_shift($query);
$arg = (isset($query['0']) && ctype_digit($query['0'])) ? (int) $query['0'] : null;
$page = $arg;
}
}
return array(
'year' => $year,
'month' => $month,
'page' => $page
);
}
}