[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_content/helpers/ -> content.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1