Changeset 2497318
- Timestamp:
- 03/16/2021 07:59:46 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fpw-category-thumbnails/trunk/classes/fpw-category-thumbnails-class.php
r2496446 r2497318 14 14 var $fctVersion; 15 15 var $fctPage, $fptPage; 16 var $fctLocale;17 var $translationURL;18 var $languagepackPath;19 var $translationStatus;20 var $translationResponse;21 16 var $wpVersion; 22 17 var $mapArray; … … 40 35 // set WP version 41 36 $this->wpVersion = $wp_version; 42 $this->fctLocale = get_locale();43 44 // set translation URL45 $this->translationURL = 'http://svn.wp-plugins.org/fpw-category-thumbnails/translations/' .46 $this->fctVersion . '/fpw-category-thumbnails-' . $this->fctLocale;47 48 // set translation path (language pack)49 $this->languagepackPath = WP_CONTENT_DIR . '/languages/plugins/fpw-category-thumbnails-' . $this->fctLocale;50 37 51 38 // initialize $showRestore … … 134 121 } 135 122 136 // check translation file availability137 function translationAvailable() {138 139 // if language file exist, do not load it again140 if ( is_readable( $this->languagepackPath . '.mo' ) )141 return 'installed';142 143 if ( version_compare( $this->wpVersion, '3.6.0', '<' ) ) {144 $this->translationResponse = wp_remote_get( $this->translationURL . '.mo', array( 'timeout' => 300 ) );145 } else {146 $this->translationResponse = wp_safe_remote_get( $this->translationURL . '.mo', array( 'timeout' => 300 ) );147 }148 149 // if no translation file exists exit the check150 if ( is_wp_error( $this->translationResponse ) || $this->translationResponse[ 'response' ][ 'code' ] != '200' )151 return 'not_exist';152 153 return 'available';154 }155 156 123 // register plugin's textdomain 157 124 function init() { 158 125 load_plugin_textdomain( 'fpw-category-thumbnails' ); 159 if ( !( 'en_US' == $this->fctLocale ) )160 $this->translationStatus = $this->translationAvailable();161 126 } 162 127 … … 403 368 } 404 369 405 private function doGetLanguage() {406 if ( 'not_exist' == $this->translationStatus ) {407 $m = __( 'Language pack for this version is not yet available.', 'fpw-category-thumbnails' );408 } elseif ( 'installed' == $this->translationStatus ) {409 $m = __( 'Language pack is already installed.', 'fpw-category-thumbnails' );410 } else {411 $handle = @fopen( $this->languagepackPath . '.mo', 'wb' );412 fwrite( $handle, $this->translationResponse[ 'body' ] );413 fclose($handle);414 if ( version_compare( $this->wpVersion, '3.6.0', '<' ) ) {415 $this->translationResponse = wp_remote_get( $this->translationURL . '.po', array( 'timeout' => 300 ) );416 } else {417 $this->translationResponse = wp_safe_remote_get( $this->translationURL . '.po', array( 'timeout' => 300 ) );418 }419 if ( !is_wp_error( $this->translationResponse ) ) {420 $handle = @fopen( $this->languagepackPath . '.po', 'wb' );421 fwrite( $handle, $this->translationResponse[ 'body' ] );422 fclose($handle);423 }424 $this->translationStatus = 'installed';425 $m = __( 'Language pack downloaded successfully. It will be applied as soon as this page is reloaded.', 'fpw-category-thumbnails' );426 }427 return $m;428 }429 430 370 // plugin's Settings page 431 371 function fctSettings() {
Note: See TracChangeset
for help on using the changeset viewer.