Changeset 3002
- Timestamp:
- 04/25/2016 03:38:34 PM (9 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes
- Files:
-
- 4 added
- 8 deleted
- 1 edited
- 9 copied
- 2 moved
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' ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/cli/class-update-caches.php
r2999 r3002 1 1 <?php 2 2 3 class WPorg_GP_CLI_Update_Caches extends WP_CLI_Command { 3 namespace WordPressdotorg\GlotPress\Routes\CLI; 4 5 use GP; 6 use WP_CLI; 7 use WP_CLI_Command; 8 9 class Update_Caches extends WP_CLI_Command { 4 10 5 11 private $cache_group = 'wporg-translate'; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-index.php
r2999 r3002 1 1 <?php 2 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use GP_Locales; 6 use GP_Route; 7 2 8 /** 3 9 * Index Route Class. … … 5 11 * Provides the route for translate.wordpress.org/. 6 12 */ 7 class WPorg_GP_Route_Index extends GP_Route {13 class Index extends GP_Route { 8 14 9 15 private $cache_group = 'wporg-translate'; … … 24 30 $locales[] = GP_Locales::by_slug( $locale ); 25 31 } 26 usort( $locales, array( $this, '_sort_english_name_callback' ) );32 usort( $locales, array( $this, '_sort_english_name_callback' ) ); 27 33 unset( $existing_locales ); 28 34 -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-locale.php
r2999 r3002 1 1 <?php 2 2 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 3 5 // wporg_get_plugin_icon() 4 if ( file_exists( WPORGPATH . 'extend/plugins-plugins/_plugin-icons.php' ) ) { 5 include_once WPORGPATH . 'extend/plugins-plugins/_plugin-icons.php'; 6 } 6 use GP; 7 use GP_Locales; 8 use GP_Route; 9 use stdClass; 7 10 8 11 /** … … 11 14 * Provides the route for translate.wordpress.org/locale/$locale. 12 15 */ 13 class WPorg_GP_Route_Locale extends GP_Route {16 class Locale extends GP_Route { 14 17 15 18 /** 16 19 * Prints projects/translation sets of a top level project. 17 20 * 18 * @param string $locale_slugSlug of the locale.19 * @param string $set_slugSlug of the translation set.20 * @param string $project_pathPath of a project.21 * @param string $locale_slug Slug of the locale. 22 * @param string $set_slug Slug of the translation set. 23 * @param bool|string $project_path Path of a project. 21 24 */ 22 25 public function get_locale_projects( $locale_slug, $set_slug = 'default', $project_path = false ) { … … 101 104 $project_ids = array_merge( 102 105 $project_ids, 103 $wpdb->get_col( "SELECT id FROM {$wpdb->gp_projects} WHERE parent_project_id IN( " . implode(', ', $project_ids ) . ")")106 $wpdb->get_col( "SELECT id FROM {$wpdb->gp_projects} WHERE parent_project_id IN( " . implode( ', ', $project_ids ) . ')' ) 104 107 ); 105 108 … … 192 195 } 193 196 194 switch ( $project->slug ) {197 switch ( $project->slug ) { 195 198 case 'wp': 196 199 return '<div class="wordpress-icon"><span class="dashicons dashicons-wordpress-alt"></span></div>'; 197 200 case 'meta': 198 switch ( $sub_project->slug ) {201 switch ( $sub_project->slug ) { 199 202 case 'forums': 200 203 return '<div class="default-icon"><span class="dashicons dashicons-format-chat"></span></div>'; -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-redirector.php
r2999 r3002 1 1 <?php 2 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use GP_Route; 6 2 7 /** 3 8 * Redirector Route Class. … … 5 10 * Provides redirection routes. 6 11 */ 7 class WPorg_GP_Route_Redirector extends GP_Route {12 class Redirector extends GP_Route { 8 13 9 14 public function redirect_languages( $path = '' ) { -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php
r2999 r3002 1 1 <?php 2 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use GP; 6 use GP_Route; 7 2 8 /** 3 9 * Stats Route Class. … … 5 11 * Provides the route for translate.wordpress.org/stats. 6 12 */ 7 class WPorg_GP_Route_Stats extends GP_Route {13 class Stats extends GP_Route { 8 14 9 15 public function get_stats_overview() { … … 22 28 23 29 // I'm sure there's somewhere to fetch these from statically defined 24 $wp_project = GP::$project->by_path( 'wp');30 $wp_project = GP::$project->by_path( 'wp' ); 25 31 foreach ( GP::$project->find_many( array( 'parent_project_id' => $wp_project->id, 'active' => 1 ), 'name ASC' ) as $wp_sub_project ) { 26 32 // Prefix the WordPress projects... … … 75 81 $parent_project_ids = implode(',', array( 76 82 GP::$project->by_path( 'wp-plugins' )->id, 77 GP::$project->by_path( 'wp-themes' )->id 83 GP::$project->by_path( 'wp-themes' )->id, 78 84 ) ); 79 85 $sql = "SELECT -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-wp-directory.php
r2999 r3002 1 1 <?php 2 2 3 class WPorg_GP_Route_WP_Directory extends GP_Route { 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use DateInterval; 6 use DatePeriod; 7 use DateTime; 8 use GP_Route; 9 10 class WP_Directory extends GP_Route { 4 11 5 12 /** … … 46 53 unset( $translation_editors ); 47 54 48 foreach ( $this->get_translation_contributors_by_locale( $project->id ) as $row ) {55 foreach ( $this->get_translation_contributors_by_locale( $project->id ) as $row ) { 49 56 if ( ! isset( $contributors_by_locale[ $row->locale ] ) ) { 50 57 $contributors_by_locale[ $row->locale ] = $default_value; … … 79 86 80 87 foreach ( $sub_projects as $sub_project ) { 81 foreach ( $this->get_translation_contributors_by_locale( $sub_project ) as $row ) {88 foreach ( $this->get_translation_contributors_by_locale( $sub_project ) as $row ) { 82 89 if ( ! isset( $contributors_by_locale[ $row->locale ] ) ) { 83 90 $contributors_by_locale[ $row->locale ] = $default_value; … … 112 119 * Generates the chart data for contributors activity. 113 120 * 114 * @param GP_Project $project_idThe project.121 * @param \GP_Project $project The project. 115 122 * @return array The data to build a chart via Chartist.js. 116 123 */ … … 126 133 $project_ids = array_merge( array( $project->id ), $sub_projects ); 127 134 $translation_set_ids = $wpdb->get_col( " 128 SELECT `id` FROM {$wpdb->gp_translation_sets} WHERE `project_id` IN ( " . implode( ',', $project_ids ) . ")135 SELECT `id` FROM {$wpdb->gp_translation_sets} WHERE `project_id` IN ( " . implode( ',', $project_ids ) . ") 129 136 " ); 130 137 … … 139 146 140 147 $days = array(); 141 foreach ( $date_range as $date ) {148 foreach ( $date_range as $date ) { 142 149 $days[] = $date->format( 'Y-m-d' ); 143 150 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-wp-plugins.php
r2999 r3002 1 1 <?php 2 2 3 class WPorg_GP_Route_WP_Plugins extends WPorg_GP_Route_WP_Directory { 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use GP; 6 7 class WP_Plugins extends WP_Directory { 4 8 5 9 /** … … 105 109 */ 106 110 public function get_plugin_contributors( $project_slug ) { 107 global $wpdb;108 109 111 $project_path = 'wp-plugins/' . $project_slug; 110 112 $project = GP::$project->by_path( $project_path ); … … 169 171 $default = '<div class="default-icon"><span class="dashicons dashicons-admin-plugins"></span></div>'; 170 172 173 $icon = ''; 171 174 if ( function_exists( 'wporg_get_plugin_icon' ) ) { 172 175 $icon = wporg_get_plugin_icon( $project->slug, $size ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-wp-themes.php
r2999 r3002 1 1 <?php 2 2 3 class WPorg_GP_Route_WP_Themes extends WPorg_GP_Route_WP_Directory { 3 namespace WordPressdotorg\GlotPress\Routes\Routes; 4 5 use GP; 6 7 class WP_Themes extends WP_Directory { 4 8 5 9 /** -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/wporg-gp-routes.php
r2932 r3002 3 3 * Plugin name: GlotPress: Custom Routes 4 4 * Description: Provides custom routes like <code>/locale</code> or <code>/stats</code> for translate.wordpress.org. 5 * Version: 1.05 * Version: 2.0 6 6 * Author: WordPress.org 7 7 * Author URI: http://wordpress.org/ … … 9 9 */ 10 10 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'; 11 namespace WordPressdotorg\GlotPress\Routes; 18 12 19 class WPorg_GP_Routes { 13 use WordPressdotorg\Autoload; 20 14 21 public function __construct() { 22 add_action( 'template_redirect', array( $this, 'register_routes' ), 5);15 // Store the root plugin file for usage with functions which use the plugin basename. 16 define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ ); 23 17 24 if ( defined( 'WP_CLI' ) && WP_CLI ) { 25 $this->register_cli_commands(); 26 } 27 } 28 29 /** 30 * Registers custom routes and removes default routes. 31 * 32 * Removes: 33 * - API: /languages/$locale 34 * - /languages/$locale 35 * - /languages/$locale 36 * - /languages/$locale/$path 37 * - /profile/$path 38 * - /projects/wp-plugins/? 39 * - /projects/wp-themes/? 40 * 41 * Adds: 42 * - / 43 * - /locale/$locale 44 * - /locale/$locale/$path 45 * - /locale/$locale/$path/$path 46 * - /locale/$locale/$path/$path/$path 47 * - /stats/? 48 * - /projects/wp-plugins/$project 49 * - /projects/wp-plugins/$project/contributors 50 * - /projects/wp-plugins/$project/language-packs 51 * - /projects/wp-themes/$project 52 * - /projects/wp-themes/$project/contributors 53 * - /projects/wp-themes/$project/language-packs 54 */ 55 public function register_routes() { 56 $request_uri = GP::$router->request_uri(); 57 $path = '(.+?)'; 58 $locale = '(' . implode( '|', array_map( function( $locale ) { return $locale->slug; }, GP_Locales::locales() ) ) . ')'; 59 60 if ( gp_startswith( $request_uri, '/' . GP::$router->api_prefix . '/' ) ) { // API requests. 61 // Delete default routes. 62 GP::$router->remove( "/languages/$locale" ); 63 } else { 64 // Delete default routes. 65 GP::$router->remove( "/languages/$locale" ); 66 GP::$router->remove( "/languages/$locale/$path" ); 67 GP::$router->remove( "/profile" ); 68 GP::$router->remove( "/profile/$path" ); 69 70 // 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' ) ); 75 76 // 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' ) ); 83 $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' ) ); 90 } 91 } 92 93 /** 94 * Registers CLI commands if WP-CLI is loaded. 95 */ 96 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' ); 100 } 18 if ( ! class_exists( '\WordPressdotorg\Autoload\Autoloader', false ) ) { 19 include __DIR__ . '/vendor/wordpressdotorg/class-autoloader.php'; 101 20 } 102 21 103 function wporg_gp_routes() { 104 global $wporg_gp_routes;22 // Register an Autoloader for all files. 23 Autoload\register_class_path( __NAMESPACE__, __DIR__ . '/inc' ); 105 24 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' ); 25 // Instantiate the Plugin. 26 Plugin::get_instance();
Note: See TracChangeset
for help on using the changeset viewer.