Source for file article.php
Documentation is available at article.php
* @subpackage com_content
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Content Component Article Model
* @subpackage com_content
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
// Load state from the request.
$pk =
$app->input->getInt('id');
$offset =
$app->input->getUInt('limitstart');
$this->setState('list.offset', $offset);
$params =
$app->getParams();
// TODO: Tune these values based on other permissions.
if ((!$user->authorise('core.edit.state', 'com_content')) &&
(!$user->authorise('core.edit', 'com_content')))
* Method to get article data.
* @param integer $pk The id of the article.
* @return mixed Menu item data object on success, false on failure.
public function getItem($pk =
null)
$pk =
(!empty($pk)) ?
$pk : (int)
$this->getState('article.id');
if ($this->_item ===
null)
if (!isset
($this->_item[$pk]))
$query =
$db->getQuery(true)
'item.select', 'a.id, a.asset_id, a.title, a.alias, a.introtext, a.fulltext, ' .
// If badcats is not null, this means that the article is inside an unpublished category
// In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published)
'CASE WHEN badcats.id is null THEN a.state ELSE 0 END AS state, ' .
'a.catid, a.created, a.created_by, a.created_by_alias, ' .
// Use created if modified is 0
'CASE WHEN a.modified = ' .
$db->quote($db->getNullDate()) .
' THEN a.created ELSE a.modified END as modified, ' .
'a.modified_by, a.checked_out, a.checked_out_time, a.publish_up, a.publish_down, ' .
'a.images, a.urls, a.attribs, a.version, a.ordering, ' .
'a.metakey, a.metadesc, a.access, a.hits, a.metadata, a.featured, a.language, a.xreference'
$query->from('#__content AS a');
// Join on category table.
$query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access')
->join('LEFT', '#__categories AS c on c.id = a.catid');
$query->select('u.name AS author')
->join('LEFT', '#__users AS u on u.id = a.created_by');
$subQuery =
$db->getQuery(true)
->select('MAX(contact.id) AS id')
->from('#__contact_details AS contact')
->where('contact.published = 1')
->where('contact.user_id = a.created_by');
$subQuery->where('(contact.language in (' .
$db->quote(JFactory::getLanguage()->getTag()) .
',' .
$db->quote('*') .
') OR contact.language IS NULL)');
$query->select('(' .
$subQuery .
') as contactid');
$query->where('a.language in (' .
$db->quote(JFactory::getLanguage()->getTag()) .
',' .
$db->quote('*') .
')');
// Join over the categories to get parent category titles
$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias')
->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');
$query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count')
->join('LEFT', '#__content_rating AS v ON a.id = v.content_id')
->where('a.id = ' . (int)
$pk);
// Filter by start and end dates.
$nullDate =
$db->quote($db->getNullDate());
$nowDate =
$db->quote($date->toSql());
$query->where('(a.publish_up = ' .
$nullDate .
' OR a.publish_up <= ' .
$nowDate .
')')
->where('(a.publish_down = ' .
$nullDate .
' OR a.publish_down >= ' .
$nowDate .
')');
// Join to check for category published state in parent categories up the tree
// If all categories are published, badcats.id will be null, and we just use the article state
$subquery =
' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ';
$subquery .=
'ON cat.lft BETWEEN parent.lft AND parent.rgt ';
$subquery .=
'WHERE parent.extension = ' .
$db->quote('com_content');
$subquery .=
' AND parent.published <= 0 GROUP BY cat.id)';
$query->join('LEFT OUTER', $subquery .
' AS badcats ON badcats.id = c.id');
// Filter by published state.
$published =
$this->getState('filter.published');
$archived =
$this->getState('filter.archived');
$query->where('(a.state = ' . (int)
$published .
' OR a.state =' . (int)
$archived .
')');
$data =
$db->loadObject();
// Check for published state if filter set.
if (((is_numeric($published)) ||
(is_numeric($archived))) &&
(($data->state !=
$published) &&
($data->state !=
$archived)))
// Convert parameter fields to objects.
$registry->loadString($data->attribs);
$data->params =
clone $this->getState('params');
$data->params->merge($registry);
$registry->loadString($data->metadata);
$data->metadata =
$registry;
// Compute selected asset permissions.
// Technically guest could edit an article, but lets not check that to improve performance a little.
if (!$user->get('guest'))
$userId =
$user->get('id');
$asset =
'com_content.article.' .
$data->id;
// Check general edit permission first.
if ($user->authorise('core.edit', $asset))
$data->params->set('access-edit', true);
// Now check if edit.own is available.
elseif (!empty($userId) &&
$user->authorise('core.edit.own', $asset))
// Check for a valid user and that they are the owner.
if ($userId ==
$data->created_by)
$data->params->set('access-edit', true);
// Compute view access permissions.
if ($access =
$this->getState('filter.access'))
// If the access filter has been set, we already know this user can view.
$data->params->set('access-view', true);
// If no access filter is set, the layout takes some responsibility for display of limited information.
$groups =
$user->getAuthorisedViewLevels();
if ($data->catid ==
0 ||
$data->category_access ===
null)
$data->params->set('access-view', in_array($data->access, $groups));
$data->params->set('access-view', in_array($data->access, $groups) &&
in_array($data->category_access, $groups));
$this->_item[$pk] =
$data;
if ($e->getCode() ==
404)
// Need to go thru the error handler to allow Redirect to work.
$this->_item[$pk] =
false;
return $this->_item[$pk];
* Increment the hit counter for the article.
* @param integer $pk Optional primary key of the article to increment.
* @return boolean True if successful; false otherwise and internal error set.
public function hit($pk =
0)
$hitcount =
$input->getInt('hitcount', 1);
$pk =
(!empty($pk)) ?
$pk : (int)
$this->getState('article.id');
* Save user vote on article
* @param integer $pk Joomla Article Id
* @param integer $rate Voting rate
* @return boolean Return true on success
public function storeVote($pk =
0, $rate =
0)
if ($rate >=
1 &&
$rate <=
5 &&
$pk >
0)
$userIP =
$_SERVER['REMOTE_ADDR'];
$query =
$db->getQuery(true);
// Create the base select statement.
->from($db->quoteName('#__content_rating'))
->where($db->quoteName('content_id') .
' = ' . (int)
$pk);
// Set the query and load the result.
$rating =
$db->loadObject();
// Check for a database error.
// There are no ratings yet, so lets insert our rating
$query =
$db->getQuery(true);
// Create the base insert statement.
$query->insert($db->quoteName('#__content_rating'))
->columns(array($db->quoteName('content_id'), $db->quoteName('lastip'), $db->quoteName('rating_sum'), $db->quoteName('rating_count')))
->values((int)
$pk .
', ' .
$db->quote($userIP) .
',' . (int)
$rate .
', 1');
// Set the query and execute the insert.
catch
(RuntimeException $e)
if ($userIP !=
($rating->lastip))
$query =
$db->getQuery(true);
// Create the base update statement.
$query->update($db->quoteName('#__content_rating'))
->set($db->quoteName('rating_count') .
' = rating_count + 1')
->set($db->quoteName('rating_sum') .
' = rating_sum + ' . (int)
$rate)
->set($db->quoteName('lastip') .
' = ' .
$db->quote($userIP))
->where($db->quoteName('content_id') .
' = ' . (int)
$pk);
// Set the query and execute the update.
catch
(RuntimeException $e)
Documentation generated on Tue, 19 Nov 2013 14:53:52 +0100 by phpDocumentor 1.4.3