* @copyright 2006 by http://wombat.exit0.net * @package wombat * @subpackage file */ /** * wbFile auxiliary class to handle files * * @version 1.0.0 * @package wombat * @subpackage file */ class wbFile { /** * touch file * * @param string $file * @return bool true on success */ static public function touch( $file, $mkdir = true ) { if( !file_exists( $file ) ) { if( !self::mkDir( dirname( $file ) ) ) { return false; } touch( $file ); chmod( $file, 0666 ); } return true; } /** * mkdir * * @param string $dir * @param bool $recursive * @return bool true on success */ static public function mkDir( $dir, $recursive = true ) { if( is_dir( $dir ) ) { return true; } mkdir( $dir, 0777, $recursive ); return true; } /** * load content from file * * @param string $file * @return string content of file */ static public function load( $file ) { if( !is_file( $file ) ) { return false; } return file_get_contents( $file ); } /** * save content to file * * @param string $file * @param string content of file * @return bool true on success */ static public function save( $file, $content ) { if( !file_exists( $file ) ) { self::touch( $file ); } return file_put_contents( $file, $content ); } /** * check file age * * @param string $file * @param string $age in seconds * @param bool $isFile * @return bool if file is newer */ static public function isNewer( $file, $age, $isFile = false ) { if( !is_file( $file ) ) { return false; } if( $isFile ) { $minAge = filemtime( $age ); } else { $minAge = time() - $age; } if( filemtime( $file ) > $minAge ) { return true; } return false; } } ?>