<?php /* Written by: Adam Crownoble Created: 5/8/2005 Updated: 8/6/2005 (Added Show in Menu support) Email: [email protected] Website: obledesign.com Name: CascadingMenu Description: Incorporates breadcrumbs into a menu. Properties: &doc_id=Current Document ID;int;0 &parent_class=Parent CSS Class;string;parent &children_class=Children CSS Class;string;children &child_class=Child CSS Class;string;child ¤t_class=Current CSS Class;string;current Thanks: to php.net for inspiration. */ // PSUEDO CONSTANTS // $page_fields = 'id, pagetitle, menutitle, description, published, deleted, isfolder, hidemenu'; // INITIALIZE VARIABLES // $end_tag = ''; $count = 1; $parents = array(); $parents_html = ''; $children_html = ''; if(!$doc_id) { $doc_id = $modx->documentIdentifier; } // If doc_id not set use the current doc $page = $modx->getPageInfo($doc_id,0,$page_fields); // If the current page is a folder add it to the parent array if($page['isfolder']) { $parents[$page['id']] = $page; } // Loop through each parent to the current page // if it's published, not deleted and show in menu is set, add it to the parent array while($page = $modx->getParent($page['id'],0,$page_fields)) { if($page['published'] && !$page['deleted'] && !$page['hidemenu']) { $parents[] = $page; } } // Reverse the array of parents so we can start at the top instead of the bottom $parents = array_reverse($parents,true); // Remove any unpublished, deleted or hidden parents foreach($parents as $key=>$parent) { if(!$parent['published'] || $parent['deleted'] || $parent['hidemenu']) { unset($parents[$key]); } } $parent_count = count($parents); // Loop through each parent and add it to the html foreach($parents as $parent) { $id = $parent['id']; $title = ($parent['menutitle'] ? $parent['menutitle'] : $parent['pagetitle']); // Get classes $parent_classes = " {$parent_class} "; if($parent['id'] == $doc_id) { $parent_classes .= " $current_class "; } if($count==$parent_count) { $parent_classes .= " {$children_class} "; } // End the <li> tag immpediatley only if this isn't the current parent because it's children need to go inside the <li> $end_tag = ($count<$parent_count ? "</li>\n" : "\n"); $parents_html .= <<<EOD <li><a href="[~{$id}~]">{$title}</a>{$end_tag} EOD; $count++; } // Get the children of the last parent $children = $modx->getActiveChildren($parent['id']); // Loop through each child and add it to the html foreach($children as $child) { // Get title $title = $child['menutitle'] ? $child['menutitle'] : $child['pagetitle']; // Get classes $child_classes = " {$child_class} "; if($child['id'] == $doc_id) { $child_classes .= " {$current_class} "; } $children_html .= <<<EOD <li><a href="[~{$child['id']}~]">{$title}</a></li>\n EOD; } // Complile the HTML into one HTML string $html = <<<EOD <ul> {$children_html} </ul> EOD; // If there are parents... if($parents_html) { $html = <<<EOD <ul> {$children_html} </ul> EOD; } // Return the HTML return $html; ?>