aboutsummaryrefslogtreecommitdiff
path: root/mod/subgroups/views/default/navigation/breadcrumbs.php
blob: 6ceb5eacc54cc7b2f22b4bbca144ff8b3deaf4de (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
<?php
/**
 * Displays breadcrumbs.
 *
 * @package Elgg
 * @subpackage Core
 *
 * @uses $vars['breadcrumbs'] (Optional) Array of arrays with keys 'title' and 'link'
 * @uses $vars['class']
 *
 * @see elgg_push_breadcrumb
 */

if (isset($vars['breadcrumbs'])) {
	$breadcrumbs = $vars['breadcrumbs'];
} else {
	$breadcrumbs = elgg_get_breadcrumbs();
}


$page_owner = elgg_get_page_owner_entity();

if(elgg_instanceof($page_owner, 'group')) {
	
	// $breadcrumbs[1] should corresponds to group's breadcrumb
	// we'll look for it in crumbs link
	
	$link = $breadcrumbs[1]['link'];
	$guid = (string) $page_owner->guid;
	$alias = $page_owner->alias;

	$title = $breadcrumbs[1]['title'];
	$name = $page_owner->name;

	if(strpos($link, $guid) || $alias && strpos($link, $alias) || !$link && $title == $name) {
		$first_crumb = array_shift($breadcrumbs);
		$container = get_entity($page_owner->container_guid);
		while(elgg_instanceof($container, 'group')) {
			
			// TODO: I should find a better solution for this.
			if(strpos($first_crumb['link'], 'groups') !== false) {
				$container_link = str_replace('all', "profile/$container->guid", $first_crumb['link']);
			} elseif(strpos($first_crumb['link'], 'discussion') !== false) {
				$container_link = str_replace('all', "owner/$container->guid", $first_crumb['link']);
			} else {
				$container_link = str_replace('all', "group/$container->guid", $first_crumb['link']);
			}
			
			$container_link = elgg_trigger_plugin_hook('container_crumb_link', 'breadcrumbs', array('container' => $container, 'first_crumb' => $first_crumb), $container_link);
			
			array_unshift($breadcrumbs, array(
				'title' => $container->name,
				'link' => $container_link,
			));
			$container = get_entity($container->container_guid);
		}
		array_unshift($breadcrumbs, $first_crumb);
	}
}


$class = 'elgg-menu elgg-breadcrumbs';
$additional_class = elgg_extract('class', $vars, '');
if ($additional_class) {
	$class = "$class $additional_class";
}

if (is_array($breadcrumbs) && count($breadcrumbs) > 0) {
	echo "<ul class=\"$class\">";
	foreach ($breadcrumbs as $breadcrumb) {
		if (!empty($breadcrumb['link'])) {
			$crumb = elgg_view('output/url', array(
				'href' => $breadcrumb['link'],
				'text' => $breadcrumb['title'],
				'is_trusted' => true,
			));
		} else {
			$crumb = $breadcrumb['title'];
		}
		echo "<li>$crumb</li>";
	}
	echo '</ul>';
}