PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_content/helpers/content.php

https://github.com/CCI-Studios/Wee-Magazine
PHP | 240 lines | 154 code | 28 blank | 58 comment | 27 complexity | e4744ce6c1f969d616b5ad9155ad2153 MD5 | raw file
  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. // No direct access
  7. defined('_JEXEC') or die;
  8. /**
  9. * Content component helper.
  10. *
  11. * @package Joomla.Administrator
  12. * @subpackage com_content
  13. * @since 1.6
  14. */
  15. class ContentHelper
  16. {
  17. public static $extension = 'com_content';
  18. /**
  19. * Configure the Linkbar.
  20. *
  21. * @param string $vName The name of the active view.
  22. *
  23. * @return void
  24. * @since 1.6
  25. */
  26. public static function addSubmenu($vName)
  27. {
  28. JSubMenuHelper::addEntry(
  29. JText::_('JGLOBAL_ARTICLES'),
  30. 'index.php?option=com_content&view=articles',
  31. $vName == 'articles'
  32. );
  33. JSubMenuHelper::addEntry(
  34. JText::_('COM_CONTENT_SUBMENU_CATEGORIES'),
  35. 'index.php?option=com_categories&extension=com_content',
  36. $vName == 'categories');
  37. JSubMenuHelper::addEntry(
  38. JText::_('COM_CONTENT_SUBMENU_FEATURED'),
  39. 'index.php?option=com_content&view=featured',
  40. $vName == 'featured'
  41. );
  42. }
  43. /**
  44. * Gets a list of the actions that can be performed.
  45. *
  46. * @param int The category ID.
  47. * @param int The article ID.
  48. *
  49. * @return JObject
  50. * @since 1.6
  51. */
  52. public static function getActions($categoryId = 0, $articleId = 0)
  53. {
  54. // Reverted a change for version 2.5.6
  55. $user = JFactory::getUser();
  56. $result = new JObject;
  57. if (empty($articleId) && empty($categoryId)) {
  58. $assetName = 'com_content';
  59. }
  60. elseif (empty($articleId)) {
  61. $assetName = 'com_content.category.'.(int) $categoryId;
  62. }
  63. else {
  64. $assetName = 'com_content.article.'.(int) $articleId;
  65. }
  66. $actions = array(
  67. 'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'
  68. );
  69. foreach ($actions as $action) {
  70. $result->set($action, $user->authorise($action, $assetName));
  71. }
  72. return $result;
  73. }
  74. /**
  75. * Applies the content tag filters to arbitrary text as per settings for current user group
  76. * @param text The string to filter
  77. * @return string The filtered string
  78. */
  79. public static function filterText($text)
  80. {
  81. // Filter settings
  82. $config = JComponentHelper::getParams('com_config');
  83. $user = JFactory::getUser();
  84. $userGroups = JAccess::getGroupsByUser($user->get('id'));
  85. $filters = $config->get('filters');
  86. $blackListTags = array();
  87. $blackListAttributes = array();
  88. $customListTags = array();
  89. $customListAttributes = array();
  90. $whiteListTags = array();
  91. $whiteListAttributes = array();
  92. $noHtml = false;
  93. $whiteList = false;
  94. $blackList = false;
  95. $customList = false;
  96. $unfiltered = false;
  97. // Cycle through each of the user groups the user is in.
  98. // Remember they are included in the Public group as well.
  99. foreach ($userGroups as $groupId)
  100. {
  101. // May have added a group but not saved the filters.
  102. if (!isset($filters->$groupId)) {
  103. continue;
  104. }
  105. // Each group the user is in could have different filtering properties.
  106. $filterData = $filters->$groupId;
  107. $filterType = strtoupper($filterData->filter_type);
  108. if ($filterType == 'NH') {
  109. // Maximum HTML filtering.
  110. $noHtml = true;
  111. }
  112. elseif ($filterType == 'NONE') {
  113. // No HTML filtering.
  114. $unfiltered = true;
  115. }
  116. else {
  117. // Black, white or custom list.
  118. // Preprocess the tags and attributes.
  119. $tags = explode(',', $filterData->filter_tags);
  120. $attributes = explode(',', $filterData->filter_attributes);
  121. $tempTags = array();
  122. $tempAttributes = array();
  123. foreach ($tags as $tag)
  124. {
  125. $tag = trim($tag);
  126. if ($tag) {
  127. $tempTags[] = $tag;
  128. }
  129. }
  130. foreach ($attributes as $attribute)
  131. {
  132. $attribute = trim($attribute);
  133. if ($attribute) {
  134. $tempAttributes[] = $attribute;
  135. }
  136. }
  137. // Collect the black or white list tags and attributes.
  138. // Each lists is cummulative.
  139. if ($filterType == 'BL') {
  140. $blackList = true;
  141. $blackListTags = array_merge($blackListTags, $tempTags);
  142. $blackListAttributes = array_merge($blackListAttributes, $tempAttributes);
  143. }
  144. elseif ($filterType == 'CBL') {
  145. // Only set to true if Tags or Attributes were added
  146. if ($tempTags || $tempAttributes) {
  147. $customList = true;
  148. $customListTags = array_merge($customListTags, $tempTags);
  149. $customListAttributes = array_merge($customListAttributes, $tempAttributes);
  150. }
  151. }
  152. elseif ($filterType == 'WL') {
  153. $whiteList = true;
  154. $whiteListTags = array_merge($whiteListTags, $tempTags);
  155. $whiteListAttributes = array_merge($whiteListAttributes, $tempAttributes);
  156. }
  157. }
  158. }
  159. // Remove duplicates before processing (because the black list uses both sets of arrays).
  160. $blackListTags = array_unique($blackListTags);
  161. $blackListAttributes = array_unique($blackListAttributes);
  162. $customListTags = array_unique($customListTags);
  163. $customListAttributes = array_unique($customListAttributes);
  164. $whiteListTags = array_unique($whiteListTags);
  165. $whiteListAttributes = array_unique($whiteListAttributes);
  166. // Unfiltered assumes first priority.
  167. if ($unfiltered) {
  168. // Dont apply filtering.
  169. }
  170. else {
  171. // Custom blacklist precedes Default blacklist
  172. if ($customList) {
  173. $filter = JFilterInput::getInstance(array(), array(), 1, 1);
  174. // Override filter's default blacklist tags and attributes
  175. if ($customListTags) {
  176. $filter->tagBlacklist = $customListTags;
  177. }
  178. if ($customListAttributes) {
  179. $filter->attrBlacklist = $customListAttributes;
  180. }
  181. }
  182. // Black lists take third precedence.
  183. elseif ($blackList) {
  184. // Remove the white-listed attributes from the black-list.
  185. $filter = JFilterInput::getInstance(
  186. array_diff($blackListTags, $whiteListTags), // blacklisted tags
  187. array_diff($blackListAttributes, $whiteListAttributes), // blacklisted attributes
  188. 1, // blacklist tags
  189. 1 // blacklist attributes
  190. );
  191. // Remove white listed tags from filter's default blacklist
  192. if ($whiteListTags) {
  193. $filter->tagBlacklist = array_diff($filter->tagBlacklist, $whiteListTags);
  194. }
  195. // Remove white listed attributes from filter's default blacklist
  196. if ($whiteListAttributes) {
  197. $filter->attrBlacklist = array_diff($filter->attrBlacklist);
  198. }
  199. }
  200. // White lists take fourth precedence.
  201. elseif ($whiteList) {
  202. $filter = JFilterInput::getInstance($whiteListTags, $whiteListAttributes, 0, 0, 0); // turn off xss auto clean
  203. }
  204. // No HTML takes last place.
  205. else {
  206. $filter = JFilterInput::getInstance();
  207. }
  208. $text = $filter->clean($text, 'html');
  209. }
  210. return $text;
  211. }
  212. }