Created
June 29, 2012 06:26
-
-
Save cha0s/3016239 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function base_url() { | |
return (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; | |
} | |
function path_parts() { | |
return array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); | |
} | |
function transform_name($name) { | |
return ucwords(str_replace(array('.php', '_'), Array('', ' '), $name)); | |
} | |
function body_classes() { | |
$classes = array(); | |
$parts = path_parts(); | |
if (0 == count($parts)) return ''; | |
foreach ($parts as $part) { | |
$classes[] = transform_name($part); | |
} | |
return implode(' ', $classes); | |
} | |
/** | |
* Display breadcrumbs and site sections based on path to file | |
*/ | |
function breadcrumbs($separator = ' » ', $home = 'Home') { | |
$parts = path_parts(); | |
if (0 === count($parts)) return ''; | |
$base_url = base_url(); | |
$last = end(array_keys($parts)); | |
$crumb_history = ''; | |
$breadcrumbs = array("<a href=\"$base_url\">$home</a>"); | |
foreach (path_parts() AS $x => $crumb) { | |
if ($crumb_history) $crumb_history .= '/'; | |
$crumb_history .= $crumb; | |
$title = transform_name($crumb); | |
if ($x !== $last) { | |
$breadcrumbs[] = '<a href="' . $base_url . $crumb_history . '">' . $title . '</a>'; | |
} | |
else { | |
$breadcrumbs[] = $title; | |
} | |
} | |
return implode($separator, $breadcrumbs); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment