Changeset 3002 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php
- Timestamp:
- 04/25/2016 03:38:34 PM (10 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc
- Files:
-
- 1 added
- 1 copied
-
. (added)
-
class-plugin.php (copied) (copied from sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/wporg-gp-routes.php) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php
r2999 r3002 1 1 <?php 2 /**3 * Plugin name: GlotPress: Custom Routes4 * Description: Provides custom routes like <code>/locale</code> or <code>/stats</code> for translate.wordpress.org.5 * Version: 1.06 * Author: WordPress.org7 * Author URI: http://wordpress.org/8 * License: GPLv2 or later9 */10 2 11 require_once __DIR__ . '/routes/redirector.php'; 12 require_once __DIR__ . '/routes/index.php'; 13 require_once __DIR__ . '/routes/locale.php'; 14 require_once __DIR__ . '/routes/stats-overview.php'; 15 require_once __DIR__ . '/routes/wp-directory.php'; 16 require_once __DIR__ . '/routes/wp-plugins.php'; 17 require_once __DIR__ . '/routes/wp-themes.php'; 3 namespace WordPressdotorg\GlotPress\Routes; 18 4 19 class WPorg_GP_Routes { 5 use GP; 6 use GP_Locales; 7 use WP_CLI; 20 8 21 public function __construct() { 9 class Plugin { 10 11 /** 12 * @var Plugin The singleton instance. 13 */ 14 private static $instance; 15 16 /** 17 * 18 * @var Sync\Translation_Sync 19 */ 20 public $translation_sync = null; 21 22 /** 23 * Returns always the same instance of this plugin. 24 * 25 * @return Plugin 26 */ 27 public static function get_instance() { 28 if ( ! ( self::$instance instanceof Plugin ) ) { 29 self::$instance = new Plugin(); 30 } 31 return self::$instance; 32 } 33 34 /** 35 * Instantiates a new Plugin object. 36 */ 37 private function __construct() { 38 add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); 39 } 40 41 /** 42 * Initializes the plugin. 43 */ 44 public function plugins_loaded() { 45 if ( file_exists( WPORGPATH . 'extend/plugins-plugins/_plugin-icons.php' ) ) { 46 include_once WPORGPATH . 'extend/plugins-plugins/_plugin-icons.php'; 47 } 48 22 49 add_action( 'template_redirect', array( $this, 'register_routes' ), 5 ); 23 50 … … 65 92 GP::$router->remove( "/languages/$locale" ); 66 93 GP::$router->remove( "/languages/$locale/$path" ); 67 GP::$router->remove( "/profile");94 GP::$router->remove( '/profile' ); 68 95 GP::$router->remove( "/profile/$path" ); 69 96 70 97 // Redirect routes. 71 GP::$router->prepend( '/languages', array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );72 GP::$router->prepend( "/languages/$path", array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );73 GP::$router->prepend( '/projects/wp-plugins/?', array( 'WPorg_GP_Route_Redirector', 'redirect_index' ) );74 GP::$router->prepend( '/projects/wp-themes/?', array( 'WPorg_GP_Route_Redirector', 'redirect_index' ) );98 GP::$router->prepend( '/languages', array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_languages' ) ); 99 GP::$router->prepend( "/languages/$path", array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_languages' ) ); 100 GP::$router->prepend( '/projects/wp-plugins/?', array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_index' ) ); 101 GP::$router->prepend( '/projects/wp-themes/?', array( __NAMESPACE__ . '\Routes\Redirector', 'redirect_index' ) ); 75 102 76 103 // Register custom routes. 77 GP::$router->prepend( '/', array( 'WPorg_GP_Route_Index', 'get_locales' ) );78 GP::$router->prepend( "/locale/$locale", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );79 GP::$router->prepend( "/locale/$locale/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );80 GP::$router->prepend( "/locale/$locale/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );81 GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_project' ) );82 GP::$router->prepend( '/stats/?', array( 'WPorg_GP_Route_Stats', 'get_stats_overview' ) );104 GP::$router->prepend( '/', array( __NAMESPACE__ . '\Routes\Index', 'get_locales' ) ); 105 GP::$router->prepend( "/locale/$locale", array( __NAMESPACE__ . '\Routes\Locale', 'get_locale_projects' ) ); 106 GP::$router->prepend( "/locale/$locale/$path", array( __NAMESPACE__ . '\Routes\Locale', 'get_locale_projects' ) ); 107 GP::$router->prepend( "/locale/$locale/$path/$path", array( __NAMESPACE__ . '\Routes\Locale', 'get_locale_projects' ) ); 108 GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( __NAMESPACE__ . '\Routes\Locale', 'get_locale_project' ) ); 109 GP::$router->prepend( '/stats/?', array( __NAMESPACE__ . '\Routes\Stats', 'get_stats_overview' ) ); 83 110 $project = '([^/]*)/?'; 84 GP::$router->prepend( "/projects/wp-plugins/$project", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_projects' ) );85 GP::$router->prepend( "/projects/wp-plugins/$project/contributors", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_contributors' ) );86 GP::$router->prepend( "/projects/wp-plugins/$project/language-packs", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_language_packs' ) );87 GP::$router->prepend( "/projects/wp-themes/$project", array( 'WPorg_GP_Route_WP_Themes', 'get_theme_projects' ) );88 GP::$router->prepend( "/projects/wp-themes/$project/contributors", array( 'WPorg_GP_Route_WP_Themes', 'get_theme_contributors' ) );89 GP::$router->prepend( "/projects/wp-themes/$project/language-packs", array( 'WPorg_GP_Route_WP_Themes', 'get_theme_language_packs' ) );111 GP::$router->prepend( "/projects/wp-plugins/$project", array( __NAMESPACE__ . '\Routes\WP_Plugins', 'get_plugin_projects' ) ); 112 GP::$router->prepend( "/projects/wp-plugins/$project/contributors", array( __NAMESPACE__ . '\Routes\WP_Plugins', 'get_plugin_contributors' ) ); 113 GP::$router->prepend( "/projects/wp-plugins/$project/language-packs", array( __NAMESPACE__ . '\Routes\WP_Plugins', 'get_plugin_language_packs' ) ); 114 GP::$router->prepend( "/projects/wp-themes/$project", array( __NAMESPACE__ . '\Routes\WP_Themes', 'get_theme_projects' ) ); 115 GP::$router->prepend( "/projects/wp-themes/$project/contributors", array( __NAMESPACE__ . '\Routes\WP_Themes', 'get_theme_contributors' ) ); 116 GP::$router->prepend( "/projects/wp-themes/$project/language-packs", array( __NAMESPACE__ . '\Routes\WP_Themes', 'get_theme_language_packs' ) ); 90 117 } 91 118 } … … 95 122 */ 96 123 function register_cli_commands() { 97 require_once __DIR__ . '/cli/update-caches.php'; 98 99 WP_CLI::add_command( 'wporg-translate update-cache', 'WPorg_GP_CLI_Update_Caches' ); 124 WP_CLI::add_command( 'wporg-translate update-cache', __NAMESPACE__ . '\CLI\Update_Caches' ); 100 125 } 101 126 } 102 103 function wporg_gp_routes() {104 global $wporg_gp_routes;105 106 if ( ! isset( $wporg_gp_routes ) ) {107 $wporg_gp_routes = new WPorg_GP_Routes();108 }109 110 return $wporg_gp_routes;111 }112 add_action( 'plugins_loaded', 'wporg_gp_routes' );
Note: See TracChangeset
for help on using the changeset viewer.