示例#1
0
 /**
  * Returns the categories
  *
  * @param	FTL_Binding
  * @param	array/null
  *
  * @return	array
  *
  */
 public static function get_categories(FTL_Binding $tag)
 {
     // Categories model
     self::$ci->load->model('category_model');
     // Current page
     $page = $tag->get('page');
     // Local storage key
     $lsk = '__all__';
     // Get the local cache data
     $element_name = $tag->getParentName();
     $element = $tag->get($element_name);
     if (!is_null($element)) {
         $lsk = '__' . $element_name . '__' . $element['name'];
     }
     // Set the local cache data
     if (!isset(self::$categories[$lsk])) {
         // CSS class to use for the current category
         $active_class = $tag->getAttribute('active_class', 'active');
         // Asked category
         $asked_category_name = self::get_asked_category_uri();
         // Check if the element has one category array (eg. for Articles)
         if (isset($element['categories'])) {
             $categories = $element['categories'];
             // Fix the 'nb' key (nb_articles using this category)
             foreach ($categories as $key => $category) {
                 $categories[$key]['nb'] = '1';
             }
         } else {
             if ($element_name == 'page') {
                 $id_page = !is_null($page) ? $page['id_page'] : NULL;
             } else {
                 $id_page = NULL;
             }
             $categories = self::$ci->category_model->get_categories_list($id_page, Settings::get_lang());
         }
         $page_url = !is_null($page) ? trim($page['absolute_url'], '/') . '/' : Pages::get_home_page_url();
         $category_uri_segment = self::get_config_special_uri_segment('category');
         // Add the URL to the category to each category row
         // Also add the active class
         foreach ($categories as $key => $category) {
             $categories[$key]['url'] = $page_url . $category_uri_segment . '/' . $category['name'];
             $categories[$key]['lang_url'] = $page_url . $category_uri_segment . '/' . $category['name'];
             // Active category ?
             $categories[$key]['active_class'] = $category['name'] == $asked_category_name ? $active_class : '';
             $categories[$key]['is_active'] = !empty($categories[$key]['active_class']) ? TRUE : FALSE;
         }
         self::$categories[$lsk] = array_values($categories);
     }
     return self::$categories[$lsk];
 }
示例#2
0
 public static function get_archives(FTL_Binding $tag)
 {
     // Categories model
     self::$ci->load->model('article_model');
     // Page
     $page = $tag->get('page');
     if (is_null($page)) {
         $page = self::registry('page');
     }
     // Period format. see : http://php.net/manual/fr/function.date.php
     $format = $tag->getAttribute('format', 'F');
     // Attribute : active class
     $active_class = $tag->getAttribute('active_class', 'active');
     // filter
     $filter = $tag->getAttribute('filter', FALSE);
     if ($filter != FALSE) {
         $filter = self::process_filter($filter);
     }
     // month
     $with_month = $tag->getAttribute('month');
     // order
     $order = $tag->getAttribute('order');
     $order = $order == 'ASC' ? 'period ASC' : 'period DESC';
     // Archive string : 'yyyy' or 'yyyy.mm'. Used for CSS active class
     $_archive_string = '';
     // Archive URI args
     $args = self::get_special_uri_array('archives');
     if (!empty($args)) {
         $_archive_string = isset($args[0]) ? $args[0] : '';
         $_archive_string .= isset($args[1]) ? '.' . $args[1] : '';
     }
     // Archives URI segment, as set in the config file
     $archives_uri_segment = self::get_config_special_uri_segment('archives');
     // Get the archives
     $archives = self::$ci->article_model->get_archives_list(array('id_page' => $page['id_page']), Settings::get_lang(), $filter, $with_month, $order);
     // Translated period array
     $month_formats = array('D', 'l', 'F', 'M');
     $page_url = !is_null($page) ? $page['absolute_url'] . '/' : Pages::get_home_page_url();
     foreach ($archives as &$row) {
         $year = substr($row['period'], 0, 4);
         $month = substr($row['period'], 4);
         if ($month != '') {
             $month = strlen($month) == 1 ? '0' . $month : $month;
             $timestamp = mktime(0, 0, 0, $month, 1, $year);
             // Get date in the wished format
             $period = (string) date($format, $timestamp);
             // Translate the period month
             if (in_array($format, $month_formats)) {
                 $period = lang(strtolower($period));
             }
             $row['period'] = $period . ' ' . $year;
             $row['url'] = $page_url . $archives_uri_segment . '/' . $year . '/' . $month;
             $row['active_class'] = $year . '.' . $month == $_archive_string ? $active_class : '';
         } else {
             $row['period'] = $year;
             $row['url'] = $page_url . $archives_uri_segment . '/' . $year;
             $row['active_class'] = $year == $_archive_string ? $active_class : '';
         }
         $row['is_active'] = !empty($row['active_class']) ? TRUE : FALSE;
     }
     return $archives;
 }