<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[8249] sites/trunk/wordpress.org/public_html/wp-content/plugins: Translate: Add a per-locale stats page which lists plugin/theme translation status.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/8249">8249</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/8249","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2019-02-14 06:43:05 +0000 (Thu, 14 Feb 2019)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Translate: Add a per-locale stats page which lists plugin/theme translation status.

Notes:
 - This is currently not linked from anywhere.
 - The number displayed (250) may be lowered, currently only ~245 theme projects and ~200 plugin projects are displayed due to filtering.
 - Plugins displays based on Code (Dev+Stable) + Readme (Dev+Stable).

Examples:
 - https://translate.wordpress.org/locale/de/default/stats/plugins
 - https://translate.wordpress.org/locale/de/default/stats/themes

See <a href="http://meta.trac.wordpress.org/ticket/2290">#2290</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggproutesincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggproutesincroutesclassstatsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationstemplatesstatspluginthemesoverviewphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-plugin-themes-overview.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggpcustomizationstemplatesstatspluginthemesoverviewphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-plugin-themes-overview.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-plugin-themes-overview.php                               (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-plugin-themes-overview.php 2019-02-14 06:43:05 UTC (rev 8249)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,101 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+gp_title( __( 'Translation status overview &lt; GlotPress' ) );
+gp_enqueue_script( 'tablesorter' );
+
+$breadcrumb   = array();
+$breadcrumb[] = gp_link_get( '/stats', __( 'Locale Stats' ) );
+$breadcrumb[] = gp_link_get( '/locales/' . $locale . '/' . $locale_slug, $gp_locale->native_name );
+$breadcrumb[] = trim( ucwords( $view ), 's' ) . ' translation status overview';
+gp_breadcrumb( $breadcrumb );
+gp_tmpl_header();
+
+$columns = array(
+       'all'          => __( 'Translated Percent' ),
+       'current'      => __( 'Translated' ),
+       'untranslated' => __( 'Untranslated' ),
+       'fuzzy'        => __( 'Fuzzy' ),
+       'waiting'      => __( 'Waiting' ),
+);
+$main_column_title = trim( ucwords( $view ), 's' );
+
+?>
+<div class="stats-table">
+       <table id="stats-table" class="table">
+               <thead>
+                       <tr>
+                               <th><?php echo $main_column_title; ?></th>
+                               <?php
+                                       foreach ( $columns as $title ) {
+                                               printf( "<th>%s</th>", $title );
+                                       }
+
+                               ?>
+                       </tr>
+               </thead>
+               <tbody>
+                       <?php
+                       foreach ( $items as $slug => $details ) {
+                               $project_link = gp_url( gp_url_join( 'locale', $gp_locale->slug, $locale_slug, $details->project->path ) );
+                               // Themes get a shortcut..
+                               if ( 'themes' == $view ) {
+                                       $project_link = gp_url( gp_url_join( 'projects', $details->project->path, $gp_locale->slug, $locale_slug ) );
+                               }
+
+                               $project_overview_link = gp_url( gp_url_join( 'projects', $details->project->path ) );
+
+                               echo '<tr>';
+                               printf(
+                                       '<th title="%s" data-column-title="%s" data-sort-value="%s"><a href="%s">%s</a></th>',
+                                       esc_attr( sprintf( __( "%s+ Active Installations" ), number_format_i18n( $details->installs ) ) ),
+                                       esc_attr( $main_column_title ),
+                                       $details->installs,
+                                       $project_overview_link,
+                                       $details->project->name
+                               );
+
+                               foreach ( $columns as $field => $title ) {
+                                       $sort_value = $stat_value = ( $details->stats->{$field} ?? 0 );
+                                       $percent = $stat_value / $details->stats->all * 100;
+                                       $link = $project_link;
+                                       $cell_text = number_format_i18n( $stat_value );
+
+                                       if ( in_array( $field, [ 'fuzzy', 'untranslated', 'waiting' ] ) ) {
+                                               $percent = 100 - $percent;
+                                               $link    = add_query_arg( 'filters[status]', $field, $project_link );
+                                       } elseif ( 'all' == $field ) {
+                                               $percent    = ($details->stats->current ?? 0) / $details->stats->all * 100;
+                                               $sort_value = $percent;
+                                               $cell_text  = ( $percent > 50 ? floor( $percent ) : ceil( $percent ) ) . '%';
+                                       }
+
+                                       $percent_class = 'percent' . (int) ( $percent / 10 ) * 10;
+
+                                       printf( '<td class="%s" data-column-title="%s" data-sort-value="%s"><a href="%s">%s</a></td>',
+                                               $percent_class,
+                                               $title,
+                                               $sort_value,
+                                               $link,
+                                               $cell_text
+                                       );
+                               }
+                               echo '</tr>';
+                       }
+                       ?>
+               </tbody>
+       </table>
+</div>
+
+<script type="text/javascript">
+jQuery( document ).ready( function( $ ) {
+       $( '#stats-table' ).tablesorter( {
+               textExtraction: function( node ) {
+                       var cellValue = $( node ).text(),
+                               sortValue = $( node ).data( 'sortValue' );
+
+                       return ( undefined !== sortValue ) ? sortValue : cellValue;
+               }
+       });
+});
+</script>
+<?php
+gp_tmpl_footer();
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/templates/stats-plugin-themes-overview.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggproutesincclasspluginphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php     2019-02-14 05:15:39 UTC (rev 8248)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php       2019-02-14 06:43:05 UTC (rev 8249)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -87,6 +87,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         *  - (/locale)/$locale/$dir/glossary/-delete
</span><span class="cx" style="display: block; padding: 0 10px">         *  - (/locale)/$locale/$dir/glossary/-export
</span><span class="cx" style="display: block; padding: 0 10px">         *  - (/locale)/$locale/$dir/glossary/-import
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         *  - /locale/$locale/$dir/stats(?:/(plugins|themes))?s
</ins><span class="cx" style="display: block; padding: 0 10px">          *  - /stats/?
</span><span class="cx" style="display: block; padding: 0 10px">         *  - /projects/wp-plugins/$project
</span><span class="cx" style="display: block; padding: 0 10px">         *  - /projects/wp-plugins/$project/contributors
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -142,6 +143,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        GP::$router->prepend( "(/locale)/$locale/$dir/glossary/-export", array( 'GP_Route_Glossary_Entry', 'export_glossary_entries_get' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        GP::$router->prepend( "(/locale)/$locale/$dir/glossary/-import", array( 'GP_Route_Glossary_Entry', 'import_glossary_entries_get' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        GP::$router->prepend( "(/locale)/$locale/$dir/glossary/-import", array( 'GP_Route_Glossary_Entry', 'import_glossary_entries_post' ), 'post' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        GP::$router->prepend( "/locale/$locale/$dir/stats(?:/(plugins|themes))?", array( __NAMESPACE__ . '\Routes\Stats', 'get_stats_plugin_theme_overview' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                         GP::$router->prepend( '/stats', array( __NAMESPACE__ . '\Routes\Stats', 'get_stats_overview' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                        GP::$router->prepend( '/consistency', array( __NAMESPACE__ . '\Routes\Consistency', 'get_search_form' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporggproutesincroutesclassstatsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php       2019-02-14 05:15:39 UTC (rev 8248)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php 2019-02-14 06:43:05 UTC (rev 8249)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,6 +4,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> use GP;
</span><span class="cx" style="display: block; padding: 0 10px"> use GP_Route;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+use GP_Locales;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Stats Route Class.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -137,4 +138,90 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $this->tmpl( 'stats-overview', get_defined_vars() );
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function get_stats_plugin_theme_overview( $locale, $locale_slug, $view = false ) {
+               global $wpdb;
+               if ( ! $locale || ! $locale_slug || ! $view ) {
+                       wp_redirect( '/stats', 301 );
+                       die();
+               }
+
+               $gp_locale = GP_Locales::by_slug( $locale );
+
+               $items = array();
+               if ( 'plugins' == $view ) {
+                       // Fetch top 100 plugins..
+                       $items = get_transient( __METHOD__ . '_plugin_items' );
+                       if ( ! $items ) {
+                               $api = wp_safe_remote_get( 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[per_page]=250' );
+                               foreach ( json_decode( wp_remote_retrieve_body( $api ) )->plugins as $plugin ) {
+                                       $items[ $plugin->slug ] = (object) [
+                                               'installs' => $plugin->active_installs,
+                                       ];
+                               }
+                               set_transient( __METHOD__ . '_plugin_items', $items, DAY_IN_SECONDS );
+                       }
+               } elseif ( 'themes' == $view && defined( 'WPORG_THEME_DIRECTORY_BLOGID' ) ) {
+                       $items = get_transient( __METHOD__ . '_theme_items' );
+                       if ( ! $items ) {
+                               // The Themes API API isn't playing nice.. Easiest way..
+                               switch_to_blog( WPORG_THEME_DIRECTORY_BLOGID );
+                               $items = $wpdb->get_results(
+                                       "SELECT p.post_name as slug, pm.meta_value as installs
+                                       FROM {$wpdb->posts} p
+                                       LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id AND pm.meta_key = '_active_installs'
+                                       WHERE p.post_type = 'repopackage' AND p.post_status = 'publish'
+                                       ORDER BY pm.meta_value+0 DESC, p.post_date
+                                       LIMIT 250",
+                                       OBJECT_K
+                               );
+                               restore_current_blog();
+                               foreach ( $items as $slug => $details ) {
+                                       unset( $items[$slug]->slug );
+                               }
+                               set_transient( __METHOD__ . '_theme_items', $items, DAY_IN_SECONDS );
+                       }
+               } else {
+                       wp_safe_redirect( '/stats' );
+                       die();
+               }
+
+               $project_ids = [];
+               foreach ( $items as $slug => $details ) {
+                       $items[$slug]->project = GP::$project->by_path( 'wp-' . $view . '/' . $slug );
+                       if ( ! $items[$slug]->project || ! $items[$slug]->project->active ) {
+                               // Not all top-all-time plugins/themes have translation projects.
+                               unset( $items[ $slug ] );
+                               continue;
+                       }
+
+                       if (
+                               'plugins' == $view &&
+                               (
+                                       ! GP::$project->by_path( $items[$slug]->project->path . '/dev' )
+                                       &&
+                                       ! GP::$project->by_path( $items[$slug]->project->path . '/stable' )
+                               )
+                       ) {
+                               // Not all top plugins are translation-aware, lets just skip those..
+                               unset( $items[ $slug ] );
+                               continue;
+                       }
+
+                       $project_ids[ $items[$slug]->project->id ] = $slug;
+               }
+
+               $sql_project_ids = implode( ', ', array_map( 'intval', array_keys( $project_ids ) ) );
+               $stats = $wpdb->get_results( $wpdb->prepare(
+                       "SELECT `project_id`, `all`, `current`, `waiting`, `untranslated`
+                               FROM {$wpdb->project_translation_status}
+                               WHERE project_id IN ($sql_project_ids)
+                               AND locale = %s AND locale_slug = %s",
+                       $locale, $locale_slug
+               ) );
+               foreach ( $stats as $row ) {
+                       $items[ $project_ids[ $row->project_id ] ]->stats = $row;
+               }
+
+               $this->tmpl( 'stats-plugin-themes-overview', compact( 'locale', 'locale_slug', 'view', 'gp_locale', 'items' ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>

</body>
</html>