Fork me on GitHub
Subscribe 2

Ticket #1128 (fixed enhancement)

Convert breadcrumbs to be a function

  • Created: 2019-01-29 05:11:21
  • Reported by: quy
  • Assigned to: quy
  • Milestone: 1.6
  • Component: code
  • Priority: normal

Lets create a breadcrumb function to generate the breadcrumb markup.

Current code:

		<ul class="crumbs">
			<li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
			<li><span>»&#160;</span><a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
			<li><span>»&#160;</span><strong><a href="viewtopic.php?id=<?php echo $id ?>"><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></a></strong></li>
		</ul>

Proposed code to use breadcrumb function.

$crumbs = generate_crumbs(array(
	array($lang_common['Index'], 'index.php'),
	array(pun_htmlspecialchars($cur_topic['forum_name']), 'viewforum.php?id='.$cur_topic['forum_id']),
	array(pun_htmlspecialchars($cur_topic['subject']), 'viewtopic.php?id='.$id)));
//
// Generate breadcrumb navigation
//
function generate_crumbs($crumbs)
{
	$crumbs_markup = '<nav aria-label="breadcrumb"><ol class="crumbs">';

	foreach ($crumbs as $index => $crumb)
	{
		$separator = $index ? '<span aria-hidden="true">&raquo;&#160;</span>' : '';

		if (is_array($crumb))
			$crumbs_markup .= '<li>'.$separator.'<a href="'.$crumb[1].'">'.$crumb[0].'</a></li>';
		else
			$crumbs_markup .= '<li>'.$separator.'<strong>'.$crumb.'</strong></li>';
	}

	$crumbs_markup .= '</ol></nav>';

	return $crumbs_markup;
}

History

Franz 2019-03-24 22:28:12

  • Status changed from open to fixed.

Franz 2019-03-24 22:53:23

Commit ba0a586 to fluxbb master

Move HTML escaping into generate_crumbs()

Refs #1128.