Changeset 12574
- Timestamp:
- 05/08/2023 02:46:30 AM (19 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php
r12531 r12574 1056 1056 return $support_reps; 1057 1057 } 1058 1059 /** 1060 * Get the plugin or theme object slugs for a given user. 1061 * 1062 * @param int $user_id The user id. 1063 * @return array 1064 */ 1065 public function get_user_object_slugs( $user_id ) { 1066 global $wpdb; 1067 1068 // Check the cache. 1069 $cache_key = $user_id; 1070 $cache_group = $this->compat() . '-user-object-slugs'; 1071 $slugs = wp_cache_get( $cache_key, $cache_group ); 1072 if ( $slugs !== false ) { 1073 return $slugs; 1074 } 1075 $slugs = []; 1076 1077 // Themes. 1078 if ( 'theme' == $this->compat() ) { 1079 $slugs = $wpdb->get_col( $wpdb->prepare( 1080 "SELECT post_name 1081 FROM %i 1082 WHERE post_type = 'repopackage' AND post_author = %d", 1083 $wpdb->base_prefix . WPORG_THEME_DIRECTORY_BLOGID . '_posts', 1084 $user_id 1085 ) ); 1086 } 1087 1088 // Plugins 1089 if ( 'plugin' == $this->compat() ) { 1090 $slugs = $wpdb->get_col( $wpdb->prepare( 1091 "SELECT DISTINCT p.post_name 1092 FROM %i AS t 1093 LEFT JOIN %i AS tt ON tt.term_id = t.term_id 1094 LEFT JOIN %i AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id 1095 LEFT JOIN %i AS p ON tr.object_id = p.ID 1096 WHERE tt.taxonomy IN( 'plugin_contributors', 'plugin_support_reps', 'plugin_committers' ) AND t.name = %s", 1097 $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_terms', 1098 $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_term_taxonomy', 1099 $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_term_relationships', 1100 $wpdb->base_prefix . WPORG_PLUGIN_DIRECTORY_BLOGID . '_posts', 1101 get_user_by( 'id', $user_id )->user_nicename 1102 ) ); 1103 } 1104 1105 wp_cache_set( $cache_key, $slugs, $cache_group, HOUR_IN_SECONDS ); 1106 1107 return $slugs; 1108 } 1058 1109 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.js
r11664 r12574 57 57 banner.hide(); 58 58 } else { 59 userList = currentlyViewing.map( function( item ) { 59 anonymousUsers = currentlyViewing.filter( function( item ) { return ! item.user_id; } ); 60 anonymousUserCount = anonymousUsers.length; 61 anonymousUserTyping = anonymousUsers.filter( function( item ) { return !! item.isTyping; } ).length; 62 userList = currentlyViewing.filter( function( item ) { return !! item.user_id; } ); 63 64 // Markup those who are typing, and flatten it to just the name. 65 userList = userList.map( function( item ) { 60 66 return item.who + ( item.isTyping ? ' ' + __( '(is typing)', 'wporg-forums' ) : '' ); 61 67 } ); 62 68 63 if ( userCount > 1 ) { 69 // Add the anonymous users to the list. 70 if ( anonymousUserCount ) { 71 var anonymousText = _n( '%s other person', '%s other people', anonymousUserCount, 'wporg-forums' ); 72 73 anonymousText = anonymousText.replace( '%s', anonymousUserCount ); 74 if ( anonymousUserTyping ) { 75 anonymousText += ' ' + _n( '(%s is typing)', '(%s are typing)', anonymousUserTyping, 'wporg-forums' ); 76 } 77 78 userList.push( anonymousText ); 79 } 80 81 displayCount = userList.length; 82 83 if ( displayCount > 1 ) { 64 84 userlistPretty = __( '%1$s and %2$s', 'wporg-forums' ) 65 .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( userCount > 2 ? ',' : '' ) )66 .replace( '%2$s', userList.slice( -1 ) );85 .replace( '%1$s', userList.slice( 0, -1 ).join( ', ' ) + ( displayCount > 2 ? ',' : '' ) ) 86 .replace( '%2$s', userList.slice( -1 ) ); 67 87 } else { 68 88 userlistPretty = userList.join( ', ' ); // only one element. -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-also-viewing/wporg-bbp-also-viewing.php
r12412 r12574 2 2 namespace WordPressdotorg\BBP_Also_Viewing; 3 3 use function WordPressdotorg\SEO\Canonical\get_canonical_url; 4 use const MINUTE_IN_SECONDS; 4 5 5 6 /** … … 28 29 29 30 const USER_OPTION = 'also-viewing'; 30 const TIMEOUT = 5 * \MINUTE_IN_SECONDS;31 const TIMEOUT = 5 * MINUTE_IN_SECONDS; 31 32 const REFRESH_INT = 45; // How often the client should check for new viewers in seconds. 32 33 const CACHE_GROUP = 'also-viewing'; 33 const CACHE_TIME = 5 * \MINUTE_IN_SECONDS;34 const CACHE_TIME = 5 * MINUTE_IN_SECONDS; 34 35 const REPLY_THRESH = 20; // The number of replies a user must have before the feature can be opt'd into. 35 36 … … 275 276 * Get the list of OTHER users who are currently viewing a page. 276 277 * 278 * This anonymizes users so that only mods can see other mods, and plugin support reps can see other reps and committers. 279 * 277 280 * @param string $page The page to get the userse for. 278 281 * … … 287 290 } 288 291 292 // Anonymize the list of users if appropriate. 293 // Mods + Admins can see all. 294 if ( current_user_can( 'moderate' ) || current_user_can( 'list_users' ) ) { 295 return array_values( $users ); 296 } 297 298 // Anonymize mods for other users. 299 foreach ( $users as &$u ) { 300 if ( user_can( $u['user_id'], 'moderate' ) ) { 301 $u['who'] = ''; 302 $u['user_id'] = 0; 303 } 304 } 305 306 // Anonymize users unless they've got similar caps. 307 // Plugin support reps can see other reps and committers -for their own plugins-. 308 $current_user_objects = get_user_object_slugs( get_current_user_id() ); 309 foreach ( $users as &$u ) { 310 $user_objects = get_user_object_slugs( $u['user_id'] ); 311 if ( ! array_intersect( $user_objects, $current_user_objects ) ) { 312 $u['who'] = ''; 313 $u['user_id'] = 0; 314 } 315 } 316 289 317 return array_values( $users ); 318 } 319 320 /** 321 * Fetch the list of plugins/themes a user has access to. 322 * 323 * @param int $user_id The user ID to check for. 324 * @return array Array of plugin slugs. 325 */ 326 function get_user_object_slugs( $user_id ) { 327 if ( ! class_exists( '\WordPressdotorg\Forums\Plugin' ) ) { 328 return []; 329 } 330 331 $plugin_slugs = \WordPressdotorg\Forums\Plugin::get_instance()->plugins->get_user_object_slugs( $user_id ); 332 $theme_slugs = \WordPressdotorg\Forums\Plugin::get_instance()->themes->get_user_object_slugs( $user_id ); 333 334 $matrix = []; 335 foreach ( $plugin_slugs as $slug ) { 336 $matrix[] = "plugin:{$slug}"; 337 } 338 foreach ( $theme_slugs as $slug ) { 339 $matrix[] = "theme:{$slug}"; 340 } 341 342 return $matrix; 290 343 } 291 344
Note: See TracChangeset
for help on using the changeset viewer.