This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnapp/classes/lnApp/BreadCrumb.php
2014-02-18 15:27:08 +11:00

88 lines
2.1 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering a BreadCrumb menu.
*
* @package lnApp
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_BreadCrumb extends HTMLRender {
protected static $_data = array();
protected static $_spacer = ' &raquo; ';
protected static $_c = 0;
protected $_items = array('body');
protected static $_required_keys = array('body');
/**
* Enable a friendly name to be used for a path
*/
public static function name($path,$name,$override=TRUE) {
if (isset(self::$_data['name'][$path]) AND ! $override)
return;
self::$_data['name'][$path] = $name;
}
/**
* Render this BreadCrumb
*/
protected function render() {
$output = '<article class="breadcrumbs">';
$output .= HTML::anchor('/',_('Home'));
$data = empty(self::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : self::$_data['path'];
$c = count($data);
$i=0;
foreach ($data as $k => $v) {
$i++;
$output .= '<div class="breadcrumb_divider"></div>';
$p = join('/',array_slice($data,0,$k+1));
$output .= $i==$c ? '<span id="active">' : '<span id="inactive">';
$output .= HTML::anchor(
(empty(self::$_data['url'][$p]) ? $p : self::$_data['url'][$p]),
(empty(self::$_data['name'][$p]) ? ucfirst(URL::dir($v)) : self::$_data['name'][$p])
);
$output .= '</span>';
}
$output .= '</article>';
return $output;
}
/**
* Set the BreadCrumb path
*
* @param array Block attributes
*/
public static function set($path) {
$path = strtolower($path);
if (is_string($path))
self::$_data['path'] = explode('/',$path);
elseif (is_array($path))
self::$_data['path'] = $path;
else
throw new Kohana_Exception('Path is not a string, nor an array');
}
/**
* Enable specifying the URL for a path
*/
public static function URL($path,$url,$override=TRUE) {
$path = strtolower($path);
$url = strtolower($url);
if (isset(self::$_data['url'][$path]) AND ! $override)
return;
self::$_data['url'][$path] = $url;
}
}
?>