Changeset 2663 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/locale.php
- Timestamp:
- 03/01/2016 10:46:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/routes/locale.php
r2181 r2663 167 167 $variants = $this->get_locale_variants( $locale_slug, array( $sub_project->id ) ); 168 168 } 169 170 $locale_contributors = $this->get_locale_contributors( $sub_project, $locale_slug, $set_slug ); 169 171 170 172 $this->tmpl( 'locale-project', get_defined_vars() ); … … 258 260 259 261 return $slugs; 262 } 263 264 /** 265 * Retrieves contributors of a project. 266 * 267 * @param GP_Project $project A GlotPress project. 268 * @param string $locale_slug Slug of the locale. 269 * @param string $set_slug Slug of the translation set. 270 * @return array Contributors. 271 */ 272 private function get_locale_contributors( $project, $locale_slug, $set_slug ) { 273 global $wpdb; 274 275 $locale_contributors = array( 276 'editors' => array(), 277 'contributors' => array(), 278 ); 279 280 // Get the translation editors of the project. 281 $editors = $wpdb->get_col( $wpdb->prepare( " 282 SELECT 283 `user_id` 284 FROM {$wpdb->wporg_translation_editors} 285 WHERE 286 `project_id` = %d 287 AND `locale` = %s 288 ", $project->id, $locale_slug ) ); 289 290 // Get the names of the translation editors. 291 foreach ( $editors as $editor_id ) { 292 $user = get_user_by( 'id', $editor_id ); 293 if ( ! $user ) { 294 continue; 295 } 296 297 $locale_contributors['editors'][ $editor_id ] = (object) array( 298 'nicename' => $user->user_nicename, 299 'display_name' => $this->_encode( $user->display_name ), 300 'email' => $user->user_email, 301 ); 302 } 303 unset( $editors ); 304 305 // Get the contributors of the project. 306 $contributors = array(); 307 308 // In case the project has a translation set, like /wp-themes/twentysixteen. 309 $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $project->id, $set_slug, $locale_slug ); 310 if ( $translation_set ) { 311 $contributors = array_merge( 312 $contributors, 313 $this->get_locale_contributors_by_translation_set( $translation_set ) 314 ); 315 } 316 317 // Check if the project has sub-projects, like /wp-plugins/wordpress-importer. 318 $sub_projects = $wpdb->get_col( $wpdb->prepare( " 319 SELECT id 320 FROM {$wpdb->gp_projects} 321 WHERE parent_project_id = %d 322 ", $project->id ) ); 323 324 foreach ( $sub_projects as $sub_project ) { 325 $translation_set = GP::$translation_set->by_project_id_slug_and_locale( $sub_project, $set_slug, $locale_slug ); 326 if ( ! $translation_set ) { 327 continue; 328 } 329 330 $contributors = array_merge( 331 $contributors, 332 $this->get_locale_contributors_by_translation_set( $translation_set ) 333 ); 334 } 335 336 // Get the names of the contributors. 337 foreach ( $contributors as $contributor_id ) { 338 if ( isset( $locale_contributors['editors'][ $contributor_id ] ) ) { 339 continue; 340 } 341 342 if ( isset( $locale_contributors['contributors'][ $contributor_id ] ) ) { 343 continue; 344 } 345 346 $user = get_user_by( 'id', $contributor_id ); 347 if ( ! $user ) { 348 continue; 349 } 350 351 $locale_contributors['contributors'][ $contributor_id ] = (object) array( 352 'nicename' => $user->user_nicename, 353 'display_name' => $this->_encode( $user->display_name ), 354 'email' => $user->user_email, 355 ); 356 } 357 unset( $contributors ); 358 359 return $locale_contributors; 360 } 361 362 /** 363 * Retrieves contributors of a translation set. 364 * 365 * @param GP_Translation_Set $translation_set A translation set. 366 * @return array List of user IDs. 367 */ 368 private function get_locale_contributors_by_translation_set( $translation_set ) { 369 global $wpdb; 370 371 $user_ids = $wpdb->get_col( $wpdb->prepare( " 372 SELECT DISTINCT( `user_id` ) 373 FROM `{$wpdb->gp_translations}` 374 WHERE 375 `translation_set_id` = %d 376 AND `user_id` IS NOT NULL AND `user_id` != 0 377 AND `status` <> 'rejected' 378 AND `date_modified` > %s 379 ", $translation_set->id, date( 'Y-m-d', time() - YEAR_IN_SECONDS ) ) ); 380 381 return $user_ids; 260 382 } 261 383 … … 620 742 return strcasecmp( $a->name, $b->name ); 621 743 } 744 745 private function _encode( $raw ) { 746 $raw = mb_convert_encoding( $raw, 'UTF-8', 'ASCII, JIS, UTF-8, Windows-1252, ISO-8859-1' ); 747 return ent2ncr( htmlspecialchars_decode( htmlentities( $raw, ENT_NOQUOTES, 'UTF-8' ), ENT_NOQUOTES ) ); 748 } 622 749 }
Note: See TracChangeset
for help on using the changeset viewer.