Example #1
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get document
     $document = JFactory::getDocument();
     // Legacy
     $moduleId = $application->input->get('moduleID', 0, 'int');
     if ($moduleId) {
         $application->input->set('task', 'module');
         $application->input->set('id', $moduleId);
     }
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     // Trigger the corresponding subview
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Load the comments counters in a single query for all items
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Add items to feed
     foreach ($this->items as $item) {
         // Add item
         $document->addItem($this->getFeedItem($item));
     }
 }
Example #2
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     // Trigger the corresponding method
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Generate the view params depedning on the task prefix. This let's us have one common layout file for listing items
     $this->generateItemlistParams($task);
     // Load the comments counters in a single query for all items
     if ($this->params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Plugins
     foreach ($this->items as $item) {
         $item->events = $item->getEvents('com_k2.itemlist.' . $task, $this->params, $this->offset);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $this->pagination = new JPagination($this->total, $this->offset, $this->limit);
     // Display
     parent::display($tpl);
 }
Example #3
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     // Trigger the corresponding method
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Generate the view params depedning on the task prefix. This let's us have one common layout file for listing items
     $this->generateItemlistParams($task);
     // Load the comments counters in a single query for all items
     if ($this->params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Plugins
     foreach ($this->items as $item) {
         $item->events = $item->getEvents('com_k2.itemlist.' . $task, $this->params, $this->offset);
     }
     // Add feed link
     $this->feedLink = JRoute::_('&format=feed&limitstart=');
     // Add feed links to head
     if ($this->feedLinkToHead) {
         $attributes = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
         $this->document->addHeadLink(JRoute::_('&format=feed&limitstart=&type=rss'), 'alternate', 'rel', $attributes);
         $attributes = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
         $this->document->addHeadLink(JRoute::_('&format=feed&limitstart=&type=atom'), 'alternate', 'rel', $attributes);
     }
     // Pagination
     jimport('joomla.html.pagination');
     $this->pagination = new JPagination($this->total, $this->offset, $this->limit);
     // Display
     try {
         parent::display($tpl);
     } catch (Exception $e) {
         if ($this->_template === false) {
             $this->setLayout('itemlist');
         }
         parent::display($tpl);
     }
 }
Example #4
0
 public function display($tpl = null)
 {
     // Get application
     $application = JFactory::getApplication();
     // Get input
     $task = $application->input->get('task', '', 'cmd');
     $this->offset = $application->input->get('limitstart', 0, 'int');
     $this->limit = $application->input->get('limit', 10, 'int');
     $callback = $application->input->get('callback', '', 'cmd');
     // Trigger the corresponding subview
     if (method_exists($this, $task)) {
         call_user_func(array($this, $task));
     } else {
         throw new Exception(JText::_('K2_NOT_FOUND'), 404);
     }
     // Response
     $response = new stdClass();
     $response->site = new stdClass();
     $response->site->url = JURI::root();
     $response->site->name = $application->getCfg('sitename');
     $response->items = array();
     // Load the comments counters in a single query for all items
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('comments')) {
         K2Items::countComments($this->items);
     }
     // Add items to JSON
     foreach ($this->items as $item) {
         // Add item
         $response->items[] = $this->getJsonItem($item);
     }
     // Encode response
     $response = json_encode($response);
     // Output
     if ($callback) {
         $this->document->setMimeEncoding('application/javascript');
         echo $callback . '(' . $response . ')';
     } else {
         echo $response;
     }
 }
Example #5
0
 public static function getItems($params)
 {
     // Component params
     $componentParams = JComponentHelper::getParams('com_k2');
     // Get model
     $model = K2Model::getInstance('Items');
     // Set site state
     $model->setState('site', true);
     // Set states depending on source
     if ($params->get('source') == 'specific') {
         $items = array();
         if ($params->get('items')) {
             $itemIds = array_filter((array) $params->get('items'));
             if (count($itemIds)) {
                 // Apply sorting
                 foreach ($itemIds as $itemId) {
                     // Fetch item
                     $model->setState('id', $itemId);
                     $items[] = $model->getRow();
                 }
             }
         }
     } else {
         // Category filter
         $model->setState('category.filter', $params->get('filter'));
         // Featured
         if ($params->get('featured') == 2) {
             $model->setState('featured', 1);
         } else {
             if ($params->get('featured') == 0) {
                 $model->setState('featured', 0);
             }
         }
         // Set time range if sorting is comments or hits
         if ($params->get('timeRange') && ($params->get('sorting') == 'comments' || $params->get('sorting') == 'hits')) {
             $now = JFactory::getDate();
             switch ($params->get('timeRange')) {
                 case '1':
                     $interval = 'P1D';
                     break;
                 case '3':
                     $interval = 'P3D';
                     break;
                 case '7':
                     $interval = 'P1W';
                     break;
                 case '15':
                     $interval = 'P2W';
                     break;
                 case '30':
                     $interval = 'P1M';
                     break;
                 case '90':
                     $interval = 'P3M';
                     break;
                 case '180':
                     $interval = 'P6M';
                     break;
             }
             $date = $now->sub(new DateInterval($interval));
             $model->setState('created.value', $date->toSql());
             $model->setState('created.operator', '>');
         }
         // Fetch only items with media
         if ($params->get('media')) {
             $model->setState('media', true);
         }
         // Set limit
         $model->setState('limit', $params->get('limit'));
         // Set sorting
         $model->setState('sorting', $params->get('sorting'));
         // Get items
         $items = $model->getRows();
     }
     // Prepare data
     foreach ($items as $item) {
         // Plugins
         $item->events = $item->getEvents('mod_k2_content', $params, 0, $params->get('k2Plugins'), $params->get('jPlugins'));
         // Introtext word limit
         if ($params->get('itemIntroTextWordLimit')) {
             $item->introtext = K2HelperUtilities::wordLimit($item->introtext, $params->get('itemIntroTextWordLimit'));
         }
         // Set the selected image as default
         $item->image = $item->getImage($params->get('itemImgSize'));
     }
     // Load the comments counters in a single query for all items
     if ($params->get('itemCommentsCounter') && $componentParams->get('comments')) {
         K2Items::countComments($items);
     }
     // Set the avatar width if it's inherited from component settings
     if ($params->get('itemAuthorAvatarWidthSelect') == 'custom') {
         $params->set('itemAuthorAvatarWidth', $componentParams->get('userImageWidth'));
     }
     // Set the custom link url if user has selected a menu link item
     if ($params->get('itemCustomLinkMenuItem') && $params->get('itemCustomLink')) {
         $application = JFactory::getApplication();
         $menu = $application->getMenu();
         $menuLink = $menu->getItem($params->get('itemCustomLinkMenuItem'));
         if ($menuLink) {
             if (!$params->get('itemCustomLinkTitle')) {
                 $params->set('itemCustomLinkTitle', $menuLink->title);
             }
             $params->set('itemCustomLinkURL', JRoute::_('index.php?&Itemid=' . $menuLink->id));
         }
     }
     // Return
     return $items;
 }