Файл: adultscript-2.0.3-pro/files/modules/frontpage/frontpage.php
Строк: 55
<?php
defined('_VALID') or die('Restricted Access!');
require MODULES_DIR.'/video/functions/url.php';
class VModule_frontpage
{
    private $db;
    private $cache;
    public function __construct()
    {
        $this->db        = VF::factory('database');
        $this->tpl        = VF::factory('template');
        $this->cache    = VF::factory('cache');
    }
    
    public function render()
    {
        VLanguage::load('frontend.frontpage');
    
        $errors        = array();
        $messages    = array();
        if (isset($_SESSION['error'])) {
            $errors[] = $_SESSION['error'];
            unset($_SESSION['error']);
        }
        
        if (isset($_SESSION['message'])) {
            $messages[]    = $_SESSION['message'];
            unset($_SESSION['message']);
        }
    
        if (VCfg::get('frontpage.watched')) {
            $sql        = "SELECT video_id, title, slug, rating, rated_by, duration, thumb, thumbs,
                                  total_views, ext, hd, add_time, premium, likes
                             FROM #__video
                             WHERE status = 1
                             ORDER BY view_time DESC
                           LIMIT ".VCfg::get('frontpage.watched_per_page');
            if (!$watched = $this->cache->get($sql, 900)) {
                $watched = $this->db->get_rows($sql);
                if ($this->db->affected_rows()) {
                    $this->cache->store($sql, $watched, 900);
                }
            }
            
            $this->tpl->watched    = $watched;
        }
        
        $sql_count      = "SELECT COUNT(*) AS total_videos 
                             FROM #__video 
                           WHERE status = 1";
        $total_videos   = $this->db->get_field($sql_count, 'total_videos');
        $pagination        = VPagination::get(1, $total_videos, VCfg::get('frontpage.videos_per_page'));
        
        $display        = VCfg::get('frontpage.videos');
        if ($display == 'recent' or $display == 'both') {
              $sql            = "SELECT v.video_id, v.title, v.slug, v.rating, v.likes,
                                        v.rated_by, v.duration, v.premium,
                                        v.thumb, v.thumbs, v.total_views,
                                        v.ext, v.hd, v.add_time, u.username
                               FROM #__video AS v
                                 LEFT JOIN #__user AS u ON (u.user_id = v.user_id AND u.status = '1')
                                 WHERE v.status = 1
                                 ORDER BY v.add_time DESC";
            $sql            = $sql. ' LIMIT '.$pagination['limit'];
              if (!$this->tpl->recent = $this->cache->get($sql, 3600)) {
                  $this->tpl->recent        = $this->db->get_rows($sql);
                  if ($this->db->affected_rows()) {
                      $this->cache->store($sql, $this->tpl->recent, 3600);
                  }
              }
        } 
        
        if ($display == 'featured' or $display == 'both') {
              $sql            = "SELECT v.video_id, v.title, v.slug, v.rating, v.likes,
                                        v.rated_by, v.duration, v.premium,
                                      v.thumb, v.thumbs, v.total_views,
                                      v.ext, v.hd, v.add_time, u.username
                                 FROM #__video_featured AS f
                                 INNER JOIN #__video AS v ON (v.video_id = f.video_id AND v.status = 1)
                               LEFT JOIN #__user AS u ON (u.user_id = v.user_id AND u.status = '1')
                               ORDER BY f.feature_time DESC";
            $sql            = $sql. ' LIMIT '.$pagination['limit'];
              if (!$this->tpl->featured = $this->cache->get($sql, 3600)) {
                  $this->tpl->featured        = $this->db->get_rows($sql);
                  if ($this->db->affected_rows()) {
                      $this->cache->store($sql, $this->tpl->featured, 3600);
                  }
              }
        }
        
        $this->tpl->canonical    = BASE_URL.'/';
        $this->tpl->canonicalm    = MOBILE_URL.'/';
        $this->tpl->menu        = 'home';
        
        $this->tpl->errors        = $errors;
        $this->tpl->messages    = $messages;
        
        $this->tpl->order        = 'recent';
        $this->tpl->timeline    = '';
        $this->tpl->category    = 0;
        $this->tpl->pagination    = $pagination;
        
        $this->tpl->load(array('header', 'frontpage', 'footer'));
        $this->tpl->display();
    }
}