00001 <?php
00002
00018 function findFiles( $dir, $exts ) {
00019 if( is_dir( $dir ) ) {
00020 if( $dhl = opendir( $dir ) ) {
00021 while( ( $file = readdir( $dhl ) ) !== false ) {
00022 if( is_file( $dir . '/' . $file ) ) {
00023 list( , $ext ) = splitFilename( $dir . '/' . $file );
00024 if( array_search( strtolower( $ext ), $exts ) !== false )
00025 $files[] = $dir . '/' . $file;
00026 }
00027 }
00028 return $files;
00029 } else {
00030 return false;
00031 }
00032 } else {
00033 return false;
00034 }
00035 }
00036
00043 function splitFilename( $filename ) {
00044 $parts = explode( '.', $filename );
00045 $ext = $parts[ count( $parts ) - 1 ];
00046 unset( $parts[ count( $parts ) - 1 ] );
00047 $fname = implode( '.', $parts );
00048 return array( $fname, $ext );
00049 }
00050
00065 function findAuxFile( $file, $auxExtension, $maxStrip = 1 ) {
00066 if ( strpos( $auxExtension, '.' ) !== 0 ) {
00067 $auxExtension = '.' . $auxExtension;
00068 }
00069
00070 $d = dirname( $file );
00071 $n = basename( $file );
00072
00073 while ( $maxStrip >= 0 ) {
00074 $f = $d . '/' . $n . $auxExtension;
00075
00076 if ( file_exists( $f ) ) {
00077 return $f;
00078 }
00079
00080 $idx = strrpos( $n, '.' );
00081 if ( !$idx ) break;
00082
00083 $n = substr( $n, 0, $idx );
00084 $maxStrip -= 1;
00085 }
00086
00087 return false;
00088 }