forked from patricktalmadge/bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breadcrumbs.php
72 lines (61 loc) · 1.44 KB
/
breadcrumbs.php
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
<?php namespace Bootstrapper;
use \HTML;
/**
* Breadcrumbs for creating Twitter Bootstrap style breadcrumbs.
*
* @package Bundles
* @subpackage Twitter
* @author Patrick Talmadge - Follow @patricktalmadge
*
* @see http://twitter.github.com/bootstrap/
*/
class Breadcrumbs
{
/**
* The values that represnts the Breadcrumb separator.
*
* @var array
*/
public static $separator = '/';
/**
* Creates the a new Breadcrumb.
* @param array $links
* @param array $attributes
* @return string
*/
public static function create($links, $attributes = array())
{
if (empty($links))
return;
$l = array();
foreach ($links as $label => $url)
{
if (is_string($label) || is_array($url))
{
$l[] = static::renderItem('<a href="'.$url.'">'.$label.'</a>');
}
else
$l[] = static::renderItem($url, true);
}
$attributes = Helpers::add_class($attributes, 'breadcrumb');
$html = '<ul'.HTML::attributes($attributes).'>';
$html .= implode('', $l);
$html .= '</ul>';
return $html;
}
/**
* Renders a breadcrumb item.
* @param string $content
* @param boolean $active
* @return string
*/
protected static function renderItem($content, $active = false)
{
$separator = !$active ? '<span class="divider">'.static::$separator.'</span>' : '';
$class = $active ? ' class="active"' : '';
$html = '<li'.$class.'>';
$html .= $content.$separator;
$html .= '</li>';
return $html;
}
}