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