File: D:/HostingSpaces/SBogers59/ferrumbv.nl/wwwroot/lib/ui/breadcrumb.class.php
<?php
/**
* breadcrumb.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 18/08/14
*/
class UI_Breadcrumb
{
private $_pageName;
private $_lang;
private $_crumbs;
public function __construct($pageName)
{
$this->_pageName = $pageName;
// Translate
$Translator = new Translator(URL_LANG);
$this->_lang = $Translator->get();
}
/**
* Push an item to the breadcrumb
*/
private function push($title, $url, $class=null)
{
$key = count($this->_crumbs);
$this->_crumbs[$key]['title'] = $title;
$this->_crumbs[$key]['url'] = $url;
$this->_crumbs[$key]['class'] = $class;
}
/**
* Create Breadcrump
*/
public function create($data)
{
// Get Root data
$rootPageTitle = $this->_lang[$this->_pageName];
$rootUrlTitle = Fn::encodeUrl($rootPageTitle);
// Is the current page the root page
$root = isset($data['@attributes']['root']);
$this->push($rootPageTitle,SITE_ROOT . $rootUrlTitle);
if ( ! $root ) $this->push($data['title'],SITE_ROOT . $rootUrlTitle . '/' . Fn::encodeUrl($data['title']));
$output = '';
// Add breadcrumb to output
foreach($this->_crumbs as $key => $crumb)
{
// Itemscope holder
$output .= '<div';
if($key != 0) $output .= ' itemprop="child"';
$output .= ' itemscope itemtype="http://data-vocabulary.org/Breadcrumb">';
if($key != 0) $output .= '<span class="sep">/</span>';
// Is this the last item
$last = ($key+1 == count($this->_crumbs));
// Link
$output .= '<a href="' . $crumb['url'] . '" itemprop="url"';
if($crumb['class'] != null) $output .= ' class="' . $crumb['class'] .'"';
$output .= '>';
$output .= '<span itemprop="title">';
if($last) $output .= '<strong>';
$output .= $crumb['title'];
if($last) $output .= '</strong>';
$output .= '</span>';
$output .= '</a>';
}
// Close up nesting
for($i=0;$i<count($this->_crumbs);$i++)
{
$output .= '</div>';
}
return $output;
}
}