Ticket #1388: 1388.4.diff
File 1388.4.diff, 6.2 KB (added by , 10 years ago) |
---|
-
gp-plugins/wporg-routes/routes/wp-plugins.php
88 88 89 89 $this->tmpl( 'projects-wp-plugins', get_defined_vars() ); 90 90 } 91 92 private function get_project_contributors( $project_id ) { 93 global $gpdb; 94 95 $sql = $gpdb->prepare( ' 96 SELECT ts.`locale`, ts.`slug` AS `locale_slug`, t.`user_id`, COUNT(*) AS `translation_count` 97 FROM `' . $gpdb->translations .'` t, `'. $gpdb->translation_sets . '` ts 98 WHERE t.`translation_set_id` = ts.`id` 99 AND t.`user_id` IS NOT NULL AND t.`user_id` != 0 100 AND ts.`project_id` = %d 101 GROUP BY ts.`locale`, ts.`slug`, t.`user_id` 102 ', $project_id ); 103 104 return $gpdb->get_results( $sql ); 105 } 106 107 function get_plugin_project_contributors( $project_slug ) { 108 global $gpdb; 109 110 $project_path = 'wp-plugins/' . $project_slug; 111 $project = GP::$project->by_path( $project_path ); 112 if ( ! $project ) { 113 return $this->die_with_404(); 114 } 115 116 $sub_projects = $gpdb->get_results( $gpdb->prepare( " 117 SELECT id 118 FROM {$gpdb->prefix}projects 119 WHERE parent_project_id = %d 120 ", $project->id ) ); 121 122 // also include the main project in the count 123 $sub_projects[] = $project; 124 125 $project_contributors = array(); 126 foreach ( $sub_projects as $sub_project ) { 127 128 foreach( $this->get_project_contributors( $sub_project->id ) as $row ) { 129 $locale_key = $row->locale; 130 if ( 'default' != $row->locale_slug ) { 131 $locale_key = $row->locale . '/' . $row->locale_slug; 132 } 133 134 if ( ! isset( $project_contributors[ $locale_key ] ) ) { 135 $project_contributors[ $locale_key ] = array(); 136 } 137 138 if ( ! isset( $project_contributors[ $locale_key ][ $row->user_id ] ) ) { 139 $project_contributors[ $locale_key ][ $row->user_id ] = 0; 140 } 141 142 // sum up translations per user over all (sub-)projects 143 $project_contributors[ $locale_key ][ $row->user_id ] += $row->translation_count; 144 } 145 } 146 147 // sort by locales for display 148 ksort( $project_contributors ); 149 150 if ( function_exists( 'wporg_get_plugin_icon' ) ) { 151 $project->icon = wporg_get_plugin_icon( $project->slug, 64 ); 152 } else { 153 $project->icon = '<div class="default-icon"><span class="dashicons dashicons-admin-plugins"></span></div>'; 154 } 155 156 $this->tmpl( 'contributors-project', get_defined_vars() ); 157 } 91 158 } -
gp-plugins/wporg-routes/wporg-routes.php
43 43 GP::$router->prepend( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) ); 44 44 GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) ); 45 45 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/contributors/?", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_project_contributors' ) ); 48 49 } 49 50 } 50 51 -
gp-templates/contributors-project.php
1 <?php 2 $edit_link = gp_link_project_edit_get( $project, __( '(edit)' ) ); 3 4 gp_title( sprintf( __( 'Contributors < %s < GlotPress' ), esc_html( $project->name ) ) ); 5 gp_breadcrumb_project( $project ); 6 7 wp_enqueue_script( 'common' ); 8 wp_enqueue_script( 'tablesorter' ); 9 10 gp_tmpl_header(); 11 ?> 12 13 <div class="project-header"> 14 <p class="project-description"><?php echo apply_filters( 'project_description', $project->description, $project ); ?></p> 15 16 <div class="project-box"> 17 <div class="project-box-header"> 18 <div class="project-icon"> 19 <?php echo $project->icon; ?> 20 </div> 21 22 <ul class="project-meta"> 23 <li class="project-name"><?php echo $project->name; ?> <?php echo $edit_link; ?></li> 24 </ul> 25 </div> 26 </div> 27 </div> 28 29 <div class="stats-table"> 30 <table id="contributors-table" class="table"> 31 <thead> 32 <tr> 33 <th class="locale"><?php echo _( 'Locale' ); ?></th> 34 <th class="username"><?php echo _( 'Username' ); ?></th> 35 <th class="translations"><?php echo _( 'Translations' ); ?></th> 36 </tr> 37 </thead> 38 <tbody> 39 <?php 40 foreach ( $project_contributors as $locale => $contributors ) : 41 $gp_locale = GP_Locales::by_slug( $locale ); 42 43 $set_slug = 'default'; 44 45 // Variants (de/formal for example) don't have GP_Locales in this context 46 if ( ! $gp_locale && ( list( $base_locale_slug, $set_slug ) = explode( '/', $locale_slug ) ) ) : 47 $gp_locale = clone GP_Locales::by_slug( $base_locale_slug ); 48 49 // Just append it for now.. 50 $gp_locale->wp_locale .= '/' . $set_slug; 51 $gp_locale->english_name .= ' (' . ucfirst( $set_slug ) . ')'; 52 endif; 53 54 if ( ! $gp_locale || ! $gp_locale->wp_locale ) : 55 continue; 56 endif; 57 58 foreach ( $contributors as $contributor => $translation_count ): 59 $user = GP::$user->get( $contributor ); 60 ?> 61 <tr> 62 <th title="<?php echo esc_attr( $gp_locale->wp_locale ); ?>"> 63 <a href="<?php echo gp_url( gp_url_join( 'locale', $gp_locale->slug, $set_slug, $project->path ) ); ?>"> 64 <?php echo esc_html( $gp_locale->english_name ); ?> 65 </a> 66 </th> 67 <td><?php echo $user->user_login; ?></td> 68 <td><?php echo $translation_count; ?></td> 69 </tr> 70 <?php endforeach; ?> 71 <?php endforeach; ?> 72 </tbody> 73 </table> 74 </div> 75 76 <script type="text/javascript"> 77 jQuery( function( $ ) { 78 $( '#contributors-table' ).tablesorter( { 79 textExtraction: function( node ) { 80 var cellValue = $( node ).text(), 81 sortValue = $( node ).data( 'sortValue' ); 82 83 return ( undefined !== sortValue ) ? sortValue : cellValue; 84 } 85 }); 86 }); 87 </script> 88 89 <?php gp_tmpl_footer();