I've been spending some time on my site optimizing everything recently. I noticed there were occasionally some 404 items in my logs that were like "menu-path-www.example.com". On looking into this further, I found that Nice Menus innocently creates this path as a class on each menu item, and some "unknown" browser reads it as an actual link.

Here's the technical rundown:
For each link that Nice Menus generates, it adds a class like this:
<li id="menu-##" class="menu-path-[path-to-link]"><a href="path-to-link">Link Text</a></li>
When you create a link to another site in your menu, you might end up with the following:
<li id="menu-230" class="menu-path-www.example.com-somefolder-somefile.htm">...

Even though this is just a class, some browsers read it as an actual link and attempt to fetch the link at
http://www.yoursite.com/menu-path-www.example.com-somefolder-somefile.htm.

Note that this only happens when there's a "www" in the path. For example, if the link points to "http://subdomain.example.com" (where "subdomain" is anything other than "www"), there won't be an error.

Code Fix:
The easiest fix for this is just to blank out $path_class entirely (since I can't imagine a good use for it anyway). To do this, add the following to your template.php:

function phptemplate_nice_menu_tree($pid = 1, $menu = NULL) {
  $menu = isset($menu) ? $menu : menu_get_menu();
  $output['content'] = '';

  $output['subject'] = check_plain($menu['items'][$pid]['title']);

  if ($menu['visible'][$pid]['children']) {
    // Build class name based on menu path 
    // e.g. to give each menu item individual style.
    foreach ($menu['visible'][$pid]['children'] as $mid) {  
      // Strip funny symbols
      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu['items'][$mid]['path']);
      // Convert slashes to dashes
      $clean_path = str_replace('/', '-', $clean_path);
      $path_class = '';
      if (count($menu['visible'][$mid]['children']) > 0) {
        $output['content'] .= '<li id="menu-'. $mid .'" class="menuparent '. $path_class .'">'. menu_item_link($mid);
        $output['content'] .= '<ul>';
        $tmp = theme('nice_menu_tree', $mid);
        $output['content'] .= $tmp['content'];
        $output['content'] .= "</ul>\n";
        $output['content'] .= "</li>\n";
      }
      else {
        $output['content'] .= '<li id="menu-'. $mid .'" class="'. $path_class .'">'. menu_item_link($mid) .'</li>'."\n";
      }
    }
  }
  return $output;
}

That code is copied directly from nice_menus.module 5.x-1.4 with the only change being $path_class = '';

I would recommend that the module developer remove $path_class entirely from the code since I can't really think of a good reason anyone would want to base a CSS class on a path (particularly because paths may change whereas ID's always stay the same).

Comments

add1sun’s picture

No need to get rid of path class since some people may want it and probably are already using it. I'm not going to cut it out from under them for no reason. All we need to do is add www to the symbols that get stripped out in the $clean_path variable. Not really that hard and certainly less drastic.

hargobind’s picture

I agree that you don't want to arbitrarily remove this feature since people might be using it already.

However, most people don't need path-based classes, and it causes unnecessary bandwidth bloat on most sites. I'm recommending that you add an option to the Site Configuration page to turn this feature on/off. Not very difficult to do, and if you need my help I'll gladly pitch in some code.

BTW, thanks for this killer module!

add1sun’s picture

Status: Active » Fixed

I added www to the list of things to strip in all versions. I really don't think adding the path is such a huge burden that I need to add yet another setting just for that.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.