Ticket #340: 340.diff
File 340.diff, 5.1 KB (added by , 11 years ago) |
---|
-
wordpress.org/public_html/wp-content/plugins/wp-i18n-team-crawler
-
wordpress.org/public_html/wp-content/plugins/wp-i18n-team-crawler/crawler.php
Property changes on: wordpress.org/public_html/wp-content/plugins/wp-i18n-team-crawler ___________________________________________________________________ Added: svn:externals ## -0,0 +1 ## +locales http://glotpress.svn.wordpress.org/trunk/locales/
1 <?php 2 3 class WP_I18n_Team_Crawler { 4 5 public static function get_sites() { 6 include 'locales/locales.php'; 7 8 $locales = GP_Locales::locales(); 9 $locales = array_filter( $locales, array( __CLASS__, 'filter_locale_for_wp' ) ); 10 usort( $locales, array( __CLASS__, 'sort_locales' ) ); 11 12 return $locales; 13 } 14 15 public static function get_validators( $locale ) { 16 $url = 'http://api.wordpress.org/core/credits/1.1/?version=' . self::current_wordpress_version() . '&locale=' . $locale; 17 18 if ( false === ( $validators = get_transient( 'wp-i18n-validators-' . $locale ) ) ) { 19 $response = wp_remote_get( $url ); 20 $body = wp_remote_retrieve_body( $response ); 21 22 if( $body ) { 23 $data = json_decode( $body ); 24 25 if( isset( $data->groups->validators ) ) { 26 $validators = $data->groups->validators->data; 27 } 28 else { 29 $validators = array(); 30 } 31 32 if( isset( $data->groups->translators ) ) { 33 $translators = $data->groups->translators->data; 34 } 35 else { 36 $translators = array(); 37 } 38 39 set_transient( 'wp-i18n-validators-' . $locale, $validators, DAY_IN_SECONDS * 2 ); 40 set_transient( 'wp-i18n-translators-' . $locale, $translators, DAY_IN_SECONDS * 2 ); 41 } 42 } 43 44 return $validators; 45 } 46 47 public static function get_translators( $locale ) { 48 if ( false === ( $translators = get_transient( 'wp-i18n-translators-' . $locale ) ) ) { 49 self::get_validators( $locale ); 50 51 $translators = get_transient( 'wp-i18n-translators-' . $locale ); 52 } 53 54 return $translators; 55 } 56 57 58 /* HELPER FUNCTIONS*/ 59 60 private static function current_wordpress_version() { 61 global $wp_version; 62 63 return $wp_version; 64 } 65 66 public static function filter_locale_for_wp( $element ) { 67 if ( ! isset( $element->wp_locale ) ) { 68 return false; 69 } 70 71 return true; 72 } 73 74 public static function sort_locales( $a, $b ) { 75 return strcmp( $a->english_name, $b->english_name ); 76 } 77 78 } 79 80 new WP_I18n_Team_Crawler(); 81 No newline at end of file -
wordpress.org/public_html/wp-content/plugins/wp-i18n-team-crawler/wp-i18n-team-crawler.php
1 <?php 2 /* 3 Plugin Name: WP I18N Teams 4 Plugin URI: 5 Description: Scans through a few APIs to generate a list of all languages/members 6 Version: 0.1 7 License: GPLv2 or later 8 Author: Marko Heijnen 9 Author URI: http://www.markoheijnen.com 10 Text Domain: wp-i18n-team-crawler 11 Domain Path: /languages 12 */ 13 14 include 'crawler.php'; 15 16 class WP_I18n_Teams { 17 18 public function __construct() { 19 add_shortcode( 'wp-i18n-team', array( $this, 'all_information' ) ); 20 } 21 22 public function all_information( $args ) { 23 $html = ''; 24 $sites = WP_I18n_Team_Crawler::get_sites(); 25 26 foreach ( $sites as $site ) { 27 $validators = WP_I18n_Team_Crawler::get_validators( $site->wp_locale ); 28 $translators = WP_I18n_Team_Crawler::get_translators( $site->wp_locale ); 29 30 $html .= '<li>'; 31 $html .= '<h2>' . $site->english_name . ' – ' . $site->native_name . ' ( ' . $site->wp_locale . ' )</h2>'; 32 $html .= '<a href="http://' . $site->slug .'.wordpress.org">View site</a>'; 33 34 $html .= '<h3>' . __( 'Validators', 'wp-i18n-team-crawler' ) . '</h3>'; 35 $html .= '<ul>'; 36 37 if ( $validators ) { 38 foreach( $validators as $validator ) { 39 $html .= '<li>'; 40 $html .= $validator[0]; 41 $html .= '</li>'; 42 } 43 } 44 else { 45 $html .= '<li>' . __( 'No validators yet', 'wp-i18n-team-crawler' ) . '</li>'; 46 } 47 48 $html .= '</ul>'; 49 50 if( $translators ) { 51 $html .= '<h3>' . __( 'Translators', 'wp-i18n-team-crawler' ) . '</h3>'; 52 $html .= '<ul>'; 53 54 foreach( $translators as $translator ) { 55 $html .= '<li>'; 56 $html .= $translator; 57 $html .= '</li>'; 58 } 59 60 $html .= '</ul>'; 61 } 62 } 63 64 $html = '<ul class="translators-info">' . $html . '</ul>'; 65 66 return $html; 67 } 68 } 69 70 new WP_I18n_Teams(); 71 No newline at end of file