function test_get_first_unnested_item() { $nested = array('one' => array('secondary1' => array('tertiary1', 'tertiary2'), 'secondary2', 'secondary3'), 'two', 'three'); $this->assertIdentical('tertiary1', get_first_unnested_item($nested)); $sitemap = array('foo' => 'foo.php', 'bar' => array('baz' => 'baz.php'), 'chewie' => array('han' => 'han.php'), 'yoda' => array('obi' => array('luke' => 'luke.php')), 'anakin' => 'vader.php'); $this->assertIdentical(get_first_unnested_item($sitemap), 'foo.php'); $this->assertIdentical(get_first_unnested_item($sitemap['bar']), 'baz.php'); $this->assertIdentical(get_first_unnested_item($sitemap['yoda']), 'luke.php'); $this->assertIdentical(get_first_unnested_item($sitemap['chewie']), 'han.php'); }
/** * Determines the link for the current section. * * If the section's sub items are an array * the 'slug name' is used for the link, * if the section's sub item is a string, * the string is used for the link. * * Optionally check any section given as a parameter. */ function get_section_link($section = '', $section_sub = '') { global $_section; # Use the current section unless a specific section is given as a parameter $section = use_default($section, $_section); # if $section_sub is undefined, get it from the sitemap if (!$section_sub) { $sitemap = get_sitemap(); $section_sub = $sitemap[$section]; } $link = ''; if (is_array($section_sub)) { if (has_index_pages()) { $link .= slug_name($section); $link .= '.php'; } else { $link .= get_first_unnested_item($section_sub); # link to first sub item that isn't a nested array } } elseif (is_string($section_sub)) { $link = $section_sub; } return $link; }