Вход Регистрация
Файл: adultscript-2.0.3-pro/files/modules/news/news.php
Строк: 101
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VModule_news
{
    protected 
$db;
    protected 
$cache;
    public function 
__construct()
    {
        
$this->db        = VF::factory('database');
        
$this->cache    = VF::factory('cache');
    }
    
    public function 
render()
    {
        
$component    = VUri::request(1);
        
        
// we dont allow any ".." in the component name
        
if (strpos($component, '..')) {
            
VModule::load('404', TRUE);
        }
        
        if (
$component == '' OR is_numeric($component)) {
            
$component    = 'browse';
        } else {
            
$component    = 'view';
        }
        
        
$component_class    = 'VComponent_news_'.$component;
        
$component_file        = BASE_DIR.'/modules/news/components/'.$component.'.php';
        
        try {
            require 
$component_file;
            
            
$obj = new $component_class;
            
$obj->render();
        } catch (
Exception $e) {
            throw new 
VException($e);
        }
    }
    
    protected function 
get_archive()
    {
        
$dates  = array();
        
$this->db->query("SELECT add_date
                          FROM #__news
                          WHERE status = '1'
                          ORDER BY add_date ASC
                          LIMIT 1"
);
        if (
$this->db->affected_rows()) {
              
$data            = $this->db->fetch_assoc();
            
$expl            = explode(' ', $data['add_date']);
            
$expl            = explode('-', $expl['0']);
            
$start_year        = $expl['0'];
            
$start_month    = $expl['1'];
        } else {
              return 
$dates;
        }
        
        
$this->db->query("SELECT DATE_FORMAT(add_date, '%Y-%m') AS end_date
                          FROM #__news
                          WHERE status = '1'
                          ORDER BY add_date DESC
                          LIMIT 1"
);
        if (
$this->db->affected_rows()) {
            
$data              = $this->db->fetch_assoc();
            
$expl            = explode('-', $data['end_date']);
            
$end_year        = $expl['0'];
            
$end_month        = $expl['1'];
        } else {
              return 
$dates;
        }
        
        if (
$start_year == $end_year) {
              for (
$month=$start_month; $month<=$end_month; $month++) {
                  
$time            = mktime(0, 0, 0, $month, 1, $start_year);
                  
$dates[$time]     = $start_year.'/'.sprintf('%02d', (int) $month);
              }
        } else {
              for (
$year=$start_year; $year<=$end_year; $year++) {
                  if (
$year == $start_year) {
                      for (
$month=$start_month; $month<=12; $month++) {
                          
$time            = mktime(0, 0, 0, $month, 1, $year);
                          
$dates[$time]     = $start_year.'/'.sprintf('%02d', (int) $month);
                      }
                  } elseif (
$year == $end_year) {
                      for (
$month=1; $month<=$end_month; $month++) {
                          
$time            = mktime(0, 0, 0, $month, 1, $year);
                          
$dates[$time]     = $start_year.'/'.sprintf('%02d', (int) $month);
                      }
                  } else {
                      for (
$month=1; $month<=12; $month++) {
                          
$time            = mktime(0, 0, 0, $month, 1, $year);
                          
$dates[$time]     = $start_year.'/'.sprintf('%02d', (int) $month);
                      }                      
                  }
              }
        }
        
//        echo VF::debug($dates).'<br />';
        
        
return $dates;
    }
}
Онлайн: 2
Реклама