[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_users/src/View/Profile/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   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\Site\View\Profile;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\MVC\View\GenericDataException;
  16  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  17  use Joomla\CMS\Object\CMSObject;
  18  use Joomla\CMS\Plugin\PluginHelper;
  19  use Joomla\CMS\Router\Route;
  20  use Joomla\CMS\User\User;
  21  use Joomla\Component\Users\Administrator\Helper\Mfa;
  22  use Joomla\Database\DatabaseDriver;
  23  
  24  // phpcs:disable PSR1.Files.SideEffects
  25  \defined('_JEXEC') or die;
  26  // phpcs:enable PSR1.Files.SideEffects
  27  
  28  /**
  29   * Profile view class for Users.
  30   *
  31   * @since  1.6
  32   */
  33  class HtmlView extends BaseHtmlView
  34  {
  35      /**
  36       * Profile form data for the user
  37       *
  38       * @var  User
  39       */
  40      protected $data;
  41  
  42      /**
  43       * The Form object
  44       *
  45       * @var  \Joomla\CMS\Form\Form
  46       */
  47      protected $form;
  48  
  49      /**
  50       * The page parameters
  51       *
  52       * @var  \Joomla\Registry\Registry|null
  53       */
  54      protected $params;
  55  
  56      /**
  57       * The model state
  58       *
  59       * @var  CMSObject
  60       */
  61      protected $state;
  62  
  63      /**
  64       * An instance of DatabaseDriver.
  65       *
  66       * @var    DatabaseDriver
  67       * @since  3.6.3
  68       *
  69       * @deprecated  5.0 Will be removed without replacement
  70       */
  71      protected $db;
  72  
  73      /**
  74       * The page class suffix
  75       *
  76       * @var    string
  77       * @since  4.0.0
  78       */
  79      protected $pageclass_sfx = '';
  80  
  81      /**
  82       * The Multi-factor Authentication configuration interface for the user.
  83       *
  84       * @var   string|null
  85       * @since 4.2.0
  86       */
  87      protected $mfaConfigurationUI;
  88  
  89      /**
  90       * Execute and display a template script.
  91       *
  92       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  93       *
  94       * @return  void|boolean
  95       *
  96       * @since   1.6
  97       * @throws  \Exception
  98       */
  99      public function display($tpl = null)
 100      {
 101          $user = $this->getCurrentUser();
 102  
 103          // Get the view data.
 104          $this->data               = $this->get('Data');
 105          $this->form               = $this->getModel()->getForm(new CMSObject(['id' => $user->id]));
 106          $this->state              = $this->get('State');
 107          $this->params             = $this->state->get('params');
 108          $this->mfaConfigurationUI = Mfa::getConfigurationInterface($user);
 109          $this->db                 = Factory::getDbo();
 110  
 111          // Check for errors.
 112          if (count($errors = $this->get('Errors'))) {
 113              throw new GenericDataException(implode("\n", $errors), 500);
 114          }
 115  
 116          // View also takes responsibility for checking if the user logged in with remember me.
 117          $cookieLogin = $user->get('cookieLogin');
 118  
 119          if (!empty($cookieLogin)) {
 120              // If so, the user must login to edit the password and other data.
 121              // What should happen here? Should we force a logout which destroys the cookies?
 122              $app = Factory::getApplication();
 123              $app->enqueueMessage(Text::_('JGLOBAL_REMEMBER_MUST_LOGIN'), 'message');
 124              $app->redirect(Route::_('index.php?option=com_users&view=login', false));
 125  
 126              return false;
 127          }
 128  
 129          // Check if a user was found.
 130          if (!$this->data->id) {
 131              throw new \Exception(Text::_('JERROR_USERS_PROFILE_NOT_FOUND'), 404);
 132          }
 133  
 134          PluginHelper::importPlugin('content');
 135          $this->data->text = '';
 136          Factory::getApplication()->triggerEvent('onContentPrepare', array ('com_users.user', &$this->data, &$this->data->params, 0));
 137          unset($this->data->text);
 138  
 139          // Check for layout from menu item.
 140          $query = Factory::getApplication()->getMenu()->getActive()->query;
 141  
 142          if (
 143              isset($query['layout']) && isset($query['option']) && $query['option'] === 'com_users'
 144              && isset($query['view']) && $query['view'] === 'profile'
 145          ) {
 146              $this->setLayout($query['layout']);
 147          }
 148  
 149          // Escape strings for HTML output
 150          $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx', ''));
 151  
 152          $this->prepareDocument();
 153  
 154          parent::display($tpl);
 155      }
 156  
 157      /**
 158       * Prepares the document
 159       *
 160       * @return  void
 161       *
 162       * @since   1.6
 163       * @throws  \Exception
 164       */
 165      protected function prepareDocument()
 166      {
 167          // Because the application sets a default page title,
 168          // we need to get it from the menu item itself
 169          $menu = Factory::getApplication()->getMenu()->getActive();
 170  
 171          if ($menu) {
 172              $this->params->def('page_heading', $this->params->get('page_title', $this->getCurrentUser()->name));
 173          } else {
 174              $this->params->def('page_heading', Text::_('COM_USERS_PROFILE'));
 175          }
 176  
 177          $this->setDocumentTitle($this->params->get('page_title', ''));
 178  
 179          if ($this->params->get('menu-meta_description')) {
 180              $this->document->setDescription($this->params->get('menu-meta_description'));
 181          }
 182  
 183          if ($this->params->get('robots')) {
 184              $this->document->setMetaData('robots', $this->params->get('robots'));
 185          }
 186      }
 187  }


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