adjust active page selection order
This commit is contained in:
@ -186,39 +186,55 @@ class Navigation extends Template {
|
|||||||
$selectString = ltrim( Routes::getUri(false), '/' );
|
$selectString = ltrim( Routes::getUri(false), '/' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$explodedUrl = explode( '/', $selectString );
|
|
||||||
|
|
||||||
$variations = [
|
$variations = [
|
||||||
Routes::getRequestUrl(),
|
Routes::getRequestUrl(),
|
||||||
|
Routes::getAddress() . $selectString,
|
||||||
|
$selectString,
|
||||||
Routes::getUri(),
|
Routes::getUri(),
|
||||||
Routes::getUri(false),
|
Routes::getUri(false),
|
||||||
Routes::getAddress() . $selectString,
|
|
||||||
Routes::getAddress() . $explodedUrl[0],
|
|
||||||
'/' . $selectString,
|
|
||||||
$selectString,
|
|
||||||
$explodedUrl[0],
|
|
||||||
'/' . $explodedUrl[0],
|
|
||||||
'/' . $explodedUrl[0] . '/',
|
|
||||||
$explodedUrl[0] . '/index',
|
|
||||||
'/' . $explodedUrl[0] . '/index',
|
|
||||||
'/' . $explodedUrl[0] . '/index/',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ( $variations as $url ) {
|
foreach ( $variations as $url ) {
|
||||||
$regex = "#(.*)<li(?: class=\")?(.*?)(?:\")?>\s*?<a href=\"$url\"(?: class=\")?(.*?)(?:\")>?#is";
|
$regex = "#(.*)<li(?: class=\")?(.*?)(?:\")?>\s*?<a href=\"$url\"(?: class=\")?(.*?)(?:\")(.*?)>#is";
|
||||||
if ( preg_match( $regex, $view ) ) {
|
if ( preg_match( $regex, $view ) ) {
|
||||||
$regSelect = $url;
|
$regSelect = $url;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( empty( $regSelect ) ) {
|
||||||
|
$explodedUrl = explode( '/', $selectString );
|
||||||
|
|
||||||
|
$explodedUrlCopy = $explodedUrl;
|
||||||
|
$variations = [];
|
||||||
|
foreach ( $explodedUrl as $key => $section ) {
|
||||||
|
$variations[] = Routes::getAddress() . implode( '/', $explodedUrlCopy );
|
||||||
|
$variations[] = implode( '/', $explodedUrlCopy );
|
||||||
|
$variations[] = '/' . implode( '/', $explodedUrlCopy );
|
||||||
|
$variations[] = '/' . implode( '/', $explodedUrlCopy ) . '/';
|
||||||
|
$variations[] = implode( '/', $explodedUrlCopy ) . '/index';
|
||||||
|
$variations[] = '/' . implode( '/', $explodedUrlCopy ) . '/index';
|
||||||
|
$variations[] = '/' . implode( '/', $explodedUrlCopy ) . '/index/';
|
||||||
|
array_pop( $explodedUrlCopy );
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ( $variations as $key => $url ) {
|
||||||
|
$regex = "#(.*)<li(?: class=\")?(.*?)(?:\")?>\s*?<a href=\"$url\"(?: class=\")?(.*?)(?:\")(.*?)>#is";
|
||||||
|
if ( preg_match( $regex, $view ) ) {
|
||||||
|
$regSelect = $url;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! empty( $regSelect ) ) {
|
if ( ! empty( $regSelect ) ) {
|
||||||
$regSelect = preg_quote( $regSelect );
|
$regSelect = preg_quote( $regSelect );
|
||||||
$regActive = "$1<li class=\"$2\"><a href=\"$regSelect\" class=\"$3 active\">";
|
$regActive = "$1<li class=\"$2\"><a href=\"$regSelect\" class=\"$3 active\"$4>";
|
||||||
$view = preg_replace( $regex, $regActive, $view );
|
$view = preg_replace( $regex, $regActive, $view );
|
||||||
|
|
||||||
$parentRegex = "#(.*)class=\"(.*?)collapse(.*?)<li class=\"nav-item\">\s*<a href=\"$regSelect\" class=\"submenu (.*?)\">#is";
|
$parentRegex = "#(.*)class=\"(.*?)collapse(.*?)<li class=\"nav-item\">\s*<a href=\"$regSelect\" class=\"submenu (.*?)\"(.*?)>#is";
|
||||||
if ( preg_match( $parentRegex, $view ) ) {
|
if ( preg_match( $parentRegex, $view ) ) {
|
||||||
$expandRegex = "$1 class=\"$2collapse show$3<li class=\"nav-item\"><a href=\"$regSelect\" class=\"submenu active $4\">";
|
$expandRegex = "$1 class=\"$2collapse show$3<li class=\"nav-item\"><a href=\"$regSelect\" class=\"submenu active $4\"$5>";
|
||||||
$view = preg_replace( $parentRegex, $expandRegex, $view );
|
$view = preg_replace( $parentRegex, $expandRegex, $view );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user