way 1:
function theme_nice_menu_build($menu) {
$output = '';
// $backgroundColor = '#000000';
$backgroundColor = 'transparent';
foreach ($menu as $menu_item) {
$mlid = $menu_item['link']['mlid'];
// Check to see if it is a visible menu item.
if ($menu_item['link']['hidden'] == 0) {
// Build class name based on menu path
// e.g. to give each menu item individual style.
// Strip funny symbols.
$clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
// Convert slashes to dashes.
$clean_path = str_replace('/', '-', $clean_path);
$path_class = 'menu-path-'. $clean_path;
//----begin edit
$imageTag = urldecode(theme('menu_item_link', $menu_item['link']));
$menuArray = explode("|",$_GET['menu']);
$sql_menulinks = db_query("SELECT link_title,link_stageon FROM {menu_links} where mlid='" . $mlid . "' and hidden=0 and menu_name!='navigation' and plid=0");
$result_menulinks = db_fetch_array($sql_menulinks);
$image_on = $result_menulinks['link_stageon'];
if (in_array($mlid, $menuArray)) {
if($result_menulinks && $result_menulinks['link_stageon']){
$imageTag = preg_replace("/src=\".*?\" onmouse/",'src="'.$image_on.'" onmouse',$imageTag);
$imageTag = preg_replace("/src='.*?' onmouse/",'src="'.$image_on.'" onmouse',$imageTag);
//$imageTag = preg_replace("/onmouseout=\"this.src='.*?'\"/","onmouseout=\"this.src='".$image_on."'\"",$imageTag);
}
}
//----end edit
// If it has children build a nice little tree under it.
if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
// Keep passing children into the function 'til we get them all.
$children = theme('nice_menu_build', $menu_item['below']);
// Set the class to parent only of children are displayed.
$parent_class = $children ? 'menuparent ' : '';
$output .= '<li id="menu-'. $mlid .'" class="'. $parent_class . $path_class .'" style="background-color:'.$backgroundColor.';z-index:1">'. $imageTag;
// Build the child UL only if children are displayed for the user.
// you can also do as children menu, at this script. i don't do it.
/*if ($children) {
$output .= '<ul>';
$output .= $children;
$output .= "</ul>";
}*/
$output .= "</li>\n";
}
else {
$output .= '<li id="menu-'. $mlid .'" class="'. $path_class .'" style="background-color:'.$backgroundColor.';">'. $imageTag .'</li>'."\n";
}
}
}
return $output;
}
way 2
the bold part can be replaced by the follow:
//echo $urlMenuArray['link_title'];
preg_match("/onmouseover=\"this\.src='([^']*)'\"/",$urlMenuArray['link_title'],$match);
//echo $match[1];
preg_match("/src='([^']*)'/",$urlMenuArray['link_title'],$match2);
//echo $match2[1];
$urlMenuArray['link_title'] = str_replace($match2[1],$match[1],$urlMenuArray['link_title']);