menu_trail_by_path.module in Menu Trail By Path 6
File
menu_trail_by_path.module
View source
<?php
function phptemplate_links($links, $attributes = array(
'class' => 'links',
)) {
$output = '';
$path = drupal_get_path_alias($_GET['q']);
if (count($links) > 0) {
$output = '<ul' . drupal_attributes($attributes) . '>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || $link['href'] == '<front>' && drupal_is_front_page())) {
$class .= ' active';
}
if (isset($link['href'])) {
$link_alias = drupal_get_path_alias($link['href']);
if (substr($path, 0, strlen($link_alias)) == $link_alias) {
$class .= ' active-trail';
}
if (strpos($link['attributes']['class'], 'active-trail') !== FALSE && strpos($class, 'active') === FALSE) {
$class .= ' active';
$link['attributes']['class'] .= ' active';
}
$link = l($link['title'], $link['href'], $link);
}
else {
if (!empty($link['title'])) {
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$link = '<span' . $span_attributes . '>' . $link['title'] . '</span>';
}
}
$i++;
$output .= '<li' . drupal_attributes(array(
'class' => $class,
)) . '>';
$output .= $link;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}