Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Fixed admin_url, admin_anchor, nonce_admin_url and nonce_admin_anchor…
Browse files Browse the repository at this point in the history
… context guess.
  • Loading branch information
bkader committed May 23, 2018
1 parent 7431bb9 commit 6f132a4
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions skeleton/helpers/KB_url_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,19 @@ function admin_url($uri = '')

$exp = explode('/', $uri);

list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
if (count($exp) === 1)
{
foreach ($contexts as $context => $status)
list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
{
if ('admin' !== $context && true === $status)
foreach ($contexts as $context => $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
if ('admin' !== $context && true === $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
}
}
}
}
Expand Down Expand Up @@ -467,16 +470,19 @@ function admin_anchor($uri = '', $title = '', $attrs = '')

$exp = explode('/', $uri);

list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
if (count($exp) === 1)
{
foreach ($contexts as $context => $status)
list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
{
if ('admin' !== $context && true === $status)
foreach ($contexts as $context => $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
if ('admin' !== $context && true === $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
}
}
}
}
Expand All @@ -498,6 +504,7 @@ function admin_anchor($uri = '', $title = '', $attrs = '')
* @link https://goo.gl/wGXHO9
*
* @since 1.5.0
* @since 2.0.1 Added automatic context guess.
*
* @param string $uri The URI used to generate the URL.
* @return string $action The action to attach to the URL.
Expand All @@ -513,16 +520,20 @@ function nonce_admin_url($uri = '', $action = -1)

$exp = explode('/', $uri);

list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
if (count($exp) === 1)
{
$context = $CI->uri->segment(2);
list($module, $method, $controller) = array_pad($exp, 3, null);

if (false === strpos($context, $uri)
&& (isset($contexts[$context]) && true === $contexts[$context]))
if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
foreach ($contexts as $context => $status)
{
if ('admin' !== $context && true === $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
}
}
}
}

Expand Down Expand Up @@ -558,6 +569,7 @@ function safe_admin_url($uri = '', $action = -1)
* @link https://goo.gl/wGXHO9
*
* @since 1.5.0
* @since 2.0.1 Added automatic context guess.
*
* @param string $uri The URI used to generate the URL.
* @param mixed $action The action attached to the URL.
Expand All @@ -576,16 +588,20 @@ function nonce_admin_anchor($uri = '', $action = -1, $title = '', $attrs = '')

$exp = explode('/', $uri);

list($module, $method, $controller) = array_pad($exp, 3, null);

if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
if (count($exp) === 1)
{
$context = $CI->uri->segment(2);
list($module, $method, $controller) = array_pad($exp, 3, null);

if (false === strpos($context, $uri)
&& (isset($contexts[$context]) && true === $contexts[$context]))
if ( ! empty($contexts = $CI->router->module_contexts(strtok($module, '?'))))
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
foreach ($contexts as $context => $status)
{
if ('admin' !== $context && true === $status)
{
$uri = $context.'/'.ltrim(str_replace($context, '', $uri), '/');
break;
}
}
}
}

Expand Down

0 comments on commit 6f132a4

Please sign in to comment.