{NAV_ANY_LEVEL} - Another Navigation RT With Many Options
Posted: Sat 21. Jan 2006, 17:03
				
				Hi,
I have "bastelt" a navigation-tag with the following features:
- show only one menu level you want to see
- auto startlevel > shows sublevels. you can write startlevel and level count
- link to parent menu, yes or no, name of parent or diffrent name
- hide one ore more menus
- one style for navigation-tag or for every menu
- special style for active link and for back link
- separator between menus
I hope there are not so much mistakes in the script but I have tested and everything was working...
Latest Update: 15.03.2006, 22:30
- changed some code for valid html
- The active Link has now a 'id=current'
- I added a new parameter ($xtra_menu_style). It can be 0 or 1. When 1 and $start_level_name = 0 (auto), the "div" and "ul" "active" tag of every sub menu get a extra style (style name = $style + alias from parent menu). So it`s possible, that a dynamic sub menu can change the color or anything else depending from the parent menu.
Example Style:
Grüzli - Andi
			I have "bastelt" a navigation-tag with the following features:
- show only one menu level you want to see
- auto startlevel > shows sublevels. you can write startlevel and level count
- link to parent menu, yes or no, name of parent or diffrent name
- hide one ore more menus
- one style for navigation-tag or for every menu
- special style for active link and for back link
- separator between menus
I hope there are not so much mistakes in the script but I have tested and everything was working...
Latest Update: 15.03.2006, 22:30
- changed some code for valid html
- The active Link has now a 'id=current'
- I added a new parameter ($xtra_menu_style). It can be 0 or 1. When 1 and $start_level_name = 0 (auto), the "div" and "ul" "active" tag of every sub menu get a extra style (style name = $style + alias from parent menu). So it`s possible, that a dynamic sub menu can change the color or anything else depending from the parent menu.
Code: Select all
<?php
// parameter(9): {NAV_ANY_LEVEL:$start_level_name:$auto_start_level:$auto_level_depth:$back_link:$hide_level:$style:$xtra_menu_style:$xtra_li_style:$separator}
// $start_level_name: name of parent menu, 0=>auto, shows act level, string=>alias of parent menu
// $auto_start_level: startlevel from which menus are shown. only if $start_level_name <> 0, number=>number of startlevel >=0
// $auto_level_depth: count of shown levels starting from $auto_start_level. only if $start_level_name <> 0, number=>number of levels to show >=0
// $back_link: link to parent menu. only if $start_level_name <> 0, 0=>no link, 1=>link name is name of parent menu, string=>different name
// $hide_level: menus to hide. if more, separete with ",". 0=>no hidden menus, string=>alias of menus to hide
// $style: name of style for div,ul,li. string=>style name
// $xtra_menu_style: every menu (div, ul) get a style. only if $start_level_name <> 0, $style + alias of parent menu. 0=>no, 1=>yes
// $xtra_li_style: every "li" get a style. $style + alias of menu. 0=>no, 1=>yes
// $separator: separator between menus. 0=>no, string=>separator
// always write 0 for unused parameters
// style from active menu: $style + _active
// style from link to parent menu: $style + _back
// example: {NAV_ANY_LEVEL:mynavi:2:1:back:0:mystyle:0:0:|}
// standard (for starting and testing): {NAV_ANY_LEVEL:0:0:0:0:0:any_navi:0:0:0}
// installation: make a file ("reptag_nav_any_level.php") in "phpwcms_template\inc_script\frontend_render" and copy the script in the file
// Andi Platen, 07.03.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com
// -------------------------------------------------------------
function get_navi_struct($catID, $start_level_name, $auto_start_level, $auto_level_depth)
{
	if($start_level_name != '0')
	{
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_alias'] == $start_level_name)
			{
				$start_id = $GLOBALS['content']["struct"][$key]['acat_id'];
			}
		}
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_struct'] == $start_id)
			{
				$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
			}
		}
	}
	else
	{
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_struct'] == $catID && $GLOBALS['level_count'] <= $auto_start_level + $auto_level_depth)
			{
				$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
			}
		}
		if(!$navi_struct && $GLOBALS['level_count'] > $auto_start_level)
		{
			foreach($GLOBALS['content']["struct"] as $key => $value)
			{
				if($GLOBALS['content']["struct"][$key]['acat_id'] == $GLOBALS['content']['cat_id'])
				{
					$akt_level = $GLOBALS['content']["struct"][$key]['acat_struct'];
				}
			}
			foreach($GLOBALS['content']["struct"] as $key => $value)
			{
				if($GLOBALS['content']["struct"][$key]['acat_struct'] == $akt_level)
				{
					$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
				}
			}
		}
	}
	return $navi_struct;
}
// -------------------------------------------------------------
// -------------------------------------------------------------
function get_any_level_breadcrumb($start_id, $struct_array)
{
	$data = array();
	while ($start_id)
	{
		$data[$start_id] = $struct_array[$start_id]["acat_alias"];
		$start_id		 = $struct_array[$start_id]["acat_struct"];
	}
	if(!empty($struct_array[$start_id]["acat_alias"]))
	{
		$data[$start_id] = $struct_array[$start_id]["acat_alias"];
	}
	return array_reverse($data, 1);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
function css_any_level($struct, $catID, $start_level_name="", $auto_start_level="", $auto_level_depth="", $back_link="", $hide_level="", $style="", $xtra_menu_style="", $xtra_li_style="", $separator="", $link_to="index.php")
{
	$start_level_name = trim($start_level_name);
	$auto_start_level = intval($auto_start_level);
	$auto_level_depth = intval($auto_level_depth);
	$back_link = trim($back_link);
	$hide_level = trim($hide_level);
	$style = trim($style);
	$xtra_menu_style = trim($xtra_menu_style);
	$xtra_li_style = trim($xtra_li_style);
	$separator = htmlentities(trim($separator));
	$css_list = "";
	if($hide_level != '0')
	{
		$hide_level = explode(",", $hide_level);
	}
	if($style == '0')
	{
		$style = 'any_navi';
	}
	if($separator == '0')
	{
		unset($separator);
	}
	$navi_struct = get_navi_struct($catID, $start_level_name, $auto_start_level, $auto_level_depth);
	$breadcrumb = get_any_level_breadcrumb($GLOBALS['content']["cat_id"], $GLOBALS['content']['struct']);
	$act_cat = $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_alias'];
	if($navi_struct)
	{
		foreach($navi_struct as $key => $value)
		{
			if(is_array($hide_level) && in_array($navi_struct[$key]['acat_alias'], $hide_level))
			{
				unset($navi_struct[$key]);
			}
			if($navi_struct[$key]['acat_hidden'] == '1')
			{
				unset($navi_struct[$key]);
			}
		}
		foreach($navi_struct as $key => $value)
		{
			if($start_level_name == '0' && $back_link != '0')
			{
				$back_link_id = $navi_struct[$key]['acat_struct'];
			}
			if($xtra_menu_style == '1')
			{
				$back_link_id = $navi_struct[$key]['acat_struct'];
			}
		}
	}
	if($start_level_name == '0' && $GLOBALS['level_count'] < $auto_start_level)
	{
		unset($navi_struct);
	}
	if($navi_struct)
	{
		if($start_level_name == '0' && $back_link != '0' && $GLOBALS['level_count'] > $auto_start_level)
		{
			if(!array_key_exists($act_cat, $navi_struct)
			|| (array_key_exists($act_cat, $navi_struct) && $GLOBALS['level_count'] > $auto_start_level + 1))
			{
				if($back_link == '1')
				{
					$name = $GLOBALS['content']['struct'][$back_link_id]['acat_name'];
				}
				else
				{
					$name = $back_link;
				}
				foreach($GLOBALS['content']['struct'] as $key => $value)
				{
					$back_link_alias = $GLOBALS['content']['struct'][$back_link_id]['acat_struct'];
				}
				$link = $link_to . "?" . $GLOBALS['content']['struct'][$back_link_alias]['acat_alias'];
				$css_list .= '<li id="' . $style . '_back"><a href="' . $link . '">' . $name . '</a></li>' . "\n";
				if($separator)
				{
					$css_list .= "<li>" . $separator . "</li>\n";
				}
			}
		}
		foreach($navi_struct as $key => $value)
		{
			if($navi_struct[$key]['acat_redirect'] != "")
			{
				$link = $navi_struct[$key]['acat_redirect'];
			}
			else
			{
				$link = $link_to . "?" . $navi_struct[$key]['acat_alias'];
			}
			if(in_array($navi_struct[$key]["acat_alias"], $breadcrumb))
			{
				if($xtra_menu_style == '1' && $xtra_li_style == '0')
    			{
    				$menu_style = $GLOBALS['content']['struct'][$back_link_id]['acat_alias'];
					$css_list .= '<li id="' . $style . '_' . $menu_style . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else if($xtra_menu_style == '1' && $xtra_li_style == '1')
    			{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else if($xtra_menu_style == '0' && $xtra_li_style == '1')
    			{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else
				{
					$css_list .= '<li id="' . $style . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
			}
			else
			{
				if($xtra_li_style == '0')
				{
					$css_list .= '<li><a href="' . $link . '">';
				}
				else
				{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '"><a href="' . $link . '">';
				}
			}
			$css_list .= html_specialchars($navi_struct[$key]["acat_name"]) . "</a>";
			$css_list .= "</li>\n";
			if($value != end($navi_struct) && $separator)
			{
				$css_list .= "<li>" . $separator . "</li>\n";
			}
   		}
    }
    if($css_list)
    {
    	if($xtra_menu_style == '1')
    	{
    		$menu_style = $GLOBALS['content']['struct'][$back_link_id]['acat_alias'];
    		$css_list = "<div id=\"".$style."_".$menu_style."\">\n  <ul id=\"".$style."_".$menu_style."_ul\">\n". $css_list ."  </ul>\n</div>";
    	}
    	else
    	{
    		$css_list = "<div id=\"".$style."\">\n  <ul id=\"".$style."_ul\">\n". $css_list ."  </ul>\n</div>";
    	}
    }
    return $css_list;
}
// -------------------------------------------------------------
// -------------------------------------------------------------
if(!( strpos($content["all"],'{NAV_ANY_LEVEL')===false ) )
{
   $content["all"] = str_replace('{NAV_ANY_LEVEL}', css_any_level($content["struct"],$content["cat_id"]), $content["all"]);
   $content["all"] = preg_replace('/\{NAV_ANY_LEVEL:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)\}/e', 'css_any_level($content["struct"],$content["cat_id"],"$1","$2","$3","$4","$5","$6","$7","$8","$9")', $content["all"]);
}
// -------------------------------------------------------------
?>
Example Style:
Code: Select all
#any_navi
{
	
}
#any_navi ul
{
	font-size: 10px;
	margin: 0;
	padding: 0;
}
#any_navi li
{
	list-style: none;
	display: inline;
	color: #999999;
}
#any_navi a:link, #any_navi a:visited
{
	color: #999999;
	font-weight: bold;
	text-decoration: none;
}
#any_navi a:hover, #any_navi_active a:link, #any_navi_active a:visited, #any_navi_active a:hover, #any_navi_active a:active
{
	color: #000000;
	font-weight: bold;
	text-decoration: none;
}


 
 
 
  