Source for file newsfeed.php

Documentation is available at newsfeed.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Site
  4.  * @subpackage  com_newsfeeds
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * Newsfeeds Component Newsfeed Model
  14.  *
  15.  * @package     Joomla.Site
  16.  * @subpackage  com_newsfeeds
  17.  * @since       1.5
  18.  */
  19. {
  20.     /**
  21.      * Model context string.
  22.      *
  23.      * @var        string 
  24.      * @since   1.6
  25.      */
  26.     protected $_context = 'com_newsfeeds.newsfeed';
  27.  
  28.     /**
  29.      * Method to auto-populate the model state.
  30.      *
  31.      * Note. Calling getState in this method will result in recursion.
  32.      *
  33.      * @return  void 
  34.      * @since   1.6
  35.      */
  36.     protected function populateState()
  37.     {
  38.         $app JFactory::getApplication('site');
  39.  
  40.         // Load state from the request.
  41.         $pk $app->input->getInt('id');
  42.         $this->setState('newsfeed.id'$pk);
  43.  
  44.         $offset $app->input->get('limitstart'0'uint');
  45.         $this->setState('list.offset'$offset);
  46.  
  47.         // Load the parameters.
  48.         $params $app->getParams();
  49.         $this->setState('params'$params);
  50.  
  51.         $user JFactory::getUser();
  52.         if ((!$user->authorise('core.edit.state''com_newsfeeds')) &&  (!$user->authorise('core.edit''com_newsfeeds'))){
  53.             $this->setState('filter.published'1);
  54.             $this->setState('filter.archived'2);
  55.         }
  56.     }
  57.  
  58.     /**
  59.      * Method to get newsfeed data.
  60.      *
  61.      * @param   integer    The id of the newsfeed.
  62.      *
  63.      * @return  mixed  Menu item data object on success, false on failure.
  64.      * @since   1.6
  65.      */
  66.     public function &getItem($pk null)
  67.     {
  68.         $pk (!empty($pk)) $pk : (int) $this->getState('newsfeed.id');
  69.  
  70.         if ($this->_item === null)
  71.         {
  72.             $this->_item = array();
  73.         }
  74.  
  75.         if (!isset($this->_item[$pk]))
  76.         {
  77.             try
  78.             {
  79.                 $db $this->getDbo();
  80.                 $query $db->getQuery(true)
  81.                     ->select($this->getState('item.select''a.*'))
  82.                     ->from('#__newsfeeds AS a');
  83.  
  84.                 // Join on category table.
  85.                 $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
  86.                     ->join('LEFT''#__categories AS c on c.id = a.catid');
  87.  
  88.                 // Join on user table.
  89.                 $query->select('u.name AS author')
  90.                     ->join('LEFT''#__users AS u on u.id = a.created_by');
  91.  
  92.                 // Join over the categories to get parent category titles
  93.                 $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias')
  94.                     ->join('LEFT''#__categories as parent ON parent.id = c.parent_id')
  95.  
  96.                     ->where('a.id = ' . (int) $pk);
  97.  
  98.                 // Filter by start and end dates.
  99.                 $nullDate $db->quote($db->getNullDate());
  100.                 $nowDate $db->quote(JFactory::getDate()->toSql());
  101.  
  102.                 // Filter by published state.
  103.                 $published $this->getState('filter.published');
  104.                 $archived $this->getState('filter.archived');
  105.                 if (is_numeric($published))
  106.                 {
  107.                     $query->where('(a.published = ' . (int) $published ' OR a.published =' . (int) $archived ')')
  108.                         ->where('(a.publish_up = ' $nullDate ' OR a.publish_up <= ' $nowDate ')')
  109.                         ->where('(a.publish_down = ' $nullDate ' OR a.publish_down >= ' $nowDate ')')
  110.                         ->where('(c.published = ' . (int) $published ' OR c.published =' . (int) $archived ')');
  111.                 }
  112.  
  113.                 $db->setQuery($query);
  114.  
  115.                 $data $db->loadObject();
  116.  
  117.                 if (empty($data))
  118.                 {
  119.                     JError::raiseError(404JText::_('COM_NEWSFEEDS_ERROR_FEED_NOT_FOUND'));
  120.                 }
  121.  
  122.                 // Check for published state if filter set.
  123.                 if (((is_numeric($published)) || (is_numeric($archived))) && (($data->published != $published&& ($data->published != $archived)))
  124.                 {
  125.                     JError::raiseError(404JText::_('COM_NEWSFEEDS_ERROR_FEED_NOT_FOUND'));
  126.                 }
  127.  
  128.                 // Convert parameter fields to objects.
  129.                 $registry new JRegistry;
  130.                 $registry->loadString($data->params);
  131.                 $data->params clone $this->getState('params');
  132.                 $data->params->merge($registry);
  133.  
  134.                 $registry new JRegistry;
  135.                 $registry->loadString($data->metadata);
  136.                 $data->metadata $registry;
  137.  
  138.                 // Compute access permissions.
  139.                 if ($access $this->getState('filter.access'))
  140.                 {
  141.                     // If the access filter has been set, we already know this user can view.
  142.                     $data->params->set('access-view'true);
  143.                 }
  144.                 else {
  145.                     // If no access filter is set, the layout takes some responsibility for display of limited information.
  146.                     $user JFactory::getUser();
  147.                     $groups $user->getAuthorisedViewLevels();
  148.                     $data->params->set('access-view'in_array($data->access$groups&& in_array($data->category_access$groups));
  149.                 }
  150.  
  151.                 $this->_item[$pk$data;
  152.             }
  153.             catch (Exception $e)
  154.             {
  155.                 $this->setError($e);
  156.                 $this->_item[$pkfalse;
  157.             }
  158.         }
  159.  
  160.         return $this->_item[$pk];
  161.     }
  162.  
  163.     /**
  164.      * Increment the hit counter for the newsfeed.
  165.      *
  166.      * @param   int  $pk  Optional primary key of the item to increment.
  167.      *
  168.      * @return  boolean  True if successful; false otherwise and internal error set.
  169.      *
  170.      * @since   3.0
  171.      */
  172.     public function hit($pk 0)
  173.     {
  174.         $input JFactory::getApplication()->input;
  175.         $hitcount $input->getInt('hitcount'1);
  176.  
  177.         if ($hitcount)
  178.         {
  179.             $pk (!empty($pk)) $pk : (int) $this->getState('newsfeed.id');
  180.  
  181.             $table JTable::getInstance('Newsfeed''NewsfeedsTable');
  182.             $table->load($pk);
  183.             $table->hit($pk);
  184.         }
  185.  
  186.         return true;
  187.     }
  188. }

Documentation generated on Tue, 19 Nov 2013 15:09:29 +0100 by phpDocumentor 1.4.3