PHPLayersMenu 3.2.0 follow up
Just spent a couple of hours playing with this script that creates a nice DHTML tree menu system and is pretty well cross browser with a nice fall back feature should it need it.
Anyhow I wanted to change a menu on my site and decided I would adapt this script to use an XML file for it’s menu data rather than a flat text file.
I didn’t want to get to involved in someone elses unsupported code. So, I decided to write a quick php function that takes an xml file and generates the required format that the original script requires. It’s literally just a couple of lines so I thought I’d put it on here:
function displayChildrenRecursive($xmlObj, &$resultString, $depth=0) {
foreach($xmlObj->children() as $child) {
// [dots]|[text]|[link]|[title]|[icon]|[target]|[expanded]
$resultString = $resultString.str_repeat(‘.’,$depth+1).’|’.$child[description].’|’.$child[url].’|’.$child[tooltip].’|’.$child[icon].’|’.$child[target].’|’.$child[expanded].”\n”;
displayChildrenRecursive($child, $resultString, $depth+1);
}
return $resultString;
}
Now all I need to do in the phplayersmenu script is this:
$xml = simplexml_load_file(‘menu.xml’);
$phpLayersMenuString = displayChildrenRecursive($xml, $phpLayersMenuString);
$mid->setMenuStructureString($phpLayersMenuString); //instead of $mid->setMenuStructureFile(‘menu.txt’);
And voila! There you have it – this script now works with a well formed XML document which is a much nicer way to represent a tree!