Plugin Directory

Changeset 369969


Ignore:
Timestamp:
04/07/2011 08:04:04 AM (15 years ago)
Author:
stevevls
Message:

minor compatibility fix for .mo file download on systems where file_get_contents won't fetch URLs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gts-translation/tags/1.1.5/wordpress/GtsPluginWordpress.php

    r369686 r369969  
    496496        global $wp_version;
    497497        $locale_name = com_gts_Language::get_by_code( $language )->wordpressLocaleName;
    498         $svn_url = "http://svn.automattic.com/wordpress-i18n/$locale_name";
     498
     499        $svn_host = 'svn.automattic.com';
     500        $svn_url = "/wordpress-i18n/$locale_name";
    499501        $svn_messages_dir = "messages" . ( $domain != "default" ? "/$domain" : "");
    500502
     
    503505        }
    504506
    505         $tags = @file_get_contents( "$svn_url/tags/" );
     507        $tags_fp = $this->url_get_stream( $svn_host, 80, "$svn_url/tags/" );
     508        $tags = @stream_get_contents( $tags_fp );
     509        @fclose( $tags_fp );
     510
    506511        if( $tags ) {
    507512
     
    531536
    532537                foreach ( $prioritized_versions as $version ) {
    533                     if( $this->download_mofile_to_i18n_dir( "$svn_url/tags/$version/$svn_messages_dir/$locale_name.mo", $domain, $version, "$locale_name.mo" ) ) {
     538                    if( $this->download_mofile_to_i18n_dir( $svn_host, "$svn_url/tags/$version/$svn_messages_dir/$locale_name.mo", $domain, $version, "$locale_name.mo" ) ) {
    534539                        return TRUE;
    535540                    }
     
    538543        }
    539544
    540         return $this->download_mofile_to_i18n_dir( "$svn_url/trunk/$svn_messages_dir/$locale_name.mo", $domain, "0.0", "$locale_name.mo" );
    541     }
    542 
    543 
    544     function download_mofile_to_i18n_dir( $svn_url, $dirname, $version, $filename ) {
    545 
    546         $i18n_base = GTS_I18N_DIR . "/$version/$dirname/";
    547 
    548         $mo_stream = @fopen( $svn_url, 'r' );
     545        return $this->download_mofile_to_i18n_dir( $svn_host, "$svn_url/trunk/$svn_messages_dir/$locale_name.mo", $domain, "0.0", "$locale_name.mo" );
     546    }
     547
     548
     549    function download_mofile_to_i18n_dir( $svn_host, $svn_url, $dirname, $version, $filename ) {
     550
     551        $i18n_base = GTS_I18N_DIR . "/$version/$dirname";
     552
     553        $mo_stream = $this->url_get_stream( $svn_host, 80, $svn_url );
    549554        if( !$mo_stream ) {
    550555            return FALSE;
     
    567572
    568573        return TRUE;
     574    }
     575
     576
     577    // this is a workaround to deal with hosts where file_get_contents doesn't work for URLs
     578    // due to security constraints...
     579    function url_get_stream( $host, $port, $url ) {
     580
     581        $fp = @fsockopen( $host, $port );
     582
     583        if( $fp ) {
     584            @fwrite( $fp, "GET $url HTTP/1.1\r\n" );
     585            @fwrite( $fp, "Host: $host\r\n" );
     586            @fwrite( $fp, "\r\n" );
     587
     588            // in our ghetto wire impl, we'll ignore headers.  when we come across
     589            // the first blank \r\n, we'll return the result.
     590            while ( $str = @fgets( $fp, 4096) ) {
     591                if ( $str == "\r\n" ) {
     592                    return $fp;
     593                }
     594            }
     595        }
     596
     597        return $fp;
    569598    }
    570599
     
    12791308define( 'GTS_PLUGIN_URL', trailingslashit( WP_PLUGIN_URL ) . basename( GTS_PLUGIN_DIR) );
    12801309
    1281 define( 'GTS_I18N_DIR', GTS_PLUGIN_DIR . '/i18n/' );
     1310define( 'GTS_I18N_DIR', GTS_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'i18n' );
    12821311
    12831312$plugin_data = get_file_data( GTS_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'Gts.php', array( 'Name' => 'Plugin Name', 'Version' => 'Version' ) );
Note: See TracChangeset for help on using the changeset viewer.