0; $abs = preg_replace( $re, '/', $abs, -1, $n ) ) {} // Absolute URL is ready.. return $scheme.'://'.$abs; } /** * Changes the extension of a file. * * @param string $file_path The full file name/path to change * @param string $new_extension The extension to change to (no leading dot) * @return string The newly-changed full file name/path */ public static function change_extension( $file_path, $new_extension ) { $info = pathinfo( $file_path ); $print_dirname = ( empty( $info['dirname'] ) || ( $info['dirname'] == '.' ) ) ? '' : ( $info['dirname'].'/' ); $print_extension = ( empty( $new_extension ) ) ? '' : ( '.'.$new_extension ); return $print_dirname.$info['filename'].$print_extension; } /** * Returns an array of files found under a specific directory. * * @param string $folder The directory path to search for files * @param string $pattern A regex pattern to be used to filter in results (take care that this could match the whole path) * @param boolean $include_subdirectories Set to 'true' if all subfolder should be searched; set to 'false' if just the top-level * @return array The list of fule filepaths that met the criteria */ public static function get_files( $folder, $pattern = '/.*/', $include_subdirectories = false ) { $dir = $include_subdirectories ? new \RecursiveDirectoryIterator( $folder ) : new \DirectoryIterator( $folder ); $iters = $include_subdirectories ? new \RecursiveIteratorIterator( $dir ) : new \IteratorIterator( $dir ); $file_list = array(); foreach ( $iters as $iter ) { $file = $iter->getPathname(); if ( !preg_match( $pattern, $file ) ) continue; if ( !is_file( $file ) ) continue; $file_list[] = $file; } return $file_list; } /** * Changes all occurences of backslashes to forward slashes - can come * in handy when working with a windows path that needs to look like * a *nix path instead. * * @param string $path The path to change * @return string The path with forward slashes */ public static function force_forward_slashes( $path ) { return str_replace( '\\', '/', $path ); } /** * Trying to figure out the ski.web directory for both local and remote * versions has become ridiculous. As a result, it is a requirement for * installation that the programmer define the SKI_URI. Should be something * like 'http://localhost/mysite' instead of 'e:\wamp\www\mysite'. * * @return string The full path to where ski.web resides */ public static function get_ski_directory_uri() { // If the programmer properly set the installation directory. if ( defined( 'SKI_URI' ) ) { return SKI_URI; } // Making it here means they have not, so cut out with information. die( 'You must define the SKI_URI just before you include the ski.web library' ); } /** * Looks at the URL that was used to open the current page (from the server). * Note: Do not rely on $_SERVER['REQUEST_SCHEME']; some older versions of * Apache do not fill that value in properly. * * @return string Something like 'http', 'https', 'ftp', etc. No '://' is included. */ public static function get_request_protocol() { if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) return 'https'; else if ( isset( $_SERVER['REQUEST_SCHEME'] ) ) return $_SERVER['REQUEST_SCHEME']; return 'http'; } /* PRIVATE */ /** * Only use this class as a utility.. */ private function __construct() { // Intentionally blank.. } } ?>