Example #1
0
 /**
  * @param string $arg comma seperated argument list: $top_level, $bottom_level, $options
  *		$top_level  (int)  The upper level of the menu to show, if deeper (in this case > ) than 0, only the submenu is shown
  *		$bottom_level  (int)  The lower level of menu to show
  *		$expand_level (int)  The upper level from where to start expanding sublinks, if -1 no expansion
  * 		$expand_all (int)	Whether or not to expand all levels below $expand_level (defaults to 0)
  * 		$source_menu (string)	Which menu to use
  *
  */
 static function CustomMenu($arg, $title = false)
 {
     global $page, $gp_index;
     //from output functions
     if (is_array($title)) {
         $title = $page->title;
     }
     $title_index = false;
     if (isset($gp_index[$title])) {
         $title_index = $gp_index[$title];
     }
     $args = explode(',', $arg);
     $args += array(0 => 0, 1 => 3, 2 => -1, 3 => 1, 4 => '');
     //defaults
     list($top_level, $bottom_level, $expand_level, $expand_all, $source_menu) = $args;
     //get menu array
     $source_menu_array = gpOutput::GetMenuArray($source_menu);
     //reduce array to $title => $level
     $menu = array();
     foreach ($source_menu_array as $temp_key => $titleInfo) {
         if (!isset($titleInfo['level'])) {
             break;
         }
         $menu[$temp_key] = $titleInfo['level'];
     }
     //Reduce for expansion
     //first reduction
     //message('expand level: '.$expand_level);
     if ((int) $expand_level >= 1) {
         if ($expand_all) {
             $menu = gpOutput::MenuReduce_ExpandAll($menu, $expand_level, $title_index, $top_level);
         } else {
             $menu = gpOutput::MenuReduce_Expand($menu, $expand_level, $title_index, $top_level);
         }
     }
     //Reduce if $top_level >= 0
     //second reduction
     if ((int) $top_level > 0) {
         //echo 'top level: '.$top_level;
         //message('top: '.$top_level);
         $menu = gpOutput::MenuReduce_Top($menu, $top_level, $title_index);
     } else {
         $top_level = 0;
     }
     //Reduce by trimming off titles below $bottom_level
     // last reduction : in case the selected link is below $bottom_level
     if ($bottom_level > 0) {
         //message('bottom: '.$bottom_level);
         $menu = gpOutput::MenuReduce_Bottom($menu, $bottom_level);
     }
     gpOutput::OutputMenu($menu, $top_level, $source_menu_array);
 }