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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / inc / class-wcml-languages-upgrader.php
woocommerce-multilingual / inc Last commit date
admin-menus 4 weeks ago currencies 4 weeks ago template-classes 4 weeks ago translation-editor 4 weeks ago class-wcml-ajax-setup.php 4 weeks ago class-wcml-attributes.php 4 weeks ago class-wcml-capabilities.php 4 weeks ago class-wcml-cart-removed-items-widget.php 1 year ago class-wcml-cart-switch-lang-functions.php 4 weeks ago class-wcml-cart-sync-warnings.php 4 weeks ago class-wcml-cart.php 4 weeks ago class-wcml-comments.php 4 weeks ago class-wcml-compatibility.php 4 weeks ago class-wcml-coupons.php 4 weeks ago class-wcml-dependencies.php 4 weeks ago class-wcml-emails.php 4 weeks ago class-wcml-endpoints.php 4 weeks ago class-wcml-install.php 4 weeks ago class-wcml-languages-upgrader.php 4 weeks ago class-wcml-locale.php 4 weeks ago class-wcml-orders.php 4 weeks ago class-wcml-products-screen-options.php 4 weeks ago class-wcml-products.php 4 weeks ago class-wcml-reports.php 4 weeks ago class-wcml-requests.php 4 weeks ago class-wcml-resources.php 4 weeks ago class-wcml-store-pages.php 4 weeks ago class-wcml-terms.php 4 weeks ago class-wcml-tp-support.php 4 weeks ago class-wcml-troubleshooting.php 4 weeks ago class-wcml-upgrade.php 4 weeks ago class-wcml-url-translation.php 4 weeks ago class-wcml-wc-gateways.php 4 weeks ago class-wcml-wc-shipping.php 4 weeks ago class-wcml-wc-strings.php 4 weeks ago class-wcml-widgets.php 4 weeks ago constants.php 4 weeks ago functions-pure.php 4 weeks ago functions.php 4 weeks ago installer-loader.php 4 weeks ago missing-php-functions.php 4 weeks ago wcml-core-functions.php 4 weeks ago wcml-switch-lang-request.php 4 weeks ago
class-wcml-languages-upgrader.php
213 lines
1 <?php
2
3 class WCML_Languages_Upgrader {
4
5
6
7 public function __construct() {
8
9 add_action( 'icl_update_active_languages', [ $this, 'download_woocommerce_translations_for_active_languages' ] );
10 add_filter( 'upgrader_pre_download', [ $this, 'version_update' ], 10, 2 );
11 add_action( 'admin_notices', [ $this, 'translation_upgrade_notice' ] );
12 add_action( 'wp_ajax_hide_wcml_translations_message', [ $this, 'hide_wcml_translations_message' ] );
13
14 $this->load_js();
15 }
16
17 public function download_woocommerce_translations( $lang_code, $wc_version ) {
18 global $sitepress;
19
20 $locale = $sitepress->get_locale( $lang_code );
21
22 if ( $locale !== 'en_US' && $this->has_available_update( $locale, $wc_version ) ) {
23
24 $wc_version = $wc_version ?: WC_VERSION;
25
26 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
27 require_once ABSPATH . 'wp-admin/includes/file.php';
28 require_once ABSPATH . 'wp-admin/includes/plugin.php';
29 require_once ABSPATH . 'wp-admin/includes/template.php';
30
31 $url = 'update-core.php?action=do-translation-upgrade';
32 $nonce = 'upgrade-translations';
33 $title = '';
34 $context = WP_LANG_DIR;
35
36 $upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
37
38 $upgr_object = [];
39 $upgr_object[0] = new stdClass();
40 $upgr_object[0]->type = 'plugin';
41 $upgr_object[0]->slug = 'woocommerce';
42 $upgr_object[0]->language = $locale;
43 $upgr_object[0]->version = $wc_version;
44 $upgr_object[0]->updated = date( 'Y-m-d H:i:s' );
45 $upgr_object[0]->package = $this->get_language_pack_uri( $locale, $wc_version );
46 $upgr_object[0]->autoupdate = 1;
47
48 $ob_level_before = ob_get_level();
49
50 $upgrader->bulk_upgrade( $upgr_object );
51
52 $ob_level_after = ob_get_level();
53 if ( $ob_level_after > $ob_level_before ) {
54 ob_end_clean();
55 }
56
57 $this->save_translation_version( $locale, false, $wc_version );
58 }
59
60 }
61
62
63 public function download_woocommerce_translations_for_active_languages( $wc_version = false ) {
64 global $sitepress, $woocommerce_wpml;
65
66 $active_languages = $sitepress->get_active_languages();
67
68 $current_language = $sitepress->get_current_language();
69
70 foreach ( $active_languages as $language ) {
71
72 $this->download_woocommerce_translations( $language['code'], $wc_version );
73
74 }
75
76 $sitepress->switch_lang( $current_language );
77
78 if ( isset( $woocommerce_wpml->url_translation ) ) {
79 $woocommerce_wpml->url_translation->register_product_and_taxonomy_bases();
80 }
81
82 }
83
84 public function get_language_pack_uri( $locale, $version = false ) {
85
86 if ( ! $version ) {
87 $version = WC_VERSION;
88 }
89
90 $repo = 'https://downloads.wordpress.org/translation/plugin/woocommerce/';
91 return $repo . $version . '/' . $locale . '.zip';
92 }
93
94 public function version_update( $reply, $package ) {
95
96 $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice' ) );
97
98 if ( ! is_array( $notices ) ) {
99 return $reply;
100 }
101
102 foreach ( $notices as $key => $locale ) {
103 if ( strstr( $package, 'woocommerce' ) && strstr( $package, $locale ) ) {
104
105 $this->save_translation_version( $locale, $key );
106
107 }
108 }
109
110 return $reply;
111 }
112
113
114 public function save_translation_version( $locale, $key = false, $wc_version = false ) {
115
116 $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice' ) );
117
118 update_option( 'woocommerce_language_pack_version_' . $locale, [ $wc_version ?: WC_VERSION, $locale ] );
119
120 if ( is_array( $notices ) ) {
121
122 if ( ! $key ) {
123 $key = array_search( $locale, $notices );
124 }
125
126 unset( $notices[ $key ] );
127
128 update_option( 'wcml_translations_upgrade_notice', $notices );
129
130 }
131
132 }
133
134 public function has_available_update( $locale, $wc_version = false ) {
135 $wc_version = $wc_version ?: WC_VERSION;
136
137 $version = get_option( 'woocommerce_language_pack_version_' . $locale, [ '0', $locale ] );
138
139 $is_new_version = ! is_array( $version ) || version_compare( $version[0], $wc_version, '<' ) || $version[1] !== $locale;
140 $mo_file_absent = ! file_exists( sprintf( WP_LANG_DIR . '/plugins/woocommerce-%s.mo', $locale ) );
141
142 $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice', [] ) );
143
144 if ( 'en_US' !== $locale && ( $is_new_version || $mo_file_absent ) ) {
145 if ( $this->check_if_language_pack_exists( $locale, $wc_version ) ) {
146
147 if ( ! $notices || ! in_array( $locale, $notices ) ) {
148 $notices[] = $locale;
149
150 update_option( 'wcml_translations_upgrade_notice', $notices );
151 update_option( 'hide_wcml_translations_message', 0 );
152 }
153
154 return true;
155 } else {
156 update_option( 'woocommerce_language_pack_version_' . $locale, [ $wc_version, $locale ] );
157 }
158 }
159
160 return false;
161 }
162
163
164 public function check_if_language_pack_exists( $locale, $wc_version ) {
165
166 $response = wp_safe_remote_get( $this->get_language_pack_uri( $locale, $wc_version ), [ 'timeout' => 60 ] );
167
168 if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && $response['body'] !== '404 File not found' ) {
169 return true;
170 } else {
171 return false;
172 }
173 }
174
175
176 public function translation_upgrade_notice() {
177 $screen = get_current_screen();
178 $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice' ) );
179
180 if ( 'update-core' !== $screen->id && ! empty( $notices ) && ! get_option( 'hide_wcml_translations_message' ) ) {
181
182 $lang_notices = new WCML_Languages_Upgrade_Notice( $notices );
183 $lang_notices->show();
184 }
185 }
186
187 public function hide_wcml_translations_message() {
188 $nonce = filter_input( INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
189 if ( ! $nonce || ! wp_verify_nonce( $nonce, 'hide_wcml_translations_message' ) ) {
190 die( 'Invalid nonce' );
191 }
192 update_option( 'hide_wcml_translations_message', true );
193
194 die();
195 }
196
197 public function load_js() {
198
199 wp_register_script( 'wcml-lang-notice', WCML_PLUGIN_URL . '/res/js/languages_notice' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true );
200 wp_enqueue_script( 'wcml-lang-notice' );
201
202 wp_localize_script(
203 'wcml-lang-notice',
204 'wcml_language_upgrade_notices',
205 [
206 'dont_close' => esc_html__( "Downloading translations... Please don't close this page.", 'woocommerce-multilingual' ),
207 ]
208 );
209
210 }
211
212 }
213