Making WordPress.org

Ticket #1388: 1388.diff

File 1388.diff, 4.7 KB (added by akirk, 10 years ago)
  • gp-plugins/wporg-project-stats.php

     
    144144                }
    145145        }
    146146
     147        function get_project_contributors( $project_id, $locale = false, $locale_slug = false ) {
     148                global $gpdb;
     149                $where_locale = '';
     150
     151                if ( $locale !== false ) {
     152                        $where_locale .= $gpdb->prepare( ' AND ts.`locale` = %s', $locale );
     153                }
     154
     155                if ( $locale_slug !== false ) {
     156                        $where_locale .= $gpdb->prepare( ' AND ts.`slug` = %s', $slug );
     157                }
     158
     159                $sql = $gpdb->prepare( '
     160                        SELECT ts.`locale`, ts.`slug` AS `locale_slug`, t.`user_id`, COUNT(*) AS `translation_count`
     161                        FROM `' . $gpdb->translations .'` t, `'. $gpdb->translation_sets . '` ts
     162                        WHERE t.`translation_set_id` = ts.`id` AND t.`user_id` IS NOT NULL AND ts.`project_id` = %d
     163                        ' . $where_locale . '
     164                        GROUP BY ts.`locale`, ts.`slug`, t.`user_id`
     165                ', $project_id);
     166
     167                $result = array();
     168                foreach ( $gpdb->get_results( $sql ) as $row ) {
     169                        $locale_key = $row->locale;
     170                        if ( 'default' != $row->locale_slug ) {
     171                                $locale_key = $row->locale . '/' . $row->locale_slug;
     172                        }
     173
     174                        if ( !isset( $result[ $locale_key ] ) ) {
     175                                $result[ $locale_key ] = array();
     176                        }
     177                        $result[ $locale_key ][] = $row;
     178                }
     179
     180                return $result;
     181        }
     182
    147183}
    148184GP::$plugins->wporg_project_stats = new GP_WPorg_Project_Stats;
    149185
  • gp-templates/projects-wp-plugins.php

     
    1919?>
    2020
    2121<div class="project-header">
    22         <p class="project-description"><?php echo apply_filters( 'project_description', $project->description, $project ); ?></p>
     22        <p class="project-description">
     23                <?php echo apply_filters( 'project_description', $project->description, $project ); ?><br/>
     24                <a href="" id="project-contributors-link">Display Contributors</a>
     25        </p>
    2326
    2427        <div class="project-box">
    2528                <div class="project-box-header">
     
    3235                        </ul>
    3336                </div>
    3437        </div>
     38
     39        <p id="project-contributors">
     40                <?php
     41                foreach ( GP::$plugins->wporg_project_stats->get_project_contributors( $project->id ) as $locale => $contributors ) :
     42                        $gp_locale = GP_Locales::by_slug( $locale );
     43
     44                        $set_slug  = 'default';
     45
     46                        // Variants (de/formal for example) don't have GP_Locales in this context
     47                        if ( ! $gp_locale && ( list( $base_locale_slug, $set_slug ) = explode( '/', $locale_slug ) ) ) :
     48                                $gp_locale = clone GP_Locales::by_slug( $base_locale_slug );
     49
     50                                // Just append it for now..
     51                                $gp_locale->wp_locale .= '/' . $set_slug;
     52                                $gp_locale->english_name .=  ' (' . ucfirst( $set_slug ) . ')';
     53                        endif;
     54
     55                        if ( ! $gp_locale || ! $gp_locale->wp_locale ) :
     56                                continue;
     57                        endif;
     58                ?>
     59                        <span title="<?php echo esc_attr( $gp_locale->wp_locale );?>">
     60                                <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>"><?php
     61                                        echo esc_html( $gp_locale->english_name );
     62                                ?></a>:
     63                        </span>
     64                <?php $t = ''; foreach ( $contributors as $contributor ) {
     65                        $user = GP::$user->get( $contributor->user_id );
     66                        echo $t;
     67                        $t = ', ';
     68                        ?><span title="<?php printf( _n( '%d translation', '%d translations', $contributor->translation_count ), $contributor->translation_count ); ?>"><?php echo $user->user_login; ?></span><?php
     69                } ?><br/>
     70                <?php endforeach; ?>
     71        </p>
     72
     73
    3574</div>
    3675
    3776<div class="stats-table">
     
    113152
    114153<script type="text/javascript">
    115154jQuery( function( $ ) {
     155        $( '#project-contributors-link' ).on( 'click', function() {
     156                $( '#project-contributors' ).toggle();
     157                return false;
     158        });
    116159        $( '#stats-table' ).tablesorter( {
    117160                textExtraction: function( node ) {
    118161                        var cellValue = $( node ).text(),
  • gp-templates/style.css

     
    540540        line-height: 1.3;
    541541}
    542542
    543 .projects .project-description {
     543.projects .project-description,
     544.projects #project-contributors {
    544545        font-size: 13px;
    545546}
    546547
     
    632633        margin-bottom: 30px;
    633634}
    634635
    635 .project-header .project-description {
     636.project-header .project-description,
     637.project-header #project-contributors {
    636638        float: left;
    637639        width: 100%;
    638640        max-width: 520px;
     
    639641        margin-top: 20px;
    640642}
    641643
     644.project-header #project-contributors {
     645        display: none;
     646}
     647
    642648.project-header .project-box {
    643649        position: relative;
    644650        float: right;
     
    870876                width: 100%;
    871877        }
    872878
    873         .project-header .project-description {
     879        .project-header .project-description,
     880        .project-header #project-contributors {
    874881                float: none;
    875882        }
    876883