diff --git a/wp-content/plugins/polylang/admin/admin-base.php b/wp-content/plugins/polylang/admin/admin-base.php index 826073d4..2f3c765a 100644 --- a/wp-content/plugins/polylang/admin/admin-base.php +++ b/wp-content/plugins/polylang/admin/admin-base.php @@ -1,27 +1,70 @@ notices = new PLL_Admin_Notices( $this ); + if ( ! $this->model->get_languages_list() ) { return; } @@ -49,10 +93,12 @@ class PLL_Admin_Base extends PLL_Base { $this->links = new PLL_Admin_Links( $this ); // FIXME needed here ? $this->static_pages = new PLL_Admin_Static_Pages( $this ); // FIXME needed here ? $this->filters_links = new PLL_Filters_Links( $this ); // FIXME needed here ? + $this->default_term = new PLL_Admin_Default_Term( $this ); + $this->default_term->add_hooks(); // Filter admin language for users // We must not call user info before WordPress defines user roles in wp-settings.php - add_filter( 'setup_theme', array( $this, 'init_user' ) ); + add_action( 'setup_theme', array( $this, 'init_user' ) ); add_filter( 'request', array( $this, 'request' ) ); // Adds the languages in admin bar @@ -63,8 +109,12 @@ class PLL_Admin_Base extends PLL_Base { * Adds the link to the languages panel in the WordPress admin menu * * @since 0.1 + * + * @return void */ public function add_menus() { + global $admin_page_hooks; + // Prepare the list of tabs $tabs = array( 'lang' => __( 'Languages', 'polylang' ) ); @@ -84,11 +134,14 @@ class PLL_Admin_Base extends PLL_Base { */ $tabs = apply_filters( 'pll_settings_tabs', $tabs ); + $parent = ''; + foreach ( $tabs as $tab => $title ) { $page = 'lang' === $tab ? 'mlang' : "mlang_$tab"; if ( empty( $parent ) ) { $parent = $page; - add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, null, 'dashicons-translation' ); + add_menu_page( $title, __( 'Languages', 'polylang' ), 'manage_options', $page, '__return_null', 'dashicons-translation' ); + $admin_page_hooks[ $page ] = 'languages'; // Hack to avoid the localization of the hook name. See: https://core.trac.wordpress.org/ticket/18857 } add_submenu_page( $parent, $title, $title, 'manage_options', $page, array( $this, 'languages_page' ) ); @@ -99,6 +152,8 @@ class PLL_Admin_Base extends PLL_Base { * Setup js scripts & css styles ( only on the relevant pages ) * * @since 0.6 + * + * @return void */ public function admin_enqueue_scripts() { $screen = get_current_screen(); @@ -108,26 +163,83 @@ class PLL_Admin_Base extends PLL_Base { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - // For each script: - // 0 => the pages on which to load the script - // 1 => the scripts it needs to work - // 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise - // 3 => 1 if loaded in footer - // FIXME: check if I can load more scripts in footer + /* + * For each script: + * 0 => the pages on which to load the script + * 1 => the scripts it needs to work + * 2 => 1 if loaded even if languages have not been defined yet, 0 otherwise + * 3 => 1 if loaded in footer + */ $scripts = array( - 'post' => array( array( 'post', 'media', 'async-upload', 'edit' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-autocomplete' ), 0, 0 ), - 'media' => array( array( 'upload' ), array( 'jquery' ), 0, 1 ), - 'term' => array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ), - 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ), + 'user' => array( array( 'profile', 'user-edit' ), array( 'jquery' ), 0, 0 ), + 'widgets' => array( array( 'widgets' ), array( 'jquery' ), 0, 0 ), ); - foreach ( $scripts as $script => $v ) { - if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) { - wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/' . $script . $suffix . '.js', POLYLANG_FILE ), $v[1], POLYLANG_VERSION, $v[3] ); + if ( ! empty( $screen->post_type ) && $this->model->is_translated_post_type( $screen->post_type ) ) { + $scripts['post'] = array( array( 'edit', 'upload' ), array( 'jquery', 'wp-ajax-response' ), 0, 1 ); + + // Classic editor. + if ( ! method_exists( $screen, 'is_block_editor' ) || ! $screen->is_block_editor() ) { + $scripts['classic-editor'] = array( array( 'post', 'media', 'async-upload' ), array( 'jquery', 'wp-ajax-response', 'post', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 ); + } + + // Block editor with legacy metabox in WP 5.0+. + if ( method_exists( $screen, 'is_block_editor' ) && $screen->is_block_editor() && ! pll_use_block_editor_plugin() ) { + $scripts['block-editor'] = array( array( 'post' ), array( 'jquery', 'wp-ajax-response', 'wp-api-fetch', 'jquery-ui-dialog', 'wp-i18n' ), 0, 1 ); } } - wp_enqueue_style( 'polylang_admin', plugins_url( '/css/admin' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION ); + if ( ! empty( $screen->taxonomy ) && $this->model->is_translated_taxonomy( $screen->taxonomy ) ) { + $scripts['term'] = array( array( 'edit-tags', 'term' ), array( 'jquery', 'wp-ajax-response', 'jquery-ui-autocomplete' ), 0, 1 ); + } + + foreach ( $scripts as $script => $v ) { + if ( in_array( $screen->base, $v[0] ) && ( $v[2] || $this->model->get_languages_list() ) ) { + wp_enqueue_script( 'pll_' . $script, plugins_url( '/js/build/' . $script . $suffix . '.js', POLYLANG_ROOT_FILE ), $v[1], POLYLANG_VERSION, $v[3] ); + if ( 'classic-editor' === $script || 'block-editor' === $script ) { + wp_set_script_translations( 'pll_' . $script, 'polylang' ); + } + } + } + + wp_register_style( 'polylang_admin', plugins_url( '/css/build/admin' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); + wp_enqueue_style( 'polylang_dialog', plugins_url( '/css/build/dialog' . $suffix . '.css', POLYLANG_ROOT_FILE ), array( 'polylang_admin' ), POLYLANG_VERSION ); + + $this->localize_scripts(); + } + + /** + * Enqueue scripts to the WP Customizer. + * + * @since 2.4.0 + * + * @return void + */ + public function customize_controls_enqueue_scripts() { + if ( $this->model->get_languages_list() ) { + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + wp_enqueue_script( 'pll_widgets', plugins_url( '/js/build/widgets' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION, true ); + $this->localize_scripts(); + } + } + + /** + * Localize scripts. + * + * @since 2.4.0 + * + * @return void + */ + public function localize_scripts() { + if ( wp_script_is( 'pll_widgets', 'enqueued' ) ) { + wp_localize_script( + 'pll_widgets', + 'pll_widgets', + array( + 'flags' => wp_list_pluck( $this->model->get_languages_list(), 'flag', 'slug' ), + ) + ); + } } /** @@ -143,6 +255,8 @@ class PLL_Admin_Base extends PLL_Base { * see: https://wordpress.org/support/topic/invalid-url-during-wordpress-new-dashboard-widget-operation * * @since 1.4 + * + * @return void */ public function admin_print_footer_scripts() { global $post_ID, $tag_ID; @@ -157,84 +271,108 @@ class PLL_Admin_Base extends PLL_Base { } $str = http_build_query( $params ); - $arr = json_encode( $params ); -?> - - + curlang = $this->filter_lang; - // POST - if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( $_POST['post_lang_choice'] ) ) { - $this->curlang = $lang; - } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( $_POST['term_lang_choice'] ) ) { - $this->curlang = $lang; - } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( $_POST['inline_lang_choice'] ) ) { - $this->curlang = $lang; - } - // Edit Post - if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { + if ( isset( $_REQUEST['pll_post_id'] ) && $lang = $this->model->post->get_language( (int) $_REQUEST['pll_post_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->curlang = $lang; - } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && is_numeric( $_GET['post'] ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { + } elseif ( 'post.php' === $GLOBALS['pagenow'] && isset( $_GET['post'] ) && $this->model->is_translated_post_type( get_post_type( (int) $_GET['post'] ) ) && $lang = $this->model->post->get_language( (int) $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->curlang = $lang; - } elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( $_GET['post_type'] ) ) ) { - $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( $_GET['new_lang'] ); + } elseif ( 'post-new.php' === $GLOBALS['pagenow'] && ( empty( $_GET['post_type'] ) || $this->model->is_translated_post_type( sanitize_key( $_GET['post_type'] ) ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->curlang = empty( $_GET['new_lang'] ) ? $this->pref_lang : $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification } // Edit Term - // FIXME 'edit-tags.php' for backward compatibility with WP < 4.5 - elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { + elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->curlang = $lang; - } elseif ( isset( $_REQUEST['pll_term_id'] ) && $lang = $this->model->term->get_language( (int) $_REQUEST['pll_term_id'] ) ) { - $this->curlang = $lang; - } elseif ( 'edit-tags.php' === $GLOBALS['pagenow'] && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( $_GET['taxonomy'] ) ) { - if ( ! empty( $_GET['new_lang'] ) ) { - $this->curlang = $this->model->get_language( $_GET['new_lang'] ); + } elseif ( in_array( $GLOBALS['pagenow'], array( 'edit-tags.php', 'term.php' ) ) && isset( $_GET['taxonomy'] ) && $this->model->is_translated_taxonomy( sanitize_key( $_GET['taxonomy'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + if ( isset( $_GET['tag_ID'] ) && $lang = $this->model->term->get_language( (int) $_GET['tag_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->curlang = $lang; + } elseif ( ! empty( $_GET['new_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->curlang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification } elseif ( empty( $this->curlang ) ) { $this->curlang = $this->pref_lang; } } // Ajax - if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { - $this->curlang = $this->model->get_language( $_REQUEST['lang'] ); + if ( wp_doing_ajax() && ! empty( $_REQUEST['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->curlang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification + } + + // Inform that the admin language has been set. + if ( $this->curlang ) { + /** This action is documented in frontend/choose-lang.php */ + do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang ); + } else { + /** This action is documented in include/class-polylang.php */ + do_action( 'pll_no_language_defined' ); // To load overridden textdomains. } } @@ -242,18 +380,15 @@ class PLL_Admin_Base extends PLL_Base { * Defines the backend language and the admin language filter based on user preferences * * @since 1.2.3 + * + * @return void */ public function init_user() { - // Backend locale - // FIXME: Backward compatibility with WP < 4.7 - if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) { - add_filter( 'locale', array( $this, 'get_locale' ) ); - } - // Language for admin language filter: may be empty // $_GET['lang'] is numeric when editing a language, not when selecting a new language in the filter - if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( $_GET['lang'] ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) { - update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( $_GET['lang'] ) ) ? $lang->slug : '' ); + // We intentionally don't use a nonce to update the language filter + if ( ! wp_doing_ajax() && ! empty( $_GET['lang'] ) && ! is_numeric( sanitize_key( $_GET['lang'] ) ) && current_user_can( 'edit_user', $user_id = get_current_user_id() ) ) { // phpcs:ignore WordPress.Security.NonceVerification + update_user_meta( $user_id, 'pll_filter_content', ( $lang = $this->model->get_language( sanitize_key( $_GET['lang'] ) ) ) ? $lang->slug : '' ); // phpcs:ignore WordPress.Security.NonceVerification } $this->filter_lang = $this->model->get_language( get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ); @@ -262,38 +397,26 @@ class PLL_Admin_Base extends PLL_Base { $this->pref_lang = empty( $this->filter_lang ) ? $this->model->get_language( $this->options['default_lang'] ) : $this->filter_lang; /** - * Filter the preferred language on admin side - * The preferred language is used for example to determine the language of a new post + * Filters the preferred language on admin side. + * The preferred language is used for example to determine the language of a new post. * * @since 1.2.3 * - * @param object $pref_lang preferred language + * @param PLL_Language $pref_lang Preferred language. */ $this->pref_lang = apply_filters( 'pll_admin_preferred_language', $this->pref_lang ); $this->set_current_language(); - // Inform that the admin language has been set - // Only if the admin language is one of the Polylang defined language - // FIXME test get_user_locale for backward compatibility with WP 4.7 - if ( $curlang = $this->model->get_language( function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale() ) ) { - // FIXME: Backward compatibility with WP < 4.7 - if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) { - $GLOBALS['text_direction'] = $curlang->is_rtl ? 'rtl' : 'ltr'; // force text direction according to language setting - } - - /** This action is documented in frontend/choose-lang.php */ - do_action( 'pll_language_defined', $curlang->slug, $curlang ); - } else { - /** This action is documented in include/class-polylang.php */ - do_action( 'pll_no_language_defined' ); // to load overridden textdomains - } + // Plugin i18n, only needed for backend. + load_plugin_textdomain( 'polylang' ); } /** * Avoids parsing a tax query when all languages are requested * Fixes https://wordpress.org/support/topic/notice-undefined-offset-0-in-wp-includesqueryphp-on-line-3877 introduced in WP 4.1 - * @see the suggestion of @boonebgorges, https://core.trac.wordpress.org/ticket/31246 + * + * @see https://core.trac.wordpress.org/ticket/31246 the suggestion of @boonebgorges. * * @since 1.6.5 * @@ -309,24 +432,12 @@ class PLL_Admin_Base extends PLL_Base { } /** - * Get the locale based on user preference - * FIXME: Backward compatibility with WP < 4.7 - * - * @since 0.4 - * - * @param string $locale - * @return string modified locale - */ - public function get_locale( $locale ) { - return ( $loc = get_user_meta( get_current_user_id(), 'locale', 'true' ) ) ? $loc : $locale; - } - - /** - * Adds the languages list in admin bar for the admin languages filter + * Adds the languages list in admin bar for the admin languages filter. * * @since 0.9 * - * @param object $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar global object. + * @return void */ public function admin_bar_menu( $wp_admin_bar ) { $all_item = (object) array( @@ -344,25 +455,46 @@ class PLL_Admin_Base extends PLL_Base { esc_html( $selected->name ) ); - $wp_admin_bar->add_menu( array( - 'id' => 'languages', - 'title' => $selected->flag . $title, - 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ), - 'meta' => array( 'title' => __( 'Filters content by language', 'polylang' ) ), - ) ); + /** + * Filters the admin languages filter submenu items + * + * @since 2.6 + * + * @param array $items The admin languages filter submenu items. + */ + $items = apply_filters( 'pll_admin_languages_filter', array_merge( array( $all_item ), $this->model->get_languages_list() ) ); - foreach ( array_merge( array( $all_item ), $this->model->get_languages_list() ) as $lang ) { + $menu = array( + 'id' => 'languages', + 'title' => $selected->flag . $title, + 'href' => esc_url( add_query_arg( 'lang', $selected->slug, remove_query_arg( 'paged' ) ) ), + 'meta' => array( + 'title' => __( 'Filters content by language', 'polylang' ), + ), + ); + + if ( 'all' !== $selected->slug ) { + $menu['meta']['class'] = 'pll-filtered-languages'; + } + + if ( ! empty( $items ) ) { + $wp_admin_bar->add_menu( $menu ); + } + + foreach ( $items as $lang ) { if ( $selected->slug === $lang->slug ) { continue; } - $wp_admin_bar->add_menu( array( - 'parent' => 'languages', - 'id' => $lang->slug, - 'title' => $lang->flag . esc_html( $lang->name ), - 'href' => esc_url( add_query_arg( 'lang', $lang->slug, remove_query_arg( 'paged' ) ) ), - 'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ), - ) ); + $wp_admin_bar->add_menu( + array( + 'parent' => 'languages', + 'id' => $lang->slug, + 'title' => $lang->flag . esc_html( $lang->name ), + 'href' => esc_url( add_query_arg( 'lang', $lang->slug, remove_query_arg( 'paged' ) ) ), + 'meta' => 'all' === $lang->slug ? array() : array( 'lang' => esc_attr( $lang->get_locale( 'display' ) ) ), + ) + ); } } } diff --git a/wp-content/plugins/polylang/admin/admin-block-editor.php b/wp-content/plugins/polylang/admin/admin-block-editor.php new file mode 100644 index 00000000..669c95bf --- /dev/null +++ b/wp-content/plugins/polylang/admin/admin-block-editor.php @@ -0,0 +1,66 @@ +model = &$polylang->model; + $this->pref_lang = &$polylang->pref_lang; + + new PLL_Block_Editor_Filter_Preload_Paths( array( $this, 'preload_paths' ), 10, 2 ); + } + + /** + * Filters the preload REST requests by the current language of the post. + * Necessary otherwise subsequent REST requests, all filtered by the language, + * would not hit the preloaded requests. + * + * @since 2.5 + * + * @param (string|string[])[] $preload_paths Array of paths to preload. + * @param WP_Post $post The post resource data. + * @return (string|string[])[] + */ + public function preload_paths( $preload_paths, $post ) { + if ( $post instanceof WP_Post && $this->model->is_translated_post_type( $post->post_type ) ) { + $lang = $this->model->post->get_language( $post->ID ); + + if ( ! $lang ) { + $lang = $this->pref_lang; + } + + foreach ( $preload_paths as $k => $path ) { + if ( is_string( $path ) && '/' !== $path ) { + $preload_paths[ $k ] = $path . "&lang={$lang->slug}"; + } + } + } + + return $preload_paths; + } +} diff --git a/wp-content/plugins/polylang/admin/admin-classic-editor.php b/wp-content/plugins/polylang/admin/admin-classic-editor.php new file mode 100644 index 00000000..0e3771ea --- /dev/null +++ b/wp-content/plugins/polylang/admin/admin-classic-editor.php @@ -0,0 +1,362 @@ +model = &$polylang->model; + $this->links = &$polylang->links; + $this->curlang = &$polylang->curlang; + $this->pref_lang = &$polylang->pref_lang; + + // Adds the Languages box in the 'Edit Post' and 'Edit Page' panels + add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); + + // Ajax response for changing the language in the post metabox + add_action( 'wp_ajax_post_lang_choice', array( $this, 'post_lang_choice' ) ); + add_action( 'wp_ajax_pll_posts_not_translated', array( $this, 'ajax_posts_not_translated' ) ); + + // Filters the pages by language in the parent dropdown list in the page attributes metabox + add_filter( 'page_attributes_dropdown_pages_args', array( $this, 'page_attributes_dropdown_pages_args' ), 10, 2 ); + + // Notice + add_action( 'edit_form_top', array( $this, 'edit_form_top' ) ); + } + + /** + * Adds the Language box in the 'Edit Post' and 'Edit Page' panels ( as well as in custom post types panels ) + * + * @since 0.1 + * + * @param string $post_type Current post type + * @return void + */ + public function add_meta_boxes( $post_type ) { + if ( $this->model->is_translated_post_type( $post_type ) ) { + add_meta_box( + 'ml_box', + __( 'Languages', 'polylang' ), + array( $this, 'post_language' ), + $post_type, + 'side', + 'high', + array( + '__back_compat_meta_box' => pll_use_block_editor_plugin(), + ) + ); + } + } + + /** + * Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels + * + * @since 0.1 + * + * @return void + */ + public function post_language() { + global $post_ID; + $post_type = get_post_type( $post_ID ); + + // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + $from_post_id = isset( $_GET['from_post'] ) ? (int) $_GET['from_post'] : 0; + + $lang = ( $lg = $this->model->post->get_language( $post_ID ) ) ? $lg : + ( isset( $_GET['new_lang'] ) ? $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) : // phpcs:ignore WordPress.Security.NonceVerification + $this->pref_lang ); + + $dropdown = new PLL_Walker_Dropdown(); + + $id = ( 'attachment' === $post_type ) ? sprintf( 'attachments[%d][language]', (int) $post_ID ) : 'post_lang_choice'; + + $dropdown_html = $dropdown->walk( + $this->model->get_languages_list(), + -1, + array( + 'name' => $id, + 'class' => 'post_lang_choice tags-input', + 'selected' => $lang ? $lang->slug : '', + 'flag' => true, + ) + ); + + wp_nonce_field( 'pll_language', '_pll_nonce' ); + + // NOTE: the class "tags-input" allows to include the field in the autosave $_POST ( see autosave.js ) + printf( + '

%1$s

+ +
%4$s
', + esc_html__( 'Language', 'polylang' ), + esc_attr( $id ), + ( 'attachment' === $post_type ? 'media' : 'post' ), + $dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput + ); + + /** + * Fires before displaying the list of translations in the Languages metabox for posts + * + * @since 1.8 + */ + do_action( 'pll_before_post_translations', $post_type ); + + echo '
'; + if ( $lang ) { + if ( 'attachment' === $post_type ) { + include __DIR__ . '/view-translations-media.php'; + } else { + include __DIR__ . '/view-translations-post.php'; + } + } + echo '
' . "\n"; + } + + /** + * Ajax response for changing the language in the post metabox + * + * @since 0.2 + * + * @return void + */ + public function post_lang_choice() { + check_ajax_referer( 'pll_language', '_pll_nonce' ); + + if ( ! isset( $_POST['post_id'], $_POST['lang'], $_POST['post_type'] ) ) { + wp_die( 'The request is missing the parameter "post_type", "lang" and/or "post_id".' ); + } + + global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist + $post_ID = (int) $_POST['post_id']; + $lang_slug = sanitize_key( $_POST['lang'] ); + $lang = $this->model->get_language( $lang_slug ); + $post_type = sanitize_key( $_POST['post_type'] ); + + if ( empty( $lang ) ) { + wp_die( esc_html( "{$lang_slug} is not a valid language code." ) ); + } + + $post_type_object = get_post_type_object( $post_type ); + + if ( empty( $post_type_object ) ) { + wp_die( esc_html( "{$post_type} is not a valid post type." ) ); + } + + if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) { + wp_die( 'You are not allowed to edit this post.' ); + } + + $this->model->post->update_language( $post_ID, $lang ); + + ob_start(); + if ( 'attachment' === $post_type ) { + include __DIR__ . '/view-translations-media.php'; + } else { + include __DIR__ . '/view-translations-post.php'; + } + $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) ); + ob_end_clean(); + + // Categories + if ( isset( $_POST['taxonomies'] ) ) { // Not set for pages + $supplemental = array(); + + foreach ( array_map( 'sanitize_key', $_POST['taxonomies'] ) as $taxname ) { + $taxonomy = get_taxonomy( $taxname ); + + if ( ! empty( $taxonomy ) ) { + ob_start(); + $popular_ids = wp_popular_terms_checklist( $taxonomy->name ); + $supplemental['populars'] = ob_get_contents(); + ob_end_clean(); + + ob_start(); + // Use $post_ID to remember checked terms in case we come back to the original language + wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) ); + $supplemental['all'] = ob_get_contents(); + ob_end_clean(); + + $supplemental['dropdown'] = wp_dropdown_categories( + array( + 'taxonomy' => $taxonomy->name, + 'hide_empty' => 0, + 'name' => 'new' . $taxonomy->name . '_parent', + 'orderby' => 'name', + 'hierarchical' => 1, + 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', + 'echo' => 0, + ) + ); + + $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) ); + } + } + } + + // Parent dropdown list ( only for hierarchical post types ) + if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) { + $post = get_post( $post_ID ); + + if ( ! empty( $post ) ) { + // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1 + $dropdown_args = array( + 'post_type' => $post->post_type, + 'exclude_tree' => $post->ID, + 'selected' => $post->post_parent, + 'name' => 'parent_id', + 'show_option_none' => __( '(no parent)', 'polylang' ), + 'sort_column' => 'menu_order, post_title', + 'echo' => 0, + ); + + /** This filter is documented in wp-admin/includes/meta-boxes.php */ + $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3 + + $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput + } + } + + // Flag + $x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) ); + + // Sample permalink + $x->Add( array( 'what' => 'permalink', 'data' => get_sample_permalink_html( $post_ID ) ) ); + + $x->send(); + } + + /** + * Ajax response for input in translation autocomplete input box + * + * @since 1.5 + * + * @return void + */ + public function ajax_posts_not_translated() { + check_ajax_referer( 'pll_language', '_pll_nonce' ); + + if ( ! isset( $_GET['post_type'], $_GET['post_language'], $_GET['translation_language'], $_GET['term'], $_GET['pll_post_id'] ) ) { + wp_die( 0 ); + } + + $post_type = sanitize_key( $_GET['post_type'] ); + + if ( ! post_type_exists( $post_type ) ) { + wp_die( 0 ); + } + + $term = wp_unslash( $_GET['term'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput + + $post_language = $this->model->get_language( sanitize_key( $_GET['post_language'] ) ); + $translation_language = $this->model->get_language( sanitize_key( $_GET['translation_language'] ) ); + + $return = array(); + + $untranslated_posts = $this->model->post->get_untranslated( $post_type, $post_language, $translation_language, $term ); + + // format output + foreach ( $untranslated_posts as $post ) { + $return[] = array( + 'id' => $post->ID, + 'value' => $post->post_title, + 'link' => $this->links->edit_post_translation_link( $post->ID ), + ); + } + + // Add current translation in list + if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) { + $post = get_post( $post_id ); + + if ( ! empty( $post ) ) { + array_unshift( + $return, + array( + 'id' => $post_id, + 'value' => $post->post_title, + 'link' => $this->links->edit_post_translation_link( $post_id ), + ) + ); + } + } + + wp_die( wp_json_encode( $return ) ); + } + + /** + * Filters the pages by language in the parent dropdown list in the page attributes metabox. + * + * @since 0.6 + * + * @param array $dropdown_args Arguments passed to wp_dropdown_pages(). + * @param WP_Post $post The page being edited. + * @return array Modified arguments. + */ + public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) { + $dropdown_args['lang'] = isset( $_POST['lang'] ) ? $this->model->get_language( sanitize_key( $_POST['lang'] ) ) : $this->model->post->get_language( $post->ID ); // phpcs:ignore WordPress.Security.NonceVerification + if ( ! $dropdown_args['lang'] ) { + $dropdown_args['lang'] = $this->pref_lang; + } + + return $dropdown_args; + } + + /** + * Displays a notice if the user has not sufficient rights to overwrite synchronized taxonomies and metas. + * + * @since 2.6 + * + * @param WP_Post $post the post currently being edited. + * @return void + */ + public function edit_form_top( $post ) { + if ( ! $this->model->post->current_user_can_synchronize( $post->ID ) ) { + ?> +
+

+ +

+
+ model = &$polylang->model; + $this->pref_lang = &$polylang->pref_lang; + $this->options = &$polylang->options; + $this->taxonomies = $this->model->get_translated_taxonomies(); + } + + /** + * Setups filters and actions needed. + * + * @since 3.1 + * + * @return void + */ + public function add_hooks() { + foreach ( $this->taxonomies as $taxonomy ) { + if ( 'category' === $taxonomy ) { + // Allows to get the default terms in all languages + add_filter( 'option_default_' . $taxonomy, array( $this, 'option_default_term' ) ); + add_action( 'update_option_default_' . $taxonomy, array( $this, 'update_option_default_term' ), 10, 2 ); + + // Adds the language column in the 'Terms' table. + add_filter( 'manage_' . $taxonomy . '_custom_column', array( $this, 'term_column' ), 10, 3 ); + } + } + add_action( 'pll_add_language', array( $this, 'handle_default_term_on_create_language' ) ); + + // The default term should be in the default language + add_action( 'pll_update_default_lang', array( $this, 'update_default_term_language' ) ); + + // Prevents deleting all the translations of the default term + add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_term' ), 10, 4 ); + } + + /** + * Filters the default term in note below the term list table and in settings->writing dropdown + * + * @since 1.2 + * + * @param int $taxonomy_term_id The taxonomy term id. + * @return int A taxonomy term id. + */ + public function option_default_term( $taxonomy_term_id ) { + if ( isset( $this->pref_lang ) && $tr = $this->model->term->get( $taxonomy_term_id, $this->pref_lang ) ) { + $taxonomy_term_id = $tr; + } + return $taxonomy_term_id; + } + + /** + * Checks if the new default term is translated in all languages + * If not, create the translations + * + * @since 1.7 + * + * @param int $old_value The old option value. + * @param int $value The new option value. + * @return void + */ + public function update_option_default_term( $old_value, $value ) { + $default_cat_lang = $this->model->term->get_language( $value ); + + // Assign a default language to default term + if ( ! $default_cat_lang ) { + $default_cat_lang = $this->model->get_language( $this->options['default_lang'] ); + $this->model->term->set_language( (int) $value, $default_cat_lang ); + } + + $taxonomy = substr( current_filter(), 22 ); + + foreach ( $this->model->get_languages_list() as $language ) { + if ( $language->slug != $default_cat_lang->slug && ! $this->model->term->get_translation( $value, $language ) ) { + $this->create_default_term( $language, $taxonomy ); + } + } + } + + /** + * Create a default term for a language + * + * @since 1.2 + * + * @param object|string|int $lang language + * @param string $taxonomy The current taxonomy + * @return void + */ + public function create_default_term( $lang, $taxonomy ) { + $lang = $this->model->get_language( $lang ); + + // create a new term + // FIXME this is translated in admin language when we would like it in $lang + $cat_name = __( 'Uncategorized', 'polylang' ); + $cat_slug = sanitize_title( $cat_name . '-' . $lang->slug ); + $cat = wp_insert_term( $cat_name, $taxonomy, array( 'slug' => $cat_slug ) ); + + // check that the term was not previously created ( in case the language was deleted and recreated ) + $cat = isset( $cat->error_data['term_exists'] ) ? $cat->error_data['term_exists'] : $cat['term_id']; + + // set language + $this->model->term->set_language( (int) $cat, $lang ); + + // this is a translation of the default term + $default = (int) get_option( 'default_' . $taxonomy ); + $translations = $this->model->term->get_translations( $default ); + + $this->model->term->save_translations( (int) $cat, $translations ); + } + + /** + * Manages the default term when new languages are created. + * + * @since 3.1 + * + * @param array $args Argument used to create the language. @see PLL_Admin_Model::add_language(). + * @return void + */ + public function handle_default_term_on_create_language( $args ) { + foreach ( $this->taxonomies as $taxonomy ) { + if ( 'category' === $taxonomy ) { + $default = (int) get_option( 'default_' . $taxonomy ); + + // Assign default language to default term + if ( ! $this->model->term->get_language( $default ) ) { + $this->model->term->set_language( $default, $args['slug'] ); + } elseif ( empty( $args['no_default_cat'] ) && ! $this->model->term->get( $default, $args['slug'] ) ) { + $this->create_default_term( $args['slug'], $taxonomy ); + } + } + } + } + + /** + * Identify the default term in the terms list table to disable the language dropdown in js. + * + * @since 3.1 + * + * @param string $out The output. + * @param string $column The custom column's name. + * @param int $term_id The term id. + * @return string The HTML string. + */ + public function term_column( $out, $column, $term_id ) { + if ( $column === $this->get_first_language_column() && $this->is_default_term( $term_id ) ) { + $out .= sprintf( '', intval( $term_id ) ); + } + + return $out; + } + + /** + * Returns the first language column in the posts, pages and media library tables + * + * @since 0.9 + * + * @return string first language column name + */ + protected function get_first_language_column() { + $columns = array(); + + foreach ( $this->model->get_languages_list() as $language ) { + $columns[] = 'language_' . $language->slug; + } + + return empty( $columns ) ? '' : reset( $columns ); + } + + /** + * Prevents deleting all the translations of the default term + * + * @since 2.1 + * + * @param array $caps The user's actual capabilities. + * @param string $cap Capability name. + * @param int $user_id The user ID. + * @param array $args Adds the context to the cap. The term id. + * @return array + */ + public function fix_delete_default_term( $caps, $cap, $user_id, $args ) { + if ( 'delete_term' === $cap && $this->is_default_term( reset( $args ) ) ) { + $caps[] = 'do_not_allow'; + } + + return $caps; + } + + /** + * Check if the term is the default term. + * + * @since 3.1 + * + * @param int $term_id The term id. + * @return bool True if the term is the default term, false otherwise. + */ + public function is_default_term( $term_id ) { + $term = get_term( $term_id ); + if ( $term instanceof WP_Term ) { + $default_term_id = get_option( 'default_' . $term->taxonomy ); + return $default_term_id && in_array( $default_term_id, $this->model->term->get_translations( $term_id ) ); + } + return false; + } + + /** + * Updates the default term language. + * + * @since 3.1 + * + * @param string $slug Language slug. + * @return void + */ + public function update_default_term_language( $slug ) { + foreach ( $this->taxonomies as $taxonomy ) { + if ( 'category' === $taxonomy ) { + $default_cats = $this->model->term->get_translations( get_option( 'default_' . $taxonomy ) ); + if ( isset( $default_cats[ $slug ] ) ) { + update_option( 'default_' . $taxonomy, $default_cats[ $slug ] ); + } + } + } + } +} diff --git a/wp-content/plugins/polylang/admin/admin-filters-columns.php b/wp-content/plugins/polylang/admin/admin-filters-columns.php index 4687a1cd..08e1170a 100644 --- a/wp-content/plugins/polylang/admin/admin-filters-columns.php +++ b/wp-content/plugins/polylang/admin/admin-filters-columns.php @@ -1,16 +1,34 @@ model = &$polylang->model; $this->filter_lang = &$polylang->filter_lang; - // add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels + // Hide the column of the filtered language. + add_filter( 'hidden_columns', array( $this, 'hidden_columns' ) ); // Since WP 4.4. + + // Add the language and translations columns in 'All Posts', 'All Pages' and 'Media library' panels. foreach ( $this->model->get_translated_post_types() as $type ) { - // use the latest filter late as some plugins purely overwrite what's done by others :( - // specific case for media + // Use the latest filter late as some plugins purely overwrite what's done by others :( + // Specific case for media. add_filter( 'manage_' . ( 'attachment' == $type ? 'upload' : 'edit-' . $type ) . '_columns', array( $this, 'add_post_column' ), 100 ); add_action( 'manage_' . ( 'attachment' == $type ? 'media' : $type . '_posts' ) . '_custom_column', array( $this, 'post_column' ), 10, 2 ); } - // quick edit and bulk edit - add_filter( 'quick_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 ); - add_filter( 'bulk_edit_custom_box', array( $this, 'quick_edit_custom_box' ), 10, 2 ); + // Quick edit and bulk edit. + add_filter( 'quick_edit_custom_box', array( $this, 'quick_edit_custom_box' ) ); + add_filter( 'bulk_edit_custom_box', array( $this, 'quick_edit_custom_box' ) ); - // adds the language column in the 'Categories' and 'Post Tags' tables + // Adds the language column in the 'Categories' and 'Post Tags' tables. foreach ( $this->model->get_translated_taxonomies() as $tax ) { add_filter( 'manage_edit-' . $tax . '_columns', array( $this, 'add_term_column' ) ); add_filter( 'manage_' . $tax . '_custom_column', array( $this, 'term_column' ), 10, 3 ); } - // ajax responses to update list table rows + // Ajax responses to update list table rows. add_action( 'wp_ajax_pll_update_post_rows', array( $this, 'ajax_update_post_rows' ) ); add_action( 'wp_ajax_pll_update_term_rows', array( $this, 'ajax_update_term_rows' ) ); } /** - * adds languages and translations columns in posts, pages, media, categories and tags tables + * Adds languages and translations columns in posts, pages, media, categories and tags tables. * * @since 0.8.2 * - * @param array $columns List of table columns - * @param string $before The column before which we want to add our languages - * @return array modified list of columns + * @param string[] $columns List of table columns. + * @param string $before The column before which we want to add our languages. + * @return string[] Modified list of columns. */ protected function add_column( $columns, $before ) { if ( $n = array_search( $before, array_keys( $columns ) ) ) { @@ -60,56 +81,69 @@ class PLL_Admin_Filters_Columns { } foreach ( $this->model->get_languages_list() as $language ) { - // don't add the column for the filtered language - if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) { - $columns[ 'language_' . $language->slug ] = $language->flag ? $language->flag . '' . esc_html( $language->name ) . '' : esc_html( $language->slug ); - } + $columns[ 'language_' . $language->slug ] = $this->get_flag_html( $language ) . '' . esc_html( $language->name ) . ''; } return isset( $end ) ? array_merge( $columns, $end ) : $columns; } /** - * returns the first language column in the posts, pages and media library tables + * Returns the first language column in the posts, pages and media library tables * * @since 0.9 * * @return string first language column name */ protected function get_first_language_column() { + $columns = array(); + foreach ( $this->model->get_languages_list() as $language ) { - if ( empty( $this->filter_lang ) || $language->slug != $this->filter_lang->slug ) { - $columns[] = 'language_' . $language->slug; - } + $columns[] = 'language_' . $language->slug; } return empty( $columns ) ? '' : reset( $columns ); } /** - * adds the language and translations columns ( before the comments column ) in the posts, pages and media library tables + * Hides the column for the filtered language. + * + * @since 2.7 + * + * @param string[] $hidden Array of hidden columns. + * @return string[] + */ + public function hidden_columns( $hidden ) { + if ( ! empty( $this->filter_lang ) ) { + $hidden[] = 'language_' . $this->filter_lang->slug; + } + return $hidden; + } + + /** + * Adds the language and translations columns ( before the comments column ) in the posts, pages and media library tables. * * @since 0.1 * - * @param array $columns list of posts table columns - * @return array modified list of columns + * @param string[] $columns List of posts table columns. + * @return string[] Modified list of columns. */ - function add_post_column( $columns ) { + public function add_post_column( $columns ) { return $this->add_column( $columns, 'comments' ); } /** - * fills the language and translations columns in the posts, pages and media library tables + * Fills the language and translations columns in the posts, pages and media library tables * take care that when doing ajax inline edit, the post may not be updated in database yet * * @since 0.1 * * @param string $column Column name * @param int $post_id + * @return void */ public function post_column( $column, $post_id ) { - $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action']; - $lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->post->get_language( $post_id ); + $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification + $lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->post->get_language( $post_id ); // phpcs:ignore WordPress.Security.NonceVerification if ( false === strpos( $column, 'language_' ) || ! $lang ) { return; @@ -117,20 +151,24 @@ class PLL_Admin_Filters_Columns { $language = $this->model->get_language( substr( $column, 9 ) ); - // hidden field containing the post language for quick edit + if ( empty( $language ) ) { + return; + } + + // Hidden field containing the post language for quick edit if ( $column == $this->get_first_language_column() ) { printf( '', intval( $post_id ), esc_html( $lang->slug ) ); } - $post_type_object = get_post_type_object( get_post_type( $post_id ) ); - - // link to edit post ( or a translation ) + // Link to edit post ( or a translation ) if ( $id = $this->model->post->get( $post_id, $language ) ) { // get_edit_post_link returns nothing if the user cannot edit the post - // thanks to Solinx. See http://wordpress.org/support/topic/feature-request-incl-code-check-for-capabilities-in-admin-screens + // Thanks to Solinx. See http://wordpress.org/support/topic/feature-request-incl-code-check-for-capabilities-in-admin-screens if ( $link = get_edit_post_link( $id ) ) { + $flag = ''; if ( $id === $post_id ) { - $class = 'pll_icon_tick'; + $flag = $this->get_flag_html( $language ); + $class = 'pll_column_flag'; /* translators: accessibility text, %s is a native language name */ $s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name ); } else { @@ -138,43 +176,52 @@ class PLL_Admin_Filters_Columns { /* translators: accessibility text, %s is a native language name */ $s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ); } - printf( - '%4$s', - esc_attr( $class ), esc_attr( get_post( $id )->post_title ), esc_url( $link ), esc_html( $s ) - ); + + $post = get_post( $id ); + + if ( ! empty( $post ) ) { + printf( + '%4$s%5$s', + esc_attr( $class ), + esc_attr( $post->post_title ), + esc_url( $link ), + esc_html( $s ), + $flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped + ); + } } elseif ( $id === $post_id ) { printf( - '%s', + '%1$s%2$s', /* translators: accessibility text, %s is a native language name */ - esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ) + esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ), + $this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped ); } } - // link to add a new translation + // Link to add a new translation else { - echo $this->links->new_post_translation_link( $post_id, $language ); + echo $this->links->new_post_translation_link( $post_id, $language ); // phpcs:ignore WordPress.Security.EscapeOutput } } /** - * quick edit & bulk edit + * Quick edit & bulk edit * * @since 0.9 * * @param string $column column name - * @param string $type either 'edit-tags' for terms list table or post type for posts list table * @return string unmodified $column */ - public function quick_edit_custom_box( $column, $type ) { + public function quick_edit_custom_box( $column ) { if ( $column == $this->get_first_language_column() ) { $elements = $this->model->get_languages_list(); if ( current_filter() == 'bulk_edit_custom_box' ) { - array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '— No Change —' ) ) ); + array_unshift( $elements, (object) array( 'slug' => -1, 'name' => __( '— No Change —', 'polylang' ) ) ); } $dropdown = new PLL_Walker_Dropdown(); - // the hidden field 'old_lang' allows to pass the old language to ajax request + // The hidden field 'old_lang' allows to pass the old language to ajax request printf( '
@@ -185,63 +232,85 @@ class PLL_Admin_Filters_Columns {
', esc_html__( 'Language', 'polylang' ), - $dropdown->walk( $elements, array( 'name' => 'inline_lang_choice', 'id' => '' ) ) + $dropdown->walk( $elements, -1, array( 'name' => 'inline_lang_choice', 'id' => '' ) ) // phpcs:ignore WordPress.Security.EscapeOutput ); } return $column; } /** - * adds the language column ( before the posts column ) in the 'Categories' or 'Post Tags' table + * Adds the language column ( before the posts column ) in the 'Categories' or 'Post Tags' table. * * @since 0.1 * - * @param array $columns list of terms table columns - * @return array modified list of columns + * @param string[] $columns List of terms table columns. + * @return string[] modified List of columns. */ public function add_term_column( $columns ) { + $screen = get_current_screen(); + + // Avoid displaying languages in screen options when editing a term. + if ( $screen instanceof WP_Screen && 'term' === $screen->base ) { + return $columns; + } + return $this->add_column( $columns, 'posts' ); } /** - * fills the language column in the 'Categories' or 'Post Tags' table + * Fills the language column in the 'Categories' or 'Post Tags' table * * @since 0.1 * * @param string $out * @param string $column Column name * @param int $term_id + * @return string */ public function term_column( $out, $column, $term_id ) { - $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action']; - if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( $_POST['inline_lang_choice'] ) : $this->model->term->get_language( $term_id ) ) ) { + $inline = wp_doing_ajax() && isset( $_REQUEST['action'], $_POST['inline_lang_choice'] ) && 'inline-save-tax' === $_REQUEST['action']; // phpcs:ignore WordPress.Security.NonceVerification + if ( false === strpos( $column, 'language_' ) || ! ( $lang = $inline ? $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) : $this->model->term->get_language( $term_id ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification return $out; } - $post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type']; // 2nd case for quick edit - $taxonomy = isset( $GLOBALS['taxonomy'] ) ? $GLOBALS['taxonomy'] : $_REQUEST['taxonomy']; + if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification + } - if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { + if ( isset( $GLOBALS['post_type'] ) ) { + $post_type = $GLOBALS['post_type']; + } + + if ( isset( $_REQUEST['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $taxonomy = sanitize_key( $_REQUEST['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification + } + + if ( isset( $GLOBALS['taxonomy'] ) ) { + $taxonomy = $GLOBALS['taxonomy']; + } + + if ( ! isset( $taxonomy, $post_type ) || ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { return $out; } $term_id = (int) $term_id; $language = $this->model->get_language( substr( $column, 9 ) ); - if ( $column == $this->get_first_language_column() ) { - $out = sprintf( '', intval( $term_id ), esc_html( $lang->slug ) ); - - // identify the default categories to disable the language dropdown in js - if ( in_array( get_option( 'default_category' ), $this->model->term->get_translations( $term_id ) ) ) { - $out .= sprintf( '', intval( $term_id ) ); - } + if ( empty( $language ) ) { + return $out; } - // link to edit term ( or a translation ) + if ( $column == $this->get_first_language_column() ) { + $out = sprintf( '', intval( $term_id ), esc_html( $lang->slug ) ); + } + + // Link to edit term ( or a translation ) if ( ( $id = $this->model->term->get( $term_id, $language ) ) && $term = get_term( $id, $taxonomy ) ) { if ( $link = get_edit_term_link( $id, $taxonomy, $post_type ) ) { + $flag = ''; if ( $id === $term_id ) { - $class = 'pll_icon_tick'; + $flag = $this->get_flag_html( $language ); + $class = 'pll_column_flag'; /* translators: accessibility text, %s is a native language name */ $s = sprintf( __( 'Edit this item in %s', 'polylang' ), $language->name ); } else { @@ -250,19 +319,24 @@ class PLL_Admin_Filters_Columns { $s = sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ); } $out .= sprintf( - '%4$s', - $class, esc_attr( $term->name ), esc_url( $link ), esc_html( $s ) + '%4$s%5$s', + $class, + esc_attr( $term->name ), + esc_url( $link ), + esc_html( $s ), + $flag // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped ); } elseif ( $id === $term_id ) { - $out .= printf( - '%s', + $out .= sprintf( + '%1$s%2$s', /* translators: accessibility text, %s is a native language name */ - esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ) + esc_html( sprintf( __( 'This item is in %s', 'polylang' ), $language->name ) ), + $this->get_flag_html( $language ) // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped ); } } - // link to add a new translation + // Link to add a new translation else { $out .= $this->links->new_term_translation_link( $term_id, $taxonomy, $post_type, $language ); } @@ -271,26 +345,36 @@ class PLL_Admin_Filters_Columns { } /** - * update rows of translated posts when the language is modified in quick edit + * Update rows of translated posts when the language is modified in quick edit * * @since 1.7 + * + * @return void */ public function ajax_update_post_rows() { - global $wp_list_table; - - if ( ! post_type_exists( $post_type = $_POST['post_type'] ) || ! $this->model->is_translated_post_type( $post_type ) ) { - die( 0 ); - } - check_ajax_referer( 'inlineeditnonce', '_pll_nonce' ); - $x = new WP_Ajax_Response(); - $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) ); + if ( ! isset( $_POST['post_type'], $_POST['post_id'], $_POST['screen'] ) ) { + wp_die( 0 ); + } - $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations - $translations = array_merge( $translations, array( $_POST['post_id'] ) ); // add current post + $post_type = sanitize_key( $_POST['post_type'] ); + + if ( ! post_type_exists( $post_type ) || ! $this->model->is_translated_post_type( $post_type ) ) { + wp_die( 0 ); + } + + /** @var WP_Posts_List_Table $wp_list_table */ + $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) ); + + $x = new WP_Ajax_Response(); + + // Collect old translations + $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $translations = array_map( 'intval', $translations ); + $translations = array_merge( $translations, array( (int) $_POST['post_id'] ) ); // Add current post + foreach ( $translations as $post_id ) { $level = is_post_type_hierarchical( $post_type ) ? count( get_ancestors( $post_id, $post_type ) ) : 0; if ( $post = get_post( $post_id ) ) { @@ -305,27 +389,37 @@ class PLL_Admin_Filters_Columns { } /** - * update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit + * Update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit * * @since 1.7 + * + * @return void */ public function ajax_update_term_rows() { - global $wp_list_table; - - if ( ! taxonomy_exists( $taxonomy = $_POST['taxonomy'] ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) { - die( 0 ); - } - check_ajax_referer( 'pll_language', '_pll_nonce' ); - $x = new WP_Ajax_Response(); - $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) ); + if ( ! isset( $_POST['taxonomy'], $_POST['term_id'], $_POST['screen'] ) ) { + wp_die( 0 ); + } - $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // collect old translations - $translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // add current translations - $translations = array_unique( $translations ); // remove duplicates + $taxonomy = sanitize_key( $_POST['taxonomy'] ); + + if ( ! taxonomy_exists( $taxonomy ) || ! $this->model->is_translated_taxonomy( $taxonomy ) ) { + wp_die( 0 ); + } + + /** @var WP_Terms_List_Table $wp_list_table */ + $wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => sanitize_key( $_POST['screen'] ) ) ); + + $x = new WP_Ajax_Response(); + + // Collect old translations + $translations = empty( $_POST['translations'] ) ? array() : explode( ',', $_POST['translations'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $translations = array_map( 'intval', $translations ); + $translations = array_merge( $translations, $this->model->term->get_translations( (int) $_POST['term_id'] ) ); // Add current translations + $translations = array_unique( $translations ); // Remove duplicates + foreach ( $translations as $term_id ) { $level = is_taxonomy_hierarchical( $taxonomy ) ? count( get_ancestors( $term_id, $taxonomy ) ) : 0; if ( $tag = get_term( $term_id, $taxonomy ) ) { @@ -338,4 +432,16 @@ class PLL_Admin_Filters_Columns { $x->send(); } + + /** + * Returns the language flag or teh language slug if there is no flag. + * + * @since 2.8 + * + * @param PLL_Language $language PLL_Language object. + * @return string + */ + protected function get_flag_html( $language ) { + return $language->flag ? $language->flag : sprintf( '%s', esc_html( $language->slug ) ); + } } diff --git a/wp-content/plugins/polylang/admin/admin-filters-media.php b/wp-content/plugins/polylang/admin/admin-filters-media.php index 99ce7997..cef96b16 100644 --- a/wp-content/plugins/polylang/admin/admin-filters-media.php +++ b/wp-content/plugins/polylang/admin/admin-filters-media.php @@ -1,4 +1,7 @@ posts = &$polylang->posts; + // Adds the language field and translations tables in the 'Edit Media' panel add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); // Adds actions related to languages when creating, saving or deleting media - add_action( 'add_attachment', array( $this, 'set_default_language' ) ); add_filter( 'attachment_fields_to_save', array( $this, 'save_media' ), 10, 2 ); - add_filter( 'wp_delete_file', array( $this, 'wp_delete_file' ) ); // Creates a media translation - if ( isset( $_GET['action'], $_GET['new_lang'], $_GET['from_media'] ) && 'translate_media' === $_GET['action'] ) { + if ( isset( $_GET['action'], $_GET['new_lang'], $_GET['from_media'] ) && 'translate_media' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification add_action( 'admin_init', array( $this, 'translate_media' ) ); } } /** - * Adds the language field and translations tables in the 'Edit Media' panel + * Adds the language field and translations tables in the 'Edit Media' panel. * Needs WP 3.5+ * * @since 0.9 * - * @param array $fields list of form fields - * @param object $post - * @return array modified list of form fields + * @param array $fields List of form fields. + * @param WP_Post $post The attachment being edited. + * @return array Modified list of form fields. */ public function attachment_fields_to_edit( $fields, $post ) { if ( 'post.php' == $GLOBALS['pagenow'] ) { @@ -53,91 +61,45 @@ class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base { $fields['language'] = array( 'label' => __( 'Language', 'polylang' ), 'input' => 'html', - 'html' => $dropdown->walk( $this->model->get_languages_list(), array( - 'name' => sprintf( 'attachments[%d][language]', $post_id ), - 'class' => 'media_lang_choice', - 'selected' => $lang ? $lang->slug : '', - ) ), + 'html' => $dropdown->walk( + $this->model->get_languages_list(), + -1, + array( + 'name' => sprintf( 'attachments[%d][language]', $post_id ), + 'class' => 'media_lang_choice', + 'selected' => $lang ? $lang->slug : '', + ) + ), ); return $fields; } - /** - * Creates a media translation - * - * @since 1.8 - * - * @param int $post_id - * @param string|object $lang - * @return int id of the translated media - */ - public function create_media_translation( $post_id, $lang ) { - $post = get_post( $post_id ); - - if ( empty( $post ) ) { - return $post; - } - - $lang = $this->model->get_language( $lang ); // Make sure we get a valid language slug - - // Create a new attachment ( translate attachment parent if exists ) - $post->ID = null; // Will force the creation - $post->post_parent = ( $post->post_parent && $tr_parent = $this->model->post->get_translation( $post->post_parent, $lang->slug ) ) ? $tr_parent : 0; - $post->tax_input = array( 'language' => array( $lang->slug ) ); // Assigns the language - $tr_id = wp_insert_attachment( $post ); - - // Copy metadata, attached file and alternative text - foreach ( array( '_wp_attachment_metadata', '_wp_attached_file', '_wp_attachment_image_alt' ) as $key ) { - if ( $meta = get_post_meta( $post_id, $key, true ) ) { - add_post_meta( $tr_id, $key, $meta ); - } - } - - $this->model->post->set_language( $tr_id, $lang ); - - $translations = $this->model->post->get_translations( $post_id ); - if ( ! $translations && $src_lang = $this->model->post->get_language( $post_id ) ) { - $translations[ $src_lang->slug ] = $post_id; - } - - $translations[ $lang->slug ] = $tr_id; - $this->model->post->save_translations( $tr_id, $translations ); - - /** - * Fires after a media translation is created - * - * @since 1.6.4 - * - * @param int $post_id post id of the source media - * @param int $tr_id post id of the new media translation - * @param string $slug language code of the new translation - */ - do_action( 'pll_translate_media', $post_id, $tr_id, $lang->slug ); - return $tr_id; - } - /** * Creates a media translation * * @since 0.9 + * + * @return void */ public function translate_media() { - // Security check - check_admin_referer( 'translate_media' ); - $post_id = (int) $_GET['from_media']; + if ( isset( $_GET['from_media'], $_GET['new_lang'] ) ) { + // Security check + check_admin_referer( 'translate_media' ); + $post_id = (int) $_GET['from_media']; - // Bails if the translations already exists - // See https://wordpress.org/support/topic/edit-translation-in-media-attachments?#post-7322303 - // Or if the source media does not exist - if ( $this->model->post->get_translation( $post_id, $_GET['new_lang'] ) || ! get_post( $post_id ) ) { - wp_safe_redirect( wp_get_referer() ); + // Bails if the translations already exists + // See https://wordpress.org/support/topic/edit-translation-in-media-attachments?#post-7322303 + // Or if the source media does not exist + if ( $this->model->post->get_translation( $post_id, sanitize_key( $_GET['new_lang'] ) ) || ! get_post( $post_id ) ) { + wp_safe_redirect( wp_get_referer() ); + exit; + } + + $tr_id = $this->posts->create_media_translation( $post_id, sanitize_key( $_GET['new_lang'] ) ); + wp_safe_redirect( admin_url( sprintf( 'post.php?post=%d&action=edit', $tr_id ) ) ); // WP 3.5+ exit; } - - $tr_id = $this->create_media_translation( $post_id, $_GET['new_lang'] ); - wp_safe_redirect( admin_url( sprintf( 'post.php?post=%d&action=edit', $tr_id ) ) ); // WP 3.5+ - exit; } /** @@ -153,43 +115,10 @@ class PLL_Admin_Filters_Media extends PLL_Admin_Filters_Post_Base { public function save_media( $post, $attachment ) { // Language is filled in attachment by the function applying the filter 'attachment_fields_to_save' // All security checks have been done by functions applying this filter - if ( ! empty( $attachment['language'] ) ) { - $this->model->post->set_language( $post['ID'], $attachment['language'] ); - } - - if ( isset( $_POST['media_tr_lang'] ) ) { - $this->save_translations( $post['ID'], $_POST['media_tr_lang'] ); + if ( ! empty( $attachment['language'] ) && current_user_can( 'edit_post', $post['ID'] ) ) { + $this->model->post->update_language( $post['ID'], $this->model->get_language( $attachment['language'] ) ); } return $post; } - - /** - * Prevents WP deleting files when there are still media using them - * Thanks to Bruno "Aesqe" Babic and its plugin file gallery in which I took all the ideas for this function - * - * @since 0.9 - * - * @param string $file - * @return string unmodified $file - */ - public function wp_delete_file( $file ) { - global $wpdb; - - $uploadpath = wp_upload_dir(); - - $ids = $wpdb->get_col( $wpdb->prepare( " - SELECT post_id FROM $wpdb->postmeta - WHERE meta_key = '_wp_attached_file' AND meta_value = %s", - substr_replace( $file, '', 0, strlen( trailingslashit( $uploadpath['basedir'] ) ) ) - ) ); - - if ( ! empty( $ids ) ) { - // Regenerate intermediate sizes if it's an image ( since we could not prevent WP deleting them before ) - wp_update_attachment_metadata( $ids[0], wp_generate_attachment_metadata( $ids[0], $file ) ); - return ''; // Prevent deleting the main file - } - - return $file; - } } diff --git a/wp-content/plugins/polylang/admin/admin-filters-post-base.php b/wp-content/plugins/polylang/admin/admin-filters-post-base.php index b6ed5009..e8a3d9ef 100644 --- a/wp-content/plugins/polylang/admin/admin-filters-post-base.php +++ b/wp-content/plugins/polylang/admin/admin-filters-post-base.php @@ -1,15 +1,33 @@ model->post->get_language( $post_id ) ) { - if ( isset( $_GET['new_lang'] ) && $lang = $this->model->get_language( $_GET['new_lang'] ) ) { - $this->model->post->set_language( $post_id, $lang ); - } - - elseif ( ( $parent_id = wp_get_post_parent_id( $post_id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) { - $this->model->post->set_language( $post_id, $parent_lang ); - } - - else { - $this->model->post->set_language( $post_id, $this->pref_lang ); - } - } - } - - /** - * save translations from language metabox - * - * @since 1.5 - * - * @param int $post_id - * @param array $arr - * @return array + * @param int $post_id Post id of the post being saved. + * @param int[] $arr An array with language codes as key and post id as value. + * @return int[] The array of translated post ids. */ protected function save_translations( $post_id, $arr ) { - // security check - // as 'wp_insert_post' can be called from outside WP admin + // Security check as 'wp_insert_post' can be called from outside WP admin. check_admin_referer( 'pll_language', '_pll_nonce' ); - // save translations after checking the translated post is in the right language - foreach ( $arr as $lang => $tr_id ) { - $translations[ $lang ] = ( $tr_id && $this->model->post->get_language( (int) $tr_id )->slug == $lang ) ? (int) $tr_id : 0; - } - - $this->model->post->save_translations( $post_id, $translations ); + $translations = $this->model->post->save_translations( $post_id, $arr ); return $translations; } } diff --git a/wp-content/plugins/polylang/admin/admin-filters-post.php b/wp-content/plugins/polylang/admin/admin-filters-post.php index b8dc42b3..bb1d651f 100644 --- a/wp-content/plugins/polylang/admin/admin-filters-post.php +++ b/wp-content/plugins/polylang/admin/admin-filters-post.php @@ -1,4 +1,7 @@ options = &$polylang->options; $this->curlang = &$polylang->curlang; add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); @@ -25,27 +32,10 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { // Filters posts, pages and media by language add_action( 'parse_query', array( $this, 'parse_query' ) ); - // Adds the Languages box in the 'Edit Post' and 'Edit Page' panels - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 ); - - // Ajax response for changing the language in the post metabox - add_action( 'wp_ajax_post_lang_choice', array( $this, 'post_lang_choice' ) ); - add_action( 'wp_ajax_pll_posts_not_translated', array( $this, 'ajax_posts_not_translated' ) ); - // Adds actions and filters related to languages when creating, saving or deleting posts and pages add_action( 'load-post.php', array( $this, 'edit_post' ) ); add_action( 'load-edit.php', array( $this, 'bulk_edit_posts' ) ); add_action( 'wp_ajax_inline-save', array( $this, 'inline_edit_post' ), 0 ); // Before WordPress - add_action( 'save_post', array( $this, 'save_post' ), 21, 3 ); // Priority 21 to come after advanced custom fields ( 20 ) and before the event calendar which breaks everything after 25 - add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 4 ); - add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 4 ); - add_action( 'before_delete_post', array( $this, 'delete_post' ) ); - if ( $this->options['media_support'] ) { - add_action( 'delete_attachment', array( $this, 'delete_post' ) ); // Action shared with media - } - - // Filters the pages by language in the parent dropdown list in the page attributes metabox - add_filter( 'page_attributes_dropdown_pages_args', array( $this, 'page_attributes_dropdown_pages_args' ), 10, 2 ); // Sets the language in Tiny MCE add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_before_init' ) ); @@ -58,13 +48,20 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { * to filter the parent dropdown per post language in quick edit * * @since 1.7 + * + * @return void */ public function admin_enqueue_scripts() { $screen = get_current_screen(); + if ( empty( $screen ) ) { + return; + } + // Hierarchical taxonomies if ( 'edit' == $screen->base && $taxonomies = get_object_taxonomies( $screen->post_type, 'object' ) ) { // Get translated hierarchical taxonomies + $hierarchical_taxonomies = array(); foreach ( $taxonomies as $taxonomy ) { if ( $taxonomy->hierarchical && $taxonomy->show_in_quick_edit && $this->model->is_translated_taxonomy( $taxonomy->name ) ) { $hierarchical_taxonomies[] = $taxonomy->name; @@ -72,11 +69,14 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { } if ( ! empty( $hierarchical_taxonomies ) ) { - $terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) ); + $terms = get_terms( $hierarchical_taxonomies, array( 'get' => 'all' ) ); + $term_languages = array(); - foreach ( $terms as $term ) { - if ( $lang = $this->model->term->get_language( $term->term_id ) ) { - $term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id; + if ( is_array( $terms ) ) { + foreach ( $terms as $term ) { + if ( $lang = $this->model->term->get_language( $term->term_id ) ) { + $term_languages[ $lang->slug ][ $term->taxonomy ][] = $term->term_id; + } } } @@ -89,7 +89,11 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { // Hierarchical post types if ( 'edit' == $screen->base && is_post_type_hierarchical( $screen->post_type ) ) { - $pages = get_pages(); + $pages = get_pages( array( 'sort_column' => 'menu_order, post_title' ) ); // Same arguments as the parent pages dropdown to avoid an extra query. + + update_post_caches( $pages, $screen->post_type, true, false ); + + $page_languages = array(); foreach ( $pages as $page ) { if ( $lang = $this->model->post->get_language( $page->ID ) ) { @@ -105,288 +109,46 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { } /** - * Filters posts, pages and media by language + * Filters posts, pages and media by language. * * @since 0.1 * - * @param object $query a WP_Query object + * @param WP_Query $query WP_Query object. + * @return void */ public function parse_query( $query ) { $pll_query = new PLL_Query( $query, $this->model ); $pll_query->filter_query( $this->curlang ); } - /** - * Adds the Language box in the 'Edit Post' and 'Edit Page' panels ( as well as in custom post types panels ) - * - * @since 0.1 - * - * @param string $post_type Current post type - * @param object $post Current post - */ - public function add_meta_boxes( $post_type, $post ) { - if ( $this->model->is_translated_post_type( $post_type ) ) { - add_meta_box( 'ml_box', __( 'Languages', 'polylang' ), array( $this, 'post_language' ), $post_type, 'side', 'high' ); - } - } - - /** - * Displays the Languages metabox in the 'Edit Post' and 'Edit Page' panels - * - * @since 0.1 - */ - public function post_language() { - global $post_ID; - $post_id = $post_ID; - $post_type = get_post_type( $post_ID ); - - $lang = ( $lg = $this->model->post->get_language( $post_ID ) ) ? $lg : - ( isset( $_GET['new_lang'] ) ? $this->model->get_language( $_GET['new_lang'] ) : - $this->pref_lang ); - - $dropdown = new PLL_Walker_Dropdown(); - - wp_nonce_field( 'pll_language', '_pll_nonce' ); - - // NOTE: the class "tags-input" allows to include the field in the autosave $_POST ( see autosave.js ) - printf( ' -

%1$s

- -
%4$s
', - esc_html__( 'Language', 'polylang' ), - $id = ( 'attachment' === $post_type ) ? sprintf( 'attachments[%d][language]', $post_ID ) : 'post_lang_choice', - 'attachment' === $post_type ? 'media' : 'post', - $dropdown->walk( $this->model->get_languages_list(), array( - 'name' => $id, - 'class' => 'post_lang_choice tags-input', - 'selected' => $lang ? $lang->slug : '', - 'flag' => true, - ) ) - ); - - /** - * Fires before displaying the list of translations in the Languages metabox for posts - * - * @since 1.8 - */ - do_action( 'pll_before_post_translations', $post_type ); - - echo '
'; - if ( $lang ) { - include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php'; - } - echo '
' . "\n"; - } - - /** - * Ajax response for changing the language in the post metabox - * - * @since 0.2 - */ - public function post_lang_choice() { - check_ajax_referer( 'pll_language', '_pll_nonce' ); - - global $post_ID; // Obliged to use the global variable for wp_popular_terms_checklist - $post_id = $post_ID = (int) $_POST['post_id']; - $lang = $this->model->get_language( $_POST['lang'] ); - - $post_type = $_POST['post_type']; - $post_type_object = get_post_type_object( $post_type ); - if ( ! current_user_can( $post_type_object->cap->edit_post, $post_ID ) ) { - wp_die( -1 ); - } - - $this->model->post->set_language( $post_ID, $lang ); // Save language, useful to set the language when uploading media from post - - ob_start(); - if ( $lang ) { - include PLL_ADMIN_INC . '/view-translations-' . ( 'attachment' == $post_type ? 'media' : 'post' ) . '.php'; - } - $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) ); - ob_end_clean(); - - // Categories - if ( isset( $_POST['taxonomies'] ) ) { - // Not set for pages - foreach ( $_POST['taxonomies'] as $taxname ) { - $taxonomy = get_taxonomy( $taxname ); - - ob_start(); - $popular_ids = wp_popular_terms_checklist( $taxonomy->name ); - $supplemental['populars'] = ob_get_contents(); - ob_end_clean(); - - ob_start(); - // Use $post_ID to remember checked terms in case we come back to the original language - wp_terms_checklist( $post_ID, array( 'taxonomy' => $taxonomy->name, 'popular_cats' => $popular_ids ) ); - $supplemental['all'] = ob_get_contents(); - ob_end_clean(); - - $supplemental['dropdown'] = wp_dropdown_categories( array( - 'taxonomy' => $taxonomy->name, - 'hide_empty' => 0, - 'name' => 'new' . $taxonomy->name . '_parent', - 'orderby' => 'name', - 'hierarchical' => 1, - 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', - 'echo' => 0, - ) ); - - $x->Add( array( 'what' => 'taxonomy', 'data' => $taxonomy->name, 'supplemental' => $supplemental ) ); - } - } - - // Parent dropdown list ( only for hierarchical post types ) - if ( in_array( $post_type, get_post_types( array( 'hierarchical' => true ) ) ) ) { - $post = get_post( $post_ID ); - - // Args and filter from 'page_attributes_meta_box' in wp-admin/includes/meta-boxes.php of WP 4.2.1 - $dropdown_args = array( - 'post_type' => $post->post_type, - 'exclude_tree' => $post->ID, - 'selected' => $post->post_parent, - 'name' => 'parent_id', - 'show_option_none' => __( '(no parent)' ), - 'sort_column' => 'menu_order, post_title', - 'echo' => 0, - ); - - /** This filter is documented in wp-admin/includes/meta-boxes.php */ - $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post ); // Since WP 3.3 - - $x->Add( array( 'what' => 'pages', 'data' => wp_dropdown_pages( $dropdown_args ) ) ); - } - - // Flag - $x->Add( array( 'what' => 'flag', 'data' => empty( $lang->flag ) ? esc_html( $lang->slug ) : $lang->flag ) ); - - // Sample permalink - $x->Add( array( 'what' => 'permalink', 'data' => get_sample_permalink_html( $post_ID ) ) ); - - $x->send(); - } - - /** - * Ajax response for input in translation autocomplete input box - * - * @since 1.5 - */ - public function ajax_posts_not_translated() { - check_ajax_referer( 'pll_language', '_pll_nonce' ); - - if ( ! post_type_exists( $_GET['post_type'] ) ) { - die( 0 ); - } - - $post_language = $this->model->get_language( $_GET['post_language'] ); - $translation_language = $this->model->get_language( $_GET['translation_language'] ); - - // Don't order by title: see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough - $args = array( - 's' => wp_unslash( $_GET['term'] ), - 'suppress_filters' => 0, // To make the post_fields filter work - 'lang' => 0, // Avoid admin language filter - 'numberposts' => 20, // Limit to 20 posts - 'post_status' => 'any', - 'post_type' => $_GET['post_type'], - 'tax_query' => array( - array( - 'taxonomy' => 'language', - 'field' => 'term_taxonomy_id', // WP 3.5+ - 'terms' => $translation_language->term_taxonomy_id, - ), - ), - ); - - /** - * Filter the query args when auto suggesting untranslated posts in the Languages metabox - * This should help plugins to fix some edge cases - * - * @see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough - * - * @since 1.7 - * - * @param array $args WP_Query arguments - */ - $args = apply_filters( 'pll_ajax_posts_not_translated_args', $args ); - $posts = get_posts( $args ); - - $return = array(); - - foreach ( $posts as $key => $post ) { - if ( ! $this->model->post->get_translation( $post->ID, $post_language ) ) { - $return[] = array( - 'id' => $post->ID, - 'value' => $post->post_title, - 'link' => $this->links->edit_post_translation_link( $post->ID ), - ); - } - } - - // Add current translation in list - if ( $post_id = $this->model->post->get_translation( (int) $_GET['pll_post_id'], $translation_language ) ) { - $post = get_post( $post_id ); - array_unshift( $return, array( - 'id' => $post_id, - 'value' => $post->post_title, - 'link' => $this->links->edit_post_translation_link( $post_id ), - ) ); - } - - wp_die( json_encode( $return ) ); - } - /** * Save language and translation when editing a post (post.php) * * @since 2.3 + * + * @return void */ public function edit_post() { - if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) { + if ( isset( $_POST['post_lang_choice'], $_POST['post_ID'] ) && $post_id = (int) $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification check_admin_referer( 'pll_language', '_pll_nonce' ); $post = get_post( $post_id ); + + if ( empty( $post ) ) { + return; + } + $post_type_object = get_post_type_object( $post->post_type ); + if ( empty( $post_type_object ) ) { + return; + } + if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) { - $this->model->post->set_language( $post_id, $this->model->get_language( $_POST['post_lang_choice'] ) ); + $this->model->post->set_language( $post_id, $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ); if ( isset( $_POST['post_tr_lang'] ) ) { - $this->save_translations( $post_id, $_POST['post_tr_lang'] ); - } - } - } - } - - /** - * Save language when inline editing or bulk editing a post - * Fix translations if necessary - * - * @since 2.3 - * - * @param int $post_id Post ID - * @param object $lang Language - */ - protected function inline_save_language( $post_id, $lang ) { - $post = get_post( $post_id ); - $post_type_object = get_post_type_object( $post->post_type ); - - if ( current_user_can( $post_type_object->cap->edit_post, $post_id ) ) { - $old_lang = $this->model->post->get_language( $post_id ); // Stores the old language - $this->model->post->set_language( $post_id, $lang ); // set new language - - // Checks if the new language already exists in the translation group - if ( $old_lang && $old_lang->slug != $lang->slug ) { - $translations = $this->model->post->get_translations( $post_id ); - - // If yes, separate this post from the translation group - if ( array_key_exists( $lang->slug, $translations ) ) { - $this->model->post->delete_translation( $post_id ); - } - - elseif ( array_key_exists( $old_lang->slug, $translations ) ) { - unset( $translations[ $old_lang->slug ] ); - $this->model->post->save_translations( $post_id, $translations ); + $this->save_translations( $post_id, array_map( 'absint', $_POST['post_tr_lang'] ) ); } } } @@ -396,15 +158,19 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { * Save language when bulk editing a post * * @since 2.3 + * + * @return void */ public function bulk_edit_posts() { - if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) && -1 !== $_GET['inline_lang_choice'] ) { + if ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'], $_REQUEST['post'] ) && -1 !== $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification check_admin_referer( 'bulk-posts' ); - if ( $lang = $this->model->get_language( $_GET['inline_lang_choice'] ) ) { + if ( $lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ) ) { $post_ids = array_map( 'intval', (array) $_REQUEST['post'] ); foreach ( $post_ids as $post_id ) { - $this->inline_save_language( $post_id, $lang ); + if ( current_user_can( 'edit_post', $post_id ) ) { + $this->model->post->update_language( $post_id, $lang ); + } } } } @@ -414,176 +180,21 @@ class PLL_Admin_Filters_Post extends PLL_Admin_Filters_Post_Base { * Save language when inline editing a post * * @since 2.3 + * + * @return void */ public function inline_edit_post() { check_admin_referer( 'inlineeditnonce', '_inline_edit' ); if ( isset( $_POST['post_ID'], $_POST['inline_lang_choice'] ) ) { $post_id = (int) $_POST['post_ID']; - $lang = $this->model->get_language( $_POST['inline_lang_choice'] ); - if ( $post_id && $lang ) { - $this->inline_save_language( $post_id, $lang ); + $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ); + if ( $post_id && $lang && current_user_can( 'edit_post', $post_id ) ) { + $this->model->post->update_language( $post_id, $lang ); } } } - /** - * Called when a post ( or page ) is saved, published or updated - * - * @since 0.1 - * @since 2.3 Does not save the language and translations anymore, unless the post has no language yet - * - * @param int $post_id - * @param object $post - * @param bool $update Whether it is an update or not - */ - public function save_post( $post_id, $post, $update ) { - // Does nothing except on post types which are filterable - if ( $this->model->is_translated_post_type( $post->post_type ) ) { - if ( $id = wp_is_post_revision( $post_id ) ) { - $post_id = $id; - } - - $lang = $this->model->post->get_language( $post_id ); - - if ( empty( $lang ) ) { - $this->set_default_language( $post_id ); - } - - /** - * Fires after the post language and translations are saved - * - * @since 1.2 - * - * @param int $post_id Post id - * @param object $post Post object - * @param array $translations The list of translations post ids - */ - do_action( 'pll_save_post', $post_id, $post, $this->model->post->get_translations( $post_id ) ); - } - } - - /** - * Make sure saved terms are in the right language (especially tags with same name in different languages) - * - * @since 2.3 - * - * @param int $object_id Object ID. - * @param array $terms An array of object terms. - * @param array $tt_ids An array of term taxonomy IDs. - * @param string $taxonomy Taxonomy slug. - */ - public function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy ) { - static $avoid_recursion; - - if ( ! $avoid_recursion && $this->model->is_translated_taxonomy( $taxonomy ) && ! empty( $terms ) ) { - $lang = $this->model->post->get_language( $object_id ); - - if ( ! empty( $lang ) && is_array( $terms ) ) { - // Convert to term ids if we got tag names - $strings = array_filter( $terms, 'is_string' ); - if ( ! empty( $strings ) ) { - $_terms = get_terms( $taxonomy, array( 'name' => $strings, 'object_ids' => $object_id, 'fields' => 'ids' ) ); - $terms = array_merge( array_diff( $terms, $strings ), $_terms ); - } - - $term_ids = array_combine( $terms, $terms ); - $languages = array_map( array( $this->model->term, 'get_language' ), $term_ids ); - $languages = wp_list_pluck( $languages, 'slug' ); - $wrong_terms = array_diff( $languages, array( $lang->slug ) ); - - if ( ! empty( $wrong_terms ) ) { - // We got terms in a wrong language - $wrong_term_ids = array_keys( $wrong_terms ); - $terms = get_the_terms( $object_id, $taxonomy ); - wp_remove_object_terms( $object_id, $wrong_term_ids, $taxonomy ); - - if ( is_array( $terms ) ) { - $newterms = array(); - - foreach ( $terms as $term ) { - if ( in_array( $term->term_id, $wrong_term_ids ) ) { - // Check if the term is in the correct language or if a translation exist ( mainly for default category ) - if ( $newterm = $this->model->term->get( $term->term_id, $lang ) ) { - $newterms[] = (int) $newterm; - } - - // Or choose the correct language for tags ( initially defined by name ) - elseif ( $newterm = $this->model->term_exists( $term->name, $taxonomy, $term->parent, $lang ) ) { - $newterms[] = (int) $newterm; // Cast is important otherwise we get 'numeric' tags - } - - // Or create the term in the correct language - elseif ( ! is_wp_error( $term_info = wp_insert_term( $term->name, $taxonomy ) ) ) { - $newterms[] = (int) $term_info['term_id']; - } - } - } - - $avoid_recursion = true; - wp_set_object_terms( $object_id, array_unique( $newterms ), $taxonomy, true ); // Append - $avoid_recursion = false; - } - } - } - } - } - - /** - * Make sure that the post parent is in the correct language when using bulk edit - * - * @since 1.8 - * - * @param int $post_parent Post parent ID. - * @param int $post_id Post ID. - * @param array $new_postarr Array of parsed post data. - * @param array $postarr Array of sanitized, but otherwise unmodified post data. - * @return int - */ - public function wp_insert_post_parent( $post_parent, $post_id, $new_postarr, $postarr ) { - if ( isset( $postarr['bulk_edit'] ) ) { - check_admin_referer( 'bulk-posts' ); - $lang = -1 == $postarr['inline_lang_choice'] ? - $this->model->post->get_language( $post_id ) : - $this->model->get_language( $postarr['inline_lang_choice'] ); - $post_parent = $this->model->post->get_translation( $post_parent, $lang ); - } - return $post_parent; - } - - /** - * Called when a post, page or media is deleted - * Don't delete translations if this is a post revision thanks to AndyDeGroo who catched this bug - * http://wordpress.org/support/topic/plugin-polylang-quick-edit-still-breaks-translation-linking-of-pages-in-072 - * - * @since 0.1 - * - * @param int $post_id - */ - public function delete_post( $post_id ) { - if ( ! wp_is_post_revision( $post_id ) ) { - $this->model->post->delete_translation( $post_id ); - } - } - - /** - * Filters the pages by language in the parent dropdown list in the page attributes metabox - * - * @since 0.6 - * - * @param array $dropdown_args Arguments passed to wp_dropdown_pages - * @param object $post - * @return array Modified arguments - */ - public function page_attributes_dropdown_pages_args( $dropdown_args, $post ) { - $dropdown_args['lang'] = isset( $_POST['lang'] ) ? $this->model->get_language( $_POST['lang'] ) : $this->model->post->get_language( $post->ID ); // ajax or not ? - if ( ! $dropdown_args['lang'] ) { - $dropdown_args['lang'] = $this->pref_lang; - } - - return $dropdown_args; - } - /** * Sets the language attribute and text direction for Tiny MCE * diff --git a/wp-content/plugins/polylang/admin/admin-filters-term.php b/wp-content/plugins/polylang/admin/admin-filters-term.php index 14362433..55cbd7d8 100644 --- a/wp-content/plugins/polylang/admin/admin-filters-term.php +++ b/wp-content/plugins/polylang/admin/admin-filters-term.php @@ -1,4 +1,7 @@ links = &$polylang->links; $this->model = &$polylang->model; $this->options = &$polylang->options; - $this->curlang = &$polylang->curlang; - $this->filter_lang = &$polylang->filter_lang; $this->pref_lang = &$polylang->pref_lang; + $this->default_term = &$polylang->default_term; foreach ( $this->model->get_translated_taxonomies() as $tax ) { // Adds the language field in the 'Categories' and 'Post Tags' panels @@ -30,15 +81,12 @@ class PLL_Admin_Filters_Term { // Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels add_action( $tax . '_edit_form_fields', array( $this, 'edit_term_form' ) ); - - // Adds action related to languages when deleting categories and post tags - add_action( 'delete_' . $tax, array( $this, 'delete_term' ) ); } // Adds actions related to languages when creating or saving categories and post tags add_filter( 'wp_dropdown_cats', array( $this, 'wp_dropdown_cats' ) ); - add_action( 'create_term', array( $this, 'save_term' ), 999, 3 ); - add_action( 'edit_term', array( $this, 'save_term' ), 999, 3 ); // late as it may conflict with other plugins, see http://wordpress.org/support/topic/polylang-and-wordpress-seo-by-yoast + add_action( 'create_term', array( $this, 'save_term' ), 900, 3 ); + add_action( 'edit_term', array( $this, 'save_term' ), 900, 3 ); // Late as it may conflict with other plugins, see http://wordpress.org/support/topic/polylang-and-wordpress-seo-by-yoast add_action( 'pre_post_update', array( $this, 'pre_post_update' ) ); add_filter( 'pre_term_name', array( $this, 'pre_term_name' ) ); add_filter( 'pre_term_slug', array( $this, 'pre_term_slug' ), 10, 2 ); @@ -47,18 +95,6 @@ class PLL_Admin_Filters_Term { add_action( 'wp_ajax_term_lang_choice', array( $this, 'term_lang_choice' ) ); add_action( 'wp_ajax_pll_terms_not_translated', array( $this, 'ajax_terms_not_translated' ) ); - // Adds cache domain when querying terms - add_filter( 'get_terms_args', array( $this, 'get_terms_args' ), 10, 2 ); - - // Filters categories and post tags by language - add_filter( 'terms_clauses', array( $this, 'terms_clauses' ), 10, 3 ); - add_action( 'parse_query', array( $this, 'set_tax_query_lang' ) ); - add_action( 'posts_selection', array( $this, 'unset_tax_query_lang' ) ); - - // Allows to get the default categories in all languages - add_filter( 'option_default_category', array( $this, 'option_default_category' ) ); - add_action( 'update_option_default_category', array( $this, 'update_option_default_category' ), 10, 2 ); - // Updates the translations term ids when splitting a shared term add_action( 'split_shared_term', array( $this, 'split_shared_term' ), 10, 4 ); // WP 4.2 } @@ -67,77 +103,117 @@ class PLL_Admin_Filters_Term { * Adds the language field in the 'Categories' and 'Post Tags' panels * * @since 0.1 + * + * @return void */ public function add_term_form() { - $taxonomy = $_GET['taxonomy']; - $post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type']; + if ( isset( $_GET['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $taxonomy = sanitize_key( $_GET['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification + } - if ( ! taxonomy_exists( $taxonomy ) || ! post_type_exists( $post_type ) ) { + if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification + } + + if ( isset( $GLOBALS['post_type'] ) ) { + $post_type = $GLOBALS['post_type']; + } + + if ( ! isset( $taxonomy, $post_type ) || ! taxonomy_exists( $taxonomy ) || ! post_type_exists( $post_type ) ) { return; } - $lang = isset( $_GET['new_lang'] ) ? $this->model->get_language( $_GET['new_lang'] ) : $this->pref_lang; + $from_term_id = isset( $_GET['from_tag'] ) ? (int) $_GET['from_tag'] : 0; // phpcs:ignore WordPress.Security.NonceVerification + + $lang = isset( $_GET['new_lang'] ) ? $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) : $this->pref_lang; // phpcs:ignore WordPress.Security.NonceVerification + $dropdown = new PLL_Walker_Dropdown(); + $dropdown_html = $dropdown->walk( + $this->model->get_languages_list(), + -1, + array( + 'name' => 'term_lang_choice', + 'value' => 'term_id', + 'selected' => $lang ? $lang->term_id : '', + 'flag' => true, + ) + ); + wp_nonce_field( 'pll_language', '_pll_nonce' ); - printf( ' -
+ printf( + '
%s

%s

', esc_html__( 'Language', 'polylang' ), - $dropdown->walk( $this->model->get_languages_list(), array( - 'name' => 'term_lang_choice', - 'value' => 'term_id', - 'selected' => $lang ? $lang->term_id : '', - 'flag' => true, - ) ), + $dropdown_html, // phpcs:ignore esc_html__( 'Sets the language', 'polylang' ) ); - if ( ! empty( $_GET['from_tag'] ) ) { - printf( '', (int) $_GET['from_tag'] ); + if ( ! empty( $from_term_id ) ) { + printf( '', (int) $from_term_id ); } // Adds translation fields echo '
'; if ( $lang ) { - include PLL_ADMIN_INC . '/view-translations-term.php'; + include __DIR__ . '/view-translations-term.php'; } echo '
' . "\n"; } /** - * Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels + * Adds the language field and translations tables in the 'Edit Category' and 'Edit Tag' panels. * * @since 0.1 * - * @param object $tag + * @param WP_Term $tag The term being edited. + * @return void */ public function edit_term_form( $tag ) { - $post_type = isset( $GLOBALS['post_type'] ) ? $GLOBALS['post_type'] : $_REQUEST['post_type']; + if ( isset( $_REQUEST['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $post_type = sanitize_key( $_REQUEST['post_type'] ); // phpcs:ignore WordPress.Security.NonceVerification + } - if ( ! post_type_exists( $post_type ) ) { + if ( isset( $GLOBALS['post_type'] ) ) { + $post_type = $GLOBALS['post_type']; + } + + if ( ! isset( $post_type ) || ! post_type_exists( $post_type ) ) { return; } - $term_id = $tag->term_id; - $taxonomy = $tag->taxonomy; + $term_id = $tag->term_id; + $taxonomy = $tag->taxonomy; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $lang = $this->model->term->get_language( $term_id ); $lang = empty( $lang ) ? $this->pref_lang : $lang; + // Disable the language dropdown and the translations input fields for default terms to prevent removal + $disabled = $this->default_term->is_default_term( $term_id ); + $dropdown = new PLL_Walker_Dropdown(); - // Disable the language dropdown and the translations input fields for default categories to prevent removal - $disabled = in_array( get_option( 'default_category' ), $this->model->term->get_translations( $term_id ) ); + $dropdown_html = $dropdown->walk( + $this->model->get_languages_list(), + -1, + array( + 'name' => 'term_lang_choice', + 'value' => 'term_id', + 'selected' => $lang->term_id, + 'disabled' => $disabled, + 'flag' => true, + ) + ); - printf( ' - + wp_nonce_field( 'pll_language', '_pll_nonce' ); + + printf( + ' - %s @@ -145,22 +221,13 @@ class PLL_Admin_Filters_Term {

%s

', - wp_nonce_field( 'pll_language', '_pll_nonce', true, false ), esc_html__( 'Language', 'polylang' ), - $dropdown->walk( $this->model->get_languages_list(), array( - 'name' => 'term_lang_choice', - 'value' => 'term_id', - 'selected' => $lang ? $lang->term_id : '', - 'disabled' => $disabled, - 'flag' => true, - ) ), + $dropdown_html, // phpcs:ignore esc_html__( 'Sets the language', 'polylang' ) ); echo ''; - if ( $lang ) { - include PLL_ADMIN_INC . '/view-translations-term.php'; - } + include __DIR__ . '/view-translations-term.php'; echo '' . "\n"; } @@ -173,10 +240,15 @@ class PLL_Admin_Filters_Term { * @return string modified html */ public function wp_dropdown_cats( $output ) { - if ( isset( $_GET['taxonomy'], $_GET['from_tag'], $_GET['new_lang'] ) && taxonomy_exists( $_GET['taxonomy'] ) ) { - $term = get_term( (int) $_GET['from_tag'], $_GET['taxonomy'] ); - if ( $term && $id = $term->parent ) { - $lang = $this->model->get_language( $_GET['new_lang'] ); + if ( isset( $_GET['taxonomy'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $taxonomy = sanitize_key( $_GET['taxonomy'] ); // phpcs:ignore WordPress.Security.NonceVerification + } + + if ( isset( $taxonomy, $_GET['from_tag'], $_GET['new_lang'] ) && taxonomy_exists( $taxonomy ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $term = get_term( (int) $_GET['from_tag'], $taxonomy ); // phpcs:ignore WordPress.Security.NonceVerification + + if ( $term instanceof WP_Term && $id = $term->parent ) { + $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); // phpcs:ignore WordPress.Security.NonceVerification if ( $parent = $this->model->term->get_translation( $id, $lang ) ) { return str_replace( '"' . $parent . '"', '"' . $parent . '" selected="selected"', $output ); } @@ -186,38 +258,19 @@ class PLL_Admin_Filters_Term { } /** - * stores the current post_id when bulk editing posts for use in save_language and pre_term_slug + * Stores the current post_id when bulk editing posts for use in save_language and pre_term_slug * * @since 1.7 * * @param int $post_id + * @return void */ public function pre_post_update( $post_id ) { - if ( isset( $_GET['bulk_edit'] ) ) { + if ( isset( $_GET['bulk_edit'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->post_id = $post_id; } } - /** - * Allows to set a language by default for terms if it has no language yet - * - * @since 1.5.4 - * - * @param int $term_id - * @param string $taxonomy - */ - protected function set_default_language( $term_id, $taxonomy ) { - if ( ! $this->model->term->get_language( $term_id ) ) { - // Sets language from term parent if exists thanks to Scott Kingsley Clark - if ( ( $term = get_term( $term_id, $taxonomy ) ) && ! empty( $term->parent ) && $parent_lang = $this->model->term->get_language( $term->parent ) ) { - $this->model->term->set_language( $term_id, $parent_lang ); - } - else { - $this->model->term->set_language( $term_id, $this->pref_lang ); - } - } - } - /** * Saves language * @@ -225,6 +278,7 @@ class PLL_Admin_Filters_Term { * * @param int $term_id * @param string $taxonomy + * @return void */ protected function save_language( $term_id, $taxonomy ) { global $wpdb; @@ -233,14 +287,13 @@ class PLL_Admin_Filters_Term { // Edit tags if ( isset( $_POST['term_lang_choice'] ) ) { - if ( 'add-' . $taxonomy == $_POST['action'] ) { - check_ajax_referer( $_POST['action'], '_ajax_nonce-add-' . $taxonomy ); // category metabox - } - else { - check_admin_referer( 'pll_language', '_pll_nonce' ); // edit tags or tags metabox + if ( isset( $_POST['action'] ) && sanitize_key( $_POST['action'] ) === 'add-' . $taxonomy ) { // phpcs:ignore WordPress.Security.NonceVerification + check_ajax_referer( 'add-' . $taxonomy, '_ajax_nonce-add-' . $taxonomy ); // Category metabox + } else { + check_admin_referer( 'pll_language', '_pll_nonce' ); // Edit tags or tags metabox } - $this->model->term->set_language( $term_id, $this->model->get_language( $_POST['term_lang_choice'] ) ); + $this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ); } // *Post* bulk edit, in case a new term is created @@ -259,17 +312,22 @@ class PLL_Admin_Filters_Term { // No WP function to get all terms with the exact same name so let's use a custom query // $terms = get_terms( $taxonomy, array( 'name' => $term->name, 'hide_empty' => false, 'fields' => 'ids' ) ); should be OK in 4.2 // I may need to rework the loop below - $terms = $wpdb->get_results( $wpdb->prepare( " - SELECT t.term_id FROM $wpdb->terms AS t - INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id - WHERE tt.taxonomy = %s AND t.name = %s", - $taxonomy, $term->name - ) ); + $terms = $wpdb->get_results( + $wpdb->prepare( + "SELECT t.term_id FROM $wpdb->terms AS t + INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id + WHERE tt.taxonomy = %s AND t.name = %s", + $taxonomy, + $term->name + ) + ); // If we have several terms with the same name, they are translations of each other if ( count( $terms ) > 1 ) { + $translations = array(); + foreach ( $terms as $term ) { - $translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id; + $translations[ $this->model->term->get_language( $term->term_id )->slug ] = $term->term_id; } $this->model->term->save_translations( $term_id, $translations ); @@ -277,7 +335,9 @@ class PLL_Admin_Filters_Term { } else { - $this->model->term->set_language( $term_id, $this->model->get_language( $_GET['inline_lang_choice'] ) ); + if ( current_user_can( 'edit_term', $term_id ) ) { + $this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ) ); + } } } @@ -288,52 +348,37 @@ class PLL_Admin_Filters_Term { '_inline_edit' ); - $old_lang = $this->model->term->get_language( $term_id ); // Stores the old language - $lang = $this->model->get_language( $_POST['inline_lang_choice'] ); // New language - $translations = $this->model->term->get_translations( $term_id ); - - // Checks if the new language already exists in the translation group - if ( $old_lang && $old_lang->slug != $lang->slug ) { - if ( array_key_exists( $lang->slug, $translations ) ) { - $this->model->term->delete_translation( $term_id ); - } - - elseif ( array_key_exists( $old_lang->slug, $translations ) ) { - unset( $translations[ $old_lang->slug ] ); - $this->model->term->save_translations( $term_id, $translations ); - } - } - - $this->model->term->set_language( $term_id, $lang ); // Set new language + $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ); + $this->model->term->update_language( $term_id, $lang ); } // Edit post elseif ( isset( $_POST['post_lang_choice'] ) ) { // FIXME should be useless now check_admin_referer( 'pll_language', '_pll_nonce' ); - $this->model->term->set_language( $term_id, $this->model->get_language( $_POST['post_lang_choice'] ) ); - } - - else { - $this->set_default_language( $term_id, $taxonomy ); + $this->model->term->set_language( $term_id, $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ); } } /** - * Save translations from our form + * Save translations from our form. * * @since 1.5 * - * @param int $term_id - * @return array + * @param int $term_id The term id of teh term being saved. + * @return int[] The array of translated term ids. */ protected function save_translations( $term_id ) { - // Security check as 'wp_update_term' can be called from outside WP admin + // Security check as 'wp_update_term' can be called from outside WP admin. check_admin_referer( 'pll_language', '_pll_nonce' ); - // Save translations after checking the translated term is in the right language ( as well as cast id to int ) - foreach ( $_POST['term_tr_lang'] as $lang => $tr_id ) { - $tr_lang = $this->model->term->get_language( (int) $tr_id ); - $translations[ $lang ] = $tr_lang && $tr_lang->slug == $lang ? (int) $tr_id : 0; + $translations = array(); + + // Save translations after checking the translated term is in the right language ( as well as cast id to int ). + if ( isset( $_POST['term_tr_lang'] ) ) { + foreach ( array_map( 'absint', $_POST['term_tr_lang'] ) as $lang => $tr_id ) { + $tr_lang = $this->model->term->get_language( $tr_id ); + $translations[ $lang ] = $tr_lang && $tr_lang->slug == $lang ? $tr_id : 0; + } } $this->model->term->save_translations( $term_id, $translations ); @@ -350,6 +395,7 @@ class PLL_Admin_Filters_Term { * @param int $term_id * @param int $tt_id term taxonomy id * @param string $taxonomy + * @return void */ public function save_term( $term_id, $tt_id, $taxonomy ) { // Does nothing except on taxonomies which are filterable @@ -357,32 +403,21 @@ class PLL_Admin_Filters_Term { return; } + $tax = get_taxonomy( $taxonomy ); + + if ( empty( $tax ) ) { + return; + } + // Capability check // As 'wp_update_term' can be called from outside WP admin // 2nd test for creating tags when creating / editing a post - $tax = get_taxonomy( $taxonomy ); - if ( current_user_can( $tax->cap->edit_terms ) || ( isset( $_POST['tax_input'][ $taxonomy ] ) && current_user_can( $tax->cap->assign_terms ) ) ) { + if ( current_user_can( $tax->cap->edit_terms ) || ( isset( $_POST['tax_input'][ $taxonomy ] ) && current_user_can( $tax->cap->assign_terms ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification $this->save_language( $term_id, $taxonomy ); - if ( isset( $_POST['term_tr_lang'] ) ) { - $translations = $this->save_translations( $term_id ); + if ( isset( $_POST['term_tr_lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->save_translations( $term_id ); } - - /** - * Fires after the term language and translations are saved - * - * @since 1.2 - * - * @param int $term_id term id - * @param string $taxonomy taxonomy name - * @param array $translations the list of translations term ids - */ - do_action( 'pll_save_term', $term_id, $taxonomy, empty( $translations ) ? $this->model->term->get_translations( $term_id ) : $translations ); - } - - // Attempts to set a default language even if no capability - else { - $this->set_default_language( $term_id, $taxonomy ); } } @@ -412,62 +447,57 @@ class PLL_Admin_Filters_Term { // If the term already exists in another language if ( ! $slug && $this->model->is_translated_taxonomy( $taxonomy ) && term_exists( $name, $taxonomy ) ) { - if ( isset( $_POST['term_lang_choice'] ) ) { - $slug = $name . '-' . $this->model->get_language( $_POST['term_lang_choice'] )->slug; + if ( isset( $_POST['term_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification } - elseif ( isset( $_POST['inline_lang_choice'] ) ) { - $slug = $name . '-' . $this->model->get_language( $_POST['inline_lang_choice'] )->slug; + elseif ( isset( $_POST['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification } // *Post* bulk edit, in case a new term is created - elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) { + elseif ( isset( $_GET['bulk_edit'], $_GET['inline_lang_choice'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification // Bulk edit does not modify the language - if ( -1 == $_GET['inline_lang_choice'] ) { - $slug = $name . '-' . $this->model->post->get_language( $this->post_id )->slug; + if ( -1 == $_GET['inline_lang_choice'] ) { // phpcs:ignore WordPress.Security.NonceVerification + $lang = $this->model->post->get_language( $this->post_id ); } else { - $slug = $name . '-' . $this->model->get_language( $_GET['inline_lang_choice'] )->slug; + $lang = $this->model->get_language( sanitize_key( $_GET['inline_lang_choice'] ) ); // phpcs:ignore WordPress.Security.NonceVerification } } + + if ( ! empty( $lang ) && ! $this->model->term_exists_by_slug( $name, $lang, $taxonomy ) ) { + $slug = $name . '-' . $lang->slug; + } } return $slug; } - /** - * Called when a category or post tag is deleted - * Deletes language and translations - * - * @since 0.1 - * - * @param int $term_id - */ - public function delete_term( $term_id ) { - $this->model->term->delete_translation( $term_id ); - $this->model->term->delete_language( $term_id ); - } - /** * Ajax response for edit term form * * @since 0.2 + * + * @return void */ public function term_lang_choice() { check_ajax_referer( 'pll_language', '_pll_nonce' ); - $lang = $this->model->get_language( $_POST['lang'] ); - $term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null; - $taxonomy = $_POST['taxonomy']; - $post_type = $_POST['post_type']; + if ( ! isset( $_POST['taxonomy'], $_POST['post_type'], $_POST['lang'] ) ) { + wp_die( 0 ); + } - if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { - die( 0 ); + $lang = $this->model->get_language( sanitize_key( $_POST['lang'] ) ); + $term_id = isset( $_POST['term_id'] ) ? (int) $_POST['term_id'] : null; // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + $taxonomy = sanitize_key( $_POST['taxonomy'] ); + $post_type = sanitize_key( $_POST['post_type'] ); + + if ( empty( $lang ) || ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { + wp_die( 0 ); } ob_start(); - if ( $lang ) { - include PLL_ADMIN_INC . '/view-translations-term.php'; - } + include __DIR__ . '/view-translations-term.php'; $x = new WP_Ajax_Response( array( 'what' => 'translations', 'data' => ob_get_contents() ) ); ob_end_clean(); @@ -475,14 +505,14 @@ class PLL_Admin_Filters_Term { // $args copied from edit_tags.php except echo if ( is_taxonomy_hierarchical( $taxonomy ) ) { $args = array( - 'hide_empty' => 0, - 'hide_if_empty' => false, - 'taxonomy' => $taxonomy, - 'name' => 'parent', - 'orderby' => 'name', - 'hierarchical' => true, - 'show_option_none' => __( 'None' ), - 'echo' => 0, + 'hide_empty' => 0, + 'hide_if_empty' => false, + 'taxonomy' => $taxonomy, + 'name' => 'parent', + 'orderby' => 'name', + 'hierarchical' => true, + 'show_option_none' => __( 'None', 'polylang' ), + 'echo' => 0, ); $x->Add( array( 'what' => 'parent', 'data' => wp_dropdown_categories( $args ) ) ); } @@ -491,7 +521,7 @@ class PLL_Admin_Filters_Term { // Tests copied from edit_tags.php else { $tax = get_taxonomy( $taxonomy ); - if ( ! is_null( $tax->labels->popular_items ) ) { + if ( ! empty( $tax ) && ! is_null( $tax->labels->popular_items ) ) { $args = array( 'taxonomy' => $taxonomy, 'echo' => false ); if ( current_user_can( $tax->cap->edit_terms ) ) { $args = array_merge( $args, array( 'link' => 'edit' ) ); @@ -514,202 +544,71 @@ class PLL_Admin_Filters_Term { * Ajax response for input in translation autocomplete input box * * @since 1.5 + * + * @return void */ public function ajax_terms_not_translated() { check_ajax_referer( 'pll_language', '_pll_nonce' ); - $s = wp_unslash( $_GET['term'] ); - $post_type = $_GET['post_type']; - $taxonomy = $_GET['taxonomy']; - - if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { - die( 0 ); + if ( ! isset( $_GET['term'], $_GET['post_type'], $_GET['taxonomy'], $_GET['term_language'], $_GET['translation_language'] ) ) { + wp_die( 0 ); } - $term_language = $this->model->get_language( $_GET['term_language'] ); - $translation_language = $this->model->get_language( $_GET['translation_language'] ); + /** @var string */ + $s = wp_unslash( $_GET['term'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput + $post_type = sanitize_key( $_GET['post_type'] ); + $taxonomy = sanitize_key( $_GET['taxonomy'] ); + if ( ! post_type_exists( $post_type ) || ! taxonomy_exists( $taxonomy ) ) { + wp_die( 0 ); + } + + $term_language = $this->model->get_language( sanitize_key( $_GET['term_language'] ) ); + $translation_language = $this->model->get_language( sanitize_key( $_GET['translation_language'] ) ); + + $terms = array(); $return = array(); - // It is more efficient to use one common query for all languages as soon as there are more than 2 - foreach ( get_terms( $taxonomy, 'hide_empty=0&lang=0&name__like=' . $s ) as $term ) { - $lang = $this->model->term->get_language( $term->term_id ); + // Add current translation in list. + // Not in add term as term_id is not set. + if ( isset( $_GET['term_id'] ) && 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) { + $terms = array( get_term( $term_id, $taxonomy ) ); + } - if ( $lang && $lang->slug == $translation_language->slug && ! $this->model->term->get_translation( $term->term_id, $term_language ) ) { + // It is more efficient to use one common query for all languages as soon as there are more than 2. + $all_terms = get_terms( $taxonomy, 'hide_empty=0&lang=0&name__like=' . $s ); + if ( is_array( $all_terms ) ) { + foreach ( $all_terms as $term ) { + $lang = $this->model->term->get_language( $term->term_id ); + + if ( $lang && $lang->slug == $translation_language->slug && ! $this->model->term->get_translation( $term->term_id, $term_language ) ) { + $terms[] = $term; + } + } + } + + // Format the ajax response. + foreach ( $terms as $term ) { + if ( $term instanceof WP_Term ) { $return[] = array( - 'id' => $term->term_id, - 'value' => $term->name, - 'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ), + 'id' => $term->term_id, + 'value' => rtrim( // Trim the seperator added at the end by WP. + get_term_parents_list( + $term->term_id, + $term->taxonomy, + array( + 'separator' => ' > ', + 'link' => false, + ) + ), + ' >' + ), + 'link' => $this->links->edit_term_translation_link( $term->term_id, $term->taxonomy, $post_type ), ); } } - // Add current translation in list - // Not in add term for as term_id is not set - if ( 'undefined' !== $_GET['term_id'] && $term_id = $this->model->term->get_translation( (int) $_GET['term_id'], $translation_language ) ) { - $term = get_term( $term_id, $taxonomy ); - array_unshift( $return, array( - 'id' => $term_id, - 'value' => $term->name, - 'link' => $this->links->edit_term_translation_link( $term->term_id, $taxonomy, $post_type ), - ) ); - } - - wp_die( json_encode( $return ) ); - } - - /** - * Get the language(s) to filter get_terms - * - * @since 1.7.6 - * - * @param array $taxonomies queried taxonomies - * @param array $args get_terms arguments - * @return object|string|bool the language(s) to use in the filter, false otherwise - */ - protected function get_queried_language( $taxonomies, $args ) { - // Does nothing except on taxonomies which are filterable - // Since WP 4.7, make sure not to filter wp_get_object_terms() - if ( ! $this->model->is_translated_taxonomy( $taxonomies ) || ! empty( $args['object_ids'] ) ) { - return false; - } - - if ( isset( $this->tax_query_lang ) ) { - $args['lang'] = $this->tax_query_lang; - } - - // If get_terms is queried with a 'lang' parameter - if ( isset( $args['lang'] ) ) { - return $args['lang']; - } - - // On tags page, everything should be filtered according to the admin language filter except the parent dropdown - if ( 'edit-tags.php' === $GLOBALS['pagenow'] && empty( $args['class'] ) ) { - return $this->filter_lang; - } - - return $this->curlang; - } - - /** - * Adds language dependent cache domain when querying terms - * Useful as the 'lang' parameter is not included in cache key by WordPress - * - * @since 1.3 - * - * @param array $args - * @param array $taxonomies - * @return array modified arguments - */ - public function get_terms_args( $args, $taxonomies ) { - // don't break _get_term_hierarchy() - if ( 'all' === $args['get'] && 'id' === $args['orderby'] && 'id=>parent' === $args['fields'] ) { - $args['lang'] = ''; - } - - if ( $lang = $this->get_queried_language( $taxonomies, $args ) ) { - $lang = is_string( $lang ) && strpos( $lang, ',' ) ? explode( ',', $lang ) : $lang; - $key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $this->model->get_language( $lang )->slug ); - $args['cache_domain'] = empty( $args['cache_domain'] ) ? 'pll' . $key : $args['cache_domain'] . $key; - } - return $args; - } - - /** - * Filters categories and post tags by language(s) when needed on admin side - * - * @since 0.5 - * - * @param array $clauses list of sql clauses - * @param array $taxonomies list of taxonomies - * @param array $args get_terms arguments - * @return array modified sql clauses - */ - public function terms_clauses( $clauses, $taxonomies, $args ) { - $lang = $this->get_queried_language( $taxonomies, $args ); - return ! empty( $lang ) ? $this->model->terms_clauses( $clauses, $lang ) : $clauses; // adds our clauses to filter by current language - } - - /** - * Sets the WP_Term_Query language when doing a WP_Query - * Needed since WP 4.9 - * - * @since 2.3.2 - * - * @param object $query WP_Query object - */ - public function set_tax_query_lang( $query ) { - $this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : ''; - } - - /** - * Removes the WP_Term_Query language filter for WP_Query - * Needed since WP 4.9 - * - * @since 2.3.2 - */ - public function unset_tax_query_lang() { - unset( $this->tax_query_lang ); - } - - /** - * Hack to avoid displaying delete link for the default category in all languages - * Also returns the default category in the right language when called from wp_delete_term - * - * @since 1.2 - * - * @param int $value - * @return int - */ - public function option_default_category( $value ) { - // Filters the default category in note below the category list table and in settings->writing dropdown - if ( isset( $this->pref_lang ) && $tr = $this->model->term->get( $value, $this->pref_lang ) ) { - $value = $tr; - } - - // FIXME backward compatibility with WP < 4.7 - if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) { - $traces = debug_backtrace(); - $n = version_compare( PHP_VERSION, '7', '>=' ) ? 3 : 4; // PHP 7 does not include call_user_func_array - - if ( isset( $traces[ $n ] ) ) { - // FIXME 'column_name' for backward compatibility with WP < 4.3 - if ( in_array( $traces[ $n ]['function'], array( 'column_cb', 'column_name', 'handle_row_actions' ) ) && in_array( $traces[ $n ]['args'][0]->term_id, $this->model->term->get_translations( $value ) ) ) { - return $traces[ $n ]['args'][0]->term_id; - } - - if ( 'wp_delete_term' == $traces[ $n ]['function'] ) { - return $this->model->term->get( $value, $this->model->term->get_language( $traces[ $n ]['args'][0] ) ); - } - } - } - - return $value; - } - - /** - * Checks if the new default category is translated in all languages - * If not, create the translations - * - * @since 1.7 - * - * @param int $old_value - * @param int $value - */ - public function update_option_default_category( $old_value, $value ) { - $default_cat_lang = $this->model->term->get_language( $value ); - - // Assign a default language to default category - if ( ! $default_cat_lang ) { - $default_cat_lang = $this->model->get_language( $this->options['default_lang'] ); - $this->model->term->set_language( (int) $value, $default_cat_lang ); - } - - foreach ( $this->model->get_languages_list() as $language ) { - if ( $language->slug != $default_cat_lang->slug && ! $this->model->term->get_translation( $value, $language ) ) { - $this->model->create_default_category( $language ); - } - } + wp_die( wp_json_encode( $return ) ); } /** @@ -722,6 +621,7 @@ class PLL_Admin_Filters_Term { * @param int $new_term_id * @param int $term_taxonomy_id * @param string $taxonomy + * @return void */ public function split_shared_term( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { if ( ! $this->model->is_translated_taxonomy( $taxonomy ) ) { @@ -734,8 +634,13 @@ class PLL_Admin_Filters_Term { return; } - $avoid_recursion = true; $lang = $this->model->term->get_language( $term_id ); + if ( empty( $lang ) ) { + return; + } + + $avoid_recursion = true; + $translations = array(); foreach ( $this->model->term->get_translations( $term_id ) as $key => $tr_id ) { if ( $lang->slug == $key ) { @@ -746,7 +651,7 @@ class PLL_Admin_Filters_Term { $translations[ $key ] = _split_shared_term( $tr_id, $tr_term->term_taxonomy_id ); // Hack translation ids sent by the form to avoid overwrite in PLL_Admin_Filters_Term::save_translations - if ( isset( $_POST['term_tr_lang'][ $key ] ) && $_POST['term_tr_lang'][ $key ] == $tr_id ) { + if ( isset( $_POST['term_tr_lang'][ $key ] ) && $_POST['term_tr_lang'][ $key ] == $tr_id ) { // phpcs:ignore WordPress.Security.NonceVerification $_POST['term_tr_lang'][ $key ] = $translations[ $key ]; } } diff --git a/wp-content/plugins/polylang/admin/admin-filters-widgets-options.php b/wp-content/plugins/polylang/admin/admin-filters-widgets-options.php new file mode 100644 index 00000000..04ba92c3 --- /dev/null +++ b/wp-content/plugins/polylang/admin/admin-filters-widgets-options.php @@ -0,0 +1,35 @@ +base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + parent::in_widget_form( $widget, $return, $instance ); + } + } + +} diff --git a/wp-content/plugins/polylang/admin/admin-filters.php b/wp-content/plugins/polylang/admin/admin-filters.php index 85714b00..d27651c5 100644 --- a/wp-content/plugins/polylang/admin/admin-filters.php +++ b/wp-content/plugins/polylang/admin/admin-filters.php @@ -1,4 +1,7 @@ model->get_languages_list( array( 'fields' => 'locale' ) ), $specific_locales ) ) { - add_filter( 'sanitize_title', array( $this, 'sanitize_title' ), 10, 3 ); - add_filter( 'sanitize_user', array( $this, 'sanitize_user' ), 10, 3 ); - } - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); - } - /** - * Modifies the widgets forms to add our language dropdown list - * - * @since 0.3 - * - * @param object $widget Widget instance - * @param null $return Not used - * @param array $instance Widget settings - */ - public function in_widget_form( $widget, $return, $instance ) { - $screen = get_current_screen(); - - // Test the Widgets screen and the Customizer to avoid displaying the option in page builders - // Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, not in $_GET. - if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { - $dropdown = new PLL_Walker_Dropdown(); - printf( '

', - esc_attr( $widget->id . '_lang_choice' ), - esc_html__( 'The widget is displayed for:', 'polylang' ), - $dropdown->walk( - array_merge( - array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ), - $this->model->get_languages_list() - ), - array( - 'name' => $widget->id . '_lang_choice', - 'class' => 'tags-input', - 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'], - ) - ) - ); - } - } - - /** - * Called when widget options are saved - * saves the language associated to the widget - * - * @since 0.3 - * - * @param array $instance Widget options - * @param array $new_instance Not used - * @param array $old_instance Not used - * @param object $widget WP_Widget object - * @return array Widget options - */ - public function widget_update_callback( $instance, $new_instance, $old_instance, $widget ) { - if ( ! empty( $_POST[ $key = $widget->id . '_lang_choice' ] ) && in_array( $_POST[ $key ], $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ) { - $instance['pll_lang'] = $_POST[ $key ]; - } else { - unset( $instance['pll_lang'] ); - } - - return $instance; + // Add post state for translations of the privacy policy page + add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); } /** @@ -106,19 +41,13 @@ class PLL_Admin_Filters extends PLL_Filters { * @since 0.4 * * @param int $user_id + * @return void */ public function personal_options_update( $user_id ) { - // Admin language - // FIXME Backward compatibility with WP < 4.7 - if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) { - $user_lang = in_array( $_POST['user_lang'], $this->model->get_languages_list( array( 'fields' => 'locale' ) ) ) ? $_POST['user_lang'] : 0; - update_user_meta( $user_id, 'locale', $user_lang ); - } - // Biography translations foreach ( $this->model->get_languages_list() as $lang ) { $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug; - $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); + $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput /** This filter is documented in wp-includes/user.php */ $description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses @@ -127,44 +56,22 @@ class PLL_Admin_Filters extends PLL_Filters { } /** - * Form for language user preference in user profile + * Outputs hidden information to modify the biography form with js. * * @since 0.4 * - * @param object $profileuser + * @param WP_User $profileuser The current WP_User object. + * @return void */ public function personal_options( $profileuser ) { - // FIXME: Backward compatibility with WP < 4.7 - if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) { - $dropdown = new PLL_Walker_Dropdown(); - printf( ' - - - %s - ', - esc_html__( 'Admin language', 'polylang' ), - $dropdown->walk( - array_merge( - array( (object) array( 'locale' => 0, 'name' => __( 'WordPress default', 'polylang' ) ) ), - $this->model->get_languages_list() - ), - array( - 'name' => 'user_lang', - 'value' => 'locale', - 'selected' => get_user_meta( $profileuser->ID, 'locale', true ), - ) - ) - ); - } - - // Hidden information to modify the biography form with js foreach ( $this->model->get_languages_list() as $lang ) { $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug; /** This filter is documented in wp-includes/user.php */ $description = apply_filters( 'user_description', get_user_meta( $profileuser->ID, $meta, true ) ); // Applies WP default filter wp_kses_data - printf( '', + printf( + '', esc_attr( $lang->slug ), esc_attr( $lang->name ), esc_attr( $description ) @@ -173,95 +80,15 @@ class PLL_Admin_Filters extends PLL_Filters { } /** - * Upgrades languages files after a core upgrade - * only for backward compatibility WP < 4.0 *AND* Polylang < 1.6 - * - * @since 0.6 - * - * @param string $version new WP version - */ - public function upgrade_languages( $version ) { - // $GLOBALS['wp_version'] is the old WP version - if ( version_compare( $version, '4.0', '>=' ) && version_compare( $GLOBALS['wp_version'], '4.0', '<' ) ) { - - /** This filter is documented in wp-admin/includes/update-core.php */ - apply_filters( 'update_feedback', __( 'Upgrading language files…', 'polylang' ) ); - PLL_Upgrade::download_language_packs(); - } - } - - /** - * Allows to update translations files for plugins and themes + * Allows to update translations files for plugins and themes. * * @since 1.6 * - * @param array $locales Not used - * @return array list of locales to update + * @param string[] $locales List of locales to update for plugins and themes. + * @return string[] */ - function update_check_locales( $locales ) { - return $this->model->get_languages_list( array( 'fields' => 'locale' ) ); - } - - /** - * Filters the locale according to the current language instead of the language - * of the admin interface - * - * @since 2.0 - * - * @param string $locale - * @return string - */ - public function get_locale( $locale ) { - return $this->curlang->locale; - } - - /** - * Maybe fix the result of sanitize_title() in case the languages include German or Danish - * Without this filter, if language of the title being sanitized is different from the language - * used for the admin interface and if one this language is German or Danish, some specific - * characters such as ä, ö, ü, ß are incorrectly sanitized. - * - * @since 2.0 - * - * @param string $title Sanitized title. - * @param string $raw_title The title prior to sanitization. - * @param string $context The context for which the title is being sanitized. - * @return string - */ - public function sanitize_title( $title, $raw_title, $context ) { - static $once = false; - - if ( ! $once && 'save' == $context && ! empty( $this->curlang ) && ! empty( $title ) ) { - $once = true; - add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface - $title = sanitize_title( $raw_title, '', $context ); - remove_filter( 'locale', array( $this, 'get_locale' ), 20 ); - $once = false; - } - return $title; - } - - /** - * Maybe fix the result of sanitize_user() in case the languages include German or Danish - * - * @since 2.0 - * - * @param string $username Sanitized username. - * @param string $raw_username The username prior to sanitization. - * @param bool $strict Whether to limit the sanitization to specific characters. Default false. - * @return string - */ - public function sanitize_user( $username, $raw_username, $strict ) { - static $once = false; - - if ( ! $once && ! empty( $this->curlang ) ) { - $once = true; - add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface - $username = sanitize_user( $raw_username, '', $strict ); - remove_filter( 'locale', array( $this, 'get_locale' ), 20 ); - $once = false; - } - return $username; + public function update_check_locales( $locales ) { + return array_merge( $locales, $this->model->get_languages_list( array( 'fields' => 'locale' ) ) ); } /** @@ -278,4 +105,23 @@ class PLL_Admin_Filters extends PLL_Filters { } return $classes; } + + /** + * Adds post state for translations of the privacy policy page. + * + * @since 2.7 + * + * @param string[] $post_states An array of post display states. + * @param WP_Post $post The current post object. + * @return string[] + */ + public function display_post_states( $post_states, $post ) { + $page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' ); + + if ( $page_for_privacy_policy && in_array( $post->ID, $this->model->post->get_translations( $page_for_privacy_policy ) ) ) { + $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page', 'polylang' ); + } + + return $post_states; + } } diff --git a/wp-content/plugins/polylang/admin/admin-links.php b/wp-content/plugins/polylang/admin/admin-links.php index e398e9cd..84c60ebe 100644 --- a/wp-content/plugins/polylang/admin/admin-links.php +++ b/wp-content/plugins/polylang/admin/admin-links.php @@ -1,89 +1,52 @@ cap->create_posts ) ) { - return ''; - } + protected function new_translation_link( $link, $language ) { + $str = ''; - if ( 'attachment' == $post_type ) { - $args = array( - 'action' => 'translate_media', - 'from_media' => $post_id, - 'new_lang' => $language->slug, - ); - - // add nonce for media as we will directly publish a new attachment from a click on this link - $link = wp_nonce_url( add_query_arg( $args, admin_url( 'admin.php' ) ), 'translate_media' ); - } else { - $args = array( - 'post_type' => $post_type, - 'from_post' => $post_id, - 'new_lang' => $language->slug, - ); - - $link = add_query_arg( $args, admin_url( 'post-new.php' ) ); - } - - /** - * Filter the new post translation link - * - * @since 1.8 - * - * @param string $link the new post translation link - * @param object $language the language of the new translation - * @param int $post_id the source post id - */ - return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id ); - } - - /** - * returns html markup for a new post translation link - * - * @since 1.8 - * - * @param int $post_id - * @param object $language - * @return string - */ - public function new_post_translation_link( $post_id, $language ) { - $link = $this->get_new_post_translation_link( $post_id, $language ); - return $link ? sprintf( - '%2$s', - esc_url( $link ), + if ( $link ) { /* translators: accessibility text, %s is a native language name */ - esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) ) - ) : ''; + $hint = sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ); + + $str = sprintf( + '%3$s', + esc_url( $link ), + esc_attr( $hint ), + esc_html( $hint ) + ); + } + + return $str; } /** - * returns html markup for a translation link + * Returns the html markup for a translation link. * - * @since 1.4 + * @since 2.6 * - * @param int $post_id translation post id + * @param string $link The translation link. + * @param PLL_Language $language The language of the translation. * @return string */ - public function edit_post_translation_link( $post_id ) { - $link = get_edit_post_link( $post_id ); - $language = $this->model->post->get_language( $post_id ); + public function edit_translation_link( $link, $language ) { return $link ? sprintf( '%2$s', esc_url( $link ), @@ -93,14 +56,111 @@ class PLL_Admin_Links extends PLL_Links { } /** - * get the link to create a new term translation + * Get the link to create a new post translation. * * @since 1.5 * - * @param int $term_id - * @param string $taxonomy - * @param string $post_type - * @param object $language + * @param int $post_id The source post id. + * @param PLL_Language $language The language of the new translation. + * @param string $context Optional. Defaults to 'display' which encodes '&' to '&'. + * Otherwise, preserves '&'. + * @return string + */ + public function get_new_post_translation_link( $post_id, $language, $context = 'display' ) { + $post_type = get_post_type( $post_id ); + $post_type_object = get_post_type_object( get_post_type( $post_id ) ); + if ( empty( $post_type_object ) || ! current_user_can( $post_type_object->cap->create_posts ) ) { + return ''; + } + + // Special case for the privacy policy page which is associated to a specific capability + if ( 'page' === $post_type_object->name && ! current_user_can( 'manage_privacy_options' ) ) { + $privacy_page = get_option( 'wp_page_for_privacy_policy' ); + if ( $privacy_page && in_array( $post_id, $this->model->post->get_translations( $privacy_page ) ) ) { + return ''; + } + } + + if ( 'attachment' === $post_type ) { + $args = array( + 'action' => 'translate_media', + 'from_media' => $post_id, + 'new_lang' => $language->slug, + ); + + $link = add_query_arg( $args, admin_url( 'admin.php' ) ); + + // Add nonce for media as we will directly publish a new attachment from a click on this link + if ( 'display' === $context ) { + $link = wp_nonce_url( $link, 'translate_media' ); + } else { + $link = add_query_arg( '_wpnonce', wp_create_nonce( 'translate_media' ), $link ); + } + } else { + $args = array( + 'post_type' => $post_type, + 'from_post' => $post_id, + 'new_lang' => $language->slug, + ); + + $link = add_query_arg( $args, admin_url( 'post-new.php' ) ); + + if ( 'display' === $context ) { + $link = wp_nonce_url( $link, 'new-post-translation' ); + } else { + $link = add_query_arg( '_wpnonce', wp_create_nonce( 'new-post-translation' ), $link ); + } + } + + /** + * Filters the new post translation link. + * + * @since 1.8 + * + * @param string $link The new post translation link. + * @param PLL_Language $language The language of the new translation. + * @param int $post_id The source post id. + */ + return apply_filters( 'pll_get_new_post_translation_link', $link, $language, $post_id ); + } + + /** + * Returns the html markup for a new post translation link. + * + * @since 1.8 + * + * @param int $post_id The source post id. + * @param PLL_Language $language The language of the new translation. + * @return string + */ + public function new_post_translation_link( $post_id, $language ) { + $link = $this->get_new_post_translation_link( $post_id, $language ); + return $this->new_translation_link( $link, $language ); + } + + /** + * Returns the html markup for a post translation link. + * + * @since 1.4 + * + * @param int $post_id The translation post id. + * @return string + */ + public function edit_post_translation_link( $post_id ) { + $link = get_edit_post_link( $post_id ); + $language = $this->model->post->get_language( $post_id ); + return $this->edit_translation_link( $link, $language ); + } + + /** + * Get the link to create a new term translation. + * + * @since 1.5 + * + * @param int $term_id Source term id. + * @param string $taxonomy Taxonomy name. + * @param string $post_type Post type name. + * @param PLL_Language $language The language of the new translation. * @return string */ public function get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) { @@ -119,59 +179,48 @@ class PLL_Admin_Links extends PLL_Links { $link = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); /** - * Filter the new term translation link + * Filters the new term translation link. * * @since 1.8 * - * @param string $link the new term translation link - * @param object $language the language of the new translation - * @param int $term_id the source term id - * @param string $taxonomy - * @param string $post_type + * @param string $link The new term translation link. + * @param PLL_Language $language The language of the new translation. + * @param int $term_id The source term id. + * @param string $taxonomy Taxonomy name. + * @param string $post_type Post type name. */ return apply_filters( 'pll_get_new_term_translation_link', $link, $language, $term_id, $taxonomy, $post_type ); } /** - * returns html markup for a new term translation + * Returns the html markup for a new term translation. * * @since 1.8 * - * @param int $term_id - * @param string $taxonomy - * @param string $post_type - * @param object $language + * @param int $term_id Source term id. + * @param string $taxonomy Taxonomy name. + * @param string $post_type Post type name. + * @param PLL_Language $language The language of the new translation. * @return string */ public function new_term_translation_link( $term_id, $taxonomy, $post_type, $language ) { $link = $this->get_new_term_translation_link( $term_id, $taxonomy, $post_type, $language ); - return $link ? sprintf( - '%2$s', - esc_url( $link ), - /* translators: accessibility text, %s is a native language name */ - esc_html( sprintf( __( 'Add a translation in %s', 'polylang' ), $language->name ) ) - ) : ''; + return $this->new_translation_link( $link, $language ); } /** - * returns html markup for a term translation link + * Returns the html markup for a term translation link. * * @since 1.4 * - * @param object $term_id translation term id - * @param string $taxonomy - * @param string $post_type + * @param int $term_id Translation term id. + * @param string $taxonomy Taxonomy name. + * @param string $post_type Post type name. * @return string */ public function edit_term_translation_link( $term_id, $taxonomy, $post_type ) { $link = get_edit_term_link( $term_id, $taxonomy, $post_type ); $language = $this->model->term->get_language( $term_id ); - return $link ? sprintf( - '%2$s', - esc_url( $link ), - /* translators: accessibility text, %s is a native language name */ - esc_html( sprintf( __( 'Edit the translation in %s', 'polylang' ), $language->name ) ) - ) : ''; + return $this->edit_translation_link( $link, $language ); } } - diff --git a/wp-content/plugins/polylang/admin/admin-model.php b/wp-content/plugins/polylang/admin/admin-model.php index f52c6079..cdcc41a2 100644 --- a/wp-content/plugins/polylang/admin/admin-model.php +++ b/wp-content/plugins/polylang/admin/admin-model.php @@ -1,7 +1,10 @@ language name ( used only for display ) - * slug -> language code ( ideally 2-letters ISO 639-1 language code ) - * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... - * rtl -> 1 if rtl language, 0 otherwise - * term_group -> language order when displayed - * - * Optional arguments that $args can contain: - * no_default_cat -> if set, no default category will be created for this language - * flag -> country code, see flags.php + * and creates a default category for this language. * * @since 1.2 * - * @param array $args - * @return bool true if success / false if failed + * @param array $args { + * @type string $name Language name ( used only for display ). + * @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ). + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... + * @type int $rtl 1 if rtl language, 0 otherwise. + * @type int $term_group Language order when displayed. + * @type string $no_default_cat Optional, if set, no default category will be created for this language. + * @type string $flag Optional, country code, @see flags.php. + * } + * @return WP_Error|true true if success / WP_Error if failed. */ public function add_language( $args ) { - if ( ! $this->validate_lang( $args ) ) { - return false; + $errors = $this->validate_lang( $args ); + if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0 + return $errors; } // First the language taxonomy - $description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) ); + $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) ); $r = wp_insert_term( $args['name'], 'language', array( 'slug' => $args['slug'], 'description' => $description ) ); if ( is_wp_error( $r ) ) { // Avoid an ugly fatal error if something went wrong ( reported once in the forum ) - add_settings_error( 'general', 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) ); - return false; + return new WP_Error( 'pll_add_language', __( 'Impossible to add the language.', 'polylang' ) ); } wp_update_term( (int) $r['term_id'], 'language', array( 'term_group' => (int) $args['term_group'] ) ); // can't set the term group directly in wp_insert_term @@ -52,11 +52,6 @@ class PLL_Admin_Model extends PLL_Model { // If this is the first language created, set it as default language $this->options['default_lang'] = $args['slug']; update_option( 'polylang', $this->options ); - - // And assign default language to default category - $this->term->set_language( (int) get_option( 'default_category' ), (int) $r['term_id'] ); - } elseif ( empty( $args['no_default_cat'] ) ) { - $this->create_default_category( $args['slug'] ); } // Init a mo_id for this language @@ -64,33 +59,32 @@ class PLL_Admin_Model extends PLL_Model { $mo->export_to_db( $this->get_language( $args['slug'] ) ); /** - * Fires when a language is added + * Fires when a language is added. * * @since 1.9 * - * @param array $args arguments used to create the language + * @param array $args Arguments used to create the language. @see PLL_Admin_Model::add_language(). */ do_action( 'pll_add_language', $args ); $this->clean_languages_cache(); // Again to set add mo_id in the cached languages list flush_rewrite_rules(); // Refresh rewrite rules - - add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); return true; } /** - * Delete a language + * Delete a language. * * @since 1.2 * - * @param int $lang_id language term_id + * @param int $lang_id Language term_id. + * @return bool */ public function delete_language( $lang_id ) { $lang = $this->get_language( (int) $lang_id ); if ( empty( $lang ) ) { - return; + return false; } // Oops ! we are deleting the default language... @@ -127,7 +121,7 @@ class PLL_Admin_Model extends PLL_Model { // Delete menus locations if ( ! empty( $this->options['nav_menus'] ) ) { foreach ( $this->options['nav_menus'] as $theme => $locations ) { - foreach ( $locations as $location => $languages ) { + foreach ( array_keys( $locations ) as $location ) { unset( $this->options['nav_menus'][ $theme ][ $location ][ $lang->slug ] ); } } @@ -141,7 +135,7 @@ class PLL_Admin_Model extends PLL_Model { // Delete the string translations $post = wpcom_vip_get_page_by_title( 'polylang_mo_' . $lang->term_id, OBJECT, 'polylang_mo' ); - if ( ! empty( $post ) ) { + if ( $post instanceof WP_Post ) { wp_delete_post( $post->ID ); } @@ -157,32 +151,31 @@ class PLL_Admin_Model extends PLL_Model { update_option( 'polylang', $this->options ); flush_rewrite_rules(); // refresh rewrite rules - add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' ); + return true; } /** - * Update language properties - * - * List of arguments that $args must contain: - * lang_id -> term_id of the language to modify - * name -> language name ( used only for display ) - * slug -> language code ( ideally 2-letters ISO 639-1 language code - * locale -> WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... - * rtl -> 1 if rtl language, 0 otherwise - * term_group -> language order when displayed - * - * Optional arguments that $args can contain: - * flag -> country code, see flags.php + * Updates language properties. * * @since 1.2 * - * @param array $args - * @return bool true if success / false if failed + * @param array $args { + * @type int $lang_id Id of the language to modify. + * @type string $name Language name ( used only for display ). + * @type string $slug Language code ( ideally 2-letters ISO 639-1 language code ). + * @type string $locale WordPress locale. If something wrong is used for the locale, the .mo files will not be loaded... + * @type int $rtl 1 if rtl language, 0 otherwise. + * @type int $term_group Language order when displayed. + * @type string $flag Optional, country code, @see flags.php. + * } + * @return WP_Error|true true if success / WP_Error if failed. */ public function update_language( $args ) { $lang = $this->get_language( (int) $args['lang_id'] ); - if ( ! $this->validate_lang( $args, $lang ) ) { - return false; + + $errors = $this->validate_lang( $args, $lang ); + if ( $errors->get_error_code() ) { // Using has_errors() would be more meaningful but is available only since WP 5.0 + return $errors; } // Update links to this language in posts and terms in case the slug has been modified @@ -211,7 +204,7 @@ class PLL_Admin_Model extends PLL_Model { // Update menus locations if ( ! empty( $this->options['nav_menus'] ) ) { foreach ( $this->options['nav_menus'] as $theme => $locations ) { - foreach ( $locations as $location => $languages ) { + foreach ( array_keys( $locations ) as $location ) { if ( ! empty( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ) ) { $this->options['nav_menus'][ $theme ][ $location ][ $slug ] = $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ]; unset( $this->options['nav_menus'][ $theme ][ $location ][ $old_slug ] ); @@ -235,95 +228,118 @@ class PLL_Admin_Model extends PLL_Model { update_option( 'polylang', $this->options ); // And finally update the language itself - $description = serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) ); + $description = maybe_serialize( array( 'locale' => $args['locale'], 'rtl' => (int) $args['rtl'], 'flag_code' => empty( $args['flag'] ) ? '' : $args['flag'] ) ); wp_update_term( (int) $lang->term_id, 'language', array( 'slug' => $slug, 'name' => $args['name'], 'description' => $description, 'term_group' => (int) $args['term_group'] ) ); - wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) ); + if ( empty( $lang->tl_term_id ) ) { + // Attempt to repair the term_language if it has been deleted by a database cleaning tool. + wp_insert_term( $args['name'], 'term_language', array( 'slug' => 'pll_' . $slug ) ); + } else { + wp_update_term( (int) $lang->tl_term_id, 'term_language', array( 'slug' => 'pll_' . $slug, 'name' => $args['name'] ) ); + } /** - * Fires when a language is added + * Fires when a language is updated. * * @since 1.9 * - * @param array $args arguments used to modify the language + * @param array $args Arguments used to modify the language. @see PLL_Admin_Model::update_language(). */ do_action( 'pll_update_language', $args ); $this->clean_languages_cache(); flush_rewrite_rules(); // Refresh rewrite rules - add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' ); return true; } /** - * Validates data entered when creating or updating a language - * @see PLL_Admin_Model::add_language + * Validates data entered when creating or updating a language. + * + * @see PLL_Admin_Model::add_language(). * * @since 0.4 * - * @param array $args - * @param object $lang optional the language currently updated, the language is created if not set - * @return bool true if success / false if failed + * @param array $args Parameters of {@see PLL_Admin_Model::add_language() or @see PLL_Admin_Model::update_language()}. + * @param PLL_Language $lang Optional the language currently updated, the language is created if not set. + * @return WP_Error */ protected function validate_lang( $args, $lang = null ) { + $errors = new WP_Error(); + // Validate locale with the same pattern as WP 4.3. See #28303 if ( ! preg_match( '#^[a-z]{2,3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?$#', $args['locale'], $matches ) ) { - add_settings_error( 'general', 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) ); + $errors->add( 'pll_invalid_locale', __( 'Enter a valid WordPress locale', 'polylang' ) ); } // Validate slug characters if ( ! preg_match( '#^[a-z_-]+$#', $args['slug'] ) ) { - add_settings_error( 'general', 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) ); + $errors->add( 'pll_invalid_slug', __( 'The language code contains invalid characters', 'polylang' ) ); } // Validate slug is unique foreach ( $this->get_languages_list() as $language ) { - if ( $language->slug === $args['slug'] && ( null === $lang || ( isset( $lang ) && $lang->term_id != $language->term_id ) ) ) { - add_settings_error( 'general', 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) ); + if ( $language->slug === $args['slug'] && ( null === $lang || $lang->term_id !== $language->term_id ) ) { + $errors->add( 'pll_non_unique_slug', __( 'The language code must be unique', 'polylang' ) ); } } // Validate name // No need to sanitize it as wp_insert_term will do it for us if ( empty( $args['name'] ) ) { - add_settings_error( 'general', 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) ); + $errors->add( 'pll_invalid_name', __( 'The language must have a name', 'polylang' ) ); } // Validate flag if ( ! empty( $args['flag'] ) && ! file_exists( POLYLANG_DIR . '/flags/' . $args['flag'] . '.png' ) ) { - add_settings_error( 'general', 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) ); + $flag = PLL_Language::get_flag_informations( $args['flag'] ); + + if ( ! empty( $flag['url'] ) ) { + $response = function_exists( 'vip_safe_wp_remote_get' ) ? vip_safe_wp_remote_get( esc_url_raw( $flag['url'] ) ) : wp_remote_get( esc_url_raw( $flag['url'] ) ); + } + + if ( empty( $response ) || is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { + $errors->add( 'pll_invalid_flag', __( 'The flag does not exist', 'polylang' ) ); + } } - return get_settings_errors() ? false : true; + return $errors; } /** - * Used to set the language of posts or terms in mass + * Assigns a language to posts or terms in mass. * * @since 1.2 * - * @param string $type either 'post' or 'term' - * @param array $ids array of post ids or term ids - * @param object|string $lang object or slug + * @param string $type Either 'post' or 'term'. + * @param int[] $ids Array of post ids or term ids. + * @param PLL_Language|string $lang Language to assign to the posts or terms. + * @return void */ public function set_language_in_mass( $type, $ids, $lang ) { global $wpdb; - $ids = array_map( 'intval', $ids ); $lang = $this->get_language( $lang ); - $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id; + + if ( empty( $lang ) ) { + return; + } + + $tt_id = 'term' === $type ? $lang->tl_term_taxonomy_id : $lang->term_taxonomy_id; + $values = array(); + $ids = array_map( 'intval', $ids ); foreach ( $ids as $id ) { $values[] = $wpdb->prepare( '( %d, %d )', $id, $tt_id ); } if ( ! empty( $values ) ) { - $values = array_unique( $values ); - $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $values ) ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', array_unique( $values ) ) ); $lang->update_count(); // Updating term count is mandatory ( thanks to AndyDeGroo ) } if ( 'term' === $type ) { clean_term_cache( $ids, 'term_language' ); + $translations = array(); foreach ( $ids as $id ) { $translations[] = array( $lang->slug => $id ); @@ -338,34 +354,42 @@ class PLL_Admin_Model extends PLL_Model { } /** - * Used to create a translations groups in mass + * Creates translations groups in mass. * * @since 1.6.3 * - * @param string $type either 'post' or 'term' - * @param array $translations array of translations arrays + * @param string $type Either 'post' or 'term' + * @param array $translations Array of translations arrays. + * @return void */ public function set_translation_in_mass( $type, $translations ) { global $wpdb; - $taxonomy = $type . '_translations'; + $taxonomy = $type . '_translations'; + $terms = array(); + $slugs = array(); + $description = array(); + $count = array(); foreach ( $translations as $t ) { $term = uniqid( 'pll_' ); // the term name $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term ); $slugs[] = $wpdb->prepare( '%s', $term ); - $description[ $term ] = serialize( $t ); + $description[ $term ] = maybe_serialize( $t ); $count[ $term ] = count( $t ); } // Insert terms if ( ! empty( $terms ) ) { - $terms = array_unique( $terms ); - $wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "INSERT INTO {$wpdb->terms} ( slug, name ) VALUES " . implode( ',', array_unique( $terms ) ) ); } // Get all terms with their term_id - $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . ' )' ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $terms = $wpdb->get_results( "SELECT term_id, slug FROM {$wpdb->terms} WHERE slug IN ( " . implode( ',', $slugs ) . ' )' ); + $term_ids = array(); + $tts = array(); // Prepare terms taxonomy relationship foreach ( $terms as $term ) { @@ -375,20 +399,23 @@ class PLL_Admin_Model extends PLL_Model { // Insert term_taxonomy if ( ! empty( $tts ) ) { - $tts = array_unique( $tts ); - $wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description, count ) VALUES " . implode( ',', $tts ) ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "INSERT INTO {$wpdb->term_taxonomy} ( term_id, taxonomy, description, count ) VALUES " . implode( ',', array_unique( $tts ) ) ); } // Get all terms with term_taxonomy_id $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) ); + $trs = array(); - // Prepare objects relationships - foreach ( $terms as $term ) { - $t = unserialize( $term->description ); - if ( in_array( $t, $translations ) ) { - foreach ( $t as $object_id ) { - if ( ! empty( $object_id ) ) { - $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); + // Prepare objects relationships. + if ( is_array( $terms ) ) { + foreach ( $terms as $term ) { + $t = maybe_unserialize( $term->description ); + if ( in_array( $t, $translations ) ) { + foreach ( $t as $object_id ) { + if ( ! empty( $object_id ) ) { + $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); + } } } } @@ -396,7 +423,8 @@ class PLL_Admin_Model extends PLL_Model { // Insert term_relationships if ( ! empty( $trs ) ) { - $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) ); $trs = array_unique( $trs ); } @@ -404,122 +432,74 @@ class PLL_Admin_Model extends PLL_Model { } /** - * Returns untranslated posts and terms ids ( used in settings ) - * - * @since 0.9 - * @since 2.2.6 Add the $limit argument - * - * @param in $limit Max number of posts or terms to return. Defaults to -1 (no limit). - * @return array Array made of an array of post ids and an array of term ids - */ - public function get_objects_with_no_lang( $limit = -1 ) { - global $wpdb; - - /** - * Filters the max number of posts or terms to return when searching objects with no language - * This filter can be used to decrease the memory usage in case the number of objects - * without language is too big. Using a negative value is equivalent to have no limit. - * - * @since 2.2.6 - * - * @param int $limit Max number of posts or terms to retrieve from the database - */ - $limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit ); - - $posts = get_posts( array( - 'numberposts' => $limit, - 'nopaging' => $limit <= 0, - 'post_type' => $this->get_translated_post_types(), - 'post_status' => 'any', - 'fields' => 'ids', - 'tax_query' => array( - array( - 'taxonomy' => 'language', - 'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ), - 'operator' => 'NOT IN', - ), - ), - ) ); - - $terms = $wpdb->get_col( sprintf( " - SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy} - WHERE taxonomy IN ('%s') - AND {$wpdb->term_taxonomy}.term_id NOT IN ( - SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s) - ) - %s", - implode( "','", array_map( 'esc_sql', $this->get_translated_taxonomies() ) ), - implode( ',', array_map( 'intval', $this->get_languages_list( array( 'fields' => 'tl_term_taxonomy_id' ) ) ) ), - $limit > 0 ? "LIMIT {$limit}" : '' - ) ); - - /** - * Filter the list of untranslated posts ids and terms ids - * - * @since 0.9 - * - * @param bool|array $objects false if no ids found, list of post and/or term ids otherwise - */ - return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) ); - } - - /** - * Used to delete translations or update the translations when a language slug has been modified in settings + * Updates the translations when a language slug has been modified in settings + * or deletes them when a language is removed. * * @since 0.5 * - * @param string $old_slug the old language slug - * @param string $new_slug optional, the new language slug, if not set it means the correspondent has been deleted + * @param string $old_slug The old language slug. + * @param string $new_slug Optional, the new language slug, if not set it means that the language has been deleted. + * @return void */ public function update_translations( $old_slug, $new_slug = '' ) { global $wpdb; - $terms = get_terms( array( 'post_translations', 'term_translations' ) ); + $terms = get_terms( array( 'post_translations', 'term_translations' ) ); + $term_ids = array(); + $dr = array(); + $dt = array(); + $ut = array(); - foreach ( $terms as $term ) { - $term_ids[ $term->taxonomy ][] = $term->term_id; - $tr = unserialize( $term->description ); - if ( ! empty( $tr[ $old_slug ] ) ) { - if ( $new_slug ) { - $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete - } else { - $dr['id'][] = (int) $tr[ $old_slug ]; - $dr['tt'][] = (int) $term->term_taxonomy_id; - } - unset( $tr[ $old_slug ] ); + if ( is_array( $terms ) ) { + foreach ( $terms as $term ) { + $term_ids[ $term->taxonomy ][] = $term->term_id; + $tr = maybe_unserialize( $term->description ); + if ( ! empty( $tr[ $old_slug ] ) ) { + if ( $new_slug ) { + $tr[ $new_slug ] = $tr[ $old_slug ]; // Suppress this for delete + } else { + $dr['id'][] = (int) $tr[ $old_slug ]; + $dr['tt'][] = (int) $term->term_taxonomy_id; + } + unset( $tr[ $old_slug ] ); - if ( empty( $tr ) || 1 == count( $tr ) ) { - $dt['t'][] = (int) $term->term_id; - $dt['tt'][] = (int) $term->term_taxonomy_id; - } else { - $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, serialize( $tr ) ); - $ut['in'][] = (int) $term->term_id; + if ( empty( $tr ) || 1 == count( $tr ) ) { + $dt['t'][] = (int) $term->term_id; + $dt['tt'][] = (int) $term->term_taxonomy_id; + } else { + $ut['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $term->term_id, maybe_serialize( $tr ) ); + $ut['in'][] = (int) $term->term_id; + } } } } // Delete relationships if ( ! empty( $dr ) ) { - $wpdb->query( " - DELETE FROM $wpdb->term_relationships + // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( + "DELETE FROM $wpdb->term_relationships WHERE object_id IN ( " . implode( ',', $dr['id'] ) . ' ) - AND term_taxonomy_id IN ( ' . implode( ',', $dr['tt'] ) . ' ) - ' ); + AND term_taxonomy_id IN ( ' . implode( ',', $dr['tt'] ) . ' )' + ); + // PHPCS:enable } // Delete terms if ( ! empty( $dt ) ) { - $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . ' )' ); - $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . ' )' ); + $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $dt['t'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ( " . implode( ',', $dt['tt'] ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared } // Update terms if ( ! empty( $ut ) ) { - $wpdb->query( " - UPDATE $wpdb->term_taxonomy + // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( + "UPDATE $wpdb->term_taxonomy SET description = ( CASE term_id " . implode( ' ', $ut['case'] ) . ' END ) - WHERE term_id IN ( ' . implode( ',', $ut['in'] ) . ' ) - ' ); + WHERE term_id IN ( ' . implode( ',', $ut['in'] ) . ' )' + ); + // PHPCS:enable } if ( ! empty( $term_ids ) ) { @@ -531,27 +511,33 @@ class PLL_Admin_Model extends PLL_Model { /** * Updates the default language - * taking care to update the default category & the nav menu locations + * taking care to update the default category & the nav menu locations. * * @since 1.8 * - * @param string $slug new language slug + * @param string $slug New language slug. + * @return void */ public function update_default_lang( $slug ) { // The nav menus stored in theme locations should be in the default language $theme = get_stylesheet(); if ( ! empty( $this->options['nav_menus'][ $theme ] ) ) { + $menus = array(); + foreach ( $this->options['nav_menus'][ $theme ] as $key => $loc ) { $menus[ $key ] = empty( $loc[ $slug ] ) ? 0 : $loc[ $slug ]; } set_theme_mod( 'nav_menu_locations', $menus ); } - // The default category should be in the default language - $default_cats = $this->term->get_translations( get_option( 'default_category' ) ); - if ( isset( $default_cats[ $slug ] ) ) { - update_option( 'default_category', $default_cats[ $slug ] ); - } + /** + * Fires when a default language is updated. + * + * @since 3.1 + * + * @param string $slug Slug. + */ + do_action( 'pll_update_default_lang', $slug ); // Update options $this->options['default_lang'] = $slug; diff --git a/wp-content/plugins/polylang/admin/admin-nav-menu.php b/wp-content/plugins/polylang/admin/admin-nav-menu.php index c331da69..f0fb8389 100644 --- a/wp-content/plugins/polylang/admin/admin-nav-menu.php +++ b/wp-content/plugins/polylang/admin/admin-nav-menu.php @@ -1,4 +1,7 @@ theme = get_option( 'stylesheet' ); - // Populates nav menus locations // Since WP 4.4, must be done before customize_register is fired add_filter( 'theme_mod_nav_menu_locations', array( $this, 'theme_mod_nav_menu_locations' ), 20 ); @@ -32,19 +33,17 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * adds the language switcher metabox and create new nav menu locations * * @since 1.1 + * + * @return void */ public function admin_init() { add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); add_action( 'wp_update_nav_menu_item', array( $this, 'wp_update_nav_menu_item' ), 10, 2 ); - add_filter( 'wp_get_nav_menu_items', array( $this, 'translate_switcher_title' ) ); // Translation of menus based on chosen locations add_filter( 'pre_update_option_theme_mods_' . $this->theme, array( $this, 'pre_update_option_theme_mods' ) ); add_action( 'delete_nav_menu', array( $this, 'delete_nav_menu' ) ); - // Filter _wp_auto_add_pages_to_menu by language - add_action( 'transition_post_status', array( $this, 'auto_add_pages_to_menu' ), 5, 3 ); // before _wp_auto_add_pages_to_menu - // FIXME is it possible to choose the order ( after theme locations in WP3.5 and older ) ? // FIXME not displayed if Polylang is activated before the first time the user goes to nav menus http://core.trac.wordpress.org/ticket/16828 add_meta_box( 'pll_lang_switch_box', __( 'Language switcher', 'polylang' ), array( $this, 'lang_switch' ), 'nav-menus', 'side', 'high' ); @@ -58,6 +57,8 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * Thanks to John Morris for his very interesting post http://www.johnmorrisonline.com/how-to-add-a-fully-functional-custom-meta-box-to-wordpress-navigation-menus/ * * @since 1.1 + * + * @return void */ public function lang_switch() { global $_nav_menu_placeholder, $nav_menu_selected_id; @@ -68,17 +69,17 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu {

- class="button-secondary submit-add-to-menu right" value="" name="add-post-type-menu-item" id="submit-posttype-lang-switch"> + class="button-secondary submit-add-to-menu right" value="" name="add-post-type-menu-item" id="submit-posttype-lang-switch">

@@ -90,30 +91,36 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * Prepares javascript to modify the language switcher menu item * * @since 1.1 + * + * @return void */ public function admin_enqueue_scripts() { $screen = get_current_screen(); - if ( 'nav-menus' != $screen->base ) { + if ( empty( $screen ) || 'nav-menus' !== $screen->base ) { return; } $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/nav-menu' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery' ), POLYLANG_VERSION ); + wp_enqueue_script( 'pll_nav_menu', plugins_url( '/js/build/nav-menu' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION ); - $data['strings'] = PLL_Switcher::get_switcher_options( 'menu', 'string' ); // The strings for the options - $data['title'] = __( 'Language switcher', 'polylang' ); // The title + $data = array( + 'strings' => PLL_Switcher::get_switcher_options( 'menu', 'string' ), // The strings for the options + 'title' => __( 'Languages', 'polylang' ), // The title + 'val' => array(), + ); // Get all language switcher menu items - $items = get_posts( array( - 'numberposts' => -1, - 'nopaging' => true, - 'post_type' => 'nav_menu_item', - 'fields' => 'ids', - 'meta_key' => '_pll_menu_item', - ) ); + $items = get_posts( + array( + 'numberposts' => -1, + 'nopaging' => true, + 'post_type' => 'nav_menu_item', + 'fields' => 'ids', + 'meta_key' => '_pll_menu_item', + ) + ); // The options values for the language switcher - $data['val'] = array(); foreach ( $items as $item ) { $data['val'][ $item ] = get_post_meta( $item, '_pll_menu_item', true ); } @@ -129,9 +136,10 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * * @param int $menu_id not used * @param int $menu_item_db_id + * @return void */ public function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0 ) { - if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#pll_switcher' != $_POST['menu-item-url'][ $menu_item_db_id ] ) { + if ( empty( $_POST['menu-item-url'][ $menu_item_db_id ] ) || '#pll_switcher' !== $_POST['menu-item-url'][ $menu_item_db_id ] ) { // phpcs:ignore WordPress.Security.NonceVerification return; } @@ -147,7 +155,7 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { } } else { - foreach ( $options as $opt => $v ) { + foreach ( array_keys( $options ) as $opt ) { $options[ $opt ] = empty( $_POST[ 'menu-item-' . $opt ][ $menu_item_db_id ] ) ? 0 : 1; } update_post_meta( $menu_item_db_id, '_pll_menu_item', $options ); // Allow us to easily identify our nav menu item @@ -155,23 +163,6 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { } } - /** - * Translates the language switcher menu items title in case the user switches the admin language - * - * @since 1.1.1 - * - * @param array $items - * @return array modified $items - */ - public function translate_switcher_title( $items ) { - foreach ( $items as $item ) { - if ( '#pll_switcher' == $item->url ) { - $item->post_title = __( 'Language switcher', 'polylang' ); - } - } - return $items; - } - /** * Assign menu languages and translations based on ( temporary ) locations * @@ -181,8 +172,6 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * @return array */ public function update_nav_menu_locations( $locations ) { - $default = $this->options['default_lang']; - // Extract language and menu from locations foreach ( $locations as $loc => $menu ) { $infos = $this->explode_location( $loc ); @@ -197,25 +186,25 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { } /** - * Assign menu languages and translations based on ( temporary ) locations + * Assign menu languages and translations based on ( temporary ) locations. * * @since 1.1 * - * @param array $mods theme mods - * @return unmodified $mods + * @param mixed $mods Theme mods. + * @return mixed */ public function pre_update_option_theme_mods( $mods ) { if ( current_user_can( 'edit_theme_options' ) && isset( $mods['nav_menu_locations'] ) ) { // Manage Locations tab in Appearance -> Menus - if ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) { + if ( isset( $_GET['action'] ) && 'locations' === $_GET['action'] ) { // phpcs:ignore WordPress.Security.NonceVerification check_admin_referer( 'save-menu-locations' ); $this->options['nav_menus'][ $this->theme ] = array(); } // Edit Menus tab in Appearance -> Menus // Add the test of $_POST['update-nav-menu-nonce'] to avoid conflict with Vantage theme - elseif ( isset( $_POST['action'], $_POST['update-nav-menu-nonce'] ) && 'update' == $_POST['action'] ) { + elseif ( isset( $_POST['action'], $_POST['update-nav-menu-nonce'] ) && 'update' === $_POST['action'] ) { check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); $this->options['nav_menus'][ $this->theme ] = array(); } @@ -253,7 +242,7 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { } if ( is_array( $menus ) ) { - foreach ( $menus as $loc => $menu ) { + foreach ( array_keys( $menus ) as $loc ) { foreach ( $this->model->get_languages_list() as $lang ) { if ( ! empty( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ] ) && term_exists( $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ], 'nav_menu' ) ) { $menus[ $this->combine_location( $loc, $lang ) ] = $this->options['nav_menus'][ $this->theme ][ $loc ][ $lang->slug ]; @@ -271,8 +260,9 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { * @since 1.7.3 * * @param int $term_id nav menu id + * @return void */ - function delete_nav_menu( $term_id ) { + public function delete_nav_menu( $term_id ) { if ( isset( $this->options['nav_menus'] ) ) { foreach ( $this->options['nav_menus'] as $theme => $locations ) { foreach ( $locations as $loc => $languages ) { @@ -287,48 +277,4 @@ class PLL_Admin_Nav_Menu extends PLL_Nav_Menu { update_option( 'polylang', $this->options ); } } - - /** - * Filters the option nav_menu_options for auto added pages to menu - * - * @since 0.9.4 - * - * @param array $options - * @return array Modified options - */ - public function nav_menu_options( $options ) { - $options['auto_add'] = array_intersect( $options['auto_add'], $this->auto_add_menus ); - return $options; - } - - /** - * Filters _wp_auto_add_pages_to_menu by language - * - * @since 0.9.4 - * - * @param string $new_status Transition to this post status. - * @param string $old_status Previous post status. - * @param object $post Post data. - */ - public function auto_add_pages_to_menu( $new_status, $old_status, $post ) { - if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) { - return; - } - - if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) { - $this->auto_add_menus = array(); - - $lang = $this->model->post->get_language( $post->ID ); - $lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned - - // Get all the menus in the page language - foreach ( $this->options['nav_menus'][ $this->theme ] as $loc ) { - if ( ! empty( $loc[ $lang ] ) ) { - $this->auto_add_menus[] = $loc[ $lang ]; - } - } - - add_filter( 'option_nav_menu_options', array( $this, 'nav_menu_options' ) ); - } - } } diff --git a/wp-content/plugins/polylang/admin/admin-notices.php b/wp-content/plugins/polylang/admin/admin-notices.php new file mode 100644 index 00000000..6af9edda --- /dev/null +++ b/wp-content/plugins/polylang/admin/admin-notices.php @@ -0,0 +1,270 @@ +options = &$polylang->options; + + add_action( 'admin_init', array( $this, 'hide_notice' ) ); + add_action( 'admin_notices', array( $this, 'display_notices' ) ); + } + + /** + * Add a custom notice + * + * @since 2.3.9 + * + * @param string $name Notice name + * @param string $html Content of the notice + * @return void + */ + public static function add_notice( $name, $html ) { + self::$notices[ $name ] = $html; + } + + /** + * Get custom notices. + * + * @since 2.3.9 + * + * @return string[] + */ + public static function get_notices() { + return self::$notices; + } + + /** + * Has a notice been dismissed? + * + * @since 2.3.9 + * + * @param string $notice Notice name + * @return bool + */ + public static function is_dismissed( $notice ) { + $dismissed = get_option( 'pll_dismissed_notices', array() ); + + // Handle legacy user meta + $dismissed_meta = get_user_meta( get_current_user_id(), 'pll_dismissed_notices', true ); + if ( is_array( $dismissed_meta ) ) { + if ( array_diff( $dismissed_meta, $dismissed ) ) { + $dismissed = array_merge( $dismissed, $dismissed_meta ); + update_option( 'pll_dismissed_notices', $dismissed ); + } + if ( ! is_multisite() ) { + // Don't delete on multisite to avoid the notices to appear in other sites. + delete_user_meta( get_current_user_id(), 'pll_dismissed_notices' ); + } + } + + return in_array( $notice, $dismissed ); + } + + /** + * Should we display notices on this screen? + * + * @since 2.3.9 + * + * @param string $notice The notice name. + * @return bool + */ + protected function can_display_notice( $notice ) { + $screen = get_current_screen(); + + if ( empty( $screen ) ) { + return false; + } + + $screen_id = sanitize_title( __( 'Languages', 'polylang' ) ); + + /** + * Filter admin notices which can be displayed + * + * @since 2.7.0 + * + * @param bool $display Whether the notice should be displayed or not. + * @param string $notice The notice name. + */ + return apply_filters( + 'pll_can_display_notice', + in_array( + $screen->id, + array( + 'dashboard', + 'plugins', + 'toplevel_page_mlang', + $screen_id . '_page_mlang_strings', + $screen_id . '_page_mlang_settings', + ) + ), + $notice + ); + } + + /** + * Stores a dismissed notice in database + * + * @since 2.3.9 + * + * @param string $notice + * @return void + */ + public static function dismiss( $notice ) { + $dismissed = get_option( 'pll_dismissed_notices', array() ); + + if ( ! in_array( $notice, $dismissed ) ) { + $dismissed[] = $notice; + update_option( 'pll_dismissed_notices', array_unique( $dismissed ) ); + } + } + + /** + * Handle a click on the dismiss button + * + * @since 2.3.9 + * + * @return void + */ + public function hide_notice() { + if ( isset( $_GET['pll-hide-notice'], $_GET['_pll_notice_nonce'] ) ) { + $notice = sanitize_key( $_GET['pll-hide-notice'] ); + check_admin_referer( $notice, '_pll_notice_nonce' ); + self::dismiss( $notice ); + wp_safe_redirect( remove_query_arg( array( 'pll-hide-notice', '_pll_notice_nonce' ), wp_get_referer() ) ); + exit; + } + } + + /** + * Displays notices + * + * @since 2.3.9 + * + * @return void + */ + public function display_notices() { + if ( current_user_can( 'manage_options' ) ) { + // Core notices + if ( defined( 'WOOCOMMERCE_VERSION' ) && ! defined( 'PLLWC_VERSION' ) && $this->can_display_notice( 'pllwc' ) && ! $this->is_dismissed( 'pllwc' ) ) { + $this->pllwc_notice(); + } + + if ( ! defined( 'POLYLANG_PRO' ) && $this->can_display_notice( 'review' ) && ! $this->is_dismissed( 'review' ) && ! empty( $this->options['first_activation'] ) && time() > $this->options['first_activation'] + 15 * DAY_IN_SECONDS ) { + $this->review_notice(); + } + + // Custom notices + foreach ( $this->get_notices() as $notice => $html ) { + if ( $this->can_display_notice( $notice ) && ! $this->is_dismissed( $notice ) ) { + ?> +
+ dismiss_button( $notice ); + echo wp_kses_post( $html ); + ?> +
+ %s', + esc_url( wp_nonce_url( add_query_arg( 'pll-hide-notice', $name ), $name, '_pll_notice_nonce' ) ), + /* translators: accessibility text */ + esc_html__( 'Dismiss this notice.', 'polylang' ) + ); + } + + /** + * Displays a notice if WooCommerce is activated without Polylang for WooCommerce + * + * @since 2.3.9 + * + * @return void + */ + private function pllwc_notice() { + ?> +
+ dismiss_button( 'pllwc' ); ?> +

+ ', + '' + ); + ?> +

+
+ +
+ dismiss_button( 'review' ); ?> +

+ ', + '' + ); + ?> +

+
+ links = &$polylang->links; + // Removes the editor and the template select dropdown for pages for posts + add_filter( 'use_block_editor_for_post', array( $this, 'use_block_editor_for_post' ), 10, 2 ); // Since WP 5.0 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 ); // Add post state for translations of the front page and posts page @@ -26,24 +36,44 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages { // Refresh language cache when a static front page has been translated add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 ); - // Checks if chosen page on front is translated - add_filter( 'pre_update_option_page_on_front', array( $this, 'update_page_on_front' ), 10, 2 ); - add_filter( 'customize_validate_page_on_front', array( $this, 'customize_validate_page_on_front' ), 10, 2 ); - // Prevents WP resetting the option add_filter( 'pre_update_option_show_on_front', array( $this, 'update_show_on_front' ), 10, 2 ); + + add_action( 'admin_notices', array( $this, 'notice_must_translate' ) ); } /** - * Removes the editor for translations of the pages for posts - * Removes the page template select dropdown in page attributes metabox too + * Don't use the block editor for the translations of the pages for posts + * + * @since 2.5 + * + * @param bool $use_block_editor Whether the post can be edited or not. + * @param WP_Post $post The post being checked. + * @return bool + */ + public function use_block_editor_for_post( $use_block_editor, $post ) { + if ( 'page' === $post->post_type ) { + add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) ); + + if ( ( get_option( 'page_for_posts' ) == $post->ID ) && empty( $post->post_content ) ) { + return false; + } + } + + return $use_block_editor; + } + + /** + * Removes the editor for the translations of the pages for posts. + * Removes the page template select dropdown in page attributes metabox too. * * @since 2.2.2 * - * @param string $post_type Current post type - * @param object $post Current post + * @param string $post_type Current post type. + * @param WP_Post $post Current post. + * @return void */ - function add_meta_boxes( $post_type, $post ) { + public function add_meta_boxes( $post_type, $post ) { if ( 'page' === $post_type ) { add_filter( 'option_page_for_posts', array( $this, 'translate_page_for_posts' ) ); @@ -55,34 +85,35 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages { } /** - * Add post state for translations of the front page and posts page + * Adds post state for translations of the front page and posts page. * * @since 1.8 * - * @param array $post_states - * @param object $post - * @return array + * @param string[] $post_states An array of post display states. + * @param WP_Post $post The current post object. + * @return string[] */ public function display_post_states( $post_states, $post ) { if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_on_front' ) ) ) ) { - $post_states['page_on_front'] = __( 'Front Page' ); + $post_states['page_on_front'] = __( 'Front Page', 'polylang' ); } if ( in_array( $post->ID, $this->model->get_languages_list( array( 'fields' => 'page_for_posts' ) ) ) ) { - $post_states['page_for_posts'] = __( 'Posts Page' ); + $post_states['page_for_posts'] = __( 'Posts Page', 'polylang' ); } return $post_states; } /** - * Refresh language cache when a static front page has been translated + * Refreshes the language cache when a static front page has been translated. * * @since 1.8 * - * @param int $post_id Not used - * @param object $post Not used - * @param array $translations + * @param int $post_id Not used. + * @param WP_Post $post Not used. + * @param int[] $translations Translations of the post being saved. + * @return void */ public function pll_save_post( $post_id, $post, $translations ) { if ( in_array( $this->page_on_front, $translations ) ) { @@ -90,63 +121,6 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages { } } - /** - * Checks if a page is translated in all languages - * - * @since 2.2 - * - * @param int $page_id - * @return bool - */ - protected function is_page_translated( $page_id ) { - if ( $page_id ) { - $translations = count( $this->model->post->get_translations( $page_id ) ); - $languages = count( $this->model->get_languages_list() ); - - if ( $languages > 1 && $translations != $languages ) { - return false; - } - } - - return true; - } - - /** - * Prevents choosing an untranslated static front page - * Displays an error message - * - * @since 1.6 - * - * @param int $page_id New page on front page id - * @param int $old_id Old page on front page_id - * @return int - */ - public function update_page_on_front( $page_id, $old_id ) { - if ( ! $this->is_page_translated( $page_id ) ) { - $page_id = $old_id; - add_settings_error( 'reading', 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) ); - } - - return $page_id; - } - - /** - * Displays an error message in the customizer when choosing an untranslated static front page - * - * @since 2.2 - * - * @param object $validity WP_Error object - * @param int $page_id New page on front page id - * @return object - */ - public function customize_validate_page_on_front( $validity, $page_id ) { - if ( ! $this->is_page_translated( $page_id ) ) { - return new WP_Error( 'pll_page_on_front_error', __( 'The chosen static front page must be translated in all languages.', 'polylang' ) ); - } - - return $validity; - } - /** * Prevents WP resetting the option if the admin language filter is active for a language with no pages * @@ -162,4 +136,63 @@ class PLL_Admin_Static_Pages extends PLL_Static_Pages { } return $value; } + + /** + * Add a notice to translate the static front page if it is not translated in all languages + * This is especially useful after a new language is created. + * The notice is not dismissible and displayed on the Languages pages and the list of pages. + * + * @since 2.6 + * + * @return void + */ + public function notice_must_translate() { + $screen = get_current_screen(); + + if ( ! empty( $screen ) && ( 'toplevel_page_mlang' === $screen->id || 'edit-page' === $screen->id ) ) { + $message = $this->get_must_translate_message(); + + if ( ! empty( $message ) ) { + printf( + '

%s

', + $message // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + ); + } + } + } + + /** + * Returns the message asking to translate the static front page in all languages. + * + * @since 2.8 + * + * @return string + */ + public function get_must_translate_message() { + $message = ''; + + if ( $this->page_on_front ) { + $untranslated = array(); + + foreach ( $this->model->get_languages_list() as $language ) { + if ( ! $this->model->post->get( $this->page_on_front, $language ) ) { + $untranslated[] = sprintf( + '%s', + esc_url( $this->links->get_new_post_translation_link( $this->page_on_front, $language ) ), + esc_html( $language->name ) + ); + } + } + + if ( ! empty( $untranslated ) ) { + $message = sprintf( + /* translators: %s is a comma separated list of native language names */ + esc_html__( 'You must translate your static front page in %s.', 'polylang' ), + implode( ', ', $untranslated ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + ); + } + } + + return $message; + } } diff --git a/wp-content/plugins/polylang/admin/admin-strings.php b/wp-content/plugins/polylang/admin/admin-strings.php index 6374ac22..3746dce0 100644 --- a/wp-content/plugins/polylang/admin/admin-strings.php +++ b/wp-content/plugins/polylang/admin/admin-strings.php @@ -1,26 +1,47 @@ array( - 'blogname' => __( 'Site Title' ), - 'blogdescription' => __( 'Tagline' ), - 'date_format' => __( 'Date Format' ), - 'time_format' => __( 'Time Format' ), - ), 'widget_title' => __( 'Widget title', 'polylang' ), 'widget_text' => __( 'Widget text', 'polylang' ), ); - // WP strings - foreach ( self::$default_strings['options'] as $option => $string ) { - self::register_string( $string, get_option( $option ), 'WordPress' ); - } - - // widgets titles + // Widgets titles global $wp_registered_widgets; $sidebars = wp_get_sidebars_widgets(); foreach ( $sidebars as $sidebar => $widgets ) { @@ -74,8 +79,8 @@ class PLL_Admin_Strings { } foreach ( $widgets as $widget ) { - // nothing can be done if the widget is created using pre WP2.8 API :( - // there is no object, so we can't access it to get the widget options + // Nothing can be done if the widget is created using pre WP2.8 API :( + // There is no object, so we can't access it to get the widget options if ( ! isset( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! is_object( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! method_exists( $wp_registered_widgets[ $widget ]['callback'][0], 'get_settings' ) ) { continue; } @@ -83,7 +88,7 @@ class PLL_Admin_Strings { $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings(); $number = $wp_registered_widgets[ $widget ]['params'][0]['number']; - // don't enable widget translation if the widget is visible in only one language or if there is no title + // Don't enable widget translation if the widget is visible in only one language or if there is no title if ( empty( $widget_settings[ $number ]['pll_lang'] ) ) { if ( isset( $widget_settings[ $number ]['title'] ) && $title = $widget_settings[ $number ]['title'] ) { self::register_string( self::$default_strings['widget_title'], $title, 'Widget' ); @@ -109,7 +114,7 @@ class PLL_Admin_Strings { } /** - * performs the sanitization ( before saving in DB ) of default strings translations + * Performs the sanitization ( before saving in DB ) of default strings translations * * @since 1.6 * @@ -117,19 +122,13 @@ class PLL_Admin_Strings { * @param string $name unique name for the string * @return string */ - static public function sanitize_string_translation( $translation, $name ) { - $translation = wp_unslash( trim( $translation ) ); - - if ( false !== ( $option = array_search( $name, self::$default_strings['options'], true ) ) ) { - $translation = sanitize_option( $option, $translation ); - } - + public static function sanitize_string_translation( $translation, $name ) { if ( $name == self::$default_strings['widget_title'] ) { - $translation = strip_tags( $translation ); + $translation = sanitize_text_field( $translation ); } if ( $name == self::$default_strings['widget_text'] && ! current_user_can( 'unfiltered_html' ) ) { - $translation = wp_unslash( wp_filter_post_kses( addslashes( $translation ) ) ); // wp_filter_post_kses() expects slashed + $translation = wp_kses_post( $translation ); } return $translation; diff --git a/wp-content/plugins/polylang/admin/admin.php b/wp-content/plugins/polylang/admin/admin.php index 5e5d5e9f..1a9286f3 100644 --- a/wp-content/plugins/polylang/admin/admin.php +++ b/wp-content/plugins/polylang/admin/admin.php @@ -1,70 +1,104 @@ inherited, reference to Polylang options array - * model => inherited, reference to PLL_Model object - * links_model => inherited, reference to PLL_Links_Model object - * links => inherited, reference to PLL_Admin_Links object - * static_pages => inherited, reference to PLL_Admin_Static_Pages object - * filters_links => inherited, reference to PLL_Filters_Links object - * curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise) - * filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar) - * pref_lang => inherited, preferred language used as default when saving posts or terms - * filters => reference to PLL_Filters object - * filters_columns => reference to PLL_Admin_Filters_Columns object - * filters_post => reference to PLL_Admin_Filters_Post object - * filters_term => reference to PLL_Admin_filters_Term object - * nav_menu => reference to PLL_Admin_Nav_Menu object - * filters_media => optional, reference to PLL_Admin_Filters_Media object + * Main Polylang class for admin (except Polylang pages), accessible from @see PLL(). * * @since 1.2 */ class PLL_Admin extends PLL_Admin_Base { - public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $sync, $filters_media; + /** + * @var PLL_Admin_Filters + */ + public $filters; /** - * loads the polylang text domain - * setups filters and action needed on all admin pages and on plugins page + * @var PLL_Admin_Filters_Columns + */ + public $filters_columns; + + /** + * @var PLL_Admin_Filters_Post + */ + public $filters_post; + + /** + * @var PLL_Admin_Filters_Term + */ + public $filters_term; + + /** + * @var PLL_Admin_Filters_Media + */ + public $filters_media; + + /** + * @since 2.9 + * + * @var PLL_Filters_Sanitization + */ + public $filters_sanitization; + + /** + * @var PLL_Admin_Block_Editor + */ + public $block_editor; + + /** + * @var PLL_Admin_Classic_Editor + */ + public $classic_editor; + + /** + * @var PLL_Admin_Nav_Menu + */ + public $nav_menu; + + /** + * @var PLL_Admin_Filters_Widgets_Options + */ + public $filters_widgets_options; + + /** + * Setups filters and action needed on all admin pages and on plugins page. * * @since 1.2 * - * @param object $links_model + * @param PLL_Links_Model $links_model Reference to the links model. */ public function __construct( &$links_model ) { parent::__construct( $links_model ); - // adds a 'settings' link in the plugins table + // Adds a 'settings' link in the plugins table add_filter( 'plugin_action_links_' . POLYLANG_BASENAME, array( $this, 'plugin_action_links' ) ); add_action( 'in_plugin_update_message-' . POLYLANG_BASENAME, array( $this, 'plugin_update_message' ), 10, 2 ); } /** - * setups filters and action needed on all admin pages and on plugins page - * loads the settings pages or the filters base on the request + * Setups filters and action needed on all admin pages and on plugins page + * Loads the settings pages or the filters base on the request * * @since 1.2 */ public function init() { parent::init(); - // setup filters for admin pages - // priority 5 to make sure filters are there before customize_register is fired + // Setup filters for admin pages + // Priority 5 to make sure filters are there before customize_register is fired if ( $this->model->get_languages_list() ) { add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 ); } } /** - * adds a 'settings' link in the plugins table + * Adds a 'settings' link for our plugin in the plugins list table. * * @since 0.1 * - * @param array $links list of links associated to the plugin - * @return array modified list of links + * @param string[] $links List of links associated to the plugin. + * @return string[] Modified list of links. */ public function plugin_action_links( $links ) { array_unshift( $links, '' . __( 'Settings', 'polylang' ) . '' ); @@ -72,29 +106,35 @@ class PLL_Admin extends PLL_Admin_Base { } /** - * adds the upgrade notice in plugins table + * Adds the upgrade notice in plugins table * * @since 1.1.6 * * @param array $plugin_data Not used * @param object $r Plugin update data + * @return void */ - function plugin_update_message( $plugin_data, $r ) { + public function plugin_update_message( $plugin_data, $r ) { if ( isset( $r->upgrade_notice ) ) { printf( '

%s

', esc_html( $r->upgrade_notice ) ); } } /** - * setup filters for admin pages + * Setup filters for admin pages * * @since 1.2 + * @since 2.7 instantiate a PLL_Bulk_Translate instance. + * @return void */ public function add_filters() { - // all these are separated just for convenience and maintainability - $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Sync' ); + $this->filters_sanitization = new PLL_Filters_Sanitization( $this->get_locale_for_sanitization() ); + $this->filters_widgets_options = new PLL_Admin_Filters_Widgets_Options( $this ); - // don't load media filters if option is disabled or if user has no right + // All these are separated just for convenience and maintainability + $classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Classic_Editor', 'Block_Editor' ); + + // Don't load media filters if option is disabled or if user has no right if ( $this->options['media_support'] && ( $obj = get_post_type_object( 'attachment' ) ) && ( current_user_can( $obj->cap->edit_posts ) || current_user_can( $obj->cap->create_posts ) ) ) { $classes[] = 'Filters_Media'; } @@ -113,4 +153,28 @@ class PLL_Admin extends PLL_Admin_Base { $this->$obj = new $class( $this ); } } + + /** + * Retrieve the locale according to the current language instead of the language + * of the admin interface. + * + * @since 2.0 + * + * @return string + */ + public function get_locale_for_sanitization() { + $locale = get_locale(); + + if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $locale = $lang->locale; + } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $locale = $lang->locale; + } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $locale = $lang->locale; + } elseif ( ! empty( $this->curlang ) ) { + $locale = $this->curlang->locale; + } + + return $locale; + } } diff --git a/wp-content/plugins/polylang/admin/block-editor-filter-preload-paths.php b/wp-content/plugins/polylang/admin/block-editor-filter-preload-paths.php new file mode 100644 index 00000000..01115248 --- /dev/null +++ b/wp-content/plugins/polylang/admin/block-editor-filter-preload-paths.php @@ -0,0 +1,59 @@ +callback = $callback; + + if ( class_exists( 'WP_Block_Editor_Context' ) ) { // Since WP 5.8. + add_filter( 'block_editor_rest_api_preload_paths', array( $this, 'block_editor_rest_api_preload_paths' ), $priority, $arguments_number ); + } else { + add_filter( 'block_editor_preload_paths', $callback, $priority, $arguments_number ); + } + } + + /** + * Filters the array of REST API paths that will be used to preloaded common data to use with the block editor. + * + * Converts the WP_Block_Editor_Context object to a WP_Post if provided in the context. + * + * @since 3.1 + * + * @param string[] $preload_paths The preload paths loaded by the Block Editor. + * @param WP_Block_Editor_Context $block_editor_context The post resource data. + * @return array|mixed|string[] (string|string[])[] + */ + public function block_editor_rest_api_preload_paths( $preload_paths, $block_editor_context = null ) { + if ( null === $block_editor_context ) { + return call_user_func( $this->callback, $preload_paths ); + } elseif ( ! empty( $block_editor_context->post ) ) { + return call_user_func_array( $this->callback, array( $preload_paths, $block_editor_context->post ) ); + } + + return call_user_func_array( $this->callback, array( $preload_paths, $block_editor_context ) ); + } +} diff --git a/wp-content/plugins/polylang/admin/view-translations-media.php b/wp-content/plugins/polylang/admin/view-translations-media.php index a9c7509a..4a44d961 100644 --- a/wp-content/plugins/polylang/admin/view-translations-media.php +++ b/wp-content/plugins/polylang/admin/view-translations-media.php @@ -1,8 +1,9 @@ - flag; ?>name ); ?> + flag; // phpcs:ignore WordPress.Security.EscapeOutput ?>name ); ?> model->post->get_translation( $post_id, $language ) ) && $translation_id !== $post_id ) { + if ( ( $translation_id = $this->model->post->get_translation( $post_ID, $language ) ) && $translation_id !== $post_ID ) { + // The translation exists printf( - '%s', + '', esc_attr( $language->slug ), - esc_attr( $translation_id ), - $this->links->edit_post_translation_link( $translation_id ) + esc_attr( $translation_id ) ); - } - - // No translation - else { - echo $this->links->new_post_translation_link( $post_id, $language ); + echo $this->links->edit_post_translation_link( $translation_id ); // phpcs:ignore WordPress.Security.EscapeOutput + } else { + // No translation + echo $this->links->new_post_translation_link( $post_ID, $language ); // phpcs:ignore WordPress.Security.EscapeOutput } ?> diff --git a/wp-content/plugins/polylang/admin/view-translations-post.php b/wp-content/plugins/polylang/admin/view-translations-post.php index 532da01c..41d45b22 100644 --- a/wp-content/plugins/polylang/admin/view-translations-post.php +++ b/wp-content/plugins/polylang/admin/view-translations-post.php @@ -1,11 +1,12 @@

@@ -17,12 +18,12 @@ if ( ! defined( 'ABSPATH' ) ) { } $value = $this->model->post->get_translation( $post_ID, $language ); - if ( ! $value || $value == $post_ID ) { // $value == $post_ID happens if the post has been ( auto )saved before changing the language + if ( ! $value || $value == $post_ID ) { // $value == $post_ID happens if the post has been (auto)saved before changing the language $value = ''; } - if ( isset( $_GET['from_post'] ) ) { - $value = $this->model->post->get( (int) $_GET['from_post'], $language ); + if ( ! empty( $from_post_id ) ) { + $value = $this->model->post->get( $from_post_id, $language ); } $link = $add_link = $this->links->new_post_translation_link( $post_ID, $language ); @@ -33,9 +34,9 @@ if ( ! defined( 'ABSPATH' ) ) { } ?> - flag ? $language->flag : esc_html( $language->slug ); ?> - - + flag ? $language->flag : esc_html( $language->slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?> + + %2$s + printf( + ' - ', + ', esc_attr( $language->slug ), /* translators: accessibility text */ esc_html__( 'Translation', 'polylang' ), - empty( $value ) ? 0 : esc_attr( $selected->ID ), - empty( $value ) ? '' : esc_attr( $selected->post_title ), - empty( $link ) ? ' disabled="disabled"' : '', + ( empty( $value ) ? 0 : esc_attr( $selected->ID ) ), + ( empty( $value ) ? '' : esc_attr( $selected->post_title ) ), esc_attr( $language->get_locale( 'display' ) ), - $language->is_rtl ? 'rtl' : 'ltr' + ( $language->is_rtl ? 'rtl' : 'ltr' ) ); ?> diff --git a/wp-content/plugins/polylang/admin/view-translations-term.php b/wp-content/plugins/polylang/admin/view-translations-term.php index 03df94ab..b13dd34a 100644 --- a/wp-content/plugins/polylang/admin/view-translations-term.php +++ b/wp-content/plugins/polylang/admin/view-translations-term.php @@ -1,7 +1,8 @@ model->term->get_translation( $term_id, $language ) ) && $translation_id != $term_id ) { $translation = get_term( $translation_id, $taxonomy ); } - if ( isset( $_GET['from_tag'] ) && ( $translation_id = $this->model->term->get( (int) $_GET['from_tag'], $language ) ) && ! $this->model->term->get_translation( $translation_id, $lang ) ) { + if ( ! empty( $from_term_id ) && ( $translation_id = $this->model->term->get( $from_term_id, $language ) ) && ! $this->model->term->get_translation( $translation_id, $lang ) ) { $translation = get_term( $translation_id, $taxonomy ); } @@ -48,7 +49,7 @@ else { ?> - flag ? $language->flag : esc_html( $language->slug ); ?> + flag ? $language->flag : esc_html( $language->slug ); // phpcs:ignore WordPress.Security.EscapeOutput ?> %2$s', @@ -60,25 +61,25 @@ else { - - + + %2$s + printf( + ' ', esc_attr( $language->slug ), /* translators: accessibility text */ esc_html__( 'Translation', 'polylang' ), - empty( $translation ) ? 0 : esc_attr( $translation->term_id ), - empty( $translation ) ? '' : esc_attr( $translation->name ), - empty( $disabled ) ? '' : ' disabled="disabled"', + ( empty( $translation ) ? 0 : esc_attr( $translation->term_id ) ), + ( empty( $translation ) ? '' : esc_attr( $translation->name ) ), + disabled( empty( $disabled ), false, false ), esc_attr( $language->get_locale( 'display' ) ), - $language->is_rtl ? 'rtl' : 'ltr' + ( $language->is_rtl ? 'rtl' : 'ltr' ) ); ?> diff --git a/wp-content/plugins/polylang/changelog.txt b/wp-content/plugins/polylang/changelog.txt index d90a5750..5c8657cc 100644 --- a/wp-content/plugins/polylang/changelog.txt +++ b/wp-content/plugins/polylang/changelog.txt @@ -2,6 +2,471 @@ This file contains only old changelog. See readme.txt for newer versions. += 2.9.2 (2021-02-02) = + +* Pro: Fix translation of CPTUI plural label and description not working +* Add Spanish (Ecuador) to the list of predefined languages +* Fix typo in "WordPress" string translation group. Props Viktor Szépe #682 + += 2.9.1 (2020-12-15) = + +* Fix PHP notice: Undefined property: PLL_Cache_Compat::$options with cache plugins. Props bahaa-almahamid. #658 +* Fix title of the search results page with Yoast SEO > 14.0 + += 2.9 (2020-12-07) = + +* Add compatibility with WordPress 5.6 +* Pro: Add locale fallback used when the theme or plugins translations are not available +* Pro: Fix SSO and browser preferred language redirect when using multiple domains +* Pro: Fix post slugs for German and Danish in the REST API +* Pro: Fix a fatal error in ACF integration when saving url modifications with multiple domains +* Pro: Fix a deprecated notice fired by ACF since the version 5.9.2 +* Pro: Fix ACF relationship fields not reloaded when changing the language in the classic editor +* Update plugin updater to version 1.8 +* Add Lower Sorbian to the list of predefined language +* Options are now translated on backend when using the admin language filter +* Keep previous translations when modifying an option value +* Add navigation markup to the language switcher widget +* Fix canonical redirect for taxonomy terms +* Fix a fatal error when deleting a post with a translation group corrupted in the database +* Fix a fatal error when switching to plain permalinks and using multiple domains +* Fix a conflict with WP Sweep which could corrupt languages +* Fix title displayed instead of meta description with Yoast SEO > 14.0 +* Fix PHP Notice: Undefined index: wp_the_query in /frontend/choose-lang-content.php on line 92 + += 2.8.4 (2020-11-03) = + +* Pro: Remove useless bulk translate action for ACF fields groups +* Pro: Fix the translation of the CPTUI labels when the language is set from the content +* Fix sitemaps redirected to the default language since WP 5.5.1 +* Fix object cache not flushed for sticky posts #601 +* Fix blog page broken when trashing a page and the blog page is not translated in all languages +* Fix custom flags ignored in WPML compatibility mode +* Fix breadcrumb for untranslated post types in Yoast SEO + += 2.8.3 (2020-10-13) = + +* Honor install_languages capability to download language packs +* Pro: Fix integrations not loaded (with The Events Calendar, CPTUI, Content blocks) +* Pro: Fix fatal error with ACF if a flexible content includes a repeater and a relationship +* Pro: Fix terms sharing their slug impossible to update without changing the slug +* When available, use wpcom_vip_get_page_by_path() instead of get_page_by_path() +* Fix queries filtered when editing a post that was declared untranslatable after it got a language +* Fix issues with Yoast SEO 14.0+ (breadcrumbs, canonical, title and description) + += 2.8.2 (2020-09-08) = + +* Pro: Fix posts sharing the same slug displayed on the same page +* Fix: Don't use a javascript localized string removed in WP 5.5 #568 +* Fix fatal error in site health when no language is defined #563 +* Fix various issues with Yoast SEO 14.x #65, #503, #505 +* Fix fatal error with MU Domain Mapping when saving domains in Polylang settings #569 + += 2.8.1 (2020-08-25) = + +* Pro: Fix fatal error with WP 4.9 +* Fix pll_the_languages() with 'raw' option returning html flag instead of flag url #558 +* Fix compatibility with Duplicate Posts not correcly loaded #557 +* Fix custom flag size in admin bar language switcher #559 +* Fix tag clouds mixed in the classic editor #561 + += 2.8 (2020-08-17) = + +* Pro: Add a language switcher block +* Pro: Add compatibility with block image edition introduced in WP 5.5 +* Pro: Fix our private taxonomies being displayed in the ACF field group rules. +* Pro: Fix incorrect flags loaded from the block editor +* Pro: Fix SSO causing a wrong redirect when using subdomains (introduced in 2.7.4) +* Pro: Fix a performance issue on the plugins list +* Pro: Fix option to automatically duplicate media in all languages when uploading a new file not honored in block image +* Use composer for autoload and Polylang Pro dependency on Polylang +* Display a flag for each post in the posts list tables (same for terms). #515 +* Add test for the homepage translations to Site Health +* Add debug information to Site Health +* Add compatibility with the sitemaps introduced in WP 5.5 #451 +* Always filter WP_Query by the current language +* Support wildcards in "admin-texts" parent keys in wpml-config.xml +* Fix sticky posts showed for all languages when the admin language filter is active #469 +* Fix a performance issue on the pages list +* Fix dependency to jQuery Migrate removed from WP 5.5 #539 +* Fix: output secure cookie when using a cache plugin and ssl #542 +* Fix the possibility to create 2 terms with the same name in the same language, without specifying the second slug. +* Fix sticky posts appearing 2 times in WP 5.5 + += 2.7.4 (2020-06-29) = + +* Pro: Allow using our /untranslated-posts REST endpoint for non-public post types +* Pro: Fix broken display in the block editor sidebar when a language has no flag +* Pro: Fix SSO breaking the preview on secondary domains +* Pro: Fix ACF translation option not working for term custom fields +* Pro: Fix a styling issue in the fields group list table in ACF 5.9 +* Add Spanish from Puerto Rico to the predefined list of languages + += 2.7.3 (2020-05-26) = + +* Security: Slash metas +* Pro: Fix categories not savedafter the language has been switched in the block editor +* Pro: Fix ACF fields stored as integers instead of strings +* Pro: Fix ACF untranslated posts or terms being copied when creating a new translation +* Pro: Fix PHP notice with ACF when a repeater or group is included in a flexible content +* Pro: Fix "DevTools failed to load SourceMap" warning in browser console +* Update plugin updater to 1.7.1 +* Honor the filter "pll_the_language_link" when the language switcher displays a dropdown #506 +* Fix "Something went wrong" message when quick editing untranslated post types #508 +* Fix wpseo_opengraph deprecated warning #509 + += 2.7.2 (2020-04-27) = + +* Pro: Re-allow to modify the capability for strings translations +* Pro: Fix redirect for posts having the same slug as a media +* Pro: Fix PHP notice with ACF flexible content +* Pro: Fix a fatal error with InfiniteWP +* Update plugin updater to 1.7 +* Fix font in setup wizard + += 2.7.1 (2020-04-09) = + +* Pro: Fix untranslated post types filtered by the parameter in the REST API #493 +* Fix fatal error when the function idn_to_ascii is not available +* Fix PHP warning warning when a 3rd party plugin declares options not stored in DB in wpml-config.xml #492 +* Fix fatal error when a 3rd party plugin declares options stored as objects in wpml-config.xml #494 + += 2.7 (2020-04-06) = + +* Minimum WordPress version is now 4.9 +* Pro: Strings translations can now be exported and imported (in PO format) +* Pro: Allow to decide individually which ACF fields to copy or synchronize +* Pro: Add action pll_inactive_language_requested +* Pro; Fix fatal error in The Events Calendar compatibility when no language is defined yet +* Pro: Fix bulk translate when a post has no language +* Pro: Fix reusable block saved without language +* Pro: Fix post requested by slug not filtered in REST API, when the slug is shared +* Add a setup wizard +* Add Swahili, Upper Sorbian, Sindhi and Spanish from Uruguay to the list of predefined languages +* Add flags in the predefined list of languages +* Allow to hide the metaboxes from the screen options +* The deletion of the plugin's data at uninstall is now controlled by a PHP constant instead of an option #456 +* Add parent in ajax response when selecting a term in autocomplete field #328 +* Add Vary: Accept-Language http header in home page redirect. Props @chesio #452 +* Improve performance to register/unregister WPML strings +* Add support for the action wpml_switch_language +* Add post_status to the list of accepted args of pll_count_posts() +* Apply the filter pll_preferred_language in wp-login.php +* Use filtered wrappers to create meta when creating media translations #231 +* Allow to translate the Twenty Seventeen header video Youtube url #460 +* Notices are now dismissed per site instead of per user #478 +* Fix terms not visible in the quick edit when only one language is defined and teh admin language filter is active +* Fix post state not displayed for translations of the privacy policy page #395 +* Fix wildcards not correctly interpreted in wpml-config.xml +* Fix product categories with special characters duplicated when importing WooCommerce products #474 + += 2.6.10 (2020-02-19) = + +* Pro: Fix sticky posts not filtered in REST API (introduced in 2.6.9) +* Fix wrong language detected if a child page uses the slug of another language +* Fix a PHP notice with PHP 7.4. #438 +* Fix lang-item-first class in language switcher when the current language is hidden. #445 +* Fix partially a conflict with Fusion Builder (the other part of the conflict being in Fusion Builder). + += 2.6.9 (2020-01-15) = + +* Pro: Use 'parse_query' rather than 'rest_{$type}_query' to filter REST requests. +* Pro: Filter the comments REST endpoint. +* Pro: Fix duplication of terms without language. +* Pro: Fix fatal error when Admin Columns is activated and no language is defined yet. +* Fix shortlink when using one subdomain or domain per language + += 2.6.8 (2019-12-11) = + +* Pro: Fix conflict with JetThemesCore from Crocoblock +* Fix: better detection of REST requests when using plain permalinks +* Fix usage of deprecated action wpmu_new_blog in WP 5.1+ +* Fix PHP notices with PHP 7.4 + += 2.6.7 (2019-11-14) = + +* Require PHP 5.6 +* Fix PHP warning in WP 5.3 + += 2.6.6 (2019-11-12) = + +* Pro: Fix wrong ajax url when using one domain per language +* Pro: Fix conflict with user switching plugin when using multiple domains +* Pro: Fix latest posts block in WP 5.3 +* Fix database error when attempting to sync an untranslated page parent +* Fix a conflict with the theme Neptune by Osetin + += 2.6.5 (2019-10-09) = + +* Pro: Require ACF 5.7.11+ to activate the compatibility to avoid fatal errors with older versions +* Pro: Avoid translating empty front slug (could cause a wrong redirect to /wp-admin) +* Pro: Fix filter wp_unique_term_slug not always correctly applied. +* Pro: Fix a conflict with Divi causing post synchronization buttons to be displayed multiple times +* Avoid notice in WP CLI context + += 2.6.4 (2019-08-27) = + +* Pro: Fix a conflict preventing meta synchronization when ACF is active +* Pro: Fix post metas not correctly copied when translating a Beaver Builder page +* Pro: Fix a fatal error when posts made with Elementor are synchronized +* Pro: Fix Prewiew button not working correctly when using one domain per language +* Pro: Fix post synchronization not available for WP CRON and WP CLI +* Fix future posts not available in the autocomplete input field of the languages metabox +* Fix translations files not loaded on REST requests +* Fix deleted term parent not synchronized + += 2.6.3 (2019-08-06) = + +* Pro: Fix fatal error when updating an ACF field from frontend +* Pro: Add action 'pll_post_synchronized' +* Allow to get the current or default language object using the API. Props Jory Hogeveen. #359 +* Fix empty span in languages switcher widget when showing only flags +* Fix wpml_register_single_string when updating the original string + += 2.6.2 (2019-07-16) = + +* Pro: Fix slow admin in case the translations update server can't be reached +* Pro: Fix value not correctly translated for ACF clone fields in repeater +* Fix strings translations mixed when registered via the WPML compatibility. #381 + += 2.6.1 (2019-07-03) = + +* Pro: Fix Yoast SEO sitemap for inactive languages when using subdomains or multiple domains +* Fix fatal error in combination with Yoast SEO and Social Warfare +* Fix post type archive url in Yoast SEO sitemap + += 2.6 (2019-06-26) = + +* Pro: Remove all languages files. All translations are now maintained on TranslationsPress +* Pro: Move the languages metabox to a block editor plugin +* Pro: Better management of user capabilities when synchronizing posts +* Pro: Separate REST requests from the frontend +* Pro: Copy the post slug when duplicating a post +* Pro: Duplicate ACF term metas when terms are automatically duplicated when creating a new post translation +* Pro: Fix hierarchy lost when duplicating terms +* Pro: Fix page shared slugs with special characters +* Pro: Fix synchronized posts sharing their slug when the language is set from the content +* Pro: Fix PHP warning with ACF Pro 5.8.1 +* Pro: Fix ACF clone fields not translated in repeaters +* Better management of user capablities when synchronizing taxonomies terms and custom fields +* Extend string translations search to translated strings #207 +* Update plugin updater to 1.6.18 +* Honor the filter `pll_flag` when performing the flag validation when creating a new language +* Modify the title and the label for the language switcher menu items #307 +* Add support for international domain names +* Add a title to the link icon used to add a translation #325 +* Add a notice when a static front page is not translated in a language +* Add support for custom term fields in wpml-config.xml +* Add filter `pll_admin_languages_filter` for the list of items the admin bar language filter +* Add compatibility with WP Offload Media Lite. Props Daniel Berkman +* Yoast SEO: Add post type archive url in all languages to the sitemap +* Fix www. not redirected to not www. for the home page in multiple domains #311 +* Fix cropped images not being synchronized +* Fix auto added page to menus when the page is created with the block editor +* Fix embed of translated static front page #318 +* Fix a possible infinite redirect if the static front page is not translated +* Fix incorrect behavior of action 'wpml_register_single_string' when updating the string source +* Fix fatal error with Jetpack when no languages has been defined yet #330 +* Fix a conflict with Laravel Valet. Props @chesio. #250 +* Fix a conflict with Thesis. +* Fix a conflict with Pods in the block editor. Props Jory Hogeveen. #369 +* Fix fatal error with Twenty Fourteen introduced in version 2.5.4. #374 + += 2.5.4 (2019-05-28) = + +* Add Kannada to the predefined languages list +* Yoast SEO: Fix primary product cat not copied or synchronized +* WPMU Domain Mapping: Fix incorrect domain used for the theme +* Fix style-rtl.css not loaded when the language is set from the content #356 +* Fix Jetpack featured pages not working. Props Anis Ladram. #357 +* Fix Call to undefined function wp_generate_attachment_metadata() + += 2.5.3 (2019-04-16) = + +* Add de_AT and pt_AO to the predefined languages list +* Pro: Add filter pll_translate_blocks +* Pro: fix PHP notice when the queried post type has been modified to an array +* Pro: fix PHP warning when combined with The Event Calendar and Page builder by SiteOrigin + += 2.5.2 (2019-02-12) = + +* Pro: Fix translated slugs not accepting forward slashes +* Pro: Fix fatal error with ACF Pro 5.7.11 +* Fix parent categories incorrectly synchronized #327 + += 2.5.1 (2019-01-16) = + +* Security: Fix categories and media duplication not protected from CSRF +* Pro: Allow to update the plugin with WP CLI +* Pro: Fix search in the button block not filtered in the correct language (needs WP 5.1) +* Add Saraiki to the predefined languages list +* Fix a conflict causing a blank page with Divi + += 2.5 (2018-12-06) = + +* Add compatibility with WP 5.0 +* Fix custom flags when the WP content folder is not in the WP install folder +* Fix PHP notice if a language has no flag + += 2.4.1 (2018-11-27) = + +* Pro: Add compatibility with REST API changes made in WP 5.0 +* Pro: Fix sticky posts in the REST API +* Pro: Fix overwritten custom post slug when the post is updated with the REST API +* Pro: Fix bulk translate for media +* Fix a conflict with Custom sidebars and Content aware sidebars +* Fix a conflict with the theme Pokemania +* Fix PHP notices when using the function 'icl_link_to_element' for terms +* Fix title slugs for posts written in German + += 2.4 (2018-11-12) = + +* Minimum WordPress version is now 4.7 +* Pro: Add the possibility to bulk duplicate or bulk synchronize posts. +* Pro: Add compatibility with Admin Columns +* Pro: Add synchronized posts to the REST API +* Pro: Fix variations messed when changing WooCommerce attributes slugs +* Pro: Fix incorrect language for ajax requests made on front by The Events Calendar +* Pro: Fix term not duplicated correctly when the language is set from the content +* Refactor the core to activate on front and for the REST api actions that were previously available only in the backend (language checks, synchronizations...). +* Add flags to widgets displayed in only one language (Props Jory Hogeveen) #257 +* Honor the filter 'pll_the_language_args' for all options in menus #237 +* Add better filters for default flags and custom flags +* Custom flags can now be stored in the polylang directory in the theme +* Custom flags can now use SVG +* Add compatibility with Jetpack featured content module +* Fix Twenty Fourteen featured posts possibly not filtered per language +* Fix home url not working with WordPress MU Domain mapping +* Fix Assigning a parent category breaking the hierarchy of translated category +* Fix: Accept 0,1 and 1.0 as q factors in browser preferred language detection (Props Dominic Rubas) +* Fix performance issue when using hundreds of widgets +* Fix translations possibly wrong if the post language is changed without saving the post after + += 2.3.11 (2018-10-03) = + +* Pro: Add action 'pll_created_sync_post' +* Pro: Fix language and translations not included for tags in the REST API +* Fix Assigning a parent category breaking the hierarchy of translated category + += 2.3.10 (2018-08-16) = + +* Fix Lingotek notice not dismissable +* Fix fatal error with the widget calendar + += 2.3.9 (2018-08-14) = + +* Add a notice to inform about Polylang for WooCommerce +* Deprecate PLL_Pointer +* Fix bulk editing pages with no language breaking hierarchy #281 +* Fix an edge case where rewrite rules could be messed on a multisite +* MU Domain Mapping: fix secondary domain redirected to primary domain + += 2.3.8 (2018-07-16) = + +* Pro: Duplicate term meta when duplicating a post creates new terms +* Pro: Add compatibility with ACF Pro when it's bundled with the theme +* Pro: Fix a fatal error when duplicating posts +* Set cookie during the home redirect +* Accept a port in the url to detect the site home +* Add filter 'pll_is_cache_active' to allow to load the cache compatibility #270 #274 +* Fix potential fatal error when a 3rd party misuses the 'wpml_active_languages' filter #268 +* Fix Uncaught TypeError: s.split is not a function. Props Wouter Van Vliet #262 +* Fix text alignment for RTL scripts in Lingotek panel #247 +* Fix html language attribute filter on admin +* Fix cookie expiration time when set in js. Props Jens Nachtigall #271 +* Fix fatal error when a 3rd party misuses the WP_Query tax_query param. Props JanneAalto #252 +* Fix an edge case which could mess home pages on a multisite + + += 2.3.7 (2018-06-07) = + +* Pro: The Events Calendar: Fix untranslated events shown in all languages +* Avoid displaying edit links of translations of the privacy policy page to non-admin +* Fix draft created when creating a new page on multisite +* Do not prevent using the cache for home when using WP Rocket 3.0.5 or later #236 +* Fix language filter applied to wrong queries on admin side + += 2.3.6 (2018-05-17) = + +* Pro: Fix post type archive slug not translated in ACF page link fields +* WP 4.9.6: Translate the privacy policy page +* WP 4.9.6: Add the translated user descriptions to exported personal data +* Update Plugin updater to version 1.6.16 +* Fix conflict with the plugin View Admin As. Props Jory Hogeveen. #253 + += 2.3.5 (2018-05-08) = + +* Pro: Fix translated CPT slugs when one CPT name is a substring of another one. Props Steve Reimer. +* Pro: Fix canonical redirection for post types archives when the CPT slug is translated +* Pro: Fix ACF private key uselessly synchronized when the public custom field is not synchronized +* Add filter 'pll_filter_query_excluded_query_vars' +* Redirect www. to non www. when using multiple domains +* Fix Yoast SEO category sitemap not filtered by language when using multiple domains +* Fix PLL_COOKIE === false not honored when using a cache plugin. #248 +* Fix empty predefined languages list + += 2.3.4 (2018-03-27) = + +* Pro: Fix conflict with Pods related to translated slugs for custom post types +* Add Friulian to the predefined languages list +* Fix conflict (javascript error) with Gütenberg #225 +* Fix conflict on ajax requests introduced by WooCoommerce 3.3.4 +* Fix queries by 'category_name' not auto translated #238 + += 2.3.3 (2018-03-15) = + +* Pro: Fix tax query using a term sharing slugs (fix a conflict with Fusion Builder) +* Restore Polylang (free) on REST requests, while disabling the language filter as in v2.3 +* Rework auto translated query with taxonomy in different language #223 +* Synchronize Yoast SEO primary category (needs Yoast SEO 7.0+) +* Fix PHP warning introduced by Yoast SEO 7.0 #229 +* Fix tax query when using the relation 'OR' +* Fix a conflict with the combination of Barrel + WP Bakery Page Builder +* Fix broken redirect with MU domain mapping #226 +* Fix site title not translated in password change email + += 2.3.2 (2018-03-05) = + +* Pro: Fix REST requests not filtered by the requested language (introduced in 2.3). +* Pro: Fix error 404 on single posts if posts are untranslatable +* Deactivate Polylang (free) on REST requests by default. +* Fix translated terms unassigned from posts when deleting a term +* Fix auto translated query with taxonomy in different language returning empty results since WP 4.9 #223 +* Fix conflict with a homepage option of the theme Extra +* Fix warning when filtering get_pages() + += 2.3.1 (2018-02-15) = + +* Pro: Fix GET REST request with slug parameter deleting the post slug +* Fix http request with a custom query var being redirected to the home page #216 + += 2.3 (2018-01-30) = + +* Pro: Duplicating a post now duplicates untranslated terms and the featured image (if media are translatable) +* Pro: Add filter 'pll_sync_post_fields' +* Pro: Translate ACF Pro clone fields when creating a new field group translation +* Pro: Allow to share slugs when creating a post or term with the REST API +* Pro: Load asynchronously the script added on front for multiple domains and subdomains +* Pro: Fix 'lang' parameter not interpreted when the query includes 'name' +* Refactor the synchronization of metas for better synchronization and performance improvement +* Refactor the synchronization of taxonomy terms for performance improvement +* Refactor language and translations saving for performance improvement +* Refactor the synchronization of sticky posts +* Remove all languages files. All translations are now maintained on https://translate.wordpress.org/projects/wp-plugins/polylang #199 +* Refactor the list of languages to merge predefined languages, Facebook locales and fixes for W3C locales +* Automatically deactivate Polylang when activating Polylang Pro +* Disable programmatically translated post types and taxonomies in settings. Props Ulrich Pogson. #180 +* Set the cookie language in Javascript when a cache plugin is active +* Automatically remove the home page from cache when requesting the detection of the browser preferred language +* Use relative urls for the admin language filter in admin bar. #209 +* Disable auto translation of WP_Term_Query if it has a 'lang' parameter +* Don't filter REST requests by default. #211 +* Fix Yoast SEO statistics in dashboard showing only the default language. #211 +* Fix WP Rocket clearing the cache of the wrong adjacent post +* Fix random header image +* Fix home page not correctly loaded when adding a query var +* Fix: Impossible to change the language code when the language code is also a WordPress locale. + = 2.2.8 (2018-01-09) = * Pro: Fix: Impossible to link past events by translation in The Events Calendar @@ -1470,4 +1935,3 @@ This version does include important changes in database. More than ever, make a = 0.1 (2011-09-22) = * Initial release - diff --git a/wp-content/plugins/polylang/css/admin.min.css b/wp-content/plugins/polylang/css/admin.min.css deleted file mode 100644 index bb5a7b37..00000000 --- a/wp-content/plugins/polylang/css/admin.min.css +++ /dev/null @@ -1 +0,0 @@ -#pll-licenses-table td,.translation label{vertical-align:top}#add-lang select{width:95%}.column-locale,.languages .column-slug{width:15%}.column-default_lang{width:5%}.column-count,.column-flag,.column-term_group{width:10%}.icon-default-lang:before{font-family:dashicons;content:"\f155"}.form-field input[type=radio]{width:auto;margin-right:2px}#pll-about-box p,#pll-recommended p{text-align:justify}#pll-about-box input{margin:0;padding:0;float:right}.stringstranslations .column-context,.stringstranslations .column-name{width:10%}.stringstranslations .column-string{width:33%}.translation label{display:inline-block;width:23%}.translation input,.translation textarea{width:72%}.pll-settings{margin-top:20px}.pll-settings .plugin-title{width:25%}#wpbody-content .pll-settings .pll-configure tr{display:table-row}#wpbody-content .pll-settings .pll-configure td{display:table-cell}#wpbody-content .pll-settings .pll-configure>td{padding:20px 20px 20px 40px}.pll-configure legend{font-size:14px;font-weight:600;margin-bottom:.5em}.pll-configure td .description{margin-top:2px;margin-bottom:.5em}.pll-configure p.submit{margin-top:20px}.pll-configure .button{margin-right:20px}.pll-configure fieldset{margin-bottom:1.5em}.pll-inline-block-list{margin:0}.pll-inline-block-list li{display:inline-block;margin:0;width:250px}#pll-domains-table td{padding:2px 2px 2px 1.5em;-webkit-box-shadow:none;box-shadow:none;border:none}.pll-settings-url-col{display:inline-block;width:49%;vertical-align:top}#pll-licenses-table label{font-size:1em;font-weight:600}.pll-configure .pll-deactivate-license{margin:0 0 0 20px}td[class*=column-language_],th[class*=column-language_]{width:1.5em}.pll-dir-rtl input[type=text],.pll-dir-rtl textarea{direction:rtl}.pll-dir-ltr input[type=text],.pll-dir-ltr textarea{direction:ltr}.pll-dir-ltr .tr_lang,.pll-dir-rtl .tr_lang{direction:inherit}#post-translations p{float:left}#post-translations table{table-layout:fixed;width:100%;clear:both}#post-translations a{text-decoration:none}#post-translations .pll-column-icon,#post-translations .pll-language-column{width:20px}#post-translations .tr_lang{width:100%}#post-translations td{padding:2px}#post-translations .spinner,#term-translations .spinner{float:none;margin:0;background-position:center;width:auto}.pll-column-icon{text-align:center}#select-post-language .pll-select-flag{padding:4px;margin-right:32px}#select-media-language .pll-select-flag{padding:4px;margin-right:10px}.pll-media-edit-column{float:right}.pll-translation-flag{margin-right:14px}#select-add-term-language .pll-select-flag{padding:11px;margin-right:13px}#select-edit-term-language .pll-select-flag{padding:11px;margin-right:4px}#term-translations p{font-size:12px;font-style:normal;padding:2px;color:#23282d}#add-term-translations,#edit-term-translations{width:95%}#term-translations .pll-language-column{line-height:28px;width:20%}#add-term-translations .pll-language-column,#term-translations .pll-edit-column{width:20px}#edit-term-translations .pll-language-column{padding:15px 10px;font-weight:400}.pll_icon_tick:before{content:"\f147"}.pll_icon_add:before{content:"\f132"}.pll_icon_edit:before{content:"\f464"}[class^=pll_icon_]{font:20px/1 dashicons;vertical-align:middle}#wpadminbar #wp-admin-bar-languages .ab-item img{margin:0 8px 0 2px}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{float:none;top:4px}#wpadminbar #wp-admin-bar-languages .ab-icon:before{content:"\f326";top:1px}@media screen and (max-width:782px){#wpbody-content .pll-settings .pll-configure>td{padding:20px}#wpbody-content .pll-settings #cb{padding:20px 9px}.pll-inline-block{width:auto}.pll-settings-url-col{display:block;width:100%}#wpbody-content .pll-settings #pll-licenses-table td{display:block}.pll-configure .pll-deactivate-license{margin:10px 0 5px}.stringstranslations .column-context,.stringstranslations .column-name{display:none}.translation label{display:block;width:95%;padding-left:0}.translation input{width:95%}#edit-term-translations .pll-language-name,#select-add-term-language .pll-select-flag,#select-edit-term-language .pll-select-flag{display:none}#edit-term-translations{width:100%}#add-term-translations .pll-language-column{line-height:38px}#edit-term-translations td{padding:8px 10px}#edit-term-translations .pll-edit-column,#edit-term-translations .pll-language-column{width:20px}.term-translations .pll-edit-column,.term-translations .pll-language-column,.term-translations .pll-translation-column{display:table-cell}.term-translations .hidden{display:none}#wpadminbar #wp-admin-bar-languages{display:block}#wpadminbar #wp-admin-bar-languages>.ab-item{width:50px;text-align:center}#wpadminbar #wp-admin-bar-languages>.ab-item .ab-icon:before{font:32px/1 dashicons;top:-1px}#wpadminbar #wp-admin-bar-languages>.ab-item img{margin:19px 0}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{margin-right:6px;font-size:20px!important;line-height:20px!important}} diff --git a/wp-content/plugins/polylang/css/admin.css b/wp-content/plugins/polylang/css/build/admin.css similarity index 72% rename from wp-content/plugins/polylang/css/admin.css rename to wp-content/plugins/polylang/css/build/admin.css index ca4a2ea1..a06f572f 100644 --- a/wp-content/plugins/polylang/css/admin.css +++ b/wp-content/plugins/polylang/css/build/admin.css @@ -3,6 +3,19 @@ width: 95%; } +#add-lang label { + margin: 0.35em 0 0.5em; +} + +.pll-legend { + display: block; + padding: 2px 0; + color: #1d2327; + font-weight: 400; + text-shadow: none; + margin: 0.35em 0 0.5em; +} + .column-locale, .languages .column-slug { width : 15% @@ -21,10 +34,13 @@ font-family: 'dashicons'; content: "\f155"; } - -.form-field input[type="radio"] { - width: auto; - margin-right: 2px; +.pll-icon:before{ + display: inline-block; + text-align: left; + width: 15px; +} +.pll-circle:before{ + content: "\25cf"; } /* about Polylang metabox */ @@ -55,9 +71,22 @@ vertical-align: top; } +.translation { + display: flex; /* fix #691 to remove default margin bottom */ +} +@media screen and (max-width: 782px) { /* reset default display property for small device */ + .translation{ + display: block; + } +} +.translation textarea{ + display: block; /* fix #691 to remove default margin bottom */ +} .translation input, .translation textarea { width: 72%; + box-sizing: border-box; /* to be sure field don't overrun outside their wrapper */ + margin-bottom: 4px; /* fix #691 set the same margin bottom for both textarea and input tags */ } /* settings */ @@ -143,9 +172,10 @@ } /* language columns in edit.php and edit-tags.php */ -th[class*='column-language_'], -td[class*='column-language_'] { +.wp-list-table th[class*='column-language_'], +.wp-list-table td[class*='column-language_'] { width: 1.5em; + box-sizing: content-box; /* Override ACF 5.9.0 styles */ } /* Text direction in post.php and edit-tags.php */ @@ -165,8 +195,17 @@ td[class*='column-language_'] { } /* languages metabox in post.php */ +#ml_box p { + margin-top: 1em; +} + #post-translations p { float: left; + margin-top: 1em; +} + +.rtl #post-translations p { + float: right; } #post-translations table { @@ -200,13 +239,15 @@ td[class*='column-language_'] { width: auto; } -.pll-column-icon { - text-align: center; -} - #select-post-language .pll-select-flag { padding: 4px; - margin-right: 32px; + margin-right: 10px; +} + +.rtl #select-post-language .pll-select-flag { + padding: 4px; + margin-right: 0px; + margin-left: 10px; } /* specific cases for media */ @@ -236,7 +277,7 @@ td[class*='column-language_'] { #term-translations p { /* same style as label */ - font-size: 12px; + font-weight: 400; font-style: normal; padding: 2px; color: #23282d; @@ -263,12 +304,10 @@ td[class*='column-language_'] { } /* icon fonts */ -.pll_icon_tick:before { - content: "\f147"; -} .pll_icon_add:before { content: "\f132"; } + .pll_icon_edit:before { content: "\f464"; } @@ -293,6 +332,47 @@ td[class*='column-language_'] { top: 1px; } +#wp-admin-bar-languages.pll-filtered-languages { + background: #a03f3f; +} +/* Enforce white color for WordPress admin light theme. */ +#wpadminbar #wp-admin-bar-languages.pll-filtered-languages span.ab-label{ + color: #fff; +} + +/* Notices */ +.pll-notice.notice { + padding-right: 38px; + position: relative; +} + +.pll-notice a.notice-dismiss { + text-decoration: none; +} + +.pll-notice .button { + margin-right: 10px; +} + +/* Metaboxes holder in Strings translations screen */ +.languages_page_mlang_strings .metabox-holder > div { + display: flex; +} +.languages_page_mlang_strings .metabox-holder > div > div { + flex-grow: 1; +} +.languages_page_mlang_strings .metabox-holder > div > div:nth-child(2n) { + margin-left: 1rem; +} +.languages_page_mlang_strings .metabox-holder > div > div.closed { + border:0; + background: none; +} +.languages_page_mlang_strings .metabox-holder > div > div.closed .postbox-header{ + border: 1px solid #ccd0d4; + background: #fff; +} + @media screen and ( max-width: 782px ) { /* settings */ #wpbody-content .pll-settings .pll-configure > td { @@ -323,21 +403,25 @@ td[class*='column-language_'] { } /* strings translations table */ - .stringstranslations .column-context, - .stringstranslations .column-name { - display: none; /* backward compatibility WP < 4.3 */ - } - .translation label { display: block; width: 95%; padding-left: 0; } - .translation input { + .translation input, + .translation textarea { width: 95%; } + /* Metaboxes holder in Strings translations screen */ + .languages_page_mlang_strings .metabox-holder > div { + flex-direction: column; + } + .languages_page_mlang_strings .metabox-holder > div > div:nth-child(2n) { + margin-left: 0; + } + /* hide selected language flag and translations language name */ #select-add-term-language .pll-select-flag, #select-edit-term-language .pll-select-flag, diff --git a/wp-content/plugins/polylang/css/build/admin.min.css b/wp-content/plugins/polylang/css/build/admin.min.css new file mode 100644 index 00000000..a289211f --- /dev/null +++ b/wp-content/plugins/polylang/css/build/admin.min.css @@ -0,0 +1 @@ +#add-lang select{width:95%}#add-lang label,.pll-legend{margin:.35em 0 .5em}.pll-legend{color:#1d2327;display:block;font-weight:400;padding:2px 0;text-shadow:none}.column-locale,.languages .column-slug{width:15%}.column-default_lang{width:5%}.column-count,.column-flag,.column-term_group{width:10%}.icon-default-lang:before{content:"\f155";font-family:dashicons}.pll-icon:before{display:inline-block;text-align:left;width:15px}.pll-circle:before{content:"\25cf"}#pll-about-box p,#pll-recommended p{text-align:justify}#pll-about-box input{float:right;margin:0;padding:0}.stringstranslations .column-context,.stringstranslations .column-name{width:10%}.stringstranslations .column-string{width:33%}.translation label{display:inline-block;vertical-align:top;width:23%}.translation{display:flex}@media screen and (max-width:782px){.translation{display:block}}.translation textarea{display:block}.translation input,.translation textarea{box-sizing:border-box;margin-bottom:4px;width:72%}.pll-settings{margin-top:20px}.pll-settings .plugin-title{width:25%}#wpbody-content .pll-settings .pll-configure tr{display:table-row}#wpbody-content .pll-settings .pll-configure td{display:table-cell}#wpbody-content .pll-settings .pll-configure>td{padding:20px 20px 20px 40px}.pll-configure legend{font-size:14px;font-weight:600;margin-bottom:.5em}.pll-configure td .description{margin-bottom:.5em;margin-top:2px}.pll-configure p.submit{margin-top:20px}.pll-configure .button{margin-right:20px}.pll-configure fieldset{margin-bottom:1.5em}.pll-inline-block-list{margin:0}.pll-inline-block-list li{display:inline-block;margin:0;width:250px}#pll-domains-table td{border:none;-webkit-box-shadow:none;box-shadow:none;padding:2px 2px 2px 1.5em}.pll-settings-url-col{display:inline-block;vertical-align:top;width:49%}#pll-licenses-table td{vertical-align:top}#pll-licenses-table label{font-size:1em;font-weight:600}.pll-configure .pll-deactivate-license{margin:0 0 0 20px}.wp-list-table td[class*=column-language_],.wp-list-table th[class*=column-language_]{box-sizing:content-box;width:1.5em}.pll-dir-rtl input[type=text],.pll-dir-rtl textarea{direction:rtl}.pll-dir-ltr input[type=text],.pll-dir-ltr textarea{direction:ltr}.pll-dir-ltr .tr_lang,.pll-dir-rtl .tr_lang{direction:inherit}#ml_box p{margin-top:1em}#post-translations p{float:left;margin-top:1em}.rtl #post-translations p{float:right}#post-translations table{clear:both;table-layout:fixed;width:100%}#post-translations a{text-decoration:none}#post-translations .pll-column-icon,#post-translations .pll-language-column{width:20px}#post-translations .tr_lang{width:100%}#post-translations td{padding:2px}#post-translations .spinner,#term-translations .spinner{background-position:50%;float:none;margin:0;width:auto}#select-post-language .pll-select-flag{margin-right:10px;padding:4px}.rtl #select-post-language .pll-select-flag{margin-left:10px;margin-right:0;padding:4px}#select-media-language .pll-select-flag{margin-right:10px;padding:4px}.pll-media-edit-column{float:right}.pll-translation-flag{margin-right:14px}#select-add-term-language .pll-select-flag{margin-right:13px;padding:11px}#select-edit-term-language .pll-select-flag{margin-right:4px;padding:11px}#term-translations p{color:#23282d;font-style:normal;font-weight:400;padding:2px}#add-term-translations,#edit-term-translations{width:95%}#term-translations .pll-language-column{line-height:28px;width:20%}#add-term-translations .pll-language-column,#term-translations .pll-edit-column{width:20px}#edit-term-translations .pll-language-column{font-weight:400;padding:15px 10px}.pll_icon_add:before{content:"\f132"}.pll_icon_edit:before{content:"\f464"}[class^=pll_icon_]{font:20px/1 dashicons;vertical-align:middle}#wpadminbar #wp-admin-bar-languages .ab-item img{margin:0 8px 0 2px}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{float:none;top:4px}#wpadminbar #wp-admin-bar-languages .ab-icon:before{content:"\f326";top:1px}#wp-admin-bar-languages.pll-filtered-languages{background:#a03f3f}#wpadminbar #wp-admin-bar-languages.pll-filtered-languages span.ab-label{color:#fff}.pll-notice.notice{padding-right:38px;position:relative}.pll-notice a.notice-dismiss{text-decoration:none}.pll-notice .button{margin-right:10px}.languages_page_mlang_strings .metabox-holder>div{display:flex}.languages_page_mlang_strings .metabox-holder>div>div{flex-grow:1}.languages_page_mlang_strings .metabox-holder>div>div:nth-child(2n){margin-left:1rem}.languages_page_mlang_strings .metabox-holder>div>div.closed{background:none;border:0}.languages_page_mlang_strings .metabox-holder>div>div.closed .postbox-header{background:#fff;border:1px solid #ccd0d4}@media screen and (max-width:782px){#wpbody-content .pll-settings .pll-configure>td{padding:20px}#wpbody-content .pll-settings #cb{padding:20px 9px}.pll-inline-block{width:auto}.pll-settings-url-col{display:block;width:100%}#wpbody-content .pll-settings #pll-licenses-table td{display:block}.pll-configure .pll-deactivate-license{margin:10px 0 5px}.translation label{display:block;padding-left:0;width:95%}.translation input,.translation textarea{width:95%}.languages_page_mlang_strings .metabox-holder>div{flex-direction:column}.languages_page_mlang_strings .metabox-holder>div>div:nth-child(2n){margin-left:0}#edit-term-translations .pll-language-name,#select-add-term-language .pll-select-flag,#select-edit-term-language .pll-select-flag{display:none}#edit-term-translations{width:100%}#add-term-translations .pll-language-column{line-height:38px}#edit-term-translations td{padding:8px 10px}#edit-term-translations .pll-edit-column,#edit-term-translations .pll-language-column{width:20px}.term-translations .pll-edit-column,.term-translations .pll-language-column,.term-translations .pll-translation-column{display:table-cell}.term-translations .hidden{display:none}#wpadminbar #wp-admin-bar-languages{display:block}#wpadminbar #wp-admin-bar-languages>.ab-item{text-align:center;width:50px}#wpadminbar #wp-admin-bar-languages>.ab-item .ab-icon:before{font:32px/1 dashicons;top:-1px}#wpadminbar #wp-admin-bar-languages>.ab-item img{margin:19px 0}#wpadminbar #wp-admin-bar-languages #wp-admin-bar-all .ab-item .ab-icon{font-size:20px!important;line-height:20px!important;margin-right:6px}} \ No newline at end of file diff --git a/wp-content/plugins/polylang/css/build/dialog.css b/wp-content/plugins/polylang/css/build/dialog.css new file mode 100644 index 00000000..103d15af --- /dev/null +++ b/wp-content/plugins/polylang/css/build/dialog.css @@ -0,0 +1,85 @@ +/* By default Polylang dialog box use WordPress jQuery UI dialog styles. + However WooCommerce loads its own jQuery UI dialog styles and we need to override them by ours + to revert to the default WordPress ones. +*/ +.pll-confirmation-modal.ui-widget, +.pll-confirmation-modal.ui-widget .ui-widget, +.pll-confirmation-modal .ui-widget { + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; + font-size: 13px; +} +.pll-confirmation-modal.ui-dialog { + padding: 0; + z-index: 100102; + background: #fff; + border: 0; + color: #444; + border-radius: 0; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */ +} +.ui-dialog.pll-confirmation-modal .ui-dialog-titlebar { + background: #fcfcfc; + border-radius: 0; + border: 0; + border-bottom: 1px solid #dfdfdf; + height: 36px; + font-size: 18px; + font-weight: 600; + line-height: 2; + padding: 0 36px 0 16px; + color: #444; + position: static; +} +.ui-dialog.pll-confirmation-modal .ui-dialog-title { + float: none; + width: auto; + margin: 0; +} +.pll-confirmation-modal .ui-widget-header .ui-icon { + background: none; + position: static; +} +.pll-confirmation-modal .ui-button.ui-dialog-titlebar-close { + padding: 0; + margin: 0; + top: 0; + right: 0; + width: 36px; + height: 36px; + border: 0; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */ + background: none; /* Override WooCommerce dialog styles - jQuery UI 1.11.4 - WP < 5.6 */ +} +.ui-dialog.pll-confirmation-modal .ui-dialog-content { + border: 0; + padding: 16px; + color: #444; + position: static; + box-sizing: border-box; +} +.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane{ + margin: 0; + padding: 16px; + border: 0; + background: #fcfcfc; + border-top: 1px solid #dfdfdf; +} +.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane .ui-button{ + margin: 0 0 0 16px; + padding: 0 10px 1px; + background: #f7f7f7; + border: 1px solid #cccccc; + border-radius: 3px; + position: static; + line-height: 2; + vertical-align: top; +} +.ui-dialog.pll-confirmation-modal .ui-button:hover, +.ui-dialog.pll-confirmation-modal .ui-button:focus { + background: #fafafa; + border-color: #999; + color: #23282d; +} +.pll-confirmation-modal + .ui-widget-overlay { + background: #000; + opacity: 0.7; + z-index: 100101; +} diff --git a/wp-content/plugins/polylang/css/build/dialog.min.css b/wp-content/plugins/polylang/css/build/dialog.min.css new file mode 100644 index 00000000..c56daa33 --- /dev/null +++ b/wp-content/plugins/polylang/css/build/dialog.min.css @@ -0,0 +1 @@ +.pll-confirmation-modal.ui-widget,.pll-confirmation-modal .ui-widget,.pll-confirmation-modal.ui-widget .ui-widget{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px}.pll-confirmation-modal.ui-dialog{background:#fff;border:0;border-radius:0;color:#444;padding:0;z-index:100102}.ui-dialog.pll-confirmation-modal .ui-dialog-titlebar{background:#fcfcfc;border:0;border-bottom:1px solid #dfdfdf;border-radius:0;color:#444;font-size:18px;font-weight:600;height:36px;line-height:2;padding:0 36px 0 16px;position:static}.ui-dialog.pll-confirmation-modal .ui-dialog-title{float:none;margin:0;width:auto}.pll-confirmation-modal .ui-widget-header .ui-icon{background:none;position:static}.pll-confirmation-modal .ui-button.ui-dialog-titlebar-close{background:none;border:0;height:36px;margin:0;padding:0;right:0;top:0;width:36px}.ui-dialog.pll-confirmation-modal .ui-dialog-content{border:0;box-sizing:border-box;color:#444;padding:16px;position:static}.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane{background:#fcfcfc;border:0;border-top:1px solid #dfdfdf;margin:0;padding:16px}.ui-dialog.pll-confirmation-modal .ui-dialog-buttonpane .ui-button{background:#f7f7f7;border:1px solid #ccc;border-radius:3px;line-height:2;margin:0 0 0 16px;padding:0 10px 1px;position:static;vertical-align:top}.ui-dialog.pll-confirmation-modal .ui-button:focus,.ui-dialog.pll-confirmation-modal .ui-button:hover{background:#fafafa;border-color:#999;color:#23282d}.pll-confirmation-modal+.ui-widget-overlay{background:#000;opacity:.7;z-index:100101} \ No newline at end of file diff --git a/wp-content/plugins/polylang/css/build/selectmenu.css b/wp-content/plugins/polylang/css/build/selectmenu.css new file mode 100644 index 00000000..6040faa2 --- /dev/null +++ b/wp-content/plugins/polylang/css/build/selectmenu.css @@ -0,0 +1,239 @@ +/* Greatly modified version of the jquery-ui.css */ + +.ui-widget-overlay { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; +} + +.ui-menu { + list-style: none; + padding: 0; + margin: 0; + display: block; + outline: none; +} + +.ui-menu .ui-menu { + position: absolute; +} + +.ui-menu .ui-menu-item { + position: relative; + margin: 0; + padding: 3px 1em 3px .4em; + cursor: pointer; + min-height: 0; /* support: IE7 */ + /* support: IE10, see #8844 */ + list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); +} + +/* for jQuery UI 1.12 which introduces a wrapper */ +.ui-menu .ui-menu-item:not([role]) { + padding: 0; +} + +.ui-menu-item-wrapper { + padding: 3px 1em 3px 2em; +} +.rtl .ui-menu .ui-menu-item { + text-align: right; +} + +/* icon support */ +.ui-menu-icons { + position: relative; +} + +.ui-menu-icons .ui-menu-item[role] { + padding-left: 2em; +} + +.rtl .ui-menu-item-wrapper, /* for jQuery UI 1.12 which introduces a wrapper */ +.rtl .ui-menu-icons .ui-menu-item[role] { + padding-left: 1em; + padding-right: 2em; +} + +/* left-aligned */ +.ui-selectmenu-text .ui-icon, +.ui-menu .ui-icon { + position: absolute; + top: 0; + bottom: 0; + left: .3em; + margin: auto 0; +} + +.rtl .ui-selectmenu-text .ui-icon, +.rtl .ui-menu .ui-icon { + right: .3em; + left: auto; +} + +/* right-aligned */ +.ui-menu .ui-menu-icon { + left: auto; + right: 0; +} + +.ui-selectmenu-menu { + padding: 0; + margin: 0; + position: absolute; + top: 0; + left: 0; + display: none; +} + +.ui-selectmenu-menu .ui-menu { + overflow: auto; + /* Support: IE7 */ + overflow-x: hidden; + padding-bottom: 1px; +} + +.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup { + font-size: 1em; + font-weight: bold; + line-height: 23px; + padding: 2px 0.4em; + margin: 0.5em 0 0 0; + height: auto; + border: 0; +} + +.ui-selectmenu-open { + display: block; +} + +.ui-selectmenu-button, /* jQuery UI 1.11.4 - WP < 5.6 */ +.ui-selectmenu-button.ui-button { + display: inline-block; + overflow: hidden; + position: relative; + text-decoration: none; + box-sizing: border-box; /* To keep width calculation in percent since WP 5.6 */ + text-align: left; + white-space: nowrap; + vertical-align: top; + padding: 0; + line-height: normal; /* Override WC Bookings styles with WP < 5.6 */ + height: 28px; /* Override WC Bookings styles with WP < 5.6 */ +} + +.ui-selectmenu-button span.ui-icon { + right: 0.5em; + left: auto; + position: absolute; + top: 26%; + width: 16px; + height: 16px; + text-indent: 0; /* due to text-indent for jquery ui-dialog in wizard */ + background: none; +} + +.rtl .ui-selectmenu-button span.ui-icon { + left: 0.5em; + right: auto; +} + + +.ui-selectmenu-button.ui-widget span.ui-selectmenu-text, /* Override WC Bookings styles with WP < 5.6 */ +.ui-selectmenu-button span.ui-selectmenu-text { + text-align: left; + padding: 0.1em 2.1em 0.2em 2em; + display: block; + line-height: 23px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + margin: 0; +} + +.rtl .ui-selectmenu-button span.ui-selectmenu-text { + text-align: right; + padding: 0.2em 2em 0.2em 2.1em; +} + +.ui-widget-content, +.ui-state-default, +.ui-selectmenu-button.ui-state-default, /* Override WC Bookings styles with WP < 5.6 */ +.ui-button.ui-selectmenu-button-closed, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */ +.ui-button.ui-selectmenu-button-open, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */ +.ui-widget-content .ui-state-default, +.ui-widget-header .ui-state-default { + background: #fff; + border: 1px solid #ddd; + box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset; + color: #32373c; +} +/* Override to have same styles as WP form styles since WordPress 5.4 */ +.toplevel_page_mlang .ui-selectmenu-button.ui-state-default, +.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-closed, /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */ +.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-open{ /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */ + box-shadow: 0 0 0 transparent; + border-radius: 4px; + border: 1px solid #7e8993; +} + +/* From this line and below: override WooCommerce bookings plugin styles which overrides default WordPress styles */ +.pll-selectmenu-menu .ui-widget, +.pll-selectmenu-button.ui-widget { + font-size: 13px; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; +} + +.toplevel_page_mlang .ui-button.ui-selectmenu-button:focus{ + color: #016087; /* Same color as WordPress focused select HTML tag */ + border-color: #007cba; + box-shadow: 0 0 0 1px #007cba; + outline: 2px solid transparent; + background: #fff; /* Override bookings plugin styles which overrides default WordPress styles */ +} + +.toplevel_page_mlang .ui-menu-item, +.toplevel_page_mlang .ui-widget-content .ui-state-hover, +.toplevel_page_mlang .ui-widget-content .ui-state-focus, +.toplevel_page_mlang .ui-widget-content .ui-state-active { + color: #016087; /* Same color as option in a WordPress focused select HTML tag */ + margin: 0; +} + +.ui-selectmenu-open .ui-widget-content .ui-state-hover, /* Override WC Bookings styles with WP < 5.6 */ +.ui-selectmenu-open .ui-widget-content .ui-state-focus, /* Override WC Bookings styles with WP < 5.6 */ +.ui-selectmenu-open .ui-widget-content .ui-state-active, /* Override WC Bookings styles with WP < 5.6 */ +.pll-selectmenu-menu .ui-widget-content .ui-state-hover, +.pll-selectmenu-menu .ui-widget-content .ui-state-focus, +.pll-selectmenu-menu .ui-widget-content .ui-state-active { /* To be compatible jQuery UI 1.12.1 since WordPress 5.6 */ + background: #d5d5d5; + border: 0; +} + +.ui-selectmenu-button.ui-state-focus { + border: 1px solid #5b9dd9; + box-shadow: 0 0 2px rgba(30, 140, 190, 0.8); +} + +.ui-icon-triangle-1-s:before { + content: ""; + background: #fff url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 0px top 55%; + background-size: 16px 16px; + box-sizing: border-box; + position: absolute; + width: 16px; + height: 16px; +} + +.pll-selectmenu-button.ui-button:hover, +.pll-wizard .ui-button:hover, +.pll-wizard .ui-button:focus { + background: #fff; /* To override jQuery ui-dialog styles provided by WordPress */ +} + +.ui-widget-content { + max-height: 231px; + box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3); +} diff --git a/wp-content/plugins/polylang/css/build/selectmenu.min.css b/wp-content/plugins/polylang/css/build/selectmenu.min.css new file mode 100644 index 00000000..6a71f5b2 --- /dev/null +++ b/wp-content/plugins/polylang/css/build/selectmenu.min.css @@ -0,0 +1 @@ +.ui-widget-overlay{height:100%;left:0;position:fixed;top:0;width:100%}.ui-menu{display:block;list-style:none;margin:0;outline:none;padding:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{cursor:pointer;list-style-image:url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");margin:0;min-height:0;padding:3px 1em 3px .4em;position:relative}.ui-menu .ui-menu-item:not([role]){padding:0}.ui-menu-item-wrapper{padding:3px 1em 3px 2em}.rtl .ui-menu .ui-menu-item{text-align:right}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item[role]{padding-left:2em}.rtl .ui-menu-icons .ui-menu-item[role],.rtl .ui-menu-item-wrapper{padding-left:1em;padding-right:2em}.ui-menu .ui-icon,.ui-selectmenu-text .ui-icon{bottom:0;left:.3em;margin:auto 0;position:absolute;top:0}.rtl .ui-menu .ui-icon,.rtl .ui-selectmenu-text .ui-icon{left:auto;right:.3em}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-selectmenu-menu{display:none;left:0;margin:0;padding:0;position:absolute;top:0}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{border:0;font-size:1em;font-weight:700;height:auto;line-height:23px;margin:.5em 0 0;padding:2px .4em}.ui-selectmenu-open{display:block}.ui-selectmenu-button,.ui-selectmenu-button.ui-button{box-sizing:border-box;display:inline-block;height:28px;line-height:normal;overflow:hidden;padding:0;position:relative;text-align:left;text-decoration:none;vertical-align:top;white-space:nowrap}.ui-selectmenu-button span.ui-icon{background:none;height:16px;left:auto;position:absolute;right:.5em;text-indent:0;top:26%;width:16px}.rtl .ui-selectmenu-button span.ui-icon{left:.5em;right:auto}.ui-selectmenu-button.ui-widget span.ui-selectmenu-text,.ui-selectmenu-button span.ui-selectmenu-text{display:block;line-height:23px;margin:0;overflow:hidden;padding:.1em 2.1em .2em 2em;text-align:left;text-overflow:ellipsis;white-space:nowrap}.rtl .ui-selectmenu-button span.ui-selectmenu-text{padding:.2em 2em .2em 2.1em;text-align:right}.ui-button.ui-selectmenu-button-closed,.ui-button.ui-selectmenu-button-open,.ui-selectmenu-button.ui-state-default,.ui-state-default,.ui-widget-content,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{background:#fff;border:1px solid #ddd;box-shadow:inset 0 1px 2px rgba(0,0,0,.07);color:#32373c}.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-closed,.toplevel_page_mlang .ui-selectmenu-button.ui-selectmenu-button-open,.toplevel_page_mlang .ui-selectmenu-button.ui-state-default{border:1px solid #7e8993;border-radius:4px;box-shadow:0 0 0 transparent}.pll-selectmenu-button.ui-widget,.pll-selectmenu-menu .ui-widget{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif;font-size:13px}.toplevel_page_mlang .ui-button.ui-selectmenu-button:focus{background:#fff;border-color:#007cba;box-shadow:0 0 0 1px #007cba;color:#016087;outline:2px solid transparent}.toplevel_page_mlang .ui-menu-item,.toplevel_page_mlang .ui-widget-content .ui-state-active,.toplevel_page_mlang .ui-widget-content .ui-state-focus,.toplevel_page_mlang .ui-widget-content .ui-state-hover{color:#016087;margin:0}.pll-selectmenu-menu .ui-widget-content .ui-state-active,.pll-selectmenu-menu .ui-widget-content .ui-state-focus,.pll-selectmenu-menu .ui-widget-content .ui-state-hover,.ui-selectmenu-open .ui-widget-content .ui-state-active,.ui-selectmenu-open .ui-widget-content .ui-state-focus,.ui-selectmenu-open .ui-widget-content .ui-state-hover{background:#d5d5d5;border:0}.ui-selectmenu-button.ui-state-focus{border:1px solid #5b9dd9;box-shadow:0 0 2px rgba(30,140,190,.8)}.ui-icon-triangle-1-s:before{background:#fff url(data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E) no-repeat right 0 top 55%;background-size:16px 16px;box-sizing:border-box;content:"";height:16px;position:absolute;width:16px}.pll-selectmenu-button.ui-button:hover,.pll-wizard .ui-button:focus,.pll-wizard .ui-button:hover{background:#fff}.ui-widget-content{box-shadow:0 2px 6px hsla(0,0%,39%,.3);max-height:231px} \ No newline at end of file diff --git a/wp-content/plugins/polylang/css/build/wizard.css b/wp-content/plugins/polylang/css/build/wizard.css new file mode 100644 index 00000000..b6c6a62a --- /dev/null +++ b/wp-content/plugins/polylang/css/build/wizard.css @@ -0,0 +1,951 @@ +@charset "UTF-8"; +body { + margin: 65px auto 24px; + box-shadow: none; + background: #f1f1f1; + padding: 0; + border: 0; /* fix-pro #856 override WP install.css */ +} + +#pll-logo { + border: 0; + margin: 0 0 24px; + padding: 0; + text-align: center; + font-family: sans-serif; + font-size: 64px; + text-transform: uppercase; + color: #000; + line-height: normal; +} +#pll-logo a { + display: flex; + justify-content: center; + color: #000; + text-decoration: none; +} + +#pll-logo img { + max-width: 100%; + margin-right: 16px; +} +.rtl #pll-logo img { + margin-right: 0; + margin-left: 16px; +} + +.pll-wizard-footer { + text-align: center +} + +.pll-wizard .select2-container { + text-align: left; + width: auto +} + +.pll-wizard .hidden { + display: none +} + +.pll-wizard-content { + box-shadow: 0 1px 3px rgba(0, 0, 0, .13); + padding: 2em; + margin: 0 0 20px; + background: #fff; + overflow: hidden; + zoom: 1; + text-align: left; +} +.rtl .pll-wizard-content{ + text-align: right; +} + +.pll-wizard-content h1, +.pll-wizard-content h2, +.pll-wizard-content h3, +.pll-wizard-content table { + margin: 0 0 20px; + border: 0; + padding: 0; + color: #666; + clear: none; + font-weight: 500 +} + +.pll-wizard-content p { + margin: 20px 0; + font-size: 1em; + line-height: 1.75em; + color: #666 +} + +.pll-wizard-content table { + font-size: 1em; + line-height: 1.75em; + color: #666; + width: 100%; + margin-top: 20px; +} +.pll-wizard-content table td span{ + display: inline-block; +} + +.pll-wizard-content table caption { + caption-side: bottom; + font-style: italic; + text-align: right; +} +.rtl .pll-wizard-content table caption { + text-align: left; +} + +.pll-wizard-content table caption .icon-default-lang{ + font-style: normal; +} + +.pll-wizard-content a { + color: #a03f3f; +} + +.pll-wizard-content a:focus, +.pll-wizard-content a:hover, +.pll-wizard-footer-links:hover { + color: #dd5454 +} + +.pll-wizard-content .pll-wizard-next-steps { + overflow: hidden; + margin: 0 0 24px; + padding-bottom: 2px +} + +.pll-wizard-content .pll-wizard-next-steps h2 { + margin-bottom: 12px +} + +.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-first { + float: left; + width: 50%; + box-sizing: border-box +} + +.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-last { + float: right; + width: 50%; + box-sizing: border-box +} + +.pll-wizard-content .pll-wizard-next-steps ul { + padding: 0 2em 0 0; + list-style: none outside; + margin: 0 +} + +.pll-wizard-content .pll-wizard-next-steps ul li a { + display: block; + padding: 0 0 .75em +} + +.pll-wizard-content .pll-wizard-next-steps ul li a::before { + color: #82878c; + font: normal 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 0 10px 0 0; + top: 1px; + position: relative; + text-decoration: none!important; + vertical-align: top +} + +.pll-wizard-steps { + padding: 0 0 24px; + margin: 0; + list-style: none outside; + overflow: hidden; + color: #ccc; + width: 100%; + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: inline-flex +} + +.pll-wizard-steps li { + width: 100%; + float: left; + padding: 0 0 .8em; + margin: 0; + text-align: center; + position: relative; + border-bottom: 4px solid #ccc; + line-height: 1.4em +} + +.pll-wizard-steps li a { + color: #a03f3f; + text-decoration: none; + padding: 1.5em; + margin: -1.5em; + position: relative; + z-index: 1 +} + +.pll-wizard-steps li a:focus, +.pll-wizard-steps li a:hover { + color: #dd5454; + text-decoration: underline +} + +.pll-wizard-steps li::before { + content: ""; + border: 4px solid #ccc; + border-radius: 100%; + width: 4px; + height: 4px; + position: absolute; + bottom: 0; + left: 50%; + margin-left: -6px; + margin-bottom: -8px; + background: #fff +} + +.pll-wizard-steps li.active { + border-color: #a03f3f; + color: #a03f3f; + font-weight: 700 +} + +.pll-wizard-steps li.active::before { + border-color: #a03f3f +} + +.pll-wizard-steps li.done { + border-color: #a03f3f; + color: #a03f3f +} + +.pll-wizard-steps li.done::before { + border-color: #a03f3f; + background: #a03f3f +} + +.pll-wizard .pll-wizard-actions { + overflow: hidden; + margin: 20px 0 0; + position: relative +} + +.pll-wizard .pll-wizard-actions .button { + font-size: 16px; + font-weight: 300; + padding: 1em 2em; + line-height: 1em; + margin-right: .5em; + margin-bottom: 2px; + margin-top: 10px; + height: auto; + border-radius: 4px; + box-shadow: none; + min-width: auto; + border-color: #a03f3f; + color: #a03f3f; +} + +.pll-wizard .pll-wizard-content .button { + border-color: #a03f3f; + color: #a03f3f; +} + +.pll-wizard .pll-wizard-content .button-primary, +.pll-wizard .pll-wizard-actions .button-primary { + background-color: #a03f3f; + border-color: #a03f3f; + color: #fff; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #a03f3f; + text-shadow: 0 -1px 1px #a03f3f, 1px 0 1px #a03f3f, 0 1px 1px #a03f3f, -1px 0 1px #a03f3f; + margin: 0; + opacity: 1 +} + +.pll-wizard .pll-wizard-content .button-small .dashicons { + font-size: 15px; + height: auto; + vertical-align: middle; +} + +.pll-wizard .button-primary:active, +.pll-wizard .button-primary:focus, +.pll-wizard input[type="checkbox"]:focus + label.button-primary, +.pll-wizard .button-primary:hover { + background: #dd5454; + border-color: #dd5454; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #dd5454 +} +.pll-wizard .pll-wizard-actions .button-primary[disabled], +.pll-wizard .pll-wizard-actions .button-primary:disabled, +.pll-wizard .pll-wizard-actions .button-primary.disabled { + cursor: wait; + background-color: #bb5454 !important; + border-color: #bb5454 !important; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #bb5454 !important; + text-shadow: 0 -1px 1px #bb5454, 1px 0 1px #bb5454, 0 1px 1px #bb5454, -1px 0 1px #bb5454 !important; + color: #ffa3a3 !important; +} +.pll-wizard-content p:last-child { + margin-bottom: 0 +} + +.pll-wizard-footer-links { + font-size: .85em; + color: #7b7b7b; + margin: 1.18em auto; + display: inline-block; + text-align: center +} + +.pll-wizard-services { + border: 1px solid #eee; + padding: 0; + margin: 0 0 1em; + list-style: none outside; + border-radius: 4px; + overflow: hidden +} + +.pll-wizard-services p { + margin: 0 0 1em 0; + padding: 0; + font-size: 1em; + line-height: 1.5em +} + +.pll-wizard-service-item { + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-flex-wrap: nowrap; + flex-wrap: nowrap; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + justify-content: space-between; + padding: 0; + border-bottom: 1px solid #eee; + color: #666; + -webkit-box-align: center; + -webkit-align-items: center; + align-items: center +} + +.media-step .pll-wizard-service-item{ + border: 0; +} + +.media-step .pll-wizard-service-item:last-child{ + display: block; +} + +.media-step .pll-wizard-service-item .pll-wizard-service-enable{ + padding-bottom: 0; +} + +.pll-wizard-service-item:last-child { + border-bottom: 0 +} + +.pll-wizard-service-item .pll-wizard-service-name { + -webkit-flex-basis: 0; + flex-basis: 0; + min-width: 160px; + text-align: center; + font-weight: 700; + padding: 2em 0; + -webkit-align-self: stretch; + align-self: stretch; + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-box-align: baseline; + -webkit-align-items: baseline; + align-items: baseline +} + +.pll-wizard-service-item .pll-wizard-service-name img { + max-width: 75px +} + +.pll-wizard-service-item .pll-wizard-service-description { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + flex-grow: 1; + padding: 20px +} + +.pll-wizard-service-item .pll-wizard-service-example { + padding: 0 20px 20px +} + +.pll-wizard-service-item .pll-wizard-service-example p{ + text-align: right; +} +.rtl .pll-wizard-service-item .pll-wizard-service-example p{ + text-align: left; +} + +.pll-wizard-service-item .pll-wizard-service-description p { + margin-bottom: 1em +} + +.pll-wizard-service-item .pll-wizard-service-description p:last-child { + margin-bottom: 0 +} + +.pll-wizard-service-item .pll-wizard-service-description .pll-wizard-service-settings-description { + display: block; + font-style: italic; + color: #999 +} + +.pll-wizard-service-item .pll-wizard-service-enable { + -webkit-flex-basis: 0; + flex-basis: 0; + min-width: 75px; + text-align: center; + cursor: pointer; + padding: 2em 0; + position: relative; + max-height: 1.5em; + -webkit-align-self: flex-start; + align-self: flex-start; + -webkit-box-ordinal-group: 4; + -webkit-order: 3; + order: 3 +} + +.pll-wizard-service-item .pll-wizard-service-toggle { + position: relative +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] { + position:absolute; + opacity: 0; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label { + position: relative; + display: inline-block; + width: 44px; + height: 20px; + border-radius: 10em; + cursor: pointer; + text-indent: -9999px; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:focus + label { + border:1px dashed #777; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before, +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after { + content: ''; + position: absolute; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before { + left: 0; + top: 0; + width: 44px; + height: 20px; + background: #ddd; + border-radius: 10em; + transition: background-color .2s; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after { + width: 16px; + height: 16px; + transition: all .2s; + border-radius: 50%; + background: #fff; + margin: 2px; + top: 0; + left: 0; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::before { + background:#a03f3f; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::after { + right: 0; + left:auto; +} + +.pll-wizard-service-item .pll-wizard-service-settings { + display: none; + margin-top: .75em; + margin-bottom: 0; + cursor: default +} + +.pll-wizard-service-item .pll-wizard-service-settings.hide { + display: none +} + +.pll-wizard-service-item.checked .pll-wizard-service-settings { + display: inline-block +} + +.pll-wizard-service-item.checked .pll-wizard-service-settings.hide { + display: none +} + +.pll-wizard-service-item.closed { + border-bottom: 0 +} + +.step { + text-align: center +} + +.pll-wizard .button .dashicons{ + vertical-align: middle; +} +.rtl .dashicons-arrow-right-alt2:before { + content: "\f341"; +} +.pll-wizard .pll-wizard-actions .button:active, +.pll-wizard .pll-wizard-actions .button:focus, +.pll-wizard .pll-wizard-actions .button:hover { + box-shadow: none +} + +.pll-wizard-next-steps { + border: 1px solid #eee; + border-radius: 4px; + list-style: none; + padding: 0 +} + +.pll-wizard-next-steps li { + padding: 0 +} + +.pll-wizard-next-steps .pll-wizard-next-step-item { + display: -webkit-box; + display: -webkit-flex; + display: flex; + border-top: 1px solid #eee +} + +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border, +.pll-wizard-next-steps .pll-wizard-next-step-item:first-child { + border-top: 0 +} + +.pll-wizard-next-steps .pll-wizard-next-step-description { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + flex-grow: 1; + margin: 1.5em +} + +.pll-wizard-next-steps .pll-wizard-next-step-action { + -webkit-box-flex: 0; + -webkit-flex-grow: 0; + flex-grow: 0; + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-box-align: center; + -webkit-align-items: center; + align-items: center +} + +.pll-wizard-next-steps .pll-wizard-next-step-action .button { + margin: 1em 1.5em +} + +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-description, +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-actions, +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-action .button{ + margin-top: 0; +} + + +.pll-wizard-next-steps p.next-step-heading { + margin: 0; + font-size: .95em; + font-weight: 400; + font-variant: all-petite-caps +} + +.pll-wizard-next-steps p.next-step-extra-info { + margin: 0 +} + +.pll-wizard-next-steps h3.next-step-description { + margin: 0; + font-size: 16px; + font-weight: 600; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps { + border-top: 1px solid #eee; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-next-step-description { + margin-bottom: 0 +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions { + margin: 0 0 1.5em 0; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button { + font-size: 15px; + margin: 1em 0 1em 1.5em; +} +.rtl .pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button { + margin: 1em 1.5em 1em 0; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button::last-child { + margin-right: 1.5em; +} + +.pll-wizard-content img{ + max-width: 100%; + margin-right: 0.5em; +} +.rtl .pll-wizard-content img{ + margin-left: 0.5em; +} + +.pll-wizard-content .form-field label{ + margin-bottom: 5px; + display: block; +} + +.pll-wizard-content .form-field select{ + padding: 3px; +} + +.pll-wizard-content .languages-step select, +.pll-wizard-content .untranslated-contents-step select{ + width: 100%; +} + +.languages-step .form-field .button{ + margin-left: 15px; +} +.languages-step .form-field .button > span{ + margin-right: 0.3em; +} +.rtl .languages-step .form-field .button{ + margin-left: 0; + margin-right: 15px; +} +.rtl .languages-step .form-field .button > span{ + margin-left: 0.3em; + margin-right: 0; +} + +.pll-wizard-content .languages-step .select-language-field{ + display: flex; +} + +.pll-wizard-content #languages{ + display: none; +} +.pll-wizard-content #languages tr th:first-child{ + width: 80%; +} +.pll-wizard-content #languages .dashicons{ + color: #a03f3f; +} +.pll-wizard-content #languages img{ + margin-right: 5px; +} +.pll-wizard-content .error{ + color: #a03f3f; + font-weight: bold; +} +.pll-wizard-content #messages .error{ + background: #fccfcf; + padding: 0.5rem; + border: 1px solid #a03f3f; + margin-bottom: 0.5rem; +} + +.pll-wizard-content #slide-toggle{ + position:absolute; + opacity: 0; +} + +.pll-wizard-content #slide-toggle + label{ + position:relative; +} +.pll-wizard-content #slide-toggle + label + span{ + display: block; +} + +.pll-wizard-content #slide-toggle + label .dashicons{ + margin-right: 0.3em; +} +.rtl .pll-wizard-content #slide-toggle + label .dashicons{ + margin-left: 0.3em; + margin-right: 0; +} +.pll-wizard-content #slide-toggle ~ #screenshot > img { + max-height: 500px; + margin-top: 10px; + -webkit-transition: all .5s cubic-bezier(0, 1, 0.5, 1); + transition: all .5s cubic-bezier(0, 1, 0.5, 1); +} +.pll-wizard-content #slide-toggle:checked ~ #screenshot > img { + max-height: 0; +} +.hide { + display: none; +} + +input[type="text"].field-in-error, +input[type="password"].field-in-error, +input[type="checkbox"].field-in-error, +input[type="color"].field-in-error, +input[type="date"].field-in-error, +input[type="datetime"].field-in-error, +input[type="datetime-local"].field-in-error, +input[type="email"].field-in-error, +input[type="month"].field-in-error, +input[type="number"].field-in-error, +input[type="search"].field-in-error, +input[type="radio"].field-in-error, +input[type="tel"].field-in-error, +input[type="text"].field-in-error, +input[type="time"].field-in-error, +input[type="url"].field-in-error, +input[type="week"].field-in-error, +select.field-in-error, +textarea.field-in-error, +span.field-in-error, +.field-in-error{ + border-color: #a03f3f; +} + +input[type="text"].field-in-error:focus, +input[type="password"].field-in-error:focus, +input[type="checkbox"].field-in-error:focus, +input[type="color"].field-in-error:focus, +input[type="date"].field-in-error:focus, +input[type="datetime"].field-in-error:focus, +input[type="datetime-local"].field-in-error:focus, +input[type="email"].field-in-error:focus, +input[type="month"].field-in-error:focus, +input[type="number"].field-in-error:focus, +input[type="search"].field-in-error:focus, +input[type="radio"].field-in-error:focus, +input[type="tel"].field-in-error:focus, +input[type="text"].field-in-error:focus, +input[type="time"].field-in-error:focus, +input[type="url"].field-in-error:focus, +input[type="week"].field-in-error:focus, +select.field-in-error:focus, +textarea.field-in-error:focus, +span.field-in-error:focus, +.field-in-error:focus{ + border: 1px solid #a03f3f; + box-shadow: 0 0 2px rgba(160, 63, 63, 0.8); + outline-color: #a03f3f; + outline-style: auto; + outline-width: thin; +} + +/* override install styles by returning back to forms styles */ +.form-table input.regular-text{ + width: 25em; +} +.form-table input.field-in-error{ + border-color: #a03f3f; +} +#pll-licenses-table td{ + padding: 10px 9px; +} +#pll-licenses-table .license-valid td p{ + min-width: 35em; +} +#pll-licenses-table .pll-deactivate-license{ + margin: 0 0 0 20px; +} +.rtl #pll-licenses-table .pll-deactivate-license{ + margin: 0 10px 0 0; +} +.pll-wizard-content .documentation { + padding: 24px 24px 0; + margin: 0 0 24px; + overflow: hidden; + background: #f5f5f5 +} + +.pll-wizard-content .documentation p { + padding: 0; + margin: 0 0 12px; +} +.documentation-container { + display: -webkit-box; + display: -webkit-flex; + display: flex; + justify-content: flex-end; +} + +.documentation-container .documentation-button-container { + -webkit-box-flex: 0; + -webkit-flex-grow: 0; + flex-grow: 0; +} + +.wc-setup .wc-setup-actions .button.documentation-button { + height: 42px; + padding: 0 1em; + margin: 0; +} +#dialog{ + display: none; +} +.pll-wizard .ui-dialog.ui-widget-content{ + max-height: none; +} +.pll-wizard .ui-dialog-title::before{ + content: "\f534"; + font-family: dashicons; + display: inline-block; + line-height: 1; + font-weight: 400; + font-style: normal; + speak: none; + text-decoration: inherit; + text-transform: none; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + width: 20px; + height: 20px; + font-size: 20px; + vertical-align: middle; + text-align: center; + margin: 0 5px 5px 0; + transition: color 0.1s ease-in; +} +.rtl.pll-wizard .ui-dialog-title::before{ + margin-right: 0; + margin-left: 5px; +} +.pll-wizard .ui-dialog ul{ + list-style: disc; + padding-left: 20px; +} +.rtl.pll-wizard .ui-dialog ul{ + padding-left: 0; + padding-right: 20px; +} +.pll-wizard li{ + margin-bottom: 0; +} +#translations{ + border-collapse: collapse; +} +#translations tbody:nth-child(odd){ + background-color: #f9f9f9; +} +#translations.striped > tbody > :nth-child(odd) { + background-color: transparent; /* Override common WordPress style */ +} +.pll-wizard-content mark{ + background: transparent none; +} +.pll-wizard-content mark{ + color: #7ad03a; +} +@media screen and (max-width: 782px) { + /* Override WordPress button css rules */ + .languages-step .form-field .button{ + font-size: 13px; + line-height: 26px; + height: 28px; + padding: 0 10px 1px; + vertical-align: top; + } + + #pll-licenses-table .pll-deactivate-license{ + margin: 10px 0 5px; + } +} +@media only screen and (max-width:620px) { + /* Override dialog width rule */ + .ui-dialog{ + width: 100% !important; + } + +} +@media only screen and (max-width:500px) { + #pll-logo a, + .select-language-field{ + flex-direction: column; + } + .select-language-field .action-buttons{ + display: flex; + justify-content: flex-end; + } + .languages-step .form-field .button{ + margin: 5px 0 0; + } +} +@media only screen and (max-width:400px) { + #pll-logo { + font-size: 56px; + } + .pll-wizard-steps { + display: none + } + .pll-wizard-service-item { + -webkit-flex-wrap: wrap; + flex-wrap: wrap + } + .pll-wizard-service-item .pll-wizard-service-enable { + -webkit-box-ordinal-group: 3; + -webkit-order: 2; + order: 2; + padding: 20px 0 0 + } + .pll-wizard-service-item .pll-wizard-service-description { + -webkit-box-ordinal-group: 4; + -webkit-order: 3; + order: 3 + } + .pll-wizard-service-item .pll-wizard-service-name { + padding: 20px 20px 0; + text-align: left; + -webkit-box-pack: justify!important; + -webkit-justify-content: space-between!important; + justify-content: space-between!important + } + .pll-wizard-service-item .pll-wizard-service-name img { + margin: 0 + } + .pll-wizard-next-steps .pll-wizard-next-step-item { + -webkit-flex-wrap: wrap; + flex-wrap: wrap + } + .pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-description { + margin-bottom: 0 + } + .pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-action p { + margin: 0 + } +} +@media only screen and (max-width:360px) { + #pll-logo { + font-size: 48px; + } +} diff --git a/wp-content/plugins/polylang/css/build/wizard.min.css b/wp-content/plugins/polylang/css/build/wizard.min.css new file mode 100644 index 00000000..86f167f2 --- /dev/null +++ b/wp-content/plugins/polylang/css/build/wizard.min.css @@ -0,0 +1 @@ +body{background:#f1f1f1;box-shadow:none;margin:65px auto 24px}#pll-logo,body{border:0;padding:0}#pll-logo{color:#000;font-family:sans-serif;font-size:64px;line-height:normal;margin:0 0 24px;text-align:center;text-transform:uppercase}#pll-logo a{color:#000;display:flex;justify-content:center;text-decoration:none}#pll-logo img{margin-right:16px;max-width:100%}.rtl #pll-logo img{margin-left:16px;margin-right:0}.pll-wizard-footer{text-align:center}.pll-wizard .select2-container{text-align:left;width:auto}.pll-wizard .hidden{display:none}.pll-wizard-content{zoom:1;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.13);margin:0 0 20px;overflow:hidden;padding:2em;text-align:left}.rtl .pll-wizard-content{text-align:right}.pll-wizard-content h1,.pll-wizard-content h2,.pll-wizard-content h3,.pll-wizard-content table{border:0;clear:none;color:#666;font-weight:500;margin:0 0 20px;padding:0}.pll-wizard-content p{color:#666;font-size:1em;line-height:1.75em;margin:20px 0}.pll-wizard-content table{color:#666;font-size:1em;line-height:1.75em;margin-top:20px;width:100%}.pll-wizard-content table td span{display:inline-block}.pll-wizard-content table caption{caption-side:bottom;font-style:italic;text-align:right}.rtl .pll-wizard-content table caption{text-align:left}.pll-wizard-content table caption .icon-default-lang{font-style:normal}.pll-wizard-content a{color:#a03f3f}.pll-wizard-content a:focus,.pll-wizard-content a:hover,.pll-wizard-footer-links:hover{color:#dd5454}.pll-wizard-content .pll-wizard-next-steps{margin:0 0 24px;overflow:hidden;padding-bottom:2px}.pll-wizard-content .pll-wizard-next-steps h2{margin-bottom:12px}.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-first{box-sizing:border-box;float:left;width:50%}.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-last{box-sizing:border-box;float:right;width:50%}.pll-wizard-content .pll-wizard-next-steps ul{list-style:none outside;margin:0;padding:0 2em 0 0}.pll-wizard-content .pll-wizard-next-steps ul li a{display:block;padding:0 0 .75em}.pll-wizard-content .pll-wizard-next-steps ul li a:before{speak:none;color:#82878c;display:inline-block;font:normal 20px/1 dashicons;padding:0 10px 0 0;position:relative;text-decoration:none!important;top:1px;vertical-align:top}.pll-wizard-steps{color:#ccc;display:-webkit-inline-box;display:-webkit-inline-flex;display:inline-flex;list-style:none outside;margin:0;overflow:hidden;padding:0 0 24px;width:100%}.pll-wizard-steps li{border-bottom:4px solid #ccc;float:left;line-height:1.4em;margin:0;padding:0 0 .8em;position:relative;text-align:center;width:100%}.pll-wizard-steps li a{color:#a03f3f;margin:-1.5em;padding:1.5em;position:relative;text-decoration:none;z-index:1}.pll-wizard-steps li a:focus,.pll-wizard-steps li a:hover{color:#dd5454;text-decoration:underline}.pll-wizard-steps li:before{background:#fff;border:4px solid #ccc;border-radius:100%;bottom:0;content:"";height:4px;left:50%;margin-bottom:-8px;margin-left:-6px;position:absolute;width:4px}.pll-wizard-steps li.active{border-color:#a03f3f;color:#a03f3f;font-weight:700}.pll-wizard-steps li.active:before{border-color:#a03f3f}.pll-wizard-steps li.done{border-color:#a03f3f;color:#a03f3f}.pll-wizard-steps li.done:before{background:#a03f3f;border-color:#a03f3f}.pll-wizard .pll-wizard-actions{margin:20px 0 0;overflow:hidden;position:relative}.pll-wizard .pll-wizard-actions .button{border-color:#a03f3f;border-radius:4px;box-shadow:none;color:#a03f3f;font-size:16px;font-weight:300;height:auto;line-height:1em;margin-bottom:2px;margin-right:.5em;margin-top:10px;min-width:auto;padding:1em 2em}.pll-wizard .pll-wizard-content .button{border-color:#a03f3f;color:#a03f3f}.pll-wizard .pll-wizard-actions .button-primary,.pll-wizard .pll-wizard-content .button-primary{background-color:#a03f3f;border-color:#a03f3f;box-shadow:inset 0 1px 0 hsla(0,0%,100%,.25),0 1px 0 #a03f3f;color:#fff;margin:0;opacity:1;text-shadow:0 -1px 1px #a03f3f,1px 0 1px #a03f3f,0 1px 1px #a03f3f,-1px 0 1px #a03f3f}.pll-wizard .pll-wizard-content .button-small .dashicons{font-size:15px;height:auto;vertical-align:middle}.pll-wizard .button-primary:active,.pll-wizard .button-primary:focus,.pll-wizard .button-primary:hover,.pll-wizard input[type=checkbox]:focus+label.button-primary{background:#dd5454;border-color:#dd5454;box-shadow:inset 0 1px 0 hsla(0,0%,100%,.25),0 1px 0 #dd5454}.pll-wizard .pll-wizard-actions .button-primary.disabled,.pll-wizard .pll-wizard-actions .button-primary:disabled,.pll-wizard .pll-wizard-actions .button-primary[disabled]{background-color:#bb5454!important;border-color:#bb5454!important;box-shadow:inset 0 1px 0 hsla(0,0%,100%,.25),0 1px 0 #bb5454!important;color:#ffa3a3!important;cursor:wait;text-shadow:0 -1px 1px #bb5454,1px 0 1px #bb5454,0 1px 1px #bb5454,-1px 0 1px #bb5454!important}.pll-wizard-content p:last-child{margin-bottom:0}.pll-wizard-footer-links{color:#7b7b7b;display:inline-block;font-size:.85em;margin:1.18em auto;text-align:center}.pll-wizard-services{border:1px solid #eee;border-radius:4px;list-style:none outside;margin:0 0 1em;overflow:hidden;padding:0}.pll-wizard-services p{font-size:1em;line-height:1.5em;margin:0 0 1em;padding:0}.pll-wizard-service-item{-webkit-box-pack:justify;-webkit-box-align:center;-webkit-align-items:center;align-items:center;border-bottom:1px solid #eee;color:#666;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-wrap:nowrap;flex-wrap:nowrap;-webkit-justify-content:space-between;justify-content:space-between;padding:0}.media-step .pll-wizard-service-item{border:0}.media-step .pll-wizard-service-item:last-child{display:block}.media-step .pll-wizard-service-item .pll-wizard-service-enable{padding-bottom:0}.pll-wizard-service-item:last-child{border-bottom:0}.pll-wizard-service-item .pll-wizard-service-name{-webkit-box-align:baseline;-webkit-align-items:baseline;align-items:baseline;-webkit-align-self:stretch;align-self:stretch;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-basis:0;flex-basis:0;font-weight:700;min-width:160px;padding:2em 0;text-align:center}.pll-wizard-service-item .pll-wizard-service-name img{max-width:75px}.pll-wizard-service-item .pll-wizard-service-description{-webkit-box-flex:1;-webkit-flex-grow:1;flex-grow:1;padding:20px}.pll-wizard-service-item .pll-wizard-service-example{padding:0 20px 20px}.pll-wizard-service-item .pll-wizard-service-example p{text-align:right}.rtl .pll-wizard-service-item .pll-wizard-service-example p{text-align:left}.pll-wizard-service-item .pll-wizard-service-description p{margin-bottom:1em}.pll-wizard-service-item .pll-wizard-service-description p:last-child{margin-bottom:0}.pll-wizard-service-item .pll-wizard-service-description .pll-wizard-service-settings-description{color:#999;display:block;font-style:italic}.pll-wizard-service-item .pll-wizard-service-enable{-webkit-box-ordinal-group:4;-webkit-align-self:flex-start;align-self:flex-start;cursor:pointer;-webkit-flex-basis:0;flex-basis:0;max-height:1.5em;min-width:75px;-webkit-order:3;order:3;padding:2em 0;position:relative;text-align:center}.pll-wizard-service-item .pll-wizard-service-toggle{position:relative}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]{opacity:0;position:absolute}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]+label{border-radius:10em;cursor:pointer;display:inline-block;height:20px;position:relative;text-indent:-9999px;width:44px}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:focus+label{border:1px dashed #777}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]+label:after,.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]+label:before{content:"";position:absolute}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]+label:before{background:#ddd;border-radius:10em;height:20px;left:0;top:0;transition:background-color .2s;width:44px}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]+label:after{background:#fff;border-radius:50%;height:16px;left:0;margin:2px;top:0;transition:all .2s;width:16px}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked+label:before{background:#a03f3f}.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked+label:after{left:auto;right:0}.pll-wizard-service-item .pll-wizard-service-settings{cursor:default;display:none;margin-bottom:0;margin-top:.75em}.pll-wizard-service-item .pll-wizard-service-settings.hide{display:none}.pll-wizard-service-item.checked .pll-wizard-service-settings{display:inline-block}.pll-wizard-service-item.checked .pll-wizard-service-settings.hide{display:none}.pll-wizard-service-item.closed{border-bottom:0}.step{text-align:center}.pll-wizard .button .dashicons{vertical-align:middle}.rtl .dashicons-arrow-right-alt2:before{content:"\f341"}.pll-wizard .pll-wizard-actions .button:active,.pll-wizard .pll-wizard-actions .button:focus,.pll-wizard .pll-wizard-actions .button:hover{box-shadow:none}.pll-wizard-next-steps{border:1px solid #eee;border-radius:4px;list-style:none;padding:0}.pll-wizard-next-steps li{padding:0}.pll-wizard-next-steps .pll-wizard-next-step-item{border-top:1px solid #eee;display:-webkit-box;display:-webkit-flex;display:flex}.pll-wizard-next-steps .pll-wizard-next-step-item.no-border,.pll-wizard-next-steps .pll-wizard-next-step-item:first-child{border-top:0}.pll-wizard-next-steps .pll-wizard-next-step-description{-webkit-box-flex:1;-webkit-flex-grow:1;flex-grow:1;margin:1.5em}.pll-wizard-next-steps .pll-wizard-next-step-action{-webkit-box-flex:0;-webkit-box-align:center;-webkit-align-items:center;align-items:center;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-grow:0;flex-grow:0}.pll-wizard-next-steps .pll-wizard-next-step-action .button{margin:1em 1.5em}.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-actions,.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-action .button,.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-description{margin-top:0}.pll-wizard-next-steps p.next-step-heading{font-size:.95em;font-variant:all-petite-caps;font-weight:400;margin:0}.pll-wizard-next-steps p.next-step-extra-info{margin:0}.pll-wizard-next-steps h3.next-step-description{font-size:16px;font-weight:600;margin:0}.pll-wizard-next-steps .pll-wizard-additional-steps{border-top:1px solid #eee}.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-next-step-description{margin-bottom:0}.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions{margin:0 0 1.5em}.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button{font-size:15px;margin:1em 0 1em 1.5em}.rtl .pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button{margin:1em 1.5em 1em 0}.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button::last-child{margin-right:1.5em}.pll-wizard-content img{margin-right:.5em;max-width:100%}.rtl .pll-wizard-content img{margin-left:.5em}.pll-wizard-content .form-field label{display:block;margin-bottom:5px}.pll-wizard-content .form-field select{padding:3px}.pll-wizard-content .languages-step select,.pll-wizard-content .untranslated-contents-step select{width:100%}.languages-step .form-field .button{margin-left:15px}.languages-step .form-field .button>span{margin-right:.3em}.rtl .languages-step .form-field .button{margin-left:0;margin-right:15px}.rtl .languages-step .form-field .button>span{margin-left:.3em;margin-right:0}.pll-wizard-content .languages-step .select-language-field{display:flex}.pll-wizard-content #languages{display:none}.pll-wizard-content #languages tr th:first-child{width:80%}.pll-wizard-content #languages .dashicons{color:#a03f3f}.pll-wizard-content #languages img{margin-right:5px}.pll-wizard-content .error{color:#a03f3f;font-weight:700}.pll-wizard-content #messages .error{background:#fccfcf;border:1px solid #a03f3f;margin-bottom:.5rem;padding:.5rem}.pll-wizard-content #slide-toggle{opacity:0;position:absolute}.pll-wizard-content #slide-toggle+label{position:relative}.pll-wizard-content #slide-toggle+label+span{display:block}.pll-wizard-content #slide-toggle+label .dashicons{margin-right:.3em}.rtl .pll-wizard-content #slide-toggle+label .dashicons{margin-left:.3em;margin-right:0}.pll-wizard-content #slide-toggle~#screenshot>img{margin-top:10px;max-height:500px;-webkit-transition:all .5s cubic-bezier(0,1,.5,1);transition:all .5s cubic-bezier(0,1,.5,1)}.pll-wizard-content #slide-toggle:checked~#screenshot>img{max-height:0}.hide{display:none}.field-in-error,input[type=checkbox].field-in-error,input[type=color].field-in-error,input[type=date].field-in-error,input[type=datetime-local].field-in-error,input[type=datetime].field-in-error,input[type=email].field-in-error,input[type=month].field-in-error,input[type=number].field-in-error,input[type=password].field-in-error,input[type=radio].field-in-error,input[type=search].field-in-error,input[type=tel].field-in-error,input[type=text].field-in-error,input[type=time].field-in-error,input[type=url].field-in-error,input[type=week].field-in-error,select.field-in-error,span.field-in-error,textarea.field-in-error{border-color:#a03f3f}.field-in-error:focus,input[type=checkbox].field-in-error:focus,input[type=color].field-in-error:focus,input[type=date].field-in-error:focus,input[type=datetime-local].field-in-error:focus,input[type=datetime].field-in-error:focus,input[type=email].field-in-error:focus,input[type=month].field-in-error:focus,input[type=number].field-in-error:focus,input[type=password].field-in-error:focus,input[type=radio].field-in-error:focus,input[type=search].field-in-error:focus,input[type=tel].field-in-error:focus,input[type=text].field-in-error:focus,input[type=time].field-in-error:focus,input[type=url].field-in-error:focus,input[type=week].field-in-error:focus,select.field-in-error:focus,span.field-in-error:focus,textarea.field-in-error:focus{border:1px solid #a03f3f;box-shadow:0 0 2px rgba(160,63,63,.8);outline-color:#a03f3f;outline-style:auto;outline-width:thin}.form-table input.regular-text{width:25em}.form-table input.field-in-error{border-color:#a03f3f}#pll-licenses-table td{padding:10px 9px}#pll-licenses-table .license-valid td p{min-width:35em}#pll-licenses-table .pll-deactivate-license{margin:0 0 0 20px}.rtl #pll-licenses-table .pll-deactivate-license{margin:0 10px 0 0}.pll-wizard-content .documentation{background:#f5f5f5;margin:0 0 24px;overflow:hidden;padding:24px 24px 0}.pll-wizard-content .documentation p{margin:0 0 12px;padding:0}.documentation-container{display:-webkit-box;display:-webkit-flex;display:flex;justify-content:flex-end}.documentation-container .documentation-button-container{-webkit-box-flex:0;-webkit-flex-grow:0;flex-grow:0}.wc-setup .wc-setup-actions .button.documentation-button{height:42px;margin:0;padding:0 1em}#dialog{display:none}.pll-wizard .ui-dialog.ui-widget-content{max-height:none}.pll-wizard .ui-dialog-title:before{speak:none;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;content:"\f534";display:inline-block;font-family:dashicons;font-size:20px;font-style:normal;font-weight:400;height:20px;line-height:1;margin:0 5px 5px 0;text-align:center;text-decoration:inherit;text-transform:none;transition:color .1s ease-in;vertical-align:middle;width:20px}.rtl.pll-wizard .ui-dialog-title:before{margin-left:5px;margin-right:0}.pll-wizard .ui-dialog ul{list-style:disc;padding-left:20px}.rtl.pll-wizard .ui-dialog ul{padding-left:0;padding-right:20px}.pll-wizard li{margin-bottom:0}#translations{border-collapse:collapse}#translations tbody:nth-child(odd){background-color:#f9f9f9}#translations.striped>tbody>:nth-child(odd){background-color:transparent}.pll-wizard-content mark{background:transparent none;color:#7ad03a}@media screen and (max-width:782px){.languages-step .form-field .button{font-size:13px;height:28px;line-height:26px;padding:0 10px 1px;vertical-align:top}#pll-licenses-table .pll-deactivate-license{margin:10px 0 5px}}@media only screen and (max-width:620px){.ui-dialog{width:100%!important}}@media only screen and (max-width:500px){#pll-logo a,.select-language-field{flex-direction:column}.select-language-field .action-buttons{display:flex;justify-content:flex-end}.languages-step .form-field .button{margin:5px 0 0}}@media only screen and (max-width:400px){#pll-logo{font-size:56px}.pll-wizard-steps{display:none}.pll-wizard-service-item{-webkit-flex-wrap:wrap;flex-wrap:wrap}.pll-wizard-service-item .pll-wizard-service-enable{-webkit-box-ordinal-group:3;-webkit-order:2;order:2;padding:20px 0 0}.pll-wizard-service-item .pll-wizard-service-description{-webkit-box-ordinal-group:4;-webkit-order:3;order:3}.pll-wizard-service-item .pll-wizard-service-name{-webkit-box-pack:justify!important;-webkit-justify-content:space-between!important;justify-content:space-between!important;padding:20px 20px 0;text-align:left}.pll-wizard-service-item .pll-wizard-service-name img{margin:0}.pll-wizard-next-steps .pll-wizard-next-step-item{-webkit-flex-wrap:wrap;flex-wrap:wrap}.pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-description{margin-bottom:0}.pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-action p{margin:0}}@media only screen and (max-width:360px){#pll-logo{font-size:48px}} \ No newline at end of file diff --git a/wp-content/plugins/polylang/css/selectmenu.css b/wp-content/plugins/polylang/css/selectmenu.css deleted file mode 100644 index 9eb29261..00000000 --- a/wp-content/plugins/polylang/css/selectmenu.css +++ /dev/null @@ -1,140 +0,0 @@ -/* Greatly modified version of the jquery-ui.css */ - -.ui-widget-overlay { - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; -} - -.ui-menu { - list-style: none; - padding: 0; - margin: 0; - display: block; - outline: none; -} - -.ui-menu .ui-menu { - position: absolute; -} - -.ui-menu .ui-menu-item { - position: relative; - margin: 0; - padding: 3px 1em 3px .4em; - min-height: 0; /* support: IE7 */ - /* support: IE10, see #8844 */ - list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"); -} - -/* icon support */ -.ui-menu-icons { - position: relative; -} - -.ui-menu-icons .ui-menu-item { - padding-left: 2em; -} - -/* left-aligned */ -.ui-selectmenu-text .ui-icon, -.ui-menu .ui-icon { - position: absolute; - top: 0; - bottom: 0; - left: .2em; - margin: auto 0; -} - -/* right-aligned */ -.ui-menu .ui-menu-icon { - left: auto; - right: 0; -} - -.ui-selectmenu-menu { - padding: 0; - margin: 0; - position: absolute; - top: 0; - left: 0; - display: none; -} - -.ui-selectmenu-menu .ui-menu { - overflow: auto; - /* Support: IE7 */ - overflow-x: hidden; - padding-bottom: 1px; -} - -.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup { - font-size: 1em; - font-weight: bold; - line-height: 23px; - padding: 2px 0.4em; - margin: 0.5em 0 0 0; - height: auto; - border: 0; -} - -.ui-selectmenu-open { - display: block; -} - -.ui-selectmenu-button { - display: inline-block; - overflow: hidden; - position: relative; - text-decoration: none; -} - -.ui-selectmenu-button span.ui-icon { - right: 0.5em; - left: auto; - margin-top: -10px; - position: absolute; - top: 50%; -} - -.ui-selectmenu-button span.ui-selectmenu-text { - text-align: left; - padding: 0.4em 2.1em 0.4em 2em; - display: block; - line-height: 23px; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.ui-widget-content, -.ui-state-default, -.ui-widget-content .ui-state-default, -.ui-widget-header .ui-state-default { - background: #fff; - border: 1px solid #ddd; - box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07) inset; - color: #32373c; -} - -.ui-widget-content .ui-state-hover, -.ui-widget-content .ui-state-focus { - background: #f5f5f5; -} - -.ui-selectmenu-button.ui-state-focus { - border: 1px solid #5b9dd9; - box-shadow: 0 0 2px rgba(30, 140, 190, 0.8); -} - -.ui-icon-triangle-1-s:before { - content: "\f140"; - font: 20px/1 'dashicons'; -} - -.ui-widget-content { - max-height: 231px; - box-shadow: 0 2px 6px rgba(100, 100, 100, 0.3); -} diff --git a/wp-content/plugins/polylang/css/selectmenu.min.css b/wp-content/plugins/polylang/css/selectmenu.min.css deleted file mode 100644 index 5527ee05..00000000 --- a/wp-content/plugins/polylang/css/selectmenu.min.css +++ /dev/null @@ -1 +0,0 @@ -.ui-widget-overlay{position:fixed;top:0;left:0;width:100%;height:100%}.ui-menu{list-style:none;padding:0;margin:0;display:block;outline:0}.ui-menu .ui-menu{position:absolute}.ui-menu .ui-menu-item{position:relative;margin:0;padding:3px 1em 3px .4em;min-height:0;list-style-image:url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)}.ui-menu-icons{position:relative}.ui-menu-icons .ui-menu-item{padding-left:2em}.ui-menu .ui-icon,.ui-selectmenu-text .ui-icon{position:absolute;top:0;bottom:0;left:.2em;margin:auto 0}.ui-menu .ui-menu-icon{left:auto;right:0}.ui-selectmenu-menu{padding:0;margin:0;position:absolute;top:0;left:0;display:none}.ui-selectmenu-menu .ui-menu{overflow:auto;overflow-x:hidden;padding-bottom:1px}.ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup{font-size:1em;font-weight:700;line-height:23px;padding:2px .4em;margin:.5em 0 0;height:auto;border:0}.ui-selectmenu-open{display:block}.ui-selectmenu-button{display:inline-block;overflow:hidden;position:relative;text-decoration:none}.ui-selectmenu-button span.ui-icon{right:.5em;left:auto;margin-top:-10px;position:absolute;top:50%}.ui-selectmenu-button span.ui-selectmenu-text{text-align:left;padding:.4em 2.1em .4em 2em;display:block;line-height:23px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.ui-state-default,.ui-widget-content,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default{background:#fff;border:1px solid #ddd;box-shadow:0 1px 2px rgba(0,0,0,.07) inset;color:#32373c}.ui-widget-content .ui-state-focus,.ui-widget-content .ui-state-hover{background:#f5f5f5}.ui-selectmenu-button.ui-state-focus{border:1px solid #5b9dd9;box-shadow:0 0 2px rgba(30,140,190,.8)}.ui-icon-triangle-1-s:before{content:"\f140";font:20px/1 dashicons}.ui-widget-content{max-height:231px;box-shadow:0 2px 6px rgba(100,100,100,.3)} diff --git a/wp-content/plugins/polylang/flags/ad.png b/wp-content/plugins/polylang/flags/ad.png index 625ca84f..0523f1b2 100644 Binary files a/wp-content/plugins/polylang/flags/ad.png and b/wp-content/plugins/polylang/flags/ad.png differ diff --git a/wp-content/plugins/polylang/flags/ae.png b/wp-content/plugins/polylang/flags/ae.png index ef3a1ecf..c47bfeb3 100644 Binary files a/wp-content/plugins/polylang/flags/ae.png and b/wp-content/plugins/polylang/flags/ae.png differ diff --git a/wp-content/plugins/polylang/flags/af.png b/wp-content/plugins/polylang/flags/af.png index a4742e29..b1a1a3b6 100644 Binary files a/wp-content/plugins/polylang/flags/af.png and b/wp-content/plugins/polylang/flags/af.png differ diff --git a/wp-content/plugins/polylang/flags/ag.png b/wp-content/plugins/polylang/flags/ag.png index 556d5504..f607adc7 100644 Binary files a/wp-content/plugins/polylang/flags/ag.png and b/wp-content/plugins/polylang/flags/ag.png differ diff --git a/wp-content/plugins/polylang/flags/ai.png b/wp-content/plugins/polylang/flags/ai.png index 74ed29d9..4aa64254 100644 Binary files a/wp-content/plugins/polylang/flags/ai.png and b/wp-content/plugins/polylang/flags/ai.png differ diff --git a/wp-content/plugins/polylang/flags/al.png b/wp-content/plugins/polylang/flags/al.png index 92354cb6..6ffe0ac0 100644 Binary files a/wp-content/plugins/polylang/flags/al.png and b/wp-content/plugins/polylang/flags/al.png differ diff --git a/wp-content/plugins/polylang/flags/am.png b/wp-content/plugins/polylang/flags/am.png index 344a2a86..e7520d7a 100644 Binary files a/wp-content/plugins/polylang/flags/am.png and b/wp-content/plugins/polylang/flags/am.png differ diff --git a/wp-content/plugins/polylang/flags/an.png b/wp-content/plugins/polylang/flags/an.png index 633e4b89..2b61643e 100644 Binary files a/wp-content/plugins/polylang/flags/an.png and b/wp-content/plugins/polylang/flags/an.png differ diff --git a/wp-content/plugins/polylang/flags/ao.png b/wp-content/plugins/polylang/flags/ao.png index bcbd1d6d..742882fe 100644 Binary files a/wp-content/plugins/polylang/flags/ao.png and b/wp-content/plugins/polylang/flags/ao.png differ diff --git a/wp-content/plugins/polylang/flags/ar.png b/wp-content/plugins/polylang/flags/ar.png index e5ef8f1f..46d43f45 100644 Binary files a/wp-content/plugins/polylang/flags/ar.png and b/wp-content/plugins/polylang/flags/ar.png differ diff --git a/wp-content/plugins/polylang/flags/arab.png b/wp-content/plugins/polylang/flags/arab.png index 365172ac..fd70e4a2 100644 Binary files a/wp-content/plugins/polylang/flags/arab.png and b/wp-content/plugins/polylang/flags/arab.png differ diff --git a/wp-content/plugins/polylang/flags/as.png b/wp-content/plugins/polylang/flags/as.png index 32f30e4c..e66a3ae2 100644 Binary files a/wp-content/plugins/polylang/flags/as.png and b/wp-content/plugins/polylang/flags/as.png differ diff --git a/wp-content/plugins/polylang/flags/at.png b/wp-content/plugins/polylang/flags/at.png index 0f15f34f..bed916d9 100644 Binary files a/wp-content/plugins/polylang/flags/at.png and b/wp-content/plugins/polylang/flags/at.png differ diff --git a/wp-content/plugins/polylang/flags/au.png b/wp-content/plugins/polylang/flags/au.png index a01389a7..8b0d2445 100644 Binary files a/wp-content/plugins/polylang/flags/au.png and b/wp-content/plugins/polylang/flags/au.png differ diff --git a/wp-content/plugins/polylang/flags/aw.png b/wp-content/plugins/polylang/flags/aw.png index a3579c2d..b272f781 100644 Binary files a/wp-content/plugins/polylang/flags/aw.png and b/wp-content/plugins/polylang/flags/aw.png differ diff --git a/wp-content/plugins/polylang/flags/ax.png b/wp-content/plugins/polylang/flags/ax.png index 1eea80a7..256d61e6 100644 Binary files a/wp-content/plugins/polylang/flags/ax.png and b/wp-content/plugins/polylang/flags/ax.png differ diff --git a/wp-content/plugins/polylang/flags/az.png b/wp-content/plugins/polylang/flags/az.png index 4ee9fe5c..d9a32de7 100644 Binary files a/wp-content/plugins/polylang/flags/az.png and b/wp-content/plugins/polylang/flags/az.png differ diff --git a/wp-content/plugins/polylang/flags/ba.png b/wp-content/plugins/polylang/flags/ba.png index c7749924..d10cd5cf 100644 Binary files a/wp-content/plugins/polylang/flags/ba.png and b/wp-content/plugins/polylang/flags/ba.png differ diff --git a/wp-content/plugins/polylang/flags/basque.png b/wp-content/plugins/polylang/flags/basque.png index cb2f25e1..3b593695 100644 Binary files a/wp-content/plugins/polylang/flags/basque.png and b/wp-content/plugins/polylang/flags/basque.png differ diff --git a/wp-content/plugins/polylang/flags/bb.png b/wp-content/plugins/polylang/flags/bb.png index 0df19c71..e786361e 100644 Binary files a/wp-content/plugins/polylang/flags/bb.png and b/wp-content/plugins/polylang/flags/bb.png differ diff --git a/wp-content/plugins/polylang/flags/bd.png b/wp-content/plugins/polylang/flags/bd.png index 076a8bf8..de039dd8 100644 Binary files a/wp-content/plugins/polylang/flags/bd.png and b/wp-content/plugins/polylang/flags/bd.png differ diff --git a/wp-content/plugins/polylang/flags/be.png b/wp-content/plugins/polylang/flags/be.png index d86ebc80..94470bc8 100644 Binary files a/wp-content/plugins/polylang/flags/be.png and b/wp-content/plugins/polylang/flags/be.png differ diff --git a/wp-content/plugins/polylang/flags/bf.png b/wp-content/plugins/polylang/flags/bf.png index ab5ce8fe..167207f3 100644 Binary files a/wp-content/plugins/polylang/flags/bf.png and b/wp-content/plugins/polylang/flags/bf.png differ diff --git a/wp-content/plugins/polylang/flags/bg.png b/wp-content/plugins/polylang/flags/bg.png index 0469f060..fd9b9766 100644 Binary files a/wp-content/plugins/polylang/flags/bg.png and b/wp-content/plugins/polylang/flags/bg.png differ diff --git a/wp-content/plugins/polylang/flags/bh.png b/wp-content/plugins/polylang/flags/bh.png index ea8ce687..1d2ff785 100644 Binary files a/wp-content/plugins/polylang/flags/bh.png and b/wp-content/plugins/polylang/flags/bh.png differ diff --git a/wp-content/plugins/polylang/flags/bi.png b/wp-content/plugins/polylang/flags/bi.png index 5cc2e30c..2331b802 100644 Binary files a/wp-content/plugins/polylang/flags/bi.png and b/wp-content/plugins/polylang/flags/bi.png differ diff --git a/wp-content/plugins/polylang/flags/bj.png b/wp-content/plugins/polylang/flags/bj.png index 1cc8b458..5405502f 100644 Binary files a/wp-content/plugins/polylang/flags/bj.png and b/wp-content/plugins/polylang/flags/bj.png differ diff --git a/wp-content/plugins/polylang/flags/bm.png b/wp-content/plugins/polylang/flags/bm.png index c0c7aead..7c8046c7 100644 Binary files a/wp-content/plugins/polylang/flags/bm.png and b/wp-content/plugins/polylang/flags/bm.png differ diff --git a/wp-content/plugins/polylang/flags/bn.png b/wp-content/plugins/polylang/flags/bn.png index 8fb09849..59c2eb45 100644 Binary files a/wp-content/plugins/polylang/flags/bn.png and b/wp-content/plugins/polylang/flags/bn.png differ diff --git a/wp-content/plugins/polylang/flags/bo.png b/wp-content/plugins/polylang/flags/bo.png index ce7ba522..a7bdabc7 100644 Binary files a/wp-content/plugins/polylang/flags/bo.png and b/wp-content/plugins/polylang/flags/bo.png differ diff --git a/wp-content/plugins/polylang/flags/br.png b/wp-content/plugins/polylang/flags/br.png index 9b1a5538..eabb7ba3 100644 Binary files a/wp-content/plugins/polylang/flags/br.png and b/wp-content/plugins/polylang/flags/br.png differ diff --git a/wp-content/plugins/polylang/flags/bs.png b/wp-content/plugins/polylang/flags/bs.png index 639fa6cf..741a25ca 100644 Binary files a/wp-content/plugins/polylang/flags/bs.png and b/wp-content/plugins/polylang/flags/bs.png differ diff --git a/wp-content/plugins/polylang/flags/bt.png b/wp-content/plugins/polylang/flags/bt.png index 1d512dff..65571d1b 100644 Binary files a/wp-content/plugins/polylang/flags/bt.png and b/wp-content/plugins/polylang/flags/bt.png differ diff --git a/wp-content/plugins/polylang/flags/bw.png b/wp-content/plugins/polylang/flags/bw.png index fcb10394..f00a4166 100644 Binary files a/wp-content/plugins/polylang/flags/bw.png and b/wp-content/plugins/polylang/flags/bw.png differ diff --git a/wp-content/plugins/polylang/flags/by.png b/wp-content/plugins/polylang/flags/by.png index 504774ec..864c6042 100644 Binary files a/wp-content/plugins/polylang/flags/by.png and b/wp-content/plugins/polylang/flags/by.png differ diff --git a/wp-content/plugins/polylang/flags/bz.png b/wp-content/plugins/polylang/flags/bz.png index be63ee1c..b36bc0ad 100644 Binary files a/wp-content/plugins/polylang/flags/bz.png and b/wp-content/plugins/polylang/flags/bz.png differ diff --git a/wp-content/plugins/polylang/flags/ca.png b/wp-content/plugins/polylang/flags/ca.png index 1f204193..5cbb1260 100644 Binary files a/wp-content/plugins/polylang/flags/ca.png and b/wp-content/plugins/polylang/flags/ca.png differ diff --git a/wp-content/plugins/polylang/flags/catalonia.png b/wp-content/plugins/polylang/flags/catalonia.png index 5041e308..616e1cd1 100644 Binary files a/wp-content/plugins/polylang/flags/catalonia.png and b/wp-content/plugins/polylang/flags/catalonia.png differ diff --git a/wp-content/plugins/polylang/flags/cc.png b/wp-content/plugins/polylang/flags/cc.png index aed3d3b4..6c50dbe8 100644 Binary files a/wp-content/plugins/polylang/flags/cc.png and b/wp-content/plugins/polylang/flags/cc.png differ diff --git a/wp-content/plugins/polylang/flags/cd.png b/wp-content/plugins/polylang/flags/cd.png index 5e489424..c282ffe6 100644 Binary files a/wp-content/plugins/polylang/flags/cd.png and b/wp-content/plugins/polylang/flags/cd.png differ diff --git a/wp-content/plugins/polylang/flags/cf.png b/wp-content/plugins/polylang/flags/cf.png index da687bdc..b67aa2d0 100644 Binary files a/wp-content/plugins/polylang/flags/cf.png and b/wp-content/plugins/polylang/flags/cf.png differ diff --git a/wp-content/plugins/polylang/flags/cg.png b/wp-content/plugins/polylang/flags/cg.png index a859792e..ff346931 100644 Binary files a/wp-content/plugins/polylang/flags/cg.png and b/wp-content/plugins/polylang/flags/cg.png differ diff --git a/wp-content/plugins/polylang/flags/ch.png b/wp-content/plugins/polylang/flags/ch.png index 242ec01a..29f6c55b 100644 Binary files a/wp-content/plugins/polylang/flags/ch.png and b/wp-content/plugins/polylang/flags/ch.png differ diff --git a/wp-content/plugins/polylang/flags/ci.png b/wp-content/plugins/polylang/flags/ci.png index 3f2c62eb..ae6c89b7 100644 Binary files a/wp-content/plugins/polylang/flags/ci.png and b/wp-content/plugins/polylang/flags/ci.png differ diff --git a/wp-content/plugins/polylang/flags/ck.png b/wp-content/plugins/polylang/flags/ck.png index 746d3d6f..dfb2e78a 100644 Binary files a/wp-content/plugins/polylang/flags/ck.png and b/wp-content/plugins/polylang/flags/ck.png differ diff --git a/wp-content/plugins/polylang/flags/cl.png b/wp-content/plugins/polylang/flags/cl.png index 29c6d61b..6d3f3b69 100644 Binary files a/wp-content/plugins/polylang/flags/cl.png and b/wp-content/plugins/polylang/flags/cl.png differ diff --git a/wp-content/plugins/polylang/flags/cm.png b/wp-content/plugins/polylang/flags/cm.png index f65c5bd5..a655979f 100644 Binary files a/wp-content/plugins/polylang/flags/cm.png and b/wp-content/plugins/polylang/flags/cm.png differ diff --git a/wp-content/plugins/polylang/flags/cn.png b/wp-content/plugins/polylang/flags/cn.png index 89144146..f64afc15 100644 Binary files a/wp-content/plugins/polylang/flags/cn.png and b/wp-content/plugins/polylang/flags/cn.png differ diff --git a/wp-content/plugins/polylang/flags/co.png b/wp-content/plugins/polylang/flags/co.png index a118ff4a..b62e1315 100644 Binary files a/wp-content/plugins/polylang/flags/co.png and b/wp-content/plugins/polylang/flags/co.png differ diff --git a/wp-content/plugins/polylang/flags/cr.png b/wp-content/plugins/polylang/flags/cr.png index c7a37317..55139ecf 100644 Binary files a/wp-content/plugins/polylang/flags/cr.png and b/wp-content/plugins/polylang/flags/cr.png differ diff --git a/wp-content/plugins/polylang/flags/cu.png b/wp-content/plugins/polylang/flags/cu.png index 083f1d61..859e5982 100644 Binary files a/wp-content/plugins/polylang/flags/cu.png and b/wp-content/plugins/polylang/flags/cu.png differ diff --git a/wp-content/plugins/polylang/flags/cv.png b/wp-content/plugins/polylang/flags/cv.png index a63f7eaf..cef21f92 100644 Binary files a/wp-content/plugins/polylang/flags/cv.png and b/wp-content/plugins/polylang/flags/cv.png differ diff --git a/wp-content/plugins/polylang/flags/cx.png b/wp-content/plugins/polylang/flags/cx.png index 48e31adb..a2d748e4 100644 Binary files a/wp-content/plugins/polylang/flags/cx.png and b/wp-content/plugins/polylang/flags/cx.png differ diff --git a/wp-content/plugins/polylang/flags/cy.png b/wp-content/plugins/polylang/flags/cy.png index 5b1ad6c0..7f9ed40d 100644 Binary files a/wp-content/plugins/polylang/flags/cy.png and b/wp-content/plugins/polylang/flags/cy.png differ diff --git a/wp-content/plugins/polylang/flags/cz.png b/wp-content/plugins/polylang/flags/cz.png index c8403dd2..6c2c5656 100644 Binary files a/wp-content/plugins/polylang/flags/cz.png and b/wp-content/plugins/polylang/flags/cz.png differ diff --git a/wp-content/plugins/polylang/flags/de.png b/wp-content/plugins/polylang/flags/de.png index ac4a9773..41bc81b6 100644 Binary files a/wp-content/plugins/polylang/flags/de.png and b/wp-content/plugins/polylang/flags/de.png differ diff --git a/wp-content/plugins/polylang/flags/dj.png b/wp-content/plugins/polylang/flags/dj.png index 582af364..fb82dcc9 100644 Binary files a/wp-content/plugins/polylang/flags/dj.png and b/wp-content/plugins/polylang/flags/dj.png differ diff --git a/wp-content/plugins/polylang/flags/dk.png b/wp-content/plugins/polylang/flags/dk.png index e2993d3c..3b9282c2 100644 Binary files a/wp-content/plugins/polylang/flags/dk.png and b/wp-content/plugins/polylang/flags/dk.png differ diff --git a/wp-content/plugins/polylang/flags/dm.png b/wp-content/plugins/polylang/flags/dm.png index 5fbffcba..5488cb52 100644 Binary files a/wp-content/plugins/polylang/flags/dm.png and b/wp-content/plugins/polylang/flags/dm.png differ diff --git a/wp-content/plugins/polylang/flags/do.png b/wp-content/plugins/polylang/flags/do.png index 5a04932d..d27ef3d7 100644 Binary files a/wp-content/plugins/polylang/flags/do.png and b/wp-content/plugins/polylang/flags/do.png differ diff --git a/wp-content/plugins/polylang/flags/dz.png b/wp-content/plugins/polylang/flags/dz.png index 335c2391..78a7be65 100644 Binary files a/wp-content/plugins/polylang/flags/dz.png and b/wp-content/plugins/polylang/flags/dz.png differ diff --git a/wp-content/plugins/polylang/flags/ec.png b/wp-content/plugins/polylang/flags/ec.png index 0caa0b1e..fef746c2 100644 Binary files a/wp-content/plugins/polylang/flags/ec.png and b/wp-content/plugins/polylang/flags/ec.png differ diff --git a/wp-content/plugins/polylang/flags/ee.png b/wp-content/plugins/polylang/flags/ee.png index 0c82efb7..e49b1b47 100644 Binary files a/wp-content/plugins/polylang/flags/ee.png and b/wp-content/plugins/polylang/flags/ee.png differ diff --git a/wp-content/plugins/polylang/flags/eg.png b/wp-content/plugins/polylang/flags/eg.png index 8a3f7a10..f37f60a6 100644 Binary files a/wp-content/plugins/polylang/flags/eg.png and b/wp-content/plugins/polylang/flags/eg.png differ diff --git a/wp-content/plugins/polylang/flags/eh.png b/wp-content/plugins/polylang/flags/eh.png index 90a1195b..49bff039 100644 Binary files a/wp-content/plugins/polylang/flags/eh.png and b/wp-content/plugins/polylang/flags/eh.png differ diff --git a/wp-content/plugins/polylang/flags/england.png b/wp-content/plugins/polylang/flags/england.png index 3a7311d5..e0984c30 100644 Binary files a/wp-content/plugins/polylang/flags/england.png and b/wp-content/plugins/polylang/flags/england.png differ diff --git a/wp-content/plugins/polylang/flags/er.png b/wp-content/plugins/polylang/flags/er.png index 13065ae9..5d6d16cb 100644 Binary files a/wp-content/plugins/polylang/flags/er.png and b/wp-content/plugins/polylang/flags/er.png differ diff --git a/wp-content/plugins/polylang/flags/es.png b/wp-content/plugins/polylang/flags/es.png index c2de2d71..04c65aa9 100644 Binary files a/wp-content/plugins/polylang/flags/es.png and b/wp-content/plugins/polylang/flags/es.png differ diff --git a/wp-content/plugins/polylang/flags/esperanto.png b/wp-content/plugins/polylang/flags/esperanto.png index 03a333e2..00306b66 100644 Binary files a/wp-content/plugins/polylang/flags/esperanto.png and b/wp-content/plugins/polylang/flags/esperanto.png differ diff --git a/wp-content/plugins/polylang/flags/et.png b/wp-content/plugins/polylang/flags/et.png index 2e893fa0..45a622fe 100644 Binary files a/wp-content/plugins/polylang/flags/et.png and b/wp-content/plugins/polylang/flags/et.png differ diff --git a/wp-content/plugins/polylang/flags/fi.png b/wp-content/plugins/polylang/flags/fi.png index 14ec091b..a1a843f4 100644 Binary files a/wp-content/plugins/polylang/flags/fi.png and b/wp-content/plugins/polylang/flags/fi.png differ diff --git a/wp-content/plugins/polylang/flags/fj.png b/wp-content/plugins/polylang/flags/fj.png index cee99889..308d1ecd 100644 Binary files a/wp-content/plugins/polylang/flags/fj.png and b/wp-content/plugins/polylang/flags/fj.png differ diff --git a/wp-content/plugins/polylang/flags/fk.png b/wp-content/plugins/polylang/flags/fk.png index ceaeb27d..9a1c740e 100644 Binary files a/wp-content/plugins/polylang/flags/fk.png and b/wp-content/plugins/polylang/flags/fk.png differ diff --git a/wp-content/plugins/polylang/flags/fm.png b/wp-content/plugins/polylang/flags/fm.png index 066bb247..b97a1248 100644 Binary files a/wp-content/plugins/polylang/flags/fm.png and b/wp-content/plugins/polylang/flags/fm.png differ diff --git a/wp-content/plugins/polylang/flags/fo.png b/wp-content/plugins/polylang/flags/fo.png index cbceb809..4cad1fc6 100644 Binary files a/wp-content/plugins/polylang/flags/fo.png and b/wp-content/plugins/polylang/flags/fo.png differ diff --git a/wp-content/plugins/polylang/flags/fr.png b/wp-content/plugins/polylang/flags/fr.png index 8332c4ec..9e443e68 100644 Binary files a/wp-content/plugins/polylang/flags/fr.png and b/wp-content/plugins/polylang/flags/fr.png differ diff --git a/wp-content/plugins/polylang/flags/ga.png b/wp-content/plugins/polylang/flags/ga.png index 0e0d4343..8c902aca 100644 Binary files a/wp-content/plugins/polylang/flags/ga.png and b/wp-content/plugins/polylang/flags/ga.png differ diff --git a/wp-content/plugins/polylang/flags/galicia.png b/wp-content/plugins/polylang/flags/galicia.png index 64b0cbb4..ed656876 100644 Binary files a/wp-content/plugins/polylang/flags/galicia.png and b/wp-content/plugins/polylang/flags/galicia.png differ diff --git a/wp-content/plugins/polylang/flags/gb.png b/wp-content/plugins/polylang/flags/gb.png index ff701e19..f8c4cbdb 100644 Binary files a/wp-content/plugins/polylang/flags/gb.png and b/wp-content/plugins/polylang/flags/gb.png differ diff --git a/wp-content/plugins/polylang/flags/gd.png b/wp-content/plugins/polylang/flags/gd.png index 9ab57f54..060fe2b9 100644 Binary files a/wp-content/plugins/polylang/flags/gd.png and b/wp-content/plugins/polylang/flags/gd.png differ diff --git a/wp-content/plugins/polylang/flags/ge.png b/wp-content/plugins/polylang/flags/ge.png index 728d9707..26cbbc9d 100644 Binary files a/wp-content/plugins/polylang/flags/ge.png and b/wp-content/plugins/polylang/flags/ge.png differ diff --git a/wp-content/plugins/polylang/flags/gh.png b/wp-content/plugins/polylang/flags/gh.png index 4e2f8965..573e1b1e 100644 Binary files a/wp-content/plugins/polylang/flags/gh.png and b/wp-content/plugins/polylang/flags/gh.png differ diff --git a/wp-content/plugins/polylang/flags/gi.png b/wp-content/plugins/polylang/flags/gi.png index e76797f6..412a6428 100644 Binary files a/wp-content/plugins/polylang/flags/gi.png and b/wp-content/plugins/polylang/flags/gi.png differ diff --git a/wp-content/plugins/polylang/flags/gl.png b/wp-content/plugins/polylang/flags/gl.png index ef12a73b..9a376c8e 100644 Binary files a/wp-content/plugins/polylang/flags/gl.png and b/wp-content/plugins/polylang/flags/gl.png differ diff --git a/wp-content/plugins/polylang/flags/gm.png b/wp-content/plugins/polylang/flags/gm.png index 0720b667..d39aa5b6 100644 Binary files a/wp-content/plugins/polylang/flags/gm.png and b/wp-content/plugins/polylang/flags/gm.png differ diff --git a/wp-content/plugins/polylang/flags/gn.png b/wp-content/plugins/polylang/flags/gn.png index ea660b01..e6e8ec88 100644 Binary files a/wp-content/plugins/polylang/flags/gn.png and b/wp-content/plugins/polylang/flags/gn.png differ diff --git a/wp-content/plugins/polylang/flags/gp.png b/wp-content/plugins/polylang/flags/gp.png index dbb086d0..aceeea92 100644 Binary files a/wp-content/plugins/polylang/flags/gp.png and b/wp-content/plugins/polylang/flags/gp.png differ diff --git a/wp-content/plugins/polylang/flags/gq.png b/wp-content/plugins/polylang/flags/gq.png index ebe20a28..5450d0b9 100644 Binary files a/wp-content/plugins/polylang/flags/gq.png and b/wp-content/plugins/polylang/flags/gq.png differ diff --git a/wp-content/plugins/polylang/flags/gr.png b/wp-content/plugins/polylang/flags/gr.png index 8651ade7..57afba59 100644 Binary files a/wp-content/plugins/polylang/flags/gr.png and b/wp-content/plugins/polylang/flags/gr.png differ diff --git a/wp-content/plugins/polylang/flags/gs.png b/wp-content/plugins/polylang/flags/gs.png index 7ef0bf59..2efa092b 100644 Binary files a/wp-content/plugins/polylang/flags/gs.png and b/wp-content/plugins/polylang/flags/gs.png differ diff --git a/wp-content/plugins/polylang/flags/gt.png b/wp-content/plugins/polylang/flags/gt.png index c43a70d3..bcd0e148 100644 Binary files a/wp-content/plugins/polylang/flags/gt.png and b/wp-content/plugins/polylang/flags/gt.png differ diff --git a/wp-content/plugins/polylang/flags/gu.png b/wp-content/plugins/polylang/flags/gu.png index 92f37c05..1e7644e0 100644 Binary files a/wp-content/plugins/polylang/flags/gu.png and b/wp-content/plugins/polylang/flags/gu.png differ diff --git a/wp-content/plugins/polylang/flags/gw.png b/wp-content/plugins/polylang/flags/gw.png index b37bcf06..762cdee1 100644 Binary files a/wp-content/plugins/polylang/flags/gw.png and b/wp-content/plugins/polylang/flags/gw.png differ diff --git a/wp-content/plugins/polylang/flags/gy.png b/wp-content/plugins/polylang/flags/gy.png index 22cbe2f5..e90b8f78 100644 Binary files a/wp-content/plugins/polylang/flags/gy.png and b/wp-content/plugins/polylang/flags/gy.png differ diff --git a/wp-content/plugins/polylang/flags/hk.png b/wp-content/plugins/polylang/flags/hk.png index d5c380ca..d285f57c 100644 Binary files a/wp-content/plugins/polylang/flags/hk.png and b/wp-content/plugins/polylang/flags/hk.png differ diff --git a/wp-content/plugins/polylang/flags/hm.png b/wp-content/plugins/polylang/flags/hm.png index a01389a7..8b0d2445 100644 Binary files a/wp-content/plugins/polylang/flags/hm.png and b/wp-content/plugins/polylang/flags/hm.png differ diff --git a/wp-content/plugins/polylang/flags/hn.png b/wp-content/plugins/polylang/flags/hn.png index 96f83885..d108cd01 100644 Binary files a/wp-content/plugins/polylang/flags/hn.png and b/wp-content/plugins/polylang/flags/hn.png differ diff --git a/wp-content/plugins/polylang/flags/hr.png b/wp-content/plugins/polylang/flags/hr.png index 696b5154..ced07809 100644 Binary files a/wp-content/plugins/polylang/flags/hr.png and b/wp-content/plugins/polylang/flags/hr.png differ diff --git a/wp-content/plugins/polylang/flags/ht.png b/wp-content/plugins/polylang/flags/ht.png index 416052af..bc5a3857 100644 Binary files a/wp-content/plugins/polylang/flags/ht.png and b/wp-content/plugins/polylang/flags/ht.png differ diff --git a/wp-content/plugins/polylang/flags/hu.png b/wp-content/plugins/polylang/flags/hu.png index 7baafe44..3ce93695 100644 Binary files a/wp-content/plugins/polylang/flags/hu.png and b/wp-content/plugins/polylang/flags/hu.png differ diff --git a/wp-content/plugins/polylang/flags/id.png b/wp-content/plugins/polylang/flags/id.png index c6bc0faf..fc6b7b99 100644 Binary files a/wp-content/plugins/polylang/flags/id.png and b/wp-content/plugins/polylang/flags/id.png differ diff --git a/wp-content/plugins/polylang/flags/ie.png b/wp-content/plugins/polylang/flags/ie.png index 26baa31e..0432bc77 100644 Binary files a/wp-content/plugins/polylang/flags/ie.png and b/wp-content/plugins/polylang/flags/ie.png differ diff --git a/wp-content/plugins/polylang/flags/il.png b/wp-content/plugins/polylang/flags/il.png index 2ca772d0..315ac318 100644 Binary files a/wp-content/plugins/polylang/flags/il.png and b/wp-content/plugins/polylang/flags/il.png differ diff --git a/wp-content/plugins/polylang/flags/in.png b/wp-content/plugins/polylang/flags/in.png index e4d7e81a..14f49a59 100644 Binary files a/wp-content/plugins/polylang/flags/in.png and b/wp-content/plugins/polylang/flags/in.png differ diff --git a/wp-content/plugins/polylang/flags/io.png b/wp-content/plugins/polylang/flags/io.png index 3e74b6a3..e9282073 100644 Binary files a/wp-content/plugins/polylang/flags/io.png and b/wp-content/plugins/polylang/flags/io.png differ diff --git a/wp-content/plugins/polylang/flags/iq.png b/wp-content/plugins/polylang/flags/iq.png index 878a3514..989cdc82 100644 Binary files a/wp-content/plugins/polylang/flags/iq.png and b/wp-content/plugins/polylang/flags/iq.png differ diff --git a/wp-content/plugins/polylang/flags/ir.png b/wp-content/plugins/polylang/flags/ir.png index c5fd136a..bdbf70da 100644 Binary files a/wp-content/plugins/polylang/flags/ir.png and b/wp-content/plugins/polylang/flags/ir.png differ diff --git a/wp-content/plugins/polylang/flags/is.png b/wp-content/plugins/polylang/flags/is.png index b8f6d0f0..3dd06dba 100644 Binary files a/wp-content/plugins/polylang/flags/is.png and b/wp-content/plugins/polylang/flags/is.png differ diff --git a/wp-content/plugins/polylang/flags/it.png b/wp-content/plugins/polylang/flags/it.png index 89692f74..9dc1a86b 100644 Binary files a/wp-content/plugins/polylang/flags/it.png and b/wp-content/plugins/polylang/flags/it.png differ diff --git a/wp-content/plugins/polylang/flags/jm.png b/wp-content/plugins/polylang/flags/jm.png index 7be119e0..83fcc756 100644 Binary files a/wp-content/plugins/polylang/flags/jm.png and b/wp-content/plugins/polylang/flags/jm.png differ diff --git a/wp-content/plugins/polylang/flags/jo.png b/wp-content/plugins/polylang/flags/jo.png index 11bd4972..c6c11ada 100644 Binary files a/wp-content/plugins/polylang/flags/jo.png and b/wp-content/plugins/polylang/flags/jo.png differ diff --git a/wp-content/plugins/polylang/flags/jp.png b/wp-content/plugins/polylang/flags/jp.png index 325fbad3..82168d96 100644 Binary files a/wp-content/plugins/polylang/flags/jp.png and b/wp-content/plugins/polylang/flags/jp.png differ diff --git a/wp-content/plugins/polylang/flags/ke.png b/wp-content/plugins/polylang/flags/ke.png index 51879adf..33306eea 100644 Binary files a/wp-content/plugins/polylang/flags/ke.png and b/wp-content/plugins/polylang/flags/ke.png differ diff --git a/wp-content/plugins/polylang/flags/kg.png b/wp-content/plugins/polylang/flags/kg.png index 0a818f67..73f997f2 100644 Binary files a/wp-content/plugins/polylang/flags/kg.png and b/wp-content/plugins/polylang/flags/kg.png differ diff --git a/wp-content/plugins/polylang/flags/kh.png b/wp-content/plugins/polylang/flags/kh.png index 30f6bb1b..ee718d9d 100644 Binary files a/wp-content/plugins/polylang/flags/kh.png and b/wp-content/plugins/polylang/flags/kh.png differ diff --git a/wp-content/plugins/polylang/flags/ki.png b/wp-content/plugins/polylang/flags/ki.png index 2dcce4b3..2835c460 100644 Binary files a/wp-content/plugins/polylang/flags/ki.png and b/wp-content/plugins/polylang/flags/ki.png differ diff --git a/wp-content/plugins/polylang/flags/km.png b/wp-content/plugins/polylang/flags/km.png index 812b2f56..2ee55b1c 100644 Binary files a/wp-content/plugins/polylang/flags/km.png and b/wp-content/plugins/polylang/flags/km.png differ diff --git a/wp-content/plugins/polylang/flags/kn.png b/wp-content/plugins/polylang/flags/kn.png index febd5b48..f3f43999 100644 Binary files a/wp-content/plugins/polylang/flags/kn.png and b/wp-content/plugins/polylang/flags/kn.png differ diff --git a/wp-content/plugins/polylang/flags/kp.png b/wp-content/plugins/polylang/flags/kp.png index d3d509aa..c55ebef1 100644 Binary files a/wp-content/plugins/polylang/flags/kp.png and b/wp-content/plugins/polylang/flags/kp.png differ diff --git a/wp-content/plugins/polylang/flags/kr.png b/wp-content/plugins/polylang/flags/kr.png index 9c0a78eb..ea24bd06 100644 Binary files a/wp-content/plugins/polylang/flags/kr.png and b/wp-content/plugins/polylang/flags/kr.png differ diff --git a/wp-content/plugins/polylang/flags/kurdistan.png b/wp-content/plugins/polylang/flags/kurdistan.png index 02517b46..fded8c5d 100644 Binary files a/wp-content/plugins/polylang/flags/kurdistan.png and b/wp-content/plugins/polylang/flags/kurdistan.png differ diff --git a/wp-content/plugins/polylang/flags/kw.png b/wp-content/plugins/polylang/flags/kw.png index 96546da3..9e852ebb 100644 Binary files a/wp-content/plugins/polylang/flags/kw.png and b/wp-content/plugins/polylang/flags/kw.png differ diff --git a/wp-content/plugins/polylang/flags/ky.png b/wp-content/plugins/polylang/flags/ky.png index 15c5f8e4..c2cd8201 100644 Binary files a/wp-content/plugins/polylang/flags/ky.png and b/wp-content/plugins/polylang/flags/ky.png differ diff --git a/wp-content/plugins/polylang/flags/kz.png b/wp-content/plugins/polylang/flags/kz.png index 45a8c887..52f6cfec 100644 Binary files a/wp-content/plugins/polylang/flags/kz.png and b/wp-content/plugins/polylang/flags/kz.png differ diff --git a/wp-content/plugins/polylang/flags/la.png b/wp-content/plugins/polylang/flags/la.png index e28acd01..a93fb5da 100644 Binary files a/wp-content/plugins/polylang/flags/la.png and b/wp-content/plugins/polylang/flags/la.png differ diff --git a/wp-content/plugins/polylang/flags/lb.png b/wp-content/plugins/polylang/flags/lb.png index d0d452bf..ba5df97e 100644 Binary files a/wp-content/plugins/polylang/flags/lb.png and b/wp-content/plugins/polylang/flags/lb.png differ diff --git a/wp-content/plugins/polylang/flags/lc.png b/wp-content/plugins/polylang/flags/lc.png index a47d0655..72526dbd 100644 Binary files a/wp-content/plugins/polylang/flags/lc.png and b/wp-content/plugins/polylang/flags/lc.png differ diff --git a/wp-content/plugins/polylang/flags/li.png b/wp-content/plugins/polylang/flags/li.png index 6469909c..cac346ba 100644 Binary files a/wp-content/plugins/polylang/flags/li.png and b/wp-content/plugins/polylang/flags/li.png differ diff --git a/wp-content/plugins/polylang/flags/lk.png b/wp-content/plugins/polylang/flags/lk.png index 088aad6d..9942f39e 100644 Binary files a/wp-content/plugins/polylang/flags/lk.png and b/wp-content/plugins/polylang/flags/lk.png differ diff --git a/wp-content/plugins/polylang/flags/lr.png b/wp-content/plugins/polylang/flags/lr.png index 89a5bc7e..175bcd8e 100644 Binary files a/wp-content/plugins/polylang/flags/lr.png and b/wp-content/plugins/polylang/flags/lr.png differ diff --git a/wp-content/plugins/polylang/flags/ls.png b/wp-content/plugins/polylang/flags/ls.png index 33fdef10..3c0f37fd 100644 Binary files a/wp-content/plugins/polylang/flags/ls.png and b/wp-content/plugins/polylang/flags/ls.png differ diff --git a/wp-content/plugins/polylang/flags/lt.png b/wp-content/plugins/polylang/flags/lt.png index c8ef0da0..9860367e 100644 Binary files a/wp-content/plugins/polylang/flags/lt.png and b/wp-content/plugins/polylang/flags/lt.png differ diff --git a/wp-content/plugins/polylang/flags/lu.png b/wp-content/plugins/polylang/flags/lu.png index 4cabba98..cf14435c 100644 Binary files a/wp-content/plugins/polylang/flags/lu.png and b/wp-content/plugins/polylang/flags/lu.png differ diff --git a/wp-content/plugins/polylang/flags/lv.png b/wp-content/plugins/polylang/flags/lv.png index 49b69981..ec616e83 100644 Binary files a/wp-content/plugins/polylang/flags/lv.png and b/wp-content/plugins/polylang/flags/lv.png differ diff --git a/wp-content/plugins/polylang/flags/ly.png b/wp-content/plugins/polylang/flags/ly.png index b163a9f8..e04ecb37 100644 Binary files a/wp-content/plugins/polylang/flags/ly.png and b/wp-content/plugins/polylang/flags/ly.png differ diff --git a/wp-content/plugins/polylang/flags/ma.png b/wp-content/plugins/polylang/flags/ma.png index f3867702..a96ae457 100644 Binary files a/wp-content/plugins/polylang/flags/ma.png and b/wp-content/plugins/polylang/flags/ma.png differ diff --git a/wp-content/plugins/polylang/flags/mc.png b/wp-content/plugins/polylang/flags/mc.png index 1aa830f1..a4a03893 100644 Binary files a/wp-content/plugins/polylang/flags/mc.png and b/wp-content/plugins/polylang/flags/mc.png differ diff --git a/wp-content/plugins/polylang/flags/md.png b/wp-content/plugins/polylang/flags/md.png index 4e92c189..4faa1d1b 100644 Binary files a/wp-content/plugins/polylang/flags/md.png and b/wp-content/plugins/polylang/flags/md.png differ diff --git a/wp-content/plugins/polylang/flags/me.png b/wp-content/plugins/polylang/flags/me.png index ac725355..70d7b4f5 100644 Binary files a/wp-content/plugins/polylang/flags/me.png and b/wp-content/plugins/polylang/flags/me.png differ diff --git a/wp-content/plugins/polylang/flags/mg.png b/wp-content/plugins/polylang/flags/mg.png index d2715b3d..fd71126a 100644 Binary files a/wp-content/plugins/polylang/flags/mg.png and b/wp-content/plugins/polylang/flags/mg.png differ diff --git a/wp-content/plugins/polylang/flags/mh.png b/wp-content/plugins/polylang/flags/mh.png index fb523a8c..572b2cc0 100644 Binary files a/wp-content/plugins/polylang/flags/mh.png and b/wp-content/plugins/polylang/flags/mh.png differ diff --git a/wp-content/plugins/polylang/flags/mk.png b/wp-content/plugins/polylang/flags/mk.png index db173aaf..5b495c78 100644 Binary files a/wp-content/plugins/polylang/flags/mk.png and b/wp-content/plugins/polylang/flags/mk.png differ diff --git a/wp-content/plugins/polylang/flags/ml.png b/wp-content/plugins/polylang/flags/ml.png index 2cec8ba4..83d2d3ce 100644 Binary files a/wp-content/plugins/polylang/flags/ml.png and b/wp-content/plugins/polylang/flags/ml.png differ diff --git a/wp-content/plugins/polylang/flags/mm.png b/wp-content/plugins/polylang/flags/mm.png index 10340d26..c820369e 100644 Binary files a/wp-content/plugins/polylang/flags/mm.png and b/wp-content/plugins/polylang/flags/mm.png differ diff --git a/wp-content/plugins/polylang/flags/mn.png b/wp-content/plugins/polylang/flags/mn.png index 9396355d..99af9598 100644 Binary files a/wp-content/plugins/polylang/flags/mn.png and b/wp-content/plugins/polylang/flags/mn.png differ diff --git a/wp-content/plugins/polylang/flags/mo.png b/wp-content/plugins/polylang/flags/mo.png index deb801dd..179edf3f 100644 Binary files a/wp-content/plugins/polylang/flags/mo.png and b/wp-content/plugins/polylang/flags/mo.png differ diff --git a/wp-content/plugins/polylang/flags/mp.png b/wp-content/plugins/polylang/flags/mp.png index 298d588b..5e51851f 100644 Binary files a/wp-content/plugins/polylang/flags/mp.png and b/wp-content/plugins/polylang/flags/mp.png differ diff --git a/wp-content/plugins/polylang/flags/mq.png b/wp-content/plugins/polylang/flags/mq.png index 010143b3..16a24fce 100644 Binary files a/wp-content/plugins/polylang/flags/mq.png and b/wp-content/plugins/polylang/flags/mq.png differ diff --git a/wp-content/plugins/polylang/flags/mr.png b/wp-content/plugins/polylang/flags/mr.png index 319546b1..60bc15f8 100644 Binary files a/wp-content/plugins/polylang/flags/mr.png and b/wp-content/plugins/polylang/flags/mr.png differ diff --git a/wp-content/plugins/polylang/flags/ms.png b/wp-content/plugins/polylang/flags/ms.png index d4cbb433..19cb7b63 100644 Binary files a/wp-content/plugins/polylang/flags/ms.png and b/wp-content/plugins/polylang/flags/ms.png differ diff --git a/wp-content/plugins/polylang/flags/mt.png b/wp-content/plugins/polylang/flags/mt.png index 00af9487..32e460ce 100644 Binary files a/wp-content/plugins/polylang/flags/mt.png and b/wp-content/plugins/polylang/flags/mt.png differ diff --git a/wp-content/plugins/polylang/flags/mu.png b/wp-content/plugins/polylang/flags/mu.png index b7fdce1b..6219cb67 100644 Binary files a/wp-content/plugins/polylang/flags/mu.png and b/wp-content/plugins/polylang/flags/mu.png differ diff --git a/wp-content/plugins/polylang/flags/mv.png b/wp-content/plugins/polylang/flags/mv.png index 5073d9ec..22a5982d 100644 Binary files a/wp-content/plugins/polylang/flags/mv.png and b/wp-content/plugins/polylang/flags/mv.png differ diff --git a/wp-content/plugins/polylang/flags/mw.png b/wp-content/plugins/polylang/flags/mw.png index 13886e9f..7b72870d 100644 Binary files a/wp-content/plugins/polylang/flags/mw.png and b/wp-content/plugins/polylang/flags/mw.png differ diff --git a/wp-content/plugins/polylang/flags/mx.png b/wp-content/plugins/polylang/flags/mx.png index 5bc58ab3..233d6c52 100644 Binary files a/wp-content/plugins/polylang/flags/mx.png and b/wp-content/plugins/polylang/flags/mx.png differ diff --git a/wp-content/plugins/polylang/flags/my.png b/wp-content/plugins/polylang/flags/my.png index 9034cbab..ef4fc070 100644 Binary files a/wp-content/plugins/polylang/flags/my.png and b/wp-content/plugins/polylang/flags/my.png differ diff --git a/wp-content/plugins/polylang/flags/mz.png b/wp-content/plugins/polylang/flags/mz.png index 76405e06..c1202739 100644 Binary files a/wp-content/plugins/polylang/flags/mz.png and b/wp-content/plugins/polylang/flags/mz.png differ diff --git a/wp-content/plugins/polylang/flags/na.png b/wp-content/plugins/polylang/flags/na.png index 63358c67..cb1488aa 100644 Binary files a/wp-content/plugins/polylang/flags/na.png and b/wp-content/plugins/polylang/flags/na.png differ diff --git a/wp-content/plugins/polylang/flags/nc.png b/wp-content/plugins/polylang/flags/nc.png index 2cad2837..bf83cce3 100644 Binary files a/wp-content/plugins/polylang/flags/nc.png and b/wp-content/plugins/polylang/flags/nc.png differ diff --git a/wp-content/plugins/polylang/flags/ne.png b/wp-content/plugins/polylang/flags/ne.png index d85f424f..1db0c05b 100644 Binary files a/wp-content/plugins/polylang/flags/ne.png and b/wp-content/plugins/polylang/flags/ne.png differ diff --git a/wp-content/plugins/polylang/flags/nf.png b/wp-content/plugins/polylang/flags/nf.png index f9bcdda1..225e608c 100644 Binary files a/wp-content/plugins/polylang/flags/nf.png and b/wp-content/plugins/polylang/flags/nf.png differ diff --git a/wp-content/plugins/polylang/flags/ng.png b/wp-content/plugins/polylang/flags/ng.png index 3eea2e02..71db6052 100644 Binary files a/wp-content/plugins/polylang/flags/ng.png and b/wp-content/plugins/polylang/flags/ng.png differ diff --git a/wp-content/plugins/polylang/flags/ni.png b/wp-content/plugins/polylang/flags/ni.png index 3969aaaa..8a3df9f4 100644 Binary files a/wp-content/plugins/polylang/flags/ni.png and b/wp-content/plugins/polylang/flags/ni.png differ diff --git a/wp-content/plugins/polylang/flags/nl.png b/wp-content/plugins/polylang/flags/nl.png index fe44791e..34b52a24 100644 Binary files a/wp-content/plugins/polylang/flags/nl.png and b/wp-content/plugins/polylang/flags/nl.png differ diff --git a/wp-content/plugins/polylang/flags/no.png b/wp-content/plugins/polylang/flags/no.png index 160b6b5b..0f98f5e2 100644 Binary files a/wp-content/plugins/polylang/flags/no.png and b/wp-content/plugins/polylang/flags/no.png differ diff --git a/wp-content/plugins/polylang/flags/np.png b/wp-content/plugins/polylang/flags/np.png index aeb058b7..4fda5d66 100644 Binary files a/wp-content/plugins/polylang/flags/np.png and b/wp-content/plugins/polylang/flags/np.png differ diff --git a/wp-content/plugins/polylang/flags/nr.png b/wp-content/plugins/polylang/flags/nr.png index 705fc337..e4d79777 100644 Binary files a/wp-content/plugins/polylang/flags/nr.png and b/wp-content/plugins/polylang/flags/nr.png differ diff --git a/wp-content/plugins/polylang/flags/nu.png b/wp-content/plugins/polylang/flags/nu.png index c3ce4aed..350a9ddd 100644 Binary files a/wp-content/plugins/polylang/flags/nu.png and b/wp-content/plugins/polylang/flags/nu.png differ diff --git a/wp-content/plugins/polylang/flags/nz.png b/wp-content/plugins/polylang/flags/nz.png index 10d6306d..c83bd1ab 100644 Binary files a/wp-content/plugins/polylang/flags/nz.png and b/wp-content/plugins/polylang/flags/nz.png differ diff --git a/wp-content/plugins/polylang/flags/occitania.png b/wp-content/plugins/polylang/flags/occitania.png index e500b351..08688df9 100644 Binary files a/wp-content/plugins/polylang/flags/occitania.png and b/wp-content/plugins/polylang/flags/occitania.png differ diff --git a/wp-content/plugins/polylang/flags/om.png b/wp-content/plugins/polylang/flags/om.png index 2ffba7e8..2eb3a155 100644 Binary files a/wp-content/plugins/polylang/flags/om.png and b/wp-content/plugins/polylang/flags/om.png differ diff --git a/wp-content/plugins/polylang/flags/pa.png b/wp-content/plugins/polylang/flags/pa.png index 9b2ee9a7..1f84ae5a 100644 Binary files a/wp-content/plugins/polylang/flags/pa.png and b/wp-content/plugins/polylang/flags/pa.png differ diff --git a/wp-content/plugins/polylang/flags/pe.png b/wp-content/plugins/polylang/flags/pe.png index 62a04977..342d003b 100644 Binary files a/wp-content/plugins/polylang/flags/pe.png and b/wp-content/plugins/polylang/flags/pe.png differ diff --git a/wp-content/plugins/polylang/flags/pf.png b/wp-content/plugins/polylang/flags/pf.png index 771a0f65..4663091b 100644 Binary files a/wp-content/plugins/polylang/flags/pf.png and b/wp-content/plugins/polylang/flags/pf.png differ diff --git a/wp-content/plugins/polylang/flags/pg.png b/wp-content/plugins/polylang/flags/pg.png index 10d62334..46d82189 100644 Binary files a/wp-content/plugins/polylang/flags/pg.png and b/wp-content/plugins/polylang/flags/pg.png differ diff --git a/wp-content/plugins/polylang/flags/ph.png b/wp-content/plugins/polylang/flags/ph.png index b89e1593..7aeee8c5 100644 Binary files a/wp-content/plugins/polylang/flags/ph.png and b/wp-content/plugins/polylang/flags/ph.png differ diff --git a/wp-content/plugins/polylang/flags/pk.png b/wp-content/plugins/polylang/flags/pk.png index e9df70ca..e898448c 100644 Binary files a/wp-content/plugins/polylang/flags/pk.png and b/wp-content/plugins/polylang/flags/pk.png differ diff --git a/wp-content/plugins/polylang/flags/pl.png b/wp-content/plugins/polylang/flags/pl.png index d413d010..10da179a 100644 Binary files a/wp-content/plugins/polylang/flags/pl.png and b/wp-content/plugins/polylang/flags/pl.png differ diff --git a/wp-content/plugins/polylang/flags/pm.png b/wp-content/plugins/polylang/flags/pm.png index ba91d2c7..b6cd50f2 100644 Binary files a/wp-content/plugins/polylang/flags/pm.png and b/wp-content/plugins/polylang/flags/pm.png differ diff --git a/wp-content/plugins/polylang/flags/pn.png b/wp-content/plugins/polylang/flags/pn.png index aa9344f5..600994df 100644 Binary files a/wp-content/plugins/polylang/flags/pn.png and b/wp-content/plugins/polylang/flags/pn.png differ diff --git a/wp-content/plugins/polylang/flags/pr.png b/wp-content/plugins/polylang/flags/pr.png index 82d9130d..cf104c42 100644 Binary files a/wp-content/plugins/polylang/flags/pr.png and b/wp-content/plugins/polylang/flags/pr.png differ diff --git a/wp-content/plugins/polylang/flags/ps.png b/wp-content/plugins/polylang/flags/ps.png index f5f54776..e313f318 100644 Binary files a/wp-content/plugins/polylang/flags/ps.png and b/wp-content/plugins/polylang/flags/ps.png differ diff --git a/wp-content/plugins/polylang/flags/pt.png b/wp-content/plugins/polylang/flags/pt.png index ece79801..c90c4456 100644 Binary files a/wp-content/plugins/polylang/flags/pt.png and b/wp-content/plugins/polylang/flags/pt.png differ diff --git a/wp-content/plugins/polylang/flags/pw.png b/wp-content/plugins/polylang/flags/pw.png index 6178b254..b1a4f4fc 100644 Binary files a/wp-content/plugins/polylang/flags/pw.png and b/wp-content/plugins/polylang/flags/pw.png differ diff --git a/wp-content/plugins/polylang/flags/py.png b/wp-content/plugins/polylang/flags/py.png index cb8723c0..0f143ffe 100644 Binary files a/wp-content/plugins/polylang/flags/py.png and b/wp-content/plugins/polylang/flags/py.png differ diff --git a/wp-content/plugins/polylang/flags/qa.png b/wp-content/plugins/polylang/flags/qa.png index ed4c621f..9945c685 100644 Binary files a/wp-content/plugins/polylang/flags/qa.png and b/wp-content/plugins/polylang/flags/qa.png differ diff --git a/wp-content/plugins/polylang/flags/quebec.png b/wp-content/plugins/polylang/flags/quebec.png index a90cf0bb..8c34644a 100644 Binary files a/wp-content/plugins/polylang/flags/quebec.png and b/wp-content/plugins/polylang/flags/quebec.png differ diff --git a/wp-content/plugins/polylang/flags/ro.png b/wp-content/plugins/polylang/flags/ro.png index 57e74a65..24e989a3 100644 Binary files a/wp-content/plugins/polylang/flags/ro.png and b/wp-content/plugins/polylang/flags/ro.png differ diff --git a/wp-content/plugins/polylang/flags/rs.png b/wp-content/plugins/polylang/flags/rs.png index 9439a5b6..8fb41a5d 100644 Binary files a/wp-content/plugins/polylang/flags/rs.png and b/wp-content/plugins/polylang/flags/rs.png differ diff --git a/wp-content/plugins/polylang/flags/ru.png b/wp-content/plugins/polylang/flags/ru.png index 47da4214..2c5f1337 100644 Binary files a/wp-content/plugins/polylang/flags/ru.png and b/wp-content/plugins/polylang/flags/ru.png differ diff --git a/wp-content/plugins/polylang/flags/rw.png b/wp-content/plugins/polylang/flags/rw.png index 53564917..2ce16456 100644 Binary files a/wp-content/plugins/polylang/flags/rw.png and b/wp-content/plugins/polylang/flags/rw.png differ diff --git a/wp-content/plugins/polylang/flags/sa.png b/wp-content/plugins/polylang/flags/sa.png index b4641c7e..0246b1a6 100644 Binary files a/wp-content/plugins/polylang/flags/sa.png and b/wp-content/plugins/polylang/flags/sa.png differ diff --git a/wp-content/plugins/polylang/flags/sb.png b/wp-content/plugins/polylang/flags/sb.png index a9937ccf..da51301e 100644 Binary files a/wp-content/plugins/polylang/flags/sb.png and b/wp-content/plugins/polylang/flags/sb.png differ diff --git a/wp-content/plugins/polylang/flags/sc.png b/wp-content/plugins/polylang/flags/sc.png index 39ee3718..52408113 100644 Binary files a/wp-content/plugins/polylang/flags/sc.png and b/wp-content/plugins/polylang/flags/sc.png differ diff --git a/wp-content/plugins/polylang/flags/scotland.png b/wp-content/plugins/polylang/flags/scotland.png index a0e57b41..eda0d491 100644 Binary files a/wp-content/plugins/polylang/flags/scotland.png and b/wp-content/plugins/polylang/flags/scotland.png differ diff --git a/wp-content/plugins/polylang/flags/sd.png b/wp-content/plugins/polylang/flags/sd.png index eaab69eb..20fb2305 100644 Binary files a/wp-content/plugins/polylang/flags/sd.png and b/wp-content/plugins/polylang/flags/sd.png differ diff --git a/wp-content/plugins/polylang/flags/se.png b/wp-content/plugins/polylang/flags/se.png index 1994653d..4f66b472 100644 Binary files a/wp-content/plugins/polylang/flags/se.png and b/wp-content/plugins/polylang/flags/se.png differ diff --git a/wp-content/plugins/polylang/flags/sg.png b/wp-content/plugins/polylang/flags/sg.png index dd34d612..a4e86518 100644 Binary files a/wp-content/plugins/polylang/flags/sg.png and b/wp-content/plugins/polylang/flags/sg.png differ diff --git a/wp-content/plugins/polylang/flags/sh.png b/wp-content/plugins/polylang/flags/sh.png index 4b1d2a29..6ac0d805 100644 Binary files a/wp-content/plugins/polylang/flags/sh.png and b/wp-content/plugins/polylang/flags/sh.png differ diff --git a/wp-content/plugins/polylang/flags/si.png b/wp-content/plugins/polylang/flags/si.png index bb1476ff..36f0a959 100644 Binary files a/wp-content/plugins/polylang/flags/si.png and b/wp-content/plugins/polylang/flags/si.png differ diff --git a/wp-content/plugins/polylang/flags/sk.png b/wp-content/plugins/polylang/flags/sk.png index 7ccbc827..5b613d99 100644 Binary files a/wp-content/plugins/polylang/flags/sk.png and b/wp-content/plugins/polylang/flags/sk.png differ diff --git a/wp-content/plugins/polylang/flags/sl.png b/wp-content/plugins/polylang/flags/sl.png index 12d812d2..72c6af42 100644 Binary files a/wp-content/plugins/polylang/flags/sl.png and b/wp-content/plugins/polylang/flags/sl.png differ diff --git a/wp-content/plugins/polylang/flags/sm.png b/wp-content/plugins/polylang/flags/sm.png index 3df2fdcf..fe9a6bb9 100644 Binary files a/wp-content/plugins/polylang/flags/sm.png and b/wp-content/plugins/polylang/flags/sm.png differ diff --git a/wp-content/plugins/polylang/flags/sn.png b/wp-content/plugins/polylang/flags/sn.png index eabb71db..889c002a 100644 Binary files a/wp-content/plugins/polylang/flags/sn.png and b/wp-content/plugins/polylang/flags/sn.png differ diff --git a/wp-content/plugins/polylang/flags/so.png b/wp-content/plugins/polylang/flags/so.png index 4a1ea4b2..843606fd 100644 Binary files a/wp-content/plugins/polylang/flags/so.png and b/wp-content/plugins/polylang/flags/so.png differ diff --git a/wp-content/plugins/polylang/flags/sr.png b/wp-content/plugins/polylang/flags/sr.png index 5eff9271..b1684cb1 100644 Binary files a/wp-content/plugins/polylang/flags/sr.png and b/wp-content/plugins/polylang/flags/sr.png differ diff --git a/wp-content/plugins/polylang/flags/ss.png b/wp-content/plugins/polylang/flags/ss.png index 6b5018a2..833eef24 100644 Binary files a/wp-content/plugins/polylang/flags/ss.png and b/wp-content/plugins/polylang/flags/ss.png differ diff --git a/wp-content/plugins/polylang/flags/st.png b/wp-content/plugins/polylang/flags/st.png index 2978557b..f1b0b531 100644 Binary files a/wp-content/plugins/polylang/flags/st.png and b/wp-content/plugins/polylang/flags/st.png differ diff --git a/wp-content/plugins/polylang/flags/sv.png b/wp-content/plugins/polylang/flags/sv.png index 24987990..70ac44f2 100644 Binary files a/wp-content/plugins/polylang/flags/sv.png and b/wp-content/plugins/polylang/flags/sv.png differ diff --git a/wp-content/plugins/polylang/flags/sy.png b/wp-content/plugins/polylang/flags/sy.png index f5ce30dc..a39ebefb 100644 Binary files a/wp-content/plugins/polylang/flags/sy.png and b/wp-content/plugins/polylang/flags/sy.png differ diff --git a/wp-content/plugins/polylang/flags/sz.png b/wp-content/plugins/polylang/flags/sz.png index 914ee861..9ae48512 100644 Binary files a/wp-content/plugins/polylang/flags/sz.png and b/wp-content/plugins/polylang/flags/sz.png differ diff --git a/wp-content/plugins/polylang/flags/tc.png b/wp-content/plugins/polylang/flags/tc.png index 8fc1156b..e6972adf 100644 Binary files a/wp-content/plugins/polylang/flags/tc.png and b/wp-content/plugins/polylang/flags/tc.png differ diff --git a/wp-content/plugins/polylang/flags/td.png b/wp-content/plugins/polylang/flags/td.png index 667f21fd..acf1da6f 100644 Binary files a/wp-content/plugins/polylang/flags/td.png and b/wp-content/plugins/polylang/flags/td.png differ diff --git a/wp-content/plugins/polylang/flags/tf.png b/wp-content/plugins/polylang/flags/tf.png index 80529a43..fe4ade76 100644 Binary files a/wp-content/plugins/polylang/flags/tf.png and b/wp-content/plugins/polylang/flags/tf.png differ diff --git a/wp-content/plugins/polylang/flags/tg.png b/wp-content/plugins/polylang/flags/tg.png index 3aa00ad4..b9a04838 100644 Binary files a/wp-content/plugins/polylang/flags/tg.png and b/wp-content/plugins/polylang/flags/tg.png differ diff --git a/wp-content/plugins/polylang/flags/th.png b/wp-content/plugins/polylang/flags/th.png index dd8ba917..ad9462a6 100644 Binary files a/wp-content/plugins/polylang/flags/th.png and b/wp-content/plugins/polylang/flags/th.png differ diff --git a/wp-content/plugins/polylang/flags/tibet.png b/wp-content/plugins/polylang/flags/tibet.png index 6ecc135e..b2f743bd 100644 Binary files a/wp-content/plugins/polylang/flags/tibet.png and b/wp-content/plugins/polylang/flags/tibet.png differ diff --git a/wp-content/plugins/polylang/flags/tj.png b/wp-content/plugins/polylang/flags/tj.png index 617bf645..192bd87e 100644 Binary files a/wp-content/plugins/polylang/flags/tj.png and b/wp-content/plugins/polylang/flags/tj.png differ diff --git a/wp-content/plugins/polylang/flags/tk.png b/wp-content/plugins/polylang/flags/tk.png index 67b8c8cb..59a93bd7 100644 Binary files a/wp-content/plugins/polylang/flags/tk.png and b/wp-content/plugins/polylang/flags/tk.png differ diff --git a/wp-content/plugins/polylang/flags/tl.png b/wp-content/plugins/polylang/flags/tl.png index 77da181e..e65b54a7 100644 Binary files a/wp-content/plugins/polylang/flags/tl.png and b/wp-content/plugins/polylang/flags/tl.png differ diff --git a/wp-content/plugins/polylang/flags/tm.png b/wp-content/plugins/polylang/flags/tm.png index 828020ec..a5a00005 100644 Binary files a/wp-content/plugins/polylang/flags/tm.png and b/wp-content/plugins/polylang/flags/tm.png differ diff --git a/wp-content/plugins/polylang/flags/tn.png b/wp-content/plugins/polylang/flags/tn.png index 183cdd3d..57e21bdd 100644 Binary files a/wp-content/plugins/polylang/flags/tn.png and b/wp-content/plugins/polylang/flags/tn.png differ diff --git a/wp-content/plugins/polylang/flags/to.png b/wp-content/plugins/polylang/flags/to.png index f89b8ba7..e320c68f 100644 Binary files a/wp-content/plugins/polylang/flags/to.png and b/wp-content/plugins/polylang/flags/to.png differ diff --git a/wp-content/plugins/polylang/flags/tr.png b/wp-content/plugins/polylang/flags/tr.png index be32f77e..4b472dd6 100644 Binary files a/wp-content/plugins/polylang/flags/tr.png and b/wp-content/plugins/polylang/flags/tr.png differ diff --git a/wp-content/plugins/polylang/flags/tt.png b/wp-content/plugins/polylang/flags/tt.png index 2a11c1e2..fec31bc1 100644 Binary files a/wp-content/plugins/polylang/flags/tt.png and b/wp-content/plugins/polylang/flags/tt.png differ diff --git a/wp-content/plugins/polylang/flags/tv.png b/wp-content/plugins/polylang/flags/tv.png index 28274c5f..359b8be8 100644 Binary files a/wp-content/plugins/polylang/flags/tv.png and b/wp-content/plugins/polylang/flags/tv.png differ diff --git a/wp-content/plugins/polylang/flags/tw.png b/wp-content/plugins/polylang/flags/tw.png index f31c654c..e026cb72 100644 Binary files a/wp-content/plugins/polylang/flags/tw.png and b/wp-content/plugins/polylang/flags/tw.png differ diff --git a/wp-content/plugins/polylang/flags/tz.png b/wp-content/plugins/polylang/flags/tz.png index c00ff796..3b1090ac 100644 Binary files a/wp-content/plugins/polylang/flags/tz.png and b/wp-content/plugins/polylang/flags/tz.png differ diff --git a/wp-content/plugins/polylang/flags/ua.png b/wp-content/plugins/polylang/flags/ua.png index 09563a21..24cd433c 100644 Binary files a/wp-content/plugins/polylang/flags/ua.png and b/wp-content/plugins/polylang/flags/ua.png differ diff --git a/wp-content/plugins/polylang/flags/ug.png b/wp-content/plugins/polylang/flags/ug.png index 33f4affa..1cac8d7c 100644 Binary files a/wp-content/plugins/polylang/flags/ug.png and b/wp-content/plugins/polylang/flags/ug.png differ diff --git a/wp-content/plugins/polylang/flags/us.png b/wp-content/plugins/polylang/flags/us.png index 10f451fe..81899ff3 100644 Binary files a/wp-content/plugins/polylang/flags/us.png and b/wp-content/plugins/polylang/flags/us.png differ diff --git a/wp-content/plugins/polylang/flags/uy.png b/wp-content/plugins/polylang/flags/uy.png index 31d948a0..6d3f7e24 100644 Binary files a/wp-content/plugins/polylang/flags/uy.png and b/wp-content/plugins/polylang/flags/uy.png differ diff --git a/wp-content/plugins/polylang/flags/uz.png b/wp-content/plugins/polylang/flags/uz.png index fef5dc17..f9d4707e 100644 Binary files a/wp-content/plugins/polylang/flags/uz.png and b/wp-content/plugins/polylang/flags/uz.png differ diff --git a/wp-content/plugins/polylang/flags/va.png b/wp-content/plugins/polylang/flags/va.png index b31eaf22..05f59d18 100644 Binary files a/wp-content/plugins/polylang/flags/va.png and b/wp-content/plugins/polylang/flags/va.png differ diff --git a/wp-content/plugins/polylang/flags/vc.png b/wp-content/plugins/polylang/flags/vc.png index 8fa17b06..0e0626b9 100644 Binary files a/wp-content/plugins/polylang/flags/vc.png and b/wp-content/plugins/polylang/flags/vc.png differ diff --git a/wp-content/plugins/polylang/flags/ve.png b/wp-content/plugins/polylang/flags/ve.png index 00c90f9a..a4ac3357 100644 Binary files a/wp-content/plugins/polylang/flags/ve.png and b/wp-content/plugins/polylang/flags/ve.png differ diff --git a/wp-content/plugins/polylang/flags/veneto.png b/wp-content/plugins/polylang/flags/veneto.png index 8dcf6a7b..45c5a1cf 100644 Binary files a/wp-content/plugins/polylang/flags/veneto.png and b/wp-content/plugins/polylang/flags/veneto.png differ diff --git a/wp-content/plugins/polylang/flags/vg.png b/wp-content/plugins/polylang/flags/vg.png index 41569079..47df07b9 100644 Binary files a/wp-content/plugins/polylang/flags/vg.png and b/wp-content/plugins/polylang/flags/vg.png differ diff --git a/wp-content/plugins/polylang/flags/vi.png b/wp-content/plugins/polylang/flags/vi.png index ed26915a..12e7fb36 100644 Binary files a/wp-content/plugins/polylang/flags/vi.png and b/wp-content/plugins/polylang/flags/vi.png differ diff --git a/wp-content/plugins/polylang/flags/vn.png b/wp-content/plugins/polylang/flags/vn.png index ec7cd48a..911897f7 100644 Binary files a/wp-content/plugins/polylang/flags/vn.png and b/wp-content/plugins/polylang/flags/vn.png differ diff --git a/wp-content/plugins/polylang/flags/vu.png b/wp-content/plugins/polylang/flags/vu.png index b3397bc6..508fc0ae 100644 Binary files a/wp-content/plugins/polylang/flags/vu.png and b/wp-content/plugins/polylang/flags/vu.png differ diff --git a/wp-content/plugins/polylang/flags/wales.png b/wp-content/plugins/polylang/flags/wales.png index e0d7cee1..d43bb1ac 100644 Binary files a/wp-content/plugins/polylang/flags/wales.png and b/wp-content/plugins/polylang/flags/wales.png differ diff --git a/wp-content/plugins/polylang/flags/wf.png b/wp-content/plugins/polylang/flags/wf.png index 9f955873..45bfce65 100644 Binary files a/wp-content/plugins/polylang/flags/wf.png and b/wp-content/plugins/polylang/flags/wf.png differ diff --git a/wp-content/plugins/polylang/flags/ws.png b/wp-content/plugins/polylang/flags/ws.png index c1695080..cdda4f23 100644 Binary files a/wp-content/plugins/polylang/flags/ws.png and b/wp-content/plugins/polylang/flags/ws.png differ diff --git a/wp-content/plugins/polylang/flags/ye.png b/wp-content/plugins/polylang/flags/ye.png index 468dfad0..0908b9b8 100644 Binary files a/wp-content/plugins/polylang/flags/ye.png and b/wp-content/plugins/polylang/flags/ye.png differ diff --git a/wp-content/plugins/polylang/flags/yt.png b/wp-content/plugins/polylang/flags/yt.png index c298f378..4e43a1ed 100644 Binary files a/wp-content/plugins/polylang/flags/yt.png and b/wp-content/plugins/polylang/flags/yt.png differ diff --git a/wp-content/plugins/polylang/flags/za.png b/wp-content/plugins/polylang/flags/za.png index 57c58e21..c7fc63e0 100644 Binary files a/wp-content/plugins/polylang/flags/za.png and b/wp-content/plugins/polylang/flags/za.png differ diff --git a/wp-content/plugins/polylang/flags/zm.png b/wp-content/plugins/polylang/flags/zm.png index c25b07be..0b4bbfae 100644 Binary files a/wp-content/plugins/polylang/flags/zm.png and b/wp-content/plugins/polylang/flags/zm.png differ diff --git a/wp-content/plugins/polylang/flags/zw.png b/wp-content/plugins/polylang/flags/zw.png index 53c97259..a808419e 100644 Binary files a/wp-content/plugins/polylang/flags/zw.png and b/wp-content/plugins/polylang/flags/zw.png differ diff --git a/wp-content/plugins/polylang/frontend/accept-language.php b/wp-content/plugins/polylang/frontend/accept-language.php new file mode 100644 index 00000000..10b01ec5 --- /dev/null +++ b/wp-content/plugins/polylang/frontend/accept-language.php @@ -0,0 +1,112 @@ + '(\b[a-z]{2,3}|[a-z]{4}|[a-z]{5-8}\b)', + 'language-extension' => '(?:-(\b[a-z]{3}){1,3}\b)?', + 'script' => '(?:-(\b[a-z]{4})\b)?', + 'region' => '(?:-(\b[a-z]{2}|[0-9]{3})\b)?', + 'variant' => '(?:-(\b[0-9][a-z]{1,3}|[a-z][a-z0-9]{4,7})\b)?', + 'extension' => '(?:-(\b[a-wy-z]-[a-z0-9]{2,8})\b)?', + 'private-use' => '(?:-(\bx-[a-z0-9]{1,8})\b)?', + ); + + /** + * @var string[] { + * @type string $language Usually 2 or three letters (ISO 639). + * @type string $language-extension Up to three groups of 3 letters. + * @type string $script Four letters. + * @type string $region Either two letters of three digits. + * @type string $variant Either one digit followed by 1 to 3 letters, or a letter followed by 2 to 7 alphanumerical characters. + * @type string $extension One letter that cannot be an 'x', followed by 2 to 8 alphanumerical characters. + * @type string $private-use Starts by 'x-', followed by 1 to 8 alphanumerical characters. + * } + */ + protected $subtags; + + /** + * @var float + */ + protected $quality; + + /** + * PLL_Accept_Language constructor. + * + * @since 3.0 + * + * @param string[] $subtags With subtag name as keys and subtag values as names. + * @param mixed $quality Floating point value from 0.0 to 1.0. Higher values indicates a user's preference. + */ + public function __construct( $subtags, $quality = 1.0 ) { + $this->subtags = $subtags; + $this->quality = is_numeric( $quality ) ? floatval( $quality ) : 1.0; + } + + /** + * Creates a new instance from an array resulting of a PHP {@see preg_match()} or {@see preg_match_all()} call. + * + * @since 3.0 + * + * @param string[] $matches Expects first entry to be full match, following entries to be subtags and last entry to be quality factor. + * @return PLL_Accept_Language + */ + public static function from_array( $matches ) { + $subtags = array_combine( + array_keys( array_slice( self::SUBTAG_PATTERNS, 0, count( $matches ) - 1 ) ), + array_slice( $matches, 1, count( self::SUBTAG_PATTERNS ) ) + ); + $quality = count( $matches ) === 9 ? $matches[8] : 1.0; + + return new PLL_Accept_Language( $subtags, $quality ); + } + + /** + * Returns the full language tag. + * + * @since 3.0 + * + * @return string + */ + public function __toString() { + $subtags = array_filter( + $this->subtags, + function ( $subtag ) { + return ! empty( trim( $subtag ) ); + } + ); + return implode( '-', $subtags ); + } + + /** + * Returns the quality factor as negotiated by the browser agent. + * + * @since 3.0 + * + * @return float + */ + public function get_quality() { + return $this->quality; + } + + /** + * Returns a subtag from the language tag. + * + * @since 3.0 + * + * @param string $name A valid subtag name, {@see PLL_Accept_Language::SUBTAG_PATTERNS} for available subtag names. + * @return string + */ + public function get_subtag( $name ) { + return isset( $this->subtags[ $name ] ) ? $this->subtags[ $name ] : ''; + } +} diff --git a/wp-content/plugins/polylang/frontend/accept-languages-collection.php b/wp-content/plugins/polylang/frontend/accept-languages-collection.php new file mode 100644 index 00000000..b82c2ad0 --- /dev/null +++ b/wp-content/plugins/polylang/frontend/accept-languages-collection.php @@ -0,0 +1,143 @@ +1|0)(?>\.[0-9]+)?)'; + $full_pattern = "/{$language_pattern}(?:{$quality_pattern})?/i"; + + preg_match_all( + $full_pattern, + $http_header, + $lang_parse, + PREG_SET_ORDER + ); + + return new PLL_Accept_Languages_Collection( + array_map( + array( PLL_Accept_Language::class, 'from_array' ), + $lang_parse + ) + ); + } + + /** + * PLL_Accept_Languages_Collection constructor. + * + * @since 3.0 + * + * @param PLL_Accept_Language[] $accept_languages + */ + public function __construct( $accept_languages = array() ) { + $this->accept_languages = $accept_languages; + } + + /** + * Bubble sort ( need a stable sort for Android, so can't use a PHP sort function ). + * + * @since 3.0 + * + * @return void + */ + public function bubble_sort() { + $k = $this->accept_languages; + $v = array_map( + function ( $accept_lang ) { + return $accept_lang->get_quality(); + }, + $this->accept_languages + ); + + if ( $n = count( $k ) ) { + + if ( $n > 1 ) { + for ( $i = 2; $i <= $n; $i++ ) { + for ( $j = 0; $j <= $n - 2; $j++ ) { + if ( $v[ $j ] < $v[ $j + 1 ] ) { + // Swap values. + $temp = $v[ $j ]; + $v[ $j ] = $v[ $j + 1 ]; + $v[ $j + 1 ] = $temp; + // Swap keys. + $temp = $k[ $j ]; + $k[ $j ] = $k[ $j + 1 ]; + $k[ $j + 1 ] = $temp; + } + } + } + } + $this->accept_languages = array_filter( + $k, + function ( $accept_lang ) { + return $accept_lang->get_quality() > 0; + } + ); + } + } + + /** + * Looks through sorted list and use first one that matches our language list. + * + * @since 3.0 + * + * @param PLL_Language[] $languages + * @return string|false A language slug if there's a match, false otherwise. + */ + public function find_best_match( $languages = array() ) { + foreach ( $this->accept_languages as $accept_lang ) { + // First loop to match the exact locale. + foreach ( $languages as $language ) { + if ( 0 === strcasecmp( $accept_lang, $language->get_locale( 'display' ) ) ) { + return $language->slug; + } + } + + // In order of priority. + $subsets = array(); + if ( ! empty( $accept_lang->get_subtag( 'region' ) ) ) { + $subsets[] = $accept_lang->get_subtag( 'language' ) . '-' . $accept_lang->get_subtag( 'region' ); + $subsets[] = $accept_lang->get_subtag( 'region' ); + } + if ( ! empty( $accept_lang->get_subtag( 'variant' ) ) ) { + $subsets[] = $accept_lang->get_subtag( 'language' ) . '-' . $accept_lang->get_subtag( 'variant' ); + } + $subsets[] = $accept_lang->get_subtag( 'language' ); + + // More loops to match the subsets. + foreach ( $languages as $language ) { + foreach ( $subsets as $subset ) { + + if ( 0 === stripos( $subset, $language->slug ) || 0 === stripos( $language->get_locale( 'display' ), $subset ) ) { + return $language->slug; + } + } + } + } + return false; + } +} diff --git a/wp-content/plugins/polylang/frontend/choose-lang-content.php b/wp-content/plugins/polylang/frontend/choose-lang-content.php index b20002bf..6da6ad7a 100644 --- a/wp-content/plugins/polylang/frontend/choose-lang-content.php +++ b/wp-content/plugins/polylang/frontend/choose-lang-content.php @@ -1,4 +1,7 @@ options['media_support'] ) ) { return $this->get_preferred_language(); } if ( $var = get_query_var( 'lang' ) ) { $lang = explode( ',', $var ); - $lang = $this->model->get_language( reset( $lang ) ); // choose the first queried language + $lang = $this->model->get_language( reset( $lang ) ); // Choose the first queried language } elseif ( ( is_single() || is_page() || ( is_attachment() && $this->options['media_support'] ) ) && ( ( $var = get_queried_object_id() ) || ( $var = get_query_var( 'p' ) ) || ( $var = get_query_var( 'page_id' ) ) || ( $var = get_query_var( 'attachment_id' ) ) ) ) { @@ -61,39 +67,41 @@ class PLL_Choose_Lang_Content extends PLL_Choose_lang { else { foreach ( $this->model->get_translated_taxonomies() as $taxonomy ) { - if ( $var = get_query_var( get_taxonomy( $taxonomy )->query_var ) ) { + $tax_object = get_taxonomy( $taxonomy ); + if ( ! empty( $tax_object ) && $var = get_query_var( $tax_object->query_var ) ) { $lang = $this->model->term->get_language( $var, $taxonomy ); } } } /** - * Filter the language before it is set from the content + * Filters the language before it is set from the content. * * @since 0.9 * - * @param bool|object $lang language object or false if none was found + * @param PLL_Language|false $lang Language object or false if none was found. */ return apply_filters( 'pll_get_current_language', isset( $lang ) ? $lang : false ); } /** - * sets the language for home page - * add the lang query var when querying archives with no language code + * Sets the language for the home page. + * Adds the lang query var when querying archives with no language code. * * @since 1.2 * - * @param object $query instance of WP_Query + * @param WP_Query $query Instance of WP_Query. + * @return void */ public function parse_main_query( $query ) { - if ( $query !== $GLOBALS['wp_the_query'] ) { + if ( empty( $GLOBALS['wp_the_query'] ) || $query !== $GLOBALS['wp_the_query'] ) { return; } $qv = $query->query_vars; - // homepage is requested, let's set the language - // take care to avoid posts page for which is_home = 1 + // Homepage is requested, let's set the language + // Take care to avoid posts page for which is_home = 1 if ( empty( $query->query ) && ( is_home() || is_page() ) ) { $this->home_language(); $this->home_requested(); @@ -106,8 +114,8 @@ class PLL_Choose_Lang_Content extends PLL_Choose_lang { $query->is_author || ( ! empty( $qv['post_type'] ) && $query->is_post_type_archive && $this->model->is_translated_post_type( $qv['post_type'] ) ); - // sets the language in case we hide the default language - // use $query->query['s'] as is_search is not set when search is empty + // Sets the language in case we hide the default language + // Use $query->query['s'] as is_search is not set when search is empty // http://wordpress.org/support/topic/search-for-empty-string-in-default-language if ( $this->options['hide_default'] && ! isset( $qv['lang'] ) && ( $is_archive || isset( $query->query['s'] ) || ( count( $query->query ) == 1 && ! empty( $qv['feed'] ) ) ) ) { $this->set_language( $this->model->get_language( $this->options['default_lang'] ) ); @@ -116,24 +124,26 @@ class PLL_Choose_Lang_Content extends PLL_Choose_lang { } /** - * sets the language from content + * Sets the language from content * * @since 1.2 + * + * @return void */ public function wp() { - // nothing to do if the language has already been set ( although normally the filter has been removed ) - if ( ! $this->curlang && $curlang = $this->get_language_from_content() ) { + // Nothing to do if the language has already been set ( although normally the filter has been removed ) + if ( empty( $this->curlang ) && $curlang = $this->get_language_from_content() ) { parent::set_language( $curlang ); } } /** - * if no language found by get_language_from_content, return the preferred one + * If no language is found by {@see PLL_Choose_Lang_Content::get_language_from_content()}, returns the preferred one. * * @since 0.9 * - * @param object|bool $lang Language found in get_language_from_content - * @return object Language + * @param PLL_Language|false $lang Language found by {@see PLL_Choose_Lang_Content::get_language_from_content()}. + * @return PLL_Language */ public function pll_get_current_language( $lang ) { return ! $lang ? $this->get_preferred_language() : $lang; diff --git a/wp-content/plugins/polylang/frontend/choose-lang-domain.php b/wp-content/plugins/polylang/frontend/choose-lang-domain.php index 74eabd0b..dd11f19f 100644 --- a/wp-content/plugins/polylang/frontend/choose-lang-domain.php +++ b/wp-content/plugins/polylang/frontend/choose-lang-domain.php @@ -1,4 +1,7 @@ model->get_language( $this->links_model->get_language_from_url() ); @@ -27,6 +34,8 @@ class PLL_Choose_Lang_Domain extends PLL_Choose_Lang_Url { * Adds query vars to query for home pages in all languages * * @since 1.5 + * + * @return void */ public function home_requested() { $this->set_curlang_in_query( $GLOBALS['wp_query'] ); diff --git a/wp-content/plugins/polylang/frontend/choose-lang-url.php b/wp-content/plugins/polylang/frontend/choose-lang-url.php index 9cc6e544..dec824c3 100644 --- a/wp-content/plugins/polylang/frontend/choose-lang-url.php +++ b/wp-content/plugins/polylang/frontend/choose-lang-url.php @@ -1,4 +1,7 @@ links_model->home, PHP_URL_HOST ) ); - $home_path = parse_url( $this->links_model->home, PHP_URL_PATH ); + $host = str_replace( 'www.', '', wp_parse_url( $this->links_model->home, PHP_URL_HOST ) ); // Remove www. for the comparison + $home_path = (string) wp_parse_url( $this->links_model->home, PHP_URL_PATH ); - $requested_host = str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ); - $requested_uri = rtrim( str_replace( $this->index, '', $_SERVER['REQUEST_URI'] ), '/' ); // some PHP setups turn requests for / into /index.php in REQUEST_URI + $requested_url = pll_get_requested_url(); + $requested_host = str_replace( 'www.', '', wp_parse_url( $requested_url, PHP_URL_HOST ) ); // Remove www. for the comparison + $requested_path = rtrim( str_replace( $this->index, '', wp_parse_url( $requested_url, PHP_URL_PATH ) ), '/' ); // Some PHP setups turn requests for / into /index.php in REQUEST_URI + $requested_query = wp_parse_url( $requested_url, PHP_URL_QUERY ); - // home is requested - if ( $requested_host == $host && $requested_uri == $home_path && empty( $_SERVER['QUERY_STRING'] ) ) { + // Home is requested + if ( $requested_host === $host && $requested_path === $home_path && empty( $requested_query ) ) { $this->home_language(); add_action( 'setup_theme', array( $this, 'home_requested' ) ); } - // take care to post & page preview http://wordpress.org/support/topic/static-frontpage-url-parameter-url-language-information - elseif ( isset( $_GET['preview'] ) && ( ( isset( $_GET['p'] ) && $id = (int) $_GET['p'] ) || ( isset( $_GET['page_id'] ) && $id = (int) $_GET['page_id'] ) ) ) { + // Take care to post & page preview http://wordpress.org/support/topic/static-frontpage-url-parameter-url-language-information + elseif ( isset( $_GET['preview'] ) && ( ( isset( $_GET['p'] ) && $id = (int) $_GET['p'] ) || ( isset( $_GET['page_id'] ) && $id = (int) $_GET['page_id'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification $curlang = ( $lg = $this->model->post->get_language( $id ) ) ? $lg : $this->model->get_language( $this->options['default_lang'] ); } - // take care to ( unattached ) attachments - elseif ( isset( $_GET['attachment_id'] ) && $id = (int) $_GET['attachment_id'] ) { + // Take care to ( unattached ) attachments + elseif ( isset( $_GET['attachment_id'] ) && $id = (int) $_GET['attachment_id'] ) { // phpcs:ignore WordPress.Security.NonceVerification $curlang = ( $lg = $this->model->post->get_language( $id ) ) ? $lg : $this->get_preferred_language(); } @@ -61,14 +77,14 @@ class PLL_Choose_Lang_Url extends PLL_Choose_lang { $curlang = $this->model->get_language( $this->options['default_lang'] ); } - // if no language found, check_language_code_in_url will attempt to find one and redirect to the correct url - // otherwise 404 will be fired in the preferred language + // If no language found, check_language_code_in_url() will attempt to find one and redirect to the correct url + // Otherwise a 404 will be fired in the preferred language $this->set_language( empty( $curlang ) ? $this->get_preferred_language() : $curlang ); } /** - * adds the current language in query vars + * Adds the current language in query vars * useful for subdomains and multiple domains * * @since 1.8 @@ -80,14 +96,14 @@ class PLL_Choose_Lang_Url extends PLL_Choose_lang { // FIXME take care not to break untranslated content // FIXME media ? - // untranslated post types + // Untranslated post types if ( isset( $qv['post_type'] ) && ! $this->model->is_translated_post_type( $qv['post_type'] ) ) { return $qv; } - // untranslated taxonomies - $tax_qv = array_filter( wp_list_pluck( get_taxonomies( array(), 'objects' ), 'query_var' ) ); // get all taxonomies query vars - $tax_qv = array_intersect( $tax_qv, array_keys( $qv ) ); // get all queried taxonomies query vars + // Untranslated taxonomies + $tax_qv = array_filter( wp_list_pluck( get_taxonomies( array(), 'objects' ), 'query_var' ) ); // Get all taxonomies query vars + $tax_qv = array_intersect( $tax_qv, array_keys( $qv ) ); // Get all queried taxonomies query vars if ( ! $this->model->is_translated_taxonomy( array_keys( $tax_qv ) ) ) { return $qv; diff --git a/wp-content/plugins/polylang/frontend/choose-lang.php b/wp-content/plugins/polylang/frontend/choose-lang.php index 2f4d66dc..09cde813 100644 --- a/wp-content/plugins/polylang/frontend/choose-lang.php +++ b/wp-content/plugins/polylang/frontend/choose-lang.php @@ -1,16 +1,50 @@ set_language( empty( $_REQUEST['lang'] ) ? $this->get_preferred_language() : $this->model->get_language( $_REQUEST['lang'] ) ); + if ( Polylang::is_ajax_on_front() || ! wp_using_themes() ) { + $this->set_language( empty( $_REQUEST['lang'] ) ? $this->get_preferred_language() : $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification } add_action( 'pre_comment_on_post', array( $this, 'pre_comment_on_post' ) ); // sets the language of comment @@ -42,156 +78,109 @@ abstract class PLL_Choose_Lang { } /** - * writes language cookie - * loads user defined translations - * fires the action 'pll_language_defined' + * Sets the current language + * and fires the action 'pll_language_defined'. * * @since 1.2 * - * @param object $curlang current language + * @param PLL_Language $curlang Current language. + * @return void */ protected function set_language( $curlang ) { - // don't set the language a second time + // Don't set the language a second time if ( isset( $this->curlang ) ) { return; } - // final check in case $curlang has an unexpected value - // see https://wordpress.org/support/topic/detect-browser-language-sometimes-setting-null-language + // Final check in case $curlang has an unexpected value + // See https://wordpress.org/support/topic/detect-browser-language-sometimes-setting-null-language $this->curlang = ( $curlang instanceof PLL_Language ) ? $curlang : $this->model->get_language( $this->options['default_lang'] ); $GLOBALS['text_direction'] = $this->curlang->is_rtl ? 'rtl' : 'ltr'; + if ( did_action( 'wp_default_styles' ) ) { + wp_styles()->text_direction = $GLOBALS['text_direction']; + } /** - * Fires when the current language is defined + * Fires when the current language is defined. * * @since 0.9.5 * - * @param string $slug current language code - * @param object $curlang current language object + * @param string $slug Current language code. + * @param PLL_Language $curlang Current language object. */ do_action( 'pll_language_defined', $this->curlang->slug, $this->curlang ); } /** - * set a cookie to remember the language. - * possibility to set PLL_COOKIE to false will disable cookie although it will break some functionalities + * Set a cookie to remember the language. + * Setting PLL_COOKIE to false will disable cookie although it will break some functionalities * * @since 1.5 + * + * @return void */ public function maybe_setcookie() { - // check headers have not been sent to avoid ugly error - // cookie domain must be set to false for localhost ( default value for COOKIE_DOMAIN ) thanks to Stephen Harris. - if ( ! headers_sent() && PLL_COOKIE !== false && ! empty( $this->curlang ) && ( ! isset( $_COOKIE[ PLL_COOKIE ] ) || $_COOKIE[ PLL_COOKIE ] != $this->curlang->slug ) && ! is_404() ) { - - /** - * Filter the Polylang cookie duration - * - * @since 1.8 - * - * @param int $duration cookie duration in seconds - */ - $expiration = apply_filters( 'pll_cookie_expiration', YEAR_IN_SECONDS ); - - setcookie( - PLL_COOKIE, - $this->curlang->slug, - time() + $expiration, - COOKIEPATH, - 2 == $this->options['force_lang'] ? parse_url( $this->links_model->home, PHP_URL_HOST ) : COOKIE_DOMAIN, - is_ssl() + // Don't set cookie in javascript when a cache plugin is active. + if ( ! pll_is_cache_active() && ! empty( $this->curlang ) && ! is_404() ) { + $args = array( + 'domain' => 2 === $this->options['force_lang'] ? wp_parse_url( $this->links_model->home, PHP_URL_HOST ) : COOKIE_DOMAIN, + 'samesite' => 3 === $this->options['force_lang'] ? 'None' : 'Lax', ); + PLL_Cookie::set( $this->curlang->slug, $args ); } } /** - * get the preferred language according to the browser preferences - * code adapted from http://www.thefutureoftheweb.com/blog/use-accept-language-header + * Get the preferred language according to the browser preferences. * * @since 1.8 * - * @return string|bool the preferred language slug or false + * @return string|bool The preferred language slug or false. */ public function get_preferred_browser_language() { - $accept_langs = array(); - if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { - // break up string into pieces ( languages and q factors ) - preg_match_all( '/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*( 1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse ); + $accept_langs = PLL_Accept_Languages_Collection::from_accept_language_header( sanitize_text_field( wp_unslash( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) ); - $k = $lang_parse[1]; - $v = $lang_parse[4]; + $accept_langs->bubble_sort(); - if ( $n = count( $k ) ) { - // set default to 1 for any without q factor - foreach ( $v as $key => $val ) { - if ( '' === $val ) { - $v[ $key ] = 1; - } - } + $languages = $this->model->get_languages_list( array( 'hide_empty' => true ) ); // Hides languages with no post. - // bubble sort ( need a stable sort for Android, so can't use a PHP sort function ) - if ( $n > 1 ) { - for ( $i = 2; $i <= $n; $i++ ) { - for ( $j = 0; $j <= $n - 2; $j++ ) { - if ( $v[ $j ] < $v[ $j + 1 ] ) { - // swap values - $temp = $v[ $j ]; - $v[ $j ] = $v[ $j + 1 ]; - $v[ $j + 1 ] = $temp; - // Swap keys - $temp = $k[ $j ]; - $k[ $j ] = $k[ $j + 1 ]; - $k[ $j + 1 ] = $temp; - } - } - } - } - $accept_langs = array_combine( $k, $v ); - } + /** + * Filters the list of languages to use to match the browser preferences. + * + * @since 1.9.3 + * + * @param array $languages Array of PLL_Language objects. + */ + $languages = apply_filters( 'pll_languages_for_browser_preferences', $languages ); + + return $accept_langs->find_best_match( $languages ); } - $languages = $this->model->get_languages_list( array( 'hide_empty' => true ) ); // hides languages with no post - - /** - * Filter the list of languages to use to match the browser preferences - * - * @since 1.9.3 - * - * @param array $languages array of PLL_Language objects - */ - $languages = apply_filters( 'pll_languages_for_browser_preferences', $languages ); - - // looks through sorted list and use first one that matches our language list - foreach ( array_keys( $accept_langs ) as $accept_lang ) { - // first loop to match the exact locale - foreach ( $languages as $language ) { - if ( 0 === strcasecmp( $accept_lang, $language->get_locale( 'display' ) ) ) { - return $language->slug; - } - } - - // second loop to match the language set - foreach ( $languages as $language ) { - if ( 0 === stripos( $accept_lang, $language->slug ) || 0 === stripos( $language->get_locale( 'display' ), $accept_lang ) ) { - return $language->slug; - } - } - } return false; } /** - * returns the language according to browser preference or the default language + * Returns the preferred language + * either from the cookie if it's a returning visit + * or according to browser preference + * or the default language * * @since 0.1 * * @return object browser preferred language or default language */ public function get_preferred_language() { - // check first if the user was already browsing this site + $language = false; + $cookie = false; + if ( isset( $_COOKIE[ PLL_COOKIE ] ) ) { - return $this->model->get_language( $_COOKIE[ PLL_COOKIE ] ); + // Check first if the user was already browsing this site. + $language = sanitize_key( $_COOKIE[ PLL_COOKIE ] ); + $cookie = true; + } elseif ( $this->options['browser'] ) { + $language = $this->get_preferred_browser_language(); } /** @@ -201,38 +190,44 @@ abstract class PLL_Choose_Lang { * Polylang fallbacks to the default language * * @since 1.0 + * @since 2.7 Added $cookie parameter. * - * @param string $language preferred language code + * @param string|bool $language Preferred language code, false if none has been found. + * @param bool $cookie Whether the preferred language has been defined by the cookie. */ - $slug = apply_filters( 'pll_preferred_language', $this->options['browser'] ? $this->get_preferred_browser_language() : false ); + $slug = apply_filters( 'pll_preferred_language', $language, $cookie ); - // return default if there is no preferences in the browser or preferences does not match our languages or it is requested not to use the browser preference + // Return default if there is no preferences in the browser or preferences does not match our languages or it is requested not to use the browser preference return ( $lang = $this->model->get_language( $slug ) ) ? $lang : $this->model->get_language( $this->options['default_lang'] ); } /** - * sets the language when home page is requested + * Sets the language when home page is requested * * @since 1.2 + * + * @return void */ protected function home_language() { - // test referer in case PLL_COOKIE is set to false - // thanks to Ov3rfly http://wordpress.org/support/topic/enhance-feature-when-front-page-is-visited-set-language-according-to-browser - $language = $this->options['hide_default'] && ( ( isset( $_SERVER['HTTP_REFERER'] ) && in_array( parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_HOST ), $this->links_model->get_hosts() ) ) || ! $this->options['browser'] ) ? + // Test referer in case PLL_COOKIE is set to false. Since WP 3.6.1, wp_get_referer() validates the host which is exactly what we want + // Thanks to Ov3rfly http://wordpress.org/support/topic/enhance-feature-when-front-page-is-visited-set-language-according-to-browser + $language = $this->options['hide_default'] && ( wp_get_referer() || ! $this->options['browser'] ) ? $this->model->get_language( $this->options['default_lang'] ) : - $this->get_preferred_language(); // sets the language according to browser preference or default language + $this->get_preferred_language(); // Sets the language according to browser preference or default language $this->set_language( $language ); } /** - * to call when the home page has been requested - * make sure to call this after 'setup_theme' has been fired as we need $wp_query - * performs a redirection to the home page in the current language if needed + * To call when the home page has been requested + * Make sure to call this after 'setup_theme' has been fired as we need $wp_query + * Performs a redirection to the home page in the current language if needed * * @since 0.9 + * + * @return void */ public function home_requested() { - // we are already on the right page + // We are already on the right page if ( $this->options['default_lang'] == $this->curlang->slug && $this->options['hide_default'] ) { $this->set_curlang_in_query( $GLOBALS['wp_query'] ); @@ -243,47 +238,56 @@ abstract class PLL_Choose_Lang { */ do_action( 'pll_home_requested' ); } - // redirect to the home page in the right language - // test to avoid crash if get_home_url returns something wrong + // Redirect to the home page in the right language + // Test to avoid crash if get_home_url returns something wrong // FIXME why this happens? http://wordpress.org/support/topic/polylang-crashes-1 - // don't redirect if $_POST is not empty as it could break other plugins - // don't forget the query string which may be added by plugins - elseif ( is_string( $redirect = $this->curlang->home_url ) && empty( $_POST ) ) { - $redirect = empty( $_SERVER['QUERY_STRING'] ) ? $redirect : $redirect . ( $this->links_model->using_permalinks ? '?' : '&' ) . $_SERVER['QUERY_STRING']; + // Don't redirect if $_POST is not empty as it could break other plugins + elseif ( is_string( $redirect = $this->curlang->home_url ) && empty( $_POST ) ) { // phpcs:ignore WordPress.Security.NonceVerification + // Don't forget the query string which may be added by plugins + $query_string = wp_parse_url( pll_get_requested_url(), PHP_URL_QUERY ); + if ( ! empty( $query_string ) ) { + $redirect .= ( $this->links_model->using_permalinks ? '?' : '&' ) . $query_string; + } /** * When a visitor reaches the site home, Polylang redirects to the home page in the correct language. * This filter allows plugins to modify the redirected url or prevent this redirection + * /!\ this filter may be fired *before* the theme is loaded * * @since 1.1.1 * * @param string $redirect the url the visitor will be redirected to */ - if ( $redirect = apply_filters( 'pll_redirect_home', $redirect ) ) { - wp_redirect( $redirect ); + $redirect = apply_filters( 'pll_redirect_home', $redirect ); + if ( $redirect && wp_validate_redirect( $redirect ) ) { + $this->maybe_setcookie(); + header( 'Vary: Accept-Language' ); + wp_safe_redirect( $redirect, 302, POLYLANG ); exit; } } } /** - * set the language when posting a comment + * Set the language when posting a comment * * @since 0.8.4 * * @param int $post_id the post being commented + * @return void */ public function pre_comment_on_post( $post_id ) { $this->set_language( $this->model->post->get_language( $post_id ) ); } /** - * modifies some main query vars for home page and page for posts - * to enable one home page ( and one page for posts ) per language + * Modifies some main query vars for the home page and the page for posts + * to enable one home page (and one page for posts) per language. * * @since 1.2 * - * @param object $query instance of WP_Query + * @param WP_Query $query Instance of WP_Query. + * @return void */ public function parse_main_query( $query ) { if ( ! $query->is_main_query() ) { @@ -295,8 +299,8 @@ abstract class PLL_Choose_Lang { * * @since 1.8 * - * @param bool|object $lang false or language object - * @param object $query WP_Query object + * @param PLL_Language|false $lang Language object or false. + * @param WP_Query $query WP_Query object. */ if ( $lang = apply_filters( 'pll_set_language_from_query', false, $query ) ) { $this->set_language( $lang ); @@ -315,11 +319,12 @@ abstract class PLL_Choose_Lang { } /** - * Sets the current language in the query + * Sets the current language in the query. * * @since 2.2 * - * @param object $query + * @param WP_Query $query Instance of WP_Query. + * @return void */ protected function set_curlang_in_query( &$query ) { $pll_query = new PLL_Query( $query, $this->model ); diff --git a/wp-content/plugins/polylang/frontend/frontend-auto-translate.php b/wp-content/plugins/polylang/frontend/frontend-auto-translate.php index 766dbe5f..d14fbe15 100644 --- a/wp-content/plugins/polylang/frontend/frontend-auto-translate.php +++ b/wp-content/plugins/polylang/frontend/frontend-auto-translate.php @@ -1,4 +1,7 @@ model->get_translated_taxonomies(), get_taxonomies( array( '_builtin' => false ) ) ) as $taxonomy ) { $tax = get_taxonomy( $taxonomy ); $arr = array(); - if ( ! empty( $qv[ $tax->query_var ] ) ) { + if ( ! empty( $tax ) && ! empty( $qv[ $tax->query_var ] ) ) { $sep = strpos( $qv[ $tax->query_var ], ',' ) !== false ? ',' : '+'; // Two possible separators foreach ( explode( $sep, $qv[ $tax->query_var ] ) as $slug ) { $arr[] = $this->get_translated_term_by( 'slug', $slug, $taxonomy ); @@ -164,13 +178,15 @@ class PLL_Frontend_Auto_Translate { if ( ! empty( $post_types ) ) { // No function to get post by name except get_posts itself - $id = $wpdb->get_var( sprintf( " - SELECT ID from {$wpdb->posts} - WHERE {$wpdb->posts}.post_type IN ( '%s' ) - AND post_name='%s'", - implode( "', '", esc_sql( $post_types ) ), - esc_sql( $qv['name'] ) - ) ); + $id = $wpdb->get_var( + sprintf( + "SELECT ID from {$wpdb->posts} + WHERE {$wpdb->posts}.post_type IN ( '%s' ) + AND post_name='%s'", + implode( "', '", esc_sql( $post_types ) ), + esc_sql( $qv['name'] ) + ) + ); $qv['name'] = ( $id && ( $tr_id = $this->get_post( $id ) ) && $tr = get_post( $tr_id ) ) ? $tr->post_name : $qv['name']; } } @@ -183,12 +199,12 @@ class PLL_Frontend_Auto_Translate { // Array of post ids // post_parent__in & post_parent__not_in since WP 3.6 - foreach ( array( 'post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in' ) as $key ) { + foreach ( array( 'post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in' ) as $key ) { // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn $arr = array(); if ( ! empty( $qv[ $key ] ) ) { // post__in used by the 2 functions below // Useless to filter them as output is already in the right language and would result in performance loss - foreach ( debug_backtrace() as $trace ) { + foreach ( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) as $trace ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions if ( in_array( $trace['function'], array( 'wp_nav_menu', 'gallery_shortcode' ) ) ) { return; } @@ -214,6 +230,8 @@ class PLL_Frontend_Auto_Translate { */ public function get_terms_args( $args, $taxonomies ) { if ( ! isset( $args['lang'] ) && ! empty( $args['include'] ) && ( empty( $taxonomies ) || $this->model->is_translated_taxonomy( $taxonomies ) ) ) { + $arr = array(); + foreach ( wp_parse_id_list( $args['include'] ) as $id ) { $arr[] = ( $tr = $this->get_term( $id ) ) ? $tr : $id; } diff --git a/wp-content/plugins/polylang/frontend/frontend-filters-links.php b/wp-content/plugins/polylang/frontend/frontend-filters-links.php index cf7f0e85..1dbb0c05 100644 --- a/wp-content/plugins/polylang/frontend/frontend-filters-links.php +++ b/wp-content/plugins/polylang/frontend/frontend-filters-links.php @@ -1,4 +1,7 @@ ID}:{$link}"; @@ -120,14 +150,14 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { /** * Modifies filtered taxonomies ( post format like ) and translated taxonomies links - * and caches the result + * and caches the result. * * @since 0.7 * - * @param string $link - * @param object $term term object - * @param string $tax taxonomy name - * @return string modified link + * @param string $link Term link. + * @param WP_Term $term Term object. + * @param string $tax Taxonomy name. + * @return string Modified link. */ public function term_link( $link, $term, $tax ) { $cache_key = "term:{$term->term_id}:{$link}"; @@ -147,10 +177,26 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { return $_link; } + /** + * Modifies the post short link when using one domain or subdomain per language. + * + * @since 2.6.9 + * + * @param string $link Post permalink. + * @param int $post_id Post id. + * @return string Post permalink with the correct domain. + */ + public function shortlink( $link, $post_id ) { + $post_type = get_post_type( $post_id ); + return $this->model->is_translated_post_type( $post_type ) ? $this->links_model->switch_language_in_link( $link, $this->model->post->get_language( $post_id ) ) : $link; + } + /** * Outputs references to translated pages ( if exists ) in the html head section * * @since 0.1 + * + * @return void */ public function wp_head() { // Don't output anything on paged archives: see https://wordpress.org/support/topic/hreflang-on-page2 @@ -159,6 +205,8 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { return; } + $urls = array(); + // Google recommends to include self link https://support.google.com/webmasters/answer/189077?hl=en foreach ( $this->model->get_languages_list() as $language ) { if ( $url = $this->links->get_translation_url( $language ) ) { @@ -168,6 +216,8 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { // Outputs the section only if there are translations ( $urls always contains self link ) if ( ! empty( $urls ) && count( $urls ) > 1 ) { + $languages = array(); + $hreflangs = array(); // Prepare the list of languages to remove the country code foreach ( array_keys( $urls ) as $locale ) { @@ -217,10 +267,8 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { return $url; } - static $white_list, $black_list; // Avoid evaluating this at each function call - // We *want* to filter the home url in these cases - if ( empty( $white_list ) ) { + if ( empty( $this->white_list ) ) { // On Windows get_theme_root() mixes / and \ // We want only \ for the comparison with debug_backtrace $theme_root = get_theme_root(); @@ -236,16 +284,19 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { * * @param array $args */ - $white_list = apply_filters( 'pll_home_url_white_list', array( - array( 'file' => $theme_root ), - array( 'function' => 'wp_nav_menu' ), - array( 'function' => 'login_footer' ), - array( 'function' => 'get_custom_logo' ), - ) ); + $this->white_list = apply_filters( + 'pll_home_url_white_list', + array( + array( 'file' => $theme_root ), + array( 'function' => 'wp_nav_menu' ), + array( 'function' => 'login_footer' ), + array( 'function' => 'get_custom_logo' ), + ) + ); } // We don't want to filter the home url in these cases - if ( empty( $black_list ) ) { + if ( empty( $this->black_list ) ) { /** * Filter the black list of the Polylang 'home_url' filter @@ -257,24 +308,27 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { * * @param array $args */ - $black_list = apply_filters( 'pll_home_url_black_list', array( - array( 'file' => 'searchform.php' ), // Since WP 3.6 searchform.php is passed through get_search_form - array( 'function' => 'get_search_form' ), - ) ); + $this->black_list = apply_filters( + 'pll_home_url_black_list', + array( + array( 'file' => 'searchform.php' ), // Since WP 3.6 searchform.php is passed through get_search_form + array( 'function' => 'get_search_form' ), + ) + ); } - $traces = version_compare( PHP_VERSION, '5.2.5', '>=' ) ? debug_backtrace( false ) : debug_backtrace(); + $traces = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions unset( $traces[0], $traces[1] ); // We don't need the last 2 calls: this function + call_user_func_array (or apply_filters on PHP7+) foreach ( $traces as $trace ) { // Black list first - foreach ( $black_list as $v ) { + foreach ( $this->black_list as $v ) { if ( ( isset( $trace['file'], $v['file'] ) && false !== strpos( $trace['file'], $v['file'] ) ) || ( isset( $trace['function'], $v['function'] ) && $trace['function'] == $v['function'] ) ) { return $url; } } - foreach ( $white_list as $v ) { + foreach ( $this->white_list as $v ) { if ( ( isset( $trace['function'], $v['function'] ) && $trace['function'] == $v['function'] ) || ( isset( $trace['file'], $v['file'] ) && false !== strpos( $trace['file'], $v['file'] ) && in_array( $trace['function'], array( 'home_url', 'get_home_url', 'bloginfo', 'get_bloginfo' ) ) ) ) { $ok = true; @@ -299,66 +353,97 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { } /** - * If the language code is not in agreement with the language of the content - * redirects incoming links to the proper URL to avoid duplicate content + * If the language code is not in agreement with the language of the content, + * redirects incoming links to the proper URL to avoid duplicate content. * * @since 0.9.6 * - * @param string $requested_url optional - * @param bool $do_redirect optional, whether to perform the redirection or not - * @return string if redirect is not performed + * @param string $requested_url Optional, defaults to requested url. + * @param bool $do_redirect Optional, whether to perform the redirect or not. + * @return string|void Returns if redirect is not performed. */ public function check_canonical_url( $requested_url = '', $do_redirect = true ) { - global $wp_query, $post, $is_IIS; - - // Don't redirect in same cases as WP - if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || ( $is_IIS && ! iis7_supports_permalinks() ) ) { + // Don't redirect in same cases as WP. + if ( is_trackback() || is_search() || is_admin() || is_preview() || is_robots() || ( $GLOBALS['is_IIS'] && ! iis7_supports_permalinks() ) ) { return; } - // Don't redirect mysite.com/?attachment_id= to mysite.com/en/?attachment_id= - if ( 1 == $this->options['force_lang'] && is_attachment() && isset( $_GET['attachment_id'] ) ) { + // Don't redirect mysite.com/?attachment_id= to mysite.com/en/?attachment_id=. + if ( 1 == $this->options['force_lang'] && is_attachment() && isset( $_GET['attachment_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return; } - // If the default language code is not hidden and the static front page url contains the page name - // the customizer lands here and the code below would redirect to the list of posts + /* + * If the default language code is not hidden and the static front page url contains the page name, + * the customizer lands here and the code below would redirect to the list of posts. + */ if ( is_customize_preview() ) { return; } if ( empty( $requested_url ) ) { - $requested_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $requested_url = pll_get_requested_url(); } if ( is_single() || is_page() ) { - if ( isset( $post->ID ) && $this->model->is_translated_post_type( $post->post_type ) ) { + $post = get_post(); + if ( $post instanceof WP_Post && $this->model->is_translated_post_type( $post->post_type ) ) { $language = $this->model->post->get_language( (int) $post->ID ); } } + elseif ( $this->links_model->using_permalinks && is_category() && ! empty( $this->wp_query()->query['cat'] ) ) { + // When we receive a plain permaling with a cat query var, we need to redirect to the pretty permalink. + if ( $this->model->is_translated_taxonomy( $this->get_queried_taxonomy( $this->wp_query()->tax_query ) ) ) { + $term_id = $this->get_queried_term_id( $this->wp_query()->tax_query ); + $language = $this->model->term->get_language( $term_id ); + $redirect_url = $this->maybe_add_page_to_redirect_url( get_term_link( $term_id ) ); + } + } + elseif ( is_category() || is_tag() || is_tax() ) { - $obj = $wp_query->get_queried_object(); - if ( $this->model->is_translated_taxonomy( $obj->taxonomy ) ) { + // We need to switch the language when there is no language provided in a pretty permalink. + $obj = get_queried_object(); + if ( ! empty( $obj ) && $this->model->is_translated_taxonomy( $obj->taxonomy ) ) { $language = $this->model->term->get_language( (int) $obj->term_id ); } } - elseif ( $wp_query->is_posts_page ) { - $obj = $wp_query->get_queried_object(); - $language = $this->model->post->get_language( (int) $obj->ID ); + elseif ( is_404() && ! empty( $this->wp_query()->tax_query ) ) { + // When a wrong language is passed through a pretty permalink, we just need to switch the language. + if ( $this->model->is_translated_taxonomy( $this->get_queried_taxonomy( $this->wp_query()->tax_query ) ) ) { + $term_id = $this->get_queried_term_id( $this->wp_query()->tax_query ); + $language = $this->model->term->get_language( $term_id ); + } } - elseif ( is_404() && ! empty( $wp_query->query['page_id'] ) && $id = get_query_var( 'page_id' ) ) { - // Special case for page shortlinks when using subdomains or multiple domains - // Needed because redirect_canonical doesn't accept to change the domain name + elseif ( $this->links_model->using_permalinks && $this->wp_query()->is_posts_page && ! empty( $this->wp_query()->query['page_id'] ) && $id = get_query_var( 'page_id' ) ) { $language = $this->model->post->get_language( (int) $id ); + $redirect_url = $this->maybe_add_page_to_redirect_url( get_permalink( $id ) ); + } + + elseif ( $this->wp_query()->is_posts_page ) { + $obj = get_queried_object(); + if ( $obj instanceof WP_Post ) { + $language = $this->model->post->get_language( (int) $obj->ID ); + } + } + + if ( 3 === $this->options['force_lang'] ) { + $requested_host = wp_parse_url( $requested_url, PHP_URL_HOST ); + foreach ( $this->options['domains'] as $lang => $domain ) { + $host = wp_parse_url( $domain, PHP_URL_HOST ); + if ( 'www.' . $requested_host === $host || 'www.' . $host === $requested_host ) { + $language = $this->model->get_language( $lang ); + $redirect_url = str_replace( '://' . $requested_host, '://' . $host, $requested_url ); + } + } } if ( empty( $language ) ) { $language = $this->curlang; $redirect_url = $requested_url; - } else { + } elseif ( empty( $redirect_url ) ) { // First get the canonical url evaluated by WP // Workaround a WP bug which removes the port for some urls and get it back at second call to redirect_canonical $_redirect_url = ( ! $_redirect_url = redirect_canonical( $requested_url, false ) ) ? $requested_url : $_redirect_url; @@ -371,21 +456,102 @@ class PLL_Frontend_Filters_Links extends PLL_Filters_Links { } /** - * Filters the canonical url detected by Polylang + * Filters the canonical url detected by Polylang. * * @since 1.6 * - * @param bool|string $redirect_url false or the url to redirect to - * @param object $language the language detected + * @param string|false $redirect_url False or the url to redirect to. + * @param PLL_Language $language The language detected. */ $redirect_url = apply_filters( 'pll_check_canonical_url', $redirect_url, $language ); // The language is not correctly set so let's redirect to the correct url for this object - if ( $do_redirect && $redirect_url && $requested_url != $redirect_url ) { - wp_redirect( $redirect_url, 301 ); - exit; + if ( $do_redirect ) { + // Protect against chained redirects. + if ( $redirect_url && $requested_url != $redirect_url && $redirect_url === $this->check_canonical_url( $redirect_url, false ) && wp_validate_redirect( $redirect_url ) ) { + wp_safe_redirect( $redirect_url, 301, POLYLANG ); + exit; + } else { + return; + } } return $redirect_url; } + + /** + * Returns the link to the paged page if requested. + * + * @since 2.9 + * + * @param string $redirect_url The url to redirect to. + * @return string + */ + protected function maybe_add_page_to_redirect_url( $redirect_url ) { + if ( ! empty( $this->wp_query()->query['paged'] ) && $page = get_query_var( 'paged' ) ) { + $redirect_url = $this->links_model->add_paged_to_link( $redirect_url, $page ); + } + return $redirect_url; + } + + /** + * Returns the term_id of the requested term. + * + * @since 2.9 + * + * @param WP_Tax_Query $tax_query An instance of WP_Tax_Query. + * @return int|false + */ + protected function get_queried_term_id( $tax_query ) { + $queried_terms = $tax_query->queried_terms; + $taxonomy = $this->get_queried_taxonomy( $tax_query ); + + if ( ! is_array( $queried_terms[ $taxonomy ]['terms'] ) ) { + return false; + } + $field = $queried_terms[ $taxonomy ]['field']; + $term = reset( $queried_terms[ $taxonomy ]['terms'] ); + + // We can get a term_id when requesting a plain permalink, eg /?cat=1. + if ( 'term_id' === $field ) { + return $term; + } + + // We get a slug when requesting a pretty permalink with the wrong language. + $args = array( + 'lang' => '', + 'taxonomy' => $taxonomy, + $field => $term, + 'hide_empty' => false, + 'fields' => 'ids', + ); + $terms = get_terms( $args ); + return reset( $terms ); + } + + /** + * Find the taxonomy being queried. + * + * @since 2.9 + * + * @param WP_Tax_Query $tax_query An instance of WP_Tax_Query. + * @return string A taxonomy slug + */ + protected function get_queried_taxonomy( $tax_query ) { + $queried_terms = $tax_query->queried_terms; + unset( $queried_terms['language'] ); + + return key( $queried_terms ); + } + + /** + * Returns the Global WordPress WP_Query object. + * + * @since 3.0 + * + * @return WP_Query + */ + protected function wp_query() { + return $GLOBALS['wp_query']; + } } diff --git a/wp-content/plugins/polylang/frontend/frontend-filters-search.php b/wp-content/plugins/polylang/frontend/frontend-filters-search.php index 73fc8f02..a8ebeb13 100644 --- a/wp-content/plugins/polylang/frontend/frontend-filters-search.php +++ b/wp-content/plugins/polylang/frontend/frontend-filters-search.php @@ -1,15 +1,30 @@ links_model = &$polylang->links_model; $this->curlang = &$polylang->curlang; - // adds the language information in the search form - // low priority in case the search form is created using the same filter as described in http://codex.wordpress.org/Function_Reference/get_search_form + // Adds the language information in the search form + // Low priority in case the search form is created using the same filter as described in http://codex.wordpress.org/Function_Reference/get_search_form add_filter( 'get_search_form', array( $this, 'get_search_form' ), 99 ); - // adds the language information in admin bar search form + // Adds the language information in admin bar search form add_action( 'add_admin_bar_menus', array( $this, 'add_admin_bar_menus' ) ); - // adds javascript at the end of the document - // was used for WP < 3.6. kept just in case + // Adds javascript at the end of the document + // Was used for WP < 3.6. kept just in case if ( defined( 'PLL_SEARCH_FORM_JS' ) && PLL_SEARCH_FORM_JS ) { add_action( 'wp_footer', array( $this, 'wp_print_footer_scripts' ) ); } } /** - * adds the language information in the search form - * does not work if searchform.php ( prior to WP 3.6 ) is used or if the search form is hardcoded in another template file + * Adds the language information in the search form. + * + * Does not work if searchform.php ( prior to WP 3.6 ) is used or if the search form is hardcoded in another template file * * @since 0.1 * - * @param string $form search form - * @return string modified search form + * @param string $form The search form HTML. + * @return string Modified search form. */ public function get_search_form( $form ) { if ( $form ) { if ( $this->links_model->using_permalinks ) { - // take care to modify only the url in the
tag - preg_match( '##', $form, $matches ); + // Take care to modify only the url in the tag. + preg_match( '##', $form, $matches ); $old = reset( $matches ); - $new = preg_replace( '#' . esc_url( $this->links_model->home ) . '\/?#', esc_url( $this->curlang->search_url ), $old ); + // Replace action attribute (a text with no space and no closing tag within double quotes or simple quotes or without quotes). + $new = preg_replace( '#\saction=("[^"\r\n]+"|\'[^\'\r\n]+\'|[^\'"][^>\s]+)#', ' action="' . esc_url( $this->curlang->search_url ) . '"', $old ); $form = str_replace( $old, $new, $form ); - } - else { + } else { $form = str_replace( '', '', $form ); } } @@ -60,47 +76,57 @@ class PLL_Frontend_Filters_Search { } /** - * adds the language information in admin bar search form + * Adds the language information in admin bar search form * * @since 1.2 + * + * @return void */ - function add_admin_bar_menus() { + public function add_admin_bar_menus() { remove_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 ); add_action( 'admin_bar_menu', array( $this, 'admin_bar_search_menu' ), 4 ); } /** - * rewrites the admin bar search form to pass our get_search form filter. See #21342 - * code base is WP 4.3.1 + * Rewrites the admin bar search form to pass our get_search_form filter. See #21342. + * Code last checked: WP 5.4.1. * * @since 0.9 * - * @param object $wp_admin_bar + * @param WP_Admin_Bar $wp_admin_bar + * @return void */ public function admin_bar_search_menu( $wp_admin_bar ) { $form = '
'; $form .= ''; - $form .= ''; - $form .= ''; + $form .= ''; + $form .= ''; $form .= '
'; - $wp_admin_bar->add_menu( array( - 'parent' => 'top-secondary', - 'id' => 'search', - 'title' => $this->get_search_form( $form ), // pass the get_search_form filter - 'meta' => array( 'class' => 'admin-bar-search', 'tabindex' => -1 ), - ) ); + $wp_admin_bar->add_node( + array( + 'parent' => 'top-secondary', + 'id' => 'search', + 'title' => $this->get_search_form( $form ), // Pass the get_search_form filter. + 'meta' => array( + 'class' => 'admin-bar-search', + 'tabindex' => -1, + ), + ) + ); } /** - * allows modifying the search form if it does not pass get_search_form + * Allows modifying the search form if it does not pass get_search_form * * @since 0.1 + * + * @return void */ public function wp_print_footer_scripts() { - // don't use directly e[0] just in case there is somewhere else an element named 's' - // check before if the hidden input has not already been introduced by get_search_form ( FIXME: is there a way to improve this ) ? - // thanks to AndyDeGroo for improving the code for compatibility with old browsers + // Don't use directly e[0] just in case there is somewhere else an element named 's' + // Check before if the hidden input has not already been introduced by get_search_form ( FIXME: is there a way to improve this ) ? + // Thanks to AndyDeGroo for improving the code for compatibility with old browsers // http://wordpress.org/support/topic/development-of-polylang-version-08?replies=6#post-2645559 $lang = esc_js( $this->curlang->slug ); $js = "//"; - echo ''; + echo ''; // phpcs:ignore WordPress.Security.EscapeOutput } } diff --git a/wp-content/plugins/polylang/frontend/frontend-filters-widgets.php b/wp-content/plugins/polylang/frontend/frontend-filters-widgets.php new file mode 100644 index 00000000..e812a3bc --- /dev/null +++ b/wp-content/plugins/polylang/frontend/frontend-filters-widgets.php @@ -0,0 +1,155 @@ +curlang = &$polylang->curlang; + $this->cache = new PLL_Cache(); + + add_filter( 'sidebars_widgets', array( $this, 'sidebars_widgets' ) ); + } + + /** + * Remove widgets from sidebars if they are not visible in the current language + * Needed to allow is_active_sidebar() to return false if all widgets are not for the current language. See #54 + * + * @since 2.1 + * @since 2.4 The result is cached as the function can be very expensive in case there are a lot of widgets + * + * @param array $sidebars_widgets An associative array of sidebars and their widgets + * @return array + */ + public function sidebars_widgets( $sidebars_widgets ) { + global $wp_registered_widgets; + + if ( empty( $wp_registered_widgets ) ) { + return $sidebars_widgets; + } + + $cache_key = md5( maybe_serialize( $sidebars_widgets ) ); + $_sidebars_widgets = $this->cache->get( "sidebars_widgets_{$cache_key}" ); + + if ( false !== $_sidebars_widgets ) { + return $_sidebars_widgets; + } + + $sidebars_widgets = $this->filter_widgets_sidebars( $sidebars_widgets, $wp_registered_widgets ); + + $this->cache->set( "sidebars_widgets_{$cache_key}", $sidebars_widgets ); + + return $sidebars_widgets; + } + + /** + * Method that handles the removal of widgets in the sidebars depending on their display language. + * + * @since 3.1 + * + * @param array $widget_data An array containing the widget data + * @param array $sidebars_widgets An associative array of sidebars and their widgets + * @param string $sidebar Sidebar name + * @param int $key Widget number + * @return array An associative array of sidebars and their widgets + */ + public function handle_widget_in_sidebar_callback( $widget_data, $sidebars_widgets, $sidebar, $key ) { + // Remove the widget if not visible in the current language + if ( ! empty( $widget_data['settings'][ $widget_data['number'] ]['pll_lang'] ) && $widget_data['settings'][ $widget_data['number'] ]['pll_lang'] !== $this->curlang->slug ) { + unset( $sidebars_widgets[ $sidebar ][ $key ] ); + } + return $sidebars_widgets; + } + + /** + * Browse the widgets sidebars and sort the ones that should be displayed or not. + * + * @since 3.1 + * + * @param array $sidebars_widgets An associative array of sidebars and their widgets + * @param array $wp_registered_widgets Array of all registered widgets. + * @return array An associative array of sidebars and their widgets + */ + public function filter_widgets_sidebars( $sidebars_widgets, $wp_registered_widgets ) { + foreach ( $sidebars_widgets as $sidebar => $widgets ) { + if ( 'wp_inactive_widgets' === $sidebar || empty( $widgets ) ) { + continue; + } + + foreach ( $widgets as $key => $widget ) { + if ( ! $this->is_widget_object( $wp_registered_widgets, $widget ) ) { + continue; + } + + $widget_data = $this->get_widget_data( $wp_registered_widgets, $widget ); + + $sidebars_widgets = $this->handle_widget_in_sidebar_callback( $widget_data, $sidebars_widgets, $sidebar, $key ); + } + } + return $sidebars_widgets; + } + + /** + * Test if the widget is an object. + * + * @since 3.1 + * + * @param array $wp_registered_widgets Array of all registered widgets. + * @param string $widget String that identifies the widget. + * @return bool True if object, false otherwise. + */ + protected function is_widget_object( $wp_registered_widgets, $widget ) { + // Nothing can be done if the widget is created using pre WP2.8 API :( + // There is no object, so we can't access it to get the widget options + return isset( $wp_registered_widgets[ $widget ]['callback'] ) && + is_array( $wp_registered_widgets[ $widget ]['callback'] ) && + isset( $wp_registered_widgets[ $widget ]['callback'][0] ) && + is_object( $wp_registered_widgets[ $widget ]['callback'][0] ) && + method_exists( $wp_registered_widgets[ $widget ]['callback'][0], 'get_settings' ); + } + + /** + * Get widgets settings and number. + * + * @since 3.1 + * + * @param array $wp_registered_widgets Array of all registered widgets. + * @param string $widget String that identifies the widget. + * @return array An array containing the widget settings and number. + */ + protected function get_widget_data( $wp_registered_widgets, $widget ) { + $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings(); + $number = $wp_registered_widgets[ $widget ]['params'][0]['number']; + + return array( + 'settings' => $widget_settings, + 'number' => $number, + ); + } +} diff --git a/wp-content/plugins/polylang/frontend/frontend-filters.php b/wp-content/plugins/polylang/frontend/frontend-filters.php index 865cc0bb..40219a7d 100644 --- a/wp-content/plugins/polylang/frontend/frontend-filters.php +++ b/wp-content/plugins/polylang/frontend/frontend-filters.php @@ -1,4 +1,7 @@ options['media_support'] ) { add_filter( 'widget_media_image_instance', array( $this, 'widget_media_instance' ), 1 ); // Since WP 4.8 } // Strings translation ( must be applied before WordPress applies its default formatting filters ) - foreach ( array( 'widget_text', 'widget_title', 'option_blogname', 'option_blogdescription', 'option_date_format', 'option_time_format' ) as $filter ) { + foreach ( array( 'widget_text', 'widget_title' ) as $filter ) { add_filter( $filter, 'pll__', 1 ); } // Translates biography add_filter( 'get_user_metadata', array( $this, 'get_user_metadata' ), 10, 4 ); - // Set posts and terms language when created from frontend ( ex with P2 theme ) - add_action( 'save_post', array( $this, 'save_post' ), 200, 2 ); - add_action( 'create_term', array( $this, 'save_term' ), 10, 3 ); - add_action( 'edit_term', array( $this, 'save_term' ), 10, 3 ); - - if ( $this->options['media_support'] ) { - add_action( 'add_attachment', array( $this, 'set_default_language' ) ); - } - - // Support theme customizer - // FIXME of course does not work if 'transport' is set to 'postMessage' - if ( isset( $_POST['wp_customize'], $_POST['customized'] ) ) { - add_filter( 'pre_option_blogname', 'pll__', 20 ); - add_filter( 'pre_option_blogdescription', 'pll__', 20 ); - } - - // FIXME test get_user_locale for backward compatibility with WP < 4.7 - if ( Polylang::is_ajax_on_front() && function_exists( 'get_user_locale' ) ) { + if ( Polylang::is_ajax_on_front() ) { add_filter( 'load_textdomain_mofile', array( $this, 'load_textdomain_mofile' ) ); } } @@ -79,25 +54,25 @@ class PLL_Frontend_Filters extends PLL_Filters { * * @since 0.1 * - * @param string $locale * @return string */ - public function get_locale( $locale ) { + public function get_locale() { return $this->curlang->locale; } /** - * Filters sticky posts by current language + * Filters sticky posts by current language. * * @since 0.8 * - * @param array $posts list of sticky posts ids - * @return array modified list of sticky posts ids + * @param int[] $posts List of sticky posts ids. + * @return int[] Modified list of sticky posts ids */ public function option_sticky_posts( $posts ) { global $wpdb; - if ( $this->curlang && ! empty( $posts ) ) { + // Do not filter sticky posts on REST requests as $this->curlang is *not* the 'lang' parameter set in the request + if ( ! defined( 'REST_REQUEST' ) && ! empty( $this->curlang ) && ! empty( $posts ) ) { $_posts = wp_cache_get( 'sticky_posts', 'options' ); // This option is usually cached in 'all_options' by WP if ( empty( $_posts ) || ! is_array( $_posts[ $this->curlang->term_taxonomy_id ] ) ) { @@ -108,10 +83,11 @@ class PLL_Frontend_Filters extends PLL_Filters { $_posts = array_fill_keys( $languages, array() ); // Init with empty arrays $languages = implode( ',', $languages ); + // PHPCS:ignore WordPress.DB.PreparedSQL $relations = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM {$wpdb->term_relationships} WHERE object_id IN ({$posts}) AND term_taxonomy_id IN ({$languages})" ); foreach ( $relations as $relation ) { - $_posts[ $relation->term_taxonomy_id ][] = $relation->object_id; + $_posts[ $relation->term_taxonomy_id ][] = (int) $relation->object_id; } wp_cache_add( 'sticky_posts', $_posts, 'options' ); } @@ -122,72 +98,6 @@ class PLL_Frontend_Filters extends PLL_Filters { return $posts; } - /** - * Adds language dependent cache domain when querying terms - * useful as the 'lang' parameter is not included in cache key by WordPress - * - * @since 1.3 - * - * @param array $args - * @return array - */ - public function get_terms_args( $args ) { - if ( isset( $args['lang'] ) ) { - $lang = $args['lang']; - } elseif ( isset( $this->tax_query_lang ) ) { - $lang = $args['lang'] = empty( $this->tax_query_lang ) && ! empty( $args['slug'] ) ? $this->curlang->slug : $this->tax_query_lang; - } else { - $lang = $this->curlang->slug; - } - - $key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $lang ); - $args['cache_domain'] = empty( $args['cache_domain'] ) ? 'pll' . $key : $args['cache_domain'] . $key; - return $args; - } - - /** - * Filters categories and post tags by language when needed - * - * @since 0.2 - * - * @param array $clauses sql clauses - * @param array $taxonomies - * @param array $args get_terms arguments - * @return array modified sql clauses - */ - public function terms_clauses( $clauses, $taxonomies, $args ) { - // Does nothing except on taxonomies which are filterable - // Since WP 4.7, make sure not to filter wp_get_object_terms() - if ( ! $this->model->is_translated_taxonomy( $taxonomies ) || ! empty( $args['object_ids'] ) ) { - return $clauses; - } - - // Adds our clauses to filter by language - return $this->model->terms_clauses( $clauses, isset( $args['lang'] ) ? $args['lang'] : $this->curlang ); - } - - /** - * Sets the WP_Term_Query language when doing a WP_Query - * Needed since WP 4.9 - * - * @since 2.3.2 - * - * @param object $query WP_Query object - */ - public function set_tax_query_lang( $query ) { - $this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : ''; - } - - /** - * Removes the WP_Term_Query language filter for WP_Query - * Needed since WP 4.9 - * - * @since 2.3.2 - */ - public function unset_tax_query_lang() { - unset( $this->tax_query_lang ); - } - /** * Modifies the sql request for wp_get_archives to filter by the current language * @@ -217,54 +127,17 @@ class PLL_Frontend_Filters extends PLL_Filters { /** * Filters the widgets according to the current language * Don't display if a language filter is set and this is not the current one + * Needed for {@see https://developer.wordpress.org/reference/functions/the_widget/ the_widget()}. * * @since 0.3 * - * @param array $instance widget settings - * @param object $widget WP_Widget object + * @param array $instance Widget settings * @return bool|array false if we hide the widget, unmodified $instance otherwise */ - public function widget_display_callback( $instance, $widget ) { + public function widget_display_callback( $instance ) { return ! empty( $instance['pll_lang'] ) && $instance['pll_lang'] != $this->curlang->slug ? false : $instance; } - /** - * Remove widgets from sidebars if they are not visible in the current language - * Needed to allow is_active_sidebar() to return false if all widgets are not for the current language. See #54 - * - * @since 2.1 - * - * @param array $sidebars_widgets An associative array of sidebars and their widgets - * @return array - */ - public function sidebars_widgets( $sidebars_widgets ) { - global $wp_registered_widgets; - - foreach ( $sidebars_widgets as $sidebar => $widgets ) { - if ( 'wp_inactive_widgets' == $sidebar || empty( $widgets ) ) { - continue; - } - - foreach ( $widgets as $key => $widget ) { - // Nothing can be done if the widget is created using pre WP2.8 API :( - // There is no object, so we can't access it to get the widget options - if ( ! isset( $wp_registered_widgets[ $widget ]['callback'] ) || ! is_array( $wp_registered_widgets[ $widget ]['callback'] ) || ! isset( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! is_object( $wp_registered_widgets[ $widget ]['callback'][0] ) || ! method_exists( $wp_registered_widgets[ $widget ]['callback'][0], 'get_settings' ) ) { - continue; - } - - $widget_settings = $wp_registered_widgets[ $widget ]['callback'][0]->get_settings(); - $number = $wp_registered_widgets[ $widget ]['params'][0]['number']; - - // Remove the widget if not visible in the current language - if ( ! empty( $widget_settings[ $number ]['pll_lang'] ) && $widget_settings[ $number ]['pll_lang'] !== $this->curlang->slug ) { - unset( $sidebars_widgets[ $sidebar ][ $key ] ); - } - } - } - - return $sidebars_widgets; - } - /** * Translates media in media widgets * @@ -308,64 +181,6 @@ class PLL_Frontend_Filters extends PLL_Filters { return 'description' === $meta_key && $this->curlang->slug !== $this->options['default_lang'] ? get_user_meta( $id, 'description_' . $this->curlang->slug, $single ) : $null; } - /** - * Allows to set a language by default for posts if it has no language yet - * - * @since 1.5.4 - * - * @param int $post_id - */ - public function set_default_language( $post_id ) { - if ( ! $this->model->post->get_language( $post_id ) ) { - if ( isset( $_REQUEST['lang'] ) ) { - $this->model->post->set_language( $post_id, $_REQUEST['lang'] ); - } elseif ( ( $parent_id = wp_get_post_parent_id( $post_id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) { - $this->model->post->set_language( $post_id, $parent_lang ); - } else { - $this->model->post->set_language( $post_id, $this->curlang ); - } - } - } - - /** - * Called when a post ( or page ) is saved, published or updated - * Does nothing except on post types which are filterable - * Sets the language but does not allow to modify it - * - * @since 1.1 - * - * @param int $post_id - * @param object $post - */ - public function save_post( $post_id, $post ) { - if ( $this->model->is_translated_post_type( $post->post_type ) ) { - $this->set_default_language( $post_id ); - } - } - - /** - * Called when a category or post tag is created or edited - * Does nothing except on taxonomies which are filterable - * Sets the language but does not allow to modify it - * - * @since 1.1 - * - * @param int $term_id - * @param int $tt_id Term taxonomy id - * @param string $taxonomy - */ - public function save_term( $term_id, $tt_id, $taxonomy ) { - if ( $this->model->is_translated_taxonomy( $taxonomy ) && ! $this->model->term->get_language( $term_id ) ) { - if ( isset( $_REQUEST['lang'] ) ) { - $this->model->term->set_language( $term_id, $_REQUEST['lang'] ); - } elseif ( ( $term = get_term( $term_id, $taxonomy ) ) && ! empty( $term->parent ) && $parent_lang = $this->model->term->get_language( $term->parent ) ) { - $this->model->term->set_language( $term_id, $parent_lang ); - } else { - $this->model->term->set_language( $term_id, $this->curlang ); - } - } - } - /** * Filters the translation files to load when doing ajax on front * This is needed because WP the language files associated to the user locale when a user is logged in diff --git a/wp-content/plugins/polylang/frontend/frontend-links.php b/wp-content/plugins/polylang/frontend/frontend-links.php index 85a9c981..a60578da 100644 --- a/wp-content/plugins/polylang/frontend/frontend-links.php +++ b/wp-content/plugins/polylang/frontend/frontend-links.php @@ -1,4 +1,7 @@ get_queried_object_id(); /** - * Filter the translation url before Polylang attempts to find one - * Internally used by Polylang for the static front page and posts page + * Filters the translation url before Polylang attempts to find one. + * Internally used by Polylang for the static front page and posts page. * * @since 1.8 * - * @param string $url Empty or the url of the translation of teh current page - * @param object $language Language of the translation - * @param int $queried_object_id Queried object id + * @param string $url Empty or the url of the translation of teh current page. + * @param PLL_Language $language Language of the translation. + * @param int $queried_object_id Queried object id. */ if ( ! $url = apply_filters( 'pll_pre_translation_url', '', $language, $queried_object_id ) ) { $qv = $wp_query->query_vars; - $hide = $this->options['default_lang'] == $language->slug && $this->options['hide_default']; // Post and attachment - if ( is_single() && ( $this->options['media_support'] || ! is_attachment() ) && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->current_user_can_read( $id ) ) { + if ( is_single() && ( $this->options['media_support'] || ! is_attachment() ) && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->model->post->current_user_can_read( $id ) ) { $url = get_permalink( $id ); } // Page - elseif ( is_page() && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->current_user_can_read( $id ) ) { + elseif ( is_page() && ( $id = $this->model->post->get( $queried_object_id, $language ) ) && $this->model->post->current_user_can_read( $id ) ) { $url = get_page_link( $id ); } @@ -96,7 +109,7 @@ class PLL_Frontend_Links extends PLL_Links { $lang = $this->model->term->get_language( $term->term_id ); if ( ! $lang || $language->slug == $lang->slug ) { - $url = wpcom_vip_get_term_link( $term, $term->taxonomy ); // Self link + $url = get_term_link( $term, $term->taxonomy ); // Self link } elseif ( $tr_id = $this->model->term->get_translation( $term->term_id, $language ) ) { @@ -115,7 +128,7 @@ class PLL_Frontend_Links extends PLL_Links { * @param array $args Arguments used to evaluated the number of posts in the archive */ if ( ! apply_filters( 'pll_hide_archive_translation_url', ! $count, $language->slug, array( 'taxonomy' => $term->taxonomy ) ) ) { - $url = wpcom_vip_get_term_link( $tr_term, $term->taxonomy ); + $url = get_term_link( $tr_term, $term->taxonomy ); } } } @@ -181,7 +194,7 @@ class PLL_Frontend_Links extends PLL_Links { * @return string */ public function get_archive_url( $language ) { - $url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $url = pll_get_requested_url(); $url = $this->links_model->switch_language_in_link( $url, $language ); $url = $this->links_model->remove_paged_from_link( $url ); @@ -197,12 +210,12 @@ class PLL_Frontend_Links extends PLL_Links { } /** - * Returns the home url in the right language + * Returns the home url in the right language. * * @since 0.1 * - * @param object $language Optional, defaults to current language - * @param bool $is_search Optional, whether we need the home url for a search form, defaults to false + * @param PLL_Language|string $language Optional, defaults to current language. + * @param bool $is_search Optional, whether we need the home url for a search form, defaults to false. */ public function get_home_url( $language = '', $is_search = false ) { if ( empty( $language ) ) { diff --git a/wp-content/plugins/polylang/frontend/frontend-nav-menu.php b/wp-content/plugins/polylang/frontend/frontend-nav-menu.php index 30158c34..4d6db479 100644 --- a/wp-content/plugins/polylang/frontend/frontend-nav-menu.php +++ b/wp-content/plugins/polylang/frontend/frontend-nav-menu.php @@ -1,4 +1,7 @@ $item ) { + foreach ( $items as $item ) { if ( $options = get_post_meta( $item->ID, '_pll_menu_item', true ) ) { - $i = 0; + /** This filter is documented in include/switcher.php */ + $options = apply_filters( 'pll_the_languages_args', $options ); // Honor the filter here for 'show_flags', 'show_names' and 'dropdown'. - $switcher = new PLL_Switcher; + $switcher = new PLL_Switcher(); $args = array_merge( array( 'raw' => 1 ), $options ); + + /** @var array */ $the_languages = $switcher->the_languages( PLL()->links, $args ); // parent item for dropdown if ( ! empty( $options['dropdown'] ) ) { - $item->title = $this->get_item_title( $this->curlang->flag, $this->curlang->name, $options ); + $name = isset( $options['display_names_as'] ) && 'slug' === $options['display_names_as'] ? $this->curlang->slug : $this->curlang->name; + $item->title = $this->get_item_title( $this->curlang->get_display_flag(), $name, $options ); $item->attr_title = ''; $item->classes = array( 'pll-parent-menu-item' ); + $item->menu_order += $offset; $new_items[] = $item; $offset++; } + $i = 0; // for incrementation of menu order only in case of dropdown foreach ( $the_languages as $lang ) { + $i++; $lang_item = clone $item; $lang_item->ID = $lang_item->ID . '-' . $lang['slug']; // A unique ID $lang_item->title = $this->get_item_title( $lang['flag'], $lang['name'], $options ); @@ -117,14 +133,17 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { $lang_item->url = $lang['url']; $lang_item->lang = $lang['locale']; // Save this for use in nav_menu_link_attributes $lang_item->classes = $lang['classes']; - $lang_item->menu_order += $offset + $i++; if ( ! empty( $options['dropdown'] ) ) { + $lang_item->menu_order = $item->menu_order + $i; $lang_item->menu_item_parent = $item->db_id; $lang_item->db_id = 0; // to avoid recursion + } else { + $lang_item->menu_order += $offset; } $new_items[] = $lang_item; + $offset++; } - $offset += $i - 1; + $offset--; } else { $item->menu_order += $offset; $new_items[] = $item; @@ -134,12 +153,12 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { } /** - * Returns the ancestors of a menu item + * Returns the ancestors of a menu item. * * @since 1.1.1 * - * @param object $item - * @return array ancestors ids + * @param stdClass $item Menu item. + * @return int[] Ancestors ids. */ public function get_ancestors( $item ) { $ids = array(); @@ -151,12 +170,12 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { } /** - * Removes current-menu and current-menu-ancestor classes to lang switcher when not on the home page + * Removes current-menu and current-menu-ancestor classes to lang switcher when not on the home page. * * @since 1.1.1 * - * @param array $items - * @return array modified menu items + * @param stdClass[] $items An array of menu items. + * @return stdClass[] */ public function wp_nav_menu_objects( $items ) { $r_ids = $k_ids = array(); @@ -185,14 +204,14 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { } /** - * Adds hreflang attribute for the language switcher menu items - * available since WP 3.6 + * Adds hreflang attribute for the language switcher menu items. + * available since WP 3.6. * * @since 1.1 * - * @param array $atts - * @param object $item - * @return array modified $atts + * @param string[] $atts HTML attributes applied to the menu item's `` element. + * @param stdClass $item Menu item. + * @return string[] Modified attributes. */ public function nav_menu_link_attributes( $atts, $item ) { if ( isset( $item->lang ) ) { @@ -215,25 +234,21 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { // First get multilingual menu locations from DB $theme = get_option( 'stylesheet' ); - foreach ( $menus as $loc => $menu ) { + foreach ( array_keys( $menus ) as $loc ) { $menus[ $loc ] = empty( $this->options['nav_menus'][ $theme ][ $loc ][ $this->curlang->slug ] ) ? 0 : $this->options['nav_menus'][ $theme ][ $loc ][ $this->curlang->slug ]; } // Support for theme customizer - // Let's look for multilingual menu locations directly in $_POST as there are not in customizer object - if ( isset( $_POST['wp_customize'], $_POST['customized'] ) ) { - $customized = json_decode( wp_unslash( $_POST['customized'] ) ); - - if ( is_object( $customized ) ) { - foreach ( $customized as $key => $c ) { - if ( false !== strpos( $key, 'nav_menu_locations[' ) ) { - $loc = substr( trim( $key, ']' ), 19 ); - $infos = $this->explode_location( $loc ); - if ( $infos['lang'] == $this->curlang->slug ) { - $menus[ $infos['location'] ] = $c; - } elseif ( $this->curlang->slug == $this->options['default_lang'] ) { - $menus[ $loc ] = $c; - } + if ( is_customize_preview() ) { + global $wp_customize; + foreach ( $wp_customize->unsanitized_post_values() as $key => $value ) { + if ( false !== strpos( $key, 'nav_menu_locations[' ) ) { + $loc = substr( trim( $key, ']' ), 19 ); + $infos = $this->explode_location( $loc ); + if ( $infos['lang'] === $this->curlang->slug ) { + $menus[ $infos['location'] ] = (int) $value; + } elseif ( $this->curlang->slug === $this->options['default_lang'] ) { + $menus[ $loc ] = (int) $value; } } } @@ -275,7 +290,7 @@ class PLL_Frontend_Nav_Menu extends PLL_Nav_Menu { if ( ! $menu && ! $args['theme_location'] ) { $menus = wp_get_nav_menus(); foreach ( $menus as $menu_maybe ) { - if ( $menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { + if ( wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) ) ) { foreach ( $this->options['nav_menus'][ $theme ] as $menus ) { if ( in_array( $menu_maybe->term_id, $menus ) && ! empty( $menus[ $this->curlang->slug ] ) ) { $args['menu'] = $menus[ $this->curlang->slug ]; diff --git a/wp-content/plugins/polylang/frontend/frontend-static-pages.php b/wp-content/plugins/polylang/frontend/frontend-static-pages.php index ebb9a702..4f3d5ed5 100644 --- a/wp-content/plugins/polylang/frontend/frontend-static-pages.php +++ b/wp-content/plugins/polylang/frontend/frontend-static-pages.php @@ -1,4 +1,7 @@ curlang->page_on_front ); @@ -71,8 +89,8 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * @return int */ public function translate_page_on_front( $v ) { - // returns the current page if there is no translation to avoid ugly notices - return isset( $this->curlang->page_on_front ) ? $this->curlang->page_on_front : $v; + // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache + return isset( $this->curlang->page_on_front ) && ( $this->curlang->page_on_front ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_on_front : $v; } /** @@ -81,16 +99,14 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * @since 0.1 * * @param string $redirect_url - * @param string $requested_url * @return bool|string modified url, false if redirection is canceled */ - public function redirect_canonical( $redirect_url, $requested_url ) { - global $wp_query; - if ( is_page() && ! is_feed() && isset( $wp_query->queried_object ) && $wp_query->queried_object->ID == $this->curlang->page_on_front ) { - $url = is_paged() ? $this->links_model->add_paged_to_link( $this->links->get_home_url(), $wp_query->query_vars['page'] ) : $this->links->get_home_url(); + public function redirect_canonical( $redirect_url ) { + if ( is_page() && ! is_feed() && get_queried_object_id() == $this->curlang->page_on_front ) { + $url = is_paged() ? $this->links_model->add_paged_to_link( $this->links->get_home_url(), get_query_var( 'page' ) ) : $this->links->get_home_url(); // Don't forget additional query vars - $query = parse_url( $redirect_url, PHP_URL_QUERY ); + $query = wp_parse_url( $redirect_url, PHP_URL_QUERY ); if ( ! empty( $query ) ) { parse_str( $query, $query_vars ); $query_vars = rawurlencode_deep( $query_vars ); // WP encodes query vars values @@ -104,14 +120,14 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { } /** - * Translates the url of the page on front and page for posts + * Translates the url of the page on front and page for posts. * * @since 1.8 * - * @param string $url not used - * @param object $language language in which we want the translation - * @param int $queried_object_id id of the queried object - * @return string + * @param string $url Not used. + * @param PLL_Language $language Language in which we want the translation. + * @param int $queried_object_id Id of the queried object. + * @return string The translation url. */ public function pll_pre_translation_url( $url, $language, $queried_object_id ) { if ( ! empty( $queried_object_id ) ) { @@ -130,7 +146,7 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { } /** - * Handles canonical redirection if we are on a static front page + * Prevents canonical redirection if we are on a static front page * * @since 1.8 * @@ -138,24 +154,7 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * @return bool|string */ public function pll_check_canonical_url( $redirect_url ) { - if ( ! empty( $this->curlang->page_on_front ) && is_page( $this->curlang->page_on_front ) ) { - // Redirect www.mysite.fr to mysite.fr - if ( 3 === $this->options['force_lang'] ) { - foreach ( $this->options['domains'] as $lang => $domain ) { - $host = parse_url( $domain, PHP_URL_HOST ); - if ( 'www.' . $_SERVER['HTTP_HOST'] === $host || 'www.' . $host === $_SERVER['HTTP_HOST'] ) { - $language = $this->model->get_language( $lang ); - return $language->home_url; - } - } - } - - // Prevents canonical redirection made by WP from secondary language to main language - if ( $this->options['redirect_lang'] ) { - return false; - } - } - return $redirect_url; + return $this->options['redirect_lang'] && ! $this->options['force_lang'] && ! empty( $this->curlang->page_on_front ) && is_page( $this->curlang->page_on_front ) ? false : $redirect_url; } /** @@ -163,7 +162,7 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * * @since 2.3 * - * @param object $query + * @param WP_Query $query The WP_Query object. * @return bool */ protected function is_front_page( $query ) { @@ -176,9 +175,9 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * * @since 1.8 * - * @param bool|object $lang - * @param object $query - * @return bool|object + * @param PLL_Language|false $lang The current language, false if it is not set yet. + * @param WP_Query $query The main WP query. + * @return PLL_Language|false */ public function page_on_front_query( $lang, $query ) { if ( ! empty( $lang ) || ! $this->page_on_front ) { @@ -192,10 +191,15 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { // Redirect the language page to the homepage when using a static front page elseif ( ( $this->options['redirect_lang'] || $this->options['hide_default'] ) && $this->is_front_page( $query ) && $lang = $this->model->get_language( get_query_var( 'lang' ) ) ) { - $query->set( 'page_id', $lang->page_on_front ); - $query->is_singular = $query->is_page = true; $query->is_archive = $query->is_tax = false; - unset( $query->query_vars['lang'], $query->queried_object ); // Reset queried object + if ( ! empty( $lang->page_on_front ) ) { + $query->set( 'page_id', $lang->page_on_front ); + $query->is_singular = $query->is_page = true; + unset( $query->query_vars['lang'], $query->queried_object ); // Reset queried object + } else { + // Handle case where the static front page hasn't be translated to avoid a possible infinite redirect loop. + $query->is_home = true; + } } // Fix paged static front page in plain permalinks when Settings > Reading doesn't match the default language @@ -234,9 +238,9 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { * * @since 1.8 * - * @param bool|object $lang - * @param object $query - * @return bool|object + * @param PLL_Language|false $lang The current language, false if it is not set yet. + * @param WP_Query $query The main WP query. + * @return PLL_Language|false */ public function page_for_posts_query( $lang, $query ) { if ( empty( $lang ) && $this->page_for_posts ) { @@ -256,14 +260,15 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { } /** - * Get queried page_id ( if exists ) - * If permalinks are used, WordPress does set and use $query->queried_object_id and sets $query->query_vars['page_id'] to 0 - * and does set and use $query->query_vars['page_id'] if permalinks are not used :( + * Get the queried page_id (if it exists ). + * + * If permalinks are used, WordPress does set and use `$query->queried_object_id` and sets `$query->query_vars['page_id']` to 0, + * and does set and use `$query->query_vars['page_id']` if permalinks are not used :(. * * @since 1.5 * - * @param object $query instance of WP_Query - * @return int page_id + * @param WP_Query $query Instance of WP_Query. + * @return int The page_id. */ protected function get_page_id( $query ) { if ( ! empty( $query->query_vars['pagename'] ) && isset( $query->queried_object_id ) ) { @@ -274,6 +279,6 @@ class PLL_Frontend_Static_Pages extends PLL_Static_Pages { return $query->query_vars['page_id']; } - return 0; // No page queried + return 0; // No page queried. } } diff --git a/wp-content/plugins/polylang/frontend/frontend.php b/wp-content/plugins/polylang/frontend/frontend.php index a9e4acd9..ccc59d25 100644 --- a/wp-content/plugins/polylang/frontend/frontend.php +++ b/wp-content/plugins/polylang/frontend/frontend.php @@ -1,35 +1,74 @@ inherited, reference to Polylang options array - * model => inherited, reference to PLL_Model object - * links_model => inherited, reference to PLL_Links_Model object - * links => reference to PLL_Links object - * static_pages => reference to PLL_Frontend_Static_Pages object - * filters_links => inherited, reference to PLL_Frontend_Filters_Links object - * choose_lang => reference to PLL_Choose_lang object - * curlang => current language - * filters => reference to PLL_Filters object - * filters_search => reference to PLL_Frontend_Filters_Search object - * nav_menu => reference to PLL_Frontend_Nav_Menu object - * auto_translate => optional, reference to PLL_Auto_Translate object + * Main Polylang class when on frontend, accessible from @see PLL(). * * @since 1.2 */ class PLL_Frontend extends PLL_Base { + /** + * Current language. + * + * @var PLL_Language + */ public $curlang; - public $links, $choose_lang, $filters, $filters_search, $nav_menu, $auto_translate; /** - * Constructor + * @var PLL_Frontend_Auto_Translate + */ + public $auto_translate; + + /** + * The class selecting the current language. + * + * @var PLL_Choose_Lang + */ + public $choose_lang; + + /** + * @var PLL_Frontend_Filters + */ + public $filters; + + /** + * @var PLL_Frontend_Filters_Links + */ + public $filters_links; + + /** + * @var PLL_Frontend_Filters_Search + */ + public $filters_search; + + /** + * @var PLL_Frontend_Links + */ + public $links; + + /** + * @var PLL_Frontend_Nav_Menu + */ + public $nav_menu; + + /** + * @var PLL_Frontend_Static_Pages + */ + public $static_pages; + + /** + * @var PLL_Frontend_Filters_Widgets + */ + public $filters_widgets; + + /** + * Constructor. * * @since 1.2 * - * @param object $links_model + * @param PLL_Links_Model $links_model Reference to the links model. */ public function __construct( &$links_model ) { parent::__construct( $links_model ); @@ -54,39 +93,38 @@ class PLL_Frontend extends PLL_Base { * @since 1.2 */ public function init() { + parent::init(); + $this->links = new PLL_Frontend_Links( $this ); - // Don't set any language for REST requests when Polylang Pro is not active - if ( ! class_exists( 'PLL_REST_Translated_Object' ) && 0 === strpos( str_replace( 'index.php', '', $_SERVER['REQUEST_URI'] ), '/' . rest_get_url_prefix() . '/' ) ) { - /** This action is documented in include/class-polylang.php */ - do_action( 'pll_no_language_defined' ); - } else { - // Static front page and page for posts - if ( 'page' === get_option( 'show_on_front' ) ) { - $this->static_pages = new PLL_Frontend_Static_Pages( $this ); - } - - // Setup the language chooser - $c = array( 'Content', 'Url', 'Url', 'Domain' ); - $class = 'PLL_Choose_Lang_' . $c[ $this->options['force_lang'] ]; - $this->choose_lang = new $class( $this ); - $this->choose_lang->init(); - - // Need to load nav menu class early to correctly define the locations in the customizer when the language is set from the content - $this->nav_menu = new PLL_Frontend_Nav_Menu( $this ); + // Static front page and page for posts + if ( 'page' === get_option( 'show_on_front' ) ) { + $this->static_pages = new PLL_Frontend_Static_Pages( $this ); } + + // Setup the language chooser + $c = array( 'Content', 'Url', 'Url', 'Domain' ); + $class = 'PLL_Choose_Lang_' . $c[ $this->options['force_lang'] ]; + $this->choose_lang = new $class( $this ); + $this->choose_lang->init(); + + // Need to load nav menu class early to correctly define the locations in the customizer when the language is set from the content + $this->nav_menu = new PLL_Frontend_Nav_Menu( $this ); } /** * Setups filters and nav menus once the language has been defined * * @since 1.2 + * + * @return void */ public function pll_language_defined() { // Filters $this->filters_links = new PLL_Frontend_Filters_Links( $this ); $this->filters = new PLL_Frontend_Filters( $this ); $this->filters_search = new PLL_Frontend_Filters_Search( $this ); + $this->filters_widgets = new PLL_Frontend_Filters_Widgets( $this ); // Auto translate for Ajax if ( ( ! defined( 'PLL_AUTO_TRANSLATE' ) || PLL_AUTO_TRANSLATE ) && wp_doing_ajax() ) { @@ -95,11 +133,12 @@ class PLL_Frontend extends PLL_Base { } /** - * When querying multiple taxonomies, makes sure that the language is not the queried object + * When querying multiple taxonomies, makes sure that the language is not the queried object. * * @since 1.8 * - * @param object $query WP_Query object + * @param WP_Query $query WP_Query object. + * @return void */ public function parse_tax_query( $query ) { $pll_query = new PLL_Query( $query, $this->model ); @@ -111,11 +150,12 @@ class PLL_Frontend extends PLL_Base { } /** - * mMdifies some query vars to "hide" that the language is a taxonomy and avoid conflicts + * Modifies some query vars to "hide" that the language is a taxonomy and avoid conflicts. * * @since 1.2 * - * @param object $query WP_Query object + * @param WP_Query $query WP_Query object. + * @return void */ public function parse_query( $query ) { $qv = $query->query_vars; @@ -134,7 +174,7 @@ class PLL_Frontend extends PLL_Base { // Remove pages query when the language is set unless we do a search // Take care not to break the single page, attachment and taxonomies queries! - if ( empty( $qv['post_type'] ) && ! $query->is_search && ! $query->is_page && ! $query->is_attachment && empty( $taxonomies ) ) { + if ( empty( $qv['post_type'] ) && ! $query->is_search && ! $query->is_singular && empty( $taxonomies ) && ! $query->is_category && ! $query->is_tag ) { $query->set( 'post_type', 'post' ); } @@ -156,26 +196,31 @@ class PLL_Frontend extends PLL_Base { * Auto translate posts and terms ids * * @since 1.2 + * + * @return void */ public function auto_translate() { $this->auto_translate = new PLL_Frontend_Auto_Translate( $this ); } /** - * Resets some variables when switching blog - * Overrides parent method + * Resets some variables when the blog is switched. + * Overrides the parent method. * * @since 1.5.1 * - * @param int $new_blog - * @param int $old_blog + * @param int $new_blog_id New blog ID. + * @param int $prev_blog_id Previous blog ID. + * @return void */ - public function switch_blog( $new_blog, $old_blog ) { - // Need to check that some languages are defined when user is logged in, has several blogs, some without any languages - if ( parent::switch_blog( $new_blog, $old_blog ) && did_action( 'pll_language_defined' ) && $this->model->get_languages_list() ) { + public function switch_blog( $new_blog_id, $prev_blog_id ) { + parent::switch_blog( $new_blog_id, $prev_blog_id ); + + // Need to check that some languages are defined when user is logged in, has several blogs, some without any languages. + if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) && did_action( 'pll_language_defined' ) && $this->model->get_languages_list() ) { static $restore_curlang; if ( empty( $restore_curlang ) ) { - $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs + $restore_curlang = $this->curlang->slug; // To always remember the current language through blogs. } $lang = $this->model->get_language( $restore_curlang ); diff --git a/wp-content/plugins/polylang/include/api.php b/wp-content/plugins/polylang/include/api.php index ddfe4901..40a503d0 100644 --- a/wp-content/plugins/polylang/include/api.php +++ b/wp-content/plugins/polylang/include/api.php @@ -1,93 +1,112 @@ displays a dropdown if set to 1, defaults to 0 - * echo => echoes the switcher if set to 1 ( default ) - * hide_if_empty => hides languages with no posts ( or pages ) if set to 1 ( default ) - * show_flags => shows flags if set to 1, defaults to 0 - * show_names => shows languages names if set to 1 ( default ) - * display_names_as => whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to name - * force_home => forces linking to the home page is set to 1, defaults to 0 - * hide_if_no_translation => hides the link if there is no translation if set to 1, defaults to 0 - * hide_current => hides the current language if set to 1, defaults to 0 - * post_id => if not null, link to translations of post defined by post_id, defaults to null - * raw => set this to true to build your own custom language switcher, defaults to 0 - * item_spacing => whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to preserve + * Template tag: displays the language switcher. + * The function does nothing if used outside the frontend. * + * @api * @since 0.5 * - * @param array $args optional - * @return null|string|array null if displaying, array if raw is requested, string otherwise + * @param array $args { + * Optional array of arguments. + * + * @type int $dropdown The list is displayed as dropdown if set to 1, defaults to 0. + * @type int $echo Echoes the list if set to 1, defaults to 1. + * @type int $hide_if_empty Hides languages with no posts ( or pages ) if set to 1, defaults to 1. + * @type int $show_flags Displays flags if set to 1, defaults to 0. + * @type int $show_names Shows language names if set to 1, defaults to 1. + * @type string $display_names_as Whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to name. + * @type int $force_home Will always link to the homepage in the translated language if set to 1, defaults to 0. + * @type int $hide_if_no_translation Hides the link if there is no translation if set to 1, defaults to 0. + * @type int $hide_current Hides the current language if set to 1, defaults to 0. + * @type int $post_id Returns links to the translations of the post defined by post_id if set, defaults to not set. + * @type int $raw Return a raw array instead of html markup if set to 1, defaults to 0. + * @type string $item_spacing Whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to 'preserve'. + * } + * @return string|array Either the html markup of the switcher or the raw elements to build a custom language switcher. */ -function pll_the_languages( $args = '' ) { - if ( PLL() instanceof PLL_Frontend ) { - $switcher = new PLL_Switcher; - return $switcher->the_languages( PLL()->links, $args ); - } - return ''; +function pll_the_languages( $args = array() ) { + $switcher = new PLL_Switcher(); + return $switcher->the_languages( PLL()->links, $args ); } /** - * Returns the current language on frontend - * Returns the language set in admin language filter on backend ( false if set to all languages ) + * Returns the current language on frontend. + * Returns the language set in admin language filter on backend ( false if set to all languages ). * + * @api * @since 0.8.1 * - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' - * @return string|bool The requested field for the current language + * @param string $field Optional, the language field to return ( @see PLL_Language ), defaults to 'slug'. Pass OBJECT constant to get the language object. + * @return string|PLL_Language|false The requested field for the current language. */ function pll_current_language( $field = 'slug' ) { + if ( OBJECT === $field ) { + return PLL()->curlang; + } return isset( PLL()->curlang->$field ) ? PLL()->curlang->$field : false; } /** - * Returns the default language + * Returns the default language. * + * @api * @since 1.0 * - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' - * @return string The requested field for the default language + * @param string $field Optional, the language field to return ( @see PLL_Language ), defaults to 'slug'. Pass OBJECT constant to get the language object. + * @return string|PLL_Language|false The requested field for the default language. */ function pll_default_language( $field = 'slug' ) { - return isset( PLL()->options['default_lang'] ) && ( $lang = PLL()->model->get_language( PLL()->options['default_lang'] ) ) && isset( $lang->$field ) ? $lang->$field : false; + if ( isset( PLL()->options['default_lang'] ) ) { + $lang = PLL()->model->get_language( PLL()->options['default_lang'] ); + if ( $lang ) { + if ( OBJECT === $field ) { + return $lang; + } + return isset( $lang->$field ) ? $lang->$field : false; + } + } + return false; } /** - * Among the post and its translations, returns the id of the post which is in the language represented by $slug + * Among the post and its translations, returns the id of the post which is in the language represented by $lang. * + * @api * @since 0.5 * - * @param int $post_id post id - * @param string $slug optional language code, defaults to current language - * @return int|false|null post id of the translation if exists, false otherwise, null if the current language is not defined yet + * @param int $post_id Post id. + * @param string $lang Optional language code, defaults to the current language. + * @return int|false|null Post id of the translation if it exists, false otherwise, null if the current language is not defined yet. */ -function pll_get_post( $post_id, $slug = '' ) { - return ( $slug = $slug ? $slug : pll_current_language() ) ? PLL()->model->post->get( $post_id, $slug ) : null; +function pll_get_post( $post_id, $lang = '' ) { + return ( $lang = $lang ? $lang : pll_current_language() ) ? PLL()->model->post->get( $post_id, $lang ) : null; } /** - * Among the term and its translations, returns the id of the term which is in the language represented by $slug + * Among the term and its translations, returns the id of the term which is in the language represented by $lang. * + * @api * @since 0.5 * - * @param int $term_id term id - * @param string $slug optional language code, defaults to current language - * @return int|false|null term id of the translation if exists, false otherwise, null if the current language is not defined yet + * @param int $term_id Term id. + * @param string $lang Optional language code, defaults to the current language. + * @return int|false|null Term id of the translation if it exists, false otherwise, null if the current language is not defined yet. */ -function pll_get_term( $term_id, $slug = '' ) { - return ( $slug = $slug ? $slug : pll_current_language() ) ? PLL()->model->term->get( $term_id, $slug ) : null; +function pll_get_term( $term_id, $lang = '' ) { + return ( $lang = $lang ? $lang : pll_current_language() ) ? PLL()->model->term->get( $term_id, $lang ) : null; } /** - * Returns the home url in the current language + * Returns the home url in a language. * + * @api * @since 0.8 * - * @param string $lang language code ( optional on frontend ) + * @param string $lang Optional language code, defaults to the current language. * @return string */ function pll_home_url( $lang = '' ) { @@ -99,40 +118,45 @@ function pll_home_url( $lang = '' ) { } /** - * Registers a string for translation in the "strings translation" panel + * Registers a string for translation in the "strings translation" panel. * + * @api * @since 0.6 * - * @param string $name a unique name for the string - * @param string $string the string to register - * @param string $context optional the group in which the string is registered, defaults to 'polylang' - * @param bool $multiline optional whether the string table should display a multiline textarea or a single line input, defaults to single line + * @param string $name A unique name for the string. + * @param string $string The string to register. + * @param string $context Optional, the group in which the string is registered, defaults to 'polylang'. + * @param bool $multiline Optional, true if the string table should display a multiline textarea, + * false if should display a single line input, defaults to false. + * @return void */ -function pll_register_string( $name, $string, $context = 'polylang', $multiline = false ) { +function pll_register_string( $name, $string, $context = 'Polylang', $multiline = false ) { if ( PLL() instanceof PLL_Admin_Base ) { PLL_Admin_Strings::register_string( $name, $string, $context, $multiline ); } } /** - * Translates a string ( previously registered with pll_register_string ) + * Translates a string ( previously registered with pll_register_string ). * + * @api * @since 0.6 * - * @param string $string the string to translate - * @return string the string translation in the current language + * @param string $string The string to translate. + * @return string The string translated in the current language. */ function pll__( $string ) { - return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; + return is_scalar( $string ) ? __( $string, 'pll_string' ) : $string; // PHPCS:ignore WordPress.WP.I18n } /** * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output. * + * @api * @since 2.1 * - * @param string $string the string to translate - * @return string translation in the current language + * @param string $string The string to translate. + * @return string The string translated in the current language. */ function pll_esc_html__( $string ) { return esc_html( pll__( $string ) ); @@ -141,10 +165,11 @@ function pll_esc_html__( $string ) { /** * Translates a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes. * + * @api * @since 2.1 * - * @param string $string The string to translate - * @return string + * @param string $string The string to translate. + * @return string The string translated in the current language. */ function pll_esc_attr__( $string ) { return esc_attr( pll__( $string ) ); @@ -152,45 +177,53 @@ function pll_esc_attr__( $string ) { /** * Echoes a translated string ( previously registered with pll_register_string ) + * It is an equivalent of _e() and is not escaped. * + * @api * @since 0.6 * - * @param string $string The string to translate + * @param string $string The string to translate. + * @return void */ function pll_e( $string ) { - echo pll__( $string ); + echo pll__( $string ); // phpcs:ignore } /** * Echoes a translated string ( previously registered with pll_register_string ) and escapes it for safe use in HTML output. * + * @api * @since 2.1 * - * @param string $string The string to translate + * @param string $string The string to translate. + * @return void */ function pll_esc_html_e( $string ) { - echo pll_esc_html__( $string ); + echo pll_esc_html__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput } /** * Echoes a translated a string ( previously registered with pll_register_string ) and escapes it for safe use in HTML attributes. * + * @api * @since 2.1 * - * @param string $string The string to translate + * @param string $string The string to translate. + * @return void */ function pll_esc_attr_e( $string ) { - echo pll_esc_attr__( $string ); + echo pll_esc_attr__( $string ); // phpcs:ignore WordPress.Security.EscapeOutput } /** - * Translates a string ( previously registered with pll_register_string ) + * Translates a string ( previously registered with pll_register_string ). * + * @api * @since 1.5.4 * - * @param string $string the string to translate - * @param string $lang language code - * @return string the string translation in the requested language + * @param string $string The string to translate. + * @param string $lang Language code. + * @return string The string translated in the requested language. */ function pll_translate_string( $string, $lang ) { if ( PLL() instanceof PLL_Frontend && pll_current_language() == $lang ) { @@ -201,7 +234,7 @@ function pll_translate_string( $string, $lang ) { return $string; } - static $cache; // Cache object to avoid loading the same translations object several times + static $cache; // Cache object to avoid loading the same translations object several times. if ( empty( $cache ) ) { $cache = new PLL_Cache(); @@ -217,11 +250,12 @@ function pll_translate_string( $string, $lang ) { } /** - * Returns true if Polylang manages languages and translations for this post type + * Returns true if Polylang manages languages and translations for this post type. * + * @api * @since 1.0.1 * - * @param string $post_type Post type name + * @param string $post_type Post type name. * @return bool */ function pll_is_translated_post_type( $post_type ) { @@ -229,11 +263,12 @@ function pll_is_translated_post_type( $post_type ) { } /** - * Returns true if Polylang manages languages and translations for this taxonomy + * Returns true if Polylang manages languages and translations for this taxonomy. * + * @api * @since 1.0.1 * - * @param string $tax Taxonomy name + * @param string $tax Taxonomy name. * @return bool */ function pll_is_translated_taxonomy( $tax ) { @@ -241,17 +276,18 @@ function pll_is_translated_taxonomy( $tax ) { } /** - * Returns the list of available languages - * - * List of parameters accepted in $args: - * - * hide_empty => hides languages with no posts if set to true ( defaults to false ) - * fields => return only that field if set ( see PLL_Language for a list of fields ) + * Returns the list of available languages. * + * @api * @since 1.5 * - * @param array $args list of parameters - * @return array + * @param array $args { + * Optional array of arguments. + * + * @type bool $hide_empty Hides languages with no posts if set to true ( defaults to false ). + * @type string $fields Return only that field if set ( @see PLL_Language for a list of fields ), defaults to 'slug'. + * } + * @return string[] */ function pll_languages_list( $args = array() ) { $args = wp_parse_args( $args, array( 'fields' => 'slug' ) ); @@ -259,35 +295,41 @@ function pll_languages_list( $args = array() ) { } /** - * Set the post language + * Sets the post language. * + * @api * @since 1.5 * - * @param int $id post id - * @param string $lang language code + * @param int $id Post id. + * @param string $lang Language code. + * @return void */ function pll_set_post_language( $id, $lang ) { PLL()->model->post->set_language( $id, $lang ); } /** - * Set the term language + * Sets the term language. * + * @api * @since 1.5 * - * @param int $id term id - * @param string $lang language code + * @param int $id Term id. + * @param string $lang Language code. + * @return void */ function pll_set_term_language( $id, $lang ) { PLL()->model->term->set_language( $id, $lang ); } /** - * Save posts translations + * Save posts translations. * + * @api * @since 1.5 * - * @param array $arr an associative array of translations with language code as key and post id as value + * @param int[] $arr An associative array of translations with language code as key and post id as value. + * @return void */ function pll_save_post_translations( $arr ) { PLL()->model->post->save_translations( reset( $arr ), $arr ); @@ -296,84 +338,106 @@ function pll_save_post_translations( $arr ) { /** * Save terms translations * + * @api * @since 1.5 * - * @param array $arr an associative array of translations with language code as key and term id as value + * @param int[] $arr An associative array of translations with language code as key and term id as value. + * @return void */ function pll_save_term_translations( $arr ) { PLL()->model->term->save_translations( reset( $arr ), $arr ); } /** - * Returns the post language + * Returns the post language. * + * @api * @since 1.5.4 * - * @param int $post_id - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' - * @return bool|string The requested field for the post language, false if no language is associated to that post + * @param int $post_id Post id. + * @param string $field Optional, the language field to return ( @see PLL_Language ), defaults to 'slug'. + * @return string|false The requested field for the post language, false if no language is associated to that post. */ function pll_get_post_language( $post_id, $field = 'slug' ) { return ( $lang = PLL()->model->post->get_language( $post_id ) ) ? $lang->$field : false; } /** - * Returns the term language + * Returns the term language. * + * @api * @since 1.5.4 * - * @param int $term_id - * @param string $field Optional, the language field to return ( see PLL_Language ), defaults to 'slug' - * @return bool|string The requested field for the term language, false if no language is associated to that term + * @param int $term_id Term id. + * @param string $field Optional, the language field to return ( @see PLL_Language ), defaults to 'slug'. + * @return string|false The requested field for the term language, false if no language is associated to that term. */ function pll_get_term_language( $term_id, $field = 'slug' ) { return ( $lang = PLL()->model->term->get_language( $term_id ) ) ? $lang->$field : false; } /** - * Returns an array of translations of a post + * Returns an array of translations of a post. * + * @api * @since 1.8 * - * @param int $post_id - * @return array an associative array of translations with language code as key and translation post_id as value + * @param int $post_id Post id. + * @return int[] An associative array of translations with language code as key and translation post id as value. */ function pll_get_post_translations( $post_id ) { return PLL()->model->post->get_translations( $post_id ); } /** - * Returns an array of translations of a term + * Returns an array of translations of a term. * + * @api * @since 1.8 * - * @param int $term_id - * @return array an associative array of translations with language code as key and translation term_id as value + * @param int $term_id Term id. + * @return int[] An associative array of translations with language code as key and translation term id as value. */ function pll_get_term_translations( $term_id ) { return PLL()->model->term->get_translations( $term_id ); } /** - * Count posts in a language + * Counts posts in a language. * + * @api * @since 1.5 * - * @param string $lang language code - * @param array $args ( accepted keys: post_type, m, year, monthnum, day, author, author_name, post_format ) - * @return int posts count + * @param string $lang Language code. + * @param array $args { + * Optional arguments. + * Accepted keys: + * + * @type string $post_type Post type. + * @type int $m YearMonth ( ex: 201307 ). + * @type int $year 4 digit year. + * @type int $monthnum Month number (from 1 to 12). + * @type int $day Day of the month (from 1 to 31). + * @type int $author Author id. + * @type string $author_name Author nicename. + * @type string $post_format Post format. + * @type string $post_status Post status. + * } + * @return int Posts count. */ function pll_count_posts( $lang, $args = array() ) { return PLL()->model->count_posts( PLL()->model->get_language( $lang ), $args ); } /** - * Allows to access the Polylang instance - * It is always preferable to use API functions - * Internal methods may be changed without prior notice + * Allows to access the Polylang instance. + * However, it is always preferable to use API functions + * as internal methods may be changed without prior notice. * * @since 1.8 + * + * @return PLL_Frontend|PLL_Admin|PLL_Settings|PLL_REST_Request */ -function PLL() { +function PLL() { // PHPCS:ignore WordPress.NamingConventions.ValidFunctionName return $GLOBALS['polylang']; } diff --git a/wp-content/plugins/polylang/include/base.php b/wp-content/plugins/polylang/include/base.php index 66ef339b..8ee82b5f 100644 --- a/wp-content/plugins/polylang/include/base.php +++ b/wp-content/plugins/polylang/include/base.php @@ -1,4 +1,7 @@ links_model = &$links_model; @@ -27,15 +61,39 @@ abstract class PLL_Base { // User defined strings translations add_action( 'pll_language_defined', array( $this, 'load_strings_translations' ), 5 ); add_action( 'change_locale', array( $this, 'load_strings_translations' ) ); // Since WP 4.7 + add_action( 'personal_options_update', array( $this, 'load_strings_translations' ), 1, 0 ); // Before WP, for confirmation request when changing the user email. // Switch_to_blog add_action( 'switch_blog', array( $this, 'switch_blog' ), 10, 2 ); } + /** + * Instantiates classes reacting to CRUD operations on posts and terms, + * only when at least one language is defined. + * + * @since 2.6 + * + * @return void + */ + public function init() { + if ( $this->model->get_languages_list() ) { + $this->posts = new PLL_CRUD_Posts( $this ); + $this->terms = new PLL_CRUD_Terms( $this ); + + // WordPress options. + new PLL_Translate_Option( 'blogname', array(), array( 'context' => 'WordPress' ) ); + new PLL_Translate_Option( 'blogdescription', array(), array( 'context' => 'WordPress' ) ); + new PLL_Translate_Option( 'date_format', array(), array( 'context' => 'WordPress' ) ); + new PLL_Translate_Option( 'time_format', array(), array( 'context' => 'WordPress' ) ); + } + } + /** * Registers our widgets * * @since 0.1 + * + * @return void */ public function widgets_init() { register_widget( 'PLL_Widget_Languages' ); @@ -54,10 +112,11 @@ abstract class PLL_Base { * @since 2.1.3 $locale parameter added. * * @param string $locale Locale. Defaults to current locale. + * @return void */ public function load_strings_translations( $locale = '' ) { if ( empty( $locale ) ) { - $locale = get_locale(); + $locale = ( is_admin() && ! Polylang::is_ajax_on_front() ) ? get_user_locale() : get_locale(); } $language = $this->model->get_language( $locale ); @@ -72,55 +131,40 @@ abstract class PLL_Base { } /** - * Resets some variables when switching blog - * Applies only if Polylang is active on the new blog + * Resets some variables when the blog is switched. + * Applied only if Polylang is active on the new blog. * * @since 1.5.1 * - * @param int $new_blog - * @param int $old_blog - * @return bool not used by WP but by child class + * @param int $new_blog_id New blog ID. + * @param int $prev_blog_id Previous blog ID. + * @return void */ - public function switch_blog( $new_blog, $old_blog ) { - $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array(); - $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) ); - - // 2nd test needed when Polylang is not networked activated - // 3rd test needed when Polylang is networked activated and a new site is created - if ( $new_blog != $old_blog && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' ) ) { - $this->options = get_option( 'polylang' ); // Needed for menus + public function switch_blog( $new_blog_id, $prev_blog_id ) { + if ( $this->is_active_on_new_blog( $new_blog_id, $prev_blog_id ) ) { + $this->options = get_option( 'polylang' ); // Needed for menus. + remove_action( 'pre_option_rewrite_rules', array( $this->links_model, 'prepare_rewrite_rules' ) ); $this->links_model = $this->model->get_links_model(); - return true; } - return false; } /** - * Some backward compatibility with Polylang < 1.2 - * Allows for example to call $polylang->get_languages_list() instead of $polylang->model->get_languages_list() - * This works but should be slower than the direct call, thus an error is triggered in debug mode + * Checks if Polylang is active on the new blog when the blog is switched. * - * @since 1.2 + * @since 3.0 * - * @param string $func function name - * @param array $args function arguments + * @param int $new_blog_id New blog ID. + * @param int $prev_blog_id Previous blog ID. + * @return bool */ - public function __call( $func, $args ) { - foreach ( $this as $prop => &$obj ) { - if ( is_object( $obj ) && method_exists( $obj, $func ) ) { - if ( WP_DEBUG ) { - $debug = debug_backtrace(); - $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func - trigger_error( sprintf( - '%1$s was called incorrectly in %3$s on line %4$s: the call to $polylang->%1$s() has been deprecated in Polylang 1.2, use PLL()->%2$s->%1$s() instead.' . "\nError handler", - $func, $prop, $debug[ $i ]['file'], $debug[ $i ]['line'] - ) ); - } - return call_user_func_array( array( $obj, $func ), $args ); - } - } + protected function is_active_on_new_blog( $new_blog_id, $prev_blog_id ) { + $plugins = ( $sitewide_plugins = get_site_option( 'active_sitewide_plugins' ) ) && is_array( $sitewide_plugins ) ? array_keys( $sitewide_plugins ) : array(); + $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) ); - $debug = debug_backtrace(); - trigger_error( sprintf( 'Call to undefined function PLL()->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR ); + /* + * The 2nd test is needed when Polylang is not networked activated. + * The 3rd test is needed when Polylang is networked activated and a new site is created. + */ + return $new_blog_id !== $prev_blog_id && in_array( POLYLANG_BASENAME, $plugins ) && get_option( 'polylang' ); } } diff --git a/wp-content/plugins/polylang/include/cache.php b/wp-content/plugins/polylang/include/cache.php index 971df9c3..0c1f7251 100644 --- a/wp-content/plugins/polylang/include/cache.php +++ b/wp-content/plugins/polylang/include/cache.php @@ -1,4 +1,7 @@ blog_id = $new_blog; @@ -37,6 +53,7 @@ class PLL_Cache { * * @param string $key * @param mixed $data + * @return void */ public function set( $key, $data ) { $this->cache[ $this->blog_id ][ $key ] = $data; @@ -60,6 +77,7 @@ class PLL_Cache { * @since 1.7 * * @param string $key + * @return void */ public function clean( $key = '' ) { if ( empty( $key ) ) { diff --git a/wp-content/plugins/polylang/include/class-polylang.php b/wp-content/plugins/polylang/include/class-polylang.php index 78c7a18a..ef1367d6 100644 --- a/wp-content/plugins/polylang/include/class-polylang.php +++ b/wp-content/plugins/polylang/include/class-polylang.php @@ -1,4 +1,7 @@ is_deactivation() ) { + if ( $install->is_deactivation() || ! $install->can_activate() ) { return; } @@ -47,46 +52,12 @@ class Polylang { PLL_OLT_Manager::instance(); } - // Extra code for compatibility with some plugins - // Loaded as soon as possible as we may need to act before other plugins are loaded + /* + * Loads the compatibility with some plugins and themes. + * Loaded as soon as possible as we may need to act before other plugins are loaded. + */ if ( ! defined( 'PLL_PLUGINS_COMPAT' ) || PLL_PLUGINS_COMPAT ) { - PLL_Plugins_Compat::instance(); - } - } - - /** - * Autoload classes - * - * @since 1.2 - * - * @param string $class - */ - public function autoload( $class ) { - // Not a Polylang class - if ( 0 !== strncmp( 'PLL_', $class, 4 ) ) { - return; - } - - $class = str_replace( '_', '-', strtolower( substr( $class, 4 ) ) ); - $to_find = array( 'media', 'share', 'slug', 'slugs', 'sync', 'translate', 'wpml', 'xdata', 'rest' ); - $dir = implode( '-', array_intersect( explode( '-', $class ), $to_find ) ); - - $dirs = array( - PLL_FRONT_INC, - PLL_MODULES_INC, - PLL_MODULES_INC . "/$dir", - PLL_MODULES_INC . '/plugins', - PLL_INSTALL_INC, - PLL_ADMIN_INC, - PLL_SETTINGS_INC, - PLL_INC, - ); - - foreach ( $dirs as $dir ) { - if ( file_exists( $file = "$dir/$class.php" ) ) { - require_once $file; - return; - } + PLL_Integrations::instance(); } } @@ -97,11 +68,11 @@ class Polylang { * * @return bool */ - static public function is_ajax_on_front() { + public static function is_ajax_on_front() { // Special test for plupload which does not use jquery ajax and thus does not pass our ajax prefilter // Special test for customize_save done in frontend but for which we want to load the admin - $in = isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], array( 'upload-attachment', 'customize_save' ) ); - $is_ajax_on_front = wp_doing_ajax() && empty( $_REQUEST['pll_ajax_backend'] ) && ! $in; + $in = isset( $_REQUEST['action'] ) && in_array( sanitize_key( $_REQUEST['action'] ), array( 'upload-attachment', 'customize_save' ) ); // phpcs:ignore WordPress.Security.NonceVerification + $is_ajax_on_front = wp_doing_ajax() && empty( $_REQUEST['pll_ajax_backend'] ) && ! $in; // phpcs:ignore WordPress.Security.NonceVerification /** * Filters whether the current request is an ajax request on front. @@ -113,13 +84,54 @@ class Polylang { return apply_filters( 'pll_is_ajax_on_front', $is_ajax_on_front ); } + /** + * Is the current request a REST API request? + * Inspired by WP::parse_request() + * Needed because at this point, the constant REST_REQUEST is not defined yet + * + * @since 2.4.1 + * + * @return bool + */ + public static function is_rest_request() { + // Handle pretty permalinks. + $home_path = trim( wp_parse_url( home_url(), PHP_URL_PATH ), '/' ); + $home_path_regex = sprintf( '|^%s|i', preg_quote( $home_path, '|' ) ); + + $req_uri = trim( wp_parse_url( pll_get_requested_url(), PHP_URL_PATH ), '/' ); + $req_uri = preg_replace( $home_path_regex, '', $req_uri ); + $req_uri = trim( $req_uri, '/' ); + $req_uri = str_replace( 'index.php', '', $req_uri ); + $req_uri = trim( $req_uri, '/' ); + + // And also test rest_route query string parameter is not empty for plain permalinks. + $query_string = array(); + wp_parse_str( wp_parse_url( pll_get_requested_url(), PHP_URL_QUERY ), $query_string ); + $rest_route = isset( $query_string['rest_route'] ) ? trim( $query_string['rest_route'], '/' ) : false; + + return 0 === strpos( $req_uri, rest_get_url_prefix() . '/' ) || ! empty( $rest_route ); + } + + /** + * Tells if we are in the wizard process. + * + * @since 2.7 + * + * @return bool + */ + public static function is_wizard() { + return isset( $_GET['page'] ) && ! empty( $_GET['page'] ) && 'mlang_wizard' === sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification + } + /** * Defines constants * May be overridden by a plugin if set before plugins_loaded, 1 * * @since 1.6 + * + * @return void */ - static public function define_constants() { + public static function define_constants() { // Cookie name. no cookie will be used if set to false if ( ! defined( 'PLL_COOKIE' ) ) { define( 'PLL_COOKIE', 'pll_language' ); @@ -132,12 +144,12 @@ class Polylang { // Admin if ( ! defined( 'PLL_ADMIN' ) ) { - define( 'PLL_ADMIN', defined( 'DOING_CRON' ) || ( defined( 'WP_CLI' ) && WP_CLI ) || ( is_admin() && ! PLL_AJAX_ON_FRONT ) ); + define( 'PLL_ADMIN', wp_doing_cron() || ( defined( 'WP_CLI' ) && WP_CLI ) || ( is_admin() && ! PLL_AJAX_ON_FRONT ) ); } - // Settings page whatever the tab + // Settings page whatever the tab except for the wizard which needs to be an admin process. if ( ! defined( 'PLL_SETTINGS' ) ) { - define( 'PLL_SETTINGS', is_admin() && ( ( isset( $_GET['page'] ) && 0 === strpos( $_GET['page'], 'mlang' ) ) || ! empty( $_REQUEST['pll_ajax_settings'] ) ) ); + define( 'PLL_SETTINGS', is_admin() && ( ( isset( $_GET['page'] ) && 0 === strpos( sanitize_key( $_GET['page'] ), 'mlang' ) && ! self::is_wizard() ) || ! empty( $_REQUEST['pll_ajax_settings'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification } } @@ -146,6 +158,8 @@ class Polylang { * setups models and separate admin and frontend * * @since 1.2 + * + * @return void */ public function init() { global $polylang; @@ -161,6 +175,11 @@ class Polylang { } } + // In some edge cases, it's possible that no options were found in the database. Load default options as we need some. + if ( ! $options ) { + $options = PLL_Install::get_default_options(); + } + // Make sure that this filter is *always* added before PLL_Model::get_languages_list() is called for the first time add_filter( 'pll_languages_list', array( 'PLL_Static_Pages', 'pll_languages_list' ), 2, 2 ); // Before PLL_Links_Model @@ -172,21 +191,10 @@ class Polylang { * * @param string $class either PLL_Model or PLL_Admin_Model */ - $class = apply_filters( 'pll_model', PLL_SETTINGS ? 'PLL_Admin_Model' : 'PLL_Model' ); + $class = apply_filters( 'pll_model', PLL_SETTINGS || self::is_wizard() ? 'PLL_Admin_Model' : 'PLL_Model' ); $model = new $class( $options ); $links_model = $model->get_links_model(); - if ( PLL_SETTINGS ) { - $polylang = new PLL_Settings( $links_model ); - } - elseif ( PLL_ADMIN ) { - $polylang = new PLL_Admin( $links_model ); - } - // Do nothing on frontend if no language is defined - elseif ( $model->get_languages_list() && empty( $_GET['deactivate-polylang'] ) ) { - $polylang = new PLL_Frontend( $links_model ); - } - if ( ! $model->get_languages_list() ) { /** * Fires when no language has been defined yet @@ -197,7 +205,30 @@ class Polylang { do_action( 'pll_no_language_defined' ); } - if ( ! empty( $polylang ) ) { + $class = ''; + + if ( PLL_SETTINGS ) { + $class = 'PLL_Settings'; + } elseif ( PLL_ADMIN ) { + $class = 'PLL_Admin'; + } elseif ( self::is_rest_request() ) { + $class = 'PLL_REST_Request'; + } elseif ( $model->get_languages_list() ) { + $class = 'PLL_Frontend'; + } + + /** + * Filters the class to use to instantiate the $polylang object + * + * @since 2.6 + * + * @param string $class A class name. + */ + $class = apply_filters( 'pll_context', $class ); + + if ( ! empty( $class ) ) { + $polylang = new $class( $links_model ); + /** * Fires after the $polylang object is created and before the API is loaded * @@ -207,11 +238,14 @@ class Polylang { */ do_action_ref_array( 'pll_pre_init', array( &$polylang ) ); - require_once PLL_INC . '/api.php'; // Loads the API + require_once __DIR__ . '/api.php'; // Loads the API - if ( ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT ) { - PLL_WPML_Compat::instance(); // WPML API - PLL_WPML_Config::instance(); // wpml-config.xml + // Loads the modules. + $load_scripts = glob( POLYLANG_DIR . '/modules/*/load.php', GLOB_NOSORT ); + if ( is_array( $load_scripts ) ) { + foreach ( $load_scripts as $load_script ) { + require_once $load_script; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable + } } $polylang->init(); @@ -227,5 +261,3 @@ class Polylang { } } } - -new Polylang(); diff --git a/wp-content/plugins/polylang/include/cookie.php b/wp-content/plugins/polylang/include/cookie.php new file mode 100644 index 00000000..fc63a877 --- /dev/null +++ b/wp-content/plugins/polylang/include/cookie.php @@ -0,0 +1,86 @@ + 0 !== $expiration ? time() + $expiration : 0, + 'path' => COOKIEPATH, + 'domain' => COOKIE_DOMAIN, // Cookie domain must be set to false for localhost ( default value for COOKIE_DOMAIN ) thanks to Stephen Harris. + 'secure' => is_ssl(), + 'httponly' => false, + 'samesite' => 'Lax', + ); + + return wp_parse_args( $args, $defaults ); + } + + /** + * Sets the cookie. + * + * @since 2.9 + * + * @param string $lang Language cookie value. + * @param array $args { + * Optional. Array of arguments for setting the cookie. + * + * @type string $path Cookie path, defaults to COOKIEPATH. + * @type string $domain Cookie domain, defaults to COOKIE_DOMAIN + * @type bool $secure Should the cookie be sent only over https? + * @type bool $httponly Should the cookie accessed only over http protocol? Defaults to false. + * @type string $samesite Either 'Strict', 'Lax' or 'None', defaults to 'Lax'. + * } + * @return void + */ + public static function set( $lang, $args = array() ) { + $args = self::parse_args( $args ); + + if ( ! headers_sent() && PLL_COOKIE !== false && self::get() !== $lang ) { + if ( version_compare( PHP_VERSION, '7.3', '<' ) ) { + $args['path'] .= '; SameSite=' . $args['samesite']; // Hack to set SameSite value in PHP < 7.3. Doesn't work with newer versions. + setcookie( PLL_COOKIE, $lang, $args['expires'], $args['path'], $args['domain'], $args['secure'], $args['httponly'] ); + } else { + setcookie( PLL_COOKIE, $lang, $args ); + } + } + } + + /** + * Returns the language cookie value. + * + * @since 2.9 + * + * @return string + */ + public static function get() { + return isset( $_COOKIE[ PLL_COOKIE ] ) ? sanitize_key( $_COOKIE[ PLL_COOKIE ] ) : ''; + } +} diff --git a/wp-content/plugins/polylang/include/crud-posts.php b/wp-content/plugins/polylang/include/crud-posts.php new file mode 100644 index 00000000..9193e77f --- /dev/null +++ b/wp-content/plugins/polylang/include/crud-posts.php @@ -0,0 +1,330 @@ +model = &$polylang->model; + $this->pref_lang = &$polylang->pref_lang; + $this->curlang = &$polylang->curlang; + + add_action( 'save_post', array( $this, 'save_post' ), 10, 2 ); + add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 4 ); + add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 4 ); + add_action( 'before_delete_post', array( $this, 'delete_post' ) ); + + // Specific for media + if ( $polylang->options['media_support'] ) { + add_action( 'add_attachment', array( $this, 'set_default_language' ) ); + add_action( 'delete_attachment', array( $this, 'delete_post' ) ); + add_filter( 'wp_delete_file', array( $this, 'wp_delete_file' ) ); + } + } + + /** + * Allows to set a language by default for posts if it has no language yet + * + * @since 1.5 + * + * @param int $post_id + * @return void + */ + public function set_default_language( $post_id ) { + if ( ! $this->model->post->get_language( $post_id ) ) { + if ( ! empty( $_GET['new_lang'] ) && $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + // Defined only on admin. + $this->model->post->set_language( $post_id, $lang ); + } elseif ( ! isset( $this->pref_lang ) && ! empty( $_REQUEST['lang'] ) && $lang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + // Testing $this->pref_lang makes this test pass only on admin. + $this->model->post->set_language( $post_id, $lang ); + } elseif ( ( $parent_id = wp_get_post_parent_id( $post_id ) ) && $parent_lang = $this->model->post->get_language( $parent_id ) ) { + $this->model->post->set_language( $post_id, $parent_lang ); + } elseif ( isset( $this->pref_lang ) ) { + // Always defined on admin, never defined on frontend + $this->model->post->set_language( $post_id, $this->pref_lang ); + } else { + // Only on frontend due to the previous test always true on admin + $this->model->post->set_language( $post_id, $this->curlang ); + } + } + } + + /** + * Called when a post ( or page ) is saved, published or updated. + * + * @since 0.1 + * @since 2.3 Does not save the language and translations anymore, unless the post has no language yet. + * + * @param int $post_id Post id of the post being saved. + * @param WP_Post $post The post being saved. + * @return void + */ + public function save_post( $post_id, $post ) { + // Does nothing except on post types which are filterable. + if ( $this->model->is_translated_post_type( $post->post_type ) ) { + if ( $id = wp_is_post_revision( $post_id ) ) { + $post_id = $id; + } + + $lang = $this->model->post->get_language( $post_id ); + + if ( empty( $lang ) ) { + $this->set_default_language( $post_id ); + } + + /** + * Fires after the post language and translations are saved. + * + * @since 1.2 + * + * @param int $post_id Post id. + * @param WP_Post $post Post object. + * @param int[] $translations The list of translations post ids. + */ + do_action( 'pll_save_post', $post_id, $post, $this->model->post->get_translations( $post_id ) ); + } + } + + /** + * Makes sure that saved terms are in the right language (especially tags with same name in different languages). + * + * @since 2.3 + * + * @param int $object_id Object ID. + * @param WP_Term[] $terms An array of object terms. + * @param int[] $tt_ids An array of term taxonomy IDs. + * @param string $taxonomy Taxonomy slug. + * @return void + */ + public function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy ) { + static $avoid_recursion; + + if ( ! $avoid_recursion && $this->model->is_translated_taxonomy( $taxonomy ) && ! empty( $terms ) ) { + $lang = $this->model->post->get_language( $object_id ); + + if ( ! empty( $lang ) && is_array( $terms ) ) { + // Convert to term ids if we got tag names + $strings = array_filter( $terms, 'is_string' ); + if ( ! empty( $strings ) ) { + $_terms = get_terms( $taxonomy, array( 'name' => $strings, 'object_ids' => $object_id, 'fields' => 'ids' ) ); + $terms = array_merge( array_diff( $terms, $strings ), $_terms ); + } + + $term_ids = array_combine( $terms, $terms ); + $languages = array_map( array( $this->model->term, 'get_language' ), $term_ids ); + $languages = array_filter( $languages ); // Remove terms without language. + $languages = wp_list_pluck( $languages, 'slug' ); + $wrong_terms = array_diff( $languages, array( $lang->slug ) ); + + if ( ! empty( $wrong_terms ) ) { + // We got terms in a wrong language + $wrong_term_ids = array_keys( $wrong_terms ); + $terms = get_the_terms( $object_id, $taxonomy ); + wp_remove_object_terms( $object_id, $wrong_term_ids, $taxonomy ); + + if ( is_array( $terms ) ) { + $newterms = array(); + + foreach ( $terms as $term ) { + if ( in_array( $term->term_id, $wrong_term_ids ) ) { + // Check if the term is in the correct language or if a translation exist ( mainly for default category ) + if ( $newterm = $this->model->term->get( $term->term_id, $lang ) ) { + $newterms[] = (int) $newterm; + } + + // Or choose the correct language for tags ( initially defined by name ) + elseif ( $newterm = $this->model->term_exists( $term->name, $taxonomy, $term->parent, $lang ) ) { + $newterms[] = (int) $newterm; // Cast is important otherwise we get 'numeric' tags + } + + // Or create the term in the correct language + elseif ( ! is_wp_error( $term_info = wp_insert_term( $term->name, $taxonomy ) ) ) { + $newterms[] = (int) $term_info['term_id']; + } + } + } + + $avoid_recursion = true; + wp_set_object_terms( $object_id, array_unique( $newterms ), $taxonomy, true ); // Append + $avoid_recursion = false; + } + } + } + } + } + + /** + * Make sure that the post parent is in the correct language when using bulk edit + * + * @since 1.8 + * + * @param int $post_parent Post parent ID. + * @param int $post_id Post ID. + * @param array $new_postarr Array of parsed post data. + * @param array $postarr Array of sanitized, but otherwise unmodified post data. + * @return int + */ + public function wp_insert_post_parent( $post_parent, $post_id, $new_postarr, $postarr ) { + if ( isset( $postarr['bulk_edit'], $postarr['inline_lang_choice'] ) ) { + check_admin_referer( 'bulk-posts' ); + $lang = -1 == $postarr['inline_lang_choice'] ? + $this->model->post->get_language( $post_id ) : + $this->model->get_language( $postarr['inline_lang_choice'] ); + // Dont break the hierarchy in case the post has no language + if ( ! empty( $lang ) ) { + $post_parent = $this->model->post->get_translation( $post_parent, $lang ); + } + } + return $post_parent; + } + + /** + * Called when a post, page or media is deleted + * Don't delete translations if this is a post revision thanks to AndyDeGroo who catched this bug + * http://wordpress.org/support/topic/plugin-polylang-quick-edit-still-breaks-translation-linking-of-pages-in-072 + * + * @since 0.1 + * + * @param int $post_id + * @return void + */ + public function delete_post( $post_id ) { + if ( ! wp_is_post_revision( $post_id ) ) { + $this->model->post->delete_translation( $post_id ); + } + } + + /** + * Prevents WP deleting files when there are still media using them. + * + * @since 0.9 + * + * @param string $file Path to the file to delete. + * @return string Empty or unmodified path. + */ + public function wp_delete_file( $file ) { + global $wpdb; + + $uploadpath = wp_upload_dir(); + + // Get the main attached file. + $attached_file = substr_replace( $file, '', 0, strlen( trailingslashit( $uploadpath['basedir'] ) ) ); + $attached_file = preg_replace( '#-\d+x\d+\.([a-z]+)$#', '.$1', $attached_file ); + + $ids = $wpdb->get_col( + $wpdb->prepare( + "SELECT post_id FROM $wpdb->postmeta + WHERE meta_key = '_wp_attached_file' AND meta_value = %s", + $attached_file + ) + ); + + if ( ! empty( $ids ) ) { + return ''; // Prevent deleting the file. + } + + return $file; + } + + /** + * Creates a media translation + * + * @since 1.8 + * + * @param int $post_id Original attachment id. + * @param string|object $lang New translation language. + * @return int Attachment id of the translated media. + */ + public function create_media_translation( $post_id, $lang ) { + if ( empty( $post_id ) ) { + return 0; + } + + $post = get_post( $post_id, ARRAY_A ); + + if ( empty( $post ) ) { + return 0; + } + + $lang = $this->model->get_language( $lang ); // Make sure we get a valid language slug. + + if ( empty( $lang ) ) { + return 0; + } + + // Create a new attachment ( translate attachment parent if exists ). + add_filter( 'pll_enable_duplicate_media', '__return_false', 99 ); // Avoid a conflict with automatic duplicate at upload. + unset( $post['ID'] ); // Will force the creation. + $post['post_parent'] = ( $post['post_parent'] && $tr_parent = $this->model->post->get_translation( $post['post_parent'], $lang->slug ) ) ? $tr_parent : 0; + $post['tax_input'] = array( 'language' => array( $lang->slug ) ); // Assigns the language. + $tr_id = wp_insert_attachment( wp_slash( $post ) ); + remove_filter( 'pll_enable_duplicate_media', '__return_false', 99 ); // Restore automatic duplicate at upload. + + // Copy metadata. + $data = wp_get_attachment_metadata( $post_id, true ); // Unfiltered. + if ( is_array( $data ) ) { + wp_update_attachment_metadata( $tr_id, wp_slash( $data ) ); // Directly uses update_post_meta, so expects slashed. + } + + // Copy attached file. + if ( $file = get_attached_file( $post_id, true ) ) { // Unfiltered. + update_attached_file( $tr_id, wp_slash( $file ) ); // Directly uses update_post_meta, so expects slashed. + } + + // Copy alternative text. Direct use of the meta as there is no filtered wrapper to manipulate it. + if ( $text = get_post_meta( $post_id, '_wp_attachment_image_alt', true ) ) { + add_post_meta( $tr_id, '_wp_attachment_image_alt', wp_slash( $text ) ); + } + + $this->model->post->set_language( $tr_id, $lang ); + + $translations = $this->model->post->get_translations( $post_id ); + $translations[ $lang->slug ] = $tr_id; + $this->model->post->save_translations( $tr_id, $translations ); + + /** + * Fires after a media translation is created + * + * @since 1.6.4 + * + * @param int $post_id Post id of the source media. + * @param int $tr_id Post id of the new media translation. + * @param string $slug Language code of the new translation. + */ + do_action( 'pll_translate_media', $post_id, $tr_id, $lang->slug ); + return $tr_id; + } +} diff --git a/wp-content/plugins/polylang/include/crud-terms.php b/wp-content/plugins/polylang/include/crud-terms.php new file mode 100644 index 00000000..fafec201 --- /dev/null +++ b/wp-content/plugins/polylang/include/crud-terms.php @@ -0,0 +1,247 @@ +model = &$polylang->model; + $this->curlang = &$polylang->curlang; + $this->filter_lang = &$polylang->filter_lang; + $this->pref_lang = &$polylang->pref_lang; + + // Saving terms + add_action( 'create_term', array( $this, 'save_term' ), 999, 3 ); + add_action( 'edit_term', array( $this, 'save_term' ), 999, 3 ); // After PLL_Admin_Filters_Term + + // Adds cache domain when querying terms + add_filter( 'get_terms_args', array( $this, 'get_terms_args' ), 10, 2 ); + + // Filters terms by language + add_filter( 'terms_clauses', array( $this, 'terms_clauses' ), 10, 3 ); + add_action( 'pre_get_posts', array( $this, 'set_tax_query_lang' ), 999 ); + add_action( 'posts_selection', array( $this, 'unset_tax_query_lang' ), 0 ); + + // Deleting terms + add_action( 'pre_delete_term', array( $this, 'delete_term' ) ); + } + + /** + * Allows to set a language by default for terms if it has no language yet + * + * @since 1.5.4 + * + * @param int $term_id + * @param string $taxonomy + * @return void + */ + protected function set_default_language( $term_id, $taxonomy ) { + if ( ! $this->model->term->get_language( $term_id ) ) { + if ( ! isset( $this->pref_lang ) && ! empty( $_REQUEST['lang'] ) && $lang = $this->model->get_language( sanitize_key( $_REQUEST['lang'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification + // Testing $this->pref_lang makes this test pass only on frontend. + $this->model->term->set_language( $term_id, $lang ); + } elseif ( ( $term = get_term( $term_id, $taxonomy ) ) && ! empty( $term->parent ) && $parent_lang = $this->model->term->get_language( $term->parent ) ) { + // Sets language from term parent if exists thanks to Scott Kingsley Clark + $this->model->term->set_language( $term_id, $parent_lang ); + } elseif ( isset( $this->pref_lang ) ) { + // Always defined on admin, never defined on frontend + $this->model->term->set_language( $term_id, $this->pref_lang ); + } else { + // Only on frontend due to the previous test always true on admin + $this->model->term->set_language( $term_id, $this->curlang ); + } + } + } + + /** + * Called when a category or post tag is created or edited. + * Does nothing except on taxonomies which are filterable. + * + * @since 0.1 + * + * @param int $term_id Term id of the term being saved. + * @param int $tt_id Term taxonomy id. + * @param string $taxonomy Taxonomy name. + * @return void + */ + public function save_term( $term_id, $tt_id, $taxonomy ) { + if ( $this->model->is_translated_taxonomy( $taxonomy ) ) { + + $lang = $this->model->term->get_language( $term_id ); + + if ( empty( $lang ) ) { + $this->set_default_language( $term_id, $taxonomy ); + } + + /** + * Fires after the term language and translations are saved. + * + * @since 1.2 + * + * @param int $term_id Term id. + * @param string $taxonomy Taxonomy name. + * @param int[] $translations The list of translations term ids. + */ + do_action( 'pll_save_term', $term_id, $taxonomy, $this->model->term->get_translations( $term_id ) ); + } + } + + /** + * Get the language(s) to filter WP_Term_Query. + * + * @since 1.7.6 + * + * @param string[] $taxonomies Queried taxonomies. + * @param array $args WP_Term_Query arguments. + * @return PLL_Language|string|false The language(s) to use in the filter, false otherwise. + */ + protected function get_queried_language( $taxonomies, $args ) { + global $pagenow; + + // Does nothing except on taxonomies which are filterable + // Since WP 4.7, make sure not to filter wp_get_object_terms() + if ( ! $this->model->is_translated_taxonomy( $taxonomies ) || ! empty( $args['object_ids'] ) ) { + return false; + } + + // If get_terms is queried with a 'lang' parameter + if ( isset( $args['lang'] ) ) { + return $args['lang']; + } + + // On tags page, everything should be filtered according to the admin language filter except the parent dropdown + if ( 'edit-tags.php' === $pagenow && empty( $args['class'] ) ) { + return $this->filter_lang; + } + + return $this->curlang; + } + + /** + * Adds language dependent cache domain when querying terms. + * Useful as the 'lang' parameter is not included in cache key by WordPress. + * + * @since 1.3 + * + * @param array $args WP_Term_Query arguments. + * @param string[] $taxonomies Queried taxonomies. + * @return array Modified arguments. + */ + public function get_terms_args( $args, $taxonomies ) { + // Don't break _get_term_hierarchy(). + if ( 'all' === $args['get'] && 'id' === $args['orderby'] && 'id=>parent' === $args['fields'] ) { + $args['lang'] = ''; + } + + if ( isset( $this->tax_query_lang ) ) { + $args['lang'] = empty( $this->tax_query_lang ) && ! empty( $this->curlang ) && ! empty( $args['slug'] ) ? $this->curlang->slug : $this->tax_query_lang; + } + + if ( $lang = $this->get_queried_language( $taxonomies, $args ) ) { + $lang = is_string( $lang ) && strpos( $lang, ',' ) ? explode( ',', $lang ) : $lang; + $key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $this->model->get_language( $lang )->slug ); + $args['cache_domain'] = empty( $args['cache_domain'] ) ? 'pll' . $key : $args['cache_domain'] . $key; + } + return $args; + } + + /** + * Filters categories and post tags by language(s) when needed on admin side + * + * @since 0.2 + * + * @param string[] $clauses List of sql clauses. + * @param string[] $taxonomies List of taxonomies. + * @param array $args WP_Term_Query arguments. + * @return string[] Modified sql clauses. + */ + public function terms_clauses( $clauses, $taxonomies, $args ) { + $lang = $this->get_queried_language( $taxonomies, $args ); + return $this->model->terms_clauses( $clauses, $lang ); + } + + /** + * Sets the WP_Term_Query language when doing a WP_Query. + * Needed since WP 4.9. + * + * @since 2.3.2 + * + * @param WP_Query $query WP_Query object. + * @return void + */ + public function set_tax_query_lang( $query ) { + $this->tax_query_lang = isset( $query->query_vars['lang'] ) ? $query->query_vars['lang'] : ''; + } + + /** + * Removes the WP_Term_Query language filter for WP_Query. + * Needed since WP 4.9. + * + * @since 2.3.2 + * + * @return void + */ + public function unset_tax_query_lang() { + unset( $this->tax_query_lang ); + } + + /** + * Called when a category or post tag is deleted + * Deletes language and translations + * + * @since 0.1 + * + * @param int $term_id + * @return void + */ + public function delete_term( $term_id ) { + $this->model->term->delete_translation( $term_id ); + $this->model->term->delete_language( $term_id ); + } +} diff --git a/wp-content/plugins/polylang/include/filters-links.php b/wp-content/plugins/polylang/include/filters-links.php index e7c55013..4696c1ef 100644 --- a/wp-content/plugins/polylang/include/filters-links.php +++ b/wp-content/plugins/polylang/include/filters-links.php @@ -1,4 +1,7 @@ options = &$polylang->options; $this->curlang = &$polylang->curlang; - // Low priority on links filters to come after any other modifications + // Low priority on links filters to come after any other modifications. if ( $this->options['force_lang'] ) { add_filter( 'post_link', array( $this, 'post_type_link' ), 20, 2 ); add_filter( '_get_page_link', array( $this, '_get_page_link' ), 20, 2 ); @@ -35,11 +67,12 @@ class PLL_Filters_Links { add_filter( 'attachment_link', array( $this, 'attachment_link' ), 20, 2 ); } - if ( 3 === $this->options['force_lang'] ) { + // Keeps the preview post link on default domain when using multiple domains and SSO is not available. + if ( 3 === $this->options['force_lang'] && ! class_exists( 'PLL_Xdata_Domain' ) ) { add_filter( 'preview_post_link', array( $this, 'preview_post_link' ), 20 ); } - // Rewrites post types archives links to filter them by language + // Rewrites post types archives links to filter them by language. add_filter( 'post_type_archive_link', array( $this, 'post_type_archive_link' ), 20, 2 ); } @@ -71,13 +104,13 @@ class PLL_Filters_Links { } /** - * Modifies custom posts links + * Modifies custom posts links. * * @since 1.6 * - * @param string $link post link - * @param object $post post object - * @return string modified post link + * @param string $link Post link. + * @param WP_Post $post Post object. + * @return string Modified post link. */ public function post_type_link( $link, $post ) { // /!\ WP does not use pretty permalinks for preview @@ -86,13 +119,13 @@ class PLL_Filters_Links { $link = $this->options['force_lang'] ? $this->links_model->switch_language_in_link( $link, $lang ) : $link; /** - * Filter a post or custom post type link + * Filters a post or custom post type link. * * @since 1.6 * - * @param string $link the post link - * @param object $lang the current language - * @param object $post the post object + * @param string $link The post link. + * @param PLL_Language $lang The current language. + * @param WP_Post $post The post object. */ $link = apply_filters( 'pll_post_type_link', $link, $lang, $post ); } @@ -101,14 +134,14 @@ class PLL_Filters_Links { } /** - * Modifies term link + * Modifies term links. * * @since 0.7 * - * @param string $link term link - * @param object $term term object - * @param string $tax taxonomy name - * @return string modified term link + * @param string $link Term link. + * @param WP_Term $term Term object. + * @param string $tax Taxonomy name; + * @return string Modified term link. */ public function term_link( $link, $term, $tax ) { if ( $this->model->is_translated_taxonomy( $tax ) ) { @@ -120,23 +153,24 @@ class PLL_Filters_Links { * * @since 1.6 * - * @param string $link the term link - * @param object $lang the current language - * @param object $term the term object + * @param string $link The term link. + * @param PLL_Language $lang The current language. + * @param WP_Term $term The term object. */ return apply_filters( 'pll_term_link', $link, $lang, $term ); } - // in case someone calls get_term_link for the 'language' taxonomy + // In case someone calls get_term_link for the 'language' taxonomy. if ( 'language' === $tax ) { - return $this->links_model->home_url( $term ); + $lang = $this->model->get_language( $term->term_id ); + return $this->links_model->home_url( $lang ); } return $link; } /** - * FIXME: keeps the preview post link on default domain when using multiple domains + * Keeps the preview post link on default domain when using multiple domains * * @since 1.6.1 * diff --git a/wp-content/plugins/polylang/include/filters-sanitization.php b/wp-content/plugins/polylang/include/filters-sanitization.php new file mode 100644 index 00000000..1bdd2a12 --- /dev/null +++ b/wp-content/plugins/polylang/include/filters-sanitization.php @@ -0,0 +1,106 @@ +locale = $locale; + + // We need specific filters for some languages like German and Danish + $specific_locales = array( 'da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal', 'ca', 'sr_RS', 'bs_BA' ); + if ( in_array( $locale, $specific_locales ) ) { + add_filter( 'sanitize_title', array( $this, 'sanitize_title' ), 10, 3 ); + add_filter( 'sanitize_user', array( $this, 'sanitize_user' ), 10, 3 ); + } + } + + /** + * Retrieve the locale code of the language. + * + * @since 2.0 + * + * @return string + */ + public function get_locale() { + return $this->locale; + } + + /** + * Maybe fix the result of sanitize_title() in case the languages include German or Danish + * Without this filter, if language of the title being sanitized is different from the language + * used for the admin interface and if one this language is German or Danish, some specific + * characters such as ä, ö, ü, ß are incorrectly sanitized. + * + * All the process is done by the remove_accents() WordPress function based on the locale value + * + * @link https://github.com/WordPress/WordPress/blob/5.5.1/wp-includes/formatting.php#L1920-L1944 + * + * @since 2.0 + * + * @param string $title Sanitized title. + * @param string $raw_title The title prior to sanitization. + * @param string $context The context for which the title is being sanitized. + * @return string + */ + public function sanitize_title( $title, $raw_title, $context ) { + static $once = false; + + if ( ! $once && 'save' == $context && ! empty( $title ) ) { + $once = true; + add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface + $title = sanitize_title( $raw_title, '', $context ); + remove_filter( 'locale', array( $this, 'get_locale' ), 20 ); + $once = false; + } + return $title; + } + + /** + * Maybe fix the result of sanitize_user() in case the languages include German or Danish + * + * All the process is done by the remove_accents() WordPress function based on the locale value + * + * @link https://github.com/WordPress/WordPress/blob/5.5-branch/wp-includes/formatting.php#L1920-L1944 + * + * @since 2.0 + * + * @param string $username Sanitized username. + * @param string $raw_username The username prior to sanitization. + * @param bool $strict Whether to limit the sanitization to specific characters. Default false. + * @return string + */ + public function sanitize_user( $username, $raw_username, $strict ) { + static $once = false; + + if ( ! $once ) { + $once = true; + add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface + $username = sanitize_user( $raw_username, $strict ); + remove_filter( 'locale', array( $this, 'get_locale' ), 20 ); + $once = false; + } + return $username; + } +} diff --git a/wp-content/plugins/polylang/include/filters-widgets-options.php b/wp-content/plugins/polylang/include/filters-widgets-options.php new file mode 100644 index 00000000..0e59ef5c --- /dev/null +++ b/wp-content/plugins/polylang/include/filters-widgets-options.php @@ -0,0 +1,93 @@ +model = $polylang->model; + + add_action( 'in_widget_form', array( $this, 'in_widget_form' ), 10, 3 ); + add_filter( 'widget_update_callback', array( $this, 'widget_update_callback' ), 10, 2 ); + } + + /** + * Add the language filter field to the widgets options form. + * + * @since 3.0 Moved PLL_Admin_Filters. + * @since 3.1 Rename lang_choice field name and id to pll_lang as the widget setting. + * + * @param WP_Widget $widget + * @param null $return + * @param array $instance + * @return void + */ + public function in_widget_form( $widget, $return, $instance ) { + $dropdown = new PLL_Walker_Dropdown(); + + $dropdown_html = $dropdown->walk( + array_merge( + array( (object) array('slug' => 0, 'name' => __( 'All languages', 'polylang' )) ), + $this->model->get_languages_list() + ), + -1, + array( + 'id' => $widget->get_field_id( 'pll_lang' ), + 'name' => $widget->get_field_name( 'pll_lang' ), + 'class' => 'tags-input pll-lang-choice', + 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'], + ) + ); + + printf( + '

', + esc_attr( $widget->get_field_id( 'pll_lang' ) ), + esc_html__( 'The widget is displayed for:', 'polylang' ), + $dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput + ); + } + + /** + * Called when widget options are saved. + * Saves the language associated to the widget. + * + * @since 0.3 + * @since 3.0 Moved from PLL_Admin_Filters. + * @since 3.1 Remove unused $old_instance and $widget parameters. + * + * @param array $instance The current Widget's options. + * @param array $new_instance The new Widget's options. + * @return array Widget options. + */ + public function widget_update_callback( $instance, $new_instance ) { + if ( ! empty( $new_instance['pll_lang'] ) && $lang = $this->model->get_language( $new_instance['pll_lang'] ) ) { + $instance['pll_lang'] = $lang->slug; + } else { + unset( $instance['pll_lang'] ); + } + + return $instance; + } + +} diff --git a/wp-content/plugins/polylang/include/filters.php b/wp-content/plugins/polylang/include/filters.php index bf0561ea..a4902a48 100644 --- a/wp-content/plugins/polylang/include/filters.php +++ b/wp-content/plugins/polylang/include/filters.php @@ -1,4 +1,7 @@ options = &$polylang->options; $this->curlang = &$polylang->curlang; + // Deletes our cache for sticky posts when the list is updated. + add_action( 'update_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) ); + add_action( 'add_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) ); + add_action( 'delete_option_sticky_posts', array( $this, 'delete_sticky_posts_cache' ) ); + // Filters the comments according to the current language add_action( 'parse_comment_query', array( $this, 'parse_comment_query' ) ); add_filter( 'comments_clauses', array( $this, 'comments_clauses' ), 10, 2 ); @@ -37,71 +69,105 @@ class PLL_Filters { // Converts the locale to a valid W3C locale add_filter( 'language_attributes', array( $this, 'language_attributes' ) ); - // Prevents deleting all the translations of the default category - add_filter( 'map_meta_cap', array( $this, 'fix_delete_default_category' ), 10, 4 ); - // Translate the site title in emails sent to users add_filter( 'password_change_email', array( $this, 'translate_user_email' ) ); add_filter( 'email_change_email', array( $this, 'translate_user_email' ) ); + + // Translates the privacy policy page + add_filter( 'option_wp_page_for_privacy_policy', array( $this, 'translate_page_for_privacy_policy' ), 20 ); // Since WP 4.9.6 + add_filter( 'map_meta_cap', array( $this, 'fix_privacy_policy_page_editing' ), 10, 4 ); + + // Personal data exporter + add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_personal_data_exporter' ), 0 ); // Since WP 4.9.6 } /** - * Get the language to filter a comments query + * Deletes the cache for multilingual sticky posts. + * + * @since 2.8.4 + * + * @return void + */ + public function delete_sticky_posts_cache() { + wp_cache_delete( 'sticky_posts', 'options' ); + } + + /** + * Get the language to filter a comments query. * * @since 2.0 + * @since 3.1 Always returns an array. Renamed from get_comments_queried_language(). * - * @param object $query - * @return object|bool the language(s) to use in the filter, false otherwise + * @param WP_Comment_Query $query WP_Comment_Query object. + * @return PLL_Language[] The languages to use in the filter. */ - protected function get_comments_queried_language( $query ) { - // Don't filter comments if comment ids or post ids are specified + protected function get_comments_queried_languages( $query ) { + // Don't filter comments if comment ids or post ids are specified. $plucked = wp_array_slice_assoc( $query->query_vars, array( 'comment__in', 'parent', 'post_id', 'post__in', 'post_parent' ) ); $fields = array_filter( $plucked ); if ( ! empty( $fields ) ) { - return false; + return array(); } - // Don't filter comments if a non translated post type is specified + // Don't filter comments if a non translated post type is specified. if ( ! empty( $query->query_vars['post_type'] ) && ! $this->model->is_translated_post_type( $query->query_vars['post_type'] ) ) { - return false; + return array(); } - return empty( $query->query_vars['lang'] ) ? $this->curlang : $this->model->get_language( $query->query_vars['lang'] ); + // If comments are queried with a 'lang' parameter, keeps only language codes. + if ( isset( $query->query_vars['lang'] ) ) { + $languages = is_string( $query->query_vars['lang'] ) ? explode( ',', $query->query_vars['lang'] ) : $query->query_vars['lang']; + if ( is_array( $languages ) ) { + $languages = array_map( array( $this->model, 'get_language' ), $languages ); + return array_filter( $languages ); + } + } + + if ( ! empty( $this->curlang ) ) { + return array( $this->curlang ); + } + + return array(); } /** - * Adds language dependent cache domain when querying comments - * Useful as the 'lang' parameter is not included in cache key by WordPress - * Needed since WP 4.6 as comments have been added to persistent cache. See #36906, #37419 + * Adds a language dependent cache domain when querying comments. + * Useful as the 'lang' parameter is not included in cache key by WordPress. + * Needed since WP 4.6 as comments have been added to persistent cache. See #36906, #37419. * * @since 2.0 * - * @param object $query + * @param WP_Comment_Query $query WP_Comment_Query object. + * @return void */ public function parse_comment_query( $query ) { - if ( $lang = $this->get_comments_queried_language( $query ) ) { - $key = '_' . ( is_array( $lang ) ? implode( ',', $lang ) : $this->model->get_language( $lang )->slug ); + $lang = $this->get_comments_queried_languages( $query ); + if ( ! empty( $lang ) ) { + $lang = wp_list_pluck( $lang, 'slug' ); + $key = '_' . implode( ',', $lang ); $query->query_vars['cache_domain'] = empty( $query->query_vars['cache_domain'] ) ? 'pll' . $key : $query->query_vars['cache_domain'] . $key; } } /** - * Filters the comments according to the current language - * Used by the recent comments widget and admin language filter + * Filters the comments according to the current language. + * Used by the recent comments widget and admin language filter. * * @since 0.2 * - * @param array $clauses sql clauses - * @param object $query WP_Comment_Query object - * @return array modified $clauses + * @param string[] $clauses SQL clauses. + * @param WP_Comment_Query $query WP_Comment_Query object. + * @return string[] Modified $clauses. */ public function comments_clauses( $clauses, $query ) { global $wpdb; - $lang = $this->get_comments_queried_language( $query ); + $lang = $this->get_comments_queried_languages( $query ); if ( ! empty( $lang ) ) { - // If this clause is not already added by WP + $lang = wp_list_pluck( $lang, 'slug' ); + + // If this clause is not already added by WP. if ( ! strpos( $clauses['join'], '.ID' ) ) { $clauses['join'] .= " JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; } @@ -113,13 +179,13 @@ class PLL_Filters { } /** - * Filters get_pages per language + * Filters get_pages() per language. * * @since 1.4 * - * @param array $pages an array of pages already queried - * @param array $args get_pages arguments - * @return array modified list of pages + * @param WP_Post[] $pages An array of pages already queried. + * @param array $args Array of get_pages() arguments. + * @return WP_Post[] Modified list of pages. */ public function get_pages( $pages, $args ) { if ( isset( $args['lang'] ) && empty( $args['lang'] ) ) { @@ -139,7 +205,7 @@ class PLL_Filters { $once = true; // avoid infinite loop $r = array( - 'lang' => 0, // So this query is not filtered + 'lang' => 0, // So this query is not filtered 'numberposts' => -1, 'nopaging' => true, 'post_type' => $args['post_type'], @@ -154,8 +220,8 @@ class PLL_Filters { ), ); - // Take care that 'exclude' argument accepts integer or strings too - $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) ); + // Take care that 'exclude' argument accepts integer or strings too. + $args['exclude'] = array_merge( wp_parse_id_list( $args['exclude'] ), get_posts( $r ) ); // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude $pages = get_pages( $args ); } @@ -182,34 +248,34 @@ class PLL_Filters { } /** - * Modifies the sql request for get_adjacent_post to filter by the current language + * Modifies the sql request for get_adjacent_post to filter by the current language. * * @since 0.1 * * @param string $sql The JOIN clause in the SQL. * @param bool $in_same_term Whether post should be in a same taxonomy term. - * @param array $excluded_terms Array of excluded term IDs. + * @param int[] $excluded_terms Array of excluded term IDs. * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. * @param WP_Post $post WP_Post object. - * @return string modified JOIN clause + * @return string Modified JOIN clause. */ - public function posts_join( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) { + public function posts_join( $sql, $in_same_term, $excluded_terms, $taxonomy, $post ) { return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->join_clause( 'p' ) : $sql; } /** - * Modifies the sql request for wp_get_archives and get_adjacent_post to filter by the current language + * Modifies the sql request for wp_get_archives and get_adjacent_post to filter by the current language. * * @since 0.1 * * @param string $sql The WHERE clause in the SQL. * @param bool $in_same_term Whether post should be in a same taxonomy term. - * @param array $excluded_terms Array of excluded term IDs. + * @param int[] $excluded_terms Array of excluded term IDs. * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. * @param WP_Post $post WP_Post object. - * @return string modified WHERE clause + * @return string Modified WHERE clause. */ - public function posts_where( $sql, $in_same_term, $excluded_terms, $taxonomy = '', $post = null ) { + public function posts_where( $sql, $in_same_term, $excluded_terms, $taxonomy, $post ) { return $this->model->is_translated_post_type( $post->post_type ) && ! empty( $this->curlang ) ? $sql . $this->model->post->where_clause( $this->curlang ) : $sql; } @@ -222,51 +288,115 @@ class PLL_Filters { * @return string */ public function language_attributes( $output ) { - if ( $language = $this->model->get_language( get_locale() ) ) { + if ( $language = $this->model->get_language( is_admin() ? get_user_locale() : get_locale() ) ) { $output = str_replace( '"' . get_bloginfo( 'language' ) . '"', '"' . $language->get_locale( 'display' ) . '"', $output ); } return $output; } - - /** - * Prevents deleting all the translations of the default category - * - * @since 2.1 - * - * @param array $caps The user's actual capabilities. - * @param string $cap Capability name. - * @param int $user_id The user ID. - * @param array $args Adds the context to the cap. The category id. - * @return array - */ - public function fix_delete_default_category( $caps, $cap, $user_id, $args ) { - if ( 'delete_term' === $cap ) { - $term = get_term( reset( $args ) ); // Since WP 4.4, we can get the term to get the taxonomy - if ( $term instanceof WP_Term ) { - $default_cat = get_option( 'default_' . $term->taxonomy ); - if ( $default_cat && array_intersect( $args, $this->model->term->get_translations( $default_cat ) ) ) { - $caps[] = 'do_not_allow'; - } - } - } - - return $caps; - } - /** * Translates the site title in emails sent to the user (change email, reset password) * It is necessary to filter the email because WP evaluates the site title before calling switch_to_locale() * * @since 2.1.3 * - * @param array $email - * @return array + * @param string[] $email Email contents. + * @return string[] Translated email contents. */ - function translate_user_email( $email ) { + public function translate_user_email( $email ) { $blog_name = wp_specialchars_decode( pll__( get_option( 'blogname' ) ), ENT_QUOTES ); $email['subject'] = sprintf( $email['subject'], $blog_name ); $email['message'] = str_replace( '###SITENAME###', $blog_name, $email['message'] ); return $email; } + + /** + * Translates the privacy policy page, on both frontend and admin + * + * @since 2.3.6 + * + * @param int $id Privacy policy page id + * @return int + */ + public function translate_page_for_privacy_policy( $id ) { + return empty( $this->curlang ) ? $id : $this->model->post->get( $id, $this->curlang ); + } + + /** + * Prevents edit and delete links for the translations of the privacy policy page for non admin + * + * @since 2.3.7 + * + * @param array $caps The user's actual capabilities. + * @param string $cap Capability name. + * @param int $user_id The user ID. + * @param array $args Adds the context to the cap. The category id. + * @return array + */ + public function fix_privacy_policy_page_editing( $caps, $cap, $user_id, $args ) { + if ( in_array( $cap, array( 'edit_page', 'edit_post', 'delete_page', 'delete_post' ) ) ) { + $privacy_page = get_option( 'wp_page_for_privacy_policy' ); + if ( $privacy_page && array_intersect( $args, $this->model->post->get_translations( $privacy_page ) ) ) { + $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) ); + } + } + + return $caps; + } + + /** + * Register our personal data exporter + * + * @since 2.3.6 + * + * @param array $exporters Personal data exporters + * @return array + */ + public function register_personal_data_exporter( $exporters ) { + $exporters[] = array( + 'exporter_friendly_name' => __( 'Translated user descriptions', 'polylang' ), + 'callback' => array( $this, 'user_data_exporter' ), + ); + return $exporters; + } + + /** + * Export translated user description as WP exports only the description in the default language + * + * @since 2.3.6 + * + * @param string $email_address User email address + * @return array Personal data + */ + public function user_data_exporter( $email_address ) { + $email_address = trim( $email_address ); + $data_to_export = array(); + $user_data_to_export = array(); + + if ( $user = get_user_by( 'email', $email_address ) ) { + foreach ( $this->model->get_languages_list() as $lang ) { + if ( $lang->slug !== $this->options['default_lang'] && $value = get_user_meta( $user->ID, 'description_' . $lang->slug, true ) ) { + $user_data_to_export[] = array( + /* translators: %s is a language native name */ + 'name' => sprintf( __( 'User description - %s', 'polylang' ), $lang->name ), + 'value' => $value, + ); + } + } + + if ( ! empty( $user_data_to_export ) ) { + $data_to_export[] = array( + 'group_id' => 'user', + 'group_label' => __( 'User', 'polylang' ), + 'item_id' => "user-{$user->ID}", + 'data' => $user_data_to_export, + ); + } + } + + return array( + 'data' => $data_to_export, + 'done' => true, + ); + } } diff --git a/wp-content/plugins/polylang/include/functions.php b/wp-content/plugins/polylang/include/functions.php index ab555743..16987f4d 100644 --- a/wp-content/plugins/polylang/include/functions.php +++ b/wp-content/plugins/polylang/include/functions.php @@ -1,8 +1,12 @@ id of term in 'language' taxonomy - * name => language name. Ex: English - * slug => language code used in url. Ex: en - * term_group => order of the language when displayed in a list of languages - * term_taxonomy_id => term taxonomy id in 'language' taxonomy - * taxonomy => 'language' - * description => language locale for backward compatibility - * parent => 0 / not used - * count => number of posts and pages in that language - * tl_term_id => id of the term in 'term_language' taxonomy - * tl_term_taxonomy_id => term taxonomy id in 'term_language' taxonomy - * tl_count => number of terms in that language ( not used by Polylang ) - * locale => WordPress language locale. Ex: en_US - * is_rtl => 1 if the language is rtl - * w3c => W3C locale - * flag_code => code of the flag - * flag_url => url of the flag - * flag => html img of the flag - * custom_flag_url => url of the custom flag if exists, internal use only, moves to flag_url on frontend - * custom_flag => html img of the custom flag if exists, internal use only, moves to flag on frontend - * home_url => home url in this language - * search_url => home url to use in search forms - * host => host of this language - * mo_id => id of the post storing strings translations - * page_on_front => id of the page on front in this language ( set from pll_languages_list filter ) - * page_for_posts => id of the page for posts in this language ( set from pll_languages_list filter ) + * A language object is made of two terms in 'language' and 'term_language' taxonomies. + * Manipulating only one object per language instead of two terms should make things easier. * * @since 1.2 */ class PLL_Language { - public $term_id, $name, $slug, $term_group, $term_taxonomy_id, $taxonomy, $description, $parent, $count; - public $tl_term_id, $tl_term_taxonomy_id, $tl_count; - public $locale, $is_rtl; - public $w3c, $facebook; - public $flag_url, $flag; - public $home_url, $search_url; - public $host, $mo_id; - public $page_on_front, $page_for_posts; + /** + * Id of the term in 'language' taxonomy. + * + * @var int + */ + public $term_id; /** - * Constructor: builds a language object given its two corresponding terms in language and term_language taxonomies + * Language name. Ex: English. + * + * @var string + */ + public $name; + + /** + * Language code used in url. Ex: en. + * + * @var string + */ + public $slug; + + /** + * Order of the language when displayed in a list of languages. + * + * @var int + */ + public $term_group; + + /** + * Term taxonomy id in 'language' taxonomy. + * + * @var int + */ + public $term_taxonomy_id; + + /** + * Number of posts and pages in that language. + * + * @var int + */ + public $count; + + /** + * Id of the term in 'term_language' taxonomy. + * + * @var int + */ + public $tl_term_id; + + /** + * Term taxonomy id in 'term_language' taxonomy. + * + * @var int + */ + public $tl_term_taxonomy_id; + + /** + * Number of terms in that language. + * + * @var int + */ + public $tl_count; + + /** + * WordPress language locale. Ex: en_US. + * + * @var string + */ + public $locale; + + /** + * 1 if the language is rtl, 0 otherwise. + * + * @var int + */ + public $is_rtl; + + /** + * W3C locale. + * + * @var string. + */ + public $w3c; + + /** + * Facebook locale. + * + * @var string. + */ + public $facebook; + + /** + * Home url in this language. + * + * @var string + */ + public $home_url; + + /** + * Home url to use in search forms. + * + * @var string + */ + public $search_url; + + /** + * Host corresponding to this language. + * + * @var string + */ + public $host; + + /** + * Id of the post storing strings translations. + * + * @var int + */ + public $mo_id; + + /** + * Id of the page on front in this language ( set from pll_languages_list filter ). + * + * @var int + */ + public $page_on_front; + + /** + * Id of the page for posts in this language ( set from pll_languages_list filter ). + * + * @var int + */ + public $page_for_posts; + + /** + * Code of the flag. + * + * @var string + */ + public $flag_code; + + /** + * Url of the flag. + * + * @var string + */ + public $flag_url; + + /** + * Html markup of the flag. + * + * @var string + */ + public $flag; + + /** + * Url of the custom flag if it exists. + * + * @var string + */ + public $custom_flag_url; + + /** + * Html markup of the custom flag if it exists. + * + * @var string + */ + public $custom_flag; + + /** + * Constructor: builds a language object given its two corresponding terms in 'language' and 'term_language' taxonomies. * * @since 1.2 * - * @param object|array $language 'language' term or language object properties stored as an array - * @param object $term_language Corresponding 'term_language' term + * @param WP_Term|array $language Term in 'language' taxonomy or language object properties stored as an array. + * @param WP_Term $term_language Corresponding 'term_language' term. */ public function __construct( $language, $term_language = null ) { - // Build the object from all properties stored as an array if ( empty( $term_language ) ) { + // Build the object from all properties stored as an array. foreach ( $language as $prop => $value ) { $this->$prop = $value; } - } - - // Build the object from taxonomies - else { - foreach ( $language as $prop => $value ) { - $this->$prop = in_array( $prop, array( 'term_id', 'term_taxonomy_id', 'count' ) ) ? (int) $language->$prop : $language->$prop; - } + } else { + // Build the object from taxonomy terms. + $this->term_id = (int) $language->term_id; + $this->name = $language->name; + $this->slug = $language->slug; + $this->term_group = (int) $language->term_group; + $this->term_taxonomy_id = (int) $language->term_taxonomy_id; + $this->count = (int) $language->count; $this->tl_term_id = (int) $term_language->term_id; $this->tl_term_taxonomy_id = (int) $term_language->term_taxonomy_id; $this->tl_count = (int) $term_language->count; - // The description field can contain any property - // Backward compatibility for is_rtl + // The description field can contain any property. $description = maybe_unserialize( $language->description ); foreach ( $description as $prop => $value ) { 'rtl' == $prop ? $this->is_rtl = $value : $this->$prop = $value; } - $this->description = &$this->locale; // Backward compatibility with Polylang < 1.2 - $this->mo_id = PLL_MO::get_id( $this ); - include PLL_SETTINGS_INC . '/languages.php'; + $languages = include POLYLANG_DIR . '/settings/languages.php'; $this->w3c = isset( $languages[ $this->locale ]['w3c'] ) ? $languages[ $this->locale ]['w3c'] : str_replace( '_', '-', $this->locale ); if ( isset( $languages[ $this->locale ]['facebook'] ) ) { $this->facebook = $languages[ $this->locale ]['facebook']; @@ -90,41 +222,121 @@ class PLL_Language { } /** - * sets flag_url and flag properties + * Get the flag informations: * - * @since 1.2 + * @since 2.6 + * + * @param string $code Flag code. + * @return array { + * Flag informations. + * + * @type string $url Flag url. + * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. + * @type int $width Optional, flag width in pixels. + * @type int $height Optional, flag height in pixels. + * } */ - public function set_flag() { - $flags['flag']['url'] = ''; + public static function get_flag_informations( $code ) { + $flag = array( 'url' => '' ); - // Polylang builtin flags - if ( ! empty( $this->flag_code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $this->flag_code . '.png' ) ) ) { - $flags['flag']['url'] = esc_url_raw( plugins_url( $file, POLYLANG_FILE ) ); + // Polylang builtin flags. + if ( ! empty( $code ) && file_exists( POLYLANG_DIR . ( $file = '/flags/' . $code . '.png' ) ) ) { + $flag['url'] = plugins_url( $file, POLYLANG_FILE ); - // If base64 encoded flags are preferred + // If base64 encoded flags are preferred. if ( ! defined( 'PLL_ENCODED_FLAGS' ) || PLL_ENCODED_FLAGS ) { - $flags['flag']['src'] = 'data:image/png;base64,' . base64_encode( file_get_contents( POLYLANG_DIR . $file ) ); - } else { - $flags['flag']['src'] = esc_url( plugins_url( $file, POLYLANG_FILE ) ); + list( $flag['width'], $flag['height'] ) = getimagesize( POLYLANG_DIR . $file ); + $file_contents = file_get_contents( POLYLANG_DIR . $file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents + $flag['src'] = 'data:image/png;base64,' . base64_encode( $file_contents ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode } } - // Custom flags ? - if ( file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.png' ) ) || file_exists( PLL_LOCAL_DIR . ( $file = '/' . $this->locale . '.jpg' ) ) ) { - $url = content_url( '/polylang' . $file ); - $flags['custom_flag']['url'] = esc_url_raw( $url ); - $flags['custom_flag']['src'] = esc_url( $url ); + /** + * Filters flag informations: + * + * @since 2.4 + * + * @param array $flag { + * Information about the flag. + * + * @type string $url Flag url. + * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. + * @type int $width Optional, flag width in pixels. + * @type int $height Optional, flag height in pixels. + * } + * @param string $code Flag code. + */ + $flag = apply_filters( 'pll_flag', $flag, $code ); + + $flag['url'] = esc_url_raw( $flag['url'] ); + + if ( empty( $flag['src'] ) ) { + $flag['src'] = esc_url( set_url_scheme( $flag['url'], 'relative' ) ); + } + + return $flag; + } + + /** + * Sets flag_url and flag properties. + * + * @since 1.2 + * + * @return void + */ + public function set_flag() { + $flags = array( 'flag' => self::get_flag_informations( $this->flag_code ) ); + + // Custom flags? + $directories = array( + PLL_LOCAL_DIR, + get_stylesheet_directory() . '/polylang', + get_template_directory() . '/polylang', + ); + + foreach ( $directories as $dir ) { + if ( file_exists( $file = "{$dir}/{$this->locale}.png" ) || file_exists( $file = "{$dir}/{$this->locale}.jpg" ) || file_exists( $file = "{$dir}/{$this->locale}.svg" ) ) { + $flags['custom_flag']['url'] = content_url( '/' . str_replace( WP_CONTENT_DIR, '', $file ) ); + break; + } } /** - * Filter the flag title attribute - * Defaults to the language name + * Filters the custom flag informations. + * + * @param array $flag { + * Information about the custom flag. + * + * @type string $url Flag url. + * @type string $src Optional, src attribute value if different of the url, for example if base64 encoded. + * @type int $width Optional, flag width in pixels. + * @type int $height Optional, flag height in pixels. + * } + * @param string $code Flag code. + * + * @since 2.4 + */ + $flags['custom_flag'] = apply_filters( 'pll_custom_flag', empty( $flags['custom_flag'] ) ? null : $flags['custom_flag'], $this->flag_code ); + + if ( ! empty( $flags['custom_flag']['url'] ) ) { + if ( empty( $flags['custom_flag']['src'] ) ) { + $flags['custom_flag']['src'] = esc_url( set_url_scheme( $flags['custom_flag']['url'], 'relative' ) ); + } + + $flags['custom_flag']['url'] = esc_url_raw( $flags['custom_flag']['url'] ); + } else { + unset( $flags['custom_flag'] ); + } + + /** + * Filters the flag title attribute. + * Defaults to the language name. * * @since 0.7 * - * @param string $title the flag title attribute - * @param string $slug the language code - * @param string $locale the language locale + * @param string $title The flag title attribute. + * @param string $slug The language code. + * @param string $locale The language locale. */ $title = apply_filters( 'pll_flag_title', $this->name, $this->slug, $this->locale ); @@ -132,66 +344,105 @@ class PLL_Language { $this->{$key . '_url'} = empty( $flag['url'] ) ? '' : $flag['url']; /** - * Filter the html markup of a flag + * Filters the html markup of a flag. * * @since 1.0.2 * - * @param string $flag html markup of the flag or empty string - * @param string $slug language code + * @param string $flag Html markup of the flag or empty string. + * @param string $slug Language code. */ - $this->{$key} = apply_filters( 'pll_get_flag', empty( $flag['src'] ) ? '' : - sprintf( - '%s', - $flag['src'], - esc_attr( $title ), - esc_attr( $this->name ) - ), + $this->{$key} = apply_filters( + 'pll_get_flag', + self::get_flag_html( $flag, $title, $this->name ), $this->slug ); } } /** - * Replace flag by custom flag - * Takes care of url scheme + * Get HTML code for flag. * - * @since 1.7 + * @since 2.7 + * + * @param array $flag Flag properties: src, width and height. + * @param string $title Optional title attribute. + * @param string $alt Optional alt attribute. + * @return string */ - public function set_custom_flag() { - // Overwrite with custom flags on frontend only - if ( ! empty( $this->custom_flag ) ) { - $this->flag = $this->custom_flag; - $this->flag_url = $this->custom_flag_url; - unset( $this->custom_flag, $this->custom_flag_url ); // hide this + public static function get_flag_html( $flag, $title = '', $alt = '' ) { + if ( empty( $flag['src'] ) ) { + return ''; } - // Set url scheme, also for default flags - if ( is_ssl() ) { - $this->flag = str_replace( 'http://', 'https://', $this->flag ); - $this->flag_url = str_replace( 'http://', 'https://', $this->flag_url ); - } else { - $this->flag = str_replace( 'https://', 'http://', $this->flag ); - $this->flag_url = str_replace( 'https://', 'http://', $this->flag_url ); + $alt_attr = empty( $alt ) ? '' : sprintf( ' alt="%s"', esc_attr( $alt ) ); + $width_attr = empty( $flag['width'] ) ? '' : sprintf( ' width="%s"', (int) $flag['width'] ); + $height_attr = empty( $flag['height'] ) ? '' : sprintf( ' height="%s"', (int) $flag['height'] ); + + $style = ''; + $sizes = array_intersect_key( $flag, array_flip( array( 'width', 'height' ) ) ); + + if ( ! empty( $sizes ) ) { + array_walk( + $sizes, + function ( &$value, $key ) { + $value = sprintf( '%s: %dpx;', esc_attr( $key ), (int) $value ); + } + ); + $style = sprintf( ' style="%s"', implode( ' ', $sizes ) ); } + + return sprintf( + '', + $flag['src'], + $alt_attr, + $width_attr, + $height_attr, + $style + ); } /** - * Updates post and term count + * Returns the html of the custom flag if any, or the default flag otherwise. + * + * @since 2.8 + * + * @return string + */ + public function get_display_flag() { + return empty( $this->custom_flag ) ? $this->flag : $this->custom_flag; + } + + /** + * Returns the url of the custom flag if any, or the default flag otherwise. + * + * @since 2.8 + * + * @return string + */ + public function get_display_flag_url() { + return empty( $this->custom_flag_url ) ? $this->flag_url : $this->custom_flag_url; + } + + /** + * Updates post and term count. * * @since 1.2 + * + * @return void */ public function update_count() { - wp_update_term_count( $this->term_taxonomy_id, 'language' ); // posts count - wp_update_term_count( $this->tl_term_taxonomy_id, 'term_language' ); // terms count + wp_update_term_count( $this->term_taxonomy_id, 'language' ); // Posts count. + wp_update_term_count( $this->tl_term_taxonomy_id, 'term_language' ); // Terms count. } /** - * Set home_url and search_url properties + * Set home_url and search_url properties. * * @since 1.3 * - * @param string $search_url - * @param string $home_url + * @param string $search_url Home url to use in search forms. + * @param string $home_url Home url. + * @return void */ public function set_home_url( $search_url, $home_url ) { $this->search_url = $search_url; @@ -199,30 +450,32 @@ class PLL_Language { } /** - * Set home_url scheme - * this can't be cached across pages + * Sets the scheme of the home url and the flag urls. * - * @since 1.6.4 + * This can't be cached across pages. + * + * @since 2.8 + * + * @return void */ - public function set_home_url_scheme() { - if ( is_ssl() ) { - $this->home_url = str_replace( 'http://', 'https://', $this->home_url ); - $this->search_url = str_replace( 'http://', 'https://', $this->search_url ); - } + public function set_url_scheme() { + $this->home_url = set_url_scheme( $this->home_url ); + $this->search_url = set_url_scheme( $this->search_url ); - else { - $this->home_url = str_replace( 'https://', 'http://', $this->home_url ); - $this->search_url = str_replace( 'https://', 'http://', $this->search_url ); + // Set url scheme, also for the flags. + $this->flag_url = set_url_scheme( $this->flag_url ); + if ( ! empty( $this->custom_flag_url ) ) { + $this->custom_flag_url = set_url_scheme( $this->custom_flag_url ); } } /** - * Returns the language locale - * Converts WP locales to W3C valid locales for display + * Returns the language locale. + * Converts WP locales to W3C valid locales for display. * * @since 1.8 * - * @param string $filter either 'display' or 'raw', defaults to raw + * @param string $filter Either 'display' or 'raw', defaults to raw. * @return string */ public function get_locale( $filter = 'raw' ) { diff --git a/wp-content/plugins/polylang/include/license.php b/wp-content/plugins/polylang/include/license.php index 80e48bb3..4fe4b8dd 100644 --- a/wp-content/plugins/polylang/include/license.php +++ b/wp-content/plugins/polylang/include/license.php @@ -1,4 +1,7 @@ id = sanitize_title( $item_name ); $this->file = $file; $this->name = $item_name; @@ -37,6 +92,7 @@ class PLL_License { // Updater add_action( 'admin_init', array( $this, 'auto_updater' ), 0 ); + add_action( 'cli_init', array( $this, 'auto_updater' ), 0 ); // For WP CLI. // Register settings add_filter( 'pll_settings_licenses', array( $this, 'settings' ) ); @@ -53,6 +109,8 @@ class PLL_License { * Auto updater * * @since 1.9 + * + * @return void */ public function auto_updater() { $args = array( @@ -128,10 +186,17 @@ class PLL_License { * @since 1.9 * * @param string $request check_license | activate_license | deactivate_license + * @return void */ private function api_request( $request ) { $licenses = get_option( 'polylang_licenses' ); - unset( $licenses[ $this->id ], $this->license_data ); + + if ( is_array( $licenses ) ) { + unset( $licenses[ $this->id ] ); + } else { + $licenses = array(); + } + unset( $this->license_data ); if ( ! empty( $this->license_key ) ) { // Data to send in our API request @@ -146,7 +211,7 @@ class PLL_License { $response = wp_remote_post( $this->api_url, array( - 'timeout' => 15, + 'timeout' => 3, 'sslverify' => false, 'body' => $api_params, ) @@ -168,4 +233,123 @@ class PLL_License { update_option( 'polylang_licenses', $licenses ); // FIXME called multiple times when saving all licenses } + + /** + * Get the html form field in a table row (one per license key) for display + * + * @since 2.7 + * + * @return string + */ + public function get_form_field() { + if ( ! empty( $this->license_data ) ) { + $license = $this->license_data; + } + + $class = 'license-null'; + $message = ''; + + $out = sprintf( + '' . + '', + esc_attr( $this->id ), + esc_attr( $this->name ), + esc_html( $this->license_key ) + ); + + if ( ! empty( $license ) && is_object( $license ) ) { + $now = time(); + $expiration = isset( $license->expires ) ? strtotime( $license->expires ) : false; + + // Special case: the license expired after the last check + if ( $license->success && $expiration && $expiration < $now ) { + $license->success = false; + $license->error = 'expired'; + } + + if ( false === $license->success ) { + $class = 'notice-error notice-alt'; + + switch ( $license->error ) { + case 'expired': + $message = sprintf( + /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ + esc_html__( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), + esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), + sprintf( '
', 'https://polylang.pro/account/' ), + '' + ); + break; + + case 'disabled': + case 'revoked': + $message = esc_html__( 'Your license key has been disabled.', 'polylang' ); + break; + + case 'missing': + $message = sprintf( + /* translators: %1$s is link start tag, %2$s is link end tag. */ + esc_html__( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ), + sprintf( '', 'https://polylang.pro/account/' ), + '' + ); + break; + + case 'invalid': + case 'site_inactive': + $message = sprintf( + /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */ + esc_html__( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ), + esc_html( $this->name ), + sprintf( '', 'https://polylang.pro/account/' ), + '' + ); + break; + + case 'item_name_mismatch': + /* translators: %s is a product name */ + $message = sprintf( esc_html__( 'This is not a %s license key.', 'polylang' ), esc_html( $this->name ) ); + break; + + case 'no_activations_left': + $message = sprintf( + /* translators: %1$s is link start tag, %2$s is link end tag */ + esc_html__( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ), + sprintf( '', 'https://polylang.pro/account/' ), + '' + ); + break; + } + } else { + $class = 'license-valid'; + + $out .= sprintf( '', esc_attr( $this->id ), esc_html__( 'Deactivate', 'polylang' ) ); + + if ( 'lifetime' === $license->expires ) { + $message = esc_html__( 'The license key never expires.', 'polylang' ); + } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { + $class = 'notice-warning notice-alt'; + $message = sprintf( + /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ + esc_html__( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ), + esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ), + sprintf( '', 'https://polylang.pro/account/' ), + '' + ); + } else { + $message = sprintf( + /* translators: %s is a date */ + esc_html__( 'Your license key expires on %s.', 'polylang' ), + esc_html( date_i18n( get_option( 'date_format' ), $expiration ) ) + ); + } + } + } + + if ( ! empty( $message ) ) { + $out .= '

' . $message . '

'; + } + + return sprintf( '%s', esc_attr( $this->id ), $class, $out ); + } } diff --git a/wp-content/plugins/polylang/include/links-abstract-domain.php b/wp-content/plugins/polylang/include/links-abstract-domain.php index 9539376a..ba1772d7 100644 --- a/wp-content/plugins/polylang/include/links-abstract-domain.php +++ b/wp-content/plugins/polylang/include/links-abstract-domain.php @@ -1,4 +1,7 @@ get_hosts() ) ) ? $lang : ''; } /** - * Sets the home urls + * Sets the home urls. * * @since 2.2 * - * @param object $language + * @param PLL_Language $language Language object. */ protected function set_home_url( $language ) { $home_url = $this->home_url( $language ); - $language->set_home_url( $home_url, $home_url ); // Search url and home url are the same + $language->set_home_url( $home_url, $home_url ); // Search url and home url are the same. } /** diff --git a/wp-content/plugins/polylang/include/links-default.php b/wp-content/plugins/polylang/include/links-default.php index ba2e2175..29f960de 100644 --- a/wp-content/plugins/polylang/include/links-default.php +++ b/wp-content/plugins/polylang/include/links-default.php @@ -1,4 +1,7 @@ options['hide_default'] && $this->options['default_lang'] == $lang->slug ) ? $url : add_query_arg( 'lang', $lang->slug, $url ); @@ -46,7 +54,7 @@ class PLL_Links_Default extends PLL_Links_Model { * @param string $url url to modify * @return string modified url */ - function remove_paged_from_link( $url ) { + public function remove_paged_from_link( $url ) { return remove_query_arg( 'paged', $url ); } @@ -75,7 +83,7 @@ class PLL_Links_Default extends PLL_Links_Model { */ public function get_language_from_url( $url = '' ) { if ( empty( $url ) ) { - $url = $_SERVER['REQUEST_URI']; + $url = pll_get_requested_url(); } $pattern = '#lang=(' . implode( '|', $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) . ')#'; @@ -83,12 +91,12 @@ class PLL_Links_Default extends PLL_Links_Model { } /** - * Returns the static front page url + * Returns the static front page url. * * @since 1.8 * - * @param object $lang - * @return string + * @param PLL_Language $lang The language object. + * @return string The static front page url. */ public function front_page_url( $lang ) { if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) { diff --git a/wp-content/plugins/polylang/include/links-directory.php b/wp-content/plugins/polylang/include/links-directory.php index 8140cc79..4eebd6a1 100644 --- a/wp-content/plugins/polylang/include/links-directory.php +++ b/wp-content/plugins/polylang/include/links-directory.php @@ -1,4 +1,7 @@ options['rewrite'] ? '' : 'language/'; $slug = $this->options['default_lang'] == $lang->slug && $this->options['hide_default'] ? '' : $base . $lang->slug . '/'; - $root = ( false === strpos( $url, '://' ) ) ? $this->home_relative . $this->root : $this->home . '/' . $this->root; + $root = ( false === strpos( $url, '://' ) ) ? $this->home_relative . $this->root : preg_replace( '#^https?://#', '://', $this->home . '/' . $this->root ); if ( false === strpos( $url, $new = $root . $slug ) ) { - $pattern = str_replace( '/', '\/', $root ); + $pattern = preg_quote( $root, '#' ); $pattern = '#' . $pattern . '#'; return preg_replace( $pattern, $new, $url, 1 ); // Only once } @@ -79,7 +89,9 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { * @param string $url url to modify * @return string modified url */ - function remove_language_from_link( $url ) { + public function remove_language_from_link( $url ) { + $languages = array(); + foreach ( $this->model->get_languages_list() as $language ) { if ( ! $this->options['hide_default'] || $this->options['default_lang'] != $language->slug ) { $languages[] = $language->slug; @@ -87,10 +99,10 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { } if ( ! empty( $languages ) ) { - $root = ( false === strpos( $url, '://' ) ) ? $this->home_relative . $this->root : $this->home . '/' . $this->root; + $root = ( false === strpos( $url, '://' ) ) ? $this->home_relative . $this->root : preg_replace( '#^https?://#', '://', $this->home . '/' . $this->root ); - $pattern = str_replace( '/', '\/', $root ); - $pattern = '#' . $pattern . ( $this->options['rewrite'] ? '' : 'language\/' ) . '(' . implode( '|', $languages ) . ')(\/|$)#'; + $pattern = preg_quote( $root, '#' ); + $pattern = '#' . $pattern . ( $this->options['rewrite'] ? '' : 'language/' ) . '(' . implode( '|', $languages ) . ')(/|$)#'; $url = preg_replace( $pattern, $root, $url ); } return $url; @@ -108,26 +120,25 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { */ public function get_language_from_url( $url = '' ) { if ( empty( $url ) ) { - $path = $_SERVER['REQUEST_URI']; - } else { - $path = parse_url( $url, PHP_URL_PATH ); + $url = pll_get_requested_url(); } + $path = wp_parse_url( $url, PHP_URL_PATH ); $root = ( false === strpos( $url, '://' ) ) ? $this->home_relative . $this->root : $this->home . '/' . $this->root; - $pattern = parse_url( $root . ( $this->options['rewrite'] ? '' : 'language/' ), PHP_URL_PATH ); - $pattern = str_replace( '/', '\/', $pattern ); - $pattern = '#' . $pattern . '(' . implode( '|', $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) . ')(\/|$)#'; + $pattern = wp_parse_url( $root . ( $this->options['rewrite'] ? '' : 'language/' ), PHP_URL_PATH ); + $pattern = preg_quote( $pattern, '#' ); + $pattern = '#^' . $pattern . '(' . implode( '|', $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) . ')(/|$)#'; return preg_match( $pattern, trailingslashit( $path ), $matches ) ? $matches[1] : ''; // $matches[1] is the slug of the requested language } /** - * Returns the home url - * links_model interface + * Returns the home url in a given language. + * links_model interface. * * @since 1.3.1 * - * @param object $lang PLL_Language object + * @param PLL_Language $lang PLL_Language object. * @return string */ public function home_url( $lang ) { @@ -140,8 +151,10 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { * Optionally removes 'language' in permalinks so that we get http://www.myblog/en/ instead of http://www.myblog/language/en/ * * @since 1.2 + * + * @return void */ - function add_permastruct() { + public function add_permastruct() { // Language information always in front of the uri ( 'with_front' => false ) // The 3rd parameter structure has been modified in WP 3.4 // Leads to error 404 for pages when there is no language created yet @@ -151,12 +164,12 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { } /** - * Prepares rewrite rules filters + * Prepares the rewrite rules filters. * * @since 0.8.1 * - * @param array $pre not used - * @return unmodified $pre + * @param mixed $pre Not used as the filter is used as an action. + * @return mixed */ public function prepare_rewrite_rules( $pre ) { // Don't modify the rules if there is no languages created yet @@ -176,13 +189,13 @@ class PLL_Links_Directory extends PLL_Links_Permalinks { /** * The rewrite rules ! - * always make sure the default language is at the end in case the language information is hidden for default language - * thanks to brbrbr http://wordpress.org/support/topic/plugin-polylang-rewrite-rules-not-correct + * Always make sure that the default language is at the end in case the language information is hidden for default language. + * Thanks to brbrbr http://wordpress.org/support/topic/plugin-polylang-rewrite-rules-not-correct. * * @since 0.8.1 * - * @param array $rules rewrite rules - * @return array modified rewrite rules + * @param string[] $rules Rewrite rules. + * @return string[] Modified rewrite rules. */ public function rewrite_rules( $rules ) { $filter = str_replace( '_rewrite_rules', '', current_filter() ); diff --git a/wp-content/plugins/polylang/include/links-domain.php b/wp-content/plugins/polylang/include/links-domain.php index 7473330b..e11aa921 100644 --- a/wp-content/plugins/polylang/include/links-domain.php +++ b/wp-content/plugins/polylang/include/links-domain.php @@ -1,4 +1,7 @@ hosts[ $lang->slug ] ) ) { - $url = preg_replace( '#:\/\/(' . parse_url( $this->home, PHP_URL_HOST ) . ')($|\/.*)#', '://' . $this->hosts[ $lang->slug ] . '$2', $url ); + $url = preg_replace( '#://(' . wp_parse_url( $this->home, PHP_URL_HOST ) . ')($|/.*)#', '://' . $this->hosts[ $lang->slug ] . '$2', $url ); } return $url; } @@ -54,36 +64,44 @@ class PLL_Links_Domain extends PLL_Links_Abstract_Domain { */ public function remove_language_from_link( $url ) { if ( ! empty( $this->hosts ) ) { - $url = preg_replace( '#:\/\/(' . implode( '|', $this->hosts ) . ')($|\/.*)#', '://' . parse_url( $this->home, PHP_URL_HOST ) . '$2', $url ); + $url = preg_replace( '#://(' . implode( '|', $this->hosts ) . ')($|/.*)#', '://' . wp_parse_url( $this->home, PHP_URL_HOST ) . '$2', $url ); } return $url; } /** - * Returns the home url - * links_model interface + * Returns the home url in a given language. + * links_model interface. * * @since 1.3.1 * - * @param object $lang PLL_Language object + * @param PLL_Language $lang PLL_Language object. * @return string */ - function home_url( $lang ) { + public function home_url( $lang ) { return trailingslashit( empty( $this->options['domains'][ $lang->slug ] ) ? $this->home : $this->options['domains'][ $lang->slug ] ); } /** - * Get hosts managed on the website + * Get hosts managed on the website. * * @since 1.5 * - * @return array list of hosts + * @return string[] List of hosts. */ public function get_hosts() { $hosts = array(); foreach ( $this->options['domains'] as $lang => $domain ) { - $hosts[ $lang ] = parse_url( $domain, PHP_URL_HOST ); + $host = wp_parse_url( $domain, PHP_URL_HOST ); + // idn_to_ascii is much faster than the WordPress method. + if ( function_exists( 'idn_to_ascii' ) ) { + // The use of the constant is mandatory in PHP 7.2 and PHP 7.3 to avoid a deprecated notice. + $hosts[ $lang ] = defined( 'INTL_IDNA_VARIANT_UTS46' ) ? idn_to_ascii( $host, 0, INTL_IDNA_VARIANT_UTS46 ) : idn_to_ascii( $host ); + } else { + $hosts[ $lang ] = Requests_IDNAEncoder::encode( $host ); + } } + return $hosts; } } diff --git a/wp-content/plugins/polylang/include/links-model.php b/wp-content/plugins/polylang/include/links-model.php index 6e850616..78181138 100644 --- a/wp-content/plugins/polylang/include/links-model.php +++ b/wp-content/plugins/polylang/include/links-model.php @@ -1,43 +1,131 @@ model = &$model; + $this->model = &$model; $this->options = &$model->options; $this->home = home_url(); - add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // after PLL_Static_Pages + add_filter( 'pll_languages_list', array( $this, 'pll_languages_list' ), 4 ); // After PLL_Static_Pages. add_filter( 'pll_after_languages_cache', array( $this, 'pll_after_languages_cache' ) ); - // adds our domains or subdomains to allowed hosts for safe redirection + // Adds our domains or subdomains to allowed hosts for safe redirection. add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) ); } /** - * Changes the language code in url + * Adds the language code in url. + * + * @since 1.2 + * + * @param string $url The url to modify. + * @param PLL_Language $lang The language object. + * @return string Modified url. + */ + abstract public function add_language_to_link( $url, $lang ); + + /** + * Returns the url without language code. + * + * @since 1.2 + * + * @param string $url The url to modify. + * @return string Modified url. + */ + abstract public function remove_language_from_link( $url ); + + /** + * Returns the link to the first page. + * + * @since 1.2 + * + * @param string $url The url to modify. + * @return string Modified url. + */ + abstract public function remove_paged_from_link( $url ); + + /** + * Returns the link to a paged page. * * @since 1.5 * - * @param string $url url to modify - * @param object $lang language - * @return string modified url + * @param string $url The url to modify. + * @param int $page The page number. + * @return string Modified url. + */ + abstract public function add_paged_to_link( $url, $page ); + + /** + * Returns the language based on language code in url. + * + * @since 1.2 + * @since 2.0 add $url argument. + * + * @param string $url Optional, defaults to thej current url. + * @return string Language slug. + */ + abstract public function get_language_from_url( $url = '' ); + + /** + * Returns the static front page url. + * + * @since 1.8 + * + * @param PLL_Language $lang The language object. + * @return string The static front page url. + */ + abstract public function front_page_url( $lang ); + + /** + * Changes the language code in url. + * + * @since 1.5 + * + * @param string $url The url to modify. + * @param PLL_Language $lang The language object. + * @return string Modified url. */ public function switch_language_in_link( $url, $lang ) { $url = $this->remove_language_from_link( $url ); @@ -45,22 +133,22 @@ abstract class PLL_Links_Model { } /** - * Get hosts managed on the website + * Get hosts managed on the website. * * @since 1.5 * - * @return array list of hosts + * @return string[] The list of hosts. */ public function get_hosts() { - return array( parse_url( $this->home, PHP_URL_HOST ) ); + return array( wp_parse_url( $this->home, PHP_URL_HOST ) ); } /** - * Returns the home url + * Returns the home url in a given language. * * @since 1.3.1 * - * @param object $lang PLL_Language object + * @param PLL_Language $lang PLL_Language object. * @return string */ public function home_url( $lang ) { @@ -69,25 +157,29 @@ abstract class PLL_Links_Model { } /** - * Sets the home urls + * Sets the home urls in PLL_Language. * * @since 1.8 * - * @param object $language + * @param PLL_Language $language PLL_Language object. + * @return void */ protected function set_home_url( $language ) { - $search_url = $this->home_url( $language ); - $home_url = empty( $language->page_on_front ) || $this->options['redirect_lang'] ? $search_url : $this->front_page_url( $language ); - $language->set_home_url( $search_url, $home_url ); + // We should always have a default language here, except, temporarily, in PHPUnit tests. The test here protects against PHP notices. + if ( isset( $this->options['default_lang'] ) ) { + $search_url = $this->home_url( $language ); + $home_url = empty( $language->page_on_front ) || $this->options['redirect_lang'] ? $search_url : $this->front_page_url( $language ); + $language->set_home_url( $search_url, $home_url ); + } } /** - * Sets the home urls and flags before the languages are persistently cached + * Sets the home urls and flags before the languages are persistently cached. * * @since 1.8 * - * @param array $languages array of PLL_Language objects - * @return array + * @param PLL_Language[] $languages Array of PLL_Language objects. + * @return PLL_Language[] Array of PLL_Language objects with home url and flag. */ public function pll_languages_list( $languages ) { foreach ( $languages as $language ) { @@ -98,34 +190,34 @@ abstract class PLL_Links_Model { } /** - * Sets the home urls when not cached - * Sets the home urls scheme + * Sets the home urls when not cached. + * Sets the home urls scheme. * * @since 1.8 * - * @param array $languages array of PLL_Language objects - * @return array + * @param PLL_Language[] $languages Array of PLL_Language objects. + * @return PLL_Language[] Array of PLL_Language objects. */ public function pll_after_languages_cache( $languages ) { foreach ( $languages as $language ) { - // Get the home urls when not cached + // Get the home urls when not cached. if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || ( defined( 'PLL_CACHE_HOME_URL' ) && ! PLL_CACHE_HOME_URL ) ) { $this->set_home_url( $language ); } - // Ensures that the ( possibly cached ) home url uses the right scheme http or https - $language->set_home_url_scheme(); + // Ensures that the ( possibly cached ) home and flag urls use the right scheme http or https. + $language->set_url_scheme(); } return $languages; } /** - * Adds our domains or subdomains to allowed hosts for safe redirection + * Adds our domains or subdomains to allowed hosts for safe redirect. * * @since 1.4.3 * - * @param array $hosts allowed hosts - * @return array + * @param string[] $hosts Allowed hosts. + * @return string[] Modified list of allowed hosts. */ public function allowed_redirect_hosts( $hosts ) { return array_unique( array_merge( $hosts, array_values( $this->get_hosts() ) ) ); diff --git a/wp-content/plugins/polylang/include/links-permalinks.php b/wp-content/plugins/polylang/include/links-permalinks.php index 93b14202..0d9ee665 100644 --- a/wp-content/plugins/polylang/include/links-permalinks.php +++ b/wp-content/plugins/polylang/include/links-permalinks.php @@ -1,4 +1,7 @@ use_trailing_slashes ? '/' : '', $url ), $url ); + return apply_filters( 'pll_remove_paged_from_link', preg_replace( '#/page/[0-9]+/?#', $this->use_trailing_slashes ? '/' : '', $url ), $url ); } /** @@ -70,11 +105,11 @@ abstract class PLL_Links_Permalinks extends PLL_Links_Model { } /** - * Returns the home url + * Returns the home url. * * @since 1.3.1 * - * @param object $lang PLL_Language object + * @param PLL_Language $lang PLL_Language object. * @return string */ public function home_url( $lang ) { @@ -82,12 +117,12 @@ abstract class PLL_Links_Permalinks extends PLL_Links_Model { } /** - * Returns the static front page url + * Returns the static front page url. * * @since 1.8 * - * @param object $lang - * @return string + * @param PLL_Language $lang The language object. + * @return string The static front page url. */ public function front_page_url( $lang ) { if ( $this->options['hide_default'] && $lang->slug == $this->options['default_lang'] ) { @@ -102,6 +137,8 @@ abstract class PLL_Links_Permalinks extends PLL_Links_Model { * Prepares rewrite rules filters * * @since 1.6 + * + * @return string[] */ public function get_rewrite_rules_filters() { // Make sure we have the right post types and taxonomies diff --git a/wp-content/plugins/polylang/include/links-subdomain.php b/wp-content/plugins/polylang/include/links-subdomain.php index d1a553d6..5dfbe856 100644 --- a/wp-content/plugins/polylang/include/links-subdomain.php +++ b/wp-content/plugins/polylang/include/links-subdomain.php @@ -1,4 +1,7 @@ slug . '.' ) ) { @@ -49,6 +58,8 @@ class PLL_Links_Subdomain extends PLL_Links_Abstract_Domain { * @return string modified url */ public function remove_language_from_link( $url ) { + $languages = array(); + foreach ( $this->model->get_languages_list() as $language ) { if ( ! $this->options['hide_default'] || $this->options['default_lang'] != $language->slug ) { $languages[] = $language->slug; @@ -56,23 +67,23 @@ class PLL_Links_Subdomain extends PLL_Links_Abstract_Domain { } if ( ! empty( $languages ) ) { - $url = preg_replace( '#:\/\/(' . implode( '|', $languages ) . ')\.#', $this->www, $url ); + $url = preg_replace( '#://(' . implode( '|', $languages ) . ')\.#', $this->www, $url ); } return $url; } /** - * Get hosts managed on the website + * Get hosts managed on the website. * * @since 1.5 * - * @return array list of hosts + * @return string[] The list of hosts. */ public function get_hosts() { $hosts = array(); foreach ( $this->model->get_languages_list() as $lang ) { - $hosts[ $lang->slug ] = parse_url( $this->home_url( $lang ), PHP_URL_HOST ); + $hosts[ $lang->slug ] = wp_parse_url( $this->home_url( $lang ), PHP_URL_HOST ); } return $hosts; } diff --git a/wp-content/plugins/polylang/include/links.php b/wp-content/plugins/polylang/include/links.php index d7baa9c3..052b545f 100644 --- a/wp-content/plugins/polylang/include/links.php +++ b/wp-content/plugins/polylang/include/links.php @@ -1,4 +1,7 @@ model->get_language( $language ); return $is_search ? $language->search_url : $language->home_url; } - - /** - * Checks if the current user can read the post - * - * @since 1.5 - * - * @param int $post_id - * @return bool - */ - public function current_user_can_read( $post_id ) { - $post = get_post( $post_id ); - - if ( 'inherit' === $post->post_status && $post->post_parent ) { - $post = get_post( $post->post_parent ); - } - - if ( 'inherit' === $post->post_status || in_array( $post->post_status, get_post_stati( array( 'public' => true ) ) ) ) { - return true; - } - - // Follow WP practices, which shows links to private posts ( when readable ), but not for draft posts ( ex: get_adjacent_post_link() ) - if ( in_array( $post->post_status, get_post_stati( array( 'private' => true ) ) ) ) { - $post_type_object = get_post_type_object( $post->post_type ); - $user = wp_get_current_user(); - return is_user_logged_in() && ( current_user_can( $post_type_object->cap->read_private_posts ) || $user->ID == $post->post_author ); // Comparison must not be strict! - } - - return false; - } } diff --git a/wp-content/plugins/polylang/include/mo.php b/wp-content/plugins/polylang/include/mo.php index d307b30f..f0f25850 100644 --- a/wp-content/plugins/polylang/include/mo.php +++ b/wp-content/plugins/polylang/include/mo.php @@ -1,4 +1,7 @@ add_entry( $this->make_entry( '', '' ) ); // Empty string translation, just in case - // Would be convenient to store the whole object but it would take a huge space in DB - // So let's keep only the strings in an array + /* + * It would be convenient to store the whole object but it would take a huge space in DB. + * So let's keep only the strings in an array. + * The strings are slashed to avoid breaking slashed strings in update_post_meta. + * @see https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping. + */ $strings = array(); foreach ( $this->entries as $entry ) { - $strings[] = array( $entry->singular, $this->translate( $entry->singular ) ); + $strings[] = wp_slash( array( $entry->singular, $this->translate( $entry->singular ) ) ); } - $strings = wp_slash( $strings ); // Avoid breaking slashed strings in update_post_meta. See https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping - if ( empty( $lang->mo_id ) ) { $post = array( 'post_title' => 'polylang_mo_' . $lang->term_id, @@ -55,11 +61,12 @@ class PLL_MO extends MO { } /** - * Reads a PLL_MO object from a custom post meta + * Reads a PLL_MO object from a custom post meta. * * @since 1.2 * - * @param object $lang The language in which we want to get strings + * @param PLL_Language $lang The language in which we want to get strings. + * @return void */ public function import_from_db( $lang ) { if ( ! empty( $lang->mo_id ) ) { @@ -73,11 +80,11 @@ class PLL_MO extends MO { } /** - * Returns the post id of the post storing the strings translations + * Returns the post id of the post storing the strings translations. * * @since 1.4 * - * @param object $lang + * @param PLL_Language $lang The language object. * @return int */ public static function get_id( $lang ) { @@ -98,8 +105,22 @@ class PLL_MO extends MO { * Invalidate the cache when adding a new language * * @since 2.0.5 + * + * @return void */ public function clean_cache() { wp_cache_delete( 'polylang_mo_ids' ); } + + /** + * Deletes a string + * + * @since 2.9 + * + * @param string $string The source string to remove from the translations. + * @return void + */ + public function delete_entry( $string ) { + unset( $this->entries[ $string ] ); + } } diff --git a/wp-content/plugins/polylang/include/model.php b/wp-content/plugins/polylang/include/model.php index 097c814f..9e3ac94c 100644 --- a/wp-content/plugins/polylang/include/model.php +++ b/wp-content/plugins/polylang/include/model.php @@ -1,4 +1,7 @@ options = &$options; $this->cache = new PLL_Cache(); - $this->post = new PLL_Translated_Post( $this ); // translated post sub model - $this->term = new PLL_Translated_Term( $this ); // translated term sub model + $this->post = new PLL_Translated_Post( $this ); // Translated post sub model. + $this->term = new PLL_Translated_Term( $this ); // Translated term sub model. - // we need to clean languages cache when editing a language and when modifying the permalink structure + // We need to clean languages cache when editing a language and when modifying the permalink structure. add_action( 'edited_term_taxonomy', array( $this, 'clean_languages_cache' ), 10, 2 ); add_action( 'update_option_permalink_structure', array( $this, 'clean_languages_cache' ) ); add_action( 'update_option_siteurl', array( $this, 'clean_languages_cache' ) ); @@ -34,29 +61,27 @@ class PLL_Model { add_filter( 'get_terms_args', array( $this, 'get_terms_args' ) ); - // just in case someone would like to display the language description ;- ) + // Just in case someone would like to display the language description ;). add_filter( 'language_description', '__return_empty_string' ); } /** - * Returns the list of available languages - * caches the list in a db transient ( except flags ), unless PLL_CACHE_LANGUAGES is set to false - * caches the list ( with flags ) in the private property $languages - * - * list of parameters accepted in $args: - * - * hide_empty => hides languages with no posts if set to true ( defaults to false ) - * fields => return only that field if set ( see PLL_Language for a list of fields ) + * Returns the list of available languages. + * - Stores the list in a db transient ( except flags ), unless PLL_CACHE_LANGUAGES is set to false. + * - Caches the list ( with flags ) in a PLL_Cache object. * * @since 0.1 * - * @param array $args - * @return array|string|int list of PLL_Language objects or PLL_Language object properties + * @param array $args { + * @type bool $hide_empty Hides languages with no posts if set to true ( defaults to false ). + * @type string $fields Returns only that field if set; {@see PLL_Language} for a list of fields. + * } + * @return array List of PLL_Language objects or PLL_Language object properties. */ public function get_languages_list( $args = array() ) { if ( false === $languages = $this->cache->get( 'languages' ) ) { - // create the languages from taxonomies + // Create the languages from taxonomies. if ( ( defined( 'PLL_CACHE_LANGUAGES' ) && ! PLL_CACHE_LANGUAGES ) || false === ( $languages = get_transient( 'pll_languages_list' ) ) ) { $languages = get_terms( 'language', array( 'hide_empty' => false, 'orderby' => 'term_group' ) ); $languages = empty( $languages ) || is_wp_error( $languages ) ? array() : $languages; @@ -66,56 +91,51 @@ class PLL_Model { array() : array_combine( wp_list_pluck( $term_languages, 'slug' ), $term_languages ); if ( ! empty( $languages ) && ! empty( $term_languages ) ) { - // don't use array_map + create_function to instantiate an autoloaded class as it breaks badly in old versions of PHP + // Don't use array_map + create_function() to instantiate an autoloaded class as it breaks badly in old versions of PHP. foreach ( $languages as $k => $v ) { $languages[ $k ] = new PLL_Language( $v, $term_languages[ 'pll_' . $v->slug ] ); } - // we will need the languages list to allow its access in the filter below + // We will need the languages list to allow its access in the filter below. $this->cache->set( 'languages', $languages ); /** - * Filter the list of languages *before* it is stored in the persistent cache - * /!\ this filter is fired *before* the $polylang object is available + * Filters the list of languages *before* it is stored in the persistent cache. + * /!\ This filter is fired *before* the $polylang object is available. * * @since 1.7.5 * - * @param array $languages the list of language objects - * @param object $model PLL_Model object + * @param PLL_Language[] $languages The list of language objects. + * @param PLL_Model $model PLL_Model object. */ $languages = apply_filters( 'pll_languages_list', $languages, $this ); - // don't store directly objects as it badly break with some hosts ( GoDaddy ) due to race conditions when using object cache - // thanks to captin411 for catching this! - // see https://wordpress.org/support/topic/fatal-error-pll_model_languages_list?replies=8#post-6782255; + /* + * Don't store directly objects as it badly break with some hosts ( GoDaddy ) due to race conditions when using object cache. + * Thanks to captin411 for catching this! + * @see https://wordpress.org/support/topic/fatal-error-pll_model_languages_list?replies=8#post-6782255 + */ set_transient( 'pll_languages_list', array_map( 'get_object_vars', $languages ) ); } else { - $languages = array(); // in case something went wrong + $languages = array(); // In case something went wrong. } } - // create the languages directly from arrays stored in transients + // Create the languages directly from arrays stored in transients. else { foreach ( $languages as $k => $v ) { $languages[ $k ] = new PLL_Language( $v ); } } - // custom flags - if ( ! PLL_ADMIN ) { - foreach ( $languages as $language ) { - $language->set_custom_flag(); - } - } - /** - * Filter the list of languages *after* it is stored in the persistent cache - * /!\ this filter is fired *before* the $polylang object is available + * Filters the list of languages *after* it is stored in the persistent cache. + * /!\ This filter is fired *before* the $polylang object is available. * * @since 1.8 * - * @param array $languages the list of language objects + * @param PLL_Language[] $languages The list of language objects. */ $languages = apply_filters( 'pll_after_languages_cache', $languages ); $this->cache->set( 'languages', $languages ); @@ -123,7 +143,7 @@ class PLL_Model { $args = wp_parse_args( $args, array( 'hide_empty' => false ) ); - // remove empty languages if requested + // Remove empty languages if requested. if ( $args['hide_empty'] ) { $languages = wp_list_filter( $languages, array( 'count' => 0 ), 'NOT' ); } @@ -140,6 +160,7 @@ class PLL_Model { * * @param int $term not used * @param string $taxonomy taxonomy name + * @return void */ public function clean_languages_cache( $term = 0, $taxonomy = null ) { if ( empty( $taxonomy ) || 'language' == $taxonomy ) { @@ -164,12 +185,12 @@ class PLL_Model { } /** - * Returns the language by its term_id, tl_term_id, slug or locale + * Returns the language by its term_id, tl_term_id, slug or locale. * * @since 0.1 * - * @param int|string $value term_id, tl_term_id, slug or locale of the queried language - * @return object|bool PLL_Language object, false if no language found + * @param mixed $value term_id, tl_term_id, slug or locale of the queried language. + * @return PLL_Language|false Language object, false if no language found. */ public function get_language( $value ) { if ( is_object( $value ) ) { @@ -182,6 +203,7 @@ class PLL_Model { $this->cache->set( 'language:' . $lang->tl_term_id, $lang ); $this->cache->set( 'language:' . $lang->slug, $lang ); $this->cache->set( 'language:' . $lang->locale, $lang ); + $this->cache->set( 'language:' . $lang->w3c, $lang ); } $return = $this->cache->get( 'language:' . $value ); } @@ -190,13 +212,13 @@ class PLL_Model { } /** - * Adds terms clauses to get_terms to filter them by languages - used in both frontend and admin + * Adds terms clauses to the term query to filter them by languages. * * @since 1.2 * - * @param array $clauses the list of sql clauses in terms query - * @param object $lang PLL_Language object - * @return array modified list of clauses + * @param string[] $clauses The list of sql clauses in terms query. + * @param PLL_Language $lang PLL_Language object. + * @return string[] Modified list of clauses. */ public function terms_clauses( $clauses, $lang ) { if ( ! empty( $lang ) && false === strpos( $clauses['join'], 'pll_tr' ) ) { @@ -207,18 +229,19 @@ class PLL_Model { } /** - * Returns post types that need to be translated - * the post types list is cached for better better performance - * wait for 'after_setup_theme' to apply the cache to allow themes adding the filter in functions.php + * Returns post types that need to be translated. + * The post types list is cached for better better performance. + * The method waits for 'after_setup_theme' to apply the cache + * to allow themes adding the filter in functions.php. * * @since 1.2 * - * @param bool $filter true if we should return only valid registered post types - * @return array post type names for which Polylang manages languages and translations + * @param bool $filter True if we should return only valid registered post types. + * @return string[] Post type names for which Polylang manages languages and translations. */ public function get_translated_post_types( $filter = true ) { if ( false === $post_types = $this->cache->get( 'post_types' ) ) { - $post_types = array( 'post' => 'post', 'page' => 'page' ); + $post_types = array( 'post' => 'post', 'page' => 'page', 'wp_block' => 'wp_block' ); if ( ! empty( $this->options['media_support'] ) ) { $post_types['attachment'] = 'attachment'; @@ -229,15 +252,15 @@ class PLL_Model { } /** - * Filter the list of post types available for translation. + * Filters the list of post types available for translation. * The default are post types which have the parameter ‘public’ set to true. * The filter must be added soon in the WordPress loading process: * in a function hooked to ‘plugins_loaded’ or directly in functions.php for themes. * * @since 0.8 * - * @param array $post_types list of post type names - * @param bool $is_settings true when displaying the list of custom post types in Polylang settings + * @param string[] $post_types List of post type names. + * @param bool $is_settings True when displaying the list of custom post types in Polylang settings. */ $post_types = apply_filters( 'pll_get_post_types', $post_types, false ); @@ -250,11 +273,11 @@ class PLL_Model { } /** - * Returns true if Polylang manages languages and translations for this post type + * Returns true if Polylang manages languages and translations for this post type. * * @since 1.2 * - * @param string|array $post_type post type name or array of post type names + * @param string|string[] $post_type Post type name or array of post type names. * @return bool */ public function is_translated_post_type( $post_type ) { @@ -263,12 +286,12 @@ class PLL_Model { } /** - * Return taxonomies that need to be translated + * Returns taxonomies that need to be translated. * * @since 1.2 * - * @param bool $filter true if we should return only valid registered taxonomies - * @return array array of registered taxonomy names for which Polylang manages languages and translations + * @param bool $filter True if we should return only valid registered taxonomies. + * @return string[] Array of registered taxonomy names for which Polylang manages languages and translations. */ public function get_translated_taxonomies( $filter = true ) { if ( false === $taxonomies = $this->cache->get( 'taxonomies' ) ) { @@ -279,15 +302,15 @@ class PLL_Model { } /** - * Filter the list of taxonomies available for translation. + * Filters the list of taxonomies available for translation. * The default are taxonomies which have the parameter ‘public’ set to true. * The filter must be added soon in the WordPress loading process: * in a function hooked to ‘plugins_loaded’ or directly in functions.php for themes. * * @since 0.8 * - * @param array $taxonomies list of taxonomy names - * @param bool $is_settings true when displaying the list of custom taxonomies in Polylang settings + * @param string[] $taxonomies List of taxonomy names. + * @param bool $is_settings True when displaying the list of custom taxonomies in Polylang settings. */ $taxonomies = apply_filters( 'pll_get_taxonomies', $taxonomies, false ); if ( did_action( 'after_setup_theme' ) ) { @@ -299,11 +322,11 @@ class PLL_Model { } /** - * Returns true if Polylang manages languages and translations for this taxonomy + * Returns true if Polylang manages languages and translations for this taxonomy. * * @since 1.2 * - * @param string|array $tax taxonomy name or array of taxonomy names + * @param string|string[] $tax Taxonomy name or array of taxonomy names. * @return bool */ public function is_translated_taxonomy( $tax ) { @@ -312,12 +335,12 @@ class PLL_Model { } /** - * Return taxonomies that need to be filtered ( post_format like ) + * Return staxonomies that need to be filtered ( post_format like ). * * @since 1.7 * - * @param bool $filter true if we should return only valid registered taxonomies - * @return array array of registered taxonomy names + * @param bool $filter True if we should return only valid registered taxonomies. + * @return string[] Array of registered taxonomy names. */ public function get_filtered_taxonomies( $filter = true ) { if ( did_action( 'after_setup_theme' ) ) { @@ -328,15 +351,15 @@ class PLL_Model { $taxonomies = array( 'post_format' => 'post_format' ); /** - * Filter the list of taxonomies not translatable but filtered by language. + * Filters the list of taxonomies not translatable but filtered by language. * Includes only the post format by default * The filter must be added soon in the WordPress loading process: * in a function hooked to ‘plugins_loaded’ or directly in functions.php for themes. * * @since 1.7 * - * @param array $taxonomies list of taxonomy names - * @param bool $is_settings true when displaying the list of custom taxonomies in Polylang settings + * @param string[] $taxonomies List of taxonomy names. + * @param bool $is_settings True when displaying the list of custom taxonomies in Polylang settings. */ $taxonomies = apply_filters( 'pll_filtered_taxonomies', $taxonomies, false ); } @@ -345,11 +368,11 @@ class PLL_Model { } /** - * Returns true if Polylang filters this taxonomy per language + * Returns true if Polylang filters this taxonomy per language. * * @since 1.7 * - * @param string|array $tax taxonomy name or array of taxonomy names + * @param string|string[] $tax Taxonomy name or array of taxonomy names. * @return bool */ public function is_filtered_taxonomy( $tax ) { @@ -358,7 +381,7 @@ class PLL_Model { } /** - * Returns the query vars of all filtered taxonomies + * Returns the query vars of all filtered taxonomies. * * @since 1.7 * @@ -368,65 +391,31 @@ class PLL_Model { $query_vars = array(); foreach ( $this->get_filtered_taxonomies() as $filtered_tax ) { $tax = get_taxonomy( $filtered_tax ); - $query_vars[] = $tax->query_var; + if ( ! empty( $tax ) ) { + $query_vars[] = $tax->query_var; + } } return $query_vars; } - /** - * Create a default category for a language - * - * @since 1.2 - * - * @param object|string|int $lang language - */ - public function create_default_category( $lang ) { - $lang = $this->get_language( $lang ); - - // create a new category - // FIXME this is translated in admin language when we would like it in $lang - $cat_name = __( 'Uncategorized' ); - $cat_slug = sanitize_title( $cat_name . '-' . $lang->slug ); - $cat = wp_insert_term( $cat_name, 'category', array( 'slug' => $cat_slug ) ); - - // check that the category was not previously created ( in case the language was deleted and recreated ) - $cat = isset( $cat->error_data['term_exists'] ) ? $cat->error_data['term_exists'] : $cat['term_id']; - - // set language - $this->term->set_language( (int) $cat, $lang ); - - // this is a translation of the default category - $default = (int) get_option( 'default_category' ); - $translations = $this->term->get_translations( $default ); - if ( empty( $translations ) ) { - if ( $lg = $this->term->get_language( $default ) ) { - $translations[ $lg->slug ] = $default; - } - else { - $translations = array(); - } - } - - $this->term->save_translations( (int) $cat, $translations ); - } - /** * It is possible to have several terms with the same name in the same taxonomy ( one per language ) - * but the native term_exists will return true even if only one exists - * so here the function adds the language parameter + * but the native term_exists() will return true even if only one exists. + * So here the function adds the language parameter. * * @since 1.4 * - * @param string $term_name the term name - * @param string $taxonomy taxonomy name - * @param int $parent parent term id - * @param string|object $language the language slug or object - * @return null|int the term_id of the found term + * @param string $term_name The term name. + * @param string $taxonomy Taxonomy name. + * @param int $parent Parent term id. + * @param string|PLL_Language $language The language slug or object. + * @return null|int The term_id of the found term. */ public function term_exists( $term_name, $taxonomy, $parent, $language ) { global $wpdb; $term_name = trim( wp_unslash( $term_name ) ); + $term_name = _wp_specialchars( $term_name ); $select = "SELECT t.term_id FROM $wpdb->terms AS t"; $join = " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; @@ -438,22 +427,69 @@ class PLL_Model { $where .= $wpdb->prepare( ' AND tt.parent = %d', $parent ); } + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared return $wpdb->get_var( $select . $join . $where ); } /** - * Gets the number of posts per language in a date, author or post type archive + * Checks if a term slug exists in a given language, taxonomy, hierarchy. + * + * @since 1.9 + * @since 2.8 Moved from PLL_Share_Term_Slug::term_exists() to PLL_Model::term_exists_by_slug(). + * + * @param string $slug The term slug to test. + * @param string|PLL_Language $language The language slug or object. + * @param string $taxonomy Optional taxonomy name. + * @param int $parent Optional parent term id. + * @return null|int The term_id of the found term. + */ + public function term_exists_by_slug( $slug, $language, $taxonomy = '', $parent = 0 ) { + global $wpdb; + + $select = "SELECT t.term_id FROM {$wpdb->terms} AS t"; + $join = " INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id"; + $join .= $this->term->join_clause(); + $where = $wpdb->prepare( ' WHERE t.slug = %s', $slug ); + $where .= $this->term->where_clause( $this->get_language( $language ) ); + + if ( ! empty( $taxonomy ) ) { + $where .= $wpdb->prepare( ' AND tt.taxonomy = %s', $taxonomy ); + } + + if ( $parent > 0 ) { + $where .= $wpdb->prepare( ' AND tt.parent = %d', $parent ); + } + + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + return $wpdb->get_var( $select . $join . $where ); + } + + + /** + * Gets the number of posts per language in a date, author or post type archive. * * @since 1.2 * - * @param object $lang - * @param array $q WP_Query arguments ( accepted: post_type, m, year, monthnum, day, author, author_name, post_format ) + * @param PLL_Language $lang PLL_Language instance. + * @param array $q { + * WP_Query arguments: + * + * @type string|string[] $post_type Post type or array of post types. + * @type int $m Combination YearMonth. Accepts any four-digit year and month. + * @type int $year Four-digit year. + * @type int $monthnum Two-digit month. + * @type int $day Day of the month. + * @type int $author Author id. + * @type string $author_name User 'user_nicename'. + * @type string $post_format Post format. + * @type string $post_status Post status. + * } * @return int */ public function count_posts( $lang, $q = array() ) { global $wpdb; - $q = wp_parse_args( $q, array( 'post_type' => 'post' ) ); + $q = wp_parse_args( $q, array( 'post_type' => 'post', 'post_status' => 'publish' ) ); if ( ! is_array( $q['post_type'] ) ) { $q['post_type'] = array( $q['post_type'] ); @@ -466,17 +502,17 @@ class PLL_Model { } if ( empty( $q['post_type'] ) ) { - $q['post_type'] = array( 'post' ); // we *need* a post type + $q['post_type'] = array( 'post' ); // We *need* a post type. } - $cache_key = md5( serialize( $q ) ); - $counts = wp_cache_get( $cache_key, 'pll_count_posts' ); + $cache_key = 'pll_count_posts_' . md5( maybe_serialize( $q ) ); + $counts = wp_cache_get( $cache_key, 'counts' ); if ( false === $counts ) { $select = "SELECT pll_tr.term_taxonomy_id, COUNT( * ) AS num_posts FROM {$wpdb->posts}"; $join = $this->post->join_clause(); - $where = " WHERE post_status = 'publish'"; - $where .= sprintf( " AND {$wpdb->posts}.post_type IN ( '%s' )", join( "', '", esc_sql( $q['post_type'] ) ) ); + $where = sprintf( " WHERE post_status = '%s'", esc_sql( $q['post_status'] ) ); + $where .= sprintf( " AND {$wpdb->posts}.post_type IN ( '%s' )", implode( "', '", esc_sql( $q['post_type'] ) ) ); $where .= $this->post->where_clause( $this->get_languages_list() ); $groupby = ' GROUP BY pll_tr.term_taxonomy_id'; @@ -514,7 +550,7 @@ class PLL_Model { $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $q['author'] ); } - // filtered taxonomies ( post_format ) + // Filtered taxonomies ( post_format ). foreach ( $this->get_filtered_taxonomies_query_vars() as $tax_qv ) { if ( ! empty( $q[ $tax_qv ] ) ) { @@ -525,35 +561,36 @@ class PLL_Model { } } + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared $res = $wpdb->get_results( $select . $join . $where . $groupby, ARRAY_A ); foreach ( (array) $res as $row ) { $counts[ $row['term_taxonomy_id'] ] = $row['num_posts']; } - wp_cache_set( $cache_key, $counts, 'pll_count_posts' ); + wp_cache_set( $cache_key, $counts, 'counts' ); } return empty( $counts[ $lang->term_taxonomy_id ] ) ? 0 : $counts[ $lang->term_taxonomy_id ]; } /** - * Setup the links model based on options + * Setup the links model based on options. * * @since 1.2 * - * @return object implementing "links_model interface" + * @return PLL_Links_Model */ public function get_links_model() { $c = array( 'Directory', 'Directory', 'Subdomain', 'Domain' ); $class = get_option( 'permalink_structure' ) ? 'PLL_Links_' . $c[ $this->options['force_lang'] ] : 'PLL_Links_Default'; /** - * Filter the links model class to use - * /!\ this filter is fired *before* the $polylang object is available + * Filters the links model class to use. + * /!\ this filter is fired *before* the $polylang object is available. * * @since 2.1.1 * - * @param string $class A class name: PLL_Links_Default, PLL_Links_Directory, PLL_Links_Subdomain, PLL_Links_Domain + * @param string $class A class name: PLL_Links_Default, PLL_Links_Directory, PLL_Links_Subdomain, PLL_Links_Domain. */ $class = apply_filters( 'pll_links_model', $class ); @@ -561,65 +598,109 @@ class PLL_Model { } /** - * Some backward compatibility with Polylang < 1.8 - * allows for example to call $polylang->model->get_post_languages( $post_id ) instead of $polylang->model->post->get_language( $post_id ) - * this works but should be slower than the direct call, thus an error is triggered in debug mode + * Returns posts and terms ids without language ( used in settings ). * - * @since 1.8 + * @since 0.9 + * @since 2.2.6 Add the $limit argument. * - * @param string $func Function name - * @param array $args Function arguments + * @param int $limit Max number of posts or terms to return. Defaults to -1 (no limit). + * @return array { + * Objects without language. + * + * @type int[] $posts Array of post ids. + * @type int[] $terms Array of term ids. + * } */ - public function __call( $func, $args ) { - $f = $func; + public function get_objects_with_no_lang( $limit = -1 ) { + /** + * Filters the max number of posts or terms to return when searching objects with no language. + * This filter can be used to decrease the memory usage in case the number of objects + * without language is too big. Using a negative value is equivalent to have no limit. + * + * @since 2.2.6 + * + * @param int $limit Max number of posts or terms to retrieve from the database. + */ + $limit = (int) apply_filters( 'get_objects_with_no_lang_limit', $limit ); - switch ( $func ) { - case 'get_object_term': - $o = ( false === strpos( $args[1], 'term' ) ) ? 'post' : 'term'; - break; + $posts = $this->get_posts_with_no_lang( $this->get_translated_post_types(), $limit ); + $terms = $this->get_terms_with_no_lang( $this->get_translated_taxonomies(), $limit ); - case 'save_translations': - case 'delete_translation': - case 'get_translations': - case 'get_translation': - case 'join_clause': - $o = ( 'post' == $args[0] || $this->is_translated_post_type( $args[0] ) ) ? 'post' : ( 'term' == $args[0] || $this->is_translated_taxonomy( $args[0] ) ? 'term' : false ); - unset( $args[0] ); - break; + /** + * Filters the list of untranslated posts ids and terms ids + * + * @since 0.9 + * + * @param array|false $objects false if no ids found, list of post and/or term ids otherwise. + */ + return apply_filters( 'pll_get_objects_with_no_lang', empty( $posts ) && empty( $terms ) ? false : array( 'posts' => $posts, 'terms' => $terms ) ); + } - case 'set_post_language': - case 'get_post_language': - case 'set_term_language': - case 'get_term_language': - case 'delete_term_language': - case 'get_post': - case 'get_term': - $str = explode( '_', $func ); - $f = empty( $str[2] ) ? $str[0] : $str[0] . '_' . $str[2]; - $o = $str[1]; - break; + /** + * Returns ids of post without language. + * + * @since 3.1 + * + * @param string|string[] $post_types A translated post type or an array of translated post types. + * @param int $limit Max number of posts to return. + * @return int[] + */ + public function get_posts_with_no_lang( $post_types, $limit ) { + return get_posts( + array( + 'numberposts' => $limit, + 'nopaging' => $limit <= 0, + 'post_type' => $post_types, + 'post_status' => 'any', + 'fields' => 'ids', + 'tax_query' => array( + array( + 'taxonomy' => 'language', + 'terms' => $this->get_languages_list( array( 'fields' => 'term_id' ) ), + 'operator' => 'NOT IN', + ), + ), + ) + ); + } - case 'where_clause': - case 'get_objects_in_language': - $o = $args[1]; - unset( $args[1] ); - break; + /** + * Returns ids of terms without language. + * + * @since 3.1 + * + * @param string|string[] $taxonomies A translated taxonomy or an array of taxonomies post types. + * @param int $limit Max number of terms to return. + * @return int[] + */ + public function get_terms_with_no_lang( $taxonomies, $limit ) { + global $wpdb; + + $taxonomies = (array) $taxonomies; + + $sql = sprintf( + "SELECT {$wpdb->term_taxonomy}.term_id FROM {$wpdb->term_taxonomy} + WHERE taxonomy IN ('%s') + AND {$wpdb->term_taxonomy}.term_id NOT IN ( + SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN (%s) + ) + %s", + implode( "','", array_map( 'esc_sql', $taxonomies ) ), + implode( ',', array_map( 'intval', $this->get_languages_list( array( 'fields' => 'tl_term_taxonomy_id' ) ) ) ), + $limit > 0 ? sprintf( 'LIMIT %d', intval( $limit ) ) : '' + ); + + $key = md5( $sql ); + $last_changed = wp_cache_get_last_changed( 'terms' ); + $cache_key = "terms_no_lang:{$key}:{$last_changed}"; + + $term_ids = wp_cache_get( $cache_key, 'terms' ); + + if ( false === $term_ids ) { + $term_ids = $wpdb->get_col( $sql ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + wp_cache_set( $cache_key, $term_ids, 'terms' ); } - if ( ! empty( $o ) && is_object( $this->$o ) && method_exists( $this->$o, $f ) ) { - if ( WP_DEBUG ) { - $debug = debug_backtrace(); - $i = 1 + empty( $debug[1]['line'] ); // the file and line are in $debug[2] if the function was called using call_user_func - - trigger_error( sprintf( - '%1$s was called incorrectly in %4$s on line %5$s: the call to $polylang->model->%1$s() has been deprecated in Polylang 1.8, use PLL()->model->%2$s->%3$s() instead.' . "\nError handler", - $func, $o, $f, $debug[ $i ]['file'], $debug[ $i ]['line'] - ) ); - } - return call_user_func_array( array( $this->$o, $f ), $args ); - } - - $debug = debug_backtrace(); - trigger_error( sprintf( 'Call to undefined function PLL()->model->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR ); + return $term_ids; } } diff --git a/wp-content/plugins/polylang/include/nav-menu.php b/wp-content/plugins/polylang/include/nav-menu.php index d34028ec..bd6e01c6 100644 --- a/wp-content/plugins/polylang/include/nav-menu.php +++ b/wp-content/plugins/polylang/include/nav-menu.php @@ -1,16 +1,43 @@ model = &$polylang->model; $this->options = &$polylang->options; - // integration with WP customizer + $this->theme = get_option( 'stylesheet' ); + + add_filter( 'wp_setup_nav_menu_item', array( $this, 'wp_setup_nav_menu_item' ) ); + + // Integration with WP customizer add_action( 'customize_register', array( $this, 'create_nav_menu_locations' ), 5 ); + + // Filter _wp_auto_add_pages_to_menu by language + add_action( 'transition_post_status', array( $this, 'auto_add_pages_to_menu' ), 5, 3 ); // before _wp_auto_add_pages_to_menu } /** - * create temporary nav menu locations ( one per location and per language ) for all non-default language + * Assigns the title and label to the language switcher menu items + * + * @since 2.6 + * + * @param stdClass $item Menu item. + * @return stdClass + */ + public function wp_setup_nav_menu_item( $item ) { + if ( isset( $item->url ) && '#pll_switcher' === $item->url ) { + $item->post_title = __( 'Languages', 'polylang' ); + $item->type_label = __( 'Language switcher', 'polylang' ); + } + return $item; + } + + /** + * Create temporary nav menu locations ( one per location and per language ) for all non-default language * to do only one time * * @since 1.2 + * + * @return void */ public function create_nav_menu_locations() { static $once; global $_wp_registered_nav_menus; + $arr = array(); + if ( isset( $_wp_registered_nav_menus ) && ! $once ) { foreach ( $_wp_registered_nav_menus as $loc => $name ) { foreach ( $this->model->get_languages_list() as $lang ) { @@ -47,12 +101,12 @@ class PLL_Nav_Menu { } /** - * creates a temporary nav menu location from a location and a language + * Creates a temporary nav menu location from a location and a language * * @since 1.8 * - * @param string $loc nav menu location - * @param object $lang + * @param string $loc Nav menu location. + * @param PLL_Language $lang Language object. * @return string */ public function combine_location( $loc, $lang ) { @@ -60,14 +114,15 @@ class PLL_Nav_Menu { } /** - * get nav menu locations and language from a temporary location + * Get nav menu locations and language from a temporary location. * * @since 1.8 * - * @param string $loc temporary location - * @return array - * 'location' => nav menu location - * 'lang' => language slug + * @param string $loc Temporary location. + * @return string[] { + * @type string $location Nav menu location. + * @type string $lang Language code. + * } */ public function explode_location( $loc ) { $infos = explode( '___', $loc ); @@ -76,4 +131,47 @@ class PLL_Nav_Menu { } return array_combine( array( 'location', 'lang' ), $infos ); } + + /** + * Filters the option nav_menu_options for auto added pages to menu + * + * @since 0.9.4 + * + * @param array $options + * @return array Modified options + */ + public function nav_menu_options( $options ) { + $options['auto_add'] = array_intersect( $options['auto_add'], $this->auto_add_menus ); + return $options; + } + + /** + * Filters _wp_auto_add_pages_to_menu by language. + * + * @since 0.9.4 + * + * @param string $new_status Transition to this post status. + * @param string $old_status Previous post status. + * @param WP_Post $post Post object. + * @return void + */ + public function auto_add_pages_to_menu( $new_status, $old_status, $post ) { + if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type || ! empty( $post->post_parent ) ) { + return; + } + + if ( ! empty( $this->options['nav_menus'][ $this->theme ] ) ) { + $lang = $this->model->post->get_language( $post->ID ); + $lang = empty( $lang ) ? $this->options['default_lang'] : $lang->slug; // If the page has no language yet, the default language will be assigned + + // Get all the menus in the page language + foreach ( $this->options['nav_menus'][ $this->theme ] as $loc ) { + if ( ! empty( $loc[ $lang ] ) ) { + $this->auto_add_menus[] = $loc[ $lang ]; + } + } + + add_filter( 'option_nav_menu_options', array( $this, 'nav_menu_options' ) ); + } + } } diff --git a/wp-content/plugins/polylang/include/olt-manager.php b/wp-content/plugins/polylang/include/olt-manager.php index 6ff52615..a1211d09 100644 --- a/wp-content/plugins/polylang/include/olt-manager.php +++ b/wp-content/plugins/polylang/include/olt-manager.php @@ -1,4 +1,7 @@ list_textdomains ) ) { - - // Since WP 4.7 we need to reset the internal cache of _get_path_to_translation when switching from any locale to en_US - // See WP_Locale_Switcher::change_locale() - // FIXME test _get_path_to_translation for backward compatibility with WP < 4.7 - if ( function_exists( '_get_path_to_translation' ) ) { - _get_path_to_translation( null, true ); + /* + * FIXME: Backward compatibility with WP < 5.6 + * From WP 4.7 to 5.5, we need to reset the internal cache of _get_path_to_translation when switching from any locale to en_US. + * See WP_Locale_Switcher::change_locale() + */ + if ( ! class_exists( 'WP_Textdomain_Registry' ) && function_exists( '_get_path_to_translation' ) ) { + _get_path_to_translation( '', true ); } foreach ( $this->list_textdomains as $textdomain ) { @@ -137,38 +163,23 @@ class PLL_OLT_Manager { } /** - * FIXME: Backward compatibility with Polylang for WooCommerce < 0.3.4 - * To remove in Polylang 2.1 - * - * @since 0.1 - * - * @param bool $bool not used - * @param string $domain text domain name - * @param string $mofile translation file name - * @return bool - */ - public function mofile( $bool, $domain, $mofile ) { - return $bool; - } - - /** - * Saves all text domains in a table for later usage - * It replaces the 'override_load_textdomain' filter used since 0.1 + * Saves all text domains in a table for later usage. + * It replaces the 'override_load_textdomain' filter previously used. * * @since 2.0.4 * - * @param string $mofile translation file name - * @param string $domain text domain name - * @return bool + * @param string $mofile The translation file name. + * @param string $domain The text domain name. + * @return string */ public function load_textdomain_mofile( $mofile, $domain ) { - // On multisite, 2 files are sharing the same domain so we need to distinguish them + // On multisite, 2 files are sharing the same domain so we need to distinguish them. if ( 'default' === $domain && false !== strpos( $mofile, '/ms-' ) ) { $this->list_textdomains['ms-default'] = array( 'mo' => $mofile, 'domain' => $domain ); } else { $this->list_textdomains[ $domain ] = array( 'mo' => $mofile, 'domain' => $domain ); } - return ''; // Hack to prevent WP loading text domains as we will load them all later + return ''; // Hack to prevent WP loading text domains as we will load them all later. } /** @@ -205,22 +216,25 @@ class PLL_OLT_Manager { } /** - * Translates post types and taxonomies labels once the language is known + * Translates post types and taxonomies labels once the language is known. * * @since 0.9 * - * @param object $type either a post type or a taxonomy + * @param WP_Post_Type|WP_Taxonomy $type Either a post type or a taxonomy. + * @return void */ public function translate_labels( $type ) { // Use static array to avoid translating several times the same ( default ) labels static $translated = array(); - foreach ( $type->labels as $key => $label ) { + foreach ( (array) $type->labels as $key => $label ) { if ( is_string( $label ) && isset( $this->labels[ $label ] ) ) { if ( empty( $translated[ $label ] ) ) { + // PHPCS:disable WordPress.WP.I18n $type->labels->$key = $translated[ $label ] = isset( $this->labels[ $label ]['context'] ) ? _x( $label, $this->labels[ $label ]['context'], $this->labels[ $label ]['domain'] ) : __( $label, $this->labels[ $label ]['domain'] ); + // PHPCS:enable } else { $type->labels->$key = $translated[ $label ]; @@ -230,12 +244,12 @@ class PLL_OLT_Manager { } /** - * Allows Polylang to be the first plugin loaded ;- ) + * Allows Polylang to be the first plugin loaded ;-). * * @since 1.2 * - * @param array $plugins list of active plugins - * @return array list of active plugins + * @param string[] $plugins List of active plugins. + * @return string[] List of active plugins. */ public function make_polylang_first( $plugins ) { if ( $key = array_search( POLYLANG_BASENAME, $plugins ) ) { diff --git a/wp-content/plugins/polylang/include/pointer.php b/wp-content/plugins/polylang/include/pointer.php deleted file mode 100644 index 82e8442d..00000000 --- a/wp-content/plugins/polylang/include/pointer.php +++ /dev/null @@ -1,110 +0,0 @@ - required, unique identifier of the pointer - * id => required, the pointer will be attached to this html id - * position => optional array, if used both sub parameters are required - * edge => 'top' or 'bottom' - * align => 'right' or 'left' - * width => optional, the width in px - * title => required, title - * content => required, content - * buttons => optional array of arrays, by default the pointer uses the standard dismiss button offered by WP - * label => the label of the button - * link => optional link for the button. By default, the button just dismisses the pointer - * - * @since 1.7.7 - * - * @param array $args - */ - public function __construct( $args ) { - $this->args = $args; - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); - } - - /** - * enqueue javascripts and styles if the pointer has not been dismissed - * - * @since 1.7.7 - */ - public function enqueue_scripts() { - $dismissed = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); - if ( in_array( $this->args['pointer'], $dismissed ) || ! current_user_can( 'manage_options' ) ) { - return; - } - - // Add pointer javascript - add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) ); - - wp_enqueue_style( 'wp-pointer' ); - wp_enqueue_script( 'wp-pointer' ); - } - - /** - * adds the javascript of our pointer to the page - * - * @since 1.7.7 - */ - public function print_js() { - - // add optional buttons - if ( ! empty( $this->args['buttons'] ) ) { - $b = " - var widget = pointer.pointer( 'widget' ); - var buttons = $( '.wp-pointer-buttons', widget ); - $( 'a.close', widget ).remove();"; // removes the WP button - - // all the buttons use the standard WP ajax action to remember the pointer has been dismissed - foreach ( $this->args['buttons'] as $button ) { - $b .= sprintf( " - $( '' ).addClass( '%s' ).html( '%s' ).css( 'margin-left', '10px' ).click( function() { - $.post( ajaxurl, { - pointer: '%s', - action: 'dismiss-wp-pointer' - }, function( response ) { - %s - } ); - } ).appendTo( buttons );", - empty( $button['link'] ) ? 'button' : 'button button-primary', - esc_html( $button['label'] ), - $this->args['pointer'], - empty( $button['link'] ) ? "pointer.pointer( 'close' )" : sprintf( "location.href = '%s'", $button['link'] ) - ); - } - } - - $js = sprintf( " - //", - $this->args['id'], - sprintf( '

%s

%s

', esc_html( $this->args['title'] ), esc_html( $this->args['content'] ) ), - empty( $this->args['position'] ) ? '' : sprintf( 'position: {edge: "%s", align: "%s",},', $this->args['position']['edge'], $this->args['position']['align'] ), - empty( $this->args['width'] ) ? '' : sprintf( 'pointerWidth: %d,', $this->args['width'] ), - empty( $b ) ? '' : $b - ); - echo ''; - } -} diff --git a/wp-content/plugins/polylang/include/query.php b/wp-content/plugins/polylang/include/query.php index 1c08880b..20f7093d 100644 --- a/wp-content/plugins/polylang/include/query.php +++ b/wp-content/plugins/polylang/include/query.php @@ -1,4 +1,7 @@ query = &$query; $this->model = &$model; } + /** + * Checks if the query already includes a language taxonomy. + * + * @since 3.0 + * + * @param array $qvars WP_Query query vars. + * @return bool + */ + protected function is_already_filtered( $qvars ) { + if ( isset( $qvars['lang'] ) ) { + return true; + } + + if ( ! empty( $qvars['tax_query'] ) && is_array( $qvars['tax_query'] ) ) { + foreach ( $qvars['tax_query'] as $tax_query ) { + if ( isset( $tax_query['taxonomy'] ) && 'language' === $tax_query['taxonomy'] ) { + return true; + } + } + } + + return false; + } + /** * Check if translated taxonomy is queried * Compatible with nested queries introduced in WP 4.1 + * * @see https://wordpress.org/support/topic/tax_query-bug * * @since 1.7 @@ -81,12 +96,13 @@ class PLL_Query { } /** - * Sets the language in query - * Optimized for ( needs ) WP 3.5+ + * Sets the language in query. + * Optimized for (and requires) WP 3.5+. * * @since 2.2 * - * @param object $lang + * @param PLL_Language $lang Language object. + * @return void */ public function set_language( $lang ) { // Defining directly the tax_query ( rather than setting 'lang' avoids transforming the query by WP ) @@ -105,43 +121,34 @@ class PLL_Query { array( $tax_query ), 'relation' => 'AND', ); - } else { + } elseif ( is_array( $tax_query ) ) { + // The tax query is expected to be *always* an array, but it seems that 3rd parties fill it with a string + // Causing a fatal error if we don't check it. + // See https://wordpress.org/support/topic/fatal-error-2947/ $tax_query[] = $lang_query; + } elseif ( empty( $tax_query ) ) { + // Supposing the tax query has been wrongly filled with an empty string + $tax_query = array( $lang_query ); } } /** - * Add the language in query after it has checked that it won't conflict with other query vars + * Adds the language in the query after it has checked that it won't conflict with other query vars. * * @since 2.2 * - * @param object $lang Language + * @param PLL_Language $lang Language. + * @return void */ public function filter_query( $lang ) { $qvars = &$this->query->query_vars; - if ( ! isset( $qvars['lang'] ) ) { - // Do not filter the query if the language is already specified in another way - foreach ( self::$excludes as $k ) { - if ( ! empty( $qvars[ $k ] ) ) { - return; - } - } - - // Specific case for 'cat' as it can contain negative values - if ( ! empty( $qvars['cat'] ) ) { - foreach ( explode( ',', $qvars['cat'] ) as $cat ) { - if ( $cat > 0 ) { - return; - } - } - } - + if ( ! $this->is_already_filtered( $qvars ) ) { $taxonomies = array_intersect( $this->model->get_translated_taxonomies(), get_taxonomies( array( '_builtin' => false ) ) ); foreach ( $taxonomies as $tax ) { - $tax = get_taxonomy( $tax ); - if ( ! empty( $qvars[ $tax->query_var ] ) ) { + $tax_object = get_taxonomy( $tax ); + if ( ! empty( $tax_object ) && ! empty( $qvars[ $tax_object->query_var ] ) ) { return; } } @@ -157,7 +164,7 @@ class PLL_Query { if ( $taxonomies && ( empty( $qvars['post_type'] ) || 'any' === $qvars['post_type'] ) ) { foreach ( $taxonomies as $taxonomy ) { $tax_object = get_taxonomy( $taxonomy ); - if ( $this->model->is_translated_post_type( $tax_object->object_type ) ) { + if ( ! empty( $tax_object ) && $this->model->is_translated_post_type( $tax_object->object_type ) ) { $this->set_language( $lang ); break; } diff --git a/wp-content/plugins/polylang/include/rest-request.php b/wp-content/plugins/polylang/include/rest-request.php new file mode 100644 index 00000000..ab3926a6 --- /dev/null +++ b/wp-content/plugins/polylang/include/rest-request.php @@ -0,0 +1,72 @@ +model->get_languages_list() ) { + + /** This action is documented in include/class-polylang.php */ + do_action( 'pll_no_language_defined' ); // To load overridden textdomains. + + $this->filters_links = new PLL_Filters_Links( $this ); + $this->filters = new PLL_Filters( $this ); + $this->filters_widgets_options = new PLL_Filters_Widgets_Options( $this ); + + // Static front page and page for posts. + if ( 'page' === get_option( 'show_on_front' ) ) { + $this->static_pages = new PLL_Static_Pages( $this ); + } + + $this->links = new PLL_Admin_Links( $this ); + + $this->nav_menu = new PLL_Nav_Menu( $this ); // For auto added pages to menu. + } + } +} diff --git a/wp-content/plugins/polylang/include/static-pages.php b/wp-content/plugins/polylang/include/static-pages.php index f18b1298..f83164ce 100644 --- a/wp-content/plugins/polylang/include/static-pages.php +++ b/wp-content/plugins/polylang/include/static-pages.php @@ -1,23 +1,56 @@ model = &$polylang->model; + $this->model = &$polylang->model; $this->options = &$polylang->options; $this->curlang = &$polylang->curlang; @@ -26,27 +59,30 @@ abstract class PLL_Static_Pages { // Modifies the page link in case the front page is not in the default language add_filter( 'page_link', array( $this, 'page_link' ), 20, 2 ); - // clean the languages cache when editing page of front, page for posts + // Clean the languages cache when editing page of front, page for posts add_action( 'update_option_show_on_front', array( $this->model, 'clean_languages_cache' ) ); add_action( 'update_option_page_on_front', array( $this->model, 'clean_languages_cache' ) ); add_action( 'update_option_page_for_posts', array( $this->model, 'clean_languages_cache' ) ); - // refresh rewrite rules when the page on front is modified + // Refresh rewrite rules when the page on front is modified add_action( 'update_option_page_on_front', 'flush_rewrite_rules' ); + + // OEmbed + add_filter( 'oembed_request_post_id', array( $this, 'oembed_request_post_id' ), 10, 2 ); } /** - * stores the page on front and page for posts ids + * Stores the page on front and page for posts ids * * @since 1.8 + * + * @return void */ public function init() { if ( 'page' == get_option( 'show_on_front' ) ) { $this->page_on_front = get_option( 'page_on_front' ); $this->page_for_posts = get_option( 'page_for_posts' ); - } - - else { + } else { $this->page_on_front = 0; $this->page_for_posts = 0; } @@ -62,19 +98,22 @@ abstract class PLL_Static_Pages { * @return string modified link */ public function page_link( $link, $id ) { - if ( ( $lang = $this->model->post->get_language( $id ) ) && $id == $lang->page_on_front ) { + $lang = $this->model->post->get_language( $id ); + + if ( $lang && $id == $lang->page_on_front ) { return $lang->home_url; } return $link; } /** - * adds page_on_front and page_for_posts properties to the language objects + * Adds page_on_front and page_for_posts properties to the language objects. * * @since 1.8 * - * @param array $languages - * @param object $model + * @param PLL_Language[] $languages The list of languages. + * @param PLL_Model $model The instance of PLL_Model. + * @return PLL_Language[] */ public static function pll_languages_list( $languages, $model ) { if ( 'page' === get_option( 'show_on_front' ) ) { @@ -96,7 +135,26 @@ abstract class PLL_Static_Pages { * @return int */ public function translate_page_for_posts( $v ) { - // Returns the current page if there is no translation to avoid ugly notices - return isset( $this->curlang->page_for_posts ) ? $this->curlang->page_for_posts : $v; + // Don't attempt to translate in a 'switch_blog' action as there is a risk to call this function while initializing the languages cache + return isset( $this->curlang->page_for_posts ) && ( $this->curlang->page_for_posts ) && ! doing_action( 'switch_blog' ) ? $this->curlang->page_for_posts : $v; + } + + /** + * Fixes the oembed for the translated static front page + * when the language page is redirected to the front page + * + * @since 2.6 + * + * @param int $post_id The post ID. + * @param string $url The requested URL. + * @return int + */ + public function oembed_request_post_id( $post_id, $url ) { + foreach ( $this->model->get_languages_list() as $lang ) { + if ( trailingslashit( $url ) === trailingslashit( $lang->home_url ) ) { + $post_id = $lang->page_on_front; + } + } + return $post_id; } } diff --git a/wp-content/plugins/polylang/include/switcher.php b/wp-content/plugins/polylang/include/switcher.php index 666e0e95..cc8e26ad 100644 --- a/wp-content/plugins/polylang/include/switcher.php +++ b/wp-content/plugins/polylang/include/switcher.php @@ -1,4 +1,7 @@ 0, // Display as list and not as dropdown. + 'echo' => 1, // Echoes the list. + 'hide_if_empty' => 1, // Hides languages with no posts (or pages). + 'show_flags' => 0, // Don't show flags. + 'show_names' => 1, // Show language names. + 'display_names_as' => 'name', // Display the language name. + 'force_home' => 0, // Tries to find a translation. + 'hide_if_no_translation' => 0, // Don't hide the link if there is no translation. + 'hide_current' => 0, // Don't hide the current language. + 'post_id' => null, // Link to the translations of the current page. + 'raw' => 0, // Build the language switcher. + 'item_spacing' => 'preserve', // Preserve whitespace between list items. + 'admin_render' => 0, // Make the switcher in a frontend context. + 'admin_current_lang' => null, // Use the global current language. + ); + + /** + * @var PLL_Links + */ + protected $links; /** * Returns options available for the language switcher - menu or widget @@ -13,66 +37,114 @@ class PLL_Switcher { * * @since 0.7 * - * @param string $type optional either 'menu' or 'widget', defaults to 'widget' + * @param string $type optional either 'menu', 'widget' or 'block', defaults to 'widget' * @param string $key optional either 'string' or 'default', defaults to 'string' * @return array list of switcher options strings or default values */ - static public function get_switcher_options( $type = 'widget', $key = 'string' ) { + public static function get_switcher_options( $type = 'widget', $key = 'string' ) { $options = array( - 'dropdown' => array( 'string' => __( 'Displays as dropdown', 'polylang' ), 'default' => 0 ), + 'dropdown' => array( 'string' => __( 'Displays as a dropdown', 'polylang' ), 'default' => 0 ), 'show_names' => array( 'string' => __( 'Displays language names', 'polylang' ), 'default' => 1 ), 'show_flags' => array( 'string' => __( 'Displays flags', 'polylang' ), 'default' => 0 ), 'force_home' => array( 'string' => __( 'Forces link to front page', 'polylang' ), 'default' => 0 ), 'hide_current' => array( 'string' => __( 'Hides the current language', 'polylang' ), 'default' => 0 ), 'hide_if_no_translation' => array( 'string' => __( 'Hides languages with no translation', 'polylang' ), 'default' => 0 ), ); - return wp_list_pluck( $options, $key ); } + /** + * Returns the current language code. + * + * @since 3.0 + * + * @param array $args Arguments passed to {@see PLL_Switcher::the_languages()}. + * @return string + */ + protected function get_current_language( $args ) { + if ( $args['admin_current_lang'] ) { + return $args['admin_current_lang']; + } + + if ( isset( $this->links->curlang ) ) { + return $this->links->curlang->slug; + } + + return $this->links->options['default_lang']; + } + + /** + * Returns the link for a given language. + * + * @since 3.0 + * + * @param PLL_Language $language Language. + * @param array $args Arguments passed to {@see PLL_Switcher::the_languages()}. + * @return string|null + */ + protected function get_link( $language, $args ) { + global $post; + + // Priority to the post passed in parameters. + if ( null !== $args['post_id'] ) { + $tr_id = $this->links->model->post->get( $args['post_id'], $language ); + if ( $tr_id && $this->links->model->post->current_user_can_read( $tr_id ) ) { + return get_permalink( $tr_id ); + } + } + + // If we are on frontend. + if ( $this->links instanceof PLL_Frontend_Links ) { + return $this->links->get_translation_url( $language ); + } + + // For blocks in posts in REST requests. + if ( $post instanceof WP_Post ) { + $tr_id = $this->links->model->post->get( $post->ID, $language ); + if ( $tr_id && $this->links->model->post->current_user_can_read( $tr_id ) ) { + return get_permalink( $tr_id ); + } + } + + return null; + } + /** * Get the language elements for use in a walker * - * List of parameters accepted in $args: - * @see PLL_Switcher::the_languages - * * @since 1.2 * - * @param object $links instance of PLL_Frontend_Links - * @param array $args - * @return array + * @param array $args Arguments passed to {@see PLL_Switcher::the_languages()}. + * @return array Language switcher elements. */ - protected function get_elements( $links, $args ) { - + protected function get_elements( $args ) { $first = true; + $out = array(); - foreach ( $links->model->get_languages_list( array( 'hide_empty' => $args['hide_if_empty'] ) ) as $language ) { + foreach ( $this->links->model->get_languages_list( array( 'hide_empty' => $args['hide_if_empty'] ) ) as $language ) { $id = (int) $language->term_id; $order = (int) $language->term_group; $slug = $language->slug; $locale = $language->get_locale( 'display' ); - $classes = array( 'lang-item', 'lang-item-' . $id, 'lang-item-' . esc_attr( $slug ) ); - $url = null; // Avoids potential notice + $item_classes = array( 'lang-item', 'lang-item-' . $id, 'lang-item-' . esc_attr( $slug ) ); + $classes = isset( $args['classes'] ) && is_array( $args['classes'] ) ? + array_merge( + $item_classes, + $args['classes'] + ) : + $item_classes; + $link_classes = isset( $args['link_classes'] ) ? $args['link_classes'] : array(); + $current_lang = $this->get_current_language( $args ) === $slug; - if ( $first ) { - $classes[] = 'lang-item-first'; - $first = false; - } - - if ( $current_lang = $links->curlang->slug == $slug ) { + if ( $current_lang ) { if ( $args['hide_current'] && ! ( $args['dropdown'] && ! $args['raw'] ) ) { continue; // Hide current language except for dropdown - } - else { + } else { $classes[] = 'current-lang'; } } - if ( null !== $args['post_id'] && ( $tr_id = $links->model->post->get( $args['post_id'], $language ) ) && $links->current_user_can_read( $tr_id ) ) { - $url = get_permalink( $tr_id ); - } elseif ( null === $args['post_id'] ) { - $url = $links->get_translation_url( $language ); - } + $url = $this->get_link( $language, $args ); if ( $no_translation = empty( $url ) ) { $classes[] = 'no-translation'; @@ -83,9 +155,9 @@ class PLL_Switcher { * * @since 0.7 * - * @param string $url the link - * @param string $slug language code - * @param string $locale language locale + * @param string|null $url The link, null if no translation was found. + * @param string $slug The language code. + * @param string $locale The language locale */ $url = apply_filters( 'pll_the_language_link', $url, $slug, $language->locale ); @@ -94,59 +166,54 @@ class PLL_Switcher { continue; } - $url = empty( $url ) || $args['force_home'] ? $links->get_home_url( $language ) : $url; // If the page is not translated, link to the home page + $url = empty( $url ) || $args['force_home'] ? $this->links->get_home_url( $language ) : $url; // If the page is not translated, link to the home page $name = $args['show_names'] || ! $args['show_flags'] || $args['raw'] ? ( 'slug' == $args['display_names_as'] ? $slug : $language->name ) : ''; - $flag = $args['raw'] && ! $args['show_flags'] ? $language->flag_url : ( $args['show_flags'] ? $language->flag : '' ); + $flag = $args['raw'] && ! $args['show_flags'] ? $language->get_display_flag_url() : ( $args['show_flags'] ? $language->get_display_flag() : '' ); - $out[ $slug ] = compact( 'id', 'order', 'slug', 'locale', 'name', 'url', 'flag', 'current_lang', 'no_translation', 'classes' ); + if ( $first ) { + $classes[] = 'lang-item-first'; + $first = false; + } + + $out[ $slug ] = compact( 'id', 'order', 'slug', 'locale', 'name', 'url', 'flag', 'current_lang', 'no_translation', 'classes', 'link_classes' ); } - return empty( $out ) ? array() : $out; + return $out; } /** * Displays a language switcher - * or returns the raw elements to build a custom language switcher - * - * List of parameters accepted in $args: - * - * dropdown => the list is displayed as dropdown if set, defaults to 0 - * echo => echoes the list if set to 1, defaults to 1 - * hide_if_empty => hides languages with no posts ( or pages ) if set to 1, defaults to 1 - * show_flags => displays flags if set to 1, defaults to 0 - * show_names => show language names if set to 1, defaults to 1 - * display_names_as => whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to name - * force_home => will always link to home in translated language if set to 1, defaults to 0 - * hide_if_no_translation => hide the link if there is no translation if set to 1, defaults to 0 - * hide_current => hide the current language if set to 1, defaults to 0 - * post_id => returns links to translations of post defined by post_id if set, defaults not set - * raw => return a raw array instead of html markup if set to 1, defaults to 0 - * item_spacing => whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to preserve + * or returns the raw elements to build a custom language switcher. * * @since 0.1 * - * @param object $links instance of PLL_Frontend_Links - * @param array $args + * @param PLL_Links $links Instance of PLL_Links. + * @param array $args { + * Optional array of arguments. + * + * @type int $dropdown The list is displayed as dropdown if set, defaults to 0. + * @type int $echo Echoes the list if set to 1, defaults to 1. + * @type int $hide_if_empty Hides languages with no posts ( or pages ) if set to 1, defaults to 1. + * @type int $show_flags Displays flags if set to 1, defaults to 0. + * @type int $show_names Shows language names if set to 1, defaults to 1. + * @type string $display_names_as Whether to display the language name or its slug, valid options are 'slug' and 'name', defaults to name. + * @type int $force_home Will always link to home in translated language if set to 1, defaults to 0. + * @type int $hide_if_no_translation Hides the link if there is no translation if set to 1, defaults to 0. + * @type int $hide_current Hides the current language if set to 1, defaults to 0. + * @type int $post_id Returns links to the translations of the post defined by post_id if set, defaults not set. + * @type int $raw Return a raw array instead of html markup if set to 1, defaults to 0. + * @type string $item_spacing Whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to 'preserve'. + * @type int $admin_render Allows to force the current language code in an admin context if set, default to 0. Need to set the admin_current_lang argument below. + * @type string $admin_current_lang The current language code in an admin context. Need to set the admin_render to 1, defaults not set. + * @type string[] $classes A list of CSS classes to set to each elements outputted. + * @type string[] $link_classes A list of CSS classes to set to each link outputted. + * } * @return string|array either the html markup of the switcher or the raw elements to build a custom language switcher */ - public function the_languages( $links, $args = '' ) { - $defaults = array( - 'dropdown' => 0, // display as list and not as dropdown - 'echo' => 1, // echoes the list - 'hide_if_empty' => 1, // hides languages with no posts ( or pages ) - 'menu' => 0, // not for nav menu ( this argument is deprecated since v1.1.1 ) - 'show_flags' => 0, // don't show flags - 'show_names' => 1, // show language names - 'display_names_as' => 'name', // valid options are slug and name - 'force_home' => 0, // tries to find a translation - 'hide_if_no_translation' => 0, // don't hide the link if there is no translation - 'hide_current' => 0, // don't hide current language - 'post_id' => null, // if not null, link to translations of post defined by post_id - 'raw' => 0, // set this to true to build your own custom language switcher - 'item_spacing' => 'preserve', // 'preserve' or 'discard' whitespace between list items - ); - $args = wp_parse_args( $args, $defaults ); + public function the_languages( $links, $args = array() ) { + $this->links = $links; + $args = wp_parse_args( $args, self::DEFAULTS ); /** * Filter the arguments of the 'pll_the_languages' template tag @@ -157,12 +224,17 @@ class PLL_Switcher { */ $args = apply_filters( 'pll_the_languages_args', $args ); + // Force not to hide the language for the widget preview even if the option is checked. + if ( $this->links instanceof PLL_Admin_Links ) { + $args['hide_if_no_translation'] = 0; + } + // Prevents showing empty options in dropdown if ( $args['dropdown'] ) { $args['show_names'] = 1; } - $elements = $this->get_elements( $links, $args ); + $elements = $this->get_elements( $args ); if ( $args['raw'] ) { return $elements; @@ -171,9 +243,8 @@ class PLL_Switcher { if ( $args['dropdown'] ) { $args['name'] = 'lang_choice_' . $args['dropdown']; $walker = new PLL_Walker_Dropdown(); - $args['selected'] = $links->curlang->slug; - } - else { + $args['selected'] = $this->get_current_language( $args ); + } else { $walker = new PLL_Walker_List(); } @@ -185,18 +256,13 @@ class PLL_Switcher { * @param string $html html returned/outputted by the template tag * @param array $args arguments passed to the template tag */ - $out = apply_filters( 'pll_the_languages', $walker->walk( $elements, $args ), $args ); + $out = apply_filters( 'pll_the_languages', $walker->walk( $elements, -1, $args ), $args ); // Javascript to switch the language when using a dropdown list - if ( $args['dropdown'] ) { - foreach ( $links->model->get_languages_list() as $language ) { - $url = $links->get_translation_url( $language ); - $urls[ $language->slug ] = $args['force_home'] || empty( $url ) ? $links->get_home_url( $language ) : $url; - } - + if ( $args['dropdown'] && 0 === $args['admin_render'] ) { // Accept only few valid characters for the urls_x variable name ( as the widget id includes '-' which is invalid ) - $out .= sprintf( ' - ', - 'urls_' . preg_replace( '#[^a-zA-Z0-9]#', '', $args['dropdown'] ), json_encode( $urls ), esc_js( $args['name'] ) + 'urls_' . preg_replace( '#[^a-zA-Z0-9]#', '', $args['dropdown'] ), + wp_json_encode( wp_list_pluck( $elements, 'url' ) ), + esc_js( $args['name'] ) ); } if ( $args['echo'] ) { - echo $out; + echo $out; // phpcs:ignore WordPress.Security.EscapeOutput } return $out; } diff --git a/wp-content/plugins/polylang/include/translate-option.php b/wp-content/plugins/polylang/include/translate-option.php new file mode 100644 index 00000000..c7befcd6 --- /dev/null +++ b/wp-content/plugins/polylang/include/translate-option.php @@ -0,0 +1,331 @@ + 1, + * 'option_key_to_translate_2' => 1, + * 'my_group' => array( + * 'sub_key_to_translate_1' => 1, + * 'sub_key_to_translate_2' => 1, + * ), + * ) + * + * Note: only keys are interpreted. Any scalar can be used as values. + * @param array $args { + * Optional. Array of arguments for registering the option. + * + * @type string $context The group in which the strings will be registered. + * @type string $sanitize_callback A callback function that sanitizes the option's value. + * } + */ + public function __construct( $name, $keys = array(), $args = array() ) { + // Registers the strings. + $context = isset( $args['context'] ) ? $args['context'] : 'Polylang'; + $this->register_string_recursive( $context, $name, get_option( $name ), $keys ); + + // Translates the strings. + $this->keys = $keys; + add_filter( 'option_' . $name, array( $this, 'translate' ) ); // Make sure to add this filter after options are registered. + + // Filters updated values. + add_filter( 'pre_update_option_' . $name, array( $this, 'pre_update_option' ), 10, 3 ); + add_action( 'update_option_' . $name, array( $this, 'update_option' ) ); + + // Sanitizes translated strings. + if ( empty( $args['sanitize_callback'] ) ) { + add_filter( 'pll_sanitize_string_translation', array( $this, 'sanitize_option' ), 10, 2 ); + } else { + add_filter( 'pll_sanitize_string_translation', $args['sanitize_callback'], 10, 3 ); + } + } + + /** + * Translates the strings registered for an option. + * + * @since 1.0 + * + * @param mixed $value Either a string to translate or a list of strings to translate. + * @return mixed Translated string(s). + */ + public function translate( $value ) { + return $this->translate_string_recursive( $value, $this->keys ); + } + + /** + * Recursively translates the strings registered for an option. + * + * @since 1.0 + * + * @param mixed $values Either a string to translate or a list of strings to translate. + * @param array|bool $key Array of option keys to translate. + * @return array|string Translated string(s) + */ + protected function translate_string_recursive( $values, $key ) { + $children = is_array( $key ) ? $key : array(); + + if ( is_array( $values ) || is_object( $values ) ) { + if ( count( $children ) ) { + foreach ( $children as $name => $child ) { + if ( is_array( $values ) && isset( $values[ $name ] ) ) { + $values[ $name ] = $this->translate_string_recursive( $values[ $name ], $child ); + continue; + } + + if ( is_object( $values ) && isset( $values->$name ) ) { + $values->$name = $this->translate_string_recursive( $values->$name, $child ); + continue; + } + + $pattern = '#^' . str_replace( '*', '(?:.+)', $name ) . '$#'; + + foreach ( $values as $n => &$value ) { + // The first case could be handled by the next one, but we avoid calls to preg_match here. + if ( '*' === $name || ( false !== strpos( $name, '*' ) && preg_match( $pattern, $n ) ) ) { + $value = $this->translate_string_recursive( $value, $child ); + } + } + } + } else { + // Parent key is a wildcard and no sub-key has been whitelisted. + foreach ( $values as &$value ) { + $value = $this->translate_string_recursive( $value, $key ); + } + } + } else { + $values = pll__( $values ); + } + + return $values; + } + + /** + * Recursively registers strings for an option. + * + * @since 1.0 + * @since 2.7 Signature modified + * + * @param string $context The group in which the strings will be registered. + * @param string $option Option name. + * @param mixed $values Option value. + * @param array|bool $key Array of option keys to translate. + * @return void + */ + protected function register_string_recursive( $context, $option, $values, $key ) { + if ( is_object( $values ) ) { + $values = (array) $values; + } + + if ( is_array( $values ) ) { + $children = is_array( $key ) ? $key : array(); + + if ( count( $children ) ) { + foreach ( $children as $name => $child ) { + if ( isset( $values[ $name ] ) ) { + $this->register_string_recursive( $context, $name, $values[ $name ], $child ); + continue; + } + + $pattern = '#^' . str_replace( '*', '(?:.+)', $name ) . '$#'; + + foreach ( $values as $n => $value ) { + // The first case could be handled by the next one, but we avoid calls to preg_match here. + if ( '*' === $name || ( false !== strpos( $name, '*' ) && preg_match( $pattern, $n ) ) ) { + $this->register_string_recursive( $context, $n, $value, $child ); + } + } + } + } else { + foreach ( $values as $n => $value ) { + // Parent key is a wildcard and no sub-key has been whitelisted. + $this->register_string_recursive( $context, $n, $value, $key ); + } + } + } else { + PLL_Admin_Strings::register_string( $option, $values, $context, true ); + } + } + + /** + * Filters an option before it is updated. + * + * This is the step 1 in the update process, in which we prevent the update of + * strings to their translations by filtering them out, and we store the updated strings + * for the next step. + * + * @since 2.9 + * + * @param mixed $value The new, unserialized option value. + * @param mixed $old_value The old (filtered) option value. + * @param string $name Option name. + * @return mixed + */ + public function pre_update_option( $value, $old_value, $name ) { + // Stores the unfiltered old option value before it is updated in DB. + remove_filter( 'option_' . $name, array( $this, 'translate' ), 10, 2 ); + $unfiltered_old_value = get_option( $name ); + add_filter( 'option_' . $name, array( $this, 'translate' ), 20, 2 ); + + // Load strings translations according to the admin language filter + $locale = pll_current_language( 'locale' ); + if ( empty( $locale ) ) { + $locale = pll_default_language( 'locale' ); + } + PLL()->load_strings_translations( $locale ); + + // Filters out the strings which would be updated to their translations and stores the updated strings. + $value = $this->check_value_recursive( $unfiltered_old_value, $value, $this->keys ); + + return $value; + } + + /** + * Updates the string translations to keep the same translated value when updating the original option. + * + * This is the step 2 in the update process. Knowing all strings that have been updated, + * we remove the old strings from the strings translations and replace them by + * the new strings with the old translations. + * + * @since 2.9 + * + * @return void + */ + public function update_option() { + $curlang = pll_current_language(); + + if ( ! empty( $this->updated_strings ) ) { + foreach ( pll_languages_list() as $lang ) { + + $language = PLL()->model->get_language( $lang ); + $mo = new PLL_MO(); + $mo->import_from_db( $language ); + + foreach ( $this->updated_strings as $old_string => $string ) { + $translation = $mo->translate( $old_string ); + if ( ( empty( $curlang ) && $translation === $old_string ) || $lang === $curlang ) { + $translation = $string; + } + + // Removes the old entry and replace it by the new one, with the same translation. + $mo->delete_entry( $old_string ); + $mo->add_entry( $mo->make_entry( $string, $translation ) ); + } + + $mo->export_to_db( $language ); + } + } + } + + /** + * Recursively compares the updated strings to the translation of the old string. + * + * This is the heart of the update process. If an updated string is found to be + * the same as the translation of the old string, we restore the old string to + * prevent the update in {@see PLL_Translate_Option::pre_update_option()}, otherwise + * the updated string is stored in {@see PLL_Translate_Option::updated_strings} to be able to + * later assign the translations to the new value in {@see PLL_Translate_Option::update_option()}. + * + * @since 2.9 + * + * @param mixed $old_values The old option value. + * @param mixed $values The new option value.. + * @param array|bool $key Array of option keys to translate. + * @return mixed + */ + protected function check_value_recursive( $old_values, $values, $key ) { + $children = is_array( $key ) ? $key : array(); + + if ( is_array( $values ) || is_object( $values ) ) { + if ( count( $children ) ) { + foreach ( $children as $name => $child ) { + if ( is_array( $values ) && is_array( $old_values ) && isset( $old_values[ $name ], $values[ $name ] ) ) { + $values[ $name ] = $this->check_value_recursive( $old_values[ $name ], $values[ $name ], $child ); + continue; + } + + if ( is_object( $values ) && is_object( $old_values ) && isset( $old_values->$name, $values->$name ) ) { + $values->$name = $this->check_value_recursive( $old_values->$name, $values->$name, $child ); + continue; + } + + $pattern = '#^' . str_replace( '*', '(?:.+)', $name ) . '$#'; + + foreach ( $values as $n => $value ) { + // The first case could be handled by the next one, but we avoid calls to preg_match here. + if ( '*' === $name || ( false !== strpos( $name, '*' ) && preg_match( $pattern, $n ) ) ) { + if ( is_array( $values ) && is_array( $old_values ) && isset( $old_values[ $n ] ) ) { + $values[ $n ] = $this->check_value_recursive( $old_values[ $n ], $value, $child ); + } + + if ( is_object( $values ) && is_object( $old_values ) && isset( $old_values->$n ) ) { + $values->$n = $this->check_value_recursive( $old_values->$n, $value, $child ); + } + } + } + } + } else { + // Parent key is a wildcard and no sub-key has been whitelisted. + foreach ( $values as $n => $value ) { + if ( is_array( $values ) && is_array( $old_values ) && isset( $old_values[ $n ] ) ) { + $values[ $n ] = $this->check_value_recursive( $old_values[ $n ], $value, $key ); + } + + if ( is_object( $values ) && is_object( $old_values ) && isset( $old_values->$n ) ) { + $values->$n = $this->check_value_recursive( $old_values->$n, $value, $key ); + } + } + } + } elseif ( $old_values !== $values ) { + if ( pll__( $old_values ) === $values ) { + $values = $old_values; // Prevents updating the value to its translation. + } else { + $this->updated_strings[ $old_values ] = $values; // Stores the updated strings. + } + } + + return $values; + } + + /** + * Sanitizes the option value. + * + * @since 2.9 + * + * @param string $value The unsanitised value. + * @param string $name The name of the option. + * @return string Sanitized value. + */ + public function sanitize_option( $value, $name ) { + return sanitize_option( $name, $value ); + } +} diff --git a/wp-content/plugins/polylang/include/translated-object.php b/wp-content/plugins/polylang/include/translated-object.php index 002cdee7..d79e6c72 100644 --- a/wp-content/plugins/polylang/include/translated-object.php +++ b/wp-content/plugins/polylang/include/translated-object.php @@ -1,41 +1,130 @@ model = &$model; - // register our taxonomies as soon as possible - // this is early registration, not ready for rewrite rules as wp_rewrite will be setup later + /* + * Register our taxonomies as soon as possible. + * This is early registration, not ready for rewrite rules as $wp_rewrite will be setup later. + */ $args = array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false, '_pll' => true ); register_taxonomy( $this->tax_language, $this->object_type, $args ); - $args['update_count_callback'] = '_update_generic_term_count'; // count *all* posts to avoid deleting in clean_translations_terms + $args['update_count_callback'] = '_update_generic_term_count'; // Count *all* objects to avoid deleting in clean_translations_terms. register_taxonomy( $this->tax_translations, $this->object_type, $args ); } /** - * Wrap wp_get_object_terms to cache it and return only one object - * inspired by the function get_the_terms + * Stores the language in the database. + * + * @since 0.6 + * + * @param int $id Object id. + * @param int|string|PLL_Language $lang Language (term_id or slug or object). + * @return void + */ + abstract public function set_language( $id, $lang ); + + /** + * Returns the language of an object. + * + * @since 0.1 + * + * @param int $id Object id. + * @return PLL_Language|false PLL_Language object, false if no language is associated to that object. + */ + abstract public function get_language( $id ); + + /** + * Assigns a new language to an object, taking care of the translations group. + * + * @since 3.1 + * + * @param int $id Object id. + * @param PLL_Language $lang New language to assign to the object. + * @return void + */ + public function update_language( $id, $lang ) { + if ( $this->get_language( $id ) === $lang ) { + return; + } + + $this->set_language( $id, $lang ); + + $translations = $this->get_translations( $id ); + + if ( $translations ) { + // Remove the post's former language from the new translations group. + $translations = array_diff( $translations, array( $id ) ); + $this->save_translations( $id, $translations ); + } + } + + /** + * Wrap wp_get_object_terms() to cache it and return only one object. + * inspired by the WordPress function get_the_terms(). * * @since 1.2 * - * @param int $object_id post_id or term_id - * @param string $taxonomy Polylang taxonomy depending if we are looking for a post ( or term ) language ( or translation ) - * @return bool|object the term associated to the object in the requested taxonomy if exists, false otherwise + * @param int $object_id Object id ( typically a post_id or term_id ). + * @param string $taxonomy Polylang taxonomy depending if we are looking for a post ( or term ) language ( or translation ). + * @return WP_Term|false The term associated to the object in the requested taxonomy if it exists, false otherwise. */ public function get_object_term( $object_id, $taxonomy ) { if ( empty( $object_id ) || is_wp_error( $object_id ) ) { @@ -43,22 +132,30 @@ abstract class PLL_Translated_Object { } $object_id = (int) $object_id; + + if ( $object_id < 0 ) { + return false; + } + $term = get_object_term_cache( $object_id, $taxonomy ); if ( false === $term ) { - // query language and translations at the same time + // Query language and translations at the same time. $taxonomies = array( $this->tax_language, $this->tax_translations ); - // query terms - foreach ( wp_get_object_terms( $object_id, $taxonomies, array( 'update_term_meta_cache' => false ) ) as $t ) { - $terms[ $t->taxonomy ] = $t; - if ( $t->taxonomy == $taxonomy ) { - $term = $t; + // Query terms. + $terms = array(); + $object_terms = wp_get_object_terms( $object_id, $taxonomies, array( 'update_term_meta_cache' => false ) ); + if ( is_array( $object_terms ) ) { + foreach ( $object_terms as $t ) { + $terms[ $t->taxonomy ] = $t; + if ( $t->taxonomy == $taxonomy ) { + $term = $t; + } } } - // store it the way WP wants it - // set an empty cache if no term found in the taxonomy + // Stores it the way WP expects it. Set an empty cache if no term was found in the taxonomy. foreach ( $taxonomies as $tax ) { wp_cache_add( $object_id, empty( $terms[ $tax ] ) ? array() : array( $terms[ $tax ] ), $tax . '_relationships' ); } @@ -71,66 +168,70 @@ abstract class PLL_Translated_Object { } /** - * Tells whether a translation term must be updated + * Tells whether a translation term must be updated. * * @since 2.3 * - * @param array $id Post id or term id - * @param array $translations An associative array of translations with language code as key and translation id as value + * @param int $id Object id ( typically a post_id or term_id ). + * @param int[] $translations An associative array of translations with language code as key and translation id as value. + * @return bool */ protected function should_update_translation_group( $id, $translations ) { - // Don't do anything if no translations have been added to the group - $old_translations = $this->get_translations( $id ); // Includes at least $id itself + // Don't do anything if no translations have been added to the group. + $old_translations = $this->get_translations( $id ); // Includes at least $id itself. return count( array_diff_assoc( $translations, $old_translations ) ) > 0; } /** - * Saves translations for posts or terms + * Saves translations for posts or terms. * * @since 0.5 * - * @param int $id Post id or term id - * @param array $translations An associative array of translations with language code as key and translation id as value + * @param int $id Object id ( typically a post_id or term_id ). + * @param int[] $translations An associative array of translations with language code as key and translation id as value. + * + * @return int[] An associative array with language codes as key and post ids as values. */ public function save_translations( $id, $translations ) { + $translations = $this->validate_translations( $translations ); + $id = (int) $id; - if ( ( $lang = $this->get_language( $id ) ) && isset( $translations ) && is_array( $translations ) ) { - // sanitize the translations array + if ( $lang = $this->get_language( $id ) ) { + // Sanitize the translations array. $translations = array_map( 'intval', $translations ); - $translations = array_merge( array( $lang->slug => $id ), $translations ); // make sure this object is in translations - $translations = array_diff( $translations, array( 0 ) ); // don't keep non translated languages - $translations = array_intersect_key( $translations, array_flip( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ); // keep only valid languages slugs as keys + $translations = array_merge( array( $lang->slug => $id ), $translations ); // Make sure this object is in translations. + $translations = array_diff( $translations, array( 0 ) ); // Don't keep non translated languages. + $translations = array_intersect_key( $translations, array_flip( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ); // Keep only valid languages slugs as keys. - // unlink removed translations + // Unlink removed translations. $old_translations = $this->get_translations( $id ); foreach ( array_diff_assoc( $old_translations, $translations ) as $object_id ) { $this->delete_translation( $object_id ); } - // Check id we need to create or update the translation group + // Check id we need to create or update the translation group. if ( $this->should_update_translation_group( $id, $translations ) ) { $terms = wp_get_object_terms( $translations, $this->tax_translations ); $term = reset( $terms ); - // create a new term if necessary + // Create a new term if necessary. if ( empty( $term ) ) { - wp_insert_term( $group = uniqid( 'pll_' ), $this->tax_translations, array( 'description' => serialize( $translations ) ) ); - } - else { - // take care not to overwrite extra data stored in description field, if any - $d = unserialize( $term->description ); - $d = is_array( $d ) ? array_diff_key( $d, $old_translations ) : array(); // remove old translations - $d = array_merge( $d, $translations ); // add new one - wp_update_term( $group = (int) $term->term_id, $this->tax_translations, array( 'description' => serialize( $d ) ) ); + wp_insert_term( $group = uniqid( 'pll_' ), $this->tax_translations, array( 'description' => maybe_serialize( $translations ) ) ); + } else { + // Take care not to overwrite extra data stored in the description field, if any. + $d = maybe_unserialize( $term->description ); + $d = is_array( $d ) ? array_diff_key( $d, $old_translations ) : array(); // Remove old translations. + $d = array_merge( $d, $translations ); // Add new one. + wp_update_term( $group = (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $d ) ) ); } - // link all translations to the new term + // Link all translations to the new term. foreach ( $translations as $p ) { wp_set_object_terms( $p, $group, $this->tax_translations ); } - // clean now unused translation groups + // Clean now unused translation groups. foreach ( wp_list_pluck( $terms, 'term_id' ) as $term_id ) { $term = get_term( $term_id, $this->tax_translations ); if ( empty( $term->count ) ) { @@ -138,52 +239,76 @@ abstract class PLL_Translated_Object { } } } + return $translations; + } else { + return array(); } } /** - * Deletes a translation of a post or term + * Returns translations after checking the translated post is in the right language + * + * @since 3.1 + * + * @param int[] $translations An associative array of translations with language code as key and translation id as value. + * + * @return int[] + */ + public function validate_translations( $translations ) { + $valid_translations = array(); + + foreach ( $translations as $lang => $tr_id ) { + $valid_translations[ $lang ] = ( $tr_id && $this->get_language( (int) $tr_id )->slug == $lang ) ? (int) $tr_id : 0; + } + + return $valid_translations; + } + + /** + * Deletes a translation of a post or term. * * @since 0.5 * - * @param int $id post id or term id + * @param int $id Object id ( typically a post_id or term_id ). + * @return void */ public function delete_translation( $id ) { $id = (int) $id; $term = $this->get_object_term( $id, $this->tax_translations ); if ( ! empty( $term ) ) { - $d = unserialize( $term->description ); - $slug = array_search( $id, $this->get_translations( $id ) ); // in case some plugin stores the same value with different key - unset( $d[ $slug ] ); + $d = maybe_unserialize( $term->description ); + if ( is_array( $d ) ) { + $slug = array_search( $id, $this->get_translations( $id ) ); // In case some plugin stores the same value with different key. + unset( $d[ $slug ] ); + } if ( empty( $d ) ) { wp_delete_term( (int) $term->term_id, $this->tax_translations ); - } - else { - wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => serialize( $d ) ) ); + } else { + wp_update_term( (int) $term->term_id, $this->tax_translations, array( 'description' => maybe_serialize( $d ) ) ); } } } /** - * Returns an array of translations of a post or term + * Returns an array of translations of a post or term. * * @since 0.5 * - * @param int $id post id or term id - * @return array an associative array of translations with language code as key and translation id as value + * @param int $id Object id ( typically a post_id or term_id ). + * @return int[] An associative array of translations with language code as key and translation id as value. */ public function get_translations( $id ) { $term = $this->get_object_term( $id, $this->tax_translations ); - $translations = empty( $term ) ? array() : unserialize( $term->description ); + $translations = empty( $term ) ? array() : maybe_unserialize( $term->description ); - // make sure we return only translations ( thus we allow plugins to store other information in the array ) + // Make sure we return only translations ( thus we allow plugins to store other information in the array ). if ( is_array( $translations ) ) { $translations = array_intersect_key( $translations, array_flip( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ); } - // make sure to return at least the passed post or term in its translation array + // Make sure to return at least the passed object in its translation array. if ( empty( $translations ) && $lang = $this->get_language( $id ) ) { $translations = array( $lang->slug => $id ); } @@ -192,13 +317,13 @@ abstract class PLL_Translated_Object { } /** - * Returns the id of the translation of a post or term + * Returns the id of the translation of a post or term. * * @since 0.5 * - * @param int $id post id or term id - * @param object|string $lang object or slug - * @return bool|int post id or term id of the translation, false if there is none + * @param int $id Object id ( typically a post_id or term_id ). + * @param PLL_Language|string $lang Language ( slug or object ). + * @return int|false Object id of the translation, false if there is none. */ public function get_translation( $id, $lang ) { if ( ! $lang = $this->model->get_language( $lang ) ) { @@ -215,41 +340,56 @@ abstract class PLL_Translated_Object { * * @since 0.1 * - * @param int $id post id or term id - * @param int|string|object $lang language ( term_id or slug or object ) - * @return bool|int the translation post id or term id if exists, otherwise the post id or term id, false if the post has no language + * @param int $id Object id ( typically a post_id or term_id ). + * @param int|string|PLL_Language $lang Language ( term_id or slug or object ). + * @return int|false The translation object id if exists, otherwise the passed id, false if the passed object has no language. */ public function get( $id, $lang ) { - $obj_lang = $this->get_language( $id ); // FIXME is this necessary? - if ( ! $lang || ! $obj_lang ) { + $id = (int) $id; + $lang = $this->model->get_language( $lang ); + $obj_lang = $this->get_language( $id ); + if ( empty( $lang ) || empty( $obj_lang ) ) { return false; } - $lang = $this->model->get_language( $lang ); return $obj_lang->term_id == $lang->term_id ? $id : $this->get_translation( $id, $lang ); } /** - * A where clause to add to sql queries when filtering by language is needed directly in query + * A join clause to add to sql queries when filtering by language is needed directly in query. * * @since 1.2 * - * @param object|array|string $lang a PLL_Language object or a comma separated list of language slug or an array of language slugs - * @return string where clause + * @param string $alias Optional alias for object table. + * @return string Join clause. + */ + abstract public function join_clause( $alias = '' ); + + /** + * A where clause to add to sql queries when filtering by language is needed directly in query. + * + * @since 1.2 + * + * @param PLL_Language|string|string[] $lang PLL_Language object or a comma separated list of language slug or an array of language slugs. + * @return string Where clause. */ public function where_clause( $lang ) { - global $wpdb; $tt_id = $this->tax_tt; - // $lang is an object - // generally the case if the query is coming from Polylang + /* + * $lang is an object. + * This is generally the case if the query is coming from Polylang. + */ if ( is_object( $lang ) ) { return ' AND pll_tr.term_taxonomy_id = ' . absint( $lang->$tt_id ); } - // $lang is a comma separated list of slugs ( or an array of slugs ) - // generally the case is the query is coming from outside with 'lang' parameter - $slugs = is_array( $lang ) ? $lang : explode( ',', $lang ); + /* + * $lang is a comma separated list of slugs ( or an array of slugs ). + * This is generally the case is the query is coming from outside with a 'lang' parameter. + */ + $slugs = is_array( $lang ) ? $lang : explode( ',', $lang ); + $languages = array(); foreach ( $slugs as $slug ) { $languages[] = absint( $this->model->get_language( $slug )->$tt_id ); } @@ -258,17 +398,71 @@ abstract class PLL_Translated_Object { } /** - * Returns ids of objects in a language similarly to get_objects_in_term for a taxonomy - * faster than get_objects_in_term as it avoids a JOIN + * Returns ids of objects in a language similarly to get_objects_in_term() for a taxonomy. + * It is faster than get_objects_in_term() as it avoids a JOIN. * * @since 1.4 * - * @param object $lang a PLL_Language object - * @return array + * @param PLL_Language $lang PLL_Language object. + * @return int[] Object ids. */ public function get_objects_in_language( $lang ) { global $wpdb; $tt_id = $this->tax_tt; - return $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $lang->$tt_id ) ); + + $last_changed = wp_cache_get_last_changed( 'terms' ); + $cache_key = "polylang:get_objects_in_language:{$lang->$tt_id}:{$last_changed}"; + $cache = wp_cache_get( $cache_key, 'terms' ); + + if ( false === $cache ) { + $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $lang->$tt_id ) ); + wp_cache_set( $cache_key, $object_ids, 'terms' ); + } else { + $object_ids = (array) $cache; + } + + if ( ! $object_ids ) { + return array(); + } + + return $object_ids; + } + + /** + * Check if a user can synchronize translations. + * + * @since 2.6 + * + * @param int $id Object id. + * @return bool + */ + public function current_user_can_synchronize( $id ) { + /** + * Filters whether a synchronization capability check should take place. + * + * @since 2.6 + * + * @param bool|null $check Null to enable the capability check, + * true to always allow the synchronization, + * false to always disallow the synchronization. + * Defaults to true. + * @param int $id The synchronization source object id. + */ + $check = apply_filters( "pll_pre_current_user_can_synchronize_{$this->type}", true, $id ); + if ( null !== $check ) { + return $check; + } + + if ( ! current_user_can( "edit_{$this->type}", $id ) ) { + return false; + } + + foreach ( $this->get_translations( $id ) as $tr_id ) { + if ( $tr_id !== $id && ! current_user_can( "edit_{$this->type}", $tr_id ) ) { + return false; + } + } + + return true; } } diff --git a/wp-content/plugins/polylang/include/translated-post.php b/wp-content/plugins/polylang/include/translated-post.php index 7d7e7821..cb069b32 100644 --- a/wp-content/plugins/polylang/include/translated-post.php +++ b/wp-content/plugins/polylang/include/translated-post.php @@ -1,4 +1,7 @@ object_type = null; + $this->object_type = null; // For taxonomies + $this->type = 'post'; // For capabilities $this->tax_language = 'language'; $this->tax_translations = 'post_translations'; $this->tax_tt = 'term_taxonomy_id'; @@ -34,17 +38,20 @@ class PLL_Translated_Post extends PLL_Translated_Object { } /** - * Store the post language in the database + * Store the post language in the database. * * @since 0.6 * - * @param int $post_id post id - * @param int|string|object $lang language ( term_id or slug or object ) + * @param int $post_id Post id. + * @param int|string|PLL_Language $lang Language (term_id or slug or object). + * @return void */ public function set_language( $post_id, $lang ) { $old_lang = $this->get_language( $post_id ); $old_lang = $old_lang ? $old_lang->slug : ''; - $lang = $lang ? $this->model->get_language( $lang )->slug : ''; + + $lang = $this->model->get_language( $lang ); + $lang = $lang ? $lang->slug : ''; if ( $old_lang !== $lang ) { wp_set_post_terms( (int) $post_id, $lang, 'language' ); @@ -57,7 +64,7 @@ class PLL_Translated_Post extends PLL_Translated_Object { * @since 0.1 * * @param int $post_id post id - * @return bool|object PLL_Language object, false if no language is associated to that post + * @return PLL_Language|false PLL_Language object, false if no language is associated to that post */ public function get_language( $post_id ) { $lang = $this->get_object_term( $post_id, 'language' ); @@ -65,15 +72,16 @@ class PLL_Translated_Post extends PLL_Translated_Object { } /** - * Deletes a translation + * Deletes a translation. * * @since 0.5 * - * @param int $id post id + * @param int $id Post id. + * @return void */ public function delete_translation( $id ) { parent::delete_translation( $id ); - wp_set_object_terms( $id, null, $this->tax_translations ); + wp_set_object_terms( $id, array(), $this->tax_translations ); } /** @@ -96,23 +104,28 @@ class PLL_Translated_Post extends PLL_Translated_Object { * Register the language taxonomy * * @since 1.2 + * + * @return void */ public function register_taxonomy() { - register_taxonomy( 'language', $this->model->get_translated_post_types(), array( - 'labels' => array( - 'name' => __( 'Languages', 'polylang' ), - 'singular_name' => __( 'Language', 'polylang' ), - 'all_items' => __( 'All languages', 'polylang' ), - ), - // FIXME backward compatibility with WP 4.4.x: we must keep public to true for WP to accept our query var - 'public' => version_compare( $GLOBALS['wp_version'], '4.4', '>=' ) && version_compare( $GLOBALS['wp_version'], '4.5', '<' ), - 'show_ui' => false, // hide the taxonomy on admin side, needed for WP 4.4.x - 'show_in_nav_menus' => false, // no metabox for nav menus, needed for WP 4.4.x - 'publicly_queryable' => true, // since WP 4.5 - 'query_var' => 'lang', - 'rewrite' => $this->model->options['force_lang'] < 2, // no rewrite for domains and sub-domains - '_pll' => true, // polylang taxonomy - ) ); + register_taxonomy( + 'language', + $this->model->get_translated_post_types(), + array( + 'labels' => array( + 'name' => __( 'Languages', 'polylang' ), + 'singular_name' => __( 'Language', 'polylang' ), + 'all_items' => __( 'All languages', 'polylang' ), + ), + 'public' => false, + 'show_ui' => false, // hide the taxonomy on admin side, needed for WP 4.4.x + 'show_in_nav_menus' => false, // no metabox for nav menus, needed for WP 4.4.x + 'publicly_queryable' => true, // since WP 4.5 + 'query_var' => 'lang', + 'rewrite' => $this->model->options['force_lang'] < 2, // no rewrite for domains and sub-domains + '_pll' => true, // polylang taxonomy + ) + ); } /** @@ -121,6 +134,7 @@ class PLL_Translated_Post extends PLL_Translated_Object { * @since 1.2 * * @param string $post_type post type name + * @return void */ public function registered_post_type( $post_type ) { if ( $this->model->is_translated_post_type( $post_type ) ) { @@ -130,17 +144,126 @@ class PLL_Translated_Post extends PLL_Translated_Object { } /** - * Forces calling 'update_object_term_cache' when querying posts or pages - * this is especially useful for nav menus with a lot of pages - * without doing this, we would have one query per page in the menu to get the page language for the permalink + * Forces calling 'update_object_term_cache' when querying posts or pages. + * This is especially useful for nav menus with a lot of pages as, without doing this, + * we would have one query per page in the menu to get the page language for the permalink. * * @since 1.8 * - * @param object $query reference to the query object + * @param WP_Query $query Reference to the query object. + * @return void */ public function pre_get_posts( $query ) { if ( ! empty( $query->query['post_type'] ) && $this->model->is_translated_post_type( $query->query['post_type'] ) ) { $query->query_vars['update_post_term_cache'] = true; } } + + /** + * Checks if the current user can read the post + * + * @since 1.5 + * + * @param int $post_id Post ID + * @param string $context Optional, 'edit' or 'view', defaults to 'view'. + * @return bool + */ + public function current_user_can_read( $post_id, $context = 'view' ) { + $post = get_post( $post_id ); + + if ( empty( $post ) ) { + return false; + } + + if ( 'inherit' === $post->post_status && $post->post_parent ) { + $post = get_post( $post->post_parent ); + + if ( empty( $post ) ) { + return false; + } + } + + if ( 'inherit' === $post->post_status || in_array( $post->post_status, get_post_stati( array( 'public' => true ) ) ) ) { + return true; + } + + // Follow WP practices, which shows links to private posts ( when readable ), but not for draft posts ( ex: get_adjacent_post_link() ) + if ( in_array( $post->post_status, get_post_stati( array( 'private' => true ) ) ) ) { + $post_type_object = get_post_type_object( $post->post_type ); + $user = wp_get_current_user(); + return is_user_logged_in() && ( current_user_can( $post_type_object->cap->read_private_posts ) || $user->ID == $post->post_author ); // Comparison must not be strict! + } + + // In edit context, show draft and future posts. + if ( 'edit' === $context ) { + $states = get_post_stati( + array( + 'protected' => true, + 'show_in_admin_all_list' => true, + ) + ); + + if ( in_array( $post->post_status, $states ) ) { + $user = wp_get_current_user(); + return is_user_logged_in() && ( current_user_can( 'edit_posts' ) || $user->ID == $post->post_author ); // Comparison must not be strict! + } + } + + return false; + } + + /** + * Returns a list of posts in a language ( $lang ) + * not translated in another language ( $untranslated_in ). + * + * @since 2.6 + * + * @param string $type Post type. + * @param PLL_Language $untranslated_in The language the posts must not be translated in. + * @param PLL_Language $lang Language of the searched posts. + * @param string $search Limit the results to the posts matching this string. + * @return WP_Post[] Array of posts. + */ + public function get_untranslated( $type, $untranslated_in, $lang, $search = '' ) { + $return = array(); + + // Don't order by title: see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough + $args = array( + 's' => $search, + 'suppress_filters' => 0, // To make the post_fields filter work + 'lang' => 0, // Avoid admin language filter + 'numberposts' => 20, // Limit to 20 posts + 'post_status' => 'any', + 'post_type' => $type, + 'tax_query' => array( + array( + 'taxonomy' => 'language', + 'field' => 'term_taxonomy_id', // WP 3.5+ + 'terms' => $lang->term_taxonomy_id, + ), + ), + ); + + /** + * Filter the query args when auto suggesting untranslated posts in the Languages metabox + * This should help plugins to fix some edge cases + * + * @see https://wordpress.org/support/topic/find-translated-post-when-10-is-not-enough + * + * @since 1.7 + * + * @param array $args WP_Query arguments + */ + $args = apply_filters( 'pll_ajax_posts_not_translated_args', $args ); + $posts = get_posts( $args ); + + foreach ( $posts as $post ) { + if ( $post instanceof WP_Post && ! $this->get_translation( $post->ID, $untranslated_in ) && $this->current_user_can_read( $post->ID, 'edit' ) ) { + $return[] = $post; + } + } + + return $return; + } + } diff --git a/wp-content/plugins/polylang/include/translated-term.php b/wp-content/plugins/polylang/include/translated-term.php index 27ec290d..ebd55fb4 100644 --- a/wp-content/plugins/polylang/include/translated-term.php +++ b/wp-content/plugins/polylang/include/translated-term.php @@ -1,4 +1,7 @@ object_type = 'term'; + $this->object_type = 'term'; // For taxonomies + $this->type = 'term'; // For capabilities $this->tax_language = 'term_language'; $this->tax_translations = 'term_translations'; $this->tax_tt = 'tl_term_taxonomy_id'; @@ -24,25 +28,28 @@ class PLL_Translated_Term extends PLL_Translated_Object { // Filters to prime terms cache add_filter( 'get_terms', array( $this, '_prime_terms_cache' ), 10, 2 ); - add_filter( 'wp_get_object_terms', array( $this, 'wp_get_object_terms' ), 10, 3 ); + add_filter( 'get_object_terms', array( $this, 'wp_get_object_terms' ), 10, 3 ); add_action( 'clean_term_cache', array( $this, 'clean_term_cache' ) ); } /** - * Stores the term language in the database + * Stores the term language in the database. * * @since 0.6 * - * @param int $term_id term id - * @param int|string|object $lang language ( term_id or slug or object ) + * @param int $term_id Term id. + * @param int|string|PLL_Language $lang Language (term_id or slug or object). + * @return void */ public function set_language( $term_id, $lang ) { $term_id = (int) $term_id; $old_lang = $this->get_language( $term_id ); $old_lang = $old_lang ? $old_lang->tl_term_id : ''; - $lang = $lang ? $this->model->get_language( $lang )->tl_term_id : ''; + + $lang = $this->model->get_language( $lang ); + $lang = $lang ? $lang->tl_term_id : ''; if ( $old_lang !== $lang ) { wp_set_object_terms( $term_id, $lang, 'term_language' ); @@ -63,6 +70,7 @@ class PLL_Translated_Term extends PLL_Translated_Object { * @since 0.5 * * @param int $term_id term id + * @return void */ public function delete_language( $term_id ) { wp_delete_object_term_relationships( $term_id, 'term_language' ); @@ -75,7 +83,7 @@ class PLL_Translated_Term extends PLL_Translated_Object { * * @param int|string $value term id or term slug * @param string $taxonomy optional taxonomy needed when the term slug is passed as first parameter - * @return bool|object PLL_Language object, false if no language is associated to that term + * @return PLL_Language|false PLL_Language object, false if no language is associated to that term */ public function get_language( $value, $taxonomy = '' ) { if ( is_numeric( $value ) ) { @@ -84,7 +92,10 @@ class PLL_Translated_Term extends PLL_Translated_Object { // get_term_by still not cached in WP 3.5.1 but internally, the function is always called by term_id elseif ( is_string( $value ) && $taxonomy ) { - $term_id = wpcom_vip_get_term_by( 'slug', $value, $taxonomy )->term_id; + $term = get_term_by( 'slug', $value, $taxonomy ); + if ( $term instanceof WP_Term ) { + $term_id = $term->term_id; + } } // Get the language and make sure it is a PLL_Language object @@ -92,12 +103,13 @@ class PLL_Translated_Term extends PLL_Translated_Object { } /** - * Tells whether a translation term must updated + * Tells whether a translation term must updated. * * @since 2.3 * - * @param array $id Post id or term id - * @param array $translations An associative array of translations with language code as key and translation id as value + * @param int $id Post id or term id. + * @param int[] $translations An associative array of translations with language code as key and translation id as value. + * @return bool */ protected function should_update_translation_group( $id, $translations ) { // Don't do anything if no translations have been added to the group @@ -117,6 +129,7 @@ class PLL_Translated_Term extends PLL_Translated_Object { * @since 0.5 * * @param int $id term id + * @return void */ public function delete_translation( $id ) { global $wpdb; @@ -125,10 +138,10 @@ class PLL_Translated_Term extends PLL_Translated_Object { parent::delete_translation( $id ); wp_delete_object_term_relationships( $id, 'term_translations' ); - if ( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) FROM $wpdb->terms WHERE term_id = %d;", $id ) ) ) { + if ( ! doing_action( 'pre_delete_term' ) && $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( * ) FROM $wpdb->terms WHERE term_id = %d;", $id ) ) ) { // Always keep a group for terms to allow relationships remap when importing from a WXR file - $translations[ $slug ] = $id; - wp_insert_term( $group = uniqid( 'pll_' ), 'term_translations', array( 'description' => serialize( $translations ) ) ); + $translations = array( $slug => $id ); + wp_insert_term( $group = uniqid( 'pll_' ), 'term_translations', array( 'description' => maybe_serialize( $translations ) ) ); wp_set_object_terms( $id, $group, 'term_translations' ); } } @@ -137,24 +150,28 @@ class PLL_Translated_Term extends PLL_Translated_Object { * A join clause to add to sql queries when filtering by language is needed directly in query * * @since 1.2 + * @since 2.6 The `$alias` parameter was added. * + * @param string $alias Alias for $wpdb->terms table * @return string join clause */ - public function join_clause() { + public function join_clause( $alias = 't' ) { global $wpdb; - return " INNER JOIN $wpdb->term_relationships AS pll_tr ON pll_tr.object_id = t.term_id"; + return " INNER JOIN $wpdb->term_relationships AS pll_tr ON pll_tr.object_id = $alias.term_id"; } /** - * Cache language and translations when terms are queried by get_terms + * Caches the language and translations when terms are queried by get_terms(). * * @since 1.2 * - * @param array $terms queried terms - * @param array $taxonomies queried taxonomies - * @return array unmodified $terms + * @param WP_Term[]|int[] $terms Queried terms. + * @param string[] $taxonomies Queried taxonomies. + * @return WP_Term[]|int[] Unmodified $terms. */ public function _prime_terms_cache( $terms, $taxonomies ) { + $term_ids = array(); + if ( is_array( $terms ) && $this->model->is_translated_taxonomy( $taxonomies ) ) { foreach ( $terms as $term ) { $term_ids[] = is_object( $term ) ? $term->term_id : (int) $term; @@ -168,17 +185,16 @@ class PLL_Translated_Term extends PLL_Translated_Object { } /** - * When terms are found for posts, add their language and translations to cache + * When terms are found for posts, add their language and translations to cache. * * @since 1.2 * - * @param array $terms terms found - * @param array $object_ids not used - * @param array $taxonomies terms taxonomies - * @return array unmodified $terms + * @param WP_Term[] $terms Array of terms for the given object or objects. + * @param int[] $object_ids Array of object IDs for which terms were retrieved. + * @param string[] $taxonomies Array of taxonomy names from which terms were retrieved. + * @return WP_Term[] Unmodified $terms. */ public function wp_get_object_terms( $terms, $object_ids, $taxonomies ) { - $taxonomies = explode( "', '", trim( $taxonomies, "'" ) ); if ( ! in_array( 'term_translations', $taxonomies ) ) { $this->_prime_terms_cache( $terms, $taxonomies ); } @@ -186,13 +202,14 @@ class PLL_Translated_Term extends PLL_Translated_Object { } /** - * When the term cache is cleaned, clean the object term cache too + * When the term cache is cleaned, cleans the object term cache too. * * @since 2.0 * - * @param array $ids An array of term IDs. + * @param int[] $ids An array of term IDs. + * @return void */ - function clean_term_cache( $ids ) { + public function clean_term_cache( $ids ) { clean_object_term_cache( $ids, 'term' ); } } diff --git a/wp-content/plugins/polylang/include/walker-dropdown.php b/wp-content/plugins/polylang/include/walker-dropdown.php index ef38fa99..70581013 100644 --- a/wp-content/plugins/polylang/include/walker-dropdown.php +++ b/wp-content/plugins/polylang/include/walker-dropdown.php @@ -1,4 +1,7 @@ 'parent', 'id' => 'id' ); + /** + * Database fields to use. + * + * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields. + * + * @var array + */ + public $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); /** * Outputs one element * * @since 1.2 * - * @param string $output Passed by reference. Used to append additional content. - * @param object $element The data object. - * @param int $depth Depth of the item. - * @param array $args An array of additional arguments. - * @param int $current_object_id ID of the current item. + * @param string $output Passed by reference. Used to append additional content. + * @param stdClass $element The data object. + * @param int $depth Depth of the item. + * @param array $args An array of additional arguments. + * @param int $current_object_id ID of the current item. + * @return void */ - function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { + public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $value = $args['value']; $output .= sprintf( "\t" . '' . "\n", esc_attr( $element->$value ), method_exists( $element, 'get_locale' ) ? sprintf( ' lang="%s"', esc_attr( $element->get_locale( 'display' ) ) ) : '', - isset( $args['selected'] ) && $args['selected'] === $element->$value ? ' selected="selected"' : '', + selected( isset( $args['selected'] ) && $args['selected'] === $element->$value, true, false ), esc_html( $element->name ) ); } @@ -35,14 +46,15 @@ class PLL_Walker_Dropdown extends Walker { * * @since 1.2 * - * @param object $element Data object. - * @param array $children_elements List of elements to continue traversing. - * @param int $max_depth Max depth to traverse. - * @param int $depth Depth of current element. - * @param array $args An array of arguments. - * @param string $output Passed by reference. Used to append additional content. + * @param stdClass $element Data object. + * @param array $children_elements List of elements to continue traversing. + * @param int $max_depth Max depth to traverse. + * @param int $depth Depth of current element. + * @param array $args An array of arguments. + * @param string $output Passed by reference. Used to append additional content. + * @return void */ - function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { + public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { $element = (object) $element; // Make sure we have an object $element->parent = $element->id = 0; // Don't care about this parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); @@ -52,6 +64,7 @@ class PLL_Walker_Dropdown extends Walker { * Starts the output of the dropdown list * * @since 1.2 + * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3 * * List of parameters accepted in $args: * @@ -63,12 +76,30 @@ class PLL_Walker_Dropdown extends Walker { * class => the class attribute * disabled => disables the dropdown if set to 1 * - * @param array $elements elements to display - * @param array $args - * @return string + * @param array $elements An array of elements. + * @param int $max_depth The maximum hierarchical depth. + * @param mixed ...$args Additional arguments. + * @return string The hierarchical item output. */ - function walk( $elements, $args = array() ) { + public function walk( $elements, $max_depth, ...$args ) { // // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility $output = ''; + + if ( is_array( $max_depth ) ) { // @phpstan-ignore-line + // Backward compatibility with Polylang < 2.6.7 + if ( WP_DEBUG ) { + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions + sprintf( + '%s was called incorrectly. The method expects an integer as second parameter since Polylang 2.6.7', + __METHOD__ + ) + ); + } + $args = $max_depth; + $max_depth = -1; + } else { + $args = isset( $args[0] ) ? $args[0] : array(); + } + $args = wp_parse_args( $args, array( 'value' => 'slug', 'name' => 'lang_choice' ) ); if ( ! empty( $args['flag'] ) ) { @@ -82,11 +113,11 @@ class PLL_Walker_Dropdown extends Walker { $output .= sprintf( '' . "\n", - $name = esc_attr( $args['name'] ), - isset( $args['id'] ) && ! $args['id'] ? '' : ' id="' . ( empty( $args['id'] ) ? $name : esc_attr( $args['id'] ) ) . '"', + esc_attr( $args['name'] ), + isset( $args['id'] ) && ! $args['id'] ? '' : ' id="' . ( empty( $args['id'] ) ? esc_attr( $args['name'] ) : esc_attr( $args['id'] ) ) . '"', empty( $args['class'] ) ? '' : ' class="' . esc_attr( $args['class'] ) . '"', - empty( $args['disabled'] ) ? '' : ' disabled="disabled"', - parent::walk( $elements, -1, $args ) + disabled( empty( $args['disabled'] ), false, false ), + parent::walk( $elements, $max_depth, $args ) ); return $output; diff --git a/wp-content/plugins/polylang/include/walker-list.php b/wp-content/plugins/polylang/include/walker-list.php index d42747ab..0eda1419 100644 --- a/wp-content/plugins/polylang/include/walker-list.php +++ b/wp-content/plugins/polylang/include/walker-list.php @@ -1,4 +1,7 @@ 'parent', 'id' => 'id' ); + /** + * Database fields to use. + * + * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields. + * + * @var array + */ + public $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); /** * Outputs one element * * @since 1.2 * - * @param string $output Passed by reference. Used to append additional content. - * @param object $element The data object. - * @param int $depth Depth of the item. - * @param array $args An array of additional arguments. - * @param int $current_object_id ID of the current item. + * @param string $output Passed by reference. Used to append additional content. + * @param stdClass $element The data object. + * @param int $depth Depth of the item. + * @param array $args An array of additional arguments. + * @param int $current_object_id ID of the current item. + * @return void */ - function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { + public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $output .= sprintf( - '%6$s
  • %4$s%5$s
  • %7$s', + '%6$s
  • %4$s%5$s
  • %7$s', esc_attr( implode( ' ', $element->classes ) ), esc_attr( $element->locale ), esc_url( $element->url ), $element->flag, - $args['show_flags'] ? sprintf( '%2$s', is_rtl() ? 'right' : 'left', esc_html( $element->name ) ) : esc_html( $element->name ), + $args['show_flags'] && $args['show_names'] ? sprintf( '%2$s', is_rtl() ? 'right' : 'left', esc_html( $element->name ) ) : esc_html( $element->name ), 'discard' === $args['item_spacing'] ? '' : "\t", - 'discard' === $args['item_spacing'] ? '' : "\n" + 'discard' === $args['item_spacing'] ? '' : "\n", + empty( $element->link_classes ) ? '' : 'class="' . esc_attr( implode( ' ', $element->link_classes ) ) . '"' ); } @@ -37,14 +49,15 @@ class PLL_Walker_List extends Walker { * * @since 1.2 * - * @param object $element Data object. - * @param array $children_elements List of elements to continue traversing. - * @param int $max_depth Max depth to traverse. - * @param int $depth Depth of current element. - * @param array $args An array of arguments. - * @param string $output Passed by reference. Used to append additional content. + * @param stdClass $element Data object. + * @param array $children_elements List of elements to continue traversing. + * @param int $max_depth Max depth to traverse. + * @param int $depth Depth of current element. + * @param array $args An array of arguments. + * @param string $output Passed by reference. Used to append additional content. + * @return void */ - function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { + public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { $element = (object) $element; // Make sure we have an object $element->parent = $element->id = 0; // Don't care about this parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); @@ -54,12 +67,30 @@ class PLL_Walker_List extends Walker { * Overrides Walker:walk to set depth argument * * @since 1.2 + * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3 * - * @param array $elements elements to display - * @param array $args - * @return string + * @param array $elements An array of elements. + * @param int $max_depth The maximum hierarchical depth. + * @param mixed ...$args Additional arguments. + * @return string The hierarchical item output. */ - function walk( $elements, $args = array() ) { - return parent::walk( $elements, -1, $args ); + public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility + if ( is_array( $max_depth ) ) { // @phpstan-ignore-line + // Backward compatibility with Polylang < 2.6.7 + if ( WP_DEBUG ) { + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions + sprintf( + '%s was called incorrectly. The method expects an integer as second parameter since Polylang 2.6.7', + __METHOD__ + ) + ); + } + $args = $max_depth; + $max_depth = -1; + } else { + $args = isset( $args[0] ) ? $args[0] : array(); + } + + return parent::walk( $elements, $max_depth, $args ); } } diff --git a/wp-content/plugins/polylang/include/widget-calendar.php b/wp-content/plugins/polylang/include/widget-calendar.php index 2a8eb7ad..10eabe7e 100644 --- a/wp-content/plugins/polylang/include/widget-calendar.php +++ b/wp-content/plugins/polylang/include/widget-calendar.php @@ -1,58 +1,73 @@ not very efficient (add 4 to 5 sql queries) - * method used since 0.5: remove the WP widget and replace it by our own -> our language filter will not work if get_calendar is called directly by a theme + * This classes rewrite the whole Calendar widget functionality as there is no filter on sql queries and only a filter on final output. + * Code last checked: WP 5.5. + * + * A request to add filters on sql queries exists: http://core.trac.wordpress.org/ticket/15202. + * Method used in 0.4.x: use of the get_calendar filter and overwrite the output of get_calendar function -> not very efficient (add 4 to 5 sql queries). + * Method used since 0.5: remove the WP widget and replace it by our own -> our language filter will not work if get_calendar is called directly by a theme. * * @since 0.5 */ class PLL_Widget_Calendar extends WP_Widget_Calendar { + protected static $pll_instance = 0; // Can't use $instance of WP_Widget_Calendar as it's private :/. /** - * displays the widget - * modified version of the parent function to call our own get_calendar function + * Outputs the content for the current Calendar widget instance. + * Modified version of the parent function to call our own get_calendar() method. * * @since 0.5 * - * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance The settings for the particular instance of the widget + * @param array $args Display arguments including 'before_title', 'after_title', + * 'before_widget', and 'after_widget'. + * @param array $instance The settings for the particular instance of the widget. */ - function widget( $args, $instance ) { + public function widget( $args, $instance ) { + $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ - $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? ' ' : $instance['title'], $instance, $this->id_base ); + $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); + echo $args['before_widget']; if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; } - echo '
    '; + if ( 0 === self::$pll_instance ) { #modified# + echo '
    '; + } else { + echo '
    '; + } empty( PLL()->curlang ) ? get_calendar() : self::get_calendar(); #modified# echo '
    '; echo $args['after_widget']; + + self::$pll_instance++; #modified# } /** - * modified version of WP get_calendar function to filter the query + * Modified version of the WP get_calendar() function to filter the queries. * * @since 0.5 * * @param bool $initial Optional, default is true. Use initial calendar names. - * @param bool $echo Optional, default is true. Set to false for return. - * @return string|null String when retrieving, null when displaying. + * @param bool $echo Optional, default is true. Set to false for return. + * @return void|string Void if `$echo` argument is true, calendar HTML if `$echo` is false. */ - static function get_calendar( $initial = true, $echo = true ) { + static public function get_calendar( $initial = true, $echo = true ) { global $wpdb, $m, $monthnum, $year, $wp_locale, $posts; - $join_clause = PLL()->model->post->join_clause(); #added# + $join_clause = PLL()->model->post->join_clause(); #added# $where_clause = PLL()->model->post->where_clause( PLL()->curlang ); #added# - $key = md5( PLL()->curlang->slug . $m . $monthnum . $year ); #modified# + $key = md5( PLL()->curlang->slug . $m . $monthnum . $year ); #modified# $cache = wp_cache_get( 'get_calendar', 'calendar' ); if ( $cache && is_array( $cache ) && isset( $cache[ $key ] ) ) { @@ -73,7 +88,7 @@ class PLL_Widget_Calendar extends WP_Widget_Calendar { // Quick check. If we have no posts at all, abort! if ( ! $posts ) { - $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); + $gotsome = $wpdb->get_var( "SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1" ); if ( ! $gotsome ) { $cache[ $key ] = ''; wp_cache_set( 'get_calendar', $cache, 'calendar' ); @@ -84,20 +99,19 @@ class PLL_Widget_Calendar extends WP_Widget_Calendar { if ( isset( $_GET['w'] ) ) { $w = (int) $_GET['w']; } - // week_begins = 0 stands for Sunday + // week_begins = 0 stands for Sunday. $week_begins = (int) get_option( 'start_of_week' ); - $ts = current_time( 'timestamp' ); - // Let's figure out when we are + // Let's figure out when we are. if ( ! empty( $monthnum ) && ! empty( $year ) ) { - $thismonth = zeroise( intval( $monthnum ), 2 ); - $thisyear = (int) $year; + $thismonth = zeroise( (int) $monthnum, 2 ); + $thisyear = (int) $year; } elseif ( ! empty( $w ) ) { - // We need to get the month from MySQL + // We need to get the month from MySQL. $thisyear = (int) substr( $m, 0, 4 ); - //it seems MySQL's weeks disagree with PHP's - $d = ( ( $w - 1 ) * 7 ) + 6; - $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')"); + // It seems MySQL's weeks disagree with PHP's. + $d = ( ( $w - 1 ) * 7 ) + 6; + $thismonth = $wpdb->get_var( "SELECT DATE_FORMAT((DATE_ADD('{$thisyear}0101', INTERVAL $d DAY) ), '%m')" ); } elseif ( ! empty( $m ) ) { $thisyear = (int) substr( $m, 0, 4 ); if ( strlen( $m ) < 6 ) { @@ -106,34 +120,38 @@ class PLL_Widget_Calendar extends WP_Widget_Calendar { $thismonth = zeroise( (int) substr( $m, 4, 2 ), 2 ); } } else { - $thisyear = gmdate( 'Y', $ts ); - $thismonth = gmdate( 'm', $ts ); + $thisyear = current_time( 'Y' ); + $thismonth = current_time( 'm' ); } - $unixmonth = mktime( 0, 0 , 0, $thismonth, 1, $thisyear ); - $last_day = date( 't', $unixmonth ); + $unixmonth = mktime( 0, 0, 0, $thismonth, 1, $thisyear ); + $last_day = gmdate( 't', $unixmonth ); - // Get the next and previous month and year with at least one post - $previous = $wpdb->get_row( "SELECT MONTH( post_date ) AS month, YEAR( post_date ) AS year + // Get the next and previous month and year with at least one post. + $previous = $wpdb->get_row( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts $join_clause WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' $where_clause ORDER BY post_date DESC - LIMIT 1" ); #modified# - $next = $wpdb->get_row( "SELECT MONTH( post_date ) AS month, YEAR( post_date ) AS year + LIMIT 1" + ); #modified# + $next = $wpdb->get_row( + "SELECT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts $join_clause WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' AND post_type = 'post' AND post_status = 'publish' $where_clause ORDER BY post_date ASC - LIMIT 1" ); #modified# + LIMIT 1" + ); #modified# - /* translators: Calendar caption: 1: month name, 2: 4-digit year */ + /* translators: Calendar caption: 1: Month name, 2: 4-digit year. */ $calendar_caption = _x( '%1$s %2$s', 'calendar caption' ); - $calendar_output = ' + $calendar_output = '
    '; @@ -145,84 +163,62 @@ class PLL_Widget_Calendar extends WP_Widget_Calendar { } foreach ( $myweek as $wd ) { - $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); - $wd = esc_attr( $wd ); + $day_name = $initial ? $wp_locale->get_weekday_initial( $wd ) : $wp_locale->get_weekday_abbrev( $wd ); + $wd = esc_attr( $wd ); $calendar_output .= "\n\t\t"; } $calendar_output .= ' - - - '; - - if ( $previous ) { - $calendar_output .= "\n\t\t".''; - } else { - $calendar_output .= "\n\t\t".''; - } - - $calendar_output .= "\n\t\t".''; - - if ( $next ) { - $calendar_output .= "\n\t\t".''; - } else { - $calendar_output .= "\n\t\t".''; - } - - $calendar_output .= ' - - - '; $daywithpost = array(); - // Get days with posts - $dayswithposts = $wpdb->get_results( "SELECT DISTINCT DAYOFMONTH( post_date ) - FROM $wpdb->posts $join_clause - WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' - AND post_type = 'post' AND post_status = 'publish' $where_clause - AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N ); #modified# + // Get days with posts. + $dayswithposts = $wpdb->get_results( + "SELECT DISTINCT DAYOFMONTH(post_date) + FROM $wpdb->posts $join_clause WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' + AND post_type = 'post' AND post_status = 'publish' + AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' $where_clause", + ARRAY_N + ); #modified# + if ( $dayswithposts ) { foreach ( (array) $dayswithposts as $daywith ) { - $daywithpost[] = $daywith[0]; + $daywithpost[] = (int) $daywith[0]; } } - // See how much we should pad in the beginning - $pad = calendar_week_mod( date( 'w', $unixmonth ) - $week_begins ); + // See how much we should pad in the beginning. + $pad = calendar_week_mod( gmdate( 'w', $unixmonth ) - $week_begins ); if ( 0 != $pad ) { - $calendar_output .= "\n\t\t".''; + $calendar_output .= "\n\t\t" . ''; } - $newrow = false; - $daysinmonth = (int) date( 't', $unixmonth ); + $newrow = false; + $daysinmonth = (int) gmdate( 't', $unixmonth ); for ( $day = 1; $day <= $daysinmonth; ++$day ) { - if ( isset($newrow) && $newrow ) { + if ( isset( $newrow ) && $newrow ) { $calendar_output .= "\n\t\n\t\n\t\t"; } $newrow = false; - if ( $day == gmdate( 'j', $ts ) && - $thismonth == gmdate( 'm', $ts ) && - $thisyear == gmdate( 'Y', $ts ) ) { + if ( current_time( 'j' ) == $day && + current_time( 'm' ) == $thismonth && + current_time( 'Y' ) == $thisyear ) { $calendar_output .= ''; - if ( 6 == calendar_week_mod( date( 'w', mktime(0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { + if ( 6 == calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ) ) { $newrow = true; } } - $pad = 7 - calendar_week_mod( date( 'w', mktime( 0, 0 , 0, $thismonth, $day, $thisyear ) ) - $week_begins ); - if ( $pad != 0 && $pad != 7 ) { - $calendar_output .= "\n\t\t".''; + $pad = 7 - calendar_week_mod( gmdate( 'w', mktime( 0, 0, 0, $thismonth, $day, $thisyear ) ) - $week_begins ); + if ( 0 != $pad && 7 != $pad ) { + $calendar_output .= "\n\t\t" . ''; } - $calendar_output .= "\n\t\n\t\n\t
    ' . sprintf( $calendar_caption, $wp_locale->get_month( $thismonth ), - date( 'Y', $unixmonth ) + gmdate( 'Y', $unixmonth ) ) . '
    $day_name
    « ' . - $wp_locale->get_month_abbrev( $wp_locale->get_month( $previous->month ) ) . - '  ' . - $wp_locale->get_month_abbrev( $wp_locale->get_month( $next->month ) ) . - ' » 
      
    '; } else { $calendar_output .= ''; } - if ( in_array( $day, $daywithpost ) ) { - // any posts today? - $date_format = date( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); - $label = sprintf( __( 'Posts published on %s' ), $date_format ); + if ( in_array( $day, $daywithpost, true ) ) { + // Any posts today? + $date_format = gmdate( _x( 'F j, Y', 'daily archives date format' ), strtotime( "{$thisyear}-{$thismonth}-{$day}" ) ); + /* translators: Post calendar label. %s: Date. */ + $label = sprintf( __( 'Posts published on %s' ), $date_format ); $calendar_output .= sprintf( '%s', get_day_link( $thisyear, $thismonth, $day ), @@ -232,30 +228,51 @@ class PLL_Widget_Calendar extends WP_Widget_Calendar { } else { $calendar_output .= $day; } + $calendar_output .= '  
    "; + + $calendar_output .= "\n\t\n\t"; + + $calendar_output .= "\n\t"; + + $calendar_output .= ''; $cache[ $key ] = $calendar_output; wp_cache_set( 'get_calendar', $cache, 'calendar' ); if ( $echo ) { - /** - * Filter the HTML calendar output. - * - * @since 3.0.0 - * - * @param string $calendar_output HTML output of the calendar. - */ + /** This filter is documented in wp-includes/general-template.php */ echo apply_filters( 'get_calendar', $calendar_output ); return; } diff --git a/wp-content/plugins/polylang/include/widget-languages.php b/wp-content/plugins/polylang/include/widget-languages.php index 60a97087..ad92c769 100644 --- a/wp-content/plugins/polylang/include/widget-languages.php +++ b/wp-content/plugins/polylang/include/widget-languages.php @@ -1,4 +1,7 @@ __( 'Displays a language switcher', 'polylang' ), + 'description' => __( 'Displays a language switcher', 'polylang' ), 'customize_selective_refresh' => true, ) ); @@ -30,27 +33,51 @@ class PLL_Widget_Languages extends WP_Widget { * * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. * @param array $instance The settings for the particular instance of the widget + * @return void */ - function widget( $args, $instance ) { - // Sets a unique id for dropdown - $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $args['widget_id']; + public function widget( $args, $instance ) { + // Sets a unique id for dropdown. + $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $this->id; if ( $list = pll_the_languages( array_merge( $instance, array( 'echo' => 0 ) ) ) ) { $title = empty( $instance['title'] ) ? '' : $instance['title']; + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); - echo $args['before_widget']; + echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput + if ( $title ) { - echo $args['before_title'] . $title . $args['after_title']; + echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput } + + // The title may be filtered: Strip out HTML and make sure the aria-label is never empty. + $aria_label = trim( wp_strip_all_tags( $title ) ); + if ( ! $aria_label ) { + $aria_label = __( 'Choose a language', 'polylang' ); + } + if ( $instance['dropdown'] ) { - echo ''; - echo $list; + echo ''; + echo $list; // phpcs:ignore WordPress.Security.EscapeOutput } else { - echo "
      \n" . $list . "
    \n"; + $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml'; + + /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */ + $format = apply_filters( 'navigation_widgets_format', $format ); + + if ( 'html5' === $format ) { + echo ''; + } } - echo $args['after_widget']; + + echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput } } @@ -63,8 +90,8 @@ class PLL_Widget_Languages extends WP_Widget { * @param array $old_instance Old settings for this instance * @return array Settings to save or bool false to cancel saving */ - function update( $new_instance, $old_instance ) { - $instance['title'] = strip_tags( $new_instance['title'] ); + public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable + $instance = array( 'title' => sanitize_text_field( $new_instance['title'] ) ); foreach ( array_keys( PLL_Switcher::get_switcher_options( 'widget' ) ) as $key ) { $instance[ $key ] = ! empty( $new_instance[ $key ] ) ? 1 : 0; } @@ -73,87 +100,39 @@ class PLL_Widget_Languages extends WP_Widget { } /** - * Displays the widget form + * Displays the widget form. * * @since 0.4 * - * @param array $instance Current settings + * @param array $instance Current settings. + * @return string */ - function form( $instance ) { + public function form( $instance ) { // Default values $instance = wp_parse_args( (array) $instance, array_merge( array( 'title' => '' ), PLL_Switcher::get_switcher_options( 'widget', 'default' ) ) ); // Title printf( '

    ', - $this->get_field_id( 'title' ), + esc_attr( $this->get_field_id( 'title' ) ), esc_html__( 'Title:', 'polylang' ), - $this->get_field_name( 'title' ), + esc_attr( $this->get_field_name( 'title' ) ), esc_attr( $instance['title'] ) ); - $fields = ''; foreach ( PLL_Switcher::get_switcher_options( 'widget' ) as $key => $str ) { - $fields .= sprintf( + printf( '
    ', - $this->get_field_id( $key ), - $this->get_field_name( $key ), - $instance[ $key ] ? ' checked="checked"' : '', + esc_attr( $this->get_field_id( $key ) ), + esc_attr( $this->get_field_name( $key ) ), + checked( $instance[ $key ], true, false ), esc_html( $str ), - in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' class="no-dropdown-' . $this->id . '"' : '', - ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '', - 'pll-' . $key + in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? sprintf( ' class="no-dropdown-%s"', esc_attr( $this->id ) ) : '', + ( ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '' ), + esc_attr( 'pll-' . $key ) ); } - echo $fields; - - // FIXME echoing script in form is not very clean - // but it does not work if enqueued properly : - // clicking save on a widget makes this code unreachable for the just saved widget ( ?! ) - $this->admin_print_script(); - } - - /** - * Add javascript to control the language switcher options - * - * @since 1.3 - */ - public function admin_print_script() { - static $done = false; - - if ( $done ) { - return; - } - - $done = true; - ?> - - plugin_basename == $_GET['plugin']; + return isset( $_GET['action'], $_GET['plugin'] ) && 'deactivate' === $_GET['action'] && $this->plugin_basename === $_GET['plugin']; // phpcs:ignore WordPress.Security.NonceVerification } /** @@ -44,6 +52,7 @@ class PLL_Install_Base { * * @param string $what Either 'activate' or 'deactivate' * @param bool $networkwide + * @return void */ protected function do_for_all_blogs( $what, $networkwide ) { // Network @@ -69,6 +78,7 @@ class PLL_Install_Base { * @since 1.7 * * @param bool $networkwide + * @return void */ public function activate( $networkwide ) { $this->do_for_all_blogs( 'activate', $networkwide ); @@ -78,6 +88,8 @@ class PLL_Install_Base { * Plugin activation * * @since 0.5 + * + * @return void */ protected function _activate() { // Can be overriden in child class @@ -89,6 +101,7 @@ class PLL_Install_Base { * @since 0.1 * * @param bool $networkwide + * @return void */ public function deactivate( $networkwide ) { $this->do_for_all_blogs( 'deactivate', $networkwide ); @@ -98,20 +111,23 @@ class PLL_Install_Base { * Plugin deactivation * * @since 0.5 + * + * @return void */ protected function _deactivate() { // Can be overriden in child class } /** - * Blog creation on multisite ( to set default options ) + * Site creation on multisite ( to set default options ) * - * @since 0.9.4 + * @since 2.6.8 * - * @param int $blog_id + * @param WP_Site $new_site New site object. + * @return void */ - public function wpmu_new_blog( $blog_id ) { - switch_to_blog( $blog_id ); + public function new_site( $new_site ) { + switch_to_blog( $new_site->id ); $this->_activate(); restore_current_blog(); } diff --git a/wp-content/plugins/polylang/install/install.php b/wp-content/plugins/polylang/install/install.php index 8f2a0407..680ab2af 100644 --- a/wp-content/plugins/polylang/install/install.php +++ b/wp-content/plugins/polylang/install/install.php @@ -1,4 +1,7 @@ %s

    ', - /* translators: %1$s and %2$s are WordPress version numbers */ - sprintf( esc_html__( 'You are using WordPress %1$s. Polylang requires at least WordPress %2$s.', 'polylang' ), - esc_html( $wp_version ), - PLL_MIN_WP_VERSION - ) - ) ); + add_action( 'admin_notices', array( $this, 'wp_version_notice' ) ); + return false; } - $this->do_for_all_blogs( 'activate', $networkwide ); + + return true; } /** - * Get default Polylang options + * Displays a notice if PHP min version is not met. + * + * @since 2.6.7 + * + * @return void + */ + public function php_version_notice() { + load_plugin_textdomain( 'polylang' ); // Plugin i18n. + + printf( + '

    %s

    ', + sprintf( + /* translators: 1: Plugin name 2: Current PHP version 3: Required PHP version */ + esc_html__( '%1$s has deactivated itself because you are using an old version of PHP. You are using using PHP %2$s. %1$s requires PHP %3$s.', 'polylang' ), + esc_html( POLYLANG ), + PHP_VERSION, + esc_html( PLL_MIN_PHP_VERSION ) + ) + ); + } + + /** + * Displays a notice if WP min version is not met. + * + * @since 2.6.7 + * + * @return void + */ + public function wp_version_notice() { + global $wp_version; + + load_plugin_textdomain( 'polylang' ); // Plugin i18n. + + printf( + '

    %s

    ', + sprintf( + /* translators: 1: Plugin name 2: Current WordPress version 3: Required WordPress version */ + esc_html__( '%1$s has deactivated itself because you are using an old version of WordPress. You are using using WordPress %2$s. %1$s requires at least WordPress %3$s.', 'polylang' ), + esc_html( POLYLANG ), + esc_html( $wp_version ), + esc_html( PLL_MIN_WP_VERSION ) + ) + ); + } + + /** + * Get default Polylang options. * * @since 1.8 * - * return array + * @return array */ - static public function get_default_options() { + public static function get_default_options() { return array( - 'browser' => 1, // Default language for the front page is set by browser preference - 'rewrite' => 1, // Remove /language/ in permalinks ( was the opposite before 0.7.2 ) - 'hide_default' => 1, // Remove URL language information for default language ( was the opposite before 2.1.5 ) - 'force_lang' => 1, // Add URL language information ( was 0 before 1.7 ) - 'redirect_lang' => 0, // Do not redirect the language page to the homepage - 'media_support' => 1, // Support languages and translation for media by default - 'uninstall' => 0, // Do not remove data when uninstalling Polylang - 'sync' => array(), // Synchronisation is disabled by default ( was the opposite before 1.2 ) - 'post_types' => array(), - 'taxonomies' => array(), - 'domains' => array(), - 'version' => POLYLANG_VERSION, + 'browser' => 0, // Default language for the front page is not set by browser preference (was the opposite before 3.1). + 'rewrite' => 1, // Remove /language/ in permalinks (was the opposite before 0.7.2). + 'hide_default' => 1, // Remove URL language information for default language (was the opposite before 2.1.5). + 'force_lang' => 1, // Add URL language information (was 0 before 1.7). + 'redirect_lang' => 0, // Do not redirect the language page to the homepage. + 'media_support' => 0, // Do not support languages and translation for media by default (was the opposite before 3.1). + 'uninstall' => 0, // Do not remove data when uninstalling Polylang. + 'sync' => array(), // Synchronisation is disabled by default (was the opposite before 1.2). + 'post_types' => array(), + 'taxonomies' => array(), + 'domains' => array(), + 'version' => POLYLANG_VERSION, + 'first_activation' => time(), ); } @@ -61,6 +108,8 @@ class PLL_Install extends PLL_Install_Base { * Plugin activation * * @since 0.5 + * + * @return void */ protected function _activate() { if ( $options = get_option( 'polylang' ) ) { @@ -90,6 +139,8 @@ class PLL_Install extends PLL_Install_Base { * Plugin deactivation * * @since 0.5 + * + * @return void */ protected function _deactivate() { delete_option( 'rewrite_rules' ); // Don't use flush_rewrite_rules at network activation. See #32471 diff --git a/wp-content/plugins/polylang/install/plugin-updater.php b/wp-content/plugins/polylang/install/plugin-updater.php index 0cb3113f..d7c18c52 100644 --- a/wp-content/plugins/polylang/install/plugin-updater.php +++ b/wp-content/plugins/polylang/install/plugin-updater.php @@ -7,10 +7,10 @@ if ( ! defined( 'ABSPATH' ) ) { /** * Allows plugins to use their own update API. - * Modified version with 'polylang' text domain and comments for translators + * Modified version with 'polylang' text domain and comments for translators. * * @author Easy Digital Downloads - * @version 1.6.15 + * @version 1.8.0 */ class PLL_Plugin_Updater { @@ -22,6 +22,8 @@ class PLL_Plugin_Updater { private $wp_override = false; private $cache_key = ''; + private $health_check_timeout = 5; + /** * Class constructor. * @@ -47,6 +49,15 @@ class PLL_Plugin_Updater { $edd_plugin_data[ $this->slug ] = $this->api_data; + /** + * Fires after the $edd_plugin_data is setup. + * + * @since x.x.x + * + * @param array $edd_plugin_data Array of EDD SL plugin data. + */ + do_action( 'post_edd_sl_plugin_updater_setup', $edd_plugin_data ); + // Set up hooks. $this->init(); @@ -98,29 +109,50 @@ class PLL_Plugin_Updater { return $_transient_data; } + $current = $this->get_repo_api_data(); + if ( false !== $current && is_object( $current ) && isset( $current->new_version ) ) { + if ( version_compare( $this->version, $current->new_version, '<' ) ) { + $_transient_data->response[ $this->name ] = $current; + } else { + // Populating the no_update information is required to support auto-updates in WordPress 5.5. + $_transient_data->no_update[ $this->name ] = $current; + } + } + $_transient_data->last_checked = time(); + $_transient_data->checked[ $this->name ] = $this->version; + + return $_transient_data; + } + + /** + * Get repo API data from store. + * Save to cache. + * + * @return \stdClass + */ + public function get_repo_api_data() { $version_info = $this->get_cached_version_info(); if ( false === $version_info ) { - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); - - $this->set_version_info_cache( $version_info ); - - } - - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { - - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { - - $_transient_data->response[ $this->name ] = $version_info; - + $version_info = $this->api_request( + 'plugin_latest_version', + array( + 'slug' => $this->slug, + 'beta' => $this->beta, + ) + ); + if ( ! $version_info ) { + return false; } - $_transient_data->last_checked = current_time( 'timestamp' ); - $_transient_data->checked[ $this->name ] = $this->version; + // This is required for your plugin to support auto-updates in WordPress 5.5. + $version_info->plugin = $this->name; + $version_info->id = $this->name; + $this->set_version_info_cache( $version_info ); } - return $_transient_data; + return $version_info; } /** @@ -156,11 +188,28 @@ class PLL_Plugin_Updater { if ( empty( $update_cache->response ) || empty( $update_cache->response[ $this->name ] ) ) { - $version_info = $this->get_cached_version_info(); + $version_info = $this->get_repo_api_data(); if ( false === $version_info ) { $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug, 'beta' => $this->beta ) ); + // Since we disabled our filter for the transient, we aren't running our object conversion on banners, sections, or icons. Do this now: + if ( isset( $version_info->banners ) && ! is_array( $version_info->banners ) ) { + $version_info->banners = $this->convert_object_to_array( $version_info->banners ); + } + + if ( isset( $version_info->sections ) && ! is_array( $version_info->sections ) ) { + $version_info->sections = $this->convert_object_to_array( $version_info->sections ); + } + + if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { + $version_info->icons = $this->convert_object_to_array( $version_info->icons ); + } + + if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) { + $version_info->contributors = $this->convert_object_to_array( $version_info->contributors ); + } + $this->set_version_info_cache( $version_info ); } @@ -169,12 +218,12 @@ class PLL_Plugin_Updater { } if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { - $update_cache->response[ $this->name ] = $version_info; - + } else { + $update_cache->no_update[ $this->name ] = $version_info; } - $update_cache->last_checked = current_time( 'timestamp' ); + $update_cache->last_checked = time(); $update_cache->checked[ $this->name ] = $this->version; set_site_transient( 'update_plugins', $update_cache ); @@ -202,7 +251,7 @@ class PLL_Plugin_Updater { if ( empty( $version_info->download_link ) ) { printf( /* translators: %1$s plugin name, %3$s plugin version, %2$s is link start tag, %4$s is link end tag. */ - esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ), + __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s.', 'polylang' ), esc_html( $version_info->name ), '', esc_html( $version_info->new_version ), @@ -211,7 +260,7 @@ class PLL_Plugin_Updater { } else { printf( /* translators: %1$s plugin name, %3$s plugin version, %2$s and %5$s are link start tags, %4$s and %6$s are link end tags. */ - esc_html__( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ), + __( 'There is a new version of %1$s available. %2$sView version %3$s details%4$s or %5$supdate now%6$s.', 'polylang' ), esc_html( $version_info->name ), '', esc_html( $version_info->new_version ), @@ -256,14 +305,13 @@ class PLL_Plugin_Updater { 'is_ssl' => is_ssl(), 'fields' => array( 'banners' => array(), - 'reviews' => false + 'reviews' => false, + 'icons' => array(), ) ); - $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); - // Get the transient where we store the api request for this plugin for 24 hours - $edd_api_request_transient = $this->get_cached_version_info( $cache_key ); + $edd_api_request_transient = $this->get_cached_version_info(); //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. if ( empty( $edd_api_request_transient ) ) { @@ -271,7 +319,7 @@ class PLL_Plugin_Updater { $api_response = $this->api_request( 'plugin_information', $to_send ); // Expires in 3 hours - $this->set_version_info_cache( $api_response, $cache_key ); + $this->set_version_info_cache( $api_response ); if ( false !== $api_response ) { $_data = $api_response; @@ -283,27 +331,52 @@ class PLL_Plugin_Updater { // Convert sections into an associative array, since we're getting an object, but Core expects an array. if ( isset( $_data->sections ) && ! is_array( $_data->sections ) ) { - $new_sections = array(); - foreach ( $_data->sections as $key => $value ) { - $new_sections[ $key ] = $value; - } - - $_data->sections = $new_sections; + $_data->sections = $this->convert_object_to_array( $_data->sections ); } // Convert banners into an associative array, since we're getting an object, but Core expects an array. if ( isset( $_data->banners ) && ! is_array( $_data->banners ) ) { - $new_banners = array(); - foreach ( $_data->banners as $key => $value ) { - $new_banners[ $key ] = $value; - } + $_data->banners = $this->convert_object_to_array( $_data->banners ); + } - $_data->banners = $new_banners; + // Convert icons into an associative array, since we're getting an object, but Core expects an array. + if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) { + $_data->icons = $this->convert_object_to_array( $_data->icons ); + } + + // Convert contributors into an associative array, since we're getting an object, but Core expects an array. + if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) { + $_data->contributors = $this->convert_object_to_array( $_data->contributors ); + } + + if( ! isset( $_data->plugin ) ) { + $_data->plugin = $this->name; } return $_data; } + /** + * Convert some objects to arrays when injecting data into the update API + * + * Some data like sections, banners, and icons are expected to be an associative array, however due to the JSON + * decoding, they are objects. This method allows us to pass in the object and return an associative array. + * + * @since 3.6.5 + * + * @param stdClass $data + * + * @return array + */ + private function convert_object_to_array( $data ) { + $new_data = array(); + foreach ( $data as $key => $value ) { + $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value; + } + + return $new_data; + } + /** * Disable SSL verification in order to prevent download update failures * @@ -334,15 +407,39 @@ class PLL_Plugin_Updater { */ private function api_request( $_action, $_data ) { - global $wp_version; + global $wp_version, $edd_plugin_url_available; + + $verify_ssl = $this->verify_ssl(); + + // Do a quick status check on this domain if we haven't already checked it. + $store_hash = md5( $this->api_url ); + if ( ! is_array( $edd_plugin_url_available ) || ! isset( $edd_plugin_url_available[ $store_hash ] ) ) { + $test_url_parts = parse_url( $this->api_url ); + + $scheme = ! empty( $test_url_parts['scheme'] ) ? $test_url_parts['scheme'] : 'http'; + $host = ! empty( $test_url_parts['host'] ) ? $test_url_parts['host'] : ''; + $port = ! empty( $test_url_parts['port'] ) ? ':' . $test_url_parts['port'] : ''; + + if ( empty( $host ) ) { + $edd_plugin_url_available[ $store_hash ] = false; + } else { + $test_url = $scheme . '://' . $host . $port; + $response = wp_remote_get( $test_url, array( 'timeout' => $this->health_check_timeout, 'sslverify' => $verify_ssl ) ); + $edd_plugin_url_available[ $store_hash ] = is_wp_error( $response ) ? false : true; + } + } + + if ( false === $edd_plugin_url_available[ $store_hash ] ) { + return false; + } $data = array_merge( $this->api_data, $_data ); if ( $data['slug'] != $this->slug ) { - return; + return false; } - if( $this->api_url == trailingslashit (home_url() ) ) { + if ( $this->api_url == trailingslashit ( home_url() ) ) { return false; // Don't allow a plugin to ping itself } @@ -358,7 +455,6 @@ class PLL_Plugin_Updater { 'beta' => ! empty( $data['beta'] ), ); - $verify_ssl = $this->verify_ssl(); $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => $verify_ssl, 'body' => $api_params ) ); if ( ! is_wp_error( $request ) ) { @@ -375,7 +471,11 @@ class PLL_Plugin_Updater { $request->banners = maybe_unserialize( $request->banners ); } - if( ! empty( $request->sections ) ) { + if ( $request && isset( $request->icons ) ) { + $request->icons = maybe_unserialize( $request->icons ); + } + + if ( ! empty( $request->sections ) ) { foreach( $request->sections as $key => $section ) { $request->$key = (array) $section; } @@ -384,6 +484,9 @@ class PLL_Plugin_Updater { return $request; } + /** + * If available, show the changelog for sites in a multisite install. + */ public function show_changelog() { global $edd_plugin_data; @@ -405,9 +508,7 @@ class PLL_Plugin_Updater { } $data = $edd_plugin_data[ $_REQUEST['slug'] ]; - $beta = ! empty( $data['beta'] ) ? true : false; - $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' ); - $version_info = $this->get_cached_version_info( $cache_key ); + $version_info = $this->get_cached_version_info(); if( false === $version_info ) { @@ -428,7 +529,6 @@ class PLL_Plugin_Updater { $version_info = json_decode( wp_remote_retrieve_body( $request ) ); } - if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { $version_info->sections = maybe_unserialize( $version_info->sections ); } else { @@ -441,17 +541,28 @@ class PLL_Plugin_Updater { } } - $this->set_version_info_cache( $version_info, $cache_key ); + $this->set_version_info_cache( $version_info ); + // Delete the unneeded option + delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) ); } - if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { - echo '
    ' . $version_info->sections['changelog'] . '
    '; + if ( isset( $version_info->sections ) ) { + $sections = $this->convert_object_to_array( $version_info->sections ); + if ( ! empty( $sections['changelog'] ) ) { + echo '
    ' . wp_kses_post( $sections['changelog'] ) . '
    '; + } } exit; } + /** + * Gets the plugin's cached version information from the database. + * + * @param string $cache_key + * @return boolean|string + */ public function get_cached_version_info( $cache_key = '' ) { if( empty( $cache_key ) ) { @@ -460,14 +571,26 @@ class PLL_Plugin_Updater { $cache = get_option( $cache_key ); - if( empty( $cache['timeout'] ) || current_time( 'timestamp' ) > $cache['timeout'] ) { + if( empty( $cache['timeout'] ) || time() > $cache['timeout'] ) { return false; // Cache is expired } - return json_decode( $cache['value'] ); + // We need to turn the icons into an array, thanks to WP Core forcing these into an object at some point. + $cache['value'] = json_decode( $cache['value'] ); + if ( ! empty( $cache['value']->icons ) ) { + $cache['value']->icons = (array) $cache['value']->icons; + } + + return $cache['value']; } + /** + * Adds the plugin version information to the database. + * + * @param string $value + * @param string $cache_key + */ public function set_version_info_cache( $value = '', $cache_key = '' ) { if( empty( $cache_key ) ) { @@ -475,12 +598,14 @@ class PLL_Plugin_Updater { } $data = array( - 'timeout' => strtotime( '+3 hours', current_time( 'timestamp' ) ), + 'timeout' => strtotime( '+3 hours', time() ), 'value' => json_encode( $value ) ); update_option( $cache_key, $data, 'no' ); + // Delete the duplicate option + delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) ); } /** diff --git a/wp-content/plugins/polylang/install/t15s.php b/wp-content/plugins/polylang/install/t15s.php new file mode 100644 index 00000000..caee4a9a --- /dev/null +++ b/wp-content/plugins/polylang/install/t15s.php @@ -0,0 +1,237 @@ +slug = $slug; + $this->api_url = $api_url; + + add_action( 'init', array( __CLASS__, 'register_clean_translations_cache' ), 9999 ); + add_filter( 'translations_api', array( $this, 'translations_api' ), 10, 3 ); + add_filter( 'site_transient_update_plugins', array( $this, 'site_transient_update_plugins' ) ); + } + + /** + * Short-circuits translations API requests for private projects. + * + * @since 2.6 + * + * @param bool|array $result The result object. Default false. + * @param string $requested_type The type of translations being requested. + * @param object $args Translation API arguments. + * @return bool|array + */ + public function translations_api( $result, $requested_type, $args ) { + if ( 'plugins' === $requested_type && $this->slug === $args['slug'] ) { + return self::get_translations( $args['slug'], $this->api_url ); + } + + return $result; + } + + /** + * Filters the translations transients to include the private plugin or theme. + * + * @see wp_get_translation_updates() + * + * @since 2.6 + * + * @param bool|array $value The transient value. + * @return bool|array + */ + public function site_transient_update_plugins( $value ) { + if ( ! $value ) { + $value = new stdClass(); + } + + if ( ! isset( $value->translations ) ) { + $value->translations = array(); + } + + $translations = self::get_translations( $this->slug, $this->api_url ); + + if ( ! isset( $translations['translations'] ) ) { + return $value; + } + + $installed_translations = self::get_installed_translations(); + + foreach ( (array) $translations['translations'] as $translation ) { + if ( in_array( $translation['language'], self::get_available_languages() ) ) { + if ( isset( $installed_translations[ $this->slug ][ $translation['language'] ] ) && $translation['updated'] ) { + $local = new DateTime( $installed_translations[ $this->slug ][ $translation['language'] ]['PO-Revision-Date'] ); + $remote = new DateTime( $translation['updated'] ); + + if ( $local >= $remote ) { + continue; + } + } + + $translation['type'] = 'plugin'; + $translation['slug'] = $this->slug; + + $value->translations[] = $translation; + } + } + + return $value; + } + + /** + * Registers actions for clearing translation caches. + * + * @since 2.6 + * + * @return void + */ + public static function register_clean_translations_cache() { + add_action( 'set_site_transient_update_plugins', array( __CLASS__, 'clean_translations_cache' ) ); + add_action( 'delete_site_transient_update_plugins', array( __CLASS__, 'clean_translations_cache' ) ); + } + + /** + * Clears existing translation cache. + * + * @since 2.6 + * + * @return void + */ + public static function clean_translations_cache() { + $translations = get_site_transient( self::TRANSIENT_KEY_PLUGIN ); + + if ( ! is_object( $translations ) ) { + return; + } + + /* + * Don't delete the cache if the transient gets changed multiple times + * during a single request. Set cache lifetime to maximum 15 seconds. + */ + $cache_lifespan = 15; + $time_not_changed = isset( $translations->_last_checked ) && ( time() - $translations->_last_checked ) > $cache_lifespan; + + if ( ! $time_not_changed ) { + return; + } + + delete_site_transient( self::TRANSIENT_KEY_PLUGIN ); + } + + /** + * Gets the translations for a given project. + * + * @since 2.6 + * + * @param string $slug Project directory slug. + * @param string $url Full GlotPress API URL for the project. + * @return array Translation data. + */ + private static function get_translations( $slug, $url ) { + $translations = get_site_transient( self::TRANSIENT_KEY_PLUGIN ); + + if ( ! is_object( $translations ) ) { + $translations = new stdClass(); + } + + if ( isset( $translations->{$slug} ) && is_array( $translations->{$slug} ) ) { + return $translations->{$slug}; + } + + $result = json_decode( wp_remote_retrieve_body( wp_remote_get( $url, array( 'timeout' => 3 ) ) ), true ); + + // Nothing found. + if ( ! is_array( $result ) ) { + $result = array(); + } + + $translations->{$slug} = $result; + $translations->_last_checked = time(); + + set_site_transient( self::TRANSIENT_KEY_PLUGIN, $translations ); + return $result; + } + + /** + * Returns installed translations. + * + * Used to cache the result of wp_get_installed_translations() as it is very expensive. + * + * @since 2.8 + * + * @return array + */ + private static function get_installed_translations() { + if ( null === self::$installed_translations ) { + self::$installed_translations = wp_get_installed_translations( 'plugins' ); + } + return self::$installed_translations; + } + + /** + * Returns available languages. + * + * Used to cache the result of get_available_languages() as it is very expensive. + * + * @since 2.8 + * + * @return array + */ + private static function get_available_languages() { + if ( null === self::$available_languages ) { + self::$available_languages = get_available_languages(); + } + return self::$available_languages; + } +} diff --git a/wp-content/plugins/polylang/install/upgrade.php b/wp-content/plugins/polylang/install/upgrade.php index b64052a2..7c3f1c11 100644 --- a/wp-content/plugins/polylang/install/upgrade.php +++ b/wp-content/plugins/polylang/install/upgrade.php @@ -1,4 +1,7 @@ can_upgrade() ) { ob_start(); $this->admin_notices(); // FIXME the error message is displayed two times - die( ob_get_contents() ); + die( ob_get_contents() ); // phpcs:ignore WordPress.Security.EscapeOutput } } @@ -60,25 +70,27 @@ class PLL_Upgrade { * @return bool true if upgrade is possible, false otherwise */ public function can_upgrade() { - // Don't manage upgrade from version < 0.8 - return version_compare( $this->options['version'], '0.8', '>=' ); + // Don't manage upgrade from version < 1.8 + return version_compare( $this->options['version'], '1.8', '>=' ); } /** * Displays a notice when ugrading from a too old version * * @since 1.0 + * + * @return void */ public function admin_notices() { - load_plugin_textdomain( 'polylang', false, basename( POLYLANG_DIR ) . '/languages' ); + load_plugin_textdomain( 'polylang' ); printf( '

    %s

    %s

    ', esc_html__( 'Polylang has been deactivated because you upgraded from a too old version.', 'polylang' ), sprintf( /* translators: %1$s and %2$s are Polylang version numbers */ - esc_html__( 'Please upgrade first to %1$s before ugrading to %2$s.', 'polylang' ), - '0.9.8', - POLYLANG_VERSION + esc_html__( 'Before upgrading to %2$s, please upgrade to %1$s.', 'polylang' ), + '2.9', + POLYLANG_VERSION // phpcs:ignore WordPress.Security.EscapeOutput ) ); } @@ -87,479 +99,28 @@ class PLL_Upgrade { * Upgrades the plugin depending on the previous version * * @since 1.2 + * + * @return void */ public function _upgrade() { - foreach ( array( '0.9', '1.0', '1.1', '1.2', '1.2.1', '1.2.3', '1.3', '1.4', '1.4.1', '1.4.4', '1.5', '1.6', '1.7.4', '1.8', '2.0.8', '2.1', '2.3' ) as $version ) { + foreach ( array( '2.0.8', '2.1', '2.7', '2.8.1' ) as $version ) { if ( version_compare( $this->options['version'], $version, '<' ) ) { call_user_func( array( $this, 'upgrade_' . str_replace( '.', '_', $version ) ) ); } } - $delete_pre_1_2_data = get_transient( 'pll_upgrade_1_4' ); - if ( false !== $delete_pre_1_2_data && absint( $delete_pre_1_2_data ) < time() ) { - $this->delete_pre_1_2_data(); - } - $this->options['previous_version'] = $this->options['version']; // Remember the previous version of Polylang since v1.7.7 $this->options['version'] = POLYLANG_VERSION; update_option( 'polylang', $this->options ); } - /** - * Upgrades if the previous version is < 0.9 - * - * @since 1.2 - */ - protected function upgrade_0_9() { - $this->options['sync'] = defined( 'PLL_SYNC' ) && ! PLL_SYNC ? 0 : 1; // The option replaces PLL_SYNC in 0.9 - } - - /** - * Upgrades if the previous version is < 1.0 - * - * @since 1.2 - */ - protected function upgrade_1_0() { - // The option replaces PLL_MEDIA_SUPPORT in 1.0 - $this->options['media_support'] = defined( 'PLL_MEDIA_SUPPORT' ) && ! PLL_MEDIA_SUPPORT ? 0 : 1; - - // Split the synchronization options in 1.0 - $this->options['sync'] = empty( $this->options['sync'] ) ? array() : array_keys( PLL_Settings_Sync::list_metas_to_sync() ); - - // Set default values for post types and taxonomies to translate - $this->options['post_types'] = array_values( get_post_types( array( '_builtin' => false, 'show_ui' => true ) ) ); - $this->options['taxonomies'] = array_values( get_taxonomies( array( '_builtin' => false, 'show_ui' => true ) ) ); - update_option( 'polylang', $this->options ); - - flush_rewrite_rules(); // Rewrite rules have been modified in 1.0 - } - - /** - * Upgrades if the previous version is < 1.1 - * - * @since 1.2 - */ - protected function upgrade_1_1() { - // Update strings register with icl_register_string - $strings = get_option( 'polylang_wpml_strings' ); - if ( $strings ) { - foreach ( $strings as $key => $string ) { - $strings[ $key ]['icl'] = 1; - } - update_option( 'polylang_wpml_strings', $strings ); - } - - // Move polylang_widgets options - if ( $widgets = get_option( 'polylang_widgets' ) ) { - $this->options['widgets'] = $widgets; - delete_option( 'polylang_widgets' ); - } - } - - /** - * Upgrades if the previous version is < 1.2 - * - * @since 1.2 - */ - protected function upgrade_1_2() { - $this->options['domains'] = array(); // Option added in 1.2 - - // Need to register the taxonomies - foreach ( array( 'language', 'term_language', 'post_translations', 'term_translations' ) as $taxonomy ) { - register_taxonomy( $taxonomy, null, array( 'label' => false, 'public' => false, 'query_var' => false, 'rewrite' => false ) ); - } - - // Abort if the db upgrade has already been done previously - if ( get_terms( 'term_language', array( 'hide_empty' => 0 ) ) ) { - return; - } - - set_time_limit( 0 ); // In case we upgrade a huge site - - // Upgrade old model based on metas to new model based on taxonomies - global $wpdb; - $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // Registers the termmeta table in wpdb - $languages = get_terms( 'language', array( 'hide_empty' => 0 ) ); // Don't use get_languages_list which can't work with the old model - - foreach ( $languages as $lang ) { - // First update language with new storage for locale and text direction - $text_direction = get_metadata( 'term', $lang->term_id, '_rtl', true ); - $desc = serialize( array( 'locale' => $lang->description, 'rtl' => $text_direction ) ); - wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $desc ) ); - - // Add language to new 'term_language' taxonomy - $term_lang = wp_insert_term( $lang->name, 'term_language', array( 'slug' => 'pll_' . $lang->slug ) ); - $lang_tt_ids[ $lang->term_id ] = $term_lang['term_taxonomy_id']; // Keep the term taxonomy id for future - } - - // Get all terms with a language defined - $terms = $wpdb->get_results( "SELECT term_id, meta_value FROM $wpdb->termmeta WHERE meta_key = '_language'" ); - foreach ( $terms as $key => $term ) { - $terms[ $key ] = $wpdb->prepare( '( %d, %d )', $term->term_id, $lang_tt_ids[ $term->meta_value ] ); - } - - $terms = array_unique( $terms ); - - // Assign language to each term - if ( ! empty( $terms ) ) { - $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $terms ) ); - } - - // Translations - foreach ( array( 'post', 'term' ) as $type ) { - $table = $type . 'meta'; - $terms = $slugs = $tts = $trs = array(); - - // Get all translated objects - $objects = $wpdb->get_col( "SELECT DISTINCT meta_value FROM {$wpdb->$table} WHERE meta_key = '_translations'" ); - - if ( empty( $objects ) ) { - continue; - } - - foreach ( $objects as $obj ) { - $term = uniqid( 'pll_' ); // The term name - $terms[] = $wpdb->prepare( '( %s, %s )', $term, $term ); - $slugs[] = $wpdb->prepare( '%s', $term ); - $translations = maybe_unserialize( maybe_unserialize( $obj ) ); // 2 unserialize due to an old storage bug - $description[ $term ] = serialize( $translations ); - } - - $terms = array_unique( $terms ); - - // Insert terms - if ( ! empty( $terms ) ) { - $wpdb->query( "INSERT INTO $wpdb->terms ( slug, name ) VALUES " . implode( ',', $terms ) ); - } - - // Get all terms with their term_id - $terms = $wpdb->get_results( "SELECT term_id, slug FROM $wpdb->terms WHERE slug IN ( " . implode( ',', $slugs ) . ' )' ); - - // Prepare terms taxonomy relationship - foreach ( $terms as $term ) { - $tts[] = $wpdb->prepare( '( %d, %s, %s )', $term->term_id, $type . '_translations', $description[ $term->slug ] ); - } - - $tts = array_unique( $tts ); - - // Insert term_taxonomy - if ( ! empty( $tts ) ) { - $wpdb->query( "INSERT INTO $wpdb->term_taxonomy ( term_id, taxonomy, description ) VALUES " . implode( ',', $tts ) ); - } - - // Get all terms with term_taxonomy_id - $terms = get_terms( $type . '_translations', array( 'hide_empty' => false ) ); - - // Prepare objects relationships - foreach ( $terms as $term ) { - $translations = unserialize( $term->description ); - foreach ( $translations as $object_id ) { - if ( ! empty( $object_id ) ) { - $trs[] = $wpdb->prepare( '( %d, %d )', $object_id, $term->term_taxonomy_id ); - } - } - } - - $trs = array_unique( $trs ); - - // Insert term_relationships - if ( ! empty( $trs ) ) { - $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) ); - } - } - - // Upgrade of string translations is now in upgrade_1_2_1 - // Upgrade of nav menus is now in upgrade_1_2_3 - } - - /** - * Upgrades if the previous version is < 1.2.1 - * - * @since 1.2.1 - */ - protected function upgrade_1_2_1() { - // Strings translations - foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) { - if ( $strings = get_option( 'polylang_mo' . $lang->term_id ) ) { - $mo = new PLL_MO(); - foreach ( $strings as $msg ) { - $mo->add_entry( $mo->make_entry( $msg[0], $msg[1] ) ); - } - $mo->export_to_db( $lang ); - } - } - } - - /** - * Upgrades if the previous version is < 1.2.3 - * Uprades multilingual menus depending on the old version due to multiple changes in menus management - * - * @since 1.2.3 - */ - public function upgrade_1_2_3() { - // Old version < 1.1 - // Multilingal locations and switcher item were stored in a dedicated option - if ( version_compare( $this->options['version'], '1.1', '<' ) ) { - if ( $menu_lang = get_option( 'polylang_nav_menus' ) ) { - foreach ( $menu_lang as $location => $arr ) { - if ( ! in_array( $location, array_keys( get_registered_nav_menus() ) ) ) { - continue; - } - - $switch_options = array_slice( $arr, -5, 5 ); - $translations = array_diff_key( $arr, $switch_options ); - $has_switcher = array_shift( $switch_options ); - - foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) { - // Move nav menus locations - if ( ! empty( $translations[ $lang->slug ] ) ) { - $locations[ $location ][ $lang->slug ] = $translations[ $lang->slug ]; - } - - // Create the menu items for the language switcher - if ( ! empty( $has_switcher ) ) { - $menu_item_db_id = wp_update_nav_menu_item( $translations[ $lang->slug ], 0, array( - 'menu-item-title' => __( 'Language switcher', 'polylang' ), - 'menu-item-url' => '#pll_switcher', - 'menu-item-status' => 'publish', - ) ); - - update_post_meta( $menu_item_db_id, '_pll_menu_item', $switch_options ); - } - } - } - - if ( ! empty( $locations ) ) { - $this->options['nav_menus'][ get_option( 'stylesheet' ) ] = $locations; - } - - delete_option( 'polylang_nav_menus' ); - } - } - - elseif ( empty( $this->options['nav_menus'] ) ) { - $menus = get_theme_mod( 'nav_menu_locations' ); - - if ( is_array( $menus ) ) { - // If old version < 1.2 - // Clean the WP option as it was a bad idea to pollute it - if ( version_compare( $this->options['version'], '1.2', '<' ) ) { - foreach ( $menus as $loc => $menu ) { - if ( $pos = strpos( $loc, '#' ) ) { - unset( $menus[ $loc ] ); - } - } - - set_theme_mod( 'nav_menu_locations', $menus ); - } - - // Get the multilingual locations - foreach ( $menus as $loc => $menu ) { - foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) { - $arr[ $loc ][ $lang->slug ] = pll_get_term( $menu, $lang ); - } - } - - if ( ! empty( $arr ) ) { - $this->options['nav_menus'][ get_option( 'stylesheet' ) ] = $arr; - } - } - } - } - - /** - * Upgrades if the previous version is < 1.3 - * Moves the user biographies in default language to the 'description' user meta - * - * @since 1.3 - */ - protected function upgrade_1_3() { - $usermeta = 'description_' . $this->options['default_lang']; - $query = new WP_User_Query( array( 'blog_id' => $GLOBALS['blog_id'], 'meta_key' => $usermeta ) ); - - foreach ( $query->get_results() as $user ) { - $desc = get_user_meta( $user->ID, $usermeta, true ); - if ( ! empty( $desc ) ) { - update_user_meta( $user->ID, 'description', $desc ); - delete_user_meta( $user->ID, $usermeta ); - } - } - } - - /** - * Upgrades if the previous version is < 1.4 - * Sets a transient to delete old model data - * Deletes language cache (due to bug correction in home urls in 1.3.1 and added mo_id in 1.4) - * - * @since 1.4 - */ - protected function upgrade_1_4() { - set_transient( 'pll_upgrade_1_4', time() + 60 * 24 * 60 * 60 ); // 60 days - delete_transient( 'pll_languages_list' ); - } - - /** - * Old data were not deleted in 1.2, just in case... - * Delete them at first upgrade at least 60 days after upgrade to 1.4 - * - * @since 1.4 - */ - protected function delete_pre_1_2_data() { - // Suppress data of the old model < 1.2 - global $wpdb; - $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb in case WP < 4.4 - - // Do nothing if the termmeta table does not exists - if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) { - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" ); - } - - // Delete the strings translations - $languages = get_terms( 'language', array( 'hide_empty' => false ) ); - foreach ( $languages as $lang ) { - delete_option( 'polylang_mo' . $lang->term_id ); - } - - delete_transient( 'pll_upgrade_1_4' ); - } - - /** - * Upgrades if the previous version is < 1.4.1 - * Disables the browser detection when using multiple domains - * - * @since 1.4.1 - */ - protected function upgrade_1_4_1() { - if ( 3 == $this->options['force_lang'] ) { - $this->options['browser'] = $this->options['hide_default'] = 0; - } - } - - /** - * Upgrades if the previous version is < 1.4.4 - * Uprades widgets options for language filter - * - * @since 1.4.4 - */ - protected function upgrade_1_4_4() { - foreach ( $GLOBALS['wp_registered_widgets'] as $widget ) { - if ( ! empty( $this->options['widgets'][ $widget['id'] ] ) && ! empty( $widget['callback'][0] ) && ! empty( $widget['params'][0]['number'] ) ) { - $obj = $widget['callback'][0]; - if ( is_object( $obj ) && method_exists( $obj, 'get_settings' ) && method_exists( $obj, 'save_settings' ) ) { - $settings = $obj->get_settings(); - $settings[ $widget['params'][0]['number'] ]['pll_lang'] = $this->options['widgets'][ $widget['id'] ]; - $obj->save_settings( $settings ); - } - } - } - unset( $this->options['widgets'] ); - } - - /** - * Upgrades if the previous version is < 1.5 - * Deletes language cache (due to host property added and bug on search url) - * - * @since 1.5 - */ - protected function upgrade_1_5() { - delete_transient( 'pll_languages_list' ); - } - - /** - * Upgrades if the previous version is < 1.6 - * Upgrades core language files to get the .po file (only for WP 4.0+) - * - * @since 1.6 - */ - protected function upgrade_1_6() { - if ( version_compare( $GLOBALS['wp_version'], '4.0', '>=' ) ) { - self::download_language_packs(); - } - } - - /** - * Downloads language packs - * Intended to be used only one time (at upgrade to Polylang 1.6 or first upgrade of WP 4.0 or later) - * Adapted from wp_download_language_pack - * Rewritten because wp_download_language_pack checks the existence of .mo and I need to download .po - * - * @since 1.6 - */ - static function download_language_packs() { - $languages = pll_languages_list( array( 'fields' => 'locale' ) ); - - // Prevents upgrade if the .po file is already here. Let WP manage the upgrades :) - foreach ( $languages as $key => $locale ) { - if ( file_exists( WP_LANG_DIR . "/$locale.po" ) ) { - unset( $languages[ $key ] ); - } - } - - if ( empty( $languages ) ) { - return; - } - - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; - $translations = wp_get_available_translations(); - if ( ! $translations ) { - return; - } - - foreach ( $translations as $translation ) { - if ( in_array( $translation['language'], $languages ) ) { - $translation['type'] = 'core'; - $translations_to_load[] = (object) $translation; - } - } - - if ( ! empty( $translations_to_load ) ) { - require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; - $upgrader = new Language_Pack_Upgrader( new Automatic_Upgrader_Skin ); - $upgrader->bulk_upgrade( $translations_to_load, array( 'clear_update_cache' => false ) ); - } - } - - /** - * Upgrades if the previous version is < 1.7.4 - * - * @since 1.7.4 - */ - protected function upgrade_1_7_4() { - delete_transient( 'pll_languages_list' ); // Deletes language cache (due to flag properties added in 1.7, page on front removed in 1.7.2, home url fixes in 1.7.4) - flush_rewrite_rules(); // Flush rewrite rules due to custom taxonomy rewrite rule bug fix - } - - /** - * Upgrades if the previous version is < 1.8 - * - * @since 1.8 - */ - protected function upgrade_1_8() { - // Adds the flag code in languages stored in DB - include PLL_SETTINGS_INC . '/languages.php'; - - $terms = get_terms( 'language', array( 'hide_empty' => 0 ) ); - - foreach ( $terms as $lang ) { - $description = maybe_unserialize( $lang->description ); - if ( isset( $languages[ $description['locale'] ] ) ) { - $description['flag_code'] = $languages[ $description['locale'] ]['flag']; - $description = serialize( $description ); - wp_update_term( (int) $lang->term_id, 'language', array( 'description' => $description ) ); - } - } - - delete_transient( 'pll_languages_list' ); - } - /** * Upgrades if the previous version is < 2.0.8 * Changes the user meta 'user_lang' to 'locale' to match WP 4.7 choice * * @since 2.0.8 + * + * @return void */ protected function upgrade_2_0_8() { global $wpdb; @@ -567,35 +128,78 @@ class PLL_Upgrade { } /** - * Upgrades if the previous version is < 2.1 - * Moves strings translations from polylang_mo post_content to post meta _pll_strings_translations + * Upgrades if the previous version is < 2.1. + * Moves strings translations from polylang_mo post_content to post meta _pll_strings_translations. * * @since 2.1 + * + * @return void */ protected function upgrade_2_1() { - foreach ( get_terms( 'language', array( 'hide_empty' => 0 ) ) as $lang ) { - $mo_id = PLL_MO::get_id( $lang ); - $meta = get_post_meta( $mo_id, '_pll_strings_translations', true ); + $posts = get_posts( + array( + 'post_type' => 'polylang_mo', + 'post_status' => 'any', + 'numberposts' => -1, + 'nopaging' => true, + ) + ); - if ( empty( $meta ) ) { - $post = get_post( $mo_id, OBJECT ); - $strings = unserialize( $post->post_content ); - if ( is_array( $strings ) ) { - update_post_meta( $mo_id, '_pll_strings_translations', $strings ); + if ( is_array( $posts ) ) { + foreach ( $posts as $post ) { + $meta = get_post_meta( $post->ID, '_pll_strings_translations', true ); + + if ( empty( $meta ) ) { + $strings = maybe_unserialize( $post->post_content ); + if ( is_array( $strings ) ) { + update_post_meta( $post->ID, '_pll_strings_translations', $strings ); + } } } } } /** - * Upgrades if the previous version is < 2.3 + * Upgrades if the previous version is < 2.7 + * Replace numeric keys by hashes in WPML registered strings + * Dismiss the wizard notice for existing sites * - * Deletes language cache due to 'redirect_lang' option removed for subdomains and multiple domains in 2.2 - * and W3C and Facebook locales added to PLL_Language objects in 2.3 + * @since 2.7 * - * @since 2.3 + * @return void */ - protected function upgrade_2_3() { + protected function upgrade_2_7() { + $strings = get_option( 'polylang_wpml_strings' ); + if ( is_array( $strings ) ) { + $new_strings = array(); + + foreach ( $strings as $string ) { + $context = $string['context']; + $name = $string['name']; + + $key = md5( "$context | $name" ); + $new_strings[ $key ] = $string; + } + update_option( 'polylang_wpml_strings', $new_strings ); + } + + PLL_Admin_Notices::dismiss( 'wizard' ); + } + + /** + * Upgrades if the previous version is < 2.8.1 + * + * Deletes language cache due to: + * - 'redirect_lang' option removed for subdomains and multiple domains in 2.2 + * - W3C and Facebook locales added to PLL_Language objects in 2.3 + * - flags moved to a different directory in Polylang Pro 2.8 + * - bug of flags url returning html fixed in 2.8.1 + * + * @since 2.8.1 + * + * @return void + */ + protected function upgrade_2_8_1() { delete_transient( 'pll_languages_list' ); } } diff --git a/wp-content/plugins/polylang/integrations/aqua-resizer/aqua-resizer.php b/wp-content/plugins/polylang/integrations/aqua-resizer/aqua-resizer.php new file mode 100644 index 00000000..99f93077 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/aqua-resizer/aqua-resizer.php @@ -0,0 +1,32 @@ + 'aq_resize' ) ) ); + } +} diff --git a/wp-content/plugins/polylang/integrations/aqua-resizer/load.php b/wp-content/plugins/polylang/integrations/aqua-resizer/load.php new file mode 100644 index 00000000..d5dd13f2 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/aqua-resizer/load.php @@ -0,0 +1,13 @@ +aq_resizer = new PLL_Aqua_Resizer(); +PLL_Integrations::instance()->aq_resizer->init(); diff --git a/wp-content/plugins/polylang/integrations/cache/cache-compat.php b/wp-content/plugins/polylang/integrations/cache/cache-compat.php new file mode 100644 index 00000000..3da1589d --- /dev/null +++ b/wp-content/plugins/polylang/integrations/cache/cache-compat.php @@ -0,0 +1,102 @@ +options['force_lang'] ) ? wp_parse_url( PLL()->links_model->home, PHP_URL_HOST ) : COOKIE_DOMAIN; + $samesite = ( 3 === PLL()->options['force_lang'] ) ? 'None' : 'Lax'; + + /** This filter is documented in include/cookie.php */ + $expiration = (int) apply_filters( 'pll_cookie_expiration', YEAR_IN_SECONDS ); + + if ( 0 !== $expiration ) { + $format = 'var expirationDate = new Date(); + expirationDate.setTime( expirationDate.getTime() + %7$d * 1000 ); + document.cookie = "%1$s=%2$s; expires=" + expirationDate.toUTCString() + "; path=%3$s%4$s%5$s%6$s";'; + } else { + $format = 'document.cookie = "%1$s=%2$s; path=%3$s%4$s%5$s%6$s";'; + } + + $js = sprintf( + "(function() { + {$format} + }());\n", + esc_js( PLL_COOKIE ), + esc_js( pll_current_language() ), + esc_js( COOKIEPATH ), + $domain ? '; domain=' . esc_js( $domain ) : '', + is_ssl() ? '; secure' : '', + '; SameSite=' . $samesite, + esc_js( $expiration ) + ); + echo "\n"; // phpcs:ignore WordPress.Security.EscapeOutput + } + + /** + * Informs cache plugins not to cache the home in the default language + * When the detection of the browser preferred language is active + * + * @since 2.3 + */ + public function do_not_cache_site_home() { + if ( ! defined( 'DONOTCACHEPAGE' ) && PLL()->options['browser'] && PLL()->options['hide_default'] && is_front_page() && pll_current_language() === pll_default_language() ) { + define( 'DONOTCACHEPAGE', true ); + } + } + + /** + * Allows cache plugins to clean the right post type archive cache when cleaning a post cache. + * + * @since 3.0.5 + * + * @param int $post_id Post id. + */ + public function clean_post_cache( $post_id ) { + $lang = PLL()->model->post->get_language( $post_id ); + + if ( $lang ) { + $filter_callback = function ( $link, $post_type ) use ( $lang ) { + return pll_is_translated_post_type( $post_type ) && 'post' !== $post_type ? PLL()->links_model->switch_language_in_link( $link, $lang ) : $link; + }; + add_filter( 'post_type_archive_link', $filter_callback, 99, 2 ); + } + } +} diff --git a/wp-content/plugins/polylang/integrations/cache/load.php b/wp-content/plugins/polylang/integrations/cache/load.php new file mode 100644 index 00000000..247f3572 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/cache/load.php @@ -0,0 +1,21 @@ +cache_compat = new PLL_Cache_Compat(), 'init' ) ); + } + }, + 0 +); + diff --git a/wp-content/plugins/polylang/integrations/custom-field-template/cft.php b/wp-content/plugins/polylang/integrations/custom-field-template/cft.php new file mode 100644 index 00000000..1ce9a6bf --- /dev/null +++ b/wp-content/plugins/polylang/integrations/custom-field-template/cft.php @@ -0,0 +1,35 @@ +ID; + } + } +} diff --git a/wp-content/plugins/polylang/integrations/custom-field-template/load.php b/wp-content/plugins/polylang/integrations/custom-field-template/load.php new file mode 100644 index 00000000..cab104dc --- /dev/null +++ b/wp-content/plugins/polylang/integrations/custom-field-template/load.php @@ -0,0 +1,21 @@ +cft = new PLL_Cft(); + PLL_Integrations::instance()->cft->init(); + } + }, + 0 +); diff --git a/wp-content/plugins/polylang/integrations/domain-mapping/domain-mapping.php b/wp-content/plugins/polylang/integrations/domain-mapping/domain-mapping.php new file mode 100644 index 00000000..4a8ad9a0 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/domain-mapping/domain-mapping.php @@ -0,0 +1,80 @@ + 1 ) { + // Don't go further if we stopped loading the plugin early ( for example when deactivate-polylang=1 ). + if ( ! function_exists( 'PLL' ) ) { + return; + } + + // Don't redirect the main site + if ( is_main_site() ) { + return; + } + + // Don't redirect post previews + if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) { // phpcs:ignore WordPress.Security.NonceVerification + return; + } + + // Don't redirect theme customizer + if ( isset( $_POST['customize'] ) && isset( $_POST['theme'] ) && 'on' === $_POST['customize'] ) { // phpcs:ignore WordPress.Security.NonceVerification + return; + } + + // If we can't associate the requested domain to a language, redirect to the default domain + $requested_url = pll_get_requested_url(); + $requested_host = wp_parse_url( $requested_url, PHP_URL_HOST ); + + $hosts = PLL()->links_model->get_hosts(); + $lang = array_search( $requested_host, $hosts ); + + if ( empty( $lang ) ) { + $status = get_site_option( 'dm_301_redirect' ) ? '301' : '302'; // Honor status redirect option + $redirect = str_replace( '://' . $requested_host, '://' . $hosts[ $options['default_lang'] ], $requested_url ); + wp_safe_redirect( $redirect, $status ); + exit; + } + } else { + // Otherwise rely on MU Domain Mapping + redirect_to_mapped_domain(); + } + } +} diff --git a/wp-content/plugins/polylang/integrations/domain-mapping/load.php b/wp-content/plugins/polylang/integrations/domain-mapping/load.php new file mode 100644 index 00000000..2c78f09a --- /dev/null +++ b/wp-content/plugins/polylang/integrations/domain-mapping/load.php @@ -0,0 +1,12 @@ +dm = new PLL_Domain_Mapping(); diff --git a/wp-content/plugins/polylang/integrations/duplicate-post/duplicate-post.php b/wp-content/plugins/polylang/integrations/duplicate-post/duplicate-post.php new file mode 100644 index 00000000..0e47179a --- /dev/null +++ b/wp-content/plugins/polylang/integrations/duplicate-post/duplicate-post.php @@ -0,0 +1,38 @@ +duplicate_post = new PLL_Duplicate_Post(); + PLL_Integrations::instance()->duplicate_post->init(); + } + }, + 0 +); diff --git a/wp-content/plugins/polylang/integrations/integrations.php b/wp-content/plugins/polylang/integrations/integrations.php new file mode 100644 index 00000000..bc574c22 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/integrations.php @@ -0,0 +1,49 @@ +is_active() || false !== $featured_ids ) { + return $featured_ids; + } + + $settings = Featured_Content::get_setting(); + + if ( ! $term = get_term_by( 'name', $settings['tag-name'], 'post_tag' ) ) { + return $featured_ids; + } + + // Get featured tag translations + $tags = PLL()->model->term->get_translations( $term->term_id ); + $ids = array(); + + // Query for featured posts in all languages + // One query per language to get the correct number of posts per language + foreach ( $tags as $tag ) { + $args = array( + 'lang' => 0, // Avoid language filters. + 'fields' => 'ids', + 'numberposts' => Featured_Content::$max_posts, + 'tax_query' => array( + array( + 'taxonomy' => 'post_tag', + 'terms' => (int) $tag, + ), + ), + ); + + // Available in Jetpack, but not in Twenty Fourteen. + if ( isset( Featured_Content::$post_types ) ) { + $args['post_type'] = Featured_Content::$post_types; + } + + $_ids = get_posts( $args ); + $ids = array_merge( $ids, $_ids ); + } + + $ids = array_map( 'absint', $ids ); + set_transient( 'featured_content_ids', $ids ); + + return $ids; + } + + /** + * Translates the featured tag id in featured content settings + * Mainly to allow hiding it when requested in featured content options + * Acts only on frontend + * + * @since 1.4 + * + * @param array $settings featured content settings + * @return array modified $settings + */ + public function option_featured_content( $settings ) { + if ( $this->is_active() && PLL() instanceof PLL_Frontend && $settings['tag-id'] && $tr = pll_get_term( $settings['tag-id'] ) ) { + $settings['tag-id'] = $tr; + } + + return $settings; + } +} diff --git a/wp-content/plugins/polylang/modules/plugins/jetpack.php b/wp-content/plugins/polylang/integrations/jetpack/jetpack.php similarity index 83% rename from wp-content/plugins/polylang/modules/plugins/jetpack.php rename to wp-content/plugins/polylang/integrations/jetpack/jetpack.php index 16b35896..23a35bb6 100644 --- a/wp-content/plugins/polylang/modules/plugins/jetpack.php +++ b/wp-content/plugins/polylang/integrations/jetpack/jetpack.php @@ -1,4 +1,7 @@ $post ) { if ( pll_current_language() !== pll_get_post_language( $post['post_id'] ) ) { unset( $posts[ $k ] ); @@ -69,12 +70,11 @@ class PLL_Jetpack { * * @since 1.5.4 * - * @param string $r Contact Form HTML output. - * @param string $field_label Field label. - * @param int|null $id Post ID. + * @param string $r Contact Form HTML output. + * @param string $field_label Field label. * @return string */ - public function grunion_contact_form_field_html_filter( $r, $field_label, $id ) { + public function grunion_contact_form_field_html_filter( $r, $field_label ) { if ( function_exists( 'icl_translate' ) ) { if ( pll_current_language() !== pll_default_language() ) { $label_translation = icl_translate( 'jetpack ', $field_label . '_label', $field_label ); @@ -116,7 +116,7 @@ class PLL_Jetpack { * @param string $post_id Post ID of the post for which we are retrieving Related Posts. * @return array */ - function jetpack_relatedposts_filter_filters( $filters, $post_id ) { + public function jetpack_relatedposts_filter_filters( $filters, $post_id ) { $slug = sanitize_title( pll_get_post_language( $post_id, 'slug' ) ); $filters[] = array( 'term' => array( 'taxonomy.language.slug' => $slug ) ); return $filters; @@ -131,7 +131,7 @@ class PLL_Jetpack { * @return array */ public function jetpack_infinite_scroll_js_settings( $settings ) { - $settings['history']['host'] = parse_url( pll_home_url(), PHP_URL_HOST ); // Jetpack uses get_option( 'home' ) + $settings['history']['host'] = wp_parse_url( pll_home_url(), PHP_URL_HOST ); // Jetpack uses get_option( 'home' ) return $settings; } } diff --git a/wp-content/plugins/polylang/integrations/jetpack/load.php b/wp-content/plugins/polylang/integrations/jetpack/load.php new file mode 100644 index 00000000..791f0915 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/jetpack/load.php @@ -0,0 +1,14 @@ +jetpack = new PLL_Jetpack(); // Must be loaded before the plugin is active. +add_action( 'pll_init', array( PLL_Integrations::instance()->featured_content = new PLL_Featured_Content(), 'init' ) ); diff --git a/wp-content/plugins/polylang/integrations/no-category-base/load.php b/wp-content/plugins/polylang/integrations/no-category-base/load.php new file mode 100644 index 00000000..4684789a --- /dev/null +++ b/wp-content/plugins/polylang/integrations/no-category-base/load.php @@ -0,0 +1,13 @@ +no_category_base = new PLL_No_Category_Base(); +PLL_Integrations::instance()->no_category_base->init(); diff --git a/wp-content/plugins/polylang/integrations/no-category-base/no-category-base.php b/wp-content/plugins/polylang/integrations/no-category-base/no-category-base.php new file mode 100644 index 00000000..703ac6bf --- /dev/null +++ b/wp-content/plugins/polylang/integrations/no-category-base/no-category-base.php @@ -0,0 +1,36 @@ +twenty_seventeen = new PLL_Twenty_Seventeen(), 'init' ) ); diff --git a/wp-content/plugins/polylang/integrations/twenty-seventeen/twenty-seven-teen.php b/wp-content/plugins/polylang/integrations/twenty-seventeen/twenty-seven-teen.php new file mode 100644 index 00000000..a75540fa --- /dev/null +++ b/wp-content/plugins/polylang/integrations/twenty-seventeen/twenty-seven-teen.php @@ -0,0 +1,30 @@ + 1 ), array( 'context' => 'Twenty Seventeen' ) ); + } + } +} diff --git a/wp-content/plugins/polylang/integrations/wp-importer/load.php b/wp-content/plugins/polylang/integrations/wp-importer/load.php new file mode 100644 index 00000000..180db28d --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-importer/load.php @@ -0,0 +1,12 @@ +wp_importer = new PLL_WordPress_Importer(); diff --git a/wp-content/plugins/polylang/integrations/wp-importer/wordpress-importer.php b/wp-content/plugins/polylang/integrations/wp-importer/wordpress-importer.php new file mode 100644 index 00000000..e7b51feb --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-importer/wordpress-importer.php @@ -0,0 +1,70 @@ +getFileName() ) ) . '/languages' ); + + $GLOBALS['wp_import'] = new PLL_WP_Import(); + register_importer( 'wordpress', 'WordPress', __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.', 'polylang' ), array( $GLOBALS['wp_import'], 'dispatch' ) ); // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled + } + + /** + * Sets the flag when importing a language and the file has been exported with Polylang < 1.8. + * + * @since 1.8 + * + * @param array $terms An array of arrays containing terms information form the WXR file. + * @return array + */ + public function wp_import_terms( $terms ) { + $languages = include POLYLANG_DIR . '/settings/languages.php'; + + foreach ( $terms as $key => $term ) { + if ( 'language' === $term['term_taxonomy'] ) { + $description = maybe_unserialize( $term['term_description'] ); + if ( empty( $description['flag_code'] ) && isset( $languages[ $description['locale'] ] ) ) { + $description['flag_code'] = $languages[ $description['locale'] ]['flag']; + $terms[ $key ]['term_description'] = maybe_serialize( $description ); + } + } + } + return $terms; + } +} diff --git a/wp-content/plugins/polylang/modules/plugins/wp-import.php b/wp-content/plugins/polylang/integrations/wp-importer/wp-import.php similarity index 65% rename from wp-content/plugins/polylang/modules/plugins/wp-import.php rename to wp-content/plugins/polylang/integrations/wp-importer/wp-import.php index 2fc46f71..7219d41b 100644 --- a/wp-content/plugins/polylang/modules/plugins/wp-import.php +++ b/wp-content/plugins/polylang/integrations/wp-importer/wp-import.php @@ -1,22 +1,30 @@ terms + // Store this for future usage as parent function unsets $this->terms foreach ( $this->terms as $term ) { if ( 'post_translations' == $term['term_taxonomy'] ) { $this->post_translations[] = $term; @@ -28,13 +36,13 @@ class PLL_WP_Import extends WP_Import { parent::process_terms(); - // update the languages list if needed - // first reset the core terms cache as WordPress Importer calls wp_suspend_cache_invalidation( true ); + // Update the languages list if needed + // First reset the core terms cache as WordPress Importer calls wp_suspend_cache_invalidation( true ); wp_cache_set( 'last_changed', microtime(), 'terms' ); PLL()->model->clean_languages_cache(); if ( ( $options = get_option( 'polylang' ) ) && empty( $options['default_lang'] ) && ( $languages = PLL()->model->get_languages_list() ) ) { - // assign the default language if importer created the first language + // Assign the default language if importer created the first language $default_lang = reset( $languages ); $options['default_lang'] = $default_lang->slug; update_option( 'polylang', $options ); @@ -45,15 +53,15 @@ class PLL_WP_Import extends WP_Import { } /** - * overrides WP_Import::process_post to remap posts translations - * also merges strings translations from the WXR file to the existing ones + * Overrides WP_Import::process_post to remap posts translations + * Also merges strings translations from the WXR file to the existing ones * * @since 1.2 */ - function process_posts() { + public function process_posts() { $menu_items = $mo_posts = array(); - // store this for future usage as parent function unset $this->posts + // Store this for future usage as parent function unset $this->posts foreach ( $this->posts as $post ) { if ( 'nav_menu_item' == $post['post_type'] ) { $menu_items[] = $post; @@ -65,17 +73,17 @@ class PLL_WP_Import extends WP_Import { } if ( ! empty( $mo_posts ) ) { - new PLL_MO(); // just to register the polylang_mo post type before processing posts + new PLL_MO(); // Just to register the polylang_mo post type before processing posts } parent::process_posts(); - PLL()->model->clean_languages_cache(); // to update the posts count in ( cached ) languages list + PLL()->model->clean_languages_cache(); // To update the posts count in ( cached ) languages list $this->remap_translations( $this->post_translations, $this->processed_posts ); unset( $this->post_translations ); - // language switcher menu items + // Language switcher menu items foreach ( $menu_items as $item ) { foreach ( $item['postmeta'] as $meta ) { if ( '_pll_menu_item' == $meta['key'] ) { @@ -84,12 +92,12 @@ class PLL_WP_Import extends WP_Import { } } - // merge strings translations + // Merge strings translations foreach ( $mo_posts as $post ) { $lang_id = (int) substr( $post['post_title'], 12 ); if ( ! empty( $this->processed_terms[ $lang_id ] ) ) { - if ( $strings = unserialize( $post['post_content'] ) ) { + if ( $strings = maybe_unserialize( $post['post_content'] ) ) { $mo = new PLL_MO(); $mo->import_from_db( $this->processed_terms[ $lang_id ] ); foreach ( $strings as $msg ) { @@ -98,44 +106,46 @@ class PLL_WP_Import extends WP_Import { $mo->export_to_db( $this->processed_terms[ $lang_id ] ); } } - // delete the now useless imported post + // Delete the now useless imported post wp_delete_post( $this->processed_posts[ $post['post_id'] ], true ); } } /** - * remaps terms languages + * Remaps terms languages * * @since 1.2 * * @param array $terms array of terms in 'term_translations' taxonomy */ - function remap_terms_relations( &$terms ) { + protected function remap_terms_relations( &$terms ) { global $wpdb; + $trs = array(); + foreach ( $terms as $term ) { - $translations = unserialize( $term['term_description'] ); + $translations = maybe_unserialize( $term['term_description'] ); foreach ( $translations as $slug => $old_id ) { if ( $old_id && ! empty( $this->processed_terms[ $old_id ] ) && $lang = PLL()->model->get_language( $slug ) ) { - // language relationship + // Language relationship $trs[] = $wpdb->prepare( '( %d, %d )', $this->processed_terms[ $old_id ], $lang->tl_term_taxonomy_id ); - // translation relationship + // Translation relationship $trs[] = $wpdb->prepare( '( %d, %d )', $this->processed_terms[ $old_id ], get_term( $this->processed_terms[ $term['term_id'] ], 'term_translations' )->term_taxonomy_id ); } } } - // insert term_relationships + // Insert term_relationships if ( ! empty( $trs ) ) { $trs = array_unique( $trs ); - // make sure we don't attempt to insert already existing term relationships - $existing_trs = $wpdb->get_results( " - SELECT tr.object_id, tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr - INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id - WHERE tt.taxonomy IN ( 'term_language', 'term_translations' ) - " ); + // Make sure we don't attempt to insert already existing term relationships + $existing_trs = $wpdb->get_results( + "SELECT tr.object_id, tr.term_taxonomy_id FROM {$wpdb->term_relationships} AS tr + INNER JOIN {$wpdb->term_taxonomy} AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id + WHERE tt.taxonomy IN ( 'term_language', 'term_translations' )" + ); foreach ( $existing_trs as $key => $tr ) { $existing_trs[ $key ] = $wpdb->prepare( '( %d, %d )', $tr->object_id, $tr->term_taxonomy_id ); @@ -144,24 +154,27 @@ class PLL_WP_Import extends WP_Import { $trs = array_diff( $trs, $existing_trs ); if ( ! empty( $trs ) ) { - $wpdb->query( "INSERT INTO $wpdb->term_relationships ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) ); + // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "INSERT INTO {$wpdb->term_relationships} ( object_id, term_taxonomy_id ) VALUES " . implode( ',', $trs ) ); } } } /** - * remaps translations for both posts and terms + * Remaps translations for both posts and terms * * @since 1.2 * * @param array $terms array of terms in 'post_translations' or 'term_translations' taxonomies * @param array $processed_objects array of posts or terms processed by WordPress Importer */ - function remap_translations( &$terms, &$processed_objects ) { + protected function remap_translations( &$terms, &$processed_objects ) { global $wpdb; + $u = array(); + foreach ( $terms as $term ) { - $translations = unserialize( $term['term_description'] ); + $translations = maybe_unserialize( $term['term_description'] ); $new_translations = array(); foreach ( $translations as $slug => $old_id ) { @@ -171,15 +184,19 @@ class PLL_WP_Import extends WP_Import { } if ( ! empty( $new_translations ) ) { - $u['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $this->processed_terms[ $term['term_id'] ], serialize( $new_translations ) ); + $u['case'][] = $wpdb->prepare( 'WHEN %d THEN %s', $this->processed_terms[ $term['term_id'] ], maybe_serialize( $new_translations ) ); $u['in'][] = (int) $this->processed_terms[ $term['term_id'] ]; } } if ( ! empty( $u ) ) { - $wpdb->query( "UPDATE $wpdb->term_taxonomy + // PHPCS:disable WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( + "UPDATE {$wpdb->term_taxonomy} SET description = ( CASE term_id " . implode( ' ', $u['case'] ) . ' END ) - WHERE term_id IN ( ' . implode( ',', $u['in'] ) . ' )' ); + WHERE term_id IN ( ' . implode( ',', $u['in'] ) . ' )' + ); + // PHPCS:enable } } } diff --git a/wp-content/plugins/polylang/integrations/wp-offload-media/as3cf.php b/wp-content/plugins/polylang/integrations/wp-offload-media/as3cf.php new file mode 100644 index 00000000..4910f710 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-offload-media/as3cf.php @@ -0,0 +1,72 @@ +is_media_translated[ $post_id ] = ( count( pll_get_post_translations( $post_id ) ) > 1 ); + } + + /** + * Deletes the WP Offload Media information from the attachment being deleted. + * That way WP Offload Media won't delete the file stored in the cloud. + * Done after Polylang has deleted the translations informations, to avoid the synchronization of the deletion + * and of course before WP Offload Media deletes the file, normally at priority 20. + * + * @since 2.6 + * + * @param int $post_id Id of the attachment being deleted. + */ + public function prevent_file_deletion( $post_id ) { + if ( ! empty( $this->is_media_translated[ $post_id ] ) ) { + delete_post_meta( $post_id, 'amazonS3_info' ); + delete_post_meta( $post_id, 'as3cf_filesize_total' ); + } + } +} diff --git a/wp-content/plugins/polylang/integrations/wp-offload-media/load.php b/wp-content/plugins/polylang/integrations/wp-offload-media/load.php new file mode 100644 index 00000000..25657e59 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-offload-media/load.php @@ -0,0 +1,21 @@ +as3cf = new PLL_AS3CF(), 'init' ) ); + } + }, + 0 +); + diff --git a/wp-content/plugins/polylang/integrations/wp-sweep/load.php b/wp-content/plugins/polylang/integrations/wp-sweep/load.php new file mode 100644 index 00000000..a64f2c25 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-sweep/load.php @@ -0,0 +1,21 @@ +wp_sweep = new PLL_WP_Sweep(); + PLL_Integrations::instance()->wp_sweep->init(); + } + }, + 0 +); diff --git a/wp-content/plugins/polylang/integrations/wp-sweep/wp-sweep.php b/wp-content/plugins/polylang/integrations/wp-sweep/wp-sweep.php new file mode 100644 index 00000000..eba57c59 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wp-sweep/wp-sweep.php @@ -0,0 +1,61 @@ + 'term_id' ) ), + pll_languages_list( array( 'fields' => 'tl_term_id' ) ) + ); + + return array_unique( $excluded_term_ids ); + } +} diff --git a/wp-content/plugins/polylang/integrations/wpseo/load.php b/wp-content/plugins/polylang/integrations/wpseo/load.php new file mode 100644 index 00000000..a6dd0001 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wpseo/load.php @@ -0,0 +1,21 @@ +wpseo = new PLL_WPSEO(), 'init' ) ); + } + }, + 0 +); + diff --git a/wp-content/plugins/polylang/integrations/wpseo/wpseo-ogp.php b/wp-content/plugins/polylang/integrations/wpseo/wpseo-ogp.php new file mode 100644 index 00000000..b5d7bfb1 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wpseo/wpseo-ogp.php @@ -0,0 +1,55 @@ +locale = $locale; + } + + /** + * Returns the meta Opengraph alternate locale meta tag + * + * @since 2.7.3 + * + * @return string + */ + public function present() { + return sprintf( '', esc_attr( $this->get() ) ); + } + + /** + * Returns the alternate locale + * + * @since 2.7.3 + * + * @return string + */ + public function get() { + return $this->locale; + } +} + diff --git a/wp-content/plugins/polylang/integrations/wpseo/wpseo.php b/wp-content/plugins/polylang/integrations/wpseo/wpseo.php new file mode 100644 index 00000000..16575759 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/wpseo/wpseo.php @@ -0,0 +1,493 @@ +options['force_lang'] > 1 ) { + add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_false' ); // Disable cache! otherwise WPSEO keeps only one domain (thanks to Junaid Bhura) + add_filter( 'home_url', array( $this, 'wpseo_home_url' ), 10, 2 ); // Fix home_url + add_action( 'setup_theme', array( $this, 'maybe_deactivate_sitemap' ) ); // Deactivate sitemaps for inactive languages. + } else { + // Get all terms in all languages when the language is set from the content or directory name + add_filter( 'get_terms_args', array( $this, 'wpseo_remove_terms_filter' ) ); + add_action( 'pre_get_posts', array( $this, 'before_sitemap' ), 0 ); // Needs to be fired before WPSEO_Sitemaps::redirect() + } + + add_filter( 'pll_home_url_white_list', array( $this, 'wpseo_home_url_white_list' ) ); + if ( version_compare( WPSEO_VERSION, '14.0', '<' ) ) { + add_action( 'wpseo_opengraph', array( $this, 'wpseo_ogp' ), 2 ); + } else { + add_filter( 'wpseo_frontend_presenters', array( $this, 'wpseo_frontend_presenters' ) ); + } + add_filter( 'wpseo_canonical', array( $this, 'wpseo_canonical' ) ); + add_filter( 'wpseo_frontend_presentation', array( $this, 'frontend_presentation' ) ); + add_filter( 'wpseo_breadcrumb_indexables', array( $this, 'breadcrumb_indexables' ) ); + } else { + add_filter( 'pll_copy_post_metas', array( $this, 'copy_post_metas' ), 10, 2 ); + add_filter( 'pll_translate_post_meta', array( $this, 'translate_post_meta' ), 10, 3 ); + } + } + + /** + * Registers options for translation. + * + * @since 2.9 + */ + public function wpseo_translate_options() { + if ( method_exists( 'WPSEO_Options', 'clear_cache' ) ) { + WPSEO_Options::clear_cache(); + } + + $keys = array( + 'title-*', + 'metadesc-*', + 'bctitle-*', + 'breadcrumbs-sep', + 'breadcrumbs-home', + 'breadcrumbs-prefix', + 'breadcrumbs-archiveprefix', + 'breadcrumbs-searchprefix', + 'breadcrumbs-404crumb', + 'company_name', + 'rssbefore', + 'rssafter', + ); + + new PLL_Translate_Option( 'wpseo_titles', array_fill_keys( $keys, 1 ), array( 'context' => 'wordpress-seo' ) ); + + $keys = array( + 'og_frontpage_title', + 'og_frontpage_desc', + ); + + new PLL_Translate_Option( 'wpseo_social', array_fill_keys( $keys, 1 ), array( 'context' => 'wordpress-seo' ) ); + } + + /** + * Fixes the home url as well as the stylesheet url + * Only when using multiple domains or subdomains + * + * @since 1.6.4 + * + * @param string $url + * @param string $path + * @return $url + */ + public function wpseo_home_url( $url, $path ) { + if ( empty( $path ) ) { + $path = ltrim( wp_parse_url( pll_get_requested_url(), PHP_URL_PATH ), '/' ); + } + + if ( preg_match( '#sitemap(_index)?\.xml|([^\/]+?)-?sitemap([0-9]+)?\.xml|([a-z]+)?-?sitemap\.xsl#', $path ) ) { + $url = PLL()->links_model->switch_language_in_link( $url, PLL()->curlang ); + } + + return $url; + } + + /** + * Get active languages for the sitemaps + * + * @since 2.0 + * + * @return array list of active language slugs, empty if all languages are active + */ + protected function wpseo_get_active_languages() { + $languages = PLL()->model->get_languages_list(); + if ( wp_list_filter( $languages, array( 'active' => false ) ) ) { + return wp_list_pluck( wp_list_filter( $languages, array( 'active' => false ), 'NOT' ), 'slug' ); + } + return array(); + } + + /** + * Modifies the sql request for posts sitemaps + * Only when using multiple domains or subdomains or if some languages are not active + * + * @since 1.6.4 + * + * @param string $sql JOIN clause + * @param string $post_type + * @return string + */ + public function wpseo_posts_join( $sql, $post_type ) { + return pll_is_translated_post_type( $post_type ) && ( PLL()->options['force_lang'] > 1 || $this->wpseo_get_active_languages() ) ? $sql . PLL()->model->post->join_clause() : $sql; + } + + /** + * Modifies the sql request for posts sitemaps + * Only when using multiple domains or subdomains or if some languages are not active + * + * @since 1.6.4 + * + * @param string $sql WHERE clause + * @param string $post_type + * @return string + */ + public function wpseo_posts_where( $sql, $post_type ) { + if ( pll_is_translated_post_type( $post_type ) ) { + if ( PLL()->options['force_lang'] > 1 ) { + return $sql . PLL()->model->post->where_clause( PLL()->curlang ); + } + + if ( $languages = $this->wpseo_get_active_languages() ) { + return $sql . PLL()->model->post->where_clause( $languages ); + } + } + return $sql; + } + + /** + * Removes the language filter (and remove inactive languages) for the taxonomy sitemaps + * Only when the language is set from the content or directory name + * + * @since 1.0.3 + * + * @param array $args get_terms arguments + * @return array modified list of arguments + */ + public function wpseo_remove_terms_filter( $args ) { + if ( isset( $GLOBALS['wp_query']->query['sitemap'] ) ) { + $args['lang'] = implode( ',', $this->wpseo_get_active_languages() ); + } + return $args; + } + + /** + * Deactivates the sitemap for inactive languages when using subdomains or multiple domains + * + * @since 2.6.1 + */ + public function maybe_deactivate_sitemap() { + global $wpseo_sitemaps; + + if ( isset( $wpseo_sitemaps ) ) { + $active_languages = $this->wpseo_get_active_languages(); + if ( ! empty( $active_languages ) && ! in_array( pll_current_language(), $active_languages ) ) { + remove_action( 'pre_get_posts', array( $wpseo_sitemaps, 'redirect' ), 1 ); + } + } + } + + /** + * Add filters before the sitemap is evaluated and outputed. + * + * @since 2.6 + * + * @param WP_Query $query Instance of WP_Query being filtered. + */ + public function before_sitemap( $query ) { + $type = $query->get( 'sitemap' ); + + // Add the post post type archives in all languages to the sitemap + // Add the homepages for all languages to the sitemap when the front page displays posts + if ( $type && pll_is_translated_post_type( $type ) && ( 'post' !== $type || ! get_option( 'page_on_front' ) ) ) { + add_filter( "wpseo_sitemap_{$type}_content", array( $this, 'add_post_type_archive' ) ); + } + } + + /** + * Generates a post type archive sitemap url + * + * @since 2.6.1 + * + * @param string $link The url. + * @param string $post_type The post type name. + * @return string Formatted sitemap url. + */ + protected function format_sitemap_url( $link, $post_type ) { + global $wpseo_sitemaps; + + return $wpseo_sitemaps->renderer->sitemap_url( + array( + 'loc' => $link, + 'mod' => WPSEO_Sitemaps::get_last_modified_gmt( $post_type ), + 'pri' => 1, + 'chf' => 'daily', + ) + ); + } + + /** + * Adds the home and post type archives urls for all (active) languages to the sitemap + * + * @since 2.6 + * + * @param string $str additional urls to sitemap post + * @return string + */ + public function add_post_type_archive( $str ) { + $post_type = substr( substr( current_filter(), 14 ), 0, -8 ); + $post_type_obj = get_post_type_object( $post_type ); + $languages = wp_list_filter( PLL()->model->get_languages_list(), array( 'active' => false ), 'NOT' ); + + if ( 'post' === $post_type ) { + if ( ! empty( PLL()->options['hide_default'] ) ) { + // The home url is of course already added by WPSEO. + $languages = wp_list_filter( $languages, array( 'slug' => pll_default_language() ), 'NOT' ); + } + + foreach ( $languages as $lang ) { + $str .= $this->format_sitemap_url( pll_home_url( $lang->slug ), $post_type ); + } + } elseif ( $post_type_obj->has_archive ) { + // Exclude cases where a post type archive is attached to a page (ex: WooCommerce). + $slug = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; + + if ( ! wpcom_vip_get_page_by_path( $slug ) ) { + // The post type archive in the current language is already added by WPSEO. + $languages = wp_list_filter( $languages, array( 'slug' => pll_current_language() ), 'NOT' ); + + foreach ( $languages as $lang ) { + PLL()->curlang = $lang; // Switch the language to get the correct archive link. + $link = get_post_type_archive_link( $post_type ); + $str .= $this->format_sitemap_url( $link, $post_type ); + } + } + } + + return $str; + } + + /** + * Filters home url + * + * @since 1.1.2 + * + * @param array $arr + * @return array + */ + public function wpseo_home_url_white_list( $arr ) { + return array_merge( $arr, array( array( 'file' => 'wordpress-seo' ) ) ); + } + + /** + * Get alternate language codes for Opengraph + * + * @since 2.7.3 + * + * @return array + */ + protected function get_ogp_alternate_languages() { + $alternates = array(); + + foreach ( PLL()->model->get_languages_list() as $language ) { + if ( PLL()->curlang->slug !== $language->slug && PLL()->links->get_translation_url( $language ) && isset( $language->facebook ) ) { + $alternates[] = $language->facebook; + } + } + + // There is a risk that 2 languages have the same Facebook locale. So let's make sure to output each locale only once. + return array_unique( $alternates ); + } + + /** + * Adds opengraph support for translations + * + * @since 1.6 + */ + public function wpseo_ogp() { + global $wpseo_og; + + // WPSEO already deals with the locale + if ( did_action( 'pll_init' ) && method_exists( $wpseo_og, 'og_tag' ) ) { + foreach ( $this->get_ogp_alternate_languages() as $lang ) { + $wpseo_og->og_tag( 'og:locale:alternate', $lang ); + } + } + } + + /** + * Adds opengraph support for translations + * + * @since 2.7.3 + * + * @param array $presenters An array of objects implementing Abstract_Indexable_Presenter + * @return array + */ + public function wpseo_frontend_presenters( $presenters ) { + $_presenters = array(); + + foreach ( $presenters as $presenter ) { + $_presenters[] = $presenter; + if ( $presenter instanceof Yoast\WP\SEO\Presenters\Open_Graph\Locale_Presenter ) { + foreach ( $this->get_ogp_alternate_languages() as $lang ) { + $_presenters[] = new PLL_WPSEO_OGP( $lang ); + } + } + } + return $_presenters; + } + + /** + * Fixes the canonical front page url as unlike WP, WPSEO does not add a trailing slash to the canonical front page url + * + * @since 1.7.10 + * + * @param string $url + * @return $url + */ + public function wpseo_canonical( $url ) { + return is_front_page( $url ) && get_option( 'permalink_structure' ) ? trailingslashit( $url ) : $url; + } + + /** + * Fixes the links and strings stored in the indexable table since Yoast SEO 14.0 + * + * @since 2.8.2 + * + * @param object $presentation The indexable presentation. + * @return object + */ + public function frontend_presentation( $presentation ) { + switch ( $presentation->model->object_type ) { + case 'home-page': + $presentation->model->permalink = pll_home_url(); + $presentation->model->title = WPSEO_Options::get( 'title-home-wpseo' ); + $presentation->model->description = WPSEO_Options::get( 'metadesc-home-wpseo' ); + $presentation->model->open_graph_title = WPSEO_Options::get( 'og_frontpage_title' ); + $presentation->model->open_graph_description = WPSEO_Options::get( 'og_frontpage_desc' ); + break; + + case 'post-type-archive': + if ( pll_is_translated_post_type( $presentation->model->object_sub_type ) ) { + $presentation->model->permalink = get_post_type_archive_link( $presentation->model->object_sub_type ); + $presentation->model->title = WPSEO_Options::get( 'title-ptarchive-' . $presentation->model->object_sub_type ); + $presentation->model->description = WPSEO_Options::get( 'metadesc-ptarchive-' . $presentation->model->object_sub_type ); + } + break; + + case 'user': + $presentation->model->permalink = get_author_posts_url( $presentation->model->object_id ); + break; + + case 'system-page': + switch ( $presentation->model->object_sub_type ) { + case '404': + $presentation->model->title = WPSEO_Options::get( 'title-404-wpseo' ); + break; + case 'search-result': + $presentation->model->title = WPSEO_Options::get( 'title-search-wpseo' ); + break; + } + break; + } + + return $presentation; + } + + /** + * Fixes the breadcrumb links and strings stored in the indexable table since Yoast SEO 14.0 + * + * @since 2.8.3 + * + * @param array $indexables An array of Indexable objects. + * @return object + */ + public function breadcrumb_indexables( $indexables ) { + foreach ( $indexables as &$indexable ) { + switch ( $indexable->object_type ) { + case 'home-page': + $indexable->permalink = pll_home_url(); + $indexable->breadcrumb_title = pll__( WPSEO_Options::get( 'breadcrumbs-home' ) ); + break; + + case 'post-type-archive': + if ( pll_is_translated_post_type( $indexable->object_sub_type ) ) { + $indexable->permalink = get_post_type_archive_link( $indexable->object_sub_type ); + $breadcrumb_title = WPSEO_Options::get( 'bctitle-ptarchive-' . $indexable->object_sub_type ); + $breadcrumb_title = $breadcrumb_title ? $breadcrumb_title : $indexable->breadcrumb_title; // The option may be empty. + $indexable->breadcrumb_title = pll__( $breadcrumb_title ); + } + break; + } + } + + return $indexables; + } + + /** + * Copies or synchronizes the metas. + * + * @since 2.3.3 + * + * @param string[] $keys List of custom fields names. + * @param bool $sync True if it is synchronization, false if it is a copy. + * @return array + */ + public function copy_post_metas( $keys, $sync ) { + if ( ! $sync ) { + // Text requiring translation. + $keys[] = '_yoast_wpseo_title'; + $keys[] = '_yoast_wpseo_metadesc'; + $keys[] = '_yoast_wpseo_bctitle'; + $keys[] = '_yoast_wpseo_focuskw'; + $keys[] = '_yoast_wpseo_opengraph-title'; + $keys[] = '_yoast_wpseo_opengraph-description'; + $keys[] = '_yoast_wpseo_twitter-title'; + $keys[] = '_yoast_wpseo_twitter-description'; + + // Copy the image urls. + $keys[] = '_yoast_wpseo_opengraph-image'; + $keys[] = '_yoast_wpseo_twitter-image'; + } + + $keys[] = '_yoast_wpseo_meta-robots-noindex'; + $keys[] = '_yoast_wpseo_meta-robots-nofollow'; + $keys[] = '_yoast_wpseo_meta-robots-adv'; + + $taxonomies = get_taxonomies( + array( + 'hierarchical' => true, + 'public' => true, + ) + ); + + foreach ( $taxonomies as $taxonomy ) { + $keys[] = '_yoast_wpseo_primary_' . $taxonomy; + } + + return $keys; + } + + /** + * Translate the primary term during the synchronization process + * + * @since 2.3.3 + * + * @param int $value Meta value. + * @param string $key Meta key. + * @param string $lang Language of target. + * @return int + */ + public function translate_post_meta( $value, $key, $lang ) { + if ( false !== strpos( $key, '_yoast_wpseo_primary_' ) ) { + $value = pll_get_term( $value, $lang ); + } + return $value; + } +} diff --git a/wp-content/plugins/polylang/integrations/yarpp/load.php b/wp-content/plugins/polylang/integrations/yarpp/load.php new file mode 100644 index 00000000..5ea74d99 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/yarpp/load.php @@ -0,0 +1,20 @@ +yarpp = new PLL_Yarpp(), 'init' ) ); + } + }, + 0 +); diff --git a/wp-content/plugins/polylang/integrations/yarpp/yarpp.php b/wp-content/plugins/polylang/integrations/yarpp/yarpp.php new file mode 100644 index 00000000..11e66d68 --- /dev/null +++ b/wp-content/plugins/polylang/integrations/yarpp/yarpp.php @@ -0,0 +1,20 @@ +yarpp_support = 1; + } +} diff --git a/wp-content/plugins/polylang/js/admin.js b/wp-content/plugins/polylang/js/admin.js deleted file mode 100644 index fc12c603..00000000 --- a/wp-content/plugins/polylang/js/admin.js +++ /dev/null @@ -1,191 +0,0 @@ -jQuery( document ).ready(function( $ ) { - var transitionTimeout; - - // languages list table - // accessibility to row actions on focus - // mainly copy paste of WP code from common.js - $( 'table.languages' ).on({ // restricted to languages list table - focusin: function() { - clearTimeout( transitionTimeout ); - focusedRowActions = $( this ).find( '.row-actions' ); - // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. - $( '.row-actions' ).not( this ).removeClass( 'visible' ); - focusedRowActions.addClass( 'visible' ); - }, - focusout: function() { - // Tabbing between post title and .row-actions links needs a brief pause, otherwise - // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ). - transitionTimeout = setTimeout(function() { - focusedRowActions.removeClass( 'visible' ); - }, 30 ); - } - }, 'tr' ); // acts on the whole tr instead of single td as we have actions links in several columns - - // extends selectmenu to add flags in menu items - $.widget( "custom.iconselectmenu", $.ui.selectmenu, { - _renderItem: function( ul, item ) { - var li = $( "
  • ", { text: item.label } ); - - if ( item.value ) { - $( "", { - src: pll_flag_base_url + item.value + '.png', - "class": "ui-icon" - }).appendTo( li ); - } - - return li.appendTo( ul ); - } - }); - - // allows to display the flag for the selected menu item - function add_icon( event, ui ) { - var value = $( this ).val(); - if ( value ) { - var txt = $( this ).iconselectmenu( "widget" ).children( ":last" ); - var img = $( '' ).appendTo( txt ); - img.attr( "src", pll_flag_base_url + value + '.png' ); - } - } - - // overrides the flag dropdown list with our customized jquery ui selectmenu - $( "#flag_list" ).iconselectmenu({ - create: add_icon, - select: add_icon, - }); - - // languages form - // fills the fields based on the language dropdown list choice - $( '#lang_list' ).change(function() { - var value = $( this ).val().split( ':' ); - var selected = $( "select option:selected" ).text().split( ' - ' ); - $( '#lang_slug' ).val( value[0] ); - $( '#lang_locale' ).val( value[1] ); - $( 'input[name="rtl"]' ).val( [value[2]] ); - $( '#lang_name' ).val( selected[0] ); - $( '#flag_list option[value="' + value[3] + '"]' ).attr( 'selected', 'selected' ); - - // recreate the jquery ui selectmenu - $( "#flag_list" ).iconselectmenu( 'destroy' ).iconselectmenu({ - create: add_icon, - select: add_icon, - }) - }); - - // strings translations - // save translations when pressing enter - $( '.translation input' ).keypress(function( event ){ - if ( 13 === event.keyCode ) { - event.preventDefault(); - $( '#submit' ).click(); - } - }); - - // settings page - // click on configure link - $( '#the-list' ).on( 'click', '.configure>a', function(){ - $( '.pll-configure' ).hide().prev().show(); - $( this ).closest( 'tr' ).hide().next().show(); - return false; - }); - - // cancel - $( '#the-list' ).on( 'click', '.cancel', function(){ - $( this ).closest( 'tr' ).hide().prev().show(); - }); - - // save settings - $( '#the-list' ).on( 'click', '.save', function(){ - var tr = $( this ).closest( 'tr' ); - var parts = tr.attr( 'id' ).split( '-' ); - - var data = { - action: 'pll_save_options', - pll_ajax_settings: true, - module: parts[parts.length - 1], - _pll_nonce: $( '#_pll_nonce' ).val() - } - - data = tr.find( ':input' ).serialize() + '&' + $.param( data ); - - $.post( ajaxurl, data, function( response ) { - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); - $.each( res.responses, function() { - switch ( this.what ) { - case 'license-update': - $( '#pll-license-' + this.data ).replaceWith( this.supplemental.html ); - break; - case 'success': - tr.hide().prev().show(); // close only if there is no error - case 'error': - $( '.settings-error' ).remove(); // remove previous messages if any - $( 'h1' ).after( this.data ); - - // Make notices dismissible - // copy paste of common.js from WP 4.2.2 - $( '.notice.is-dismissible' ).each(function() { - var $this = $( this ), - $button = $( '' ), - btnText = commonL10n.dismiss || ''; - - // Ensure plain text - $button.find( '.screen-reader-text' ).text( btnText ); - - $this.append( $button ); - - $button.on( 'click.wp-dismiss-notice', function( event ) { - event.preventDefault(); - $this.fadeTo( 100 , 0, function() { - $( this ).slideUp( 100, function() { - $( this ).remove(); - }); - }); - }); - }); - break; - } - }); - }); - }); - - // act when pressing enter or esc in configurations - $( '.pll-configure' ).keypress(function( event ){ - if ( 13 === event.keyCode ) { - event.preventDefault(); - $( this ).find( '.save' ).click(); - } - - if ( 27 === event.keyCode ) { - event.preventDefault(); - $( this ).find( '.cancel' ).click(); - } - }); - - // settings URL modifications - // manages visibility of fields - $( "input[name='force_lang']" ).change(function() { - function pll_toggle( a, test ) { - test ? a.show() : a.hide(); - } - - var value = $( this ).val(); - pll_toggle( $( '#pll-domains-table' ), 3 == value ); - pll_toggle( $( "#pll-hide-default" ), 3 > value ); - pll_toggle( $( "#pll-rewrite" ), 2 > value ); - pll_toggle( $( "#pll-redirect-lang" ), 2 > value ); - }); - - // settings license - // deactivate button - $( '.pll-deactivate-license' ).on( 'click', function() { - var data = { - action: 'pll_deactivate_license', - pll_ajax_settings: true, - id: $( this ).attr( 'id' ), - _pll_nonce: $( '#_pll_nonce' ).val() - } - $.post( ajaxurl, data , function( response ){ - $( '#pll-license-' + response.id ).replaceWith( response.html ); - }); - }); - -}); diff --git a/wp-content/plugins/polylang/js/admin.min.js b/wp-content/plugins/polylang/js/admin.min.js deleted file mode 100644 index 5fdff77e..00000000 --- a/wp-content/plugins/polylang/js/admin.min.js +++ /dev/null @@ -1 +0,0 @@ -jQuery(document).ready(function(e){function t(){var t=e(this).val();if(t){var n=e(this).iconselectmenu("widget").children(":last"),i=e('').appendTo(n);i.attr("src",pll_flag_base_url+t+".png")}}var n;e("table.languages").on({focusin:function(){clearTimeout(n),focusedRowActions=e(this).find(".row-actions"),e(".row-actions").not(this).removeClass("visible"),focusedRowActions.addClass("visible")},focusout:function(){n=setTimeout(function(){focusedRowActions.removeClass("visible")},30)}},"tr"),e.widget("custom.iconselectmenu",e.ui.selectmenu,{_renderItem:function(t,n){var i=e("
  • ",{text:n.label});return n.value&&e("",{src:pll_flag_base_url+n.value+".png","class":"ui-icon"}).appendTo(i),i.appendTo(t)}}),e("#flag_list").iconselectmenu({create:t,select:t}),e("#lang_list").change(function(){var n=e(this).val().split(":"),i=e("select option:selected").text().split(" - ");e("#lang_slug").val(n[0]),e("#lang_locale").val(n[1]),e('input[name="rtl"]').val([n[2]]),e("#lang_name").val(i[0]),e('#flag_list option[value="'+n[3]+'"]').attr("selected","selected"),e("#flag_list").iconselectmenu("destroy").iconselectmenu({create:t,select:t})}),e(".translation input").keypress(function(t){13===t.keyCode&&(t.preventDefault(),e("#submit").click())}),e("#the-list").on("click",".configure>a",function(){return e(".pll-configure").hide().prev().show(),e(this).closest("tr").hide().next().show(),!1}),e("#the-list").on("click",".cancel",function(){e(this).closest("tr").hide().prev().show()}),e("#the-list").on("click",".save",function(){var t=e(this).closest("tr"),n=t.attr("id").split("-"),i={action:"pll_save_options",pll_ajax_settings:!0,module:n[n.length-1],_pll_nonce:e("#_pll_nonce").val()};i=t.find(":input").serialize()+"&"+e.param(i),e.post(ajaxurl,i,function(n){var i=wpAjax.parseAjaxResponse(n,"ajax-response");e.each(i.responses,function(){switch(this.what){case"license-update":e("#pll-license-"+this.data).replaceWith(this.supplemental.html);break;case"success":t.hide().prev().show();case"error":e(".settings-error").remove(),e("h1").after(this.data),e(".notice.is-dismissible").each(function(){var t=e(this),n=e(''),i=commonL10n.dismiss||"";n.find(".screen-reader-text").text(i),t.append(n),n.on("click.wp-dismiss-notice",function(n){n.preventDefault(),t.fadeTo(100,0,function(){e(this).slideUp(100,function(){e(this).remove()})})})})}})})}),e(".pll-configure").keypress(function(t){13===t.keyCode&&(t.preventDefault(),e(this).find(".save").click()),27===t.keyCode&&(t.preventDefault(),e(this).find(".cancel").click())}),e("input[name='force_lang']").change(function(){function t(e,t){t?e.show():e.hide()}var n=e(this).val();t(e("#pll-domains-table"),3==n),t(e("#pll-hide-default"),3>n),t(e("#pll-rewrite"),2>n),t(e("#pll-redirect-lang"),2>n)}),e(".pll-deactivate-license").on("click",function(){var t={action:"pll_deactivate_license",pll_ajax_settings:!0,id:e(this).attr("id"),_pll_nonce:e("#_pll_nonce").val()};e.post(ajaxurl,t,function(t){e("#pll-license-"+t.id).replaceWith(t.html)})})}); diff --git a/wp-content/plugins/polylang/js/build/admin.js b/wp-content/plugins/polylang/js/build/admin.js new file mode 100644 index 00000000..0fc7c0b1 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/admin.js @@ -0,0 +1,417 @@ +var __webpack_exports__ = {}; +/** + * @package Polylang + */ + +jQuery( + function( $ ) { + + // languages list table + // accessibility to row actions on focus + // mainly copy paste of WP code from common.js + var transitionTimeout; + $( 'table.languages' ).on( + { // restricted to languages list table + focusin: function() { + clearTimeout( transitionTimeout ); + var focusedRowActions = $( this ).find( '.row-actions' ); + // transitionTimeout is necessary for Firefox, but Chrome won't remove the CSS class without a little help. + $( '.row-actions' ).not( this ).removeClass( 'visible' ); + focusedRowActions.addClass( 'visible' ); + }, + focusout: function() { + // Tabbing between post title and .row-actions links needs a brief pause, otherwise + // the .row-actions div gets hidden in transit in some browsers ( ahem, Firefox ). + transitionTimeout = setTimeout( + function() { + focusedRowActions.removeClass( 'visible' ); + }, + 30 + ); + } + }, + 'tr' + ); // acts on the whole tr instead of single td as we have actions links in several columns + + /** + * Common functions and variables for overriding languages and flags dropdown list by a jQuery UI selectmenu widget. + */ + + // Add a boolean variable to be able to check jQuery UI >= 1.12 which is introduced in WP 5.6. + // Backward compatibility WP < 5.6 + var isJqueryUImin112 = $.ui.version >= '1.12.0'; + // Allow to check if a flag list dropdown is present. Not present in the Wizard steps or other settings page. + var flagListExist = $( "#flag_list" ).length; + // Allow to check if a language list dropdown is present. Not present in other settings page. + var langListExist = $( "#lang_list" ).length; + // jQuery UI selectmenu widget width option + var defaultSelectmenuWidth = '95%'; + var wizardSelectmenuWidth = '100%'; + + // Inject flag image when jQuery UI selectmenu is created or an item is selected. + // jQuery UI 1.12 introduce a wrapper inside de li tag which is necessary to selectmenu widget to work correctly. + // Mainly copy from the orginal jQuery UI 1.12 selectmenu widget _renderItem method. + // Note this code works fine with jQuery UI 1.11.4 too. + var selectmenuRenderItem = function( ul, item ) { + var li = $( '
  • ' ); + var wrapper = $( '
    '); + + if ( item.disabled ) { + this._addClass( li, null, "ui-state-disabled" ); + } + this._setText( wrapper, item.label ); + + // Add the flag from the data attribute in the selected element. + wrapper.prepend( $( item.element ).data( 'flag-html' ) ); + wrapper.children( 'img' ).addClass( 'ui-icon' ); + + return li.append( wrapper ).appendTo( ul ); + }; + // Override selected item to inject flag for jQuery UI less than 1.12. + var selectmenuRefreshButtonText = function( selectElement ) { + var buttonText = $( selectElement ).selectmenu( 'instance' ).buttonText; + buttonText.prepend( $( selectElement ).children( ':selected' ).data( 'flag-html' ) ); + buttonText.children( 'img' ).addClass( 'ui-icon' ); + }; + // Override selected item since jQuery UI 1.12 which introduces extension point method _renderButtonItem. + // @see https://api.jqueryui.com/1.12/selectmenu/#method-_renderButtonItem _renderButtonItem documentation. + var selectmenuRenderButtonItem = function ( selectElement ) { + var buttonItem = $( '' ); + this._setText( buttonItem, selectElement.label ); + this._addClass( buttonItem, "ui-selectmenu-text" ); + + // Add the flag from the data attribute in the selected element. + buttonItem.prepend( $( selectElement.element ).data( 'flag-html' ) ); + buttonItem.children( 'img' ).addClass( 'ui-icon' ); + + return buttonItem; + } + + /** + * Initialize a jQuery UI selectmenu widget on a DOM element + * + * @param {*} element - The jQuery object representing the DOM element to attach the widget with. + * @param {*} config - All the parameters - options and callbacks - necessary to configure the jQuery UI selectmenu widget. + * @return {Object} - The jQuery UI selectmenu widget object instance. + */ + function initializeSelectmenuWidget( element, config ) { + // Create the jQuery UI selectmenu widget for flags list dropdown and return its instance. + var selectmenuWidgetInstance = element.selectmenu( config ).selectmenu( 'instance' ); + // Overrides each item in the jQuery UI selectmenu list by injecting flag image. + selectmenuWidgetInstance._renderItem = selectmenuRenderItem; + // Override the selected item rendering for jQuery UI 1.12 + if ( isJqueryUImin112 ) { + selectmenuWidgetInstance._renderButtonItem = selectmenuRenderButtonItem; + // Need to refresh to take in account the new button item rendering method after the selectmenu widget instanciaion. + selectmenuWidgetInstance.refresh(); + } + return selectmenuWidgetInstance + } + /** + * Selectmenu widget common parameters for its configuration: options and callbacks. + */ + + // Selectmenu widget options + var selectmenuOptions = { + width: defaultSelectmenuWidth, + classes: { + 'ui-selectmenu-menu': 'pll-selectmenu-menu', + 'ui-selectmenu-button': 'pll-selectmenu-button', + } + }; + + // Selectmenu widget callbacks + var selectmenuFlagListCallbacks = {}; + // Callbacks when Selectmenu widget create or select event is triggered. + var createSelectCallback = function( event, ui ) { + selectmenuRefreshButtonText( event.target ); + } + + /** + * Overrides the flag dropdown list with our customized jquery ui selectmenu. + */ + + // Callbacks when Selectmenu widget change or open event is triggered. + // Needed to correctly refresh the selected element in the list when editing an existing language or when the value change is triggered by the language choice. + // jQuery UI 1.11 callback version. + var changeOpenCallback = function( event, ui ){ + selectmenuRefreshButtonText( $( event.target ).selectmenu( 'refresh' ) ); + } + // jQueryUI 1.12 callback version. + var changeOpenCallbackjQueryUI112 = function( event, ui ){ + // Just a refresh of the menu is needed with jQuery UI 1.12 because _renderButtonItem is triggered and then inject correctly the flag. + $( event.target ).selectmenu( 'refresh' ); + } + // There is no need of create and select callbacks with jQuery UI 1.12 because overriding _renderButtonItem method do the job. + if ( isJqueryUImin112 ) { + selectmenuFlagListCallbacks = + { + change: changeOpenCallbackjQueryUI112, + open: changeOpenCallbackjQueryUI112, + }; + } else { + selectmenuFlagListCallbacks = { + create: createSelectCallback, + select: createSelectCallback, + change: changeOpenCallback, + open: changeOpenCallback, + }; + } + + // Create the selectmenu widget only if the field is present. + if ( flagListExist ) { + // Create the jQuery UI selectmenu widget for flags list dropdown and return its instance. + var selectmenuFlagList = initializeSelectmenuWidget( $( '#flag_list' ), Object.assign( {}, selectmenuOptions, selectmenuFlagListCallbacks ) ); + $( '#lang_list' ).on( + 'languageChanged', + function( event, flag ) { + // Refresh the flag field + selectmenuFlagList.element.val( flag ); + selectmenuFlagList._trigger( 'change' ); + } + ); + } + + /** + * Language choice in predefined languages in Polylang Languages settings page and wizard. + * Overrides the predefined language dropdown list with our customized jQuery ui selectmenu widget. + */ + + /** + * Fill the other language form fields from the language element selected in the language list dropdown. + * + * @param {Object} language - language object of the selected element in the language list dropdown. + */ + function fillLanguageFields( language ) { + $( '#lang_slug' ).val( language.slug ); + $( '#lang_locale' ).val( language.locale ); + $( 'input[name="rtl"]' ).val( language.rtl ); + $( '#lang_name' ).val( language.name ); + } + + /** + * Parse selected language element in the language list dropdown. + * + * @param {object} event - jQuery triggered event. + * @return {object} The language object with its named properties. + */ + function parseSelectedLanguage( event ) { + var selectedElement = $('option:selected', event.target); + var values = selectedElement.val().split(':') + return { + slug: values[0], + locale: values[1], + rtl: [values[2]], + flag: values[3], + name: selectedElement.text().split(' - ')[0] // At the moment there is no need of the 2nd part because it corresponds on the locale which is already known by splitting the selected element value + }; + } + + // Callback when selectmenu widget change event is triggered. + var changeCallback = function( event, ui ) { + var language = parseSelectedLanguage( event ); + + fillLanguageFields( language ); + + $( event.target ).trigger( 'languageChanged', language.flag ); + }; + + // Create the jQuery UI selectmenu widget languages list dropdown and return its instance. + var selectmenuLangListCallbacks = {}; + // For the wizard we need a 100% width. So we override the previous defined value of selectmenuOptions. + if( $( '#lang_list' ).closest( '.pll-wizard-content' ).length > 0 ) { + selectmenuOptions = Object.assign( selectmenuOptions, { width: wizardSelectmenuWidth } ); + } + + // There is no need of create and select callbacks with jQuery UI 1.12 because overrinding _renderButtonItem method do the job. + if ( isJqueryUImin112 ) { + selectmenuLangListCallbacks = { + change: changeCallback, + }; + } else { + selectmenuLangListCallbacks = { + create: createSelectCallback, + select: createSelectCallback, + change: changeCallback, + }; + } + if ( langListExist ) { + initializeSelectmenuWidget( $( '#lang_list' ), Object.assign( {}, selectmenuOptions, selectmenuLangListCallbacks ) ); + } + + // strings translations + // save translations when pressing enter + $( '.translation input' ).on( + 'keydown', + function( event ){ + if ( 'Enter' === event.key ) { + event.preventDefault(); + $( '#submit' ).trigger( 'click' ); + } + } + ); + + // settings page + // click on configure link + $( '#the-list' ).on( + 'click', + '.configure>a', + function(){ + $( '.pll-configure' ).hide().prev().show(); + $( this ).closest( 'tr' ).hide().next().show(); + return false; + } + ); + + // cancel + $( '#the-list' ).on( + 'click', + '.cancel', + function(){ + $( this ).closest( 'tr' ).hide().prev().show(); + } + ); + + // save settings + $( '#the-list' ).on( + 'click', + '.save', + function(){ + var tr = $( this ).closest( 'tr' ); + var parts = tr.attr( 'id' ).split( '-' ); + + var data = { + action: 'pll_save_options', + pll_ajax_settings: true, + module: parts[parts.length - 1], + _pll_nonce: $( '#_pll_nonce' ).val() + }; + + data = tr.find( ':input' ).serialize() + '&' + $.param( data ); + + $.post( + ajaxurl, + data, + function( response ) { + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); + $.each( + res.responses, + function() { + switch ( this.what ) { + case 'license-update': + $( '#pll-license-' + this.data ).replaceWith( this.supplemental.html ); + break; + case 'success': + tr.hide().prev().show(); // close only if there is no error + case 'error': + $( '.settings-error' ).remove(); // remove previous messages if any + $( 'h1' ).after( this.data ); + + // Make notices dismissible + // copy paste of common.js from WP 4.2.2 + $( '.notice.is-dismissible' ).each( + function() { + var $this = $( this ), + $button = $( '' ), + btnText = pll_admin.dismiss_notice || ''; + + // Ensure plain text + $button.find( '.screen-reader-text' ).text( btnText ); + + // Whitelist because of how the button is built. See above + $this.append( $button ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + $button.on( + 'click.wp-dismiss-notice', + function( event ) { + event.preventDefault(); + $this.fadeTo( + 100, + 0, + function() { + $( this ).slideUp( + 100, + function() { + $( this ).remove(); + } + ); + } + ); + } + ); + } + ); + break; + } + } + ); + } + ); + } + ); + + // act when pressing enter or esc in configurations + $( '.pll-configure' ).on( + 'keydown', + function( event ){ + if ( 'Enter' === event.key ) { + event.preventDefault(); + $( this ).find( '.save' ).trigger( 'click' ); + } + + if ( 'Escape' === event.key ) { + event.preventDefault(); + $( this ).find( '.cancel' ).trigger( 'click' ); + } + } + ); + + // settings URL modifications + // manages visibility of fields + $( "input[name='force_lang']" ).on( + 'change', + function() { + function pll_toggle( a, test ) { + test ? a.show() : a.hide(); + } + + var value = $( this ).val(); + pll_toggle( $( '#pll-domains-table' ), 3 == value ); + pll_toggle( $( "#pll-hide-default" ), 3 > value ); + pll_toggle( $( "#pll-rewrite" ), 2 > value ); + pll_toggle( $( "#pll-redirect-lang" ), 2 > value ); + } + ); + + // settings license + // deactivate button + $( '.pll-deactivate-license' ).on( + 'click', + function() { + var data = { + action: 'pll_deactivate_license', + pll_ajax_settings: true, + id: $( this ).attr( 'id' ), + _pll_nonce: $( '#_pll_nonce' ).val() + }; + $.post( + ajaxurl, + data, + function( response ){ + $( '#pll-license-' + response.id ).replaceWith( response.html ); + } + ); + } + ); + + // Manage closing the metabox. + // close postboxes that should be closed + $( '.if-js-closed' ).removeClass( 'if-js-closed' ).addClass( 'closed' ); + // postboxes setup + if ( 'undefined' !== typeof postboxes ) { + postboxes.add_postbox_toggles( pagenow ); + } + } +); + + diff --git a/wp-content/plugins/polylang/js/build/admin.min.js b/wp-content/plugins/polylang/js/build/admin.min.js new file mode 100644 index 00000000..8b33fa36 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/admin.min.js @@ -0,0 +1 @@ +var __webpack_exports__={};jQuery((function(e){var t;e("table.languages").on({focusin:function(){clearTimeout(t);var n=e(this).find(".row-actions");e(".row-actions").not(this).removeClass("visible"),n.addClass("visible")},focusout:function(){t=setTimeout((function(){focusedRowActions.removeClass("visible")}),30)}},"tr");var n=e.ui.version>="1.12.0",l=e("#flag_list").length,s=e("#lang_list").length,i=function(t,n){var l=e("
  • "),s=e("
    ");return n.disabled&&this._addClass(l,null,"ui-state-disabled"),this._setText(s,n.label),s.prepend(e(n.element).data("flag-html")),s.children("img").addClass("ui-icon"),l.append(s).appendTo(t)},a=function(t){var n=e(t).selectmenu("instance").buttonText;n.prepend(e(t).children(":selected").data("flag-html")),n.children("img").addClass("ui-icon")},c=function(t){var n=e("");return this._setText(n,t.label),this._addClass(n,"ui-selectmenu-text"),n.prepend(e(t.element).data("flag-html")),n.children("img").addClass("ui-icon"),n};function o(e,t){var l=e.selectmenu(t).selectmenu("instance");return l._renderItem=i,n&&(l._renderButtonItem=c,l.refresh()),l}var r={width:"95%",classes:{"ui-selectmenu-menu":"pll-selectmenu-menu","ui-selectmenu-button":"pll-selectmenu-button"}},u={},d=function(e,t){a(e.target)},p=function(t,n){a(e(t.target).selectmenu("refresh"))},g=function(t,n){e(t.target).selectmenu("refresh")};if(u=n?{change:g,open:g}:{create:d,select:d,change:p,open:p},l){var h=o(e("#flag_list"),Object.assign({},r,u));e("#lang_list").on("languageChanged",(function(e,t){h.element.val(t),h._trigger("change")}))}var f=function(t,n){var l=function(t){var n=e("option:selected",t.target),l=n.val().split(":");return{slug:l[0],locale:l[1],rtl:[l[2]],flag:l[3],name:n.text().split(" - ")[0]}}(t);!function(t){e("#lang_slug").val(t.slug),e("#lang_locale").val(t.locale),e('input[name="rtl"]').val(t.rtl),e("#lang_name").val(t.name)}(l),e(t.target).trigger("languageChanged",l.flag)},v={};e("#lang_list").closest(".pll-wizard-content").length>0&&(r=Object.assign(r,{width:"100%"})),v=n?{change:f}:{create:d,select:d,change:f},s&&o(e("#lang_list"),Object.assign({},r,v)),e(".translation input").on("keydown",(function(t){"Enter"===t.key&&(t.preventDefault(),e("#submit").trigger("click"))})),e("#the-list").on("click",".configure>a",(function(){return e(".pll-configure").hide().prev().show(),e(this).closest("tr").hide().next().show(),!1})),e("#the-list").on("click",".cancel",(function(){e(this).closest("tr").hide().prev().show()})),e("#the-list").on("click",".save",(function(){var t=e(this).closest("tr"),n=t.attr("id").split("-"),l={action:"pll_save_options",pll_ajax_settings:!0,module:n[n.length-1],_pll_nonce:e("#_pll_nonce").val()};l=t.find(":input").serialize()+"&"+e.param(l),e.post(ajaxurl,l,(function(n){var l=wpAjax.parseAjaxResponse(n,"ajax-response");e.each(l.responses,(function(){switch(this.what){case"license-update":e("#pll-license-"+this.data).replaceWith(this.supplemental.html);break;case"success":t.hide().prev().show();case"error":e(".settings-error").remove(),e("h1").after(this.data),e(".notice.is-dismissible").each((function(){var t=e(this),n=e(''),l=pll_admin.dismiss_notice||"";n.find(".screen-reader-text").text(l),t.append(n),n.on("click.wp-dismiss-notice",(function(n){n.preventDefault(),t.fadeTo(100,0,(function(){e(this).slideUp(100,(function(){e(this).remove()}))}))}))}))}}))}))})),e(".pll-configure").on("keydown",(function(t){"Enter"===t.key&&(t.preventDefault(),e(this).find(".save").trigger("click")),"Escape"===t.key&&(t.preventDefault(),e(this).find(".cancel").trigger("click"))})),e("input[name='force_lang']").on("change",(function(){function t(e,t){t?e.show():e.hide()}var n=e(this).val();t(e("#pll-domains-table"),3==n),t(e("#pll-hide-default"),3>n),t(e("#pll-rewrite"),2>n),t(e("#pll-redirect-lang"),2>n)})),e(".pll-deactivate-license").on("click",(function(){var t={action:"pll_deactivate_license",pll_ajax_settings:!0,id:e(this).attr("id"),_pll_nonce:e("#_pll_nonce").val()};e.post(ajaxurl,t,(function(t){e("#pll-license-"+t.id).replaceWith(t.html)}))})),e(".if-js-closed").removeClass("if-js-closed").addClass("closed"),"undefined"!=typeof postboxes&&postboxes.add_postbox_toggles(pagenow)})); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/build/block-editor.js b/wp-content/plugins/polylang/js/build/block-editor.js new file mode 100644 index 00000000..d122d42a --- /dev/null +++ b/wp-content/plugins/polylang/js/build/block-editor.js @@ -0,0 +1,355 @@ +/******/ "use strict"; +var __webpack_exports__ = {}; + +;// CONCATENATED MODULE: ./js/src/lib/confirmation-modal.js +/** + * @package Polylang + */ + +const languagesList = jQuery( '.post_lang_choice' ); + +// Dialog box for alerting the user about a risky changing. +const initializeConfimationModal = () => { + // We can't use underscore or lodash in this common code because it depends of the context classic or block editor. + // Classic editor underscore is loaded, Block editor lodash is loaded. + const { __ } = wp.i18n; + + // Create dialog container. + const dialogContainer = jQuery( + '
    ', + { + id: 'pll-dialog', + style: 'display:none;' + } + ).text( __( 'Are you sure you want to change the language of the current content?', 'polylang' ) ); + + // Put it after languages list dropdown. + // PHPCS ignore dialogContainer is a new safe HTML code generated above. + languagesList.after( dialogContainer ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after + + const dialogResult = new Promise( + ( confirm, cancel ) => { + const confirmDialog = ( what ) => { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + switch ( what ) { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + case 'yes': + // Confirm the new language. + languagesList.data( 'old-value', languagesList.children( ':selected' ).first().val() ); + confirm(); + break; + case 'no': + // Revert to the old language. + languagesList.val( languagesList.data( 'old-value' ) ); + cancel( 'Cancel' ); + break; + } + dialogContainer.dialog( 'close' ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + } // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + + // Initialize dialog box in the case a language is selected but not added in the list. + const dialogOptions = { + autoOpen: false, + modal: true, + draggable: false, + resizable: false, + title: __( 'Change language', 'polylang' ), + minWidth: 600, + maxWidth: '100%', + open: function( event, ui ) { + // Change dialog box position for rtl language + if ( jQuery( 'body' ).hasClass( 'rtl' ) ) { + jQuery( this ).parent().css( + { + right: jQuery( this ).parent().css( 'left' ), + left: 'auto' + } + ); + } + }, + close: function( event, ui ) { + // When we're closing the dialog box we need to cancel the language change as we click on Cancel button. + confirmDialog( 'no' ); + }, + buttons: [ + { + text: __( 'OK', 'polylang' ), + click: function( event ) { + confirmDialog( 'yes' ); + } + }, + { + text: __( 'Cancel', 'polylang' ), + click: function( event ) { + confirmDialog( 'no' ); + } + } + ] + }; + + if ( jQuery.ui.version >= '1.12.0' ) { + Object.assign( dialogOptions, { classes: { 'ui-dialog': 'pll-confirmation-modal' } } ); + } else { + Object.assign( dialogOptions, { dialogClass: 'pll-confirmation-modal' } ); // jQuery UI 1.11.4 - WP < 5.6 + } + + dialogContainer.dialog( dialogOptions ); + } + ); + return { dialogContainer, dialogResult }; +} + +const initializeLanguageOldValue = () => { + // Keep the old language value to be able to compare to the new one and revert to it if necessary. + languagesList.attr( 'data-old-value', languagesList.children( ':selected' ).first().val() ); +}; + +;// CONCATENATED MODULE: ./js/src/block-editor.js +/** + * @package Polylang + */ + + + +/** + * Filter REST API requests to add the language in the request + * + * @since 2.5 + */ +wp.apiFetch.use( + function( options, next ) { + // If options.url is defined, this is not a REST request but a direct call to post.php for legacy metaboxes. + if ( 'undefined' === typeof options.url ) { + if ( 'undefined' === typeof options.data || null === options.data ) { + // GET + options.path += ( ( options.path.indexOf( '?' ) >= 0 ) ? '&lang=' : '?lang=' ) + getCurrentLanguage(); + } else { + // PUT, POST + options.data.lang = getCurrentLanguage(); + } + } + return next( options ); + } +); + +/** + * Get the language from the HTML form + * + * @since 2.5 + * + * @return {Element.value} + */ +function getCurrentLanguage() { + return document.querySelector( '[name=post_lang_choice]' ).value; +} + +/** + * Handles internals of the metabox: + * Language select, autocomplete input field. + * + * @since 1.5 + * + * Save post after lang choice is done and redirect to the same page for refreshing all the data. + * + * @since 2.5 + * + * Link post saving after refreshing the metabox. + * + * @since 3.0 + */ +jQuery( + function( $ ) { + // Initialize current language to be able to compare if it changes. + initializeLanguageOldValue(); + + + // Ajax for changing the post's language in the languages metabox + $( '.post_lang_choice' ).on( + 'change', + function( event ) { + const select = wp.data.select; + const dispatch = wp.data.dispatch; + const subscribe = wp.data.subscribe; + const emptyPost = isEmptyPost(); + + // Initialize the confirmation dialog box. + const confirmationModal = initializeConfimationModal(); + const { dialogContainer : dialog } = confirmationModal; + let { dialogResult } = confirmationModal; + // The selected option in the dropdown list. + const selectedOption = event.target; + + // Specific case for empty posts. + // Place at the beginning because window.location changing triggers automatically page reloading. + if ( location.pathname.match( /post-new.php/gi ) && emptyPost ) { + reloadPageForEmptyPost( selectedOption.value ); + } + + // Otherwise send an ajax request to refresh the legacy metabox and set the post language with the new language. + // It needs a confirmation of the user before changing the language. + // Need to wait the ajax response before triggering the block editor post save action. + if ( $( this ).data( 'old-value' ) !== selectedOption.value && ! emptyPost ) { + dialog.dialog( 'open' ); + } else { + // Update the old language with the new one to be able to compare it in the next changing. + // Because the page isn't reloaded in this case. + initializeLanguageOldValue(); + dialogResult = Promise.resolve(); + } + + dialogResult.then( + () => { + var data = { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + action: 'post_lang_choice', + lang: selectedOption.value, + post_type: $( '#post_type' ).val(), + post_id: $( '#post_ID' ).val(), + _pll_nonce: $( '#_pll_nonce' ).val() + } + + $.post( + ajaxurl, + data, + function( response ) { + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); + $.each( + res.responses, + function() { + switch ( this.what ) { + case 'translations': // Translations fields + // Data is built and come from server side and is well escaped when necessary + $( '.translations' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + init_translations(); + break; + case 'flag': // Flag in front of the select dropdown + // Data is built and come from server side and is well escaped when necessary + $( '.pll-select-flag' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + break; + } + } + ); + blockEditorSavePostAndReloadPage(); + } + ); + }, + () => {} // Do nothing when promise is rejected by clicking the Cancel dialog button. + ); + + function isEmptyPost() { + const editor = wp.data.select( 'core/editor' ); + const title = editor.getEditedPostAttribute( 'title' ).trim(); + const content = editor.getEditedPostAttribute( 'content' ).trim(); + const excerpt = editor.getEditedPostAttribute( 'excerpt' ).trim(); + + return ! title && ! content && ! excerpt; + } + + /** + * Reload the block editor page for empty posts. + * + * @param {string} lang The target language code. + */ + function reloadPageForEmptyPost( lang ) { + // Change the new_lang parameter with the new language value for reloading the page + // WPCS location.search is never written in the page, just used to reload page with the right value of new_lang + // new_lang input is controlled server side in PHP. The value come from the dropdown list of language returned and escaped server side. + // Notice that window.location changing triggers automatically page reloading. + if ( -1 != location.search.indexOf( 'new_lang' ) ) { + // use regexp non capturing group to replace new_lang parameter no matter where it is and capture other parameters which can be behind it + window.location.search = window.location.search.replace( /(?:new_lang=[^&]*)(&)?(.*)/, 'new_lang=' + lang + '$1$2' ); // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment + } else { + window.location.search = window.location.search + ( ( -1 != window.location.search.indexOf( '?' ) ) ? '&' : '?' ) + 'new_lang=' + lang; // phpcs:ignore WordPressVIPMinimum.JS.Window.location, WordPressVIPMinimum.JS.Window.VarAssignment + } + }; + + /** + * Triggers block editor post save and reload the block editor page when everything is ok. + */ + function blockEditorSavePostAndReloadPage() { + + let unsubscribe = null; + + // Listen if the savePost is completely done by subscribing to its events. + const savePostIsDone = new Promise( + function( resolve, reject ) { + unsubscribe = subscribe( + function() { + const isSavePostSucceeded = select( 'core/editor' ).didPostSaveRequestSucceed(); + const isSavePostFailed = select( 'core/editor' ).didPostSaveRequestFail(); + if ( isSavePostSucceeded || isSavePostFailed ) { + if ( isSavePostFailed ) { + reject(); + } else { + resolve(); + } + } + } + ); + } + ); + + // Triggers the post save. + dispatch( 'core/editor' ).savePost(); + + // Process + savePostIsDone.then( + function() { + // If the post is well saved, we can reload the page + window.location.reload(); + }, + function() { + // If the post save failed + unsubscribe(); + } + ).catch( + function() { + // If an exception is thrown + unsubscribe(); + } + ); + }; + } + ); + + // Translations autocomplete input box + function init_translations() { + $( '.tr_lang' ).each( + function(){ + var tr_lang = $( this ).attr( 'id' ).substring( 8 ); + var td = $( this ).parent().parent().siblings( '.pll-edit-column' ); + + $( this ).autocomplete( + { + minLength: 0, + + source: ajaxurl + '?action=pll_posts_not_translated' + + '&post_language=' + $( '.post_lang_choice' ).val() + + '&translation_language=' + tr_lang + + '&post_type=' + $( '#post_type' ).val() + + '&_pll_nonce=' + $( '#_pll_nonce' ).val(), + + select: function( event, ui ) { + $( '#htr_lang_' + tr_lang ).val( ui.item.id ); + // ui.item.link is built and come from server side and is well escaped when necessary + td.html( ui.item.link ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + }, + } + ); + + // When the input box is emptied + $( this ).on( + 'blur', + function() { + if ( ! $( this ).val() ) { + $( '#htr_lang_' + tr_lang ).val( 0 ); + // Value is retrieved from HTML already generated server side + td.html( td.siblings( '.hidden' ).children().clone() ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + } + } + ); + } + ); + } + + init_translations(); + } +); + diff --git a/wp-content/plugins/polylang/js/build/block-editor.min.js b/wp-content/plugins/polylang/js/build/block-editor.min.js new file mode 100644 index 00000000..d5f23d66 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/block-editor.min.js @@ -0,0 +1 @@ +"use strict";var __webpack_exports__={};const languagesList=jQuery(".post_lang_choice"),initializeConfimationModal=()=>{const{__:t}=wp.i18n,a=jQuery("
    ",{id:"pll-dialog",style:"display:none;"}).text(t("Are you sure you want to change the language of the current content?","polylang"));languagesList.after(a);const e=new Promise(((e,n)=>{const l=t=>{switch(t){case"yes":languagesList.data("old-value",languagesList.children(":selected").first().val()),e();break;case"no":languagesList.val(languagesList.data("old-value")),n("Cancel")}a.dialog("close")},i={autoOpen:!1,modal:!0,draggable:!1,resizable:!1,title:t("Change language","polylang"),minWidth:600,maxWidth:"100%",open:function(t,a){jQuery("body").hasClass("rtl")&&jQuery(this).parent().css({right:jQuery(this).parent().css("left"),left:"auto"})},close:function(t,a){l("no")},buttons:[{text:t("OK","polylang"),click:function(t){l("yes")}},{text:t("Cancel","polylang"),click:function(t){l("no")}}]};jQuery.ui.version>="1.12.0"?Object.assign(i,{classes:{"ui-dialog":"pll-confirmation-modal"}}):Object.assign(i,{dialogClass:"pll-confirmation-modal"}),a.dialog(i)}));return{dialogContainer:a,dialogResult:e}},initializeLanguageOldValue=()=>{languagesList.attr("data-old-value",languagesList.children(":selected").first().val())};function getCurrentLanguage(){return document.querySelector("[name=post_lang_choice]").value}wp.apiFetch.use((function(t,a){return void 0===t.url&&(void 0===t.data||null===t.data?t.path+=(t.path.indexOf("?")>=0?"&lang=":"?lang=")+getCurrentLanguage():t.data.lang=getCurrentLanguage()),a(t)})),jQuery((function(t){function a(){t(".tr_lang").each((function(){var a=t(this).attr("id").substring(8),e=t(this).parent().parent().siblings(".pll-edit-column");t(this).autocomplete({minLength:0,source:ajaxurl+"?action=pll_posts_not_translated&post_language="+t(".post_lang_choice").val()+"&translation_language="+a+"&post_type="+t("#post_type").val()+"&_pll_nonce="+t("#_pll_nonce").val(),select:function(n,l){t("#htr_lang_"+a).val(l.item.id),e.html(l.item.link)}}),t(this).on("blur",(function(){t(this).val()||(t("#htr_lang_"+a).val(0),e.html(e.siblings(".hidden").children().clone()))}))}))}initializeLanguageOldValue(),t(".post_lang_choice").on("change",(function(e){const n=wp.data.select,l=wp.data.dispatch,i=wp.data.subscribe,o=function(){const t=wp.data.select("core/editor"),a=t.getEditedPostAttribute("title").trim(),e=t.getEditedPostAttribute("content").trim(),n=t.getEditedPostAttribute("excerpt").trim();return!a&&!e&&!n}(),s=initializeConfimationModal(),{dialogContainer:c}=s;let{dialogResult:r}=s;const u=e.target;var g;location.pathname.match(/post-new.php/gi)&&o&&(g=u.value,-1!=location.search.indexOf("new_lang")?window.location.search=window.location.search.replace(/(?:new_lang=[^&]*)(&)?(.*)/,"new_lang="+g+"$1$2"):window.location.search=window.location.search+(-1!=window.location.search.indexOf("?")?"&":"?")+"new_lang="+g),t(this).data("old-value")===u.value||o?(initializeLanguageOldValue(),r=Promise.resolve()):c.dialog("open"),r.then((()=>{var e={action:"post_lang_choice",lang:u.value,post_type:t("#post_type").val(),post_id:t("#post_ID").val(),_pll_nonce:t("#_pll_nonce").val()};t.post(ajaxurl,e,(function(e){var o=wpAjax.parseAjaxResponse(e,"ajax-response");t.each(o.responses,(function(){switch(this.what){case"translations":t(".translations").html(this.data),a();break;case"flag":t(".pll-select-flag").html(this.data)}})),function(){let t=null;const a=new Promise((function(a,e){t=i((function(){const t=n("core/editor").didPostSaveRequestSucceed(),l=n("core/editor").didPostSaveRequestFail();(t||l)&&(l?e():a())}))}));l("core/editor").savePost(),a.then((function(){window.location.reload()}),(function(){t()})).catch((function(){t()}))}()}))}),(()=>{}))})),a()})); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/build/classic-editor.js b/wp-content/plugins/polylang/js/build/classic-editor.js new file mode 100644 index 00000000..242e7270 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/classic-editor.js @@ -0,0 +1,444 @@ +/******/ "use strict"; +var __webpack_exports__ = {}; + +;// CONCATENATED MODULE: ./js/src/lib/confirmation-modal.js +/** + * @package Polylang + */ + +const languagesList = jQuery( '.post_lang_choice' ); + +// Dialog box for alerting the user about a risky changing. +const initializeConfimationModal = () => { + // We can't use underscore or lodash in this common code because it depends of the context classic or block editor. + // Classic editor underscore is loaded, Block editor lodash is loaded. + const { __ } = wp.i18n; + + // Create dialog container. + const dialogContainer = jQuery( + '
    ', + { + id: 'pll-dialog', + style: 'display:none;' + } + ).text( __( 'Are you sure you want to change the language of the current content?', 'polylang' ) ); + + // Put it after languages list dropdown. + // PHPCS ignore dialogContainer is a new safe HTML code generated above. + languagesList.after( dialogContainer ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after + + const dialogResult = new Promise( + ( confirm, cancel ) => { + const confirmDialog = ( what ) => { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + switch ( what ) { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + case 'yes': + // Confirm the new language. + languagesList.data( 'old-value', languagesList.children( ':selected' ).first().val() ); + confirm(); + break; + case 'no': + // Revert to the old language. + languagesList.val( languagesList.data( 'old-value' ) ); + cancel( 'Cancel' ); + break; + } + dialogContainer.dialog( 'close' ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + } // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + + // Initialize dialog box in the case a language is selected but not added in the list. + const dialogOptions = { + autoOpen: false, + modal: true, + draggable: false, + resizable: false, + title: __( 'Change language', 'polylang' ), + minWidth: 600, + maxWidth: '100%', + open: function( event, ui ) { + // Change dialog box position for rtl language + if ( jQuery( 'body' ).hasClass( 'rtl' ) ) { + jQuery( this ).parent().css( + { + right: jQuery( this ).parent().css( 'left' ), + left: 'auto' + } + ); + } + }, + close: function( event, ui ) { + // When we're closing the dialog box we need to cancel the language change as we click on Cancel button. + confirmDialog( 'no' ); + }, + buttons: [ + { + text: __( 'OK', 'polylang' ), + click: function( event ) { + confirmDialog( 'yes' ); + } + }, + { + text: __( 'Cancel', 'polylang' ), + click: function( event ) { + confirmDialog( 'no' ); + } + } + ] + }; + + if ( jQuery.ui.version >= '1.12.0' ) { + Object.assign( dialogOptions, { classes: { 'ui-dialog': 'pll-confirmation-modal' } } ); + } else { + Object.assign( dialogOptions, { dialogClass: 'pll-confirmation-modal' } ); // jQuery UI 1.11.4 - WP < 5.6 + } + + dialogContainer.dialog( dialogOptions ); + } + ); + return { dialogContainer, dialogResult }; +} + +const initializeLanguageOldValue = () => { + // Keep the old language value to be able to compare to the new one and revert to it if necessary. + languagesList.attr( 'data-old-value', languagesList.children( ':selected' ).first().val() ); +}; + +;// CONCATENATED MODULE: ./js/src/classic-editor.js +/** + * @package Polylang + */ + + + +// tag suggest in metabox +jQuery( + function( $ ) { + $.ajaxPrefilter( + function( options, originalOptions, jqXHR ) { + var lang = $( '.post_lang_choice' ).val(); + if ( 'string' === typeof options.data && -1 !== options.url.indexOf( 'action=ajax-tag-search' ) && lang ) { + options.data = 'lang=' + lang + '&' + options.data; + } + } + ); + } +); + +// overrides tagBox.get +jQuery( + function( $ ) { + // overrides function to add the language + tagBox.get = function( id ) { + var tax = id.substr( id.indexOf( '-' ) + 1 ); + + // add the language in the $_POST variable + var data = { + action: 'get-tagcloud', + lang: $( '.post_lang_choice' ).val(), + tax: tax + } + + $.post( + ajaxurl, + data, + function( r, stat ) { + if ( 0 == r || 'success' != stat ) { + r = wpAjax.broken; + } + + // @see code from WordPress core https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/js/tags-box.js#L291 + // @see wp_generate_tag_cloud function which generate the escaped HTML https://github.com/WordPress/WordPress/blob/a02b5cc2a8eecb8e076fbb7cf4de7bd2ec8a8eb1/wp-includes/category-template.php#L966-L975 + r = $( '
    ' ).addClass( 'the-tagcloud' ).attr( 'id', 'tagcloud-' + tax ).html( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + $( 'a', r ).on( + 'click', + function(){ + tagBox.flushTags( $( this ).closest( '.inside' ).children( '.tagsdiv' ), this ); + return false; + } + ); + + var tagCloud = $( '#tagcloud-' + tax ); + // add an if else condition to allow modifying the tags outputed when switching the language + var v = tagCloud.css( 'display' ); + if ( v ) { + // See the comment above when r variable is created. + $( '#tagcloud-' + tax ).replaceWith( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith + $( '#tagcloud-' + tax ).css( 'display', v ); + } + else { + // See the comment above when r variable is created. + $( '#' + id ).after( r ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.after + } + } + ); + } + } +); + +jQuery( + function( $ ) { + // collect taxonomies - code partly copied from WordPress + var taxonomies = new Array(); + $( '.categorydiv' ).each( + function(){ + var this_id = $( this ).attr( 'id' ), taxonomyParts, taxonomy; + + taxonomyParts = this_id.split( '-' ); + taxonomyParts.shift(); + taxonomy = taxonomyParts.join( '-' ); + taxonomies.push( taxonomy ); // store the taxonomy for future use + + // add our hidden field in the new category form - for each hierarchical taxonomy + // to set the language when creating a new category + // html code inserted come from html code itself. + $( '#' + taxonomy + '-add-submit' ).before( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.before + $( '' ).attr( 'type', 'hidden' ) + .attr( 'id', taxonomy + '-lang' ) + .attr( 'name', 'term_lang_choice' ) + .attr( 'value', $( '.post_lang_choice' ).val() ) + ); + } + ); + + // Initialize current language to be able to compare if it changes. + initializeLanguageOldValue(); + + // ajax for changing the post's language in the languages metabox + $( '.post_lang_choice' ).on( + 'change', + function( event ) { + // Initialize the confirmation dialog box. + const confirmationModal = initializeConfimationModal(); + const { dialogContainer: dialog } = confirmationModal; + let { dialogResult } = confirmationModal; + // The selected option in the dropdown list. + const selectedOption = event.target; + + if ( $( this ).data( 'old-value' ) !== selectedOption.value && ! isEmptyPost() ) { + dialog.dialog( 'open' ); + } else { + dialogResult = Promise.resolve(); + } + + // phpcs:disable PEAR.Functions.FunctionCallSignature.EmptyLine + dialogResult.then( + () => { + var lang = selectedOption.options[selectedOption.options.selectedIndex].lang; // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' ); // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + + var data = { // phpcs:ignore PEAR.Functions.FunctionCallSignature.Indent + action: 'post_lang_choice', + lang: selectedOption.value, + post_type: $( '#post_type' ).val(), + taxonomies: taxonomies, + post_id: $( '#post_ID' ).val(), + _pll_nonce: $( '#_pll_nonce' ).val() + } + + $.post( + ajaxurl, + data, + function( response ) { + var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); + $.each( + res.responses, + function() { + switch ( this.what ) { + case 'translations': // translations fields + // Data is built and come from server side and is well escaped when necessary + $( '.translations' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + init_translations(); + break; + case 'taxonomy': // categories metabox for posts + var tax = this.data; + // @see wp_terms_checklist https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/template.php#L175 + // @see https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/class-walker-category-checklist.php#L89-L111 + $( '#' + tax + 'checklist' ).html( this.supplemental.all ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + // @see wp_popular_terms_checklist https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/template.php#L236 + $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + // @see wp_dropdown_categories https://github.com/WordPress/WordPress/blob/5.5.1/wp-includes/category-template.php#L336 + // which is called by PLL_Admin_Classic_Editor::post_lang_choice to generate supplemental.dropdown + $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.replaceWith + $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field + break; + case 'pages': // parent dropdown list for pages + // @see wp_dropdown_pages https://github.com/WordPress/WordPress/blob/5.2.2/wp-includes/post-template.php#L1186-L1208 + // @see https://github.com/WordPress/WordPress/blob/5.2.2/wp-includes/class-walker-page-dropdown.php#L88 + $( '#parent_id' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + break; + case 'flag': // flag in front of the select dropdown + // Data is built and come from server side and is well escaped when necessary + $( '.pll-select-flag' ).html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + break; + case 'permalink': // Sample permalink + var div = $( '#edit-slug-box' ); + if ( '-1' != this.data && div.children().length ) { + // @see get_sample_permalink_html https://github.com/WordPress/WordPress/blob/5.2.2/wp-admin/includes/post.php#L1425-L1454 + div.html( this.data ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + } + break; + } + } + ); + + // Update the old language with the new one to be able to compare it in the next changing. + initializeLanguageOldValue(); + // modifies the language in the tag cloud + $( '.tagcloud-link' ).each( + function() { + var id = $( this ).attr( 'id' ); + tagBox.get( id ); + } + ); + + // Modifies the text direction + $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir ); + $( '#content_ifr' ).contents().find( 'html' ).attr( 'lang', lang ).attr( 'dir', dir ); + $( '#content_ifr' ).contents().find( 'body' ).attr( 'dir', dir ); + + pll.media.resetAllAttachmentsCollections(); + } + ) + }, + () => {} // Do nothing when promise is rejected by clicking the Cancel dialog button. + ); + // phpcs:enable PEAR.Functions.FunctionCallSignature.EmptyLine + + function isEmptyPost() { + const title = $( 'input#title' ).val(); + const content = $( 'textarea#content' ).val(); + const excerpt = $( 'textarea#excerpt' ).val(); + + return ! title && ! content && ! excerpt; + } + } + ); + + // translations autocomplete input box + function init_translations() { + $( '.tr_lang' ).each( + function(){ + var tr_lang = $( this ).attr( 'id' ).substring( 8 ); + var td = $( this ).parent().parent().siblings( '.pll-edit-column' ); + + $( this ).autocomplete( + { + minLength: 0, + source: ajaxurl + '?action=pll_posts_not_translated' + + '&post_language=' + $( '.post_lang_choice' ).val() + + '&translation_language=' + tr_lang + + '&post_type=' + $( '#post_type' ).val() + + '&_pll_nonce=' + $( '#_pll_nonce' ).val(), + select: function( event, ui ) { + $( '#htr_lang_' + tr_lang ).val( ui.item.id ); + // ui.item.link is built and come from server side and is well escaped when necessary + td.html( ui.item.link ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + }, + } + ); + + // when the input box is emptied + $( this ).on( + 'blur', + function() { + if ( ! $( this ).val() ) { + $( '#htr_lang_' + tr_lang ).val( 0 ); + // Value is retrieved from HTML already generated server side + td.html( td.siblings( '.hidden' ).children().clone() ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + } + } + ); + } + ); + } + + init_translations(); + } +); + +/** + * @since 3.0 + * + * @namespace pll + */ +var pll = window.pll || {}; + +/** + * @since 3.0 + * + * @namespace pll.media + */ +_.extend( pll, { media: {} } ); + +/** + * @since 3.0 + * + * @alias pll.media + * @memberOf pll + * @namespace + */ +var media = _.extend( + pll.media, /** @lends pll.media.prototype */ + { + /** + * TODO: Find a way to delete references to Attachments collections that are not used anywhere else. + * + * @type {wp.media.model.Attachments} + */ + attachmentsCollections : [], + + /** + * Imitates { @see wp.media.query } but log all Attachments collections created. + * + * @param {Object} [props] + * @return {wp.media.model.Attachments} + */ + query: function( props ) { + var attachments = pll.media.query.delegate( props ); + + pll.media.attachmentsCollections.push( attachments ); + + return attachments; + }, + + resetAllAttachmentsCollections: function() { + this.attachmentsCollections.forEach( + function( attachmentsCollection ) { + /** + * First reset the { @see wp.media.model.Attachments } collection. + * Then, if it is mirroring a { @see wp.media.model.Query } collection, + * refresh this one too, so it will fetch new data from the server, + * and then the wp.media.model.Attachments collection will syncrhonize with the new data. + */ + attachmentsCollection.reset(); + if (attachmentsCollection.mirroring) { + attachmentsCollection.mirroring._hasMore = true; + attachmentsCollection.mirroring.reset(); + } + } + ); + } + } +); + +if ( 'undefined' !== typeof wp && 'undefined' !== typeof wp.media ) { + + /** + * @since 3.0 + * + * @memberOf pll.media + */ + media.query = _.extend( + media.query, /** @lends pll.media.query prototype */ + { + /** + * @type Function References WordPress { @see wp.media.query } constructor + */ + delegate: wp.media.query + } + ) + + // Substitute WordPress media query shortcut with our decorated function. + wp.media.query = media.query + +} + diff --git a/wp-content/plugins/polylang/js/build/classic-editor.min.js b/wp-content/plugins/polylang/js/build/classic-editor.min.js new file mode 100644 index 00000000..ee7beeff --- /dev/null +++ b/wp-content/plugins/polylang/js/build/classic-editor.min.js @@ -0,0 +1 @@ +"use strict";var __webpack_exports__={};const languagesList=jQuery(".post_lang_choice"),initializeConfimationModal=()=>{const{__:t}=wp.i18n,a=jQuery("
    ",{id:"pll-dialog",style:"display:none;"}).text(t("Are you sure you want to change the language of the current content?","polylang"));languagesList.after(a);const e=new Promise(((e,l)=>{const n=t=>{switch(t){case"yes":languagesList.data("old-value",languagesList.children(":selected").first().val()),e();break;case"no":languagesList.val(languagesList.data("old-value")),l("Cancel")}a.dialog("close")},i={autoOpen:!1,modal:!0,draggable:!1,resizable:!1,title:t("Change language","polylang"),minWidth:600,maxWidth:"100%",open:function(t,a){jQuery("body").hasClass("rtl")&&jQuery(this).parent().css({right:jQuery(this).parent().css("left"),left:"auto"})},close:function(t,a){n("no")},buttons:[{text:t("OK","polylang"),click:function(t){n("yes")}},{text:t("Cancel","polylang"),click:function(t){n("no")}}]};jQuery.ui.version>="1.12.0"?Object.assign(i,{classes:{"ui-dialog":"pll-confirmation-modal"}}):Object.assign(i,{dialogClass:"pll-confirmation-modal"}),a.dialog(i)}));return{dialogContainer:a,dialogResult:e}},initializeLanguageOldValue=()=>{languagesList.attr("data-old-value",languagesList.children(":selected").first().val())};jQuery((function(t){t.ajaxPrefilter((function(a,e,l){var n=t(".post_lang_choice").val();"string"==typeof a.data&&-1!==a.url.indexOf("action=ajax-tag-search")&&n&&(a.data="lang="+n+"&"+a.data)}))})),jQuery((function(t){tagBox.get=function(a){var e=a.substr(a.indexOf("-")+1),l={action:"get-tagcloud",lang:t(".post_lang_choice").val(),tax:e};t.post(ajaxurl,l,(function(l,n){0!=l&&"success"==n||(l=wpAjax.broken),l=t("
    ").addClass("the-tagcloud").attr("id","tagcloud-"+e).html(l),t("a",l).on("click",(function(){return tagBox.flushTags(t(this).closest(".inside").children(".tagsdiv"),this),!1}));var i=t("#tagcloud-"+e).css("display");i?(t("#tagcloud-"+e).replaceWith(l),t("#tagcloud-"+e).css("display",i)):t("#"+a).after(l)}))}})),jQuery((function(t){var a=new Array;function e(){t(".tr_lang").each((function(){var a=t(this).attr("id").substring(8),e=t(this).parent().parent().siblings(".pll-edit-column");t(this).autocomplete({minLength:0,source:ajaxurl+"?action=pll_posts_not_translated&post_language="+t(".post_lang_choice").val()+"&translation_language="+a+"&post_type="+t("#post_type").val()+"&_pll_nonce="+t("#_pll_nonce").val(),select:function(l,n){t("#htr_lang_"+a).val(n.item.id),e.html(n.item.link)}}),t(this).on("blur",(function(){t(this).val()||(t("#htr_lang_"+a).val(0),e.html(e.siblings(".hidden").children().clone()))}))}))}t(".categorydiv").each((function(){var e,l;(e=t(this).attr("id").split("-")).shift(),l=e.join("-"),a.push(l),t("#"+l+"-add-submit").before(t("").attr("type","hidden").attr("id",l+"-lang").attr("name","term_lang_choice").attr("value",t(".post_lang_choice").val()))})),initializeLanguageOldValue(),t(".post_lang_choice").on("change",(function(l){const n=initializeConfimationModal(),{dialogContainer:i}=n;let{dialogResult:s}=n;const o=l.target;t(this).data("old-value")===o.value||function(){const a=t("input#title").val(),e=t("textarea#content").val(),l=t("textarea#excerpt").val();return!a&&!e&&!l}()?s=Promise.resolve():i.dialog("open"),s.then((()=>{var l=o.options[o.options.selectedIndex].lang,n=t('.pll-translation-column > span[lang="'+l+'"]').attr("dir"),i={action:"post_lang_choice",lang:o.value,post_type:t("#post_type").val(),taxonomies:a,post_id:t("#post_ID").val(),_pll_nonce:t("#_pll_nonce").val()};t.post(ajaxurl,i,(function(a){var i=wpAjax.parseAjaxResponse(a,"ajax-response");t.each(i.responses,(function(){switch(this.what){case"translations":t(".translations").html(this.data),e();break;case"taxonomy":var a=this.data;t("#"+a+"checklist").html(this.supplemental.all),t("#"+a+"checklist-pop").html(this.supplemental.populars),t("#new"+a+"_parent").replaceWith(this.supplemental.dropdown),t("#"+a+"-lang").val(t(".post_lang_choice").val());break;case"pages":t("#parent_id").html(this.data);break;case"flag":t(".pll-select-flag").html(this.data);break;case"permalink":var l=t("#edit-slug-box");"-1"!=this.data&&l.children().length&&l.html(this.data)}})),initializeLanguageOldValue(),t(".tagcloud-link").each((function(){var a=t(this).attr("id");tagBox.get(a)})),t("body").removeClass("pll-dir-rtl").removeClass("pll-dir-ltr").addClass("pll-dir-"+n),t("#content_ifr").contents().find("html").attr("lang",l).attr("dir",n),t("#content_ifr").contents().find("body").attr("dir",n),pll.media.resetAllAttachmentsCollections()}))}),(()=>{}))})),e()}));var pll=window.pll||{};_.extend(pll,{media:{}});var media=_.extend(pll.media,{attachmentsCollections:[],query:function(t){var a=pll.media.query.delegate(t);return pll.media.attachmentsCollections.push(a),a},resetAllAttachmentsCollections:function(){this.attachmentsCollections.forEach((function(t){t.reset(),t.mirroring&&(t.mirroring._hasMore=!0,t.mirroring.reset())}))}});"undefined"!=typeof wp&&void 0!==wp.media&&(media.query=_.extend(media.query,{delegate:wp.media.query}),wp.media.query=media.query); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/build/languages-step.js b/wp-content/plugins/polylang/js/build/languages-step.js new file mode 100644 index 00000000..3f24a89e --- /dev/null +++ b/wp-content/plugins/polylang/js/build/languages-step.js @@ -0,0 +1,304 @@ +var __webpack_exports__ = {}; +/** + * @package Polylang + */ + +jQuery( + function( $ ) { + var addLanguageForm = $( '.languages-step' ); // Form element. + var languageFields = $( '#language-fields' ); // Element where to append hidden fields for creating language. + var languagesTable = $( '#languages' ); // Table element contains languages list to create. + var languagesListTable = $( '#languages tbody' ); // Table rows with languages list to create. + var definedLanguagesListTable = $( '#defined-languages tbody' ); // Table rows with already defined languages list. + var languagesList = $( '#lang_list' ); // Select form element with predefined languages without already created languages. + var nextStepButton = $( '[name="save_step"]' ); // The button for continuing to the next step. + var messagesContainer = $( '#messages' ); // Element where to display error messages. + var languagesMap = new Map(); // Languages map object for managing the languages to create. + var dialog = $( '#dialog' ); // Dialog box for alerting the language selected has not been added to the list. + + /** + * Add a language in the list to create it in Polylang settings + * + * @param {object} language The language object + */ + function addLanguage( language ) { + // language properties come from the select dropdown which is built server side and well escaped. + // see template view-wizard-step-languages.php. + var languageValueHtml = $( '' ).text( language.text ).prepend( language.flagUrl ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + var languageTrashIconHtml = $( '' ) + .append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ) + .addClass( 'dashicons dashicons-trash' ) + .attr( 'data-language', language.locale ) + .append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ) + .addClass( 'screen-reader-text' ) + .text( pll_wizard_params.i18n_remove_language_icon ) + ) + ); + // see the comment and the harcoded code above. languageTrashIconHtml and languageValueHtml are safe. + var languageLineHtml = $( '' ).prepend( languageTrashIconHtml ).prepend( languageValueHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + var languageFieldHtml = $( '' ).attr( + { + type: 'hidden', + name: 'languages[]' + } + ).val( language.locale ); + + languagesList.val( '' ); + languagesList.selectmenu( 'refresh' ); // Refresh jQuery selectmenu widget after changing the value. + + languagesMap.set( language.locale, language ); + + // see above how languageLineHtml is built. + languagesListTable.append( languageLineHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + // Bind click event on trash icon. + languagesListTable.on( + 'click', + 'span[data-language=' + language.locale + ']', + function( event ) { + event.preventDefault(); + // Remove line in languages table. + $( this ).parents( 'tr' ).remove(); + // Remove input field. + var languageField = languageFields.children( 'input[value=' + $( this ).data( 'language' ) + ']' ).remove(); + // If there is no more languages hide languages table. + if ( languagesListTable.children().length <= 0 ) { + languagesTable.hide(); + } + // Remove language from the Map. + languagesMap.delete( $( this ).data( 'language' ) ); + // Hide error message. + hideError(); + } + ); + // see above how languageFieldHtml is built. + // Add hidden input field for posting the form. + languageFields.append( languageFieldHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + } + + /** + * Display an error message + * + * @param {string} message The message to display + */ + function showError( message ) { + messagesContainer.empty(); + // html is harcoded and use of jQuery text method which is safe to add message value. + // In addition message is i18n value which is initialized server side in PLL_Wizard::add_step_languages and correctly escaped. + messagesContainer.prepend( $( '

    ' ).addClass( 'error' ).text( message ) ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + } + + /** + * Hide all error messages and fields in error + */ + function hideError() { + messagesContainer.empty(); + addLanguageForm.find( '.error' ).removeClass( 'error field-in-error' ); + } + + /** + * Style the field to indicate where the error is + * + * @param {object} field The jQuery element which is in error + */ + function showFieldInError( field ) { + field.addClass( 'error field-in-error' ); + } + + /** + * Focus on a specific element + * + * @param {object} field The jQuery element which will be focused + */ + function focusOnField( field ) { + field.trigger( 'focus' ); + } + + /** + * Disable a specific button + * + * @param {object} button + */ + function disableButton( button ){ + button.prop( 'disabled', true ); + // Because the button is disabled we need to add the value of the button to ensure it will pass in the request. + addLanguageForm.append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ).prop( + { + type: 'hidden', + name: button.prop( 'name' ), + value: button.prop( 'value' ) + } + ) + ); + } + + /** + * Remove error when a new selection is done in languages list. + */ + languagesList.on( + 'selectmenuchange', + function() { + hideError();; + } + ); + /** + * Bind click event on "Add language" button + */ + $( '#add-language' ).on( + 'click', + function( event ) { + hideError(); + var selectedOption = event.currentTarget.form.lang_list.options[event.currentTarget.form.lang_list.selectedIndex]; + if ( '' !== selectedOption.value && ! languagesMap.has( selectedOption.value ) ) { + addLanguage( + { + locale: selectedOption.value, + text: selectedOption.innerText, + name: $( selectedOption ).data( 'language-name' ), + flagUrl: $( selectedOption ).data( 'flag-html' ) + } + ); + // Show table of languages. + languagesTable.show(); + // Put back the focus on the select language field after clicking on "Add language button". + focusOnField( $( '#lang_list-button' ) ); + } else { + var message = pll_wizard_params.i18n_no_language_selected; + if ( languagesMap.has( selectedOption.value ) ) { + message = pll_wizard_params.i18n_language_already_added; + } + showError( message ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + + } + } + ); + + /** + * Bind submit event on "add_lang" form + */ + addLanguageForm.on( + 'submit', + function( event ) { + // Verify if there is at least one language. + var isLanguagesAlreadyDefined = definedLanguagesListTable.children().length > 0; + var selectedLanguage = $( '#lang_list' ).val(); + if ( languagesMap.size <= 0 && ! isLanguagesAlreadyDefined ) { + if ( '' === selectedLanguage ) { + showError( pll_wizard_params.i18n_no_language_added ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + } else { + showError( pll_wizard_params.i18n_add_language_needed ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#add-language' ) ); // Put the focus on the "Add language" button. + } + return false; + } + // Verify if the language has been added in the list otherwise display a dialog box to confirm what to do. + if ( '' !== selectedLanguage ) { + // Verify we don't add a duplicate language before opening the dialog box otherwise display an error message. + if ( ! languagesMap.has( selectedLanguage ) ) { + dialog.dialog( 'open' ); + } else { + showError( pll_wizard_params.i18n_language_already_added ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + } + return false; + } + disableButton( nextStepButton ); + } + ); + + // Is there an error return by PHP ? + var searchParams = new URLSearchParams( document.location.search ); + if ( searchParams.has( 'activate_error' ) ) { + // If the error code exists, display it. + if ( undefined !== pll_wizard_params[ searchParams.get( 'activate_error' ) ] ) { + showError( pll_wizard_params[ searchParams.get( 'activate_error' ) ] ); + } + } + + function confirmDialog( what ) { + switch ( what ) { + case 'yes': + var selectedOption = $( '#lang_list' ).children( ':selected' ); + addLanguage( + { + locale: selectedOption[0].value, + text: selectedOption[0].innerText, + name: $( selectedOption ).data( 'language-name' ), + flagUrl: $( selectedOption ).data( 'flag-html' ) + } + ); + break; + case 'no': + // Empty select form field and submit again the form. + languagesList.val( '' ); + break; + case 'ignore': + } + dialog.dialog( 'close' ); + if ( 'ignore' === what ) { + focusOnField( $( '#lang_list-button' ) ); + } else { + addLanguageForm.submit(); + } + } + + // Initialize dialog box in the case a language is selected but not added in the list. + dialog.dialog( + { + autoOpen: false, + modal: true, + draggable: false, + resizable: false, + title: pll_wizard_params.i18n_dialog_title, + minWidth: 600, + maxWidth: '100%', + open: function( event, ui ) { + // Change dialog box position for rtl language + if ( $( 'body' ).hasClass( 'rtl' ) ) { + $( this ).parent().css( + { + right: $( this ).parent().css( 'left' ), + left: 'auto' + } + ); + } + // Display language name and flag information in dialog box. + $( this ).find( '#dialog-language' ).text( $( '#lang_list' ).children( ':selected' ).first().text() ); + // language properties come from the select dropdown #lang_list which is built server side and well escaped. + // see template view-wizard-step-languages.php. + $( this ).find( '#dialog-language-flag' ).empty().prepend( $( '#lang_list' ).children( ':selected' ).data( 'flag-html' ) ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + }, + buttons: [ + { + text: pll_wizard_params.i18n_dialog_yes_button, + click: function( event ) { + confirmDialog( 'yes' ); + } + }, + { + text: pll_wizard_params.i18n_dialog_no_button, + click: function( event ) { + confirmDialog( 'no' ); + } + }, + { + text: pll_wizard_params.i18n_dialog_ignore_button, + click: function( event ) { + confirmDialog( 'ignore' ); + } + } + ] + } + ) + } +); + diff --git a/wp-content/plugins/polylang/js/build/languages-step.min.js b/wp-content/plugins/polylang/js/build/languages-step.min.js new file mode 100644 index 00000000..81bcb6c1 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/languages-step.min.js @@ -0,0 +1 @@ +var __webpack_exports__={};jQuery((function(a){var e=a(".languages-step"),n=a("#language-fields"),t=a("#languages"),l=a("#languages tbody"),i=a("#defined-languages tbody"),r=a("#lang_list"),s=a('[name="save_step"]'),d=a("#messages"),o=new Map,g=a("#dialog");function u(e){var i=a("").text(e.text).prepend(e.flagUrl),s=a("").append(a("").addClass("dashicons dashicons-trash").attr("data-language",e.locale).append(a("").addClass("screen-reader-text").text(pll_wizard_params.i18n_remove_language_icon))),d=a("").prepend(s).prepend(i),g=a("").attr({type:"hidden",name:"languages[]"}).val(e.locale);r.val(""),r.selectmenu("refresh"),o.set(e.locale,e),l.append(d),l.on("click","span[data-language="+e.locale+"]",(function(e){e.preventDefault(),a(this).parents("tr").remove();n.children("input[value="+a(this).data("language")+"]").remove();l.children().length<=0&&t.hide(),o.delete(a(this).data("language")),_()})),n.append(g)}function p(e){d.empty(),d.prepend(a("

    ").addClass("error").text(e))}function _(){d.empty(),e.find(".error").removeClass("error field-in-error")}function c(a){a.addClass("error field-in-error")}function m(a){a.trigger("focus")}r.on("selectmenuchange",(function(){_()})),a("#add-language").on("click",(function(e){_();var n=e.currentTarget.form.lang_list.options[e.currentTarget.form.lang_list.selectedIndex];if(""===n.value||o.has(n.value)){var l=pll_wizard_params.i18n_no_language_selected;o.has(n.value)&&(l=pll_wizard_params.i18n_language_already_added),p(l),c(r.next("span.ui-selectmenu-button")),m(a("#lang_list-button"))}else u({locale:n.value,text:n.innerText,name:a(n).data("language-name"),flagUrl:a(n).data("flag-html")}),t.show(),m(a("#lang_list-button"))})),e.on("submit",(function(n){var t,l=i.children().length>0,d=a("#lang_list").val();return o.size<=0&&!l?(""===d?(p(pll_wizard_params.i18n_no_language_added),c(r.next("span.ui-selectmenu-button")),m(a("#lang_list-button"))):(p(pll_wizard_params.i18n_add_language_needed),c(r.next("span.ui-selectmenu-button")),m(a("#add-language"))),!1):""!==d?(o.has(d)?(p(pll_wizard_params.i18n_language_already_added),c(r.next("span.ui-selectmenu-button")),m(a("#lang_list-button"))):g.dialog("open"),!1):((t=s).prop("disabled",!0),void e.append(a("").prop({type:"hidden",name:t.prop("name"),value:t.prop("value")})))}));var f=new URLSearchParams(document.location.search);function h(n){switch(n){case"yes":var t=a("#lang_list").children(":selected");u({locale:t[0].value,text:t[0].innerText,name:a(t).data("language-name"),flagUrl:a(t).data("flag-html")});break;case"no":r.val("")}g.dialog("close"),"ignore"===n?m(a("#lang_list-button")):e.submit()}f.has("activate_error")&&void 0!==pll_wizard_params[f.get("activate_error")]&&p(pll_wizard_params[f.get("activate_error")]),g.dialog({autoOpen:!1,modal:!0,draggable:!1,resizable:!1,title:pll_wizard_params.i18n_dialog_title,minWidth:600,maxWidth:"100%",open:function(e,n){a("body").hasClass("rtl")&&a(this).parent().css({right:a(this).parent().css("left"),left:"auto"}),a(this).find("#dialog-language").text(a("#lang_list").children(":selected").first().text()),a(this).find("#dialog-language-flag").empty().prepend(a("#lang_list").children(":selected").data("flag-html"))},buttons:[{text:pll_wizard_params.i18n_dialog_yes_button,click:function(a){h("yes")}},{text:pll_wizard_params.i18n_dialog_no_button,click:function(a){h("no")}},{text:pll_wizard_params.i18n_dialog_ignore_button,click:function(a){h("ignore")}}]})})); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/build/nav-menu.js b/wp-content/plugins/polylang/js/build/nav-menu.js new file mode 100644 index 00000000..f7e9d70d --- /dev/null +++ b/wp-content/plugins/polylang/js/build/nav-menu.js @@ -0,0 +1,106 @@ +var __webpack_exports__ = {}; +/** + * Handles the options in the language switcher nav menu metabox. + * + * @package Polylang + */ + +jQuery( + function( $ ) { + $( '#update-nav-menu' ).on( + 'click', + function( e ) { + if ( e.target && e.target.className && -1 != e.target.className.indexOf( 'item-edit' ) ) { + $( "input[value='#pll_switcher'][type=text]" ).parent().parent().parent().each( + function(){ + var item = $( this ).attr( 'id' ).substring( 19 ); + $( this ).children( 'p:not( .field-move )' ).remove(); // remove default fields we don't need + + // item is a number part of id of parent menu item built by WordPress + // pll_data is built server side with i18n strings without HTML and data retrieved from post meta + // the usage of attr method is safe before append call. + h = $( '' ).attr( + { + type: 'hidden', + id: 'edit-menu-item-title-' + item, + name: 'menu-item-title[' + item + ']', + value: pll_data.title + } + ); + $( this ).append( h ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + h = $( '' ).attr( + { + type: 'hidden', + id: 'edit-menu-item-url-' + item, + name: 'menu-item-url[' + item + ']', + value: '#pll_switcher' + } + ); + $( this ).append( h ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + // a hidden field which exits only if our jQuery code has been executed + h = $( '' ).attr( + { + type: 'hidden', + id: 'edit-menu-item-pll-detect-' + item, + name: 'menu-item-pll-detect[' + item + ']', + value: 1 + } + ); + $( this ).append( h ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + ids = Array( 'hide_if_no_translation', 'hide_current', 'force_home', 'show_flags', 'show_names', 'dropdown' ); // reverse order + + // add the fields + for ( var i = 0, idsLength = ids.length; i < idsLength; i++ ) { + p = $( '

    ' ).attr( 'class', 'description' ); + // p is hardcoded just above by using attr method which is safe. + $( this ).prepend( p ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + // item is a number part of id of parent menu item built by WordPress + // pll_data is built server side with i18n strings without HTML + label = $( '

    ' ).text( lang[1] ) ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + td.append( desc ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + } + ); + + td.append( '
    ' ); + // Whitelist because description come from html code generated by WordPress + td.append( span ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + } +); + diff --git a/wp-content/plugins/polylang/js/build/user.min.js b/wp-content/plugins/polylang/js/build/user.min.js new file mode 100644 index 00000000..a6e6b3fb --- /dev/null +++ b/wp-content/plugins/polylang/js/build/user.min.js @@ -0,0 +1 @@ +var __webpack_exports__={};jQuery((function(e){var n=e("#description").parent(),i=e("#description").clone(),t=n.children(".description").clone();n.children().remove(),e(".biography").each((function(){lang=e(this).attr("name").split("___"),desc=i.clone(),desc.attr("name","description_"+lang[0]),desc.attr("id","description_"+lang[0]),desc.html(e(this).val()),n.append(e("
    ").text(lang[1])),n.append(desc)})),n.append("
    "),n.append(t)})); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/build/widgets.js b/wp-content/plugins/polylang/js/build/widgets.js new file mode 100644 index 00000000..54888911 --- /dev/null +++ b/wp-content/plugins/polylang/js/build/widgets.js @@ -0,0 +1,153 @@ +var __webpack_exports__ = {}; +/** + * Adds a flag to the widgets filtered by a language. + * + * @package Polylang + */ + +jQuery( + function( $ ) { + var widgets_container, + widgets_selector, + flags, + isBlockEditor = 'undefined' !== typeof wp.blockEditor; + + if ( 'undefined' !== typeof pll_widgets && pll_widgets.hasOwnProperty( 'flags' ) ) { + flags = pll_widgets.flags; + } + + /** + * Prepend widget titles with a flag once a language is selected. + * + * @param {object} widget The widget element. + * @return {void} Nothing. + */ + function add_flag( widget ) { + if ( ! flags ) { + return; + } + widget = $( widget ); + var title = isBlockEditor ? widget.prev('h3') : $( '.widget-top .widget-title h3', widget ), + locale = $( '.pll-lang-choice option:selected', widget ).val(), + // Icon is HTML built and come from server side and is well escaped when necessary + icon = ( locale && flags.hasOwnProperty( locale ) ) ? flags[ locale ] : null; + + if ( icon ) { + icon += '   '; + var current = $( '.pll-lang', title ); + if ( current.length ) { + current.html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + } else { + flag = $( '' ).addClass( 'pll-lang' ).html( icon ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html + // See the comment above about the icon which is safe. So it is also safe to prepend flag which uses icon. + title.prepend( flag ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + } + } else { + $( '.pll-lang', title ).remove(); + } + } + + if ( isBlockEditor ) { + + widgets_container = $( '.edit-widgets-main-block-list' ); + widgets_selector = '.widget'; + + // Update flags when we click on the legacy widget to display its form. + widgets_container.on( + 'click', + '.wp-block-legacy-widget', + function() { + add_flag( $( this ).find( '.widget' ) ); + } + ); + + } else { + if ( 'undefined' !== typeof wp.customize ) { + + widgets_container = $( '#customize-controls' ); + widgets_selector = '.customize-control .widget'; + + /** + * WP Customizer add control listener. + * + * @link https://wordpress.stackexchange.com/questions/256536/callback-after-wordpress-customizer-complete-loading + * + * @param {object} control The control type. + * @return {void} Nothing. + */ + function customize_add_flag( control ) { + if ( ! control.extended( wp.customize.Widgets.WidgetControl ) ) { + return; + } + + /* + * Make sure the widget's contents are embedded; normally this is done + * when the control is expanded, for DOM performance reasons. + */ + control.embedWidgetContent(); + + // Now we know for sure the widget is fully embedded. + add_flag( control.container.find( '.widget' ) ); + } + wp.customize.control.each( customize_add_flag ); + wp.customize.control.bind( 'add', customize_add_flag ); + + } else { + + widgets_container = $( '#widgets-right' ); + widgets_selector = '.widget'; + + } + + // Add flags on load. + $( widgets_selector, widgets_container ).each( + function() { + add_flag( this ); + } + ); + } + + // Update flags. + widgets_container.on( + 'change', + '.pll-lang-choice', + function() { + add_flag( $( this ).parents( '.widget' ) ); + } + ); + + function pll_toggle( a, test ) { + test ? a.show() : a.hide(); + } + + // Remove all options if dropdown is checked. + $( '.widgets-sortables,.control-section-sidebar,.edit-widgets-main-block-list' ).on( + 'change', + '.pll-dropdown', + function() { + var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' ); + pll_toggle( $( '.no-dropdown-' + this_id ), true != $( this ).prop( 'checked' ) ); + } + ); + + // Disallow unchecking both show names and show flags. + var options = ['-show_flags', '-show_names']; + $.each( + options, + function( i, v ) { + $( '.widgets-sortables,.control-section-sidebar,.edit-widgets-main-block-list' ).on( + 'change', + '.pll' + v, + function() { + var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' ); + if ( true != $( this ).prop( 'checked' ) ) { + $( '#widget-' + this_id + options[ 1 - i ] ).prop( 'checked', true ); + } + } + ); + } + ); + + } +); + diff --git a/wp-content/plugins/polylang/js/build/widgets.min.js b/wp-content/plugins/polylang/js/build/widgets.min.js new file mode 100644 index 00000000..2d7eec3f --- /dev/null +++ b/wp-content/plugins/polylang/js/build/widgets.min.js @@ -0,0 +1 @@ +var __webpack_exports__={};jQuery((function(e){var t,i,n,o=void 0!==wp.blockEditor;function l(t){if(n){t=e(t);var i=o?t.prev("h3"):e(".widget-top .widget-title h3",t),l=e(".pll-lang-choice option:selected",t).val(),d=l&&n.hasOwnProperty(l)?n[l]:null;if(d){d+="   ";var s=e(".pll-lang",i);s.length?s.html(d):(flag=e("").addClass("pll-lang").html(d),i.prepend(flag))}else e(".pll-lang",i).remove()}}if("undefined"!=typeof pll_widgets&&pll_widgets.hasOwnProperty("flags")&&(n=pll_widgets.flags),o)i=".widget",(t=e(".edit-widgets-main-block-list")).on("click",".wp-block-legacy-widget",(function(){l(e(this).find(".widget"))}));else{if(void 0!==wp.customize){function d(e){e.extended(wp.customize.Widgets.WidgetControl)&&(e.embedWidgetContent(),l(e.container.find(".widget")))}t=e("#customize-controls"),i=".customize-control .widget",wp.customize.control.each(d),wp.customize.control.bind("add",d)}else t=e("#widgets-right"),i=".widget";e(i,t).each((function(){l(this)}))}t.on("change",".pll-lang-choice",(function(){l(e(this).parents(".widget"))})),e(".widgets-sortables,.control-section-sidebar,.edit-widgets-main-block-list").on("change",".pll-dropdown",(function(){var t,i=e(this).parent().parent().parent().children(".widget-id").attr("value");t=e(".no-dropdown-"+i),1!=e(this).prop("checked")?t.show():t.hide()}));var s=["-show_flags","-show_names"];e.each(s,(function(t,i){e(".widgets-sortables,.control-section-sidebar,.edit-widgets-main-block-list").on("change",".pll"+i,(function(){var i=e(this).parent().parent().parent().children(".widget-id").attr("value");1!=e(this).prop("checked")&&e("#widget-"+i+s[1-t]).prop("checked",!0)}))}))})); \ No newline at end of file diff --git a/wp-content/plugins/polylang/js/media.js b/wp-content/plugins/polylang/js/media.js deleted file mode 100644 index 794dedbb..00000000 --- a/wp-content/plugins/polylang/js/media.js +++ /dev/null @@ -1,6 +0,0 @@ -// when clicking on attach link, filters find post list per media language -(function( $ ){ - $.ajaxPrefilter(function ( options, originalOptions, jqXHR ) { - options.data = 'pll_post_id=' + $( '#affected' ).val() + '&' + options.data; - }); -})( jQuery ) diff --git a/wp-content/plugins/polylang/js/media.min.js b/wp-content/plugins/polylang/js/media.min.js deleted file mode 100644 index 050f6bb7..00000000 --- a/wp-content/plugins/polylang/js/media.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a){a.ajaxPrefilter(function(t){t.data="pll_post_id="+a("#affected").val()+"&"+t.data})}(jQuery); diff --git a/wp-content/plugins/polylang/js/nav-menu.js b/wp-content/plugins/polylang/js/nav-menu.js deleted file mode 100644 index c549883f..00000000 --- a/wp-content/plugins/polylang/js/nav-menu.js +++ /dev/null @@ -1,68 +0,0 @@ -jQuery( document ).ready(function( $ ) { - $( '#update-nav-menu' ).bind( 'click', function( e ) { - if ( e.target && e.target.className && -1 != e.target.className.indexOf( 'item-edit' ) ) { - $( "input[value='#pll_switcher'][type=text]" ).parent().parent().parent().each(function(){ - var item = $( this ).attr( 'id' ).substring( 19 ); - $( this ).children( 'p:not( .field-move )' ).remove(); // remove default fields we don't need - - h = $( '' ).attr({ - type: 'hidden', - id: 'edit-menu-item-title-' + item, - name: 'menu-item-title[' + item + ']', - value: pll_data.title - }); - $( this ).append( h ); - - h = $( '' ).attr({ - type: 'hidden', - id: 'edit-menu-item-url-' + item, - name: 'menu-item-url[' + item + ']', - value: '#pll_switcher' - }); - $( this ).append( h ); - - // a hidden field which exits only if our jQuery code has been executed - h = $( '' ).attr({ - type: 'hidden', - id: 'edit-menu-item-pll-detect-' + item, - name: 'menu-item-pll-detect[' + item + ']', - value: 1 - }); - $( this ).append( h ); - - ids = Array( 'hide_if_no_translation', 'hide_current', 'force_home', 'show_flags', 'show_names', 'dropdown' ); // reverse order - - // add the fields - for ( var i = 0; i < ids.length; i++ ) { - p = $( '

    ' ).attr( 'class', 'description' ); - $( this ).prepend( p ); - label = $( '

    ' + r + '
    ' ); - $( 'a', r ).click(function(){ - tagBox.flushTags( $( this ).closest( '.inside' ).children( '.tagsdiv' ), this ); - return false; - }); - - // add an if else condition to allow modifying the tags outputed when switching the language - if ( v = $( '.the-tagcloud' ).css( 'display' ) ) { - $( '.the-tagcloud' ).replaceWith( r ); - $( '.the-tagcloud' ).css( 'display', v ); - } - else { - $( '#' + id ).after( r ); - } - }); - } -})( jQuery ); - -// quick edit -(function( $ ) { - $( document ).bind( 'DOMNodeInserted', function( e ) { - var t = $( e.target ); - - // WP inserts the quick edit from - if ( 'inline-edit' == t.attr( 'id' ) ) { - var post_id = t.prev().attr( 'id' ).replace( "post-", "" ); - - if ( post_id > 0 ) { - // language dropdown - var select = t.find( ':input[name="inline_lang_choice"]' ); - var lang = $( '#lang_' + post_id ).html(); - select.val( lang ); // populates the dropdown - - filter_terms( lang ); // initial filter for category checklist - filter_pages( lang ); // initial filter for parent dropdown - - // modify category checklist an parent dropdown on language change - select.change(function() { - filter_terms( $( this ).val() ); - filter_pages( $( this ).val() ); - }); - } - } - - // filter category checklist - function filter_terms( lang ) { - if ( "undefined" != typeof( pll_term_languages ) ) { - $.each( pll_term_languages, function( lg, term_tax ) { - $.each( term_tax, function( tax, terms ) { - $.each( terms, function( i ) { - id = '#' + tax + '-' + pll_term_languages[ lg ][ tax ][ i ]; - lang == lg ? $( id ).show() : $( id ).hide(); - }); - }); - }); - } - } - - // filter parent page dropdown list - function filter_pages( lang ) { - if ( "undefined" != typeof( pll_page_languages ) ) { - $.each( pll_page_languages, function( lg, pages ) { - $.each( pages, function( i ) { - v = $( '#post_parent option[value="' + pll_page_languages[ lg ][ i ] + '"]' ); - lang == lg ? v.show() : v.hide(); - }); - }); - } - } - }); -})( jQuery ); - -// update rows of translated posts when the language is modified in quick edit -// acts on ajaxSuccess event -(function( $ ) { - $( document ).ajaxSuccess(function( event, xhr, settings ) { - function update_rows( post_id ) { - // collect old translations - var translations = new Array; - $( '.translation_' + post_id ).each(function() { - translations.push( $( this ).parent().parent().attr( 'id' ).substring( 5 ) ); - }); - - var data = { - action: 'pll_update_post_rows', - post_id: post_id, - translations: translations.join( ',' ), - post_type: $( "input[name='post_type']" ).val(), - screen: $( "input[name='screen']" ).val(), - _pll_nonce: $( "input[name='_inline_edit']" ).val() // reuse quick edit nonce - } - - // get the modified rows in ajax and update them - $.post( ajaxurl, data, function( response ) { - if ( response ) { - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); - $.each( res.responses, function() { - if ( 'row' == this.what ) { - $( "#post-" + this.supplemental.post_id ).replaceWith( this.data ); - } - }); - } - }); - } - - var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? - if ( 'undefined' != typeof( data['action'] ) && 'inline-save' == data['action'] ) { - update_rows( data['post_ID'] ); - } - }); -})( jQuery ); - -jQuery( document ).ready(function( $ ) { - // collect taxonomies - code partly copied from WordPress - var taxonomies = new Array(); - $( '.categorydiv' ).each(function(){ - var this_id = $( this ).attr( 'id' ), taxonomyParts, taxonomy; - - taxonomyParts = this_id.split( '-' ); - taxonomyParts.shift(); - taxonomy = taxonomyParts.join( '-' ); - taxonomies.push( taxonomy ); // store the taxonomy for future use - - // add our hidden field in the new category form - for each hierarchical taxonomy - // to set the language when creating a new category - $( '#' + taxonomy + '-add-submit' ).before( $( '' ) - .attr( 'type', 'hidden' ) - .attr( 'id', taxonomy + '-lang' ) - .attr( 'name', 'term_lang_choice' ) - .attr( 'value', $( '.post_lang_choice' ).val() ) - ); - }); - - // ajax for changing the post's language in the languages metabox - $( '.post_lang_choice' ).change(function() { - var value = $( this ).val(); - var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' ); - var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' ); - - var data = { - action: 'post_lang_choice', - lang: value, - post_type: $( '#post_type' ).val(), - taxonomies: taxonomies, - post_id: $( '#post_ID' ).val(), - _pll_nonce: $( '#_pll_nonce' ).val() - } - - $.post( ajaxurl, data , function( response ) { - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); - $.each( res.responses, function() { - switch ( this.what ) { - case 'translations': // translations fields - $( '.translations' ).html( this.data ); - init_translations(); - break; - case 'taxonomy': // categories metabox for posts - var tax = this.data; - $( '#' + tax + 'checklist' ).html( this.supplemental.all ); - $( '#' + tax + 'checklist-pop' ).html( this.supplemental.populars ); - $( '#new' + tax + '_parent' ).replaceWith( this.supplemental.dropdown ); - $( '#' + tax + '-lang' ).val( $( '.post_lang_choice' ).val() ); // hidden field - break; - case 'pages': // parent dropdown list for pages - $( '#parent_id' ).html( this.data ); - break; - case 'flag': // flag in front of the select dropdown - $( '.pll-select-flag' ).html( this.data ); - break; - case 'permalink': // Sample permalink - var div = $( '#edit-slug-box' ); - if ( '-1' != this.data && div.children().length ) { - div.html( this.data ); - } - break; - } - }); - - // modifies the language in the tag cloud - $( '.tagcloud-link' ).each(function() { - var id = $( this ).attr( 'id' ); - tagBox.get( id ); - }); - - // Modifies the text direction - $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir ); - $( '#content_ifr' ).contents().find( 'html' ).attr( 'lang', lang ).attr( 'dir', dir ); - $( '#content_ifr' ).contents().find( 'body' ).attr( 'dir', dir ); - }); - }); - - // translations autocomplete input box - function init_translations() { - $( '.tr_lang' ).each(function(){ - var tr_lang = $( this ).attr( 'id' ).substring( 8 ); - var td = $( this ).parent().parent().siblings( '.pll-edit-column' ); - - $( this ).autocomplete({ - minLength: 0, - - source: ajaxurl + '?action=pll_posts_not_translated' + - '&post_language=' + $( '.post_lang_choice' ).val() + - '&translation_language=' + tr_lang + - '&post_type=' + $( '#post_type' ).val() + - '&_pll_nonce=' + $( '#_pll_nonce' ).val(), - - select: function( event, ui ) { - $( '#htr_lang_' + tr_lang ).val( ui.item.id ); - td.html( ui.item.link ); - }, - }); - - // when the input box is emptied - $( this ).blur(function() { - if ( ! $( this ).val() ) { - $( '#htr_lang_' + tr_lang ).val( 0 ); - td.html( td.siblings( '.hidden' ).children().clone() ); - } - }); - }); - } - - init_translations(); -}); diff --git a/wp-content/plugins/polylang/js/post.min.js b/wp-content/plugins/polylang/js/post.min.js deleted file mode 100644 index 29f9101a..00000000 --- a/wp-content/plugins/polylang/js/post.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(t){t.ajaxPrefilter(function(a){"string"!=typeof a.data||-1===a.url.indexOf("action=ajax-tag-search")&&-1===a.data.indexOf("action=ajax-tag-search")||!(lang=t(".post_lang_choice").val())&&!(lang=t(':input[name="inline_lang_choice"]').val())||(a.data="lang="+lang+"&"+a.data)})}(jQuery),function(t){tagBox.get=function(a){var n=a.substr(a.indexOf("-")+1),e={action:"get-tagcloud",lang:t(".post_lang_choice").val(),tax:n};t.post(ajaxurl,e,function(e,i){0!=e&&"success"==i||(e=wpAjax.broken),e=t('
    '+e+"
    "),t("a",e).click(function(){return tagBox.flushTags(t(this).closest(".inside").children(".tagsdiv"),this),!1}),(v=t(".the-tagcloud").css("display"))?(t(".the-tagcloud").replaceWith(e),t(".the-tagcloud").css("display",v)):t("#"+a).after(e)})}}(jQuery),function(t){t(document).bind("DOMNodeInserted",function(a){function n(a){"undefined"!=typeof pll_term_languages&&t.each(pll_term_languages,function(n,e){t.each(e,function(e,i){t.each(i,function(i){id="#"+e+"-"+pll_term_languages[n][e][i],a==n?t(id).show():t(id).hide()})})})}function e(a){"undefined"!=typeof pll_page_languages&&t.each(pll_page_languages,function(n,e){t.each(e,function(e){v=t('#post_parent option[value="'+pll_page_languages[n][e]+'"]'),a==n?v.show():v.hide()})})}var i=t(a.target);if("inline-edit"==i.attr("id")){var l=i.prev().attr("id").replace("post-","");if(l>0){var s=i.find(':input[name="inline_lang_choice"]'),o=t("#lang_"+l).html();s.val(o),n(o),e(o),s.change(function(){n(t(this).val()),e(t(this).val())})}}})}(jQuery),function(t){t(document).ajaxSuccess(function(a,n,e){function i(a){var n=new Array;t(".translation_"+a).each(function(){n.push(t(this).parent().parent().attr("id").substring(5))});var e={action:"pll_update_post_rows",post_id:a,translations:n.join(","),post_type:t("input[name='post_type']").val(),screen:t("input[name='screen']").val(),_pll_nonce:t("input[name='_inline_edit']").val()};t.post(ajaxurl,e,function(a){if(a){var n=wpAjax.parseAjaxResponse(a,"ajax-response");t.each(n.responses,function(){"row"==this.what&&t("#post-"+this.supplemental.post_id).replaceWith(this.data)})}})}var l=wpAjax.unserialize(e.data);"undefined"!=typeof l.action&&"inline-save"==l.action&&i(l.post_ID)})}(jQuery),jQuery(document).ready(function(t){function a(){t(".tr_lang").each(function(){var a=t(this).attr("id").substring(8),n=t(this).parent().parent().siblings(".pll-edit-column");t(this).autocomplete({minLength:0,source:ajaxurl+"?action=pll_posts_not_translated&post_language="+t(".post_lang_choice").val()+"&translation_language="+a+"&post_type="+t("#post_type").val()+"&_pll_nonce="+t("#_pll_nonce").val(),select:function(e,i){t("#htr_lang_"+a).val(i.item.id),n.html(i.item.link)}}),t(this).blur(function(){t(this).val()||(t("#htr_lang_"+a).val(0),n.html(n.siblings(".hidden").children().clone()))})})}var n=new Array;t(".categorydiv").each(function(){var a,e,i=t(this).attr("id");a=i.split("-"),a.shift(),e=a.join("-"),n.push(e),t("#"+e+"-add-submit").before(t("").attr("type","hidden").attr("id",e+"-lang").attr("name","term_lang_choice").attr("value",t(".post_lang_choice").val()))}),t(".post_lang_choice").change(function(){var e=t(this).val(),i=t(this).children('option[value="'+e+'"]').attr("lang"),l=t('.pll-translation-column > span[lang="'+i+'"]').attr("dir"),s={action:"post_lang_choice",lang:e,post_type:t("#post_type").val(),taxonomies:n,post_id:t("#post_ID").val(),_pll_nonce:t("#_pll_nonce").val()};t.post(ajaxurl,s,function(n){var e=wpAjax.parseAjaxResponse(n,"ajax-response");t.each(e.responses,function(){switch(this.what){case"translations":t(".translations").html(this.data),a();break;case"taxonomy":var n=this.data;t("#"+n+"checklist").html(this.supplemental.all),t("#"+n+"checklist-pop").html(this.supplemental.populars),t("#new"+n+"_parent").replaceWith(this.supplemental.dropdown),t("#"+n+"-lang").val(t(".post_lang_choice").val());break;case"pages":t("#parent_id").html(this.data);break;case"flag":t(".pll-select-flag").html(this.data);break;case"permalink":var e=t("#edit-slug-box");"-1"!=this.data&&e.children().length&&e.html(this.data)}}),t(".tagcloud-link").each(function(){var a=t(this).attr("id");tagBox.get(a)}),t("body").removeClass("pll-dir-rtl").removeClass("pll-dir-ltr").addClass("pll-dir-"+l),t("#content_ifr").contents().find("html").attr("lang",i).attr("dir",l),t("#content_ifr").contents().find("body").attr("dir",l)})}),a()}); diff --git a/wp-content/plugins/polylang/js/term.js b/wp-content/plugins/polylang/js/term.js deleted file mode 100644 index 1e080408..00000000 --- a/wp-content/plugins/polylang/js/term.js +++ /dev/null @@ -1,167 +0,0 @@ -// quick edit -(function( $ ) { - $( document ).bind( 'DOMNodeInserted', function( e ) { - var t = $( e.target ); - - // WP inserts the quick edit from - if ( 'inline-edit' == t.attr( 'id' ) ) { - var term_id = t.prev().attr( 'id' ).replace( "tag-", "" ); - - if ( term_id > 0 ) { - // language dropdown - var select = t.find( ':input[name="inline_lang_choice"]' ); - var lang = $( '#lang_' + term_id ).html(); - select.val( lang ); // populates the dropdown - - // disable the language dropdown for default categories - var default_cat = $( '#default_cat_' + term_id ).html(); - if ( term_id == default_cat ) { - select.prop( 'disabled', true ); - } - } - } - }); -})( jQuery ); - - -// update rows of translated terms when adding / deleting a translation or when the language is modified in quick edit -// acts on ajaxSuccess event -(function( $ ) { - $( document ).ajaxSuccess(function( event, xhr, settings ) { - function update_rows( term_id ) { - // collect old translations - var translations = new Array; - $( '.translation_' + term_id ).each(function() { - translations.push( $( this ).parent().parent().attr( 'id' ).substring( 4 ) ); - }); - - var data = { - action: 'pll_update_term_rows', - term_id: term_id, - translations: translations.join( ',' ), - taxonomy: $( "input[name='taxonomy']" ).val(), - post_type: $( "input[name='post_type']" ).val(), - screen: $( "input[name='screen']" ).val(), - _pll_nonce: $( '#_pll_nonce' ).val() - } - - // get the modified rows in ajax and update them - $.post( ajaxurl, data, function( response ) { - if ( response ) { - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); - $.each( res.responses, function() { - if ( 'row' == this.what ) { - $( "#tag-" + this.supplemental.term_id ).replaceWith( this.data ); - } - }); - } - }); - } - - var data = wpAjax.unserialize( settings.data ); // what were the data sent by the ajax request? - if ( 'undefined' != typeof( data['action'] ) ) { - switch ( data['action'] ) { - // when adding a term, the new term_id is in the ajax response - case 'add-tag': - res = wpAjax.parseAjaxResponse( xhr.responseXML, 'ajax-response' ); - $.each( res.responses, function() { - if ( 'term' == this.what ) { - update_rows( this.supplemental.term_id ); - } - }); - - // and also reset translations hidden input fields - $( '.htr_lang' ).val( 0 ); - break; - - // when deleting a term - case 'delete-tag': - update_rows( data['tag_ID'] ); - break; - - // in case the language is modified in quick edit and breaks translations - case 'inline-save-tax': - update_rows( data['tax_ID'] ); - break; - } - } - }); -})( jQuery ); - -jQuery( document ).ready(function( $ ) { - // translations autocomplete input box - function init_translations() { - $( '.tr_lang' ).each(function(){ - var tr_lang = $( this ).attr( 'id' ).substring( 8 ); - var td = $( this ).parent().parent().siblings( '.pll-edit-column' ); - - $( this ).autocomplete({ - minLength: 0, - - source: ajaxurl + '?action=pll_terms_not_translated' + - '&term_language=' + $( '#term_lang_choice' ).val() + - '&term_id=' + $( "input[name='tag_ID']" ).val() + - '&taxonomy=' + $( "input[name='taxonomy']" ).val() + - '&translation_language=' + tr_lang + - '&post_type=' + typenow + - '&_pll_nonce=' + $( '#_pll_nonce' ).val(), - - select: function( event, ui ) { - $( '#htr_lang_' + tr_lang ).val( ui.item.id ); - td.html( ui.item.link ); - }, - }); - - // when the input box is emptied - $( this ).blur(function() { - if ( ! $( this ).val() ) { - $( '#htr_lang_' + tr_lang ).val( 0 ); - td.html( td.siblings( '.hidden' ).children().clone() ); - } - }); - }); - } - - init_translations(); - - // ajax for changing the term's language - $( '#term_lang_choice' ).change(function() { - var value = $( this ).val(); - var lang = $( this ).children( 'option[value="' + value + '"]' ).attr( 'lang' ); - var dir = $( '.pll-translation-column > span[lang="' + lang + '"]' ).attr( 'dir' ); - - var data = { - action: 'term_lang_choice', - lang: value, - from_tag: $( "input[name='from_tag']" ).val(), - term_id: $( "input[name='tag_ID']" ).val(), - taxonomy: $( "input[name='taxonomy']" ).val(), - post_type: typenow, - _pll_nonce: $( '#_pll_nonce' ).val() - } - - $.post( ajaxurl, data, function( response ) { - var res = wpAjax.parseAjaxResponse( response, 'ajax-response' ); - $.each( res.responses, function() { - switch ( this.what ) { - case 'translations': // translations fields - $( "#term-translations" ).html( this.data ); - init_translations(); - break; - case 'parent': // parent dropdown list for hierarchical taxonomies - $( '#parent' ).replaceWith( this.data ); - break; - case 'tag_cloud': // popular items - $( '.tagcloud' ).replaceWith( this.data ); - break; - case 'flag': // flag in front of the select dropdown - $( '.pll-select-flag' ).html( this.data ); - break; - } - }); - - // Modifies the text direction - $( 'body' ).removeClass( 'pll-dir-rtl' ).removeClass( 'pll-dir-ltr' ).addClass( 'pll-dir-' + dir ); - }); - }); -}); diff --git a/wp-content/plugins/polylang/js/term.min.js b/wp-content/plugins/polylang/js/term.min.js deleted file mode 100644 index 5f62a105..00000000 --- a/wp-content/plugins/polylang/js/term.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(a){a(document).bind("DOMNodeInserted",function(t){var n=a(t.target);if("inline-edit"==n.attr("id")){var e=n.prev().attr("id").replace("tag-","");if(e>0){var l=n.find(':input[name="inline_lang_choice"]'),i=a("#lang_"+e).html();l.val(i);var r=a("#default_cat_"+e).html();e==r&&l.prop("disabled",!0)}}})}(jQuery),function(a){a(document).ajaxSuccess(function(t,n,e){function l(t){var n=new Array;a(".translation_"+t).each(function(){n.push(a(this).parent().parent().attr("id").substring(4))});var e={action:"pll_update_term_rows",term_id:t,translations:n.join(","),taxonomy:a("input[name='taxonomy']").val(),post_type:a("input[name='post_type']").val(),screen:a("input[name='screen']").val(),_pll_nonce:a("#_pll_nonce").val()};a.post(ajaxurl,e,function(t){if(t){var n=wpAjax.parseAjaxResponse(t,"ajax-response");a.each(n.responses,function(){"row"==this.what&&a("#tag-"+this.supplemental.term_id).replaceWith(this.data)})}})}var i=wpAjax.unserialize(e.data);if("undefined"!=typeof i.action)switch(i.action){case"add-tag":res=wpAjax.parseAjaxResponse(n.responseXML,"ajax-response"),a.each(res.responses,function(){"term"==this.what&&l(this.supplemental.term_id)}),a(".htr_lang").val(0);break;case"delete-tag":l(i.tag_ID);break;case"inline-save-tax":l(i.tax_ID)}})}(jQuery),jQuery(document).ready(function(a){function t(){a(".tr_lang").each(function(){var t=a(this).attr("id").substring(8),n=a(this).parent().parent().siblings(".pll-edit-column");a(this).autocomplete({minLength:0,source:ajaxurl+"?action=pll_terms_not_translated&term_language="+a("#term_lang_choice").val()+"&term_id="+a("input[name='tag_ID']").val()+"&taxonomy="+a("input[name='taxonomy']").val()+"&translation_language="+t+"&post_type="+typenow+"&_pll_nonce="+a("#_pll_nonce").val(),select:function(e,l){a("#htr_lang_"+t).val(l.item.id),n.html(l.item.link)}}),a(this).blur(function(){a(this).val()||(a("#htr_lang_"+t).val(0),n.html(n.siblings(".hidden").children().clone()))})})}t(),a("#term_lang_choice").change(function(){var n=a(this).val(),e=a(this).children('option[value="'+n+'"]').attr("lang"),l=a('.pll-translation-column > span[lang="'+e+'"]').attr("dir"),i={action:"term_lang_choice",lang:n,from_tag:a("input[name='from_tag']").val(),term_id:a("input[name='tag_ID']").val(),taxonomy:a("input[name='taxonomy']").val(),post_type:typenow,_pll_nonce:a("#_pll_nonce").val()};a.post(ajaxurl,i,function(n){var e=wpAjax.parseAjaxResponse(n,"ajax-response");a.each(e.responses,function(){switch(this.what){case"translations":a("#term-translations").html(this.data),t();break;case"parent":a("#parent").replaceWith(this.data);break;case"tag_cloud":a(".tagcloud").replaceWith(this.data);break;case"flag":a(".pll-select-flag").html(this.data)}}),a("body").removeClass("pll-dir-rtl").removeClass("pll-dir-ltr").addClass("pll-dir-"+l)})})}); diff --git a/wp-content/plugins/polylang/js/user.js b/wp-content/plugins/polylang/js/user.js deleted file mode 100644 index b03dfcd6..00000000 --- a/wp-content/plugins/polylang/js/user.js +++ /dev/null @@ -1,20 +0,0 @@ -jQuery( document ).ready(function( $ ) { - // biography - // FIXME there is probably a more efficient way to do this - var td = $( '#description' ).parent(); - var d = $( '#description' ).clone(); - var span = td.children( '.description' ).clone(); - td.children().remove(); - - $( '.biography' ).each(function(){ - lang = $( this ).attr( 'name' ).split( '___' ); - desc = d.clone(); - desc.attr( 'name', 'description_' + lang[0] ); - desc.html( $( this ).val() ); - td.append( '
    ' + lang[1] + '' ); - td.append( span ); -}); diff --git a/wp-content/plugins/polylang/js/user.min.js b/wp-content/plugins/polylang/js/user.min.js deleted file mode 100644 index 51c50b0c..00000000 --- a/wp-content/plugins/polylang/js/user.min.js +++ /dev/null @@ -1 +0,0 @@ -jQuery(document).ready(function(e){var n=e("#description").parent(),d=e("#description").clone(),i=n.children(".description").clone();n.children().remove(),e(".biography").each(function(){lang=e(this).attr("name").split("___"),desc=d.clone(),desc.attr("name","description_"+lang[0]),desc.html(e(this).val()),n.append("
    "+lang[1]+""),n.append(i)}); diff --git a/wp-content/plugins/polylang/lingotek/image01.gif b/wp-content/plugins/polylang/lingotek/image01.gif deleted file mode 100644 index 0ae60ac5..00000000 Binary files a/wp-content/plugins/polylang/lingotek/image01.gif and /dev/null differ diff --git a/wp-content/plugins/polylang/lingotek/image02.png b/wp-content/plugins/polylang/lingotek/image02.png deleted file mode 100644 index 0293bb44..00000000 Binary files a/wp-content/plugins/polylang/lingotek/image02.png and /dev/null differ diff --git a/wp-content/plugins/polylang/lingotek/image03.png b/wp-content/plugins/polylang/lingotek/image03.png deleted file mode 100644 index 95ed5464..00000000 Binary files a/wp-content/plugins/polylang/lingotek/image03.png and /dev/null differ diff --git a/wp-content/plugins/polylang/lingotek/image04.png b/wp-content/plugins/polylang/lingotek/image04.png deleted file mode 100644 index 210a1f6a..00000000 Binary files a/wp-content/plugins/polylang/lingotek/image04.png and /dev/null differ diff --git a/wp-content/plugins/polylang/modules/lingotek/image01.gif b/wp-content/plugins/polylang/modules/lingotek/image01.gif new file mode 100644 index 00000000..9f9076e8 Binary files /dev/null and b/wp-content/plugins/polylang/modules/lingotek/image01.gif differ diff --git a/wp-content/plugins/polylang/modules/lingotek/image02.png b/wp-content/plugins/polylang/modules/lingotek/image02.png new file mode 100644 index 00000000..3c547c4f Binary files /dev/null and b/wp-content/plugins/polylang/modules/lingotek/image02.png differ diff --git a/wp-content/plugins/polylang/modules/lingotek/image03.png b/wp-content/plugins/polylang/modules/lingotek/image03.png new file mode 100644 index 00000000..24982668 Binary files /dev/null and b/wp-content/plugins/polylang/modules/lingotek/image03.png differ diff --git a/wp-content/plugins/polylang/modules/lingotek/image04.png b/wp-content/plugins/polylang/modules/lingotek/image04.png new file mode 100644 index 00000000..bddfb419 Binary files /dev/null and b/wp-content/plugins/polylang/modules/lingotek/image04.png differ diff --git a/wp-content/plugins/polylang/lingotek/lingotek.php b/wp-content/plugins/polylang/modules/lingotek/lingotek.php similarity index 73% rename from wp-content/plugins/polylang/lingotek/lingotek.php rename to wp-content/plugins/polylang/modules/lingotek/lingotek.php index ea4dc21d..4396982e 100644 --- a/wp-content/plugins/polylang/lingotek/lingotek.php +++ b/wp-content/plugins/polylang/modules/lingotek/lingotek.php @@ -1,8 +1,7 @@ __( 'Close' ), - ), - array( - 'label' => __( 'Learn more', 'polylang' ), - 'link' => admin_url( 'admin.php?page=mlang&tab=lingotek' ), - ), - ); - - if ( $link = $this->get_activate_link() ) { - $content .= ' ' . __( 'Click on Activate Lingotek to start translating.', 'polylang' ); - - $buttons[] = array( - 'label' => __( 'Activate Lingotek', 'polylang' ), - 'link' => str_replace( '&', '&', $link ), // wp_nonce_url escapes the url for html display. Here we want it for js + $buttons = sprintf( + '%s', + admin_url( 'admin.php?page=mlang_lingotek' ), + __( 'Learn more', 'polylang' ) ); + + if ( $link = $this->get_activate_link() ) { + $content .= ' ' . __( 'Click on Activate Lingotek to start translating.', 'polylang' ); + + $buttons = sprintf( + '%s', + $link, + __( 'Activate Lingotek', 'polylang' ) + ) . $buttons; + } + + if ( is_plugin_active( self::LINGOTEK ) ) { // Needs /wp-admin/includes/plugin.php to be loaded + PLL_Admin_Notices::dismiss( 'lingotek' ); + } else { + PLL_Admin_Notices::add_notice( 'lingotek', '

    ' . $content . '

    ' . $buttons . '

    ' ); + } } - - $args = array( - 'pointer' => 'pll_lgt', - 'id' => empty( $options['previous_version'] ) ? 'nav-tab-lingotek' : 'wp-admin-bar-languages', - 'position' => array( - 'edge' => 'top', - 'align' => 'left', - ), - 'width' => 400, - 'title' => __( 'Congratulations!', 'polylang' ), - 'content' => $content, - 'buttons' => $buttons, - ); - - new PLL_Pointer( $args ); } /** @@ -83,8 +73,12 @@ class PLL_Lingotek { * Displays the content in the Lingotek tab * * @since 1.7.7 + * + * @return void */ public function display_tab() { + PLL_Admin_Notices::dismiss( 'lingotek' ); + $activate_link = $this->get_activate_link(); $links = array( @@ -110,11 +104,11 @@ class PLL_Lingotek { printf( '

    %s

    ', esc_html__( 'Polylang is now fully integrated with Lingotek, a professional translation management system!', 'polylang' ) ); $this->box( - __( 'Automatically Translate My Site', 'polylang' ), + __( 'Automatically translate my site', 'polylang' ), __( 'Polylang is now fully integrated with Lingotek!', 'polylang' ), array( __( 'Access free machine translation for your site for up to 100,000 characters.', 'polylang' ), - __( 'Machine translation is an excellent option if you\'re on a tight budget, looking for near-instant results, and are okay with less-than-perfect quality.', 'polylang' ), + __( 'If you\'re on a tight budget, looking for near-instant results, and are okay with less-than-perfect quality, machine translation is an excellent option.', 'polylang' ), ), array_intersect_key( $links, array_flip( array( 'activate' ) ) ), 'image01.gif' @@ -134,19 +128,19 @@ class PLL_Lingotek { ); $this->box( - __( 'Professionally Translate My Site', 'polylang' ), - __( 'Do you need to professionally translate your site?', 'polylang' ), + __( 'Professionally translate my site', 'polylang' ), + __( 'Do you need professional translations for your site?', 'polylang' ), array( __( 'Start the process of getting a professional translation bid.', 'polylang' ), - __( 'Activate account so Lingotek can get an accurate count of how many words you have on your site and which languages you wish to translate into.', 'polylang' ), - __( 'Once activated click on the request translation bid and a certified translation project manager will contact you to give a no obligations translation bid.', 'polylang' ), + __( 'When you activate your account, Lingotek will be able to get an accurate count of the number of words in your site. Then tell them which languages you wish to have them translated into.', 'polylang' ), + __( 'Once activated, click on the "request translation bid" and a certified translation project manager will contact you for a no-obligations translation bid.', 'polylang' ), ), array_intersect_key( $links, array_flip( array( 'activate', 'translation' ) ) ), 'image03.png' ); $this->box( - __( 'Need Extra Services?', 'polylang' ), + __( 'Need extra services?', 'polylang' ), __( 'Do you need help translating your site?', 'polylang' ), array( __( 'Start the process of getting extra services.', 'polylang' ), @@ -164,6 +158,8 @@ class PLL_Lingotek { * Styles the content of the Lingotek tab * * @since 1.7.7 + * + * @return void */ public function print_css() { ?> @@ -176,9 +172,13 @@ class PLL_Lingotek { border: 1px solid #ddd; margin-right: 3px; margin-bottom: 3px; - height: 630px; + height: 650px; background: #fafafa; } + .rtl .ltk-feature { + text-align: right; + float: right; + } .ltk-feature h3 { height: 1em; } @@ -194,10 +194,16 @@ class PLL_Lingotek { .ltk-feature ul { margin-left: 10px; } + .rtl .ltk-feature ul { + margin-right: 10px; + } .ltk-feature ul li { list-style: inside disc; list-style-position: outside; - padding-left: 0; + padding-left: 0; + } + .rtl .ltk-feature ul li { + padding-right: 0; } .ltk-feature .ltk-desc { height: 3em; @@ -210,8 +216,6 @@ class PLL_Lingotek { .ltk-feature .ltk-lower { padding: 5px 20px 0px 20px; border-top: 1px solid #eee; - - text-align: left; font-size: 95%; } @@ -235,6 +239,7 @@ class PLL_Lingotek { * @param array $list * @param array $links * @param string $img + * @return void */ protected function box( $title, $desc, $list, $links, $img ) { ?> @@ -299,5 +304,3 @@ class PLL_Lingotek { return ''; } } - -add_action( 'wp_loaded', array( new PLL_Lingotek(), 'init' ) ); diff --git a/wp-content/plugins/polylang/modules/lingotek/load.php b/wp-content/plugins/polylang/modules/lingotek/load.php new file mode 100644 index 00000000..a91b0893 --- /dev/null +++ b/wp-content/plugins/polylang/modules/lingotek/load.php @@ -0,0 +1,14 @@ +options['force_lang'] ) ? parse_url( PLL()->links_model->home, PHP_URL_HOST ) : COOKIE_DOMAIN; - $js = sprintf( ' - var date = new Date(); - date.setTime( date.getTime() + %d ); - document.cookie = "%s=%s; expires=" + date.toUTCString() + "; path=%s%s";', - esc_js( apply_filters( 'pll_cookie_expiration', YEAR_IN_SECONDS ) ), - esc_js( PLL_COOKIE ), - esc_js( pll_current_language() ), - esc_js( COOKIEPATH ), - $domain ? '; domain=' . esc_js( $domain ) : '' - ); - echo ''; - } - - /** - * Informs cache plugins not to cache the home in the default language - * When the detection of the browser preferred language is active - * - * @since 2.3 - */ - public function do_not_cache_site_home() { - if ( ! defined( 'DONOTCACHEPAGE' ) && PLL()->options['browser'] && PLL()->options['hide_default'] && is_front_page() && pll_current_language() === pll_default_language() ) { - define( 'DONOTCACHEPAGE', true ); - } - } -} diff --git a/wp-content/plugins/polylang/modules/plugins/plugins-compat.php b/wp-content/plugins/polylang/modules/plugins/plugins-compat.php deleted file mode 100644 index a13eefc5..00000000 --- a/wp-content/plugins/polylang/modules/plugins/plugins-compat.php +++ /dev/null @@ -1,377 +0,0 @@ -jetpack = new PLL_Jetpack(); // Must be loaded before the plugin is active - - // WP Sweep - add_filter( 'wp_sweep_excluded_taxonomies', array( $this, 'wp_sweep_excluded_taxonomies' ) ); - - // Twenty Seventeen - add_action( 'init', array( $this, 'twenty_seventeen_init' ) ); - - // No category base (works for Yoast SEO too) - add_filter( 'get_terms_args', array( $this, 'no_category_base_get_terms_args' ), 5 ); // Before adding cache domain - - // WordPress MU Domain Mapping - if ( function_exists( 'redirect_to_mapped_domain' ) && ! get_site_option( 'dm_no_primary_domain' ) ) { - remove_action( 'template_redirect', 'redirect_to_mapped_domain' ); - add_action( 'template_redirect', array( $this, 'dm_redirect_to_mapped_domain' ) ); - } - } - - /** - * Access to the single instance of the class - * - * @since 1.7 - * - * @return object - */ - static public function instance() { - if ( empty( self::$instance ) ) { - self::$instance = new self(); - } - - return self::$instance; - } - - /** - * Look for active plugins and load compatibility layer if needed - * - * @since 2.3 - */ - public function plugins_loaded() { - // Yoast SEO - if ( defined( 'WPSEO_VERSION' ) ) { - add_action( 'pll_language_defined', array( $this->wpseo = new PLL_WPSEO(), 'init' ) ); - } - - // Cache plugins, with specific test for WP Fastest Cache which doesn't use WP_CACHE - if ( ( defined( 'WP_CACHE' ) && WP_CACHE ) || defined( 'WPFC_MAIN_PATH' ) ) { - add_action( 'pll_init', array( $this->cache_compat = new PLL_Cache_Compat(), 'init' ) ); - } - - // Advanced Custom Fields Pro - // The function acf_get_value() is not defined in ACF 4 - if ( class_exists( 'acf' ) && function_exists( 'acf_get_value' ) && class_exists( 'PLL_ACF' ) ) { - add_action( 'init', array( $this->acf = new PLL_ACF(), 'init' ) ); - } - - // Custom Post Type UI - if ( defined( 'CPTUI_VERSION' ) && class_exists( 'PLL_CPTUI' ) ) { - add_action( 'pll_init', array( $this->cptui = new PLL_CPTUI(), 'init' ) ); - } - - // The Event Calendar - if ( defined( 'TRIBE_EVENTS_FILE' ) && class_exists( 'PLL_TEC' ) ) { - add_action( 'pll_init', array( $this->tec = new PLL_TEC(), 'init' ) ); - } - - // Beaver Builder - if ( class_exists( 'FLBuilderLoader' ) && class_exists( 'PLL_FLBuilder' ) ) { - $this->flbuilder = new PLL_FLBuilder(); - } - - // Divi Builder - if ( ( 'Divi' === get_template() || defined( 'ET_BUILDER_PLUGIN_VERSION' ) ) && class_exists( 'PLL_Divi_Builder' ) ) { - $this->divi_builder = new PLL_Divi_Builder(); - } - } - - /** - * WordPress Importer - * If WordPress Importer is active, replace the wordpress_importer_init function - * - * @since 1.2 - */ - function maybe_wordpress_importer() { - if ( defined( 'WP_LOAD_IMPORTERS' ) && class_exists( 'WP_Import' ) ) { - remove_action( 'admin_init', 'wordpress_importer_init' ); - add_action( 'admin_init', array( $this, 'wordpress_importer_init' ) ); - } - } - - /** - * WordPress Importer - * Loads our child class PLL_WP_Import instead of WP_Import - * - * @since 1.2 - */ - function wordpress_importer_init() { - $class = new ReflectionClass( 'WP_Import' ); - load_plugin_textdomain( 'wordpress-importer', false, basename( dirname( $class->getFileName() ) ) . '/languages' ); - - $GLOBALS['wp_import'] = new PLL_WP_Import(); - register_importer( 'wordpress', 'WordPress', __( 'Import posts, pages, comments, custom fields, categories, and tags from a WordPress export file.', 'wordpress-importer' ), array( $GLOBALS['wp_import'], 'dispatch' ) ); // WPCS: spelling ok. - } - - /** - * WordPress Importer - * Backward Compatibility Polylang < 1.8 - * Sets the flag when importing a language and the file has been exported with Polylang < 1.8 - * - * @since 1.8 - * - * @param array $terms an array of arrays containing terms information form the WXR file - * @return array - */ - function wp_import_terms( $terms ) { - include PLL_SETTINGS_INC . '/languages.php'; - - foreach ( $terms as $key => $term ) { - if ( 'language' === $term['term_taxonomy'] ) { - $description = maybe_unserialize( $term['term_description'] ); - if ( empty( $description['flag_code'] ) && isset( $languages[ $description['locale'] ] ) ) { - $description['flag_code'] = $languages[ $description['locale'] ]['flag']; - $terms[ $key ]['term_description'] = serialize( $description ); - } - } - } - return $terms; - } - - /** - * YARPP - * Just makes YARPP aware of the language taxonomy ( after Polylang registered it ) - * - * @since 1.0 - */ - public function yarpp_init() { - $GLOBALS['wp_taxonomies']['language']->yarpp_support = 1; - } - - /** - * Aqua Resizer - * - * @since 1.1.5 - * - * @param array $arr - * @return array - */ - public function aq_home_url_black_list( $arr ) { - return array_merge( $arr, array( array( 'function' => 'aq_resize' ) ) ); - } - - /** - * Custom field template - * Custom field template does check $_REQUEST['post'] to populate the custom fields values - * - * @since 1.0.2 - * - * @param string $post_type unused - * @param object $post current post object - */ - public function cft_copy( $post_type, $post ) { - global $custom_field_template; - if ( isset( $custom_field_template, $_REQUEST['from_post'], $_REQUEST['new_lang'] ) && ! empty( $post ) ) { - $_REQUEST['post'] = $post->ID; - } - } - - /** - * Twenty Fourteen - * Rewrites the function Featured_Content::get_featured_post_ids() - * - * @since 1.4 - * - * @param array $featured_ids featured posts ids - * @return array modified featured posts ids ( include all languages ) - */ - public function twenty_fourteen_featured_content_ids( $featured_ids ) { - if ( 'twentyfourteen' != get_template() || ! did_action( 'pll_init' ) || false !== $featured_ids ) { - return $featured_ids; - } - - $settings = Featured_Content::get_setting(); - - if ( ! $term = wpcom_vip_get_term_by( 'name', $settings['tag-name'], 'post_tag' ) ) { - return $featured_ids; - } - - // Get featured tag translations - $tags = PLL()->model->term->get_translations( $term->term_id ); - $ids = array(); - - // Query for featured posts in all languages - // One query per language to get the correct number of posts per language - foreach ( $tags as $tag ) { - $_ids = get_posts( array( - 'lang' => 0, // avoid language filters - 'fields' => 'ids', - 'numberposts' => Featured_Content::$max_posts, - 'tax_query' => array( - array( - 'taxonomy' => 'post_tag', - 'terms' => (int) $tag, - ), - ), - ) ); - - $ids = array_merge( $ids, $_ids ); - } - - $ids = array_map( 'absint', $ids ); - set_transient( 'featured_content_ids', $ids ); - - return $ids; - } - - /** - * Twenty Fourteen - * Translates the featured tag id in featured content settings - * Mainly to allow hiding it when requested in featured content options - * Acts only on frontend - * - * @since 1.4 - * - * @param array $settings featured content settings - * @return array modified $settings - */ - public function twenty_fourteen_option_featured_content( $settings ) { - if ( 'twentyfourteen' == get_template() && PLL() instanceof PLL_Frontend && $settings['tag-id'] && $tr = pll_get_term( $settings['tag-id'] ) ) { - $settings['tag-id'] = $tr; - } - - return $settings; - } - - /** - * Duplicate Post - * Avoid duplicating the 'post_translations' taxonomy - * - * @since 1.8 - * - * @param array|string $taxonomies - * @return array - */ - function duplicate_post_taxonomies_blacklist( $taxonomies ) { - if ( empty( $taxonomies ) ) { - $taxonomies = array(); // As we get an empty string when there is no taxonomy - } - - $taxonomies[] = 'post_translations'; - return $taxonomies; - } - - /** - * WP Sweep - * Add 'term_language' and 'term_translations' to excluded taxonomies otherwise terms loose their language and translation group - * - * @since 2.0 - * - * @param array $excluded_taxonomies list of taxonomies excluded from sweeping - * @return array - */ - public function wp_sweep_excluded_taxonomies( $excluded_taxonomies ) { - return array_merge( $excluded_taxonomies, array( 'term_language', 'term_translations' ) ); - } - - /** - * Twenty Seventeen - * Translates the front page panels - * - * @since 2.0.10 - */ - public function twenty_seventeen_init() { - if ( 'twentyseventeen' === get_template() && function_exists( 'twentyseventeen_panel_count' ) && did_action( 'pll_init' ) && PLL() instanceof PLL_Frontend ) { - $num_sections = twentyseventeen_panel_count(); - for ( $i = 1; $i < ( 1 + $num_sections ); $i++ ) { - add_filter( 'theme_mod_panel_' . $i, 'pll_get_post' ); - } - } - } - - /** - * Make sure No category base plugins (including Yoast SEO) get all categories when flushing rules - * - * @since 2.1 - * - * @param array $args - * @return array - */ - public function no_category_base_get_terms_args( $args ) { - if ( doing_filter( 'category_rewrite_rules' ) ) { - $args['lang'] = ''; - } - return $args; - } - - /** - * WordPress MU Domain Mapping - * Fix primary domain check which forces only one domain per blog - * Accept only known domains/subdomains for the current blog - * - * @since 2.2 - */ - public function dm_redirect_to_mapped_domain() { - $options = get_option( 'polylang' ); - - // The language is set from the subdomain or domain name - if ( $options['force_lang'] > 1 ) { - // Don't redirect the main site - if ( is_main_site() ) { - return; - } - - // Don't redirect post previews - if ( isset( $_GET['preview'] ) && 'true' === $_GET['preview'] ) { - return; - } - - // Don't redirect theme customizer - if ( isset( $_POST['customize'] ) && isset( $_POST['theme'] ) && 'on' === $_POST['customize'] ) { - return; - } - - // If we can't associate the requested domain to a language, redirect to the default domain - $hosts = PLL()->links_model->get_hosts(); - $lang = array_search( $_SERVER['HTTP_HOST'], $hosts ); - - if ( empty( $lang ) ) { - $status = get_site_option( 'dm_301_redirect' ) ? '301' : '302'; // Honor status redirect option - $redirect = ( is_ssl() ? 'https://' : 'http://' ) . $hosts[ $options['default_lang'] ] . $_SERVER['REQUEST_URI']; - wp_redirect( $redirect, $status ); - exit; - } - } - - // Otherwise rely on MU Domain Mapping - redirect_to_mapped_domain(); - } -} diff --git a/wp-content/plugins/polylang/modules/plugins/wpseo.php b/wp-content/plugins/polylang/modules/plugins/wpseo.php deleted file mode 100644 index 4dbbdbc8..00000000 --- a/wp-content/plugins/polylang/modules/plugins/wpseo.php +++ /dev/null @@ -1,339 +0,0 @@ -options = array_merge( $wpseo_front->options, (array) get_option( $opt ) ); - } - } - - // Filters sitemap queries to remove inactive language or to get - // one sitemap per language when using multiple domains or subdomains - // because WPSEO does not accept several domains or subdomains in one sitemap - add_filter( 'wpseo_posts_join', array( $this, 'wpseo_posts_join' ), 10, 2 ); - add_filter( 'wpseo_posts_where', array( $this, 'wpseo_posts_where' ), 10, 2 ); - add_filter( 'wpseo_typecount_join', array( $this, 'wpseo_posts_join' ), 10, 2 ); - add_filter( 'wpseo_typecount_where', array( $this, 'wpseo_posts_where' ), 10, 2 ); - - if ( PLL()->options['force_lang'] > 1 ) { - add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_false' ); // Disable cache! otherwise WPSEO keeps only one domain (thanks to Junaid Bhura) - add_filter( 'home_url', array( $this, 'wpseo_home_url' ), 10, 2 ); // Fix home_url - } else { - // Get all terms in all languages when the language is set from the content or directory name - add_filter( 'get_terms_args', array( $this, 'wpseo_remove_terms_filter' ) ); - - // Add the homepages for all languages to the sitemap when the front page displays posts - if ( ! get_option( 'page_on_front' ) ) { - add_filter( 'wpseo_sitemap_post_content', array( $this, 'add_language_home_urls' ) ); - } - } - - add_filter( 'pll_home_url_white_list', array( $this, 'wpseo_home_url_white_list' ) ); - add_action( 'wpseo_opengraph', array( $this, 'wpseo_ogp' ), 2 ); - add_filter( 'wpseo_canonical', array( $this, 'wpseo_canonical' ) ); - } else { - add_action( 'admin_init', array( $this, 'wpseo_register_strings' ) ); - - // Primary category - add_filter( 'pll_copy_post_metas', array( $this, 'copy_post_metas' ) ); - add_filter( 'pll_translate_post_meta', array( $this, 'translate_post_meta' ), 10, 3 ); - } - } - - /** - * Registers strings for custom post types and custom taxonomies titles and meta descriptions - * - * @since 2.0 - */ - function wpseo_register_strings() { - $options = get_option( 'wpseo_titles' ); - foreach ( get_post_types( array( 'public' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_post_type( $t ) ) { - $this->_wpseo_register_strings( $options, array( 'title-' . $t, 'metadesc-' . $t ) ); - } - } - foreach ( get_post_types( array( 'has_archive' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_post_type( $t ) ) { - $this->_wpseo_register_strings( $options, array( 'title-ptarchive-' . $t, 'metadesc-ptarchive-' . $t, 'bctitle-ptarchive-' . $t ) ); - } - } - foreach ( get_taxonomies( array( 'public' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_taxonomy( $t ) ) { - $this->_wpseo_register_strings( $options, array( 'title-tax-' . $t, 'metadesc-tax-' . $t ) ); - } - } - } - - /** - * Helper function to translate custom post types and custom taxonomies titles and meta descriptions - * - * @since 2.1.6 - * - * @param array $options - * @param array $titles - * @return array - */ - protected function _wpseo_translate_titles( $options, $titles ) { - foreach ( $titles as $title ) { - if ( ! empty( $options[ $title ] ) ) { - $options[ $title ] = pll__( $options[ $title ] ); - } - } - return $options; - } - - /** - * Translates strings for custom post types and custom taxonomies titles and meta descriptions - * - * @since 2.0 - * - * @param array $options - * @return array - */ - function wpseo_translate_titles( $options ) { - if ( PLL() instanceof PLL_Frontend ) { - foreach ( get_post_types( array( 'public' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_post_type( $t ) ) { - $options = $this->_wpseo_translate_titles( $options, array( 'title-' . $t, 'metadesc-' . $t ) ); - } - } - foreach ( get_post_types( array( 'has_archive' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_post_type( $t ) ) { - $options = $this->_wpseo_translate_titles( $options, array( 'title-ptarchive-' . $t, 'metadesc-ptarchive-' . $t, 'bctitle-ptarchive-' . $t ) ); - } - } - foreach ( get_taxonomies( array( 'public' => true, '_builtin' => false ) ) as $t ) { - if ( pll_is_translated_taxonomy( $t ) ) { - $options = $this->_wpseo_translate_titles( $options, array( 'title-tax-' . $t, 'metadesc-tax-' . $t ) ); - } - } - } - return $options; - } - - /** - * Fixes the home url as well as the stylesheet url - * Only when using multiple domains or subdomains - * - * @since 1.6.4 - * - * @param string $url - * @param string $path - * @return $url - */ - public function wpseo_home_url( $url, $path ) { - $uri = empty( $path ) ? ltrim( $_SERVER['REQUEST_URI'], '/' ) : $path; - - if ( 'sitemap_index.xml' === $uri || preg_match( '#([^/]+?)-sitemap([0-9]+)?\.xml|([a-z]+)?-?sitemap\.xsl#', $uri ) ) { - $url = PLL()->links_model->switch_language_in_link( $url, PLL()->curlang ); - } - - return $url; - } - - /** - * Get active languages for the sitemaps - * - * @since 2.0 - * - * @return array list of active language slugs, empty if all languages are active - */ - protected function wpseo_get_active_languages() { - $languages = PLL()->model->get_languages_list(); - if ( wp_list_filter( $languages, array( 'active' => false ) ) ) { - return wp_list_pluck( wp_list_filter( $languages, array( 'active' => false ), 'NOT' ), 'slug' ); - } - return array(); - } - - /** - * Modifies the sql request for posts sitemaps - * Only when using multiple domains or subdomains or if some languages are not active - * - * @since 1.6.4 - * - * @param string $sql JOIN clause - * @param string $post_type - * @return string - */ - public function wpseo_posts_join( $sql, $post_type ) { - return pll_is_translated_post_type( $post_type ) && ( PLL()->options['force_lang'] > 1 || $this->wpseo_get_active_languages() ) ? $sql . PLL()->model->post->join_clause() : $sql; - } - - /** - * Modifies the sql request for posts sitemaps - * Only when using multiple domains or subdomains or if some languages are not active - * - * @since 1.6.4 - * - * @param string $sql WHERE clause - * @param string $post_type - * @return string - */ - public function wpseo_posts_where( $sql, $post_type ) { - if ( pll_is_translated_post_type( $post_type ) ) { - if ( PLL()->options['force_lang'] > 1 ) { - return $sql . PLL()->model->post->where_clause( PLL()->curlang ); - } - - if ( $languages = $this->wpseo_get_active_languages() ) { - return $sql . PLL()->model->post->where_clause( $languages ); - } - } - return $sql; - } - - /** - * Removes the language filter (and remove inactive languages) for the taxonomy sitemaps - * Only when the language is set from the content or directory name - * - * @since 1.0.3 - * - * @param array $args get_terms arguments - * @return array modified list of arguments - */ - public function wpseo_remove_terms_filter( $args ) { - if ( isset( $GLOBALS['wp_query']->query['sitemap'] ) ) { - $args['lang'] = implode( ',', $this->wpseo_get_active_languages() ); - } - return $args; - } - - /** - * Adds the home urls for all (active) languages to the sitemap - * - * @since 1.9 - * - * @param string $str additional urls to sitemap post - * @return string - */ - public function add_language_home_urls( $str ) { - global $wpseo_sitemaps; - $renderer = version_compare( WPSEO_VERSION, '3.2', '<' ) ? $wpseo_sitemaps : $wpseo_sitemaps->renderer; - - $languages = wp_list_pluck( wp_list_filter( PLL()->model->get_languages_list(), array( 'active' => false ), 'NOT' ), 'slug' ); - - foreach ( $languages as $lang ) { - if ( empty( PLL()->options['hide_default'] ) || pll_default_language() !== $lang ) { - $str .= $renderer->sitemap_url( array( - 'loc' => pll_home_url( $lang ), - 'pri' => 1, - 'chf' => apply_filters( 'wpseo_sitemap_homepage_change_freq', 'daily', pll_home_url( $lang ) ), - ) ); - } - } - return $str; - } - - /** - * Filters home url - * - * @since 1.1.2 - * - * @param array $arr - * @return array - */ - public function wpseo_home_url_white_list( $arr ) { - return array_merge( $arr, array( array( 'file' => 'wordpress-seo' ) ) ); - } - - /** - * Adds opengraph support for translations - * - * @since 1.6 - */ - public function wpseo_ogp() { - global $wpseo_og; - - // WPSEO already deals with the locale - if ( did_action( 'pll_init' ) && method_exists( $wpseo_og, 'og_tag' ) ) { - foreach ( PLL()->model->get_languages_list() as $language ) { - if ( PLL()->curlang->slug !== $language->slug && PLL()->links->get_translation_url( $language ) && isset( $language->facebook ) ) { - $wpseo_og->og_tag( 'og:locale:alternate', $language->facebook ); - } - } - } - } - - /** - * Fixes the canonical front page url as unlike WP, WPSEO does not add a trailing slash to the canonical front page url - * - * @since 1.7.10 - * - * @param string $url - * @return $url - */ - public function wpseo_canonical( $url ) { - return is_front_page( $url ) && get_option( 'permalink_structure' ) ? trailingslashit( $url ) : $url; - } - - /** - * Helper function to register strings for custom post types and custom taxonomies titles and meta descriptions - * - * @since 2.1.6 - * - * @param array $options - * @param array $titles - * @return array - */ - protected function _wpseo_register_strings( $options, $titles ) { - foreach ( $titles as $title ) { - if ( ! empty( $options[ $title ] ) ) { - pll_register_string( $title, $options[ $title ], 'wordpress-seo' ); - } - } - return $options; - } - - /** - * Synchronize the primary category - * - * @since 2.3.3 - * - * @param array $keys List of custom fields names - * @return array - */ - public function copy_post_metas( $keys ) { - $keys[] = '_yoast_wpseo_primary_category'; - return $keys; - } - - /** - * Translate the primary category during the synchronization process - * - * @since 2.3.3 - * - * @param int $value Meta value - * @param string $key Meta key - * @param string $lang Language of target - * @return int - */ - public function translate_post_meta( $value, $key, $lang ) { - if ( '_yoast_wpseo_primary_category' === $key ) { - $value = pll_get_term( $value, $lang ); - } - return $value; - } -} diff --git a/wp-content/plugins/polylang/modules/share-slug/load.php b/wp-content/plugins/polylang/modules/share-slug/load.php new file mode 100644 index 00000000..7c4500b8 --- /dev/null +++ b/wp-content/plugins/polylang/modules/share-slug/load.php @@ -0,0 +1,20 @@ +model->get_languages_list() ) { + add_filter( + 'pll_settings_modules', + function( $modules ) { + $modules[] = 'PLL_Settings_Preview_Share_Slug'; + return $modules; + } + ); +} diff --git a/wp-content/plugins/polylang/modules/share-slug/settings-preview-share-slug.php b/wp-content/plugins/polylang/modules/share-slug/settings-preview-share-slug.php new file mode 100644 index 00000000..7c62c8d8 --- /dev/null +++ b/wp-content/plugins/polylang/modules/share-slug/settings-preview-share-slug.php @@ -0,0 +1,70 @@ + 'share-slugs', + 'title' => __( 'Share slugs', 'polylang' ), + 'description' => $this->get_description(), + ) + ); + } + + /** + * Returns the module description. + * + * @since 3.1 + * + * @return string + */ + protected function get_description() { + return __( 'Allows to share the same URL slug across languages for posts and terms.', 'polylang' ); + } + + /** + * Tells if the module is active. + * + * @since 1.9 + * + * @return bool + */ + public function is_active() { + return false; + } + + /** + * Displays an upgrade message. + * + * @since 1.9 + * + * @return string + */ + public function get_upgrade_message() { + return $this->default_upgrade_message(); + } +} diff --git a/wp-content/plugins/polylang/modules/share-slug/settings-share-slug.php b/wp-content/plugins/polylang/modules/share-slug/settings-share-slug.php deleted file mode 100644 index fa1e6bcf..00000000 --- a/wp-content/plugins/polylang/modules/share-slug/settings-share-slug.php +++ /dev/null @@ -1,81 +0,0 @@ - 'share-slugs', - 'title' => __( 'Share slugs', 'polylang' ), - 'description' => __( 'Allows to share the same url slug across languages for posts and terms.', 'polylang' ), - ) ); - - if ( class_exists( 'PLL_Share_Post_Slug', true ) && get_option( 'permalink_structure' ) ) { - add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) ); - } - } - - /** - * tells if the module is active - * - * @since 1.9 - * - * @return bool - */ - public function is_active() { - return class_exists( 'PLL_Share_Post_Slug', true ) && $this->options['force_lang'] && get_option( 'permalink_structure' ); - } - - /** - * displays upgrade message - * - * @since 1.9 - * - * @return string - */ - public function get_upgrade_message() { - return class_exists( 'PLL_Share_Post_Slug', true ) ? '' : $this->default_upgrade_message(); - } - - /** - * displays the javascript to handle dynamically the change in url modifications - * as sharing slugs is not possible when the language is set from the content - * - * @since 1.9 - */ - public function print_js() { - wp_enqueue_script( 'jquery' ); - - $activated = sprintf( '%s', $this->action_links['activated'] ); - $deactivated = sprintf( '%s', $this->action_links['deactivated'] ); - - ?> - - model = &$polylang->model; + $this->static_pages = &$polylang->static_pages; + + // Information tab. + add_filter( 'debug_information', array( $this, 'info_options' ), 15 ); + add_filter( 'debug_information', array( $this, 'info_languages' ), 15 ); + add_filter( 'debug_information', array( $this, 'info_warning' ), 15 ); + + // Tests Tab. + add_filter( 'site_status_tests', array( $this, 'status_tests' ) ); + } + + /** + * Returns a list of keys to exclude from the site health information. + * + * @since 2.8 + * + * @return string[] List of option keys to ignore. + */ + protected function exclude_options_keys() { + return array( + 'uninstall', + 'first_activation', + ); + } + + /** + * Returns a list of keys to exclude from the site health information. + * + * @since 2.8 + * + * @return string[] List of language keys to ignore. + */ + protected function exclude_language_keys() { + return array( + 'flag', + 'host', + 'taxonomy', + 'description', + 'parent', + 'filter', + 'custom_flag', + ); + } + + /** + * Formats an array to display in options information. + * + * @since 2.8 + * + * @param array $array An array of formatted data. + * @return string + */ + protected function format_array( $array ) { + array_walk( + $array, + function ( &$value, $key ) { + if ( is_array( $value ) ) { + $ids = implode( ' , ', $value ); + $value = "$key => $ids"; + } else { + $value = "$key => $value"; + } + } + ); + + return implode( ' | ', $array ); + } + + /** + * Add Polylang Options to Site Health Informations tab. + * + * @since 2.8 + * + * @param array $debug_info The debug information to be added to the core information page. + * @return array + */ + public function info_options( $debug_info ) { + $fields = array(); + foreach ( $this->model->options as $key => $value ) { + if ( in_array( $key, $this->exclude_options_keys() ) ) { + continue; + } + + if ( ! is_array( $value ) ) { + if ( empty( $value ) ) { + $value = '0'; + } + + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = $value; + } elseif ( empty( $value ) ) { + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = '0'; + } else { + switch ( $key ) { + case 'post_types': + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = implode( ', ', $this->model->get_translated_post_types() ); + break; + case 'taxonomies': + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = implode( ', ', $this->model->get_translated_taxonomies() ); + break; + case 'domains': + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = $this->format_array( $value ); + break; + case 'nav_menus': + $current_theme = get_stylesheet(); + if ( isset( $value[ $current_theme ] ) ) { + foreach ( $value[ $current_theme ] as $location => $lang ) { + /* translators: placeholder is the menu location name */ + $fields[ $location ]['label'] = sprintf( 'menu: %s', $location ); + $fields[ $location ]['value'] = $this->format_array( $lang ); + } + } + break; + case 'media': + foreach ( $value as $sub_key => $sub_value ) { + $fields[ "$key-$sub_key" ]['label'] = "$key $sub_key"; + $fields[ "$key-$sub_key" ]['value'] = $sub_value; + } + break; + default: + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = implode( ', ', $value ); + break; + } + } + } + $debug_info['pll_options'] = array( + /* translators: placeholder is the plugin name */ + 'label' => sprintf( esc_html__( '%s Options', 'polylang' ), POLYLANG ), + 'fields' => $fields, + ); + + return $debug_info; + } + + /** + * Add Polylang Languages settings to Site Health Informations tab. + * + * @since 2.8 + * + * @param array $debug_info The debug information to be added to the core information page. + * @return array + */ + public function info_languages( $debug_info ) { + foreach ( $this->model->get_languages_list() as $language ) { + $fields = array(); + + foreach ( $language as $key => $value ) { + if ( in_array( $key, $this->exclude_language_keys(), true ) ) { + continue; + } + + if ( empty( $value ) ) { + $value = '0'; + } + + $fields[ $key ]['label'] = $key; + $fields[ $key ]['value'] = $value; + + if ( 'term_group' === $key ) { + $fields[ $key ]['label'] = 'order'; // Changed for readability but not translated as other keys are not. + } + } + + $debug_info[ 'pll_language_' . $language->slug ] = array( + /* translators: placeholder is the language name */ + 'label' => sprintf( esc_html__( 'Language: %s', 'polylang' ), esc_html( $language->name ) ), + /* translators: placeholder is the flag image */ + 'description' => sprintf( esc_html__( 'Flag used in the language switcher: %s', 'polylang' ), $this->get_flag( $language ) ), + 'fields' => $fields, + ); + } + + return $debug_info; + } + + /** + * Returns the flag used in the language switcher. + * + * @since 2.8 + * + * @param PLL_Language $language Language object. + * @return string + */ + protected function get_flag( $language ) { + $flag = $language->get_display_flag(); + return empty( $flag ) ? '' . esc_html__( 'Undefined', 'polylang' ) . '' : $flag; + } + + /** + * Add a Site Health test on homepage translation. + * + * @since 2.8 + * + * @param array $tests Array with tests declaration data. + * @return array + */ + public function status_tests( $tests ) { + // Add the test only if the homepage displays static page. + if ( 'page' === get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) { + $tests['direct']['pll_homepage'] = array( + 'label' => esc_html__( 'Homepage translated', 'polylang' ), + 'test' => array( $this, 'homepage_test' ), + ); + } + return $tests; + } + + /** + * Test if the home page is translated or not. + * + * @since 2.8 + * + * @return array $result Array with test results. + */ + public function homepage_test() { + $result = array( + 'label' => esc_html__( 'All languages have a translated homepage', 'polylang' ), + 'status' => 'good', + 'badge' => array( + 'label' => POLYLANG, + 'color' => 'blue', + ), + 'description' => sprintf( + '

    %s

    ', + esc_html__( 'It is mandatory to translate the static front page in all languages.', 'polylang' ) + ), + 'actions' => '', + 'test' => 'pll_homepage', + ); + + $message = $this->static_pages->get_must_translate_message(); + + if ( ! empty( $message ) ) { + $result['status'] = 'critical'; + $result['label'] = esc_html__( 'The homepage is not translated in all languages', 'polylang' ); + $result['description'] = sprintf( '

    %s

    ', $message ); + } + return $result; + } + + /** + * Add Polylang Warnings to Site Health Informations tab. + * + * @since 3.1 + * + * @param array $debug_info The debug information to be added to the core information page. + * @return array + */ + public function info_warning( $debug_info ) { + $fields = array(); + + $posts_no_lang = $this->get_post_ids_without_lang(); + + if ( ! empty( $posts_no_lang ) ) { + $fields['post-no-lang']['label'] = __( 'Posts without language', 'polylang' ); + $fields['post-no-lang']['value'] = $this->format_array( $posts_no_lang ); + } + + $terms_no_lang = $this->get_term_ids_without_lang(); + + if ( ! empty( $terms_no_lang ) ) { + $fields['term-no-lang']['label'] = __( 'Terms without language', 'polylang' ); + $fields['term-no-lang']['value'] = $this->format_array( $terms_no_lang ); + } + + if ( ! empty( $fields ) ) { + $debug_info['pll_warnings'] = array( + 'label' => sprintf( esc_html__( 'Polylang warnings', 'polylang' ), POLYLANG ), + 'fields' => $fields, + ); + } + + return $debug_info; + } + + /** + * Get an array with post_type as key and post ids as value. + * + * @since 3.1 + * + * @param int $limit Max number of posts to show per post type. + * @return int[][] Array containing an array of post ids. + */ + public function get_post_ids_without_lang( $limit = 5 ) { + $posts = array(); + + foreach ( $this->model->get_translated_post_types() as $post_type ) { + $post_ids_with_no_language = $this->model->get_posts_with_no_lang( $post_type, $limit ); + + if ( ! empty( $post_ids_with_no_language ) ) { + foreach ( $post_ids_with_no_language as $id ) { + $posts[ $post_type ][] = $id; + } + } + } + + return $posts; + } + + /** + * Get an array with taxonomy as key and term ids as value. + * + * @since 3.1 + * + * @param int $limit Max number of terms to show per post type. + * @return int[][] Array containing an array of term ids. + */ + public function get_term_ids_without_lang( $limit = 5 ) { + $terms = array(); + + foreach ( $this->model->get_translated_taxonomies() as $taxonomy ) { + $term_ids_with_no_language = $this->model->get_terms_with_no_lang( $taxonomy, $limit ); + + if ( ! empty( $term_ids_with_no_language ) ) { + foreach ( $term_ids_with_no_language as $id ) { + $terms[ $taxonomy ][] = $id; + } + } + } + + return $terms; + } +} diff --git a/wp-content/plugins/polylang/modules/site-health/load.php b/wp-content/plugins/polylang/modules/site-health/load.php new file mode 100644 index 00000000..7e89e5fc --- /dev/null +++ b/wp-content/plugins/polylang/modules/site-health/load.php @@ -0,0 +1,14 @@ +model->get_languages_list() ) { + $polylang->site_health = new PLL_Admin_Site_Health( $polylang ); +} diff --git a/wp-content/plugins/polylang/modules/sitemaps/abstract-sitemaps.php b/wp-content/plugins/polylang/modules/sitemaps/abstract-sitemaps.php new file mode 100644 index 00000000..a74e60e3 --- /dev/null +++ b/wp-content/plugins/polylang/modules/sitemaps/abstract-sitemaps.php @@ -0,0 +1,37 @@ + 'class-wp-sitemaps-posts' ); + return $whitelist; + } +} diff --git a/wp-content/plugins/polylang/modules/sitemaps/load.php b/wp-content/plugins/polylang/modules/sitemaps/load.php new file mode 100644 index 00000000..22d7ce56 --- /dev/null +++ b/wp-content/plugins/polylang/modules/sitemaps/load.php @@ -0,0 +1,17 @@ +model->get_languages_list() ) { + if ( $polylang->links_model instanceof PLL_Links_Abstract_Domain ) { + $polylang->sitemaps = new PLL_Sitemaps_Domain( $polylang ); + } else { + $polylang->sitemaps = new PLL_Sitemaps( $polylang ); + } + $polylang->sitemaps->init(); +} diff --git a/wp-content/plugins/polylang/modules/sitemaps/multilingual-sitemaps-provider.php b/wp-content/plugins/polylang/modules/sitemaps/multilingual-sitemaps-provider.php new file mode 100644 index 00000000..e84a43fb --- /dev/null +++ b/wp-content/plugins/polylang/modules/sitemaps/multilingual-sitemaps-provider.php @@ -0,0 +1,218 @@ +name = $provider->name; + $this->object_type = $provider->object_type; + + $this->provider = $provider; + $this->links_model = &$links_model; + $this->model = &$links_model->model; + } + + /** + * Gets a URL list for a sitemap. + * + * @since 2.8 + * + * @param int $page_num Page of results. + * @param string $object_subtype Optional. Object subtype name. Default empty. + * @return array Array of URLs for a sitemap. + */ + public function get_url_list( $page_num, $object_subtype = '' ) { + return $this->provider->get_url_list( $page_num, $object_subtype ); + } + + /** + * Gets the max number of pages available for the object type. + * + * @since 2.8 + * + * @param string $object_subtype Optional. Object subtype. Default empty. + * @return int Total number of pages. + */ + public function get_max_num_pages( $object_subtype = '' ) { + return $this->provider->get_max_num_pages( $object_subtype ); + } + + /** + * Filters the query arguments to add the language. + * + * @since 2.8 + * + * @param array $args Sitemap provider WP_Query or WP_Term_Query arguments. + * @return array + */ + public static function query_args( $args ) { + if ( ! empty( self::$filter_lang ) ) { + $args['lang'] = self::$filter_lang; + } + return $args; + } + + /** + * Gets data for a given sitemap type. + * + * @since 2.8 + * + * @param string $object_subtype_name Object subtype name if any. + * @param string $lang Optionnal language name. + * @return array + */ + protected function get_sitemap_data( $object_subtype_name, $lang = '' ) { + $object_subtype_name = (string) $object_subtype_name; + + if ( ! empty( $lang ) ) { + self::$filter_lang = $lang; + } + + $return = array( + 'name' => implode( '-', array_filter( array( $object_subtype_name, $lang ) ) ), + 'pages' => $this->get_max_num_pages( $object_subtype_name ), + ); + + self::$filter_lang = ''; + return $return; + } + + /** + * Gets data about each sitemap type. + * + * @since 2.8 + * + * @return array[] Array of sitemap types including object subtype name and number of pages. + */ + public function get_sitemap_type_data() { + $sitemap_data = array(); + + add_filter( 'wp_sitemaps_posts_query_args', array( __CLASS__, 'query_args' ) ); + add_filter( 'wp_sitemaps_taxonomies_query_args', array( __CLASS__, 'query_args' ) ); + + $object_subtypes = $this->get_object_subtypes(); + + if ( empty( $object_subtypes ) ) { + foreach ( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) as $language ) { + $sitemap_data[] = $this->get_sitemap_data( '', $language ); + } + } + + switch ( $this->provider->name ) { + case 'posts': + $func = array( $this->model, 'is_translated_post_type' ); + break; + case 'taxonomies': + $func = array( $this->model, 'is_translated_taxonomy' ); + break; + default: + return $sitemap_data; + } + + foreach ( array_keys( $object_subtypes ) as $object_subtype_name ) { + if ( call_user_func( $func, $object_subtype_name ) ) { + foreach ( $this->model->get_languages_list( array( 'fields' => 'slug' ) ) as $language ) { + $sitemap_data[] = $this->get_sitemap_data( $object_subtype_name, $language ); + } + } else { + $sitemap_data[] = $this->get_sitemap_data( $object_subtype_name ); + } + } + + return $sitemap_data; + } + + /** + * Gets the URL of a sitemap entry. + * + * @since 2.8 + * + * @param string $name The name of the sitemap. + * @param int $page The page of the sitemap. + * @return string The composed URL for a sitemap entry. + */ + public function get_sitemap_url( $name, $page ) { + // Check if a language was added in $name. + $pattern = '#(' . implode( '|', $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) . ')$#'; + if ( preg_match( $pattern, $name, $matches ) ) { + $lang = $this->model->get_language( $matches[1] ); + + if ( ! empty( $lang ) ) { + $name = preg_replace( '#(-?' . $lang->slug . ')$#', '', $name ); + $url = $this->provider->get_sitemap_url( $name, $page ); + return $this->links_model->add_language_to_link( $url, $lang ); + } + } + + // If no language is present in $name, we may attempt to get the current sitemap url (e.g. in redirect_canonical() ). + if ( get_query_var( 'lang' ) ) { + $lang = $this->model->get_language( get_query_var( 'lang' ) ); + $url = $this->provider->get_sitemap_url( $name, $page ); + return $this->links_model->add_language_to_link( $url, $lang ); + } + + return $this->provider->get_sitemap_url( $name, $page ); + } + + /** + * Returns the list of supported object subtypes exposed by the provider. + * + * @since 2.8 + * + * @return array List of object subtypes objects keyed by their name. + */ + public function get_object_subtypes() { + return $this->provider->get_object_subtypes(); + } +} diff --git a/wp-content/plugins/polylang/modules/sitemaps/sitemaps-domain.php b/wp-content/plugins/polylang/modules/sitemaps/sitemaps-domain.php new file mode 100644 index 00000000..62945471 --- /dev/null +++ b/wp-content/plugins/polylang/modules/sitemaps/sitemaps-domain.php @@ -0,0 +1,71 @@ +links_model = &$polylang->links_model; + } + + /** + * Setups actions and filters. + * + * @since 3.0 + * + * @return void + */ + public function init() { + parent::init(); + + add_filter( 'wp_sitemaps_index_entry', array( $this, 'index_entry' ) ); + add_filter( 'wp_sitemaps_stylesheet_url', array( $this->links_model, 'site_url' ) ); + add_filter( 'wp_sitemaps_stylesheet_index_url', array( $this->links_model, 'site_url' ) ); + add_filter( 'home_url', array( $this, 'sitemap_url' ) ); + } + + /** + * Filters the sitemap index entries for subdomains and multiple domains. + * + * @since 2.8 + * + * @param array $sitemap_entry Sitemap entry for the post. + * @return array + */ + public function index_entry( $sitemap_entry ) { + $sitemap_entry['loc'] = $this->links_model->site_url( $sitemap_entry['loc'] ); + return $sitemap_entry; + } + + /** + * Makes sure that the sitemap urls are always evaluated on the current domain. + * + * @since 2.8.4 + * + * @param string $url A sitemap url. + * @return string + */ + public function sitemap_url( $url ) { + if ( false !== strpos( $url, '/wp-sitemap' ) ) { + $url = $this->links_model->site_url( $url ); + } + return $url; + } +} diff --git a/wp-content/plugins/polylang/modules/sitemaps/sitemaps.php b/wp-content/plugins/polylang/modules/sitemaps/sitemaps.php new file mode 100644 index 00000000..62cca439 --- /dev/null +++ b/wp-content/plugins/polylang/modules/sitemaps/sitemaps.php @@ -0,0 +1,140 @@ +links_model = &$polylang->links_model; + $this->model = &$polylang->model; + $this->options = &$polylang->options; + } + + /** + * Setups actions and filters. + * + * @since 2.8 + * + * @return void + */ + public function init() { + parent::init(); + + add_filter( 'pll_set_language_from_query', array( $this, 'set_language_from_query' ), 10, 2 ); + add_filter( 'rewrite_rules_array', array( $this, 'rewrite_rules' ) ); + add_filter( 'wp_sitemaps_add_provider', array( $this, 'replace_provider' ) ); + } + + /** + * Assigns the current language to the default language when the sitemap url + * doesn't include any language. + * + * @since 2.8 + * + * @param string|bool $lang Current language code, false if not set yet. + * @param WP_Query $query Main WP query object. + * @return string|bool + */ + public function set_language_from_query( $lang, $query ) { + if ( isset( $query->query['sitemap'] ) && empty( $query->query['lang'] ) ) { + $lang = $this->options['default_lang']; + } + return $lang; + } + + /** + * Whitelists the home url filter for the sitemaps + * + * @since 2.8 + * + * @param array $whitelist White list. + * @return array + */ + public function home_url_white_list( $whitelist ) { + $whitelist[] = array( 'file' => 'class-wp-sitemaps-posts' ); + return $whitelist; + } + + /** + * Filters the sitemaps rewrite rules to take the languages into account. + * + * @since 2.8 + * + * @param string[] $rules Rewrite rules. + * @return string[] Modified rewrite rules. + */ + public function rewrite_rules( $rules ) { + global $wp_rewrite; + + $languages = $this->model->get_languages_list( array( 'fields' => 'slug' ) ); + + if ( empty( $languages ) ) { + return $rules; + } + + if ( $this->options['hide_default'] ) { + $languages = array_diff( $languages, array( $this->options['default_lang'] ) ); + } + + $slug = $wp_rewrite->root . ( $this->options['rewrite'] ? '^' : '^language/' ) . '(' . implode( '|', $languages ) . ')/'; + + $newrules = array(); + + foreach ( $rules as $key => $rule ) { + if ( false !== strpos( $rule, 'sitemap=$matches[1]' ) ) { + $newrules[ str_replace( '^wp-sitemap', $slug . 'wp-sitemap', $key ) ] = str_replace( + array( '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '[1]', '?' ), + array( '[9]', '[8]', '[7]', '[6]', '[5]', '[4]', '[3]', '[2]', '?lang=$matches[1]&' ), + $rule + ); // Should be enough! + } + + $newrules[ $key ] = $rule; + } + return $newrules; + } + + /** + * Replaces a sitemap provider by our decorator. + * + * @since 2.8 + * + * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider. + * @return WP_Sitemaps_Provider + */ + public function replace_provider( $provider ) { + if ( $provider instanceof WP_Sitemaps_Provider ) { + $provider = new PLL_Multilingual_Sitemaps_Provider( $provider, $this->links_model ); + } + return $provider; + } +} diff --git a/wp-content/plugins/polylang/modules/sync/admin-sync.php b/wp-content/plugins/polylang/modules/sync/admin-sync.php index e28eceec..1651da81 100644 --- a/wp-content/plugins/polylang/modules/sync/admin-sync.php +++ b/wp-content/plugins/polylang/modules/sync/admin-sync.php @@ -1,12 +1,14 @@ model = &$polylang->model; - $this->options = &$polylang->options; - - $this->taxonomies = new PLL_Sync_Tax( $polylang ); - $this->post_metas = new PLL_Sync_Post_Metas( $polylang ); - $this->term_metas = new PLL_Sync_Term_Metas( $polylang ); + parent::__construct( $polylang ); add_filter( 'wp_insert_post_parent', array( $this, 'wp_insert_post_parent' ), 10, 3 ); - add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 5, 2 ); // Before Types which populates custom fields in same hook with priority 10 - - add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 ); - add_action( 'pll_save_term', array( $this, 'sync_term_parent' ), 10, 3 ); - - if ( $this->options['media_support'] ) { - add_action( 'pll_translate_media', array( $this->taxonomies, 'copy' ), 10, 3 ); - add_action( 'pll_translate_media', array( $this->post_metas, 'copy' ), 10, 3 ); - add_action( 'edit_attachment', array( $this, 'edit_attachment' ) ); - } - - add_filter( 'pre_update_option_sticky_posts', array( $this, 'sync_sticky_posts' ), 10, 2 ); + add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ) ); + add_filter( 'use_block_editor_for_post', array( $this, 'new_post_translation' ), 5000 ); // After content duplication. } /** @@ -49,121 +36,148 @@ class PLL_Admin_Sync { * @return int */ public function wp_insert_post_parent( $post_parent, $post_id, $postarr ) { - // Make sure not to impact media translations created at the same time - return isset( $_GET['from_post'], $_GET['new_lang'], $_GET['post_type'] ) && $_GET['post_type'] === $postarr['post_type'] && ( $id = wp_get_post_parent_id( (int) $_GET['from_post'] ) ) && ( $parent = $this->model->post->get_translation( $id, $_GET['new_lang'] ) ) ? $parent : $post_parent; + if ( isset( $_GET['from_post'], $_GET['new_lang'], $_GET['post_type'] ) ) { + check_admin_referer( 'new-post-translation' ); + // Make sure not to impact media translations created at the same time + if ( $_GET['post_type'] === $postarr['post_type'] && ( $id = wp_get_post_parent_id( (int) $_GET['from_post'] ) ) && $parent = $this->model->post->get_translation( $id, sanitize_key( $_GET['new_lang'] ) ) ) { + $post_parent = $parent; + } + } + return $post_parent; } /** - * Copy post metas, menu order, comment and ping status when using "Add new" ( translation ) - * formerly used dbx_post_advanced deprecated in WP 3.7 + * Copy menu order, comment, ping status and optionally the date when creating a new tanslation * - * @since 1.2 + * @since 2.5 * - * @param string $post_type unused - * @param object $post current post object + * @param array $data An array of slashed post data. + * @return array */ - public function add_meta_boxes( $post_type, $post ) { - if ( 'post-new.php' == $GLOBALS['pagenow'] && isset( $_GET['from_post'], $_GET['new_lang'] ) && $this->model->is_translated_post_type( $post->post_type ) ) { + public function wp_insert_post_data( $data ) { + if ( isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $data['post_type'] ) ) { + check_admin_referer( 'new-post-translation' ); + + $from_post_id = (int) $_GET['from_post']; + $from_post = get_post( $from_post_id ); + + if ( $from_post instanceof WP_Post ) { + foreach ( array( 'menu_order', 'comment_status', 'ping_status' ) as $property ) { + $data[ $property ] = $from_post->$property; + } + + // Copy the date only if the synchronization is activated + if ( in_array( 'post_date', $this->options['sync'] ) ) { + $data['post_date'] = $from_post->post_date; + $data['post_date_gmt'] = $from_post->post_date_gmt; + } + } + } + + return $data; + } + + /** + * Copy post metas, and taxonomies when using "Add new" ( translation ) + * + * @since 2.5 + * @since 3.1 Use of use_block_editor_for_post filter instead of rest_api_init which is triggered too early in WP 5.8. + * + * @param bool $is_block_editor Whether the post can be edited or not. + * @return bool + */ + public function new_post_translation( $is_block_editor ) { + global $post; + static $done = array(); + + if ( ! empty( $post ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] && $this->model->is_translated_post_type( $post->post_type ) ) { + check_admin_referer( 'new-post-translation' ); + // Capability check already done in post-new.php $from_post_id = (int) $_GET['from_post']; - $from_post = get_post( $from_post_id ); - $lang = $this->model->get_language( $_GET['new_lang'] ); + $lang = $this->model->get_language( sanitize_key( $_GET['new_lang'] ) ); - if ( ! $from_post || ! $lang ) { - return; + if ( ! $from_post_id || ! $lang || ! empty( $done[ $from_post_id ] ) ) { + return $is_block_editor; } + $done[ $from_post_id ] = true; // Avoid a second duplication in the block editor. Using an array only to allow multiple phpunit tests. + $this->taxonomies->copy( $from_post_id, $post->ID, $lang->slug ); $this->post_metas->copy( $from_post_id, $post->ID, $lang->slug ); - foreach ( array( 'menu_order', 'comment_status', 'ping_status' ) as $property ) { - $post->$property = $from_post->$property; - } - - // Copy the date only if the synchronization is activated - if ( in_array( 'post_date', $this->options['sync'] ) ) { - $post->post_date = $from_post->post_date; - $post->post_date_gmt = $from_post->post_date_gmt; - } - if ( is_sticky( $from_post_id ) ) { stick_post( $post->ID ); } } + + return $is_block_editor; } /** - * Synchronizes post fields in translations + * Get post fields to synchronize. + * + * @since 2.4 + * + * @param WP_Post $post Post object. + * @return array Fields to synchronize. + */ + protected function get_fields_to_sync( $post ) { + global $wpdb; + + $postarr = parent::get_fields_to_sync( $post ); + + // For new drafts, save the date now otherwise it is overriden by WP. Thanks to JoryHogeveen. See #32. + if ( in_array( 'post_date', $this->options['sync'] ) && isset( $GLOBALS['pagenow'], $_GET['from_post'], $_GET['new_lang'] ) && 'post-new.php' === $GLOBALS['pagenow'] ) { + check_admin_referer( 'new-post-translation' ); + + unset( $postarr['post_date'] ); + unset( $postarr['post_date_gmt'] ); + + $original = get_post( (int) $_GET['from_post'] ); + + if ( $original instanceof WP_Post ) { + $wpdb->update( + $wpdb->posts, + array( + 'post_date' => $original->post_date, + 'post_date_gmt' => $original->post_date_gmt, + ), + array( 'ID' => $post->ID ) + ); + } + } + + if ( isset( $GLOBALS['post_type'] ) ) { + $post_type = $GLOBALS['post_type']; + } elseif ( isset( $_REQUEST['post_type'] ) ) { + $post_type = sanitize_key( $_REQUEST['post_type'] ); // 2nd case for quick edit + } + + // Make sure not to impact media translations when creating them at the same time as post + if ( in_array( 'post_parent', $this->options['sync'] ) && ( ! isset( $post_type ) || $post_type !== $post->post_type ) ) { + unset( $postarr['post_parent'] ); + } + + return $postarr; + } + + /** + * Synchronizes post fields in translations. * * @since 1.2 * - * @param int $post_id post id - * @param object $post post object - * @param array $translations post translations + * @param int $post_id Post id. + * @param WP_Post $post Post object. + * @param int[] $translations Post translations. */ public function pll_save_post( $post_id, $post, $translations ) { - global $wpdb; - - // Prepare properties to synchronize - foreach ( array( 'comment_status', 'ping_status', 'menu_order' ) as $property ) { - if ( in_array( $property, $this->options['sync'] ) ) { - $postarr[ $property ] = $post->$property; - } - } - - if ( in_array( 'post_date', $this->options['sync'] ) ) { - // For new drafts, save the date now otherwise it is overriden by WP. Thanks to JoryHogeveen. See #32. - if ( 'post-new.php' === $GLOBALS['pagenow'] && isset( $_GET['from_post'], $_GET['new_lang'] ) ) { - $original = get_post( (int) $_GET['from_post'] ); - $wpdb->update( - $wpdb->posts, array( - 'post_date' => $original->post_date, - 'post_date_gmt' => $original->post_date_gmt, - ), - array( 'ID' => $post_id ) - ); - } else { - $postarr['post_date'] = $post->post_date; - $postarr['post_date_gmt'] = $post->post_date_gmt; - } - } - - foreach ( $translations as $lang => $tr_id ) { - if ( ! $tr_id || $tr_id === $post_id ) { - continue; - } - - // Add comment status, ping status, menu order... to synchronization - $tr_arr = empty( $postarr ) ? array() : $postarr; - - if ( isset( $GLOBALS['post_type'] ) ) { - $post_type = $GLOBALS['post_type']; - } elseif ( isset( $_REQUEST['post_type'] ) ) { - $post_type = $_REQUEST['post_type']; // 2nd case for quick edit - } - - // Add post parent to synchronization - // Make sure not to impact media translations when creating them at the same time as post - // Do not udpate the translation parent if the user set a parent with no translation - if ( in_array( 'post_parent', $this->options['sync'] ) && isset( $post_type ) && $post_type === $post->post_type ) { - $post_parent = ( $parent_id = wp_get_post_parent_id( $post_id ) ) ? $this->model->post->get_translation( $parent_id, $lang ) : 0; - if ( ! ( $parent_id && ! $post_parent ) ) { - $tr_arr['post_parent'] = $post_parent; - } - } - - // Update all the row at once - // Don't use wp_update_post to avoid infinite loop - if ( ! empty( $tr_arr ) ) { - $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) ); - clean_post_cache( $tr_id ); - } - } + parent::pll_save_post( $post_id, $post, $translations ); // Sticky posts if ( in_array( 'sticky_posts', $this->options['sync'] ) ) { $stickies = get_option( 'sticky_posts' ); - if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) { + if ( isset( $_REQUEST['sticky'] ) && 'sticky' === $_REQUEST['sticky'] ) { // phpcs:ignore WordPress.Security.NonceVerification $stickies = array_merge( $stickies, array_values( $translations ) ); } else { $stickies = array_diff( $stickies, array_values( $translations ) ); @@ -172,78 +186,6 @@ class PLL_Admin_Sync { } } - /** - * Synchronize term parent in translations - * Calling clean_term_cache *after* this is mandatory otherwise the $taxonomy_children option is not correctly updated - * Before WP 3.9 clean_term_cache could be called ( efficiently ) only one time due to static array which prevented to update the option more than once - * This is the reason to use the edit_term filter and not edited_term - * - * @since 2.3 - * - * @param int $term_id Term id - * @param string $taxonomy Taxonomy name - * @param array $translations The list of translations term ids - */ - public function sync_term_parent( $term_id, $taxonomy, $translations ) { - global $wpdb; - - if ( is_taxonomy_hierarchical( $taxonomy ) && $this->model->is_translated_taxonomy( $taxonomy ) ) { - $term = get_term( $term_id ); - - foreach ( $translations as $lang => $tr_id ) { - if ( ! empty( $tr_id ) && $tr_id !== $term_id ) { - $tr_parent = $this->model->term->get_translation( $term->parent, $lang ); - - $wpdb->update( - $wpdb->term_taxonomy, - array( 'parent' => isset( $tr_parent ) ? $tr_parent : 0 ), - array( 'term_taxonomy_id' => get_term( (int) $tr_id, $taxonomy )->term_taxonomy_id ) - ); - - clean_term_cache( $tr_id, $taxonomy ); // OK since WP 3.9 - } - } - } - } - - /** - * Synchronizes terms and metas in translations for media - * - * @since 1.8 - * - * @param int $post_id post id - */ - public function edit_attachment( $post_id ) { - $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) ); - } - - /** - * Synchronize sticky posts - * - * @since 2.3 - * - * @param array $value New option value - * @param array $old_value Old option value - * @return array - */ - public function sync_sticky_posts( $value, $old_value ) { - if ( in_array( 'sticky_posts', $this->options['sync'] ) ) { - // Stick post - if ( $sticked = array_diff( $value, $old_value ) ) { - $translations = $this->model->post->get_translations( reset( $sticked ) ); - $value = array_unique( array_merge( $value, array_values( $translations ) ) ); - } - - // Unstick post - if ( $unsticked = array_diff( $old_value, $value ) ) { - $translations = $this->model->post->get_translations( reset( $unsticked ) ); - $value = array_unique( array_diff( $value, array_values( $translations ) ) ); - } - } - - return $value; - } - /** * Some backward compatibility with Polylang < 2.3 * allows to call PLL()->sync->copy_post_metas() and PLL()->sync->copy_taxonomies() @@ -254,24 +196,38 @@ class PLL_Admin_Sync { * * @param string $func Function name * @param array $args Function arguments + * @return mixed|void */ public function __call( $func, $args ) { $obj = substr( $func, 5 ); if ( is_object( $this->$obj ) && method_exists( $this->$obj, 'copy' ) ) { if ( WP_DEBUG ) { - $debug = debug_backtrace(); + $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions $i = 1 + empty( $debug[1]['line'] ); // The file and line are in $debug[2] if the function was called using call_user_func - trigger_error( sprintf( - '%1$s was called incorrectly in %3$s on line %4$s: the call to PLL()->sync->%1$s() has been deprecated in Polylang 2.3, use PLL()->sync->%2$s->copy() instead.' . "\nError handler", - $func, $obj, $debug[ $i ]['file'], $debug[ $i ]['line'] - ) ); + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions + sprintf( + '%1$s was called incorrectly in %3$s on line %4$s: the call to PLL()->sync->%1$s() has been deprecated in Polylang 2.3, use PLL()->sync->%2$s->copy() instead.' . "\nError handler", + esc_html( $func ), + esc_html( $obj ), + esc_html( $debug[ $i ]['file'] ), + absint( $debug[ $i ]['line'] ) + ) + ); } return call_user_func_array( array( $this->$obj, 'copy' ), $args ); } - $debug = debug_backtrace(); - trigger_error( sprintf( 'Call to undefined function PLL()->sync->%1$s() in %2$s on line %3$s' . "\nError handler", $func, $debug[0]['file'], $debug[0]['line'] ), E_USER_ERROR ); + $debug = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions + trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions + sprintf( + 'Call to undefined function PLL()->sync->%1$s() in %2$s on line %3$s' . "\nError handler", + esc_html( $func ), + esc_html( $debug[0]['file'] ), + absint( $debug[0]['line'] ) + ), + E_USER_ERROR + ); } } diff --git a/wp-content/plugins/polylang/modules/sync/load.php b/wp-content/plugins/polylang/modules/sync/load.php new file mode 100644 index 00000000..96a155ea --- /dev/null +++ b/wp-content/plugins/polylang/modules/sync/load.php @@ -0,0 +1,26 @@ +model->get_languages_list() ) { + if ( $polylang instanceof PLL_Admin_Base ) { + $polylang->sync = new PLL_Admin_Sync( $polylang ); + } else { + $polylang->sync = new PLL_Sync( $polylang ); + } + + add_filter( + 'pll_settings_modules', + function( $modules ) { + $modules[] = 'PLL_Settings_Sync'; + return $modules; + } + ); +} diff --git a/wp-content/plugins/polylang/modules/sync/settings-sync.php b/wp-content/plugins/polylang/modules/sync/settings-sync.php index 291e1965..1be0b7f7 100644 --- a/wp-content/plugins/polylang/modules/sync/settings-sync.php +++ b/wp-content/plugins/polylang/modules/sync/settings-sync.php @@ -1,4 +1,7 @@ 'sync', - 'title' => __( 'Synchronization', 'polylang' ), - 'description' => __( 'The synchronization options allow to maintain exact same values (or translations in the case of taxonomies and page parent) of meta content between the translations of a post or page.', 'polylang' ), - ) ); + parent::__construct( + $polylang, + array( + 'module' => 'sync', + 'title' => __( 'Synchronization', 'polylang' ), + 'description' => __( 'The synchronization options allow to maintain exact same values (or translations in the case of taxonomies and page parent) of meta content between the translations of a post or page.', 'polylang' ), + ) + ); } /** - * deactivates the module + * Deactivates the module * * @since 1.8 */ @@ -33,7 +45,7 @@ class PLL_Settings_Sync extends PLL_Settings_Module { } /** - * displays the settings form + * Displays the settings form * * @since 1.8 */ @@ -45,7 +57,7 @@ class PLL_Settings_Sync extends PLL_Settings_Module { printf( '
  • ', esc_attr( $key ), - in_array( $key, $this->options['sync'] ) ? 'checked="checked"' : '', + checked( in_array( $key, $this->options['sync'] ), true, false ), esc_html( $str ) ); } @@ -55,36 +67,36 @@ class PLL_Settings_Sync extends PLL_Settings_Module { } /** - * sanitizes the settings before saving + * Sanitizes the settings before saving * * @since 1.8 * * @param array $options */ protected function update( $options ) { - $newoptions['sync'] = empty( $options['sync'] ) ? array() : array_keys( $options['sync'], 1 ); + $newoptions = array( 'sync' => empty( $options['sync'] ) ? array() : array_keys( $options['sync'], 1 ) ); return $newoptions; // take care to return only validated options } /** - * get the row actions + * Get the row actions. * * @since 1.8 * - * @return array + * @return string[] Row actions. */ protected function get_actions() { return empty( $this->options['sync'] ) ? array( 'configure' ) : array( 'configure', 'deactivate' ); } /** - * list the post metas to synchronize + * Get the list of synchronization settings. * * @since 1.0 * - * @return array + * @return string[] Array synchronization options. */ - static public function list_metas_to_sync() { + public static function list_metas_to_sync() { return array( 'taxonomies' => __( 'Taxonomies', 'polylang' ), 'post_meta' => __( 'Custom fields', 'polylang' ), diff --git a/wp-content/plugins/polylang/modules/sync/sync-metas.php b/wp-content/plugins/polylang/modules/sync/sync-metas.php index d1a864c2..199f2b33 100644 --- a/wp-content/plugins/polylang/modules/sync/sync-metas.php +++ b/wp-content/plugins/polylang/modules/sync/sync-metas.php @@ -1,4 +1,7 @@ model = &$polylang->model; + add_filter( "add_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); + add_filter( "update_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); + add_filter( "delete_{$this->meta_type}_metadata", array( $this, 'can_synchronize_metadata' ), 1, 3 ); + $this->add_all_meta_actions(); add_action( "pll_save_{$this->meta_type}", array( $this, 'save_object' ), 10, 3 ); @@ -28,6 +58,8 @@ abstract class PLL_Sync_Metas { * Removes "added_{$this->meta_type}_meta" action * * @since 2.3 + * + * @return void */ protected function remove_add_meta_action() { remove_action( "added_{$this->meta_type}_meta", array( $this, 'add_meta' ), 10, 4 ); @@ -37,6 +69,8 @@ abstract class PLL_Sync_Metas { * Removes all meta synchronization actions and filters * * @since 2.3 + * + * @return void */ protected function remove_all_meta_actions() { $this->remove_add_meta_action(); @@ -52,6 +86,8 @@ abstract class PLL_Sync_Metas { * Adds "added_{$this->meta_type}_meta" action * * @since 2.3 + * + * @return void */ protected function restore_add_meta_action() { add_action( "added_{$this->meta_type}_meta", array( $this, 'add_meta' ), 10, 4 ); @@ -61,6 +97,8 @@ abstract class PLL_Sync_Metas { * Adds meta synchronization actions and filters * * @since 2.3 + * + * @return void */ protected function add_all_meta_actions() { $this->restore_add_meta_action(); @@ -100,32 +138,58 @@ abstract class PLL_Sync_Metas { } /** - * Get the custom fields to copy or synchronize + * Get the custom fields to copy or synchronize. * * @since 2.3 * - * @param int $from Id of the post from which we copy informations - * @param int $to Id of the post to which we paste informations - * @param string $lang Language slug - * @param bool $sync True if it is synchronization, false if it is a copy - * @return array List of meta keys + * @param int $from Id of the post from which we copy informations. + * @param int $to Id of the post to which we paste informations. + * @param string $lang Language slug. + * @param bool $sync True if it is synchronization, false if it is a copy. + * @return string[] List of meta keys. */ protected function get_metas_to_copy( $from, $to, $lang, $sync = false ) { /** - * Filter the custom fields to copy or synchronize + * Filters the custom fields to copy or synchronize. * * @since 0.6 * @since 1.9.2 The `$from`, `$to`, `$lang` parameters were added. * - * @param array $keys List of custom fields names - * @param bool $sync True if it is synchronization, false if it is a copy - * @param int $from Id of the post from which we copy informations - * @param int $to Id of the post to which we paste informations - * @param string $lang Language slug + * @param string[] $keys List of custom fields names. + * @param bool $sync True if it is synchronization, false if it is a copy. + * @param int $from Id of the post from which we copy informations. + * @param int $to Id of the post to which we paste informations. + * @param string $lang Language slug. */ return array_unique( apply_filters( "pll_copy_{$this->meta_type}_metas", array(), $sync, $from, $to, $lang ) ); } + /** + * Disallow modifying synchronized meta if the current user can not modify translations + * + * @since 2.6 + * + * @param null|bool $check Whether to allow adding/updating/deleting metadata. + * @param int $id Object ID. + * @param string $meta_key Meta key. + * @return null|bool + */ + public function can_synchronize_metadata( $check, $id, $meta_key ) { + if ( ! $this->model->{$this->meta_type}->current_user_can_synchronize( $id ) ) { + $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); + + foreach ( $tr_ids as $lang => $tr_id ) { + if ( $tr_id != $id ) { + $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); + if ( in_array( $meta_key, $to_copy ) ) { + return false; + } + } + } + } + return $check; + } + /** * Synchronize added metas across translations * @@ -135,6 +199,7 @@ abstract class PLL_Sync_Metas { * @param int $id Object ID. * @param string $meta_key Meta key. * @param mixed $meta_value Meta value. Must be serializable if non-scalar. + * @return void */ public function add_meta( $mid, $id, $meta_key, $meta_value ) { static $avoid_recursion = false; @@ -144,11 +209,11 @@ abstract class PLL_Sync_Metas { $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); foreach ( $tr_ids as $lang => $tr_id ) { - if ( $tr_id !== $id ) { + if ( $tr_id != $id ) { $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); if ( in_array( $meta_key, $to_copy ) ) { $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); - add_metadata( $this->meta_type, $tr_id, $meta_key, $meta_value ); + add_metadata( $this->meta_type, $tr_id, wp_slash( $meta_key ), is_object( $meta_value ) ? $meta_value : wp_slash( $meta_value ) ); } } } @@ -186,6 +251,7 @@ abstract class PLL_Sync_Metas { * @param int $id Object ID. * @param string $meta_key Meta key. * @param mixed $meta_value Meta value. Must be serializable if non-scalar. + * @return void */ public function update_meta( $mid, $id, $meta_key, $meta_value ) { static $avoid_recursion = false; @@ -194,22 +260,22 @@ abstract class PLL_Sync_Metas { $avoid_recursion = true; $hash = md5( "$id|$meta_key|" . maybe_serialize( $meta_value ) ); - $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); + $prev_meta = get_metadata_by_mid( $this->meta_type, $mid ); - foreach ( $tr_ids as $lang => $tr_id ) { - if ( $tr_id != $id ) { - $to_copy = $this->get_metas_to_copy( $id, $tr_id, $lang, true ); - if ( in_array( $meta_key, $to_copy ) ) { - $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); - $prev_meta = get_metadata_by_mid( $this->meta_type, $mid ); + if ( $prev_meta ) { + $this->remove_add_meta_action(); // We don't want to sync back the new metas + $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); + + foreach ( $tr_ids as $lang => $tr_id ) { + if ( $tr_id != $id && in_array( $meta_key, $this->get_metas_to_copy( $id, $tr_id, $lang, true ) ) ) { if ( empty( $this->prev_value[ $hash ] ) || $this->prev_value[ $hash ] === $prev_meta->meta_value ) { $prev_value = $this->maybe_translate_value( $prev_meta->meta_value, $meta_key, $id, $tr_id, $lang ); - $this->remove_add_meta_action(); // We don't want to sync back the new metas - update_metadata( $this->meta_type, $tr_id, $meta_key, $meta_value, $prev_value ); - $this->restore_add_meta_action(); + $meta_value = $this->maybe_translate_value( $meta_value, $meta_key, $id, $tr_id, $lang ); + update_metadata( $this->meta_type, $tr_id, wp_slash( $meta_key ), is_object( $meta_value ) ? $meta_value : wp_slash( $meta_value ), $prev_value ); } } } + $this->restore_add_meta_action(); } unset( $this->prev_value[ $hash ] ); @@ -218,12 +284,13 @@ abstract class PLL_Sync_Metas { } /** - * Store metas to synchronize before deleting them + * Store metas to synchronize before deleting them. * * @since 2.3 * - * @param array $mids Not used + * @param int[] $mids Not used. * @param int $id Object ID. + * @return void */ public function store_metas_to_sync( $mids, $id ) { $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); @@ -234,14 +301,15 @@ abstract class PLL_Sync_Metas { } /** - * Synchronize deleted meta across translations + * Synchronizes deleted meta across translations. * * @since 2.3 * - * @param array $mids Not used + * @param int[] $mids Not used. * @param int $id Object ID. * @param string $key Meta key. * @param mixed $value Meta value. + * @return void */ public function delete_meta( $mids, $id, $key, $value ) { static $avoid_recursion = false; @@ -252,12 +320,12 @@ abstract class PLL_Sync_Metas { $tr_ids = $this->model->{$this->meta_type}->get_translations( $id ); foreach ( $tr_ids as $lang => $tr_id ) { - if ( $tr_id !== $id ) { + if ( $tr_id != $id ) { if ( in_array( $key, $this->to_copy[ $id ][ $tr_id ] ) ) { if ( '' !== $value && null !== $value && false !== $value ) { // Same test as WP $value = $this->maybe_translate_value( $value, $key, $id, $tr_id, $lang ); } - delete_metadata( $this->meta_type, $tr_id, $key, $value ); + delete_metadata( $this->meta_type, $tr_id, wp_slash( $key ), is_object( $value ) ? $value : wp_slash( $value ) ); } } } @@ -275,6 +343,7 @@ abstract class PLL_Sync_Metas { * @param int $to Id of the target object * @param string $lang Language code of the target object * @param bool $sync Optional, defaults to true. True if it is synchronization, false if it is a copy + * @return void */ public function copy( $from, $to, $lang, $sync = false ) { $this->remove_all_meta_actions(); @@ -290,7 +359,7 @@ abstract class PLL_Sync_Metas { if ( empty( $metas[ $key ] ) ) { if ( ! empty( $tr_metas[ $key ] ) ) { // If the meta key is not present in the source object, delete all values - delete_metadata( $this->meta_type, $to, $key ); + delete_metadata( $this->meta_type, $to, wp_slash( $key ) ); } } else { if ( ! empty( $tr_metas[ $key ] ) && 1 === count( $metas[ $key ] ) && 1 === count( $tr_metas[ $key ] ) ) { @@ -298,18 +367,18 @@ abstract class PLL_Sync_Metas { $value = reset( $metas[ $key ] ); $value = maybe_unserialize( $value ); $to_value = $this->maybe_translate_value( $value, $key, $from, $to, $lang ); - update_metadata( $this->meta_type, $to, $key, $to_value ); + update_metadata( $this->meta_type, $to, wp_slash( $key ), is_object( $to_value ) ? $to_value : wp_slash( $to_value ) ); } else { // Multiple custom fields, either in the source or the target if ( ! empty( $tr_metas[ $key ] ) ) { // The synchronization of multiple values custom fields is easier if we delete all metas first - delete_metadata( $this->meta_type, $to, $key ); + delete_metadata( $this->meta_type, $to, wp_slash( $key ) ); } foreach ( $metas[ $key ] as $value ) { $value = maybe_unserialize( $value ); $to_value = $this->maybe_translate_value( $value, $key, $from, $to, $lang ); - add_metadata( $this->meta_type, $to, $key, $to_value ); + add_metadata( $this->meta_type, $to, wp_slash( $key ), is_object( $to_value ) ? $to_value : wp_slash( $to_value ) ); } } } @@ -324,15 +393,14 @@ abstract class PLL_Sync_Metas { * * @since 2.3 * - * @param int $object_id Id of the object being asaved - * @param object $obj Not used - * @param array $translations The list of translations object ids + * @param int $object_id Id of the object being saved. + * @param object $obj Not used. + * @param int[] $translations The list of translations object ids. + * @return void */ public function save_object( $object_id, $obj, $translations ) { - $src_lang = array_search( $object_id, $translations ); - foreach ( $translations as $tr_lang => $tr_id ) { - if ( $tr_id !== $object_id ) { + if ( $tr_id != $object_id ) { $this->copy( $object_id, $tr_id, $tr_lang, true ); } } diff --git a/wp-content/plugins/polylang/modules/sync/sync-post-metas.php b/wp-content/plugins/polylang/modules/sync/sync-post-metas.php index fa7f8960..04fbad0e 100644 --- a/wp-content/plugins/polylang/modules/sync/sync-post-metas.php +++ b/wp-content/plugins/polylang/modules/sync/sync-post-metas.php @@ -1,4 +1,7 @@ options['media_support'] ) { - $keys[] = '_wp_attachment_is_custom_header'; + $keys[] = '_wp_attached_file'; + $keys[] = '_wp_attachment_metadata'; + $keys[] = '_wp_attachment_backup_sizes'; + $keys[] = '_wp_attachment_is_custom_header'; // Random header image } /** This filter is documented in modules/sync/sync-metas.php */ diff --git a/wp-content/plugins/polylang/modules/sync/sync-tax.php b/wp-content/plugins/polylang/modules/sync/sync-tax.php index 625d338f..11e480be 100644 --- a/wp-content/plugins/polylang/modules/sync/sync-tax.php +++ b/wp-content/plugins/polylang/modules/sync/sync-tax.php @@ -1,4 +1,7 @@ model = &$polylang->model; + $this->model = &$polylang->model; $this->options = &$polylang->options; add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 ); @@ -25,16 +40,16 @@ class PLL_Sync_Tax { } /** - * Get the list of taxonomies to copy or to synchronize + * Get the list of taxonomies to copy or to synchronize. * * @since 1.7 * @since 2.1 The `$from`, `$to`, `$lang` parameters were added. * - * @param bool $sync True if it is synchronization, false if it is a copy - * @param int $from Id of the post from which we copy informations, optional, defaults to null - * @param int $to Id of the post to which we paste informations, optional, defaults to null - * @param string $lang Language slug, optional, defaults to null - * @return array List of taxonomy names + * @param bool $sync True if it is synchronization, false if it is a copy. + * @param int $from Id of the post from which we copy informations, optional, defaults to null. + * @param int $to Id of the post to which we paste informations, optional, defaults to null. + * @param string $lang Language slug, optional, defaults to null. + * @return string[] List of taxonomy names. */ protected function get_taxonomies_to_copy( $sync, $from = null, $to = null, $lang = null ) { $taxonomies = ! $sync || in_array( 'taxonomies', $this->options['sync'] ) ? $this->model->get_translated_taxonomies() : array(); @@ -43,16 +58,16 @@ class PLL_Sync_Tax { } /** - * Filter the taxonomies to copy or synchronize + * Filters the taxonomies to copy or synchronize. * * @since 1.7 * @since 2.1 The `$from`, `$to`, `$lang` parameters were added. * - * @param array $taxonomies List of taxonomy names - * @param bool $sync True if it is synchronization, false if it is a copy - * @param int $from Id of the post from which we copy informations - * @param int $to Id of the post to which we paste informations - * @param string $lang Language slug + * @param string[] $taxonomies List of taxonomy names. + * @param bool $sync True if it is synchronization, false if it is a copy. + * @param int $from Id of the post from which we copy informations. + * @param int $to Id of the post to which we paste informations. + * @param string $lang Language slug. */ return array_unique( apply_filters( 'pll_copy_taxonomies', $taxonomies, $sync, $from, $to, $lang ) ); } @@ -62,11 +77,11 @@ class PLL_Sync_Tax { * * @since 2.3 * - * @param array $object_id Object ID - * @param array $terms List of terms ids assigned to the source post - * @param string $taxonomy Taxonomy name - * @param string $lang Language slug - * @return array List of terms ids to assign to the target post + * @param int $object_id Object ID. + * @param int[] $terms List of terms ids assigned to the source post. + * @param string $taxonomy Taxonomy name. + * @param string $lang Language slug. + * @return int[] List of terms ids to assign to the target post. */ protected function maybe_translate_terms( $object_id, $terms, $taxonomy, $lang ) { if ( is_array( $terms ) && $this->model->is_translated_taxonomy( $taxonomy ) ) { @@ -101,46 +116,81 @@ class PLL_Sync_Tax { } /** - * When assigning terms to a post, assign translated terms to the translated posts (synchronisation) + * Maybe copy taxonomy terms from one post to the other. + * + * @since 2.6 + * + * @param int $object_id Source object ID. + * @param int $tr_id Target object ID. + * @param string $lang Target language. + * @param array $terms An array of object terms. + * @param string $taxonomy Taxonomy slug. + * @param bool $append Whether to append new terms to the old terms. + * @return void + */ + protected function copy_object_terms( $object_id, $tr_id, $lang, $terms, $taxonomy, $append ) { + $to_copy = $this->get_taxonomies_to_copy( true, $object_id, $tr_id, $lang ); + + if ( in_array( $taxonomy, $to_copy ) ) { + $newterms = $this->maybe_translate_terms( $object_id, $terms, $taxonomy, $lang ); + + // For some reasons, the user may have untranslated terms in the translation. Don't forget them. + if ( $this->model->is_translated_taxonomy( $taxonomy ) ) { + $tr_terms = get_the_terms( $tr_id, $taxonomy ); + if ( is_array( $tr_terms ) ) { + foreach ( $tr_terms as $term ) { + if ( ! $this->model->term->get_translation( $term->term_id, $this->model->post->get_language( $object_id ) ) ) { + $newterms[] = (int) $term->term_id; + } + } + } + } + + wp_set_object_terms( $tr_id, $newterms, $taxonomy, $append ); + } + + } + + /** + * When assigning terms to a post, assign translated terms to the translated posts (synchronisation). * * @since 2.3 * * @param int $object_id Object ID. * @param array $terms An array of object terms. - * @param array $tt_ids An array of term taxonomy IDs. + * @param int[] $tt_ids An array of term taxonomy IDs. * @param string $taxonomy Taxonomy slug. * @param bool $append Whether to append new terms to the old terms. + * @return void */ public function set_object_terms( $object_id, $terms, $tt_ids, $taxonomy, $append ) { static $avoid_recursion = false; $taxonomy_object = get_taxonomy( $taxonomy ); // Make sure that the taxonomy is registered for a post type - if ( ! $avoid_recursion && array_filter( $taxonomy_object->object_type, 'post_type_exists' ) ) { + if ( ! $avoid_recursion && ! empty( $taxonomy_object ) && array_filter( $taxonomy_object->object_type, 'post_type_exists' ) ) { $avoid_recursion = true; $tr_ids = $this->model->post->get_translations( $object_id ); foreach ( $tr_ids as $lang => $tr_id ) { if ( $tr_id !== $object_id ) { - $to_copy = $this->get_taxonomies_to_copy( true, $object_id, $tr_id, $lang ); + if ( $this->model->post->current_user_can_synchronize( $object_id ) ) { + $this->copy_object_terms( $object_id, $tr_id, $lang, $terms, $taxonomy, $append ); + } else { + // No permission to synchronize, so let's synchronize in reverse order + $orig_lang = array_search( $object_id, $tr_ids ); + $tr_terms = get_the_terms( $tr_id, $taxonomy ); - if ( in_array( $taxonomy, $to_copy ) ) { - $newterms = $this->maybe_translate_terms( $object_id, $terms, $taxonomy, $lang ); - - // For some reasons, the user may have untranslated terms in the translation. Don't forget them. - if ( $this->model->is_translated_taxonomy( $taxonomy ) ) { - $tr_terms = get_the_terms( $tr_id, $taxonomy ); - if ( is_array( $tr_terms ) ) { - foreach ( $tr_terms as $term ) { - if ( ! $this->model->term->get_translation( $term->term_id, $this->model->post->get_language( $object_id ) ) ) { - $newterms[] = (int) $term->term_id; - } - } - } + if ( false === $tr_terms ) { + $tr_terms = array(); } - wp_set_object_terms( $tr_id, $newterms, $taxonomy, $append ); + if ( is_array( $tr_terms ) ) { + $tr_terms = wp_list_pluck( $tr_terms, 'term_id' ); + $this->copy_object_terms( $tr_id, $object_id, $orig_lang, $tr_terms, $taxonomy, $append ); + } + break; } } } @@ -157,6 +207,7 @@ class PLL_Sync_Tax { * @param int $from Id of the source post * @param int $to Id of the target post * @param string $lang Language slug + * @return void */ public function copy( $from, $to, $lang ) { remove_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 6 ); @@ -165,7 +216,7 @@ class PLL_Sync_Tax { $taxonomies = array_intersect( get_post_taxonomies( $from ), $this->get_taxonomies_to_copy( false, $from, $to, $lang ) ); // Update the term cache to reduce the number of queries in the loop - update_object_term_cache( $from, get_post_type( $from ) ); + update_object_term_cache( array( $from ), get_post_type( $from ) ); // Copy foreach ( $taxonomies as $tax ) { @@ -183,32 +234,35 @@ class PLL_Sync_Tax { } /** - * When creating a new term, associate it to posts having translations associated to the translated terms + * When creating a new term, associate it to posts having translations associated to the translated terms. * * @since 2.3 * - * @param int $term_id Id of the created term - * @param string $taxonomy Taxonomy - * @param array $translations Ids of the translations of the created term + * @param int $term_id Id of the created term. + * @param string $taxonomy Taxonomy. + * @param int[] $translations Ids of the translations of the created term. + * @return void */ public function create_term( $term_id, $taxonomy, $translations ) { if ( doing_action( 'create_term' ) && in_array( $taxonomy, $this->get_taxonomies_to_copy( true ) ) ) { // Get all posts associated to the translated terms - $tr_posts = get_posts( array( - 'numberposts' => -1, - 'nopaging' => true, - 'post_type' => 'any', - 'post_status' => 'any', - 'fields' => 'ids', - 'tax_query' => array( - array( - 'taxonomy' => $taxonomy, - 'field' => 'id', - 'terms' => array_merge( array( $term_id ), array_values( $translations ) ), - 'include_children' => false, + $tr_posts = get_posts( + array( + 'numberposts' => -1, + 'nopaging' => true, + 'post_type' => 'any', + 'post_status' => 'any', + 'fields' => 'ids', + 'tax_query' => array( + array( + 'taxonomy' => $taxonomy, + 'field' => 'id', + 'terms' => array_merge( array( $term_id ), array_values( $translations ) ), + 'include_children' => false, + ), ), - ), - ) ); + ) + ); $lang = $this->model->term->get_language( $term_id ); // Language of the created term $posts = array(); @@ -224,7 +278,9 @@ class PLL_Sync_Tax { $posts = array_unique( $posts ); foreach ( $posts as $post_id ) { - wp_set_object_terms( $post_id, $term_id, $taxonomy, true ); + if ( current_user_can( 'assign_term', $term_id ) ) { + wp_set_object_terms( $post_id, $term_id, $taxonomy, true ); + } } } } @@ -234,6 +290,8 @@ class PLL_Sync_Tax { * to avoid translated terms to be removed from translated posts * * @since 2.3.2 + * + * @return void */ public function pre_delete_term() { remove_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 ); @@ -243,6 +301,8 @@ class PLL_Sync_Tax { * Re-activate the synchronization of terms after a term is deleted * * @since 2.3.2 + * + * @return void */ public function delete_term() { add_action( 'set_object_terms', array( $this, 'set_object_terms' ), 10, 5 ); diff --git a/wp-content/plugins/polylang/modules/sync/sync-term-metas.php b/wp-content/plugins/polylang/modules/sync/sync-term-metas.php index b300e174..34a8bd18 100644 --- a/wp-content/plugins/polylang/modules/sync/sync-term-metas.php +++ b/wp-content/plugins/polylang/modules/sync/sync-term-metas.php @@ -1,4 +1,7 @@ model = &$polylang->model; + $this->options = &$polylang->options; + + $this->taxonomies = new PLL_Sync_Tax( $polylang ); + $this->post_metas = new PLL_Sync_Post_Metas( $polylang ); + $this->term_metas = new PLL_Sync_Term_Metas( $polylang ); + + add_filter( 'wp_insert_post_parent', array( $this, 'can_sync_post_parent' ), 10, 3 ); + add_filter( 'wp_insert_post_data', array( $this, 'can_sync_post_data' ), 10, 2 ); + + add_action( 'pll_save_post', array( $this, 'pll_save_post' ), 10, 3 ); + add_action( 'created_term', array( $this, 'sync_term_parent' ), 10, 3 ); + add_action( 'edited_term', array( $this, 'sync_term_parent' ), 10, 3 ); + + add_action( 'pll_duplicate_term', array( $this->term_metas, 'copy' ), 10, 3 ); + + if ( $this->options['media_support'] ) { + add_action( 'pll_translate_media', array( $this->taxonomies, 'copy' ), 10, 3 ); + add_action( 'pll_translate_media', array( $this->post_metas, 'copy' ), 10, 3 ); + add_action( 'edit_attachment', array( $this, 'edit_attachment' ) ); + } + + add_filter( 'pre_update_option_sticky_posts', array( $this, 'sync_sticky_posts' ), 10, 2 ); + } + + /** + * Get post fields to synchronize. + * + * @since 2.4 + * + * @param WP_Post $post Post object. + * @return array + */ + protected function get_fields_to_sync( $post ) { + $postarr = array(); + + foreach ( array( 'comment_status', 'ping_status', 'menu_order' ) as $property ) { + if ( in_array( $property, $this->options['sync'] ) ) { + $postarr[ $property ] = $post->$property; + } + } + + if ( in_array( 'post_date', $this->options['sync'] ) ) { + $postarr['post_date'] = $post->post_date; + $postarr['post_date_gmt'] = $post->post_date_gmt; + } + + if ( in_array( 'post_parent', $this->options['sync'] ) ) { + $postarr['post_parent'] = wp_get_post_parent_id( $post->ID ); + } + + return $postarr; + } + + /** + * Prevents synchronized post parent modification if the current user hasn't enough rights + * + * @since 2.6 + * + * @param int $post_parent Post parent ID + * @param int $post_id Post ID, unused + * @param array $postarr Array of parsed post data + * @return int + */ + public function can_sync_post_parent( $post_parent, $post_id, $postarr ) { + if ( ! empty( $postarr['ID'] ) && ! $this->model->post->current_user_can_synchronize( $postarr['ID'] ) ) { + $tr_ids = $this->model->post->get_translations( $postarr['ID'] ); + foreach ( $tr_ids as $tr_id ) { + if ( $tr_id !== $postarr['ID'] && $post = get_post( $tr_id ) ) { + $post_parent = $post->post_parent; + break; + } + } + } + return $post_parent; + } + + /** + * Prevents synchronized post data modification if the current user hasn't enough rights + * + * @since 2.6 + * + * @param array $data An array of slashed post data. + * @param array $postarr An array of sanitized, but otherwise unmodified post data. + * @return array + */ + public function can_sync_post_data( $data, $postarr ) { + if ( ! empty( $postarr['ID'] ) && ! $this->model->post->current_user_can_synchronize( $postarr['ID'] ) ) { + foreach ( $this->model->post->get_translations( $postarr['ID'] ) as $tr_id ) { + if ( $tr_id !== $postarr['ID'] && $post = get_post( $tr_id ) ) { + $to_sync = $this->get_fields_to_sync( $post ); + $data = array_merge( $data, $to_sync ); + break; + } + } + } + return $data; + } + + /** + * Synchronizes post fields in translations. + * + * @since 2.4 + * + * @param int $post_id Post id. + * @param WP_Post $post Post object. + * @param int[] $translations Post translations. + * @return void + */ + public function pll_save_post( $post_id, $post, $translations ) { + global $wpdb; + + if ( $this->model->post->current_user_can_synchronize( $post_id ) ) { + $postarr = $this->get_fields_to_sync( $post ); + + if ( ! empty( $postarr ) ) { + foreach ( $translations as $lang => $tr_id ) { + if ( ! $tr_id || $tr_id === $post_id ) { + continue; + } + + $tr_arr = $postarr; + unset( $tr_arr['post_parent'] ); + + // Do not udpate the translation parent if the user set a parent with no translation. + if ( isset( $postarr['post_parent'] ) ) { + $post_parent = $postarr['post_parent'] ? $this->model->post->get_translation( $postarr['post_parent'], $lang ) : 0; + if ( ! ( $postarr['post_parent'] && ! $post_parent ) ) { + $tr_arr['post_parent'] = $post_parent; + } + } + + // Update all the rows at once. + if ( ! empty( $tr_arr ) ) { + // Don't use wp_update_post to avoid infinite loop. + $wpdb->update( $wpdb->posts, $tr_arr, array( 'ID' => $tr_id ) ); + clean_post_cache( $tr_id ); + } + } + } + } + } + + /** + * Synchronize term parent in translations + * Calling clean_term_cache *after* this is mandatory otherwise the $taxonomy_children option is not correctly updated + * + * @since 2.3 + * + * @param int $term_id Term id. + * @param int $tt_id Term taxonomy id, not used. + * @param string $taxonomy Taxonomy name. + * @return void + */ + public function sync_term_parent( $term_id, $tt_id, $taxonomy ) { + global $wpdb; + + if ( is_taxonomy_hierarchical( $taxonomy ) && $this->model->is_translated_taxonomy( $taxonomy ) ) { + $term = get_term( $term_id ); + + if ( $term instanceof WP_Term ) { + $translations = $this->model->term->get_translations( $term_id ); + + foreach ( $translations as $lang => $tr_id ) { + if ( ! empty( $tr_id ) && $tr_id !== $term_id ) { + $tr_parent = $this->model->term->get_translation( $term->parent, $lang ); + $tr_term = get_term( (int) $tr_id, $taxonomy ); + + if ( $tr_term instanceof WP_Term ) { + $wpdb->update( + $wpdb->term_taxonomy, + array( 'parent' => $tr_parent ? $tr_parent : 0 ), + array( 'term_taxonomy_id' => $tr_term->term_taxonomy_id ) + ); + + clean_term_cache( $tr_id, $taxonomy ); // OK since WP 3.9. + } + } + } + } + } + } + + /** + * Synchronizes terms and metas in translations for media + * + * @since 1.8 + * + * @param int $post_id post id + * @return void + */ + public function edit_attachment( $post_id ) { + $this->pll_save_post( $post_id, get_post( $post_id ), $this->model->post->get_translations( $post_id ) ); + } + + /** + * Synchronize sticky posts. + * + * @since 2.3 + * + * @param int[] $value New option value. + * @param int[] $old_value Old option value. + * @return int[] + */ + public function sync_sticky_posts( $value, $old_value ) { + if ( in_array( 'sticky_posts', $this->options['sync'] ) ) { + // Stick post + if ( $sticked = array_diff( $value, $old_value ) ) { + $translations = $this->model->post->get_translations( reset( $sticked ) ); + $value = array_unique( array_merge( $value, array_values( $translations ) ) ); + } + + // Unstick post + if ( $unsticked = array_diff( $old_value, $value ) ) { + $translations = $this->model->post->get_translations( reset( $unsticked ) ); + $value = array_unique( array_diff( $value, array_values( $translations ) ) ); + } + } + + return $value; + } +} diff --git a/wp-content/plugins/polylang/modules/translate-slugs/load.php b/wp-content/plugins/polylang/modules/translate-slugs/load.php new file mode 100644 index 00000000..f606c536 --- /dev/null +++ b/wp-content/plugins/polylang/modules/translate-slugs/load.php @@ -0,0 +1,20 @@ +model->get_languages_list() ) { + add_filter( + 'pll_settings_modules', + function( $modules ) { + $modules[] = 'PLL_Settings_Preview_Translate_Slugs'; + return $modules; + } + ); +} diff --git a/wp-content/plugins/polylang/modules/translate-slugs/settings-preview-translate-slugs.php b/wp-content/plugins/polylang/modules/translate-slugs/settings-preview-translate-slugs.php new file mode 100644 index 00000000..053ba4f0 --- /dev/null +++ b/wp-content/plugins/polylang/modules/translate-slugs/settings-preview-translate-slugs.php @@ -0,0 +1,70 @@ + 'translate-slugs', + 'title' => __( 'Translate slugs', 'polylang' ), + 'description' => $this->get_description(), + ) + ); + } + + /** + * Returns the module description. + * + * @since 3.1 + * + * @return string + */ + protected function get_description() { + return __( 'Allows to translate custom post types and taxonomies slugs in URLs.', 'polylang' ); + } + + /** + * Tells if the module is active. + * + * @since 1.9 + * + * @return bool + */ + public function is_active() { + return false; + } + + /** + * Displays an upgrade message. + * + * @since 1.9 + * + * @return string + */ + public function get_upgrade_message() { + return $this->default_upgrade_message(); + } +} diff --git a/wp-content/plugins/polylang/modules/translate-slugs/settings-translate-slugs.php b/wp-content/plugins/polylang/modules/translate-slugs/settings-translate-slugs.php deleted file mode 100644 index 7850fd61..00000000 --- a/wp-content/plugins/polylang/modules/translate-slugs/settings-translate-slugs.php +++ /dev/null @@ -1,45 +0,0 @@ - 'translate-slugs', - 'title' => __( 'Translate slugs', 'polylang' ), - 'description' => __( 'Allows to translate custom post types and taxonomies slugs in urls.', 'polylang' ), - ) ); - } - - /** - * tells if the module is active - * - * @since 1.9 - * - * @return bool - */ - public function is_active() { - return class_exists( 'PLL_Translate_Slugs_Model', true ) && get_option( 'permalink_structure' ); - } - - /** - * displays upgrade message - * - * @since 1.9 - * - * @return string - */ - public function get_upgrade_message() { - return class_exists( 'PLL_Translate_Slugs_Model', true ) ? '' : $this->default_upgrade_message(); - } -} diff --git a/wp-content/plugins/polylang/modules/wizard/css/wizard.css b/wp-content/plugins/polylang/modules/wizard/css/wizard.css new file mode 100644 index 00000000..b6c6a62a --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/css/wizard.css @@ -0,0 +1,951 @@ +@charset "UTF-8"; +body { + margin: 65px auto 24px; + box-shadow: none; + background: #f1f1f1; + padding: 0; + border: 0; /* fix-pro #856 override WP install.css */ +} + +#pll-logo { + border: 0; + margin: 0 0 24px; + padding: 0; + text-align: center; + font-family: sans-serif; + font-size: 64px; + text-transform: uppercase; + color: #000; + line-height: normal; +} +#pll-logo a { + display: flex; + justify-content: center; + color: #000; + text-decoration: none; +} + +#pll-logo img { + max-width: 100%; + margin-right: 16px; +} +.rtl #pll-logo img { + margin-right: 0; + margin-left: 16px; +} + +.pll-wizard-footer { + text-align: center +} + +.pll-wizard .select2-container { + text-align: left; + width: auto +} + +.pll-wizard .hidden { + display: none +} + +.pll-wizard-content { + box-shadow: 0 1px 3px rgba(0, 0, 0, .13); + padding: 2em; + margin: 0 0 20px; + background: #fff; + overflow: hidden; + zoom: 1; + text-align: left; +} +.rtl .pll-wizard-content{ + text-align: right; +} + +.pll-wizard-content h1, +.pll-wizard-content h2, +.pll-wizard-content h3, +.pll-wizard-content table { + margin: 0 0 20px; + border: 0; + padding: 0; + color: #666; + clear: none; + font-weight: 500 +} + +.pll-wizard-content p { + margin: 20px 0; + font-size: 1em; + line-height: 1.75em; + color: #666 +} + +.pll-wizard-content table { + font-size: 1em; + line-height: 1.75em; + color: #666; + width: 100%; + margin-top: 20px; +} +.pll-wizard-content table td span{ + display: inline-block; +} + +.pll-wizard-content table caption { + caption-side: bottom; + font-style: italic; + text-align: right; +} +.rtl .pll-wizard-content table caption { + text-align: left; +} + +.pll-wizard-content table caption .icon-default-lang{ + font-style: normal; +} + +.pll-wizard-content a { + color: #a03f3f; +} + +.pll-wizard-content a:focus, +.pll-wizard-content a:hover, +.pll-wizard-footer-links:hover { + color: #dd5454 +} + +.pll-wizard-content .pll-wizard-next-steps { + overflow: hidden; + margin: 0 0 24px; + padding-bottom: 2px +} + +.pll-wizard-content .pll-wizard-next-steps h2 { + margin-bottom: 12px +} + +.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-first { + float: left; + width: 50%; + box-sizing: border-box +} + +.pll-wizard-content .pll-wizard-next-steps .pll-wizard-next-steps-last { + float: right; + width: 50%; + box-sizing: border-box +} + +.pll-wizard-content .pll-wizard-next-steps ul { + padding: 0 2em 0 0; + list-style: none outside; + margin: 0 +} + +.pll-wizard-content .pll-wizard-next-steps ul li a { + display: block; + padding: 0 0 .75em +} + +.pll-wizard-content .pll-wizard-next-steps ul li a::before { + color: #82878c; + font: normal 20px/1 dashicons; + speak: none; + display: inline-block; + padding: 0 10px 0 0; + top: 1px; + position: relative; + text-decoration: none!important; + vertical-align: top +} + +.pll-wizard-steps { + padding: 0 0 24px; + margin: 0; + list-style: none outside; + overflow: hidden; + color: #ccc; + width: 100%; + display: -webkit-inline-box; + display: -webkit-inline-flex; + display: inline-flex +} + +.pll-wizard-steps li { + width: 100%; + float: left; + padding: 0 0 .8em; + margin: 0; + text-align: center; + position: relative; + border-bottom: 4px solid #ccc; + line-height: 1.4em +} + +.pll-wizard-steps li a { + color: #a03f3f; + text-decoration: none; + padding: 1.5em; + margin: -1.5em; + position: relative; + z-index: 1 +} + +.pll-wizard-steps li a:focus, +.pll-wizard-steps li a:hover { + color: #dd5454; + text-decoration: underline +} + +.pll-wizard-steps li::before { + content: ""; + border: 4px solid #ccc; + border-radius: 100%; + width: 4px; + height: 4px; + position: absolute; + bottom: 0; + left: 50%; + margin-left: -6px; + margin-bottom: -8px; + background: #fff +} + +.pll-wizard-steps li.active { + border-color: #a03f3f; + color: #a03f3f; + font-weight: 700 +} + +.pll-wizard-steps li.active::before { + border-color: #a03f3f +} + +.pll-wizard-steps li.done { + border-color: #a03f3f; + color: #a03f3f +} + +.pll-wizard-steps li.done::before { + border-color: #a03f3f; + background: #a03f3f +} + +.pll-wizard .pll-wizard-actions { + overflow: hidden; + margin: 20px 0 0; + position: relative +} + +.pll-wizard .pll-wizard-actions .button { + font-size: 16px; + font-weight: 300; + padding: 1em 2em; + line-height: 1em; + margin-right: .5em; + margin-bottom: 2px; + margin-top: 10px; + height: auto; + border-radius: 4px; + box-shadow: none; + min-width: auto; + border-color: #a03f3f; + color: #a03f3f; +} + +.pll-wizard .pll-wizard-content .button { + border-color: #a03f3f; + color: #a03f3f; +} + +.pll-wizard .pll-wizard-content .button-primary, +.pll-wizard .pll-wizard-actions .button-primary { + background-color: #a03f3f; + border-color: #a03f3f; + color: #fff; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #a03f3f; + text-shadow: 0 -1px 1px #a03f3f, 1px 0 1px #a03f3f, 0 1px 1px #a03f3f, -1px 0 1px #a03f3f; + margin: 0; + opacity: 1 +} + +.pll-wizard .pll-wizard-content .button-small .dashicons { + font-size: 15px; + height: auto; + vertical-align: middle; +} + +.pll-wizard .button-primary:active, +.pll-wizard .button-primary:focus, +.pll-wizard input[type="checkbox"]:focus + label.button-primary, +.pll-wizard .button-primary:hover { + background: #dd5454; + border-color: #dd5454; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #dd5454 +} +.pll-wizard .pll-wizard-actions .button-primary[disabled], +.pll-wizard .pll-wizard-actions .button-primary:disabled, +.pll-wizard .pll-wizard-actions .button-primary.disabled { + cursor: wait; + background-color: #bb5454 !important; + border-color: #bb5454 !important; + box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 1px 0 #bb5454 !important; + text-shadow: 0 -1px 1px #bb5454, 1px 0 1px #bb5454, 0 1px 1px #bb5454, -1px 0 1px #bb5454 !important; + color: #ffa3a3 !important; +} +.pll-wizard-content p:last-child { + margin-bottom: 0 +} + +.pll-wizard-footer-links { + font-size: .85em; + color: #7b7b7b; + margin: 1.18em auto; + display: inline-block; + text-align: center +} + +.pll-wizard-services { + border: 1px solid #eee; + padding: 0; + margin: 0 0 1em; + list-style: none outside; + border-radius: 4px; + overflow: hidden +} + +.pll-wizard-services p { + margin: 0 0 1em 0; + padding: 0; + font-size: 1em; + line-height: 1.5em +} + +.pll-wizard-service-item { + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-flex-wrap: nowrap; + flex-wrap: nowrap; + -webkit-box-pack: justify; + -webkit-justify-content: space-between; + justify-content: space-between; + padding: 0; + border-bottom: 1px solid #eee; + color: #666; + -webkit-box-align: center; + -webkit-align-items: center; + align-items: center +} + +.media-step .pll-wizard-service-item{ + border: 0; +} + +.media-step .pll-wizard-service-item:last-child{ + display: block; +} + +.media-step .pll-wizard-service-item .pll-wizard-service-enable{ + padding-bottom: 0; +} + +.pll-wizard-service-item:last-child { + border-bottom: 0 +} + +.pll-wizard-service-item .pll-wizard-service-name { + -webkit-flex-basis: 0; + flex-basis: 0; + min-width: 160px; + text-align: center; + font-weight: 700; + padding: 2em 0; + -webkit-align-self: stretch; + align-self: stretch; + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-box-align: baseline; + -webkit-align-items: baseline; + align-items: baseline +} + +.pll-wizard-service-item .pll-wizard-service-name img { + max-width: 75px +} + +.pll-wizard-service-item .pll-wizard-service-description { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + flex-grow: 1; + padding: 20px +} + +.pll-wizard-service-item .pll-wizard-service-example { + padding: 0 20px 20px +} + +.pll-wizard-service-item .pll-wizard-service-example p{ + text-align: right; +} +.rtl .pll-wizard-service-item .pll-wizard-service-example p{ + text-align: left; +} + +.pll-wizard-service-item .pll-wizard-service-description p { + margin-bottom: 1em +} + +.pll-wizard-service-item .pll-wizard-service-description p:last-child { + margin-bottom: 0 +} + +.pll-wizard-service-item .pll-wizard-service-description .pll-wizard-service-settings-description { + display: block; + font-style: italic; + color: #999 +} + +.pll-wizard-service-item .pll-wizard-service-enable { + -webkit-flex-basis: 0; + flex-basis: 0; + min-width: 75px; + text-align: center; + cursor: pointer; + padding: 2em 0; + position: relative; + max-height: 1.5em; + -webkit-align-self: flex-start; + align-self: flex-start; + -webkit-box-ordinal-group: 4; + -webkit-order: 3; + order: 3 +} + +.pll-wizard-service-item .pll-wizard-service-toggle { + position: relative +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] { + position:absolute; + opacity: 0; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label { + position: relative; + display: inline-block; + width: 44px; + height: 20px; + border-radius: 10em; + cursor: pointer; + text-indent: -9999px; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:focus + label { + border:1px dashed #777; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before, +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after { + content: ''; + position: absolute; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::before { + left: 0; + top: 0; + width: 44px; + height: 20px; + background: #ddd; + border-radius: 10em; + transition: background-color .2s; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox] + label::after { + width: 16px; + height: 16px; + transition: all .2s; + border-radius: 50%; + background: #fff; + margin: 2px; + top: 0; + left: 0; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::before { + background:#a03f3f; +} + +.pll-wizard-service-item .pll-wizard-service-toggle input[type=checkbox]:checked + label::after { + right: 0; + left:auto; +} + +.pll-wizard-service-item .pll-wizard-service-settings { + display: none; + margin-top: .75em; + margin-bottom: 0; + cursor: default +} + +.pll-wizard-service-item .pll-wizard-service-settings.hide { + display: none +} + +.pll-wizard-service-item.checked .pll-wizard-service-settings { + display: inline-block +} + +.pll-wizard-service-item.checked .pll-wizard-service-settings.hide { + display: none +} + +.pll-wizard-service-item.closed { + border-bottom: 0 +} + +.step { + text-align: center +} + +.pll-wizard .button .dashicons{ + vertical-align: middle; +} +.rtl .dashicons-arrow-right-alt2:before { + content: "\f341"; +} +.pll-wizard .pll-wizard-actions .button:active, +.pll-wizard .pll-wizard-actions .button:focus, +.pll-wizard .pll-wizard-actions .button:hover { + box-shadow: none +} + +.pll-wizard-next-steps { + border: 1px solid #eee; + border-radius: 4px; + list-style: none; + padding: 0 +} + +.pll-wizard-next-steps li { + padding: 0 +} + +.pll-wizard-next-steps .pll-wizard-next-step-item { + display: -webkit-box; + display: -webkit-flex; + display: flex; + border-top: 1px solid #eee +} + +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border, +.pll-wizard-next-steps .pll-wizard-next-step-item:first-child { + border-top: 0 +} + +.pll-wizard-next-steps .pll-wizard-next-step-description { + -webkit-box-flex: 1; + -webkit-flex-grow: 1; + flex-grow: 1; + margin: 1.5em +} + +.pll-wizard-next-steps .pll-wizard-next-step-action { + -webkit-box-flex: 0; + -webkit-flex-grow: 0; + flex-grow: 0; + display: -webkit-box; + display: -webkit-flex; + display: flex; + -webkit-box-align: center; + -webkit-align-items: center; + align-items: center +} + +.pll-wizard-next-steps .pll-wizard-next-step-action .button { + margin: 1em 1.5em +} + +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-description, +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-actions, +.pll-wizard-next-steps .pll-wizard-next-step-item.no-border .pll-wizard-next-step-action .button{ + margin-top: 0; +} + + +.pll-wizard-next-steps p.next-step-heading { + margin: 0; + font-size: .95em; + font-weight: 400; + font-variant: all-petite-caps +} + +.pll-wizard-next-steps p.next-step-extra-info { + margin: 0 +} + +.pll-wizard-next-steps h3.next-step-description { + margin: 0; + font-size: 16px; + font-weight: 600; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps { + border-top: 1px solid #eee; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-next-step-description { + margin-bottom: 0 +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions { + margin: 0 0 1.5em 0; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button { + font-size: 15px; + margin: 1em 0 1em 1.5em; +} +.rtl .pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button { + margin: 1em 1.5em 1em 0; +} + +.pll-wizard-next-steps .pll-wizard-additional-steps .pll-wizard-actions .button::last-child { + margin-right: 1.5em; +} + +.pll-wizard-content img{ + max-width: 100%; + margin-right: 0.5em; +} +.rtl .pll-wizard-content img{ + margin-left: 0.5em; +} + +.pll-wizard-content .form-field label{ + margin-bottom: 5px; + display: block; +} + +.pll-wizard-content .form-field select{ + padding: 3px; +} + +.pll-wizard-content .languages-step select, +.pll-wizard-content .untranslated-contents-step select{ + width: 100%; +} + +.languages-step .form-field .button{ + margin-left: 15px; +} +.languages-step .form-field .button > span{ + margin-right: 0.3em; +} +.rtl .languages-step .form-field .button{ + margin-left: 0; + margin-right: 15px; +} +.rtl .languages-step .form-field .button > span{ + margin-left: 0.3em; + margin-right: 0; +} + +.pll-wizard-content .languages-step .select-language-field{ + display: flex; +} + +.pll-wizard-content #languages{ + display: none; +} +.pll-wizard-content #languages tr th:first-child{ + width: 80%; +} +.pll-wizard-content #languages .dashicons{ + color: #a03f3f; +} +.pll-wizard-content #languages img{ + margin-right: 5px; +} +.pll-wizard-content .error{ + color: #a03f3f; + font-weight: bold; +} +.pll-wizard-content #messages .error{ + background: #fccfcf; + padding: 0.5rem; + border: 1px solid #a03f3f; + margin-bottom: 0.5rem; +} + +.pll-wizard-content #slide-toggle{ + position:absolute; + opacity: 0; +} + +.pll-wizard-content #slide-toggle + label{ + position:relative; +} +.pll-wizard-content #slide-toggle + label + span{ + display: block; +} + +.pll-wizard-content #slide-toggle + label .dashicons{ + margin-right: 0.3em; +} +.rtl .pll-wizard-content #slide-toggle + label .dashicons{ + margin-left: 0.3em; + margin-right: 0; +} +.pll-wizard-content #slide-toggle ~ #screenshot > img { + max-height: 500px; + margin-top: 10px; + -webkit-transition: all .5s cubic-bezier(0, 1, 0.5, 1); + transition: all .5s cubic-bezier(0, 1, 0.5, 1); +} +.pll-wizard-content #slide-toggle:checked ~ #screenshot > img { + max-height: 0; +} +.hide { + display: none; +} + +input[type="text"].field-in-error, +input[type="password"].field-in-error, +input[type="checkbox"].field-in-error, +input[type="color"].field-in-error, +input[type="date"].field-in-error, +input[type="datetime"].field-in-error, +input[type="datetime-local"].field-in-error, +input[type="email"].field-in-error, +input[type="month"].field-in-error, +input[type="number"].field-in-error, +input[type="search"].field-in-error, +input[type="radio"].field-in-error, +input[type="tel"].field-in-error, +input[type="text"].field-in-error, +input[type="time"].field-in-error, +input[type="url"].field-in-error, +input[type="week"].field-in-error, +select.field-in-error, +textarea.field-in-error, +span.field-in-error, +.field-in-error{ + border-color: #a03f3f; +} + +input[type="text"].field-in-error:focus, +input[type="password"].field-in-error:focus, +input[type="checkbox"].field-in-error:focus, +input[type="color"].field-in-error:focus, +input[type="date"].field-in-error:focus, +input[type="datetime"].field-in-error:focus, +input[type="datetime-local"].field-in-error:focus, +input[type="email"].field-in-error:focus, +input[type="month"].field-in-error:focus, +input[type="number"].field-in-error:focus, +input[type="search"].field-in-error:focus, +input[type="radio"].field-in-error:focus, +input[type="tel"].field-in-error:focus, +input[type="text"].field-in-error:focus, +input[type="time"].field-in-error:focus, +input[type="url"].field-in-error:focus, +input[type="week"].field-in-error:focus, +select.field-in-error:focus, +textarea.field-in-error:focus, +span.field-in-error:focus, +.field-in-error:focus{ + border: 1px solid #a03f3f; + box-shadow: 0 0 2px rgba(160, 63, 63, 0.8); + outline-color: #a03f3f; + outline-style: auto; + outline-width: thin; +} + +/* override install styles by returning back to forms styles */ +.form-table input.regular-text{ + width: 25em; +} +.form-table input.field-in-error{ + border-color: #a03f3f; +} +#pll-licenses-table td{ + padding: 10px 9px; +} +#pll-licenses-table .license-valid td p{ + min-width: 35em; +} +#pll-licenses-table .pll-deactivate-license{ + margin: 0 0 0 20px; +} +.rtl #pll-licenses-table .pll-deactivate-license{ + margin: 0 10px 0 0; +} +.pll-wizard-content .documentation { + padding: 24px 24px 0; + margin: 0 0 24px; + overflow: hidden; + background: #f5f5f5 +} + +.pll-wizard-content .documentation p { + padding: 0; + margin: 0 0 12px; +} +.documentation-container { + display: -webkit-box; + display: -webkit-flex; + display: flex; + justify-content: flex-end; +} + +.documentation-container .documentation-button-container { + -webkit-box-flex: 0; + -webkit-flex-grow: 0; + flex-grow: 0; +} + +.wc-setup .wc-setup-actions .button.documentation-button { + height: 42px; + padding: 0 1em; + margin: 0; +} +#dialog{ + display: none; +} +.pll-wizard .ui-dialog.ui-widget-content{ + max-height: none; +} +.pll-wizard .ui-dialog-title::before{ + content: "\f534"; + font-family: dashicons; + display: inline-block; + line-height: 1; + font-weight: 400; + font-style: normal; + speak: none; + text-decoration: inherit; + text-transform: none; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + width: 20px; + height: 20px; + font-size: 20px; + vertical-align: middle; + text-align: center; + margin: 0 5px 5px 0; + transition: color 0.1s ease-in; +} +.rtl.pll-wizard .ui-dialog-title::before{ + margin-right: 0; + margin-left: 5px; +} +.pll-wizard .ui-dialog ul{ + list-style: disc; + padding-left: 20px; +} +.rtl.pll-wizard .ui-dialog ul{ + padding-left: 0; + padding-right: 20px; +} +.pll-wizard li{ + margin-bottom: 0; +} +#translations{ + border-collapse: collapse; +} +#translations tbody:nth-child(odd){ + background-color: #f9f9f9; +} +#translations.striped > tbody > :nth-child(odd) { + background-color: transparent; /* Override common WordPress style */ +} +.pll-wizard-content mark{ + background: transparent none; +} +.pll-wizard-content mark{ + color: #7ad03a; +} +@media screen and (max-width: 782px) { + /* Override WordPress button css rules */ + .languages-step .form-field .button{ + font-size: 13px; + line-height: 26px; + height: 28px; + padding: 0 10px 1px; + vertical-align: top; + } + + #pll-licenses-table .pll-deactivate-license{ + margin: 10px 0 5px; + } +} +@media only screen and (max-width:620px) { + /* Override dialog width rule */ + .ui-dialog{ + width: 100% !important; + } + +} +@media only screen and (max-width:500px) { + #pll-logo a, + .select-language-field{ + flex-direction: column; + } + .select-language-field .action-buttons{ + display: flex; + justify-content: flex-end; + } + .languages-step .form-field .button{ + margin: 5px 0 0; + } +} +@media only screen and (max-width:400px) { + #pll-logo { + font-size: 56px; + } + .pll-wizard-steps { + display: none + } + .pll-wizard-service-item { + -webkit-flex-wrap: wrap; + flex-wrap: wrap + } + .pll-wizard-service-item .pll-wizard-service-enable { + -webkit-box-ordinal-group: 3; + -webkit-order: 2; + order: 2; + padding: 20px 0 0 + } + .pll-wizard-service-item .pll-wizard-service-description { + -webkit-box-ordinal-group: 4; + -webkit-order: 3; + order: 3 + } + .pll-wizard-service-item .pll-wizard-service-name { + padding: 20px 20px 0; + text-align: left; + -webkit-box-pack: justify!important; + -webkit-justify-content: space-between!important; + justify-content: space-between!important + } + .pll-wizard-service-item .pll-wizard-service-name img { + margin: 0 + } + .pll-wizard-next-steps .pll-wizard-next-step-item { + -webkit-flex-wrap: wrap; + flex-wrap: wrap + } + .pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-description { + margin-bottom: 0 + } + .pll-wizard-next-steps .pll-wizard-next-step-item .pll-wizard-next-step-action p { + margin: 0 + } +} +@media only screen and (max-width:360px) { + #pll-logo { + font-size: 48px; + } +} diff --git a/wp-content/plugins/polylang/modules/wizard/html-wizard-notice.php b/wp-content/plugins/polylang/modules/wizard/html-wizard-notice.php new file mode 100644 index 00000000..5e5f47cc --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/html-wizard-notice.php @@ -0,0 +1,49 @@ + 'mlang_wizard', + ), + admin_url( 'admin.php' ) +); +?> +

    + + + + +

    +

    + + + + +

    diff --git a/wp-content/plugins/polylang/modules/wizard/images/media-screen-rtl.png b/wp-content/plugins/polylang/modules/wizard/images/media-screen-rtl.png new file mode 100644 index 00000000..293e18f4 Binary files /dev/null and b/wp-content/plugins/polylang/modules/wizard/images/media-screen-rtl.png differ diff --git a/wp-content/plugins/polylang/modules/wizard/images/media-screen.png b/wp-content/plugins/polylang/modules/wizard/images/media-screen.png new file mode 100644 index 00000000..a90bf5c5 Binary files /dev/null and b/wp-content/plugins/polylang/modules/wizard/images/media-screen.png differ diff --git a/wp-content/plugins/polylang/modules/wizard/images/polylang-logo.png b/wp-content/plugins/polylang/modules/wizard/images/polylang-logo.png new file mode 100644 index 00000000..55f67c2e Binary files /dev/null and b/wp-content/plugins/polylang/modules/wizard/images/polylang-logo.png differ diff --git a/wp-content/plugins/polylang/modules/wizard/js/languages-step.js b/wp-content/plugins/polylang/modules/wizard/js/languages-step.js new file mode 100644 index 00000000..2f9cd496 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/js/languages-step.js @@ -0,0 +1,302 @@ +/** + * @package Polylang + */ + +jQuery( + function( $ ) { + var addLanguageForm = $( '.languages-step' ); // Form element. + var languageFields = $( '#language-fields' ); // Element where to append hidden fields for creating language. + var languagesTable = $( '#languages' ); // Table element contains languages list to create. + var languagesListTable = $( '#languages tbody' ); // Table rows with languages list to create. + var definedLanguagesListTable = $( '#defined-languages tbody' ); // Table rows with already defined languages list. + var languagesList = $( '#lang_list' ); // Select form element with predefined languages without already created languages. + var nextStepButton = $( '[name="save_step"]' ); // The button for continuing to the next step. + var messagesContainer = $( '#messages' ); // Element where to display error messages. + var languagesMap = new Map(); // Languages map object for managing the languages to create. + var dialog = $( '#dialog' ); // Dialog box for alerting the language selected has not been added to the list. + + /** + * Add a language in the list to create it in Polylang settings + * + * @param {object} language The language object + */ + function addLanguage( language ) { + // language properties come from the select dropdown which is built server side and well escaped. + // see template view-wizard-step-languages.php. + var languageValueHtml = $( '' ).text( language.text ).prepend( language.flagUrl ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + var languageTrashIconHtml = $( '' ) + .append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ) + .addClass( 'dashicons dashicons-trash' ) + .attr( 'data-language', language.locale ) + .append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ) + .addClass( 'screen-reader-text' ) + .text( pll_wizard_params.i18n_remove_language_icon ) + ) + ); + // see the comment and the harcoded code above. languageTrashIconHtml and languageValueHtml are safe. + var languageLineHtml = $( '' ).prepend( languageTrashIconHtml ).prepend( languageValueHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + var languageFieldHtml = $( '' ).attr( + { + type: 'hidden', + name: 'languages[]' + } + ).val( language.locale ); + + languagesList.val( '' ); + languagesList.selectmenu( 'refresh' ); // Refresh jQuery selectmenu widget after changing the value. + + languagesMap.set( language.locale, language ); + + // see above how languageLineHtml is built. + languagesListTable.append( languageLineHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + // Bind click event on trash icon. + languagesListTable.on( + 'click', + 'span[data-language=' + language.locale + ']', + function( event ) { + event.preventDefault(); + // Remove line in languages table. + $( this ).parents( 'tr' ).remove(); + // Remove input field. + var languageField = languageFields.children( 'input[value=' + $( this ).data( 'language' ) + ']' ).remove(); + // If there is no more languages hide languages table. + if ( languagesListTable.children().length <= 0 ) { + languagesTable.hide(); + } + // Remove language from the Map. + languagesMap.delete( $( this ).data( 'language' ) ); + // Hide error message. + hideError(); + } + ); + // see above how languageFieldHtml is built. + // Add hidden input field for posting the form. + languageFields.append( languageFieldHtml ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + + } + + /** + * Display an error message + * + * @param {string} message The message to display + */ + function showError( message ) { + messagesContainer.empty(); + // html is harcoded and use of jQuery text method which is safe to add message value. + // In addition message is i18n value which is initialized server side in PLL_Wizard::add_step_languages and correctly escaped. + messagesContainer.prepend( $( '

    ' ).addClass( 'error' ).text( message ) ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + } + + /** + * Hide all error messages and fields in error + */ + function hideError() { + messagesContainer.empty(); + addLanguageForm.find( '.error' ).removeClass( 'error field-in-error' ); + } + + /** + * Style the field to indicate where the error is + * + * @param {object} field The jQuery element which is in error + */ + function showFieldInError( field ) { + field.addClass( 'error field-in-error' ); + } + + /** + * Focus on a specific element + * + * @param {object} field The jQuery element which will be focused + */ + function focusOnField( field ) { + field.trigger( 'focus' ); + } + + /** + * Disable a specific button + * + * @param {object} button + */ + function disableButton( button ){ + button.prop( 'disabled', true ); + // Because the button is disabled we need to add the value of the button to ensure it will pass in the request. + addLanguageForm.append( // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.append + $( '' ).prop( + { + type: 'hidden', + name: button.prop( 'name' ), + value: button.prop( 'value' ) + } + ) + ); + } + + /** + * Remove error when a new selection is done in languages list. + */ + languagesList.on( + 'selectmenuchange', + function() { + hideError();; + } + ); + /** + * Bind click event on "Add language" button + */ + $( '#add-language' ).on( + 'click', + function( event ) { + hideError(); + var selectedOption = event.currentTarget.form.lang_list.options[event.currentTarget.form.lang_list.selectedIndex]; + if ( '' !== selectedOption.value && ! languagesMap.has( selectedOption.value ) ) { + addLanguage( + { + locale: selectedOption.value, + text: selectedOption.innerText, + name: $( selectedOption ).data( 'language-name' ), + flagUrl: $( selectedOption ).data( 'flag-html' ) + } + ); + // Show table of languages. + languagesTable.show(); + // Put back the focus on the select language field after clicking on "Add language button". + focusOnField( $( '#lang_list-button' ) ); + } else { + var message = pll_wizard_params.i18n_no_language_selected; + if ( languagesMap.has( selectedOption.value ) ) { + message = pll_wizard_params.i18n_language_already_added; + } + showError( message ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + + } + } + ); + + /** + * Bind submit event on "add_lang" form + */ + addLanguageForm.on( + 'submit', + function( event ) { + // Verify if there is at least one language. + var isLanguagesAlreadyDefined = definedLanguagesListTable.children().length > 0; + var selectedLanguage = $( '#lang_list' ).val(); + if ( languagesMap.size <= 0 && ! isLanguagesAlreadyDefined ) { + if ( '' === selectedLanguage ) { + showError( pll_wizard_params.i18n_no_language_added ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + } else { + showError( pll_wizard_params.i18n_add_language_needed ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#add-language' ) ); // Put the focus on the "Add language" button. + } + return false; + } + // Verify if the language has been added in the list otherwise display a dialog box to confirm what to do. + if ( '' !== selectedLanguage ) { + // Verify we don't add a duplicate language before opening the dialog box otherwise display an error message. + if ( ! languagesMap.has( selectedLanguage ) ) { + dialog.dialog( 'open' ); + } else { + showError( pll_wizard_params.i18n_language_already_added ); + showFieldInError( languagesList.next( 'span.ui-selectmenu-button' ) ); + focusOnField( $( '#lang_list-button' ) ); + } + return false; + } + disableButton( nextStepButton ); + } + ); + + // Is there an error return by PHP ? + var searchParams = new URLSearchParams( document.location.search ); + if ( searchParams.has( 'activate_error' ) ) { + // If the error code exists, display it. + if ( undefined !== pll_wizard_params[ searchParams.get( 'activate_error' ) ] ) { + showError( pll_wizard_params[ searchParams.get( 'activate_error' ) ] ); + } + } + + function confirmDialog( what ) { + switch ( what ) { + case 'yes': + var selectedOption = $( '#lang_list' ).children( ':selected' ); + addLanguage( + { + locale: selectedOption[0].value, + text: selectedOption[0].innerText, + name: $( selectedOption ).data( 'language-name' ), + flagUrl: $( selectedOption ).data( 'flag-html' ) + } + ); + break; + case 'no': + // Empty select form field and submit again the form. + languagesList.val( '' ); + break; + case 'ignore': + } + dialog.dialog( 'close' ); + if ( 'ignore' === what ) { + focusOnField( $( '#lang_list-button' ) ); + } else { + addLanguageForm.submit(); + } + } + + // Initialize dialog box in the case a language is selected but not added in the list. + dialog.dialog( + { + autoOpen: false, + modal: true, + draggable: false, + resizable: false, + title: pll_wizard_params.i18n_dialog_title, + minWidth: 600, + maxWidth: '100%', + open: function( event, ui ) { + // Change dialog box position for rtl language + if ( $( 'body' ).hasClass( 'rtl' ) ) { + $( this ).parent().css( + { + right: $( this ).parent().css( 'left' ), + left: 'auto' + } + ); + } + // Display language name and flag information in dialog box. + $( this ).find( '#dialog-language' ).text( $( '#lang_list' ).children( ':selected' ).first().text() ); + // language properties come from the select dropdown #lang_list which is built server side and well escaped. + // see template view-wizard-step-languages.php. + $( this ).find( '#dialog-language-flag' ).empty().prepend( $( '#lang_list' ).children( ':selected' ).data( 'flag-html' ) ); // phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.prepend + }, + buttons: [ + { + text: pll_wizard_params.i18n_dialog_yes_button, + click: function( event ) { + confirmDialog( 'yes' ); + } + }, + { + text: pll_wizard_params.i18n_dialog_no_button, + click: function( event ) { + confirmDialog( 'no' ); + } + }, + { + text: pll_wizard_params.i18n_dialog_ignore_button, + click: function( event ) { + confirmDialog( 'ignore' ); + } + } + ] + } + ) + } +); diff --git a/wp-content/plugins/polylang/modules/wizard/load.php b/wp-content/plugins/polylang/modules/wizard/load.php new file mode 100644 index 00000000..914e6074 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/load.php @@ -0,0 +1,14 @@ +wizard = new PLL_Wizard( $polylang ); +} diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-page.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-page.php new file mode 100644 index 00000000..e38e3d32 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-page.php @@ -0,0 +1,108 @@ + + +> + + + + + <?php + printf( + /* translators: %s is the plugin name */ + esc_html__( '%s › Setup', 'polylang' ), + esc_html( POLYLANG ) + ); + ?> + + + + steps[ $this->step ]['scripts'] ); ?> + styles, $this->steps[ $this->step ]['styles'] ) ); ?> + + + +

    + + + + +

    +
      + steps as $step_key => $step ) { + $is_completed = array_search( $this->step, array_keys( $this->steps ), true ) > array_search( $step_key, array_keys( $this->steps ), true ); + + if ( $step_key === $this->step ) { + ?> +
    1. + +
    2. + + + +
    3. + +
    4. + +
    +
    +
    step}-step" ); ?>"> + steps[ $this->step ]['view'] ) ) { + call_user_func( $this->steps[ $this->step ]['view'], $this ); + } + ?> + step ) : ?> +

    + +

    + +
    +
    + + + diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-home-page.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-home-page.php new file mode 100644 index 00000000..dd607725 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-home-page.php @@ -0,0 +1,135 @@ +model->get_languages_list(); +$default_language = count( $languages ) > 0 ? $this->options['default_lang'] : null; +$home_page_id = get_option( 'page_on_front' ); +$translations = $this->model->post->get_translations( $home_page_id ); +$untranslated_languages = array(); +$home_page = $home_page_id > 0 ? get_post( $home_page_id ) : null; +$home_page_language = $this->model->post->get_language( $home_page_id ); + +foreach ( $languages as $language ) { + if ( ! $this->model->post->get( $home_page_id, $language ) ) { + $untranslated_languages[] = $language; + } +} +?> + + + + + +

    +

    + ' . esc_html( $home_page->post_title ) . '' + ); + ?> +
    + flag . ' ' . esc_html( $home_page_language->name ) . ' ' . esc_html( $home_page_language->locale ) . '' //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + ) + ?> +
    + +

    +

    + +

    + + + + + + + + + model->get_language( $lang ); + ?> + + + + + +
    + flag; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo ' ' . esc_html( $language->name ) . ' ' . esc_html( $language->locale ) . ' '; + ?> + slug === $default_language ) : ?> + + + + + + + +
    + + + + + + + = 1 ) : ?> + + + + + + + + + + + + + + + + + + + +
    + + +
    + flag; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + echo ' ' . esc_html( $lg->name ) . ' ' . esc_html( $lg->locale ) . ' '; + ?> + slug === $default_language ) : ?> + + + + + + + +
    diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-languages.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-languages.php new file mode 100644 index 00000000..29688616 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-languages.php @@ -0,0 +1,141 @@ +model->get_languages_list(); +$default_language = count( $existing_languages ) > 0 ? $this->options['default_lang'] : null; + +$languages_list = array_diff_key( + PLL_Settings::get_predefined_languages(), + wp_list_pluck( $existing_languages, 'locale', 'locale' ) +); +?> +
    +

    + +

    +

    + +

    +

    +
    +
    +
    + +
    + +
    + +
    +
    +
    + + + + + + + + + +
    + + + + + + + + + + + ' . "\n", + esc_attr( $lg->locale ), + esc_html( $lg->name ), + $lg->flag, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + $default_language === $lg->slug ? ' ' . esc_html__( 'Default language', 'polylang' ) . '' : '' + ); + } + ?> + +
    %3$s%2$s - %1$s %4$s
    + +
    +

    + ', + '' + ); + ?> +

    +

    + +

    +
      +
    • + ' . esc_html__( 'Yes', 'polylang' ) . '' + ); + ?> +
    • +
    • + ' . esc_html__( 'No', 'polylang' ) . '' + ); + ?> +
    • +
    • + ' . esc_html__( 'Ignore', 'polylang' ) . '' + ); + ?> +
    • +
    +
    diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-last.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-last.php new file mode 100644 index 00000000..234fff05 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-last.php @@ -0,0 +1,114 @@ + +

    + +
    +

    +
    +

    + + + +

    +
    +
    + +
      +
    • +
      +

      +

      +

      + +

      +
      +
      +

      + + + +

      +
      +
    • +
    • +
      +

      +

      +

      +
      +
      +

      + + + +

      +
      +
    • + +
    • +
      +

      +

      +

      + +

      +
      +
      +

      + + + +

      +
      +
    • + + +
    • +
      +

      +

      +

      + ' . esc_html__( 'Polylang Business Pack', 'polylang' ) . '' + ); + ?> +

      +
      +
      +

      + + + +

      +
      +
    • + +
    • +
      +

      + + + +

      +
      +
    • +
    diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-licenses.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-licenses.php new file mode 100644 index 00000000..e184f32c --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-licenses.php @@ -0,0 +1,38 @@ + +

    + + +

    +

    +
    + +

    + +
    +
    + + + get_form_field(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + } + ?> + +
    +
    diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-media.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-media.php new file mode 100644 index 00000000..b9ffb087 --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-media.php @@ -0,0 +1,62 @@ + +

    +

    + + + +

    +

    + +

    +
      +
    • +
      + + + /> + +
      +
      +

      + +

      +
      +
    • +
    • +
      +

      + + + + + +

      +
      +
    • +
    diff --git a/wp-content/plugins/polylang/modules/wizard/view-wizard-step-untranslated-contents.php b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-untranslated-contents.php new file mode 100644 index 00000000..1f771f6d --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/view-wizard-step-untranslated-contents.php @@ -0,0 +1,38 @@ +model->get_languages_list(); +$default_language = ! empty( $languages_list ) ? $this->options['default_lang'] : ''; +?> +

    +

    +
    +
    + +

    +
    + + +
    diff --git a/wp-content/plugins/polylang/modules/wizard/wizard.php b/wp-content/plugins/polylang/modules/wizard/wizard.php new file mode 100644 index 00000000..758b35be --- /dev/null +++ b/wp-content/plugins/polylang/modules/wizard/wizard.php @@ -0,0 +1,864 @@ +options = &$polylang->options; + $this->model = &$polylang->model; + + // Display Wizard page before any other action to ensure displaying it outside the WordPress admin context. + // Hooked on admin_init with priority 40 to ensure PLL_Wizard_Pro is corretly initialized. + add_action( 'admin_init', array( $this, 'setup_wizard_page' ), 40 ); + // Add Wizard submenu. + add_filter( 'pll_settings_tabs', array( $this, 'settings_tabs' ), 10, 1 ); + // Add filter to select screens where to display the notice. + add_filter( 'pll_can_display_notice', array( $this, 'can_display_notice' ), 10, 2 ); + + // Default steps. + add_filter( 'pll_wizard_steps', array( $this, 'add_step_licenses' ), 100 ); + add_filter( 'pll_wizard_steps', array( $this, 'add_step_languages' ), 200 ); + add_filter( 'pll_wizard_steps', array( $this, 'add_step_media' ), 300 ); + add_filter( 'pll_wizard_steps', array( $this, 'add_step_untranslated_contents' ), 400 ); + add_filter( 'pll_wizard_steps', array( $this, 'add_step_home_page' ), 500 ); + add_filter( 'pll_wizard_steps', array( $this, 'add_step_last' ), 999 ); + } + + /** + * Save an activation transient when Polylang is activating to redirect to the wizard + * + * @since 2.7 + * + * @param bool $network_wide if activated for all sites in the network. + * @return void + */ + public static function start_wizard( $network_wide ) { + $options = get_option( 'polylang' ); + + if ( wp_doing_ajax() || $network_wide || ! empty( $options ) ) { + return; + } + set_transient( 'pll_activation_redirect', 1, 30 ); + } + + /** + * Redirect to the wizard depending on the context + * + * @since 2.7 + * + * @return void + */ + public function redirect_to_wizard() { + if ( get_transient( 'pll_activation_redirect' ) ) { + $do_redirect = true; + if ( ( isset( $_GET['page'] ) && 'mlang_wizard' === sanitize_key( $_GET['page'] ) || isset( $_GET['activate-multi'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + delete_transient( 'pll_activation_redirect' ); + $do_redirect = false; + } + + if ( $do_redirect ) { + wp_safe_redirect( + esc_url_raw( + add_query_arg( + array( + 'page' => 'mlang_wizard', + ), + admin_url( 'admin.php' ) + ) + ) + ); + exit; + } + } + } + + /** + * Add an admin Polylang submenu to access the wizard + * + * @since 2.7 + * + * @param string[] $tabs Submenus list. + * @return string[] Submenus list updated. + */ + public function settings_tabs( $tabs ) { + $tabs['wizard'] = esc_html__( 'Setup', 'polylang' ); + return $tabs; + } + + /** + * Returns true if the media step is displayable, false otherwise. + * + * @since 2.7 + * + * @param PLL_Language[] $languages List of language objects. + * @return bool + */ + public function is_media_step_displayable( $languages ) { + $media = array(); + // If there is no language or only one the media step is displayable. + if ( ! $languages || count( $languages ) < 2 ) { + return true; + } + foreach ( $languages as $language ) { + $media[ $language->slug ] = $this->model->count_posts( + $language, + array( + 'post_type' => array( 'attachment' ), + 'post_status' => 'inherit', + ) + ); + } + return count( array_filter( $media ) ) === 0; + } + + /** + * Check if the licenses step is displayable + * + * @since 2.7 + * + * @return bool + */ + public function is_licenses_step_displayable() { + $licenses = apply_filters( 'pll_settings_licenses', array() ); + return count( $licenses ) > 0; + } + + /** + * Setup the wizard page + * + * @since 2.7 + * + * @return void + */ + public function setup_wizard_page() { + + PLL_Admin_Notices::add_notice( 'wizard', $this->wizard_notice() ); + + $this->redirect_to_wizard(); + if ( ! Polylang::is_wizard() ) { + return; + } + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( esc_html__( 'Sorry, you are not allowed to manage options for this site.', 'polylang' ) ); + } + + // Enqueue scripts and styles especially for the wizard. + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + + $this->steps = apply_filters( 'pll_wizard_steps', $this->steps ); + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification + + $this->step = $step && array_key_exists( $step, $this->steps ) ? $step : current( array_keys( $this->steps ) ); + + $languages = $this->model->get_languages_list(); + + if ( count( $languages ) === 0 && ! in_array( $this->step, array( 'licenses', 'languages' ) ) ) { + wp_safe_redirect( esc_url_raw( $this->get_step_link( 'languages' ) ) ); + exit; + } + + if ( count( $languages ) > 0 && $this->model->get_objects_with_no_lang( 1 ) && ! in_array( $this->step, array( 'licenses', 'languages', 'media', 'untranslated-contents' ) ) ) { + wp_safe_redirect( esc_url_raw( $this->get_step_link( 'untranslated-contents' ) ) ); + exit; + } + + // Call the handler of the step for going to the next step. + // Be careful nonce verification with check_admin_referer must be done in each handler. + if ( ! empty( $_POST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing + call_user_func( $this->steps[ $this->step ]['handler'] ); + } + + $this->display_wizard_page(); + // Ensure nothing is done after including the page. + exit; + } + + /** + * Adds some admin screens where to display the wizard notice + * + * @since 2.7 + * + * @param bool $can_display_notice Whether the notice can be displayed. + * @param string $notice The notice name. + * @return bool + */ + public function can_display_notice( $can_display_notice, $notice ) { + if ( ! $can_display_notice && 'wizard' === $notice ) { + $screen = get_current_screen(); + $can_display_notice = ! empty( $screen ) && in_array( + $screen->base, + array( + 'edit', + 'upload', + 'options-general', + ) + ); + } + return $can_display_notice; + } + + /** + * Return html code of the wizard notice + * + * @since 2.7 + * + * @return string + */ + public function wizard_notice() { + ob_start(); + include __DIR__ . '/html-wizard-notice.php'; + return ob_get_clean(); + } + + /** + * Display the wizard page + * + * @since 2.7 + * + * @return void + */ + public function display_wizard_page() { + set_current_screen(); + include __DIR__ . '/view-wizard-page.php'; + } + + /** + * Enqueue scripts and styles for the wizard + * + * @since 2.7 + * + * @return void + */ + public function enqueue_scripts() { + wp_enqueue_style( 'polylang_admin', plugins_url( '/css/build/admin' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION ); + wp_enqueue_style( 'pll-wizard', plugins_url( '/css/build/wizard' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common', 'forms' ), POLYLANG_VERSION ); + + $this->styles = array( 'polylang_admin', 'pll-wizard' ); + } + + /** + * Get the suffix to enqueue non minified files in a Debug context + * + * @since 2.7 + * + * @return string Empty when SCRIPT_DEBUG equal to true + * otherwise .min + */ + public function get_suffix() { + return defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; + } + + /** + * Get the URL for the step's screen. + * + * @since 2.7 + * + * @param string $step slug (default: current step). + * @return string URL for the step if it exists. + * Empty string on failure. + */ + public function get_step_link( $step = '' ) { + if ( ! $step ) { + $step = $this->step; + } + + $keys = array_keys( $this->steps ); + + $step_index = array_search( $step, $keys, true ); + if ( false === $step_index ) { + return ''; + } + + return add_query_arg( 'step', $keys[ $step_index ], remove_query_arg( 'activate_error' ) ); + } + + /** + * Get the URL for the next step's screen. + * + * @since 2.7 + * + * @param string $step slug (default: current step). + * @return string URL for next step if a next step exists. + * Admin URL if it's the last step. + * Empty string on failure. + */ + public function get_next_step_link( $step = '' ) { + if ( ! $step ) { + $step = $this->step; + } + + $keys = array_keys( $this->steps ); + if ( end( $keys ) === $step ) { + return admin_url(); + } + + $step_index = array_search( $step, $keys, true ); + if ( false === $step_index ) { + return ''; + } + + return add_query_arg( 'step', $keys[ $step_index + 1 ], remove_query_arg( 'activate_error' ) ); + } + + /** + * Add licenses step to the wizard + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_licenses( $steps ) { + // Add ajax action on deactivate button in licenses step. + add_action( 'wp_ajax_pll_deactivate_license', array( $this, 'deactivate_license' ) ); + + // Be careful pll_admin script is enqueued here without depedency except jquery because only code useful for deactivate license button is needed. + // To be really loaded the script need to be passed to the $steps['licenses']['scripts'] array below with the same handle than in wp_enqueue_script(). + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery' ), POLYLANG_VERSION, true ); + wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); + + if ( $this->is_licenses_step_displayable() ) { + $steps['licenses'] = array( + 'name' => esc_html__( 'Licenses', 'polylang' ), + 'view' => array( $this, 'display_step_licenses' ), + 'handler' => array( $this, 'save_step_licenses' ), + 'scripts' => array( 'pll_admin' ), // Polylang admin script used by deactivate license button. + 'styles' => array(), + ); + } + return $steps; + } + + /** + * Display the languages step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_licenses() { + include __DIR__ . '/view-wizard-step-licenses.php'; + } + + /** + * Execute the languages step + * + * @since 2.7 + * + * @return void + */ + public function save_step_licenses() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + $redirect = $this->get_next_step_link(); + $licenses = apply_filters( 'pll_settings_licenses', array() ); + + foreach ( $licenses as $license ) { + if ( ! empty( $_POST['licenses'][ $license->id ] ) ) { + $updated_license = $license->activate_license( sanitize_key( $_POST['licenses'][ $license->id ] ) ); + if ( ! empty( $updated_license->license_data ) && false === $updated_license->license_data->success ) { + // Stay on this step with an error. + $redirect = add_query_arg( + array( + 'step' => $this->step, + 'activate_error' => 'i18n_license_key_error', + ) + ); + } + } + } + + wp_safe_redirect( esc_url_raw( $redirect ) ); + exit; + } + + /** + * Ajax method to deactivate a license + * + * @since 2.7 + * + * @return void + */ + public function deactivate_license() { + check_ajax_referer( 'pll-wizard', '_pll_nonce' ); + + if ( ! current_user_can( 'manage_options' ) ) { + wp_die( -1 ); + } + + if ( ! isset( $_POST['id'] ) ) { + wp_die( 0 ); + } + + $id = substr( sanitize_text_field( wp_unslash( $_POST['id'] ) ), 11 ); + $licenses = apply_filters( 'pll_settings_licenses', array() ); + $license = $licenses[ $id ]; + $license->deactivate_license(); + + wp_send_json( + array( + 'id' => $id, + 'html' => $license->get_form_field(), + ) + ); + } + + /** + * Add languages step to the wizard + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_languages( $steps ) { + wp_deregister_script( 'pll_admin' ); // Deregister after the licenses step enqueue to update jquery-ui-selectmenu dependency. + // The wp-ajax-response and postbox dependencies is useless in wizard steps espacially postbox which triggers a javascript error otherwise. + // To be really loaded the script need to be passed to the $steps['languages']['scripts'] array below with the same handle than in wp_enqueue_script(). + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); + wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); + wp_register_script( 'pll-wizard-languages', plugins_url( '/js/build/languages-step' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-dialog' ), POLYLANG_VERSION, true ); + wp_localize_script( + 'pll-wizard-languages', + 'pll_wizard_params', + array( + 'i18n_no_language_selected' => esc_html__( 'You need to select a language to be added.', 'polylang' ), + 'i18n_language_already_added' => esc_html__( 'You already added this language.', 'polylang' ), + 'i18n_no_language_added' => esc_html__( 'You need to add at least one language.', 'polylang' ), + 'i18n_add_language_needed' => esc_html__( 'You selected a language, however, to be able to continue, you need to add it.', 'polylang' ), + 'i18n_pll_add_language' => esc_html__( 'Impossible to add the language.', 'polylang' ), + 'i18n_pll_invalid_locale' => esc_html__( 'Enter a valid WordPress locale', 'polylang' ), + 'i18n_pll_invalid_slug' => esc_html__( 'The language code contains invalid characters', 'polylang' ), + 'i18n_pll_non_unique_slug' => esc_html__( 'The language code must be unique', 'polylang' ), + 'i18n_pll_invalid_name' => esc_html__( 'The language must have a name', 'polylang' ), + 'i18n_pll_invalid_flag' => esc_html__( 'The flag does not exist', 'polylang' ), + 'i18n_dialog_title' => esc_html__( "A language wasn't added.", 'polylang' ), + 'i18n_dialog_yes_button' => esc_html__( 'Yes', 'polylang' ), + 'i18n_dialog_no_button' => esc_html__( 'No', 'polylang' ), + 'i18n_dialog_ignore_button' => esc_html__( 'Ignore', 'polylang' ), + 'i18n_remove_language_icon' => esc_html__( 'Remove this language', 'polylang' ), + ) + ); + wp_enqueue_script( 'pll-wizard-languages' ); + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common', 'wp-jquery-ui-dialog' ), POLYLANG_VERSION ); + $steps['languages'] = array( + 'name' => esc_html__( 'Languages', 'polylang' ), + 'view' => array( $this, 'display_step_languages' ), + 'handler' => array( $this, 'save_step_languages' ), + 'scripts' => array( 'pll-wizard-languages', 'pll_admin' ), + 'styles' => array( 'pll-wizard-selectmenu' ), + ); + return $steps; + } + + /** + * Display the languages step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_languages() { + include __DIR__ . '/view-wizard-step-languages.php'; + } + + /** + * Execute the languages step + * + * @since 2.7 + * + * @return void + */ + public function save_step_languages() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + $existing_languages = $this->model->get_languages_list(); + + $all_languages = include POLYLANG_DIR . '/settings/languages.php'; + $languages = isset( $_POST['languages'] ) && is_array( $_POST['languages'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['languages'] ) ) : false; + $saved_languages = array(); + + // If there is no language added or defined. + if ( empty( $languages ) && empty( $existing_languages ) ) { + // Stay on this step with an error. + wp_safe_redirect( + esc_url_raw( + add_query_arg( + array( + 'step' => $this->step, + 'activate_error' => 'i18n_no_language_added', + ) + ) + ) + ); + exit; + } + + // Otherwise process the languages to add or skip the step if no language has been added. + if ( ! empty( $languages ) ) { + require_once ABSPATH . 'wp-admin/includes/translation-install.php'; + // Remove duplicate values. + $languages = array_unique( $languages ); + // For each language add it in Polylang settings. + foreach ( $languages as $locale ) { + $saved_languages = $all_languages[ $locale ]; + + $saved_languages['slug'] = $saved_languages['code']; + $saved_languages['rtl'] = (int) ( 'rtl' === $saved_languages['dir'] ); + $saved_languages['term_group'] = 0; // Default term_group. + + $language_added = $this->model->add_language( $saved_languages ); + + if ( $language_added instanceof WP_Error && array_key_exists( 'pll_non_unique_slug', $language_added->errors ) ) { + // Get the slug from the locale : lowercase and dash instead of underscore. + $saved_languages['slug'] = strtolower( str_replace( '_', '-', $saved_languages['locale'] ) ); + $language_added = $this->model->add_language( $saved_languages ); + } + + if ( $language_added instanceof WP_Error ) { + // Stay on this step with an error. + $error_keys = array_keys( $language_added->errors ); + wp_safe_redirect( + esc_url_raw( + add_query_arg( + array( + 'step' => $this->step, + 'activate_error' => 'i18n_' . reset( $error_keys ), + ) + ) + ) + ); + exit; + } + + if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { + wp_download_language_pack( $locale ); + } + } + } + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Add the media step to the wizard. + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_media( $steps ) { + $languages = $this->model->get_languages_list(); + + if ( $this->is_media_step_displayable( $languages ) ) { + $steps['media'] = array( + 'name' => esc_html__( 'Media', 'polylang' ), + 'view' => array( $this, 'display_step_media' ), + 'handler' => array( $this, 'save_step_media' ), + 'scripts' => array(), + 'styles' => array(), + ); + } + return $steps; + } + + /** + * Display the media step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_media() { + include __DIR__ . '/view-wizard-step-media.php'; + } + + /** + * Execute the media step + * + * @since 2.7 + * + * @return void + */ + public function save_step_media() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + $media_support = isset( $_POST['media_support'] ) ? sanitize_key( $_POST['media_support'] ) === 'yes' : false; + + $this->options['media_support'] = $media_support; + + update_option( 'polylang', $this->options ); + + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Add untranslated contents step to the wizard + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_untranslated_contents( $steps ) { + if ( ! $this->model->get_languages_list() || $this->model->get_objects_with_no_lang( 1 ) ) { + // Even if pll_admin is already enqueued with the same dependencies by the languages step, it is interesting to keep that it's also useful for the untranslated-contents step. + // To be really loaded the script need to be passed to the $steps['untranslated-contents']['scripts'] array below with the same handle than in wp_enqueue_script(). + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $this->get_suffix() . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); + wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); + wp_enqueue_style( 'pll-wizard-selectmenu', plugins_url( '/css/build/selectmenu' . $this->get_suffix() . '.css', POLYLANG_ROOT_FILE ), array( 'dashicons', 'install', 'common' ), POLYLANG_VERSION ); + $steps['untranslated-contents'] = array( + 'name' => esc_html__( 'Content', 'polylang' ), + 'view' => array( $this, 'display_step_untranslated_contents' ), + 'handler' => array( $this, 'save_step_untranslated_contents' ), + 'scripts' => array( 'pll_admin' ), + 'styles' => array( 'pll-wizard-selectmenu' ), + ); + } + return $steps; + } + + /** + * Display the untranslated contents step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_untranslated_contents() { + include __DIR__ . '/view-wizard-step-untranslated-contents.php'; + } + + /** + * Execute the untranslated contents step + * + * @since 2.7 + * + * @return void + */ + public function save_step_untranslated_contents() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + $lang = isset( $_POST['language'] ) ? sanitize_text_field( wp_unslash( $_POST['language'] ) ) : false; + + if ( empty( $lang ) ) { + $lang = $this->options['default_lang']; + } + + $language = $this->model->get_language( $lang ); + + while ( $nolang = $this->model->get_objects_with_no_lang( 1000 ) ) { + if ( ! empty( $nolang['posts'] ) ) { + $this->model->set_language_in_mass( 'post', $nolang['posts'], $language->slug ); + } + if ( ! empty( $nolang['terms'] ) ) { + $this->model->set_language_in_mass( 'term', $nolang['terms'], $language->slug ); + } + } + + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Add home page step to the wizard + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_home_page( $steps ) { + $languages = $this->model->get_languages_list(); + $home_page_id = get_option( 'page_on_front' ); + + $translations = $this->model->post->get_translations( $home_page_id ); + + if ( $home_page_id > 0 && ( ! $languages || count( $languages ) === 1 || count( $translations ) !== count( $languages ) ) ) { + $steps['home-page'] = array( + 'name' => esc_html__( 'Homepage', 'polylang' ), + 'view' => array( $this, 'display_step_home_page' ), + 'handler' => array( $this, 'save_step_home_page' ), + 'scripts' => array(), + 'styles' => array(), + ); + } + return $steps; + } + + /** + * Display the home page step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_home_page() { + include __DIR__ . '/view-wizard-step-home-page.php'; + } + + /** + * Execute the home page step + * + * @since 2.7 + * + * @return void + */ + public function save_step_home_page() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + $languages = $this->model->get_languages_list(); + + $default_language = count( $languages ) > 0 ? $this->options['default_lang'] : null; + $home_page = isset( $_POST['home_page'] ) ? sanitize_key( $_POST['home_page'] ) : false; + $home_page_title = isset( $_POST['home_page_title'] ) ? sanitize_text_field( wp_unslash( $_POST['home_page_title'] ) ) : esc_html__( 'Homepage', 'polylang' ); + $home_page_language = isset( $_POST['home_page_language'] ) ? sanitize_key( $_POST['home_page_language'] ) : false; + + $untranslated_languages = isset( $_POST['untranslated_languages'] ) ? array_map( 'sanitize_key', $_POST['untranslated_languages'] ) : array(); + + call_user_func( + apply_filters( 'pll_wizard_create_home_page_translations', array( $this, 'create_home_page_translations' ) ), + $default_language, + $home_page, + $home_page_title, + $home_page_language, + $untranslated_languages + ); + + $this->model->clean_languages_cache(); + + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } + + /** + * Create home page translations for each language defined. + * + * @since 2.7 + * + * @param string $default_language Slug of the default language; null if no default language is defined. + * @param int $home_page Post ID of the home page if it's defined, false otherwise. + * @param string $home_page_title Home page title if it's defined, 'Homepage' otherwise. + * @param string $home_page_language Slug of the home page if it's defined, false otherwise. + * @param string[] $untranslated_languages Array of languages which needs to have a home page translated. + * @return void + */ + public function create_home_page_translations( $default_language, $home_page, $home_page_title, $home_page_language, $untranslated_languages ) { + $translations = $this->model->post->get_translations( $home_page ); + + foreach ( $untranslated_languages as $language ) { + $language_properties = $this->model->get_language( $language ); + $id = wp_insert_post( + array( + 'post_title' => $home_page_title . ' - ' . $language_properties->name, + 'post_type' => 'page', + 'post_status' => 'publish', + ) + ); + $translations[ $language ] = $id; + pll_set_post_language( $id, $language ); + } + pll_save_post_translations( $translations ); + } + + /** + * Add last step to the wizard + * + * @since 2.7 + * + * @param array $steps List of steps. + * @return array List of steps updated. + */ + public function add_step_last( $steps ) { + $steps['last'] = array( + 'name' => esc_html__( 'Ready!', 'polylang' ), + 'view' => array( $this, 'display_step_last' ), + 'handler' => array( $this, 'save_step_last' ), + 'scripts' => array(), + 'styles' => array(), + ); + return $steps; + } + + /** + * Display the last step form + * + * @since 2.7 + * + * @return void + */ + public function display_step_last() { + // We ran the wizard once. So we can dismiss its notice. + PLL_Admin_Notices::dismiss( 'wizard' ); + include __DIR__ . '/view-wizard-step-last.php'; + } + + /** + * Execute the last step + * + * @since 2.7 + * + * @return void + */ + public function save_step_last() { + check_admin_referer( 'pll-wizard', '_pll_nonce' ); + + wp_safe_redirect( esc_url_raw( $this->get_next_step_link() ) ); + exit; + } +} diff --git a/wp-content/plugins/polylang/modules/wpml/load.php b/wp-content/plugins/polylang/modules/wpml/load.php new file mode 100644 index 00000000..9c10970e --- /dev/null +++ b/wp-content/plugins/polylang/modules/wpml/load.php @@ -0,0 +1,17 @@ +model->get_languages_list() ) { + if ( ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT ) { + PLL_WPML_Compat::instance(); // WPML API. + PLL_WPML_Config::instance(); // wpml-config.xml. + } +} diff --git a/wp-content/plugins/polylang/modules/wpml/settings-wpml.php b/wp-content/plugins/polylang/modules/wpml/settings-wpml.php deleted file mode 100644 index 972f3fca..00000000 --- a/wp-content/plugins/polylang/modules/wpml/settings-wpml.php +++ /dev/null @@ -1,35 +0,0 @@ - 'wpml', - 'title' => __( 'WPML Compatibility', 'polylang' ), - 'description' => __( 'WPML compatibility mode of Polylang', 'polylang' ), - ) ); - } - - /** - * tells if the module is active - * - * @since 1.8 - * - * @return bool - */ - public function is_active() { - return ! defined( 'PLL_WPML_COMPAT' ) || PLL_WPML_COMPAT; - } -} diff --git a/wp-content/plugins/polylang/modules/wpml/wpml-api.php b/wp-content/plugins/polylang/modules/wpml/wpml-api.php index 6f12a118..4df835ac 100644 --- a/wp-content/plugins/polylang/modules/wpml/wpml-api.php +++ b/wp-content/plugins/polylang/modules/wpml/wpml-api.php @@ -1,13 +1,23 @@ not applicable + // wpml_translated_language_name => not applicable add_filter( 'wpml_current_language', 'pll_current_language', 10, 0 ); add_filter( 'wpml_default_language', 'pll_default_language', 10, 0 ); - // wpml_add_language_selector => not implemented - // wpml_footer_language_selector => not applicable + // wpml_add_language_selector => not implemented + // wpml_footer_language_selector => not applicable add_action( 'wpml_add_language_form_field', array( $this, 'wpml_add_language_form_field' ) ); add_filter( 'wpml_language_is_active', array( $this, 'wpml_language_is_active' ), 10, 2 ); add_filter( 'wpml_is_rtl', array( $this, 'wpml_is_rtl' ) ); - // wpml_language_form_input_field => See wpml_add_language_form_field - // wpml_language_has_switched => not implemented + // wpml_language_form_input_field => See wpml_add_language_form_field + // wpml_language_has_switched => See wpml_switch_language + // wpml_element_trid => not implemented + // wpml_get_element_translations => not implemented + // wpml_language_switcher => not implemented + // wpml_browser_redirect_language_params => not implemented + // wpml_enqueue_browser_redirect_language => not applicable + // wpml_enqueued_browser_redirect_language => not applicable + // wpml_encode_string => not applicable + // wpml_decode_string => not applicable // Retrieving Language Information for Content add_filter( 'wpml_post_language_details', 'wpml_get_language_information', 10, 2 ); - // wpml_switch_language => not implemented + add_action( 'wpml_switch_language', array( __CLASS__, 'wpml_switch_language' ), 10, 2 ); add_filter( 'wpml_element_language_code', array( $this, 'wpml_element_language_code' ), 10, 3 ); - // wpml_element_language_details => not applicable + // wpml_element_language_details => not applicable // Retrieving Localized Content @@ -43,47 +61,59 @@ class PLL_WPML_API { add_filter( 'wpml_element_link', 'icl_link_to_element', 10, 7 ); add_filter( 'wpml_object_id', 'icl_object_id', 10, 4 ); add_filter( 'wpml_translate_single_string', array( $this, 'wpml_translate_single_string' ), 10, 4 ); - // wpml_translate_string => not applicable - // wpml_unfiltered_admin_string => not implemented + // wpml_translate_string => not applicable + // wpml_unfiltered_admin_string => not implemented add_filter( 'wpml_permalink', array( $this, 'wpml_permalink' ), 10, 2 ); - // wpml_elements_without_translations => not implemented + // wpml_elements_without_translations => not implemented add_filter( 'wpml_get_translated_slug', array( $this, 'wpml_get_translated_slug' ), 10, 3 ); // Finding the Translation State of Content - // wpml_element_translation_type + // wpml_element_translation_type => not implemented add_filter( 'wpml_element_has_translations', array( $this, 'wpml_element_has_translations' ), 10, 3 ); - // wpml_master_post_from_duplicate => not applicable - // wpml_post_duplicates => not applicable + // wpml_master_post_from_duplicate => not applicable + // wpml_post_duplicates => not applicable // Inserting Content - // wpml_admin_make_post_duplicates => not applicable - // wpml_make_post_duplicates => not applicable + // wpml_admin_make_post_duplicates => not applicable + // wpml_make_post_duplicates => not applicable add_action( 'wpml_register_single_string', 'icl_register_string', 10, 3 ); - // wpml_register_string => not applicable - // wpml_register_string_packages => not applicable - // wpml_delete_package_action => not applicable - // wpml_show_package_language_ui => not applicable - // wpml_set_element_language_details => not implemented + // wpml_register_string => not applicable + // wpml_register_string_packages => not applicable + // wpml_delete_package_action => not applicable + // wpml_show_package_language_ui => not applicable + // wpml_set_element_language_details => not implemented + // wpml_multilingual_options => not applicable // Miscellaneous - // wpml_element_type => not applicable - // wpml_setting => not applicable - // wpml_sub_setting => not applicable - // wpml_editor_cf_to_display => not applicable - // wpml_tm_save_translation_cf => not implemented - // wpml_tm_xliff_export_translated_cf => not applicable - // wpml_tm_xliff_export_original_cf => not applicable - // wpml_duplicate_generic_string => not applicable - // wpml_translatable_user_meta_fields => not implemented - // wpml_cross_domain_language_data => not applicable - // wpml_get_cross_domain_language_data => not applicable - // wpml_loaded => not applicable - // wpml_st_loaded => not applicable - // wpml_tm_loaded => not applicable - // wpml_hide_management_column (3.4.1) => not applicable + // wpml_element_type => not applicable + // wpml_setting => not applicable + // wpml_sub_setting => not applicable + // wpml_editor_cf_to_display => not applicable + // wpml_tm_save_translation_cf => not implemented + // wpml_tm_xliff_export_translated_cf => not applicable + // wpml_tm_xliff_export_original_cf => not applicable + // wpml_duplicate_generic_string => not applicable + // wpml_translatable_user_meta_fields => not implemented + // wpml_cross_domain_language_data => not applicable + // wpml_get_cross_domain_language_data => not applicable + // wpml_loaded => not applicable + // wpml_st_loaded => not applicable + // wpml_tm_loaded => not applicable + // wpml_hide_management_column (3.4.1) => not applicable + // wpml_ls_directories_to_scan => not applicable + // wpml_ls_model_css_classes => not applicable + // wpml_ls_model_language_css_classes => not applicable + // wpml_tf_feedback_open_link => not applicable + // wpml_sync_custom_field => not implemented + // wpml_sync_all_custom_fields => not implemented + // wpml_is_redirected => not implemented + + // Updating Content + + // wpml_set_translation_mode_for_post_type => not implemented } /** @@ -101,18 +131,16 @@ class PLL_WPML_API { /** * In WPML, get a language's native and translated name for display in a custom language switcher - * Since Polylang does not implement the translated name, always returns only the native name + * Since Polylang does not implement the translated name, always returns only the native name, + * so the 3rd, 4th and 5th parameters are not used. * * @since 2.2 * - * @param mixed $null Not used. - * @param string $native_name The language native name. - * @param string|bool $translated_name The language translated name. Not used. - * @param bool $native_hidden Whether to hide the language native name or not. Not used. - * @param bool $translated_hidden Whether to hide the language translated name or not. Not used. + * @param mixed $null Not used. + * @param string $native_name The language native name. * @return string */ - public function wpml_display_language_names( $null, $native_name, $translated_name = false, $native_hidden = false, $translated_hidden = false ) { + public function wpml_display_language_names( $null, $native_name ) { return $native_name; } @@ -120,12 +148,14 @@ class PLL_WPML_API { * Returns an HTML hidden input field with name=”lang” and as value the current language * * @since 2.0 + * + * @return void */ public function wpml_add_language_form_field() { $lang = pll_current_language(); $field = sprintf( '', esc_attr( $lang ) ); $field = apply_filters( 'wpml_language_form_input_field', $field, $lang ); - echo $field; + echo $field; // phpcs:ignore WordPress.Security.EscapeOutput } /** @@ -147,13 +177,42 @@ class PLL_WPML_API { * * @since 2.0 * - * @param mixed $null Not used * @return bool */ - public function wpml_is_rtl( $null ) { + public function wpml_is_rtl() { return pll_current_language( 'is_rtl' ); } + /** + * Switches whole site to the given language or restores the language that was set when first calling this function. + * Unlike the WPML original action, it is not possible to set the current language and the cookie to different values. + * + * @since 2.7 + * + * @param null|string $lang Language code to switch into, restores the original language if null. + * @param bool|string $cookie Optionally also switches the cookie. + * @return void + */ + public static function wpml_switch_language( $lang = null, $cookie = false ) { + if ( null === self::$original_language ) { + self::$original_language = PLL()->curlang; + } + + if ( empty( $lang ) ) { + PLL()->curlang = self::$original_language; + } elseif ( 'all' === $lang ) { + PLL()->curlang = null; + } elseif ( in_array( $lang, pll_languages_list() ) ) { + PLL()->curlang = PLL()->model->get_language( $lang ); + } + + if ( $cookie && isset( PLL()->choose_lang ) ) { + PLL()->choose_lang->maybe_setcookie(); + } + + do_action( 'wpml_language_has_switched', $lang, $cookie, self::$original_language ); + } + /** * Get the language code for a translatable element * @@ -167,8 +226,11 @@ class PLL_WPML_API { $type = $args['element_type']; $id = $args['element_id']; $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false ); - if ( 'term' === $pll_type && $term = wpcom_vip_get_term_by( 'term_taxonomy_id', $id ) ) { - $id = $term->term_id; + if ( 'term' === $pll_type ) { + $term = get_term_by( 'term_taxonomy_id', $id ); + if ( $term instanceof WP_Term ) { + $id = $term->term_id; + } } return $pll_type ? call_user_func( "pll_get_{$pll_type}_language", $id ) : $language_code; } diff --git a/wp-content/plugins/polylang/modules/wpml/wpml-compat.php b/wp-content/plugins/polylang/modules/wpml/wpml-compat.php index 07696c02..44ac264e 100644 --- a/wp-content/plugins/polylang/modules/wpml/wpml-compat.php +++ b/wp-content/plugins/polylang/modules/wpml/wpml-compat.php @@ -1,4 +1,7 @@ api = new PLL_WPML_API(); self::$strings = get_option( 'polylang_wpml_strings', array() ); @@ -34,9 +52,9 @@ class PLL_WPML_Compat { * * @since 1.7 * - * @return object + * @return PLL_WPML_Compat */ - static public function instance() { + public static function instance() { if ( empty( self::$instance ) ) { self::$instance = new self(); } @@ -49,6 +67,8 @@ class PLL_WPML_Compat { * in 'setup_theme' by Polylang ( based on user info ) and 'plugins_loaded' by WPML ( based on cookie ) * * @since 0.9.5 + * + * @return void */ public function define_constants() { if ( ! empty( PLL()->curlang ) ) { @@ -77,15 +97,34 @@ class PLL_WPML_Compat { * * @since 1.0.2 * - * @param string $context the group in which the string is registered, defaults to 'polylang' - * @param string $name a unique name for the string - * @param string $string the string to register + * @param string $context The group in which the string is registered. + * @param string $name A unique name for the string. + * @param string $string The string to register. + * @return void */ public function register_string( $context, $name, $string ) { - // Registers the string if it does not exist yet (multiline as in WPML) + // If a string has already been registered with the same name and context, let's replace it. + $exist_string = $this->get_string_by_context_and_name( $context, $name ); + if ( $exist_string && $exist_string !== $string ) { + $languages = PLL()->model->get_languages_list(); + + // Assign translations of the old string to the new string, except for the default language. + foreach ( $languages as $language ) { + if ( pll_default_language() !== $language->slug ) { + $mo = new PLL_MO(); + $mo->import_from_db( $language ); + $mo->add_entry( $mo->make_entry( $string, $mo->translate( $exist_string ) ) ); + $mo->export_to_db( $language ); + } + } + $this->unregister_string( $context, $name ); + } + + // Registers the string if it does not exist yet (multiline as in WPML). $to_register = array( 'context' => $context, 'name' => $name, 'string' => $string, 'multiline' => true, 'icl' => true ); if ( ! in_array( $to_register, self::$strings ) && $to_register['string'] ) { - self::$strings[] = $to_register; + $key = md5( "$context | $name" ); + self::$strings[ $key ] = $to_register; update_option( 'polylang_wpml_strings', self::$strings ); } } @@ -95,15 +134,15 @@ class PLL_WPML_Compat { * * @since 1.0.2 * - * @param string $context the group in which the string is registered, defaults to 'polylang' - * @param string $name a unique name for the string + * @param string $context The group in which the string is registered. + * @param string $name A unique name for the string. + * @return void */ public function unregister_string( $context, $name ) { - foreach ( self::$strings as $key => $string ) { - if ( $string['context'] == $context && $string['name'] == $name ) { - unset( self::$strings[ $key ] ); - update_option( 'polylang_wpml_strings', self::$strings ); - } + $key = md5( "$context | $name" ); + if ( isset( self::$strings[ $key ] ) ) { + unset( self::$strings[ $key ] ); + update_option( 'polylang_wpml_strings', self::$strings ); } } @@ -124,16 +163,12 @@ class PLL_WPML_Compat { * * @since 2.0 * - * @param string $context the group in which the string is registered - * @param string $name a unique name for the string - * @return bool|string the registered string, false if none was found + * @param string $context The group in which the string is registered. + * @param string $name A unique name for the string. + * @return bool|string The registered string, false if none was found. */ public function get_string_by_context_and_name( $context, $name ) { - foreach ( self::$strings as $string ) { - if ( $string['context'] == $context && $string['name'] == $name ) { - return $string['string']; - } - } - return false; + $key = md5( "$context | $name" ); + return isset( self::$strings[ $key ] ) ? self::$strings[ $key ]['string'] : false; } } diff --git a/wp-content/plugins/polylang/modules/wpml/wpml-config.php b/wp-content/plugins/polylang/modules/wpml/wpml-config.php index 80f84acb..6862fbe7 100644 --- a/wp-content/plugins/polylang/modules/wpml/wpml-config.php +++ b/wp-content/plugins/polylang/modules/wpml/wpml-config.php @@ -1,4 +1,7 @@ xmls = array(); + $files = $this->get_files(); + + if ( ! empty( $files ) ) { + add_filter( 'site_status_test_php_modules', array( $this, 'site_status_test_php_modules' ) ); // Require simplexml in Site health. + + // Read all files. + if ( extension_loaded( 'simplexml' ) ) { + foreach ( $files as $context => $file ) { + $xml = simplexml_load_file( $file ); + if ( false !== $xml ) { + $this->xmls[ $context ] = $xml; + } + } + } + } + + if ( ! empty( $this->xmls ) ) { + add_filter( 'pll_copy_post_metas', array( $this, 'copy_post_metas' ), 20, 2 ); + add_filter( 'pll_copy_term_metas', array( $this, 'copy_term_metas' ), 20, 2 ); + add_filter( 'pll_get_post_types', array( $this, 'translate_types' ), 10, 2 ); + add_filter( 'pll_get_taxonomies', array( $this, 'translate_taxonomies' ), 10, 2 ); + + foreach ( $this->xmls as $context => $xml ) { + $keys = $xml->xpath( 'admin-texts/key' ); + if ( is_array( $keys ) ) { + foreach ( $keys as $key ) { + $attributes = $key->attributes(); + $name = (string) $attributes['name']; + + if ( false !== strpos( $name, '*' ) ) { + $pattern = '#^' . str_replace( '*', '(?:.+)', $name ) . '$#'; + $names = preg_grep( $pattern, array_keys( wp_load_alloptions() ) ); + + if ( is_array( $names ) ) { + foreach ( $names as $_name ) { + $this->register_or_translate_option( $context, $_name, $key ); + } + } + } else { + $this->register_or_translate_option( $context, $name, $key ); + } + } + } + } + } + } + + /** + * Get all wpml-config.xml files in plugins, theme, child theme and Polylang custom directory. + * + * @since 3.1 + * + * @return array + */ + protected function get_files() { + $files = array(); // Plugins // Don't forget sitewide active plugins thanks to Reactorshop http://wordpress.org/support/topic/polylang-and-yoast-seo-plugin/page/2?replies=38#post-4801829 @@ -50,63 +122,65 @@ class PLL_WPML_Config { $plugins = array_merge( $plugins, get_option( 'active_plugins', array() ) ); foreach ( $plugins as $plugin ) { - if ( file_exists( $file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) { - $this->xmls[ dirname( $plugin ) ] = $xml; + if ( file_exists( $file = WP_PLUGIN_DIR . '/' . dirname( $plugin ) . '/wpml-config.xml' ) ) { + $files[ dirname( $plugin ) ] = $file; } } // Theme - if ( file_exists( $file = ( $template = get_template_directory() ) . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) { - $this->xmls[ get_template() ] = $xml; + if ( file_exists( $file = ( $template = get_template_directory() ) . '/wpml-config.xml' ) ) { + $files[ get_template() ] = $file; } // Child theme - if ( ( $stylesheet = get_stylesheet_directory() ) !== $template && file_exists( $file = $stylesheet . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) { - $this->xmls[ get_stylesheet() ] = $xml; + if ( ( $stylesheet = get_stylesheet_directory() ) !== $template && file_exists( $file = $stylesheet . '/wpml-config.xml' ) ) { + $files[ get_stylesheet() ] = $file; } // Custom - if ( file_exists( $file = PLL_LOCAL_DIR . '/wpml-config.xml' ) && false !== $xml = simplexml_load_file( $file ) ) { - $this->xmls['Polylang'] = $xml; + if ( file_exists( $file = PLL_LOCAL_DIR . '/wpml-config.xml' ) ) { + $files['Polylang'] = $file; } - if ( ! empty( $this->xmls ) ) { - add_filter( 'pll_copy_post_metas', array( $this, 'copy_post_metas' ), 10, 2 ); - add_filter( 'pll_get_post_types', array( $this, 'translate_types' ), 10, 2 ); - add_filter( 'pll_get_taxonomies', array( $this, 'translate_taxonomies' ), 10, 2 ); - - foreach ( $this->xmls as $context => $xml ) { - foreach ( $xml->xpath( 'admin-texts/key' ) as $key ) { - $attributes = $key->attributes(); - $name = (string) $attributes['name']; - if ( PLL() instanceof PLL_Frontend ) { - $this->options[ $name ] = $key; - add_filter( 'option_' . $name, array( $this, 'translate_strings' ) ); - } else { - $this->register_string_recursive( $context, get_option( $name ), $key ); - } - } - } - } + return $files; } /** - * Adds custom fields to the list of metas to copy when creating a new translation + * Requires the simplexml PHP module when a wpml-config.xml has been found. + * + * @since 3.1 + * + * @param array $modules An associative array of modules to test for. + * @return array + */ + public function site_status_test_php_modules( $modules ) { + $modules['simplexml'] = array( + 'extension' => 'simplexml', + 'required' => true, + ); + return $modules; + } + + /** + * Adds custom fields to the list of metas to copy when creating a new translation. * * @since 1.0 * - * @param array $metas the list of custom fields to copy or synchronize - * @param bool $sync true for sync, false for copy - * @return array the list of custom fields to copy or synchronize + * @param string[] $metas The list of custom fields to copy or synchronize. + * @param bool $sync True for sync, false for copy. + * @return string[] The list of custom fields to copy or synchronize. */ public function copy_post_metas( $metas, $sync ) { foreach ( $this->xmls as $xml ) { - foreach ( $xml->xpath( 'custom-fields/custom-field' ) as $cf ) { - $attributes = $cf->attributes(); - if ( 'copy' == $attributes['action'] || ( ! $sync && in_array( $attributes['action'], array( 'translate', 'copy-once' ) ) ) ) { - $metas[] = (string) $cf; - } else { - $metas = array_diff( $metas, array( (string) $cf ) ); + $cfs = $xml->xpath( 'custom-fields/custom-field' ); + if ( is_array( $cfs ) ) { + foreach ( $cfs as $cf ) { + $attributes = $cf->attributes(); + if ( 'copy' == $attributes['action'] || ( ! $sync && in_array( $attributes['action'], array( 'translate', 'copy-once' ) ) ) ) { + $metas[] = (string) $cf; + } else { + $metas = array_diff( $metas, array( (string) $cf ) ); + } } } } @@ -114,22 +188,51 @@ class PLL_WPML_Config { } /** - * Language and translation management for custom post types + * Adds term metas to the list of metas to copy when creating a new translation. + * + * @since 2.6 + * + * @param string[] $metas The list of term metas to copy or synchronize. + * @param bool $sync True for sync, false for copy. + * @return string[] The list of term metas to copy or synchronize. + */ + public function copy_term_metas( $metas, $sync ) { + foreach ( $this->xmls as $xml ) { + $cfs = $xml->xpath( 'custom-term-fields/custom-term-field' ); + if ( is_array( $cfs ) ) { + foreach ( $cfs as $cf ) { + $attributes = $cf->attributes(); + if ( 'copy' == $attributes['action'] || ( ! $sync && in_array( $attributes['action'], array( 'translate', 'copy-once' ) ) ) ) { + $metas[] = (string) $cf; + } else { + $metas = array_diff( $metas, array( (string) $cf ) ); + } + } + } + } + return $metas; + } + + /** + * Language and translation management for custom post types. * * @since 1.0 * - * @param array $types list of post type names for which Polylang manages language and translations - * @param bool $hide true when displaying the list in Polylang settings - * @return array list of post type names for which Polylang manages language and translations + * @param string[] $types The list of post type names for which Polylang manages language and translations. + * @param bool $hide True when displaying the list in Polylang settings. + * @return string[] The list of post type names for which Polylang manages language and translations. */ public function translate_types( $types, $hide ) { foreach ( $this->xmls as $xml ) { - foreach ( $xml->xpath( 'custom-types/custom-type' ) as $pt ) { - $attributes = $pt->attributes(); - if ( 1 == $attributes['translate'] && ! $hide ) { - $types[ (string) $pt ] = (string) $pt; - } else { - unset( $types[ (string) $pt ] ); // The theme/plugin author decided what to do with the post type so don't allow the user to change this + $pts = $xml->xpath( 'custom-types/custom-type' ); + if ( is_array( $pts ) ) { + foreach ( $pts as $pt ) { + $attributes = $pt->attributes(); + if ( 1 == $attributes['translate'] && ! $hide ) { + $types[ (string) $pt ] = (string) $pt; + } else { + unset( $types[ (string) $pt ] ); // The theme/plugin author decided what to do with the post type so don't allow the user to change this + } } } } @@ -137,22 +240,25 @@ class PLL_WPML_Config { } /** - * Language and translation management for custom taxonomies + * Language and translation management for custom taxonomies. * * @since 1.0 * - * @param array $taxonomies list of taxonomy names for which Polylang manages language and translations - * @param bool $hide true when displaying the list in Polylang settings - * @return array list of taxonomy names for which Polylang manages language and translations + * @param string[] $taxonomies The list of taxonomy names for which Polylang manages language and translations. + * @param bool $hide True when displaying the list in Polylang settings. + * @return string[] The list of taxonomy names for which Polylang manages language and translations. */ public function translate_taxonomies( $taxonomies, $hide ) { foreach ( $this->xmls as $xml ) { - foreach ( $xml->xpath( 'taxonomies/taxonomy' ) as $tax ) { - $attributes = $tax->attributes(); - if ( 1 == $attributes['translate'] && ! $hide ) { - $taxonomies[ (string) $tax ] = (string) $tax; - } else { - unset( $taxonomies[ (string) $tax ] ); // the theme/plugin author decided what to do with the taxonomy so don't allow the user to change this + $taxos = $xml->xpath( 'taxonomies/taxonomy' ); + if ( is_array( $taxos ) ) { + foreach ( $taxos as $tax ) { + $attributes = $tax->attributes(); + if ( 1 == $attributes['translate'] && ! $hide ) { + $taxonomies[ (string) $tax ] = (string) $tax; + } else { + unset( $taxonomies[ (string) $tax ] ); // the theme/plugin author decided what to do with the taxonomy so don't allow the user to change this + } } } } @@ -160,112 +266,41 @@ class PLL_WPML_Config { } /** - * Translates the strings for an option + * Registers or translates the strings for an option * - * @since 1.0 + * @since 2.8 * - * @param array|string $value Either a string to translate or a list of strings to translate - * @return array|string translated string(s) + * @param string $context The group in which the strings will be registered. + * @param string $name Option name. + * @param object $key XML node. + * @return void */ - public function translate_strings( $value ) { - $option = substr( current_filter(), 7 ); - return $this->translate_strings_recursive( $value, $this->options[ $option ] ); + protected function register_or_translate_option( $context, $name, $key ) { + $option_keys = $this->xml_to_array( $key ); + new PLL_Translate_Option( $name, reset( $option_keys ), array( 'context' => $context ) ); } /** - * Recursively registers strings for a serialized option + * Recursively transforms xml nodes to an array, ready for PLL_Translate_Option. * - * @since 1.0 + * @since 2.9 * - * @param string $context the group in which the strings will be registered - * @param array $options - * @param object $key XML node + * @param object $key XML node. + * @param array $arr Array of option keys to translate. + * @return array */ - protected function register_string_recursive( $context, $options, $key ) { + protected function xml_to_array( $key, &$arr = array() ) { + $attributes = $key->attributes(); + $name = (string) $attributes['name']; $children = $key->children(); + if ( count( $children ) ) { foreach ( $children as $child ) { - $attributes = $child->attributes(); - $name = (string) $attributes['name']; - if ( '*' === $name && is_array( $options ) ) { - foreach ( $options as $n => $option ) { - $this->register_wildcard_options_recursive( $context, $option, $n ); - } - } elseif ( isset( $options[ $name ] ) ) { - $this->register_string_recursive( $context, $options[ $name ], $child ); - } + $arr[ $name ] = $this->xml_to_array( $child, $arr[ $name ] ); } } else { - $attributes = $key->attributes(); - pll_register_string( (string) $attributes['name'], $options, $context, true ); // Multiline as in WPML + $arr[ $name ] = true; // Multiline as in WPML. } - } - - /** - * Recursively registers strings with a wildcard - * - * @since 2.1 - * - * @param string $context the group in which the strings will be registered - * @param array $options - * @param string $name Option name - */ - protected function register_wildcard_options_recursive( $context, $options, $name ) { - if ( is_array( $options ) ) { - foreach ( $options as $n => $option ) { - $this->register_wildcard_options_recursive( $context, $option, $n ); - } - } else { - pll_register_string( $name, $options, $context ); - } - } - - /** - * Recursively translates strings for a serialized option - * - * @since 1.0 - * - * @param array|string $values either a string to translate or a list of strings to translate - * @param object $key XML node - * @return array|string translated string(s) - */ - protected function translate_strings_recursive( $values, $key ) { - $children = $key->children(); - if ( count( $children ) ) { - foreach ( $children as $child ) { - $attributes = $child->attributes(); - $name = (string) $attributes['name']; - if ( '*' === $name && is_array( $values ) ) { - foreach ( $values as $n => $v ) { - $values[ $n ] = $this->translate_wildcard_options_recursive( $v, $n ); - } - } elseif ( isset( $values[ $name ] ) ) { - $values[ $name ] = $this->translate_strings_recursive( $values[ $name ], $child ); - } - } - } else { - $values = pll__( $values ); - } - return $values; - } - - /** - * Recursively translates strings registered by a wildcard - * - * @since 2.1 - * - * @param array|string $options Either a string to translate or a list of strings to translate - * @param string $name Option name - * @return array|string Translated string(s) - */ - protected function translate_wildcard_options_recursive( $options, $name ) { - if ( is_array( $options ) ) { - foreach ( $options as $n => $option ) { - $options[ $n ] = $this->translate_wildcard_options_recursive( $option, $n ); - } - } else { - $options = pll__( $options ); - } - return $options; + return $arr; } } diff --git a/wp-content/plugins/polylang/modules/wpml/wpml-legacy-api.php b/wp-content/plugins/polylang/modules/wpml/wpml-legacy-api.php index f160f376..d70e5b00 100644 --- a/wp-content/plugins/polylang/modules/wpml/wpml-legacy-api.php +++ b/wp-content/plugins/polylang/modules/wpml/wpml-legacy-api.php @@ -1,4 +1,7 @@ whether to skip missing translation or not, 0 or 1, defaults to 0 * orderby => 'id', 'code', 'name', defaults to 'id' @@ -56,15 +59,11 @@ if ( ! function_exists( 'icl_get_languages' ) ) { // NB: When 'skip_missing' is false, WPML returns all languages even if there is no content $languages = PLL()->model->get_languages_list( array( 'hide_empty' => $args['skip_missing'] ) ); - - // FIXME: Backward compatibility with WP < 4.7 - if ( function_exists( 'wp_list_sort' ) ) { - $languages = wp_list_sort( $languages, $orderby, $order ); // Since WP 4.7 - } + $languages = wp_list_sort( $languages, $orderby, $order ); // Since WP 4.7 foreach ( $languages as $lang ) { - // We can find a translation only on frontend - if ( method_exists( PLL()->links, 'get_translation_url' ) ) { + // We can find a translation only on frontend once the global $wp_query object has been instantiated + if ( method_exists( PLL()->links, 'get_translation_url' ) && ! empty( $GLOBALS['wp_query'] ) ) { $url = PLL()->links->get_translation_url( $lang ); } @@ -80,7 +79,7 @@ if ( ! function_exists( 'icl_get_languages' ) ) { 'missing' => empty( $url ) ? 1 : 0, 'translated_name' => '', // Does not exist in Polylang 'language_code' => $lang->slug, - 'country_flag_url' => $lang->flag_url, + 'country_flag_url' => $lang->get_display_flag_url(), 'url' => ! empty( $url ) ? $url : ( empty( $args['link_empty_to'] ) ? PLL()->links->get_home_url( $lang ) : str_replace( '{$lang}', $lang->slug, $args['link_empty_to'] ) ), @@ -116,7 +115,7 @@ if ( ! function_exists( 'icl_link_to_element' ) ) { } $pll_type = ( 'post' == $type || pll_is_translated_post_type( $type ) ) ? 'post' : ( 'term' == $type || pll_is_translated_taxonomy( $type ) ? 'term' : false ); - if ( $pll_type && ( $lang = pll_current_language() ) && ( $tr_id = PLL()->model->$pll_type->get_translation( $id, $lang ) ) && PLL()->links->current_user_can_read( $tr_id ) ) { + if ( $pll_type && ( $lang = pll_current_language() ) && ( $tr_id = PLL()->model->$pll_type->get_translation( $id, $lang ) ) && ( 'term' === $pll_type || PLL()->model->post->current_user_can_read( $tr_id ) ) ) { $id = $tr_id; } elseif ( ! $return_original_if_missing ) { return ''; @@ -128,8 +127,8 @@ if ( ! function_exists( 'icl_link_to_element' ) ) { $text = get_the_title( $id ); } } elseif ( taxonomy_exists( $type ) ) { - $link = wpcom_vip_get_term_link( $id, $type ); - if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && ! empty( $term ) && ! is_wp_error( $term ) ) { + $link = get_term_link( $id, $type ); + if ( empty( $text ) && ( $term = get_term( $id, $type ) ) && $term instanceof WP_Term ) { $text = $term->name; } } @@ -149,7 +148,7 @@ if ( ! function_exists( 'icl_link_to_element' ) ) { $link = sprintf( '%s', esc_url( $link ), esc_html( $text ) ); if ( $echo ) { - echo $link; + echo $link; // phpcs:ignore WordPress.Security.EscapeOutput } return $link; @@ -168,13 +167,13 @@ if ( ! function_exists( 'icl_object_id' ) ) { * @param string $lang Optional, language code, defaults to current language * @return int|null The object id of the translation, null if the translation is missing and $return_original_if_missing set to false */ - function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = false ) { + function icl_object_id( $id, $type = 'post', $return_original_if_missing = false, $lang = '' ) { $lang = $lang ? $lang : pll_current_language(); if ( 'nav_menu' === $type ) { $theme = get_option( 'stylesheet' ); if ( isset( PLL()->options['nav_menus'][ $theme ] ) ) { - foreach ( PLL()->options['nav_menus'][ $theme ] as $loc => $menu ) { + foreach ( PLL()->options['nav_menus'][ $theme ] as $menu ) { if ( array_search( $id, $menu ) && ! empty( $menu[ $lang ] ) ) { $tr_id = $menu[ $lang ]; break; @@ -210,7 +209,8 @@ if ( ! function_exists( 'wpml_get_language_information' ) ) { /** * Undocumented function used by the theme Maya * returns the post language - * @see original WPML code at https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198 + * + * @see https://wpml.org/forums/topic/canonical-urls-for-wpml-duplicated-posts/#post-52198 for the original WPML code * * @since 1.8 * @@ -239,15 +239,16 @@ if ( ! function_exists( 'icl_register_string' ) ) { /** * Registers a string for translation in the "strings translation" panel * + * The 4th and 5th parameters $allow_empty_value and $source_lang are not used by Polylang. + * * @since 0.9.3 * * @param string $context the group in which the string is registered, defaults to 'polylang' * @param string $name a unique name for the string * @param string $string the string to register - * @param bool $allow_empty_value not used - * @param string $source_lang not used by Polylang + * @return void */ - function icl_register_string( $context, $name, $string, $allow_empty_value = false, $source_lang = '' ) { + function icl_register_string( $context, $name, $string ) { PLL_WPML_Compat::instance()->register_string( $context, $name, $string ); } } @@ -260,6 +261,7 @@ if ( ! function_exists( 'icl_unregister_string' ) ) { * * @param string $context the group in which the string is registered, defaults to 'polylang' * @param string $name a unique name for the string + * @return void */ function icl_unregister_string( $context, $name ) { PLL_WPML_Compat::instance()->unregister_string( $context, $name ); @@ -282,7 +284,7 @@ if ( ! function_exists( 'icl_t' ) ) { * @param string|null $lang optional, return the translation in this language, defaults to current language * @return string the translated string */ - function icl_t( $context, $name, $string = false, &$has_translation = null, $bool = false, $lang = null ) { + function icl_t( $context, $name, $string = '', &$has_translation = null, $bool = false, $lang = null ) { return icl_translate( $context, $name, $string, false, $has_translation, $lang ); } } @@ -303,7 +305,7 @@ if ( ! function_exists( 'icl_translate' ) ) { * @param string|null $lang optional, return the translation in this language, defaults to current language * @return string the translated string */ - function icl_translate( $context, $name, $string = false, $bool = false, &$has_translation = null, $lang = null ) { + function icl_translate( $context, $name, $string = '', $bool = false, &$has_translation = null, $lang = null ) { // FIXME WPML can automatically registers the string based on an option if ( empty( $string ) ) { $string = PLL_WPML_Compat::instance()->get_string_by_context_and_name( $context, $name ); @@ -324,12 +326,14 @@ if ( ! function_exists( 'wpml_get_copied_fields_for_post_edit' ) ) { * @return array */ function wpml_get_copied_fields_for_post_edit() { - if ( empty( $_GET['from_post'] ) ) { + if ( empty( $_GET['from_post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification return array(); } + $arr = array( 'original_post_id' => (int) $_GET['from_post'] ); // phpcs:ignore WordPress.Security.NonceVerification + // Don't know what WPML does but Polylang does copy all public meta keys by default - foreach ( $keys = array_unique( array_keys( get_post_custom( (int) $_GET['from_post'] ) ) ) as $k => $meta_key ) { + foreach ( $keys = array_unique( array_keys( get_post_custom( $arr['original_post_id'] ) ) ) as $k => $meta_key ) { if ( is_protected_meta( $meta_key ) ) { unset( $keys[ $k ] ); } @@ -338,7 +342,6 @@ if ( ! function_exists( 'wpml_get_copied_fields_for_post_edit' ) ) { // Apply our filter and fill the expected output ( see /types/embedded/includes/fields-post.php ) /** This filter is documented in modules/sync/admin-sync.php */ $arr['fields'] = array_unique( apply_filters( 'pll_copy_post_metas', empty( $keys ) ? array() : $keys, false ) ); - $arr['original_post_id'] = (int) $_GET['from_post']; return $arr; } } @@ -359,6 +362,7 @@ if ( ! function_exists( 'icl_get_default_language' ) ) { if ( ! function_exists( 'wpml_get_default_language' ) ) { /** * Undocumented function reported to be used by Table Rate Shipping for WooCommerce + * * @see https://wordpress.org/support/topic/add-wpml-compatibility-function * * @since 1.8.2 diff --git a/wp-content/plugins/polylang/polylang.php b/wp-content/plugins/polylang/polylang.php index b769272c..87ef62f8 100644 --- a/wp-content/plugins/polylang/polylang.php +++ b/wp-content/plugins/polylang/polylang.php @@ -1,23 +1,32 @@ . */ if ( ! defined( 'ABSPATH' ) ) { - exit; // don't access directly + exit; // Don't access directly. }; -if ( defined( 'POLYLANG_BASENAME' ) ) { - // The user is attempting to activate a second plugin instance, typically Polylang and Polylang Pro +if ( defined( 'POLYLANG_VERSION' ) ) { + // The user is attempting to activate a second plugin instance, typically Polylang and Polylang Pro. require_once ABSPATH . 'wp-admin/includes/plugin.php'; - if ( defined( 'POLYLANG_PRO' ) ) { - // Polylang Pro is already activated - if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { - require_once ABSPATH . 'wp-includes/pluggable.php'; - deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate this plugin - // WP does not allow us to send a custom meaningful message, so just tell the plugin has been deactivated - wp_redirect( add_query_arg( 'deactivate', 'true', remove_query_arg( 'activate' ) ) ); - exit; - } - } else { - // Polylang was activated, deactivate it to keep only what we expect to be Polylang Pro - deactivate_plugins( POLYLANG_BASENAME ); + require_once ABSPATH . 'wp-includes/pluggable.php'; + if ( is_plugin_active( plugin_basename( __FILE__ ) ) ) { + deactivate_plugins( plugin_basename( __FILE__ ) ); // Deactivate this plugin. + // WP does not allow us to send a custom meaningful message, so just tell the plugin has been deactivated. + wp_safe_redirect( add_query_arg( 'deactivate', 'true', remove_query_arg( 'activate' ) ) ); + exit; } } else { // Go on loading the plugin - define( 'POLYLANG_VERSION', '2.3.4' ); - define( 'PLL_MIN_WP_VERSION', '4.4' ); + define( 'POLYLANG_VERSION', '3.1.1' ); + define( 'PLL_MIN_WP_VERSION', '5.4' ); + define( 'PLL_MIN_PHP_VERSION', '5.6' ); - define( 'POLYLANG_FILE', __FILE__ ); // this file - define( 'POLYLANG_BASENAME', plugin_basename( POLYLANG_FILE ) ); // plugin name as known by WP - define( 'POLYLANG_DIR', dirname( POLYLANG_FILE ) ); // our directory + define( 'POLYLANG_FILE', __FILE__ ); + define( 'POLYLANG_DIR', __DIR__ ); - define( 'PLL_ADMIN_INC', POLYLANG_DIR . '/admin' ); - define( 'PLL_FRONT_INC', POLYLANG_DIR . '/frontend' ); - define( 'PLL_INC', POLYLANG_DIR . '/include' ); - define( 'PLL_INSTALL_INC', POLYLANG_DIR . '/install' ); - define( 'PLL_MODULES_INC', POLYLANG_DIR . '/modules' ); - define( 'PLL_SETTINGS_INC', POLYLANG_DIR . '/settings' ); + // Whether we are using Polylang or Polylang Pro, get the filename of the plugin in use. + if ( ! defined( 'POLYLANG_ROOT_FILE' ) ) { + define( 'POLYLANG_ROOT_FILE', __FILE__ ); + } - require_once PLL_INC . '/class-polylang.php'; + if ( ! defined( 'POLYLANG_BASENAME' ) ) { + define( 'POLYLANG_BASENAME', plugin_basename( __FILE__ ) ); // Plugin name as known by WP. + require __DIR__ . '/vendor/autoload.php'; + } - if ( file_exists( PLL_INC . '/class-polylang-pro.php' ) ) { - define( 'POLYLANG_PRO', true ); - require_once PLL_INC . '/class-polylang-pro.php'; + define( 'POLYLANG', ucwords( str_replace( '-', ' ', dirname( POLYLANG_BASENAME ) ) ) ); + + if ( empty( $_GET['deactivate-polylang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + new Polylang(); } } diff --git a/wp-content/plugins/polylang/readme.txt b/wp-content/plugins/polylang/readme.txt index 4d10c168..503fde03 100644 --- a/wp-content/plugins/polylang/readme.txt +++ b/wp-content/plugins/polylang/readme.txt @@ -1,11 +1,13 @@ === Polylang === -Contributors: Chouby +Contributors: Chouby, manooweb, raaaahman, marianne38, sebastienserre Donate link: https://polylang.pro Tags: multilingual, bilingual, translate, translation, language, multilanguage, international, localization -Requires at least: 4.4 -Tested up to: 4.9 -Stable tag: 2.3.4 -License: GPLv2 or later +Requires at least: 5.4 +Tested up to: 5.8 +Requires PHP: 5.6 +Stable tag: 3.1.1 +License: GPLv3 or later +License URI: https://www.gnu.org/licenses/gpl-3.0.html Making WordPress multilingual @@ -41,7 +43,7 @@ Don't hesitate to [give your feedback](http://wordpress.org/support/view/plugin- == Installation == -1. Make sure you are using WordPress 4.4 or later and that your server is running PHP 5.2.4 or later (same requirement as WordPress itself) +1. Make sure you are using WordPress 5.1 or later and that your server is running PHP 5.6 or later (same requirement as WordPress itself) 1. If you tried other multilingual plugins, deactivate them before activating Polylang, otherwise, you may get unexpected results! 1. Install and activate the plugin as usual from the 'Plugins' menu in WordPress. 1. Go to the languages settings page and create the languages you need @@ -76,66 +78,107 @@ Don't hesitate to [give your feedback](http://wordpress.org/support/view/plugin- == Changelog == -= 2.3.4 (2018-03-27) = += 3.1.1 (2021-08-16) = -* Pro: Fix conflict with Pods related to translated slugs for custom post types -* Add Friulian to the predefined languages list -* Fix conflict (javascript error) with Gütenberg #225 -* Fix conflict on ajax requests introduced by WooCoommerce 3.3.4 -* Fix queries by 'category_name' not auto translated #238 +* Pro: Fix a fatal error with The Events Calendar +* Allow to remove the cookie with the pll_cookie_expiration filter #905 -= 2.3.3 (2018-03-15) = += 3.1 (2021-07-27) = -* Pro: Fix tax query using a term sharing slugs (fix a conflict with Fusion Builder) -* Restore Polylang (free) on REST requests, while disabling the language filter as in v2.3 -* Rework auto translated query with taxonomy in different language #223 -* Synchronize Yoast SEO primary category (needs Yoast SEO 7.0+) -* Fix PHP warning introduced by Yoast SEO 7.0 #229 -* Fix tax query when using the relation 'OR' -* Fix a conflict with the combination of Barrel + WP Bakery Page Builder -* Fix broken redirect with MU domain mapping #226 -* Fix site title not translated in password change email +* Add compatibility with WordPress 5.8 +* Raise Minimum WordPress version to 5.4 +* Pro: Allow to filter blocks by language in the widget block editor +* Pro: Allow to export and import XLIFF files for string translations +* Pro: Add the language switcher in the navigation block (experimental) +* Pro: Replace dashicons by svg icons in the block editor +* Pro: The Events Calendar: Add compatibility with Views V2 (only for sites using only one domain) +* Pro: Fix + icon displayed in the block editor sidebar when the user cannot create a translation +* Add a warning section to the site health for posts and terms without languages #825 +* Require the simplexml extension in the site health if a wpml-config.xml is found #827 +* Remove the information about the WPML compabitility mode in settings #843 +* The browser preferred language detection is now deactivated by default +* The media are now untranslated by default +* Highlight the language filter in the admin toolbar when it's active #821 +* Allow to query comments in multiple languages (just as posts and terms) #840 +* Don't disable the translation input field in the classic metabox #841 Props Onatcer +* Optimize all images including flags #848 Props lowwebtech +* Don't redirect if WordPress doesn't validate the redirect url to avoid redirects to /wp-admin/ #879 +* Fix media appearing to have a language after the language is changed in the media library grid view #807 +* Fix media not all deleted when bulk deleting from the grid view of the media library #830 +* Fix when more than one language switcher are added to the same menu #853 +* Fix PHP notice when adding a CPT archive link to a menu #868 Props davidwebca -= 2.3.2 (2018-03-05) = += 3.0.6 (2021-06-22) = -* Pro: Fix REST requests not filtered by the requested language (introduced in 2.3). -* Pro: Fix error 404 on single posts if posts are untranslatable -* Deactivate Polylang (free) on REST requests by default. -* Fix translated terms unassigned from posts when deleting a term -* Fix auto translated query with taxonomy in different language returning empty results since WP 4.9 #223 -* Fix conflict with a homepage option of the theme Extra -* Fix warning when filtering get_pages() +* Fix a conflict with the WooCommerce cart translation and cache plugins #876 -= 2.3.1 (2018-02-15) = += 3.0.5 (2021-06-08) = -* Pro: Fix GET REST request with slug parameter deleting the post slug -* Fix http request with a custom query var being redirected to the home page #216 +* Pro: fix original post not assigned to a new translation when the languages sidebar is closed +* Pro: Attempt to fix zip file corrupted on some installations when exporting string translations +* Support session cookie with the pll_cookie_expiration filter #835 +* Fix javascript error when a plugin defines its own editor for translated post types #837 +* Fix languages displayed in screen options when editing a term #850 +* Cache: fix post type archive cache not cleared when saving a post #828 -= 2.3 (2018-01-30) = += 3.0.4 (2021-04-27) = -* Pro: Duplicating a post now duplicates untranslated terms and the featured image (if media are translatable) -* Pro: Add filter 'pll_sync_post_fields' -* Pro: Translate ACF Pro clone fields when creating a new field group translation -* Pro: Allow to share slugs when creating a post or term with the REST API -* Pro: Load asynchronously the script added on front for multiple domains and subdomains -* Pro: Fix 'lang' parameter not interpreted when the query includes 'name' -* Refactor the synchronization of metas for better synchronization and performance improvement -* Refactor the synchronization of taxonomy terms for performance improvement -* Refactor language and translations saving for performance improvement -* Refactor the synchronization of sticky posts -* Remove all languages files. All translations are now maintained on https://translate.wordpress.org/projects/wp-plugins/polylang #199 -* Refactor the list of languages to merge predefined languages, Facebook locales and fixes for W3C locales -* Automatically deactivate Polylang when activating Polylang Pro -* Disable programmatically translated post types and taxonomies in settings. Props Ulrich Pogson. #180 -* Set the cookie language in Javascript when a cache plugin is active -* Automatically remove the home page from cache when requesting the detection of the browser preferred language -* Use relative urls for the admin language filter in admin bar. #209 -* Disable auto translation of WP_Term_Query if it has a 'lang' parameter -* Don't filter REST requests by default. #211 -* Fix Yoast SEO statistics in dashboard showing only the default language. #211 -* Fix WP Rocket clearing the cache of the wrong adjacent post -* Fix random header image -* Fix home page not correctly loaded when adding a query var -* Fix: Impossible to change the language code when the language code is also a WordPress locale. +* Improve performance in the pages (or hierarchical post types) list table +* Fix an ajax conflict with WooCommerce License manager + += 3.0.3 (2021-03-23) = + +* Fix a warning when a language is corrupted in database (term_language missing) +* Fix confirmation modal with WooCommerce and WordPress < 5.6 +* Fix an ajax conflict with WooCommerce Tree Table Rate Shipping and HubSpot All-In-One Marketing + += 3.0.2 (2021-03-16) = + +* Move hreflang attributes higher in the head section #771 +* Fix custom flags not working (introduced in 3.0) +* Fix translation of the confirmation modal when changing the language of a post +* Fix js and css not loaded when Polylang is used as a mu-plugin (introduced in 3.0) +* Fix support for html5 stylesheet link tags #775 +* Fix possible warning in frontend-filters-links.php +* Yoast SEO Premium: Take over the multilingual compatibility removed in Yoast SEO Premium 15.8 #796 +* Yoast SEO: Fix CPT breadcrumb title when the option is left empty #794 +* Yoast SEO: Fix sitemap.xml not redirected on secondary domains #789 + += 3.0.1 (2021-03-10) = + +* Fix media gallery messed when editing a post in the classic editor +* Fix missing script dependency on old WP versions +* Fix CSS conflict with WooCommerce Bookings for WP < 5.6 +* Fix conflict resulting in '__' already defined in block-editor.js. #779 +* Fix search form removed for some themes. Props Marián Kadaňka. #780 +* Fix fatal error with very old versions of Yoast SEO. Props Nicola Peluchetti. #781 + += 3.0 (2021-03-08) = + +* Add compatibility with WordPress 5.7 +* Remove upgrades from Polylang older than 1.8 +* Remove deprecated class PLL_Pointer +* Pro: Hide the license keys +* Pro: Fix redirect to the home page of a deactivated language +* Pro: Fix synchronization of post status not working +* Pro: Fix language switcher block not working in a post retrieved in REST API +* Pro: Fix PO export of strings with line breaks +* Pro: Fix file block title customization lost +* Add a dialog box to ask a confirmation about a language change in classic and block editors +* Improve browser language detection #591 +* Improve robustness and documentation of code +* Fix media library after the language has been chnaged in the editor metabox +* Fix duplicated title attribute on flag link in posts list +* Fix legacy block editor language metabox compatibility with WordPress 5.6 +* Fix uploaded theme and plugin files in media library +* Fix site title not translated in email change confirmation email +* Fix remaining deprecated jQuery notices #741 +* Fix compatibility with GN publisher +* Fix compatibility with Woodmart theme search form +* Fix compatibility issue with 3rd party ajax requests since jQuery 3.3 #744 +* Fix CSS conflict with WooCommerce Bookings +* Fix browser error when displaying an embed and using a cache plugin #757 +* Fix post type archive title and metadesc not translated in Yoast SEO +* Fix PHP notice in REST API See [changelog.txt](https://plugins.svn.wordpress.org/polylang/trunk/changelog.txt) for older changelog diff --git a/wp-content/plugins/polylang/settings/flags.php b/wp-content/plugins/polylang/settings/flags.php index affb594d..60e8d9f7 100644 --- a/wp-content/plugins/polylang/settings/flags.php +++ b/wp-content/plugins/polylang/settings/flags.php @@ -1,4 +1,7 @@ __( 'Andorra', 'polylang' ), - 'ae' => __( 'United Arab Emirates', 'polylang' ), - 'af' => __( 'Afghanistan', 'polylang' ), - 'ag' => __( 'Antigua and Barbuda', 'polylang' ), - 'ai' => __( 'Anguilla', 'polylang' ), - 'al' => __( 'Albania', 'polylang' ), - 'am' => __( 'Armenia', 'polylang' ), - 'an' => __( 'Netherlands Antilles', 'polylang' ), - 'ao' => __( 'Angola', 'polylang' ), - 'ar' => __( 'Argentina', 'polylang' ), - 'arab' => __( 'Arab league', 'polylang' ), - 'as' => __( 'American Samoa', 'polylang' ), - 'at' => __( 'Austria', 'polylang' ), - 'au' => __( 'Australia', 'polylang' ), - 'aw' => __( 'Aruba', 'polylang' ), - 'ax' => __( 'Åland Islands', 'polylang' ), - 'az' => __( 'Azerbaijan', 'polylang' ), - 'ba' => __( 'Bosnia and Herzegovina', 'polylang' ), - 'basque' => __( 'Basque Country', 'polylang' ), - 'bb' => __( 'Barbados', 'polylang' ), - 'bd' => __( 'Bangladesh', 'polylang' ), - 'be' => __( 'Belgium', 'polylang' ), - 'bf' => __( 'Burkina Faso', 'polylang' ), - 'bg' => __( 'Bulgaria', 'polylang' ), - 'bh' => __( 'Bahrain', 'polylang' ), - 'bi' => __( 'Burundi', 'polylang' ), - 'bj' => __( 'Benin', 'polylang' ), - 'bm' => __( 'Bermuda', 'polylang' ), - 'bn' => __( 'Brunei', 'polylang' ), - 'bo' => __( 'Bolivia', 'polylang' ), - 'br' => __( 'Brazil', 'polylang' ), - 'bs' => __( 'Bahamas', 'polylang' ), - 'bt' => __( 'Bhutan', 'polylang' ), - 'bw' => __( 'Botswana', 'polylang' ), - 'by' => __( 'Belarus', 'polylang' ), - 'bz' => __( 'Belize', 'polylang' ), - 'ca' => __( 'Canada', 'polylang' ), + 'ad' => __( 'Andorra', 'polylang' ), + 'ae' => __( 'United Arab Emirates', 'polylang' ), + 'af' => __( 'Afghanistan', 'polylang' ), + 'ag' => __( 'Antigua and Barbuda', 'polylang' ), + 'ai' => __( 'Anguilla', 'polylang' ), + 'al' => __( 'Albania', 'polylang' ), + 'am' => __( 'Armenia', 'polylang' ), + 'an' => __( 'Netherlands Antilles', 'polylang' ), + 'ao' => __( 'Angola', 'polylang' ), + 'ar' => __( 'Argentina', 'polylang' ), + 'arab' => __( 'Arab league', 'polylang' ), + 'as' => __( 'American Samoa', 'polylang' ), + 'at' => __( 'Austria', 'polylang' ), + 'au' => __( 'Australia', 'polylang' ), + 'aw' => __( 'Aruba', 'polylang' ), + 'ax' => __( 'Åland Islands', 'polylang' ), + 'az' => __( 'Azerbaijan', 'polylang' ), + 'ba' => __( 'Bosnia and Herzegovina', 'polylang' ), + 'basque' => __( 'Basque Country', 'polylang' ), + 'bb' => __( 'Barbados', 'polylang' ), + 'bd' => __( 'Bangladesh', 'polylang' ), + 'be' => __( 'Belgium', 'polylang' ), + 'bf' => __( 'Burkina Faso', 'polylang' ), + 'bg' => __( 'Bulgaria', 'polylang' ), + 'bh' => __( 'Bahrain', 'polylang' ), + 'bi' => __( 'Burundi', 'polylang' ), + 'bj' => __( 'Benin', 'polylang' ), + 'bm' => __( 'Bermuda', 'polylang' ), + 'bn' => __( 'Brunei', 'polylang' ), + 'bo' => __( 'Bolivia', 'polylang' ), + 'br' => __( 'Brazil', 'polylang' ), + 'bs' => __( 'Bahamas', 'polylang' ), + 'bt' => __( 'Bhutan', 'polylang' ), + 'bw' => __( 'Botswana', 'polylang' ), + 'by' => __( 'Belarus', 'polylang' ), + 'bz' => __( 'Belize', 'polylang' ), + 'ca' => __( 'Canada', 'polylang' ), 'catalonia' => __( 'Catalonia', 'polylang' ), - 'cc' => __( 'Cocos', 'polylang' ), - 'cd' => __( 'Democratic Republic of the Congo', 'polylang' ), - 'cf' => __( 'Central African Republic', 'polylang' ), - 'cg' => __( 'Congo', 'polylang' ), - 'ch' => __( 'Switzerland', 'polylang' ), - 'ci' => __( 'Ivory Coast', 'polylang' ), - 'ck' => __( 'Cook Islands', 'polylang' ), - 'cl' => __( 'Chile', 'polylang' ), - 'cm' => __( 'Cameroon', 'polylang' ), - 'cn' => __( 'China', 'polylang' ), - 'co' => __( 'Colombia', 'polylang' ), - 'cr' => __( 'Costa Rica', 'polylang' ), - 'cu' => __( 'Cuba', 'polylang' ), - 'cv' => __( 'Cape Verde', 'polylang' ), - 'cx' => __( 'Christmas Island', 'polylang' ), - 'cy' => __( 'Cyprus', 'polylang' ), - 'cz' => __( 'Czech Republic', 'polylang' ), - 'de' => __( 'Germany', 'polylang' ), - 'dj' => __( 'Djibouti', 'polylang' ), - 'dk' => __( 'Denmark', 'polylang' ), - 'dm' => __( 'Dominica', 'polylang' ), - 'do' => __( 'Dominican Republic', 'polylang' ), - 'dz' => __( 'Algeria', 'polylang' ), - 'ec' => __( 'Ecuador', 'polylang' ), - 'ee' => __( 'Estonia', 'polylang' ), - 'eg' => __( 'Egypt', 'polylang' ), - 'eh' => __( 'Western Sahara', 'polylang' ), - 'england' => __( 'England', 'polylang' ), - 'er' => __( 'Eritrea', 'polylang' ), - 'es' => __( 'Spain', 'polylang' ), + 'cc' => __( 'Cocos', 'polylang' ), + 'cd' => __( 'Democratic Republic of the Congo', 'polylang' ), + 'cf' => __( 'Central African Republic', 'polylang' ), + 'cg' => __( 'Congo', 'polylang' ), + 'ch' => __( 'Switzerland', 'polylang' ), + 'ci' => __( 'Ivory Coast', 'polylang' ), + 'ck' => __( 'Cook Islands', 'polylang' ), + 'cl' => __( 'Chile', 'polylang' ), + 'cm' => __( 'Cameroon', 'polylang' ), + 'cn' => __( 'China', 'polylang' ), + 'co' => __( 'Colombia', 'polylang' ), + 'cr' => __( 'Costa Rica', 'polylang' ), + 'cu' => __( 'Cuba', 'polylang' ), + 'cv' => __( 'Cape Verde', 'polylang' ), + 'cx' => __( 'Christmas Island', 'polylang' ), + 'cy' => __( 'Cyprus', 'polylang' ), + 'cz' => __( 'Czech Republic', 'polylang' ), + 'de' => __( 'Germany', 'polylang' ), + 'dj' => __( 'Djibouti', 'polylang' ), + 'dk' => __( 'Denmark', 'polylang' ), + 'dm' => __( 'Dominica', 'polylang' ), + 'do' => __( 'Dominican Republic', 'polylang' ), + 'dz' => __( 'Algeria', 'polylang' ), + 'ec' => __( 'Ecuador', 'polylang' ), + 'ee' => __( 'Estonia', 'polylang' ), + 'eg' => __( 'Egypt', 'polylang' ), + 'eh' => __( 'Western Sahara', 'polylang' ), + 'england' => __( 'England', 'polylang' ), + 'er' => __( 'Eritrea', 'polylang' ), + 'es' => __( 'Spain', 'polylang' ), 'esperanto' => __( 'Esperanto', 'polylang' ), - 'et' => __( 'Ethiopia', 'polylang' ), - 'fi' => __( 'Finland', 'polylang' ), - 'fj' => __( 'Fiji', 'polylang' ), - 'fk' => __( 'Falkland Islands', 'polylang' ), - 'fm' => __( 'Micronesia', 'polylang' ), - 'fo' => __( 'Faroe Islands', 'polylang' ), - 'fr' => __( 'France', 'polylang' ), - 'ga' => __( 'Gabon', 'polylang' ), - 'galicia' => __( 'Galicia', 'polylang' ), - 'gb' => __( 'United Kingdom', 'polylang' ), - 'gd' => __( 'Grenada', 'polylang' ), - 'ge' => __( 'Georgia', 'polylang' ), - 'gh' => __( 'Ghana', 'polylang' ), - 'gi' => __( 'Gibraltar', 'polylang' ), - 'gl' => __( 'Greenland', 'polylang' ), - 'gm' => __( 'Gambia', 'polylang' ), - 'gn' => __( 'Guinea', 'polylang' ), - 'gp' => __( 'Guadeloupe', 'polylang' ), - 'gq' => __( 'Equatorial Guinea', 'polylang' ), - 'gr' => __( 'Greece', 'polylang' ), - 'gs' => __( 'South Georgia and the South Sandwich Islands', 'polylang' ), - 'gt' => __( 'Guatemala', 'polylang' ), - 'gu' => __( 'Guam', 'polylang' ), - 'gw' => __( 'Guinea-Bissau', 'polylang' ), - 'gy' => __( 'Guyana', 'polylang' ), - 'hk' => __( 'Hong Kong', 'polylang' ), - 'hm' => __( 'Heard Island and McDonald Islands', 'polylang' ), - 'hn' => __( 'Honduras', 'polylang' ), - 'hr' => __( 'Croatia', 'polylang' ), - 'ht' => __( 'Haiti', 'polylang' ), - 'hu' => __( 'Hungary', 'polylang' ), - 'id' => __( 'Indonesia', 'polylang' ), - 'ie' => __( 'Republic of Ireland', 'polylang' ), - 'il' => __( 'Israel', 'polylang' ), - 'in' => __( 'India', 'polylang' ), - 'io' => __( 'British Indian Ocean Territory', 'polylang' ), - 'iq' => __( 'Iraq', 'polylang' ), - 'ir' => __( 'Iran', 'polylang' ), - 'is' => __( 'Iceland', 'polylang' ), - 'it' => __( 'Italy', 'polylang' ), - 'jm' => __( 'Jamaica', 'polylang' ), - 'jo' => __( 'Jordan', 'polylang' ), - 'jp' => __( 'Japan', 'polylang' ), - 'ke' => __( 'Kenya', 'polylang' ), - 'kg' => __( 'Kyrgyzstan', 'polylang' ), - 'kh' => __( 'Cambodia', 'polylang' ), - 'ki' => __( 'Kiribati', 'polylang' ), - 'km' => __( 'Comoros', 'polylang' ), - 'kn' => __( 'Saint Kitts and Nevis', 'polylang' ), - 'kp' => __( 'North Korea', 'polylang' ), - 'kr' => __( 'South Korea', 'polylang' ), + 'et' => __( 'Ethiopia', 'polylang' ), + 'fi' => __( 'Finland', 'polylang' ), + 'fj' => __( 'Fiji', 'polylang' ), + 'fk' => __( 'Falkland Islands', 'polylang' ), + 'fm' => __( 'Micronesia', 'polylang' ), + 'fo' => __( 'Faroe Islands', 'polylang' ), + 'fr' => __( 'France', 'polylang' ), + 'ga' => __( 'Gabon', 'polylang' ), + 'galicia' => __( 'Galicia', 'polylang' ), + 'gb' => __( 'United Kingdom', 'polylang' ), + 'gd' => __( 'Grenada', 'polylang' ), + 'ge' => __( 'Georgia', 'polylang' ), + 'gh' => __( 'Ghana', 'polylang' ), + 'gi' => __( 'Gibraltar', 'polylang' ), + 'gl' => __( 'Greenland', 'polylang' ), + 'gm' => __( 'Gambia', 'polylang' ), + 'gn' => __( 'Guinea', 'polylang' ), + 'gp' => __( 'Guadeloupe', 'polylang' ), + 'gq' => __( 'Equatorial Guinea', 'polylang' ), + 'gr' => __( 'Greece', 'polylang' ), + 'gs' => __( 'South Georgia and the South Sandwich Islands', 'polylang' ), + 'gt' => __( 'Guatemala', 'polylang' ), + 'gu' => __( 'Guam', 'polylang' ), + 'gw' => __( 'Guinea-Bissau', 'polylang' ), + 'gy' => __( 'Guyana', 'polylang' ), + 'hk' => __( 'Hong Kong', 'polylang' ), + 'hm' => __( 'Heard Island and McDonald Islands', 'polylang' ), + 'hn' => __( 'Honduras', 'polylang' ), + 'hr' => __( 'Croatia', 'polylang' ), + 'ht' => __( 'Haiti', 'polylang' ), + 'hu' => __( 'Hungary', 'polylang' ), + 'id' => __( 'Indonesia', 'polylang' ), + 'ie' => __( 'Republic of Ireland', 'polylang' ), + 'il' => __( 'Israel', 'polylang' ), + 'in' => __( 'India', 'polylang' ), + 'io' => __( 'British Indian Ocean Territory', 'polylang' ), + 'iq' => __( 'Iraq', 'polylang' ), + 'ir' => __( 'Iran', 'polylang' ), + 'is' => __( 'Iceland', 'polylang' ), + 'it' => __( 'Italy', 'polylang' ), + 'jm' => __( 'Jamaica', 'polylang' ), + 'jo' => __( 'Jordan', 'polylang' ), + 'jp' => __( 'Japan', 'polylang' ), + 'ke' => __( 'Kenya', 'polylang' ), + 'kg' => __( 'Kyrgyzstan', 'polylang' ), + 'kh' => __( 'Cambodia', 'polylang' ), + 'ki' => __( 'Kiribati', 'polylang' ), + 'km' => __( 'Comoros', 'polylang' ), + 'kn' => __( 'Saint Kitts and Nevis', 'polylang' ), + 'kp' => __( 'North Korea', 'polylang' ), + 'kr' => __( 'South Korea', 'polylang' ), 'kurdistan' => __( 'Kurdistan', 'polylang' ), - 'kw' => __( 'Kuwait', 'polylang' ), - 'ky' => __( 'Cayman Islands', 'polylang' ), - 'kz' => __( 'Kazakhstan', 'polylang' ), - 'la' => __( 'Laos', 'polylang' ), - 'lb' => __( 'Lebanon', 'polylang' ), - 'lc' => __( 'Saint Lucia', 'polylang' ), - 'li' => __( 'Liechtenstein', 'polylang' ), - 'lk' => __( 'Sri Lanka', 'polylang' ), - 'lr' => __( 'Liberia', 'polylang' ), - 'ls' => __( 'Lesotho', 'polylang' ), - 'lt' => __( 'Lithuania', 'polylang' ), - 'lu' => __( 'Luxembourg', 'polylang' ), - 'lv' => __( 'Latvia', 'polylang' ), - 'ly' => __( 'Libya', 'polylang' ), - 'ma' => __( 'Morocco', 'polylang' ), - 'mc' => __( 'Monaco', 'polylang' ), - 'md' => __( 'Moldova', 'polylang' ), - 'me' => __( 'Montenegro', 'polylang' ), - 'mg' => __( 'Madagascar', 'polylang' ), - 'mh' => __( 'Marshall Islands', 'polylang' ), - 'mk' => __( 'Macedonia', 'polylang' ), - 'ml' => __( 'Mali', 'polylang' ), - 'mm' => __( 'Myanmar', 'polylang' ), - 'mn' => __( 'Mongolia', 'polylang' ), - 'mo' => __( 'Macao', 'polylang' ), - 'mp' => __( 'Northern Mariana Islands', 'polylang' ), - 'mq' => __( 'Martinique', 'polylang' ), - 'mr' => __( 'Mauritania', 'polylang' ), - 'ms' => __( 'Montserrat', 'polylang' ), - 'mt' => __( 'Malta', 'polylang' ), - 'mu' => __( 'Mauritius', 'polylang' ), - 'mv' => __( 'Maldives', 'polylang' ), - 'mw' => __( 'Malawi', 'polylang' ), - 'mx' => __( 'Mexico', 'polylang' ), - 'my' => __( 'Malaysia', 'polylang' ), - 'mz' => __( 'Mozambique', 'polylang' ), - 'na' => __( 'Namibia', 'polylang' ), - 'nc' => __( 'New Caledonia', 'polylang' ), - 'ne' => __( 'Niger', 'polylang' ), - 'nf' => __( 'Norfolk Island', 'polylang' ), - 'ng' => __( 'Nigeria', 'polylang' ), - 'ni' => __( 'Nicaragua', 'polylang' ), - 'nl' => __( 'Netherlands', 'polylang' ), - 'no' => __( 'Norway', 'polylang' ), - 'np' => __( 'Nepal', 'polylang' ), - 'nr' => __( 'Nauru', 'polylang' ), - 'nu' => __( 'Niue', 'polylang' ), - 'nz' => __( 'New Zealand', 'polylang' ), + 'kw' => __( 'Kuwait', 'polylang' ), + 'ky' => __( 'Cayman Islands', 'polylang' ), + 'kz' => __( 'Kazakhstan', 'polylang' ), + 'la' => __( 'Laos', 'polylang' ), + 'lb' => __( 'Lebanon', 'polylang' ), + 'lc' => __( 'Saint Lucia', 'polylang' ), + 'li' => __( 'Liechtenstein', 'polylang' ), + 'lk' => __( 'Sri Lanka', 'polylang' ), + 'lr' => __( 'Liberia', 'polylang' ), + 'ls' => __( 'Lesotho', 'polylang' ), + 'lt' => __( 'Lithuania', 'polylang' ), + 'lu' => __( 'Luxembourg', 'polylang' ), + 'lv' => __( 'Latvia', 'polylang' ), + 'ly' => __( 'Libya', 'polylang' ), + 'ma' => __( 'Morocco', 'polylang' ), + 'mc' => __( 'Monaco', 'polylang' ), + 'md' => __( 'Moldova', 'polylang' ), + 'me' => __( 'Montenegro', 'polylang' ), + 'mg' => __( 'Madagascar', 'polylang' ), + 'mh' => __( 'Marshall Islands', 'polylang' ), + 'mk' => __( 'North Macedonia', 'polylang' ), + 'ml' => __( 'Mali', 'polylang' ), + 'mm' => __( 'Myanmar', 'polylang' ), + 'mn' => __( 'Mongolia', 'polylang' ), + 'mo' => __( 'Macao', 'polylang' ), + 'mp' => __( 'Northern Mariana Islands', 'polylang' ), + 'mq' => __( 'Martinique', 'polylang' ), + 'mr' => __( 'Mauritania', 'polylang' ), + 'ms' => __( 'Montserrat', 'polylang' ), + 'mt' => __( 'Malta', 'polylang' ), + 'mu' => __( 'Mauritius', 'polylang' ), + 'mv' => __( 'Maldives', 'polylang' ), + 'mw' => __( 'Malawi', 'polylang' ), + 'mx' => __( 'Mexico', 'polylang' ), + 'my' => __( 'Malaysia', 'polylang' ), + 'mz' => __( 'Mozambique', 'polylang' ), + 'na' => __( 'Namibia', 'polylang' ), + 'nc' => __( 'New Caledonia', 'polylang' ), + 'ne' => __( 'Niger', 'polylang' ), + 'nf' => __( 'Norfolk Island', 'polylang' ), + 'ng' => __( 'Nigeria', 'polylang' ), + 'ni' => __( 'Nicaragua', 'polylang' ), + 'nl' => __( 'Netherlands', 'polylang' ), + 'no' => __( 'Norway', 'polylang' ), + 'np' => __( 'Nepal', 'polylang' ), + 'nr' => __( 'Nauru', 'polylang' ), + 'nu' => __( 'Niue', 'polylang' ), + 'nz' => __( 'New Zealand', 'polylang' ), 'occitania' => __( 'Occitania', 'polylang' ), - 'om' => __( 'Oman', 'polylang' ), - 'pa' => __( 'Panama', 'polylang' ), - 'pe' => __( 'Peru', 'polylang' ), - 'pf' => __( 'French Polynesia', 'polylang' ), - 'pg' => __( 'Papua New Guinea', 'polylang' ), - 'ph' => __( 'Philippines', 'polylang' ), - 'pk' => __( 'Pakistan', 'polylang' ), - 'pl' => __( 'Poland', 'polylang' ), - 'pm' => __( 'Saint Pierre and Miquelon', 'polylang' ), - 'pn' => __( 'Pitcairn', 'polylang' ), - 'pr' => __( 'Puerto Rico', 'polylang' ), - 'ps' => __( 'Palestinian Territory', 'polylang' ), - 'pt' => __( 'Portugal', 'polylang' ), - 'pw' => __( 'Belau', 'polylang' ), - 'py' => __( 'Paraguay', 'polylang' ), - 'qa' => __( 'Qatar', 'polylang' ), - 'quebec' => __( 'Quebec', 'polylang' ), - 'ro' => __( 'Romania', 'polylang' ), - 'rs' => __( 'Serbia', 'polylang' ), - 'ru' => __( 'Russia', 'polylang' ), - 'rw' => __( 'Rwanda', 'polylang' ), - 'sa' => __( 'Saudi Arabia', 'polylang' ), - 'sb' => __( 'Solomon Islands', 'polylang' ), - 'sc' => __( 'Seychelles', 'polylang' ), - 'scotland' => __( 'Scotland', 'polylang' ), - 'sd' => __( 'Sudan', 'polylang' ), - 'se' => __( 'Sweden', 'polylang' ), - 'sg' => __( 'Singapore', 'polylang' ), - 'sh' => __( 'Saint Helena', 'polylang' ), - 'si' => __( 'Slovenia', 'polylang' ), - 'sk' => __( 'Slovakia', 'polylang' ), - 'sl' => __( 'Sierra Leone', 'polylang' ), - 'sm' => __( 'San Marino', 'polylang' ), - 'sn' => __( 'Senegal', 'polylang' ), - 'so' => __( 'Somalia', 'polylang' ), - 'sr' => __( 'Suriname', 'polylang' ), - 'ss' => __( 'South Sudan', 'polylang' ), - 'st' => __( 'São Tomé and Príncipe', 'polylang' ), - 'sv' => __( 'El Salvador', 'polylang' ), - 'sy' => __( 'Syria', 'polylang' ), - 'sz' => __( 'Swaziland', 'polylang' ), - 'tc' => __( 'Turks and Caicos Islands', 'polylang' ), - 'td' => __( 'Chad', 'polylang' ), - 'tf' => __( 'French Southern Territories', 'polylang' ), - 'tg' => __( 'Togo', 'polylang' ), - 'th' => __( 'Thailand', 'polylang' ), - 'tibet' => __( 'Tibet', 'polylang' ), - 'tj' => __( 'Tajikistan', 'polylang' ), - 'tk' => __( 'Tokelau', 'polylang' ), - 'tl' => __( 'Timor-Leste', 'polylang' ), - 'tm' => __( 'Turkmenistan', 'polylang' ), - 'tn' => __( 'Tunisia', 'polylang' ), - 'to' => __( 'Tonga', 'polylang' ), - 'tr' => __( 'Turkey', 'polylang' ), - 'tt' => __( 'Trinidad and Tobago', 'polylang' ), - 'tv' => __( 'Tuvalu', 'polylang' ), - 'tw' => __( 'Taiwan', 'polylang' ), - 'tz' => __( 'Tanzania', 'polylang' ), - 'ua' => __( 'Ukraine', 'polylang' ), - 'ug' => __( 'Uganda', 'polylang' ), - 'us' => __( 'United States', 'polylang' ), - 'uy' => __( 'Uruguay', 'polylang' ), - 'uz' => __( 'Uzbekistan', 'polylang' ), - 'va' => __( 'Vatican', 'polylang' ), - 'vc' => __( 'Saint Vincent and the Grenadines', 'polylang' ), - 've' => __( 'Venezuela', 'polylang' ), - 'veneto' => __( 'Veneto', 'polylang' ), - 'vg' => __( 'British Virgin Islands', 'polylang' ), - 'vi' => __( 'United States Virgin Islands', 'polylang' ), - 'vn' => __( 'Vietnam', 'polylang' ), - 'vu' => __( 'Vanuatu', 'polylang' ), - 'wales' => __( 'Wales', 'polylang' ), - 'wf' => __( 'Wallis and Futuna', 'polylang' ), - 'ws' => __( 'Western Samoa', 'polylang' ), - 'ye' => __( 'Yemen', 'polylang' ), - 'yt' => __( 'Mayotte', 'polylang' ), - 'za' => __( 'South Africa', 'polylang' ), - 'zm' => __( 'Zambia', 'polylang' ), - 'zw' => __( 'Zimbabwe', 'polylang' ), + 'om' => __( 'Oman', 'polylang' ), + 'pa' => __( 'Panama', 'polylang' ), + 'pe' => __( 'Peru', 'polylang' ), + 'pf' => __( 'French Polynesia', 'polylang' ), + 'pg' => __( 'Papua New Guinea', 'polylang' ), + 'ph' => __( 'Philippines', 'polylang' ), + 'pk' => __( 'Pakistan', 'polylang' ), + 'pl' => __( 'Poland', 'polylang' ), + 'pm' => __( 'Saint Pierre and Miquelon', 'polylang' ), + 'pn' => __( 'Pitcairn', 'polylang' ), + 'pr' => __( 'Puerto Rico', 'polylang' ), + 'ps' => __( 'Palestinian Territory', 'polylang' ), + 'pt' => __( 'Portugal', 'polylang' ), + 'pw' => __( 'Belau', 'polylang' ), + 'py' => __( 'Paraguay', 'polylang' ), + 'qa' => __( 'Qatar', 'polylang' ), + 'quebec' => __( 'Quebec', 'polylang' ), + 'ro' => __( 'Romania', 'polylang' ), + 'rs' => __( 'Serbia', 'polylang' ), + 'ru' => __( 'Russia', 'polylang' ), + 'rw' => __( 'Rwanda', 'polylang' ), + 'sa' => __( 'Saudi Arabia', 'polylang' ), + 'sb' => __( 'Solomon Islands', 'polylang' ), + 'sc' => __( 'Seychelles', 'polylang' ), + 'scotland' => __( 'Scotland', 'polylang' ), + 'sd' => __( 'Sudan', 'polylang' ), + 'se' => __( 'Sweden', 'polylang' ), + 'sg' => __( 'Singapore', 'polylang' ), + 'sh' => __( 'Saint Helena', 'polylang' ), + 'si' => __( 'Slovenia', 'polylang' ), + 'sk' => __( 'Slovakia', 'polylang' ), + 'sl' => __( 'Sierra Leone', 'polylang' ), + 'sm' => __( 'San Marino', 'polylang' ), + 'sn' => __( 'Senegal', 'polylang' ), + 'so' => __( 'Somalia', 'polylang' ), + 'sr' => __( 'Suriname', 'polylang' ), + 'ss' => __( 'South Sudan', 'polylang' ), + 'st' => __( 'São Tomé and Príncipe', 'polylang' ), + 'sv' => __( 'El Salvador', 'polylang' ), + 'sy' => __( 'Syria', 'polylang' ), + 'sz' => __( 'Swaziland', 'polylang' ), + 'tc' => __( 'Turks and Caicos Islands', 'polylang' ), + 'td' => __( 'Chad', 'polylang' ), + 'tf' => __( 'French Southern Territories', 'polylang' ), + 'tg' => __( 'Togo', 'polylang' ), + 'th' => __( 'Thailand', 'polylang' ), + 'tibet' => __( 'Tibet', 'polylang' ), + 'tj' => __( 'Tajikistan', 'polylang' ), + 'tk' => __( 'Tokelau', 'polylang' ), + 'tl' => __( 'Timor-Leste', 'polylang' ), + 'tm' => __( 'Turkmenistan', 'polylang' ), + 'tn' => __( 'Tunisia', 'polylang' ), + 'to' => __( 'Tonga', 'polylang' ), + 'tr' => __( 'Turkey', 'polylang' ), + 'tt' => __( 'Trinidad and Tobago', 'polylang' ), + 'tv' => __( 'Tuvalu', 'polylang' ), + 'tw' => __( 'Taiwan', 'polylang' ), + 'tz' => __( 'Tanzania', 'polylang' ), + 'ua' => __( 'Ukraine', 'polylang' ), + 'ug' => __( 'Uganda', 'polylang' ), + 'us' => __( 'United States', 'polylang' ), + 'uy' => __( 'Uruguay', 'polylang' ), + 'uz' => __( 'Uzbekistan', 'polylang' ), + 'va' => __( 'Vatican', 'polylang' ), + 'vc' => __( 'Saint Vincent and the Grenadines', 'polylang' ), + 've' => __( 'Venezuela', 'polylang' ), + 'veneto' => __( 'Veneto', 'polylang' ), + 'vg' => __( 'British Virgin Islands', 'polylang' ), + 'vi' => __( 'United States Virgin Islands', 'polylang' ), + 'vn' => __( 'Vietnam', 'polylang' ), + 'vu' => __( 'Vanuatu', 'polylang' ), + 'wales' => __( 'Wales', 'polylang' ), + 'wf' => __( 'Wallis and Futuna', 'polylang' ), + 'ws' => __( 'Western Samoa', 'polylang' ), + 'ye' => __( 'Yemen', 'polylang' ), + 'yt' => __( 'Mayotte', 'polylang' ), + 'za' => __( 'South Africa', 'polylang' ), + 'zm' => __( 'Zambia', 'polylang' ), + 'zw' => __( 'Zimbabwe', 'polylang' ), ); /** @@ -270,4 +273,4 @@ $flags = array( * * @param array $flags */ -$flags = apply_filters( 'pll_predefined_flags', $flags ); +return apply_filters( 'pll_predefined_flags', $flags ); diff --git a/wp-content/plugins/polylang/settings/languages.php b/wp-content/plugins/polylang/settings/languages.php index 7a6649a1..a02b08e3 100644 --- a/wp-content/plugins/polylang/settings/languages.php +++ b/wp-content/plugins/polylang/settings/languages.php @@ -1,4 +1,7 @@ array( 'code' => 'af', 'locale' => 'af', @@ -190,6 +205,14 @@ $languages = array( 'flag' => 'dk', 'facebook' => 'da_DK', ), + 'de_AT' => array( + 'code' => 'de', + 'locale' => 'de_AT', + 'name' => 'Deutsch', + 'dir' => 'ltr', + 'flag' => 'at', + 'facebook' => 'de_DE', + ), 'de_CH' => array( 'code' => 'de', 'locale' => 'de_CH', @@ -224,6 +247,13 @@ $languages = array( 'w3c' => 'de-DE', 'facebook' => 'de_DE', ), + 'dsb' => array( + 'code' => 'dsb', + 'locale' => 'dsb', + 'name' => 'Dolnoserbšćina', + 'dir' => 'ltr', + 'flag' => 'de', + ), 'dzo' => array( 'code' => 'dz', 'locale' => 'dzo', @@ -328,6 +358,14 @@ $languages = array( 'flag' => 'cr', 'facebook' => 'es_LA', ), + 'es_EC' => array( + 'code' => 'es', + 'locale' => 'es_EC', + 'name' => 'Español', + 'dir' => 'ltr', + 'flag' => 'ec', + 'facebook' => 'es_LA', + ), 'es_ES' => array( 'code' => 'es', 'locale' => 'es_ES', @@ -360,6 +398,22 @@ $languages = array( 'flag' => 'pe', 'facebook' => 'es_LA', ), + 'es_PR' => array( + 'code' => 'es', + 'locale' => 'es_PR', + 'name' => 'Español', + 'dir' => 'ltr', + 'flag' => 'pr', + 'facebook' => 'es_LA', + ), + 'es_UY' => array( + 'code' => 'es', + 'locale' => 'es_UY', + 'name' => 'Español', + 'dir' => 'ltr', + 'flag' => 'uy', + 'facebook' => 'es_LA', + ), 'es_VE' => array( 'code' => 'es', 'locale' => 'es_VE', @@ -461,6 +515,9 @@ $languages = array( 'ga' => array( 'facebook' => 'ga_IE', ), + 'gax' => array( + 'facebook' => 'om_ET', + ), 'gd' => array( 'code' => 'gd', 'locale' => 'gd', @@ -487,6 +544,9 @@ $languages = array( 'flag' => 'in', 'facebook' => 'gu_IN', ), + 'hat' => array( + 'facebook' => 'ht_HT', + ), 'hau' => array( 'facebook' => 'ha_NG', ), @@ -529,6 +589,13 @@ $languages = array( 'flag' => 'hu', 'facebook' => 'hu_HU', ), + 'hsb' => array( + 'code' => 'hsb', + 'locale' => 'hsb', + 'name' => 'Hornjoserbšćina', + 'dir' => 'ltr', + 'flag' => 'de', + ), 'hy' => array( 'code' => 'hy', 'locale' => 'hy', @@ -616,6 +683,11 @@ $languages = array( 'facebook' => 'km_KH', ), 'kn' => array( + 'code' => 'kn', + 'locale' => 'kn', + 'name' => 'ಕನ್ನಡ', + 'dir' => 'ltr', + 'flag' => 'in', 'facebook' => 'kn_IN', ), 'ko_KR' => array( @@ -807,6 +879,14 @@ $languages = array( 'flag' => 'af', 'facebook' => 'ps_AF', ), + 'pt_AO' => array( + 'code' => 'pt', + 'locale' => 'pt_AO', + 'name' => 'Português', + 'dir' => 'ltr', + 'flag' => 'ao', + 'facebook' => 'pt_PT', + ), 'pt_BR' => array( 'code' => 'pt', 'locale' => 'pt_BR', @@ -884,6 +964,13 @@ $languages = array( 'flag' => 'sk', 'facebook' => 'sk_SK', ), + 'skr' => array( + 'code' => 'skr', + 'locale' => 'skr', + 'name' => 'سرائیکی', + 'dir' => 'rtl', + 'flag' => 'pk', + ), 'sl_SI' => array( 'code' => 'sl', 'locale' => 'sl_SI', @@ -895,6 +982,13 @@ $languages = array( 'sna' => array( 'facebook' => 'sn_ZW', ), + 'snd' => array( + 'code' => 'sd', + 'locale' => 'snd', + 'name' => 'سنڌي', + 'dir' => 'rtl', + 'flag' => 'pk', + ), 'so_SO' => array( 'code' => 'so', 'locale' => 'so_SO', @@ -929,6 +1023,7 @@ $languages = array( 'name' => 'Basa Sunda', 'dir' => 'ltr', 'flag' => 'id', + 'facebook' => 'su_ID', ), 'sv_SE' => array( 'code' => 'sv', @@ -939,6 +1034,11 @@ $languages = array( 'facebook' => 'sv_SE', ), 'sw' => array( + 'code' => 'sw', + 'locale' => 'sw', + 'name' => 'Kiswahili', + 'dir' => 'ltr', + 'flag' => 'ke', 'facebook' => 'sw_KE', ), 'syr' => array( diff --git a/wp-content/plugins/polylang/settings/settings-browser.php b/wp-content/plugins/polylang/settings/settings-browser.php index 6ac28788..7005cf64 100644 --- a/wp-content/plugins/polylang/settings/settings-browser.php +++ b/wp-content/plugins/polylang/settings/settings-browser.php @@ -1,4 +1,7 @@ 'browser', - 'title' => __( 'Detect browser language', 'polylang' ), - 'description' => __( 'When the front page is visited, set the language according to the browser preference', 'polylang' ), - 'active_option' => $this->is_available() ? 'browser' : false, - ) ); + $this->options = &$polylang->options; + parent::__construct( + $polylang, + array( + 'module' => 'browser', + 'title' => __( 'Detect browser language', 'polylang' ), + 'description' => __( 'When the front page is visited, redirects to itself in the browser preferred language. As this doesn\'t work if it is cached, Polylang will attempt to disable the front page cache for known cache plugins.', 'polylang' ), + 'active_option' => $this->is_available() ? 'browser' : false, + ) + ); if ( ! class_exists( 'PLL_Xdata_Domain', true ) ) { add_action( 'admin_print_footer_scripts', array( $this, 'print_js' ) ); @@ -54,6 +67,8 @@ class PLL_Settings_Browser extends PLL_Settings_Module { * as the preferred browser language is not used when the language is set from different domains * * @since 1.8 + * + * @return void */ public function print_js() { wp_enqueue_script( 'jquery' ); @@ -72,17 +87,19 @@ class PLL_Settings_Browser extends PLL_Settings_Module { ?> 'cpt', - 'title' => __( 'Custom post types and Taxonomies', 'polylang' ), - 'description' => __( 'Activate the languages and translations management for the custom post types and taxonomies.', 'polylang' ), - ) ); + parent::__construct( + $polylang, + array( + 'module' => 'cpt', + 'title' => __( 'Custom post types and Taxonomies', 'polylang' ), + 'description' => __( 'Activate languages and translations management for the custom post types and the taxonomies.', 'polylang' ), + ) + ); $public_post_types = get_post_types( array( 'public' => true, '_builtin' => false ) ); /** This filter is documented in include/model.php */ $this->post_types = array_unique( apply_filters( 'pll_get_post_types', $public_post_types, true ) ); - $programmatically_active_post_types = array_unique( apply_filters( 'pll_get_post_types', array(), false ) ); /** This filter is documented in include/model.php */ + $programmatically_active_post_types = array_unique( apply_filters( 'pll_get_post_types', array(), false ) ); $this->disabled_post_types = array_intersect( $programmatically_active_post_types, $this->post_types ); $public_taxonomies = get_taxonomies( array( 'public' => true, '_builtin' => false ) ); @@ -35,8 +74,8 @@ class PLL_Settings_CPT extends PLL_Settings_Module { /** This filter is documented in include/model.php */ $this->taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', $public_taxonomies, true ) ); - $programmatically_active_taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', array(), false ) ); /** This filter is documented in include/model.php */ + $programmatically_active_taxonomies = array_unique( apply_filters( 'pll_get_taxonomies', array(), false ) ); $this->disabled_taxonomies = array_intersect( $programmatically_active_taxonomies, $this->taxonomies ); } @@ -68,8 +107,8 @@ class PLL_Settings_CPT extends PLL_Settings_Module { printf( '
  • ', esc_attr( $post_type ), - in_array( $post_type, $this->options['post_types'] ) || $disabled ? 'checked="checked"' : '', - $disabled ? 'disabled="disabled"' : '', + checked( in_array( $post_type, $this->options['post_types'] ) || $disabled, true, false ), + disabled( $disabled, true, false ), esc_html( $pt->labels->name ) ); } @@ -92,8 +131,8 @@ class PLL_Settings_CPT extends PLL_Settings_Module { printf( '
  • ', esc_attr( $taxonomy ), - in_array( $taxonomy, $this->options['taxonomies'] ) || $disabled ? 'checked="checked"' : '', - $disabled ? 'disabled="disabled"' : '', + checked( in_array( $taxonomy, $this->options['taxonomies'] ) || $disabled, true, false ), + disabled( $disabled, true, false ), esc_html( $tax->labels->name ) ); } @@ -113,6 +152,8 @@ class PLL_Settings_CPT extends PLL_Settings_Module { * @param array $options */ protected function update( $options ) { + $newoptions = array(); + foreach ( array( 'post_types', 'taxonomies' ) as $key ) { $newoptions[ $key ] = empty( $options[ $key ] ) ? array() : array_keys( $options[ $key ], 1 ); } diff --git a/wp-content/plugins/polylang/settings/settings-licenses.php b/wp-content/plugins/polylang/settings/settings-licenses.php index 45e1e397..f73767eb 100644 --- a/wp-content/plugins/polylang/settings/settings-licenses.php +++ b/wp-content/plugins/polylang/settings/settings-licenses.php @@ -1,4 +1,7 @@ 'licenses', - 'title' => __( 'License keys', 'polylang' ), - 'description' => __( 'Manage licenses for Polylang Pro or addons.', 'polylang' ), - ) ); + parent::__construct( + $polylang, + array( + 'module' => 'licenses', + 'title' => __( 'License keys', 'polylang' ), + 'description' => __( 'Manage licenses for Polylang Pro and add-ons.', 'polylang' ), + ) + ); - $this->buttons['cancel'] = sprintf( '', __( 'Close' ) ); + $this->buttons['cancel'] = sprintf( '', __( 'Close', 'polylang' ) ); $this->items = apply_filters( 'pll_settings_licenses', array() ); @@ -50,7 +68,7 @@ class PLL_Settings_Licenses extends PLL_Settings_Module { items as $item ) { - echo $this->get_row( $item ); + echo $this->get_row( $item ); // phpcs:ignore WordPress.Security.EscapeOutput } ?>
    @@ -59,115 +77,15 @@ class PLL_Settings_Licenses extends PLL_Settings_Module { } /** - * Get the html for a row (one per license key) for display + * Get the html for a row (one per license key) for display. * * @since 1.9 * - * @param array $item licence id, name and key + * @param PLL_License $item Object allowing to manage a license. * @return string */ protected function get_row( $item ) { - if ( ! empty( $item->license_data ) ) { - $license = $item->license_data; - } - - $class = 'license-null'; - - $out = sprintf( - '' . - '', - esc_attr( $item->id ), esc_attr( $item->name ), esc_html( $item->license_key ) - ); - - if ( ! empty( $license ) && is_object( $license ) ) { - $now = current_time( 'timestamp' ); - $expiration = strtotime( $license->expires, $now ); - - // Special case: the license expired after the last check - if ( $license->success && $expiration < $now ) { - $license->success = false; - $license->error = 'expired'; - } - - if ( false === $license->success ) { - $class = 'notice-error notice-alt'; - - switch ( $license->error ) { - case 'expired': - $message = sprintf( - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ - __( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), - date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ), - sprintf( '', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), - '' - ); - break; - - case 'missing': - $message = sprintf( - /* translators: %1$s is link start tag, %2$s is link end tag. */ - __( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ), - sprintf( '', 'https://polylang.pro/account' ), - '' - ); - break; - - case 'invalid': - case 'site_inactive': - $message = sprintf( - /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */ - __( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ), - $item->name, - sprintf( '', 'https://polylang.pro/account' ), - '' - ); - break; - - case 'item_name_mismatch': - /* translators: %s is a product name */ - $message = sprintf( __( 'This is not a %s license key.', 'polylang' ), $item->name ); - break; - - case 'no_activations_left': - $message = sprintf( - /* translators: %1$s is link start tag, %2$s is link end tag */ - __( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ), - sprintf( '', 'https://polylang.pro/account' ), - '' - ); - break; - } - } else { - $class = 'license-valid'; - - $out .= sprintf( '', $item->id, __( 'Deactivate', 'polylang' ) ); - - if ( 'lifetime' === $license->expires ) { - $message = __( 'The license key never expires.', 'polylang' ); - } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { - $class = 'notice-warning notice-alt'; - $message = sprintf( - /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ - __( 'Your license key expires soon! It expires on %1$s. %2$sRenew your license key%3$s.', 'polylang' ), - date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ), - sprintf( '', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), - '' - ); - } else { - $message = sprintf( - /* translators: %s is a date */ - __( 'Your license key expires on %s.', 'polylang' ), - date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ) - ); - } - } - } - - if ( ! empty( $message ) ) { - $out .= '

    ' . $message . '

    '; - } - - return sprintf( '%s', $item->id, $class, $out ); + return $item->get_form_field(); } /** @@ -182,15 +100,17 @@ class PLL_Settings_Licenses extends PLL_Settings_Module { wp_die( -1 ); } - if ( $this->module === $_POST['module'] && ! empty( $_POST['licenses'] ) ) { + if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] && ! empty( $_POST['licenses'] ) ) { $x = new WP_Ajax_Response(); foreach ( $this->items as $item ) { - $updated_item = $item->activate_license( sanitize_text_field( $_POST['licenses'][ $item->id ] ) ); - $x->Add( array( 'what' => 'license-update', 'data' => $item->id, 'supplemental' => array( 'html' => $this->get_row( $updated_item ) ) ) ); + if ( ! empty( $_POST['licenses'][ $item->id ] ) ) { + $updated_item = $item->activate_license( sanitize_key( $_POST['licenses'][ $item->id ] ) ); + $x->Add( array( 'what' => 'license-update', 'data' => $item->id, 'supplemental' => array( 'html' => $this->get_row( $updated_item ) ) ) ); + } } // Updated message - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' ); + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' ); ob_start(); settings_errors(); $x->Add( array( 'what' => 'success', 'data' => ob_get_clean() ) ); @@ -202,6 +122,8 @@ class PLL_Settings_Licenses extends PLL_Settings_Module { * Ajax method to deactivate a license * * @since 1.9 + * + * @return void */ public function deactivate_license() { check_ajax_referer( 'pll_options', '_pll_nonce' ); @@ -210,10 +132,16 @@ class PLL_Settings_Licenses extends PLL_Settings_Module { wp_die( -1 ); } - $id = sanitize_text_field( substr( $_POST['id'], 11 ) ); - wp_send_json( array( - 'id' => $id, - 'html' => $this->get_row( $this->items[ $id ]->deactivate_license() ), - ) ); + if ( ! isset( $_POST['id'] ) ) { + wp_die( 0 ); + } + + $id = substr( sanitize_text_field( wp_unslash( $_POST['id'] ) ), 11 ); + wp_send_json( + array( + 'id' => $id, + 'html' => $this->get_row( $this->items[ $id ]->deactivate_license() ), + ) + ); } } diff --git a/wp-content/plugins/polylang/settings/settings-media.php b/wp-content/plugins/polylang/settings/settings-media.php index 80c4261a..1f7ea615 100644 --- a/wp-content/plugins/polylang/settings/settings-media.php +++ b/wp-content/plugins/polylang/settings/settings-media.php @@ -1,4 +1,7 @@ 'media', - 'title' => __( 'Media' ), - 'description' => __( 'Activate languages and translations for media', 'polylang' ), - 'active_option' => 'media_support', - ) ); + parent::__construct( + $polylang, + array( + 'module' => 'media', + 'title' => __( 'Media', 'polylang' ), + 'description' => __( 'Activate languages and translations for media only if you need to translate the text attached to the media: the title, the alternative text, the caption, the description... Note that the file is not duplicated.', 'polylang' ), + 'active_option' => 'media_support', + ) + ); } } diff --git a/wp-content/plugins/polylang/settings/settings-module.php b/wp-content/plugins/polylang/settings/settings-module.php index 15c01c8e..2d3c60ea 100644 --- a/wp-content/plugins/polylang/settings/settings-module.php +++ b/wp-content/plugins/polylang/settings/settings-module.php @@ -1,4 +1,7 @@ model = &$polylang->model; $this->links_model = &$polylang->links_model; - $args = wp_parse_args( $args, array( - 'title' => '', - 'description' => '', - 'active_option' => false, - ) ); + $args = wp_parse_args( + $args, + array( + 'title' => '', + 'description' => '', + 'active_option' => false, + ) + ); foreach ( $args as $prop => $value ) { $this->$prop = $value; @@ -36,35 +113,31 @@ class PLL_Settings_Module { // All possible action links, even if not always a link ;-) $this->action_links = array( - 'configure' => sprintf( + 'configure' => sprintf( '%s', esc_attr__( 'Configure this module', 'polylang' ), '#', esc_html__( 'Settings', 'polylang' ) ), - - 'deactivate' => sprintf( + 'deactivate' => sprintf( '%s', esc_attr__( 'Deactivate this module', 'polylang' ), - wp_nonce_url( '?page=mlang&tab=modules&pll_action=deactivate&noheader=true&module=' . $this->module, 'pll_deactivate' ), + esc_url( wp_nonce_url( '?page=mlang&tab=modules&pll_action=deactivate&noheader=true&module=' . $this->module, 'pll_deactivate' ) ), esc_html__( 'Deactivate', 'polylang' ) ), - - 'activate' => sprintf( + 'activate' => sprintf( '%s', esc_attr__( 'Activate this module', 'polylang' ), - wp_nonce_url( '?page=mlang&tab=modules&pll_action=activate&noheader=true&module=' . $this->module, 'pll_activate' ), + esc_url( wp_nonce_url( '?page=mlang&tab=modules&pll_action=activate&noheader=true&module=' . $this->module, 'pll_activate' ) ), esc_html__( 'Activate', 'polylang' ) ), - - 'activated' => esc_html__( 'Activated', 'polylang' ), - + 'activated' => esc_html__( 'Activated', 'polylang' ), 'deactivated' => esc_html__( 'Deactivated', 'polylang' ), ); $this->buttons = array( - 'cancel' => sprintf( '', esc_html__( 'Cancel' ) ), - 'save' => sprintf( '', esc_html__( 'Save Changes' ) ), + 'cancel' => sprintf( '', esc_html__( 'Cancel', 'polylang' ) ), + 'save' => sprintf( '', esc_html__( 'Save Changes', 'polylang' ) ), ); // Ajax action to save options @@ -86,6 +159,8 @@ class PLL_Settings_Module { * Activates the module * * @since 1.8 + * + * @return void */ public function activate() { if ( ! empty( $this->active_option ) ) { @@ -98,6 +173,8 @@ class PLL_Settings_Module { * Deactivates the module * * @since 1.8 + * + * @return void */ public function deactivate() { if ( ! empty( $this->active_option ) ) { @@ -110,6 +187,8 @@ class PLL_Settings_Module { * Protected method to display a configuration form * * @since 1.8 + * + * @return void */ protected function form() { // Child classes can provide a form @@ -141,7 +220,7 @@ class PLL_Settings_Module { * @param array $options Raw options * @return array Options */ - protected function update( $options ) { + protected function update( $options ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable return array(); // It's responsibility of the child class to decide what is saved } @@ -149,6 +228,8 @@ class PLL_Settings_Module { * Ajax method to save the options * * @since 1.8 + * + * @return void */ public function save_options() { check_ajax_referer( 'pll_options', '_pll_nonce' ); @@ -156,7 +237,7 @@ class PLL_Settings_Module { wp_die( -1 ); } - if ( $this->module == $_POST['module'] ) { + if ( isset( $_POST['module'] ) && $this->module === $_POST['module'] ) { // It's up to the child class to decide which options are saved, whether there are errors or not $post = array_diff_key( $_POST, array_flip( array( 'action', 'module', 'pll_ajax_backend', '_pll_nonce' ) ) ); $options = $this->update( $post ); @@ -174,7 +255,7 @@ class PLL_Settings_Module { if ( ! get_settings_errors() ) { // Send update message - add_settings_error( 'general', 'settings_updated', __( 'Settings saved.' ), 'updated' ); + add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'polylang' ), 'updated' ); settings_errors(); $x = new WP_Ajax_Response( array( 'what' => 'success', 'data' => ob_get_clean() ) ); $x->send(); @@ -188,13 +269,15 @@ class PLL_Settings_Module { } /** - * Get the row actions + * Get the row actions. * * @since 1.8 * - * @return array + * @return string[] */ protected function get_actions() { + $actions = array(); + if ( $this->is_active() && $this->get_form() ) { $actions[] = 'configure'; } @@ -211,11 +294,11 @@ class PLL_Settings_Module { } /** - * Get the actions links + * Get the actions links. * * @since 1.8 * - * @return array + * @return string[] Action links. */ public function get_action_links() { return array_intersect_key( $this->action_links, array_flip( $this->get_actions() ) ); @@ -231,7 +314,7 @@ class PLL_Settings_Module { protected function default_upgrade_message() { return sprintf( '%s %s', - __( 'You need Polylang Pro to enable this feature.', 'polylang' ), + __( 'To enable this feature, you need Polylang Pro.', 'polylang' ), 'https://polylang.pro', __( 'Upgrade now.', 'polylang' ) ); @@ -249,11 +332,11 @@ class PLL_Settings_Module { } /** - * Get the buttons + * Get the buttons. * * @since 1.9 * - * @return array + * @return string[] An array of html fragment for the buttons. */ public function get_buttons() { return $this->buttons; diff --git a/wp-content/plugins/polylang/settings/settings-tools.php b/wp-content/plugins/polylang/settings/settings-tools.php deleted file mode 100644 index 15056b9f..00000000 --- a/wp-content/plugins/polylang/settings/settings-tools.php +++ /dev/null @@ -1,49 +0,0 @@ - 'tools', - 'title' => __( 'Tools', 'polylang' ), - 'description' => __( 'Decide whether to remove all data when deleting Polylang.', 'polylang' ), - ) ); - } - - /** - * displays the settings form - * - * @since 1.8 - */ - protected function form() { - printf( - '', - empty( $this->options['uninstall'] ) ? '' : 'checked="checked"', - esc_html__( 'Remove all Polylang data when using the "Delete" link on the plugins screen.', 'polylang' ) - ); - } - - /** - * sanitizes the settings before saving - * - * @since 1.8 - * - * @param array $options - */ - protected function update( $options ) { - $newoptions['uninstall'] = isset( $options['uninstall'] ) ? 1 : 0; - return $newoptions; // take care to return only validated options - } -} diff --git a/wp-content/plugins/polylang/settings/settings-url.php b/wp-content/plugins/polylang/settings/settings-url.php index f548b277..4babd816 100644 --- a/wp-content/plugins/polylang/settings/settings-url.php +++ b/wp-content/plugins/polylang/settings/settings-url.php @@ -1,4 +1,7 @@ 'url', - 'title' => __( 'URL modifications', 'polylang' ), - 'description' => __( 'Decide how your URLs will look like.', 'polylang' ), - 'configure' => true, - ) ); + parent::__construct( + $polylang, + array( + 'module' => 'url', + 'title' => __( 'URL modifications', 'polylang' ), + 'description' => __( 'Decide how your URLs will look like.', 'polylang' ), + 'configure' => true, + ) + ); - $this->links_model = &$polylang->links_model; $this->page_on_front = &$polylang->static_pages->page_on_front; } @@ -30,24 +48,28 @@ class PLL_Settings_Url extends PLL_Settings_Module { * Displays the fieldset to choose how the language is set * * @since 1.8 + * + * @return void */ - protected function force_lang() {?> + protected function force_lang() { + ?> +

    -

    +

    @@ -56,8 +78,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->links_model->using_permalinks ? '' : 'disabled="disabled"', - 2 == $this->options['force_lang'] ? 'checked="checked"' : '', + disabled( $this->links_model->using_permalinks, false, false ), + checked( $this->options['force_lang'], 2, false ), esc_html__( 'The language is set from the subdomain name in pretty permalinks', 'polylang' ) ); ?> @@ -67,8 +89,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->links_model->using_permalinks ? '' : 'disabled="disabled"', - 3 == $this->options['force_lang'] ? 'checked="checked"' : '', + disabled( $this->links_model->using_permalinks, false, false ), + checked( $this->options['force_lang'], 3, false ), esc_html__( 'The language is set from different domains', 'polylang' ) ); ?> @@ -76,12 +98,13 @@ class PLL_Settings_Url extends PLL_Settings_Module { options['force_lang'] ? '' : 'style="display: none;"'; ?>> model->get_languages_list() as $lg ) { + $url = isset( $this->options['domains'][ $lg->slug ] ) ? $this->options['domains'][ $lg->slug ] : ( $lg->slug == $this->options['default_lang'] ? $this->links_model->home : '' ); printf( '' . '', esc_attr( $lg->slug ), esc_attr( $lg->name ), - esc_url( isset( $this->options['domains'][ $lg->slug ] ) ? $this->options['domains'][ $lg->slug ] : ( $lg->slug == $this->options['default_lang'] ? $this->links_model->home : '' ) ) + esc_url( $url ) ); } ?> @@ -93,6 +116,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { * Displays the fieldset to choose to hide the default language information in url * * @since 1.8 + * + * @return void */ protected function hide_default() { ?> @@ -100,7 +125,7 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->options['hide_default'] ? 'checked="checked"' : '', + checked( $this->options['hide_default'], 1, false ), esc_html__( 'Hide URL language information for default language', 'polylang' ) ); ?> @@ -112,6 +137,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { * Displays the fieldset to choose to hide /language/ in url * * @since 1.8 + * + * @return void */ protected function rewrite() { ?> @@ -119,8 +146,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->links_model->using_permalinks ? '' : 'disabled="disabled"', - $this->options['rewrite'] ? 'checked="checked"' : '', + disabled( $this->links_model->using_permalinks, false, false ), + checked( $this->options['rewrite'], 1, false ), esc_html__( 'Remove /language/ in pretty permalinks', 'polylang' ) ); ?> @@ -130,8 +157,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->links_model->using_permalinks ? '' : 'disabled="disabled"', - $this->options['rewrite'] ? '' : 'checked="checked"', + disabled( $this->links_model->using_permalinks, false, false ), + checked( $this->options['rewrite'], 0, false ), esc_html__( 'Keep /language/ in pretty permalinks', 'polylang' ) ); ?> @@ -144,6 +171,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { * Displays the fieldset to choose to redirect the home page to language page * * @since 1.8 + * + * @return void */ protected function redirect_lang() { ?> @@ -151,8 +180,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { %s', - $this->options['redirect_lang'] ? 'checked="checked"' : '', - esc_html__( 'The front page url contains the language code instead of the page name or page id', 'polylang' ) + checked( $this->options['redirect_lang'], 1, false ), + esc_html__( 'The front page URL contains the language code instead of the page name or page id', 'polylang' ) ); ?> @@ -176,6 +205,8 @@ class PLL_Settings_Url extends PLL_Settings_Module { * Displays the settings * * @since 1.8 + * + * @return void */ public function form() { ?> @@ -216,8 +247,11 @@ class PLL_Settings_Url extends PLL_Settings_Module { * @since 1.8 * * @param array $options + * @return array */ protected function update( $options ) { + $newoptions = array(); + foreach ( array( 'force_lang', 'rewrite' ) as $key ) { $newoptions[ $key ] = isset( $options[ $key ] ) ? (int) $options[ $key ] : 0; } @@ -226,10 +260,17 @@ class PLL_Settings_Url extends PLL_Settings_Module { foreach ( $options['domains'] as $key => $domain ) { if ( empty( $domain ) ) { $lang = $this->model->get_language( $key ); - add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf( - /* translators: %s is a native language name */ - __( 'Please enter a valid URL for %s.', 'polylang' ), $lang->name - ) ) ); + add_settings_error( + 'general', + 'pll_invalid_domain', + esc_html( + sprintf( + /* translators: %s is a native language name */ + __( 'Please enter a valid URL for %s.', 'polylang' ), + $lang->name + ) + ) + ); } else { $newoptions['domains'][ $key ] = esc_url_raw( trim( $domain ) ); @@ -262,6 +303,7 @@ class PLL_Settings_Url extends PLL_Settings_Module { * @since 1.8 * * @param array $options new set of options to test + * @return void */ protected function check_domains( $options ) { $options = array_merge( $this->options, $options ); @@ -274,10 +316,17 @@ class PLL_Settings_Url extends PLL_Settings_Module { $response_code = wp_remote_retrieve_response_code( $response ); if ( 200 != $response_code ) { - add_settings_error( 'general', 'pll_invalid_domain', esc_html( sprintf( - /* translators: %s is an url */ - __( 'Polylang was unable to access the URL %s. Please check that the URL is valid.', 'polylang' ), $url - ) ) ); + add_settings_error( + 'general', + 'pll_invalid_domain', + esc_html( + sprintf( + /* translators: %s is an url */ + __( 'Polylang was unable to access the %s URL. Please check that the URL is valid.', 'polylang' ), + $url + ) + ) + ); } } } diff --git a/wp-content/plugins/polylang/settings/settings.php b/wp-content/plugins/polylang/settings/settings.php index 4b6888ae..4d9fbb6f 100644 --- a/wp-content/plugins/polylang/settings/settings.php +++ b/wp-content/plugins/polylang/settings/settings.php @@ -1,41 +1,50 @@ inherited, reference to Polylang options array - * model => inherited, reference to PLL_Model object - * links_model => inherited, reference to PLL_Links_Model object - * links => inherited, reference to PLL_Admin_Links object - * static_pages => inherited, reference to PLL_Admin_Static_Pages object - * filters_links => inherited, reference to PLL_Filters_Links object - * curlang => inherited, optional, current language used to filter admin content - * pref_lang => inherited, preferred language used as default when saving posts or terms + * A class for the Polylang settings pages, accessible from @see PLL(). * * @since 1.2 */ class PLL_Settings extends PLL_Admin_Base { - protected $active_tab, $modules; + + /** + * @var PLL_Admin_Model + */ + public $model; + + /** + * Name of the active module. + * + * @var string + */ + protected $active_tab; + + /** + * Array of modules classes. + * + * @var PLL_Settings_Module[] + */ + protected $modules; /** * Constructor * * @since 1.2 * - * @param object $links_model + * @param PLL_Links_Model $links_model Reference to the links model. */ public function __construct( &$links_model ) { parent::__construct( $links_model ); - if ( isset( $_GET['page'] ) ) { - $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( $_GET['page'], 6 ); + if ( isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $this->active_tab = 'mlang' === $_GET['page'] ? 'lang' : substr( sanitize_key( $_GET['page'] ), 6 ); // phpcs:ignore WordPress.Security.NonceVerification } PLL_Admin_Strings::init(); - // FIXME put this as late as possible add_action( 'admin_init', array( $this, 'register_settings_modules' ) ); // Adds screen options and the about box in the languages admin panel @@ -50,26 +59,23 @@ class PLL_Settings extends PLL_Admin_Base { * Initializes the modules * * @since 1.8 + * + * @return void */ public function register_settings_modules() { - $modules = array( - 'PLL_Settings_Tools', - 'PLL_Settings_Licenses', - ); + $modules = array(); if ( $this->model->get_languages_list() ) { - $modules = array_merge( array( + $modules = array( 'PLL_Settings_Url', 'PLL_Settings_Browser', 'PLL_Settings_Media', 'PLL_Settings_CPT', - 'PLL_Settings_Sync', - 'PLL_Settings_WPML', - 'PLL_Settings_Share_Slug', - 'PLL_Settings_Translate_Slugs', - ), $modules ); + ); } + $modules[] = 'PLL_Settings_Licenses'; + /** * Filter the list of setting modules * @@ -89,15 +95,19 @@ class PLL_Settings extends PLL_Admin_Base { * Loads the about metabox * * @since 0.8 + * + * @return void */ public function metabox_about() { - include PLL_SETTINGS_INC . '/view-about.php'; + include __DIR__ . '/view-about.php'; } /** * Adds screen options and the about box in the languages admin panel * * @since 0.9.5 + * + * @return void */ public function load_page() { if ( ! defined( 'PLL_DISPLAY_ABOUT' ) || PLL_DISPLAY_ABOUT ) { @@ -105,16 +115,19 @@ class PLL_Settings extends PLL_Admin_Base { 'pll-about-box', __( 'About Polylang', 'polylang' ), array( $this, 'metabox_about' ), - 'settings_page_mlang', // FIXME not shown in screen options + 'toplevel_page_mlang', 'normal' ); } - add_screen_option( 'per_page', array( - 'label' => __( 'Languages', 'polylang' ), - 'default' => 10, - 'option' => 'pll_lang_per_page', - ) ); + add_screen_option( + 'per_page', + array( + 'label' => __( 'Languages', 'polylang' ), + 'default' => 10, + 'option' => 'pll_lang_per_page', + ) + ); add_action( 'admin_notices', array( $this, 'notice_objects_with_no_lang' ) ); } @@ -123,13 +136,18 @@ class PLL_Settings extends PLL_Admin_Base { * Adds screen options in the strings translations admin panel * * @since 2.1 + * + * @return void */ public function load_page_strings() { - add_screen_option( 'per_page', array( - 'label' => __( 'Strings translations', 'polylang' ), - 'default' => 10, - 'option' => 'pll_strings_per_page', - ) ); + add_screen_option( + 'per_page', + array( + 'label' => __( 'Strings translations', 'polylang' ), + 'default' => 10, + 'option' => 'pll_strings_per_page', + ) + ); } /** @@ -153,22 +171,33 @@ class PLL_Settings extends PLL_Admin_Base { * @since 1.9 * * @param string $action + * @return void */ public function handle_actions( $action ) { switch ( $action ) { case 'add': check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); + $errors = $this->model->add_language( $_POST ); - if ( $this->model->add_language( $_POST ) && 'en_US' !== $_POST['locale'] ) { - // Attempts to install the language pack - require_once ABSPATH . 'wp-admin/includes/translation-install.php'; - if ( ! wp_download_language_pack( $_POST['locale'] ) ) { - add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) ); + if ( is_wp_error( $errors ) ) { + foreach ( $errors->get_error_messages() as $message ) { + add_settings_error( 'general', 'pll_add_language', $message ); } + } else { + add_settings_error( 'general', 'pll_languages_created', __( 'Language added.', 'polylang' ), 'updated' ); + $locale = sanitize_text_field( wp_unslash( $_POST['locale'] ) ); // phpcs:ignore WordPress.Security - // Force checking for themes and plugins translations updates - wp_clean_themes_cache(); - wp_clean_plugins_cache(); + if ( 'en_US' !== $locale && current_user_can( 'install_languages' ) ) { + // Attempts to install the language pack + require_once ABSPATH . 'wp-admin/includes/translation-install.php'; + if ( ! wp_download_language_pack( $locale ) ) { + add_settings_error( 'general', 'pll_download_mo', __( 'The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang' ) ); + } + + // Force checking for themes and plugins translations updates + wp_clean_themes_cache(); + wp_clean_plugins_cache(); + } } self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) break; @@ -176,8 +205,8 @@ class PLL_Settings extends PLL_Admin_Base { case 'delete': check_admin_referer( 'delete-lang' ); - if ( ! empty( $_GET['lang'] ) ) { - $this->model->delete_language( (int) $_GET['lang'] ); + if ( ! empty( $_GET['lang'] ) && $this->model->delete_language( (int) $_GET['lang'] ) ) { + add_settings_error( 'general', 'pll_languages_deleted', __( 'Language deleted.', 'polylang' ), 'updated' ); } self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) @@ -185,7 +214,16 @@ class PLL_Settings extends PLL_Admin_Base { case 'update': check_admin_referer( 'add-lang', '_wpnonce_add-lang' ); - $error = $this->model->update_language( $_POST ); + $errors = $this->model->update_language( $_POST ); + + if ( is_wp_error( $errors ) ) { + foreach ( $errors->get_error_messages() as $message ) { + add_settings_error( 'general', 'pll_update_language', $message ); + } + } else { + add_settings_error( 'general', 'pll_languages_updated', __( 'Language updated.', 'polylang' ), 'updated' ); + } + self::redirect(); // To refresh the page ( possible thanks to the $_GET['noheader']=true ) break; @@ -216,13 +254,23 @@ class PLL_Settings extends PLL_Admin_Base { case 'activate': check_admin_referer( 'pll_activate' ); - $this->modules[ $_GET['module'] ]->activate(); + if ( isset( $_GET['module'] ) ) { + $module = sanitize_key( $_GET['module'] ); + if ( isset( $this->modules[ $module ] ) ) { + $this->modules[ $module ]->activate(); + } + } self::redirect(); break; case 'deactivate': check_admin_referer( 'pll_deactivate' ); - $this->modules[ $_GET['module'] ]->deactivate(); + if ( isset( $_GET['module'] ) ) { + $module = sanitize_key( $_GET['module'] ); + if ( isset( $this->modules[ $module ] ) ) { + $this->modules[ $module ]->deactivate(); + } + } self::redirect(); break; @@ -242,6 +290,8 @@ class PLL_Settings extends PLL_Admin_Base { * Also manages user input for these pages * * @since 0.1 + * + * @return void */ public function languages_page() { switch ( $this->active_tab ) { @@ -258,42 +308,47 @@ class PLL_Settings extends PLL_Admin_Base { } // Handle user input - $action = isset( $_REQUEST['pll_action'] ) ? $_REQUEST['pll_action'] : ''; - if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { + $action = isset( $_REQUEST['pll_action'] ) ? sanitize_key( $_REQUEST['pll_action'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification + if ( 'edit' === $action && ! empty( $_GET['lang'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + // phpcs:ignore WordPress.Security.NonceVerification, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable $edit_lang = $this->model->get_language( (int) $_GET['lang'] ); } else { $this->handle_actions( $action ); } // Displays the page - include PLL_SETTINGS_INC . '/view-languages.php'; + include __DIR__ . '/view-languages.php'; } /** * Enqueues scripts and styles + * + * @return void */ public function admin_enqueue_scripts() { parent::admin_enqueue_scripts(); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; - wp_enqueue_script( 'pll_admin', plugins_url( '/js/admin' . $suffix . '.js', POLYLANG_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION ); - wp_localize_script( 'pll_admin', 'pll_flag_base_url', plugins_url( '/flags/', POLYLANG_FILE ) ); + wp_enqueue_script( 'pll_admin', plugins_url( '/js/build/admin' . $suffix . '.js', POLYLANG_ROOT_FILE ), array( 'jquery', 'wp-ajax-response', 'postbox', 'jquery-ui-selectmenu' ), POLYLANG_VERSION, true ); + wp_localize_script( 'pll_admin', 'pll_admin', array( 'dismiss_notice' => esc_html__( 'Dismiss this notice.', 'polylang' ) ) ); - wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/selectmenu' . $suffix . '.css', POLYLANG_FILE ), array(), POLYLANG_VERSION ); + wp_enqueue_style( 'pll_selectmenu', plugins_url( '/css/build/selectmenu' . $suffix . '.css', POLYLANG_ROOT_FILE ), array(), POLYLANG_VERSION ); } /** * Displays a notice when there are objects with no language assigned * * @since 1.8 + * + * @return void */ public function notice_objects_with_no_lang() { if ( ! empty( $this->options['default_lang'] ) && $this->model->get_objects_with_no_lang( 1 ) ) { printf( '

    %s %s

    ', esc_html__( 'There are posts, pages, categories or tags without language.', 'polylang' ), - wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ), + esc_url( wp_nonce_url( '?page=mlang&pll_action=content-default-lang&noheader=true', 'content-default-lang' ) ), esc_html__( 'You can set them all to the default language.', 'polylang' ) ); } @@ -306,8 +361,9 @@ class PLL_Settings extends PLL_Admin_Base { * @since 1.5 * * @param array $args query arguments to add to the url + * @return void */ - static public function redirect( $args = array() ) { + public static function redirect( $args = array() ) { if ( $errors = get_settings_errors() ) { set_transient( 'settings_errors', $errors, 30 ); $args['settings-updated'] = 1; @@ -321,22 +377,36 @@ class PLL_Settings extends PLL_Admin_Base { * Get the list of predefined languages * * @since 2.3 + * + * @return string[] { + * @type string $code ISO 639-1 language code. + * @type string $locale WordPress locale. + * @type string $name Native language name. + * @type string $dir Text direction: 'ltr' or 'rtl'. + * @type string $flag Flag code, generally the country code. + * @type string $w3c W3C locale. + * @type string $facebook Facebook locale. + * } */ - public function get_predefined_languages() { - require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); - include PLL_SETTINGS_INC . '/languages.php'; + public static function get_predefined_languages() { + require_once ABSPATH . 'wp-admin/includes/translation-install.php'; + + $languages = include __DIR__ . '/languages.php'; + $translations = wp_get_available_translations(); // Keep only languages with existing WP language pack - $translations = wp_get_available_translations(); - $translations['en_US'] = ''; // Languages packs don't include en_US - $languages = array_intersect_key( $languages, $translations ); + // Unless the transient has expired and we don't have an internet connection to refresh it + if ( ! empty( $translations ) ) { + $translations['en_US'] = ''; // Languages packs don't include en_US + $languages = array_intersect_key( $languages, $translations ); + } /** * Filter the list of predefined languages * * @since 1.7.10 * @since 2.3 The languages arrays use associative keys instead of numerical keys - * @see settings/languages.php + * @see https://github.com/polylang/polylang/blob/2.8.2/settings/languages.php the list of predefined languages * * @param array $languages */ diff --git a/wp-content/plugins/polylang/settings/table-languages.php b/wp-content/plugins/polylang/settings/table-languages.php index d90c4e0e..21ef1027 100644 --- a/wp-content/plugins/polylang/settings/table-languages.php +++ b/wp-content/plugins/polylang/settings/table-languages.php @@ -1,4 +1,7 @@ 'Languages', // Do not translate ( used for css class ) - 'ajax' => false, - ) ); + public function __construct() { + parent::__construct( + array( + 'plural' => 'Languages', // Do not translate ( used for css class ) + 'ajax' => false, + ) + ); } /** - * Generates content for a single row of the table + * Generates content for a single row of the table. * * @since 1.8 * - * @param object $item The current item + * @param PLL_Language $item The language item. + * @return void */ public function single_row( $item ) { /** @@ -37,8 +43,8 @@ class PLL_Table_Languages extends WP_List_Table { * * @since 1.8 * - * @param array $classes list of class names - * @param object $item the current item + * @param array $classes The list of class names. + * @param PLL_Language $item The language item. */ $classes = apply_filters( 'pll_languages_row_classes', array(), $item ); echo '' : ' class="' . esc_attr( implode( ' ', $classes ) ) . '">' ); @@ -47,15 +53,15 @@ class PLL_Table_Languages extends WP_List_Table { } /** - * Displays the item information in a column ( default case ) + * Displays the item information in a column ( default case ). * * @since 0.1 * - * @param object $item - * @param string $column_name - * @return string + * @param PLL_Language $item The language item. + * @param string $column_name The column name. + * @return string|int */ - function column_default( $item, $column_name ) { + public function column_default( $item, $column_name ) { switch ( $column_name ) { case 'locale': case 'slug': @@ -66,7 +72,7 @@ class PLL_Table_Languages extends WP_List_Table { return (int) $item->$column_name; default: - return $item->$column_name; // flag + return $item->$column_name; // Flag. } } @@ -76,10 +82,10 @@ class PLL_Table_Languages extends WP_List_Table { * * @since 0.1 * - * @param object $item + * @param PLL_Language $item The language item. * @return string */ - function column_name( $item ) { + public function column_name( $item ) { return sprintf( '%s', esc_attr__( 'Edit this language', 'polylang' ), @@ -94,15 +100,15 @@ class PLL_Table_Languages extends WP_List_Table { * * @since 1.8 * - * @param object $item + * @param PLL_Language $item The language item. * @return string */ - function column_default_lang( $item ) { + public function column_default_lang( $item ) { $options = get_option( 'polylang' ); if ( $options['default_lang'] != $item->slug ) { - $s = sprintf(' -
    + $s = sprintf( + '', esc_attr__( 'Select as default language', 'polylang' ), @@ -112,12 +118,12 @@ class PLL_Table_Languages extends WP_List_Table { ); /** - * Filter the default language row action in the languages list table + * Filters the default language row action in the languages list table. * * @since 1.8 * - * @param string $s html markup of the action - * @param object $item + * @param string $s The html markup of the action. + * @param PLL_Language $item The language item. */ $s = apply_filters( 'pll_default_lang_row_action', $s, $item ); } else { @@ -126,7 +132,6 @@ class PLL_Table_Languages extends WP_List_Table { /* translators: accessibility text */ esc_html__( 'Default language', 'polylang' ) ); - $actions = array(); } return $s; @@ -137,9 +142,9 @@ class PLL_Table_Languages extends WP_List_Table { * * @since 0.1 * - * @return array the list of column titles + * @return string[] The list of column titles. */ - function get_columns() { + public function get_columns() { return array( 'name' => esc_html__( 'Full name', 'polylang' ), 'locale' => esc_html__( 'Locale', 'polylang' ), @@ -158,7 +163,7 @@ class PLL_Table_Languages extends WP_List_Table { * * @return array */ - function get_sortable_columns() { + public function get_sortable_columns() { return array( 'name' => array( 'name', true ), // sorted by name by default 'locale' => array( 'locale', false ), @@ -184,9 +189,9 @@ class PLL_Table_Languages extends WP_List_Table { * * @since 1.8 * - * @param object $item The item being acted upon. - * @param string $column_name Current column name. - * @param string $primary Primary column name. + * @param PLL_Language $item The language item being acted upon. + * @param string $column_name Current column name. + * @param string $primary Primary column name. * @return string The row actions output. */ protected function handle_row_actions( $item, $column_name, $primary ) { @@ -211,12 +216,12 @@ class PLL_Table_Languages extends WP_List_Table { ); /** - * Filter the list of row actions in the languages list table + * Filters the list of row actions in the languages list table. * * @since 1.8 * - * @param array $actions list of html markup actions - * @param object $item + * @param array $actions A list of html markup actions. + * @param PLL_Language $item The language item. */ $actions = apply_filters( 'pll_languages_row_actions', $actions, $item ); @@ -233,7 +238,7 @@ class PLL_Table_Languages extends WP_List_Table { * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b. */ protected function usort_reorder( $a, $b ) { - $orderby = ! empty( $_GET['orderby'] ) ? $_GET['orderby'] : 'name'; + $orderby = ! empty( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'name'; // phpcs:ignore WordPress.Security.NonceVerification // Determine sort order if ( is_numeric( $a->$orderby ) ) { $result = $a->$orderby > $b->$orderby ? 1 : -1; @@ -241,7 +246,7 @@ class PLL_Table_Languages extends WP_List_Table { $result = strcmp( $a->$orderby, $b->$orderby ); } // Send final sort direction to usort - return ( empty( $_GET['order'] ) || 'asc' == $_GET['order'] ) ? $result : -$result; + return ( empty( $_GET['order'] ) || 'asc' === $_GET['order'] ) ? $result : -$result; // phpcs:ignore WordPress.Security.NonceVerification } /** @@ -250,8 +255,9 @@ class PLL_Table_Languages extends WP_List_Table { * @since 0.1 * * @param array $data + * @return void */ - function prepare_items( $data = array() ) { + public function prepare_items( $data = array() ) { $per_page = $this->get_items_per_page( 'pll_lang_per_page' ); $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); @@ -260,10 +266,12 @@ class PLL_Table_Languages extends WP_List_Table { $total_items = count( $data ); $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page ); - $this->set_pagination_args( array( - 'total_items' => $total_items, - 'per_page' => $per_page, - 'total_pages' => ceil( $total_items / $per_page ), - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) + ); } } diff --git a/wp-content/plugins/polylang/settings/table-settings.php b/wp-content/plugins/polylang/settings/table-settings.php index 30736cb0..b44d79bd 100644 --- a/wp-content/plugins/polylang/settings/table-settings.php +++ b/wp-content/plugins/polylang/settings/table-settings.php @@ -1,4 +1,7 @@ 'Settings', // Do not translate ( used for css class ) - 'ajax' => false, - ) ); + public function __construct() { + parent::__construct( + array( + 'plural' => 'Settings', // Do not translate ( used for css class ) + 'ajax' => false, + ) + ); } /** @@ -33,11 +38,12 @@ class PLL_Table_Settings extends WP_List_Table { } /** - * Displays a single row + * Displays a single row. * * @since 1.8 * - * @param object $item PLL_Settings_Module object + * @param PLL_Settings_Module $item Settings module item. + * @return void */ public function single_row( $item ) { // Classes to reuse css from the plugins list table @@ -53,24 +59,19 @@ class PLL_Table_Settings extends WP_List_Table { // Display an upgrade message if there is any, reusing css from the plugins updates if ( $message = $item->get_upgrade_message() ) { - printf( ' -
    + printf( + '', - sprintf( - version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ? - '
    %s
    ' : // backward compatibility with WP < 4.6 - '

    %s

    ', - $message - ) + sprintf( '

    %s

    ', $message ) // phpcs:ignore WordPress.Security.EscapeOutput ); } // The settings if there are // "inactive" class to reuse css from the plugins list table if ( $form = $item->get_form() ) { - printf( ' - + printf( + '', - esc_attr( $item->module ), esc_html( $item->title ), $form, implode( $item->get_buttons() ) + esc_attr( $item->module ), + esc_html( $item->title ), + $form, // phpcs:ignore + implode( $item->get_buttons() ) // phpcs:ignore ); } } /** - * Generates the columns for a single row of the table + * Generates the columns for a single row of the table. * * @since 1.8 * - * @param object $item The current item + * @param PLL_Settings_Module $item Settings module item. + * @return void */ protected function single_row_columns( $item ) { - list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); + $column_info = $this->get_column_info(); + $columns = $column_info[0]; + $primary = $column_info[3]; - foreach ( $columns as $column_name => $column_display_name ) { + foreach ( array_keys( $columns ) as $column_name ) { $classes = "$column_name column-$column_name"; if ( $primary === $column_name ) { $classes .= ' column-primary'; } - if ( in_array( $column_name, $hidden ) ) { - $classes .= ' hidden'; - } - if ( 'cb' == $column_name ) { echo ''; - } - else { + } else { printf( ''; } } } /** - * Displays the item information in a column ( default case ) + * Displays the item information in a column (default case). * * @since 1.8 * - * @param object $item - * @param string $column_name - * @return string + * @param PLL_Settings_Module $item Settings module item. + * @param string $column_name Column name. + * @return string The column name. */ protected function column_default( $item, $column_name ) { if ( 'plugin-title' == $column_name ) { @@ -134,11 +136,11 @@ class PLL_Table_Settings extends WP_List_Table { } /** - * Gets the list of columns + * Gets the list of columns. * * @since 1.8 * - * @return array the list of column titles + * @return string[] The list of column titles. */ public function get_columns() { return array( @@ -164,10 +166,19 @@ class PLL_Table_Settings extends WP_List_Table { * * @since 1.8 * - * @param array $items + * @param PLL_Settings_Module[] $items Array of settings module items. + * @return void */ public function prepare_items( $items = array() ) { $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns(), $this->get_primary_column_name() ); + + // Sort rows, lowest priority on top. + usort( + $items, + function( $a, $b ) { + return $a->priority > $b->priority ? 1 : -1; + } + ); $this->items = $items; } @@ -177,6 +188,7 @@ class PLL_Table_Settings extends WP_List_Table { * @since 2.1 * * @param string $which 'top' or 'bottom' + * @return void */ - protected function display_tablenav( $which ) {} + protected function display_tablenav( $which ) {} // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable } diff --git a/wp-content/plugins/polylang/settings/table-string.php b/wp-content/plugins/polylang/settings/table-string.php index f899d69d..cbea2055 100644 --- a/wp-content/plugins/polylang/settings/table-string.php +++ b/wp-content/plugins/polylang/settings/table-string.php @@ -1,4 +1,7 @@ 'Strings translations', // Do not translate ( used for css class ) - 'ajax' => false, - ) ); + public function __construct( $languages ) { + parent::__construct( + array( + 'plural' => 'Strings translations', // Do not translate ( used for css class ) + 'ajax' => false, + ) + ); $this->languages = $languages; $this->strings = PLL_Admin_Strings::get_strings(); $this->groups = array_unique( wp_list_pluck( $this->strings, 'context' ) ); - $this->selected_group = empty( $_GET['group'] ) || ! in_array( $_GET['group'], $this->groups ) ? -1 : $_GET['group']; + + $this->selected_group = -1; + + if ( ! empty( $_GET['group'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $group = sanitize_text_field( wp_unslash( $_GET['group'] ) ); // phpcs:ignore WordPress.Security.NonceVerification + if ( in_array( $group, $this->groups ) ) { + $this->selected_group = $group; + } + } add_action( 'mlang_action_string-translation', array( $this, 'save_translations' ) ); } @@ -43,7 +82,7 @@ class PLL_Table_String extends WP_List_Table { * @param string $column_name * @return string */ - function column_default( $item, $column_name ) { + public function column_default( $item, $column_name ) { return $item[ $column_name ]; } @@ -55,12 +94,12 @@ class PLL_Table_String extends WP_List_Table { * @param array $item * @return string */ - function column_cb( $item ) { + public function column_cb( $item ) { return sprintf( '', esc_attr( $item['row'] ), /* translators: accessibility text, %s is a string potentially in any language */ - sprintf( __( 'Select %s' ), format_to_edit( $item['string'] ) ), + sprintf( __( 'Select %s', 'polylang' ), format_to_edit( $item['string'] ) ), empty( $item['icl'] ) ? 'disabled' : '' // Only strings registered with WPML API can be removed ); } @@ -73,7 +112,7 @@ class PLL_Table_String extends WP_List_Table { * @param array $item * @return string */ - function column_string( $item ) { + public function column_string( $item ) { return format_to_edit( $item['string'] ); // Don't interpret special chars for the string column } @@ -85,7 +124,7 @@ class PLL_Table_String extends WP_List_Table { * @param array $item * @return string */ - function column_translations( $item ) { + public function column_translations( $item ) { $languages = array_combine( wp_list_pluck( $this->languages, 'slug' ), wp_list_pluck( $this->languages, 'name' ) ); $out = ''; @@ -93,26 +132,28 @@ class PLL_Table_String extends WP_List_Table { $input_type = $item['multiline'] ? '' : ''; - $out .= sprintf( '
    ' . $input_type . '
    ' . "\n", + $out .= sprintf( + '
    ' . $input_type . '
    ' . "\n", esc_attr( $key ), esc_attr( $item['row'] ), esc_html( $languages[ $key ] ), - format_to_edit( $translation ) ); // Don't interpret special chars + format_to_edit( $translation ) // Don't interpret special chars + ); } return $out; } /** - * Gets the list of columns + * Gets the list of columns. * * @since 0.6 * - * @return array the list of column titles + * @return string[] The list of column titles. */ - function get_columns() { + public function get_columns() { return array( - 'cb' => '', // Checkbox + 'cb' => '', // Checkbox. 'string' => esc_html__( 'String', 'polylang' ), 'name' => esc_html__( 'Name', 'polylang' ), 'context' => esc_html__( 'Group', 'polylang' ), @@ -127,7 +168,7 @@ class PLL_Table_String extends WP_List_Table { * * @return array */ - function get_sortable_columns() { + public function get_sortable_columns() { return array( 'string' => array( 'string', false ), 'name' => array( 'name', false ), @@ -146,6 +187,29 @@ class PLL_Table_String extends WP_List_Table { return 'string'; } + /** + * Search for a string in translations. Case insensitive. + * + * @since 2.6 + * + * @param PLL_MO[] $mos An array of PLL_MO objects. + * @param string $s Searched string. + * @return string[] Found strings. + */ + protected function search_in_translations( $mos, $s ) { + $founds = array(); + + foreach ( $mos as $mo ) { + foreach ( wp_list_pluck( $mo->entries, 'translations' ) as $string => $translation ) { + if ( false !== stripos( $translation[0], $s ) ) { + $founds[] = $string; + } + } + } + + return array_unique( $founds ); + } + /** * Sort items * @@ -156,66 +220,96 @@ class PLL_Table_String extends WP_List_Table { * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b. */ protected function usort_reorder( $a, $b ) { - $result = strcmp( $a[ $_GET['orderby'] ], $b[ $_GET['orderby'] ] ); // determine sort order - return ( empty( $_GET['order'] ) || 'asc' === $_GET['order'] ) ? $result : -$result; // send final sort direction to usort + if ( ! empty( $_GET['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + $orderby = sanitize_key( $_GET['orderby'] ); // phpcs:ignore WordPress.Security.NonceVerification + if ( isset( $a[ $orderby ], $b[ $orderby ] ) ) { + $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); // Determine sort order + return ( empty( $_GET['order'] ) || 'asc' === $_GET['order'] ) ? $result : -$result; // phpcs:ignore WordPress.Security.NonceVerification + } + } + + return 0; } /** * Prepares the list of items for displaying * * @since 0.6 + * + * @return void */ - function prepare_items() { - $data = $this->strings; - - // Filter for search string - $s = empty( $_GET['s'] ) ? '' : wp_unslash( $_GET['s'] ); - foreach ( $data as $key => $row ) { - if ( ( -1 !== $this->selected_group && $row['context'] !== $this->selected_group ) || ( ! empty( $s ) && stripos( $row['name'], $s ) === false && stripos( $row['string'], $s ) === false ) ) { - unset( $data[ $key ] ); - } + public function prepare_items() { + // Is admin language filter active? + if ( $lg = get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ) { + $languages = wp_list_filter( $this->languages, array( 'slug' => $lg ) ); + } else { + $languages = $this->languages; } // Load translations - foreach ( $this->languages as $language ) { - // Filters by language if requested - if ( ( $lg = get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ) && $language->slug !== $lg ) { - continue; - } + $mo = array(); + foreach ( $languages as $language ) { + $mo[ $language->slug ] = new PLL_MO(); + $mo[ $language->slug ]->import_from_db( $language ); + } + + $data = $this->strings; + + // Filter by selected group + if ( -1 !== $this->selected_group ) { + $data = wp_list_filter( $data, array( 'context' => $this->selected_group ) ); + } + + // Filter by searched string + $s = empty( $_GET['s'] ) ? '' : wp_unslash( $_GET['s'] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput + + if ( ! empty( $s ) ) { + // Search in translations + $in_translations = $this->search_in_translations( $mo, $s ); - $mo = new PLL_MO(); - $mo->import_from_db( $language ); foreach ( $data as $key => $row ) { - $data[ $key ]['translations'][ $language->slug ] = $mo->translate( $row['string'] ); - $data[ $key ]['row'] = $key; // Store the row number for convenience + if ( stripos( $row['name'], $s ) === false && stripos( $row['string'], $s ) === false && ! in_array( $row['string'], $in_translations ) ) { + unset( $data[ $key ] ); + } } } + // Sorting + uasort( $data, array( $this, 'usort_reorder' ) ); + + // Paging $per_page = $this->get_items_per_page( 'pll_strings_per_page' ); $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); - if ( ! empty( $_GET['orderby'] ) ) { // No sort by default - usort( $data, array( $this, 'usort_reorder' ) ); - } - $total_items = count( $data ); - $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page ); + $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page, true ); - $this->set_pagination_args( array( - 'total_items' => $total_items, - 'per_page' => $per_page, - 'total_pages' => ceil( $total_items / $per_page ), - ) ); + $this->set_pagination_args( + array( + 'total_items' => $total_items, + 'per_page' => $per_page, + 'total_pages' => ceil( $total_items / $per_page ), + ) + ); + + // Translate strings + // Kept for the end as it is a slow process + foreach ( $languages as $language ) { + foreach ( $this->items as $key => $row ) { + $this->items[ $key ]['translations'][ $language->slug ] = $mo[ $language->slug ]->translate( $row['string'] ); + $this->items[ $key ]['row'] = $key; // Store the row number for convenience + } + } } /** - * Get the list of possible bulk actions + * Get the list of possible bulk actions. * * @since 1.1 * - * @return array + * @return string[] Array of bulk actions. */ - function get_bulk_actions() { + public function get_bulk_actions() { return array( 'delete' => __( 'Delete', 'polylang' ) ); } @@ -228,7 +322,7 @@ class PLL_Table_String extends WP_List_Table { * @return string|false The action name or False if no action was selected */ public function current_action() { - return empty( $_POST['submit'] ) ? parent::current_action() : false; + return empty( $_POST['submit'] ) ? parent::current_action() : false; // phpcs:ignore WordPress.Security.NonceVerification } /** @@ -237,8 +331,9 @@ class PLL_Table_String extends WP_List_Table { * @since 1.1 * * @param string $which only 'top' is supported + * @return void */ - function extra_tablenav( $which ) { + public function extra_tablenav( $which ) { if ( 'top' !== $which ) { return; } @@ -252,7 +347,7 @@ class PLL_Table_String extends WP_List_Table { echo '' . "\n"; - submit_button( __( 'Filter' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); + submit_button( __( 'Filter', 'polylang' ), 'button', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); echo ''; } @@ -275,29 +370,34 @@ class PLL_Table_String extends WP_List_Table { * Optionaly clean the DB * * @since 1.9 + * + * @return void */ public function save_translations() { check_admin_referer( 'string-translation', '_wpnonce_string-translation' ); if ( ! empty( $_POST['submit'] ) ) { foreach ( $this->languages as $language ) { - if ( empty( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch ) + if ( empty( $_POST['translation'][ $language->slug ] ) || ! is_array( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch ) continue; } + $translations = array_map( 'trim', wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + $mo = new PLL_MO(); $mo->import_from_db( $language ); - foreach ( $_POST['translation'][ $language->slug ] as $key => $translation ) { + foreach ( $translations as $key => $translation ) { /** * Filter the string translation before it is saved in DB * Allows to sanitize strings registered with pll_register_string * * @since 1.6 + * @since 2.7 The translation passed to the filter is unslashed. * - * @param string $translation the string translation - * @param string $name the name as defined in pll_register_string - * @param string $context the context as defined in pll_register_string + * @param string $translation The string translation. + * @param string $name The name as defined in pll_register_string. + * @param string $context The context as defined in pll_register_string. */ $translation = apply_filters( 'pll_sanitize_string_translation', $translation, $this->strings[ $key ]['name'], $this->strings[ $key ]['context'] ); $mo->add_entry( $mo->make_entry( $this->strings[ $key ]['string'], $translation ) ); @@ -327,7 +427,7 @@ class PLL_Table_String extends WP_List_Table { // Unregisters strings registered through WPML API if ( $this->current_action() === 'delete' && ! empty( $_POST['strings'] ) && function_exists( 'icl_unregister_string' ) ) { - foreach ( $_POST['strings'] as $key ) { + foreach ( array_map( 'sanitize_key', $_POST['strings'] ) as $key ) { icl_unregister_string( $this->strings[ $key ]['context'], $this->strings[ $key ]['name'] ); } } diff --git a/wp-content/plugins/polylang/settings/view-about.php b/wp-content/plugins/polylang/settings/view-about.php index 262c69c6..dbea7642 100644 --- a/wp-content/plugins/polylang/settings/view-about.php +++ b/wp-content/plugins/polylang/settings/view-about.php @@ -1,7 +1,8 @@ ', '' ); @@ -27,14 +28,3 @@ if ( ! defined( 'ABSPATH' ) ) { } ?>

    -

    - ', - '' - ); - ?> -

    - diff --git a/wp-content/plugins/polylang/settings/view-languages.php b/wp-content/plugins/polylang/settings/view-languages.php index c1c4db8c..ea0493ab 100644 --- a/wp-content/plugins/polylang/settings/view-languages.php +++ b/wp-content/plugins/polylang/settings/view-languages.php @@ -1,7 +1,8 @@ active_tab . '.php'; - break; + include __DIR__ . '/view-tab-' . $this->active_tab . '.php'; + // Intentional fall-through to upgrade to fire the action below. default: /** diff --git a/wp-content/plugins/polylang/settings/view-tab-lang.php b/wp-content/plugins/polylang/settings/view-tab-lang.php index b3679a21..bcad9e9f 100644 --- a/wp-content/plugins/polylang/settings/view-tab-lang.php +++ b/wp-content/plugins/polylang/settings/view-tab-lang.php @@ -1,11 +1,12 @@
    @@ -18,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) {
    @@ -28,14 +29,14 @@ if ( ! defined( 'ABSPATH' ) ) {
    -

    +

    - @@ -48,139 +49,133 @@ if ( ! defined( 'ABSPATH' ) ) { -
    - - + + get_predefined_languages() as $lg ) { + $lg['flag_code'] = $lg['flag']; + $language = new PLL_Language( $lg ); + $language->set_flag(); + printf( + '' . "\n", + esc_attr( $lg['code'] ), + esc_attr( $lg['locale'] ), + 'rtl' == $lg['dir'] ? '1' : '0', + esc_attr( $lg['flag'] ), + esc_html( $lg['name'] ), + esc_html( $language->flag ) + ); + } + ?> + +

    +
    + +
    + get_predefined_languages() as $lg ) { - printf( - '' . "\n", - esc_attr( $lg['code'] ), - esc_attr( $lg['locale'] ), - 'rtl' == $lg['dir'] ? '1' : '0', - esc_attr( $lg['flag'] ), - esc_html( $lg['name'] ) - ); - } + printf( + '', + ! empty( $edit_lang ) ? esc_attr( $edit_lang->name ) : '' + ); ?> - -

    -
    +

    +
    -
    - - ', - ! empty( $edit_lang ) ? esc_attr( $edit_lang->name ) : '' - ); - ?> -

    -
    - -
    - - ', - ! empty( $edit_lang ) ? esc_attr( $edit_lang->locale ) : '' - ); - ?> -

    -
    - -
    - - ', - ! empty( $edit_lang ) ? esc_attr( $edit_lang->slug ) : '' - ); - ?> -

    -
    - -
    - - %s', - ! empty( $edit_lang ) && $edit_lang->is_rtl ? '' : 'checked="checked"', - esc_html__( 'left to right', 'polylang' ) - ); - printf( - '', - ! empty( $edit_lang ) && $edit_lang->is_rtl ? 'checked="checked"' : '', - esc_html__( 'right to left', 'polylang' ) - ); - ?> -

    -
    - -
    - - ', + ! empty( $edit_lang ) ? esc_attr( $edit_lang->locale ) : '' + ); ?> - -

    -
    +

    +
    -
    - +
    + + ', + ! empty( $edit_lang ) ? esc_attr( $edit_lang->slug ) : '' + ); + ?> +

    +
    + +
    + + %s', + checked( ! empty( $edit_lang ) && $edit_lang->is_rtl, false, false ), + esc_html__( 'left to right', 'polylang' ) + ); + printf( + '', + checked( ! empty( $edit_lang ) && $edit_lang->is_rtl, true, false ), + esc_html__( 'right to left', 'polylang' ) + ); + ?> +

    +
    + +
    + + +

    +
    + +
    + + ', + ! empty( $edit_lang ) ? esc_attr( $edit_lang->term_group ) : '' + ); + ?> +

    +
    ', - ! empty( $edit_lang ) ? esc_attr( $edit_lang->term_group ) : '' - ); - ?> -

    -
    - + submit_button( ! empty( $edit_lang ) ? __( 'Update', 'polylang' ) : __( 'Add new language', 'polylang' ) ); // since WP 3.1 + ?> - - diff --git a/wp-content/plugins/polylang/settings/view-tab-settings.php b/wp-content/plugins/polylang/settings/view-tab-settings.php index bc56d619..0a038b3b 100644 --- a/wp-content/plugins/polylang/settings/view-tab-settings.php +++ b/wp-content/plugins/polylang/settings/view-tab-settings.php @@ -1,11 +1,12 @@
    diff --git a/wp-content/plugins/polylang/settings/view-tab-strings.php b/wp-content/plugins/polylang/settings/view-tab-strings.php index 29d0cd0c..7f3a304c 100644 --- a/wp-content/plugins/polylang/settings/view-tab-strings.php +++ b/wp-content/plugins/polylang/settings/view-tab-strings.php @@ -1,7 +1,8 @@ +
    + +
    +
    diff --git a/wp-content/plugins/polylang/uninstall.php b/wp-content/plugins/polylang/uninstall.php index a2d2ece1..e952fe04 100644 --- a/wp-content/plugins/polylang/uninstall.php +++ b/wp-content/plugins/polylang/uninstall.php @@ -1,7 +1,10 @@ get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { @@ -39,25 +47,10 @@ class PLL_Uninstall { * * @since 0.5 */ - function uninstall() { - $options = get_option( 'polylang' ); - - if ( empty( $options['uninstall'] ) ) { - return; - } - - // Suppress data of the old model < 1.2 - // FIXME: to remove when support for v1.1.6 will be dropped + public function uninstall() { global $wpdb; - $wpdb->termmeta = $wpdb->prefix . 'termmeta'; // registers the termmeta table in wpdb - // Do nothing if the termmeta table does not exists - if ( count( $wpdb->get_results( "SHOW TABLES LIKE '$wpdb->termmeta'" ) ) ) { - $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = '_translations'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_language'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_rtl'" ); - $wpdb->query( "DELETE FROM $wpdb->termmeta WHERE meta_key = '_translations'" ); - } + do_action( 'pll_uninstall' ); // Need to register the taxonomies $pll_taxonomies = array( 'language', 'term_language', 'post_translations', 'term_translations' ); @@ -70,45 +63,46 @@ class PLL_Uninstall { // Delete users options foreach ( get_users( array( 'fields' => 'ID' ) ) as $user_id ) { delete_user_meta( $user_id, 'pll_filter_content' ); - delete_user_meta( $user_id, 'pll_duplicate_content' ); + delete_user_meta( $user_id, 'pll_dismissed_notices' ); // Legacy meta. foreach ( $languages as $lang ) { delete_user_meta( $user_id, 'description_' . $lang->slug ); } } // Delete menu language switchers - $ids = get_posts( array( - 'post_type' => 'nav_menu_item', - 'numberposts' => -1, - 'nopaging' => true, - 'fields' => 'ids', - 'meta_key' => '_pll_menu_item', - ) ); + $ids = get_posts( + array( + 'post_type' => 'nav_menu_item', + 'numberposts' => -1, + 'nopaging' => true, + 'fields' => 'ids', + 'meta_key' => '_pll_menu_item', + ) + ); foreach ( $ids as $id ) { wp_delete_post( $id, true ); } - // Delete the strings translations ( <1.2 ) - // FIXME: to remove when support for v1.1.6 will be dropped - foreach ( $languages as $lang ) { - delete_option( 'polylang_mo' . $lang->term_id ); - } - - // Delete the strings translations 1.2+ + // Delete the strings translations. register_post_type( 'polylang_mo', array( 'rewrite' => false, 'query_var' => false ) ); - $ids = get_posts( array( - 'post_type' => 'polylang_mo', - 'post_status' => 'any', - 'numberposts' => -1, - 'nopaging' => true, - 'fields' => 'ids', - ) ); + $ids = get_posts( + array( + 'post_type' => 'polylang_mo', + 'post_status' => 'any', + 'numberposts' => -1, + 'nopaging' => true, + 'fields' => 'ids', + ) + ); foreach ( $ids as $id ) { wp_delete_post( $id, true ); } // Delete all what is related to languages and translations + $term_ids = array(); + $tt_ids = array(); + foreach ( get_terms( $pll_taxonomies, array( 'hide_empty' => false ) ) as $term ) { $term_ids[] = (int) $term->term_id; $tt_ids[] = (int) $term->term_taxonomy_id; @@ -116,13 +110,13 @@ class PLL_Uninstall { if ( ! empty( $term_ids ) ) { $term_ids = array_unique( $term_ids ); - $wpdb->query( "DELETE FROM $wpdb->terms WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); - $wpdb->query( "DELETE FROM $wpdb->term_taxonomy WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); + $wpdb->query( "DELETE FROM {$wpdb->terms} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared + $wpdb->query( "DELETE FROM {$wpdb->term_taxonomy} WHERE term_id IN ( " . implode( ',', $term_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared } if ( ! empty( $tt_ids ) ) { $tt_ids = array_unique( $tt_ids ); - $wpdb->query( "DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ( " . implode( ',', $tt_ids ) . ' )' ); + $wpdb->query( "DELETE FROM {$wpdb->term_relationships} WHERE term_taxonomy_id IN ( " . implode( ',', $tt_ids ) . ' )' ); // PHPCS:ignore WordPress.DB.PreparedSQL.NotPrepared } // Delete options @@ -130,11 +124,10 @@ class PLL_Uninstall { delete_option( 'widget_polylang' ); // Automatically created by WP delete_option( 'polylang_wpml_strings' ); // Strings registered with icl_register_string delete_option( 'polylang_licenses' ); + delete_option( 'pll_dismissed_notices' ); // Delete transients delete_transient( 'pll_languages_list' ); - delete_transient( 'pll_upgrade_1_4' ); - delete_transient( 'pll_translated_slugs' ); } } diff --git a/wp-content/plugins/polylang/vendor/autoload.php b/wp-content/plugins/polylang/vendor/autoload.php new file mode 100644 index 00000000..bd6a156b --- /dev/null +++ b/wp-content/plugins/polylang/vendor/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0, PSR-4 and classmap class loader. + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + * @see http://www.php-fig.org/psr/psr-0/ + * @see http://www.php-fig.org/psr/psr-4/ + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + private $classMapAuthoritative = false; + private $missingClasses = array(); + private $apcuPrefix; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', array_values($this->prefixesPsr0)); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * APCu prefix to use to cache found/not-found classes, if the extension is enabled. + * + * @param string|null $apcuPrefix + */ + public function setApcuPrefix($apcuPrefix) + { + $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null; + } + + /** + * The APCu prefix in use, or null if APCu caching is not enabled. + * + * @return string|null + */ + public function getApcuPrefix() + { + return $this->apcuPrefix; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) { + return false; + } + if (null !== $this->apcuPrefix) { + $file = apcu_fetch($this->apcuPrefix.$class, $hit); + if ($hit) { + return $file; + } + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if (false === $file && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if (null !== $this->apcuPrefix) { + apcu_add($this->apcuPrefix.$class, $file); + } + + if (false === $file) { + // Remember that this class does not exist. + $this->missingClasses[$class] = true; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath . '\\'; + if (isset($this->prefixDirsPsr4[$search])) { + $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); + foreach ($this->prefixDirsPsr4[$search] as $dir) { + if (file_exists($file = $dir . $pathEnd)) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + return false; + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/wp-content/plugins/polylang/vendor/composer/LICENSE b/wp-content/plugins/polylang/vendor/composer/LICENSE new file mode 100644 index 00000000..f27399a0 --- /dev/null +++ b/wp-content/plugins/polylang/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/wp-content/plugins/polylang/vendor/composer/autoload_classmap.php b/wp-content/plugins/polylang/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..dbd15056 --- /dev/null +++ b/wp-content/plugins/polylang/vendor/composer/autoload_classmap.php @@ -0,0 +1,130 @@ + $baseDir . '/integrations/wp-offload-media/as3cf.php', + 'PLL_Abstract_Sitemaps' => $baseDir . '/modules/sitemaps/abstract-sitemaps.php', + 'PLL_Accept_Language' => $baseDir . '/frontend/accept-language.php', + 'PLL_Accept_Languages_Collection' => $baseDir . '/frontend/accept-languages-collection.php', + 'PLL_Admin' => $baseDir . '/admin/admin.php', + 'PLL_Admin_Base' => $baseDir . '/admin/admin-base.php', + 'PLL_Admin_Block_Editor' => $baseDir . '/admin/admin-block-editor.php', + 'PLL_Admin_Classic_Editor' => $baseDir . '/admin/admin-classic-editor.php', + 'PLL_Admin_Default_Term' => $baseDir . '/admin/admin-default-term.php', + 'PLL_Admin_Filters' => $baseDir . '/admin/admin-filters.php', + 'PLL_Admin_Filters_Columns' => $baseDir . '/admin/admin-filters-columns.php', + 'PLL_Admin_Filters_Media' => $baseDir . '/admin/admin-filters-media.php', + 'PLL_Admin_Filters_Post' => $baseDir . '/admin/admin-filters-post.php', + 'PLL_Admin_Filters_Post_Base' => $baseDir . '/admin/admin-filters-post-base.php', + 'PLL_Admin_Filters_Term' => $baseDir . '/admin/admin-filters-term.php', + 'PLL_Admin_Filters_Widgets_Options' => $baseDir . '/admin/admin-filters-widgets-options.php', + 'PLL_Admin_Links' => $baseDir . '/admin/admin-links.php', + 'PLL_Admin_Model' => $baseDir . '/admin/admin-model.php', + 'PLL_Admin_Nav_Menu' => $baseDir . '/admin/admin-nav-menu.php', + 'PLL_Admin_Notices' => $baseDir . '/admin/admin-notices.php', + 'PLL_Admin_Site_Health' => $baseDir . '/modules/site-health/admin-site-health.php', + 'PLL_Admin_Static_Pages' => $baseDir . '/admin/admin-static-pages.php', + 'PLL_Admin_Strings' => $baseDir . '/admin/admin-strings.php', + 'PLL_Admin_Sync' => $baseDir . '/modules/sync/admin-sync.php', + 'PLL_Aqua_Resizer' => $baseDir . '/integrations/aqua-resizer/aqua-resizer.php', + 'PLL_Base' => $baseDir . '/include/base.php', + 'PLL_Block_Editor_Filter_Preload_Paths' => $baseDir . '/admin/block-editor-filter-preload-paths.php', + 'PLL_CRUD_Posts' => $baseDir . '/include/crud-posts.php', + 'PLL_CRUD_Terms' => $baseDir . '/include/crud-terms.php', + 'PLL_Cache' => $baseDir . '/include/cache.php', + 'PLL_Cache_Compat' => $baseDir . '/integrations/cache/cache-compat.php', + 'PLL_Cft' => $baseDir . '/integrations/custom-field-template/cft.php', + 'PLL_Choose_Lang' => $baseDir . '/frontend/choose-lang.php', + 'PLL_Choose_Lang_Content' => $baseDir . '/frontend/choose-lang-content.php', + 'PLL_Choose_Lang_Domain' => $baseDir . '/frontend/choose-lang-domain.php', + 'PLL_Choose_Lang_Url' => $baseDir . '/frontend/choose-lang-url.php', + 'PLL_Cookie' => $baseDir . '/include/cookie.php', + 'PLL_Domain_Mapping' => $baseDir . '/integrations/domain-mapping/domain-mapping.php', + 'PLL_Duplicate_Post' => $baseDir . '/integrations/duplicate-post/duplicate-post.php', + 'PLL_Featured_Content' => $baseDir . '/integrations/jetpack/featured-content.php', + 'PLL_Filters' => $baseDir . '/include/filters.php', + 'PLL_Filters_Links' => $baseDir . '/include/filters-links.php', + 'PLL_Filters_Sanitization' => $baseDir . '/include/filters-sanitization.php', + 'PLL_Filters_Widgets_Options' => $baseDir . '/include/filters-widgets-options.php', + 'PLL_Frontend' => $baseDir . '/frontend/frontend.php', + 'PLL_Frontend_Auto_Translate' => $baseDir . '/frontend/frontend-auto-translate.php', + 'PLL_Frontend_Filters' => $baseDir . '/frontend/frontend-filters.php', + 'PLL_Frontend_Filters_Links' => $baseDir . '/frontend/frontend-filters-links.php', + 'PLL_Frontend_Filters_Search' => $baseDir . '/frontend/frontend-filters-search.php', + 'PLL_Frontend_Filters_Widgets' => $baseDir . '/frontend/frontend-filters-widgets.php', + 'PLL_Frontend_Links' => $baseDir . '/frontend/frontend-links.php', + 'PLL_Frontend_Nav_Menu' => $baseDir . '/frontend/frontend-nav-menu.php', + 'PLL_Frontend_Static_Pages' => $baseDir . '/frontend/frontend-static-pages.php', + 'PLL_Install' => $baseDir . '/install/install.php', + 'PLL_Install_Base' => $baseDir . '/install/install-base.php', + 'PLL_Integrations' => $baseDir . '/integrations/integrations.php', + 'PLL_Jetpack' => $baseDir . '/integrations/jetpack/jetpack.php', + 'PLL_Language' => $baseDir . '/include/language.php', + 'PLL_License' => $baseDir . '/include/license.php', + 'PLL_Lingotek' => $baseDir . '/modules/lingotek/lingotek.php', + 'PLL_Links' => $baseDir . '/include/links.php', + 'PLL_Links_Abstract_Domain' => $baseDir . '/include/links-abstract-domain.php', + 'PLL_Links_Default' => $baseDir . '/include/links-default.php', + 'PLL_Links_Directory' => $baseDir . '/include/links-directory.php', + 'PLL_Links_Domain' => $baseDir . '/include/links-domain.php', + 'PLL_Links_Model' => $baseDir . '/include/links-model.php', + 'PLL_Links_Permalinks' => $baseDir . '/include/links-permalinks.php', + 'PLL_Links_Subdomain' => $baseDir . '/include/links-subdomain.php', + 'PLL_MO' => $baseDir . '/include/mo.php', + 'PLL_Model' => $baseDir . '/include/model.php', + 'PLL_Multilingual_Sitemaps_Provider' => $baseDir . '/modules/sitemaps/multilingual-sitemaps-provider.php', + 'PLL_Nav_Menu' => $baseDir . '/include/nav-menu.php', + 'PLL_No_Category_Base' => $baseDir . '/integrations/no-category-base/no-category-base.php', + 'PLL_OLT_Manager' => $baseDir . '/include/olt-manager.php', + 'PLL_Plugin_Updater' => $baseDir . '/install/plugin-updater.php', + 'PLL_Query' => $baseDir . '/include/query.php', + 'PLL_REST_Request' => $baseDir . '/include/rest-request.php', + 'PLL_Settings' => $baseDir . '/settings/settings.php', + 'PLL_Settings_Browser' => $baseDir . '/settings/settings-browser.php', + 'PLL_Settings_CPT' => $baseDir . '/settings/settings-cpt.php', + 'PLL_Settings_Licenses' => $baseDir . '/settings/settings-licenses.php', + 'PLL_Settings_Media' => $baseDir . '/settings/settings-media.php', + 'PLL_Settings_Module' => $baseDir . '/settings/settings-module.php', + 'PLL_Settings_Preview_Share_Slug' => $baseDir . '/modules/share-slug/settings-preview-share-slug.php', + 'PLL_Settings_Preview_Translate_Slugs' => $baseDir . '/modules/translate-slugs/settings-preview-translate-slugs.php', + 'PLL_Settings_Sync' => $baseDir . '/modules/sync/settings-sync.php', + 'PLL_Settings_Url' => $baseDir . '/settings/settings-url.php', + 'PLL_Sitemaps' => $baseDir . '/modules/sitemaps/sitemaps.php', + 'PLL_Sitemaps_Domain' => $baseDir . '/modules/sitemaps/sitemaps-domain.php', + 'PLL_Static_Pages' => $baseDir . '/include/static-pages.php', + 'PLL_Switcher' => $baseDir . '/include/switcher.php', + 'PLL_Sync' => $baseDir . '/modules/sync/sync.php', + 'PLL_Sync_Metas' => $baseDir . '/modules/sync/sync-metas.php', + 'PLL_Sync_Post_Metas' => $baseDir . '/modules/sync/sync-post-metas.php', + 'PLL_Sync_Tax' => $baseDir . '/modules/sync/sync-tax.php', + 'PLL_Sync_Term_Metas' => $baseDir . '/modules/sync/sync-term-metas.php', + 'PLL_T15S' => $baseDir . '/install/t15s.php', + 'PLL_Table_Languages' => $baseDir . '/settings/table-languages.php', + 'PLL_Table_Settings' => $baseDir . '/settings/table-settings.php', + 'PLL_Table_String' => $baseDir . '/settings/table-string.php', + 'PLL_Translate_Option' => $baseDir . '/include/translate-option.php', + 'PLL_Translated_Object' => $baseDir . '/include/translated-object.php', + 'PLL_Translated_Post' => $baseDir . '/include/translated-post.php', + 'PLL_Translated_Term' => $baseDir . '/include/translated-term.php', + 'PLL_Twenty_Seventeen' => $baseDir . '/integrations/twenty-seventeen/twenty-seven-teen.php', + 'PLL_Upgrade' => $baseDir . '/install/upgrade.php', + 'PLL_WPML_API' => $baseDir . '/modules/wpml/wpml-api.php', + 'PLL_WPML_Compat' => $baseDir . '/modules/wpml/wpml-compat.php', + 'PLL_WPML_Config' => $baseDir . '/modules/wpml/wpml-config.php', + 'PLL_WPSEO' => $baseDir . '/integrations/wpseo/wpseo.php', + 'PLL_WPSEO_OGP' => $baseDir . '/integrations/wpseo/wpseo-ogp.php', + 'PLL_WP_Import' => $baseDir . '/integrations/wp-importer/wp-import.php', + 'PLL_WP_Sweep' => $baseDir . '/integrations/wp-sweep/wp-sweep.php', + 'PLL_Walker_Dropdown' => $baseDir . '/include/walker-dropdown.php', + 'PLL_Walker_List' => $baseDir . '/include/walker-list.php', + 'PLL_Widget_Calendar' => $baseDir . '/include/widget-calendar.php', + 'PLL_Widget_Languages' => $baseDir . '/include/widget-languages.php', + 'PLL_Wizard' => $baseDir . '/modules/wizard/wizard.php', + 'PLL_WordPress_Importer' => $baseDir . '/integrations/wp-importer/wordpress-importer.php', + 'PLL_Yarpp' => $baseDir . '/integrations/yarpp/yarpp.php', + 'Polylang' => $baseDir . '/include/class-polylang.php', +); diff --git a/wp-content/plugins/polylang/vendor/composer/autoload_namespaces.php b/wp-content/plugins/polylang/vendor/composer/autoload_namespaces.php new file mode 100644 index 00000000..b7fc0125 --- /dev/null +++ b/wp-content/plugins/polylang/vendor/composer/autoload_namespaces.php @@ -0,0 +1,9 @@ += 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); + if ($useStaticLoader) { + require_once __DIR__ . '/autoload_static.php'; + + call_user_func(\Composer\Autoload\ComposerStaticInit57e007bdf76a1fe336cb43b59389545b::getInitializer($loader)); + } else { + $map = require __DIR__ . '/autoload_namespaces.php'; + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + } + + $loader->register(true); + + return $loader; + } +} diff --git a/wp-content/plugins/polylang/vendor/composer/autoload_static.php b/wp-content/plugins/polylang/vendor/composer/autoload_static.php new file mode 100644 index 00000000..1ecddcd5 --- /dev/null +++ b/wp-content/plugins/polylang/vendor/composer/autoload_static.php @@ -0,0 +1,140 @@ + __DIR__ . '/../..' . '/integrations/wp-offload-media/as3cf.php', + 'PLL_Abstract_Sitemaps' => __DIR__ . '/../..' . '/modules/sitemaps/abstract-sitemaps.php', + 'PLL_Accept_Language' => __DIR__ . '/../..' . '/frontend/accept-language.php', + 'PLL_Accept_Languages_Collection' => __DIR__ . '/../..' . '/frontend/accept-languages-collection.php', + 'PLL_Admin' => __DIR__ . '/../..' . '/admin/admin.php', + 'PLL_Admin_Base' => __DIR__ . '/../..' . '/admin/admin-base.php', + 'PLL_Admin_Block_Editor' => __DIR__ . '/../..' . '/admin/admin-block-editor.php', + 'PLL_Admin_Classic_Editor' => __DIR__ . '/../..' . '/admin/admin-classic-editor.php', + 'PLL_Admin_Default_Term' => __DIR__ . '/../..' . '/admin/admin-default-term.php', + 'PLL_Admin_Filters' => __DIR__ . '/../..' . '/admin/admin-filters.php', + 'PLL_Admin_Filters_Columns' => __DIR__ . '/../..' . '/admin/admin-filters-columns.php', + 'PLL_Admin_Filters_Media' => __DIR__ . '/../..' . '/admin/admin-filters-media.php', + 'PLL_Admin_Filters_Post' => __DIR__ . '/../..' . '/admin/admin-filters-post.php', + 'PLL_Admin_Filters_Post_Base' => __DIR__ . '/../..' . '/admin/admin-filters-post-base.php', + 'PLL_Admin_Filters_Term' => __DIR__ . '/../..' . '/admin/admin-filters-term.php', + 'PLL_Admin_Filters_Widgets_Options' => __DIR__ . '/../..' . '/admin/admin-filters-widgets-options.php', + 'PLL_Admin_Links' => __DIR__ . '/../..' . '/admin/admin-links.php', + 'PLL_Admin_Model' => __DIR__ . '/../..' . '/admin/admin-model.php', + 'PLL_Admin_Nav_Menu' => __DIR__ . '/../..' . '/admin/admin-nav-menu.php', + 'PLL_Admin_Notices' => __DIR__ . '/../..' . '/admin/admin-notices.php', + 'PLL_Admin_Site_Health' => __DIR__ . '/../..' . '/modules/site-health/admin-site-health.php', + 'PLL_Admin_Static_Pages' => __DIR__ . '/../..' . '/admin/admin-static-pages.php', + 'PLL_Admin_Strings' => __DIR__ . '/../..' . '/admin/admin-strings.php', + 'PLL_Admin_Sync' => __DIR__ . '/../..' . '/modules/sync/admin-sync.php', + 'PLL_Aqua_Resizer' => __DIR__ . '/../..' . '/integrations/aqua-resizer/aqua-resizer.php', + 'PLL_Base' => __DIR__ . '/../..' . '/include/base.php', + 'PLL_Block_Editor_Filter_Preload_Paths' => __DIR__ . '/../..' . '/admin/block-editor-filter-preload-paths.php', + 'PLL_CRUD_Posts' => __DIR__ . '/../..' . '/include/crud-posts.php', + 'PLL_CRUD_Terms' => __DIR__ . '/../..' . '/include/crud-terms.php', + 'PLL_Cache' => __DIR__ . '/../..' . '/include/cache.php', + 'PLL_Cache_Compat' => __DIR__ . '/../..' . '/integrations/cache/cache-compat.php', + 'PLL_Cft' => __DIR__ . '/../..' . '/integrations/custom-field-template/cft.php', + 'PLL_Choose_Lang' => __DIR__ . '/../..' . '/frontend/choose-lang.php', + 'PLL_Choose_Lang_Content' => __DIR__ . '/../..' . '/frontend/choose-lang-content.php', + 'PLL_Choose_Lang_Domain' => __DIR__ . '/../..' . '/frontend/choose-lang-domain.php', + 'PLL_Choose_Lang_Url' => __DIR__ . '/../..' . '/frontend/choose-lang-url.php', + 'PLL_Cookie' => __DIR__ . '/../..' . '/include/cookie.php', + 'PLL_Domain_Mapping' => __DIR__ . '/../..' . '/integrations/domain-mapping/domain-mapping.php', + 'PLL_Duplicate_Post' => __DIR__ . '/../..' . '/integrations/duplicate-post/duplicate-post.php', + 'PLL_Featured_Content' => __DIR__ . '/../..' . '/integrations/jetpack/featured-content.php', + 'PLL_Filters' => __DIR__ . '/../..' . '/include/filters.php', + 'PLL_Filters_Links' => __DIR__ . '/../..' . '/include/filters-links.php', + 'PLL_Filters_Sanitization' => __DIR__ . '/../..' . '/include/filters-sanitization.php', + 'PLL_Filters_Widgets_Options' => __DIR__ . '/../..' . '/include/filters-widgets-options.php', + 'PLL_Frontend' => __DIR__ . '/../..' . '/frontend/frontend.php', + 'PLL_Frontend_Auto_Translate' => __DIR__ . '/../..' . '/frontend/frontend-auto-translate.php', + 'PLL_Frontend_Filters' => __DIR__ . '/../..' . '/frontend/frontend-filters.php', + 'PLL_Frontend_Filters_Links' => __DIR__ . '/../..' . '/frontend/frontend-filters-links.php', + 'PLL_Frontend_Filters_Search' => __DIR__ . '/../..' . '/frontend/frontend-filters-search.php', + 'PLL_Frontend_Filters_Widgets' => __DIR__ . '/../..' . '/frontend/frontend-filters-widgets.php', + 'PLL_Frontend_Links' => __DIR__ . '/../..' . '/frontend/frontend-links.php', + 'PLL_Frontend_Nav_Menu' => __DIR__ . '/../..' . '/frontend/frontend-nav-menu.php', + 'PLL_Frontend_Static_Pages' => __DIR__ . '/../..' . '/frontend/frontend-static-pages.php', + 'PLL_Install' => __DIR__ . '/../..' . '/install/install.php', + 'PLL_Install_Base' => __DIR__ . '/../..' . '/install/install-base.php', + 'PLL_Integrations' => __DIR__ . '/../..' . '/integrations/integrations.php', + 'PLL_Jetpack' => __DIR__ . '/../..' . '/integrations/jetpack/jetpack.php', + 'PLL_Language' => __DIR__ . '/../..' . '/include/language.php', + 'PLL_License' => __DIR__ . '/../..' . '/include/license.php', + 'PLL_Lingotek' => __DIR__ . '/../..' . '/modules/lingotek/lingotek.php', + 'PLL_Links' => __DIR__ . '/../..' . '/include/links.php', + 'PLL_Links_Abstract_Domain' => __DIR__ . '/../..' . '/include/links-abstract-domain.php', + 'PLL_Links_Default' => __DIR__ . '/../..' . '/include/links-default.php', + 'PLL_Links_Directory' => __DIR__ . '/../..' . '/include/links-directory.php', + 'PLL_Links_Domain' => __DIR__ . '/../..' . '/include/links-domain.php', + 'PLL_Links_Model' => __DIR__ . '/../..' . '/include/links-model.php', + 'PLL_Links_Permalinks' => __DIR__ . '/../..' . '/include/links-permalinks.php', + 'PLL_Links_Subdomain' => __DIR__ . '/../..' . '/include/links-subdomain.php', + 'PLL_MO' => __DIR__ . '/../..' . '/include/mo.php', + 'PLL_Model' => __DIR__ . '/../..' . '/include/model.php', + 'PLL_Multilingual_Sitemaps_Provider' => __DIR__ . '/../..' . '/modules/sitemaps/multilingual-sitemaps-provider.php', + 'PLL_Nav_Menu' => __DIR__ . '/../..' . '/include/nav-menu.php', + 'PLL_No_Category_Base' => __DIR__ . '/../..' . '/integrations/no-category-base/no-category-base.php', + 'PLL_OLT_Manager' => __DIR__ . '/../..' . '/include/olt-manager.php', + 'PLL_Plugin_Updater' => __DIR__ . '/../..' . '/install/plugin-updater.php', + 'PLL_Query' => __DIR__ . '/../..' . '/include/query.php', + 'PLL_REST_Request' => __DIR__ . '/../..' . '/include/rest-request.php', + 'PLL_Settings' => __DIR__ . '/../..' . '/settings/settings.php', + 'PLL_Settings_Browser' => __DIR__ . '/../..' . '/settings/settings-browser.php', + 'PLL_Settings_CPT' => __DIR__ . '/../..' . '/settings/settings-cpt.php', + 'PLL_Settings_Licenses' => __DIR__ . '/../..' . '/settings/settings-licenses.php', + 'PLL_Settings_Media' => __DIR__ . '/../..' . '/settings/settings-media.php', + 'PLL_Settings_Module' => __DIR__ . '/../..' . '/settings/settings-module.php', + 'PLL_Settings_Preview_Share_Slug' => __DIR__ . '/../..' . '/modules/share-slug/settings-preview-share-slug.php', + 'PLL_Settings_Preview_Translate_Slugs' => __DIR__ . '/../..' . '/modules/translate-slugs/settings-preview-translate-slugs.php', + 'PLL_Settings_Sync' => __DIR__ . '/../..' . '/modules/sync/settings-sync.php', + 'PLL_Settings_Url' => __DIR__ . '/../..' . '/settings/settings-url.php', + 'PLL_Sitemaps' => __DIR__ . '/../..' . '/modules/sitemaps/sitemaps.php', + 'PLL_Sitemaps_Domain' => __DIR__ . '/../..' . '/modules/sitemaps/sitemaps-domain.php', + 'PLL_Static_Pages' => __DIR__ . '/../..' . '/include/static-pages.php', + 'PLL_Switcher' => __DIR__ . '/../..' . '/include/switcher.php', + 'PLL_Sync' => __DIR__ . '/../..' . '/modules/sync/sync.php', + 'PLL_Sync_Metas' => __DIR__ . '/../..' . '/modules/sync/sync-metas.php', + 'PLL_Sync_Post_Metas' => __DIR__ . '/../..' . '/modules/sync/sync-post-metas.php', + 'PLL_Sync_Tax' => __DIR__ . '/../..' . '/modules/sync/sync-tax.php', + 'PLL_Sync_Term_Metas' => __DIR__ . '/../..' . '/modules/sync/sync-term-metas.php', + 'PLL_T15S' => __DIR__ . '/../..' . '/install/t15s.php', + 'PLL_Table_Languages' => __DIR__ . '/../..' . '/settings/table-languages.php', + 'PLL_Table_Settings' => __DIR__ . '/../..' . '/settings/table-settings.php', + 'PLL_Table_String' => __DIR__ . '/../..' . '/settings/table-string.php', + 'PLL_Translate_Option' => __DIR__ . '/../..' . '/include/translate-option.php', + 'PLL_Translated_Object' => __DIR__ . '/../..' . '/include/translated-object.php', + 'PLL_Translated_Post' => __DIR__ . '/../..' . '/include/translated-post.php', + 'PLL_Translated_Term' => __DIR__ . '/../..' . '/include/translated-term.php', + 'PLL_Twenty_Seventeen' => __DIR__ . '/../..' . '/integrations/twenty-seventeen/twenty-seven-teen.php', + 'PLL_Upgrade' => __DIR__ . '/../..' . '/install/upgrade.php', + 'PLL_WPML_API' => __DIR__ . '/../..' . '/modules/wpml/wpml-api.php', + 'PLL_WPML_Compat' => __DIR__ . '/../..' . '/modules/wpml/wpml-compat.php', + 'PLL_WPML_Config' => __DIR__ . '/../..' . '/modules/wpml/wpml-config.php', + 'PLL_WPSEO' => __DIR__ . '/../..' . '/integrations/wpseo/wpseo.php', + 'PLL_WPSEO_OGP' => __DIR__ . '/../..' . '/integrations/wpseo/wpseo-ogp.php', + 'PLL_WP_Import' => __DIR__ . '/../..' . '/integrations/wp-importer/wp-import.php', + 'PLL_WP_Sweep' => __DIR__ . '/../..' . '/integrations/wp-sweep/wp-sweep.php', + 'PLL_Walker_Dropdown' => __DIR__ . '/../..' . '/include/walker-dropdown.php', + 'PLL_Walker_List' => __DIR__ . '/../..' . '/include/walker-list.php', + 'PLL_Widget_Calendar' => __DIR__ . '/../..' . '/include/widget-calendar.php', + 'PLL_Widget_Languages' => __DIR__ . '/../..' . '/include/widget-languages.php', + 'PLL_Wizard' => __DIR__ . '/../..' . '/modules/wizard/wizard.php', + 'PLL_WordPress_Importer' => __DIR__ . '/../..' . '/integrations/wp-importer/wordpress-importer.php', + 'PLL_Yarpp' => __DIR__ . '/../..' . '/integrations/yarpp/yarpp.php', + 'Polylang' => __DIR__ . '/../..' . '/include/class-polylang.php', + ); + + public static function getInitializer(ClassLoader $loader) + { + return \Closure::bind(function () use ($loader) { + $loader->classMap = ComposerStaticInit57e007bdf76a1fe336cb43b59389545b::$classMap; + + }, null, ClassLoader::class); + } +} diff --git a/wp-content/plugins/polylang/vendor/composer/installed.json b/wp-content/plugins/polylang/vendor/composer/installed.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/wp-content/plugins/polylang/vendor/composer/installed.json @@ -0,0 +1 @@ +[]
    %s
    '; - echo $this->column_cb( $item ); + echo $this->column_cb( $item ); // phpcs:ignore WordPress.Security.EscapeOutput echo '', esc_attr( $classes ) ); - echo $this->column_default( $item, $column_name ); + echo $this->column_default( $item, $column_name ); // phpcs:ignore WordPress.Security.EscapeOutput echo '