[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Service/HTML/ -> Users.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Users\Administrator\Service\HTML;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Filesystem\Path;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Language\LanguageHelper;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\Router\Route;
  19  use Joomla\CMS\Uri\Uri;
  20  use Joomla\Database\ParameterType;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Extended Utility class for the Users component.
  28   *
  29   * @since  2.5
  30   */
  31  class Users
  32  {
  33      /**
  34       * Display an image.
  35       *
  36       * @param   string  $src  The source of the image
  37       *
  38       * @return  string  A <img> element if the specified file exists, otherwise, a null string
  39       *
  40       * @since   2.5
  41       * @throws  \Exception
  42       */
  43      public function image($src)
  44      {
  45          $src = preg_replace('#[^A-Z0-9\-_\./]#i', '', $src);
  46          $file = JPATH_SITE . '/' . $src;
  47  
  48          Path::check($file);
  49  
  50          if (!file_exists($file)) {
  51              return '';
  52          }
  53  
  54          return '<img src="' . Uri::root() . $src . '" alt="">';
  55      }
  56  
  57      /**
  58       * Displays an icon to add a note for this user.
  59       *
  60       * @param   integer  $userId  The user ID
  61       *
  62       * @return  string  A link to add a note
  63       *
  64       * @since   2.5
  65       */
  66      public function addNote($userId)
  67      {
  68          $title = Text::_('COM_USERS_ADD_NOTE');
  69  
  70          return '<a href="' . Route::_('index.php?option=com_users&task=note.add&u_id=' . (int) $userId)
  71              . '" class="btn btn-secondary btn-sm"><span class="icon-plus pe-1" aria-hidden="true">'
  72              . '</span>' . $title . '</a>';
  73      }
  74  
  75      /**
  76       * Displays an icon to filter the notes list on this user.
  77       *
  78       * @param   integer  $count   The number of notes for the user
  79       * @param   integer  $userId  The user ID
  80       *
  81       * @return  string  A link to apply a filter
  82       *
  83       * @since   2.5
  84       */
  85      public function filterNotes($count, $userId)
  86      {
  87          if (empty($count)) {
  88              return '';
  89          }
  90  
  91          $title = Text::_('COM_USERS_FILTER_NOTES');
  92  
  93          return '<a href="' . Route::_('index.php?option=com_users&view=notes&filter[search]=uid:' . (int) $userId)
  94              . '" class="dropdown-item"><span class="icon-list pe-1" aria-hidden="true"></span>' . $title . '</a>';
  95      }
  96  
  97      /**
  98       * Displays a note icon.
  99       *
 100       * @param   integer  $count   The number of notes for the user
 101       * @param   integer  $userId  The user ID
 102       *
 103       * @return  string  A link to a modal window with the user notes
 104       *
 105       * @since   2.5
 106       */
 107      public function notes($count, $userId)
 108      {
 109          if (empty($count)) {
 110              return '';
 111          }
 112  
 113          $title = Text::plural('COM_USERS_N_USER_NOTES', $count);
 114  
 115          return '<button  type="button" data-bs-target="#userModal_' . (int) $userId . '" id="modal-' . (int) $userId
 116              . '" data-bs-toggle="modal" class="dropdown-item"><span class="icon-eye pe-1" aria-hidden="true"></span>' . $title . '</button>';
 117      }
 118  
 119      /**
 120       * Renders the modal html.
 121       *
 122       * @param   integer  $count   The number of notes for the user
 123       * @param   integer  $userId  The user ID
 124       *
 125       * @return  string   The html for the rendered modal
 126       *
 127       * @since   3.4.1
 128       */
 129      public function notesModal($count, $userId)
 130      {
 131          if (empty($count)) {
 132              return '';
 133          }
 134  
 135          $title = Text::plural('COM_USERS_N_USER_NOTES', $count);
 136          $footer = '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">'
 137              . Text::_('JTOOLBAR_CLOSE') . '</button>';
 138  
 139          return HTMLHelper::_(
 140              'bootstrap.renderModal',
 141              'userModal_' . (int) $userId,
 142              array(
 143                  'title'       => $title,
 144                  'backdrop'    => 'static',
 145                  'keyboard'    => true,
 146                  'closeButton' => true,
 147                  'footer'      => $footer,
 148                  'url'         => Route::_('index.php?option=com_users&view=notes&tmpl=component&layout=modal&filter[user_id]=' . (int) $userId),
 149                  'height'      => '300px',
 150                  'width'       => '800px',
 151              )
 152          );
 153      }
 154  
 155      /**
 156       * Build an array of block/unblock user states to be used by jgrid.state,
 157       * State options will be different for any user
 158       * and for currently logged in user
 159       *
 160       * @param   boolean  $self  True if state array is for currently logged in user
 161       *
 162       * @return  array  a list of possible states to display
 163       *
 164       * @since  3.0
 165       */
 166      public function blockStates($self = false)
 167      {
 168          if ($self) {
 169              $states = array(
 170                  1 => array(
 171                      'task'           => 'unblock',
 172                      'text'           => '',
 173                      'active_title'   => 'COM_USERS_TOOLBAR_BLOCK',
 174                      'inactive_title' => '',
 175                      'tip'            => true,
 176                      'active_class'   => 'unpublish',
 177                      'inactive_class' => 'unpublish',
 178                  ),
 179                  0 => array(
 180                      'task'           => 'block',
 181                      'text'           => '',
 182                      'active_title'   => '',
 183                      'inactive_title' => 'COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF',
 184                      'tip'            => true,
 185                      'active_class'   => 'publish',
 186                      'inactive_class' => 'publish',
 187                  )
 188              );
 189          } else {
 190              $states = array(
 191                  1 => array(
 192                      'task'           => 'unblock',
 193                      'text'           => '',
 194                      'active_title'   => 'COM_USERS_TOOLBAR_UNBLOCK',
 195                      'inactive_title' => '',
 196                      'tip'            => true,
 197                      'active_class'   => 'unpublish',
 198                      'inactive_class' => 'unpublish',
 199                  ),
 200                  0 => array(
 201                      'task'           => 'block',
 202                      'text'           => '',
 203                      'active_title'   => 'COM_USERS_TOOLBAR_BLOCK',
 204                      'inactive_title' => '',
 205                      'tip'            => true,
 206                      'active_class'   => 'publish',
 207                      'inactive_class' => 'publish',
 208                  )
 209              );
 210          }
 211  
 212          return $states;
 213      }
 214  
 215      /**
 216       * Build an array of activate states to be used by jgrid.state,
 217       *
 218       * @return  array  a list of possible states to display
 219       *
 220       * @since  3.0
 221       */
 222      public function activateStates()
 223      {
 224          $states = array(
 225              1 => array(
 226                  'task'           => 'activate',
 227                  'text'           => '',
 228                  'active_title'   => 'COM_USERS_TOOLBAR_ACTIVATE',
 229                  'inactive_title' => '',
 230                  'tip'            => true,
 231                  'active_class'   => 'unpublish',
 232                  'inactive_class' => 'unpublish',
 233              ),
 234              0 => array(
 235                  'task'           => '',
 236                  'text'           => '',
 237                  'active_title'   => '',
 238                  'inactive_title' => 'COM_USERS_ACTIVATED',
 239                  'tip'            => true,
 240                  'active_class'   => 'publish',
 241                  'inactive_class' => 'publish',
 242              )
 243          );
 244  
 245          return $states;
 246      }
 247  
 248      /**
 249       * Get the sanitized value
 250       *
 251       * @param   mixed  $value  Value of the field
 252       *
 253       * @return  mixed  String/void
 254       *
 255       * @since   1.6
 256       */
 257      public function value($value)
 258      {
 259          if (is_string($value)) {
 260              $value = trim($value);
 261          }
 262  
 263          if (empty($value)) {
 264              return Text::_('COM_USERS_PROFILE_VALUE_NOT_FOUND');
 265          } elseif (!is_array($value)) {
 266              return htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
 267          }
 268      }
 269  
 270      /**
 271       * Get the space symbol
 272       *
 273       * @param   mixed  $value  Value of the field
 274       *
 275       * @return  string
 276       *
 277       * @since   1.6
 278       */
 279      public function spacer($value)
 280      {
 281          return '';
 282      }
 283  
 284      /**
 285       * Get the sanitized template style
 286       *
 287       * @param   mixed  $value  Value of the field
 288       *
 289       * @return  mixed  String/void
 290       *
 291       * @since   1.6
 292       */
 293      public function templatestyle($value)
 294      {
 295          if (empty($value)) {
 296              return static::value($value);
 297          } else {
 298              $db = Factory::getDbo();
 299              $query = $db->getQuery(true)
 300                  ->select($db->quoteName('title'))
 301                  ->from($db->quoteName('#__template_styles'))
 302                  ->where($db->quoteName('id') . ' = :id')
 303                  ->bind(':id', $value, ParameterType::INTEGER);
 304              $db->setQuery($query);
 305              $title = $db->loadResult();
 306  
 307              if ($title) {
 308                  return htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
 309              } else {
 310                  return static::value('');
 311              }
 312          }
 313      }
 314  
 315      /**
 316       * Get the sanitized language
 317       *
 318       * @param   mixed  $value  Value of the field
 319       *
 320       * @return  mixed  String/void
 321       *
 322       * @since   1.6
 323       */
 324      public function admin_language($value)
 325      {
 326          if (!$value) {
 327              return static::value($value);
 328          }
 329  
 330          $path   = LanguageHelper::getLanguagePath(JPATH_ADMINISTRATOR, $value);
 331          $file   = $path . '/langmetadata.xml';
 332  
 333          if (!is_file($file)) {
 334              // For language packs from before 4.0.
 335              $file = $path . '/' . $value . '.xml';
 336  
 337              if (!is_file($file)) {
 338                  return static::value($value);
 339              }
 340          }
 341  
 342          $result = LanguageHelper::parseXMLLanguageFile($file);
 343  
 344          if ($result) {
 345              return htmlspecialchars($result['name'], ENT_COMPAT, 'UTF-8');
 346          }
 347  
 348          return static::value($value);
 349      }
 350  
 351      /**
 352       * Get the sanitized language
 353       *
 354       * @param   mixed  $value  Value of the field
 355       *
 356       * @return  mixed  String/void
 357       *
 358       * @since   1.6
 359       */
 360      public function language($value)
 361      {
 362          if (!$value) {
 363              return static::value($value);
 364          }
 365  
 366          $path   = LanguageHelper::getLanguagePath(JPATH_SITE, $value);
 367          $file   = $path . '/langmetadata.xml';
 368  
 369          if (!is_file($file)) {
 370              // For language packs from before 4.0.
 371              $file = $path . '/' . $value . '.xml';
 372  
 373              if (!is_file($file)) {
 374                  return static::value($value);
 375              }
 376          }
 377  
 378          $result = LanguageHelper::parseXMLLanguageFile($file);
 379  
 380          if ($result) {
 381              return htmlspecialchars($result['name'], ENT_COMPAT, 'UTF-8');
 382          }
 383  
 384          return static::value($value);
 385      }
 386  
 387      /**
 388       * Get the sanitized editor name
 389       *
 390       * @param   mixed  $value  Value of the field
 391       *
 392       * @return  mixed  String/void
 393       *
 394       * @since   1.6
 395       */
 396      public function editor($value)
 397      {
 398          if (empty($value)) {
 399              return static::value($value);
 400          } else {
 401              $db = Factory::getDbo();
 402              $lang = Factory::getLanguage();
 403              $query = $db->getQuery(true)
 404                  ->select($db->quoteName('name'))
 405                  ->from($db->quoteName('#__extensions'))
 406                  ->where($db->quoteName('element') . ' = :element')
 407                  ->where($db->quoteName('folder') . ' = ' . $db->quote('editors'))
 408                  ->bind(':element', $value);
 409              $db->setQuery($query);
 410              $title = $db->loadResult();
 411  
 412              if ($title) {
 413                  $lang->load("plg_editors_$value.sys", JPATH_ADMINISTRATOR)
 414                  || $lang->load("plg_editors_$value.sys", JPATH_PLUGINS . '/editors/' . $value);
 415                  $lang->load($title . '.sys');
 416  
 417                  return Text::_($title);
 418              } else {
 419                  return static::value('');
 420              }
 421          }
 422      }
 423  }


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