Making WordPress.org

Changeset 12274


Ignore:
Timestamp:
11/23/2022 06:22:00 PM (4 years ago)
Author:
amieiro
Message:

Translate: Add mentions to comment box and Disable only Feedback <summary> events

​https://github.com/GlotPress/gp-translation-helpers/pull/113
​https://github.com/GlotPress/gp-translation-helpers/pull/143

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers-assets/templates/translation-discussion-comments.php

    r12205 r12274  
    185185        ?>
    186186</div><!-- .discussion-wrapper -->
     187<script>       
     188        jQuery(function( e, mentions ) {
     189                var mentionsList = '<?php echo wp_json_encode( $mentions_list ); ?>';
     190                var jetpackMentionsData = JSON.parse( mentionsList );
     191                if( jetpackMentionsData.length > 0 ) {
     192                        jQuery( 'textarea#comment' ).mentions( jetpackMentionsData );
     193                }
     194        });
     195</script>
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/helpers/helper-translation-discussion.php

    r12205 r12274  
    267267                }
    268268
     269                // phpcs:ignore WordPress.Security.NonceVerification.Missing
     270                $locale_exists = isset( $_POST['meta']['locale'] ) && ! empty( $this->sanitize_comment_locale( $_POST['meta']['locale'] ) );
     271
     272                // phpcs:ignore WordPress.Security.NonceVerification.Missing
     273                $locale_slug = $locale_exists ? $_POST['meta']['locale'] : null;
     274
     275                $set_slug = $locale_exists ? 'default' : null;
     276
    269277                // We were able to gather all information, let's put it in the cache.
    270                 $cache[ $post->ID ] = GP_Route_Translation_Helpers::get_permalink( $project->path, $original_id );
     278                $cache[ $post->ID ] = GP_Route_Translation_Helpers::get_permalink( $project->path, $original_id, $set_slug, $locale_slug );
    271279
    272280                return $cache[ $post->ID ];
    … …  
    562570                remove_action( 'comment_form_top', 'rosetta_comment_form_support_hint' );
    563571
    564                 $post   = self::maybe_get_temporary_post( self::get_shadow_post_id( $this->data['original_id'] ) );
     572                $post          = self::maybe_get_temporary_post( self::get_shadow_post_id( $this->data['original_id'] ) );
     573                $mentions_list = apply_filters( 'gp_mentions_list', array(), $comments, $this->data['locale_slug'], $this->data['original_id'] );
     574
    565575                $output = gp_tmpl_get_output(
    566576                        'translation-discussion-comments',
    … …  
    574584                                'project'              => $this->data['project'],
    575585                                'translation_set_slug' => $this->data['translation_set_slug'],
     586                                'mentions_list'        => $mentions_list,
     587
    576588                        ),
    577589                        $this->assets_dir . 'templates'
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-wporg-customizations.php

    r12003 r12274  
    4444                                2
    4545                        );
     46
     47                        add_filter( 'jetpack_mentions_should_load_ui', '__return_true' );
     48                        add_filter(
     49                                'jetpack_mentions_allowed_post_types',
     50                                function( $post_types ) {
     51                                        $post_types[] = Helper_Translation_Discussion::POST_TYPE;
     52                                        return $post_types;
     53                                }
     54                        );
     55
    4656                }
    4757        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/includes/class-wporg-notifications.php

    r12063 r12274  
    9595                                2
    9696                        );
     97                        add_filter(
     98                                'gp_mentions_list',
     99                                function( $result, $comments, $locale, $original_id ) {
     100                                        $validator_email_addresses  = ( $locale && $original_id ) ? WPorg_GlotPress_Notifications::get_validator_details_for_original_id( $locale, $original_id ) : array();
     101                                        $commenters_email_addresses = array_values( GP_Notifications::get_commenters_email_addresses( $comments ) );
     102
     103                                        // Remove commenter email if it already exists as a GTE.
     104                                        $commenters_email_addresses = array_filter(
     105                                                $commenters_email_addresses,
     106                                                function( $commenter_email ) use ( $validator_email_addresses ) {
     107                                                        return ( ! in_array( $commenter_email, array_column( $validator_email_addresses, 'email' ) ) );
     108                                                }
     109                                        );
     110
     111                                        $commenters_email_role = array_map(
     112                                                function( $commenter_email ) {
     113                                                        return(
     114                                                        array(
     115                                                                'role'  => 'commenter',
     116                                                                'email' => $commenter_email,
     117                                                        )
     118                                                        );
     119                                                },
     120                                                $commenters_email_addresses
     121                                        );
     122
     123                                        $all_email_addresses = array_merge(
     124                                                $validator_email_addresses,
     125                                                $commenters_email_role
     126                                        );
     127
     128                                        $current_user       = wp_get_current_user();
     129                                        $current_user_email = $current_user->user_email;
     130
     131                                        // Find all instances of the logged_in user in the array
     132                                        $user_search_result = array_keys( array_column( $all_email_addresses, 'email' ), $current_user_email );
     133
     134                                        if ( false !== $user_search_result ) {
     135                                                foreach ( $user_search_result as $index ) {
     136                                                        unset( $all_email_addresses[ $index ] );
     137                                                }
     138                                                $all_email_addresses = array_values( $all_email_addresses );
     139                                        }
     140
     141                                        $users = array_map(
     142                                                function( $mentionable_user ) {
     143                                                        $email = $mentionable_user;
     144                                                        $role  = '';
     145                                                        if ( is_array( $mentionable_user ) ) {
     146                                                                $email = $mentionable_user['email'];
     147                                                                $role  = ! ( 'commenter' === $mentionable_user['role'] ) ? ' - ' . $mentionable_user['role'] : '';
     148                                                        }
     149
     150                                                                $user = get_user_by( 'email', $email );
     151                                                                return array(
     152                                                                        'ID'            => $user->ID,
     153                                                                        'user_login'    => $user->user_login,
     154                                                                        'user_nicename' => $user->user_nicename . $role,
     155                                                                        'display_name'  => '',
     156                                                                        'source'        => array( 'translators' ),
     157                                                                        'image_URL'     => get_avatar_url( $user->ID ),
     158                                                                );
     159                                                },
     160                                                $all_email_addresses
     161                                        );
     162                                                        return $users;
     163                                },
     164                                10,
     165                                4
     166                        );
    97167                }
    98168        }
    … …  
    118188                return array_merge( $email_addresses, self::get_clpte_email_addresses_by_project( $original->id ) );
    119189        }
     190
     191        /**
     192         * Gets the email addresses and roles(GTE/PTE/CLPTE) of all project validators: GTE, PTE and CLPTE.
     193         *
     194         * @since 0.0.2
     195         *
     196         * @param string $locale  The locale for the translation.
     197         * @param int    $original_id  The original id for the string.
     198         *
     199         * @return array    The emails and roles(GTE/PTE/CLPTE) of the validators.
     200         */
     201        public static function get_validator_details_for_original_id( $locale, $original_id ): array {
     202                $gtes_email_and_role = array_map(
     203                        function( $gte_email ) {
     204                                return array(
     205                                        'role'  => 'GTE',
     206                                        'email' => $gte_email,
     207                                );
     208                        },
     209                        self::get_gte_email_addresses( $locale )
     210                );
     211
     212                $ptes_email_and_role = array_map(
     213                        function( $pte_email ) {
     214                                return array(
     215                                        'role'  => 'GTE',
     216                                        'email' => $pte_email,
     217                                );
     218                        },
     219                        self::get_pte_email_addresses_by_project_and_locale( $original_id, $locale )
     220                );
     221
     222                $clptes_email_and_role = array_map(
     223                        function( $clpte_email ) {
     224                                return array(
     225                                        'role'  => 'GTE',
     226                                        'email' => $clpte_email,
     227                                );
     228                        },
     229                        self::get_clpte_email_addresses_by_project( $original_id )
     230                );
     231
     232                return array_merge(
     233                        array_merge( $gtes_email_and_role, $ptes_email_and_role ),
     234                        $clptes_email_and_role
     235                );
     236        }
     237
    120238
    121239        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/gp-translation-helpers/js/reject-feedback.js

    r12205 r12274  
    2323
    2424                        // Remove click event added to <summary> by wporg-gp-customizations plugin
    25                         $( $gp.editor.table ).off( 'click', 'summary' );
     25                        $( $gp.editor.table ).off( 'click', 'summary.feedback-summary' );
    2626
    2727                        $( '#bulk-actions-toolbar-top .button, #bulk-actions-toolbar-bottom .button' ).click(
Note: See TracChangeset for help on using the changeset viewer.