', $after='', $divider=' » ', $eachlink='%name%', $current='%name%', $homename='Blog',$debug=FALSE) {
/*
Other than debug iformation this script should be fully multilingual. You'll just have to manually specify formatting for different languages.
'root' - The location of the root of your site. If your site is http://www.example.com/ the root should be "/". However if your site is
http://www.example.com/userslog/ the root would be "/userslog/".
'showhome' - Will show the bct when the user is on the home page, however it will just be the test specified by 'homename' and not a link.
'before' - I suggest you insert your caption here. Could use something like 'You are here:', just whatever floats your boat.
'after' - Placed after the bct.
'divider' - Placed between each item in the bct, thats not before the first and not after the last.
'eachlink' - Format of each link item in the bct. Uses replacments - %url% - url for the individual bct, and '%name$ - text for the bct,
formatting applied by script.
'current' - Format for the item representing the current page, being the last item in the bct. Replaces '%name%' only.
'homename' - Text displayed for the home link, if you don't want to call it home then just change this.
'debug' - Seting this will make the script always display debug information. You can however just set ?debug in your uri to enable it.
*/
// Can also put settings in an ini file. Make sure if you use an ini file that its valid!
if (file_exists('wp-content/jp-bct/jp-bct.ini')) extract(parse_ini_file('wp-content/jp-bct/jp-bct.ini')); // For auto install additional files should be here.
if (isset($_GET['debug'])) $debug = TRUE; // You can display debug output easy.
// FORMAT INPUT
// Get and clean the URI.
$uri = html_entity_decode(rawurldecode(strtolower($_SERVER['REQUEST_URI']))); // To the maxxx
// Trim $root from the start of the URI.
$uri = substr($uri,strlen($root));
// If there is a page .php that is not index you'll want that, but you wont want the ext.
// if (strrpos($uri,'.')) $uri = substr($uri,0,strrpos($uri,'.'));
/* finds position of . in string and trims to that point, no good for prettylinks
but can be fixed with addition of 'index.php/' to link construction, see line 152 below */
// You don't want index only.
$uri = preg_replace('/index.php/','',$uri); // replaced index$ -> index.php
// Clear out any query crap (if a file wasnt specified).
$uri = preg_replace('/\?.*/','',$uri); //commented out
// Remove slashes from the start and end.
$uri = ltrim($uri,'/');
$uri = rtrim($uri,'/');
// Possible to improve the above script some time. Also possible the above still have a few bugs in situations I haven't thought of.
($uri != '') ? $elements = explode('/', $uri) : $counter = 0; // If the uri is not empty explode it.
if ($elements) $counter = count($elements); // If it was exploded count the number of elements it produced.
echo ''; // General debug - always people in situations I haven't thought of will have some debug. Probally pointless but you know.
if ($debug) {
echo 'Debug:
Cleaned URI:'.$uri.'
Counter: '.$counter.'
Exploded: ';
print_r($elements);
echo '
';
}
// Only show home if showhome is set or there are links in the bct.
// I think it would be possible to improve this section with a bit of reworking, however the current set-up seems to work fine for the moment.
if (($showhome) and ($counter == 0)) {
$output = $before;
$output .= str_replace('%name%',$homename,$current);
$output .= $after;
return;
} elseif ($counter > 0) {
$output = $before;
$linkname = $homename;
$linkurl = $root;
$output .= jp_getcrumb($eachlink,$divider,array('name'=>$linkname, 'url'=>$linkurl)); // Home link
for ($i=0; $i<$counter; $i++)
{
$link = $elements[$i];
$linkname = str_replace('-',' ',ucfirst($link));
if ($i == ($counter-1)) {
$crumb = str_replace('%name%',$linkname,$current);
} else {
$linkurl = $linkurl . 'index.php/' . $link . '/'; // fix for broken strrpos
$crumb = jp_getcrumb($eachlink,$divider,array('name'=>$linkname,'url'=>$linkurl));
}
$output .= $crumb;
}
$output .= $after;
echo $output . "\n";
return;
}
}
function jp_getcrumb($eachlink,$divider,$data) // For use by jp_bct() only.
{
$elements = array('name','url');
$return = $eachlink;
foreach ($elements as $element)
{
$replace = 'link'.$element;
$return = str_replace('%'.$element.'%',$data[$element],$return);
}
if ($divider) $return .= $divider;
return $return;
}
?>