| // +--------------------------------------------------------------------+ // // $Id$ // /** * General file utilities functions. * * This is a group of static functions for getting file info and other * stuff. * * @package Hooks * @author Leandro Lucarella * @version $Rev$ * @since rev 122 * @access public */ class File_Util { /** * Splits a filename into path, filename and extension. * * @param string $file Filename to split. * * @return array Array where the first element (index 0) is the * path, the second is the name and the third is the * extension. * * @access public * @since rev 122 */ function splitFilename($file) { $path = preg_split('|/|', $file); $file = array_pop($path); $ext = ''; if (strstr($file, '.')) { preg_match('|([^/]+?)(\.([^\.]*))?$|', $file, $m); $file = @$m[1] . ((@$m[2] == '.' ) ? '.' : ''); $ext = @$m[3]; } $dir = count($path) ? join('/', $path) : ''; return array($dir, $file, $ext); } /** * Tells if a file is readable looking in the include path. * * @param string $file Name of the file to look for. * * @return bool True if file is readable, false if not. * * @access public * @since rev 122 */ function isReadableInclude($file) { list($dir, $page, $ext) = File_Util::splitFilename($file); if (is_readable($file)) { return true; } $include_path = array_unique(preg_split('/:/', ini_get('include_path'))); foreach ($include_path as $path) { if (is_readable("$path/$file")) { return true; } } return false; } /** * Gets the last modification date/time for a file. * * @param string $file Name of the file to get the last modification * date/time. * @param string $format Format (see strftime). * * @return string Formated string with the last modification * date/time. * * @see strftime() * @access public * @since rev 142 */ function lastModified($file, $format = '%c') { return strftime($format, filemtime($file)); } } // This is a workarround to live until PHP 4.3 is out and we can use the // native get_file_contents() function. We don't care about // $use_include_file option. function file_get_contents($file, $use_include_file = false) { if (@is_readable($file)) { $var = join('', file($file)); } else { $var = ''; } return $var; } ?>