[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/classes/ -> class-bp-groups-invite-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Groups Invitation template loop class.
   4   *
   5   * @package BuddyPress
   6   * @since 1.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Group invitation template loop class.
  14   *
  15   * @since 1.1.0
  16   */
  17  class BP_Groups_Invite_Template {
  18  
  19      /**
  20       * @since 1.1.0
  21       * @var int
  22       */
  23      public $current_invite = -1;
  24  
  25      /**
  26       * @since 1.1.0
  27       * @var int
  28       */
  29      public $invite_count;
  30  
  31      /**
  32       * @since 1.1.0
  33       * @var array
  34       */
  35      public $invites;
  36  
  37      /**
  38       * @since 1.1.0
  39       * @var object
  40       */
  41      public $invite;
  42  
  43      /**
  44       * @since 1.1.0
  45       * @var bool
  46       */
  47      public $in_the_loop;
  48  
  49      /**
  50       * @since 1.1.0
  51       * @var int
  52       */
  53      public $pag_page;
  54  
  55      /**
  56       * @since 1.1.0
  57       * @var int
  58       */
  59      public $pag_num;
  60  
  61      /**
  62       * @since 1.1.0
  63       * @var string
  64       */
  65      public $pag_links;
  66  
  67      /**
  68       * @since 1.1.0
  69       * @var int
  70       */
  71      public $total_invite_count;
  72  
  73      /**
  74       * BP_Groups_Invite_Template constructor.
  75       *
  76       * @since 1.5.0
  77       *
  78       * @param array $args
  79       */
  80  	public function __construct( $args = array() ) {
  81          $function_args = func_get_args();
  82  
  83          // Backward compatibility with old method of passing arguments.
  84          if ( ! is_array( $args ) || count( $function_args ) > 1 ) {
  85              /* translators: 1: the name of the method. 2: the name of the file. */
  86              _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
  87  
  88              $old_args_keys = array(
  89                  0  => 'user_id',
  90                  1  => 'group_id',
  91              );
  92  
  93              $args = bp_core_parse_args_array( $old_args_keys, $function_args );
  94          }
  95  
  96          $r = bp_parse_args( $args, array(
  97              'page'     => 1,
  98              'per_page' => 10,
  99              'page_arg' => 'invitepage',
 100              'user_id'  => bp_loggedin_user_id(),
 101              'group_id' => bp_get_current_group_id(),
 102          ), 'groups_invite_template' );
 103  
 104          $this->pag_arg  = sanitize_key( $r['page_arg'] );
 105          $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page']     );
 106          $this->pag_num  = bp_sanitize_pagination_arg( 'num',          $r['per_page'] );
 107  
 108          $iquery = new BP_Group_Member_Query( array(
 109              'group_id' => $r['group_id'],
 110              'type'     => 'first_joined',
 111              'per_page' => $this->pag_num,
 112              'page'     => $this->pag_page,
 113  
 114              // These filters ensure we get only pending invites.
 115              'is_confirmed' => false,
 116              'inviter_id'   => $r['user_id'],
 117          ) );
 118  
 119          $this->invite_data        = $iquery->results;
 120          $this->total_invite_count = $iquery->total_users;
 121          $this->invites            = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
 122          $this->invite_count       = count( $this->invites );
 123  
 124          // If per_page is set to 0 (show all results), don't generate
 125          // pag_links.
 126          if ( ! empty( $this->pag_num ) ) {
 127              $this->pag_links = paginate_links( array(
 128                  'base'      => add_query_arg( $this->pag_arg, '%#%' ),
 129                  'format'    => '',
 130                  'total'     => ceil( $this->total_invite_count / $this->pag_num ),
 131                  'current'   => $this->pag_page,
 132                  'prev_text' => '&larr;',
 133                  'next_text' => '&rarr;',
 134                  'mid_size'  => 1,
 135                  'add_args'  => array(),
 136              ) );
 137          } else {
 138              $this->pag_links = '';
 139          }
 140      }
 141  
 142      /**
 143       * Whether or not there are invites to show.
 144       *
 145       * @since 1.1.0
 146       *
 147       * @return bool
 148       */
 149  	public function has_invites() {
 150          if ( ! empty( $this->invite_count ) ) {
 151              return true;
 152          }
 153  
 154          return false;
 155      }
 156  
 157      /**
 158       * Increments up to the next invite to show.
 159       *
 160       * @since 1.1.0
 161       *
 162       * @return object
 163       */
 164  	public function next_invite() {
 165          $this->current_invite++;
 166          $this->invite = $this->invites[ $this->current_invite ];
 167  
 168          return $this->invite;
 169      }
 170  
 171      /**
 172       * Rewinds to the first invite to show.
 173       *
 174       * @since 1.1.0
 175       */
 176  	public function rewind_invites() {
 177          $this->current_invite = -1;
 178          if ( $this->invite_count > 0 ) {
 179              $this->invite = $this->invites[0];
 180          }
 181      }
 182  
 183      /**
 184       * Finishes up the invites to show.
 185       *
 186       * @since 1.1.0
 187       *
 188       * @return bool
 189       */
 190  	public function invites() {
 191          $tick = intval( $this->current_invite + 1 );
 192          if ( $tick < $this->invite_count ) {
 193              return true;
 194          } elseif ( $tick == $this->invite_count ) {
 195  
 196              /**
 197               * Fires right before the rewinding of invites list.
 198               *
 199               * @since 1.1.0
 200               * @since 2.3.0 `$this` parameter added.
 201               * @since 2.7.0 Action renamed from `loop_start`.
 202               *
 203               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 204               */
 205              do_action( 'group_invitation_loop_end', $this );
 206  
 207              // Do some cleaning up after the loop
 208              $this->rewind_invites();
 209          }
 210  
 211          $this->in_the_loop = false;
 212          return false;
 213      }
 214  
 215      /**
 216       * Sets up the invite to show.
 217       *
 218       * @since 1.1.0
 219       */
 220  	public function the_invite() {
 221          global $group_id;
 222  
 223          $this->in_the_loop  = true;
 224          $user_id            = $this->next_invite();
 225  
 226          $this->invite       = new stdClass;
 227          $this->invite->user = $this->invite_data[ $user_id ];
 228  
 229          // This method previously populated the user object with
 230          // BP_Core_User. We manually configure BP_Core_User data for
 231          // backward compatibility.
 232          if ( bp_is_active( 'xprofile' ) ) {
 233              $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
 234          }
 235  
 236          $this->invite->user->avatar = bp_core_fetch_avatar(
 237              array(
 238                  'item_id' => $user_id,
 239                  'type'    => 'full',
 240                  'alt'     => sprintf(
 241                      /* translators: %s: member name */
 242                      __( 'Profile photo of %s', 'buddypress' ),
 243                      $this->invite->user->fullname
 244                  )
 245              )
 246          );
 247  
 248          $this->invite->user->avatar_thumb = bp_core_fetch_avatar(
 249              array(
 250                  'item_id' => $user_id,
 251                  'type'    => 'thumb',
 252                  'alt'     => sprintf(
 253                      /* translators: %s: member name */
 254                      __( 'Profile photo of %s', 'buddypress' ),
 255                      $this->invite->user->fullname
 256                  )
 257              )
 258          );
 259  
 260          $this->invite->user->avatar_mini = bp_core_fetch_avatar(
 261              array(
 262                  'item_id' => $user_id,
 263                  'type'    => 'thumb',
 264                  'alt'     => sprintf(
 265                      /* translators: %s: member name */
 266                      __( 'Profile photo of %s', 'buddypress' ),
 267                      $this->invite->user->fullname
 268                  ),
 269                  'width'   => 30,
 270                  'height'  => 30
 271              )
 272          );
 273  
 274          $this->invite->user->email     = $this->invite->user->user_email;
 275          $this->invite->user->user_url  = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
 276          $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}'>{$this->invite->user->fullname}</a>";
 277  
 278          /* translators: %s: last activity timestamp (e.g. "active 1 hour ago") */
 279          $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
 280  
 281          if ( bp_is_active( 'groups' ) ) {
 282              $total_groups = BP_Groups_Member::total_group_count( $user_id );
 283              $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
 284          }
 285  
 286          if ( bp_is_active( 'friends' ) ) {
 287              $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
 288          }
 289  
 290          $this->invite->user->total_blogs = null;
 291  
 292          // Global'ed in bp_group_has_invites()
 293          $this->invite->group_id = $group_id;
 294  
 295          // loop has just started
 296          if ( 0 == $this->current_invite ) {
 297  
 298              /**
 299               * Fires if the current invite item is the first in the loop.
 300               *
 301               * @since 1.1.0
 302               * @since 2.3.0 `$this` parameter added.
 303               * @since 2.7.0 Action renamed from `loop_start`.
 304               *
 305               * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
 306               */
 307              do_action( 'group_invitation_loop_start', $this );
 308          }
 309      }
 310  }


Generated: Mon Sep 21 01:01:31 2020 Cross-referenced by PHPXref 0.7.1