Changeset 13004
- Timestamp:
- 07/14/2021 06:45:11 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 13 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.jshintignore
r13003 r13004 11 11 src/**/js/friends.js 12 12 src/**/js/dynamic-members.js 13 src/**/js/dynamic-groups.js 13 14 src/**/js/dynamic-widget-block.js -
trunk/Gruntfile.js
r13003 r13004 26 26 '!**/js/friends.js', 27 27 '!**/js/dynamic-members.js', 28 '!**/js/dynamic-groups.js', 28 29 '!**/js/dynamic-widget-block.js' 29 30 ], … … 46 47 '!bp-activity/css/blocks/latest-activities.css', 47 48 '!bp-friends/css/blocks/friends.css', 48 '!bp-members/css/blocks/dynamic-members.css' 49 '!bp-members/css/blocks/dynamic-members.css', 50 '!bp-groups/css/blocks/dynamic-groups.css' 49 51 ], 50 52 -
trunk/src/bp-friends/bp-friends-blocks.php
r13002 r13004 183 183 ) 184 184 ), 185 'data.avatar_alt' => esc_ html(185 'data.avatar_alt' => esc_attr( 186 186 sprintf( 187 187 /* translators: %s: member name */ -
trunk/src/bp-groups/bp-groups-blocks.php
r12996 r13004 311 311 return apply_filters( 'bp_groups_render_groups_block_output', $output, $block_args, $groups ); 312 312 } 313 314 /** 315 * Adds specific script data for the BP Groups blocks. 316 * 317 * Only used for the BP Dynamic Groups block. 318 * 319 * @since 9.0.0 320 */ 321 function bp_groups_blocks_add_script_data() { 322 $dynamic_groups_blocks = array_filter( buddypress()->groups->block_globals['bp/dynamic-groups']->items ); 323 324 if ( ! $dynamic_groups_blocks ) { 325 return; 326 } 327 328 // Include the common JS template. 329 echo bp_get_dynamic_template_part( 'assets/widgets/dynamic-groups.php' ); 330 331 // List the block specific props. 332 wp_add_inline_script( 333 'bp-dynamic-groups-script', 334 sprintf( 'var bpDynamicGroupsBlocks = %s;', wp_json_encode( array_values( $dynamic_groups_blocks ) ) ), 335 'before' 336 ); 337 } 338 339 /** 340 * Callback function to render the Dynamic Groups Block. 341 * 342 * @since 9.0.0 343 * 344 * @param array $attributes The block attributes. 345 * @return string HTML output. 346 */ 347 function bp_groups_render_dynamic_groups_block( $attributes = array() ) { 348 $block_args = wp_parse_args( 349 $attributes, 350 array( 351 'title' => __( 'Groups', 'buddypress' ), 352 'maxGroups' => 5, 353 'groupDefault' => 'active', 354 'linkTitle' => false, 355 ) 356 ); 357 358 $classnames = 'widget_bp_groups_widget buddypress widget'; 359 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) ); 360 361 $max_groups = (int) $block_args['maxGroups']; 362 $no_groups = __( 'There are no groups to display.', 'buddypress' ); 363 364 /** This filter is documented in buddypress/src/bp-groups/classes/class-bp-groups-widget.php */ 365 $separator = apply_filters( 'bp_groups_widget_separator', '|' ); 366 367 // Make sure the widget ID is unique. 368 $widget_id = uniqid( 'groups-list-' ); 369 $groups_directory_link = bp_get_groups_directory_permalink(); 370 371 // Set the Block's title. 372 if ( true === $block_args['linkTitle'] ) { 373 $widget_content = sprintf( 374 '<h2 class="widget-title"><a href="%1$s">%2$s</a></h2>', 375 esc_url( $groups_directory_link ), 376 esc_html( $block_args['title'] ) 377 ); 378 } else { 379 $widget_content = sprintf( '<h2 class="widget-title">%s</h2>', esc_html( $block_args['title'] ) ); 380 } 381 382 $item_options = array( 383 'newest' => array( 384 'class' => '', 385 'label' => __( 'Newest', 'buddypress' ), 386 ), 387 'active' => array( 388 'class' => '', 389 'label' => __( 'Active', 'buddypress' ), 390 ), 391 'popular' => array( 392 'class' => '', 393 'label' => __( 'Popular', 'buddypress' ), 394 ), 395 'alphabetical' => array( 396 'class' => '', 397 'label' => __( 'Alphabetical', 'buddypress' ), 398 ), 399 ); 400 401 $item_options_output = array(); 402 $separator_output = sprintf( ' <span class="bp-separator" role="separator">%s</span> ', esc_html( $separator ) ); 403 404 foreach ( $item_options as $item_type => $item_attr ) { 405 if ( $block_args['groupDefault'] === $item_type ) { 406 $item_attr['class'] = ' class="selected"'; 407 } 408 409 $item_options_output[] = sprintf( 410 '<a href="%1$s" data-bp-sort="%2$s"%3$s>%4$s</a>', 411 esc_url( $groups_directory_link ), 412 esc_attr( $item_type ), 413 $item_attr['class'], 414 esc_html( $item_attr['label'] ) 415 ); 416 } 417 418 $preview = ''; 419 $default_args = array( 420 'type' => $block_args['groupDefault'], 421 'per_page' => $max_groups, 422 'populate_extras' => true, 423 ); 424 425 // Previewing the Block inside the editor. 426 if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { 427 $bp_query = groups_get_groups( $default_args ); 428 $preview = sprintf( '<div class="widget-error">%s</div>', $no_groups ); 429 430 if ( is_array( $bp_query['groups'] ) && 0 < count( $bp_query['groups'] ) ) { 431 $preview = ''; 432 foreach ( $bp_query['groups'] as $group ) { 433 if ( 'newest' === $block_args['groupDefault'] ) { 434 /* translators: %s is time elapsed since the group was created */ 435 $extra = sprintf( __( 'Created %s', 'buddypress' ), bp_get_group_date_created( $group ) ); 436 } elseif ( 'popular' === $block_args['groupDefault'] ) { 437 $count = (int) $group->total_member_count; 438 439 /* translators: %s is the number of Group members */ 440 $extra = sprintf( _n( '%s member', '%s members', $count, 'buddypress' ), bp_core_number_format( $count ) ); 441 } else { 442 /* translators: %s: a human time diff. */ 443 $extra = sprintf( __( 'Active %s', 'buddypress' ), bp_get_group_last_active( $group ) ); 444 } 445 446 $preview .= bp_get_dynamic_template_part( 447 'assets/widgets/dynamic-groups.php', 448 'php', 449 array( 450 'data.link' => bp_get_group_permalink( $group ), 451 'data.name' => bp_get_group_name( $group ), 452 'data.avatar_urls.thumb' => bp_core_fetch_avatar( 453 array( 454 'item_id' => $group->id, 455 'html' => false, 456 'object' => 'group', 457 ) 458 ), 459 'data.avatar_alt' => esc_attr( 460 sprintf( 461 /* Translators: %s is the group's name. */ 462 __( 'Group Profile photo of %s', 'buddypress' ), 463 $group->name 464 ) 465 ), 466 'data.id' => $group->id, 467 'data.extra' => $extra, 468 ) 469 ); 470 } 471 } 472 } else { 473 // Get corresponding members. 474 $path = sprintf( 475 '/%1$s/%2$s/%3$s', 476 bp_rest_namespace(), 477 bp_rest_version(), 478 buddypress()->groups->id 479 ); 480 481 $default_path = add_query_arg( 482 $default_args, 483 $path 484 ); 485 486 $preloaded_groups = array(); 487 if ( bp_is_running_wp( '5.0.0' ) ) { 488 $preloaded_groups = rest_preload_api_request( '', $default_path ); 489 } 490 491 buddypress()->groups->block_globals['bp/dynamic-groups']->items[ $widget_id ] = (object) array( 492 'selector' => $widget_id, 493 'query_args' => $default_args, 494 'preloaded' => reset( $preloaded_groups ), 495 ); 496 497 // Only enqueue common/specific scripts and data once per page load. 498 if ( ! has_action( 'wp_footer', 'bp_groups_blocks_add_script_data', 1 ) ) { 499 wp_set_script_translations( 'bp-dynamic-groups-script', 'buddypress' ); 500 wp_enqueue_script( 'bp-dynamic-groups-script' ); 501 wp_localize_script( 502 'bp-dynamic-groups-script', 503 'bpDynamicGroupsSettings', 504 array( 505 'path' => ltrim( $path, '/' ), 506 'root' => esc_url_raw( get_rest_url() ), 507 'nonce' => wp_create_nonce( 'wp_rest' ), 508 ) 509 ); 510 511 add_action( 'wp_footer', 'bp_groups_blocks_add_script_data', 1 ); 512 } 513 } 514 515 $widget_content .= sprintf( 516 '<div class="item-options"> 517 %1$s 518 </div> 519 <ul id="%2$s" class="item-list" aria-live="polite" aria-relevant="all" aria-atomic="true"> 520 %3$s 521 </ul>', 522 implode( $separator_output, $item_options_output ), 523 esc_attr( $widget_id ), 524 $preview 525 ); 526 527 // Adds a container to make sure the block is styled even when used into the Columns parent block. 528 $widget_content = sprintf( '<div class="bp-dynamic-block-container">%s</div>', "\n" . $widget_content . "\n" ); 529 530 // Only add a block wrapper if not loaded into a Widgets sidebar. 531 if ( ! did_action( 'dynamic_sidebar_before' ) ) { 532 return sprintf( 533 '<div %1$s>%2$s</div>', 534 $wrapper_attributes, 535 $widget_content 536 ); 537 } 538 539 return $widget_content; 540 } -
trunk/src/bp-groups/bp-groups-cssjs.php
r12745 r13004 64 64 ); 65 65 } 66 67 /** 68 * Registers a new script to manage the dynamic part of the Dynamic groups widget/block. 69 * 70 * @since 9.0.0 71 * 72 * @param array $scripts Data about the scripts to register. 73 * @return array Data about the scripts to register. 74 */ 75 function bp_groups_register_widget_block_scripts( $scripts = array() ) { 76 $scripts['bp-dynamic-groups-script'] = array( 77 'file' => plugins_url( 'js/dynamic-groups.js', __FILE__ ), 78 'dependencies' => array( 79 'bp-dynamic-widget-block-script', 80 'wp-i18n', 81 ), 82 'footer' => true, 83 ); 84 85 return $scripts; 86 } 87 add_filter( 'bp_core_register_common_scripts', 'bp_groups_register_widget_block_scripts', 9, 1 ); -
trunk/src/bp-groups/classes/class-bp-groups-component.php
r12996 r13004 262 262 'global_tables' => $global_tables, 263 263 'meta_tables' => $meta_tables, 264 'block_globals' => array( 265 'bp/dynamic-groups' => array( 266 'widget_classnames' => array( 'widget_bp_groups_widget', 'buddypress' ), 267 ), 268 ), 264 269 ); 265 270 … … 1059 1064 'render_callback' => 'bp_groups_render_groups_block', 1060 1065 ), 1066 'bp/dynamic-groups' => array( 1067 'name' => 'bp/dynamic-groups', 1068 'editor_script' => 'bp-dynamic-groups-block', 1069 'editor_script_url' => plugins_url( 'js/blocks/dynamic-groups.js', dirname( __FILE__ ) ), 1070 'editor_script_deps' => array( 1071 'wp-blocks', 1072 'wp-element', 1073 'wp-components', 1074 'wp-i18n', 1075 'wp-block-editor', 1076 'bp-block-components', 1077 ), 1078 'style' => 'bp-dynamic-groups-block', 1079 'style_url' => plugins_url( 'css/blocks/dynamic-groups.css', dirname( __FILE__ ) ), 1080 'attributes' => array( 1081 'title' => array( 1082 'type' => 'string', 1083 'default' => __( 'Groups', 'buddypress' ), 1084 ), 1085 'maxGroups' => array( 1086 'type' => 'number', 1087 'default' => 5, 1088 ), 1089 'groupDefault' => array( 1090 'type' => 'string', 1091 'default' => 'active', 1092 ), 1093 'linkTitle' => array( 1094 'type' => 'boolean', 1095 'default' => false, 1096 ), 1097 ), 1098 'render_callback' => 'bp_groups_render_dynamic_groups_block', 1099 ), 1061 1100 ) 1062 1101 ); -
trunk/src/bp-members/bp-members-blocks.php
r13003 r13004 474 474 ) 475 475 ), 476 'data.avatar_alt' => esc_ html(476 'data.avatar_alt' => esc_attr( 477 477 sprintf( 478 478 /* translators: %s: member name */
Note: See TracChangeset
for help on using the changeset viewer.