- md5
- 47f27b2b60307f73247c0db1839fe28f
- sha1
- 2a5470a8d30f9611be6781483ecb7f88b57d0cbf
- sha256
- 50f6a1eb5a59aff21d0ee2d4c68bac80c4a20e4831cb0d34a31055e78162ba87
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Users\Site\View\Profile;
use Joomla\CMS\Event\Content\ContentPrepareEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\User;
use Joomla\Component\Users\Administrator\Helper\Mfa;
use Joomla\Component\Users\Site\Model\ProfileModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Profile view class for Users.
*
* @since 1.6
*/
class HtmlView extends BaseHtmlView
{
/**
* Profile form data for the user
*
* @var User
*/
protected $data;
/**
* The Form object
*
* @var \Joomla\CMS\Form\Form
*/
protected $form;
/**
* The page parameters
*
* @var \Joomla\Registry\Registry|null
*/
protected $params;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* The page class suffix
*
* @var string
* @since 4.0.0
*/
protected $pageclass_sfx = '';
/**
* The Multi-factor Authentication configuration interface for the user.
*
* @var string|null
* @since 4.2.0
*/
protected $mfaConfigurationUI;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void|boolean
*
* @since 1.6
* @throws \Exception
*/
public function display($tpl = null)
{
$user = $this->getCurrentUser();
/** @var ProfileModel $model */
$model = $this->getModel();
$this->data = $model->getData();
$this->form = $model->getForm();
$this->state = $model->getState();
$this->params = $this->state->get('params');
$this->mfaConfigurationUI = Mfa::getConfigurationInterface($user);
// Check for errors.
if (\count($errors = $model->getErrors())) {
throw new GenericDataException(implode("\n", $errors), 500);
}
// View also takes responsibility for checking if the user logged in with remember me.
if (isset($user->cookieLogin) && !empty($user->cookieLogin)) {
// If so, the user must login to edit the password and other data.
// What should happen here? Should we force a logout which destroys the cookies?
$app = Factory::getApplication();
$app->enqueueMessage(Text::_('JGLOBAL_REMEMBER_MUST_LOGIN'), 'message');
$app->redirect(Route::_('index.php?option=com_users&view=login', false));
return false;
}
// Check if a user was found.
if (!$this->data->id) {
throw new \Exception(Text::_('JERROR_USERS_PROFILE_NOT_FOUND'), 404);
}
$dispatcher = $this->getDispatcher();
PluginHelper::importPlugin('content', null, true, $dispatcher);
$this->data->text = '';
$dispatcher->dispatch('onContentPrepare', new ContentPrepareEvent('onContentPrepare', [
'context' => 'com_users.user',
'subject' => $this->data,
'params' => $this->data->params,
'page' => 0,
]));
unset($this->data->text);
// Check for layout from menu item.
$active = Factory::getApplication()->getMenu()->getActive();
if (
$active && isset($active->query['layout'], $active->query['option'])
&& $active->query['option'] === 'com_users'
&& isset($active->query['view']) && $active->query['view'] === 'profile'
) {
$this->setLayout($active->query['layout']);
}
// Escape strings for HTML output
$this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx', ''));
$this->prepareDocument();
parent::display($tpl);
}
/**
* Prepares the document
*
* @return void
*
* @since 1.6
* @throws \Exception
*/
protected function prepareDocument()
{
// Because the application sets a default page title,
// we need to get it from the menu item itself
$menu = Factory::getApplication()->getMenu()->getActive();
if ($menu) {
$this->params->def('page_heading', $this->params->get('page_title', $this->getCurrentUser()->name));
} else {
$this->params->def('page_heading', Text::_('COM_USERS_PROFILE'));
}
$this->setDocumentTitle($this->params->get('page_title', ''));
if ($this->params->get('menu-meta_description')) {
$this->getDocument()->setDescription($this->params->get('menu-meta_description'));
}
if ($this->params->get('robots')) {
$this->getDocument()->setMetaData('robots', $this->params->get('robots'));
}
}
}
The same content is in 8 releases, Joomla 6.2.0-alpha2 to 6.2.0. See them all, or every version of this file.