Making WordPress.org


Ignore:
Timestamp:
07/10/2015 05:29:36 PM (9 years ago)
Author:
ocean90
Message:

Translate: Improve custom routes.

  • Don't register custom routes for API request.
  • Move locale overview to translate.wordpress.org, no redirect anymore.
  • Replace /languages prefix with /locale.
  • Redirect old /languages URLs to the new route.
  • Rename custom templates.

see #994, #1091.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/wporg-routes.php

    r1684 r1721  
    11<?php
    22/**
    3  * This plugins overrides some of the default routes of GlotPress.
     3 * Register custom routes for translate.wordpress.org.
    44 *
    55 * @author ocean90
    66 */
    77
     8require_once __DIR__ . '/routes/redirector.php';
    89require_once __DIR__ . '/routes/index.php';
    910require_once __DIR__ . '/routes/locale.php';
     
    1819
    1920    public function init() {
     21        // Bail for API requests.
     22        $request_uri = GP::$router->request_uri();
     23        if ( gp_startswith( $request_uri, '/' . GP::$router->api_prefix . '/' ) ) {
     24            return;
     25        }
     26
    2027        $path = '(.+?)';
    2128        $locale = '(' . implode( '|', array_map( function( $locale ) { return $locale->slug; }, GP_Locales::locales() ) ) . ')';
    2229
    23         /*
    24          * Unset default routes.
    25          * The `routes` filter can't be used, see https://glotpress.trac.wordpress.org/ticket/249.
    26          */
     30        // Unset default routes.
    2731        unset( GP::$router->urls['/'] );
    2832        unset( GP::$router->urls["get:/languages/$locale/$path"] );
     
    3034        unset( GP::$router->urls['get:/languages'] );
    3135
    32         GP::$router->add( '/', array( 'GP_WPorg_Route_Index', 'get_index' ) );
    33         GP::$router->add( "/languages/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
    34         GP::$router->add( "/languages/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    35         GP::$router->add( "/languages/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    36         GP::$router->add( "/languages/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    37         GP::$router->add( '/languages', array( 'GP_WPorg_Route_Locale', 'get_locales' ) );
     36        // Redirect routes.
     37        GP::$router->add( "/languages/$path", array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     38        GP::$router->add( '/languages', array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     39
     40        // Register custom routes.
     41        GP::$router->add( '/', array( 'GP_WPorg_Route_Index', 'get_locales' ) );
     42        GP::$router->add( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
     43        GP::$router->add( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     44        GP::$router->add( "/locale/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     45        GP::$router->add( "/locale/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    3846    }
    3947}
Note: See TracChangeset for help on using the changeset viewer.