PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
← All changes | core/wpbc-translation.php +157 -134 10.1.311.8.4 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -38,12 +38,12 @@
38 38
39 39 // Get reloaded 'booking' or current WordPress locale
40 40 $locale = wpbc_get_maybe_reloaded_booking_locale(); // if NOT defined WPBC_LOCALE_RELOAD define by current WordPress locale
41 41
42 - //FixIn: 8.9.4.5
42 + // FixIn: 8.9.4.5.
43 43 if ( is_admin() && ( defined( 'DOING_AJAX' ) ) && ( DOING_AJAX ) ) {
44 44 //Reload locale for Ajax request
45 - wpbc_check_ajax_locale__reload_it( $locale ); // Contain --> if ( ! defined( 'WPBC_LOCALE_RELOAD' ) ) define( 'WPBC_LOCALE_RELOAD', esc_js( $_REQUEST['wpdev_active_locale'] ) );
45 + wpbc_check_ajax_locale__reload_it( $locale ); //
46 46 }
47 47
48 48 wpbc_load_country_list_file_php( $locale );
49 49
@@ -55,13 +55,12 @@
55 55
56 56 /**
57 57 * Check ( $_REQUEST['wpdev_active_locale'] ) and Reload specific Locale for the Ajax request
58 58 */
59 -function wpbc_check_ajax_locale__reload_it( $reloaded_locale ) { //FixIn: 8.4.5.1
59 +function wpbc_check_ajax_locale__reload_it( $reloaded_locale ) { // FixIn: 8.4.5.1.
60 60
61 - if ( ( isset( $_REQUEST['wpdev_active_locale'] ) ) || // Reload locale according request parameter
62 - ( isset( $_REQUEST['wpbc_ajx_locale'] ) )
63 - ) { // Reload locale according request parameter
61 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
62 + if ( ( isset( $_REQUEST['wpdev_active_locale'] ) ) || ( isset( $_REQUEST['wpbc_ajx_locale'] ) ) ) { // Reload locale according request parameter.
64 63
65 64 unload_textdomain( 'booking' );
66 65
67 66 /*
@@ -66,10 +65,10 @@
66 65
67 66 /*
68 67 * Removed because, it's configured in $locale = wpbc_get_maybe_reloaded_booking_locale(); which is executed before this action
69 68 *
70 - if ( ! defined( 'WPBC_LOCALE_RELOAD' ) ) {
71 - define( 'WPBC_LOCALE_RELOAD', esc_js( $_REQUEST['wpdev_active_locale'] ) );
69 + if ( ! defined( 'WPBC_LOCALE_RELOAD' ) ) { // $
70 + define( 'WPBC_LOCALE_RELOAD', ( $_REQUEST['wpdev_active_locale'] ) );
72 71 }
73 72 */
74 73 add_filter( 'locale', 'wpbc_get_maybe_reloaded_booking_locale', 999 ); // Set filter to load the locale of the Booking Calendar
75 74
@@ -137,9 +136,9 @@
137 136 // we have long locale like en_US, get only 2 first letters, for general locale, like 'en'
138 137 $mofile_local_short = WPBC_PLUGIN_DIR . '/languages/' . $domain . '-' . substr( $locale, 0 , 2 ) . '.mo';
139 138
140 139 // Load from General folder /wp-content/languages/plugins/plugin-name-xx_XX.mo
141 - $mofile_in_wp_folder = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo'; //FixIn: 8.9.4.6 Fix '/languages/plugin/' to '/languages/plugins/ //FixIn: 8.7.7.1
140 + $mofile_in_wp_folder = WP_LANG_DIR . '/plugins/' . $domain . '-' . $locale . '.mo'; //FixIn: 8.9.4.6 Fix '/languages/plugin/' to '/languages/plugins/ // FixIn: 8.7.7.1.
142 141
143 142
144 143 /**
145 144 * Try to load from the languages' directory first -> WP_LANG_DIR . '/plugins/' . $mofile
@@ -161,8 +160,9 @@
161 160 * load_textdomain( $domain, WPBC_PLUGIN_DIR . '/languages/' . $domain . '-' . $locale . '.mo' );
162 161 */
163 162
164 163 $plugin_rel_path = WPBC_PLUGIN_DIRNAME . '/languages';
164 + // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound
165 165 $is_mo_loaded = load_plugin_textdomain( $domain, false, $plugin_rel_path );
166 166 }
167 167
168 168
@@ -173,11 +173,11 @@
173 173 /**
174 174 * Direct load from ../wp-content/plugins/booking/languages/booking-fr_FR.mo
175 175 */
176 176
177 - $is_mo_loaded = load_textdomain( $domain, $mofile_in_plugin_folder ); //FixIn: 8.9.4.5
177 + $is_mo_loaded = load_textdomain( $domain, $mofile_in_plugin_folder ); // FixIn: 8.9.4.5.
178 178
179 - } elseif ( ( ! empty( $mofile_local_short ) ) && ( file_exists( $mofile_local_short ) ) ) { //FixIn: 8.1.3.13
179 + } elseif ( ( ! empty( $mofile_local_short ) ) && ( file_exists( $mofile_local_short ) ) ) { // FixIn: 8.1.3.13.
180 180
181 181 /**
182 182 * Direct load of short " booking-en.mo " MO file
183 183 */
@@ -183,9 +183,9 @@
183 183 */
184 184
185 185 $is_mo_loaded = load_textdomain( $domain, $mofile_local_short );
186 186
187 - } elseif ( file_exists( $mofile_in_wp_folder ) ) { //FixIn: 8.9.4.6
187 + } elseif ( file_exists( $mofile_in_wp_folder ) ) { // FixIn: 8.9.4.6.
188 188
189 189 /**
190 190 * Here possible to use
191 191 * return load_plugin_textdomain( $domain, false, $plugin_rel_path );
@@ -198,9 +198,9 @@
198 198 * so that's why we are using direct loadinf: load_textdomain( $domain, $mofile_in_wp_folder ) ../wp-content/languages/plugin/booking-fr_FR.mo
199 199 */
200 200
201 201 $is_mo_loaded = load_textdomain( $domain, $mofile_in_wp_folder );
202 - } else { //FixIn: 7.2.1.21
202 + } else { // FixIn: 7.2.1.21.
203 203
204 204 $is_unloaded = unload_textdomain( $domain );
205 205 }
206 206 }
@@ -214,25 +214,44 @@
214 214 * Load Country List file depends on plugin 'booking' locale
215 215 *
216 216 * @string $locale '' || 'en_US' || 'it_IT'
217 217 */
218 -function wpbc_load_country_list_file_php( $locale ){ //FixIn: 8.8.2.5
218 +function wpbc_load_country_list_file_php( $locale ){ // FixIn: 8.8.2.5.
219 219
220 - if ( ! empty( $locale ) ) {
221 - $locale_lang = strtolower( substr( $locale, 0, 2 ) );
222 - $locale_country = strtolower( substr( $locale, 3 ) );
220 + require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list.php';
223 221
224 - //FixIn: 8.9.4.12
225 - if ( ( $locale_lang !== 'en' ) && ( wpbc_is_file_exist( '/core/lang/wpdev-country-list-' . $locale . '.php' ) ) ) {
226 - require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list-' . $locale . '.php';
227 - } else {
228 - require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list.php';
229 - }
230 - } else {
231 - require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list.php';
222 + do_action( 'wpbc_country_list_loaded' ); // FixIn: 8.9.4.9.
223 +}
224 +
225 +
226 +/**
227 + * Validate a locale received from a request.
228 + *
229 + * Locale values are used request-wide and can later be rendered inside JavaScript and HTML attributes. Accept only
230 + * ASCII locale identifiers, such as "en", "en_US", "de_DE_formal", or "en-US". Invalid values must be rejected
231 + * instead of sanitized into a different value. // FixIn: 11.4.3.2.
232 + *
233 + * @param mixed $locale Locale value from the request.
234 + *
235 + * @return string|false Valid locale, or false when the value is invalid.
236 + */
237 +function wpbc_validate_request_locale( $locale ) {
238 +
239 + if ( ! is_string( $locale ) ) {
240 + return false;
232 241 }
233 242
234 - do_action( 'wpbc_country_list_loaded' ); //FixIn: 8.9.4.9
243 + $locale = wp_unslash( $locale );
244 +
245 + if (
246 + ( '' === $locale )
247 + || ( strlen( $locale ) > 32 )
248 + || ( 1 !== preg_match( '/\A[A-Za-z0-9]+(?:[_-][A-Za-z0-9]+)*\z/D', $locale ) )
249 + ) {
250 + return false;
251 + }
252 +
253 + return $locale;
235 254 }
236 255
237 256
238 257 /**
@@ -251,19 +270,19 @@
251 270
252 271 /**
253 272 * Check active locale in some other translation plugins, like Polylang (NOT in Ajax), etc...
254 273 */
255 - if ( ! $is_ajax ) { //FixIn: 8.9.4.7
274 + if ( ! $is_ajax ) { // FixIn: 8.9.4.7.
256 275
257 276 // Exception for Polylang plugin. It will force loading locale of Polylang plugin.
258 - if ( function_exists( 'pll_current_language' ) ) { //FixIn: 8.1.2.5
259 - if ( defined( 'POLYLANG_VERSION' ) ) { //FixIn: 8.8.3.16
277 + if ( function_exists( 'pll_current_language' ) ) { // FixIn: 8.1.2.5.
278 + if ( defined( 'POLYLANG_VERSION' ) ) { // FixIn: 8.8.3.16.
260 279 if (
261 - ( version_compare( POLYLANG_VERSION, '2.6.5', '<' ) ) //FixIn: 8.7.1.3
262 - || ( version_compare( POLYLANG_VERSION, '2.7.1', '>' ) ) //FixIn: 8.7.7.11
280 + ( version_compare( POLYLANG_VERSION, '2.6.5', '<' ) ) // FixIn: 8.7.1.3.
281 + || ( version_compare( POLYLANG_VERSION, '2.7.1', '>' ) ) // FixIn: 8.7.7.11.
263 282 ) {
264 283 $locale = pll_current_language( 'locale' );
265 - if ( ! empty( $locale ) ) { //FixIn: 8.7.7.11
284 + if ( ! empty( $locale ) ) { // FixIn: 8.7.7.11.
266 285 return $locale;
267 286 }
268 287 }
269 288 }
@@ -270,13 +289,17 @@
270 289 }
271 290 }
272 291
273 292 $wpbc_ajx_locale = false;
293 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
274 294 if ( isset( $_REQUEST['wpdev_active_locale'] ) ) {
275 - $wpbc_ajx_locale = esc_js( $_REQUEST['wpdev_active_locale'] );
295 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
296 + $wpbc_ajx_locale = wpbc_validate_request_locale( $_REQUEST['wpdev_active_locale'] );
276 297 }
298 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
277 299 if ( isset( $_REQUEST['wpbc_ajx_locale'] ) ) {
278 - $wpbc_ajx_locale = esc_js( $_REQUEST['wpbc_ajx_locale'] );
300 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
301 + $wpbc_ajx_locale = wpbc_validate_request_locale( $_REQUEST['wpbc_ajx_locale'] );
279 302 }
280 303
281 304 // Reload locale ONLY in AJAX, and if `isset $_REQUEST['wpdev_active_locale']
282 305 if (
@@ -285,10 +308,10 @@
285 308 ){
286 309 if (
287 310 ( $is_ajax )
288 311 || (
289 - ( isset( $_REQUEST['wpbc_ajx_locale_reload'] ) )
290 - && ( 'force' == $_REQUEST['wpbc_ajx_locale_reload'] )
312 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
313 + ( isset( $_REQUEST['wpbc_ajx_locale_reload'] ) ) && ( 'force' == $_REQUEST['wpbc_ajx_locale_reload'] )
291 314 )
292 315 ) { // Reload locale according request parameter
293 316 define( 'WPBC_LOCALE_RELOAD', $wpbc_ajx_locale );
294 317 }
@@ -296,9 +319,9 @@
296 319
297 320
298 321
299 322 // If not defined than get current WordPress locale and define
300 - if ( ! defined( 'WPBC_LOCALE_RELOAD' ) ) { //FixIn: 7.2.1.21
323 + if ( ! defined( 'WPBC_LOCALE_RELOAD' ) ) { // FixIn: 7.2.1.21.
301 324
302 325 $locale = wpbc_get_current_wordpress_locale(); // 'en_US' or 'it_IT', etc...
303 326
304 327 define( 'WPBC_LOCALE_RELOAD', $locale );
@@ -318,9 +341,9 @@
318 341 * @return string 'en_US'
319 342 */
320 343 function wpbc_get_current_wordpress_locale(){
321 344
322 - if ( function_exists( 'determine_locale' ) ) { //FixIn: 8.7.5.1 //FixIn: 8.7.3.15
345 + if ( function_exists( 'determine_locale' ) ) { //FixIn: 8.7.5.1 // FixIn: 8.7.3.15.
323 346 $current_locale = determine_locale();
324 347 } else {
325 348 if ( function_exists( 'get_user_locale' ) ) {
326 349 $current_locale = is_admin() ? get_user_locale() : get_locale();
@@ -344,9 +367,9 @@
344 367 * @param string $plugin_domain 'booking' - it's Booking Calendar plugin locale
345 368 *
346 369 * @return mixed|string 'it_IT'
347 370 */
348 -function wpbc_filter_recheck_plugin_locale( $locale, $plugin_domain = '' ) { //FixIn: 8.4.4.2
371 +function wpbc_filter_recheck_plugin_locale( $locale, $plugin_domain = '' ) { // FixIn: 8.4.4.2.
349 372
350 373 if (
351 374 ( 'booking' == $plugin_domain )
352 375 && ( defined( 'WPBC_LOCALE_RELOAD' ) )
@@ -384,13 +407,13 @@
384 407 /// Support functions for [lang=xx_XX] shortcode
385 408 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
386 409
387 410 /**
388 - * Translate content. Check for language sections -- [lang=xx_XX] shortcode. //FixIn: 10.0.0.46
411 + * Translate content. Check for language sections -- [lang=xx_XX] shortcode. // FixIn: 10.0.0.46.
389 412 *
390 - * @param $content_orig
391 - *
392 - * @return string
413 + * @param mixed $content_orig Content containing optional language sections.
414 + *
415 + * @return string Translated content, or an empty string for unsupported values.
393 416 */
394 417 function wpbc_lang( $content_orig ) {
395 418 return wpdev_check_for_active_language( $content_orig );
396 419 }
@@ -398,24 +421,32 @@
398 421
399 422 /**
400 423 * Check plugin text for active language section -- [lang=xx_XX] shortcode
401 424 *
402 - * @param string $content_orig
403 - * @return string
425 + * @param mixed $content_orig Content containing optional language sections.
426 + * @return string Translated content, or an empty string for unsupported values.
404 427 * Usage:
405 428 * $text = wpbc_lang( $text );
406 429 */
407 -function wpdev_check_for_active_language( $content_orig ) {
430 +function wpdev_check_for_active_language( $content_orig ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound
431 +
432 + if ( is_string( $content_orig ) ) {
433 + $content = $content_orig;
434 + } elseif ( is_scalar( $content_orig ) ) {
435 + $content = (string) $content_orig;
436 + } elseif ( is_object( $content_orig ) && method_exists( $content_orig, '__toString' ) ) {
437 + $content = (string) $content_orig;
438 + } else {
439 + return '';
440 + }
441 +
442 + $languages = array();
443 + $content_ex = explode( '[lang', $content );
444 +
445 + foreach ( $content_ex as $value ) {
446 +
447 + if ( '=' === substr( $value, 0, 1 ) ) {
408 448
409 - $content = $content_orig;
410 -
411 - $languages = array();
412 - $content_ex = explode('[lang',$content);
413 -
414 - foreach ( $content_ex as $value ) {
415 -
416 - if ( '=' == substr( $value, 0, 1 ) ) {
417 -
418 449 $pos_s = strpos( $value, '=' );
419 450 $pos_f = strpos( $value, ']' );
420 451 $key = trim( substr( $value, ( $pos_s + 1 ), ( $pos_f - $pos_s - 1 ) ) );
421 452 $value_l = trim( substr( $value, $pos_f + 1 ) );
@@ -425,9 +456,9 @@
425 456 $languages['default'] = $value;
426 457 }
427 458 }
428 459
429 - $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR';
460 + $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR'.
430 461
431 462 if ( isset( $languages[ $locale ] ) ) {
432 463 $return_text = $languages[ $locale ];
433 464 } else {
@@ -434,9 +465,9 @@
434 465 $return_text = $languages['default'];
435 466 }
436 467
437 468 $return_text = wpbc_bk_check_qtranslate( $return_text, $locale );
438 - $return_text = wpbc_check_wpml_tags( $return_text, $locale ); //FixIn: 5.4.5.8
469 + $return_text = wpbc_check_wpml_tags( $return_text, $locale ); // FixIn: 5.4.5.8.
439 470
440 471 return $return_text;
441 472 }
442 473
@@ -448,12 +479,15 @@
448 479 */
449 480 function wpbc_get_help_rows_about_config_in_several_languges() {
450 481
451 482 $field_options = array();
452 - $field_options[] = '<strong>' . __('Configuration in several languages' ,'booking') . '</strong>';
453 - $field_options[] = sprintf(__('%s - start new translation section, where %s - locale of translation' ,'booking'),'<code>[lang=LOCALE]</code>','<code>LOCALE</code>');
454 - $field_options[] = sprintf(__('Example #1: %s - start French translation section' ,'booking'),'<code>[lang=fr_FR]</code>');
455 - $field_options[] = sprintf(__('Example #2: "%s" - English and French translation of some message' ,'booking'),'<code>Thank you for your booking.[lang=fr_FR]Je vous remercie de votre reservation.</code>');
483 + $field_options[] = '<strong>' . esc_html__('Configuration in several languages' ,'booking') . '</strong>';
484 + /* translators: 1: ... */
485 + $field_options[] = sprintf( __( '%1$s - start new translation section, where %2$s - locale of translation', 'booking' ),'<code>[lang=LOCALE]</code>','<code>LOCALE</code>');
486 + /* translators: 1: ... */
487 + $field_options[] = sprintf(__( 'Example #1: %s - start French translation section' ,'booking'),'<code>[lang=fr_FR]</code>');
488 + /* translators: 1: ... */
489 + $field_options[] = sprintf(__( 'Example #2: "%s" - English and French translation of some message' ,'booking'),'<code>Thank you for your booking.[lang=fr_FR]Je vous remercie de votre reservation.</code>');
456 490
457 491 return $field_options;
458 492 }
459 493
@@ -470,9 +504,9 @@
470 504 * @param string $locale
471 505 *
472 506 * @return string
473 507 */
474 -function wpbc_check_wpml_tags( $text, $locale='' ) { //FixIn: 5.4.5.8
508 +function wpbc_check_wpml_tags( $text, $locale='' ) { // FixIn: 5.4.5.8.
475 509
476 510 if ( $locale == '' ) {
477 511 $locale = wpbc_get_maybe_reloaded_booking_locale();
478 512 }
@@ -512,8 +546,9 @@
512 546 } else { // WPML Version: 3.2
513 547
514 548 // Help info: do_action( 'wpml_register_single_string', string $context, string $name, string $value )
515 549 // https://wpml.org/wpml-hook/wpml_register_string_for_translation/
550 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
516 551 do_action( 'wpml_register_single_string', 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ) , $translation_to_check );
517 552
518 553
519 554 // Help info: apply_filters( 'wpml_translate_single_string', string $original_value, string $context, string $name, string $$language_code )
@@ -519,8 +554,9 @@
519 554 // Help info: apply_filters( 'wpml_translate_single_string', string $original_value, string $context, string $name, string $$language_code )
520 555 // https://wpml.org/wpml-hook/wpml_translate_single_string/
521 556 //$translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ) );
522 557 $language_code = $locale;
558 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
523 559 $translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ), $language_code );
524 560
525 561 }
526 562 }
@@ -577,28 +613,23 @@
577 613
578 614 echo
579 615 '<a class="button button tooltip_top"
580 616 data-original-title="'
617 + /* translators: 1: ... */
581 618 . esc_attr( sprintf( __( 'Download translation PO files from %s and update the current translation version.', 'booking' ), 'wp.org / wpbookingcalendar.com' ) )
582 619 . '" href="'
583 - . wpbc_get_settings_url()
584 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&update_translations=1#wpbc_general_settings_system_info_metabox">'
585 - . __( 'Update Translations' )
620 + . esc_url( wpbc_get_settings_url()
621 + . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) ) .'&update_translations=1#wpbc_general_settings_system_info_metabox">'
622 + . esc_html__( 'Update Translations', 'booking' )
586 623 . '</a>';
587 624
588 - echo
589 - '<a class="button button tooltip_top"
590 - data-original-title="'
591 - . esc_attr( __( 'Show exist translations status', 'booking' ) )
592 - . '"
593 - href="'
594 - . wpbc_get_settings_url()
595 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&show_translation_status=1#wpbc_general_settings_system_info_metabox">'
596 - . __( 'Show translations status', 'booking' )
597 - . '</a>';
625 + echo '<a class="button button tooltip_top"
626 + data-original-title="' . esc_attr( __( 'Show exist translations status', 'booking' ) ) . '"
627 + href="' . esc_url( wpbc_get_settings_url() . '&system_info=show&_wpnonce=' . wp_create_nonce( 'wpbc_settings_url_nonce' ) ) . '&show_translation_status=1#wpbc_general_settings_system_info_metabox">' .
628 + esc_html( __( 'Show translations status', 'booking' ) ) . '</a>';
598 629
599 630
600 - if ( $_SERVER['HTTP_HOST'] === 'beta' ) {
631 + if ( ( isset( $_SERVER['HTTP_HOST'] ) ) && ( 'beta' === $_SERVER['HTTP_HOST'] ) ) {
601 632
602 633 ?><div style="width:100%;height:2em;border-bottom:1px dashed #777;margin-bottom:1em;"></div><?php
603 634
604 635 // Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&pot=1#wpbc_general_settings_system_info_metabox
@@ -605,10 +636,10 @@
605 636 echo
606 637 '<a class="button button-secondary tooltip_top"
607 638 data-original-title="Delete wpbc_all_translations(*).php files, before Updating POT file (manually)"
608 639 style="background:#fff9e6;" href="'
609 - . wpbc_get_settings_url()
610 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&pot=erase__wpbc_all_translations#wpbc_general_settings_system_info_metabox">'
640 + . esc_url( wpbc_get_settings_url()
641 + . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) ) .'&pot=erase__wpbc_all_translations#wpbc_general_settings_system_info_metabox">'
611 642 . '1. Erase Translation PHP files'
612 643 . '</a>';
613 644 echo
614 645 '<a class="button button-secondary tooltip_top"
@@ -614,20 +645,20 @@
614 645 '<a class="button button-secondary tooltip_top"
615 646 data-original-title="Create or update wpbc_all_translations(*).php files, from actual POT file"
616 647 style="background:#fff9e6;"
617 648 href="'
618 - . wpbc_get_settings_url()
619 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&pot=1#wpbc_general_settings_system_info_metabox">'
649 + . esc_url( wpbc_get_settings_url()
650 + . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) ) .'&pot=1#wpbc_general_settings_system_info_metabox">'
620 651 . '2. Generate Translation PHP from POT file'
621 652 . '</a>';
622 653
623 654 echo
624 655 '<a class="button button-secondary tooltip_top"
625 - data-original-title="Just show WP.ORG translation status from ' . WP_LANG_DIR . '/plugins/' . ' "
656 + data-original-title="Just show WP.ORG translation status from ' . esc_attr( WP_LANG_DIR ) . '/plugins/' . ' "
626 657 style="background:#fff9e6;"
627 658 href="'
628 - . wpbc_get_settings_url()
629 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&show_translation_status=2#wpbc_general_settings_system_info_metabox">'
659 + . esc_url( wpbc_get_settings_url()
660 + . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) ) .'&show_translation_status=2#wpbc_general_settings_system_info_metabox">'
630 661 . 'Translation status WP.ORG'
631 662 . '</a>';
632 663
633 664
@@ -632,13 +663,13 @@
632 663
633 664
634 665 echo
635 666 '<a class="button button-secondary tooltip_top"
636 - data-original-title="Just show LOCAL translation status from ' . WPBC_PLUGIN_DIR . '/languages/' . ' "
667 + data-original-title="Just show LOCAL translation status from ' . esc_attr( WPBC_PLUGIN_DIR ) . '/languages/' . ' "
637 668 style="background:#fff9e6;"
638 669 href="'
639 - . wpbc_get_settings_url()
640 - . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) .'&show_translation_status=3#wpbc_general_settings_system_info_metabox">'
670 + . esc_url( wpbc_get_settings_url()
671 + . '&system_info=show&_wpnonce='. wp_create_nonce( 'wpbc_settings_url_nonce' ) ) .'&show_translation_status=3#wpbc_general_settings_system_info_metabox">'
641 672 . 'Translation status WPBC'
642 673 . '</a>';
643 674 }
644 675
@@ -647,57 +678,49 @@
647 678 }
648 679 }
649 680
650 681
682 +// ======================================================================================================================
683 +// Update Translations -- DOWNLOAD from WP.ORG and WPBC
684 +// ======================================================================================================================
651 685
652 686
653 -//======================================================================================================================
654 -// Update Translations -- DOWNLOAD from WP.ORG and WPBC
655 -//======================================================================================================================
656 -
657 -
658 -
659 -
660 687 /**
661 688 * Update transaltions of plugin from WP repository
662 689 */
663 -function wpbc_update_translations__from_wp(){
690 +function wpbc_update_translations__from_wp() {
664 691
665 - echo '<h2>' . __('Start updating translation files', 'booking') . '</h2>';
692 + echo '<h2>' . esc_html__( 'Start updating translation files', 'booking' ) . '</h2>';
693 + WPBC_Action_Scheduler_Compatibility::raise_memory_limit();
694 + WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 );
666 695
667 - if ( function_exists( 'set_time_limit' ) ) { set_time_limit( 900 ); }
668 - @ini_set('memory_limit','256M');
669 - @ini_set('max_execution_time', 300);
670 -
671 696 $wpbc_download_result = false;
672 697 if ( 'translations_updated_from_wpbc' !== get_bk_option( 'booking_translation_update_status' ) ) {
673 -
674 698 $wpbc_download_result = wpbc_translation_download_from_wpbc();
675 -
676 699 }
677 700 if ( ( ! is_wp_error( $wpbc_download_result ) ) && ( false !== $wpbc_download_result ) ) {
678 701 update_bk_option( 'booking_translation_update_status', 'translations_updated_from_wpbc' );
679 702 }
680 703
704 + $wp_org_translation_packages_arr = wpbc_get_translation_packages_arr_from_wp();
705 + /**
706 + * ..., array ( [language] => sk_SK
707 + * [version] => 8.9.3
708 + * [updated] => 2020-03-11 17:10:35
709 + * [english_name] => Slovak
710 + * [native_name] => Slovenčina
711 + * [package] => https://downloads.wordpress.org/translation/plugin/booking/8.9.3/sk_SK.zip
712 + * [iso] => Array ( [1] => sk, [2] => slk )
713 + * ),
714 + * ...
715 + */
681 716
682 - $wp_org_translation_packages_arr = wpbc_get_translation_packages_arr_from_wp(); /**
683 - * ..., array ( [language] => sk_SK
684 - [version] => 8.9.3
685 - [updated] => 2020-03-11 17:10:35
686 - [english_name] => Slovak
687 - [native_name] => Slovenčina
688 - [package] => https://downloads.wordpress.org/translation/plugin/booking/8.9.3/sk_SK.zip
689 - [iso] => Array ( [1] => sk, [2] => slk )
690 - ),
691 - * ...
692 - */
693 -
694 717 $download_result_arr = wpbc_transaltion_download_from_wp_org( $wp_org_translation_packages_arr );
695 718
696 - echo '<h2>' . __('End updating translation files', 'booking') . '</h2>';
697 - echo '<a class="button button-secondary" style="margin:10px 0;" href="' . wpbc_get_settings_url() . '" >' . __( 'Go to Settings', 'booking' ) . '</a>';
719 + echo '<h2>' . esc_html__( 'End updating translation files', 'booking' ) . '</h2>';
720 + echo '<a class="button button-secondary" style="margin:10px 0;" href="' . esc_url( wpbc_get_settings_url() ) . '" >' . esc_html__( 'Go to Settings', 'booking' ) . '</a>';
698 721
699 - update_bk_option( 'booking_translation_update_status' , 'translations_updated_from_wpbc_and_wp');
722 + update_bk_option( 'booking_translation_update_status', 'translations_updated_from_wpbc_and_wp' );
700 723 }
701 724
702 725
703 726 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -815,9 +838,9 @@
815 838 if ( ! is_admin() ) {
816 839 return $translations_arr;
817 840 }
818 841
819 - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
842 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
820 843
821 844 $api = translations_api( 'plugins', array(
822 845 'slug' => 'booking',
823 846 'version' => WP_BK_VERSION_NUM, //'8.9.3',
@@ -840,11 +863,10 @@
840 863
841 864
842 865 function wpbc_show_translation_status_compare_wpbc_wp( ) {
843 866
844 - if ( function_exists( 'set_time_limit' ) ) { set_time_limit( 900 ); }
845 - @ini_set('memory_limit','256M');
846 - @ini_set('max_execution_time', 300);
867 + WPBC_Action_Scheduler_Compatibility::raise_memory_limit();
868 + WPBC_Action_Scheduler_Compatibility::raise_time_limit( 300 );
847 869
848 870 $params = array(
849 871 'sort_field_name' => 'locale'
850 872 , 'sort_order' => SORT_ASC
@@ -987,9 +1009,9 @@
987 1009 //////////////////////////////////////////////////////////////////////////////////
988 1010
989 1011 wpbc_show_message_in_settings( $translation_message, 'info' );
990 1012
991 - echo '<a class="button button-secondary" style="margin:10px 0;" href="' . wpbc_get_settings_url() . '" >' . __( 'Go to Settings', 'booking' ) . '</a>';
1013 + echo '<a class="button button-secondary" style="margin:10px 0;" href="' . esc_url( wpbc_get_settings_url() ) . '" >' . esc_html__( 'Go to Settings', 'booking' ) . '</a>';
992 1014 }
993 1015
994 1016 /**
995 1017 * Get or Show translation statuses from "WP_LANG_DIR" folder at Booking > Settings General page
@@ -1096,9 +1118,9 @@
1096 1118 }
1097 1119
1098 1120 wpbc_show_message_in_settings( $translation_message, 'info' );
1099 1121
1100 - echo '<a class="button button-secondary" style="margin:10px 0;" href="' . wpbc_get_settings_url() . '" >' . __( 'Go to Settings', 'booking' ) . '</a>';
1122 + echo '<a class="button button-secondary" style="margin:10px 0;" href="' . esc_url( wpbc_get_settings_url() ) . '" >' . esc_html__( 'Go to Settings', 'booking' ) . '</a>';
1101 1123 }
1102 1124
1103 1125 return $translation_status_arr;
1104 1126 }
@@ -1191,9 +1213,9 @@
1191 1213 //////////////////////////////////////////////////////////////////////////////////
1192 1214
1193 1215 wpbc_show_message_in_settings( $translation_message, 'info' );
1194 1216
1195 - echo '<a class="button button-secondary" style="margin:10px 0;" href="' . wpbc_get_settings_url() . '" >' . __( 'Go to Settings', 'booking' ) . '</a>';
1217 + echo '<a class="button button-secondary" style="margin:10px 0;" href="' . esc_url( wpbc_get_settings_url() ) . '" >' . esc_html__( 'Go to Settings', 'booking' ) . '</a>';
1196 1218 }
1197 1219
1198 1220 return $translation_status_arr;
1199 1221 }
@@ -1216,9 +1238,9 @@
1216 1238 */
1217 1239 function wpbc_get_available_language_locales_from_wp_org_api(){
1218 1240
1219 1241 // Get Language names for all Locales
1220 - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
1242 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
1221 1243 /**
1222 1244 * Array( ["nl_NL"] => array ( language = "nl_NL"
1223 1245 version = "5.9"
1224 1246 updated = "2022-02-10 16:24:09"
@@ -1461,9 +1483,9 @@
1461 1483 $po->import_from_file( $pot_file );
1462 1484
1463 1485 wpbc_show_message_in_settings( 'Found <strong>' . count($po->entries) . '</strong> translations' , 'info' );
1464 1486
1465 - //FixIn: 8.7.3.6
1487 + // FixIn: 8.7.3.6.
1466 1488 $translation_files = array();
1467 1489
1468 1490
1469 1491 // Generate content of the file
@@ -1473,9 +1495,9 @@
1473 1495 $all_translations = '';
1474 1496 foreach ( $po->entries as $transaltion => $transaltion_obj ) {
1475 1497
1476 1498 $transaltion = str_replace( "'", "\'", $transaltion );
1477 - $all_translations .= ' $wpbc_all_translations[] = __(\''. $transaltion .'\', \'booking\'); ' . "\n";
1499 + $all_translations .= ' $wpbc_all_translations[] = __(\''. $transaltion .'\', \'booking\'); /* translators: 1: ... */ ' . "\n";
1478 1500 $lines_number++;
1479 1501
1480 1502 // Maximum number of lines in such files
1481 1503 if ( $lines_number >= 998 ) {
@@ -1497,10 +1519,10 @@
1497 1519
1498 1520 foreach ( $translation_files as $file_number => $file_content ) {
1499 1521
1500 1522 // Path to new PHP file with all
1501 - $new_php_file = WP_PLUGIN_DIR . '/' . trim( WPBC_PLUGIN_DIRNAME . '/core/lang/wpbc_all_translations' . ( ( ! empty( $file_number ) ) ? $file_number : '' ) . '.php', '/' ); //FixIn: 8.9.4.12
1502 -
1523 + $new_php_file = WP_PLUGIN_DIR . '/' . trim( WPBC_PLUGIN_DIRNAME . '/core/lang/wpbc_all_translations' . ( ( ! empty( $file_number ) ) ? $file_number : '' ) . '.php', '/' ); // FixIn: 8.9.4.12.
1524 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen
1503 1525 $fh = fopen( $new_php_file, 'w' );
1504 1526 if ( false === $fh ) {
1505 1527 wpbc_show_message_in_settings( 'Can not create or edit PHP file: ' . $new_php_file, 'error' );
1506 1528
@@ -1505,8 +1527,9 @@
1505 1527 wpbc_show_message_in_settings( 'Can not create or edit PHP file: ' . $new_php_file, 'error' );
1506 1528
1507 1529 return false;
1508 1530 }
1531 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite
1509 1532 $res = fwrite( $fh, $file_content );
1510 1533 if ( false === $res ) {
1511 1534 wpbc_show_message_in_settings( 'Some error during saving data into file ' . $new_php_file, 'error' );
1512 1535
@@ -1511,14 +1534,15 @@
1511 1534 wpbc_show_message_in_settings( 'Some error during saving data into file ' . $new_php_file, 'error' );
1512 1535
1513 1536 return false;
1514 1537 }
1538 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
1515 1539 $res = fclose( $fh );
1516 1540
1517 1541 wpbc_show_message_in_settings( 'Completed! [ ' . htmlentities( $new_php_file ) . ' ]', 'info' );
1518 1542 }
1519 1543
1520 - echo '<a class="button button-secondary" style="margin:10px 0;" href="' . wpbc_get_settings_url() . '" >' . __( 'Go to Settings', 'booking' ) . '</a>';
1544 + echo '<a class="button button-secondary" style="margin:10px 0;" href="' . esc_url( wpbc_get_settings_url() ) . '" >' . esc_html__( 'Go to Settings', 'booking' ) . '</a>';
1521 1545
1522 1546 return $res;
1523 1547
1524 1548 } else {
@@ -1567,14 +1591,13 @@
1567 1591 foreach ( $path_arr as $path ) {
1568 1592
1569 1593 if ( file_exists( $path ) ) {
1570 1594 if ( is_file( $path ) ) {
1571 - if ( ! unlink( $path ) ) {
1572 - throw new \RuntimeException( "Failed to unlink {$path}: " . var_export( error_get_last(), true ) );
1595 + if ( ! wp_delete_file( $path ) ) {
1596 + throw new \RuntimeException( 'Failed to unlink ' . esc_html( $path ) . ': ' . var_export( error_get_last(), true ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_var_export
1573 1597 } else {
1574 - echo '<p style="color:red;">Deleted: ' . $path . '</p>';
1598 + echo '<p style="color:red;">Deleted: ' . esc_html( $path ) . '</p>';
1575 1599 }
1576 -
1577 1600 }
1578 1601 }
1579 1602 }
1580 1603 }
@@ -1581,9 +1604,9 @@
1581 1604
1582 1605
1583 1606 // $translation = apply_filters( "gettext_{$domain}", $translation, $text, $domain );
1584 1607
1585 -//FixIn: 9.1.3.2
1608 +// FixIn: 9.1.3.2.
1586 1609 /**
1587 1610 * Check consistency of translations. For situations, when translators made mistakes with missed symbols like %s or additional items
1588 1611 *
1589 1612 * @param $translation