[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/activity/ -> widgets.php (source)

   1  <?php
   2  /**
   3   * BP Nouveau Activity widgets
   4   *
   5   * @since 3.0.0
   6   * @version 3.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * A widget to display the latest activities of your community!
  14   *
  15   * @since 3.0.0
  16   */
  17  class BP_Latest_Activities extends WP_Widget {
  18      /**
  19       * Construct the widget.
  20       *
  21       * @since 3.0.0
  22       */
  23  	public function __construct() {
  24  
  25          /**
  26           * Filters the widget options for the BP_Latest_Activities widget.
  27           *
  28           * @since 3.0.0
  29           *
  30           * @param array $value Array of widget options.
  31           */
  32          $widget_ops = apply_filters(
  33              'bp_latest_activities', array(
  34                  'classname'                   => 'bp-latest-activities buddypress',
  35                  'description'                 => __( 'Display the latest updates of your community having the types of your choice.', 'buddypress' ),
  36                  'customize_selective_refresh' => true,
  37              )
  38          );
  39  
  40          parent::__construct( false, __( '(BuddyPress) Latest Activities', 'buddypress' ), $widget_ops );
  41      }
  42  
  43      /**
  44       * Register the widget.
  45       *
  46       * @since 3.0.0
  47       */
  48  	public static function register_widget() {
  49          register_widget( 'BP_Latest_Activities' );
  50      }
  51  
  52      /**
  53       * Display the widget content.
  54       *
  55       * @since 3.0.0
  56       *
  57       * @param array $args     Widget arguments.
  58       * @param array $instance Widget settings, as saved by the user.
  59       */
  60  	public function widget( $args, $instance ) {
  61          // Default values
  62          $title      = __( 'Latest updates', 'buddypress' );
  63          $type       = array( 'activity_update' );
  64          $max        = 5;
  65          $bp_nouveau = bp_nouveau();
  66  
  67          // Check instance for a custom title
  68          if ( ! empty( $instance['title'] ) ) {
  69              $title = $instance['title'];
  70          }
  71  
  72          /**
  73           * Filters the BP_Latest_Activities widget title.
  74           *
  75           * @since 3.0.0
  76           *
  77           * @param string $title    The widget title.
  78           * @param array  $instance The settings for the particular instance of the widget.
  79           * @param string $id_base  Root ID for all widgets of this type.
  80           */
  81          $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  82  
  83          // Check instance for custom max number of activities to display
  84          if ( ! empty( $instance['max'] ) ) {
  85              $max = (int) $instance['max'];
  86          }
  87  
  88          // Check instance for custom activity types
  89          if ( ! empty( $instance['type'] ) ) {
  90              $type    = maybe_unserialize( $instance['type'] );
  91              $classes = array_map( 'sanitize_html_class', array_merge( $type, array( 'bp-latest-activities' ) ) );
  92  
  93              // Add classes to the container
  94              $args['before_widget'] = str_replace( 'bp-latest-activities', join( ' ', $classes ), $args['before_widget'] );
  95          }
  96  
  97          echo $args['before_widget'];
  98  
  99          if ( $title ) {
 100              echo $args['before_title'] . $title . $args['after_title'];
 101          }
 102  
 103          $reset_activities_template = null;
 104          if ( ! empty( $GLOBALS['activities_template'] ) ) {
 105              $reset_activities_template = $GLOBALS['activities_template'];
 106          }
 107  
 108          /**
 109           * Globalize the activity widget arguments.
 110           * @see bp_nouveau_activity_widget_query() to override
 111           */
 112          $bp_nouveau->activity->widget_args = array(
 113              'max'          => $max,
 114              'scope'        => 'all',
 115              'user_id'      => 0,
 116              'object'       => false,
 117              'action'       => join( ',', $type ),
 118              'primary_id'   => 0,
 119              'secondary_id' => 0,
 120          );
 121  
 122          bp_get_template_part( 'activity/widget' );
 123  
 124          // Reset the globals
 125          $GLOBALS['activities_template']    = $reset_activities_template;
 126          $bp_nouveau->activity->widget_args = array();
 127  
 128          echo $args['after_widget'];
 129      }
 130  
 131      /**
 132       * Update the widget settings.
 133       *
 134       * @since 3.0.0
 135       *
 136       * @param array $new_instance The new instance settings.
 137       * @param array $old_instance The old instance settings.
 138       *
 139       * @return array The widget settings.
 140       */
 141  	public function update( $new_instance, $old_instance ) {
 142          $instance = $old_instance;
 143  
 144          $instance['title'] = strip_tags( $new_instance['title'] );
 145          $instance['max']   = 5;
 146          if ( ! empty( $new_instance['max'] ) ) {
 147              $instance['max'] = $new_instance['max'];
 148          }
 149  
 150          $instance['type'] = maybe_serialize( array( 'activity_update' ) );
 151          if ( ! empty( $new_instance['type'] ) ) {
 152              $instance['type'] = maybe_serialize( $new_instance['type'] );
 153          }
 154  
 155          return $instance;
 156      }
 157  
 158      /**
 159       * Display the form to set the widget settings.
 160       *
 161       * @since 3.0.0
 162       *
 163       * @param array $instance Settings for this widget.
 164       *
 165       * @return string HTML output.
 166       */
 167  	public function form( $instance ) {
 168          $instance = bp_parse_args(
 169              (array) $instance,
 170              array(
 171                  'title' => __( 'Latest updates', 'buddypress' ),
 172                  'max'   => 5,
 173                  'type'  => '',
 174              ),
 175              'widget_latest_activities'
 176          );
 177  
 178          $title = esc_attr( $instance['title'] );
 179          $max   = (int) $instance['max'];
 180  
 181          $type = array( 'activity_update' );
 182          if ( ! empty( $instance['type'] ) ) {
 183              $type = maybe_unserialize( $instance['type'] );
 184          }
 185          ?>
 186          <p>
 187              <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'buddypress' ); ?></label>
 188              <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
 189          </p>
 190  
 191          <p>
 192              <label for="<?php echo $this->get_field_id( 'max' ); ?>"><?php _e( 'Maximum amount to display:', 'buddypress' ); ?></label>
 193              <input type="number" class="widefat" id="<?php echo $this->get_field_id( 'max' ); ?>" name="<?php echo $this->get_field_name( 'max' ); ?>" value="<?php echo intval( $max ); ?>" step="1" min="1" max="20" />
 194          </p>
 195          <p>
 196              <label for="<?php echo $this->get_field_id( 'type' ); ?>"><?php esc_html_e( 'Type:', 'buddypress' ); ?></label>
 197              <select class="widefat" multiple="multiple" id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>[]">
 198                  <?php foreach ( bp_nouveau_get_activity_filters() as $key => $name ) : ?>
 199                      <option value="<?php echo esc_attr( $key ); ?>" <?php selected( in_array( $key, $type, true ) ); ?>><?php echo esc_html( $name ); ?></option>
 200                  <?php endforeach; ?>
 201              </select>
 202          </p>
 203          <?php
 204      }
 205  }


Generated: Mon Jul 22 01:01:43 2019 Cross-referenced by PHPXref 0.7.1