custom/menu_helper/menu_helper_active/menu_helper_active.module, line 103
_menu_helper_active_get_active_path()Get active menu path for the current page.
The assigned active menu item link path for the current page or an empty string if there is no active link path.
<?php
function _menu_helper_active_get_active_path() {
$patterns = variable_get('menu_helper_active_patterns', NULL);
// If no patterns or the current page is already a menu item then exit
if ( $patterns == NULL || _menu_helper_active_is_current_path_a_menu_link() ) {
return NULL;
}
// Get actual path and alias
$q = $_GET['q'];
$alias = drupal_get_path_alias($q);
// Reduce the number of checks (aka preg_match()) in loop by first comparing the actual path and alias
// Also confirm that the path still exits using menu_get_item();
if ($q == $alias) {
// Only look for $q, which is faster
foreach ($patterns as $pattern => $path) {
if ( preg_match($pattern, $q) && menu_get_item($path)) {
return $path;
}
}
}
else {
// Look for $q and alais, which is a few micro seconds slower
foreach ($patterns as $pattern => $path) {
if ( (preg_match($pattern, $q) || preg_match($pattern, $alias)) && menu_get_item($path) ) {
return $path;
}
}
}
return NULL;
}
?>