- md5
- 5005aa353a6903824fba281b7b12a2e4
- sha1
- 137cfd5dbb795d64948cddbf07deaee3f1b3a561
- sha256
- 1c3e45df4b61507f131f85c1e348307bf0d8768c445e6bd766652f2fbd7137ec
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
<?php
/**
* @package Joomla.Administrator
* @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
*/
defined('_JEXEC') or die;
/**
* Content component helper.
*
* @package Joomla.Administrator
* @subpackage com_content
* @since 1.6
*/
class ContentHelper
{
public static $extension = 'com_content';
/**
* Configure the Linkbar.
*
* @param string $vName The name of the active view.
*
* @return void
* @since 1.6
*/
public static function addSubmenu($vName)
{
JHtmlSidebar::addEntry(
JText::_('JGLOBAL_ARTICLES'),
'index.php?option=com_content&view=articles',
$vName == 'articles'
);
JHtmlSidebar::addEntry(
JText::_('COM_CONTENT_SUBMENU_CATEGORIES'),
'index.php?option=com_categories&extension=com_content',
$vName == 'categories');
JHtmlSidebar::addEntry(
JText::_('COM_CONTENT_SUBMENU_FEATURED'),
'index.php?option=com_content&view=featured',
$vName == 'featured'
);
}
/**
* Gets a list of the actions that can be performed.
*
* @param integer The category ID.
* @param integer The article ID.
*
* @return JObject
* @since 1.6
*/
public static function getActions($categoryId = 0, $articleId = 0)
{
// Reverted a change for version 2.5.6
$user = JFactory::getUser();
$result = new JObject;
if (empty($articleId) && empty($categoryId))
{
$assetName = 'com_content';
}
elseif (empty($articleId))
{
$assetName = 'com_content.category.'.(int) $categoryId;
}
else
{
$assetName = 'com_content.article.'.(int) $articleId;
}
$actions = array(
'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'
);
foreach ($actions as $action)
{
$result->set($action, $user->authorise($action, $assetName));
}
return $result;
}
/**
* Applies the content tag filters to arbitrary text as per settings for current user group
* @param text The string to filter
* @return string The filtered string
*/
public static function filterText($text)
{
// Filter settings
$config = JComponentHelper::getParams('com_config');
$user = JFactory::getUser();
$userGroups = JAccess::getGroupsByUser($user->get('id'));
$filters = $config->get('filters');
$blackListTags = array();
$blackListAttributes = array();
$customListTags = array();
$customListAttributes = array();
$whiteListTags = array();
$whiteListAttributes = array();
$noHtml = false;
$whiteList = false;
$blackList = false;
$customList = false;
$unfiltered = false;
// Cycle through each of the user groups the user is in.
// Remember they are included in the Public group as well.
foreach ($userGroups as $groupId)
{
// May have added a group but not saved the filters.
if (!isset($filters->$groupId))
{
continue;
}
// Each group the user is in could have different filtering properties.
$filterData = $filters->$groupId;
$filterType = strtoupper($filterData->filter_type);
if ($filterType == 'NH')
{
// Maximum HTML filtering.
$noHtml = true;
}
elseif ($filterType == 'NONE')
{
// No HTML filtering.
$unfiltered = true;
}
else {
// Black, white or custom list.
// Preprocess the tags and attributes.
$tags = explode(',', $filterData->filter_tags);
$attributes = explode(',', $filterData->filter_attributes);
$tempTags = array();
$tempAttributes = array();
foreach ($tags as $tag)
{
$tag = trim($tag);
if ($tag)
{
$tempTags[] = $tag;
}
}
foreach ($attributes as $attribute)
{
$attribute = trim($attribute);
if ($attribute)
{
$tempAttributes[] = $attribute;
}
}
// Collect the black or white list tags and attributes.
// Each lists is cummulative.
if ($filterType == 'BL')
{
$blackList = true;
$blackListTags = array_merge($blackListTags, $tempTags);
$blackListAttributes = array_merge($blackListAttributes, $tempAttributes);
}
elseif ($filterType == 'CBL')
{
// Only set to true if Tags or Attributes were added
if ($tempTags || $tempAttributes)
{
$customList = true;
$customListTags = array_merge($customListTags, $tempTags);
$customListAttributes = array_merge($customListAttributes, $tempAttributes);
}
}
elseif ($filterType == 'WL')
{
$whiteList = true;
$whiteListTags = array_merge($whiteListTags, $tempTags);
$whiteListAttributes = array_merge($whiteListAttributes, $tempAttributes);
}
}
}
// Remove duplicates before processing (because the black list uses both sets of arrays).
$blackListTags = array_unique($blackListTags);
$blackListAttributes = array_unique($blackListAttributes);
$customListTags = array_unique($customListTags);
$customListAttributes = array_unique($customListAttributes);
$whiteListTags = array_unique($whiteListTags);
$whiteListAttributes = array_unique($whiteListAttributes);
// Unfiltered assumes first priority.
if ($unfiltered)
{
// Dont apply filtering.
}
else
{
// Custom blacklist precedes Default blacklist
if ($customList)
{
$filter = JFilterInput::getInstance(array(), array(), 1, 1);
// Override filter's default blacklist tags and attributes
if ($customListTags)
{
$filter->tagBlacklist = $customListTags;
}
if ($customListAttributes)
{
$filter->attrBlacklist = $customListAttributes;
}
}
// Black lists take third precedence.
elseif ($blackList)
{
// Remove the white-listed attributes from the black-list.
$filter = JFilterInput::getInstance(
// Blacklisted tags
array_diff($blackListTags, $whiteListTags),
// Blacklisted attributes
array_diff($blackListAttributes, $whiteListAttributes),
// Blacklist tags
1,
// Blacklist attributes
1
);
// Remove white listed tags from filter's default blacklist
if ($whiteListTags)
{
$filter->tagBlacklist = array_diff($filter->tagBlacklist, $whiteListTags);
}
// Remove white listed attributes from filter's default blacklist
if ($whiteListAttributes)
{
$filter->attrBlacklist = array_diff($filter->attrBlacklist);
}
}
// White lists take fourth precedence.
elseif ($whiteList)
{
$filter = JFilterInput::getInstance($whiteListTags, $whiteListAttributes, 0, 0, 0); // turn off xss auto clean
}
// No HTML takes last place.
else {
$filter = JFilterInput::getInstance();
}
$text = $filter->clean($text, 'html');
}
return $text;
}
public static function getAssociations($pk)
{
$associations = array();
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->from('#__content as c');
$query->innerJoin('#__associations as a ON a.id = c.id AND a.context='.$db->quote('com_content.item'));
$query->innerJoin('#__associations as a2 ON a.key = a2.key');
$query->innerJoin('#__content as c2 ON a2.id = c2.id');
$query->innerJoin('#__categories as ca ON c2.catid = ca.id AND ca.extension = '.$db->quote('com_content'));
$query->where('c.id =' . (int) $pk);
$select = array(
'c2.language',
$query->concatenate(array('c2.id', 'c2.alias'), ':') . ' AS id',
$query->concatenate(array('ca.id', 'ca.alias'), ':') . ' AS catid'
);
$query->select($select);
$db->setQuery($query);
$contentitems = $db->loadObjectList('language');
// Check for a database error.
if ($error = $db->getErrorMsg())
{
JError::raiseWarning(500, $error);
return false;
}
foreach ($contentitems as $tag => $item)
{
$associations[$tag] = $item;
}
return $associations;
}
}
The same content is in 2 releases, Joomla 3.0.3 to 3.0.4. See them all, or every version of this file.