/administrator/components/com_content/helpers/content.php
PHP | 303 lines | 206 code | 32 blank | 65 comment | 26 complexity | 5005aa353a6903824fba281b7b12a2e4 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
- <?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;
- }
- }