[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/system/logout/ -> logout.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  System.logout
   6   *
   7   * @copyright   (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9  
  10   * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
  11   */
  12  
  13  use Joomla\CMS\Application\ApplicationHelper;
  14  use Joomla\CMS\Plugin\CMSPlugin;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('_JEXEC') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Plugin class for logout redirect handling.
  22   *
  23   * @since  1.6
  24   */
  25  class PlgSystemLogout extends CMSPlugin
  26  {
  27      /**
  28       * @var    \Joomla\CMS\Application\CMSApplication
  29       *
  30       * @since  3.7.3
  31       */
  32      protected $app;
  33  
  34      /**
  35       * Load the language file on instantiation.
  36       *
  37       * @var    boolean
  38       *
  39       * @since  3.1
  40       */
  41      protected $autoloadLanguage = true;
  42  
  43      /**
  44       * @param   object  &$subject  The object to observe -- event dispatcher.
  45       * @param   object  $config    An optional associative array of configuration settings.
  46       *
  47       * @since   1.6
  48       */
  49      public function __construct(&$subject, $config)
  50      {
  51          parent::__construct($subject, $config);
  52  
  53          // If we are on admin don't process.
  54          if (!$this->app->isClient('site')) {
  55              return;
  56          }
  57  
  58          $hash  = ApplicationHelper::getHash('PlgSystemLogout');
  59  
  60          if ($this->app->input->cookie->getString($hash)) {
  61              // Destroy the cookie.
  62              $this->app->input->cookie->set(
  63                  $hash,
  64                  '',
  65                  1,
  66                  $this->app->get('cookie_path', '/'),
  67                  $this->app->get('cookie_domain', '')
  68              );
  69          }
  70      }
  71  
  72      /**
  73       * Method to handle any logout logic and report back to the subject.
  74       *
  75       * @param   array  $user     Holds the user data.
  76       * @param   array  $options  Array holding options (client, ...).
  77       *
  78       * @return  boolean  Always returns true.
  79       *
  80       * @since   1.6
  81       */
  82      public function onUserLogout($user, $options = [])
  83      {
  84          if ($this->app->isClient('site')) {
  85              // Create the cookie.
  86              $this->app->input->cookie->set(
  87                  ApplicationHelper::getHash('PlgSystemLogout'),
  88                  true,
  89                  time() + 86400,
  90                  $this->app->get('cookie_path', '/'),
  91                  $this->app->get('cookie_domain', ''),
  92                  $this->app->isHttpsForced(),
  93                  true
  94              );
  95          }
  96  
  97          return true;
  98      }
  99  }


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