[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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( 97 $args, 98 array( 99 'page' => 1, 100 'per_page' => 10, 101 'page_arg' => 'invitepage', 102 'user_id' => bp_loggedin_user_id(), 103 'group_id' => bp_get_current_group_id(), 104 ), 105 'groups_invite_template' 106 ); 107 108 $this->pag_arg = sanitize_key( $r['page_arg'] ); 109 $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $r['page'] ); 110 $this->pag_num = bp_sanitize_pagination_arg( 'num', $r['per_page'] ); 111 112 $iquery = new BP_Group_Member_Query( array( 113 'group_id' => $r['group_id'], 114 'type' => 'first_joined', 115 'per_page' => $this->pag_num, 116 'page' => $this->pag_page, 117 118 // These filters ensure we get only pending invites. 119 'is_confirmed' => false, 120 'inviter_id' => $r['user_id'], 121 ) ); 122 123 $this->invite_data = $iquery->results; 124 $this->total_invite_count = $iquery->total_users; 125 $this->invites = array_values( wp_list_pluck( $this->invite_data, 'ID' ) ); 126 $this->invite_count = count( $this->invites ); 127 128 // If per_page is set to 0 (show all results), don't generate 129 // pag_links. 130 if ( ! empty( $this->pag_num ) ) { 131 $this->pag_links = paginate_links( array( 132 'base' => add_query_arg( $this->pag_arg, '%#%' ), 133 'format' => '', 134 'total' => ceil( $this->total_invite_count / $this->pag_num ), 135 'current' => $this->pag_page, 136 'prev_text' => '←', 137 'next_text' => '→', 138 'mid_size' => 1, 139 'add_args' => array(), 140 ) ); 141 } else { 142 $this->pag_links = ''; 143 } 144 } 145 146 /** 147 * Whether or not there are invites to show. 148 * 149 * @since 1.1.0 150 * 151 * @return bool 152 */ 153 public function has_invites() { 154 if ( ! empty( $this->invite_count ) ) { 155 return true; 156 } 157 158 return false; 159 } 160 161 /** 162 * Increments up to the next invite to show. 163 * 164 * @since 1.1.0 165 * 166 * @return object 167 */ 168 public function next_invite() { 169 $this->current_invite++; 170 $this->invite = $this->invites[ $this->current_invite ]; 171 172 return $this->invite; 173 } 174 175 /** 176 * Rewinds to the first invite to show. 177 * 178 * @since 1.1.0 179 */ 180 public function rewind_invites() { 181 $this->current_invite = -1; 182 if ( $this->invite_count > 0 ) { 183 $this->invite = $this->invites[0]; 184 } 185 } 186 187 /** 188 * Finishes up the invites to show. 189 * 190 * @since 1.1.0 191 * 192 * @return bool 193 */ 194 public function invites() { 195 $tick = intval( $this->current_invite + 1 ); 196 if ( $tick < $this->invite_count ) { 197 return true; 198 } elseif ( $tick == $this->invite_count ) { 199 200 /** 201 * Fires right before the rewinding of invites list. 202 * 203 * @since 1.1.0 204 * @since 2.3.0 `$this` parameter added. 205 * @since 2.7.0 Action renamed from `loop_start`. 206 * 207 * @param BP_Groups_Invite_Template $this Instance of the current Invites template. 208 */ 209 do_action( 'group_invitation_loop_end', $this ); 210 211 // Do some cleaning up after the loop 212 $this->rewind_invites(); 213 } 214 215 $this->in_the_loop = false; 216 return false; 217 } 218 219 /** 220 * Sets up the invite to show. 221 * 222 * @since 1.1.0 223 */ 224 public function the_invite() { 225 global $group_id; 226 227 $this->in_the_loop = true; 228 $user_id = $this->next_invite(); 229 230 $this->invite = new stdClass; 231 $this->invite->user = $this->invite_data[ $user_id ]; 232 233 // This method previously populated the user object with 234 // BP_Core_User. We manually configure BP_Core_User data for 235 // backward compatibility. 236 if ( bp_is_active( 'xprofile' ) ) { 237 $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id ); 238 } 239 240 $this->invite->user->avatar = bp_core_fetch_avatar( 241 array( 242 'item_id' => $user_id, 243 'type' => 'full', 244 'alt' => sprintf( 245 /* translators: %s: member name */ 246 __( 'Profile photo of %s', 'buddypress' ), 247 $this->invite->user->fullname 248 ) 249 ) 250 ); 251 252 $this->invite->user->avatar_thumb = bp_core_fetch_avatar( 253 array( 254 'item_id' => $user_id, 255 'type' => 'thumb', 256 'alt' => sprintf( 257 /* translators: %s: member name */ 258 __( 'Profile photo of %s', 'buddypress' ), 259 $this->invite->user->fullname 260 ) 261 ) 262 ); 263 264 $this->invite->user->avatar_mini = bp_core_fetch_avatar( 265 array( 266 'item_id' => $user_id, 267 'type' => 'thumb', 268 'alt' => sprintf( 269 /* translators: %s: member name */ 270 __( 'Profile photo of %s', 'buddypress' ), 271 $this->invite->user->fullname 272 ), 273 'width' => 30, 274 'height' => 30 275 ) 276 ); 277 278 $this->invite->user->email = $this->invite->user->user_email; 279 $this->invite->user->user_url = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login ); 280 $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}'>{$this->invite->user->fullname}</a>"; 281 282 /* translators: %s: last activity timestamp (e.g. "Active 1 hour ago") */ 283 $this->invite->user->last_active = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'Active %s', 'buddypress' ) ); 284 285 if ( bp_is_active( 'groups' ) ) { 286 $total_groups = BP_Groups_Member::total_group_count( $user_id ); 287 $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups ); 288 } 289 290 if ( bp_is_active( 'friends' ) ) { 291 $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id ); 292 } 293 294 $this->invite->user->total_blogs = null; 295 296 // Global'ed in bp_group_has_invites() 297 $this->invite->group_id = $group_id; 298 299 // loop has just started 300 if ( 0 == $this->current_invite ) { 301 302 /** 303 * Fires if the current invite item is the first in the loop. 304 * 305 * @since 1.1.0 306 * @since 2.3.0 `$this` parameter added. 307 * @since 2.7.0 Action renamed from `loop_start`. 308 * 309 * @param BP_Groups_Invite_Template $this Instance of the current Invites template. 310 */ 311 do_action( 'group_invitation_loop_start', $this ); 312 } 313 } 314 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Oct 13 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |