Making WordPress.org

Changeset 2109


Ignore:
Timestamp:
11/22/2015 08:01:41 PM (11 years ago)
Author:
ocean90
Message:

Translate: Convert the GP plugin "wporg-routes" to a WP plugin.

See #1352.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes
Files:
2 deleted
4 edited
3 copied

Legend:

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

    r1721 r2109  
    55 * Provides the route for translate.wordpress.org/.
    66 */
    7 class GP_WPorg_Route_Index extends GP_Route {
     7class WPorg_GP_Route_Index extends GP_Route {
    88
    99        /**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/locale.php

    r2080 r2109  
    1111 * Provides the route for translate.wordpress.org/locale/$locale.
    1212 */
    13 class GP_WPorg_Route_Locale extends GP_Route {
     13class WPorg_GP_Route_Locale extends GP_Route {
    1414
    1515        /**
    … …  
    2121         */
    2222        public function get_locale_projects( $locale_slug, $set_slug = 'default', $project_path = false ) {
    23                 global $gpdb;
     23                global $wpdb;
    2424
    2525                $per_page = 20;
    … …  
    101101                $project_ids = array_merge(
    102102                        $project_ids,
    103                         $gpdb->get_col( "SELECT id FROM {$gpdb->projects} WHERE parent_project_id IN(" . implode(', ', $project_ids  ) . ")" )
     103                        $wpdb->get_col( "SELECT id FROM {$wpdb->projects} WHERE parent_project_id IN(" . implode(', ', $project_ids  ) . ")" )
    104104                );
    105105
    … …  
    244244         */
    245245        private function get_locale_variants( $locale, $project_ids ) {
    246                 global $gpdb;
     246                global $wpdb;
    247247
    248248                $project_ids = implode( ',', $project_ids );
    249                 $slugs = $gpdb->get_col( $gpdb->prepare( "
     249                $slugs = $wpdb->get_col( $wpdb->prepare( "
    250250                        SELECT DISTINCT slug
    251                         FROM {$gpdb->translation_sets}
     251                        FROM {$wpdb->translation_sets}
    252252                        WHERE
    253253                                project_id IN( $project_ids )
    … …  
    324324         */
    325325        private function get_active_sub_projects( $project, $with_sub_projects = false ) {
    326                 global $gpdb;
     326                global $wpdb;
    327327
    328328                $_projects = $project->many( "
    329329                        SELECT *
    330                         FROM {$gpdb->projects}
     330                        FROM {$wpdb->projects}
    331331                        WHERE
    332332                                parent_project_id = %d AND
    … …  
    343343                                $sub_projects = $project->many( "
    344344                                        SELECT *
    345                                         FROM {$gpdb->projects}
     345                                        FROM {$wpdb->projects}
    346346                                        WHERE
    347347                                                parent_project_id = %d AND
    … …  
    379379         */
    380380        private function get_paged_active_sub_projects( $project, $args = array() ) {
    381                 global $gpdb;
     381                global $wpdb;
    382382
    383383                $defaults = array(
    … …  
    394394                $limit_sql = '';
    395395                if ( $per_page ) {
    396                         $limit_sql = $gpdb->prepare( 'LIMIT %d, %d', ( $page - 1 ) * $per_page, $per_page );
    397                 }
    398 
    399                 $parent_project_sql = $gpdb->prepare( 'AND tp.parent_project_id = %d', $project->id );
     396                        $limit_sql = $wpdb->prepare( 'LIMIT %d, %d', ( $page - 1 ) * $per_page, $per_page );
     397                }
     398
     399                $parent_project_sql = $wpdb->prepare( 'AND tp.parent_project_id = %d', $project->id );
    400400
    401401                $search_sql = '';
    402402                if ( $search ) {
    403403                        $esc_search = '%%' . like_escape( $search ) . '%%';
    404                         $search_sql = $gpdb->prepare( 'AND ( tp.name LIKE %s OR tp.slug LIKE %s )', $esc_search, $esc_search );
     404                        $search_sql = $wpdb->prepare( 'AND ( tp.name LIKE %s OR tp.slug LIKE %s )', $esc_search, $esc_search );
    405405                }
    406406
    … …  
    448448
    449449                        // Limit to only showing base-level projects
    450                         $parent_project_sql .= " AND tp.parent_project_id IN( (SELECT id FROM {$gpdb->projects} WHERE parent_project_id IS NULL AND active = 1) )";
     450                        $parent_project_sql .= " AND tp.parent_project_id IN( (SELECT id FROM {$wpdb->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( $gpdb, 'escape' ), $this->get_user_favorites( $project->slug ) );
     465                                $user_fav_projects = array_map( array( $wpdb, 'escape' ), $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( $gpdb, 'escape' ), $this->get_user_favorites( $project->slug ) );
     477                                $user_fav_projects = array_map( array( $wpdb, 'escape' ), $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 {$gpdb->projects} tp
    516                                 LEFT JOIN {$gpdb->project_translation_status} stats ON stats.project_id = tp.id AND stats.locale = %s AND stats.locale_slug = %s
     515                        FROM {$wpdb->projects} tp
     516                                LEFT JOIN {$wpdb->project_translation_status} stats ON stats.project_id = tp.id AND stats.locale = %s AND stats.locale_slug = %s
    517517                        WHERE
    518518                                tp.active = 1
    … …  
    546546         */
    547547        function get_user_favorites( $project_slug = false ) {
    548                 global $gpdb;
     548                global $wpdb;
    549549                $user = GP::$user->current();
    550550
    … …  
    572572                                if ( $plugin_fav_ids ) {
    573573                                        $plugin_fav_ids = implode( ',', array_map( 'intval', $plugin_fav_ids ) );
    574                                         $plugin_fav_slugs = $gpdb->get_col( "SELECT topic_slug FROM " . PLUGINS_TABLE_PREFIX . "topics WHERE topic_id IN( $plugin_fav_ids )" );
     574                                        $plugin_fav_slugs = $wpdb->get_col( "SELECT topic_slug FROM " . PLUGINS_TABLE_PREFIX . "topics WHERE topic_id IN( $plugin_fav_ids )" );
    575575                                }
    576576
    … …  
    594594         */
    595595        public function get_active_top_level_projects() {
    596                 global $gpdb;
     596                global $wpdb;
    597597
    598598                return GP::$project->many( "
    599599                        SELECT *
    600                         FROM {$gpdb->projects}
     600                        FROM {$wpdb->projects}
    601601                        WHERE
    602602                                parent_project_id IS NULL
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/redirector.php

    r1721 r2109  
    55 * Provides redirection routes.
    66 */
    7 class GP_WPorg_Route_Redirector extends GP_Route {
     7class WPorg_GP_Route_Redirector extends GP_Route {
    88
    99        function redirect_languages( $path = '' ) {
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/stats-overview.php

    r2108 r2109  
    55 * Provides the route for translate.wordpress.org/stats.
    66 */
    7 class GP_WPorg_Route_Stats extends GP_Route {
     7class WPorg_GP_Route_Stats extends GP_Route {
    88
    99        public function get_stats_overview() {
    10                 global $gpdb;
     10                global $wpdb;
    1111
    1212                $projects = array(
    … …  
    4141                                (100 * stats.current/stats.all) as percent_complete,
    4242                                stats.waiting+stats.fuzzy as waiting_strings
    43                         FROM {$gpdb->prefix}project_translation_status stats
    44                                 LEFT JOIN {$gpdb->prefix}projects p ON stats.project_id = p.id
     43                        FROM {$wpdb->prefix}project_translation_status stats
     44                                LEFT JOIN {$wpdb->prefix}projects p ON stats.project_id = p.id
    4545                        WHERE
    4646                                p.path IN ( $all_project_paths_sql )
    4747                                AND p.active = 1";
    4848
    49                 $rows = $gpdb->get_results( $sql );
     49                $rows = $wpdb->get_results( $sql );
    5050
    5151                // Split out into $[Locale][Project] = %
    … …  
    8080                                locale, locale_slug,
    8181                                SUM( stats.waiting ) + SUM( stats.fuzzy ) as waiting_strings
    82                         FROM {$gpdb->prefix}project_translation_status stats
    83                                 LEFT JOIN {$gpdb->prefix}projects p ON stats.project_id = p.id
     82                        FROM {$wpdb->prefix}project_translation_status stats
     83                                LEFT JOIN {$wpdb->prefix}projects p ON stats.project_id = p.id
    8484                        WHERE
    8585                                p.parent_project_id IN ( $parent_project_ids )
    … …  
    8787                        GROUP BY locale, locale_slug";
    8888
    89                 $rows = $gpdb->get_results( $sql );
     89                $rows = $wpdb->get_results( $sql );
    9090                foreach ( $rows as $set ) {
    9191                        $locale_key = $set->locale;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/wp-plugins.php

    r2089 r2109  
    11<?php
    22
    3 class GP_WPorg_Route_WP_Plugins extends GP_Route {
     3class WPorg_GP_Route_WP_Plugins extends GP_Route {
    44
    55        public function get_plugin_projects( $project_slug ) {
    6                 global $gpdb;
     6                global $wpdb;
    77
    88                $project_path = 'wp-plugins/' . $project_slug;
    … …  
    1212                }
    1313
    14                 $rows = $gpdb->get_results( "
     14                $rows = $wpdb->get_results( "
    1515                        SELECT
    1616                                path, locale, locale_slug,
    … …  
    1818                                stats.waiting+stats.fuzzy as waiting_strings,
    1919                                stats.untranslated as untranslated
    20                         FROM {$gpdb->prefix}project_translation_status stats
    21                                 LEFT JOIN {$gpdb->prefix}projects p ON stats.project_id = p.id
     20                        FROM {$wpdb->prefix}project_translation_status stats
     21                                LEFT JOIN {$wpdb->prefix}projects p ON stats.project_id = p.id
    2222                        WHERE
    2323                                p.parent_project_id = '{$project->id}'
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/wporg-gp-routes.php

    r2108 r2109  
    11<?php
    22/**
    3  * Register custom routes for translate.wordpress.org.
    4  *
    5  * @author ocean90, obenland, dd32
     3 * Plugin name: GlotPress: Register custom routes for translate.wordpress.org.
     4 * Plugin author: ocean90, obenland, dd32
    65 */
    76
    … …  
    1211require_once __DIR__ . '/routes/wp-plugins.php';
    1312
    14 class GP_WPorg_Routes extends GP_Plugin {
    15         public $id = 'wporg-routes';
     13class WPorg_GP_Routes {
    1614
    1715        public function __construct() {
    18                 parent::__construct();
    19                 $this->add_action( 'init' );
     16                add_action( 'init', array( $this, 'register_routes' ) );
    2017        }
    2118
    22         public function init() {
     19        public function register_routes() {
    2320                // Bail for API requests.
    2421                $request_uri = GP::$router->request_uri();
    … …  
    3532
    3633                // Redirect routes.
    37                 GP::$router->prepend( '/languages', array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
    38                 GP::$router->prepend( "/languages/$path", array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     34                GP::$router->prepend( '/languages', array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
     35                GP::$router->prepend( "/languages/$path", array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
    3936
    4037                // Register custom routes.
    41                 GP::$router->prepend( '/', array( 'GP_WPorg_Route_Index', 'get_locales' ) );
    42                 GP::$router->prepend( "/locale/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    43                 GP::$router->prepend( "/locale/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    44                 GP::$router->prepend( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    45                 GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
    46                 GP::$router->prepend( '/stats/?', array( 'GP_WPorg_Route_Stats', 'get_stats_overview' ) );
     38                GP::$router->prepend( '/', array( 'WPorg_GP_Route_Index', 'get_locales' ) );
     39                GP::$router->prepend( "/locale/$locale", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     40                GP::$router->prepend( "/locale/$locale/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     41                GP::$router->prepend( "/locale/$locale/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
     42                GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_project' ) );
     43                GP::$router->prepend( '/stats/?', array( 'WPorg_GP_Route_Stats', 'get_stats_overview' ) );
    4744                $project = '([^/]*)/?';
    48                 GP::$router->prepend( "/projects/wp-plugins/$project", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_projects' ) );
     45                GP::$router->prepend( "/projects/wp-plugins/$project", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_projects' ) );
    4946        }
    5047}
    5148
    52 GP::$plugins->wporg_routes = new GP_WPorg_Routes;
     49function wporg_gp_routes() {
     50        global $wporg_gp_routes;
     51
     52        if ( ! isset( $wporg_gp_routes ) ) {
     53                $wporg_gp_routes = new WPorg_GP_Routes();
     54        }
     55
     56        return $wporg_gp_routes;
     57}
     58add_action( 'plugins_loaded', 'wporg_gp_routes' );
Note: See TracChangeset for help on using the changeset viewer.