\"%altTag%\"
"; $holders = array("%name%","%imgNum%","%navLoc%","%altTag%"); $values = array($name,$imgNum,$navLoc,$altTag); $code = str_replace($holders,$values,$linkTemplate); return $code; } function createLinkSel($name, $imgNum, $navLoc, $altTag){ $linkTemplateSel = "\"%altTag%\"
"; $holders = array("%name%","%imgNum%","%navLoc%","%altTag%"); $values = array($name,$imgNum,$navLoc,$altTag); $code = str_replace($holders,$values,$linkTemplateSel); return $code; } $link = ""; '; $codeEnd = ' echo($link); ?>'; $codeElse = '} else { '; $codeBlockEnd = '} '; function createMNif($num){ $ret = 'if($mn==' . $num . '){ '; return $ret; } function createSNif($num){ $ret = ' if($sn==' . $num . '){ '; return $ret; } function createLinkSel($arr){ $ret = ' $link = $link . createLinkSel("' . $arr[0] . '","' . $arr[1] . '","' . $arr[2] . '","' . $arr[3] .'"); '; return $ret; } function createLink($arr){ $ret = ' $link = $link . createLink("' . $arr[0] . '","' . $arr[1] . '","' . $arr[2] . '","' . $arr[3] . '"); '; return $ret; } function createElseIf($num){ $ret = '} elseif($mn=='. $num . '){ '; return $ret; } function createInfoListMain($arr){ $ret = array(); $ret[0] = strtolower(str_replace(" ","",$arr['name'])); $ret[1] = $arr['mainn']-1; $ret[2] = "mn=" . $arr['mainn']; $ret[3] = $arr['name']; return $ret; } function createInfoListSub($arr){ $ret = array(); $ret[0] = strtolower(str_replace(" ","",$arr['name'])); $ret[1] = $arr['mainn']+$arr['subn']-1; $ret[2] = "mn=" . $arr['mainn'] . "&sn=" . $arr['subn']; $ret[3] = $arr['name']; return $ret; } function explodePhrase($arr){ $stor = array(); $stor = explode('|',$arr); $arrReturn = array( 'name'=>$stor[0], 'type'=>$stor[1], 'mainn'=>$stor[2] ); if (isset($stor[3])) $arrReturn['subn']=$stor[3]; return $arrReturn; } function elseIfarray($arr,$num){ $ret = array(); foreach($arr as $i => $v){ if ($i<$num) $ret[] = $i; } if (empty($ret)){ $ret['f'] = 'false'; } return $ret; } function createFileList($str){ $str = strtolower(str_replace(" ","",$str)); $ret = "$str.gif\n{$str}_on.gif\n{$str}_over.gif\n"; return $ret; } $done = $_POST['clist']; $phrase = $_POST['list']; $phrase = trim($phrase); $phraseRaw = explode("\n", $phrase); $arrPhrase = array(); $arrSubListTemp = array(); $mainCnt = 1; $subCnt = 0; foreach($phraseRaw as $ind => $val){ $txt = trim($val); $dashChk = strpos($txt,'-'); if ($dashChk === false){ //if there is not a dash on the line if ($ind!=count($phraseRaw)){ //if it is not the last line $subChk = $phraseRaw[$ind+1]; //get the next line $subChkDash = strpos($subChk,'-'); if ($subChkDash === false){ //if there is not a dash on the next line $arrPhrase[] = "$txt|m|$mainCnt"; //name|type(m,s)|main number[|sub number] $arrSubListTemp[] = $mainCnt; $mainCnt++; } else { $subCnt = 0; $arrPhrase[] = "$txt|m|$mainCnt|$subCnt"; //name|type(m,s)|main number[|sub number] $arrSubListTemp[] = $mainCnt; $subCnt++; } } else { $arrPhrase[] = "$txt|m|$mainCnt"; //name|type(m,s)|main number[|sub number] $arrSubListTemp[] = $mainCnt; } } else { $txt = trim($txt, " -"); $arrPhrase[] = "$txt|s|$mainCnt|$subCnt"; //name|type(m,s)|main number[|sub number] $arrSubListTemp[] = $mainCnt; $subCnt++; $mainChk = $phraseRaw[$ind+1]; //get the next line $mainChkDash = strpos($mainChk,'-'); if ($mainChkDash === false){ //if there is not a dash on the next line $mainCnt++; } } } $arrPhraseCnt = count($arrPhrase); $arrSubList = array(); foreach($arrSubListTemp as $val){ //loop through array of items $arrSubList[$val] = $arrSubList[$val] + 1; } foreach($arrSubList as $ind => $val){ //loop through array of items if ($val==1) unset($arrSubList[$ind]); } $bPhrase = $codeBeg; $fPhrase = ""; $listItem = array(); foreach($arrPhrase as $ind => $val){ $itemInfo = array(); $arrElseIf = array(); $listItem = explodePhrase($val); $fPhrase = $fPhrase . createFileList($listItem['name']); if ($listItem['type']=='m'){ $bPhrase = $bPhrase . createMNif($listItem['mainn']); if (!isset($listItem['subn'])){ $itemInfo = createInfoListMain($listItem); $bPhrase = $bPhrase . createLinkSel($itemInfo); $arrElseIf = elseIfarray($arrSubList,$listItem['mainn']); if (!isset($arrElseIf['f'])){ foreach($arrElseIf as $prevMain){ $bPhrase = $bPhrase . createElseIf($prevMain); $itemInfo[1] = $listItem['mainn']+$arrSubList[$prevMain]-2; $bPhrase = $bPhrase . createLink($itemInfo); } } $bPhrase = $bPhrase . $codeElse; $itemInfo[1] = $listItem['mainn']-1; $bPhrase = $bPhrase . createLink($itemInfo); $bPhrase = $bPhrase . $codeBlockEnd; } else { $loopCnt = $arrSubList[$listItem['mainn']]; for($k=0;$k<$loopCnt;$k++){ $bPhrase = $bPhrase . createSNif($k); for($l=0;$l<$loopCnt;$l++){ $listItemSub = explodePhrase($arrPhrase[$ind+$l]); $itemInfoSub = createInfoListSub($listItemSub); if($l==$k){ $bPhrase = $bPhrase . createLinkSel($itemInfoSub); } else { $bPhrase = $bPhrase . createLink($itemInfoSub); } } $bPhrase = $bPhrase . $codeBlockEnd; } $itemInfo = createInfoListSub($listItem); $arrElseIf = elseIfarray($arrSubList,$listItem['mainn']); if (!isset($arrElseIf['f'])){ foreach($arrElseIf as $prevMain){ $bPhrase = $bPhrase . createElseIf($prevMain); $itemInfo[1] = $listItem['mainn']+$arrSubList[$prevMain]-2; $bPhrase = $bPhrase . createLink($itemInfo); } } $bPhrase = $bPhrase . $codeElse; $itemInfo[1] = $listItem['mainn']+$listItem['subn']-1; $bPhrase = $bPhrase . createLink($itemInfo); $bPhrase = $bPhrase . $codeBlockEnd; } } } $bPhrase = $bPhrase . $codeEnd; $bPhrase = $bPhrase . "\n"; $phrase = $bPhrase; ?> Navigation Menu Generator

Navigation Menu Generator

This tool was designed to generate the code for the PHP/ECMAScript menus that I use for www.phrebh.com.

To use it, list the menu items in the provided text area, in the order that you want, putting only one item on each line. Put a dash (-) in front of an item to make it a sub-menu.

The given menu items will be used to generate the image names and the alt text for the image tags. The results will also give a list of filenames needed.

To download the source code for this tool, and for other neat things, visit www.phrebh.com.