array("mysite.com", "www.mysite.com"), "staging" => array("beta.mysite.com"), "local" => array("localhost/mysite/"), ); /* Get the static path to root (home) directory @return = static path to root */ function home_url() { global $server_url; foreach ($server_url as $server => $urls) { foreach($urls as $url) { if($_SERVER["SERVER_NAME"] == parse_url("http://".$url, PHP_URL_HOST) ) { return $url; } } } return $server_url["local"][0]; } /* Get relative path to root directory @return = relative path to root */ function get_root() { $folder_depth = substr_count($_SERVER["PHP_SELF"] , "/"); // Check the amount of nested URL preg_match_all("/\w\/\w/", home_url(), $matches ); $home_depth = count($matches[0]) + 1; return str_repeat("../", $folder_depth - $home_depth); } $root = get_root(); // Global root function root() { global $root; return $root; } /* Echo path to assets directory @return = relative path to specified assets directory */ function img() { echo root().'assets/img/'; } function css() { echo root().'assets/css/'; } function js() { echo root().'assets/js/'; } function files() { echo root().'assets/files/'; } /* Get partials @param file = partial file name, without extension @return = content of the partial file */ function get($file, $params = array()) { // If first letter is not underscore, add it if(substr($file, 0, 1) !== '_') { $file = '_'.$file; } return (include root().'partials/'.$file.'.php'); } /* Get the last word from the URL, useful for Header-menu's active state @return = the last word from the current page */ function get_current_page() { $pageURL = 'http'; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } $url_break = explode('/', $pageURL); return $url_break[count($url_break)-2]; }