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 +64 -34 10.10.211.8.4 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * @version 1.0
4 4 * @package Booking Calendar
@@ -160,8 +160,9 @@
160 160 * load_textdomain( $domain, WPBC_PLUGIN_DIR . '/languages/' . $domain . '-' . $locale . '.mo' );
161 161 */
162 162
163 163 $plugin_rel_path = WPBC_PLUGIN_DIRNAME . '/languages';
164 + // phpcs:ignore PluginCheck.CodeAnalysis.DiscouragedFunctions.load_plugin_textdomainFound
164 165 $is_mo_loaded = load_plugin_textdomain( $domain, false, $plugin_rel_path );
165 166 }
166 167
167 168
@@ -215,23 +216,42 @@
215 216 * @string $locale '' || 'en_US' || 'it_IT'
216 217 */
217 218 function wpbc_load_country_list_file_php( $locale ){ // FixIn: 8.8.2.5.
218 219
219 - if ( ! empty( $locale ) ) {
220 - $locale_lang = strtolower( substr( $locale, 0, 2 ) );
221 - $locale_country = strtolower( substr( $locale, 3 ) );
220 + require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list.php';
222 221
223 - // FixIn: 8.9.4.12.
224 - if ( ( $locale_lang !== 'en' ) && ( wpbc_is_file_exist( '/core/lang/wpdev-country-list-' . $locale . '.php' ) ) ) {
225 - require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list-' . $locale . '.php';
226 - } else {
227 - require_once WPBC_PLUGIN_DIR . '/core/lang/wpdev-country-list.php';
228 - }
229 - } else {
230 - 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;
231 241 }
232 242
233 - 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;
234 254 }
235 255
236 256
237 257 /**
@@ -271,15 +291,15 @@
271 291
272 292 $wpbc_ajx_locale = false;
273 293 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
274 294 if ( isset( $_REQUEST['wpdev_active_locale'] ) ) {
275 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended
276 - $wpbc_ajx_locale = sanitize_text_field( $_REQUEST['wpdev_active_locale'] );
295 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
296 + $wpbc_ajx_locale = wpbc_validate_request_locale( $_REQUEST['wpdev_active_locale'] );
277 297 }
278 298 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
279 299 if ( isset( $_REQUEST['wpbc_ajx_locale'] ) ) {
280 - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Recommended
281 - $wpbc_ajx_locale = sanitize_text_field( $_REQUEST['wpbc_ajx_locale'] );
300 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
301 + $wpbc_ajx_locale = wpbc_validate_request_locale( $_REQUEST['wpbc_ajx_locale'] );
282 302 }
283 303
284 304 // Reload locale ONLY in AJAX, and if `isset $_REQUEST['wpdev_active_locale']
285 305 if (
@@ -389,11 +409,11 @@
389 409
390 410 /**
391 411 * Translate content. Check for language sections -- [lang=xx_XX] shortcode. // FixIn: 10.0.0.46.
392 412 *
393 - * @param $content_orig
394 - *
395 - * @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.
396 416 */
397 417 function wpbc_lang( $content_orig ) {
398 418 return wpdev_check_for_active_language( $content_orig );
399 419 }
@@ -401,24 +421,32 @@
401 421
402 422 /**
403 423 * Check plugin text for active language section -- [lang=xx_XX] shortcode
404 424 *
405 - * @param string $content_orig
406 - * @return string
425 + * @param mixed $content_orig Content containing optional language sections.
426 + * @return string Translated content, or an empty string for unsupported values.
407 427 * Usage:
408 428 * $text = wpbc_lang( $text );
409 429 */
410 -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 ) ) {
411 448
412 - $content = $content_orig;
413 -
414 - $languages = array();
415 - $content_ex = explode('[lang',$content);
416 -
417 - foreach ( $content_ex as $value ) {
418 -
419 - if ( '=' == substr( $value, 0, 1 ) ) {
420 -
421 449 $pos_s = strpos( $value, '=' );
422 450 $pos_f = strpos( $value, ']' );
423 451 $key = trim( substr( $value, ( $pos_s + 1 ), ( $pos_f - $pos_s - 1 ) ) );
424 452 $value_l = trim( substr( $value, $pos_f + 1 ) );
@@ -428,9 +456,9 @@
428 456 $languages['default'] = $value;
429 457 }
430 458 }
431 459
432 - $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR';
460 + $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR'.
433 461
434 462 if ( isset( $languages[ $locale ] ) ) {
435 463 $return_text = $languages[ $locale ];
436 464 } else {
@@ -518,8 +546,9 @@
518 546 } else { // WPML Version: 3.2
519 547
520 548 // Help info: do_action( 'wpml_register_single_string', string $context, string $name, string $value )
521 549 // https://wpml.org/wpml-hook/wpml_register_string_for_translation/
550 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
522 551 do_action( 'wpml_register_single_string', 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ) , $translation_to_check );
523 552
524 553
525 554 // Help info: apply_filters( 'wpml_translate_single_string', string $original_value, string $context, string $name, string $$language_code )
@@ -525,8 +554,9 @@
525 554 // Help info: apply_filters( 'wpml_translate_single_string', string $original_value, string $context, string $name, string $$language_code )
526 555 // https://wpml.org/wpml-hook/wpml_translate_single_string/
527 556 //$translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ) );
528 557 $language_code = $locale;
558 + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
529 559 $translation_to_check = apply_filters( 'wpml_translate_single_string', $translation_to_check, 'Booking Calendar', 'wpbc-' . tag_escape( $translation_to_check ), $language_code );
530 560
531 561 }
532 562 }
@@ -808,9 +838,9 @@
808 838 if ( ! is_admin() ) {
809 839 return $translations_arr;
810 840 }
811 841
812 - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
842 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
813 843
814 844 $api = translations_api( 'plugins', array(
815 845 'slug' => 'booking',
816 846 'version' => WP_BK_VERSION_NUM, //'8.9.3',
@@ -1208,9 +1238,9 @@
1208 1238 */
1209 1239 function wpbc_get_available_language_locales_from_wp_org_api(){
1210 1240
1211 1241 // Get Language names for all Locales
1212 - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
1242 + require_once ABSPATH . 'wp-admin/includes/translation-install.php';
1213 1243 /**
1214 1244 * Array( ["nl_NL"] => array ( language = "nl_NL"
1215 1245 version = "5.9"
1216 1246 updated = "2022-02-10 16:24:09"