Source for file rules.php

Documentation is available at rules.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  HTML
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Extended Utility class for all HTML drawing classes.
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  HTML
  17.  * @since       1.6
  18.  */
  19. abstract class JHtmlRules
  20. {
  21.     /**
  22.      * Creates the HTML for the permissions widget
  23.      *
  24.      * @param   array    $actions   Array of action objects
  25.      * @param   integer  $assetId   Id of a specific asset to  create a widget for.
  26.      * @param   integer  $parent    Id of the parent of the asset
  27.      * @param   string   $control   The form control
  28.      * @param   string   $idPrefix  Prefix for the ids assigned to specific action-group pairs
  29.      *
  30.      * @return  string   HTML for the permissions widget
  31.      *
  32.      * @see     JAccess
  33.      * @see     JFormFieldRules
  34.      * @since   1.6
  35.      */
  36.     public static function assetFormWidget($actions$assetId null$parent null$control 'jform[rules]'$idPrefix 'jform_rules')
  37.     {
  38.         $images static::_getImagesArray();
  39.  
  40.         // Get the user groups.
  41.         $groups static::_getUserGroups();
  42.  
  43.         // Get the incoming inherited rules as well as the asset specific rules.
  44.         $inheriting JAccess::getAssetRules($parent $parent static::_getParentAssetId($assetId)true);
  45.         $inherited JAccess::getAssetRules($assetIdtrue);
  46.         $rules JAccess::getAssetRules($assetId);
  47.  
  48.         $html array();
  49.  
  50.         $html['<div class="acl-options">';
  51.         $html[JHtml::_('tabs.start''acl-rules-' $assetIdarray('useCookie' => 1));
  52.         $html[JHtml::_('tabs.panel'JText::_('JLIB_HTML_ACCESS_SUMMARY')'summary');
  53.         $html['            <p>' JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC''</p>';
  54.         $html['            <table class="aclsummary-table" summary="' JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC''">';
  55.         $html['            <caption>' JText::_('JLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION''</caption>';
  56.         $html['            <tr>';
  57.         $html['                <th class="col1 hidelabeltxt">' JText::_('JLIB_RULES_GROUPS''</th>';
  58.  
  59.         foreach ($actions as $i => $action)
  60.         {
  61.             $html['                <th class="col' ($i 2'">' JText::_($action->title'</th>';
  62.         }
  63.         $html['            </tr>';
  64.  
  65.         foreach ($groups as $i => $group)
  66.         {
  67.             $html['            <tr class="row' ($i 2'">';
  68.             $html['                <td class="col1">' $group->text '</td>';
  69.  
  70.             foreach ($actions as $j => $action)
  71.             {
  72.                 $html['                <td class="col' ($j 2'">'
  73.                     . ($assetId ($inherited->allow($action->name$group->identities$images['allow'$images['deny'])
  74.                     : ($inheriting->allow($action->name$group->identities$images['allow'$images['deny'])) '</td>';
  75.             }
  76.             $html['            </tr>';
  77.         }
  78.  
  79.         $html['         </table>';
  80.  
  81.         foreach ($actions as $action)
  82.         {
  83.             $actionTitle JText::_($action->title);
  84.             $actionDesc JText::_($action->description);
  85.             $html[JHtml::_('tabs.panel'$actionTitle$action->name);
  86.             $html['            <p>' $actionDesc '</p>';
  87.             $html['            <table class="aclmodify-table" summary="' strip_tags($actionDesc'">';
  88.             $html['            <caption>' JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL'' ' $actionTitle ' '
  89.                 . JText::_('JLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE''</caption>';
  90.             $html['            <tr>';
  91.             $html['                <th class="col1 hidelabeltxt">' JText::_('JLIB_RULES_GROUP''</th>';
  92.             $html['                <th class="col2">' JText::_('JLIB_RULES_INHERIT''</th>';
  93.             $html['                <th class="col3 hidelabeltxt">' JText::_('JMODIFY''</th>';
  94.             $html['                <th class="col4">' JText::_('JCURRENT''</th>';
  95.             $html['            </tr>';
  96.  
  97.             foreach ($groups as $i => $group)
  98.             {
  99.                 $selected $rules->allow($action->name$group->value);
  100.  
  101.                 $html['            <tr class="row' ($i 2'">';
  102.                 $html['                <td class="col1">' $group->text '</td>';
  103.                 $html['                <td class="col2">'
  104.                     . ($inheriting->allow($action->name$group->identities$images['allow-i'$images['deny-i']'</td>';
  105.                 $html['                <td class="col3">';
  106.                 $html['                    <select id="' $idPrefix '_' $action->name '_' $group->value
  107.                     . '" class="inputbox" size="1" name="' $control '[' $action->name '][' $group->value ']" title="'
  108.                     . JText::sprintf('JLIB_RULES_SELECT_ALLOW_DENY_GROUP'$actionTitle$group->text'">';
  109.                 $html['                        <option value=""' ($selected === null ' selected="selected"' '''>'
  110.                     . JText::_('JLIB_RULES_INHERIT''</option>';
  111.                 $html['                        <option value="1"' ($selected === true ' selected="selected"' '''>'
  112.                     . JText::_('JLIB_RULES_ALLOWED''</option>';
  113.                 $html['                        <option value="0"' ($selected === false ' selected="selected"' '''>'
  114.                     . JText::_('JLIB_RULES_DENIED''</option>';
  115.                 $html['                    </select>';
  116.                 $html['                </td>';
  117.                 $html['                <td class="col4">'
  118.                     . ($assetId ($inherited->allow($action->name$group->identities$images['allow'$images['deny'])
  119.                     : ($inheriting->allow($action->name$group->identities$images['allow'$images['deny'])) '</td>';
  120.                 $html['            </tr>';
  121.             }
  122.  
  123.             $html['            </table>';
  124.         }
  125.  
  126.         $html[JHtml::_('tabs.end');
  127.  
  128.         // Build the footer with legend and special purpose buttons.
  129.         $html['    <div class="clr"></div>';
  130.         $html['    <ul class="acllegend fltlft">';
  131.         $html['        <li class="acl-allowed">' JText::_('JLIB_RULES_ALLOWED''</li>';
  132.         $html['        <li class="acl-denied">' JText::_('JLIB_RULES_DENIED''</li>';
  133.         $html['    </ul>';
  134.         $html['</div>';
  135.  
  136.         return implode("\n"$html);
  137.     }
  138.  
  139.     /**
  140.      * Get the id of the parent asset
  141.      *
  142.      * @param   integer  $assetId  The asset for which the parentid will be returned
  143.      *
  144.      * @return  integer  The id of the parent asset
  145.      *
  146.      * @since   1.6
  147.      */
  148.     protected static function _getParentAssetId($assetId)
  149.     {
  150.         // Get a database object.
  151.         $db JFactory::getDbo();
  152.         $query $db->getQuery(true);
  153.  
  154.         // Get the user groups from the database.
  155.         $query->select($db->quoteName('parent_id'))
  156.             ->from($db->quoteName('#__assets'))
  157.             ->where($db->quoteName('id'' = ' . (int) $assetId);
  158.         $db->setQuery($query);
  159.  
  160.         return (int) $db->loadResult();
  161.     }
  162.  
  163.     /**
  164.      * Get the user groups
  165.      *
  166.      * @return  array  Array of user groups
  167.      *
  168.      * @since   1.6
  169.      */
  170.     protected static function _getUserGroups()
  171.     {
  172.         // Get a database object.
  173.         $db JFactory::getDbo();
  174.  
  175.         // Get the user groups from the database.
  176.         $db->setQuery(
  177.             'SELECT a.id AS value, a.title AS text, b.id as parent'
  178.             . ' FROM #__usergroups AS a LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt'
  179.             . ' ORDER BY a.lft ASC, b.lft ASC'
  180.         );
  181.         $result $db->loadObjectList();
  182.         $options array();
  183.  
  184.         // Pre-compute additional values.
  185.         foreach ($result as $option)
  186.         {
  187.             $end end($options);
  188.  
  189.             if ($end === false || $end->value != $option->value)
  190.             {
  191.                 $end $option;
  192.                 $end->level 0;
  193.                 $options[$end;
  194.             }
  195.             else
  196.             {
  197.                 $end->level++;
  198.             }
  199.  
  200.             $end->identities[$option->parent;
  201.         }
  202.  
  203.         return $options;
  204.     }
  205.  
  206.     /**
  207.      * Get the array of images associate with specific permissions
  208.      *
  209.      * @return  array  An associative  array of permissions and images
  210.      *
  211.      * @since   1.6
  212.      */
  213.     protected static function _getImagesArray()
  214.     {
  215.         $images['allow-l''<label class="icon-16-allow" title="' JText::_('JLIB_RULES_ALLOWED''">' JText::_('JLIB_RULES_ALLOWED')
  216.             . '</label>';
  217.         $images['deny-l''<label class="icon-16-deny" title="' JText::_('JLIB_RULES_DENIED''">' JText::_('JLIB_RULES_DENIED''</label>';
  218.         $images['allow''<a class="icon-16-allow" title="' JText::_('JLIB_RULES_ALLOWED''"> </a>';
  219.         $images['deny''<a class="icon-16-deny" title="' JText::_('JLIB_RULES_DENIED''"> </a>';
  220.         $images['allow-i''<a class="icon-16-allowinactive" title="' JText::_('JRULE_ALLOWED_INHERITED''"> </a>';
  221.         $images['deny-i''<a class="icon-16-denyinactive" title="' JText::_('JRULE_DENIED_INHERITED''"> </a>';
  222.  
  223.         return $images;
  224.     }
  225. }

Documentation generated on Tue, 19 Nov 2013 15:12:33 +0100 by phpDocumentor 1.4.3