Making WordPress.org

Changeset 2663


Ignore:
Timestamp:
03/01/2016 10:46:06 PM (11 years ago)
Author:
ocean90
Message:

Translate: Display contributors and editors on project pages of a locale.

See #1388.

Location:
sites/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/public_html/gp-templates-new/locale-project.php

    r2285 r2663  
    179179</div>
    180180
     181<div class="locale-project-contributors">
     182        <div class="locale-project-contributors-group locale-project-contributors-contributors">
     183                <h3>Translation Contributors</h3>
     184                <?php if ( $locale_contributors['contributors'] ) : ?>
     185                <ul>
     186                        <?php
     187                        foreach ( $locale_contributors['contributors'] as $contributor ) {
     188                                printf(
     189                                        '<li><a href="https://profiles.wordpress.org/%s/">%s %s</a></li>',
     190                                        $contributor->nicename,
     191                                        get_avatar( $contributor->email, 30 ),
     192                                        $contributor->display_name ? $contributor->display_name : $contributor->nicename
     193                                );
     194                        }
     195                        ?>
     196                </ul>
     197                <?php else : ?>
     198                        <p>None, be the first?</p>
     199                <?php endif; ?>
     200        </div>
     201        <div class="locale-project-contributors-group locale-project-contributors-editors">
     202                <h3>Translation Editors</h3>
     203                <?php if ( $locale_contributors['editors'] ) : ?>
     204                <ul>
     205                        <?php
     206                        foreach ( $locale_contributors['editors'] as $editor ) {
     207                                printf(
     208                                        '<li><a href="https://profiles.wordpress.org/%s/">%s %s</a></li>',
     209                                        $editor->nicename,
     210                                        get_avatar( $editor->email, 40 ),
     211                                        $editor->display_name ? $editor->display_name : $editor->nicename
     212                                );
     213                        }
     214                        ?>
     215                </ul>
     216                <?php else : ?>
     217                        <p>None, be the first?</p>
     218                <?php endif; ?>
     219        </div>
     220</div>
     221
    181222<script>
    182223        jQuery( document ).ready( function( $ ) {
  • sites/trunk/translate.wordpress.org/public_html/gp-templates-new/style.css

    r2660 r2663  
    344344.project-status:before,
    345345.project-status:after,
     346.locale-project-contributors:before,
     347.locale-project-contributors:after,
    346348.locales:before,
    347349.locales:after {
    … …  
    355357.project-box-header:after,
    356358.project-status:after,
     359.locale-project-contributors:after,
    357360.locales:after {
    358361        clear: both;
    … …  
    12791282        display: none !important;
    12801283}
     1284
     1285.locale-project-contributors-group {
     1286        width: 50%;
     1287        float: left;
     1288}
     1289
     1290.locale-project-contributors-group ul {
     1291        padding: 0;
     1292        margin: 0;
     1293        list-style: none;
     1294}
     1295
     1296.locale-project-contributors-group li {
     1297        margin: 0 0 10px;
     1298}
     1299
     1300.locale-project-contributors-group li img {
     1301        vertical-align: middle;
     1302        margin-right: 10px;
     1303}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/locale.php

    r2181 r2663  
    167167                        $variants = $this->get_locale_variants( $locale_slug, array( $sub_project->id ) );
    168168                }
     169
     170                $locale_contributors = $this->get_locale_contributors( $sub_project, $locale_slug, $set_slug );
    169171
    170172                $this->tmpl( 'locale-project', get_defined_vars() );
    … …  
    258260
    259261                return $slugs;
     262        }
     263
     264        /**
     265         * Retrieves contributors of a project.
     266         *
     267         * @param GP_Project $project     A GlotPress project.
     268         * @param string     $locale_slug Slug of the locale.
     269         * @param string     $set_slug    Slug of the translation set.
     270         * @return array Contributors.
     271         */
     272        private function get_locale_contributors( $project, $locale_slug, $set_slug ) {
     273                global $wpdb;
     274
     275                $locale_contributors = array(
     276                        'editors'      => array(),
     277                        'contributors' => array(),
     278                );
     279
     280                // Get the translation editors of the project.
     281                $editors = $wpdb->get_col( $wpdb->prepare( "
     282                        SELECT
     283                                `user_id`
     284                        FROM {$wpdb->wporg_translation_editors}
     285                        WHERE
     286                                `project_id` = %d
     287                                AND `locale` = %s
     288                ", $project->id, $locale_slug ) );
     289
     290                // Get the names of the translation editors.
     291                foreach ( $editors as $editor_id ) {
     292                        $user = get_user_by( 'id', $editor_id );
     293                        if ( ! $user ) {
     294                                continue;
     295                        }
     296
     297                        $locale_contributors['editors'][ $editor_id ] = (object) array(
     298                                'nicename'     => $user->user_nicename,
     299                                'display_name' => $this->_encode( $user->display_name ),
     300                                'email'        => $user->user_email,
     301                        );
     302                }
     303                unset( $editors );
     304
     305                // Get the contributors of the project.
     306                $contributors = array();
     307
     308                // In case the project has a translation set, like /wp-themes/twentysixteen.
     309                $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $set_slug, $locale_slug );
     310                if ( $translation_set ) {
     311                        $contributors = array_merge(
     312                                $contributors,
     313                                $this->get_locale_contributors_by_translation_set( $translation_set )
     314                        );
     315                }
     316
     317                // Check if the project has sub-projects, like /wp-plugins/wordpress-importer.
     318                $sub_projects = $wpdb->get_col( $wpdb->prepare( "
     319                        SELECT id
     320                        FROM {$wpdb->gp_projects}
     321                        WHERE parent_project_id = %d
     322                ", $project->id ) );
     323
     324                foreach ( $sub_projects as $sub_project ) {
     325                        $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $sub_project, $set_slug, $locale_slug );
     326                        if ( ! $translation_set ) {
     327                                continue;
     328                        }
     329
     330                        $contributors = array_merge(
     331                                $contributors,
     332                                $this->get_locale_contributors_by_translation_set( $translation_set )
     333                        );
     334                }
     335
     336                // Get the names of the contributors.
     337                foreach ( $contributors as $contributor_id ) {
     338                        if ( isset( $locale_contributors['editors'][ $contributor_id ] ) ) {
     339                                continue;
     340                        }
     341
     342                        if ( isset( $locale_contributors['contributors'][ $contributor_id ] ) ) {
     343                                continue;
     344                        }
     345
     346                        $user = get_user_by( 'id', $contributor_id );
     347                        if ( ! $user ) {
     348                                continue;
     349                        }
     350
     351                        $locale_contributors['contributors'][ $contributor_id ] = (object) array(
     352                                'nicename'     => $user->user_nicename,
     353                                'display_name' => $this->_encode( $user->display_name ),
     354                                'email'        => $user->user_email,
     355                        );
     356                }
     357                unset( $contributors );
     358
     359                return $locale_contributors;
     360        }
     361
     362        /**
     363         * Retrieves contributors of a translation set.
     364         *
     365         * @param GP_Translation_Set $translation_set A translation set.
     366         * @return array List of user IDs.
     367         */
     368        private function get_locale_contributors_by_translation_set( $translation_set ) {
     369                global $wpdb;
     370
     371                $user_ids = $wpdb->get_col( $wpdb->prepare( "
     372                        SELECT DISTINCT( `user_id` )
     373                        FROM `{$wpdb->gp_translations}`
     374                        WHERE
     375                                `translation_set_id` = %d
     376                                AND `user_id` IS NOT NULL AND `user_id` != 0
     377                                AND `status` <> 'rejected'
     378                                AND `date_modified` > %s
     379                ", $translation_set->id, date( 'Y-m-d', time() - YEAR_IN_SECONDS ) ) );
     380
     381                return $user_ids;
    260382        }
    261383
    … …  
    620742                return strcasecmp( $a->name, $b->name );
    621743        }
     744
     745        private function _encode( $raw ) {
     746                $raw = mb_convert_encoding( $raw, 'UTF-8', 'ASCII, JIS, UTF-8, Windows-1252, ISO-8859-1' );
     747                return ent2ncr( htmlspecialchars_decode( htmlentities( $raw, ENT_NOQUOTES, 'UTF-8' ), ENT_NOQUOTES ) );
     748        }
    622749}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/wp-plugins.php

    r2530 r2663  
    264264                }
    265265
    266 
    267266                $labels = array_keys( $data );
    268267                array_pop( $labels );
    … …  
    311310                $json = file_get_contents( "https://api.wordpress.org/translations/plugins/1.0/?slug={$project_slug}", null, $http_context );
    312311                $language_packs = $json && '{' == $json[0] ? json_decode( $json ) : null;
    313 
    314312
    315313                $this->tmpl( 'projects-wp-plugins-language-packs', get_defined_vars() );
Note: See TracChangeset for help on using the changeset viewer.