Ticket #7860: 7860.2.diff
File 7860.2.diff, 5.8 KB (added by , 6 months ago) |
---|
-
core/credits/wp-credits.php
abstract class WP_Credits { 209 209 private function _grab_validators( $gp_locale, $path ) { 210 210 global $wpdb; 211 211 $users = $this->grab_validators( $gp_locale, $path ); 212 212 213 213 if ( ! $users ) 214 214 return array(); 215 215 216 216 $validator_data = $wpdb->get_results( "SELECT user_nicename, display_name, user_email FROM $wpdb->users WHERE ID IN (" . implode( ',', $users ) . ")" ); 217 217 218 218 $validators = array(); 219 219 220 220 foreach ( $validator_data as $user ) { 221 221 if ( $user->user_nicename == 'nacin' ) // I stopped taking Spanish in 11th grade, don't show me as a validator when I'm testing things. 222 222 continue; 223 223 if ( $user->display_name && $user->display_name != $user->user_nicename && false === strpos( $user->display_name , '?') ) 224 $validators[ $user->user_nicename ] = array( $this->_encode( $user->display_name ), md5( $user->user_email ), $user->user_nicename );224 $validators[ $user->user_nicename ] = array( $this->_encode( $user->display_name ), $this->hash( $user->user_email ), $user->user_nicename ); 225 225 else 226 $validators[ $user->user_nicename ] = array( $user->user_nicename, md5( $user->user_email ), $user->user_nicename );226 $validators[ $user->user_nicename ] = array( $user->user_nicename, $this->hash( $user->user_email ), $user->user_nicename ); 227 227 } 228 228 229 229 return $validators; 230 230 } 231 231 232 232 protected function grab_validators( $gp_locale, $path ) { 233 233 global $wpdb; 234 234 235 235 $path = 'wp/' . $path; 236 236 $path = like_escape( $path ) . '%'; 237 237 238 238 $project_ids = $wpdb->get_col( "SELECT `id` FROM `translate_projects` WHERE ( `path` LIKE '$path' OR `path` = 'wp' ) AND `active` = 1" ); // Project validators 239 239 if ( ! $project_ids ) { 240 240 $project_ids = array(); 241 241 } … … abstract class WP_Credits { 287 287 if ( isset( $this->groups ) ) 288 288 return $this->groups; 289 289 290 290 $groups = $this->groups(); 291 291 $fetch_emails_from_user_cache = $fetch_emails_from_db = array(); 292 292 293 293 foreach ( $groups as $group_slug => $group_data ) { 294 294 if ( 'list' == $group_data['type'] ) 295 295 continue; 296 296 foreach ( $group_data['data'] as $k => $person ) { 297 297 $person = (array) $person; 298 298 $new_data = array( 'name' => $person[0], 'hash' => '', 'username' => $k, 'title' => '' ); 299 299 $this->names_in_groups[] = strtolower( $k ); 300 300 301 301 if ( ! empty( $person[2] ) ) { 302 // array( 'Andrew Nacin', 'Lead Developer', ' md5hash' )302 // array( 'Andrew Nacin', 'Lead Developer', 'gravatar hash' ) 303 303 $new_data['title'] = $person[1]; 304 304 $new_data['hash'] = $person[2]; 305 305 } elseif ( empty( $person[1] ) ) { 306 306 // array( 'Andrew Nacin' ) 307 307 $fetch_emails_from_user_cache[ $k ] = $group_slug; 308 } elseif ( strlen( $person[1] ) === 32 && preg_match('/^[a-f0-9]{32}$/',$person[1] ) ) {309 // array( 'Andrew Nacin', ' md5hash' )308 } elseif ( $this->is_hashed( $person[1] ) ) { 309 // array( 'Andrew Nacin', 'gravatar hash' ) 310 310 $new_data['hash'] = $person[1]; 311 311 } else { 312 312 // array( 'Andrew Nacin', 'Lead Developer' ) 313 313 $new_data['title'] = $person[1]; 314 314 $fetch_emails_from_user_cache[ $k ] = $group_slug; 315 315 } 316 316 317 317 // Temporary: 318 if ( strlen( $new_data['hash'] ) != 32 || strpos( $new_data['hash'], '@') ) {319 $new_data['hash'] = md5( $new_data['hash'] );318 if ( ! $this->is_hashed( $new_data['hash'] ) ) { 319 $new_data['hash'] = $this->hash( $new_data['hash'] ); 320 320 } 321 321 322 322 $group_data['data'][ $k ] = array_values( $new_data ); 323 323 } 324 324 325 325 $groups[ $group_slug ]['data'] = $group_data['data']; 326 326 } 327 327 328 328 if ( $fetch_emails_from_user_cache ) { 329 329 foreach ( $fetch_emails_from_user_cache as $username => $group ) { 330 330 $user_id = wp_cache_get( $username, 'userlogins' ); 331 331 if ( $user_id ) { 332 332 if ( $user_object = wp_cache_get( $user_id, 'users' ) ) { 333 $groups[ $group ]['data'][ $username ][1] = md5( strtolower( $user_object->user_email ));333 $groups[ $group ]['data'][ $username ][1] = $this->hash( $user_object->user_email ); 334 334 } else { 335 335 $fetch_emails_from_db[ $username ] = $group; 336 336 } 337 337 } else { 338 338 $fetch_emails_from_db[ $username ] = $group; 339 339 } 340 340 } 341 341 if ( $fetch_emails_from_db ) { 342 342 $fetched = $wpdb->get_results( "SELECT user_login, ID, user_email FROM $wpdb->users WHERE user_login IN ('" . implode( "', '", array_keys( $fetch_emails_from_db ) ) . "')", OBJECT_K ); 343 343 foreach ( $fetched as $username => $row ) { 344 $groups[ $fetch_emails_from_db[ $username ] ]['data'][ $username ][1] = md5( strtolower( $row->user_email ));344 $groups[ $fetch_emails_from_db[ $username ] ]['data'][ $username ][1] = $this->hash( $row->user_email ); 345 345 wp_cache_add( $username, $row->ID, 'userlogins' ); 346 346 } 347 347 } 348 348 } 349 349 350 350 $this->groups = $groups; 351 351 return $groups; 352 352 } 353 353 354 354 private function _props() { 355 355 global $wpdb; 356 356 $props = $this->cache_get( 'props-' . $this->version ); 357 357 if ( $props !== false ) 358 358 return $props; 359 359 … … abstract class WP_Credits { 433 433 return compact( 'groups', 'data' ); 434 434 } 435 435 436 436 final public function execute() { 437 437 $results = $this->get_results(); 438 438 439 439 if ( 'cli' === php_sapi_name() ) { 440 440 print_r( $results ); 441 441 } elseif ( defined( 'JSON_RESPONSE' ) && JSON_RESPONSE ) { 442 442 echo json_encode( $results ); 443 443 } else { 444 444 echo serialize( $results ); 445 445 } 446 446 } 447 447 448 private function is_hashed( $maybe_hash ) { 449 if ( 450 ! is_string( $maybe_hash ) || 451 strpos( $maybe_hash, '@' ) !== false 452 ) { 453 return false; 454 } 455 456 switch ( strlen( $maybe_hash ) ) { 457 case 32: 458 return preg_match( '/^[a-f0-9]{32}$/', $maybe_hash ); 459 case 64: 460 return preg_match( '/^[a-f0-9]{64}$/', $maybe_hash ); 461 } 462 463 return false; 464 } 465 466 private function hash( $email ) { 467 return hash( 'sha256', strtolower( $email ) ); 468 } 469 448 470 }