) and have unfortunately run into some difficulties. Because our website uses the ‘GET’ part of PHP (for example:
) we are having problems hyperlinking to previous pages using the breadcrumb, the breadcrumb links successfully but obviously without the get addition on the end of the address.
What we would like to know is that if there is a way that we could set custom links for certain names of pages in the class.breadcrumb.inc.php file (see bottom for attached code).
PHP Code:
<?php
/**
* File: $Id: class.breadcrumb.inc.php, 2004/04/30 00:53 PDT
* -----------------------------------------------------------------------
* 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
* -----------------------------------------------------------------------
* @access public
* @author Richard Baskett <rick@baskettcase.com>
* @category directory structure
* @copyright Copyright © 2004, Baskettcase Web Development
* @example example.php
* @link http://www.baskettcase.com/classes/breadcrumb/
* @package breadcrumb
* @version 2.4.2
*/
class breadcrumb {
// Directory Structure
var $scriptArray = '';
// Filename
var $fileName = '';
// Document Root
var $document_root = '';
// Homepage name
var $homepage = 'home';
// Directory type formatting
var $dirformat = '';
// Symbol to use between Directories
var $symbol = ' > ';
// CSS Class to use for each item
var $cssClass = '';
// Special Directory text style
var $special = '';
// Frameset target value default is '_self'
var $target = '';
// is this a personal site?
var $personalSite = '';
// Show the filename with the path
var $showfile = TRUE;
// Remove the link to the current directory
var $unlinkCurrentDir = FALSE;
// Hide the file Extension
var $hideFileExt = FALSE;
// Linke the filename to itself
var $linkFile = FALSE;
// Replace underscore with space
var $_toSpace = FALSE;
// Show errors
var $showErrors = FALSE;
// Where are the images kept and what type of images
var $imagedir = array();
// Change the Directory Names to something a bit more readable
var $changeName = array();
// Change the file name to something a bit more user friendly
var $changeFileName = array();
// If variable has a value check for that page if it exists link the directory
// otherwise just show the name of the directory.
var $fileExists = array();
// Remove a directory from the breadcrumb so that it does not show
var $removeDirs = array();
/**
* function breadcrumb
* @since Version 2.0.0
*/
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.'<Br />';
#echo $_SERVER["SCRIPT_NAME"].'<Br />';
#echo $_SERVER["PATH_TRANSLATED"].'<Br />';
}
/**
* function str_split
* @since Version 2.2.0
* Converts a string to an array
*/
function str_split($string) {
for ($i=0; $i<strlen($string); $i++) $array[] = $string{$i};
return $array;
}
/**
* function specialLang
* @since Version 2.0.0
* Convert string into language specified
*/
function specialLang($string, $lang) {
// parse Directory special text style
switch($lang) {
case 'elmer': $string = str_replace('l','w',$string);
$string = str_replace('r','w',$string);
break;
case 'hacker': $string = strtoupper($string);
$string = str_replace('A','4',$string);
$string = str_replace('C','(',$string);
$string = str_replace('D','D',$string);
$string = str_replace('E','3',$string);
$string = str_replace('F','ph',$string);
$string = str_replace('G','6',$string);
$string = str_replace('H','}{',$string);
$string = str_replace('I','1',$string);
$string = str_replace('M','|V|',$string);
$string = str_replace('N','|\|',$string);
$string = str_replace('O','0',$string);
$string = str_replace('R','R',$string);
$string = str_replace('S','5',$string);
$string = str_replace('T','7',$string);
break;
case 'pig': $vowels = array('a','A','e','E','i','I','o','O','u','U');
$string = $this->str_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;
}
/**
* function dirFormat
* @since Version 2.2.0
* Convert string into specified format
*/
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;
}
/**
* function titleCase
* @since Version 2.3.0
* 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
*/
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;
}
/**
* function removeDirectories
* @since Version 2.3.2
* @author rick@baskettcase.com
* Remove the directories from the breadcrumb
*/
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;
}
/**
* function removeFileExt
* @since Version 2.4
* @author rick@baskettcase.com
* Remove the file extension from the filename
*/
function removeFileExt($filename) {
$newFileName = @explode('.',$filename);
return $newFileName[0];
}
/**
* function convertUnderScores
* @since Version 2.4
* @author rick@baskettcase.com
* Replace underscores with spaces
*/
function convertUnderScores($name) {
$varName = str_replace('_',' ',$name);
return $varName;
}
/**
* function show_breadcrumb
* @since Version 0.0.1
*/
function show_breadcrumb() {
// 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]."/";
// Use Text instead of Images
if (!$this->imagedir) {
// Replace underscores with spaces if _toSpace is set
if ($this->_toSpace==TRUE)
$dirName = $this->convertUnderScores($dirName);
// parse Directory special text style
$dirName = $this->specialLang($dirName, $this->special);
// Convert string into specified format
$dirName = $this->dirFormat($dirName, $this->dirformat);
}
// Use Images instead of text
else {
$dirName = '<img src="'.$this->imagedir[0].$dirName.'.'.
$this->imagedir[1].'" />';
}
// 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; $k<count($this->fileExists); $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.'<br />';
if (file_exists($exists_filename)) {
$showLink = 'yes';
break;
} else $showLink = 'no';
}
}
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[] = "<a class=\"LargeVerdanasoft\" href='$dir'$class$target>$dirName</a>";
elseif ($this->personalSite!='' && $i==1)
$breadcrumb[] = "<a class=\"LargeVerdanasoft\" href='$dir'$class$target>$dirName</a>";
}
// 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 = '<span class="'.$this->cssClass.'">'.
$fileName.'</span>';
// Add link to filename
if ($this->linkFile==TRUE)
$fileName = '<a class="LargeVerdanasoft" href="'.$originalFileName.'">'.$fileName.'</a>';
$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;
}
}
?>
We appreciate any help that you can provide us with.