- md5
- 8dd8b31369b1e6bbf4deecb15cb8859d
- sha1
- e5f756b00ab1ee78b6d0d03066c4855595a8008c
- sha256
- 8b572cf3d41eb83acd9dcd3effa1b665f32cd55686f525a1a2a48882a36c4e27
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
<?php
/**
* @package Joomla.Plugin
* @subpackage System.logout
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\System\Logout\Extension;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Event\User\LogoutEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Plugin class for logout redirect handling.
*
* @since 1.6
*/
final class Logout extends CMSPlugin implements SubscriberInterface
{
/**
* @param DispatcherInterface $dispatcher The object to observe -- event dispatcher.
* @param array $config An optional associative array of configuration settings.
* @param CMSApplicationInterface $app The object to observe -- event dispatcher.
*
* @since 1.6
*/
public function __construct(DispatcherInterface $dispatcher, array $config, CMSApplicationInterface $app)
{
parent::__construct($dispatcher, $config);
$this->setApplication($app);
// If we are on admin don't process.
if (!$this->getApplication()->isClient('site')) {
return;
}
$hash = ApplicationHelper::getHash('PlgSystemLogout');
if ($this->getApplication()->getInput()->cookie->getString($hash)) {
// Destroy the cookie.
$this->getApplication()->getInput()->cookie->set(
$hash,
'',
[
'expires' => 1,
'path' => $this->getApplication()->get('cookie_path', '/'),
'domain' => $this->getApplication()->get('cookie_domain', ''),
]
);
}
}
/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since 5.3.0
*/
public static function getSubscribedEvents(): array
{
return [
'onUserLogout' => 'onUserLogout',
];
}
/**
* Method to handle any logout logic and report back to the subject.
*
* @param LogoutEvent $event The event instance.
*
* @return void
*
* @since 1.6
*/
public function onUserLogout(LogoutEvent $event): void
{
if ($this->getApplication()->isClient('site')) {
// Create the cookie.
$this->getApplication()->getInput()->cookie->set(
ApplicationHelper::getHash('PlgSystemLogout'),
true,
[
'expires' => time() + 86400,
'path' => $this->getApplication()->get('cookie_path', '/'),
'domain' => $this->getApplication()->get('cookie_domain', ''),
'secure' => $this->getApplication()->isHttpsForced(),
'httponly' => true,
]
);
}
}
}
The same content is in 2 releases, Joomla 5.4.0-beta1 to 6.0.0-beta1. See them all, or every version of this file.