[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/layouts/joomla/form/field/ -> rules.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  Layout
   6   *
   7   * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  defined('_JEXEC') or die;
  12  
  13  use Joomla\CMS\Access\Access;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\Layout\LayoutHelper;
  18  use Joomla\CMS\Router\Route;
  19  use Joomla\CMS\Session\Session;
  20  
  21  extract($displayData);
  22  
  23  // Get some system objects.
  24  $document = Factory::getDocument();
  25  
  26  /**
  27   * Layout variables
  28   * -----------------
  29   * @var   string   $autocomplete    Autocomplete attribute for the field.
  30   * @var   boolean  $autofocus       Is autofocus enabled?
  31   * @var   string   $class           Classes for the input.
  32   * @var   string   $description     Description of the field.
  33   * @var   boolean  $disabled        Is this field disabled?
  34   * @var   string   $group           Group the field belongs to. <fields> section in form XML.
  35   * @var   boolean  $hidden          Is this field hidden in the form?
  36   * @var   string   $hint            Placeholder for the field.
  37   * @var   string   $id              DOM id of the field.
  38   * @var   string   $label           Label of the field.
  39   * @var   string   $labelclass      Classes to apply to the label.
  40   * @var   boolean  $multiple        Does this field support multiple values?
  41   * @var   string   $name            Name of the input field.
  42   * @var   array    $options         Options available for this field.
  43   * @var   array    $groups          Available user groups.
  44   * @var   array    $actions         Actions for the asset.
  45   * @var   integer  $assetId         Access parameters.
  46   * @var   string   $component       The component.
  47   * @var   string   $section         The section.
  48   * @var   boolean  $isGlobalConfig  Current view is global config?
  49   * @var   boolean  $newItem         The new item.
  50   * @var   object   $assetRules      Rules for asset.
  51   * @var   integer  $parentAssetId   To calculate permissions.
  52   * @var   string   $dataAttribute   Miscellaneous data attributes preprocessed for HTML output
  53   * @var   array    $dataAttributes  Miscellaneous data attributes for eg, data-*.
  54   */
  55  
  56  // Add Javascript for permission change
  57  HTMLHelper::_('form.csrf');
  58  Factory::getDocument()->getWebAssetManager()
  59      ->useStyle('webcomponent.field-permissions')
  60      ->useScript('webcomponent.field-permissions')
  61      ->useStyle('webcomponent.joomla-tab')
  62      ->useScript('webcomponent.joomla-tab');
  63  
  64  // Load JavaScript message titles
  65  Text::script('ERROR');
  66  Text::script('WARNING');
  67  Text::script('NOTICE');
  68  Text::script('MESSAGE');
  69  
  70  // Add strings for JavaScript error translations.
  71  Text::script('JLIB_JS_AJAX_ERROR_CONNECTION_ABORT');
  72  Text::script('JLIB_JS_AJAX_ERROR_NO_CONTENT');
  73  Text::script('JLIB_JS_AJAX_ERROR_OTHER');
  74  Text::script('JLIB_JS_AJAX_ERROR_PARSE');
  75  Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT');
  76  
  77  // Ajax request data.
  78  $ajaxUri = Route::_('index.php?option=com_config&task=application.store&format=json&' . Session::getFormToken() . '=1');
  79  ?>
  80  
  81  <?php // Description ?>
  82  <details>
  83      <summary class="rule-notes">
  84          <?php echo Text::_('JLIB_RULES_SETTINGS_DESC'); ?>
  85      </summary>
  86      <div class="rule-notes">
  87      <?php
  88      if ($section === 'component' || !$section) {
  89          echo Text::alt('JLIB_RULES_SETTING_NOTES', $component);
  90      } else {
  91          echo Text::alt('JLIB_RULES_SETTING_NOTES_ITEM', $component . '_' . $section);
  92      }
  93      ?>
  94      </div>
  95  </details>
  96  <?php // Begin tabs ?>
  97  <joomla-field-permissions class="row mb-2" data-uri="<?php echo $ajaxUri; ?>" <?php echo $dataAttribute; ?>>
  98      <joomla-tab orientation="vertical" id="permissions-sliders" recall breakpoint="728">
  99          <?php // Initial Active Pane ?>
 100          <?php foreach ($groups as $group) : ?>
 101              <?php $active = (int) $group->value === 1 ? ' active' : ''; ?>
 102              <joomla-tab-element class="tab-pane" <?php echo $active; ?> name="<?php echo htmlentities(LayoutHelper::render('joomla.html.treeprefix', array('level' => $group->level + 1)), ENT_COMPAT, 'utf-8') . $group->text; ?>" id="permission-<?php echo $group->value; ?>">
 103                  <table class="table respTable">
 104                      <thead>
 105                          <tr>
 106                              <th class="actions w-30" id="actions-th<?php echo $group->value; ?>">
 107                                  <span class="acl-action"><?php echo Text::_('JLIB_RULES_ACTION'); ?></span>
 108                              </th>
 109  
 110                              <th class="settings w-40" id="settings-th<?php echo $group->value; ?>">
 111                                  <span class="acl-action"><?php echo Text::_('JLIB_RULES_SELECT_SETTING'); ?></span>
 112                              </th>
 113  
 114                              <th class="w-30" id="aclaction-th<?php echo $group->value; ?>">
 115                                  <span class="acl-action"><?php echo Text::_('JLIB_RULES_CALCULATED_SETTING'); ?></span>
 116                              </th>
 117                          </tr>
 118                      </thead>
 119                      <tbody>
 120  
 121                          <?php // Check if this group has super user permissions ?>
 122                          <?php $isSuperUserGroup = Access::checkGroup($group->value, 'core.admin'); ?>
 123                          <?php foreach ($actions as $action) : ?>
 124                              <tr>
 125                                  <td class="oddCol" data-label="<?php echo Text::_('JLIB_RULES_ACTION'); ?>" headers="actions-th<?php echo $group->value; ?>">
 126                                      <label for="<?php echo $id; ?>_<?php echo $action->name; ?>_<?php echo $group->value; ?>">
 127                                          <?php echo Text::_($action->title); ?>
 128                                      </label>
 129                                      <?php if (!empty($action->description)) : ?>
 130                                          <div role="tooltip" id="tip-<?php echo $id; ?>">
 131                                              <?php echo htmlspecialchars(Text::_($action->description)); ?>
 132                                          </div>
 133                                      <?php endif; ?>
 134                                  </td>
 135                                  <td data-label="<?php echo Text::_('JLIB_RULES_SELECT_SETTING'); ?>" headers="settings-th<?php echo $group->value; ?>">
 136                                      <div class="d-flex align-items-center">
 137                                          <select data-onchange-task="permissions.apply"
 138                                                  class="form-select novalidate"
 139                                                  name="<?php echo $name; ?>[<?php echo $action->name; ?>][<?php echo $group->value; ?>]"
 140                                                  id="<?php echo $id; ?>_<?php echo $action->name; ?>_<?php echo $group->value; ?>" >
 141                                              <?php
 142                                              /**
 143                                               * Possible values:
 144                                               * null = not set means inherited
 145                                               * false = denied
 146                                               * true = allowed
 147                                               */
 148  
 149                                              // Get the actual setting for the action for this group. ?>
 150                                              <?php $assetRule = $newItem === false ? $assetRules->allow($action->name, $group->value) : null;?>
 151  
 152                                              <?php // Build the dropdowns for the permissions sliders
 153                                                  // The parent group has "Not Set", all children can rightly "Inherit" from that.?>
 154                                              <option value="" <?php echo ($assetRule === null ? ' selected="selected"' : ''); ?>>
 155                                              <?php echo Text::_(empty($group->parent_id) && $isGlobalConfig ? 'JLIB_RULES_NOT_SET' : 'JLIB_RULES_INHERITED'); ?></option>
 156                                              <option value="1" <?php echo ($assetRule === true ? ' selected="selected"' : ''); ?>>
 157                                              <?php echo Text::_('JLIB_RULES_ALLOWED'); ?></option>
 158                                              <option value="0" <?php echo ($assetRule === false ? ' selected="selected"' : ''); ?>>
 159                                              <?php echo Text::_('JLIB_RULES_DENIED'); ?></option>
 160  
 161                                          </select>&#160;
 162                                          <span id="icon_<?php echo $id; ?>_<?php echo $action->name; ?>_<?php echo $group->value; ?>"></span>
 163                                      </div>
 164                                  </td>
 165  
 166                                  <td data-label="<?php echo Text::_('JLIB_RULES_CALCULATED_SETTING'); ?>" headers="aclaction-th<?php echo $group->value; ?>">
 167                                      <?php $result = array(); ?>
 168                                      <?php // Get the group, group parent id, and group global config recursive calculated permission for the chosen action. ?>
 169                                      <?php $inheritedGroupRule   = Access::checkGroup((int) $group->value, $action->name, $assetId);
 170                                      $inheritedGroupParentAssetRule = !empty($parentAssetId) ? Access::checkGroup($group->value, $action->name, $parentAssetId) : null;
 171                                      $inheritedParentGroupRule      = !empty($group->parent_id) ? Access::checkGroup($group->parent_id, $action->name, $assetId) : null;
 172  
 173                                      // Current group is a Super User group, so calculated setting is "Allowed (Super User)".
 174                                      if ($isSuperUserGroup) {
 175                                          $result['class'] = 'badge bg-success';
 176                                          $result['text']  = '<span class="icon-lock icon-white" aria-hidden="true"></span>' . Text::_('JLIB_RULES_ALLOWED_ADMIN');
 177                                      } else {
 178                                          // First get the real recursive calculated setting and add (Inherited) to it.
 179  
 180                                          // If recursive calculated setting is "Denied" or null. Calculated permission is "Not Allowed (Inherited)".
 181                                          if ($inheritedGroupRule === null || $inheritedGroupRule === false) {
 182                                              $result['class'] = 'badge bg-danger';
 183                                              $result['text']  = Text::_('JLIB_RULES_NOT_ALLOWED_INHERITED');
 184                                          } else {
 185                                              // If recursive calculated setting is "Allowed". Calculated permission is "Allowed (Inherited)".
 186                                              $result['class'] = 'badge bg-success';
 187                                              $result['text']  = Text::_('JLIB_RULES_ALLOWED_INHERITED');
 188                                          }
 189  
 190                                          // Second part: Overwrite the calculated permissions labels if there is an explicit permission in the current group.
 191  
 192                                          /**
 193                                          * @todo: incorrect info
 194                                          * If a component has a permission that doesn't exists in global config (ex: frontend editing in com_modules) by default
 195                                          * we get "Not Allowed (Inherited)" when we should get "Not Allowed (Default)".
 196                                          */
 197  
 198                                          // If there is an explicit permission "Not Allowed". Calculated permission is "Not Allowed".
 199                                          if ($assetRule === false) {
 200                                              $result['class'] = 'badge bg-danger';
 201                                              $result['text']  =  Text::_('JLIB_RULES_NOT_ALLOWED');
 202                                          } elseif ($assetRule === true) {
 203                                              // If there is an explicit permission is "Allowed". Calculated permission is "Allowed".
 204                                              $result['class'] = 'badge bg-success';
 205                                              $result['text']  = Text::_('JLIB_RULES_ALLOWED');
 206                                          }
 207  
 208                                          // Third part: Overwrite the calculated permissions labels for special cases.
 209  
 210                                          // Global configuration with "Not Set" permission. Calculated permission is "Not Allowed (Default)".
 211                                          if (empty($group->parent_id) && $isGlobalConfig === true && $assetRule === null) {
 212                                              $result['class'] = 'badge bg-danger';
 213                                              $result['text']  = Text::_('JLIB_RULES_NOT_ALLOWED_DEFAULT');
 214                                          } elseif ($inheritedGroupParentAssetRule === false || $inheritedParentGroupRule === false) {
 215                                              /**
 216                                               * Component/Item with explicit "Denied" permission at parent Asset (Category, Component or Global config) configuration.
 217                                               * Or some parent group has an explicit "Denied".
 218                                               * Calculated permission is "Not Allowed (Locked)".
 219                                               */
 220                                              $result['class'] = 'badge bg-danger';
 221                                              $result['text']  = '<span class="icon-lock icon-white" aria-hidden="true"></span>' . Text::_('JLIB_RULES_NOT_ALLOWED_LOCKED');
 222                                          }
 223                                      }
 224                                      ?>
 225                                      <output><span class="<?php echo $result['class']; ?>"><?php echo $result['text']; ?></span></output>
 226                                  </td>
 227                              </tr>
 228                          <?php endforeach; ?>
 229                      </tbody>
 230                  </table>
 231              </joomla-tab-element>
 232          <?php endforeach; ?>
 233      </joomla-tab>
 234  </joomla-field-permissions>


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer