示例#1
0
 public function category()
 {
     // get request vars
     $page = YRequest::getInt('page', 1);
     $category_id = (int) YRequest::getInt('category_id', $this->params->get('category'));
     // init vars
     $this->category = YTable::getInstance('category')->get($category_id);
     $params = $this->category ? $this->category->getParams('site') : $this->application->getParams('frontpage');
     $this->item_order = $this->_getItemOrder($params->get('config.item_order'));
     $layout = $category_id == 0 ? 'frontpage' : 'category';
     // get categories and items
     $this->categories = $this->application->getCategoryTree(true, $this->user, true);
     $this->items = YTable::getInstance('item')->getFromCategory($this->application->id, $category_id, true, null, $this->item_order);
     // raise warning when category can not be accessed
     if (!isset($this->categories[$category_id])) {
         JError::raiseWarning(500, JText::_('Unable to access category'));
         return;
     }
     // set category and categories to display
     $this->category = $this->categories[$category_id];
     $this->selected_categories = $this->categories[$category_id]->getChildren();
     // get item pagination
     $items_per_page = $params->get('config.items_per_page', 15);
     $this->pagination = new YPagination('page', count($this->items), $page, $items_per_page);
     $this->pagination->setShowAll($items_per_page == 0);
     if ($layout == 'category') {
         $this->pagination_link = RouteHelper::getCategoryRoute($this->category);
     } else {
         $this->pagination_link = RouteHelper::getFrontpageRoute($this->application->id);
     }
     // slice out items
     if (!$this->pagination->getShowAll()) {
         $this->items = array_slice($this->items, $this->pagination->limitStart(), $items_per_page);
     }
     // create pathway
     $addpath = false;
     $catid = $this->params->get('category');
     foreach ($this->category->getPathway() as $cat) {
         if (!$catid || $addpath) {
             $link = RouteHelper::getCategoryRoute($cat);
             $this->pathway->addItem($cat->name, $link);
         }
         if ($catid && $catid == $cat->id) {
             $addpath = true;
         }
     }
     // add feed links
     if ($params->get('config.show_feed_link')) {
         if ($alternate = $params->get('config.alternate_feed_link')) {
             $this->document->addHeadLink($alternate, 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'));
         } else {
             $this->document->addHeadLink(JRoute::_(RouteHelper::getFeedRoute($this->category, 'rss')), 'alternate', 'rel', array('type' => 'application/rss+xml', 'title' => 'RSS 2.0'));
             $this->document->addHeadLink(JRoute::_(RouteHelper::getFeedRoute($this->category, 'atom')), 'alternate', 'rel', array('type' => 'application/atom+xml', 'title' => 'Atom 1.0'));
         }
     }
     // set alphaindex
     if ($params->get('template.show_alpha_index')) {
         $this->alpha_index = $this->_getAlphaindex();
     }
     // set template and params
     if (!($this->template = $this->application->getTemplate())) {
         JError::raiseError(500, JText::_('No template selected'));
         return;
     }
     $this->params = $params;
     // set renderer
     $this->renderer = new ItemRenderer();
     $this->renderer->addPath(array($this->template->getPath(), ZOO_SITE_PATH));
     // display view
     $this->getView($layout)->addTemplatePath($this->template->getPath())->setLayout($layout)->display();
 }