| | 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.7 |
| | 7 | License: GPLv2 or later |
| | 8 | Author: Marko Heijnen |
| | 9 | Author URI: http://www.markoheijnen.com |
| | 10 | Text Domain: wporg |
| | 11 | */ |
| | 12 | |
| | 13 | include 'inc/api.php'; |
| | 14 | include 'inc/crawler.php'; |
| | 15 | |
| | 16 | class WP_I18n_Teams { |
| | 17 | static $version = '0.7'; |
| | 18 | |
| | 19 | public function __construct() { |
| | 20 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| | 21 | add_shortcode( 'wp-i18n-team', array( $this, 'all_information' ) ); |
| | 22 | } |
| | 23 | |
| | 24 | public function enqueue_assets() { |
| | 25 | wp_enqueue_style( 'wp-i18n-team', plugins_url( 'css/front.css', __FILE__ ), array(), self::$version ); |
| | 26 | } |
| | 27 | |
| | 28 | public function all_information( $args ) { |
| | 29 | $no_sites = $no_downloads = $latest = $minor_behind = $major_behind_one = $major_behind_many = 0; |
| | 30 | |
| | 31 | $sites = WP_I18n_Team_Api::get_sites(); |
| | 32 | |
| | 33 | $table = '<table>'; |
| | 34 | $table .= '<thead>'; |
| | 35 | $table .= '<tr>'; |
| | 36 | $table .= '<th>' . __( 'Locale Name', 'wporg' ) . '</th>'; |
| | 37 | $table .= '<th>' . __( 'Native Name', 'wporg' ) . '</th>'; |
| | 38 | $table .= '<th>' . __( 'Locale Code', 'wporg' ) . '</th>'; |
| | 39 | $table .= '<th>' . __( 'WordPress Locale', 'wporg' ) . '</th>'; |
| | 40 | $table .= '<th>' . __( 'Version', 'wporg' ) . '</th>'; |
| | 41 | $table .= '</tr>'; |
| | 42 | $table .= '</thead>'; |
| | 43 | $table .= '<tbody>'; |
| | 44 | |
| | 45 | foreach ( $sites as $site ) { |
| | 46 | $locale = WP_I18n_Team_Crawler::get_locale( $site->slug, $site->wp_locale ); |
| | 47 | $class = ''; |
| | 48 | |
| | 49 | if ( $locale['version'] ) { |
| | 50 | $class = 'version'; |
| | 51 | |
| | 52 | $one_lower = WP_CORE_LATEST_RELEASE - 0.1; |
| | 53 | |
| | 54 | if ( $locale['version'] == WP_CORE_LATEST_RELEASE ) { |
| | 55 | $class .= ' latest'; |
| | 56 | |
| | 57 | $latest++; |
| | 58 | } |
| | 59 | else if ( substr( $locale['version'], 0, 3 ) == substr( WP_CORE_LATEST_RELEASE, 0, 3 ) ) { |
| | 60 | $class .= ' minor-behind'; |
| | 61 | |
| | 62 | $minor_behind++; |
| | 63 | } |
| | 64 | else if ( substr( $locale['version'], 0, 3 ) == substr( $one_lower, 0, 3 ) ) { |
| | 65 | $class .= ' major-behind-one'; |
| | 66 | |
| | 67 | $major_behind_one++; |
| | 68 | } |
| | 69 | else { |
| | 70 | $class .= ' major-behind-many'; |
| | 71 | |
| | 72 | $major_behind_many++; |
| | 73 | } |
| | 74 | } |
| | 75 | |
| | 76 | if ( $locale['url'] ) { |
| | 77 | $locale_code = '<a href="' . $locale['url'] . '">' . $site->slug . '</a>'; |
| | 78 | |
| | 79 | if ( $locale['version'] ) { |
| | 80 | $version = $locale['version']; |
| | 81 | } |
| | 82 | else { |
| | 83 | $version = __( 'None', 'wporg' ); |
| | 84 | |
| | 85 | $no_downloads++; |
| | 86 | } |
| | 87 | } |
| | 88 | else { |
| | 89 | $locale_code = $site->slug; |
| | 90 | $version = __( 'No site', 'wporg' ); |
| | 91 | |
| | 92 | $no_sites++; |
| | 93 | } |
| | 94 | |
| | 95 | $table .= '<tr class="' . $class . '">'; |
| | 96 | $table .= '<td>' . $site->english_name . '</td>'; |
| | 97 | $table .= '<td>' . $site->native_name . '</td>'; |
| | 98 | $table .= '<td>' . $locale_code . '</td>'; |
| | 99 | $table .= '<td>' . $site->wp_locale . '</td>'; |
| | 100 | $table .= '<td>' . $version . '</td>'; |
| | 101 | $table .= '</tr>'; |
| | 102 | } |
| | 103 | |
| | 104 | $table .= '</tbody>'; |
| | 105 | $table .= '</table>'; |
| | 106 | |
| | 107 | $html = '<p>'; |
| | 108 | $html .= sprintf( |
| | 109 | __( '%s locales up-to-date. %s locales behind by one minor version. %s locales behind by one major version. %s locales behind by two or more major versions. %s locales do not yet have a package available.', 'wporg' ), |
| | 110 | '<strong class="i18n-label latest">' . $latest . '</strong>', |
| | 111 | '<strong class="i18n-label minor-behind">' . $minor_behind . '</strong>', |
| | 112 | '<strong class="i18n-label major-behind-one">' . $major_behind_one . '</strong>', |
| | 113 | '<strong class="i18n-label major-behind-many">' . $major_behind_many . '</strong>', |
| | 114 | '<strong class="i18n-label">' . ( $no_sites + $no_downloads ) . '</strong>' |
| | 115 | ); |
| | 116 | $html .= '</p>'; |
| | 117 | |
| | 118 | $html = '<div class="translators-info">' . $html . $table . '</div>'; |
| | 119 | |
| | 120 | return $html; |
| | 121 | } |
| | 122 | |
| | 123 | } |
| | 124 | |
| | 125 | $GLOBALS['wp_i18n_teams'] = new WP_I18n_Teams(); |