Location: PHPKode > projects > Yupi cms > yupi-cms/include/menuinterface.php
<?php

/**
 * @author Edin.O
 * @copyright 2008
 */
 
/**
 * Builds menu from database 
*/ 


function GetMenuIDByName($name){
	$name = SqlEscapeString($name);
	$id = SelectValue('*',SC_TABLE_MENU , " name like '$name' " );
	return $id;
}

function GetMenu($id){
	$id = (int)$id;
	$id = SelectValue('*', SC_TABLE_MENU , " id like $id " );
	return $id;
}
/*
function MapCallback($n, $m)
{
   return(array($n => $m));
}
*/


function SimpleFlatMenu ($menuName, $strTemplate){
	$id = GetMenuIDByName($menuName);
	if ($id < 1) return "";

	global $INSTALL_SUB_DIR;

	#Load menus
	$nested = new Nested(SC_TABLE_MENU);
	$nested->MaxLavel = 1;

	$nested->LoadNodesFlat($id);

	$menu = "";
	$menu_item = "";
	#iterate and replace
	if (is_array($nested->Items)){
	foreach($nested->Items as  $Item ){
        $text  = $nested->DisplayText($Item);
        $link  = $nested->Link($Item);

		$menu_item = str_replace("{TITLE}", $text, $strTemplate);
		$menu_item = str_replace("{LINK}", ReplaceMenuTags($link), $menu_item);


        $menu .=   $menu_item;
	}
	}
	#return menu html
	return $menu;
}

function MenuFL($menuName, $template, $title=""){
	$id = GetMenuIDByName($menuName);
	if ($id < 1) return "";


	$nested = new Nested(SC_TABLE_MENU);
	$nested->MaxLavel = 1;
	$nested->LoadNodesFlat($id);

	$items = array();
	if (is_array($nested->Items)){
	foreach($nested->Items as  $Item ){
        $text  = $nested->DisplayText($Item);
        $link  = $nested->Link($Item);

		$arr['title'] = $text;
		$arr['link']  = $link;
		$items[] = $arr;
	}
	}
	$sm = new PhpTemplate;
	$sm->assign('title', $title);
	$sm->assign('items', $items);
	return $sm->fetch($template);
}

function MenuUL($menuName){
	$id = GetMenuIDByName($menuName);
	if ($id < 1) return "";

	$nested = new Nested(SC_TABLE_MENU);
	$nested->MaxLavel = 10;
	$nested->LoadNodes($id);

	return 	BuildMenuUL($nested->Items);
}

function BuildMenuUL($items){

	$lv = $items[0]['level'];
	if ($lv == 0) $s = "id=nav class='DynarchMenu' style='display:none'";
	//if ($lv == 1) $s = 'class=sub';

	$menuStr = "<ul $s>\n";
	for ($i= 0 ; $i < sizeof($items ); $i++){
		$row = $items[$i]['data'];
		$title = $row['title'];
		$link  = $items[$i]['data']['link'];

		$level = $items[$i]['level'];
		$hasCh = isset($items[$i]['children']);

		$c1= '';
		if ($level == 0) $c1 ='';


		//if ($items[$i][level]> 0) $c1 = '


		$cls = '';
		if (isset($items[$i]['children'])){
			$cls = '';
		}
		$hasTc = (isset($items[$i]['children']) && $items[$i]['level']==0);

		if ($level==0){
			if ($hasTc){
				$menuStr .= "<li><a href='$link'>$title</a>\n";
			}else{
				$menuStr .= "<li><a href='$link'>$title</a>\n";
			}
		}else{
			$c2 = "";
			//if ($hasCh) $c2 = "class=fly";
			$menuStr .= "<li><a href='$link'>$title</a>\n";
		}



		if (isset($items[$i]['children']))
		{
			$menuStr .=  BuildMenuUL($items[$i]['children']) ;
		}
		$menuStr .="</li>\n";

	}
	$menuStr .= "</ul>\n";

	return $menuStr;
}

function CssMenuH($menuName){
	$id = GetMenuIDByName($menuName);
	if ($id < 1) return "";

	$nested = new Nested(SC_TABLE_MENU);
	$nested->MaxLavel = 100;
	$nested->LoadNodes($id);

	$menu = "<div id='menuh-container'>\n";
	$menu .= "<div id='menuh'>\n";

	$menu .= BuildCssMenuH($nested->Items);

	$menu .= "</div>\n";
	$menu .= "</div>\n";

	return $menu ;

}
function BuildCssMenuH($items){

	$lv = $items[0]['level'];

	//$menuStr = "<ul>";
	for ($i= 0 ; $i < sizeof($items ); $i++){
		$row = $items[$i]['data'];
		$title = $row['title'];
		$link  = $items[$i]['data']['link'];

		$level = $items[$i]['level'];
		$hasCh = isset($items[$i]['children']);

		$c1= '';
		if ($level == 0) $c1 ='top_parent';

		$hasTc = (isset($items[$i]['children']) && $items[$i]['level']==0);



		if ($level==0){
			if ($hasTc){
				$menuStr .= "\n<ul>\n<li><a class='$c1' href='$link'>$title</a>";
			}else{
				$menuStr .= "\n<ul>\n<li><a class='top' href='$link'>$title</a>";
			}
		}else{
			$c2 = "";
			if ($hasCh) $c2 = "class=parent";
			$menuStr .= "<li><a $c2 href='$link'>$title</a>";
		}



		if (isset($items[$i]['children']))
		{
			$menuStr .="\n<ul>\n". BuildCssMenuH($items[$i]['children']) ."</ul>";
		}

		$menuStr .="</li>\n";
		if ($level==0) 	$menuStr .="</ul>\n";

	}
	//$menuStr .= "</ul>\n";

	return $menuStr;
}
?>
Return current item: Yupi cms