[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-blocks.php (source)

   1  <?php
   2  /**
   3   * BP Activity Blocks Functions.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActvityBlocks
   7   * @since 7.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  if ( ! defined( 'ABSPATH' ) ) {
  12      exit;
  13  }
  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   */
  23  function bp_activity_render_latest_activities_block( $attributes = array() ) {
  24      $block_args = bp_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      /**
  59       * Filter here to edit the arguments used by the Latest Activities block.
  60       *
  61       * @since 9.0.0
  62       *
  63       * @param array $widget_args The list of arguments for the Activity query.
  64       * @param array $block_args  The list of Block attributes.
  65       */
  66      $widget_args = apply_filters(
  67          'bp_activity_block_latest_updates_args',
  68          array(
  69              'max'          => $max_activities,
  70              'scope'        => 'all',
  71              'user_id'      => $member_id,
  72              'object'       => false,
  73              'action'       => implode( ',', $types ),
  74              'primary_id'   => 0,
  75              'secondary_id' => 0,
  76          ),
  77          $block_args
  78      );
  79  
  80      // Build the activity loop.
  81      if ( 'nouveau' === bp_get_theme_compat_id() ) {
  82          $bp_nouveau = bp_nouveau();
  83  
  84          // Globalize the activity widget arguments.
  85          $bp_nouveau->activity->widget_args = $widget_args;
  86  
  87          ob_start();
  88          bp_get_template_part( 'activity/widget' );
  89          $widget_content .= ob_get_clean();
  90  
  91          // Reset the global.
  92          $bp_nouveau->activity->widget_args = array();
  93      } else {
  94          $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' ) );
  95  
  96          if ( bp_has_activities( $widget_args ) ) {
  97              $activity_loop = '';
  98  
  99              while ( bp_activities() ) {
 100                  bp_the_activity();
 101  
 102                  $activity_footer  = '';
 103                  $activity_classes = 'activity-item';
 104                  if ( bp_activity_has_content() ) {
 105                      $activity_content = bp_get_activity_content_body();
 106                      $activity_footer  = sprintf(
 107                          '<footer>
 108                              <cite>
 109                                  <a href="%1$s" class="bp-tooltip" data-bp-tooltip="%2$s">
 110                                      %3$s
 111                                  </a>
 112                              </cite>
 113                              %4$s
 114                          </footer>',
 115                          bp_get_activity_user_link(),
 116                          bp_get_activity_member_display_name(),
 117                          bp_get_activity_avatar(
 118                              array(
 119                                  'type'   => 'thumb',
 120                                  'width'  => '40',
 121                                  'height' => '40',
 122                              )
 123                          ),
 124                          bp_insert_activity_meta()
 125                      );
 126                  } else {
 127                      $activity_classes .= ' mini';
 128                      $activity_content  = bp_get_activity_action();
 129                  }
 130  
 131                  $activity_loop .= sprintf(
 132                      '<blockquote>
 133                          <div class="%1$s">%2$s</div>
 134                          %3$s
 135                      </blockquote>',
 136                      $activity_classes,
 137                      $activity_content,
 138                      $activity_footer
 139                  );
 140              }
 141          }
 142  
 143          $widget_content .= sprintf(
 144              '<div class="activity-list item-list">
 145                  %1$s
 146              </div>',
 147              $activity_loop
 148          );
 149      }
 150  
 151      // Adds a container to make sure the block is styled even when used into the Columns parent block.
 152      $widget_content = sprintf( '<div class="bp-latest-activities-block">%s</div>', "\n" . $widget_content . "\n" );
 153  
 154      // Reset the global template loop.
 155      $GLOBALS['activities_template'] = $reset_activities_template;
 156  
 157      // Only add a block wrapper if not loaded into a Widgets sidebar.
 158      if ( ! did_action( 'dynamic_sidebar_before' ) ) {
 159          return sprintf(
 160              '<div %1$s>%2$s</div>',
 161              $wrapper_attributes,
 162              $widget_content
 163          );
 164      }
 165  
 166      return $widget_content;
 167  }


Generated: Thu Dec 26 01:01:04 2024 Cross-referenced by PHPXref 0.7.1