2013-04-22 05:50:28 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is for rendering a BreadCrumb menu.
|
|
|
|
*
|
|
|
|
* @package lnApp
|
2013-10-08 23:24:11 +00:00
|
|
|
* @category Helpers
|
2013-04-22 05:50:28 +00:00
|
|
|
* @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 = ' » ';
|
2013-04-25 00:22:36 +00:00
|
|
|
protected static $_c = 0;
|
|
|
|
protected $_items = array('body');
|
2013-04-22 05:50:28 +00:00
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
protected static $_required_keys = array('body');
|
2013-04-22 05:50:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable a friendly name to be used for a path
|
|
|
|
*/
|
|
|
|
public static function name($path,$name,$override=TRUE) {
|
|
|
|
if (isset(static::$_data['name'][$path]) AND ! $override)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static::$_data['name'][$path] = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render this BreadCrumb
|
|
|
|
*/
|
|
|
|
protected function render() {
|
2013-04-25 00:22:36 +00:00
|
|
|
$output = '<article class="breadcrumbs">';
|
|
|
|
$output .= HTML::anchor('/',_('Home'));
|
2013-04-22 05:50:28 +00:00
|
|
|
|
|
|
|
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
|
|
|
|
|
|
|
|
$c = count($data);
|
|
|
|
$i=0;
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
$i++;
|
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= '<div class="breadcrumb_divider"></div>';
|
2013-04-22 05:50:28 +00:00
|
|
|
$p = join('/',array_slice($data,0,$k+1));
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= $i==$c ? '<span id="active">' : '<span id="inactive">';
|
2013-04-22 05:50:28 +00:00
|
|
|
$output .= HTML::anchor(
|
|
|
|
(empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]),
|
|
|
|
(empty(static::$_data['name'][$p]) ? ucfirst(URL::dir($v)) : static::$_data['name'][$p])
|
|
|
|
);
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= '</span>';
|
2013-04-22 05:50:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 00:22:36 +00:00
|
|
|
$output .= '</article>';
|
2013-04-22 05:50:28 +00:00
|
|
|
return $output;
|
|
|
|
}
|
2013-04-25 00:22:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the BreadCrumb path
|
|
|
|
*
|
|
|
|
* @param array Block attributes
|
|
|
|
*/
|
|
|
|
public static function set($path) {
|
|
|
|
$path = strtolower($path);
|
|
|
|
|
|
|
|
if (is_string($path))
|
|
|
|
static::$_data['path'] = explode('/',$path);
|
|
|
|
elseif (is_array($path))
|
|
|
|
static::$_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(static::$_data['url'][$path]) AND ! $override)
|
|
|
|
return;
|
|
|
|
|
|
|
|
static::$_data['url'][$path] = $url;
|
|
|
|
}
|
2013-04-22 05:50:28 +00:00
|
|
|
}
|
|
|
|
?>
|