Making WordPress.org

Ticket #1388: 1388.9.diff

File 1388.9.diff, 11.9 KB (added by akirk, 10 years ago)

Fix "last" typo

  • gp-templates/style.css

     
    10241024        content: "\f142";
    10251025}
    10261026
     1027#translator-stats {
     1028        display: none;
     1029}
     1030
     1031#translator-stats li.filter span {
     1032        cursor: pointer;
     1033        border-bottom: 1px dotted #dfdfdf;
     1034}
     1035
     1036#translator-stats li.filter span:hover {
     1037        border-bottom-color: #d54e21;
     1038}
     1039
     1040#translators-table thead th.locale {
     1041        width: auto;
     1042        border-top: 0;
     1043        border-left: 0;
     1044        float: none;
     1045}
     1046
     1047#translators-table thead th.recent-translations {
     1048        white-space: nowrap;
     1049}
     1050
    10271051.sort-bar {
    10281052        float: right;
    10291053        margin: -30px 0 5px 5px;
     
    10311055        padding: 5px;
    10321056        border: 1px solid #dfdfdf;
    10331057        border-top: none;
    1034 }
    1035  No newline at end of file
     1058}
  • gp-templates/translators-project.php

     
     1<?php
     2$edit_link = gp_link_project_edit_get( $project, __( '(edit)' ) );
     3
     4gp_title( sprintf( __( 'Translators &lt; %s &lt; GlotPress' ), esc_html( $project->name ) ) );
     5gp_breadcrumb_project( $project );
     6
     7wp_enqueue_script( 'common' );
     8wp_enqueue_script( 'tablesorter' );
     9
     10$translators_recent = $translators_total = $translators_minimum10 = $translators_minimum100 = 0;
     11foreach ( $project_translators as $locale_slug => $translators ) {
     12        foreach ( $translators as $translator_id => $translations ) {
     13                $translators_total += 1;
     14
     15                if ( $translations->recent > 0 ) {
     16                        $translators_recent += 1;
     17                }
     18                if ( $translations->count >= 10 ) {
     19                        $translators_minimum10 += 1;
     20                }
     21                if ( $translations->count >= 100 ) {
     22                        $translators_minimum100 += 1;
     23                }
     24        }
     25}
     26
     27gp_tmpl_header();
     28?>
     29
     30<div class="project-header">
     31        <p class="project-description"><?php echo apply_filters( 'project_description', $project->description, $project ); ?></p>
     32        <div class="project-description">
     33                <a href="" id="translator-stats-toggle"><?php _e( 'Show translator stats &raquo;' ); ?></a>
     34
     35                <ul id="translator-stats">
     36                        <li><?php printf( _n( '%d people contributed translations to this project.', '%d people contributed translations to this project', $translators_total ), $translators_total ); ?></li>
     37
     38                        <?php if ( $translators_recent > 0 ): ?>
     39                                <li class="filter" data-filter="recent" data-filter-name="<?php echo esc_attr( __( 'only people who translated in the last 12 months' ) ); ?>"><span><?php printf( _n( '%d person contributed translations in the last 12 months.', '%d people contributed translations in the last 12 months.', $translators_recent ), $translators_recent ); ?></span></li>
     40                        <?php endif; ?>
     41
     42                        <?php if ( $translators_minimum10 > 0 ): ?>
     43                                <li class="filter" data-filter="minimum10" data-filter-name="<?php echo esc_attr( __( 'only people who contributed at least 10 translations' ) ); ?>"><span><?php printf( _n( '%d person contributed at least 10 translations.', '%d people contributed at least 10 translations.', $translators_minimum10 ), $translators_minimum10 ); ?></span></li>
     44                        <?php endif; ?>
     45
     46                        <?php if ( $translators_minimum100 > 0 ): ?>
     47                                <li class="filter" data-filter="minimum100" data-filter-name="<?php echo esc_attr( __( 'only people who contributed at least 100 translations' ) ); ?>"><span><?php printf( _n( '%d person contributed at least 100 translations.', '%d people contributed at least 100 translations.', $translators_minimum100 ), $translators_minimum100 ); ?></span></li>
     48                        <?php endif; ?>
     49
     50                </ul>
     51        </div>
     52
     53
     54        <div class="project-box">
     55                <div class="project-box-header">
     56                        <div class="project-icon">
     57                                <?php echo $project->icon; ?>
     58                        </div>
     59
     60                        <ul class="project-meta">
     61                                <li class="project-name"><?php echo $project->name; ?> <?php echo $edit_link; ?></li>
     62                        </ul>
     63                </div>
     64        </div>
     65</div>
     66
     67<div class="stats-table">
     68        <table id="translators-table" class="table">
     69                <thead>
     70                        <tr>
     71                                <th class="locale"><?php echo _( 'Locale' ); ?> <span class="filter-name"></span></th>
     72                                <th class="username"><?php echo _( 'Username' ); ?></th>
     73                                <th class="translations"><?php echo _( 'Translations' ); ?></th>
     74                                <th class="recent-translations"><?php echo _( 'Last 12 months' ); ?></th>
     75                        </tr>
     76                </thead>
     77                <tbody>
     78                        <?php
     79                        foreach ( $project_translators as $locale_slug => $translators ) :
     80                                $gp_locale = GP_Locales::by_slug( $locale_slug );
     81
     82                                $set_slug  = 'default';
     83
     84                                // Variants (de/formal for example) don't have GP_Locales in this context
     85                                if ( ! $gp_locale && ( list( $base_locale_slug, $set_slug ) = explode( '/', $locale_slug ) ) ) :
     86                                        $gp_locale = clone GP_Locales::by_slug( $base_locale_slug );
     87
     88                                        // Just append it for now..
     89                                        $gp_locale->wp_locale .= '/' . $set_slug;
     90                                        $gp_locale->english_name .=  ' (' . ucfirst( $set_slug ) . ')';
     91                                endif;
     92
     93                                if ( ! $gp_locale || ! $gp_locale->wp_locale ) :
     94                                        continue;
     95                                endif;
     96
     97                                foreach ( $translators as $translator_id => $translations ):
     98                                        $user = GP::$user->get( $translator_id );
     99                                        ?>
     100                                        <tr>
     101                                                <th title="<?php echo esc_attr( $gp_locale->wp_locale ); ?>">
     102                                                        <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>">
     103                                                                <?php echo esc_html( $gp_locale->english_name ); ?>
     104                                                        </a>
     105                                                </th>
     106                                                <td><?php echo $user->user_login; ?></td>
     107                                                <td><?php echo $translations->count; ?></td>
     108                                                <td><?php echo $translations->recent; ?></td>
     109                                        </tr>
     110                                <?php endforeach; ?>
     111                        <?php endforeach; ?>
     112                </tbody>
     113        </table>
     114</div>
     115
     116<script type="text/javascript">
     117jQuery( function( $ ) {
     118        $( '#translators-table' ).tablesorter( {
     119                textExtraction: function( node ) {
     120                        var cellValue = $( node ).text(),
     121                                sortValue = $( node ).data( 'sortValue' );
     122
     123                        return ( undefined !== sortValue ) ? sortValue : cellValue;
     124                }
     125        });
     126
     127        $( '#translator-stats-toggle' ).on( 'click', function() {
     128                $( '#translator-stats' ).toggle();
     129                return false;
     130        });
     131
     132        $( '#translator-stats li.filter' ).on( 'click', function() {
     133                var $this = $( this ), filter = $this.data( 'filter' );
     134
     135
     136                if (
     137                        $this.hasClass( 'active' )
     138                        || $( '#translator-stats li.filter.active' ).length
     139                ) {
     140                        $( '#translators-table thead th.locale span.filter-name' ).text( '' );
     141                        $( '#translators-table tbody tr').each( function() {
     142                                this.style.display = 'table-row';
     143                        });
     144                }
     145
     146                if ( $this.hasClass( 'active' ) ) {
     147                        $this.removeClass( 'active' );
     148                        return;
     149                }
     150                $( '#translator-stats li.filter.active' ).removeClass( 'active' );
     151
     152                $this.addClass( 'active' );
     153                $( '#translators-table thead th.locale span.filter-name' ).text( '(' + $this.data( 'filter-name' ) + ')' );
     154
     155                if ( filter === 'recent' ) {
     156                        $( '#translators-table tbody tr').each( function() {
     157                                this.style.display = parseInt( $( this ).find( 'td' ).eq( 2 ).text(), 10 ) > 0 ?
     158                                        'table-row' : 'none';
     159                        });
     160                } else if ( filter === 'minimum10' ) {
     161                        $( '#translators-table tbody tr').each( function() {
     162                                this.style.display = parseInt( $( this ).find( 'td' ).eq( 1 ).text(), 10 ) >= 10 ?
     163                                        'table-row' : 'none';
     164                        });
     165                } else if ( filter === 'minimum100' ) {
     166                        $( '#translators-table tbody tr').each( function() {
     167                                this.style.display = parseInt( $( this ).find( 'td' ).eq( 1 ).text(), 10 ) >= 100 ?
     168                                        'table-row' : 'none';
     169                        });
     170                }
     171                return false;
     172        })
     173});
     174</script>
     175
     176<?php gp_tmpl_footer();
  • gp-plugins/wporg-routes/routes/wp-plugins.php

    Property changes on: gp-templates/translators-project.php
    ___________________________________________________________________
    Added: svn:executable
    ## -0,0 +1 ##
    +*
    \ No newline at end of property
     
    8888
    8989                $this->tmpl( 'projects-wp-plugins', get_defined_vars() );
    9090        }
     91
     92        /**
     93         * Get the translators of a project including all sub-projects
     94         *
     95         * @param  integer $project_id           project id
     96         * @return object                        translators of the project and its sub-projects
     97         */
     98
     99        private function get_total_project_translators( $project_id ) {
     100                global $gpdb;
     101
     102                // query all subprojects
     103                $projects = $gpdb->get_results( $gpdb->prepare( "
     104                        SELECT id
     105                        FROM {$gpdb->prefix}projects
     106                        WHERE parent_project_id = %d
     107                ", $project_id ) );
     108
     109                // also include the main project in the count
     110                $projects[] = (object) array(
     111                        'id' => $project_id,
     112                );
     113
     114                $project_translators = array();
     115                foreach ( $projects as $project ) {
     116
     117                        foreach( $this->get_project_translators( $project->id ) as $row ) {
     118                                $locale_key = $row->locale;
     119                                if ( 'default' != $row->locale_slug ) {
     120                                        $locale_key = $row->locale . '/' . $row->locale_slug;
     121                                }
     122
     123                                if ( ! isset( $project_translators[ $locale_key ] ) ) {
     124                                        $project_translators[ $locale_key ] = array();
     125                                }
     126
     127                                if ( ! isset( $project_translators[ $locale_key ][ $row->user_id ] ) ) {
     128                                        $project_translators[ $locale_key ][ $row->user_id ] = (object) array(
     129                                                'count' => 0,
     130                                                'recent' => 0,
     131                                        );
     132                                }
     133
     134                                // sum up translations per user over all (sub-)projects
     135                                $project_translators[ $locale_key ][ $row->user_id ]->count += $row->translation_count;
     136                                $project_translators[ $locale_key ][ $row->user_id ]->recent += $row->recent_translation_count;
     137                        }
     138                }
     139
     140                return $project_translators;
     141        }
     142
     143        /**
     144         * Get the translators of a specific project
     145         *
     146         * @param  integer $project_id           project id
     147         * @return object                        translators of the project
     148         */
     149        private function get_project_translators( $project_id ) {
     150                global $gpdb;
     151
     152                $sql = $gpdb->prepare( '
     153                        SELECT ts.`locale`, ts.`slug` AS `locale_slug`, t.`user_id`, COUNT(*) AS `translation_count`,
     154                                COUNT( CASE WHEN t.date_modified > %s THEN t.date_modified END ) AS `recent_translation_count`
     155                        FROM `' . $gpdb->translations .'` t, `'. $gpdb->translation_sets . '` ts
     156                        WHERE t.`translation_set_id` = ts.`id`
     157                            AND t.`user_id` IS NOT NULL AND t.`user_id` != 0
     158                            AND ts.`project_id` = %d
     159                        GROUP BY ts.`locale`, ts.`slug`, t.`user_id`
     160                ', date( 'Y-m-d', time() - 365 * 86400 ), $project_id );
     161
     162                return $gpdb->get_results( $sql );
     163        }
     164
     165        function get_plugin_project_translators( $project_slug ) {
     166                global $gpdb;
     167
     168                $project_path = 'wp-plugins/' . $project_slug;
     169                $project = GP::$project->by_path( $project_path );
     170                if ( ! $project ) {
     171                        return $this->die_with_404();
     172                }
     173
     174                $project_translators = $this->get_total_project_translators( $project->id );
     175
     176                // sort by locales for display
     177                ksort( $project_translators );
     178
     179                if ( function_exists( 'wporg_get_plugin_icon' ) ) {
     180                        $project->icon = wporg_get_plugin_icon( $project->slug, 64 );
     181                } else {
     182                        $project->icon = '<div class="default-icon"><span class="dashicons dashicons-admin-plugins"></span></div>';
     183                }
     184
     185                $this->tmpl( 'translators-project', get_defined_vars() );
     186        }
    91187}
  • gp-plugins/wporg-routes/wporg-routes.php

     
    4343                GP::$router->prepend( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    4444                GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
    4545
    46                 $project = '([^/]*)/?';
    47                 GP::$router->prepend( "/projects/wp-plugins/$project", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_projects' ) );
     46                $project = '([^/]*)';
     47                GP::$router->prepend( "/projects/wp-plugins/$project/?", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_projects' ) );
     48                GP::$router->prepend( "/projects/wp-plugins/$project/translators/?", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_project_translators' ) );
    4849        }
    4950}
    5051