Ejemplo n.º 1
0
 function get_search_params_from_url($sm)
 {
     $um = $sm->get_url_manager();
     $params = Articles_list::get_search_params($sm, $um->list);
     return $params;
 }
Ejemplo n.º 2
0
 function generate_output($params)
 {
     $this->set_template($params);
     $sm = vivvo_lite_site::get_instance();
     $um = $sm->get_url_manager();
     $lang = vivvo_lang::get_instance();
     if (!isset($params['search_by_year']) && !$um->isset_param('search_by_year')) {
         $year = date('Y', VIVVO_START_TIME);
         $params['search_by_year'] = $year;
     } else {
         if (isset($params['search_by_year'])) {
             $year = (int) $params['search_by_year'];
         } else {
             $year = (int) $um->get_param('search_by_year');
             $params['search_by_year'] = $year;
         }
     }
     if (!isset($params['search_by_month']) && !$um->isset_param('search_by_month')) {
         $month = date('n', VIVVO_START_TIME);
         $params['search_by_month'] = $month;
     } else {
         if (isset($params['search_by_month'])) {
             $month = (int) $params['search_by_month'];
         } else {
             $month = (int) $um->get_param('search_by_month');
             $params['search_by_month'] = $month;
         }
     }
     //Articles per day
     if ($month > 0 && $year > 1900) {
         if (!isset($params['search_do_advanced'])) {
             $params['search_status'] = -1;
         }
         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
         $article_params = Articles_list::get_search_params(null, $params);
         $article_list = new Articles_list();
         $article_list->search($article_params['search_options'], '', 'ascending', 0, 0, false);
         $article_list->_query->_fields = array();
         $article_list->_query->add_fields('DAYOFMONTH( created ) AS day');
         $article_list->_query->add_fields('count( * ) AS count');
         $article_list->_query->add_group_by('TO_DAYS( created )');
         $query = $article_list->_query->get_query();
         $num_of_days = date('t', mktime(0, 0, 0, $month, 1, $year));
         $day_of_week = date('w', mktime(0, 0, 0, $month, 1, $year));
         $prev_month = $month - 1;
         if ($prev_month == 0) {
             $prev_month = 12;
             $prev_year = $year - 1;
         } else {
             $prev_year = $year;
         }
         $next_month = $month + 1;
         if ($next_month == 13) {
             $next_month = 1;
             $next_year = $year + 1;
         } else {
             $next_year = $year;
         }
         $prev_num_of_days = date('t', mktime(0, 0, 0, $prev_month, 1, $prev_year));
         if ($day_of_week != 0) {
             for ($i = 1 - $day_of_week; $i <= 0; $i++) {
                 $this->data[$i] = array();
                 $this->data[$i]['label'] = '';
                 $this->data[$i]['count'] = 0;
                 $this->data[$i]['url'] = '';
             }
         }
         for ($i = 1; $i <= $num_of_days; $i++) {
             $this->data[$i] = array();
             $this->data[$i]['label'] = $i;
             $this->data[$i]['count'] = 0;
             $this->data[$i]['url'] = '';
         }
         $next_day_of_week = date('w', mktime(0, 0, 0, $month, $num_of_days, $year));
         if ($next_day_of_week != 6) {
             for ($i = $num_of_days + 1; $i < $num_of_days + 6 - $next_day_of_week + 1; $i++) {
                 $this->data[$i] = array();
                 $this->data[$i]['label'] = '';
                 $this->data[$i]['count'] = 0;
                 $this->data[$i]['url'] = '';
             }
         }
         $count_sum = 0;
         $res = $sm->get_db()->query($query);
         if (!is_a($res, 'mdb2_error')) {
             while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                 if ($row['count'] > 0) {
                     $count_sum += $row['count'];
                     $this->data[$row['day']]['count'] += $row['count'];
                     if (isset($params['search_status']) && $params['search_status'] == -1) {
                         $this->data[$row['day']]['url'] = make_proxied_url('archive/' . $year . '/' . $month . '/' . $row['day']);
                     } else {
                         $day_params = $article_params;
                         $day_params['search_do_advanced'] = true;
                         $day_params['search_by_day'] = $row['day'];
                         $search_option = base64_encode(serialize($day_params));
                         $this->data[$row['day']]['url'] = make_absolute_url('index.php?search_options=' . $search_option);
                     }
                 }
             }
         }
         $res->free();
     }
     if ($count_sum) {
         $month_params = $article_params;
         if (isset($params['search_status']) && $params['search_status'] == -1) {
             $this->_template->assign('month_url', make_proxied_url('archive/' . $year . '/' . $month . '/'));
         } else {
             $month_params['search_do_advanced'] = true;
             $search_option = base64_encode(serialize($month_params));
             $this->_template->assign('month_url', make_absolute_url('index.php?search_options=' . $search_option));
         }
     }
     $this->_template->assign('count_list', $this->data);
     $this->_template->assign('year', $year);
     $this->_template->assign('month', strval($lang->get_value('LNG_MONTH_' . $month)));
     $this->_template->assign('prev_year', intval($year - 1));
     $this->_template->assign('prev_month_year', $prev_year);
     $this->_template->assign('prev_month', $prev_month);
     $this->_template->assign('next_year', intval($year + 1));
     $this->_template->assign('next_month_year', $next_year);
     $this->_template->assign('next_month', $next_month);
 }