Menu

#24 Function file_exists_in_path not windows friendly.

open-accepted
alan
5
2006-12-15
2006-12-13
Anonymous
No

I couldn't get the Plugin to find the other files so I checked the code. Starting line 772 in Rev76 file_exists_in_path assumes Unix paths.

So I played around.

Added an if statement to Check if DIRECTORY_SEPARATOR are not Unix then correct file for Windows slashes.

Changed substr( $path, 0, 1 ) code to look for same directory "." and not parent directory ".." then append current path. Don't use directory slash, Windows can start with // for network path or drive letter.

if( !function_exists( 'file_exists_in_path' ) ) {
function file_exists_in_path ($file) {
if( file_exists( $file ) ) return $file;
$relativeto = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
$paths = explode(PATH_SEPARATOR, get_include_path());
if (DIRECTORY_SEPARATOR != "/")
$file = str_replace ( "/" , DIRECTORY_SEPARATOR , $file );
foreach ($paths as $path) {
$fullpath = $path . DIRECTORY_SEPARATOR . $file;
if( substr( $path, 0, 1 ) == '.' && substr( $path, 0, 1 ) != '..' )
$fullpath = $relativeto . $fullpath;
if (file_exists($fullpath)) return $fullpath;
}
return false;
}
}

Discussion

  • John Arnold

    John Arnold - 2006-12-13

    Logged In: YES
    user_id=1044987
    Originator: NO

    Sorry didn't login if you have questions or problems email hopefully this comment will include contact info.

     
  • alan

    alan - 2006-12-15
    • assigned_to: nobody --> alanjcastonguay
    • status: open --> open-accepted
     
  • alan

    alan - 2006-12-15

    Logged In: YES
    user_id=1532337
    Originator: NO

    Maybe I went overboard on the sanity checks. Is there anything wrong with this? Specifically, is there any chance that include_once() could puke and not continue processing?

    set_include_path( get_include_path() . PATH_SEPARATOR . dirname(__FILE__) ); // Add plugin directory to include path
    foreach( $wordpressOpenIDRegistration_Required_Files as $___k => $___v ) {
    if( @include_once( $___k ) ) {
    wordpressOpenIDRegistration_Status_Set('loading file: '.$___k, true, '');
    continue;
    }
    wordpressOpenIDRegistration_Status_Set('file:'.$___k, false, $___v );
    break;
    }
    restore_include_path(); // Leave no footprints behind

     

Log in to post a comment.

Auth0 Logo