diff --git a/wp-content/plugins/bogo/admin/admin.php b/wp-content/plugins/bogo/admin/admin.php index ece098eb274f1e565547148ea71c120d5d595df2..f10b134cc03ce06105de9e4c8736e3d8fc88840f 100644 --- a/wp-content/plugins/bogo/admin/admin.php +++ b/wp-content/plugins/bogo/admin/admin.php @@ -7,7 +7,7 @@ require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php'; require_once BOGO_PLUGIN_DIR . '/admin/includes/language-packs.php'; require_once BOGO_PLUGIN_DIR . '/admin/includes/terms-translation.php'; -add_action( 'admin_init', 'bogo_upgrade' ); +add_action( 'admin_init', 'bogo_upgrade', 10, 0 ); function bogo_upgrade() { $old_ver = bogo_get_prop( 'version' ); @@ -20,81 +20,140 @@ function bogo_upgrade() { } } -add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' ); +add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts', 10, 1 ); function bogo_admin_enqueue_scripts( $hook_suffix ) { wp_enqueue_style( 'bogo-admin', plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ), - array(), BOGO_VERSION, 'all' ); + array(), BOGO_VERSION, 'all' + ); if ( is_rtl() ) { wp_enqueue_style( 'bogo-admin-rtl', plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ), - array(), BOGO_VERSION, 'all' ); + array(), BOGO_VERSION, 'all' + ); } wp_enqueue_script( 'bogo-admin', plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ), - array( 'jquery' ), BOGO_VERSION, true ); + array( 'jquery' ), BOGO_VERSION, true + ); + + $available_languages = bogo_available_languages( array( + 'orderby' => 'value', + ) ); + + $add_translation_l10n = array(); + + foreach ( $available_languages as $locale => $lang ) { + $add_translation_l10n[$locale] = sprintf( + /* translators: %s: language name */ + __( 'Add %s Translation', 'bogo' ), + $lang + ); + } $local_args = array( - 'saveAlert' => __( - "The changes you made will be lost if you navigate away from this page.", - 'bogo' ), + 'l10n' => array( + /* translators: accessibility text */ + 'targetBlank' => __( '(opens in a new window)', 'bogo' ), + 'language' => __( 'Language', 'bogo' ), + 'none' => __( 'None', 'bogo' ), + 'translations' => __( 'Translations', 'bogo' ), + 'addTranslation' => $add_translation_l10n, + 'noticePostCreation' => __( "Translation post created.", 'bogo' ), + 'editPost' => __( 'Edit Post', 'bogo' ), + 'saveAlert' => __( "The changes you made will be lost if you navigate away from this page.", 'bogo' ), + ), 'apiSettings' => array( 'root' => esc_url_raw( rest_url( 'bogo/v1' ) ), 'namespace' => 'bogo/v1', 'nonce' => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ), ), - 'screenReaderText' => array( - /* translators: accessibility text */ - 'targetBlank' => __( '(opens in a new window)', 'bogo' ), - ), - 'availableLanguages' => bogo_available_languages( array( - 'exclude_enus_if_inactive' => true, - 'orderby' => 'value', - ) ), + 'availableLanguages' => $available_languages, 'defaultLocale' => bogo_get_default_locale(), 'pagenow' => isset( $_GET['page'] ) ? trim( $_GET['page'] ) : '', + 'currentPost' => array(), + 'localizablePostTypes' => bogo_localizable_post_types(), ); - if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) { - $post = $GLOBALS['post']; - $local_args = array_merge( $local_args, array( - 'post_id' => $post->ID, - ) ); + if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) { + $user_locale = bogo_get_user_locale(); + + $current_post = array( + 'locale' => $user_locale, + 'lang' => bogo_lang_slug( $user_locale ), + 'translations' => array(), + ); + + if ( $post = get_post() ) { + $current_post['postId'] = $post->ID; + $post_type_object = get_post_type_object( $post->post_type ); + $edit_post_cap = $post_type_object->cap->edit_post; + + if ( $locale = get_post_meta( $post->ID, '_locale', true ) ) { + $current_post['locale'] = $locale; + $current_post['lang'] = bogo_lang_slug( $locale ); + } + + $available_locales = bogo_available_locales( array( + 'exclude' => array( $current_post['locale'] ), + ) ); + + foreach ( $available_locales as $locale ) { + $current_post['translations'][$locale] = array(); + + $translation = bogo_get_post_translation( $post->ID, $locale ); + + if ( $translation ) { + $current_post['translations'][$locale] = array( + 'postId' => $translation->ID, + 'postTitle' => $translation->post_title, + 'editLink' => current_user_can( $edit_post_cap, $translation->ID ) + ? get_edit_post_link( $translation, 'raw' ) + : '', + ); + } + } + } + + $local_args['currentPost'] = $current_post; } wp_localize_script( 'bogo-admin', 'bogo', $local_args ); } -add_action( 'admin_menu', 'bogo_admin_menu' ); +add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 ); function bogo_admin_menu() { add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ), 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page', - 'dashicons-translation', 73 ); // between Users (70) and Tools (75) + 'dashicons-translation', 73 // between Users (70) and Tools (75) + ); $tools = add_submenu_page( 'bogo', __( 'Language Packs', 'bogo' ), __( 'Language Packs', 'bogo' ), - 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' ); + 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' + ); - add_action( 'load-' . $tools, 'bogo_load_tools_page' ); + add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 ); $available_locales = bogo_available_locales( array( - 'exclude_enus_if_inactive' => true, 'current_user_can_access' => true, + 'exclude' => array( bogo_get_default_locale() ), ) ); - if ( 1 < count( $available_locales ) ) { + if ( 0 < count( $available_locales ) ) { $texts = add_submenu_page( 'bogo', __( 'Terms Translation', 'bogo' ), __( 'Terms Translation', 'bogo' ), - 'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' ); + 'bogo_edit_terms_translation', 'bogo-texts', 'bogo_texts_page' + ); - add_action( 'load-' . $texts, 'bogo_load_texts_page' ); + add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 ); } } @@ -130,16 +189,19 @@ function bogo_load_tools_page() { $redirect_to = add_query_arg( array( 'message' => 'enus_activated' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } else { if ( wp_download_language_pack( $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'install_success' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'install_failed' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } } @@ -159,16 +221,19 @@ function bogo_load_tools_page() { $redirect_to = add_query_arg( array( 'message' => 'enus_deactivated' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } else { if ( bogo_delete_language_pack( $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'delete_success' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'delete_failed' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } } @@ -183,18 +248,21 @@ function bogo_load_tools_page() { wp_die( __( "You are not allowed to manage translations.", 'bogo' ) ); } - if ( 'en_US' == $locale || ! bogo_is_available_locale( $locale ) ) { + if ( 'en_US' == $locale + or ! bogo_is_available_locale( $locale ) ) { $locale = ''; } if ( update_option( 'WPLANG', $locale ) ) { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'promote_success' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } else { $redirect_to = add_query_arg( array( 'locale' => $locale, 'message' => 'promote_failed' ), - menu_page_url( 'bogo', false ) ); + menu_page_url( 'bogo', false ) + ); } wp_safe_redirect( $redirect_to ); @@ -212,7 +280,8 @@ function bogo_load_tools_page() { ? ! bogo_is_enus_deactivated() : bogo_is_available_locale( $locale ); - if ( ! bogo_is_default_locale( $locale ) && $is_active ) { + if ( ! bogo_is_default_locale( $locale ) + and $is_active ) { $redirect_to = add_query_arg( array( 'locale' => $locale ), menu_page_url( 'bogo-texts', false ) ); @@ -225,7 +294,9 @@ function bogo_load_tools_page() { $current_screen = get_current_screen(); add_filter( 'manage_' . $current_screen->id . '_columns', - array( 'Bogo_Language_Packs_List_Table', 'define_columns' ) ); + array( 'Bogo_Language_Packs_List_Table', 'define_columns' ), + 10, 1 + ); } function bogo_tools_page() { @@ -244,6 +315,7 @@ function bogo_tools_page() { echo sprintf( '<span class="subtitle">%s</span>', sprintf( + /* translators: %s: search query */ __( 'Search results for “%s”', 'bogo' ), esc_html( $_REQUEST['s'] ) ) @@ -273,32 +345,38 @@ function bogo_load_texts_page() { if ( 'save' == $action ) { check_admin_referer( 'bogo-edit-text-translation' ); - $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null; - if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) { wp_die( __( "You are not allowed to edit translations.", 'bogo' ) ); } + $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null; + + if ( ! bogo_is_available_locale( $locale ) ) { + return; + } + + if ( ! current_user_can( 'bogo_access_locale', $locale ) ) { + wp_die( __( "You are not allowed to edit terms in this locale.", 'bogo' ) ); + } + $entries = array(); foreach ( (array) bogo_terms_translation( $locale ) as $item ) { - $entries[] = array( - 'singular' => $item['name'], - 'translations' => array( $item['translated'] ), - 'context' => preg_replace( '/:.*$/', '', $item['name'] ), - ); - } + $translation = $item['translated']; - foreach ( $_POST as $p_key => $p_val ) { - if ( in_array( $p_key, array( 'action', 'locale', 'submit', 'paged' ) ) - || substr( $p_key, 0, 1 ) == '_' ) { - continue; + $cap = isset( $item['cap'] ) + ? $item['cap'] + : 'bogo_edit_terms_translation'; + + if ( isset( $_POST[$item['name']] ) + and current_user_can( $cap ) ) { + $translation = $_POST[$item['name']]; } $entries[] = array( - 'singular' => $p_key, - 'translations' => array( $p_val ), - 'context' => preg_replace( '/:.*$/', '', $p_key ), + 'singular' => $item['name'], + 'translations' => array( $translation ), + 'context' => preg_replace( '/:.*$/', '', $item['name'] ), ); } @@ -324,7 +402,9 @@ function bogo_load_texts_page() { $current_screen = get_current_screen(); add_filter( 'manage_' . $current_screen->id . '_columns', - array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ) ); + array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ), + 10, 1 + ); add_screen_option( 'per_page', array( 'label' => __( 'Items', 'bogo' ), @@ -349,6 +429,7 @@ function bogo_texts_page() { echo sprintf( '<span class="subtitle">%s</span>', sprintf( + /* translators: %s: search query */ __( 'Search results for “%s”', 'bogo' ), esc_html( $_REQUEST['s'] ) ) @@ -361,8 +442,8 @@ function bogo_texts_page() { <?php bogo_admin_notice(); ?> <form action="" method="get"> -<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> -<input type="hidden" name="locale" value="<?php echo esc_attr( $_REQUEST['locale'] ); ?>" /> +<input type="hidden" name="page" value="<?php echo isset( $_REQUEST['page'] ) ? esc_attr( $_REQUEST['page'] ) : ''; ?>" /> +<input type="hidden" name="locale" value="<?php echo isset( $_REQUEST['locale'] ) ? esc_attr( $_REQUEST['locale'] ) : ''; ?>" /> <?php $list_table->search_box( __( 'Search Translation', 'bogo' ), 'bogo-terms-translation' @@ -372,7 +453,7 @@ function bogo_texts_page() { <form action="" method="post" id="bogo-terms-translation"> <input type="hidden" name="action" value="save" /> -<input type="hidden" name="paged" value="<?php echo absint( $_GET['paged'] ); ?>" /> +<input type="hidden" name="paged" value="<?php echo isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; ?>" /> <?php wp_nonce_field( 'bogo-edit-text-translation' ); $list_table->display(); @@ -383,7 +464,7 @@ function bogo_texts_page() { } function bogo_admin_notice( $reason = '' ) { - if ( empty( $reason ) && isset( $_GET['message'] ) ) { + if ( empty( $reason ) and isset( $_GET['message'] ) ) { $reason = $_GET['message']; } @@ -414,10 +495,12 @@ function bogo_admin_notice( $reason = '' ) { if ( '_failed' == substr( $reason, -7 ) ) { echo sprintf( '<div class="error notice notice-error is-dismissible"><p>%s</p></div>', - esc_html( $message ) ); + esc_html( $message ) + ); } else { echo sprintf( '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>', - esc_html( $message ) ); + esc_html( $message ) + ); } } diff --git a/wp-content/plugins/bogo/admin/includes/js/admin.js b/wp-content/plugins/bogo/admin/includes/js/admin.js index 4a07ce9e6da718b694c07f5a1d6e446ce8390693..5e8b121b0d2e799aa734401651027e5f33621b17 100644 --- a/wp-content/plugins/bogo/admin/includes/js/admin.js +++ b/wp-content/plugins/bogo/admin/includes/js/admin.js @@ -21,13 +21,13 @@ $( function() { $( '#bogo-add-translation' ).click( function() { - if ( ! bogo.post_id ) { + if ( ! bogo.currentPost.postId ) { return; } var locale = $( '#bogo-translations-to-add' ).val(); var rest_url = bogo.apiSettings.getRoute( - '/posts/' + bogo.post_id + '/translations/' + locale ); + '/posts/' + bogo.currentPost.postId + '/translations/' + locale ); $( '#bogo-add-translation' ).next( '.spinner' ) .css( 'visibility', 'visible' ); @@ -51,12 +51,12 @@ } ).html( function() { var output = post.title.rendered; output += ' <span class="screen-reader-text">' - + bogo.screenReaderText.targetBlank + '</span>'; + + bogo.l10n.targetBlank + '</span>'; return output; } ); $added = $( '<li></li>' ).append( $added ).append( - ' [' + post.lang.name + ']' ); + ' [' + bogo.availableLanguages[ locale ] + ']' ); $( '#bogo-translations' ).append( $added ); $( '#bogo-translations-to-add option[value="' + locale + '"]' ).detach(); @@ -82,8 +82,8 @@ } ); if ( changed ) { - event.returnValue = bogo.saveAlert; - return bogo.saveAlert; + event.returnValue = bogo.l10n.saveAlert; + return bogo.l10n.saveAlert; } } ); diff --git a/wp-content/plugins/bogo/admin/includes/language-packs.php b/wp-content/plugins/bogo/admin/includes/language-packs.php index 2a2fbf0bf17d12e019007ec935ed1c75cfa783c7..671c705542de9530fb46652f04d4265229a6c1d6 100644 --- a/wp-content/plugins/bogo/admin/includes/language-packs.php +++ b/wp-content/plugins/bogo/admin/includes/language-packs.php @@ -35,7 +35,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { $locales = array_unique( array_merge( array( bogo_get_default_locale() ), - bogo_available_locales( 'exclude_enus_if_inactive=1' ), + bogo_available_locales(), array( 'en_US' ), array_keys( wp_get_available_translations() ) ) ); @@ -69,8 +69,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { } } - if ( 'active' == $status && ! $is_active - || 'inactive' == $status && $is_active ) { + if ( 'active' == $status and ! $is_active + or 'inactive' == $status and $is_active ) { continue; } @@ -99,6 +99,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { $count_all = $this->count_active + $this->count_inactive; $all = sprintf( + /* translators: %s: number of language packs */ _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', @@ -115,6 +116,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { // Active $active = sprintf( + /* translators: %s: number of language packs */ _nx( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', @@ -131,6 +133,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { // Inactive $inactive = sprintf( + /* translators: %s: number of language packs */ _nx( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', @@ -188,6 +191,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { if ( $count_posts ) { $count_posts = sprintf( + /* translators: %s: number of posts */ _n( '%s Post', '%s Posts', $count_posts, 'bogo' ), number_format_i18n( $count_posts ) ); @@ -195,6 +199,7 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { if ( $count_pages ) { $count_pages = sprintf( + /* translators: %s: number of pages */ _n( '%s Page', '%s Pages', $count_pages, 'bogo' ), number_format_i18n( $count_pages ) ); @@ -245,7 +250,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { $actions = array(); - if ( 'en_US' == $item->locale || $this->can_install_language_pack() ) { + if ( 'en_US' == $item->locale + or $this->can_install_language_pack() ) { if ( bogo_is_default_locale( $item->locale ) ) { // nothing } elseif ( $item->active ) { @@ -260,7 +266,8 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { } } - if ( $item->active && ! bogo_is_default_locale( $item->locale ) ) { + if ( $item->active + and ! bogo_is_default_locale( $item->locale ) ) { $actions['translate'] = $this->action_link( $item, 'translate' ); } @@ -374,12 +381,13 @@ class Bogo_Language_Packs_List_Table extends WP_List_Table { function bogo_delete_language_pack( $locale ) { if ( 'en_US' == $locale - || ! bogo_is_available_locale( $locale ) - || bogo_is_default_locale( $locale ) ) { + or ! bogo_is_available_locale( $locale ) + or bogo_is_default_locale( $locale ) ) { return false; } - if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) { + if ( ! is_dir( WP_LANG_DIR ) + or ! $files = scandir( WP_LANG_DIR ) ) { return false; } @@ -395,7 +403,8 @@ function bogo_delete_language_pack( $locale ) { ); foreach ( $files as $file ) { - if ( '.' === $file[0] || is_dir( $file ) ) { + if ( '.' === $file[0] + or is_dir( $file ) ) { continue; } diff --git a/wp-content/plugins/bogo/admin/includes/nav-menu.php b/wp-content/plugins/bogo/admin/includes/nav-menu.php index 5c0190c796a31469b4d9286c32caaef0ae7aad38..884dd4bc4fcdd456e2507562de0e1b93924f785a 100644 --- a/wp-content/plugins/bogo/admin/includes/nav-menu.php +++ b/wp-content/plugins/bogo/admin/includes/nav-menu.php @@ -12,14 +12,14 @@ class Bogo_Walker_Nav_Menu_Edit extends Walker_Nav_Menu_Edit { $parallel_output = preg_replace( '/<div class="menu-item-settings wp-clearfix" id="menu-item-settings-([0-9]+)">/', '<div class="menu-item-settings wp-clearfix has-bogo-settings" id="menu-item-settings-${1}">' . $this->language_settings( $item ), - $parallel_output, 1 ); + $parallel_output, 1 + ); $output .= $parallel_output; } private function language_settings( $menu_item ) { $available_languages = bogo_available_languages( array( - 'exclude_enus_if_inactive' => true, 'orderby' => 'value', ) ); @@ -101,12 +101,12 @@ function bogo_update_nav_menu_item( $menu_id, $menu_item_id ) { foreach ( (array) bogo_available_locales() as $locale ) { if ( in_array( $locale, $current_locales ) - && ! in_array( $locale, $requested_locales ) ) { + and ! in_array( $locale, $requested_locales ) ) { delete_post_meta( $menu_item_id, '_locale', $locale ); } if ( ! in_array( $locale, $current_locales ) - && in_array( $locale, $requested_locales ) ) { + and in_array( $locale, $requested_locales ) ) { add_post_meta( $menu_item_id, '_locale', $locale ); } } diff --git a/wp-content/plugins/bogo/admin/includes/post.php b/wp-content/plugins/bogo/admin/includes/post.php index ba8391b3d91eb1376d20b62080bcc01ee64dc0c6..0ebb28fa70f9ae191f3e82e470e5af4b7e877270 100644 --- a/wp-content/plugins/bogo/admin/includes/post.php +++ b/wp-content/plugins/bogo/admin/includes/post.php @@ -2,7 +2,7 @@ /* Posts List Table */ -add_filter( 'manage_pages_columns', 'bogo_pages_columns' ); +add_filter( 'manage_pages_columns', 'bogo_pages_columns', 10, 1 ); function bogo_pages_columns( $posts_columns ) { return bogo_posts_columns( $posts_columns, 'page' ); @@ -19,16 +19,20 @@ function bogo_posts_columns( $posts_columns, $post_type ) { $posts_columns = array_merge( array_slice( $posts_columns, 0, 3 ), array( 'locale' => __( 'Locale', 'bogo' ) ), - array_slice( $posts_columns, 3 ) ); + array_slice( $posts_columns, 3 ) + ); } return $posts_columns; } add_action( 'manage_pages_custom_column', - 'bogo_manage_posts_custom_column', 10, 2 ); + 'bogo_manage_posts_custom_column', 10, 2 +); + add_action( 'manage_posts_custom_column', - 'bogo_manage_posts_custom_column', 10, 2 ); + 'bogo_manage_posts_custom_column', 10, 2 +); function bogo_manage_posts_custom_column( $column_name, $post_id ) { if ( 'locale' != $column_name ) { @@ -54,17 +58,19 @@ function bogo_manage_posts_custom_column( $column_name, $post_id ) { } echo sprintf( '<a href="%1$s">%2$s</a>', - esc_url( add_query_arg( - array( 'post_type' => $post_type, 'lang' => $locale ), - 'edit.php' ) ), - esc_html( $language ) ); + esc_url( + add_query_arg( array( + 'post_type' => $post_type, + 'lang' => $locale, + ), 'edit.php' ) + ), + esc_html( $language ) + ); } -add_action( 'restrict_manage_posts', 'bogo_restrict_manage_posts' ); - -function bogo_restrict_manage_posts() { - global $post_type; +add_action( 'restrict_manage_posts', 'bogo_restrict_manage_posts', 10, 2 ); +function bogo_restrict_manage_posts( $post_type, $which ) { if ( ! bogo_is_localizable_post_type( $post_type ) ) { return; } @@ -93,14 +99,14 @@ add_filter( 'post_row_actions', 'bogo_post_row_actions', 10, 2 ); add_filter( 'page_row_actions', 'bogo_post_row_actions', 10, 2 ); function bogo_post_row_actions( $actions, $post ) { - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { + if ( ! bogo_is_localizable_post_type( $post->post_type ) + or 'trash' === $post->post_status ) { return $actions; } $post_type_object = get_post_type_object( $post->post_type ); - if ( ! current_user_can( $post_type_object->cap->edit_post, $post->ID ) - || 'trash' == $post->post_status ) { + if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) { return $actions; } @@ -112,7 +118,8 @@ function bogo_post_row_actions( $actions, $post ) { } if ( $translation = bogo_get_post_translation( $post, $user_locale ) ) { - if ( empty( $translation->ID ) || $translation->ID == $post->ID ) { + if ( empty( $translation->ID ) + or $translation->ID === $post->ID ) { return $actions; } @@ -123,7 +130,8 @@ function bogo_post_row_actions( $actions, $post ) { $edit_link = admin_url( 'post-new.php?post_type=' . $post->post_type . '&action=bogo-add-translation' . '&locale=' . $user_locale - . '&original_post=' . $post->ID ); + . '&original_post=' . $post->ID + ); $edit_link = wp_nonce_url( $edit_link, 'bogo-add-translation' ); } @@ -136,16 +144,17 @@ function bogo_post_row_actions( $actions, $post ) { $actions['translate'] = sprintf( '<a href="%1$s">%2$s</a>', $edit_link, - esc_html( sprintf( $text, $language ) ) ); + esc_html( sprintf( $text, $language ) ) + ); return $actions; } -add_action( 'admin_init', 'bogo_add_translation' ); +add_action( 'admin_init', 'bogo_add_translation', 10, 0 ); function bogo_add_translation() { if ( empty( $_REQUEST['action'] ) - || 'bogo-add-translation' != $_REQUEST['action'] ) { + or 'bogo-add-translation' != $_REQUEST['action'] ) { return; } @@ -159,14 +168,15 @@ function bogo_add_translation() { return; } - if ( ! $original_post || ! $original_post = get_post( $original_post ) ) { + if ( ! $original_post + or ! $original_post = get_post( $original_post ) ) { return; } $post_type_object = get_post_type_object( $original_post->post_type ); if ( $post_type_object - && current_user_can( $post_type_object->cap->edit_posts ) ) { + and current_user_can( $post_type_object->cap->edit_posts ) ) { $new_post_id = bogo_duplicate_post( $original_post, $locale ); if ( $new_post_id ) { @@ -191,257 +201,111 @@ function bogo_add_l10n_meta_boxes( $post_type, $post ) { } add_meta_box( 'bogol10ndiv', __( 'Language', 'bogo' ), - 'bogo_l10n_meta_box', null, 'side', 'high' ); + 'bogo_l10n_meta_box', null, 'side', 'high', + array( + '__back_compat_meta_box' => true, + ) + ); } function bogo_l10n_meta_box( $post ) { $initial = ( 'auto-draft' == $post->post_status ); if ( $initial ) { - $post_locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; - - if ( ! bogo_is_available_locale( $post_locale ) ) { - $post_locale = bogo_get_user_locale(); - } - - $original_post = empty( $_REQUEST['original_post'] ) - ? '' : $_REQUEST['original_post']; + $post_locale = bogo_get_user_locale(); } else { $post_locale = bogo_get_post_locale( $post->ID ); - $original_post = get_post_meta( $post->ID, '_original_post', true ); - - if ( empty( $original_post ) ) { - $original_post = $post->ID; - } } $translations = bogo_get_post_translations( $post->ID ); - $available_locales = bogo_available_locales( array( - 'exclude' => array_merge( - array( $post_locale ), - array_keys( (array) $translations ) ), - 'exclude_enus_if_inactive' => true, + $available_languages = bogo_available_languages( array( 'current_user_can_access' => true, ) ); ?> -<div class="hidden"> -<input type="hidden" name="locale" value="<?php echo esc_attr( $post_locale ); ?>" /> -<input type="hidden" name="original_post" value="<?php echo esc_attr( $original_post ); ?>" /> -</div> <div class="descriptions"> <?php - $lang = bogo_get_language( $post_locale ); - $lang = empty( $lang ) ? $post_locale : $lang; + if ( isset( $available_languages[$post_locale] ) ) { + $lang = $available_languages[$post_locale]; + } else { + $lang = $post_locale; + } + + unset( $available_languages[$post_locale] ); ?> -<p><strong><?php echo esc_html( __( 'Language', 'bogo' ) ); ?>:</strong> - <?php echo esc_html( $lang ); ?></p> +<p> + <strong><?php echo esc_html( __( 'Language', 'bogo' ) ); ?>:</strong> + <?php echo esc_html( $lang ); ?> +</p> </div> <?php - do { - if ( ! $translations && ( $initial || empty( $available_locales ) ) ) { - break; - } - - echo '<div class="descriptions">'; - echo sprintf( '<p><strong>%s:</strong></p>', - esc_html( __( 'Translations', 'bogo' ) ) ); - echo '<ul id="bogo-translations">'; - - if ( $translations ) { - foreach ( $translations as $locale => $translation ) { - $edit_link = get_edit_post_link( $translation->ID ); - echo '<li>'; - - if ( $edit_link ) { - echo sprintf( - '<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span></a>', - esc_url( $edit_link ), - get_the_title( $translation->ID ), - /* translators: accessibility text */ - esc_html( __( '(opens in a new window)', 'bogo' ) ) - ); - } else { - echo get_the_title( $translation->ID ); - } - - $lang = bogo_get_language( $locale ); - $lang = empty( $lang ) ? $locale : $lang; - echo ' [' . $lang . ']'; - echo '</li>'; - } - } - - echo '</ul>'; - echo '</div>'; - } while (0); - - do { - if ( $initial || empty( $available_locales ) ) { - break; - } - - echo '<div id="bogo-add-translation-actions" class="descriptions">'; - echo sprintf( '<p><strong>%s:</strong></p>', - esc_html( __( 'Add Translation', 'bogo' ) ) ); - echo '<select id="bogo-translations-to-add">'; - - foreach ( $available_locales as $locale ) { - $lang = bogo_get_language( $locale ); - $lang = empty( $lang ) ? $locale : $lang; - echo sprintf( '<option value="%1$s">%2$s</option>', - esc_attr( $locale ), esc_html( $lang ) ); - } - - echo '</select>'; - echo '<p>'; - echo sprintf( - '<button type="button" class="button" id="%1$s">%2$s</button>', - 'bogo-add-translation', - esc_html( __( 'Add Translation', 'bogo' ) ) ); - echo '<span class="spinner"></span>'; - echo '</p>'; - echo '<div class="clear"></div>'; - echo '</div>'; - } while (0); -} - -add_action( 'save_post', 'bogo_save_post', 10, 2 ); - -function bogo_save_post( $post_id, $post ) { - if ( did_action( 'import_start' ) && ! did_action( 'import_end' ) ) { - // Importing - return; - } - - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { - return; - } - - $current_locales = get_post_meta( $post_id, '_locale' ); - $locale = null; - - if ( ! empty( $current_locales ) ) { - foreach ( $current_locales as $current_locale ) { - if ( bogo_is_available_locale( $current_locale ) ) { - $locale = $current_locale; - break; - } - } + echo '<div class="descriptions">'; + echo sprintf( '<p><strong>%s:</strong></p>', + esc_html( __( 'Translations', 'bogo' ) ) + ); - if ( empty( $locale ) || 1 < count( $current_locales ) ) { - delete_post_meta( $post_id, '_locale' ); - $current_locales = array(); - } - } + echo '<ul id="bogo-translations">'; - if ( empty( $current_locales ) ) { - if ( bogo_is_available_locale( $locale ) ) { - // $locale = $locale; - } elseif ( ! empty( $_REQUEST['locale'] ) - && bogo_is_available_locale( $_REQUEST['locale'] ) ) { - $locale = $_REQUEST['locale']; - } elseif ( 'auto-draft' == get_post_status( $post_id ) ) { - $locale = bogo_get_user_locale(); + foreach ( $translations as $locale => $translation ) { + $edit_link = get_edit_post_link( $translation->ID ); + echo '<li>'; + + if ( $edit_link ) { + echo sprintf( + '<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span></a>', + esc_url( $edit_link ), + get_the_title( $translation->ID ), + /* translators: accessibility text */ + esc_html( __( '(opens in a new window)', 'bogo' ) ) + ); } else { - $locale = bogo_get_default_locale(); + echo get_the_title( $translation->ID ); } - add_post_meta( $post_id, '_locale', $locale, true ); - } - - $current_original_posts = get_post_meta( $post_id, '_original_post' ); - - if ( ! empty( $current_original_posts ) ) { - if ( 1 < count( $current_original_posts ) ) { - delete_post_meta( $post_id, '_original_post' ); + if ( isset( $available_languages[$locale] ) ) { + $lang = $available_languages[$locale]; } else { - return; - } - } - - if ( ! empty( $_REQUEST['original_post'] ) ) { - $original = get_post_meta( $_REQUEST['original_post'], - '_original_post', true ); - - if ( empty( $original ) ) { - $original = (int) $_REQUEST['original_post']; + $lang = $locale; } - add_post_meta( $post_id, '_original_post', $original, true ); - return; + echo ' [' . $lang . ']'; + echo '</li>'; } - $original = $post_id; - - while ( 1 ) { - $q = new WP_Query(); - - $posts = $q->query( array( - 'bogo_suppress_locale_query' => true, - 'posts_per_page' => 1, - 'post_status' => 'any', - 'post_type' => $post->post_type, - 'meta_key' => '_original_post', - 'meta_value' => $original ) ); + echo '</ul>'; + echo '</div>'; - if ( empty( $posts ) ) { - add_post_meta( $post_id, '_original_post', $original, true ); - return; - } - - $original += 1; - } -} - -add_filter( 'wp_unique_post_slug', 'bogo_unique_post_slug', 10, 6 ); - -function bogo_unique_post_slug( $slug, $post_id, $status, $type, $parent, $original ) { - global $wp_rewrite; - - if ( ! bogo_is_localizable_post_type( $type ) ) { - return $slug; - } - - $feeds = is_array( $wp_rewrite->feeds ) ? $wp_rewrite->feeds : array(); - - if ( in_array( $original, $feeds ) ) { - return $slug; - } - - $locale = bogo_get_post_locale( $post_id ); - - if ( empty( $locale ) ) { - return $slug; + if ( $initial or empty( $available_languages ) ) { + return; } - $args = array( - 'posts_per_page' => 1, - 'post__not_in' => array( $post_id ), - 'post_type' => $type, - 'name' => $original, - 'lang' => $locale, + echo '<div id="bogo-add-translation-actions" class="descriptions">'; + echo sprintf( '<p><strong>%s:</strong></p>', + esc_html( __( 'Add Translation', 'bogo' ) ) ); + echo '<select id="bogo-translations-to-add">'; - $hierarchical = in_array( $type, - get_post_types( array( 'hierarchical' => true ) ) ); - - if ( $hierarchical ) { - if ( preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $original ) ) { - return $slug; + foreach ( $available_languages as $locale => $lang ) { + if ( isset( $translations[$locale] ) ) { + continue; } - $args['post_parent'] = $parent; + echo sprintf( '<option value="%1$s">%2$s</option>', + esc_attr( $locale ), esc_html( $lang ) + ); } - $q = new WP_Query(); - $posts = $q->query( $args ); - - if ( empty( $posts ) ) { - $slug = $original; - } - - return $slug; + echo '</select>'; + echo '<p>'; + echo sprintf( + '<button type="button" class="button" id="%1$s">%2$s</button>', + 'bogo-add-translation', + esc_html( __( 'Add Translation', 'bogo' ) ) + ); + echo '<span class="spinner"></span>'; + echo '</p>'; + echo '<div class="clear"></div>'; + echo '</div>'; } diff --git a/wp-content/plugins/bogo/admin/includes/terms-translation.php b/wp-content/plugins/bogo/admin/includes/terms-translation.php index 836e24f7daefa8211e7f63367019b028dec5a9bd..a28b1c03c145c4e78745126c31609268b3d04be7 100644 --- a/wp-content/plugins/bogo/admin/includes/terms-translation.php +++ b/wp-content/plugins/bogo/admin/includes/terms-translation.php @@ -26,6 +26,16 @@ class Bogo_Terms_Translation_List_Table extends WP_List_Table { $items = bogo_terms_translation( $this->locale_to_edit ); + foreach ( $items as $key => $item ) { + $cap = isset( $item['cap'] ) + ? $item['cap'] + : 'bogo_edit_terms_translation'; + + if ( ! current_user_can( $cap ) ) { + unset( $items[$key] ); + } + } + if ( ! empty( $_REQUEST['s'] ) ) { $keywords = preg_split( '/[\s]+/', $_REQUEST['s'] ); @@ -95,10 +105,10 @@ class Bogo_Terms_Translation_List_Table extends WP_List_Table { echo '<select name="locale" id="select-locale">'; echo sprintf( '<option value="">%1$s</option>', - esc_html( __( '-- Select Language to Edit --', 'bogo' ) ) ); + esc_html( __( '-- Select Language to Edit --', 'bogo' ) ) + ); $available_locales = bogo_available_locales( array( - 'exclude_enus_if_inactive' => true, 'current_user_can_access' => true, ) ); @@ -131,7 +141,8 @@ function bogo_terms_translation( $locale_to_edit ) { static $items = array(); static $locale = null; - if ( ! empty( $items ) && $locale === $locale_to_edit ) { + if ( ! empty( $items ) + and $locale === $locale_to_edit ) { return $items; } @@ -151,6 +162,7 @@ function bogo_terms_translation( $locale_to_edit ) { 'translated' => bogo_translate( 'blogname', 'blogname', get_option( 'blogname' ) ), 'context' => __( 'Site Title', 'bogo' ), + 'cap' => 'manage_options', ); $items[] = array( @@ -159,6 +171,7 @@ function bogo_terms_translation( $locale_to_edit ) { 'translated' => bogo_translate( 'blogdescription', 'blogdescription', get_option( 'blogdescription' ) ), 'context' => __( 'Tagline', 'bogo' ), + 'cap' => 'manage_options', ); remove_filter( 'get_term', 'bogo_get_term_filter' ); @@ -179,6 +192,7 @@ function bogo_terms_translation( $locale_to_edit ) { 'translated' => bogo_translate( $name, $taxonomy->name, $term->name ), 'context' => $tax_labels->name, + 'cap' => $taxonomy->cap->edit_terms, ); } } diff --git a/wp-content/plugins/bogo/admin/includes/upgrade.php b/wp-content/plugins/bogo/admin/includes/upgrade.php index 7a4e776cfca043995a8fe2d309996c9ec0d3b6da..3e143e23be1760d73b17b77129a14445ba24434d 100644 --- a/wp-content/plugins/bogo/admin/includes/upgrade.php +++ b/wp-content/plugins/bogo/admin/includes/upgrade.php @@ -1,3 +1,3 @@ <?php -add_action( 'bogo_upgrade', 'flush_rewrite_rules' ); +add_action( 'bogo_upgrade', 'flush_rewrite_rules', 10, 0 ); diff --git a/wp-content/plugins/bogo/admin/includes/user.php b/wp-content/plugins/bogo/admin/includes/user.php index 1a445dfff19188dad6374cd9bb856765c392e326..5a285425f5b8b3d0309cfc1cc3c3521bebf22a97 100644 --- a/wp-content/plugins/bogo/admin/includes/user.php +++ b/wp-content/plugins/bogo/admin/includes/user.php @@ -1,7 +1,7 @@ <?php -add_action( 'personal_options_update', 'bogo_update_user_option' ); -add_action( 'edit_user_profile_update', 'bogo_update_user_option' ); +add_action( 'personal_options_update', 'bogo_update_user_option', 10, 1 ); +add_action( 'edit_user_profile_update', 'bogo_update_user_option', 10, 1 ); function bogo_update_user_option( $user_id ) { global $wpdb; @@ -35,32 +35,24 @@ function bogo_update_user_option( $user_id ) { } } -add_action( 'personal_options', 'bogo_set_locale_options' ); +add_action( 'personal_options', 'bogo_set_locale_options', 10, 1 ); function bogo_set_locale_options( $profileuser ) { - if ( is_network_admin() ) { + if ( is_network_admin() or IS_PROFILE_PAGE ) { return; } - if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { - bogo_select_own_locale( $profileuser ); - } elseif ( ! user_can( $profileuser, 'bogo_access_all_locales' ) ) { + if ( ! user_can( $profileuser, 'bogo_access_all_locales' ) ) { bogo_set_accessible_locales( $profileuser ); } } function bogo_set_accessible_locales( $profileuser ) { $available_languages = bogo_available_languages( array( - 'exclude_enus_if_inactive' => true, 'orderby' => 'value', ) ); - $accessible_locales = bogo_get_user_accessible_locales( $profileuser->ID ); - if ( empty( $accessible_locales ) ) { - $accessible_locales = array_keys( $available_languages ); - } else { - $accessible_locales = bogo_filter_locales( $accessible_locales ); - } + $accessible_locales = bogo_get_user_accessible_locales( $profileuser->ID ); ?> @@ -89,33 +81,3 @@ function bogo_set_accessible_locales( $profileuser ) { <?php } - -function bogo_select_own_locale( $profileuser ) { - if ( ! empty( $profileuser->locale ) ) { // WordPress 4.7+ - return; - } - - $available_languages = bogo_available_languages( array( - 'exclude_enus_if_inactive' => true, - 'orderby' => 'value', - 'current_user_can_access' => true, - ) ); - - $selected = bogo_get_user_locale( $profileuser->ID ); - -?> - -<!-- Bogo plugin --> -<tr> -<th scope="row"><?php echo esc_html( __( 'Locale', 'bogo' ) ); ?></th> -<td> -<select name="bogo_own_locale"> -<?php foreach ( $available_languages as $locale => $lang ) : ?> -<option value="<?php echo esc_attr( $locale ); ?>" <?php selected( $locale, $selected ); ?>><?php echo esc_html( $lang ); ?></option> -<?php endforeach; ?> -</select> -</td> -</tr> - -<?php -} diff --git a/wp-content/plugins/bogo/admin/includes/widgets.php b/wp-content/plugins/bogo/admin/includes/widgets.php index 3f1b48115e30585e6369c38e20ed8606839ed04d..e25496503a22e41645191b43825a270b170dc54f 100644 --- a/wp-content/plugins/bogo/admin/includes/widgets.php +++ b/wp-content/plugins/bogo/admin/includes/widgets.php @@ -4,7 +4,6 @@ add_action( 'in_widget_form', 'bogo_in_widget_form', 10, 3 ); function bogo_in_widget_form( $widget, $return, $instance ) { $available_languages = bogo_available_languages( array( - 'exclude_enus_if_inactive' => true, 'orderby' => 'value', ) ); @@ -36,7 +35,8 @@ function bogo_in_widget_form( $widget, $return, $instance ) { add_filter( 'widget_update_callback', 'bogo_widget_update_callback', 10, 4 ); function bogo_widget_update_callback( $instance, $new_instance, $old_instance, $widget ) { - if ( isset( $new_instance['bogo_locales'] ) && is_array( $new_instance['bogo_locales'] ) ) { + if ( isset( $new_instance['bogo_locales'] ) + and is_array( $new_instance['bogo_locales'] ) ) { $instance['bogo_locales'] = $new_instance['bogo_locales']; } else { $instance['bogo_locales'] = array(); diff --git a/wp-content/plugins/bogo/bogo.php b/wp-content/plugins/bogo/bogo.php index aa2e2fcf5ed342f03b6acf2e8d3ef1539d80e93c..682f758ab50bcee3eb6d4ed35b2d6cdb82c5e6a7 100644 --- a/wp-content/plugins/bogo/bogo.php +++ b/wp-content/plugins/bogo/bogo.php @@ -7,10 +7,10 @@ Author: Takayuki Miyoshi Author URI: https://ideasilo.wordpress.com/ Text Domain: bogo Domain Path: /languages/ -Version: 3.2.1 +Version: 3.3.2 */ -define( 'BOGO_VERSION', '3.2.1' ); +define( 'BOGO_VERSION', '3.3.2' ); define( 'BOGO_PLUGIN', __FILE__ ); @@ -33,38 +33,34 @@ require_once BOGO_PLUGIN_DIR . '/includes/capabilities.php'; require_once BOGO_PLUGIN_DIR . '/includes/query.php'; require_once BOGO_PLUGIN_DIR . '/includes/flags.php'; require_once BOGO_PLUGIN_DIR . '/includes/rest-api.php'; +require_once BOGO_PLUGIN_DIR . '/includes/block-editor.php'; if ( is_admin() ) { require_once BOGO_PLUGIN_DIR . '/admin/admin.php'; } -add_action( 'plugins_loaded', 'bogo_plugins_loaded' ); +add_action( 'plugins_loaded', 'bogo_plugins_loaded', 10, 0 ); function bogo_plugins_loaded() { - load_plugin_textdomain( 'bogo', 'wp-content/plugins/bogo/languages', 'bogo/languages' ); + load_plugin_textdomain( 'bogo', + false, + 'bogo/languages' + ); } -add_action( 'init', 'bogo_init' ); +add_action( 'init', 'bogo_init', 10, 0 ); function bogo_init() { bogo_languages(); - Bogo_POMO::import( get_locale() ); - - if ( ! ( is_admin() || is_robots() || is_feed() || is_trackback() ) ) { - $locale = get_locale(); - - if ( ! isset( $_COOKIE['lang'] ) || $_COOKIE['lang'] != $locale ) { - setcookie( 'lang', $locale, 0, '/' ); - } - } + Bogo_POMO::import( determine_locale() ); } -add_filter( 'locale', 'bogo_locale' ); +add_filter( 'locale', 'bogo_locale', 10, 1 ); function bogo_locale( $locale ) { global $wp_rewrite, $wp_query; - if ( ! did_action( 'plugins_loaded' ) ) { + if ( ! did_action( 'plugins_loaded' ) or is_admin() ) { return $locale; } @@ -74,22 +70,19 @@ function bogo_locale( $locale ) { return $bogo_locale; } - if ( is_admin() ) { - return $bogo_locale = bogo_get_user_locale(); - } - $default_locale = bogo_get_default_locale(); if ( ! empty( $wp_query->query_vars ) ) { - if ( ( $lang = get_query_var( 'lang' ) ) - && $closest = bogo_get_closest_locale( $lang ) ) { + if ( $lang = get_query_var( 'lang' ) + and $closest = bogo_get_closest_locale( $lang ) ) { return $bogo_locale = $closest; } else { return $bogo_locale = $default_locale; } } - if ( isset( $wp_rewrite ) && $wp_rewrite->using_permalinks() ) { + if ( isset( $wp_rewrite ) + and $wp_rewrite->using_permalinks() ) { $url = is_ssl() ? 'https://' : 'http://'; $url .= $_SERVER['HTTP_HOST']; $url .= $_SERVER['REQUEST_URI']; @@ -100,24 +93,29 @@ function bogo_locale( $locale ) { $available_locales = bogo_available_locales(); $available_locales = array_map( 'bogo_lang_slug', $available_locales ); $available_locales = implode( '|', $available_locales ); - $pattern = '#^' . preg_quote( $home ) . '(' . $available_locales . ')(/|$)#'; + + $pattern = '#^' + . preg_quote( $home ) + . '(' . $available_locales . ')' + . '(/|$)#'; if ( preg_match( $pattern, $url, $matches ) - && $closest = bogo_get_closest_locale( $matches[1] ) ) { + and $closest = bogo_get_closest_locale( $matches[1] ) ) { return $bogo_locale = $closest; } } $lang = bogo_get_lang_from_url(); - if ( $lang && $closest = bogo_get_closest_locale( $lang ) ) { + if ( $lang + and $closest = bogo_get_closest_locale( $lang ) ) { return $bogo_locale = $closest; } return $bogo_locale = $default_locale; } -add_filter( 'query_vars', 'bogo_query_vars' ); +add_filter( 'query_vars', 'bogo_query_vars', 10, 1 ); function bogo_query_vars( $query_vars ) { $query_vars[] = 'lang'; @@ -125,21 +123,23 @@ function bogo_query_vars( $query_vars ) { return $query_vars; } -add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); +add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts', 10, 0 ); function bogo_enqueue_scripts() { wp_enqueue_style( 'bogo', plugins_url( 'includes/css/style.css', BOGO_PLUGIN_BASENAME ), - array(), BOGO_VERSION, 'all' ); + array(), BOGO_VERSION, 'all' + ); if ( is_rtl() ) { wp_enqueue_style( 'bogo-rtl', plugins_url( 'includes/css/style-rtl.css', BOGO_PLUGIN_BASENAME ), - array(), BOGO_VERSION, 'all' ); + array(), BOGO_VERSION, 'all' + ); } } -add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate' ); +add_action( 'deactivate_' . BOGO_PLUGIN_BASENAME, 'bogo_deactivate', 10, 0 ); function bogo_deactivate() { bogo_delete_prop( 'lang_rewrite_regex' ); diff --git a/wp-content/plugins/bogo/includes/block-editor.php b/wp-content/plugins/bogo/includes/block-editor.php new file mode 100644 index 0000000000000000000000000000000000000000..4ba41e0eac580184b5a187f36ea3906af1115a08 --- /dev/null +++ b/wp-content/plugins/bogo/includes/block-editor.php @@ -0,0 +1,21 @@ +<?php + +add_action( 'enqueue_block_editor_assets', + 'bogo_enqueue_block_editor_assets', + 10, 0 +); + +function bogo_enqueue_block_editor_assets() { + wp_enqueue_script( + 'bogo-block-editor', + plugins_url( 'includes/js/block-editor.js', BOGO_PLUGIN_BASENAME ), + array( + 'wp-components', + 'wp-data', + 'wp-edit-post', + 'wp-element', + 'wp-plugins', + ), + BOGO_VERSION + ); +} diff --git a/wp-content/plugins/bogo/includes/capabilities.php b/wp-content/plugins/bogo/includes/capabilities.php index d84da96aedf895b48c576eae2e9199af0948459b..26dc9c72a055260123479cc0e36234ef6e83e0e3 100644 --- a/wp-content/plugins/bogo/includes/capabilities.php +++ b/wp-content/plugins/bogo/includes/capabilities.php @@ -5,7 +5,7 @@ add_filter( 'map_meta_cap', 'bogo_map_meta_cap', 10, 4 ); function bogo_map_meta_cap( $caps, $cap, $user_id, $args ) { $meta_caps = array( 'bogo_manage_language_packs' => 'install_languages', - 'bogo_edit_terms_translation' => 'manage_options', + 'bogo_edit_terms_translation' => 'manage_categories', 'bogo_access_all_locales' => 'manage_options', 'bogo_access_locale' => 'read', ); @@ -18,17 +18,32 @@ function bogo_map_meta_cap( $caps, $cap, $user_id, $args ) { $caps[] = $meta_caps[$cap]; } - if ( 'bogo_access_locale' == $cap - && ! user_can( $user_id, 'bogo_access_all_locales' ) ) { - $accessible_locales = bogo_get_user_accessible_locales( $user_id ); + static $accessible_locales = array(); - if ( ! empty( $accessible_locales ) ) { - $accessible_locales = bogo_filter_locales( $accessible_locales ); - $locale = $args[0]; + if ( 'bogo_access_all_locales' !== $cap + and ! isset( $accessible_locales[$user_id] ) ) { + $accessible_locales[$user_id] = bogo_get_user_accessible_locales( + $user_id + ); + } + + if ( 'bogo_access_locale' === $cap + and ! user_can( $user_id, 'bogo_access_all_locales' ) ) { + $locale = $args[0]; + + if ( ! in_array( $locale, $accessible_locales[$user_id] ) ) { + $caps[] = 'do_not_allow'; + } + } + + if ( in_array( $cap, array( 'edit_post', 'delete_post' ), true ) + and $post = get_post( $args[0] ) + and $user_id !== $post->post_author + and ! user_can( $user_id, 'bogo_access_all_locales' ) ) { + $locale = bogo_get_post_locale( $post->ID ); - if ( ! in_array( $locale, $accessible_locales ) ) { - $caps[] = 'do_not_allow'; - } + if ( ! in_array( $locale, $accessible_locales[$user_id] ) ) { + $caps[] = 'do_not_allow'; } } diff --git a/wp-content/plugins/bogo/includes/functions.php b/wp-content/plugins/bogo/includes/functions.php index ea8c51094b6e305bf5d64c49b07d125ae04aa189..b80e34e8a6f6f2eac0a5f41e26d244094857a689 100644 --- a/wp-content/plugins/bogo/includes/functions.php +++ b/wp-content/plugins/bogo/includes/functions.php @@ -4,7 +4,7 @@ function bogo_languages() { static $languages = array(); static $textdomain_loaded = false; - if ( $languages && $textdomain_loaded ) { + if ( $languages and $textdomain_loaded and ! is_locale_switched() ) { return apply_filters( 'bogo_languages', $languages ); } @@ -32,6 +32,7 @@ function bogo_languages() { 'da_DK' => __( 'Danish', 'bogo' ), 'de_DE' => __( 'German', 'bogo' ), 'de_DE_formal' => __( 'German (Formal)', 'bogo' ), + 'de_AT' => __( 'German (Austria)', 'bogo' ), 'de_CH' => __( 'German (Switzerland)', 'bogo' ), 'de_CH_informal' => __( 'German (Switzerland) (Informal)', 'bogo' ), 'dv' => __( 'Dhivehi', 'bogo' ), @@ -52,6 +53,8 @@ function bogo_languages() { 'es_GT' => __( 'Spanish (Guatemala)', 'bogo' ), 'es_MX' => __( 'Spanish (Mexico)', 'bogo' ), 'es_PE' => __( 'Spanish (Peru)', 'bogo' ), + 'es_PR' => __( 'Spanish (Puerto Rico)', 'bogo' ), + 'es_UY' => __( 'Spanish (Uruguay)', 'bogo' ), 'es_VE' => __( 'Spanish (Venezuela)', 'bogo' ), 'et' => __( 'Estonian', 'bogo' ), 'eu' => __( 'Basque', 'bogo' ), @@ -71,6 +74,7 @@ function bogo_languages() { 'he_IL' => __( 'Hebrew', 'bogo' ), 'hi_IN' => __( 'Hindi', 'bogo' ), 'hr' => __( 'Croatian', 'bogo' ), + 'hsb' => __( 'Upper Sorbian', 'bogo' ), 'ht' => __( 'Haitian', 'bogo' ), 'hu_HU' => __( 'Hungarian', 'bogo' ), 'hy' => __( 'Armenian', 'bogo' ), @@ -109,9 +113,10 @@ function bogo_languages() { 'pa_IN' => __( 'Punjabi', 'bogo' ), 'pl_PL' => __( 'Polish', 'bogo' ), 'ps' => __( 'Pashto', 'bogo' ), - 'pt_BR' => __( 'Portuguese (Brazil)', 'bogo' ), 'pt_PT' => __( 'Portuguese (Portugal)', 'bogo' ), 'pt_PT_ao90' => __( 'Portuguese (Portugal) (Ao90)', 'bogo' ), + 'pt_AO' => __( 'Portuguese (Angola)', 'bogo' ), + 'pt_BR' => __( 'Portuguese (Brazil)', 'bogo' ), 'rhg' => __( 'Rohingya', 'bogo' ), 'ro_RO' => __( 'Romanian', 'bogo' ), 'ru_RU' => __( 'Russian', 'bogo' ), @@ -119,7 +124,9 @@ function bogo_languages() { 'sah' => __( 'Sakha', 'bogo' ), 'si_LK' => __( 'Sinhala', 'bogo' ), 'sk_SK' => __( 'Slovak', 'bogo' ), + 'skr' => __( 'Saraiki', 'bogo' ), 'sl_SI' => __( 'Slovenian', 'bogo' ), + 'snd' => __( 'Sindhi', 'bogo' ), 'so_SO' => __( 'Somali', 'bogo' ), 'sq' => __( 'Albanian', 'bogo' ), 'sr_RS' => __( 'Serbian', 'bogo' ), @@ -145,9 +152,7 @@ function bogo_languages() { 'zh_TW' => __( 'Chinese (Taiwan)', 'bogo' ), ); - if ( is_textdomain_loaded( 'bogo' ) ) { - $textdomain_loaded = true; - } + $textdomain_loaded = is_textdomain_loaded( 'bogo' ) && ! is_locale_switched(); asort( $languages, SORT_STRING ); @@ -199,7 +204,7 @@ function bogo_get_default_locale() { if ( is_multisite() ) { if ( wp_installing() - || ( false === $ms_locale = get_option( 'WPLANG' ) ) ) { + or false === $ms_locale = get_option( 'WPLANG' ) ) { $ms_locale = get_site_option( 'WPLANG' ); } @@ -238,7 +243,7 @@ function bogo_is_enus_deactivated() { function bogo_available_locales( $args = '' ) { $defaults = array( 'exclude' => array(), - 'exclude_enus_if_inactive' => false, + 'exclude_enus_if_inactive' => true, 'current_user_can_access' => false, ); @@ -255,23 +260,30 @@ function bogo_available_locales( $args = '' ) { $available_locales = $installed_locales; if ( $args['current_user_can_access'] - && ! current_user_can( 'bogo_access_all_locales' ) ) { + and ! current_user_can( 'bogo_access_all_locales' ) ) { $user_accessible_locales = bogo_get_user_accessible_locales( - get_current_user_id() ); + get_current_user_id() + ); - $available_locales = array_intersect( $available_locales, - (array) $user_accessible_locales ); + $available_locales = array_intersect( + $available_locales, + $user_accessible_locales + ); } if ( ! empty( $args['exclude'] ) ) { - $available_locales = array_diff( $available_locales, - (array) $args['exclude'] ); + $available_locales = array_diff( + $available_locales, + (array) $args['exclude'] + ); } if ( $args['exclude_enus_if_inactive'] - && bogo_is_enus_deactivated() ) { - $available_locales = array_diff( $available_locales, - array( 'en_US' ) ); + and bogo_is_enus_deactivated() ) { + $available_locales = array_diff( + $available_locales, + array( 'en_US' ) + ); } return array_unique( array_filter( $available_locales ) ); @@ -282,7 +294,9 @@ function bogo_available_languages( $args = '' ) { 'exclude' => array(), 'orderby' => 'key', 'order' => 'ASC', + 'exclude_enus_if_inactive' => true, 'current_user_can_access' => false, + 'short_name' => true, ); $args = wp_parse_args( $args, $defaults ); @@ -293,6 +307,12 @@ function bogo_available_languages( $args = '' ) { foreach ( $available_locales as $locale ) { $lang = bogo_get_language( $locale ); + + if ( $args['short_name'] and bogo_locale_is_alone( $locale ) ) { + $lang = bogo_get_short_name( $lang ); + } + + $lang = trim( $lang ); $langs[$locale] = empty( $lang ) ? "[$locale]" : $lang; } @@ -330,7 +350,7 @@ function bogo_is_available_locale( $locale ) { } function bogo_filter_locales( $locales, $filter = 'available' ) { - return array_intersect( $locales, bogo_available_locales() ); + return array_intersect( (array) $locales, bogo_available_locales() ); } /** @@ -340,9 +360,9 @@ function bogo_language_tag( $locale ) { $tag = preg_replace( '/[^0-9a-zA-Z]+/', '-', $locale ); $tag = trim( $tag, '-' ); - if ( '-formal' == substr( $tag, -7 ) ) { - $tag = substr( $tag, 0, -7 ); - } + $tag = explode( '-', $tag ); + $tag = array_slice( $tag, 0, 2 ); // de-DE-formal => de-DE + $tag = implode( '-', $tag ); return apply_filters( 'bogo_language_tag', $tag, $locale ); } @@ -355,7 +375,9 @@ function bogo_lang_slug( $locale ) { $slug = substr( $tag, 0, $pos ); } - $variations = preg_grep( '/^' . $slug . '/', bogo_available_locales() ); + $variations = preg_grep( '/^' . $slug . '/', + bogo_available_locales() + ); if ( 1 < count( $variations ) ) { $slug = $tag; @@ -364,6 +386,44 @@ function bogo_lang_slug( $locale ) { return apply_filters( 'bogo_lang_slug', $slug, $locale ); } +function bogo_locale_is_alone( $locale ) { + $tag = bogo_language_tag( $locale ); + + if ( false === strpos( $tag, '-' ) ) { + return true; + } + + $slug = bogo_lang_slug( $locale ); + + return strlen( $slug ) < strlen( $tag ); +} + +function bogo_get_short_name( $orig_name ) { + $short_name = $orig_name; + + $langs_with_variants = array( + '䏿–‡', + 'Français', + 'Português', + 'Español', + ); + + foreach ( $langs_with_variants as $lang ) { + if ( false !== strpos( $orig_name, $lang ) ) { + $short_name = $lang; + break; + } + } + + if ( preg_match( '/^([^()]+)/', $short_name, $matches ) ) { + $short_name = $matches[1]; + } + + $short_name = apply_filters( 'bogo_get_short_name', $short_name, $orig_name ); + + return trim( $short_name ); +} + function bogo_get_lang_regex() { $langs = array_map( 'bogo_lang_slug', bogo_available_locales() ); $langs = array_filter( $langs ); @@ -389,7 +449,7 @@ function bogo_get_closest_locale( $var ) { $locales = bogo_available_locales(); - if ( $variant_code && $region_code ) { + if ( $variant_code and $region_code ) { $locale = $language_code . '_' . strtoupper( $region_code ) . '_' . $variant_code; @@ -454,7 +514,7 @@ function bogo_http_accept_languages() { function bogo_url( $url = null, $lang = null ) { if ( ! $lang ) { - $lang = get_locale(); + $lang = determine_locale(); } $args = array( @@ -482,7 +542,7 @@ function bogo_get_url_with_lang( $url = null, $lang = null, $args = '' ) { $url = substr( $url, 0, - strlen( $frag ) ); } - if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) { + if ( $query = wp_parse_url( $url, PHP_URL_QUERY ) ) { parse_str( $query, $query_vars ); foreach ( array_keys( $query_vars ) as $qv ) { @@ -518,14 +578,17 @@ function bogo_get_url_with_lang( $url = null, $lang = null, $args = '' ) { return $url; } - $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() ); + $available_languages = array_map( 'bogo_lang_slug', + bogo_available_locales() + ); $tail_slashed = ( '/' == substr( $url, -1 ) ); $url = preg_replace( '#^' . preg_quote( $home ) . '((' . implode( '|', $available_languages ) . ')/)?#', $home . ( $lang_slug ? trailingslashit( $lang_slug ) : '' ), - trailingslashit( $url ) ); + trailingslashit( $url ) + ); if ( ! $tail_slashed ) { $url = untrailingslashit( $url ); @@ -548,19 +611,24 @@ function bogo_get_lang_from_url( $url = '' ) { $home = set_url_scheme( get_option( 'home' ) ); $home = trailingslashit( $home ); - $available_languages = array_map( 'bogo_lang_slug', bogo_available_locales() ); + $available_languages = array_map( 'bogo_lang_slug', + bogo_available_locales() + ); - $regex = '#^' . preg_quote( $home ) . '(' . implode( '|', $available_languages ) . ')/#'; + $regex = '#^' + . preg_quote( $home ) + . '(' . implode( '|', $available_languages ) . ')' + . '/#'; if ( preg_match( $regex, trailingslashit( $url ), $matches ) ) { return $matches[1]; } - if ( $query = @parse_url( $url, PHP_URL_QUERY ) ) { + if ( $query = wp_parse_url( $url, PHP_URL_QUERY ) ) { parse_str( $query, $query_vars ); if ( isset( $query_vars['lang'] ) - && in_array( $query_vars['lang'], $available_languages ) ) { + and in_array( $query_vars['lang'], $available_languages ) ) { return $query_vars['lang']; } } @@ -607,9 +675,41 @@ function bogo_delete_prop( $prop ) { function bogo_plugin_url( $path = '' ) { $url = plugins_url( $path, BOGO_PLUGIN ); - if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) { + if ( is_ssl() and 'http:' == substr( $url, 0, 5 ) ) { $url = 'https:' . substr( $url, 5 ); } return $url; } + +function bogo_format_atts( $atts ) { + $html = ''; + + $prioritized_atts = array( 'type', 'name', 'value' ); + + foreach ( $prioritized_atts as $att ) { + if ( isset( $atts[$att] ) ) { + $value = trim( $atts[$att] ); + $html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) ); + unset( $atts[$att] ); + } + } + + foreach ( $atts as $key => $value ) { + $key = strtolower( trim( $key ) ); + + if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) { + continue; + } + + $value = trim( $value ); + + if ( '' !== $value ) { + $html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) ); + } + } + + $html = trim( $html ); + + return $html; +} diff --git a/wp-content/plugins/bogo/includes/js/block-editor.js b/wp-content/plugins/bogo/includes/js/block-editor.js new file mode 100644 index 0000000000000000000000000000000000000000..faf1a7aeb63a994378ffb81dc6ec13c91ef2743d --- /dev/null +++ b/wp-content/plugins/bogo/includes/js/block-editor.js @@ -0,0 +1 @@ +!function(e){var t={};function n(r){if(t[r])return t[r].exports;var l=t[r]={i:r,l:!1,exports:{}};return e[r].call(l.exports,l,l.exports,n),l.l=!0,l.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var l in e)n.d(r,l,function(t){return e[t]}.bind(null,l));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t,n){var r=n(3),l=n(4),o=n(5);e.exports=function(e,t){return r(e)||l(e,t)||o()}},function(e,t,n){"use strict";n.r(t);var r=n(1),l=n.n(r),o=n(0),a=wp.plugins.registerPlugin,c=wp.editPost.PluginDocumentSettingPanel,i=wp.components,u=i.PanelRow,s=i.Button,b=i.ExternalLink,p=i.Spinner,f=wp.element.useState,g=wp.data,m=g.dispatch,d=g.useSelect,O=wp.url,j=O.addQueryArgs,y=O.hasQueryArg,E=wp.apiFetch;a("bogo-language-panel",{render:function(){var e=d((function(e){return Object.assign({},e("core/editor").getCurrentPost(),bogo.currentPost)}));if(-1==bogo.localizablePostTypes.indexOf(e.type))return Object(o.createElement)(o.Fragment,null);var t=f(e.translations),n=l()(t,2),r=n[0],a=n[1];return Object(o.createElement)(c,{name:"bogo-language-panel",title:bogo.l10n.language,className:"bogo-language-panel"},Object(o.createElement)((function(){return Object(o.createElement)(u,null,Object(o.createElement)("span",null,bogo.l10n.language),Object(o.createElement)("div",null,v(e.locale)))}),null),Object(o.createElement)((function(){var e=[];Object.entries(r).forEach((function(t){var n=l()(t,2),r=n[0],a=n[1];a.editLink&&a.postTitle?e.push(Object(o.createElement)("li",{key:r},Object(o.createElement)(b,{href:a.editLink},a.postTitle),Object(o.createElement)("br",null),Object(o.createElement)("em",null,v(r)))):a.postTitle&&e.push(Object(o.createElement)("li",{key:r},a.postTitle,Object(o.createElement)("br",null),Object(o.createElement)("em",null,v(r))))}));return Object(o.createElement)(u,null,Object(o.createElement)("span",null,bogo.l10n.translations),Object(o.createElement)((function(e){return e.listItems.length?Object(o.createElement)("ul",null,e.listItems):Object(o.createElement)("em",null,bogo.l10n.none)}),{listItems:e}))}),null),Object(o.createElement)((function(){var t=[];return Object.entries(r).forEach((function(n){var c=l()(n,2),i=c[0],u=c[1];u.postId||t.push(Object(o.createElement)("li",{key:i},Object(o.createElement)(s,{isDefault:!0,onClick:function(){var t,n;t=i,(n=Object.assign({},r))[t]={creating:!0},a(n),E({path:"/bogo/v1/posts/"+e.id+"/translations/"+t,method:"POST"}).then((function(e){var n=Object.assign({},r);n[t]={postId:e[t].id,postTitle:e[t].title.raw,editLink:e[t].edit_link,creating:!1},a(n),m("core/notices").createInfoNotice(bogo.l10n.noticePostCreation,{isDismissible:!0,type:"snackbar",speak:!0,actions:[{url:n[t].editLink,label:bogo.l10n.editPost}]})}))}},bogo.l10n.addTranslation[i]),u.creating&&Object(o.createElement)(p,null)))})),t.length<1||"auto-draft"==e.status?Object(o.createElement)(o.Fragment,null):Object(o.createElement)(u,null,Object(o.createElement)("ul",null,t))}),null))},icon:"translation"}),E.use((function(e,t){var n=bogo.currentPost.lang;return n&&("string"!=typeof e.url||y(e.url,"lang")||(e.url=j(e.url,{lang:n})),"string"!=typeof e.path||y(e.path,"lang")||(e.path=j(e.path,{lang:n}))),t(e,t)}));var v=function(e){return bogo.availableLanguages[e]?bogo.availableLanguages[e]:e}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e}},function(e,t){e.exports=function(e,t){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)){var n=[],r=!0,l=!1,o=void 0;try{for(var a,c=e[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){l=!0,o=e}finally{try{r||null==c.return||c.return()}finally{if(l)throw o}}return n}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}}]); \ No newline at end of file diff --git a/wp-content/plugins/bogo/includes/language-switcher.php b/wp-content/plugins/bogo/includes/language-switcher.php index 2d17912af4aa1e9e26d321e995fe695136422d1e..ee21a7e01dbc281499d90838ac4592679bf287b7 100644 --- a/wp-content/plugins/bogo/includes/language-switcher.php +++ b/wp-content/plugins/bogo/includes/language-switcher.php @@ -19,7 +19,7 @@ function bogo_language_switcher( $args = '' ) { $class[] = bogo_language_tag( $link['locale'] ); $class[] = bogo_lang_slug( $link['locale'] ); - if ( get_locale() == $link['locale'] ) { + if ( get_locale() === $link['locale'] ) { $class[] = 'current'; } @@ -39,20 +39,39 @@ function bogo_language_switcher( $args = '' ) { if ( empty( $link['href'] ) ) { $li = esc_html( $label ); } else { + $atts = array( + 'rel' => 'alternate', + 'hreflang' => $link['lang'], + 'href' => esc_url( $link['href'] ), + 'title' => $title, + ); + + if ( get_locale() === $link['locale'] ) { + $atts += array( + 'class' => 'current', + 'aria-current' => 'page', + ); + } + $li = sprintf( - '<a rel="alternate" hreflang="%1$s" href="%2$s" title="%3$s">%4$s</a>', - $link['lang'], - esc_url( $link['href'] ), - esc_attr( $title ), - esc_html( $label ) ); + '<a %1$s>%2$s</a>', + bogo_format_atts( $atts ), + esc_html( $label ) + ); } + $li = sprintf( + '<span class="bogo-language-name">%s</span>', + $li + ); + if ( apply_filters( 'bogo_use_flags', true ) ) { $flag = bogo_get_flag( $link['locale'] ); $flag = preg_replace( '/(?:.*?)([a-z]+)\.png$/', '$1', $flag, 1 ); $flag = sprintf( '<span class="bogoflags bogoflags-%s"></span>', - $flag ? $flag : 'zz' ); + $flag ? $flag : 'zz' + ); $li = sprintf( '<li class="%1$s">%3$s %2$s</li>', $class, $li, $flag ); } else { @@ -79,13 +98,14 @@ function bogo_language_switcher_links( $args = '' ) { $args = wp_parse_args( $args, array() ); $locale = get_locale(); - $available_languages = bogo_available_languages( array( - 'exclude_enus_if_inactive' => true ) ); + + $available_languages = bogo_available_languages(); $translations = array(); $is_singular = false; - if ( is_singular() || ! empty( $wp_query->is_posts_page ) ) { + if ( is_singular() + or ! empty( $wp_query->is_posts_page ) ) { $translations = bogo_get_post_translations( get_queried_object_id() ); $is_singular = true; } @@ -93,24 +113,29 @@ function bogo_language_switcher_links( $args = '' ) { $links = array(); foreach ( $available_languages as $code => $name ) { + $native_name = bogo_get_language_native_name( $code ); + + if ( bogo_locale_is_alone( $code ) ) { + $native_name = bogo_get_short_name( $native_name ); + } + $link = array( 'locale' => $code, 'lang' => bogo_language_tag( $code ), 'title' => $name, - 'native_name' => bogo_get_language_native_name( $code ), + 'native_name' => trim( $native_name ), 'href' => '', ); if ( $is_singular ) { - if ( $locale != $code - && ! empty( $translations[$code] ) - && 'publish' == get_post_status( $translations[$code] ) ) { + if ( $locale === $code ) { + $link['href'] = get_permalink( get_queried_object_id() ); + } elseif ( ! empty( $translations[$code] ) + and 'publish' == get_post_status( $translations[$code] ) ) { $link['href'] = get_permalink( $translations[$code] ); } } else { - if ( $locale != $code ) { - $link['href'] = bogo_url( null, $code ); - } + $link['href'] = bogo_url( null, $code ); } $links[] = $link; diff --git a/wp-content/plugins/bogo/includes/link-template.php b/wp-content/plugins/bogo/includes/link-template.php index 49b4a4c90faa15b0a74e287a40bed7f03c38d42b..c0235030ff4299d79d3674500704ef6fe63383f4 100644 --- a/wp-content/plugins/bogo/includes/link-template.php +++ b/wp-content/plugins/bogo/includes/link-template.php @@ -15,7 +15,8 @@ function bogo_post_link( $permalink, $post, $leavename ) { ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ); $permalink = bogo_get_url_with_lang( $permalink, $locale, - array( 'using_permalinks' => $using_permalinks ) ); + array( 'using_permalinks' => $using_permalinks ) + ); return $permalink; } @@ -39,7 +40,7 @@ function bogo_page_link( $permalink, $id, $sample ) { $translation = bogo_get_post_translation( $front_page_id, $locale ); - if ( $translation && $translation->ID == $id ) { + if ( $translation and $translation->ID === $id ) { $home = set_url_scheme( get_option( 'home' ) ); $home = trailingslashit( $home ); return bogo_url( $home, $locale ); @@ -52,7 +53,8 @@ function bogo_page_link( $permalink, $id, $sample ) { ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ); $permalink = bogo_get_url_with_lang( $permalink, $locale, - array( 'using_permalinks' => $using_permalinks ) ); + array( 'using_permalinks' => $using_permalinks ) + ); return $permalink; } @@ -71,7 +73,8 @@ function bogo_post_type_link( $permalink, $post, $leavename, $sample ) { ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ); $permalink = bogo_get_url_with_lang( $permalink, $locale, - array( 'using_permalinks' => $using_permalinks ) ); + array( 'using_permalinks' => $using_permalinks ) + ); return $permalink; } @@ -124,7 +127,10 @@ function bogo_post_type_archive_link( $link, $post_type ) { return bogo_url( $link ); } -add_filter( 'post_type_archive_feed_link', 'bogo_post_type_archive_feed_link', 10, 2 ); +add_filter( 'post_type_archive_feed_link', + 'bogo_post_type_archive_feed_link', + 10, 2 +); function bogo_post_type_archive_feed_link( $link, $feed ) { return bogo_url( $link ); @@ -136,17 +142,18 @@ function bogo_term_link( $link, $term, $taxonomy ) { return bogo_url( $link ); } -add_filter( 'home_url', 'bogo_home_url' ); +add_filter( 'home_url', 'bogo_home_url', 10, 1 ); function bogo_home_url( $url ) { - if ( is_admin() || ! did_action( 'template_redirect' ) ) { + if ( is_admin() + or ! did_action( 'template_redirect' ) ) { return $url; } return bogo_url( $url ); } -add_action( 'wp_head', 'bogo_m17n_headers' ); +add_action( 'wp_head', 'bogo_m17n_headers', 10, 0 ); function bogo_m17n_headers() { $languages = array(); @@ -154,7 +161,8 @@ function bogo_m17n_headers() { if ( is_singular() ) { $post_id = get_queried_object_id(); - if ( $post_id && $translations = bogo_get_post_translations( $post_id ) ) { + if ( $post_id + and $translations = bogo_get_post_translations( $post_id ) ) { $locale = get_locale(); $translations[$locale] = get_post( $post_id ); @@ -166,9 +174,7 @@ function bogo_m17n_headers() { } } } else { - $available_locales = bogo_available_locales( array( - 'exclude_enus_if_inactive' => true, - ) ); + $available_locales = bogo_available_locales(); foreach ( $available_locales as $locale ) { $languages[] = array( @@ -184,9 +190,12 @@ function bogo_m17n_headers() { $hreflang = isset( $language['hreflang'] ) ? $language['hreflang'] : ''; $href = isset( $language['href'] ) ? $language['href'] : ''; - if ( $hreflang && $href ) { - $link = sprintf( '<link rel="alternate" hreflang="%1$s" href="%2$s" />', - esc_attr( $hreflang ), esc_url( $href ) ); + if ( $hreflang and $href ) { + $link = sprintf( + '<link rel="alternate" hreflang="%1$s" href="%2$s" />', + esc_attr( $hreflang ), + esc_url( $href ) + ); echo $link . "\n"; } @@ -201,7 +210,8 @@ function bogo_adjacent_post_join( $join, $in_same_term, $excluded_terms ) { $post = get_post(); - if ( $post && bogo_is_localizable_post_type( get_post_type( $post ) ) ) { + if ( $post + and bogo_is_localizable_post_type( get_post_type( $post ) ) ) { $join .= " LEFT JOIN $wpdb->postmeta AS postmeta_bogo ON (p.ID = postmeta_bogo.post_id AND postmeta_bogo.meta_key = '_locale')"; } @@ -216,7 +226,8 @@ function bogo_adjacent_post_where( $where, $in_same_term, $excluded_terms ) { $post = get_post(); - if ( $post && bogo_is_localizable_post_type( get_post_type( $post ) ) ) { + if ( $post + and bogo_is_localizable_post_type( get_post_type( $post ) ) ) { $locale = bogo_get_post_locale( $post->ID ); $where .= " AND (1=0"; diff --git a/wp-content/plugins/bogo/includes/nav-menu.php b/wp-content/plugins/bogo/includes/nav-menu.php index 35b7e1ffe52508312bc1921ab50ac4a6055ce0e5..a2fb66bb8fb87d2fa2d5b11f8c3f3b67e152d59a 100644 --- a/wp-content/plugins/bogo/includes/nav-menu.php +++ b/wp-content/plugins/bogo/includes/nav-menu.php @@ -18,7 +18,7 @@ function bogo_get_nav_menu_items( $items, $menu, $args ) { return $items; } -add_filter( 'wp_setup_nav_menu_item', 'bogo_setup_nav_menu_item' ); +add_filter( 'wp_setup_nav_menu_item', 'bogo_setup_nav_menu_item', 10, 1 ); function bogo_setup_nav_menu_item( $menu_item ) { if ( isset( $menu_item->bogo_locales ) ) { @@ -27,7 +27,8 @@ function bogo_setup_nav_menu_item( $menu_item ) { $menu_item->bogo_locales = array(); - if ( isset( $menu_item->post_type ) && 'nav_menu_item' == $menu_item->post_type ) { + if ( isset( $menu_item->post_type ) + and 'nav_menu_item' == $menu_item->post_type ) { $menu_item->bogo_locales = get_post_meta( $menu_item->ID, '_locale' ); } diff --git a/wp-content/plugins/bogo/includes/pomo.php b/wp-content/plugins/bogo/includes/pomo.php index d3986566c6df0e18923aae841eaeb1e26d904366..690c98f39180c463b92b5ca09fe7c30d2c72c817 100644 --- a/wp-content/plugins/bogo/includes/pomo.php +++ b/wp-content/plugins/bogo/includes/pomo.php @@ -30,7 +30,7 @@ function bogo_get_term_filter( $term, $taxonomy ) { return $term; } -add_action( 'load-edit-tags.php', 'bogo_remove_get_term_filter' ); +add_action( 'load-edit-tags.php', 'bogo_remove_get_term_filter', 10, 0 ); function bogo_remove_get_term_filter() { remove_filter( 'get_term', 'bogo_get_term_filter' ); @@ -40,7 +40,8 @@ function bogo_translate_term( WP_Term $term ) { $term->name = bogo_translate( sprintf( '%s:%d', $term->taxonomy, $term->term_id ), $term->taxonomy, - $term->name ); + $term->name + ); return $term; } @@ -60,7 +61,8 @@ class Bogo_POMO { $translated = self::$mo->translate( $singular, $context ); - if ( $translated == $singular && '' !== $default ) { + if ( $translated == $singular + and '' !== $default ) { return $default; } else { return $translated; @@ -74,8 +76,10 @@ class Bogo_POMO { $dir = self::dir(); + $revision_date = new DateTimeImmutable(); + $headers = array( - 'PO-Revision-Date' => current_time( 'mysql', 'gmt' ) . '+0000', + 'PO-Revision-Date' => $revision_date->format( 'Y-m-d H:i:s' ) . '+0000', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8', 'Content-Transfer-Encoding' => '8bit', diff --git a/wp-content/plugins/bogo/includes/post.php b/wp-content/plugins/bogo/includes/post.php index 77d20b39c5456bcd475d6973ab1138d7ea009805..5289b178daf5bd138402eca3d42e505025c24fc3 100644 --- a/wp-content/plugins/bogo/includes/post.php +++ b/wp-content/plugins/bogo/includes/post.php @@ -1,5 +1,36 @@ <?php +/* Post Meta */ + +add_action( 'init', + + function() { + $post_types = bogo_localizable_post_types(); + + foreach ( $post_types as $post_type ) { + register_post_meta( $post_type, + '_locale', + array( + 'type' => 'string', + 'single' => true, + 'show_in_rest' => true, + ) + ); + + register_post_meta( $post_type, + '_original_post', + array( + 'type' => 'string', + 'single' => true, + 'show_in_rest' => true, + ) + ); + } + }, + + 10, 0 +); + /* Post Template */ add_filter( 'body_class', 'bogo_body_class', 10, 2 ); @@ -8,7 +39,7 @@ function bogo_body_class( $classes, $class ) { $locale = bogo_language_tag( get_locale() ); $locale = esc_attr( $locale ); - if ( $locale && ! in_array( $locale, $classes ) ) { + if ( $locale and ! in_array( $locale, $classes ) ) { $classes[] = $locale; } @@ -22,7 +53,7 @@ function bogo_post_class( $classes, $class, $post_id ) { $locale = bogo_language_tag( $locale ); $locale = esc_attr( $locale ); - if ( $locale && ! in_array( $locale, $classes ) ) { + if ( $locale and ! in_array( $locale, $classes ) ) { $classes[] = $locale; } @@ -41,10 +72,13 @@ function bogo_get_post_locale( $post_id ) { function bogo_localizable_post_types() { $localizable = apply_filters( 'bogo_localizable_post_types', - array( 'post', 'page' ) ); + array( 'post', 'page' ) + ); - $localizable = array_diff( $localizable, - array( 'attachment', 'revision', 'nav_menu_item' ) ); + $localizable = array_diff( + $localizable, + array( 'attachment', 'revision', 'nav_menu_item' ) + ); return $localizable; } @@ -57,7 +91,7 @@ function bogo_count_posts( $locale, $post_type = 'post' ) { global $wpdb; if ( ! bogo_is_available_locale( $locale ) - || ! bogo_is_localizable_post_type( $post_type ) ) { + or ! bogo_is_localizable_post_type( $post_type ) ) { return false; } @@ -81,22 +115,17 @@ function bogo_get_post_translations( $post_id = 0 ) { return false; } - if ( 'auto-draft' == $post->post_status ) { - if ( ! empty( $_REQUEST['original_post'] ) ) { - $original = get_post_meta( $_REQUEST['original_post'], '_original_post', true ); + static $translations = array(); - if ( empty( $original ) ) { - $original = (int) $_REQUEST['original_post']; - } - } else { - return false; - } - } else { - $original = get_post_meta( $post->ID, '_original_post', true ); + if ( isset( $translations[$post->ID] ) ) { + return $translations[$post->ID]; } - if ( empty( $original ) ) { - $original = $post->ID; + $original_post = get_post_meta( $post->ID, '_original_post', true ); + + // For back-compat + if ( empty( $original_post ) ) { + $original_post = $post->ID; } $args = array( @@ -105,23 +134,23 @@ function bogo_get_post_translations( $post_id = 0 ) { 'post_status' => 'any', 'post_type' => $post->post_type, 'meta_key' => '_original_post', - 'meta_value' => $original, + 'meta_value' => $original_post, ); $q = new WP_Query(); $posts = $q->query( $args ); - $translations = array(); - - $original_post_status = get_post_status( $original ); - - if ( $original != $post->ID && $original_post_status && 'trash' != $original_post_status ) { - $locale = bogo_get_post_locale( $original ); - $translations[$locale] = get_post( $original ); + // For back-compat + if ( is_int( $original_post ) + and $p = get_post( $original_post ) + and 'trash' !== get_post_status( $p ) ) { + array_unshift( $posts, $p ); } + $translations[$post->ID] = array(); + foreach ( $posts as $p ) { - if ( $p->ID == $post->ID ) { + if ( $p->ID === $post->ID ) { continue; } @@ -131,12 +160,14 @@ function bogo_get_post_translations( $post_id = 0 ) { continue; } - if ( ! isset( $translations[$locale] ) ) { - $translations[$locale] = $p; + if ( ! isset( $translations[$post->ID][$locale] ) ) { + $translations[$post->ID][$locale] = $p; } } - return array_filter( $translations ); + $translations[$post->ID] = array_filter( $translations[$post->ID] ); + + return $translations[$post->ID]; } function bogo_get_post_translation( $post_id, $locale ) { @@ -185,19 +216,20 @@ function bogo_get_page_by_path( $page_path, $locale = null, $post_type = 'page' $foundid = 0; foreach ( (array) $pages as $page ) { - if ( $page->post_name != $revparts[0] ) { + if ( $page->post_name !== $revparts[0] ) { continue; } $count = 0; $p = $page; - while ( $p->post_parent != 0 && isset( $pages[$p->post_parent] ) ) { + while ( $p->post_parent != 0 + and isset( $pages[$p->post_parent] ) ) { $count++; $parent = $pages[$p->post_parent]; if ( ! isset( $revparts[$count] ) - || $parent->post_name != $revparts[$count] ) { + or $parent->post_name !== $revparts[$count] ) { break; } @@ -205,8 +237,8 @@ function bogo_get_page_by_path( $page_path, $locale = null, $post_type = 'page' } if ( $p->post_parent == 0 - && $count + 1 == count( $revparts ) - && $p->post_name == $revparts[$count] ) { + and $count + 1 == count( $revparts ) + and $p->post_name === $revparts[$count] ) { $foundid = $page->ID; break; } @@ -223,13 +255,13 @@ function bogo_duplicate_post( $original_post, $locale ) { $original_post = get_post( $original_post ); if ( ! $original_post - || ! bogo_is_localizable_post_type( get_post_type( $original_post ) ) - || 'auto-draft' == get_post_status( $original_post ) ) { + or ! bogo_is_localizable_post_type( get_post_type( $original_post ) ) + or 'auto-draft' == get_post_status( $original_post ) ) { return false; } if ( ! bogo_is_available_locale( $locale ) - || bogo_get_post_locale( $original_post->ID ) == $locale ) { + or bogo_get_post_locale( $original_post->ID ) == $locale ) { return false; } @@ -257,7 +289,8 @@ function bogo_duplicate_post( $original_post, $locale ) { if ( ! empty( $original_post->post_parent ) ) { $parent_translation = bogo_get_post_translation( - $original_post->post_parent, $locale ); + $original_post->post_parent, $locale + ); if ( $parent_translation ) { $postarr['post_parent'] = $parent_translation->ID; @@ -267,9 +300,10 @@ function bogo_duplicate_post( $original_post, $locale ) { if ( $taxonomies = get_object_taxonomies( $original_post ) ) { foreach ( $taxonomies as $taxonomy ) { $terms = wp_get_post_terms( $original_post->ID, - $taxonomy, array( 'fields' => 'ids' ) ); + $taxonomy, array( 'fields' => 'ids' ) + ); - if ( $terms && ! is_wp_error( $terms ) ) { + if ( $terms and ! is_wp_error( $terms ) ) { $postarr['tax_input'][$taxonomy] = $terms; } } @@ -279,8 +313,9 @@ function bogo_duplicate_post( $original_post, $locale ) { $postarr['meta_input'] = $post_metas; } - $postarr = apply_filters( 'bogo_duplicate_post', - $postarr, $original_post, $locale ); + $postarr = apply_filters( 'bogo_duplicate_post', $postarr, + $original_post, $locale + ); if ( $taxonomies = $postarr['tax_input'] ) { $postarr['tax_input'] = array(); @@ -314,12 +349,37 @@ function bogo_duplicate_post( $original_post, $locale ) { update_post_meta( $new_post_id, '_locale', $locale ); $meta_original_post = get_post_meta( $original_post->ID, - '_original_post', true ); + '_original_post', true + ); if ( $meta_original_post ) { - update_post_meta( $new_post_id, '_original_post', $meta_original_post ); + update_post_meta( $new_post_id, + '_original_post', $meta_original_post + ); } else { - update_post_meta( $new_post_id, '_original_post', $original_post->ID ); + $original_post_guid = get_the_guid( $original_post ); + + if ( empty( $original_post_guid ) ) { + $original_post_guid = $original_post->ID; + } + + $translations = bogo_get_post_translations( $original_post ); + + update_post_meta( $original_post->ID, + '_original_post', $original_post_guid + ); + + if ( $translations ) { + foreach ( $translations as $tr_locale => $tr_post ) { + update_post_meta( $tr_post->ID, + '_original_post', $original_post_guid + ); + } + } + + update_post_meta( $new_post_id, + '_original_post', $original_post_guid + ); } } @@ -330,8 +390,8 @@ add_filter( 'get_pages', 'bogo_get_pages', 10, 2 ); function bogo_get_pages( $pages, $args ) { if ( is_admin() - || ! bogo_is_localizable_post_type( $args['post_type'] ) - || ! empty( $args['bogo_suppress_locale_query'] ) ) { + or ! bogo_is_localizable_post_type( $args['post_type'] ) + or ! empty( $args['bogo_suppress_locale_query'] ) ) { return $pages; } @@ -353,3 +413,222 @@ function bogo_get_pages( $pages, $args ) { return $new_pages; } + +add_action( 'save_post', 'bogo_save_post', 10, 2 ); + +function bogo_save_post( $post_id, $post ) { + if ( did_action( 'import_start' ) + and ! did_action( 'import_end' ) ) { + // Importing + return; + } + + if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { + return; + } + + $current_locales = get_post_meta( $post_id, '_locale' ); + $locale = null; + + if ( ! empty( $current_locales ) ) { + foreach ( $current_locales as $current_locale ) { + if ( bogo_is_available_locale( $current_locale ) ) { + $locale = $current_locale; + break; + } + } + + if ( empty( $locale ) + or 1 < count( $current_locales ) ) { + delete_post_meta( $post_id, '_locale' ); + $current_locales = array(); + } + } + + if ( empty( $current_locales ) ) { + if ( bogo_is_available_locale( $locale ) ) { + // $locale = $locale; + } elseif ( ! empty( $_REQUEST['locale'] ) + and bogo_is_available_locale( $_REQUEST['locale'] ) ) { + $locale = $_REQUEST['locale']; + } elseif ( 'auto-draft' == get_post_status( $post_id ) ) { + $locale = bogo_get_user_locale(); + } else { + $locale = bogo_get_default_locale(); + } + + add_post_meta( $post_id, '_locale', $locale, true ); + } + + $original_post = get_post_meta( $post_id, '_original_post', true ); + + if ( empty( $original_post ) ) { + $post_guid = get_the_guid( $post_id ); + + if ( empty( $post_guid ) ) { + $post_guid = $post_id; + } + + $translations = bogo_get_post_translations( $post_id ); + + update_post_meta( $post_id, '_original_post', $post_guid ); + + if ( $translations ) { + foreach ( $translations as $tr_locale => $tr_post ) { + update_post_meta( $tr_post->ID, '_original_post', $post_guid ); + } + } + } +} + +add_filter( 'pre_wp_unique_post_slug', 'bogo_unique_post_slug', 10, 6 ); + +function bogo_unique_post_slug( $override_slug, $slug, $post_id, $post_status, $post_type, $post_parent ) { + + if ( ! bogo_is_localizable_post_type( $post_type ) ) { + return $override_slug; + } + + $locale = bogo_get_post_locale( $post_id ); + + if ( ! bogo_is_available_locale( $locale ) ) { + return $override_slug; + } + + $override_slug = $slug; + + $q = new WP_Query(); + + global $wp_rewrite; + + $feeds = is_array( $wp_rewrite->feeds ) ? $wp_rewrite->feeds : array(); + + if ( is_post_type_hierarchical( $post_type ) ) { + $q_args = array( + 'name' => $slug, + 'lang' => $locale, + 'post_type' => array( $post_type, 'attachment' ), + 'post_parent' => $post_parent, + 'post__not_in' => array( $post_id ), + 'posts_per_page' => 1, + ); + + $is_bad_slug = in_array( $slug, $feeds ) + || 'embed' === $slug + || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) + || apply_filters( + 'wp_unique_post_slug_is_bad_hierarchical_slug', false, + $slug, $post_type, $post_parent + ); + + if ( ! $is_bad_slug ) { + $q_results = $q->query( $q_args ); + $is_bad_slug = ! empty( $q_results ); + } + + if ( $is_bad_slug ) { + $suffix = 1; + + while ( $is_bad_slug ) { + $suffix += 1; + $alt_slug = sprintf( '%s-%s', + bogo_truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ), + $suffix + ); + + $q_results = $q->query( array_merge( + $q_args, + array( 'name' => $alt_slug ) + ) ); + + $is_bad_slug = ! empty( $q_results ); + } + + $override_slug = $alt_slug; + } + + } else { + $q_args = array( + 'name' => $slug, + 'lang' => $locale, + 'post_type' => $post_type, + 'post__not_in' => array( $post_id ), + 'posts_per_page' => 1, + ); + + $is_bad_slug = in_array( $slug, $feeds ) + || 'embed' === $slug + || apply_filters( + 'wp_unique_post_slug_is_bad_flat_slug', false, + $slug, $post_type + ); + + if ( ! $is_bad_slug ) { + $post = get_post( $post_id ); + + if ( 'post' === $post_type + and ( ! $post or $post->post_name !== $slug ) + and preg_match( '/^[0-9]+$/', $slug ) ) { + $slug_num = intval( $slug ); + + if ( $slug_num ) { + $permastructs = array_values( array_filter( + explode( '/', get_option( 'permalink_structure' ) ) + ) ); + $postname_index = array_search( '%postname%', $permastructs ); + + $is_bad_slug = false + || 0 === $postname_index + || ( $postname_index + && '%year%' === $permastructs[$postname_index - 1] + && 13 > $slug_num ) + || ( $postname_index + && '%monthnum%' === $permastructs[$postname_index - 1] + && 32 > $slug_num ); + } + } + } + + if ( ! $is_bad_slug ) { + $q_results = $q->query( $q_args ); + $is_bad_slug = ! empty( $q_results ); + } + + if ( $is_bad_slug ) { + $suffix = 1; + + while ( $is_bad_slug ) { + $suffix += 1; + $alt_slug = sprintf( '%s-%s', + bogo_truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ), + $suffix + ); + + $q_results = $q->query( array_merge( + $q_args, + array( 'name' => $alt_slug ) + ) ); + + $is_bad_slug = ! empty( $q_results ); + } + + $override_slug = $alt_slug; + } + } + + return $override_slug; +} + +function bogo_truncate_post_slug( $slug, $length = 200 ) { + if ( strlen( $slug ) > $length ) { + $decoded_slug = urldecode( $slug ); + + if ( $decoded_slug === $slug ) { + $slug = substr( $slug, 0, $length ); + } else { + $slug = utf8_uri_encode( $decoded_slug, $length ); + } + } + + return rtrim( $slug, '-' ); +} diff --git a/wp-content/plugins/bogo/includes/query.php b/wp-content/plugins/bogo/includes/query.php index eda1ef23cbafde7781729e484650709b08817fd9..7aaec73ee7b1663ef1c57ce74211fec1363a6c12 100644 --- a/wp-content/plugins/bogo/includes/query.php +++ b/wp-content/plugins/bogo/includes/query.php @@ -1,6 +1,6 @@ <?php -add_action( 'parse_query', 'bogo_parse_query' ); +add_action( 'parse_query', 'bogo_parse_query', 10, 1 ); function bogo_parse_query( $query ) { $qv = &$query->query_vars; @@ -9,12 +9,14 @@ function bogo_parse_query( $query ) { return; } - if ( $query->is_preview() && ( $qv['page_id'] || $qv['p'] ) ) { + if ( $query->is_preview() + and ( $qv['page_id'] or $qv['p'] ) ) { $qv['bogo_suppress_locale_query'] = true; return; } - if ( isset( $qv['post_type'] ) && 'any' != $qv['post_type'] ) { + if ( isset( $qv['post_type'] ) + and 'any' != $qv['post_type'] ) { $localizable = array_filter( (array) $qv['post_type'], 'bogo_is_localizable_post_type' @@ -42,7 +44,8 @@ function bogo_parse_query( $query ) { } } - if ( empty( $locale ) || ! bogo_is_available_locale( $locale ) ) { + if ( empty( $locale ) + or ! bogo_is_available_locale( $locale ) ) { $qv['bogo_suppress_locale_query'] = true; return; } @@ -54,11 +57,13 @@ function bogo_parse_query( $query ) { } if ( $query->is_home - && 'page' == get_option( 'show_on_front' ) - && get_option( 'page_on_front' ) ) { + and 'page' == get_option( 'show_on_front' ) + and get_option( 'page_on_front' ) ) { $query_keys = array_keys( wp_parse_args( $query->query ) ); - $query_keys = array_diff( $query_keys, - array( 'preview', 'page', 'paged', 'cpage', 'lang' ) ); + $query_keys = array_diff( + $query_keys, + array( 'preview', 'page', 'paged', 'cpage', 'lang' ) + ); if ( empty( $query_keys ) ) { $query->is_page = true; @@ -83,8 +88,8 @@ function bogo_parse_query( $query ) { } if ( 'page' == get_option( 'show_on_front' ) - && isset( $query->queried_object_id ) - && $query->queried_object_id == get_option( 'page_for_posts' ) ) { + and isset( $query->queried_object_id ) + and $query->queried_object_id == get_option( 'page_for_posts' ) ) { $query->is_page = false; $query->is_home = true; $query->is_posts_page = true; @@ -92,11 +97,12 @@ function bogo_parse_query( $query ) { } if ( isset( $qv['post_type'] ) - && 'any' != $qv['post_type'] - && ! is_array( $qv['post_type'] ) - && '' != $qv['name'] ) { + and 'any' != $qv['post_type'] + and ! is_array( $qv['post_type'] ) + and '' != $qv['name'] ) { $query->queried_object = bogo_get_page_by_path( - $qv['name'], $locale, $qv['post_type'] ); + $qv['name'], $locale, $qv['post_type'] + ); if ( ! empty( $query->queried_object ) ) { $query->queried_object_id = (int) $query->queried_object->ID; @@ -107,7 +113,7 @@ function bogo_parse_query( $query ) { } if ( $query->is_posts_page - && ( ! isset( $qv['withcomments'] ) || ! $qv['withcomments'] ) ) { + and ( ! isset( $qv['withcomments'] ) or ! $qv['withcomments'] ) ) { $query->is_comment_feed = false; } @@ -178,7 +184,7 @@ function bogo_posts_where( $where, $query ) { return $where; } -add_filter( 'option_sticky_posts', 'bogo_option_sticky_posts' ); +add_filter( 'option_sticky_posts', 'bogo_option_sticky_posts', 10, 1 ); function bogo_option_sticky_posts( $posts ) { if ( is_admin() ) { @@ -196,20 +202,21 @@ function bogo_option_sticky_posts( $posts ) { return $posts; } -add_filter( 'option_page_on_front', 'bogo_get_local_post' ); -add_filter( 'option_page_for_posts', 'bogo_get_local_post' ); +add_filter( 'option_page_on_front', 'bogo_get_local_post', 10, 1 ); +add_filter( 'option_page_for_posts', 'bogo_get_local_post', 10, 1 ); function bogo_get_local_post( $post_id ) { global $wpdb; - if ( is_admin() || empty( $post_id ) ) { + if ( is_admin() + or empty( $post_id ) ) { return $post_id; } $post_type = get_post_type( $post_id ); if ( ! post_type_exists( $post_type ) - || ! bogo_is_localizable_post_type( $post_type ) ) { + or ! bogo_is_localizable_post_type( $post_type ) ) { return $post_id; } @@ -219,10 +226,11 @@ function bogo_get_local_post( $post_id ) { return $post_id; } - $original = get_post_meta( $post_id, '_original_post', true ); + $original_post = get_post_meta( $post_id, '_original_post', true ); - if ( empty( $original ) ) { - $original = $post_id; + // For back-compat + if ( empty( $original_post ) ) { + $original_post = $post_id; } $q = "SELECT ID FROM $wpdb->posts AS posts"; @@ -233,11 +241,22 @@ function bogo_get_local_post( $post_id ) { $q .= " WHERE 1=1"; $q .= " AND post_status = 'publish'"; $q .= $wpdb->prepare( " AND post_type = %s", $post_type ); - $q .= $wpdb->prepare( " AND (ID = %d OR pm1.meta_value = %d)", - $original, $original ); + + if ( is_int( $original_post ) ) { // For back-compat + $q .= $wpdb->prepare( " AND (ID = %d OR pm1.meta_value = %d)", + $original_post, $original_post + ); + } else { + $q .= $wpdb->prepare( " AND pm1.meta_value = %s", $original_post ); + } + $q .= " AND (1=0"; $q .= $wpdb->prepare( " OR pm2.meta_value LIKE %s", $locale ); - $q .= bogo_is_default_locale( $locale ) ? " OR pm2.meta_id IS NULL" : ""; + + if ( bogo_is_default_locale( $locale ) ) { + $q .= " OR pm2.meta_id IS NULL"; + } + $q .= ")"; $translation = absint( $wpdb->get_var( $q ) ); diff --git a/wp-content/plugins/bogo/includes/rest-api.php b/wp-content/plugins/bogo/includes/rest-api.php index 5abb05cc9c8c38b4d17ee2c9aba851b48df99b27..c720a94fd52b320cb4fdd8862b4b7a5076c4e9b3 100644 --- a/wp-content/plugins/bogo/includes/rest-api.php +++ b/wp-content/plugins/bogo/includes/rest-api.php @@ -1,6 +1,6 @@ <?php -add_action( 'rest_api_init', 'bogo_rest_api_init' ); +add_action( 'rest_api_init', 'bogo_rest_api_init', 10, 0 ); function bogo_rest_api_init() { register_rest_route( 'bogo/v1', @@ -37,12 +37,12 @@ function bogo_rest_languages( WP_REST_Request $request ) { $available_translations = wp_get_available_translations(); - $local_available_locales = bogo_available_locales( array( - 'exclude_enus_if_inactive' => true ) ); + $local_available_locales = bogo_available_locales(); $available_translations = array_intersect_key( $available_translations, - array_flip( $local_available_locales ) ); + array_flip( $local_available_locales ) + ); return rest_ensure_response( $available_translations ); } @@ -55,17 +55,26 @@ function bogo_rest_post_translations( WP_REST_Request $request ) { if ( ! $post ) { return new WP_Error( 'bogo_post_not_found', __( "The requested post was not found.", 'bogo' ), - array( 'status' => 404 ) ); + array( 'status' => 404 ) + ); + } + + if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { + return new WP_Error( 'bogo_post_type_invalid', + __( "The requested post type is not localizable.", 'bogo' ), + array( 'status' => 400 ) + ); } $post_type_object = get_post_type_object( $post->post_type ); - $user_can_edit = current_user_can( - $post_type_object->cap->edit_post, $post->ID ); + $edit_post_cap = $post_type_object->cap->edit_post; - if ( ! $user_can_edit && 'publish' != get_post_status( $post ) ) { + if ( ! current_user_can( $edit_post_cap, $post->ID ) + and 'publish' !== get_post_status( $post ) ) { return new WP_Error( 'bogo_post_not_found', __( "The requested post was not found.", 'bogo' ), - array( 'status' => 404 ) ); + array( 'status' => 404 ) + ); } $response = array(); @@ -73,7 +82,7 @@ function bogo_rest_post_translations( WP_REST_Request $request ) { foreach ( $translations as $locale => $translation ) { if ( ! current_user_can( 'edit_post', $translation->ID ) - && 'publish' != get_post_status( $translation ) ) { + and 'publish' !== get_post_status( $translation ) ) { continue; } @@ -101,7 +110,7 @@ function bogo_rest_post_translations( WP_REST_Request $request ) { $response[$locale]['guid']['rendered'] = apply_filters( 'get_the_guid', $translation->guid ); - if ( $user_can_edit ) { + if ( current_user_can( $edit_post_cap, $translation->ID ) ) { $response[$locale]['guid']['raw'] = $translation->guid; } } @@ -110,25 +119,29 @@ function bogo_rest_post_translations( WP_REST_Request $request ) { $response[$locale]['title']['rendered'] = get_the_title( $translation->ID ); - if ( $user_can_edit ) { + if ( current_user_can( $edit_post_cap, $translation->ID ) ) { $response[$locale]['title']['raw'] = $translation->post_title; } } if ( ! empty( $translation->post_content ) ) { - $response[$locale]['content']['rendered'] = - apply_filters( 'the_content', $translation->post_content ); + $response[$locale]['content']['rendered'] = apply_filters( + 'the_content', + $translation->post_content + ); - if ( $user_can_edit ) { + if ( current_user_can( $edit_post_cap, $translation->ID ) ) { $response[$locale]['content']['raw'] = $translation->post_content; } } if ( ! empty( $translation->post_excerpt ) ) { - $response[$locale]['excerpt']['rendered'] = apply_filters( 'the_excerpt', - apply_filters( 'get_the_excerpt', $translation->post_excerpt ) ); + $response[$locale]['excerpt']['rendered'] = apply_filters( + 'the_excerpt', + apply_filters( 'get_the_excerpt', $translation->post_excerpt ) + ); - if ( $user_can_edit ) { + if ( current_user_can( $edit_post_cap, $translation->ID ) ) { $response[$locale]['excerpt']['raw'] = $translation->post_excerpt; } } @@ -142,12 +155,18 @@ function bogo_rest_create_post_translation( WP_REST_Request $request ) { $post = get_post( $post_id ); - if ( ! $post - || ! current_user_can( 'edit_post', $post->ID ) - && 'publish' != get_post_status( $post ) ) { + if ( ! $post ) { return new WP_Error( 'bogo_post_not_found', __( "The requested post was not found.", 'bogo' ), - array( 'status' => 404 ) ); + array( 'status' => 404 ) + ); + } + + if ( ! bogo_is_localizable_post_type( $post->post_type ) ) { + return new WP_Error( 'bogo_post_type_invalid', + __( "The requested post type is not localizable.", 'bogo' ), + array( 'status' => 400 ) + ); } $locale = $request->get_param( 'locale' ); @@ -155,14 +174,15 @@ function bogo_rest_create_post_translation( WP_REST_Request $request ) { if ( ! bogo_is_available_locale( $locale ) ) { return new WP_Error( 'bogo_locale_invalid', __( "The requested locale is not available.", 'bogo' ), - array( 'status' => 400 ) ); + array( 'status' => 400 ) + ); } - if ( ( $post_type_object = get_post_type_object( $post->post_type ) ) - && ! current_user_can( $post_type_object->cap->edit_posts ) ) { - return new WP_Error( 'bogo_post_type_forbidden', - __( "You are not allowed to edit posts in this post type.", 'bogo' ), - array( 'status' => 403 ) ); + if ( ! current_user_can( 'bogo_access_locale', $locale ) ) { + return new WP_Error( 'bogo_locale_forbidden', + __( "You are not allowed to access posts in the requested locale.", 'bogo' ), + array( 'status' => 403 ) + ); } $new_post_id = bogo_duplicate_post( $post, $locale ); @@ -170,7 +190,8 @@ function bogo_rest_create_post_translation( WP_REST_Request $request ) { if ( ! $new_post_id ) { return new WP_Error( 'bogo_post_duplication_failed', __( "Failed to duplicate a post.", 'bogo' ), - array( 'status' => 500 ) ); + array( 'status' => 500 ) + ); } $new_post = get_post( $new_post_id ); diff --git a/wp-content/plugins/bogo/includes/rewrite.php b/wp-content/plugins/bogo/includes/rewrite.php index 5123cb35011e2edafccd332c06c1241f87c6de8f..40845b54c18413d91b1acf29fa5a81a5d460c02c 100644 --- a/wp-content/plugins/bogo/includes/rewrite.php +++ b/wp-content/plugins/bogo/includes/rewrite.php @@ -1,6 +1,6 @@ <?php -add_action( 'init', 'bogo_add_rewrite_tags' ); +add_action( 'init', 'bogo_add_rewrite_tags', 10, 0 ); function bogo_add_rewrite_tags() { $regex = bogo_get_lang_regex(); @@ -19,7 +19,7 @@ function bogo_add_rewrite_tags() { } } -add_filter( 'root_rewrite_rules', 'bogo_root_rewrite_rules' ); +add_filter( 'root_rewrite_rules', 'bogo_root_rewrite_rules', 10, 1 ); function bogo_root_rewrite_rules( $root_rewrite ) { global $wp_rewrite; @@ -27,12 +27,13 @@ function bogo_root_rewrite_rules( $root_rewrite ) { $permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/'; $extra = bogo_generate_rewrite_rules( $permastruct, array( - 'ep_mask' => EP_ROOT ) ); + 'ep_mask' => EP_ROOT, + ) ); return array_merge( $extra, $root_rewrite ); } -add_filter( 'post_rewrite_rules', 'bogo_post_rewrite_rules' ); +add_filter( 'post_rewrite_rules', 'bogo_post_rewrite_rules', 10, 1 ); function bogo_post_rewrite_rules( $post_rewrite ) { global $wp_rewrite; @@ -41,19 +42,27 @@ function bogo_post_rewrite_rules( $post_rewrite ) { // from wp-admin/includes/misc.php $got_rewrite = apply_filters( 'got_rewrite', - apache_mod_loaded( 'mod_rewrite', true ) ); + apache_mod_loaded( 'mod_rewrite', true ) + ); + $got_url_rewrite = apply_filters( 'got_url_rewrite', - $got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks() ); + $got_rewrite || $GLOBALS['is_nginx'] || iis7_supports_permalinks() + ); if ( ! $got_url_rewrite ) { $permastruct = preg_replace( - '#^/index\.php#', '/index.php/%lang%', $permastruct ); - } elseif ( is_multisite() && ! is_subdomain_install() && is_main_site() ) { + '#^/index\.php#', '/index.php/%lang%', $permastruct + ); + } elseif ( is_multisite() + and ! is_subdomain_install() + and is_main_site() ) { $permastruct = preg_replace( - '#^/blog#', '/%lang%/blog', $permastruct ); + '#^/blog#', '/%lang%/blog', $permastruct + ); } else { $permastruct = preg_replace( - '#^/#', '/%lang%/', $permastruct ); + '#^/#', '/%lang%/', $permastruct + ); } $extra = bogo_generate_rewrite_rules( $permastruct, array( @@ -64,7 +73,7 @@ function bogo_post_rewrite_rules( $post_rewrite ) { return array_merge( $extra, $post_rewrite ); } -add_filter( 'date_rewrite_rules', 'bogo_date_rewrite_rules' ); +add_filter( 'date_rewrite_rules', 'bogo_date_rewrite_rules', 10, 1 ); function bogo_date_rewrite_rules( $date_rewrite ) { global $wp_rewrite; @@ -74,20 +83,23 @@ function bogo_date_rewrite_rules( $date_rewrite ) { $permastruct = preg_replace( '#^' . $wp_rewrite->front . '#', '/%lang%' . $wp_rewrite->front, - $permastruct ); + $permastruct + ); $extra = bogo_generate_rewrite_rules( $permastruct, array( - 'ep_mask' => EP_DATE ) ); + 'ep_mask' => EP_DATE, + ) ); return array_merge( $extra, $date_rewrite ); } -add_filter( 'comments_rewrite_rules', 'bogo_comments_rewrite_rules' ); +add_filter( 'comments_rewrite_rules', 'bogo_comments_rewrite_rules', 10, 1 ); function bogo_comments_rewrite_rules( $comments_rewrite ) { global $wp_rewrite; - $permastruct = trailingslashit( $wp_rewrite->root ) . '%lang%/' . $wp_rewrite->comments_base; + $permastruct = trailingslashit( $wp_rewrite->root ) + . '%lang%/' . $wp_rewrite->comments_base; $extra = bogo_generate_rewrite_rules( $permastruct, array( 'ep_mask' => EP_COMMENTS, @@ -98,7 +110,7 @@ function bogo_comments_rewrite_rules( $comments_rewrite ) { return array_merge( $extra, $comments_rewrite ); } -add_filter( 'search_rewrite_rules', 'bogo_search_rewrite_rules' ); +add_filter( 'search_rewrite_rules', 'bogo_search_rewrite_rules', 10, 1 ); function bogo_search_rewrite_rules( $search_rewrite ) { global $wp_rewrite; @@ -107,12 +119,13 @@ function bogo_search_rewrite_rules( $search_rewrite ) { . $wp_rewrite->search_base . '/%search%'; $extra = bogo_generate_rewrite_rules( $permastruct, array( - 'ep_mask' => EP_SEARCH ) ); + 'ep_mask' => EP_SEARCH, + ) ); return array_merge( $extra, $search_rewrite ); } -add_filter( 'author_rewrite_rules', 'bogo_author_rewrite_rules' ); +add_filter( 'author_rewrite_rules', 'bogo_author_rewrite_rules', 10, 1 ); function bogo_author_rewrite_rules( $author_rewrite ) { global $wp_rewrite; @@ -122,15 +135,17 @@ function bogo_author_rewrite_rules( $author_rewrite ) { $permastruct = preg_replace( '#^' . $wp_rewrite->front . '#', '/%lang%' . $wp_rewrite->front, - $permastruct ); + $permastruct + ); $extra = bogo_generate_rewrite_rules( $permastruct, array( - 'ep_mask' => EP_AUTHORS ) ); + 'ep_mask' => EP_AUTHORS, + ) ); return array_merge( $extra, $author_rewrite ); } -add_filter( 'page_rewrite_rules', 'bogo_page_rewrite_rules' ); +add_filter( 'page_rewrite_rules', 'bogo_page_rewrite_rules', 10, 1 ); function bogo_page_rewrite_rules( $page_rewrite ) { global $wp_rewrite; @@ -146,19 +161,24 @@ function bogo_page_rewrite_rules( $page_rewrite ) { return array_merge( $extra, $page_rewrite ); } -add_filter( 'category_rewrite_rules', 'bogo_category_rewrite_rules' ); +add_filter( 'category_rewrite_rules', 'bogo_category_rewrite_rules', 10, 1 ); function bogo_category_rewrite_rules( $category_rewrite ) { - return bogo_taxonomy_rewrite_rules( $category_rewrite, 'category', EP_CATEGORIES ); + return bogo_taxonomy_rewrite_rules( $category_rewrite, + 'category', EP_CATEGORIES + ); } -add_filter( 'post_tag_rewrite_rules', 'bogo_post_tag_rewrite_rules' ); +add_filter( 'post_tag_rewrite_rules', 'bogo_post_tag_rewrite_rules', 10, 1 ); function bogo_post_tag_rewrite_rules( $post_tag_rewrite ) { return bogo_taxonomy_rewrite_rules( $post_tag_rewrite, 'post_tag', EP_TAGS ); } -add_filter( 'post_format_rewrite_rules', 'bogo_post_format_rewrite_rules' ); +add_filter( 'post_format_rewrite_rules', + 'bogo_post_format_rewrite_rules', + 10, 1 +); function bogo_post_format_rewrite_rules( $post_format_rewrite ) { return bogo_taxonomy_rewrite_rules( $post_format_rewrite, 'post_format' ); @@ -172,15 +192,17 @@ function bogo_taxonomy_rewrite_rules( $taxonomy_rewrite, $taxonomy, $ep_mask = E $permastruct = preg_replace( '#^' . $wp_rewrite->front . '#', '/%lang%' . $wp_rewrite->front, - $permastruct ); + $permastruct + ); $extra = bogo_generate_rewrite_rules( $permastruct, array( - 'ep_mask' => $ep_mask ) ); + 'ep_mask' => $ep_mask, + ) ); return array_merge( $extra, $taxonomy_rewrite ); } -add_filter( 'rewrite_rules_array', 'bogo_rewrite_rules_array' ); +add_filter( 'rewrite_rules_array', 'bogo_rewrite_rules_array', 10, 1 ); function bogo_rewrite_rules_array( $rules ) { global $wp_rewrite; @@ -203,7 +225,8 @@ function bogo_rewrite_rules_array( $rules ) { $post_types = array_diff( (array) bogo_localizable_post_types(), - get_post_types( array( '_builtin' => true ) ) ); + get_post_types( array( '_builtin' => true ) ) + ); if ( empty( $post_types ) ) { return $rules; @@ -224,17 +247,20 @@ function bogo_rewrite_rules_array( $rules ) { $permastruct = preg_replace( '#^' . $wp_rewrite->front . '#', '/%lang%' . $wp_rewrite->front, - $permastruct ); + $permastruct + ); } else { $permastruct = preg_replace( '#^' . $wp_rewrite->root . '#', '/%lang%/' . $wp_rewrite->root, - $permastruct ); + $permastruct + ); } $rules = array_merge( bogo_generate_rewrite_rules( $permastruct, $post_type_obj->rewrite ), - $rules ); + $rules + ); if ( $post_type_obj->has_archive ) { if ( $post_type_obj->has_archive === true ) { @@ -271,7 +297,8 @@ function bogo_rewrite_rules_array( $rules ) { if ( $post_type_obj->rewrite['pages'] ) { $extra_rules = array( - "{$lang_regex}/{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$" => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&paged=$matches[2]' ); + "{$lang_regex}/{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$" => 'index.php?lang=$matches[1]&post_type=' . $post_type . '&paged=$matches[2]', + ); $rules = $extra_rules + $rules; } @@ -292,17 +319,20 @@ function bogo_rewrite_rules_array( $rules ) { $permastruct = preg_replace( '#^' . $wp_rewrite->front . '#', '/%lang%' . $wp_rewrite->front, - $permastruct ); + $permastruct + ); } else { $permastruct = preg_replace( '#^' . $wp_rewrite->root . '#', '/%lang%/' . $wp_rewrite->root, - $permastruct ); + $permastruct + ); } $rules = array_merge( bogo_generate_rewrite_rules( $permastruct, $tax_obj->rewrite ), - $rules ); + $rules + ); } } @@ -441,15 +471,20 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) ); } - if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) { + if ( EP_PAGES & $ep_mask + or EP_PERMALINK & $ep_mask ) { $rewrite = array_merge( $rewrite, array( $commentmatch => $commentquery ) ); - } elseif ( EP_ROOT & $ep_mask && get_option( 'page_on_front' ) ) { - $rewrite = array_merge( $rewrite, array( $rootcommentmatch => $rootcommentquery ) ); + } elseif ( EP_ROOT & $ep_mask + and get_option( 'page_on_front' ) ) { + $rewrite = array_merge( $rewrite, + array( $rootcommentmatch => $rootcommentquery ) + ); } if ( $endpoints ) { foreach ( (array) $ep_query_append as $regex => $ep ) { - if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) { + if ( $ep[0] & $ep_mask + or $ep[0] & $ep_mask_specific ) { $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $wp_rewrite->preg_index( $num_toks + 2 ); } @@ -461,14 +496,14 @@ function bogo_generate_rewrite_rules( $permalink_structure, $args = '' ) { $page = false; if ( strpos( $struct, '%postname%' ) !== false - || strpos( $struct, '%post_id%' ) !== false - || strpos( $struct, '%pagename%' ) !== false - || ( strpos( $struct, '%year%' ) !== false - && strpos( $struct, '%monthnum%' ) !== false - && strpos( $struct, '%day%' ) !== false - && strpos( $struct, '%hour%' ) !== false - && strpos( $struct, '%minute%' ) !== false - && strpos( $struct, '%second%' ) !== false ) ) { + or strpos( $struct, '%post_id%' ) !== false + or strpos( $struct, '%pagename%' ) !== false + or ( strpos( $struct, '%year%' ) !== false + and strpos( $struct, '%monthnum%' ) !== false + and strpos( $struct, '%day%' ) !== false + and strpos( $struct, '%hour%' ) !== false + and strpos( $struct, '%minute%' ) !== false + and strpos( $struct, '%second%' ) !== false ) ) { $post = true; if ( strpos( $struct, '%pagename%' ) !== false ) { diff --git a/wp-content/plugins/bogo/includes/user.php b/wp-content/plugins/bogo/includes/user.php index 063f82716e4690afc81093e540debb52c374c0ff..8b28cab01a4041cd73f863621cd29cf71d6852d9 100644 --- a/wp-content/plugins/bogo/includes/user.php +++ b/wp-content/plugins/bogo/includes/user.php @@ -1,14 +1,34 @@ <?php -/* Admin Bar */ +/* Toolbar (Admin Bar) */ -add_action( 'admin_bar_menu', 'bogo_admin_bar_menu' ); +add_action( 'admin_bar_init', 'bogo_admin_bar_init', 10, 0 ); + +function bogo_admin_bar_init() { + switch_to_locale( bogo_get_user_locale() ); +} + +add_action( 'wp_after_admin_bar_render', 'bogo_after_admin_bar_render', 10, 0 ); + +function bogo_after_admin_bar_render() { + if ( is_locale_switched() ) { + restore_current_locale(); + } +} + +add_action( 'admin_bar_menu', 'bogo_admin_bar_menu', 10, 1 ); function bogo_admin_bar_menu( $wp_admin_bar ) { $current_locale = bogo_get_user_locale(); - $current_language = bogo_get_language( $current_locale ); - if ( ! $current_language ) { + $available_languages = bogo_available_languages( array( + 'current_user_can_access' => true, + ) ); + + if ( isset( $available_languages[$current_locale] ) ) { + $current_language = $available_languages[$current_locale]; + unset( $available_languages[$current_locale] ); + } else { $current_language = $current_locale; } @@ -20,18 +40,15 @@ function bogo_admin_bar_menu( $wp_admin_bar ) { esc_html( $current_language ) ), ) ); - $available_languages = bogo_available_languages( array( - 'exclude' => array( $current_locale ), - 'exclude_enus_if_inactive' => true, - 'current_user_can_access' => true, - ) ); - foreach ( $available_languages as $locale => $lang ) { - $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); - $url = add_query_arg( - array( 'redirect_to' => urlencode( $_SERVER['REQUEST_URI'] ) ), - $url ); + array( + 'action' => 'bogo-switch-locale', + 'locale' => $locale, + 'redirect_to' => urlencode( $_SERVER['REQUEST_URI'] ), + ), + admin_url( 'profile.php' ) + ); $url = wp_nonce_url( $url, 'bogo-switch-locale' ); @@ -44,11 +61,11 @@ function bogo_admin_bar_menu( $wp_admin_bar ) { } } -add_action( 'admin_init', 'bogo_switch_user_locale' ); +add_action( 'admin_init', 'bogo_switch_user_locale', 10, 0 ); function bogo_switch_user_locale() { if ( empty( $_REQUEST['action'] ) - || 'bogo-switch-locale' != $_REQUEST['action'] ) { + or 'bogo-switch-locale' != $_REQUEST['action'] ) { return; } @@ -57,7 +74,7 @@ function bogo_switch_user_locale() { $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; if ( ! bogo_is_available_locale( $locale ) - || $locale == bogo_get_user_locale() ) { + or $locale == bogo_get_user_locale() ) { return; } @@ -99,13 +116,54 @@ function bogo_get_user_accessible_locales( $user_id ) { global $wpdb; $user_id = absint( $user_id ); + + if ( user_can( $user_id, 'bogo_access_all_locales' ) ) { + $locales = bogo_available_locales(); + + return $locales; + } + $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; - $locales = get_user_meta( $user_id, $meta_key ); + $locales = (array) get_user_meta( $user_id, $meta_key ); if ( bogo_is_enus_deactivated() ) { $locales = array_diff( $locales, array( 'en_US' ) ); } + $locales = bogo_filter_locales( $locales ); + + if ( empty( $locales ) ) { + $locales = array( bogo_get_default_locale() ); + } + return $locales; } + +add_filter( 'insert_user_meta', 'bogo_user_meta_filter', 10, 3 ); + +function bogo_user_meta_filter( $meta, $user, $update ) { + if ( user_can( $user, 'bogo_access_all_locales' ) ) { + return $meta; + } + + $locale = $meta['locale']; + + if ( empty( $locale ) ) { + $locale = bogo_get_default_locale(); + } + + $accessible_locales = bogo_filter_locales( + bogo_get_user_accessible_locales( $user->ID ) + ); + + if ( empty( $accessible_locales ) ) { + $locale = ''; + } elseif ( ! in_array( $locale, $accessible_locales, true ) ) { + $locale = $accessible_locales[0]; + } + + $meta['locale'] = $locale; + + return $meta; +} diff --git a/wp-content/plugins/bogo/includes/widgets.php b/wp-content/plugins/bogo/includes/widgets.php index 9494317afe74c3397ac36cb395dfeb25a4a4c32e..852f66b7741e83922a09d0259b3e56ef69d0cb5a 100644 --- a/wp-content/plugins/bogo/includes/widgets.php +++ b/wp-content/plugins/bogo/includes/widgets.php @@ -2,7 +2,7 @@ /* Language Switcher Widget */ -add_action( 'widgets_init', 'bogo_widgets_init' ); +add_action( 'widgets_init', 'bogo_widgets_init', 10, 0 ); function bogo_widgets_init() { register_widget( 'Bogo_Widget_Language_Switcher' ); @@ -19,7 +19,8 @@ class Bogo_Widget_Language_Switcher extends WP_Widget { WP_Widget::__construct( 'bogo_language_switcher', __( 'Language Switcher', 'bogo' ), - $widget_ops, $control_ops ); + $widget_ops, $control_ops + ); } function widget( $args, $instance ) { @@ -27,7 +28,8 @@ class Bogo_Widget_Language_Switcher extends WP_Widget { empty( $instance['title'] ) ? __( 'Language Switcher', 'bogo' ) : $instance['title'], - $instance, $this->id_base ); + $instance, $this->id_base + ); echo $args['before_widget']; @@ -49,7 +51,12 @@ class Bogo_Widget_Language_Switcher extends WP_Widget { function update( $new_instance, $old_instance ) { $instance = $old_instance; - $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) ); + + $new_instance = wp_parse_args( + (array) $new_instance, + array( 'title' => '' ) + ); + $instance['title'] = strip_tags( $new_instance['title'] ); return $instance; diff --git a/wp-content/plugins/bogo/license.txt b/wp-content/plugins/bogo/license.txt index 9a7e0ca0e7275d1b1f6793d6c7d14e502c1aeb61..d6f34fd22912c5c0649424e5481bcdbb2631c8d4 100644 --- a/wp-content/plugins/bogo/license.txt +++ b/wp-content/plugins/bogo/license.txt @@ -1,4 +1,4 @@ -Bogo WordPress Plugin, 2007-2018 Takayuki Miyoshi +Bogo WordPress Plugin, 2007-2020 Takayuki Miyoshi Bogo is distributed under the terms of the GNU GPL This program is free software; you can redistribute it and/or modify diff --git a/wp-content/plugins/bogo/readme.txt b/wp-content/plugins/bogo/readme.txt index 9f71d8bf5a0c19b8919e0ce21196231cc23c1402..284570b292672f55ac82390ccbda5e40a4961c0d 100644 --- a/wp-content/plugins/bogo/readme.txt +++ b/wp-content/plugins/bogo/readme.txt @@ -1,12 +1,12 @@ === Bogo === -Contributors: takayukister +Contributors: takayukister, itpixelz Tags: multilingual, localization, language, locale, admin -Requires at least: 4.9 -Tested up to: 4.9 -Stable tag: 3.2.1 +Requires at least: 5.3 +Tested up to: 5.4 +Stable tag: 3.3.2 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html -Donate link: https://pledgie.com/campaigns/17860 +Donate link: https://contactform7.com/donate/ A straight-forward multilingual plugin. No more double-digit custom DB tables or hidden HTML comments that could cause you headaches later on. @@ -18,49 +18,73 @@ Bogo is a straight-forward multilingual plugin for WordPress. The core of WordPress itself has the built-in localization capability so you can use the dashboard and theme in one language other than English. Bogo expands this capability to let you easily build a multilingual blog on a single WordPress install. -Here are some technical details for those interested. Bogo plugin assigns [one language per post](https://codex.wordpress.org/Multilingual_WordPress#Different_types_of_multilingual_plugins). It plays nice with WordPress – Bogo does not create any additional custom table on your database, unlike some other plugins in this category. This design makes Bogo a solid, reliable and conflict-free multilingual plugin. +Here are some technical details for those interested. Bogo plugin assigns [one language per post](https://wordpress.org/support/article/multilingual-wordpress/#different-types-of-multilingual-plugins). It plays nice with WordPress – Bogo does not create any additional custom table on your database, unlike some other plugins in this category. This design makes Bogo a solid, reliable and conflict-free multilingual plugin. -= Getting Started with Bogo = += Getting started with Bogo = -1. Install language files +1. Install language packs - First, make sure you have installed language files for all languages used in your site. If you have a localized version of WordPress installed, you should already have these files for that language. + First, install language packs for languages you use on the site. You can view and install language packs in the **Language Packs** screen (**Languages > Language Packs**). - If you don't have language files yet, you can install them via Bogo's admin page (Languages > Installed Languages). +2. Select your language for admin screen -2. Select your language for admin screen (dashboard) + Bogo lets each logged-in user select a language for their admin screen UI. Select a language from the menu on the [**Toolbar**](https://wordpress.org/support/article/administration-screens/#toolbar-keeping-it-all-together), or from the menu in the **Profile** screen (**Users > Your Profile**) if the **Toolbar** is invisible. - Bogo allows each user to select a language for his/her own WordPress admin screen. Logged-in users can switch languages from the drop-down menu on the Admin Bar. +3. Translate your posts and pages - If the Admin Bar is hidden, you can also switch language on your Profile page. + To create a translation post, go to the editor screen for the original post and find the **Language** box. Bogo does only make a copy of the post; translating the copied post is your task. -3. Translate posts and pages +4. Add language switcher widgets - You can translate posts and pages into the languages you have installed. + It would be useful for site visitors if you have a language switcher on your site. Bogo provides the **Language Switcher** widget in the **Widgets** screen (**Appearance > Widgets**). - WordPress saves the contents of each post or page as usual, but Bogo adds '_locale' post_meta data. The '_locale' holds the language code of the post. + You can also use the `[bogo]` shortcode to put a language switcher inside a post content. If you want to use this shortcode in your theme's template files, embed the following code into the template: -4. Add a language switcher to your site + `<?php echo do_shortcode( '[bogo]' ); ?>` - You will want to place a language switcher on your site that allows visitors to switch languages they see on the site. The easiest method is using the Language Switcher widget included in Bogo. += Privacy notices = - Bogo also provides a shortcode "[bogo]" to allow you to place a language switcher inside a post or page content by simply inserting [bogo]. To embed a language switcher directly into your theme's template file, use this shortcode as follows: +With the default configuration, this plugin, in itself, does not: - `<?php echo do_shortcode( '[bogo]' ); ?>` +* track users by stealth; +* write any user personal data to the database; +* send any data to external servers; +* use cookies. == Installation == 1. Upload the entire `bogo` folder to the `/wp-content/plugins/` directory. -1. Activate the plugin through the 'Plugins' menu in WordPress. +1. Activate the plugin through the **Plugins** screen (**Plugins > Installed Plugins**). == Screenshots == -1. You can switch your admin language in the Admin Bar. -1. The Language Post Box manages language and translations of the Post/Page. -1. In the Language Packs screen, you can install and manage language packs. +1. You can select your language in the **Toolbar**. +1. The **Language** box manages the post's translations. +1. The **Language Packs** screen lets you view and install language packs. == Changelog == += 3.3.2 = + +* User locale: Fixes several issues seen when you are logged-in as a non-Administrator role user. +* User locale: Renders the **Toolbar** in the logged-in user's locale even on the front side. +* Capabilities: Editor role users can now access the **Terms Translation** page, but higher level capabilities are required to edit some of translation items. +* Makes the `exclude_enus_if_inactive` option true by default. +* New filter hook: `bogo_get_short_name` + += 3.3.1 = + +* Block Editor: Displays a spinner icon when creating a translation post. +* Block Editor: Suggests posts in the same locale as the current post when making a text link or doing other operations in a block. +* Block Editor: Fixes the issue that character references appear in post titles. + += 3.3 = + +* Supports Block Editor. +* Adds the `short_name` option to `bogo_available_languages()`. +* Uses the post guid for the value of the `_original_post` post meta. +* Improves HTML markup of the language switcher. + = 3.2.1 = * Recalculates values in some WP query parameters in bogo_parse_query(). @@ -72,24 +96,3 @@ Here are some technical details for those interested. Bogo plugin assigns [one l * Adds a filter hook: bogo_terms_translation. * Introduces the Bogo_Terms_Translation_List_Table class. * Introduces the Bogo_Language_Packs_List_Table class. - -= 3.1.4 = - -* Ease restrictions on locale code to accept special cases like "pt_PT_ao90". -* Add screenreader accessibility text "(opens in a new window)" to target=blank links. - -= 3.1.3 = - -* Avoid warnings in cases there is empty $row_actions for some reason. - -= 3.1.2 = - -* Fixed: Warnings were shown in Menus admin page when there were no menu registered. - -= 3.1.1 = - -* Fixed: Suppress locale query on preview. - -= 3.1 = - -* Renovated markup and style around nation flags.