Created
April 24, 2013 01:19
-
-
Save iso100/5448858 to your computer and use it in GitHub Desktop.
Ian's mods to breadcrumbs allowing a custom last class to support Foundation 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** ------------------------------------- | |
/** Create a Breadcrumb Trail | |
/** -------------------------------------*/ | |
function breadcrumb() | |
{ | |
$site_pages = $this->sql->get_site_pages(); | |
if ( ! $site_pages) | |
return FALSE; | |
// Get parameters | |
$separator = $this->EE->TMPL->fetch_param('separator', '»'); | |
$inc_separator = $this->EE->TMPL->fetch_param('inc_separator'); | |
$separator = $inc_separator === 'no' ? '' : $separator; | |
$inc_home = $this->EE->TMPL->fetch_param('inc_home'); | |
$inc_home = $inc_home === 'no' ? false : true; | |
$inc_here = $this->EE->TMPL->fetch_param('inc_here'); | |
$inc_here = $inc_here === 'no' ? false : true; | |
$here_as_title = $this->EE->TMPL->fetch_param('here_as_title'); | |
$here_as_title = $here_as_title === 'yes' ? true : false; | |
$wrap_each = $this->EE->TMPL->fetch_param('wrap_each', ''); | |
$wrap_here = $this->EE->TMPL->fetch_param('wrap_here', ''); | |
$wrap_separator = $this->EE->TMPL->fetch_param('wrap_separator', ''); | |
$separator = $wrap_separator ? "<{$wrap_separator}>{$separator}</{$wrap_separator}>" : $separator; | |
$add_last_class = $this->EE->TMPL->fetch_param('add_last_class') != 'no'; | |
// Added by Ian | |
$last_class = $this->EE->TMPL->fetch_param('custom_last_class', 'last'); | |
$channel_id = $this->EE->TMPL->fetch_param('channel', FALSE); | |
// Are we passed a URI to work from? If not use current URI | |
$uri = $this->EE->TMPL->fetch_param('uri', $this->sql->get_uri()); | |
$uri = html_entity_decode($uri); | |
// if (array_key_exists('structure_pagination_segment', $this->EE->config->_global_vars)) | |
// $uri = $this->remove_last_segment($uri); | |
// get current entry id | |
if ($channel_id !== FALSE && is_numeric($channel_id)) | |
{ | |
// Filter by channel_id. Allows duplicate URIs to exist and still be | |
// relatively useful, eg. multi-language | |
$channel_entries = $this->sql->get_entries_by_channel($channel_id); | |
$entry_ids = array_keys($site_pages['uris'], $uri); | |
$entry_id = current(array_intersect($channel_entries, $entry_ids)); | |
if ($entry_id === FALSE) | |
$entry_id = array_search($uri, $site_pages['uris']); | |
} | |
else | |
{ | |
$entry_id = array_search($uri, $site_pages['uris']); | |
} | |
// get node of the current entry | |
$node = $entry_id ? $this->nset->getNode($entry_id) : false; | |
// node does not have any structure data we return nothing to prevent errors | |
if ($node === FALSE && ! $entry_id) | |
{ | |
return FALSE; | |
} | |
// if we have an entry id but no node, we have listing entry | |
if ($entry_id && ! $node) | |
{ | |
// get entry's parent id | |
$pid = $this->get_pid_for_listing_entry($entry_id); | |
// get node of parent entry | |
$node = $this->nset->getNode($pid); | |
} | |
$right = $node['right']; | |
$inc_current = isset($pid) ? '=' : ''; | |
$site_id = $this->EE->config->item('site_id'); | |
$sql = "SELECT node.*, expt.title | |
FROM exp_structure AS node | |
INNER JOIN exp_channel_titles AS expt | |
ON node.entry_id = expt.entry_id | |
WHERE node.lft > 1 | |
AND node.lft < $right | |
AND node.rgt >$inc_current $right | |
AND expt.site_id = $site_id | |
-- AND node.lft != 2 | |
ORDER BY node.lft"; | |
$result = $this->EE->db->query($sql); | |
$home_entry = array_search('/', $site_pages['uris']) ? array_search('/', $site_pages['uris']) : 0; #default to zero | |
$site_index = trim($this->EE->functions->fetch_site_index(0, 0), '/'); | |
$home_link = $this->EE->TMPL->fetch_param('home_link', $site_index); | |
$custom_title_fields = $this->sql->create_custom_titles(TRUE); | |
// print_r($custom_title_fields); | |
$crumbs = array(); | |
$home_title = $this->EE->TMPL->fetch_param('rename_home', 'Home'); | |
if ($inc_home) | |
{ | |
$crumbs[] = '<a href="' . $home_link . '">'.$home_title.'</a>'; | |
} | |
foreach ($result->result_array() as $entry) | |
{ | |
if ($entry['entry_id'] == $home_entry) #remove homepage | |
continue; | |
$the_title = $custom_title_fields !== FALSE ? $custom_title_fields[$entry['entry_id']] : $entry['title']; | |
$crumbs[] = '<a href="' . Helper::remove_double_slashes($home_link . $site_pages['uris'][$entry['entry_id']]) . '">' . $the_title . '</a>'; | |
} | |
// If inc_here param is yes/true then show the here name | |
if ($inc_here) | |
{ | |
// If here_as_title is yes/true then show here as page title | |
if ($here_as_title) | |
{ | |
$the_title = $custom_title_fields !== FALSE ? array_key_exists($entry_id, $custom_title_fields) ? $custom_title_fields[$entry_id] : $this->sql->get_entry_title($entry_id) : $this->sql->get_entry_title($entry_id); | |
$crumbs[] = !empty($wrap_here) ? "<{$wrap_here}>$the_title</{$wrap_here}>" : $the_title; | |
} | |
else | |
{ | |
$crumbs[] = !empty($wrap_here) ? "<{$wrap_here}>Here</{$wrap_here}>" : "Here"; | |
} | |
} | |
$count = count($crumbs); | |
for ($i = 0; $i < $count; $i++) | |
{ | |
if ( ! empty( $separator) && $i != ($count-1)) | |
$crumbs[$i] = "{$crumbs[$i]} {$separator} "; | |
if ( ! empty($wrap_each)) | |
{ | |
if ($add_last_class === TRUE && $i == $count -1) | |
$crumbs[$i] = "<{$wrap_each} class=\"{$last_class}\">{$crumbs[$i]}</{$wrap_each}>"; | |
else | |
$crumbs[$i] = "<{$wrap_each}>{$crumbs[$i]}</{$wrap_each}>"; | |
} | |
else | |
{ | |
if ($add_last_class === TRUE && $i == $count -1) | |
$crumbs[$i] = '<span class="{$last_class}">'.$crumbs[$i].'</span>'; | |
} | |
} | |
return implode('', $crumbs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment