aboutsummaryrefslogtreecommitdiff
path: root/views/default/navigation/site_nav.php
blob: 0cb867c5fd5d79c74419f72408199480a55a273e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
 * Main site-wide navigation
 *
 **/

$nav_items = elgg_get_nav_items();
$featured = $nav_items['featured'];
$more = $nav_items['more'];

$nav_html = '';
$more_nav_html = '';
$context = get_context();

// sort more links alphabetically
$more_sorted = array();
foreach ($more as $info) {
	$more_sorted[] = $info->name;
}

// required because array multisort is case sensitive
$more_sorted_lower = array_map('elgg_strtolower', $more_sorted);
array_multisort($more_sorted_lower, $more);

$item_count = 0;

// if there are no featured items, display the standard tools in alphabetical order
if ($featured) {
	foreach ($featured as $info) {
		$selected = ($info->value->context == $context) ? 'class="selected"' : '';
		$title = htmlentities($info->name, ENT_QUOTES, 'UTF-8');
		$url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8');

		$nav_html .= "<li $selected><a href=\"$url\" title=\"$title\"><span>$title</span></a></li>";
	}
} elseif ($more) {
	for ($i=0; $i<6; $i++) {
		if (!array_key_exists($i, $more)) {
			break;
		}
		$info = $more[$i];

		$selected = ($info->value->context == $context) ? 'class="selected"' : '';
		$title = htmlentities($info->name, ENT_QUOTES, 'UTF-8');
		$url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8');

		$nav_html .= "<li $selected><a href=\"$url\" title=\"$title\"><span>$title</span></a></li>";
		$more[$i]->used = TRUE;
		$item_count++;
	}
}

// display the rest.
foreach ($more as $info) {
	if ($info->used) {
		continue;
	}
	$selected = ($info->value->context == $context) ? 'class="selected"' : '';
	$title = htmlentities($info->name, ENT_QUOTES, 'UTF-8');
	$url = htmlentities($info->value->url, ENT_QUOTES, 'UTF-8');

	$more_nav_html .= "<li $selected><a href=\"$url\" title=\"$title\"><span>$title</span></a></li>\n";
	$item_count++;
}

if ($more_nav_html) {
	$more = elgg_echo('more');
	$nav_html .= "<li class='navigation_more'><a class='subnav' title=\"$more\"><span>$more</span></a>
		<ul>
			$more_nav_html
		</ul>
	</li>";
}

// only display, if there are nav items to display
if ($nav_html) {
	echo <<<___END
	<div id="elgg_main_nav" class="clearfloat">
		<ul class="navigation">
			$nav_html
		</ul>
	</div>
___END;
}
?>