diff --git a/block_access.php b/block_access.php index d06dfcf..99ac53c 100644 --- a/block_access.php +++ b/block_access.php @@ -15,6 +15,8 @@ class plgSystemBlock_access extends JPlugin { + private $securedArea = ''; + function onAfterInitialise() { // onAfterDispatch() $app = JFactory::getApplication(); $user = JFactory::getUser(); @@ -24,21 +26,20 @@ function onAfterInitialise() { // onAfterDispatch() return; } // Check if security key has been entered - $logged = isset($_GET[$this->params->get('securitykey')]); + $correctKey = isset($_GET[$this->params->get('securitykey')]); // Check the current area the user wants so enter (site / admin) if ($app->isClient('site')) { $area = "site"; } - if ($app->isClient('administrator')) { $area = "admin"; } - $securedArea = strtolower($this->params->get('area')); + $this->securedArea = strtolower($this->params->get('area')); - if($area == $securedArea || $securedArea == "both") { - if ($logged) { + if($area == $this->securedArea || $this->securedArea == "all") { + if($correctKey) { $session = JFactory::getSession(); $session->set('block_access', true); // return true; @@ -49,15 +50,39 @@ function onAfterInitialise() { // onAfterDispatch() } } + function blockArea() { if($this->params->get('typeOfBlock') == "message") { - header('HTTP/1.0 403 Forbidden'); - die($this->params->get('text')); + header('HTTP/1.0 401 Unauthorized'); + die($this->params->get('message')); + } + elseif($this->params->get('typeOfBlock') == "redirect") { + $current = Uri::getInstance(); + $currentScheme = $current->getScheme(); + $currentHost = $current->getHost(); + $currentPath = $current->getPath(); + $currentUrl = $current->toString(); + + // Make sure that there's a leading slash! + $redirectPath = (strpos($this->params->get('redirectUrl'),0,1) == "/") ? $this->params->get('redirectUrl') : '/'.$this->params->get('redirectUrl'); + + $redirect = Uri::getInstance(JUri::root()); + $redirectScheme = $redirect->getScheme(); + $redirectHost = $redirect->getHost(); + $redirectPath = JUri::root(true).$redirectPath; + $redirectUrl = $redirect->setScheme($redirectScheme) + ->setHost($redirectHost) + ->setPath($redirectPath); + $redirectUrl = $redirect->toString(); + + // If the current URL is the main page, do nothing + if($currentUrl == $redirectUrl) return; + + // Else: Redirect to given URL + (CMSApplication::getInstance('site'))->redirect($redirectUrl, 301);//JUri::root() } - elseif($this->params->get('typeOfBlock') == "errorpage") { - $uri = Uri::getInstance(); - $url = $uri->toString(); - (CMSApplication::getInstance('site'))->redirect(JUri::root(), 301); + else{ + (CMSApplication::getInstance('site'))->redirect($redirectUrl, 301); } } } diff --git a/block_access.xml b/block_access.xml index 7c70eb8..40286aa 100644 --- a/block_access.xml +++ b/block_access.xml @@ -6,7 +6,7 @@ This plugin is released under the GNU/GPL License GNU General Public License joomla@devel.stefan-herzog.com - 1.1.6 + 1.1.7 PLG_BLOCK_ACCESS_DESC block_access.php @@ -17,16 +17,29 @@
- - - + + + +
diff --git a/updates.xml b/updates.xml index 9fbc703..fec7e53 100644 --- a/updates.xml +++ b/updates.xml @@ -7,9 +7,9 @@ plugin system 0 - 1.1.6 + 1.1.7 - https://github.com/alve89/plg_block_access/archive/v1.1.6.zip + https://github.com/alve89/plg_block_access/archive/v1.1.7.zip stable @@ -17,5 +17,6 @@ Stefan Herzog https://github.com/alve89 +