Hi there,
first thanks a lot for this module, this helped my fix a problem I was struggling with. But it didn't immediately work as it was supposed to. Because I'm developing on a subdirectory on this server, the functionalitity of the module broke.
I also added calls to custom_url_rewrite_outbound, so that functionality of modules like Sub-path URL Aliases is also applied before the check.
I also added template functions for local tasks, and updated the others accordingly.
The new code it the following:
function is_link_html_in_active_trail($link_html) {
$link_array = explode('href="', $link_html);
$link_array = explode('"', $link_array[1]);
$link_href = trim($link_array[0]);
return is_link_href_in_active_trail($link_href);
}
function is_link_href_in_active_trail($link_href, $current_path_alias = null) {
static $current_path_alias;
if (empty($current_path_alias)) {
$current_path_alias = drupal_get_path_alias($_GET['q']);
if (function_exists('custom_url_rewrite_outbound')) {
$options = array();
custom_url_rewrite_outbound($current_path_alias, $options, $current_path_alias);
}
}
$link_path = $link_href;
$base_path = base_path();
if (strpos($link_path, $base_path) === 0) {
$link_path = substr($link_path, strlen($base_path));
}
$link_path_alias = drupal_get_path_alias($link_path);
if (function_exists('custom_url_rewrite_outbound')) {
$options = array();
custom_url_rewrite_outbound($link_path_alias, $options, $link_path_alias);
}
return substr($current_path_alias, 0, strlen($link_path_alias)) == $link_path_alias;
}
function phptemplate_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
static $zebra = FALSE;
$zebra = !$zebra;
$class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
if (!empty($extra_class)) {
$class .= ' '. $extra_class;
}
if (!$in_active_trail) {
$in_active_trail = is_link_html_in_active_trail($link);
}
if ($in_active_trail) {
$class .= ' active-trail';
}
if ($zebra) {
$class .= ' even';
}
else {
$class .= ' odd';
}
return '<li class="'. $class .'">'. $link . $menu ."</li>\n";
}
function phptemplate_menu_local_task($link, $active = FALSE) {
$class = '';
if ($active) {
$class .= ' active';
}
if (is_link_html_in_active_trail($link)) {
$class .= ' active-trail';
}
return '<li class="' . $class . '">'. $link ."</li>\n";
}
function phptemplate_links($links, $attributes = array('class' => 'links')) {
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
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'])) {
if (is_link_href_in_active_trail($link['href'])) {
$class .= ' active-trail';
}
// add active class for containing <li> and <a> if active-trail is set on the link itself
if (strpos($link['attributes']['class'], 'active-trail') !== FALSE && strpos($class, 'active') === FALSE) {
$class .= ' active';
$link['attributes']['class'] .= ' active';
}
// Pass in $link as $options, they share the same keys.
$link = l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
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;
}
Comments
Comment #1
vojvotkinja commentedThanks a lot for this! It's a life saver!
Comment #2
davy-r commentedClosing this issue, as stated on this module's page: "The 6.x-1.x branch is no longer supported and will not receive further development".