Making WordPress.org

Changeset 1838


Ignore:
Timestamp:
08/19/2015 02:08:28 PM (11 years ago)
Author:
ocean90
Message:

WP i18n teams: Show all translation contributors and show Slack username of translation editors.

fixes #996.
fixes #1191.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/css/i18n-teams.css

    r1163 r1838  
    116116        float: left;
    117117        width: 280px;           /* todo use flexbox to prog enhance this so that they fill the space. AF is good one to test */
    118         padding-bottom: 15px;
     118        margin-bottom: 15px;
    119119        list-style-type: none;
    120120}
     
    127127}
    128128.validators a {
     129        text-decoration: none;
     130}
     131.validators .user-name {
     132        font-size: 16px;
     133}
     134.validators .user-slack {
    129135        display: block;
    130         margin: 6px 0 2px;
    131         font-size: 16px;
    132         text-decoration: none;
     136        margin-top: .2em;
    133137}
    134138
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/views/locale-details.php

    r1800 r1838  
    6161<?php else : ?>
    6262        <ul class="validators">
    63                 <?php foreach ( $locale_data['validators'] as $validator ) : ?>
     63                <?php foreach ( $locale_data['validators'] as $validator ) :
     64                        ?>
    6465                        <li>
    65                                 <a href="https://profiles.wordpress.org/<?php echo esc_attr( $validator[2] ); ?>">
    66                                         <img src="https://secure.gravatar.com/avatar/<?php echo esc_attr( $validator[1] ); ?>?size=60" class="gravatar" alt="<?php echo esc_attr( $validator[0] ); ?>" />
    67                                         <?php echo esc_html( $validator[0] ); ?>
    68                                 </a>
     66                                <a class="user-avatar" href="https://profiles.wordpress.org/<?php echo esc_attr( $validator['nice_name'] ); ?>"><?php
     67                                        echo get_avatar( $validator['email'], 60 );
     68                                ?></a>
     69                                <a class="user-name" href="https://profiles.wordpress.org/<?php echo esc_attr( $validator['nice_name'] ); ?>"><?php
     70                                        echo esc_html( $validator['display_name'] );
     71                                ?></a>
     72                                <?php
     73                                if ( $validator['slack'] ) {
     74                                        printf( '<span class="user-slack">@%s on <a href="%s">Slack</a></span>', $validator['slack'], 'https://make.wordpress.org/chat/' );
     75                                }
     76                                ?>
    6977                        </li>
    7078                <?php endforeach; ?>
     
    7785<?php if ( empty( $locale_data['translators'] ) ) : ?>
    7886        <p><?php printf( __( '%s does not have any translators yet.', 'wporg' ), $locale->english_name ); ?></p>
    79 <?php else : ?>
    80         <ul>
    81                 <?php foreach ( $locale_data['translators'] as $username => $name ) : ?>
    82                         <li>
    83                                 <a href="https://profiles.wordpress.org/<?php echo esc_attr( $username ); ?>">
    84                                         <?php echo esc_html( $name ); ?>
    85                                 </a>
    86                         </li>
    87                 <?php endforeach; ?>
    88         </ul>
     87<?php else :?>
     88        <p>
     89                <?php
     90                $translators = array();
     91                foreach ( $locale_data['translators'] as $translator ) {
     92                        $translators[] = sprintf(
     93                                '<a href="https://profiles.wordpress.org/%s">%s</a>',
     94                                esc_attr( $translator['nice_name'] ),
     95                                esc_html( $translator['display_name'] )
     96                        );
     97                }
     98                echo wp_sprintf( '%l.', $translators );
     99                ?>
     100        </p>
    89101<?php endif; ?>
    90102
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wp-i18n-teams/wp-i18n-teams.php

    r1800 r1838  
    210210                }
    211211
    212                 $contributors = self::get_contributors( $locale );
     212                $contributors = $this->get_contributors( $locale );
    213213                $locale_data['validators'] = $contributors['validators'];
    214214                $locale_data['translators'] = $contributors['translators'];
    215215
    216216                return $locale_data;
     217        }
     218
     219        /**
     220         * Get the translators and validators for the given locale.
     221         *
     222         * @param GP_Locale $locale
     223         * @return array
     224         */
     225        public function get_contributors( $locale ) {
     226                $cache = wp_cache_get( 'contributors-data:' . $locale->wp_locale, 'wp-i18n-teams' );
     227                if ( false !== $cache ) {
     228                        return $cache;
     229                }
     230
     231                $contributors = array();
     232                $contributors['validators'] = $this->get_translation_editors( $locale );
     233                $contributors['translators'] = $this->get_translation_contributors( $locale );
     234
     235                wp_cache_set( 'contributors-data:' . $locale->wp_locale, $contributors, 'wp-i18n-teams', 2 * HOUR_IN_SECONDS );
     236
     237                return $contributors;
    217238        }
    218239
     
    249270
    250271        /**
    251          * Get the translators and validators for the given locale.
     272         * Get the translation editors for the given locale.
    252273         *
    253274         * @param GP_Locale $locale
    254275         * @return array
    255276         */
    256         public static function get_contributors( $locale ) {
    257                 require_once( API_WPORGPATH . 'core/credits/wp-credits.php' );
    258 
    259                 $credits = WP_Credits::factory( WP_CORE_LATEST_RELEASE, $locale );
    260                 $results = $credits->get_results();
    261 
    262                 $contributors = array(
    263                         'validators'  => ! empty( $results['groups']['validators']['data'] )  ? $results['groups']['validators']['data']  : array(),
    264                         'translators' => ! empty( $results['groups']['translators']['data'] ) ? $results['groups']['translators']['data'] : array(),
    265                 );
     277        private function get_translation_editors( $locale ) {
     278                global $wpdb;
     279
     280                $editors = array();
     281
     282                $subdomain = $wpdb->get_var( $wpdb->prepare( "SELECT subdomain FROM locales WHERE locale = %s", $locale->wp_locale ) );
     283                if ( ! $subdomain ) {
     284                        return $editors;
     285                }
     286
     287                $blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = '/'", "$subdomain.wordpress.org" ) );
     288                if ( ! $blog_id ) {
     289                        return $editors;
     290                }
     291
     292                $meta_key = $wpdb->base_prefix . intval( $blog_id ) . '_capabilities';
     293                $users = $wpdb->get_col( "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$meta_key' AND meta_value LIKE '%translation_editor%'" );
     294                if ( ! $users ) {
     295                        return $editors;
     296                }
     297
     298                $user_data = $wpdb->get_results( "SELECT ID, user_nicename, display_name, user_email FROM $wpdb->users WHERE ID IN (" . implode( ',', $users ) . ")" );
     299                foreach ( $user_data as $user ) {
     300                        if ( $user->display_name && $user->display_name !== $user->user_nicename ) {
     301                                $editors[ $user->user_nicename ] = array(
     302                                        'display_name' => $user->display_name,
     303                                        'email'        => $user->user_email,
     304                                        'nice_name'    => $user->user_nicename,
     305                                        'slack'        => self::get_slack_username( $user->ID ),
     306                                );
     307                        } else {
     308                                $editors[ $user->user_nicename ] = array(
     309                                        'display_name' => $user->user_nicename,
     310                                        'email'        => $user->user_email,
     311                                        'nice_name'    => $user->user_nicename,
     312                                        'slack'        => self::get_slack_username( $user->ID ),
     313                                );
     314                        }
     315                }
     316
     317                uasort( $editors, array( $this, '_sort_display_name_callback' ) );
     318
     319                return $editors;
     320        }
     321
     322        /**
     323         * Get the translation contributors for the given locale.
     324         *
     325         * @param GP_Locale $locale
     326         * @return array
     327         */
     328        private function get_translation_contributors( $locale ) {
     329                global $wpdb;
     330
     331                $contributors = array();
     332
     333                $users = $wpdb->get_col( $wpdb->prepare(
     334                        "SELECT DISTINCT user_id FROM translate_user_translations_count WHERE accepted > 0 AND locale = %s",
     335                        $locale->slug
     336                ) );
     337
     338                if ( ! $users ) {
     339                        $contributors;
     340                }
     341
     342                $user_data = $wpdb->get_results( "SELECT user_nicename, display_name, user_email FROM $wpdb->users WHERE ID IN (" . implode( ',', $users ) . ")" );
     343                foreach ( $user_data as $user ) {
     344                        if ( $user->display_name && $user->display_name !== $user->user_nicename ) {
     345                                $contributors[ $user->user_nicename ] = array(
     346                                        'display_name' => $user->display_name,
     347                                        'nice_name'    => $user->user_nicename,
     348                                );
     349                        } else {
     350                                $contributors[ $user->user_nicename ] = array(
     351                                        'display_name' => $user->user_nicename,
     352                                        'nice_name'    => $user->user_nicename,
     353                                );
     354                        }
     355                }
     356
     357                uasort( $contributors, array( $this, '_sort_display_name_callback' ) );
    266358
    267359                return $contributors;
     
    318410                }
    319411        }
     412
     413        /**
     414         * Get the Slack username for a .org user.
     415         *
     416         * @param int $user_id
     417         *
     418         * @return string
     419         */
     420        protected static function get_slack_username( $user_id ) {
     421                global $wpdb;
     422
     423                $data = $wpdb->get_var( $wpdb->prepare( "SELECT profiledata FROM slack_users WHERE user_id = %d", $user_id ) );
     424                if ( $data && ( $data = json_decode( $data, true ) ) ) {
     425                        return $data['name'];
     426                }
     427
     428                return '';
     429        }
     430
     431        public function _sort_display_name_callback( $a, $b ) {
     432                return strnatcasecmp( $a['display_name'], $b['display_name'] );
     433        }
    320434}
    321435
Note: See TracChangeset for help on using the changeset viewer.