Making WordPress.org

Changeset 4997


Ignore:
Timestamp:
02/24/2017 12:18:46 AM (8 years ago)
Author:
ocean90
Message:

Translate: Redirect previous glossary paths from /projects/wp/dev/$locale/$slug/glossary to /locale/$locale/$slug/glossary.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc
Files:
2 edited

Legend:

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

    r4995 r4997  
    125125            GP::$router->prepend( '/projects/wp-plugins/?', array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_index' ) );
    126126            GP::$router->prepend( '/projects/wp-themes/?', array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_index' ) );
     127            GP::$router->prepend( "/projects/wp/$path/$locale/$dir/glossary", array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_old_glossary' ) );
    127128
    128129            // Register custom routes.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-redirector.php

    r3002 r4997  
    33namespace WordPressdotorg\GlotPress\Routes\Routes;
    44
     5use GP;
    56use GP_Route;
     7use GP_Route_Glossary_Entry;
    68
    79/**
     
    2325        $this->redirect( '/' );
    2426    }
     27
     28    /**
     29     * Redirects previous glossary paths from `/projects/wp/dev/$locale/$slug/glossary`
     30     * to `/locale/$locale/$slug/glossary`.
     31     *
     32     * @param string $project_path Path of a project.
     33     * @param string $locale       Locale slug.
     34     * @param string $slug         Slug if a translation set.
     35     */
     36    public function redirect_old_glossary( $project_path = '', $locale = '', $slug = '' ) {
     37        $project_path = "wp/$project_path";
     38
     39        $project = GP::$project->by_path( $project_path );
     40        if ( ! $project ) {
     41            $route_glossary_entry = new GP_Route_Glossary_Entry();
     42            return $route_glossary_entry->glossary_entries_get( $project_path, $locale, $slug );
     43        }
     44
     45        $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $slug, $locale );
     46        if ( ! $translation_set ) {
     47            $route_glossary_entry = new GP_Route_Glossary_Entry();
     48            return $route_glossary_entry->glossary_entries_get( $project_path, $locale, $slug );
     49        }
     50
     51        // If the current project has a glossary stop here and load it.
     52        $glossary = GP::$glossary->by_set_id( $translation_set->id );
     53        if ( $glossary ) {
     54            $route_glossary_entry = new GP_Route_Glossary_Entry();
     55            return $route_glossary_entry->glossary_entries_get( $project_path, $locale, $slug );
     56        }
     57
     58        // Otherwise redirect to the locale glossary.
     59        $locale_glossary_translation_set = GP::$translation_set->by_project_id_slug_and_locale( 0, $slug, $locale );
     60        $locale_glossary = GP::$glossary->by_set_id( $locale_glossary_translation_set->id );
     61        $this->redirect( $locale_glossary->path() );
     62    }
    2563}
Note: See TracChangeset for help on using the changeset viewer.