Purpose of file: Show the directories and their links in path * form:
* Home > Firstdir > Seconddir > Etc > filename.php

*

Information: If you use this script please contact me with a url * or product information plus the product :) and please keep all header * information intact. Cheers!

*

Pay-Pal info: paypal@baskettcase.com

* * @author Richard Baskett * @category directory structure * @copyright Copyright © 2008, Baskettcase Web Development * @example example.php * @link http://www.baskettcase.com/classes/breadcrumb/ * @link mailto:paypal@baskettcase.com * @package breadcrumb * @version 2.4.4 */ class breadcrumb { /** * Set Root Index Page * * Sets the root index page link for those who have a splash page and do not * want the home breadcrumb to take them to the splashpage. * $breadcrumb->rootIndexLink = 'index2.php'; * @var string * @since Version 2.4.4 */ var $rootIndexLink = ''; /** * Homepage naming * * A person can use any name for the homepage/base directory or not show it at * all. * $breadcrumb->homepage = 'homepage';
* Example: * homepage > Baskettcase > php_classes > breadcrumb > index.htm *

$breadcrumb->homepage = '';
* Example: * Baskettcase > php_classes > breadcrumb > index.htm * @var string * @since Version 1.0.0 */ var $homepage = 'home'; /** * Case formatting * * Specify the format you would like the directory names to be in, first * letters uppercase, all uppercase, all lowercase, or the actual naming of * your directory with no changes. * - ucwords = uppers case words (use with _toSpace) * - titlecase = upper case words except small words (the, is, with, etc) * - ucfirst = upper case first letter * - uppercase = all uppercase * - lowercase = all lowercase * - none = show directories as they are named in path structure (DEFAULT) * * $breadcrumb->dirformat = 'ucfirst';
* Example: * Baskettcase > Php_classes > Breadcrumb > Index.htm * @var string ucfirst, uppercase, lowercase, ucwords, titlecase * @since Version 1.0.0 */ var $dirformat = ''; /** * Symbol separator * * Specify what symbols to use between your directory names. *
DEFAULT = ' > '
* $breadcrumb->symbol = ' || ';
* Example: * Baskettcase || php_classes || breadcrumb || index.htm * @var string * @since Version 1.0.0 */ var $symbol = ' > '; /** * CSS Class Style * * Use a css class to define the look of your breadcrumb. * $breadcrumb->cssClass = 'crumb';
* @var string * @since Version 2.3.0 */ var $cssClass = ''; /** * Special formatting * * I also added a "special" formatting which allows you to show the path as if * Elmer Fudd wrote it, or a Hacker wrote it, or in Reverse or hey even in pig * latin! * - elmer = elmer fudd translation * - hacker = hacker speach translation * - pig = pig latin translation * - reverse = Reverses the text so it is backwards * - none = no special formatting (DEFAULT) * * $breadcrumb->special = 'elmer';
* Example: * Baskettcase > php_cwasses > bweadcwumb > index.htm * @var string elmer, hacker, pig, reverse, none * @since Version 1.0.0 */ var $special = ''; /** * Frameset Target * * Target a frameset. * $breadcrumb->target = '_blank'; * @var string * @since Version 2.4.0 */ var $target = ''; /** * Show filename * * Specify whether or not to show the current file name, just show the path or * show the path with the file name. * $breadcrumb->showfile = FALSE;
* Example: * homepage > Baskettcase > php_classes > breadcrumb *

$breadcrumb->showfile = TRUE;
* Example: * Baskettcase > php_classes > breadcrumb > index.htm * @var bool * @since Version 1.0.0 */ var $showfile = TRUE; /** * Unlink Current Directory * * Removes the current directory link. * $breadcrumb->unlinkCurrentDir = TRUE; * @var bool */ var $unlinkCurrentDir = FALSE; /** * Hide File Extension * * Hides the filename extension * $breadcrumb->hideFileExt = TRUE;
* Example: * Baskettcase > php_classes > breadcrumb > index * @var bool * @since Version 2.4.2 */ var $hideFileExt = FALSE; /** * Filename Linking * * Links the filename to itself. * $breadcrumb->linkFile = TRUE; * @var bool * @since Version 2.4.0 */ var $linkFile = FALSE; /** * Replace Underscores * * Replace underscores with spaces. * $breadcrumb->_toSpace = TRUE;
* Example: * Baskettcase > php classes > breadcrumb > index.htm * @link http://www.baskettcase.com/classes/breadcrumb/test_dir_with_underscores/underscore.php * @var bool * @since Version 2.3.0 */ var $_toSpace = FALSE; /** * Use images * * Use images in place of text for your breadcrumbs, by specifying the * directory the images can be found in. You can also specify the image type * (gif, jpg, etc), border, id, name, hspace, vspace, align, height, width, and * alt attributes. I have also included an example of how to use an image for * the separator character. If you use the changeName function along with * images, the alt attribute will be the changed name, while the id and name * attributes will remain the actual directory name. * $breadcrumb->imagedir = array('path'=>'images/', 'type'=>'gif', 'border'=>2, 'id'=>FALSE, 'name'=>TRUE, * 'hspace'=>2, 'vspace'=>4, 'align'=>'top', 'height'=>20, 'width'=>75, 'alt'=>TRUE, 'title'=>TRUE); * @var array path, type, border, id, name, hspace, vspace, align, height, width, alt, title * @since Version 2.0.0 */ var $imagedir = array(); /** * Directory aliasing * * Rename your directories to whatever you would like them to show up as in * your breadcrumb. * $breadcrumb->changeName=array('home'=>'Baskettcase Homepage', * 'php_classes'=>'PHP Classes', * 'breadcrumb'=>'Breadcrumbs Class');
* Example: * Baskettcase Homepage > PHP Classes > Breadcrumbs Class > index.htm * @var array * @since Version 1.0.0 */ var $changeName = array(); /** * Filename Aliasing * * Change the filename to a more user friendly one. * $breadcrumb->changeFileName = array('/classes/breadcrumb/index.htm'=>'Breadcrumbs PHP Class v. 2.4.4');
* Example: * Baskettcase > php_classes > breadcrumb > Breadcrumbs PHP Class v. 2.4.4 * @var array * @since Version 2.3.7 */ var $changeFileName = array(); /** * Index exists? * *

Set your index file name so that if the file exists then link the * directory, otherwise if the file does not exist do not create a link.

*

This is good for those people that do not want surfers to be able to look * at their directory structure if they do not have a default index page within * that directory. It will still show the directory name within the breadcrumb, * but it will not add a link to the directory name.

* $breadcrumb->fileExists = array('index.htm','index.php','index.html'); * @var array * @since Version 1.0.0 */ var $fileExists = array(); /** * Remove Directories * * Hide a directory from showing in the breadcrumb. * $breadcrumb->removeDirs = array('php_classes');
* Example: * homepage > Baskettcase > breadcrumb > index.htm * @var array * @since Version 2.3.7 */ var $removeDirs = array(); /** * Directory Structure * @access private */ var $scriptArray = ''; /** * File name * @access private */ var $fileName = ''; /** * Document Root * @access private */ var $document_root = ''; /** * is this a personal site? * @access private */ var $personalSite = ''; /** * Show errors * @access private */ var $showErrors = FALSE; /** * Breadcrumb * @since Version 2.0.0 * @access private */ function breadcrumb() { // Creates an array of Directory Structure $this->scriptArray = explode("/", $_SERVER['PHP_SELF']); // Pops the filename off the end and throws it into it's own variable $this->fileName = array_pop($this->scriptArray); // Is this a personal site? if (substr($_SERVER['PHP_SELF'], 1, 1)=='~') { $tmp = explode('/', $_SERVER['PHP_SELF']); $this->personalSite = $tmp[1]; $this->document_root = str_replace(str_replace('/'.$this->personalSite, '', $_SERVER["SCRIPT_NAME"]), '', $_SERVER['PATH_TRANSLATED']); } else $this->document_root = str_replace($_SERVER["SCRIPT_NAME"], '', $_SERVER['PATH_TRANSLATED']); #echo $this->document_root.'
'; #echo $_SERVER["SCRIPT_NAME"].'
'; #echo $_SERVER["PATH_TRANSLATED"].'
'; } /** * Converts a string to an array * @since Version 2.2.0 * @access private */ function str_split($string) { for ($i=0; $istr_split($string); $firstLetter = array_shift($string); $string = @implode('',$string); $string = (in_array($firstLetter, $vowels)) ? $firstLetter.$string.'yay' : $string.$firstLetter.'ay'; break; case 'reverse': $string = strrev($string); break; } return $string; } /** * Convert string into specified format * @since Version 2.2.0 * @access private */ function dirFormat($string, $format) { // parse Directory text style switch($format) { case 'titlecase': $string = $this->titleCase($string); break; case 'ucfirst': $string = ucfirst($string); break; case 'ucwords': $string = $this->convertUnderScores($string); $string = ucwords($string); break; case 'uppercase': $string = strtoupper($string); break; case 'lowercase': $string = strtolower($string); break; default: $string = $string; } return $string; } /** * TitleCase * Convert string into Title Case which excludes capitalizing certain small * words. As in a movie title, or book title. "The Wind in the Trees" * @author Justin@gha.bravepages.com, un-thesis@wakeup-people.com, mgm@starlingtech.com, rick@baskettcase.com * @access private * @since Version 2.3.0 */ function titleCase($text) { $text = $this->convertUnderScores($text); $min_word_len = 4; $always_cap_first = TRUE; $exclude = array('of','a','the ','and','an','or','nor','but','is','if', 'then','else','when','up','at','from','by','on','off', 'for','in','out','over','to','into','with','htm','html', 'php','phtml'); // Allows for the specification of the minimum length // of characters each word must be in order to be capitalized // Make sure words following punctuation are capitalized $text = str_replace(array('(', '-', '.', '?', ',',':','[',';','!'), array('( ', '- ', '. ', '? ', ', ',': ','[ ','; ','! '), $text); $words = explode (' ', strtolower($text)); $count = count($words); $num = 0; while ($num < $count) { if (strlen($words[$num]) >= $min_word_len && array_search($words[$num], $exclude) === false) $words[$num] = ucfirst($words[$num]); $num++; } $text = @implode(' ', $words); $text = str_replace( array('( ', '- ', '. ', '? ', ', ',': ','[ ','; ','! '), array('(', '-', '.', '?', ',',':','[',';','!'), $text); // Always capitalize first char if cap_first is true if ($always_cap_first) { if (ctype_alpha($text[0]) && ord($text[0]) <= ord('z') && ord($text[0]) > ord('Z')) $text[0] = chr(ord($text[0]) - 32); } return $text; } /** * Remove Directories * Remove the directories from the breadcrumb * @since Version 2.3.2 * @access private */ function removeDirectories() { $numDirs = count($this->scriptArray); for ($i=0; $i<$numDirs; $i++) { if (!in_array($this->scriptArray[$i], $this->removeDirs)) $newArray[] = $this->scriptArray[$i]; } return $newArray; } /** * Remove File Extension * Remove the file extension from the filename * @since Version 2.4 * @access private */ function removeFileExt($filename) { $newFileName = @explode('.',$filename); return $newFileName[0]; } /** * Convert Underscores * Replace underscores with spaces * @since Version 2.4 * @access private */ function convertUnderScores($name) { $varName = str_replace('_',' ',$name); return $varName; } /** * Show Breadcrumb * * Outputs the html formatted breadcrumb according to the variables you set. * echo "

".$breadcrumb->show_breadcrumb()."

";
* @since Version 0.0.1 */ function show_breadcrumb() { $dir = $showLink = $class = $target = ''; // Either set the home element or pop the first empty array off the beginning if ($this->homepage != '') $this->scriptArray[0] = $this->homepage; else $tmp = array_shift($this->scriptArray); // if this is a personal site remove the root directory and set // new homepage to user directory if ($this->personalSite!='') { $this->removeDirs[] = $this->scriptArray[0]; if ($this->homepage != '') $this->scriptArray[1] = $this->homepage; else $tmp = array_shift($this->scriptArray); } if ($this->homepage=='') $dir = '/'; // Build Path Structure $numDirs = count($this->scriptArray); // BEGIN DIRECTORY FOR LOOP for ($i=0; $i<$numDirs; $i++) { #echo $this->changeName[$this->scriptArray[$i]]; #$dirName = $this->scriptArray[$i]; $dirName = ($this->changeName[$this->scriptArray[$i]]!='') ? $this->changeName[$this->scriptArray[$i]] : $this->scriptArray[$i]; // append the current directory if ($this->personalSite!='' && $i==1) $this->scriptArray[$i] = $this->personalSite; $dir .= ($i==0 && $this->homepage!='') ? '/' : $this->scriptArray[$i]."/"; // Replace underscores with spaces if _toSpace is set if ($this->_toSpace==TRUE) $dirTxtName = $this->convertUnderScores($dirName); // parse Directory special text style $dirTxtName = $this->specialLang($dirName, $this->special); // Convert string into specified format $dirTxtName = $this->dirFormat($dirName, $this->dirformat); // Use text instead of images if ($this->imagedir['path']=='') $dirName = $dirTxtName; // Use Images instead of text else { // Set defaults if (!$this->imagedir['type']) $this->imagedir['type'] = 'gif'; if (!$this->imagedir['border']) $this->imagedir['border'] = '0'; if (!$this->imagedir['id']) $this->imagedir['id'] = TRUE; if (!$this->imagedir['name']) $this->imagedir['name'] = TRUE; if (!$this->imagedir['alt']) $this->imagedir['alt'] = TRUE; $dirName = 'imagedir['id']==TRUE) // id $dirName .= ' id="' . $this->scriptArray[$i] . '"'; if ($this->imagedir['name']==TRUE) // name $dirName .= ' name="' . $this->scriptArray[$i] . '"'; if ($this->imagedir['alt']==TRUE) { // alt $alt = ($this->changeName[$this->scriptArray[$i]]!='') ? $this->changeName[$this->scriptArray[$i]] : $this->scriptArray[$i]; $dirName .= ' alt="' . $alt . '"'; } if ($this->imagedir['title']==TRUE) { // title $title = ($this->changeName[$this->scriptArray[$i]]!='') ? $this->changeName[$this->scriptArray[$i]] : $this->scriptArray[$i]; $dirName .= ' title="' . $title . '"'; } if ($this->imagedir['hspace']) // hspace $dirName .= ' hspace="' . $this->imagedir['hspace'] . '"'; if ($this->imagedir['vspace']) // vspace $dirName .= ' vspace="' . $this->imagedir['vspace'] . '"'; if ($this->imagedir['align']) // align $dirName .= ' align="' . $this->imagedir['align'] . '"'; if ($this->imagedir['height']) // height $dirName .= ' height="' . $this->imagedir['height'] . '"'; if ($this->imagedir['width']) // width $dirName .= ' width="' . $this->imagedir['width'] . '"'; $dirName .= ' />'; } // Add CSS if ($this->cssClass!='') $class = ' class="'.$this->cssClass.'"'; // Add frame target if ($this->target!='') $target = ' target="'.$this->target.'"'; // create link // If fileExists has values then check to make sure one of those files // exists, if it does, link it, otherwise do not link if ($this->fileExists) { for ($k=0; $kfileExists); $k++) { if ($this->personalSite!='') { if (strpos($dir, $this->personalSite)) $exists_filename = str_replace($this->personalSite.'/', '', $this->document_root.$dir.$this->fileExists[$k]); else continue; } else $exists_filename = $this->document_root.$dir.$this->fileExists[$k]; #echo $exists_filename.'
'; if (file_exists($exists_filename)) { $showLink = 'yes'; break; } else $showLink = 'no'; } } // Set the root filename if it is different then the default index page $rootFileName = ($this->rootIndexLink!='' && $dir == '/') ? $this->rootIndexLink : ''; if (!in_array($this->scriptArray[$i], $this->removeDirs)) { if ($this->unlinkCurrentDir==TRUE && ($i+1)==$numDirs || $showLink=='no') $breadcrumb[] = $dirName; // If we are not supposed to remove the directory, show it elseif (!in_array($this->scriptArray[$i], $this->removeDirs) || $showLink=='yes') $breadcrumb[] = '' . $dirName . ''; elseif ($this->personalSite!='' && $i==1) $breadcrumb[] = '' . $dirName . ''; } } // END DIRECTORY FOR LOOP $fileName = $originalFileName = $this->fileName; #if ($this->fileNametoTitle==TRUE) $fileName = $this->getPageTitle(); // Check to see if hideFileExt is on, if so turn on showfile // and remove the file extension if ($this->hideFileExt==TRUE) $this->showfile = TRUE; if ($this->showfile==TRUE) { // Change the filename if filename is in changeFileName array if ($this->changeFileName[$_SERVER['PHP_SELF']]!='') $fileName = $this->changeFileName[$_SERVER['PHP_SELF']]; // If it is not then just use $fileName or remove extension if specified elseif ($this->hideFileExt==TRUE) $fileName = $this->removeFileExt($fileName); // Convert underscores to spaces if ($this->_toSpace==TRUE) $fileName = $this->convertUnderScores($fileName); // parse filename special text style $fileName = $this->specialLang($fileName, $this->special); // Convert string into specified format $fileName = $this->dirFormat($fileName, $this->dirformat); // Add CSS if ($this->cssClass!='') $fileName = ''. $fileName.''; // Add link to filename if ($this->linkFile==TRUE) $fileName = ''.$fileName.''; $fileName = $this->symbol.$fileName; } else $fileName = ''; // Web Server Path // return if we are not at root if ($numDirs>0) return @implode($this->symbol,$breadcrumb).$fileName; // if at root just return the filename else return $fileName; echo $dir; } } ?>