Making WordPress.org


Ignore:
Timestamp:
10/07/2017 01:23:36 PM (9 years ago)
Author:
ocean90
Message:

Translate, Consistency: Support filtering by parent projects and group results by translation.

File:
1 edited

Legend:

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

    r3013 r6006  
    33namespace WordPressdotorg\GlotPress\Routes\Routes;
    44
     5use GP;
    56use GP_Locales;
    67use GP_Route;
     
    1516        private $cache_group = 'wporg-translate';
    1617
     18        const PROJECTS = [
     19                1   => 'WordPress',
     20                523 => 'Themes',
     21                17  => 'Plugins',
     22                487 => 'Meta',
     23                281 => 'Apps',
     24        ];
     25
    1726        /**
    1827         * Prints a search form and the search results for a consistency view.
     
    2130                $sets = $this->get_translation_sets();
    2231
    23                 $search = $set = '';
    24                 $search_case_sensitive = true;
     32                $search = $set = $project = '';
     33                $search_case_sensitive = false;
    2534
    2635                if ( ! empty( $_REQUEST['search'] ) ) {
     
    3544                }
    3645
    37                 if ( ! empty( $_REQUEST ) && empty( $_REQUEST['search_case_sensitive'] ) ) {
    38                         $search_case_sensitive = false;
     46                if ( ! empty( $_REQUEST['search_case_sensitive'] ) ) {
     47                        $search_case_sensitive = true;
     48                }
     49
     50                if ( ! empty( $_REQUEST['project'] ) && isset( self::PROJECTS[ $_REQUEST['project'] ] ) ) {
     51                        $project = $_REQUEST['project'];
    3952                }
    4053
     
    5366                                'set'            => $set,
    5467                                'case_sensitive' => $search_case_sensitive,
     68                                'project'        => $project,
    5569                        ] );
    5670
     
    5872                        $translations_unique = array_unique( $translations );
    5973                }
     74
     75                $projects = self::PROJECTS;
    6076
    6177                $this->tmpl( 'consistency', get_defined_vars() );
     
    109125                $slug = $wpdb->prepare( '%s', $slug );
    110126
     127                $project_where = '';
     128                if ( $args['project'] ) {
     129                        $project = GP::$project->get( $args['project'] );
     130                        $project_where = $wpdb->prepare( 'AND p.path LIKE %s', $wpdb->esc_like( $project->path ) . '/%' );
     131                }
     132
    111133                $results = $wpdb->get_results( "
    112134                        SELECT
     
    134156                                AND o.status = '+active' AND o.singular {$search}
    135157                                AND ts.locale = {$locale} AND ts.slug = {$slug}
     158                                {$project_where}
    136159                        LIMIT 0, 500
    137160                " );
     
    148171
    149172        public function _sort_callback( $a, $b ) {
    150                 return strnatcmp( $a->translation, $b->translation );
     173                return strnatcasecmp( $a->translation, $b->translation );
    151174        }
    152175}
Note: See TracChangeset for help on using the changeset viewer.