Skip to content

Commit

Permalink
Make compatible with GlotPress-wp
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Apr 11, 2016
1 parent 65ee5fb commit b5767aa
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions gp-warnings.php
@@ -1,8 +1,13 @@
<?php
/**
* Plugin name: GlotPress: Warnings Dashboard
* Plugin author: Automattic
* Version: 1.0
*
* Description: Gives an overview of the warnings in a whole project, across locales.
*/


class GP_Route_Warnings extends GP_Route_Main {
public $segments = array();

Expand All @@ -21,7 +26,7 @@ function show( $project_path ) {
$translation_sets = GP::$translation_set->by_project_id( $project->id );
if ( ! $translation_sets ) $this->die_with_404();

global $gpdb;
global $wpdb;

$segments = new GP_Warnings_Segments( $this->segments );

Expand All @@ -38,29 +43,42 @@ function show( $project_path ) {

$sql_for_warnings = "
SELECT t.translation_set_id, SUM( t.status = 'current') AS current, SUM( t.status = 'waiting') AS waiting, SUM( t.status = 'fuzzy') AS fuzzy
FROM $gpdb->originals as o
INNER JOIN $gpdb->translations AS t ON o.id = t.original_id AND t.translation_set_id IN( ".$gpdb->escape( implode( ',', $translation_set_ids ) )." )
WHERE o.project_id = " . $gpdb->escape( $project->id )." AND o.status LIKE '+%'
FROM $wpdb->gp_originals as o
INNER JOIN $wpdb->gp_translations AS t ON o.id = t.original_id AND t.translation_set_id IN( ".$wpdb->escape( implode( ',', $translation_set_ids ) )." )
WHERE o.project_id = " . $wpdb->escape( $project->id )." AND o.status LIKE '+%'
AND t.warnings IS NOT NULL AND t.warnings != '' AND t.status IN ('current', 'waiting', 'fuzzy')
GROUP BY t.translation_set_id HAVING COUNT(*) > 0
ORDER BY " . $segments->order_by( 't.translation_set_id' ) . ", SUM( t.status = 'current') DESC
";

$warnings = $gpdb->get_results( $sql_for_warnings );
$warnings = $wpdb->get_results( $sql_for_warnings );

$this->tmpl( 'warnings', get_defined_vars() );
}
}

class GP_Warnings_Loader extends GP_Plugin {
class GP_Warnings {
private static $instance = null;

public static function init() {
self::get_instance();
}

public static function get_instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}

return self::$instance;
}

function __construct() {
parent::__construct();
$this->init_new_routes();
$this->add_filter( 'gp_project_actions', array( 'args' => 2 ) );
add_action( 'template_redirect', array( $this, 'register_routes' ), 5 );
add_filter( 'gp_project_actions', array( $this, 'gp_project_actions' ), 5, 2 );
}

function init_new_routes() {
GP::$router->insert( '/projects/(.+?)/-warnings', array( 'GP_Route_Warnings', 'show' ), 'get' );
function register_routes() {
GP::$router->prepend( '/projects/(.+?)/-warnings', array( 'GP_Route_Warnings', 'show' ), 'get' );
}

function gp_project_actions( $actions, $project ) {
Expand Down Expand Up @@ -122,5 +140,5 @@ public function title( $set_id ) {
}


GP::$plugins->Warnings = new GP_Warnings_Loader();
add_action( 'gp_init', array( 'GP_Warnings', 'init' ) );

0 comments on commit b5767aa

Please sign in to comment.