Making WordPress.org


Ignore:
Timestamp:
11/22/2015 09:24:33 PM (9 years ago)
Author:
ocean90
Message:

Translate: Update routes plugin to use the new rosetta roles WP plugin.

See #1352.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/locale.php

    r2109 r2111  
    3939        // Default to the Waiting or WordPress tabs
    4040        $default_project_tab = 'waiting';
    41         $user = GP::$user->current();
     41        $user_id = get_current_user_id();
    4242        if (
    43             ! $user->id || // Not logged in
    44             ! isset( GP::$plugins->wporg_rosetta_roles ) || // Rosetta Roles plugin is not enabled
     43            ! is_user_logged_in() ||
     44            ! function_exists( 'wporg_gp_rosetta_roles' ) || // Rosetta Roles plugin is not enabled
    4545            ! (
    46                 GP::$plugins->wporg_rosetta_roles->is_global_administrator( $user->id ) || // Not a global admin
    47                 GP::$plugins->wporg_rosetta_roles->is_approver_for_locale( $user->id, $locale_slug ) // Doesn't have project-level access either
     46                wporg_gp_rosetta_roles()->is_global_administrator( $user_id ) || // Not a global admin
     47                wporg_gp_rosetta_roles()->is_approver_for_locale( $user_id, $locale_slug ) // Doesn't have project-level access either
    4848            )
    4949            // Add check to see if there are any waiting translations for this locale?
     
    101101        $project_ids = array_merge(
    102102            $project_ids,
    103             $wpdb->get_col( "SELECT id FROM {$wpdb->projects} WHERE parent_project_id IN(" . implode(', ', $project_ids  ) . ")" )
     103            $wpdb->get_col( "SELECT id FROM {$wpdb->gp_projects} WHERE parent_project_id IN(" . implode(', ', $project_ids  ) . ")" )
    104104        );
    105105
     
    249249        $slugs = $wpdb->get_col( $wpdb->prepare( "
    250250            SELECT DISTINCT slug
    251             FROM {$wpdb->translation_sets}
     251            FROM {$wpdb->gp_translation_sets}
    252252            WHERE
    253253                project_id IN( $project_ids )
     
    328328        $_projects = $project->many( "
    329329            SELECT *
    330             FROM {$wpdb->projects}
     330            FROM {$wpdb->gp_projects}
    331331            WHERE
    332332                parent_project_id = %d AND
     
    343343                $sub_projects = $project->many( "
    344344                    SELECT *
    345                     FROM {$wpdb->projects}
     345                    FROM {$wpdb->gp_projects}
    346346                    WHERE
    347347                        parent_project_id = %d AND
     
    407407        // Special Waiting Project Tab
    408408        // This removes the parent_project_id restriction and replaces it with all-translation-editer-projects
    409         if ( 'waiting' == $project->slug && GP::$user->current()->id && isset( GP::$plugins->wporg_rosetta_roles ) ) {
     409        if ( 'waiting' == $project->slug && is_user_logged_in() && function_exists( 'wporg_gp_rosetta_roles' ) ) {
    410410
    411411            if ( ! $filter ) {
     
    413413            }
    414414
    415             $user_id = GP::$user->current()->id;
     415            $user_id = get_current_user_id();
    416416
    417417            // Global Admin or Locale-specific admin
    418             $can_approve_for_all = GP::$plugins->wporg_rosetta_roles->is_global_administrator( $user_id );
     418            $can_approve_for_all = wporg_gp_rosetta_roles()->is_global_administrator( $user_id );
    419419
    420420            // Check to see if they have any special approval permissions
    421421            $allowed_projects = array();
    422             if ( ! $can_approve_for_all && GP::$plugins->wporg_rosetta_roles->is_approver_for_locale( $user_id, $locale ) ) {
    423                 $allowed_projects = GP::$plugins->wporg_rosetta_roles->get_project_id_access_list( $user_id, $locale, true );
     422            if ( ! $can_approve_for_all && wporg_gp_rosetta_roles()->is_approver_for_locale( $user_id, $locale ) ) {
     423                $allowed_projects = wporg_gp_rosetta_roles()->get_project_id_access_list( $user_id, $locale, true );
    424424
    425425                // Check to see if they can approve for all projects in this locale.
     
    448448
    449449            // Limit to only showing base-level projects
    450             $parent_project_sql .= " AND tp.parent_project_id IN( (SELECT id FROM {$wpdb->projects} WHERE parent_project_id IS NULL AND active = 1) )";
     450            $parent_project_sql .= " AND tp.parent_project_id IN( (SELECT id FROM {$wpdb->gp_projects} WHERE parent_project_id IS NULL AND active = 1) )";
    451451
    452452        }
     
    463463            case 'special':
    464464                // Float favorites to the start, but only if they have untranslated strings
    465                 $user_fav_projects = array_map( array( $wpdb, 'escape' ), $this->get_user_favorites( $project->slug ) );
     465                $user_fav_projects = array_map( 'esc_sql', $this->get_user_favorites( $project->slug ) );
    466466
    467467                // Float Favorites to the start, float fully translated to the bottom, order the rest by name
     
    475475            case 'favorites':
    476476                // Only list favorites
    477                 $user_fav_projects = array_map( array( $wpdb, 'escape' ), $this->get_user_favorites( $project->slug ) );
     477                $user_fav_projects = array_map( 'esc_sql', $this->get_user_favorites( $project->slug ) );
    478478
    479479                if ( $user_fav_projects ) {
     
    513513        $_projects = $project->many( "
    514514            SELECT SQL_CALC_FOUND_ROWS tp.*
    515             FROM {$wpdb->projects} tp
     515            FROM {$wpdb->gp_projects} tp
    516516                LEFT JOIN {$wpdb->project_translation_status} stats ON stats.project_id = tp.id AND stats.locale = %s AND stats.locale_slug = %s
    517517            WHERE
     
    547547    function get_user_favorites( $project_slug = false ) {
    548548        global $wpdb;
    549         $user = GP::$user->current();
    550 
    551         if ( ! $user->id ) {
     549
     550        if ( ! is_user_logged_in() ) {
    552551            return array();
    553552        }
     553
     554        $user_id = get_current_user_id();
    554555
    555556        switch ( $project_slug ) {
     
    560561                $theme_favorites = array_map( function( $slug ) {
    561562                    return "wp-themes/$slug";
    562                 }, (array) $user->get_meta( 'theme_favorites' ) );
     563                }, (array) get_user_meta( $user_id, 'theme_favorites', true ) );
    563564
    564565                if ( 'wp-themes' === $project_slug ) {
     
    568569            case 'wp-plugins':
    569570                // Plugin favorites are stored as topic ID's
    570                 $plugin_fav_ids = array_keys( (array)$user->get_meta( PLUGINS_TABLE_PREFIX . 'plugin_favorite' ) );
     571                $plugin_fav_ids = array_keys( (array) get_user_meta( $user_id, PLUGINS_TABLE_PREFIX . 'plugin_favorite', true ) );
    571572                $plugin_fav_slugs = array();
    572573                if ( $plugin_fav_ids ) {
     
    598599        return GP::$project->many( "
    599600            SELECT *
    600             FROM {$wpdb->projects}
     601            FROM {$wpdb->gp_projects}
    601602            WHERE
    602603                parent_project_id IS NULL
Note: See TracChangeset for help on using the changeset viewer.