| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @version 1.0 |
| 4 | 4 | * @package Booking Calendar |
| @@ -409,11 +409,11 @@ | ||
| 409 | 409 | |
| 410 | 410 | /** |
| 411 | 411 | * Translate content. Check for language sections -- [lang=xx_XX] shortcode. // FixIn: 10.0.0.46. |
| 412 | 412 | * |
| 413 | - * @param mixed $content_orig Content containing optional language sections. | |
| 414 | - * | |
| 415 | - * @return string Translated content, or an empty string for unsupported values. | |
| 413 | + * @param mixed $content_orig Content containing optional language sections. | |
| 414 | + * | |
| 415 | + * @return string Translated content, or an empty string for unsupported values. | |
| 416 | 416 | */ |
| 417 | 417 | function wpbc_lang( $content_orig ) { |
| 418 | 418 | return wpdev_check_for_active_language( $content_orig ); |
| 419 | 419 | } |
| @@ -421,32 +421,32 @@ | ||
| 421 | 421 | |
| 422 | 422 | /** |
| 423 | 423 | * Check plugin text for active language section -- [lang=xx_XX] shortcode |
| 424 | 424 | * |
| 425 | - * @param mixed $content_orig Content containing optional language sections. | |
| 426 | - * @return string Translated content, or an empty string for unsupported values. | |
| 425 | + * @param mixed $content_orig Content containing optional language sections. | |
| 426 | + * @return string Translated content, or an empty string for unsupported values. | |
| 427 | 427 | * Usage: |
| 428 | 428 | * $text = wpbc_lang( $text ); |
| 429 | 429 | */ |
| 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 ) ) { | |
| 430 | +function wpdev_check_for_active_language( $content_orig ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound | |
| 448 | 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 ) ) { | |
| 448 | + | |
| 449 | 449 | $pos_s = strpos( $value, '=' ); |
| 450 | 450 | $pos_f = strpos( $value, ']' ); |
| 451 | 451 | $key = trim( substr( $value, ( $pos_s + 1 ), ( $pos_f - $pos_s - 1 ) ) ); |
| 452 | 452 | $value_l = trim( substr( $value, $pos_f + 1 ) ); |
| @@ -456,9 +456,9 @@ | ||
| 456 | 456 | $languages['default'] = $value; |
| 457 | 457 | } |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR'. | |
| 460 | + $locale = wpbc_get_maybe_reloaded_booking_locale(); // $locale = 'fr_FR'. | |
| 461 | 461 | |
| 462 | 462 | if ( isset( $languages[ $locale ] ) ) { |
| 463 | 463 | $return_text = $languages[ $locale ]; |
| 464 | 464 | } else { |
| @@ -771,13 +771,15 @@ | ||
| 771 | 771 | |
| 772 | 772 | /** |
| 773 | 773 | * Download translations from wpbookingcalendar.com, unpack it to the ../WPBC_PLUGIN_DIR/languages/' folder |
| 774 | 774 | * |
| 775 | + * @param WP_Upgrader_Skin|null $skin Optional authorized upgrader skin. | |
| 776 | + * | |
| 775 | 777 | * @return array|bool|string|WP_Error - result |
| 776 | 778 | */ |
| 777 | - function wpbc_translation_download_from_wpbc(){ | |
| 779 | + function wpbc_translation_download_from_wpbc( $skin = null ){ | |
| 778 | 780 | |
| 779 | - $my_upgrader = wpbc_get_translation_upgrader_obj(); | |
| 781 | + $my_upgrader = wpbc_get_translation_upgrader_obj( $skin ); | |
| 780 | 782 | |
| 781 | 783 | $result = $my_upgrader->run( array( |
| 782 | 784 | 'package' => 'https://wpbookingcalendar.com/download/languages/languages.zip', // Please always pass this. |
| 783 | 785 | 'destination' => WPBC_PLUGIN_DIR . '/languages/', // WPBC_PLUGIN_DIR . '/lang/', // ...and this. |
| @@ -794,11 +796,13 @@ | ||
| 794 | 796 | |
| 795 | 797 | /** |
| 796 | 798 | * Get translation Upgrader object |
| 797 | 799 | * |
| 800 | + * @param WP_Upgrader_Skin|null $skin Optional authorized upgrader skin. | |
| 801 | + * | |
| 798 | 802 | * @return WP_Upgrader obj |
| 799 | 803 | */ |
| 800 | - function wpbc_get_translation_upgrader_obj(){ | |
| 804 | + function wpbc_get_translation_upgrader_obj( $skin = null ){ | |
| 801 | 805 | |
| 802 | 806 | require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 803 | 807 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 804 | 808 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| @@ -804,11 +808,13 @@ | ||
| 804 | 808 | require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 805 | 809 | require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 806 | 810 | |
| 807 | 811 | require_once WPBC_PLUGIN_DIR . '/core/class/wpbc-class-upgrader-translation-skin.php'; |
| 808 | - $skin = new WPBC_Upgrader_Translation_Skin( | |
| 809 | - array( 'skip_header_footer' => true ) | |
| 810 | - ); | |
| 812 | + if ( ! ( $skin instanceof WP_Upgrader_Skin ) ) { | |
| 813 | + $skin = new WPBC_Upgrader_Translation_Skin( | |
| 814 | + array( 'skip_header_footer' => true ) | |
| 815 | + ); | |
| 816 | + } | |
| 811 | 817 | |
| 812 | 818 | $my_upgrader = new WP_Upgrader( $skin ); |
| 813 | 819 | |
| 814 | 820 | $my_upgrader->init(); // it's required for defining skin messages |
| @@ -1452,9 +1458,9 @@ | ||
| 1452 | 1458 | * Load translation POT file, and generate PHP file with all translations relative to plugin. |
| 1453 | 1459 | * Link: http://server.com/wp-admin/admin.php?page=wpbc-settings&system_info=show&pot=1#wpbc_general_settings_system_info_metabox |
| 1454 | 1460 | */ |
| 1455 | 1461 | function wpbc_pot_to_php() { |
| 1456 | - | |
| 1462 | + return; | |
| 1457 | 1463 | /* |
| 1458 | 1464 | * $shortcode = 'wpml'; |
| 1459 | 1465 | |
| 1460 | 1466 | // Find anything between [wpml] and [/wpml] shortcodes. Magic here: [\s\S]*? - fit to any text |