Skip to:
Content

BuddyPress.org

Changeset 13001


Ignore:
Timestamp:
07/14/2021 02:42:18 PM (4 years ago)
Author:
imath
Message:

Merge the BP Blocks plugin's 'bp/latest-activities' Block

  • Adapt Grunt sass tasks.
  • Add the Block JavaScript source files into src/js/bp-activity/js/blocks.
  • Add the Block Scss source file into src/bp-activity/sass.
  • Generate the development files to ease testing.
  • Make sure the 'bp/embed-activity' block is only registered if embeds are active for the Activity component.

Fixes #8519

Location:
trunk
Files:
11 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Gruntfile.js

    r13000 r13001  
    4040            '!bp-members/css/blocks/members.css',
    4141            '!bp-groups/css/blocks/groups.css',
    42             '!bp-core/css/blocks/login-form.css'
     42            '!bp-core/css/blocks/login-form.css',
     43            '!bp-activity/css/blocks/latest-activities.css'
    4344        ],
    4445
     
    159160                src: ['bp-core/sass/blocks/*.scss'],
    160161                dest: SOURCE_DIR + 'bp-core/css/blocks/'
     162            },
     163            activity_blocks: {
     164                cwd: SOURCE_DIR,
     165                extDot: 'last',
     166                expand: true,
     167                ext: '.css',
     168                flatten: true,
     169                src: ['bp-activity/sass/blocks/*.scss'],
     170                dest: SOURCE_DIR + 'bp-activity/css/blocks/'
    161171            }
    162172        },
  • trunk/src/bp-activity/bp-activity-blocks.php

    r12996 r13001  
    1212    exit;
    1313}
     14
     15/**
     16 * Callback function to render the Latest Activities Block.
     17 *
     18 * @since 9.0.0
     19 *
     20 * @param array $attributes The block attributes.
     21 * @return string           HTML output.
     22 */
     23function bp_activity_render_latest_activities_block( $attributes = array() ) {
     24    $block_args = wp_parse_args(
     25        $attributes,
     26        array(
     27            'title'         => __( 'Latest updates', 'buddypress' ),
     28            'maxActivities' => 5,
     29            'type'          => array( 'activity_update' ),
     30            'postId'        => 0,
     31        )
     32    );
     33
     34    $max_activities = (int) $block_args['maxActivities'];
     35
     36    // Should we get a specific member's activities?
     37    $member_id = 0;
     38    if ( $block_args['postId'] ) {
     39        $member_id = (int) get_post_field( 'post_author', $block_args['postId'] );
     40    } else {
     41        $member_id = bp_displayed_user_id();
     42    }
     43
     44    // Set the widget's wrapper attributes.
     45    $types              = (array) $block_args['type'];
     46    $classnames         = array_map( 'sanitize_html_class', array_merge( $types, array( 'bp-latest-activities', 'buddypress', 'widget' ) ) );
     47    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
     48
     49    // Set the Block's title.
     50    $widget_content = sprintf( '<h2 class="widget-title">%s</h2>', esc_html( $block_args['title'] ) );
     51
     52    // Avoid conflicts with other activity loops.
     53    $reset_activities_template = null;
     54    if ( ! empty( $GLOBALS['activities_template'] ) ) {
     55        $reset_activities_template = $GLOBALS['activities_template'];
     56    }
     57
     58    $widget_args = array(
     59        'max'          => $max_activities,
     60        'scope'        => 'all',
     61        'user_id'      => $member_id,
     62        'object'       => false,
     63        'action'       => implode( ',', $types ),
     64        'primary_id'   => 0,
     65        'secondary_id' => 0,
     66    );
     67
     68    // Build the activity loop.
     69    if ( 'nouveau' === bp_get_theme_compat_id() ) {
     70        $bp_nouveau = bp_nouveau();
     71
     72        // Globalize the activity widget arguments.
     73        $bp_nouveau->activity->widget_args = $widget_args;
     74
     75        ob_start();
     76        bp_get_template_part( 'activity/widget' );
     77        $widget_content .= ob_get_clean();
     78
     79        // Reset the global.
     80        $bp_nouveau->activity->widget_args = array();
     81    } else {
     82        $activity_loop = sprintf( '<div class="widget-error"><p>%s</p></div>', esc_html__( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ) );
     83
     84        if ( bp_has_activities( $widget_args ) ) {
     85            $activity_loop = '';
     86
     87            while ( bp_activities() ) {
     88                bp_the_activity();
     89
     90                $activity_footer  = '';
     91                $activity_classes = 'activity-item';
     92                if ( bp_activity_has_content() ) {
     93                    $activity_content = bp_get_activity_content_body();
     94                    $activity_footer  = sprintf(
     95                        '<footer>
     96                            <cite>
     97                                <a href="%1$s" class="bp-tooltip" data-bp-tooltip="%2$s">
     98                                    %3$s
     99                                </a>
     100                            </cite>
     101                            %4$s
     102                        </footer>',
     103                        bp_get_activity_user_link(),
     104                        bp_get_activity_member_display_name(),
     105                        bp_get_activity_avatar(
     106                            array(
     107                                'type'   => 'thumb',
     108                                'width'  => '40',
     109                                'height' => '40',
     110                            )
     111                        ),
     112                        bp_insert_activity_meta()
     113                    );
     114                } else {
     115                    $activity_classes .= ' mini';
     116                    $activity_content  = bp_get_activity_action();
     117                }
     118
     119                $activity_loop .= sprintf(
     120                    '<blockquote>
     121                        <div class="%1$s">%2$s</div>
     122                        %3$s
     123                    </blockquote>',
     124                    $activity_classes,
     125                    $activity_content,
     126                    $activity_footer
     127                );
     128            }
     129        }
     130
     131        $widget_content .= sprintf(
     132            '<div class="activity-list item-list">
     133                %1$s
     134            </div>',
     135            $activity_loop
     136        );
     137    }
     138
     139    // Adds a container to make sure the block is styled even when used into the Columns parent block.
     140    $widget_content = sprintf( '<div class="bp-latest-activities-block">%s</div>', "\n" . $widget_content . "\n" );
     141
     142    // Reset the global template loop.
     143    $GLOBALS['activities_template'] = $reset_activities_template;
     144
     145    // Only add a block wrapper if not loaded into a Widgets sidebar.
     146    if ( ! did_action( 'dynamic_sidebar_before' ) ) {
     147        return sprintf(
     148            '<div %1$s>%2$s</div>',
     149            $wrapper_attributes,
     150            $widget_content
     151        );
     152    }
     153
     154    return $widget_content;
     155}
  • trunk/src/bp-activity/classes/class-bp-activity-component.php

    r12996 r13001  
    208208            'global_tables'         => $global_tables,
    209209            'meta_tables'           => $meta_tables,
     210            'block_globals'         => array(
     211                'bp/latest-activities' => array(
     212                    'widget_classnames' => array( 'wp-block-bp-latest-activities', 'buddypress' ),
     213                )
     214            ),
    210215        );
    211216
     
    484489     */
    485490    public function blocks_init( $blocks = array() ) {
    486         parent::blocks_init(
    487             array(
    488                 'bp/embed-activity' => array(
    489                     'name'               => 'bp/embed-activity',
    490                     'editor_script'      => 'bp-embed-activity-block',
    491                     'editor_script_url'  => plugins_url( 'js/blocks/embed-activity.js', dirname(  __FILE__ ) ),
    492                     'editor_script_deps' => array(
    493                         'wp-blocks',
    494                         'wp-element',
    495                         'wp-i18n',
    496                         'wp-components',
    497                         'wp-block-editor',
    498                         'wp-data',
    499                         'wp-compose',
    500                         'bp-block-data',
     491        $blocks = array(
     492            'bp/latest-activities' => array(
     493                'name'               => 'bp/latest-activities',
     494                'editor_script'      => 'bp-latest-activities-block',
     495                'editor_script_url'  => plugins_url( 'js/blocks/latest-activities.js', dirname(  __FILE__ ) ),
     496                'editor_script_deps' => array(
     497                    'wp-blocks',
     498                    'wp-element',
     499                    'wp-components',
     500                    'wp-i18n',
     501                    'wp-block-editor',
     502                    'bp-block-data',
     503                    'bp-block-components',
     504                ),
     505                'style'              => 'bp-latest-activities-block',
     506                'style_url'          => plugins_url( 'css/blocks/latest-activities.css', dirname(  __FILE__ ) ),
     507                'attributes'         => array(
     508                    'title'         => array(
     509                        'type'    => 'string',
     510                        'default' => __( 'Latest updates', 'buddypress' ),
     511                    ),
     512                    'maxActivities' => array(
     513                        'type'    => 'number',
     514                        'default' => 5,
     515                    ),
     516                    'type'          => array(
     517                        'type'    => 'array',
     518                        'default' => array( 'activity_update' ),
     519                    ),
     520                    'postId'        => array(
     521                        'type'    => 'number',
     522                        'default' => 0,
    501523                    ),
    502524                ),
    503             )
    504         );
     525                'render_callback'    => 'bp_activity_render_latest_activities_block',
     526            ),
     527        );
     528
     529        if ( bp_is_active( $this->id, 'embeds' ) ) {
     530            $blocks['bp/embed-activity'] = array(
     531                'name'               => 'bp/embed-activity',
     532                'editor_script'      => 'bp-embed-activity-block',
     533                'editor_script_url'  => plugins_url( 'js/blocks/embed-activity.js', dirname(  __FILE__ ) ),
     534                'editor_script_deps' => array(
     535                    'wp-blocks',
     536                    'wp-element',
     537                    'wp-i18n',
     538                    'wp-components',
     539                    'wp-block-editor',
     540                    'wp-data',
     541                    'wp-compose',
     542                    'bp-block-data',
     543                ),
     544            );
     545        }
     546
     547        parent::blocks_init( $blocks );
    505548    }
    506549}
Note: See TracChangeset for help on using the changeset viewer.