[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-blogs/classes/ -> class-bp-blogs-recent-posts-widget.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Blogs Recent Posts Widget.
   4   *
   5   * @package BuddyPress
   6   * @subpackage BlogsWidgets
   7   * @since 1.0.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * The Recent Networkwide Posts widget.
  15   */
  16  class BP_Blogs_Recent_Posts_Widget extends WP_Widget {
  17  
  18      /**
  19       * Constructor method.
  20       */
  21  	public function __construct() {
  22          $widget_ops = array(
  23              'description'                 => __( 'A list of recently published posts from across your network.', 'buddypress' ),
  24              'classname'                   => 'widget_bp_blogs_widget buddypress widget',
  25              'customize_selective_refresh' => true,
  26          );
  27          parent::__construct( false, $name = _x( '(BuddyPress) Recent Networkwide Posts', 'widget name', 'buddypress' ), $widget_ops );
  28      }
  29  
  30      /**
  31       * Display the networkwide posts widget.
  32       *
  33       * @see WP_Widget::widget() for description of parameters.
  34       *
  35       * @param array $args     Widget arguments.
  36       * @param array $instance Widget settings, as saved by the user.
  37       */
  38  	public function widget( $args, $instance ) {
  39          global $activities_template;
  40  
  41          $title = ! empty( $instance['title'] )
  42              ? esc_html( $instance['title'] )
  43              : __( 'Recent Networkwide Posts', 'buddypress' );
  44  
  45          if ( ! empty( $instance['link_title'] ) ) {
  46              $title = '<a href="' . bp_get_blogs_directory_permalink() . '">' . esc_html( $title ) . '</a>';
  47          }
  48  
  49          /**
  50           * Filters the Blogs Recent Posts widget title.
  51           *
  52           * @since 2.2.0
  53           * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
  54           *
  55           * @param string $title    The widget title.
  56           * @param array  $instance The settings for the particular instance of the widget.
  57           * @param string $id_base  Root ID for all widgets of this type.
  58           */
  59          $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  60  
  61          echo $args['before_widget'];
  62          echo $args['before_title'] . $title . $args['after_title'];
  63  
  64          $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
  65          if ( empty( $instance['max_posts'] ) || $instance['max_posts'] > $max_limit ) {
  66              $instance['max_posts'] = 10;
  67          }
  68  
  69          $after_widget = $args['after_widget'];
  70  
  71          // Override some of the contextually set parameters for bp_has_activities().
  72          $args = array(
  73              'action'     => 'new_blog_post',
  74              'max'        => $instance['max_posts'],
  75              'per_page'   => $instance['max_posts'],
  76              'user_id'    => 0,
  77              'scope'      => false,
  78              'object'     => false,
  79              'primary_id' => false
  80          );
  81  
  82          // Back up global.
  83          $old_activities_template = $activities_template;
  84  
  85          ?>
  86  
  87          <?php if ( bp_has_activities( $args ) ) : ?>
  88  
  89              <ul id="blog-post-list" class="activity-list item-list">
  90  
  91                  <?php while ( bp_activities() ) : bp_the_activity(); ?>
  92  
  93                      <li>
  94                          <div class="activity-content" style="margin: 0">
  95                              <div class="activity-header"><?php bp_activity_action(); ?></div>
  96  
  97                              <?php if ( bp_get_activity_content_body() ) : ?>
  98  
  99                                  <div class="activity-inner"><?php bp_activity_content_body(); ?></div>
 100  
 101                              <?php endif; ?>
 102  
 103                          </div>
 104                      </li>
 105  
 106                  <?php endwhile; ?>
 107  
 108              </ul>
 109  
 110          <?php else : ?>
 111  
 112              <div id="message" class="info">
 113                  <p><?php _e( 'Sorry, there were no posts found. Why not write one?', 'buddypress' ); ?></p>
 114              </div>
 115  
 116          <?php endif; ?>
 117  
 118          <?php echo $after_widget;
 119  
 120          // Restore the global.
 121          $activities_template = $old_activities_template;
 122      }
 123  
 124      /**
 125       * Update the networkwide posts widget options.
 126       *
 127       * @param array $new_instance The new instance options.
 128       * @param array $old_instance The old instance options.
 129       * @return array $instance The parsed options to be saved.
 130       */
 131  	public function update( $new_instance, $old_instance ) {
 132          $instance = $old_instance;
 133  
 134          $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
 135  
 136          $instance['title']      = strip_tags( $new_instance['title'] );
 137          $instance['max_posts']  = $new_instance['max_posts'] > $max_limit ? $max_limit : intval( $new_instance['max_posts'] );
 138          $instance['link_title'] = ! empty( $new_instance['link_title'] );
 139  
 140          return $instance;
 141      }
 142  
 143      /**
 144       * Output the networkwide posts widget options form.
 145       *
 146       * @param array $instance Settings for this widget.
 147       *
 148       * @return void
 149       */
 150  	public function form( $instance ) {
 151          $instance = wp_parse_args( (array) $instance, array(
 152              'title'      => __( 'Recent Networkwide Posts', 'buddypress' ),
 153              'max_posts'  => 10,
 154              'link_title' => false,
 155          ) );
 156  
 157          $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
 158  
 159          $title      = strip_tags( $instance['title'] );
 160          $max_posts  = $instance['max_posts'] > $max_limit ? $max_limit : intval( $instance['max_posts'] );
 161          $link_title = (bool) $instance['link_title'];
 162  
 163          ?>
 164  
 165          <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _ex( 'Title:', 'Label for the Title field of the Recent Networkwide Posts widget', 'buddypress' ); ?> <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 ); ?>" style="width: 100%;" /></label></p>
 166          <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Blogs directory', 'buddypress' ); ?></label></p>
 167          <p><label for="<?php echo $this->get_field_id( 'max_posts' ); ?>"><?php _e( 'Max posts to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_posts' ); ?>" name="<?php echo $this->get_field_name( 'max_posts' ); ?>" type="number" min="1" max="<?php echo esc_attr( $max_limit ); ?>" value="<?php echo esc_attr( $max_posts ); ?>" style="width: 30%" /></label></p>
 168          <?php
 169      }
 170  }


Generated: Mon Oct 21 01:01:35 2019 Cross-referenced by PHPXref 0.7.1