From 7cebcd52bf3b9d2fd6055477d112aed699c3cc1d Mon Sep 17 00:00:00 2001 From: Stefan Herzog Date: Mon, 23 Aug 2021 12:13:06 +0200 Subject: [PATCH] Adding v1.1.4 --- block_access.php | 70 +++++++++++++++++++++++------------------------- block_access.xml | 20 +++++++------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/block_access.php b/block_access.php index a86ccb6..da56d6e 100644 --- a/block_access.php +++ b/block_access.php @@ -10,76 +10,72 @@ jimport('joomla.plugin.plugin'); jimport('joomla.error.exception'); +use Joomla\CMS\Uri\Uri; +use Joomla\CMS\Application\CMSApplication; class plgSystemBlock_access extends JPlugin { - - - function plgSystemBlock_access(& $subject, $config) { parent::__construct($subject, $config); } - + function onAfterInitialise() // onAfterDispatch() { - $app = JFactory::getApplication(); - $user = JFactory::getUser(); - $session = JFactory::getSession(); - + $app = JFactory::getApplication(); + $user = JFactory::getUser(); + $session= JFactory::getSession(); + if (!$this->params->get('securitykey') || $session->get('block_access')) - { + { return; } // Check if security key has been entered $logged = isset($_GET[$this->params->get('securitykey')]); - + // Check the current area the user wants so enter (site / admin) - if ($app->isSite()) + if ($app->isClient('site')) { $area = "site"; } - - if ($app->isAdmin()) + + if ($app->isClient('administrator')) { $area = "admin"; } - + $securedArea = strtolower($this->params->get('area')); - + if($area == $securedArea || $securedArea == "both") { - $this->blockArea($logged); - } - - } - - function blockArea($logged) - { - $session = JFactory::getSession(); - - if (!$logged) - { - if($this->params->get('typeOfBlock') == "message") + if ($logged) { - header('HTTP/1.0 403 Forbidden'); - die($this->params->get('text')); + $session = JFactory::getSession(); + $session->set('block_access', true); + // return true; } - elseif($this->params->get('typeOfBlock') == "errorpage") - { - header("HTTP/1.0 404 Not Found"); - header("Location:".JUri::root()."404"); + else { + $this->blockArea(); } + } + } + + function blockArea() + { + if($this->params->get('typeOfBlock') == "message") + { + header('HTTP/1.0 403 Forbidden'); + die($this->params->get('text')); } - - if ($logged) + elseif($this->params->get('typeOfBlock') == "errorpage") { - $session->set('block_access', true); -// return true; + $uri = Uri::getInstance(); + $url = $uri->toString(); + (CMSApplication::getInstance('site'))->redirect(JUri::root(), 301); } } } diff --git a/block_access.xml b/block_access.xml index c9313fa..3b28413 100644 --- a/block_access.xml +++ b/block_access.xml @@ -1,22 +1,22 @@ - + PLG_BLOCK_ACCESS_NAME Stefan Herzog February 2017 This plugin is released under the GNU/GPL License GNU General Public License joomla@devel.stefan-herzog.com - 1.1.2 + 1.1.4 PLG_BLOCK_ACCESS_DESC - block_access.php + block_access.php index.html - language + language - -
- + +
+ @@ -25,12 +25,12 @@ - + -
+
- https://devel.stefan-herzog.com/joomla/update_plgs.xml.php?plg_name=plg_block_access&name=block_access + https://raw.githubusercontent.com/alve89/plg_block_access/master/updates.xml