<?
/*
Class breadcrumb
Author: Alexander Fleites - 786-348-7637
11/12/2008 - 15:25 PM
Description: This class can generate bread crumb like navigation bars
It outputs an HTML ordered list of navigation links.
The links presentation can be configured using CSS, like example
$page_title => Internal use in function display()
$separator => character betwen breadcrumbs
$exclude => array containing exclude pages
$cant => Cant of breadcrumbs to show
$home_page => home page name
$style => class name to use in display()
Example:
include("breadcrumb.class.php");
$bc = new breadcrumb();
$bc->exclude = array("event_register");
$bc->style = "class_name";
$bc->display();
*/
class breadcrumb{
var $page_title = "";
var $separator = " > ";
var $exclude = array();
var $cant = 5;
var $home_page = "index";
var $style = "";
#constructor
function breadcrumb($separator = " > "){
$this->separator = $separator;
}
#get page_title
function SEM_GetBC_Name($from){
$afrom = explode("/", $from);
$pos = (sizeof($afrom))-1;
$title = $afrom[$pos];
$atitle = explode(".", $title);
return $atitle[0];
}
function checkCommingFrom(){
if($this->page_title == $this->home_page){
$_SESSION["breadcrumb"] = "";
}
}
public function display(){
$refer = $_SERVER['HTTP_REFERER'];
$this->page_title = $this->SEM_GetBC_Name($refer);
//Clear breadcumbs is coming from $home_page
$this->checkCommingFrom();
if(!in_array($this->page_title, $this->exclude)){
$this->page_title = str_replace("_"," ",$this->page_title);
$this->page_title = ucwords($this->page_title);
if( (isset($_SESSION["breadcrumb"])) && ($_SESSION["breadcrumb"] != "") ){
if( ($this->page_title != "") && (!strstr($_SESSION["breadcrumb"], $refer)) ){
$_SESSION["breadcrumb"] .= $this->separator."<a href='".$_SERVER['HTTP_REFERER']."'>".$this->page_title."</a>";
}
}else{
$_SESSION["breadcrumb"] = "<a href='".$_SERVER['HTTP_REFERER']."'>".$this->page_title."</a>";
}
}
//Create breadcrumbs
$aItems = split($this->separator, $_SESSION["breadcrumb"]);
if(sizeof($aItems) > 0){
//Check sttyle
if($this->style == ""){
echo "<style>
.breadcrumb, .breadcrumb a:link, .breadcrumb a:visited{
padding-left:3px;
color:black;
}
</style>";
echo "<div class='breadcrumb'>";
}else{
echo "<div class='".$this->style."'>";
}
for($i=0; $i<sizeof($aItems); $i++){
echo $aItems[$i].$this->separator;
}
echo "</div>";
}
}
}
?>