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.
khosb/application/classes/lnApp/BreadCrumb.php

94 lines
2.2 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
2012-11-09 23:13:57 +00:00
* This class is for rendering a BreadCrumb menu.
2010-11-29 22:41:08 +00:00
*
* @package lnApp
* @subpackage Page
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
2012-11-09 23:13:57 +00:00
abstract class lnApp_BreadCrumb extends HTMLRender {
2010-11-29 22:41:08 +00:00
protected static $_data = array();
protected static $_spacer = ' &raquo; ';
protected static $_required_keys = array('body');
/**
2012-11-09 23:13:57 +00:00
* Set the BreadCrumb path
2010-11-29 22:41:08 +00:00
*
* @param array Block attributes
*/
public static function set($path) {
2012-11-09 23:13:57 +00:00
$path = strtolower($path);
2010-11-29 22:41:08 +00:00
if (is_string($path))
static::$_data['path'] = explode('/',$path);
2011-12-09 04:10:53 +00:00
elseif (is_array($path))
2010-11-29 22:41:08 +00:00
static::$_data['path'] = $path;
2011-12-09 04:10:53 +00:00
else
throw new Kohana_Exception('Path is not a string, nor an array');
2010-11-29 22:41:08 +00:00
}
/**
* Enable a friendly name to be used for a path
*/
2011-12-09 04:10:53 +00:00
public static function name($path,$name,$override=TRUE) {
if (isset(static::$_data['name'][$path]) AND ! $override)
return;
2010-11-29 22:41:08 +00:00
static::$_data['name'][$path] = $name;
}
2011-12-09 04:10:53 +00:00
/**
* Enable specifying the URL for a path
*/
public static function URL($path,$url,$override=TRUE) {
2012-11-09 23:13:57 +00:00
$path = strtolower($path);
$url = strtolower($url);
2011-12-09 04:10:53 +00:00
if (isset(static::$_data['url'][$path]) AND ! $override)
return;
static::$_data['url'][$path] = $url;
}
2010-11-29 22:41:08 +00:00
/**
* Return an instance of this class
*
2012-11-09 23:13:57 +00:00
* @return BreadCrumb
2010-11-29 22:41:08 +00:00
*/
public static function factory() {
2012-11-09 23:13:57 +00:00
return new BreadCrumb;
2010-11-29 22:41:08 +00:00
}
/**
2012-11-09 23:13:57 +00:00
* Render this BreadCrumb
2010-11-29 22:41:08 +00:00
*/
protected function render() {
2012-01-29 06:23:24 +00:00
$output = '<ul id="breadcrumb">';
$output .= '<li>'.HTML::anchor('/',_('Home')).'</li>';
2010-11-29 22:41:08 +00:00
2011-05-14 07:35:33 +00:00
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
2010-11-29 22:41:08 +00:00
2012-01-29 06:23:24 +00:00
$c = count($data);
$i=0;
2010-11-29 22:41:08 +00:00
foreach ($data as $k => $v) {
2012-01-29 06:23:24 +00:00
$i++;
2010-11-29 22:41:08 +00:00
$p = join('/',array_slice($data,0,$k+1));
2012-01-29 06:23:24 +00:00
$output .= $i==$c ? '<li id="active">' : '<li>';
2011-12-09 04:10:53 +00:00
$output .= HTML::anchor(
(empty(static::$_data['url'][$p]) ? $p : static::$_data['url'][$p]),
(empty(static::$_data['name'][$p]) ? ucfirst($v) : static::$_data['name'][$p])
);
2012-01-29 06:23:24 +00:00
$output .= '</li>';
2010-11-29 22:41:08 +00:00
}
2012-01-29 06:23:24 +00:00
$output .= '</ul>';
2010-11-29 22:41:08 +00:00
return $output;
}
}
?>