[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/bp-groups/ -> bp-groups-template.php (source)

   1  <?php
   2  
   3  /**
   4   * BuddyPress Groups Template Functions
   5   *
   6   * @package BuddyPress
   7   * @subpackage GroupsTemplate
   8   */
   9  
  10  // Exit if accessed directly
  11  if ( !defined( 'ABSPATH' ) ) exit;
  12  
  13  /**
  14   * Output the groups component slug
  15   *
  16   * @package BuddyPress
  17   * @subpackage Groups Template
  18   * @since BuddyPress (1.5)
  19   *
  20   * @uses bp_get_groups_slug()
  21   */
  22  function bp_groups_slug() {
  23      echo bp_get_groups_slug();
  24  }
  25      /**
  26       * Return the groups component slug
  27       *
  28       * @package BuddyPress
  29       * @subpackage Groups Template
  30       * @since BuddyPress (1.5)
  31       */
  32  	function bp_get_groups_slug() {
  33          return apply_filters( 'bp_get_groups_slug', buddypress()->groups->slug );
  34      }
  35  
  36  /**
  37   * Output the groups component root slug
  38   *
  39   * @package BuddyPress
  40   * @subpackage Groups Template
  41   * @since BuddyPress (1.5)
  42   *
  43   * @uses bp_get_groups_root_slug()
  44   */
  45  function bp_groups_root_slug() {
  46      echo bp_get_groups_root_slug();
  47  }
  48      /**
  49       * Return the groups component root slug
  50       *
  51       * @package BuddyPress
  52       * @subpackage Groups Template
  53       * @since BuddyPress (1.5)
  54       */
  55  	function bp_get_groups_root_slug() {
  56          return apply_filters( 'bp_get_groups_root_slug', buddypress()->groups->root_slug );
  57      }
  58  
  59  /**
  60   * Output group directory permalink
  61   *
  62   * @package BuddyPress
  63   * @subpackage Groups Template
  64   * @since BuddyPress (1.5)
  65   * @uses bp_get_groups_directory_permalink()
  66   */
  67  function bp_groups_directory_permalink() {
  68      echo bp_get_groups_directory_permalink();
  69  }
  70      /**
  71       * Return group directory permalink
  72       *
  73       * @package BuddyPress
  74       * @subpackage Groups Template
  75       * @since BuddyPress (1.5)
  76       * @uses apply_filters()
  77       * @uses traisingslashit()
  78       * @uses bp_get_root_domain()
  79       * @uses bp_get_groups_root_slug()
  80       * @return string
  81       */
  82  	function bp_get_groups_directory_permalink() {
  83          return apply_filters( 'bp_get_groups_directory_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
  84      }
  85  
  86  /*****************************************************************************
  87   * Groups Template Class/Tags
  88   **/
  89  
  90  class BP_Groups_Template {
  91      var $current_group = -1;
  92      var $group_count;
  93      var $groups;
  94      var $group;
  95  
  96      var $in_the_loop;
  97  
  98      var $pag_page;
  99      var $pag_num;
 100      var $pag_links;
 101      var $total_group_count;
 102  
 103      var $single_group = false;
 104  
 105      var $sort_by;
 106      var $order;
 107  
 108  	function __construct( $args = array() ){
 109  
 110          // Backward compatibility with old method of passing arguments
 111          if ( ! is_array( $args ) || func_num_args() > 1 ) {
 112              _deprecated_argument( __METHOD__, '1.7', 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__ ) );
 113  
 114              $old_args_keys = array(
 115                  0  => 'user_id',
 116                  1  => 'type',
 117                  2  => 'page',
 118                  3  => 'per_page',
 119                  4  => 'max',
 120                  5  => 'slug',
 121                  6  => 'search_terms',
 122                  7  => 'populate_extras',
 123                  8  => 'include',
 124                  9  => 'exclude',
 125                  10 => 'show_hidden',
 126                  11 => 'page_arg',
 127              );
 128  
 129              $func_args = func_get_args();
 130              $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
 131          }
 132  
 133          $defaults = array(
 134              'type'            => 'active',
 135              'page'            => 1,
 136              'per_page'        => 20,
 137              'max'             => false,
 138              'show_hidden'     => false,
 139              'page_arg'        => 'grpage',
 140              'user_id'         => 0,
 141              'slug'            => false,
 142              'include'         => false,
 143              'exclude'         => false,
 144              'search_terms'    => '',
 145              'meta_query'      => false,
 146              'populate_extras' => true,
 147              'update_meta_cache' => true,
 148          );
 149  
 150          $r = wp_parse_args( $args, $defaults );
 151          extract( $r );
 152  
 153          $this->pag_page = isset( $_REQUEST[$page_arg] ) ? intval( $_REQUEST[$page_arg] ) : $page;
 154          $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
 155  
 156          if ( bp_current_user_can( 'bp_moderate' ) || ( is_user_logged_in() && $user_id == bp_loggedin_user_id() ) )
 157              $show_hidden = true;
 158  
 159          if ( 'invites' == $type ) {
 160              $this->groups = groups_get_invites_for_user( $user_id, $this->pag_num, $this->pag_page, $exclude );
 161          } else if ( 'single-group' == $type ) {
 162              $this->single_group = true;
 163  
 164              if ( groups_get_current_group() ) {
 165                  $group = groups_get_current_group();
 166  
 167              } else {
 168                  $group = groups_get_group( array(
 169                      'group_id'        => BP_Groups_Group::get_id_from_slug( $r['slug'] ),
 170                      'populate_extras' => $r['populate_extras'],
 171                  ) );
 172              }
 173  
 174              // backwards compatibility - the 'group_id' variable is not part of the
 175              // BP_Groups_Group object, but we add it here for devs doing checks against it
 176              //
 177              // @see https://buddypress.trac.wordpress.org/changeset/3540
 178              //
 179              // this is subject to removal in a future release; devs should check against
 180              // $group->id instead
 181              $group->group_id = $group->id;
 182  
 183              $this->groups = array( $group );
 184  
 185          } else {
 186              $this->groups = groups_get_groups( array(
 187                  'type'              => $type,
 188                  'order'             => $order,
 189                  'orderby'           => $orderby,
 190                  'per_page'          => $this->pag_num,
 191                  'page'              => $this->pag_page,
 192                  'user_id'           => $user_id,
 193                  'search_terms'      => $search_terms,
 194                  'meta_query'        => $meta_query,
 195                  'include'           => $include,
 196                  'exclude'           => $exclude,
 197                  'populate_extras'   => $populate_extras,
 198                  'update_meta_cache' => $update_meta_cache,
 199                  'show_hidden'       => $show_hidden
 200              ) );
 201          }
 202  
 203          if ( 'invites' == $type ) {
 204              $this->total_group_count = (int) $this->groups['total'];
 205              $this->group_count       = (int) $this->groups['total'];
 206              $this->groups            = $this->groups['groups'];
 207          } else if ( 'single-group' == $type ) {
 208              if ( empty( $group->id ) ) {
 209                  $this->total_group_count = 0;
 210                  $this->group_count       = 0;
 211              } else {
 212                  $this->total_group_count = 1;
 213                  $this->group_count       = 1;
 214              }
 215          } else {
 216              if ( empty( $max ) || $max >= (int) $this->groups['total'] ) {
 217                  $this->total_group_count = (int) $this->groups['total'];
 218              } else {
 219                  $this->total_group_count = (int) $max;
 220              }
 221  
 222              $this->groups = $this->groups['groups'];
 223  
 224              if ( !empty( $max ) ) {
 225                  if ( $max >= count( $this->groups ) ) {
 226                      $this->group_count = count( $this->groups );
 227                  } else {
 228                      $this->group_count = (int) $max;
 229                  }
 230              } else {
 231                  $this->group_count = count( $this->groups );
 232              }
 233          }
 234  
 235          // Build pagination links
 236          if ( (int) $this->total_group_count && (int) $this->pag_num ) {
 237              $this->pag_links = paginate_links( array(
 238                  'base'      => add_query_arg( array( $page_arg => '%#%', 'num' => $this->pag_num, 's' => $search_terms, 'sortby' => $this->sort_by, 'order' => $this->order ) ),
 239                  'format'    => '',
 240                  'total'     => ceil( (int) $this->total_group_count / (int) $this->pag_num ),
 241                  'current'   => $this->pag_page,
 242                  'prev_text' => _x( '&larr;', 'Group pagination previous text', 'buddypress' ),
 243                  'next_text' => _x( '&rarr;', 'Group pagination next text', 'buddypress' ),
 244                  'mid_size'  => 1
 245              ) );
 246          }
 247      }
 248  
 249  	function has_groups() {
 250          if ( $this->group_count )
 251              return true;
 252  
 253          return false;
 254      }
 255  
 256  	function next_group() {
 257          $this->current_group++;
 258          $this->group = $this->groups[$this->current_group];
 259  
 260          return $this->group;
 261      }
 262  
 263  	function rewind_groups() {
 264          $this->current_group = -1;
 265          if ( $this->group_count > 0 ) {
 266              $this->group = $this->groups[0];
 267          }
 268      }
 269  
 270  	function groups() {
 271          if ( $this->current_group + 1 < $this->group_count ) {
 272              return true;
 273          } elseif ( $this->current_group + 1 == $this->group_count ) {
 274              do_action('group_loop_end');
 275              // Do some cleaning up after the loop
 276              $this->rewind_groups();
 277          }
 278  
 279          $this->in_the_loop = false;
 280          return false;
 281      }
 282  
 283  	function the_group() {
 284          $this->in_the_loop = true;
 285          $this->group       = $this->next_group();
 286  
 287          if ( 0 == $this->current_group ) // loop has just started
 288              do_action('group_loop_start');
 289      }
 290  }
 291  
 292  /**
 293   * Start the Groups Template Loop
 294   *
 295   * See the $defaults definition below for a description of parameters.
 296   *
 297   * Note that the 'type' parameter overrides 'order' and 'orderby'. See
 298   * BP_Groups_Group::get() for more details.
 299   *
 300   * @param array $args
 301   * @return bool True if there are groups to display that match the params
 302   */
 303  function bp_has_groups( $args = '' ) {
 304      global $groups_template, $bp;
 305  
 306      /***
 307       * Set the defaults based on the current page. Any of these will be overridden
 308       * if arguments are directly passed into the loop. Custom plugins should always
 309       * pass their parameters directly to the loop.
 310       */
 311      $slug    = false;
 312      $type    = '';
 313      $user_id = 0;
 314      $order   = '';
 315  
 316      // User filtering
 317      if ( bp_displayed_user_id() )
 318          $user_id = bp_displayed_user_id();
 319  
 320      // Type
 321      // @todo What is $order? At some point it was removed incompletely?
 322      if ( bp_is_current_action( 'my-groups' ) ) {
 323          if ( 'most-popular' == $order ) {
 324              $type = 'popular';
 325          } elseif ( 'alphabetically' == $order ) {
 326              $type = 'alphabetical';
 327          }
 328      } elseif ( bp_is_current_action( 'invites' ) ) {
 329          $type = 'invites';
 330      } elseif ( isset( $bp->groups->current_group->slug ) && $bp->groups->current_group->slug ) {
 331          $type = 'single-group';
 332          $slug = $bp->groups->current_group->slug;
 333      }
 334  
 335      // Default search string
 336      if ( ! empty( $_REQUEST['group-filter-box'] ) ) {
 337          $search_terms = $_REQUEST['group-filter-box'];
 338      } elseif ( isset( $_REQUEST['s'] ) && !empty( $_REQUEST['s'] ) ) {
 339          $search_terms = $_REQUEST['s'];
 340      } else {
 341          $search_terms = false;
 342      }
 343  
 344      $defaults = array(
 345          'type'              => $type, // 'type' is an override for 'order' and 'orderby'. See docblock.
 346          'order'             => 'DESC',
 347          'orderby'           => 'last_activity',
 348          'page'              => 1,
 349          'per_page'          => 20,
 350          'max'               => false,
 351          'show_hidden'       => false,
 352  
 353          'page_arg'          => 'grpage', // See https://buddypress.trac.wordpress.org/ticket/3679
 354  
 355          'user_id'           => $user_id, // Pass a user ID to limit to groups this user has joined
 356          'slug'              => $slug,    // Pass a group slug to only return that group
 357          'search_terms'      => $search_terms, // Pass search terms to return only matching groups
 358          'meta_query'        => false,    // Filter by groupmeta. See WP_Meta_Query for format
 359          'include'           => false,    // Pass comma separated list or array of group ID's to return only these groups
 360          'exclude'           => false,    // Pass comma separated list or array of group ID's to exclude these groups
 361  
 362          'populate_extras'   => true,     // Get extra meta - is_member, is_banned
 363          'update_meta_cache' => true,
 364      );
 365  
 366      $r = bp_parse_args( $args, $defaults, 'has_groups' );
 367  
 368      $groups_template = new BP_Groups_Template( array(
 369          'type'              => $r['type'],
 370          'order'             => $r['order'],
 371          'orderby'           => $r['orderby'],
 372          'page'              => (int) $r['page'],
 373          'per_page'          => (int) $r['per_page'],
 374          'max'               => (int) $r['max'],
 375          'show_hidden'       => $r['show_hidden'],
 376          'page_arg'          => $r['page_arg'],
 377          'user_id'           => (int) $r['user_id'],
 378          'slug'              => $r['slug'],
 379          'search_terms'      => $r['search_terms'],
 380          'meta_query'        => $r['meta_query'],
 381          'include'           => $r['include'],
 382          'exclude'           => $r['exclude'],
 383          'populate_extras'   => (bool) $r['populate_extras'],
 384          'update_meta_cache' => (bool) $r['update_meta_cache'],
 385      ) );
 386  
 387      return apply_filters( 'bp_has_groups', $groups_template->has_groups(), $groups_template, $r );
 388  }
 389  
 390  function bp_groups() {
 391      global $groups_template;
 392      return $groups_template->groups();
 393  }
 394  
 395  function bp_the_group() {
 396      global $groups_template;
 397      return $groups_template->the_group();
 398  }
 399  
 400  function bp_group_is_visible( $group = false ) {
 401      global $groups_template;
 402  
 403      if ( bp_current_user_can( 'bp_moderate' ) )
 404          return true;
 405  
 406      if ( empty( $group ) )
 407          $group =& $groups_template->group;
 408  
 409      if ( 'public' == $group->status ) {
 410          return true;
 411      } else {
 412          if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
 413              return true;
 414          }
 415      }
 416  
 417      return false;
 418  }
 419  
 420  function bp_group_id( $group = false ) {
 421      echo bp_get_group_id( $group );
 422  }
 423  	function bp_get_group_id( $group = false ) {
 424          global $groups_template;
 425  
 426          if ( empty( $group ) )
 427              $group =& $groups_template->group;
 428  
 429          return apply_filters( 'bp_get_group_id', $group->id );
 430      }
 431  
 432  /**
 433   * Output the row class of a group
 434   *
 435   * @since BuddyPress (1.7)
 436   */
 437  function bp_group_class() {
 438      echo bp_get_group_class();
 439  }
 440      /**
 441       * Return the row class of a group
 442       *
 443       * @global BP_Groups_Template $groups_template
 444       * @return string Row class of the group
 445       * @since BuddyPress (1.7)
 446       */
 447  	function bp_get_group_class() {
 448          global $groups_template;
 449  
 450          $classes      = array();
 451          $pos_in_loop  = (int) $groups_template->current_group;
 452  
 453          // If we've only one group in the loop, don't both with odd and even.
 454          if ( $groups_template->group_count > 1 )
 455              $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd';
 456          else
 457              $classes[] = 'bp-single-group';
 458  
 459          // Group type - public, private, hidden.
 460          $classes[] = esc_attr( $groups_template->group->status );
 461  
 462          // User's group status
 463          if ( bp_is_user_active() ) {
 464              if ( bp_group_is_admin() )
 465                  $classes[] = 'is-admin';
 466  
 467              if ( bp_group_is_member() )
 468                  $classes[] = 'is-member';
 469  
 470              if ( bp_group_is_mod() )
 471                  $classes[] = 'is-mod';
 472          }
 473  
 474          $classes = apply_filters( 'bp_get_group_class', $classes );
 475          $classes = array_merge( $classes, array() );
 476          $retval = 'class="' . join( ' ', $classes ) . '"';
 477  
 478          return $retval;
 479      }
 480  
 481  function bp_group_name( $group = false ) {
 482      echo bp_get_group_name( $group );
 483  }
 484  	function bp_get_group_name( $group = false ) {
 485          global $groups_template;
 486  
 487          if ( empty( $group ) )
 488              $group =& $groups_template->group;
 489  
 490          return apply_filters( 'bp_get_group_name', $group->name );
 491      }
 492  
 493  function bp_group_type( $group = false ) {
 494      echo bp_get_group_type( $group );
 495  }
 496  	function bp_get_group_type( $group = false ) {
 497          global $groups_template;
 498  
 499          if ( empty( $group ) )
 500              $group =& $groups_template->group;
 501  
 502          if ( 'public' == $group->status ) {
 503              $type = __( "Public Group", "buddypress" );
 504          } else if ( 'hidden' == $group->status ) {
 505              $type = __( "Hidden Group", "buddypress" );
 506          } else if ( 'private' == $group->status ) {
 507              $type = __( "Private Group", "buddypress" );
 508          } else {
 509              $type = ucwords( $group->status ) . ' ' . __( 'Group', 'buddypress' );
 510          }
 511  
 512          return apply_filters( 'bp_get_group_type', $type );
 513      }
 514  
 515  function bp_group_status( $group = false ) {
 516      echo bp_get_group_status( $group );
 517  }
 518  	function bp_get_group_status( $group = false ) {
 519          global $groups_template;
 520  
 521          if ( empty( $group ) )
 522              $group =& $groups_template->group;
 523  
 524          return apply_filters( 'bp_get_group_status', $group->status );
 525      }
 526  
 527  function bp_group_avatar( $args = '' ) {
 528      echo bp_get_group_avatar( $args );
 529  }
 530  	function bp_get_group_avatar( $args = '' ) {
 531          global $bp, $groups_template;
 532  
 533          $defaults = array(
 534              'type'   => 'full',
 535              'width'  => false,
 536              'height' => false,
 537              'class'  => 'avatar',
 538              'id'     => false,
 539              'alt'    => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
 540          );
 541  
 542          $r = wp_parse_args( $args, $defaults );
 543          extract( $r, EXTR_SKIP );
 544  
 545          /* Fetch the avatar from the folder, if not provide backwards compat. */
 546          if ( !$avatar = bp_core_fetch_avatar( array( 'item_id' => $groups_template->group->id, 'object' => 'group', 'type' => $type, 'avatar_dir' => 'group-avatars', 'alt' => $alt, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'title' => $groups_template->group->name, 'alt' => $alt ) ) )
 547              $avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />';
 548  
 549          return apply_filters( 'bp_get_group_avatar', $avatar );
 550      }
 551  
 552  function bp_group_avatar_thumb( $group = false ) {
 553      echo bp_get_group_avatar_thumb( $group );
 554  }
 555  	function bp_get_group_avatar_thumb( $group = false ) {
 556          return bp_get_group_avatar( 'type=thumb' );
 557      }
 558  
 559  function bp_group_avatar_mini( $group = false ) {
 560      echo bp_get_group_avatar_mini( $group );
 561  }
 562  	function bp_get_group_avatar_mini( $group = false ) {
 563          return bp_get_group_avatar( 'type=thumb&width=30&height=30' );
 564      }
 565  
 566  function bp_group_last_active( $group = false ) {
 567      echo bp_get_group_last_active( $group );
 568  }
 569  	function bp_get_group_last_active( $group = false ) {
 570          global $groups_template;
 571  
 572          if ( empty( $group ) )
 573              $group =& $groups_template->group;
 574  
 575          $last_active = $group->last_activity;
 576  
 577          if ( !$last_active )
 578              $last_active = groups_get_groupmeta( $group->id, 'last_activity' );
 579  
 580          if ( empty( $last_active ) ) {
 581              return __( 'not yet active', 'buddypress' );
 582          } else {
 583              return apply_filters( 'bp_get_group_last_active', bp_core_time_since( $last_active ) );
 584          }
 585      }
 586  
 587  function bp_group_permalink( $group = false ) {
 588      echo bp_get_group_permalink( $group );
 589  }
 590  	function bp_get_group_permalink( $group = false ) {
 591          global $groups_template;
 592  
 593          if ( empty( $group ) )
 594              $group =& $groups_template->group;
 595  
 596          return apply_filters( 'bp_get_group_permalink', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group->slug . '/' ) );
 597      }
 598  
 599  function bp_group_admin_permalink( $group = false ) {
 600      echo bp_get_group_admin_permalink( $group );
 601  }
 602  	function bp_get_group_admin_permalink( $group = false ) {
 603          global $groups_template;
 604  
 605          if ( empty( $group ) )
 606              $group =& $groups_template->group;
 607  
 608          return apply_filters( 'bp_get_group_admin_permalink', trailingslashit( bp_get_group_permalink( $group ) . 'admin' ) );
 609      }
 610  
 611  function bp_group_slug( $group = false ) {
 612      echo bp_get_group_slug( $group );
 613  }
 614  	function bp_get_group_slug( $group = false ) {
 615          global $groups_template;
 616  
 617          if ( empty( $group ) )
 618              $group =& $groups_template->group;
 619  
 620          return apply_filters( 'bp_get_group_slug', $group->slug );
 621      }
 622  
 623  function bp_group_description( $group = false ) {
 624      echo bp_get_group_description( $group );
 625  }
 626  	function bp_get_group_description( $group = false ) {
 627          global $groups_template;
 628  
 629          if ( empty( $group ) )
 630              $group =& $groups_template->group;
 631  
 632          return apply_filters( 'bp_get_group_description', stripslashes($group->description) );
 633      }
 634  
 635  function bp_group_description_editable( $group = false ) {
 636      echo bp_get_group_description_editable( $group );
 637  }
 638  	function bp_get_group_description_editable( $group = false ) {
 639          global $groups_template;
 640  
 641          if ( empty( $group ) )
 642              $group =& $groups_template->group;
 643  
 644          return apply_filters( 'bp_get_group_description_editable', $group->description );
 645      }
 646  
 647  /**
 648   * Output an excerpt of the group description.
 649   *
 650   * @param object $group Optional. The group being referenced. Defaults to the
 651   *        group currently being iterated on in the groups loop.
 652   */
 653  function bp_group_description_excerpt( $group = false ) {
 654      echo bp_get_group_description_excerpt( $group );
 655  }
 656      /**
 657       * Get an excerpt of a group description.
 658       *
 659       * @param object $group Optional. The group being referenced. Defaults
 660       *        to the group currently being iterated on in the groups loop.
 661       * @return string Excerpt.
 662       */
 663  	function bp_get_group_description_excerpt( $group = false ) {
 664          global $groups_template;
 665  
 666          if ( empty( $group ) ) {
 667              $group =& $groups_template->group;
 668          }
 669  
 670          return apply_filters( 'bp_get_group_description_excerpt', bp_create_excerpt( $group->description ), $group );
 671      }
 672  
 673  
 674  function bp_group_public_status( $group = false ) {
 675      echo bp_get_group_public_status( $group );
 676  }
 677  	function bp_get_group_public_status( $group = false ) {
 678          global $groups_template;
 679  
 680          if ( empty( $group ) )
 681              $group =& $groups_template->group;
 682  
 683          if ( $group->is_public ) {
 684              return __( 'Public', 'buddypress' );
 685          } else {
 686              return __( 'Private', 'buddypress' );
 687          }
 688      }
 689  
 690  function bp_group_is_public( $group = false ) {
 691      echo bp_get_group_is_public( $group );
 692  }
 693  	function bp_get_group_is_public( $group = false ) {
 694          global $groups_template;
 695  
 696          if ( empty( $group ) )
 697              $group =& $groups_template->group;
 698  
 699          return apply_filters( 'bp_get_group_is_public', $group->is_public );
 700      }
 701  
 702  function bp_group_date_created( $group = false ) {
 703      echo bp_get_group_date_created( $group );
 704  }
 705  	function bp_get_group_date_created( $group = false ) {
 706          global $groups_template;
 707  
 708          if ( empty( $group ) )
 709              $group =& $groups_template->group;
 710  
 711          return apply_filters( 'bp_get_group_date_created', bp_core_time_since( strtotime( $group->date_created ) ) );
 712      }
 713  
 714  function bp_group_creator_username( $group = false ) {
 715      echo bp_get_group_creator_username( $group );
 716  }
 717  	function bp_get_group_creator_username( $group = false ) {
 718          global $groups_template;
 719  
 720          if ( empty( $group ) )
 721              $group =& $groups_template->group;
 722  
 723          return apply_filters( 'bp_get_group_creator_username', bp_core_get_user_displayname( $group->creator_id ) );
 724      }
 725  
 726  function bp_group_creator_id( $group = false ) {
 727      echo bp_get_group_creator_id( $group );
 728  }
 729  	function bp_get_group_creator_id( $group = false ) {
 730          global $groups_template;
 731  
 732          if ( empty( $group ) )
 733              $group =& $groups_template->group;
 734  
 735          return apply_filters( 'bp_get_group_creator_id', $group->creator_id );
 736      }
 737  
 738  function bp_group_creator_permalink( $group = false ) {
 739      echo bp_get_group_creator_permalink( $group );
 740  }
 741  	function bp_get_group_creator_permalink( $group = false ) {
 742          global $groups_template;
 743  
 744          if ( empty( $group ) )
 745              $group =& $groups_template->group;
 746  
 747          return apply_filters( 'bp_get_group_creator_permalink', bp_core_get_user_domain( $group->creator_id ) );
 748      }
 749  
 750  function bp_is_group_creator( $group = false, $user_id = 0 ) {
 751      global $groups_template;
 752  
 753      if ( empty( $group ) )
 754          $group =& $groups_template->group;
 755  
 756      if ( empty( $user_id ) )
 757          $user_id = bp_loggedin_user_id();
 758  
 759      return (bool) ( $group->creator_id == $user_id );
 760  }
 761  
 762  function bp_group_creator_avatar( $group = false, $args = array() ) {
 763      echo bp_get_group_creator_avatar( $group, $args );
 764  }
 765  	function bp_get_group_creator_avatar( $group = false, $args = array() ) {
 766          global $groups_template;
 767  
 768          if ( empty( $group ) )
 769              $group =& $groups_template->group;
 770  
 771          $defaults = array(
 772              'type'   => 'full',
 773              'width'  => false,
 774              'height' => false,
 775              'class'  => 'avatar',
 776              'id'     => false,
 777              'alt'    => sprintf( __( 'Group creator avatar of %s', 'buddypress' ),  bp_core_get_user_displayname( $group->creator_id ) )
 778          );
 779  
 780          $r = wp_parse_args( $args, $defaults );
 781          extract( $r, EXTR_SKIP );
 782  
 783          $avatar = bp_core_fetch_avatar( array( 'item_id' => $group->creator_id, 'type' => $type, 'css_id' => $id, 'class' => $class, 'width' => $width, 'height' => $height, 'alt' => $alt ) );
 784  
 785          return apply_filters( 'bp_get_group_creator_avatar', $avatar );
 786      }
 787  
 788  
 789  function bp_group_is_admin() {
 790      return bp_is_item_admin();
 791  }
 792  
 793  function bp_group_is_mod() {
 794      return bp_is_item_mod();
 795  }
 796  
 797  function bp_group_list_admins( $group = false ) {
 798      global $groups_template;
 799  
 800      if ( empty( $group ) ) {
 801          $group =& $groups_template->group;
 802      }
 803  
 804      // fetch group admins if 'populate_extras' flag is false
 805      if ( empty( $group->args['populate_extras'] ) ) {
 806          $query = new BP_Group_Member_Query( array(
 807              'group_id'   => $group->id,
 808              'group_role' => 'admin',
 809              'type'       => 'first_joined',
 810          ) );
 811  
 812          if ( ! empty( $query->results ) ) {
 813              $group->admins = $query->results;
 814          }
 815      }
 816  
 817      if ( ! empty( $group->admins ) ) { ?>
 818          <ul id="group-admins">
 819              <?php foreach( (array) $group->admins as $admin ) { ?>
 820                  <li>
 821                      <a href="<?php echo bp_core_get_user_domain( $admin->user_id, $admin->user_nicename, $admin->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'email' => $admin->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?></a>
 822                  </li>
 823              <?php } ?>
 824          </ul>
 825      <?php } else { ?>
 826          <span class="activity"><?php _e( 'No Admins', 'buddypress' ) ?></span>
 827      <?php } ?>
 828  <?php
 829  }
 830  
 831  function bp_group_list_mods( $group = false ) {
 832      global $groups_template;
 833  
 834      if ( empty( $group ) ) {
 835          $group =& $groups_template->group;
 836      }
 837  
 838      // fetch group mods if 'populate_extras' flag is false
 839      if ( empty( $group->args['populate_extras'] ) ) {
 840          $query = new BP_Group_Member_Query( array(
 841              'group_id'   => $group->id,
 842              'group_role' => 'mod',
 843              'type'       => 'first_joined',
 844          ) );
 845  
 846          if ( ! empty( $query->results ) ) {
 847              $group->mods = $query->results;
 848          }
 849      }
 850  
 851      if ( ! empty( $group->mods ) ) : ?>
 852  
 853          <ul id="group-mods">
 854  
 855              <?php foreach( (array) $group->mods as $mod ) { ?>
 856  
 857                  <li>
 858                      <a href="<?php echo bp_core_get_user_domain( $mod->user_id, $mod->user_nicename, $mod->user_login ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'email' => $mod->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?></a>
 859                  </li>
 860  
 861              <?php } ?>
 862  
 863          </ul>
 864  
 865  <?php else : ?>
 866  
 867          <span class="activity"><?php _e( 'No Mods', 'buddypress' ) ?></span>
 868  
 869  <?php endif;
 870  
 871  }
 872  
 873  /**
 874   * Return a list of user_ids for a group's admins
 875   *
 876   * @package BuddyPress
 877   * @since BuddyPress (1.5)
 878   *
 879   * @param BP_Groups_Group $group (optional) The group being queried. Defaults to the current group in the loop
 880   * @param string $format 'string' to get a comma-separated string, 'array' to get an array
 881   * @return mixed $admin_ids A string or array of user_ids
 882   */
 883  function bp_group_admin_ids( $group = false, $format = 'string' ) {
 884      global $groups_template;
 885  
 886      if ( empty( $group ) )
 887          $group =& $groups_template->group;
 888  
 889      $admin_ids = array();
 890  
 891      if ( $group->admins ) {
 892          foreach( $group->admins as $admin ) {
 893              $admin_ids[] = $admin->user_id;
 894          }
 895      }
 896  
 897      if ( 'string' == $format )
 898          $admin_ids = implode( ',', $admin_ids );
 899  
 900      return apply_filters( 'bp_group_admin_ids', $admin_ids );
 901  }
 902  
 903  /**
 904   * Return a list of user_ids for a group's moderators
 905   *
 906   * @package BuddyPress
 907   * @since BuddyPress (1.5)
 908   *
 909   * @param BP_Groups_Group $group (optional) The group being queried. Defaults to the current group in the loop
 910   * @param string $format 'string' to get a comma-separated string, 'array' to get an array
 911   * @return mixed $mod_ids A string or array of user_ids
 912   */
 913  function bp_group_mod_ids( $group = false, $format = 'string' ) {
 914      global $groups_template;
 915  
 916      if ( empty( $group ) )
 917          $group =& $groups_template->group;
 918  
 919      $mod_ids = array();
 920  
 921      if ( $group->mods ) {
 922          foreach( $group->mods as $mod ) {
 923              $mod_ids[] = $mod->user_id;
 924          }
 925      }
 926  
 927      if ( 'string' == $format )
 928          $mod_ids = implode( ',', $mod_ids );
 929  
 930      return apply_filters( 'bp_group_mod_ids', $mod_ids );
 931  }
 932  
 933  function bp_group_all_members_permalink() {
 934      echo bp_get_group_all_members_permalink();
 935  }
 936  	function bp_get_group_all_members_permalink( $group = false ) {
 937          global $groups_template;
 938  
 939          if ( empty( $group ) )
 940              $group =& $groups_template->group;
 941  
 942          return apply_filters( 'bp_get_group_all_members_permalink', bp_get_group_permalink( $group ) . 'members' );
 943      }
 944  
 945  function bp_group_search_form() {
 946      global $bp;
 947  
 948      $action = bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/search/';
 949      $label = __('Filter Groups', 'buddypress');
 950      $name = 'group-filter-box';
 951  
 952      $search_form_html = '<form action="' . $action . '" id="group-search-form" method="post">
 953          <label for="'. $name .'" id="'. $name .'-label">'. $label .'</label>
 954          <input type="search" name="'. $name . '" id="'. $name .'" value="'. $value .'"'.  $disabled .' />
 955  
 956          '. wp_nonce_field( 'group-filter-box', '_wpnonce_group_filter', true, false ) .'
 957          </form>';
 958  
 959      echo apply_filters( 'bp_group_search_form', $search_form_html );
 960  }
 961  
 962  function bp_group_show_no_groups_message() {
 963      if ( !groups_total_groups_for_user( bp_displayed_user_id() ) )
 964          return true;
 965  
 966      return false;
 967  }
 968  
 969  function bp_group_is_activity_permalink() {
 970  
 971      if ( !bp_is_single_item() || !bp_is_groups_component() || !bp_is_current_action( bp_get_activity_slug() ) )
 972          return false;
 973  
 974      return true;
 975  }
 976  
 977  function bp_groups_pagination_links() {
 978      echo bp_get_groups_pagination_links();
 979  }
 980  	function bp_get_groups_pagination_links() {
 981          global $groups_template;
 982  
 983          return apply_filters( 'bp_get_groups_pagination_links', $groups_template->pag_links );
 984      }
 985  
 986  function bp_groups_pagination_count() {
 987      echo bp_get_groups_pagination_count();
 988  }
 989  	function bp_get_groups_pagination_count() {
 990          global $groups_template;
 991  
 992          $start_num = intval( ( $groups_template->pag_page - 1 ) * $groups_template->pag_num ) + 1;
 993          $from_num  = bp_core_number_format( $start_num );
 994          $to_num    = bp_core_number_format( ( $start_num + ( $groups_template->pag_num - 1 ) > $groups_template->total_group_count ) ? $groups_template->total_group_count : $start_num + ( $groups_template->pag_num - 1 ) );
 995          $total     = bp_core_number_format( $groups_template->total_group_count );
 996  
 997          return apply_filters( 'bp_get_groups_pagination_count', sprintf( _n( 'Viewing group %1$s to %2$s (of %3$s group)', 'Viewing group %1$s to %2$s (of %3$s groups)', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total );
 998      }
 999  
1000  function bp_groups_auto_join() {
1001      global $bp;
1002  
1003      return apply_filters( 'bp_groups_auto_join', (bool)$bp->groups->auto_join );
1004  }
1005  
1006  function bp_group_total_members( $group = false ) {
1007      echo bp_get_group_total_members( $group );
1008  }
1009  	function bp_get_group_total_members( $group = false ) {
1010          global $groups_template;
1011  
1012          if ( empty( $group ) )
1013              $group =& $groups_template->group;
1014  
1015          return apply_filters( 'bp_get_group_total_members', $group->total_member_count );
1016      }
1017  
1018  function bp_group_member_count() {
1019      echo bp_get_group_member_count();
1020  }
1021  	function bp_get_group_member_count() {
1022          global $groups_template;
1023  
1024          if ( 1 == (int) $groups_template->group->total_member_count )
1025              return apply_filters( 'bp_get_group_member_count', sprintf( __( '%s member', 'buddypress' ), bp_core_number_format( $groups_template->group->total_member_count ) ) );
1026          else
1027              return apply_filters( 'bp_get_group_member_count', sprintf( __( '%s members', 'buddypress' ), bp_core_number_format( $groups_template->group->total_member_count ) ) );
1028      }
1029  
1030  function bp_group_forum_permalink() {
1031      echo bp_get_group_forum_permalink();
1032  }
1033  	function bp_get_group_forum_permalink( $group = false ) {
1034          global $groups_template;
1035  
1036          if ( empty( $group ) )
1037              $group =& $groups_template->group;
1038  
1039          return apply_filters( 'bp_get_group_forum_permalink', bp_get_group_permalink( $group ) . 'forum' );
1040      }
1041  
1042  function bp_group_forum_topic_count( $args = '' ) {
1043      echo bp_get_group_forum_topic_count( $args );
1044  }
1045  	function bp_get_group_forum_topic_count( $args = '' ) {
1046          global $groups_template;
1047  
1048          $defaults = array(
1049              'showtext' => false
1050          );
1051  
1052          $r = wp_parse_args( $args, $defaults );
1053          extract( $r, EXTR_SKIP );
1054  
1055          if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) )
1056              return false;
1057  
1058          if ( !bp_is_active( 'forums' ) )
1059              return false;
1060  
1061          if ( !$groups_template->group->forum_counts )
1062              $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
1063  
1064          if ( (bool) $showtext ) {
1065              if ( 1 == (int) $groups_template->group->forum_counts[0]->topics )
1066                  $total_topics = sprintf( __( '%d topic', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
1067              else
1068                  $total_topics = sprintf( __( '%d topics', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->topics );
1069          } else {
1070              $total_topics = (int) $groups_template->group->forum_counts[0]->topics;
1071          }
1072  
1073          return apply_filters( 'bp_get_group_forum_topic_count', $total_topics, (bool)$showtext );
1074      }
1075  
1076  function bp_group_forum_post_count( $args = '' ) {
1077      echo bp_get_group_forum_post_count( $args );
1078  }
1079  	function bp_get_group_forum_post_count( $args = '' ) {
1080          global $groups_template;
1081  
1082          $defaults = array(
1083              'showtext' => false
1084          );
1085  
1086          $r = wp_parse_args( $args, $defaults );
1087          extract( $r, EXTR_SKIP );
1088  
1089          if ( !$forum_id = groups_get_groupmeta( $groups_template->group->id, 'forum_id' ) )
1090              return false;
1091  
1092          if ( !bp_is_active( 'forums' ) )
1093              return false;
1094  
1095          if ( !$groups_template->group->forum_counts )
1096              $groups_template->group->forum_counts = bp_forums_get_forum_topicpost_count( (int) $forum_id );
1097  
1098          if ( (bool) $showtext ) {
1099              if ( 1 == (int) $groups_template->group->forum_counts[0]->posts )
1100                  $total_posts = sprintf( __( '%d post', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
1101              else
1102                  $total_posts = sprintf( __( '%d posts', 'buddypress' ), (int) $groups_template->group->forum_counts[0]->posts );
1103          } else {
1104              $total_posts = (int) $groups_template->group->forum_counts[0]->posts;
1105          }
1106  
1107          return apply_filters( 'bp_get_group_forum_post_count', $total_posts, (bool)$showtext );
1108      }
1109  
1110  function bp_group_is_forum_enabled( $group = false ) {
1111      global $groups_template;
1112  
1113      if ( empty( $group ) )
1114          $group =& $groups_template->group;
1115  
1116      if ( ! empty( $group->enable_forum ) )
1117          return true;
1118  
1119      return false;
1120  }
1121  
1122  function bp_group_show_forum_setting( $group = false ) {
1123      global $groups_template;
1124  
1125      if ( empty( $group ) )
1126          $group =& $groups_template->group;
1127  
1128      if ( $group->enable_forum )
1129          echo ' checked="checked"';
1130  }
1131  
1132  function bp_group_show_status_setting( $setting, $group = false ) {
1133      global $groups_template;
1134  
1135      if ( empty( $group ) )
1136          $group =& $groups_template->group;
1137  
1138      if ( $setting == $group->status )
1139          echo ' checked="checked"';
1140  }
1141  
1142  /**
1143   * Get the 'checked' value, if needed, for a given invite_status on the group create/admin screens
1144   *
1145   * @package BuddyPress
1146   * @subpackage Groups Template
1147   * @since BuddyPress (1.5)
1148   *
1149   * @param string $setting The setting you want to check against ('members', 'mods', or 'admins')
1150   * @param BP_Groups_Group $group (optional) The group whose status you want to check
1151   */
1152  function bp_group_show_invite_status_setting( $setting, $group = false ) {
1153      $group_id = isset( $group->id ) ? $group->id : false;
1154  
1155      $invite_status = bp_group_get_invite_status( $group_id );
1156  
1157      if ( $setting == $invite_status )
1158          echo ' checked="checked"';
1159  }
1160  
1161  /**
1162   * Get the invite status of a group
1163   *
1164   * 'invite_status' became part of BuddyPress in BP 1.5. In order to provide backward compatibility,
1165   * groups without a status set will default to 'members', ie all members in a group can send
1166   * invitations. Filter 'bp_group_invite_status_fallback' to change this fallback behavior.
1167   *
1168   * This function can be used either in or out of the loop.
1169   *
1170   * @package BuddyPress
1171   * @subpackage Groups Template
1172   * @since BuddyPress (1.5)
1173   *
1174   * @param int $group_id (optional) The id of the group whose status you want to check
1175   * @return mixed Returns false when no group can be found. Otherwise returns the group invite
1176   *    status, from among 'members', 'mods', and 'admins'
1177   */
1178  function bp_group_get_invite_status( $group_id = false ) {
1179      global $bp, $groups_template;
1180  
1181      if ( !$group_id ) {
1182          if ( isset( $bp->groups->current_group->id ) ) {
1183              // Default to the current group first
1184              $group_id = $bp->groups->current_group->id;
1185          } else if ( isset( $groups_template->group->id ) ) {
1186              // Then see if we're in the loop
1187              $group_id = $groups_template->group->id;
1188          } else {
1189              return false;
1190          }
1191      }
1192  
1193      $invite_status = groups_get_groupmeta( $group_id, 'invite_status' );
1194  
1195      // Backward compatibility. When 'invite_status' is not set, fall back to a default value
1196      if ( !$invite_status ) {
1197          $invite_status = apply_filters( 'bp_group_invite_status_fallback', 'members' );
1198      }
1199  
1200      return apply_filters( 'bp_group_get_invite_status', $invite_status, $group_id );
1201  }
1202  
1203  /**
1204   * Can the logged-in user send invitations in the specified group?
1205   *
1206   * @package BuddyPress
1207   * @subpackage Groups Template
1208   * @since BuddyPress (1.5)
1209   *
1210   * @param int $group_id (optional) The id of the group whose status you want to check
1211   * @return bool $can_send_invites
1212   */
1213  function bp_groups_user_can_send_invites( $group_id = false ) {
1214      global $bp;
1215  
1216      $can_send_invites = false;
1217      $invite_status    = false;
1218  
1219      if ( is_user_logged_in() ) {
1220          if ( bp_current_user_can( 'bp_moderate' ) ) {
1221              // Super admins can always send invitations
1222              $can_send_invites = true;
1223  
1224          } else {
1225              // If no $group_id is provided, default to the current group id
1226              if ( !$group_id )
1227                  $group_id = isset( $bp->groups->current_group->id ) ? $bp->groups->current_group->id : 0;
1228  
1229              // If no group has been found, bail
1230              if ( !$group_id )
1231                  return false;
1232  
1233              $invite_status = bp_group_get_invite_status( $group_id );
1234              if ( !$invite_status )
1235                  return false;
1236  
1237              switch ( $invite_status ) {
1238                  case 'admins' :
1239                      if ( groups_is_user_admin( bp_loggedin_user_id(), $group_id ) )
1240                          $can_send_invites = true;
1241                      break;
1242  
1243                  case 'mods' :
1244                      if ( groups_is_user_mod( bp_loggedin_user_id(), $group_id ) || groups_is_user_admin( bp_loggedin_user_id(), $group_id ) )
1245                          $can_send_invites = true;
1246                      break;
1247  
1248                  case 'members' :
1249                      if ( groups_is_user_member( bp_loggedin_user_id(), $group_id ) )
1250                          $can_send_invites = true;
1251                      break;
1252              }
1253          }
1254      }
1255  
1256      return apply_filters( 'bp_groups_user_can_send_invites', $can_send_invites, $group_id, $invite_status );
1257  }
1258  
1259  /**
1260   * Since BuddyPress 1.0, this generated the group settings admin/member screen.
1261   * As of BuddyPress 1.5 (r4489), and because this function outputs HTML, it was moved into /bp-default/groups/single/admin.php.
1262   *
1263   * @deprecated 1.5
1264   * @deprecated No longer used.
1265   * @since BuddyPress (1.0)
1266   * @todo Remove in 1.4
1267   */
1268  function bp_group_admin_memberlist( $admin_list = false, $group = false ) {
1269      global $groups_template;
1270  
1271      _deprecated_function( __FUNCTION__, '1.5', 'No longer used. See /bp-default/groups/single/admin.php' );
1272  
1273      if ( empty( $group ) )
1274          $group =& $groups_template->group;
1275  
1276  
1277      if ( $admins = groups_get_group_admins( $group->id ) ) : ?>
1278  
1279          <ul id="admins-list" class="item-list<?php if ( !empty( $admin_list ) ) : ?> single-line<?php endif; ?>">
1280  
1281          <?php foreach ( (array) $admins as $admin ) { ?>
1282  
1283              <?php if ( !empty( $admin_list ) ) : ?>
1284  
1285              <li>
1286  
1287                  <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?>
1288  
1289                  <h5>
1290  
1291                      <?php echo bp_core_get_userlink( $admin->user_id ); ?>
1292  
1293                      <span class="small">
1294                          <a class="button confirm admin-demote-to-member" href="<?php bp_group_member_demote_link($admin->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a>
1295                      </span>
1296                  </h5>
1297              </li>
1298  
1299              <?php else : ?>
1300  
1301              <li>
1302  
1303                  <?php echo bp_core_fetch_avatar( array( 'item_id' => $admin->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $admin->user_id ) ) ) ) ?>
1304  
1305                  <h5><?php echo bp_core_get_userlink( $admin->user_id ) ?></h5>
1306                  <span class="activity">
1307                      <?php echo bp_core_get_last_activity( strtotime( $admin->date_modified ), __( 'joined %s', 'buddypress') ); ?>
1308                  </span>
1309  
1310                  <?php if ( bp_is_active( 'friends' ) ) : ?>
1311  
1312                      <div class="action">
1313  
1314                          <?php bp_add_friend_button( $admin->user_id ); ?>
1315  
1316                      </div>
1317  
1318                  <?php endif; ?>
1319  
1320              </li>
1321  
1322              <?php endif;
1323          } ?>
1324  
1325          </ul>
1326  
1327      <?php else : ?>
1328  
1329          <div id="message" class="info">
1330              <p><?php _e( 'This group has no administrators', 'buddypress' ); ?></p>
1331          </div>
1332  
1333      <?php endif;
1334  }
1335  
1336  function bp_group_mod_memberlist( $admin_list = false, $group = false ) {
1337      global $groups_template;
1338  
1339      if ( empty( $group ) )
1340          $group =& $groups_template->group;
1341  
1342      if ( $group_mods = groups_get_group_mods( $group->id ) ) { ?>
1343  
1344          <ul id="mods-list" class="item-list<?php if ( $admin_list ) { ?> single-line<?php } ?>">
1345  
1346          <?php foreach ( (array) $group_mods as $mod ) { ?>
1347  
1348              <?php if ( !empty( $admin_list ) ) { ?>
1349  
1350              <li>
1351  
1352                  <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'width' => 30, 'height' => 30, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?>
1353  
1354                  <h5>
1355                      <?php echo bp_core_get_userlink( $mod->user_id ); ?>
1356  
1357                      <span class="small">
1358                          <a href="<?php bp_group_member_promote_admin_link( array( 'user_id' => $mod->user_id ) ) ?>" class="button confirm mod-promote-to-admin" title="<?php esc_attr_e( 'Promote to Admin', 'buddypress' ); ?>"><?php _e( 'Promote to Admin', 'buddypress' ); ?></a>
1359                          <a class="button confirm mod-demote-to-member" href="<?php bp_group_member_demote_link($mod->user_id) ?>"><?php _e( 'Demote to Member', 'buddypress' ) ?></a>
1360                      </span>
1361                  </h5>
1362              </li>
1363  
1364              <?php } else { ?>
1365  
1366              <li>
1367  
1368                  <?php echo bp_core_fetch_avatar( array( 'item_id' => $mod->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $mod->user_id ) ) ) ) ?>
1369  
1370                  <h5><?php echo bp_core_get_userlink( $mod->user_id ) ?></h5>
1371  
1372                  <span class="activity"><?php echo bp_core_get_last_activity( strtotime( $mod->date_modified ), __( 'joined %s', 'buddypress') ); ?></span>
1373  
1374                  <?php if ( bp_is_active( 'friends' ) ) : ?>
1375  
1376                      <div class="action">
1377                          <?php bp_add_friend_button( $mod->user_id ) ?>
1378                      </div>
1379  
1380                  <?php endif; ?>
1381  
1382              </li>
1383  
1384              <?php } ?>
1385          <?php } ?>
1386  
1387          </ul>
1388  
1389      <?php } else { ?>
1390  
1391          <div id="message" class="info">
1392              <p><?php _e( 'This group has no moderators', 'buddypress' ); ?></p>
1393          </div>
1394  
1395      <?php }
1396  }
1397  
1398  function bp_group_has_moderators( $group = false ) {
1399      global $groups_template;
1400  
1401      if ( empty( $group ) )
1402          $group =& $groups_template->group;
1403  
1404      return apply_filters( 'bp_group_has_moderators', groups_get_group_mods( $group->id ) );
1405  }
1406  
1407  function bp_group_member_promote_mod_link( $args = '' ) {
1408      echo bp_get_group_member_promote_mod_link( $args );
1409  }
1410  	function bp_get_group_member_promote_mod_link( $args = '' ) {
1411          global $members_template, $groups_template;
1412  
1413          $defaults = array(
1414              'user_id' => $members_template->member->user_id,
1415              'group'   => &$groups_template->group
1416          );
1417  
1418          $r = wp_parse_args( $args, $defaults );
1419          extract( $r, EXTR_SKIP );
1420  
1421          return apply_filters( 'bp_get_group_member_promote_mod_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/mod/' . $user_id, 'groups_promote_member' ) );
1422      }
1423  
1424  function bp_group_member_promote_admin_link( $args = '' ) {
1425      echo bp_get_group_member_promote_admin_link( $args );
1426  }
1427  	function bp_get_group_member_promote_admin_link( $args = '' ) {
1428          global $members_template, $groups_template;
1429  
1430          $defaults = array(
1431              'user_id' => !empty( $members_template->member->user_id ) ? $members_template->member->user_id : false,
1432              'group'   => &$groups_template->group
1433          );
1434  
1435          $r = wp_parse_args( $args, $defaults );
1436          extract( $r, EXTR_SKIP );
1437  
1438          return apply_filters( 'bp_get_group_member_promote_admin_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/promote/admin/' . $user_id, 'groups_promote_member' ) );
1439      }
1440  
1441  function bp_group_member_demote_link( $user_id = 0 ) {
1442      global $members_template;
1443  
1444      if ( !$user_id )
1445          $user_id = $members_template->member->user_id;
1446  
1447      echo bp_get_group_member_demote_link( $user_id );
1448  }
1449  	function bp_get_group_member_demote_link( $user_id = 0, $group = false ) {
1450          global $members_template, $groups_template;
1451  
1452          if ( empty( $group ) )
1453              $group =& $groups_template->group;
1454  
1455          if ( !$user_id )
1456              $user_id = $members_template->member->user_id;
1457  
1458          return apply_filters( 'bp_get_group_member_demote_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/demote/' . $user_id, 'groups_demote_member' ) );
1459      }
1460  
1461  function bp_group_member_ban_link( $user_id = 0 ) {
1462      global $members_template;
1463  
1464      if ( !$user_id )
1465          $user_id = $members_template->member->user_id;
1466  
1467      echo bp_get_group_member_ban_link( $user_id );
1468  }
1469  	function bp_get_group_member_ban_link( $user_id = 0, $group = false ) {
1470          global $groups_template;
1471  
1472          if ( empty( $group ) )
1473              $group =& $groups_template->group;
1474  
1475          return apply_filters( 'bp_get_group_member_ban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/ban/' . $user_id, 'groups_ban_member' ) );
1476      }
1477  
1478  function bp_group_member_unban_link( $user_id = 0 ) {
1479      global $members_template;
1480  
1481      if ( !$user_id )
1482          $user_id = $members_template->member->user_id;
1483  
1484      echo bp_get_group_member_unban_link( $user_id );
1485  }
1486  	function bp_get_group_member_unban_link( $user_id = 0, $group = false ) {
1487          global $members_template, $groups_template;
1488  
1489          if ( !$user_id )
1490              $user_id = $members_template->member->user_id;
1491  
1492          if ( empty( $group ) )
1493              $group =& $groups_template->group;
1494  
1495          return apply_filters( 'bp_get_group_member_unban_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/unban/' . $user_id, 'groups_unban_member' ) );
1496      }
1497  
1498  
1499  function bp_group_member_remove_link( $user_id = 0 ) {
1500      global $members_template;
1501  
1502      if ( !$user_id )
1503          $user_id = $members_template->member->user_id;
1504  
1505      echo bp_get_group_member_remove_link( $user_id );
1506  }
1507  	function bp_get_group_member_remove_link( $user_id = 0, $group = false ) {
1508          global $groups_template;
1509  
1510          if ( empty( $group ) )
1511              $group =& $groups_template->group;
1512  
1513          return apply_filters( 'bp_get_group_member_remove_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'admin/manage-members/remove/' . $user_id, 'groups_remove_member' ) );
1514      }
1515  
1516  function bp_group_admin_tabs( $group = false ) {
1517      global $bp, $groups_template;
1518  
1519      if ( empty( $group ) )
1520          $group = ( $groups_template->group ) ? $groups_template->group : $bp->groups->current_group;
1521  
1522      $current_tab = bp_get_group_current_admin_tab();
1523  
1524      if ( bp_is_item_admin() ) : ?>
1525  
1526          <li<?php if ( 'edit-details' == $current_tab || empty( $current_tab ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/edit-details' ) ?>"><?php _e( 'Details', 'buddypress' ); ?></a></li>
1527  
1528      <?php endif; ?>
1529  
1530      <?php if ( ! bp_is_item_admin() )
1531              return false; ?>
1532  
1533      <li<?php if ( 'group-settings' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/group-settings' ) ?>"><?php _e( 'Settings', 'buddypress' ); ?></a></li>
1534  
1535      <?php if ( !(int)bp_get_option( 'bp-disable-avatar-uploads' ) ) : ?>
1536  
1537          <li<?php if ( 'group-avatar'   == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/group-avatar' ) ?>"><?php _e( 'Avatar', 'buddypress' ); ?></a></li>
1538  
1539      <?php endif; ?>
1540  
1541      <li<?php if ( 'manage-members' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/manage-members' ) ?>"><?php _e( 'Members', 'buddypress' ); ?></a></li>
1542  
1543      <?php if ( $groups_template->group->status == 'private' ) : ?>
1544  
1545          <li<?php if ( 'membership-requests' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/membership-requests' ) ?>"><?php _e( 'Requests', 'buddypress' ); ?></a></li>
1546  
1547      <?php endif; ?>
1548  
1549      <?php do_action( 'groups_admin_tabs', $current_tab, $group->slug ) ?>
1550  
1551      <li<?php if ( 'delete-group' == $current_tab ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_get_group_permalink( $group ) . 'admin/delete-group' ) ?>"><?php _e( 'Delete', 'buddypress' ); ?></a></li>
1552  
1553  <?php
1554  }
1555  
1556  function bp_group_total_for_member() {
1557      echo bp_get_group_total_for_member();
1558  }
1559  	function bp_get_group_total_for_member() {
1560          return apply_filters( 'bp_get_group_total_for_member', BP_Groups_Member::total_group_count() );
1561      }
1562  
1563  function bp_group_form_action( $page ) {
1564      echo bp_get_group_form_action( $page );
1565  }
1566  	function bp_get_group_form_action( $page, $group = false ) {
1567          global $groups_template;
1568  
1569          if ( empty( $group ) )
1570              $group =& $groups_template->group;
1571  
1572          return apply_filters( 'bp_group_form_action', bp_get_group_permalink( $group ) . $page );
1573      }
1574  
1575  function bp_group_admin_form_action( $page = false ) {
1576      echo bp_get_group_admin_form_action( $page );
1577  }
1578  	function bp_get_group_admin_form_action( $page = false, $group = false ) {
1579          global $groups_template;
1580  
1581          if ( empty( $group ) )
1582              $group =& $groups_template->group;
1583  
1584          if ( empty( $page ) )
1585              $page = bp_action_variable( 0 );
1586  
1587          return apply_filters( 'bp_group_admin_form_action', bp_get_group_permalink( $group ) . 'admin/' . $page );
1588      }
1589  
1590  function bp_group_has_requested_membership( $group = false ) {
1591      global $groups_template;
1592  
1593      if ( empty( $group ) )
1594          $group =& $groups_template->group;
1595  
1596      if ( groups_check_for_membership_request( bp_loggedin_user_id(), $group->id ) )
1597          return true;
1598  
1599      return false;
1600  }
1601  
1602  /**
1603   * bp_group_is_member()
1604   *
1605   * Checks if current user is member of a group.
1606   *
1607   * @uses bp_current_user_can() Check if current user is super admin
1608   * @uses apply_filters Creates bp_group_is_member filter and passes $is_member
1609   * @usedby groups/activity.php, groups/single/forum/edit.php, groups/single/forum/topic.php to determine template part visibility
1610   * @global object $groups_template Current Group (usually in template loop)
1611   * @param object $group Group to check is_member
1612   * @return bool If user is member of group or not
1613   */
1614  function bp_group_is_member( $group = false ) {
1615      global $groups_template;
1616  
1617      // Site admins always have access
1618      if ( bp_current_user_can( 'bp_moderate' ) )
1619          return true;
1620  
1621      if ( empty( $group ) )
1622          $group =& $groups_template->group;
1623  
1624      return apply_filters( 'bp_group_is_member', !empty( $group->is_member ) );
1625  }
1626  
1627  /**
1628   * Checks if a user is banned from a group.
1629   *
1630   * If this function is invoked inside the groups template loop (e.g. the group directory), then
1631   * check $groups_template->group->is_banned instead of making another SQL query.
1632   * However, if used in a single group's pages, we must use groups_is_user_banned().
1633   *
1634   * @global BP_Groups_Template $groups_template Group template loop object
1635   * @param object $group Group to check if user is banned from the group
1636   * @param int $user_id
1637   * @return bool If user is banned from the group or not
1638   * @since BuddyPress (1.5)
1639   */
1640  function bp_group_is_user_banned( $group = false, $user_id = 0 ) {
1641      global $groups_template;
1642  
1643      // Site admins always have access
1644      if ( bp_current_user_can( 'bp_moderate' ) )
1645          return false;
1646  
1647      if ( empty( $group ) ) {
1648          $group =& $groups_template->group;
1649  
1650          if ( !$user_id && isset( $group->is_banned ) )
1651              return apply_filters( 'bp_group_is_user_banned', $group->is_banned );
1652      }
1653  
1654      if ( !$user_id )
1655          $user_id = bp_loggedin_user_id();
1656  
1657      return apply_filters( 'bp_group_is_user_banned', groups_is_user_banned( $user_id, $group->id ) );
1658  }
1659  
1660  function bp_group_accept_invite_link() {
1661      echo bp_get_group_accept_invite_link();
1662  }
1663  	function bp_get_group_accept_invite_link( $group = false ) {
1664          global $groups_template, $bp;
1665  
1666          if ( empty( $group ) )
1667              $group =& $groups_template->group;
1668  
1669          return apply_filters( 'bp_get_group_accept_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/accept/' . $group->id ), 'groups_accept_invite' ) );
1670      }
1671  
1672  function bp_group_reject_invite_link() {
1673      echo bp_get_group_reject_invite_link();
1674  }
1675  	function bp_get_group_reject_invite_link( $group = false ) {
1676          global $groups_template, $bp;
1677  
1678          if ( empty( $group ) )
1679              $group =& $groups_template->group;
1680  
1681          return apply_filters( 'bp_get_group_reject_invite_link', wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/invites/reject/' . $group->id ), 'groups_reject_invite' ) );
1682      }
1683  
1684  function bp_group_leave_confirm_link() {
1685      echo bp_get_group_leave_confirm_link();
1686  }
1687  	function bp_get_group_leave_confirm_link( $group = false ) {
1688          global $groups_template;
1689  
1690          if ( empty( $group ) )
1691              $group =& $groups_template->group;
1692  
1693          return apply_filters( 'bp_group_leave_confirm_link', wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group/yes', 'groups_leave_group' ) );
1694      }
1695  
1696  function bp_group_leave_reject_link() {
1697      echo bp_get_group_leave_reject_link();
1698  }
1699  	function bp_get_group_leave_reject_link( $group = false ) {
1700          global $groups_template;
1701  
1702          if ( empty( $group ) )
1703              $group =& $groups_template->group;
1704  
1705          return apply_filters( 'bp_get_group_leave_reject_link', bp_get_group_permalink( $group ) );
1706      }
1707  
1708  function bp_group_send_invite_form_action() {
1709      echo bp_get_group_send_invite_form_action();
1710  }
1711  	function bp_get_group_send_invite_form_action( $group = false ) {
1712          global $groups_template;
1713  
1714          if ( empty( $group ) )
1715              $group =& $groups_template->group;
1716  
1717          return apply_filters( 'bp_group_send_invite_form_action', bp_get_group_permalink( $group ) . 'send-invites/send' );
1718      }
1719  
1720  function bp_has_friends_to_invite( $group = false ) {
1721      global $groups_template;
1722  
1723      if ( !bp_is_active( 'friends' ) )
1724          return false;
1725  
1726      if ( empty( $group ) )
1727          $group =& $groups_template->group;
1728  
1729      if ( !friends_check_user_has_friends( bp_loggedin_user_id() ) || !friends_count_invitable_friends( bp_loggedin_user_id(), $group->id ) )
1730          return false;
1731  
1732      return true;
1733  }
1734  
1735  /**
1736   * Outputs a 'New Topic' button for a group.
1737   *
1738   * @since BuddyPress (1.2.7)
1739   *
1740   * @param BP_Groups_Group|bool $group The BP Groups_Group object if passed, boolean false if not passed.
1741   * @uses bp_get_group_new_topic_button() Returns the 'New Topic' button
1742   */
1743  function bp_group_new_topic_button( $group = false ) {
1744      echo bp_get_group_new_topic_button( $group );
1745  }
1746      /**
1747       * Returns a 'New Topic' button for a group.
1748       *
1749       * @since BuddyPress (1.2.7)
1750       *
1751       * @param BP_Groups_Group|bool $group The BP Groups_Group object if passed, boolean false if not passed.
1752       * @uses is_user_logged_in() Is there a user logged in?
1753       * @uses bp_group_is_user_banned() Is the current user banned from the current group?
1754       * @uses bp_is_group_forum() Are we on a group forum page?
1755       * @uses bp_is_group_forum_topic() Are we on a group topic page?
1756       * @uses bp_get_button() Renders a button
1757       * @return string HTML code for the button
1758       */
1759  	function bp_get_group_new_topic_button( $group = false ) {
1760          global $groups_template;
1761  
1762          if ( empty( $group ) )
1763              $group =& $groups_template->group;
1764  
1765          if ( !is_user_logged_in() || bp_group_is_user_banned() || !bp_is_group_forum() || bp_is_group_forum_topic() )
1766              return false;
1767  
1768          $button = array(
1769              'id'                => 'new_topic',
1770              'component'         => 'groups',
1771              'must_be_logged_in' => true,
1772              'block_self'        => true,
1773              'wrapper_class'     => 'group-button',
1774              'link_href'         => '#post-new',
1775              'link_class'        => 'group-button show-hide-new',
1776              'link_id'           => 'new-topic-button',
1777              'link_text'         => __( 'New Topic', 'buddypress' ),
1778              'link_title'        => __( 'New Topic', 'buddypress' ),
1779          );
1780  
1781          // Filter and return the HTML button
1782          return bp_get_button( apply_filters( 'bp_get_group_new_topic_button', $button ) );
1783      }
1784  
1785  function bp_group_join_button( $group = false ) {
1786      echo bp_get_group_join_button( $group );
1787  }
1788  	function bp_get_group_join_button( $group = false ) {
1789          global $groups_template;
1790  
1791          if ( empty( $group ) )
1792              $group =& $groups_template->group;
1793  
1794          if ( !is_user_logged_in() || bp_group_is_user_banned( $group ) )
1795              return false;
1796  
1797          // Group creation was not completed or status is unknown
1798          if ( !$group->status )
1799              return false;
1800  
1801          // Already a member
1802          if ( isset( $group->is_member ) && $group->is_member ) {
1803  
1804              // Stop sole admins from abandoning their group
1805               $group_admins = groups_get_group_admins( $group->id );
1806               if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() )
1807                  return false;
1808  
1809              $button = array(
1810                  'id'                => 'leave_group',
1811                  'component'         => 'groups',
1812                  'must_be_logged_in' => true,
1813                  'block_self'        => false,
1814                  'wrapper_class'     => 'group-button ' . $group->status,
1815                  'wrapper_id'        => 'groupbutton-' . $group->id,
1816                  'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
1817                  'link_text'         => __( 'Leave Group', 'buddypress' ),
1818                  'link_title'        => __( 'Leave Group', 'buddypress' ),
1819                  'link_class'        => 'group-button leave-group',
1820              );
1821  
1822          // Not a member
1823          } else {
1824  
1825              // Show different buttons based on group status
1826              switch ( $group->status ) {
1827                  case 'hidden' :
1828                      return false;
1829                      break;
1830  
1831                  case 'public':
1832                      $button = array(
1833                          'id'                => 'join_group',
1834                          'component'         => 'groups',
1835                          'must_be_logged_in' => true,
1836                          'block_self'        => false,
1837                          'wrapper_class'     => 'group-button ' . $group->status,
1838                          'wrapper_id'        => 'groupbutton-' . $group->id,
1839                          'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),
1840                          'link_text'         => __( 'Join Group', 'buddypress' ),
1841                          'link_title'        => __( 'Join Group', 'buddypress' ),
1842                          'link_class'        => 'group-button join-group',
1843                      );
1844                      break;
1845  
1846                  case 'private' :
1847  
1848                      // Member has outstanding invitation -
1849                      // show an "Accept Invitation" button
1850                      if ( $group->is_invited ) {
1851                          $button = array(
1852                              'id'                => 'accept_invite',
1853                              'component'         => 'groups',
1854                              'must_be_logged_in' => true,
1855                              'block_self'        => false,
1856                              'wrapper_class'     => 'group-button ' . $group->status,
1857                              'wrapper_id'        => 'groupbutton-' . $group->id,
1858                              'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
1859                              'link_text'         => __( 'Accept Invitation', 'buddypress' ),
1860                              'link_title'        => __( 'Accept Invitation', 'buddypress' ),
1861                              'link_class'        => 'group-button accept-invite',
1862                          );
1863  
1864                      // Member has requested membership but request is pending -
1865                      // show a "Request Sent" button
1866                      } elseif ( $group->is_pending ) {
1867                          $button = array(
1868                              'id'                => 'membership_requested',
1869                              'component'         => 'groups',
1870                              'must_be_logged_in' => true,
1871                              'block_self'        => false,
1872                              'wrapper_class'     => 'group-button pending ' . $group->status,
1873                              'wrapper_id'        => 'groupbutton-' . $group->id,
1874                              'link_href'         => bp_get_group_permalink( $group ),
1875                              'link_text'         => __( 'Request Sent', 'buddypress' ),
1876                              'link_title'        => __( 'Request Sent', 'buddypress' ),
1877                              'link_class'        => 'group-button pending membership-requested',
1878                          );
1879  
1880                      // Member has not requested membership yet -
1881                      // show a "Request Membership" button
1882                      } else {
1883                          $button = array(
1884                              'id'                => 'request_membership',
1885                              'component'         => 'groups',
1886                              'must_be_logged_in' => true,
1887                              'block_self'        => false,
1888                              'wrapper_class'     => 'group-button ' . $group->status,
1889                              'wrapper_id'        => 'groupbutton-' . $group->id,
1890                              'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),
1891                              'link_text'         => __( 'Request Membership', 'buddypress' ),
1892                              'link_title'        => __( 'Request Membership', 'buddypress' ),
1893                              'link_class'        => 'group-button request-membership',
1894                          );
1895                      }
1896  
1897                      break;
1898              }
1899          }
1900  
1901          // Filter and return the HTML button
1902          return bp_get_button( apply_filters( 'bp_get_group_join_button', $button ) );
1903      }
1904  
1905  /**
1906   * Output the Create a Group button.
1907   *
1908   * @since BuddyPress (2.0.0)
1909   */
1910  function bp_group_create_button() {
1911      echo bp_get_group_create_button();
1912  }
1913      /**
1914       * Get the Create a Group button.
1915       *
1916       * @since BuddyPress (2.0.0)
1917       *
1918       * @return string
1919       */
1920  	function bp_get_group_create_button() {
1921          if ( ! is_user_logged_in() ) {
1922              return false;
1923          }
1924  
1925          if ( ! bp_user_can_create_groups() ) {
1926              return false;
1927          }
1928  
1929          $button_args = array(
1930              'id'         => 'create_group',
1931              'component'  => 'groups',
1932              'link_text'  => __( 'Create a Group', 'buddypress' ),
1933              'link_title' => __( 'Create a Group', 'buddypress' ),
1934              'link_class' => 'button group-create bp-title-button',
1935              'link_href'  => trailingslashit( bp_get_root_domain() ) . trailingslashit( bp_get_groups_root_slug() ) . trailingslashit( 'create' ),
1936              'wrapper'    => false,
1937          );
1938  
1939          return bp_get_button( apply_filters( 'bp_get_group_create_button', $button_args ) );
1940      }
1941  
1942  /**
1943   * Prints a message if the group is not visible to the current user (it is a
1944   * hidden or private group, and the user does not have access).
1945   *
1946   * @global BP_Groups_Template $groups_template Groups template object
1947   * @param object $group Group to get status message for. Optional; defaults to current group.
1948   * @since BuddyPress (1.0)
1949   */
1950  function bp_group_status_message( $group = null ) {
1951      global $groups_template;
1952  
1953      if ( ! $group )
1954          $group =& $groups_template->group;
1955  
1956      if ( 'private' == $group->status ) {
1957           if ( ! bp_group_has_requested_membership() ) {
1958              if ( is_user_logged_in() )
1959                  $message = __( 'This is a private group and you must request group membership in order to join.', 'buddypress' );
1960              else
1961                  $message = __( 'This is a private group. To join you must be a registered site member and request group membership.', 'buddypress' );
1962  
1963          } else {
1964              $message = __( 'This is a private group. Your membership request is awaiting approval from the group administrator.', 'buddypress' );
1965          }
1966  
1967      } else {
1968          $message = __( 'This is a hidden group and only invited members can join.', 'buddypress' );
1969      }
1970  
1971      echo apply_filters( 'bp_group_status_message', $message, $group );
1972  }
1973  
1974  function bp_group_hidden_fields() {
1975      if ( isset( $_REQUEST['s'] ) ) {
1976          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['s'] ) . '" name="search_terms" />';
1977      }
1978  
1979      if ( isset( $_REQUEST['letter'] ) ) {
1980          echo '<input type="hidden" id="selected_letter" value="' . esc_attr( $_REQUEST['letter'] ) . '" name="selected_letter" />';
1981      }
1982  
1983      if ( isset( $_REQUEST['groups_search'] ) ) {
1984          echo '<input type="hidden" id="search_terms" value="' . esc_attr( $_REQUEST['groups_search'] ) . '" name="search_terms" />';
1985      }
1986  }
1987  
1988  function bp_total_group_count() {
1989      echo bp_get_total_group_count();
1990  }
1991  	function bp_get_total_group_count() {
1992          return apply_filters( 'bp_get_total_group_count', groups_get_total_group_count() );
1993      }
1994  
1995  function bp_total_group_count_for_user( $user_id = 0 ) {
1996      echo bp_get_total_group_count_for_user( $user_id );
1997  }
1998  	function bp_get_total_group_count_for_user( $user_id = 0 ) {
1999          return apply_filters( 'bp_get_total_group_count_for_user', groups_total_groups_for_user( $user_id ), $user_id );
2000      }
2001      add_filter( 'bp_get_total_group_count_for_user', 'bp_core_number_format' );
2002  
2003  
2004  /***************************************************************************
2005   * Group Members Template Tags
2006   **/
2007  
2008  class BP_Groups_Group_Members_Template {
2009      var $current_member = -1;
2010      var $member_count;
2011      var $members;
2012      var $member;
2013  
2014      var $in_the_loop;
2015  
2016      var $pag_page;
2017      var $pag_num;
2018      var $pag_links;
2019      var $total_group_count;
2020  
2021      /**
2022       * Constructor.
2023       *
2024       * @param array $args {
2025       *     An array of optional arguments.
2026       *     @type int $group_id ID of the group whose members are being
2027       *         queried. Default: current group ID.
2028       *     @type int $page Page of results to be queried. Default: 1.
2029       *     @type int $per_page Number of items to return per page of
2030       *           results. Default: 20.
2031       *     @type int $max Optional. Max number of items to return.
2032       *     @type array $exclude Optional. Array of user IDs to exclude.
2033       *     @type bool|int True (or 1) to exclude admins and mods from
2034       *           results. Default: 1.
2035       *     @type bool|int True (or 1) to exclude banned users from results.
2036       *           Default: 1.
2037       *     @type array $group_role Optional. Array of group roles to include.
2038       *     @type string $search_terms Optional. Search terms to match.
2039       * }
2040       */
2041  	function __construct( $args = array() ) {
2042  
2043          // Backward compatibility with old method of passing arguments
2044          if ( ! is_array( $args ) || func_num_args() > 1 ) {
2045              _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__ ) );
2046  
2047              $old_args_keys = array(
2048                  0 => 'group_id',
2049                  1 => 'per_page',
2050                  2 => 'max',
2051                  3 => 'exclude_admins_mods',
2052                  4 => 'exclude_banned',
2053                  5 => 'exclude',
2054                  6 => 'group_role',
2055              );
2056  
2057              $func_args = func_get_args();
2058              $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
2059          }
2060  
2061          $r = wp_parse_args( $args, array(
2062              'group_id'            => bp_get_current_group_id(),
2063              'page'                => 1,
2064              'per_page'            => 20,
2065              'max'                 => false,
2066              'exclude'             => false,
2067              'exclude_admins_mods' => 1,
2068              'exclude_banned'      => 1,
2069              'group_role'          => false,
2070              'search_terms'        => false,
2071              'type'                => 'last_joined',
2072          ) );
2073  
2074          // @todo No
2075          extract( $r );
2076  
2077          $this->pag_page = isset( $_REQUEST['mlpage'] ) ? intval( $_REQUEST['mlpage'] ) : $r['page'];
2078          $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $per_page;
2079  
2080          /**
2081           * Check the current group is the same as the supplied group ID.
2082           * It can differ when using {@link bp_group_has_members()} outside the Groups screens.
2083           */
2084          $current_group = groups_get_current_group();
2085          if ( ! $current_group || $current_group && $current_group->id !== bp_get_current_group_id() ) {
2086              $current_group = groups_get_group( array( 'group_id' => $r['group_id'] ) );
2087          }
2088  
2089          // Assemble the base URL for pagination
2090          $base_url = trailingslashit( bp_get_group_permalink( $current_group ) . bp_current_action() );
2091          if ( bp_action_variable() ) {
2092              $base_url = trailingslashit( $base_url . bp_action_variable() );
2093          }
2094  
2095          $members_args = $r;
2096  
2097          $members_args['page']     = $this->pag_page;
2098          $members_args['per_page'] = $this->pag_num;
2099  
2100          $this->members = groups_get_group_members( $members_args );
2101  
2102          if ( !$max || $max >= (int) $this->members['count'] )
2103              $this->total_member_count = (int) $this->members['count'];
2104          else
2105              $this->total_member_count = (int) $max;
2106  
2107          $this->members = $this->members['members'];
2108  
2109          if ( $max ) {
2110              if ( $max >= count($this->members) )
2111                  $this->member_count = count($this->members);
2112              else
2113                  $this->member_count = (int) $max;
2114          } else {
2115              $this->member_count = count($this->members);
2116          }
2117  
2118          $this->pag_links = paginate_links( array(
2119              'base' => add_query_arg( array( 'mlpage' => '%#%' ), $base_url ),
2120              'format' => '',
2121              'total' => !empty( $this->pag_num ) ? ceil( $this->total_member_count / $this->pag_num ) : $this->total_member_count,
2122              'current' => $this->pag_page,
2123              'prev_text' => '&larr;',
2124              'next_text' => '&rarr;',
2125              'mid_size' => 1
2126          ));
2127      }
2128  
2129  	function has_members() {
2130          if ( $this->member_count )
2131              return true;
2132  
2133          return false;
2134      }
2135  
2136  	function next_member() {
2137          $this->current_member++;
2138          $this->member = $this->members[$this->current_member];
2139  
2140          return $this->member;
2141      }
2142  
2143  	function rewind_members() {
2144          $this->current_member = -1;
2145          if ( $this->member_count > 0 ) {
2146              $this->member = $this->members[0];
2147          }
2148      }
2149  
2150  	function members() {
2151          if ( $this->current_member + 1 < $this->member_count ) {
2152              return true;
2153          } elseif ( $this->current_member + 1 == $this->member_count ) {
2154              do_action('loop_end');
2155              // Do some cleaning up after the loop
2156              $this->rewind_members();
2157          }
2158  
2159          $this->in_the_loop = false;
2160          return false;
2161      }
2162  
2163  	function the_member() {
2164  
2165          $this->in_the_loop = true;
2166          $this->member      = $this->next_member();
2167  
2168          if ( 0 == $this->current_member ) // loop has just started
2169              do_action('loop_start');
2170      }
2171  }
2172  
2173  /**
2174   * Initialize a group member query loop.
2175   *
2176   * @param array $args {
2177   *     An array of optional arguments.
2178   *     @type int $group_id ID of the group whose members are being queried.
2179   *           Default: current group ID.
2180   *     @type int $page Page of results to be queried. Default: 1.
2181   *     @type int $per_page Number of items to return per page of results.
2182   *           Default: 20.
2183   *     @type int $max Optional. Max number of items to return.
2184   *     @type array $exclude Optional. Array of user IDs to exclude.
2185   *     @type bool|int True (or 1) to exclude admins and mods from results.
2186   *           Default: 1.
2187   *     @type bool|int True (or 1) to exclude banned users from results.
2188   *           Default: 1.
2189   *     @type array $group_role Optional. Array of group roles to include.
2190   *     @type string $type Optional. Sort order of results. 'last_joined',
2191   *           'first_joined', or any of the $type params available in
2192   *           {@link BP_User_Query}. Default: 'last_joined'.
2193   *     @type string $search_terms Optional. Search terms to match.
2194   * }
2195   */
2196  function bp_group_has_members( $args = '' ) {
2197      global $members_template;
2198  
2199      $exclude_admins_mods = 1;
2200  
2201      if ( bp_is_group_members() ) {
2202          $exclude_admins_mods = 0;
2203      }
2204  
2205      $r = wp_parse_args( $args, array(
2206          'group_id'            => bp_get_current_group_id(),
2207          'page'                => 1,
2208          'per_page'            => 20,
2209          'max'                 => false,
2210          'exclude'             => false,
2211          'exclude_admins_mods' => $exclude_admins_mods,
2212          'exclude_banned'      => 1,
2213          'group_role'          => false,
2214          'search_terms'        => false,
2215          'type'                => 'last_joined',
2216      ) );
2217  
2218      if ( empty( $r['search_terms'] ) && ! empty( $_REQUEST['s'] ) )
2219          $r['search_terms'] = $_REQUEST['s'];
2220  
2221      $members_template = new BP_Groups_Group_Members_Template( $r );
2222      return apply_filters( 'bp_group_has_members', $members_template->has_members(), $members_template );
2223  }
2224  
2225  function bp_group_members() {
2226      global $members_template;
2227  
2228      return $members_template->members();
2229  }
2230  
2231  function bp_group_the_member() {
2232      global $members_template;
2233  
2234      return $members_template->the_member();
2235  }
2236  
2237  function bp_group_member_avatar() {
2238      echo bp_get_group_member_avatar();
2239  }
2240  	function bp_get_group_member_avatar() {
2241          global $members_template;
2242  
2243          return apply_filters( 'bp_get_group_member_avatar', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'full', 'email' => $members_template->member->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ) ) ) );
2244      }
2245  
2246  function bp_group_member_avatar_thumb() {
2247      echo bp_get_group_member_avatar_thumb();
2248  }
2249  	function bp_get_group_member_avatar_thumb() {
2250          global $members_template;
2251  
2252          return apply_filters( 'bp_get_group_member_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'email' => $members_template->member->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ) ) ) );
2253      }
2254  
2255  function bp_group_member_avatar_mini( $width = 30, $height = 30 ) {
2256      echo bp_get_group_member_avatar_mini( $width, $height );
2257  }
2258  	function bp_get_group_member_avatar_mini( $width = 30, $height = 30 ) {
2259          global $members_template;
2260  
2261          return apply_filters( 'bp_get_group_member_avatar_mini', bp_core_fetch_avatar( array( 'item_id' => $members_template->member->user_id, 'type' => 'thumb', 'width' => $width, 'height' => $height, 'email' => $members_template->member->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), $members_template->member->display_name ) ) ) );
2262      }
2263  
2264  function bp_group_member_name() {
2265      echo bp_get_group_member_name();
2266  }
2267  	function bp_get_group_member_name() {
2268          global $members_template;
2269  
2270          return apply_filters( 'bp_get_group_member_name', $members_template->member->display_name );
2271      }
2272  
2273  function bp_group_member_url() {
2274      echo bp_get_group_member_url();
2275  }
2276  	function bp_get_group_member_url() {
2277          global $members_template;
2278  
2279          return apply_filters( 'bp_get_group_member_url', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) );
2280      }
2281  
2282  function bp_group_member_link() {
2283      echo bp_get_group_member_link();
2284  }
2285  	function bp_get_group_member_link() {
2286          global $members_template;
2287  
2288          return apply_filters( 'bp_get_group_member_link', '<a href="' . bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) . '">' . $members_template->member->display_name . '</a>' );
2289      }
2290  
2291  function bp_group_member_domain() {
2292      echo bp_get_group_member_domain();
2293  }
2294  	function bp_get_group_member_domain() {
2295          global $members_template;
2296  
2297          return apply_filters( 'bp_get_group_member_domain', bp_core_get_user_domain( $members_template->member->user_id, $members_template->member->user_nicename, $members_template->member->user_login ) );
2298      }
2299  
2300  function bp_group_member_is_friend() {
2301      echo bp_get_group_member_is_friend();
2302  }
2303  	function bp_get_group_member_is_friend() {
2304          global $members_template;
2305  
2306          if ( !isset( $members_template->member->is_friend ) )
2307              $friend_status = 'not_friends';
2308          else
2309              $friend_status = ( 0 == $members_template->member->is_friend ) ? 'pending' : 'is_friend';
2310  
2311          return apply_filters( 'bp_get_group_member_is_friend', $friend_status );
2312      }
2313  
2314  function bp_group_member_is_banned() {
2315      echo bp_get_group_member_is_banned();
2316  }
2317  	function bp_get_group_member_is_banned() {
2318          global $members_template;
2319  
2320          return apply_filters( 'bp_get_group_member_is_banned', $members_template->member->is_banned );
2321      }
2322  
2323  function bp_group_member_css_class() {
2324      global $members_template;
2325  
2326      if ( $members_template->member->is_banned )
2327          echo apply_filters( 'bp_group_member_css_class', 'banned-user' );
2328  }
2329  
2330  function bp_group_member_joined_since() {
2331      echo bp_get_group_member_joined_since();
2332  }
2333  	function bp_get_group_member_joined_since() {
2334          global $members_template;
2335  
2336          return apply_filters( 'bp_get_group_member_joined_since', bp_core_get_last_activity( $members_template->member->date_modified, __( 'joined %s', 'buddypress') ) );
2337      }
2338  
2339  function bp_group_member_id() {
2340      echo bp_get_group_member_id();
2341  }
2342  	function bp_get_group_member_id() {
2343          global $members_template;
2344  
2345          return apply_filters( 'bp_get_group_member_id', $members_template->member->user_id );
2346      }
2347  
2348  function bp_group_member_needs_pagination() {
2349      global $members_template;
2350  
2351      if ( $members_template->total_member_count > $members_template->pag_num )
2352          return true;
2353  
2354      return false;
2355  }
2356  
2357  function bp_group_pag_id() {
2358      echo bp_get_group_pag_id();
2359  }
2360  	function bp_get_group_pag_id() {
2361          return apply_filters( 'bp_get_group_pag_id', 'pag' );
2362      }
2363  
2364  function bp_group_member_pagination() {
2365      echo bp_get_group_member_pagination();
2366      wp_nonce_field( 'bp_groups_member_list', '_member_pag_nonce' );
2367  }
2368  	function bp_get_group_member_pagination() {
2369          global $members_template;
2370          return apply_filters( 'bp_get_group_member_pagination', $members_template->pag_links );
2371      }
2372  
2373  function bp_group_member_pagination_count() {
2374      echo bp_get_group_member_pagination_count();
2375  }
2376  	function bp_get_group_member_pagination_count() {
2377          global $members_template;
2378  
2379          $start_num = intval( ( $members_template->pag_page - 1 ) * $members_template->pag_num ) + 1;
2380          $from_num = bp_core_number_format( $start_num );
2381          $to_num = bp_core_number_format( ( $start_num + ( $members_template->pag_num - 1 ) > $members_template->total_member_count ) ? $members_template->total_member_count : $start_num + ( $members_template->pag_num - 1 ) );
2382          $total = bp_core_number_format( $members_template->total_member_count );
2383  
2384          return apply_filters( 'bp_get_group_member_pagination_count', sprintf( _n( 'Viewing member %1$s to %2$s (of %3$s member)', 'Viewing members %1$s to %2$s (of %3$s members)', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total );
2385      }
2386  
2387  function bp_group_member_admin_pagination() {
2388      echo bp_get_group_member_admin_pagination();
2389      wp_nonce_field( 'bp_groups_member_admin_list', '_member_admin_pag_nonce' );
2390  }
2391  	function bp_get_group_member_admin_pagination() {
2392          global $members_template;
2393  
2394          return $members_template->pag_links;
2395      }
2396  
2397  /**
2398   * Output the Group members template
2399   *
2400   * @since BuddyPress (?)
2401   *
2402   * @return string html output
2403   */
2404  function bp_groups_members_template_part() {
2405      ?>
2406      <div class="item-list-tabs" id="subnav" role="navigation">
2407          <ul>
2408              <li class="groups-members-search" role="search">
2409                  <?php bp_directory_members_search_form(); ?>
2410              </li>
2411  
2412              <?php bp_groups_members_filter(); ?>
2413              <?php do_action( 'bp_members_directory_member_sub_types' ); ?>
2414  
2415          </ul>
2416      </div>
2417  
2418      <div id="members-group-list" class="group_members dir-list">
2419  
2420          <?php bp_get_template_part( 'groups/single/members' ); ?>
2421  
2422      </div>
2423      <?php
2424  }
2425  
2426  /**
2427   * Output the Group members filters
2428   *
2429   * @since BuddyPress (?)
2430   *
2431   * @return string html output
2432   */
2433  function bp_groups_members_filter() {
2434      ?>
2435      <li id="group_members-order-select" class="last filter">
2436          <label for="group_members-order-by"><?php _e( 'Order By:', 'buddypress' ); ?></label>
2437          <select id="group_members-order-by">
2438              <option value="last_joined"><?php _e( 'Newest', 'buddypress' ); ?></option>
2439              <option value="first_joined"><?php _e( 'Oldest', 'buddypress' ); ?></option>
2440              <option value="alphabetical"><?php _e( 'Alphabetical', 'buddypress' ); ?></option>
2441  
2442              <?php do_action( 'bp_groups_members_order_options' ); ?>
2443  
2444          </select>
2445      </li>
2446      <?php
2447  }
2448  
2449  /***************************************************************************
2450   * Group Creation Process Template Tags
2451   **/
2452  
2453  /**
2454   * Determine if the current logged in user can create groups.
2455   *
2456   * @package BuddyPress Groups
2457   * @since BuddyPress (1.5)
2458   *
2459   * @uses apply_filters() To call 'bp_user_can_create_groups'.
2460   * @uses bp_get_option() To retrieve value of 'bp_restrict_group_creation'. Defaults to 0.
2461   * @uses bp_current_user_can() To determine if current user if super admin.
2462   *
2463   * @return bool True if user can create groups. False otherwise.
2464   */
2465  function bp_user_can_create_groups() {
2466      // Super admin can always create groups
2467      if ( bp_current_user_can( 'bp_moderate' ) )
2468          return true;
2469  
2470      // Get group creation option, default to 0 (allowed)
2471      $restricted = (int) bp_get_option( 'bp_restrict_group_creation', 0 );
2472  
2473      // Allow by default
2474      $can_create = true;
2475  
2476      // Are regular users restricted?
2477      if ( $restricted )
2478          $can_create = false;
2479  
2480      return apply_filters( 'bp_user_can_create_groups', $can_create, $restricted );
2481  }
2482  
2483  function bp_group_creation_tabs() {
2484      global $bp;
2485  
2486      if ( !is_array( $bp->groups->group_creation_steps ) )
2487          return false;
2488  
2489      if ( !bp_get_groups_current_create_step() ) {
2490          $keys = array_keys( $bp->groups->group_creation_steps );
2491          $bp->groups->current_create_step = array_shift( $keys );
2492      }
2493  
2494      $counter = 1;
2495  
2496      foreach ( (array) $bp->groups->group_creation_steps as $slug => $step ) {
2497          $is_enabled = bp_are_previous_group_creation_steps_complete( $slug ); ?>
2498  
2499          <li<?php if ( bp_get_groups_current_create_step() == $slug ) : ?> class="current"<?php endif; ?>><?php if ( $is_enabled ) : ?><a href="<?php echo bp_get_root_domain() . '/' . bp_get_groups_root_slug() ?>/create/step/<?php echo $slug ?>/"><?php else: ?><span><?php endif; ?><?php echo $counter ?>. <?php echo $step['name'] ?><?php if ( $is_enabled ) : ?></a><?php else: ?></span><?php endif ?></li><?php
2500          $counter++;
2501      }
2502  
2503      unset( $is_enabled );
2504  
2505      do_action( 'groups_creation_tabs' );
2506  }
2507  
2508  function bp_group_creation_stage_title() {
2509      global $bp;
2510  
2511      echo apply_filters( 'bp_group_creation_stage_title', '<span>&mdash; ' . $bp->groups->group_creation_steps[bp_get_groups_current_create_step()]['name'] . '</span>' );
2512  }
2513  
2514  function bp_group_creation_form_action() {
2515      echo bp_get_group_creation_form_action();
2516  }
2517  	function bp_get_group_creation_form_action() {
2518          global $bp;
2519  
2520          if ( !bp_action_variable( 1 ) ) {
2521              $keys = array_keys( $bp->groups->group_creation_steps );
2522              $bp->action_variables[1] = array_shift( $keys );
2523          }
2524  
2525          return apply_filters( 'bp_get_group_creation_form_action', trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_action_variable( 1 ) ) );
2526      }
2527  
2528  function bp_is_group_creation_step( $step_slug ) {
2529      global $bp;
2530  
2531      /* Make sure we are in the groups component */
2532      if ( !bp_is_groups_component() || !bp_is_current_action( 'create' ) )
2533          return false;
2534  
2535      /* If this the first step, we can just accept and return true */
2536      $keys = array_keys( $bp->groups->group_creation_steps );
2537      if ( !bp_action_variable( 1 ) && array_shift( $keys ) == $step_slug )
2538          return true;
2539  
2540      /* Before allowing a user to see a group creation step we must make sure previous steps are completed */
2541      if ( !bp_is_first_group_creation_step() ) {
2542          if ( !bp_are_previous_group_creation_steps_complete( $step_slug ) )
2543              return false;
2544      }
2545  
2546      /* Check the current step against the step parameter */
2547      if ( bp_is_action_variable( $step_slug ) )
2548          return true;
2549  
2550      return false;
2551  }
2552  
2553  function bp_is_group_creation_step_complete( $step_slugs ) {
2554      global $bp;
2555  
2556      if ( !isset( $bp->groups->completed_create_steps ) )
2557          return false;
2558  
2559      if ( is_array( $step_slugs ) ) {
2560          $found = true;
2561  
2562          foreach ( (array) $step_slugs as $step_slug ) {
2563              if ( !in_array( $step_slug, $bp->groups->completed_create_steps ) )
2564                  $found = false;
2565          }
2566  
2567          return $found;
2568      } else {
2569          return in_array( $step_slugs, $bp->groups->completed_create_steps );
2570      }
2571  
2572      return true;
2573  }
2574  
2575  function bp_are_previous_group_creation_steps_complete( $step_slug ) {
2576      global $bp;
2577  
2578      /* If this is the first group creation step, return true */
2579      $keys = array_keys( $bp->groups->group_creation_steps );
2580      if ( array_shift( $keys ) == $step_slug )
2581          return true;
2582  
2583      reset( $bp->groups->group_creation_steps );
2584      unset( $previous_steps );
2585  
2586      /* Get previous steps */
2587      foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
2588          if ( $slug == $step_slug )
2589              break;
2590  
2591          $previous_steps[] = $slug;
2592      }
2593  
2594      return bp_is_group_creation_step_complete( $previous_steps );
2595  }
2596  
2597  function bp_new_group_id() {
2598      echo bp_get_new_group_id();
2599  }
2600  	function bp_get_new_group_id() {
2601          global $bp;
2602  
2603          if ( isset( $bp->groups->new_group_id ) )
2604              $new_group_id = $bp->groups->new_group_id;
2605          else
2606              $new_group_id = 0;
2607  
2608          return apply_filters( 'bp_get_new_group_id', $new_group_id );
2609      }
2610  
2611  function bp_new_group_name() {
2612      echo bp_get_new_group_name();
2613  }
2614  	function bp_get_new_group_name() {
2615          global $bp;
2616  
2617          if ( isset( $bp->groups->current_group->name ) )
2618              $name = $bp->groups->current_group->name;
2619          else
2620              $name = '';
2621  
2622          return apply_filters( 'bp_get_new_group_name', $name );
2623      }
2624  
2625  function bp_new_group_description() {
2626      echo bp_get_new_group_description();
2627  }
2628  	function bp_get_new_group_description() {
2629          global $bp;
2630  
2631          if ( isset( $bp->groups->current_group->description ) )
2632              $description = $bp->groups->current_group->description;
2633          else
2634              $description = '';
2635  
2636          return apply_filters( 'bp_get_new_group_description', $description );
2637      }
2638  
2639  function bp_new_group_enable_forum() {
2640      echo bp_get_new_group_enable_forum();
2641  }
2642  	function bp_get_new_group_enable_forum() {
2643          global $bp;
2644          return (int) apply_filters( 'bp_get_new_group_enable_forum', $bp->groups->current_group->enable_forum );
2645      }
2646  
2647  function bp_new_group_status() {
2648      echo bp_get_new_group_status();
2649  }
2650  	function bp_get_new_group_status() {
2651          global $bp;
2652          return apply_filters( 'bp_get_new_group_status', $bp->groups->current_group->status );
2653      }
2654  
2655  function bp_new_group_avatar( $args = '' ) {
2656      echo bp_get_new_group_avatar( $args );
2657  }
2658  	function bp_get_new_group_avatar( $args = '' ) {
2659          global $bp;
2660  
2661          $defaults = array(
2662              'type' => 'full',
2663              'width' => false,
2664              'height' => false,
2665              'class' => 'avatar',
2666              'id' => 'avatar-crop-preview',
2667              'alt' => __( 'Group avatar', 'buddypress' ),
2668              'no_grav' => false
2669          );
2670  
2671          $r = wp_parse_args( $args, $defaults );
2672          extract( $r, EXTR_SKIP );
2673  
2674          return apply_filters( 'bp_get_new_group_avatar', bp_core_fetch_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group', 'type' => $type, 'avatar_dir' => 'group-avatars', 'alt' => $alt, 'width' => $width, 'height' => $height, 'class' => $class, 'no_grav' => $no_grav ) ) );
2675      }
2676  
2677  function bp_group_creation_previous_link() {
2678      echo bp_get_group_creation_previous_link();
2679  }
2680  	function bp_get_group_creation_previous_link() {
2681          global $bp;
2682  
2683          foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
2684              if ( bp_is_action_variable( $slug ) )
2685                  break;
2686  
2687              $previous_steps[] = $slug;
2688          }
2689  
2690          return apply_filters( 'bp_get_group_creation_previous_link', trailingslashit( bp_get_root_domain() ) . bp_get_groups_root_slug() . '/create/step/' . array_pop( $previous_steps ) );
2691      }
2692  
2693  /**
2694   * Echoes the current group creation step
2695   *
2696   * @since BuddyPress (1.6)
2697   */
2698  function bp_groups_current_create_step() {
2699      echo bp_get_groups_current_create_step();
2700  }
2701      /**
2702       * Returns the current group creation step. If none is found, returns an empty string
2703       *
2704       * @since BuddyPress (1.6)
2705       *
2706       * @uses apply_filters() Filter bp_get_groups_current_create_step to modify
2707       * @return string $current_create_step
2708       */
2709  	function bp_get_groups_current_create_step() {
2710          global $bp;
2711  
2712          if ( !empty( $bp->groups->current_create_step ) ) {
2713              $current_create_step = $bp->groups->current_create_step;
2714          } else {
2715              $current_create_step = '';
2716          }
2717  
2718          return apply_filters( 'bp_get_groups_current_create_step', $current_create_step );
2719      }
2720  
2721  function bp_is_last_group_creation_step() {
2722      global $bp;
2723  
2724      $keys      = array_keys( $bp->groups->group_creation_steps );
2725      $last_step = array_pop( $keys );
2726  
2727      if ( $last_step == bp_get_groups_current_create_step() )
2728          return true;
2729  
2730      return false;
2731  }
2732  
2733  function bp_is_first_group_creation_step() {
2734      global $bp;
2735  
2736      $keys       = array_keys( $bp->groups->group_creation_steps );
2737      $first_step = array_shift( $keys );
2738  
2739      if ( $first_step == bp_get_groups_current_create_step() )
2740          return true;
2741  
2742      return false;
2743  }
2744  
2745  function bp_new_group_invite_friend_list() {
2746      echo bp_get_new_group_invite_friend_list();
2747  }
2748  	function bp_get_new_group_invite_friend_list( $args = '' ) {
2749          global $bp;
2750  
2751          if ( !bp_is_active( 'friends' ) )
2752              return false;
2753  
2754          $defaults = array(
2755              'group_id'  => false,
2756              'separator' => 'li'
2757          );
2758  
2759          $r = wp_parse_args( $args, $defaults );
2760          extract( $r, EXTR_SKIP );
2761  
2762          if ( empty( $group_id ) )
2763              $group_id = !empty( $bp->groups->new_group_id ) ? $bp->groups->new_group_id : $bp->groups->current_group->id;
2764  
2765          if ( $friends = friends_get_friends_invite_list( bp_loggedin_user_id(), $group_id ) ) {
2766              $invites = groups_get_invites_for_group( bp_loggedin_user_id(), $group_id );
2767  
2768              for ( $i = 0, $count = count( $friends ); $i < $count; ++$i ) {
2769                  $checked = '';
2770  
2771                  if ( !empty( $invites ) ) {
2772                      if ( in_array( $friends[$i]['id'], $invites ) )
2773                          $checked = ' checked="checked"';
2774                  }
2775  
2776                  $items[] = '<' . $separator . '><input' . $checked . ' type="checkbox" name="friends[]" id="f-' . $friends[$i]['id'] . '" value="' . esc_attr( $friends[$i]['id'] ) . '" /> ' . $friends[$i]['full_name'] . '</' . $separator . '>';
2777              }
2778          }
2779  
2780          if ( !empty( $items ) )
2781              return implode( "\n", (array) $items );
2782  
2783          return false;
2784      }
2785  
2786  function bp_directory_groups_search_form() {
2787  
2788      $default_search_value = bp_get_search_default_text( 'groups' );
2789      $search_value         = !empty( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : $default_search_value;
2790  
2791      $search_form_html = '<form action="" method="get" id="search-groups-form">
2792          <label><input type="text" name="s" id="groups_search" placeholder="'. esc_attr( $search_value ) .'" /></label>
2793          <input type="submit" id="groups_search_submit" name="groups_search_submit" value="'. __( 'Search', 'buddypress' ) .'" />
2794      </form>';
2795  
2796      echo apply_filters( 'bp_directory_groups_search_form', $search_form_html );
2797  
2798  }
2799  
2800  /**
2801   * Displays group header tabs
2802   *
2803   * @package BuddyPress
2804   * @todo Deprecate?
2805   */
2806  function bp_groups_header_tabs() {
2807      global $bp;?>
2808  
2809      <li<?php if ( !bp_action_variable( 0 ) || bp_is_action_variable( 'recently-active', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/recently-active' ) ?>"><?php _e( 'Recently Active', 'buddypress' ) ?></a></li>
2810      <li<?php if ( bp_is_action_variable( 'recently-joined', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/recently-joined' ) ?>"><?php _e( 'Recently Joined', 'buddypress' ) ?></a></li>
2811      <li<?php if ( bp_is_action_variable( 'most-popular', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/most-popular' ) ?>"><?php _e( 'Most Popular', 'buddypress' ) ?></a></li>
2812      <li<?php if ( bp_is_action_variable( 'admin-of', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/admin-of' ) ?>"><?php _e( 'Administrator Of', 'buddypress' ) ?></a></li>
2813      <li<?php if ( bp_is_action_variable( 'mod-of', 0 ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/mod-of' ) ?>"><?php _e( 'Moderator Of', 'buddypress' ) ?></a></li>
2814      <li<?php if ( bp_is_action_variable( 'alphabetically' ) ) : ?> class="current"<?php endif; ?>><a href="<?php echo trailingslashit( bp_displayed_user_domain() . bp_get_groups_slug() . '/my-groups/alphabetically' ) ?>"><?php _e( 'Alphabetically', 'buddypress' ) ?></a></li>
2815  
2816  <?php
2817      do_action( 'groups_header_tabs' );
2818  }
2819  
2820  /**
2821   * Displays group filter titles
2822   *
2823   * @package BuddyPress
2824   * @todo Deprecate?
2825   */
2826  function bp_groups_filter_title() {
2827      $current_filter = bp_action_variable( 0 );
2828  
2829      switch ( $current_filter ) {
2830          case 'recently-active': default:
2831              _e( 'Recently Active', 'buddypress' );
2832              break;
2833          case 'recently-joined':
2834              _e( 'Recently Joined', 'buddypress' );
2835              break;
2836          case 'most-popular':
2837              _e( 'Most Popular', 'buddypress' );
2838              break;
2839          case 'admin-of':
2840              _e( 'Administrator Of', 'buddypress' );
2841              break;
2842          case 'mod-of':
2843              _e( 'Moderator Of', 'buddypress' );
2844              break;
2845          case 'alphabetically':
2846              _e( 'Alphabetically', 'buddypress' );
2847          break;
2848      }
2849      do_action( 'bp_groups_filter_title' );
2850  }
2851  
2852  function bp_is_group_admin_screen( $slug ) {
2853      if ( !bp_is_groups_component() || !bp_is_current_action( 'admin' ) )
2854          return false;
2855  
2856      if ( bp_is_action_variable( $slug ) )
2857          return true;
2858  
2859      return false;
2860  }
2861  
2862  /**
2863   * Echoes the current group admin tab slug
2864   *
2865   * @since BuddyPress (1.6)
2866   */
2867  function bp_group_current_admin_tab() {
2868      echo bp_get_group_current_admin_tab();
2869  }
2870      /**
2871       * Returns the current group admin tab slug
2872       *
2873       * @since BuddyPress (1.6)
2874       *
2875       * @uses apply_filters() Filter bp_get_current_group_admin_tab to modify return value
2876       * @return string $tab The current tab's slug
2877       */
2878  	function bp_get_group_current_admin_tab() {
2879          if ( bp_is_groups_component() && bp_is_current_action( 'admin' ) ) {
2880              $tab = bp_action_variable( 0 );
2881          } else {
2882              $tab = '';
2883          }
2884  
2885          return apply_filters( 'bp_get_current_group_admin_tab', $tab );
2886      }
2887  
2888  /************************************************************************************
2889   * Group Avatar Template Tags
2890   **/
2891  
2892  /**
2893   * Outputs the current group avatar
2894   *
2895   * @since BuddyPress (1.0)
2896   * @param string $type thumb or full ?
2897   * @uses bp_get_group_current_avatar() to get the avatar of the current group
2898   */
2899  function bp_group_current_avatar( $type = 'thumb' ) {
2900      echo bp_get_group_current_avatar( $type );
2901  }
2902      /**
2903       * Returns the current group avatar
2904       *
2905       * @since BuddyPress (2.0.0)
2906       *
2907       * @param string $type thumb or full ?
2908       * @return string $tab The current tab's slug.
2909       */
2910  	function bp_get_group_current_avatar( $type = 'thumb' ) {
2911  
2912          $group_avatar = bp_core_fetch_avatar( array(
2913              'item_id'    => bp_get_current_group_id(),
2914              'object'     => 'group',
2915              'type'       => $type,
2916              'avatar_dir' => 'group-avatars',
2917              'alt'        => __( 'Group avatar', 'buddypress' ),
2918              'class'      => 'avatar'
2919          ) );
2920  
2921          return apply_filters( 'bp_get_group_current_avatar', $group_avatar );
2922      }
2923  
2924  function bp_get_group_has_avatar( $group_id = false ) {
2925      global $bp;
2926  
2927      if ( false === $group_id ) {
2928          $group_id = bp_get_current_group_id();
2929      }
2930  
2931      // Todo - this looks like an overgeneral check
2932      if ( ! empty( $_FILES ) ) {
2933          return false;
2934      }
2935  
2936      $group_avatar = bp_core_fetch_avatar( array(
2937          'item_id' => $group_id,
2938          'object' => 'group',
2939          'no_grav' => true,
2940          'html' => false,
2941      ) );
2942  
2943      if ( bp_core_avatar_default( 'local' ) === $group_avatar ) {
2944          return false;
2945      }
2946  
2947      return true;
2948  }
2949  
2950  function bp_group_avatar_delete_link() {
2951      echo bp_get_group_avatar_delete_link();
2952  }
2953  	function bp_get_group_avatar_delete_link() {
2954          global $bp;
2955  
2956          return apply_filters( 'bp_get_group_avatar_delete_link', wp_nonce_url( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/group-avatar/delete', 'bp_group_avatar_delete' ) );
2957      }
2958  
2959  function bp_group_avatar_edit_form() {
2960      groups_avatar_upload();
2961  }
2962  
2963  function bp_custom_group_boxes() {
2964      do_action( 'groups_custom_group_boxes' );
2965  }
2966  
2967  function bp_custom_group_admin_tabs() {
2968      do_action( 'groups_custom_group_admin_tabs' );
2969  }
2970  
2971  function bp_custom_group_fields_editable() {
2972      do_action( 'groups_custom_group_fields_editable' );
2973  }
2974  
2975  function bp_custom_group_fields() {
2976      do_action( 'groups_custom_group_fields' );
2977  }
2978  
2979  
2980  /************************************************************************************
2981   * Membership Requests Template Tags
2982   **/
2983  
2984  class BP_Groups_Membership_Requests_Template {
2985      var $current_request = -1;
2986      var $request_count;
2987      var $requests;
2988      var $request;
2989  
2990      var $in_the_loop;
2991  
2992      var $pag_page;
2993      var $pag_num;
2994      var $pag_links;
2995      var $total_request_count;
2996  
2997      /**
2998       * Constructor method.
2999       *
3000       * @param array $args {
3001       *     @type int $group_id ID of the group whose membership requests
3002       *           are being queried. Default: current group id.
3003       *     @type int $per_page Number of records to return per page of
3004       *           results. Default: 10.
3005       *     @type int $page Page of results to show. Default: 1.
3006       *     @type int $max Max items to return. Default: false (show all)
3007       * }
3008       */
3009  	function __construct( $args = array() ) {
3010  
3011          // Backward compatibility with old method of passing arguments
3012          if ( ! is_array( $args ) || func_num_args() > 1 ) {
3013              _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__ ) );
3014  
3015              $old_args_keys = array(
3016                  0 => 'group_id',
3017                  1 => 'per_page',
3018                  2 => 'max',
3019              );
3020  
3021              $func_args = func_get_args();
3022              $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
3023          }
3024  
3025          $r = wp_parse_args( $args, array(
3026              'group_id' => bp_get_current_group_id(),
3027              'per_page' => 10,
3028              'page'     => 1,
3029              'max'      => false,
3030              'type'     => 'first_joined',
3031          ) );
3032  
3033          $this->pag_page = isset( $_REQUEST['mrpage'] ) ? intval( $_REQUEST['mrpage'] ) : $r['page'];
3034          $this->pag_num  = isset( $_REQUEST['num'] ) ? intval( $_REQUEST['num'] ) : $r['per_page'];
3035  
3036          $mquery = new BP_Group_Member_Query( array(
3037              'group_id' => $r['group_id'],
3038              'type'     => $r['type'],
3039              'per_page' => $this->pag_num,
3040              'page'     => $this->pag_page,
3041  
3042              // These filters ensure we only get pending requests
3043              'is_confirmed' => false,
3044              'inviter_id'   => 0,
3045          ) );
3046  
3047          $this->requests      = array_values( $mquery->results );
3048          $this->request_count = count( $this->requests );
3049  
3050          // Compatibility with legacy format of request data objects
3051          foreach ( $this->requests as $rk => $rv ) {
3052              // For legacy reasons, the 'id' property of each
3053              // request must match the membership id, not the ID of
3054              // the user (as it's returned by BP_Group_Member_Query)
3055              $this->requests[ $rk ]->user_id = $rv->ID;
3056              $this->requests[ $rk ]->id      = $rv->membership_id;
3057  
3058              // Miscellaneous values
3059              $this->requests[ $rk ]->group_id   = $r['group_id'];
3060          }
3061  
3062          if ( !$r['max'] || $r['max'] >= (int) $mquery->total_users )
3063              $this->total_request_count = (int) $mquery->total_users;
3064          else
3065              $this->total_request_count = (int) $r['max'];
3066  
3067          if ( $r['max'] ) {
3068              if ( $r['max'] >= count($this->requests) )
3069                  $this->request_count = count($this->requests);
3070              else
3071                  $this->request_count = (int) $r['max'];
3072          } else {
3073              $this->request_count = count($this->requests);
3074          }
3075  
3076          $this->pag_links = paginate_links( array(
3077              'base' => add_query_arg( 'mrpage', '%#%' ),
3078              'format' => '',
3079              'total' => ceil( $this->total_request_count / $this->pag_num ),
3080              'current' => $this->pag_page,
3081              'prev_text' => '&larr;',
3082              'next_text' => '&rarr;',
3083              'mid_size' => 1
3084          ) );
3085      }
3086  
3087  	function has_requests() {
3088          if ( $this->request_count )
3089              return true;
3090  
3091          return false;
3092      }
3093  
3094  	function next_request() {
3095          $this->current_request++;
3096          $this->request = $this->requests[$this->current_request];
3097  
3098          return $this->request;
3099      }
3100  
3101  	function rewind_requests() {
3102          $this->current_request = -1;
3103  
3104          if ( $this->request_count > 0 )
3105              $this->request = $this->requests[0];
3106      }
3107  
3108  	function requests() {
3109          if ( $this->current_request + 1 < $this->request_count ) {
3110              return true;
3111          } elseif ( $this->current_request + 1 == $this->request_count ) {
3112              do_action('group_request_loop_end');
3113              // Do some cleaning up after the loop
3114              $this->rewind_requests();
3115          }
3116  
3117          $this->in_the_loop = false;
3118          return false;
3119      }
3120  
3121  	function the_request() {
3122          $this->in_the_loop = true;
3123          $this->request     = $this->next_request();
3124  
3125          if ( 0 == $this->current_request ) // loop has just started
3126              do_action('group_request_loop_start');
3127      }
3128  }
3129  
3130  /**
3131   * Initialize a group membership request template loop.
3132   *
3133   * @param array $args {
3134   *     @type int $group_id ID of the group. Defaults to current group.
3135   *     @type int $per_page Number of records to return per page. Default: 10.
3136   *     @type int $page Page of results to return. Default: 1.
3137   *     @type int $max Max number of items to return. Default: false.
3138   * }
3139   * @return bool True if there are requests, otherwise false.
3140   */
3141  function bp_group_has_membership_requests( $args = '' ) {
3142      global $requests_template;
3143  
3144      $defaults = array(
3145          'group_id' => bp_get_current_group_id(),
3146          'per_page' => 10,
3147          'page'     => 1,
3148          'max'      => false
3149      );
3150  
3151      $r = wp_parse_args( $args, $defaults );
3152  
3153      $requests_template = new BP_Groups_Membership_Requests_Template( $r );
3154      return apply_filters( 'bp_group_has_membership_requests', $requests_template->has_requests(), $requests_template );
3155  }
3156  
3157  function bp_group_membership_requests() {
3158      global $requests_template;
3159  
3160      return $requests_template->requests();
3161  }
3162  
3163  function bp_group_the_membership_request() {
3164      global $requests_template;
3165  
3166      return $requests_template->the_request();
3167  }
3168  
3169  function bp_group_request_user_avatar_thumb() {
3170      global $requests_template;
3171  
3172      echo apply_filters( 'bp_group_request_user_avatar_thumb', bp_core_fetch_avatar( array( 'item_id' => $requests_template->request->user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname( $requests_template->request->user_id ) ) ) ) );
3173  }
3174  
3175  function bp_group_request_reject_link() {
3176      echo bp_get_group_request_reject_link();
3177  }
3178  	function bp_get_group_request_reject_link() {
3179          global $requests_template;
3180  
3181          return apply_filters( 'bp_get_group_request_reject_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/reject/' . $requests_template->request->membership_id, 'groups_reject_membership_request' ) );
3182      }
3183  
3184  function bp_group_request_accept_link() {
3185      echo bp_get_group_request_accept_link();
3186  }
3187  	function bp_get_group_request_accept_link() {
3188          global $requests_template;
3189  
3190          return apply_filters( 'bp_get_group_request_accept_link', wp_nonce_url( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/accept/' . $requests_template->request->membership_id, 'groups_accept_membership_request' ) );
3191      }
3192  
3193  function bp_group_request_user_link() {
3194      echo bp_get_group_request_user_link();
3195  }
3196  	function bp_get_group_request_user_link() {
3197          global $requests_template;
3198  
3199          return apply_filters( 'bp_get_group_request_user_link', bp_core_get_userlink( $requests_template->request->user_id ) );
3200      }
3201  
3202  function bp_group_request_time_since_requested() {
3203      global $requests_template;
3204  
3205      echo apply_filters( 'bp_group_request_time_since_requested', sprintf( __( 'requested %s', 'buddypress' ), bp_core_time_since( strtotime( $requests_template->request->date_modified ) ) ) );
3206  }
3207  
3208  function bp_group_request_comment() {
3209      global $requests_template;
3210  
3211      echo apply_filters( 'bp_group_request_comment', strip_tags( stripslashes( $requests_template->request->comments ) ) );
3212  }
3213  
3214  /**
3215   * Output pagination links for group membership requests.
3216   *
3217   * @since BuddyPress (2.0.0)
3218   */
3219  function bp_group_requests_pagination_links() {
3220      echo bp_get_group_requests_pagination_links();
3221  }
3222      /**
3223       * Get pagination links for group membership requests.
3224       *
3225       * @since BuddyPress (2.0.0)
3226       *
3227       * @return string
3228       */
3229  	function bp_get_group_requests_pagination_links() {
3230          global $requests_template;
3231          return apply_filters( 'bp_get_group_requests_pagination_links', $requests_template->pag_links );
3232      }
3233  
3234  /**
3235   * Output pagination count text for group membership requests.
3236   *
3237   * @since BuddyPress (2.0.0)
3238   */
3239  function bp_group_requests_pagination_count() {
3240      echo bp_get_group_requests_pagination_count();
3241  }
3242      /**
3243       * Get pagination count text for group membership requests.
3244       *
3245       * @since BuddyPress (2.0.0)
3246       *
3247       * @return string
3248       */
3249  	function bp_get_group_requests_pagination_count() {
3250          global $requests_template;
3251  
3252          $start_num = intval( ( $requests_template->pag_page - 1 ) * $requests_template->pag_num ) + 1;
3253          $from_num  = bp_core_number_format( $start_num );
3254          $to_num    = bp_core_number_format( ( $start_num + ( $requests_template->pag_num - 1 ) > $requests_template->total_request_count ) ? $requests_template->total_request_count : $start_num + ( $requests_template->pag_num - 1 ) );
3255          $total     = bp_core_number_format( $requests_template->total_request_count );
3256  
3257          return apply_filters( 'bp_get_group_requests_pagination_count', sprintf( _n( 'Viewing requests %1$s to %2$s (of %3$s request)', 'Viewing request %1$s to %2$s (of %3$s requests)', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total );
3258      }
3259  
3260  /************************************************************************************
3261   * Invite Friends Template Tags
3262   **/
3263  
3264  class BP_Groups_Invite_Template {
3265      var $current_invite = -1;
3266      var $invite_count;
3267      var $invites;
3268      var $invite;
3269  
3270      var $in_the_loop;
3271  
3272      var $pag_page;
3273      var $pag_num;
3274      var $pag_links;
3275      var $total_invite_count;
3276  
3277  	public function __construct( $args = array() ) {
3278  
3279          // Backward compatibility with old method of passing arguments
3280          if ( ! is_array( $args ) || func_num_args() > 1 ) {
3281              _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__ ) );
3282  
3283              $old_args_keys = array(
3284                  0  => 'user_id',
3285                  1  => 'group_id',
3286              );
3287  
3288              $func_args = func_get_args();
3289              $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
3290          }
3291  
3292          $r = wp_parse_args( $args, array(
3293              'user_id'  => bp_loggedin_user_id(),
3294              'group_id' => bp_get_current_group_id(),
3295              'page'     => 1,
3296              'per_page' => 10,
3297          ) );
3298  
3299          $this->pag_num  = intval( $r['per_page'] );
3300          $this->pag_page = isset( $_REQUEST['invitepage'] ) ? intval( $_REQUEST['invitepage'] ) : $r['page'];
3301  
3302          $iquery = new BP_Group_Member_Query( array(
3303              'group_id' => $r['group_id'],
3304              'type'     => 'first_joined',
3305              'per_page' => $this->pag_num,
3306              'page'     => $this->pag_page,
3307  
3308              // These filters ensure we get only pending invites
3309              'is_confirmed' => false,
3310              'inviter_id'   => $r['user_id'],
3311          ) );
3312          $this->invite_data = $iquery->results;
3313  
3314          $this->total_invite_count = $iquery->total_users;
3315          $this->invites          = array_values( wp_list_pluck( $this->invite_data, 'ID' ) );
3316          $this->invite_count       = count( $this->invites );
3317  
3318          // If per_page is set to 0 (show all results), don't generate
3319          // pag_links
3320          if ( ! empty( $this->pag_num ) ) {
3321              $this->pag_links = paginate_links( array(
3322                  'base'      => add_query_arg( 'invitepage', '%#%' ),
3323                  'format'    => '',
3324                  'total'     => ceil( $this->total_invite_count / $this->pag_num ),
3325                  'current'   => $this->pag_page,
3326                  'prev_text' => '&larr;',
3327                  'next_text' => '&rarr;',
3328                  'mid_size'  => 1,
3329              ) );
3330          } else {
3331              $this->pag_links = '';
3332          }
3333      }
3334  
3335  	function has_invites() {
3336          if ( $this->invite_count )
3337              return true;
3338  
3339          return false;
3340      }
3341  
3342  	function next_invite() {
3343          $this->current_invite++;
3344          $this->invite = $this->invites[$this->current_invite];
3345  
3346          return $this->invite;
3347      }
3348  
3349  	function rewind_invites() {
3350          $this->current_invite = -1;
3351          if ( $this->invite_count > 0 )
3352              $this->invite = $this->invites[0];
3353      }
3354  
3355  	function invites() {
3356          if ( $this->current_invite + 1 < $this->invite_count ) {
3357              return true;
3358          } elseif ( $this->current_invite + 1 == $this->invite_count ) {
3359              do_action('loop_end');
3360              // Do some cleaning up after the loop
3361              $this->rewind_invites();
3362          }
3363  
3364          $this->in_the_loop = false;
3365          return false;
3366      }
3367  
3368  	function the_invite() {
3369          global $group_id;
3370          $this->in_the_loop      = true;
3371          $user_id                = $this->next_invite();
3372  
3373          $this->invite           = new stdClass;
3374          $this->invite->user     = $this->invite_data[ $user_id ];
3375  
3376          // This method previously populated the user object with
3377          // BP_Core_User. We manually configure BP_Core_User data for
3378          // backward compatibility.
3379          if ( bp_is_active( 'xprofile' ) ) {
3380              $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user( $user_id );
3381          }
3382  
3383          $this->invite->user->avatar       = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'full', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
3384          $this->invite->user->avatar_thumb = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ) ) );
3385          $this->invite->user->avatar_mini  = bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), $this->invite->user->fullname ), 'width' => 30, 'height' => 30 ) );
3386          $this->invite->user->email        = $this->invite->user->user_email;
3387          $this->invite->user->user_url     = bp_core_get_user_domain( $user_id, $this->invite->user->user_nicename, $this->invite->user->user_login );
3388          $this->invite->user->user_link    = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>";
3389          $this->invite->user->last_active  = bp_core_get_last_activity( $this->invite->user->last_activity, __( 'active %s', 'buddypress' ) );
3390  
3391          if ( bp_is_active( 'groups' ) ) {
3392              $total_groups = BP_Groups_Member::total_group_count( $user_id );
3393              $this->invite->user->total_groups = sprintf( _n( '%d group', '%d groups', $total_groups, 'buddypress' ), $total_groups );
3394          }
3395  
3396          if ( bp_is_active( 'friends' ) ) {
3397              $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
3398          }
3399  
3400          if ( bp_is_active( 'friends' ) ) {
3401              $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count( $user_id );
3402          }
3403  
3404          $this->invite->user->total_blogs = null;
3405  
3406          $this->invite->group_id = $group_id; // Globaled in bp_group_has_invites()
3407  
3408          if ( 0 == $this->current_invite ) // loop has just started
3409              do_action('loop_start');
3410      }
3411  }
3412  
3413  function bp_group_has_invites( $args = '' ) {
3414      global $invites_template, $group_id;
3415  
3416      $r = wp_parse_args( $args, array(
3417          'group_id' => false,
3418          'user_id'  => bp_loggedin_user_id(),
3419          'per_page' => false,
3420          'page'     => 1,
3421      ) );
3422  
3423      if ( empty( $r['group_id'] ) ) {
3424          if ( ! empty( buddypress()->groups->current_group ) ) {
3425              $r['group_id'] = bp_get_current_group_id();
3426          } else if ( ! empty( buddypress()->groups->new_group_id ) ) {
3427              $r['group_id'] = buddypress()->groups->new_group_id;
3428          }
3429      }
3430  
3431      // Set the global (for use in BP_Groups_Invite_Template::the_invite())
3432      if ( empty( $group_id ) ) {
3433          $group_id = $r['group_id'];
3434      }
3435  
3436      if ( ! $group_id ) {
3437          return false;
3438      }
3439  
3440      $invites_template = new BP_Groups_Invite_Template( $r );
3441      return apply_filters( 'bp_group_has_invites', $invites_template->has_invites(), $invites_template );
3442  }
3443  
3444  function bp_group_invites() {
3445      global $invites_template;
3446  
3447      return $invites_template->invites();
3448  }
3449  
3450  function bp_group_the_invite() {
3451      global $invites_template;
3452  
3453      return $invites_template->the_invite();
3454  }
3455  
3456  function bp_group_invite_item_id() {
3457      echo bp_get_group_invite_item_id();
3458  }
3459  	function bp_get_group_invite_item_id() {
3460          global $invites_template;
3461  
3462          return apply_filters( 'bp_get_group_invite_item_id', 'uid-' . $invites_template->invite->user->id );
3463      }
3464  
3465  function bp_group_invite_user_avatar() {
3466      echo bp_get_group_invite_user_avatar();
3467  }
3468  	function bp_get_group_invite_user_avatar() {
3469          global $invites_template;
3470  
3471          return apply_filters( 'bp_get_group_invite_user_avatar', $invites_template->invite->user->avatar_thumb );
3472      }
3473  
3474  function bp_group_invite_user_link() {
3475      echo bp_get_group_invite_user_link();
3476  }
3477  	function bp_get_group_invite_user_link() {
3478          global $invites_template;
3479  
3480          return apply_filters( 'bp_get_group_invite_user_link', bp_core_get_userlink( $invites_template->invite->user->id ) );
3481      }
3482  
3483  function bp_group_invite_user_last_active() {
3484      echo bp_get_group_invite_user_last_active();
3485  }
3486  	function bp_get_group_invite_user_last_active() {
3487          global $invites_template;
3488  
3489          return apply_filters( 'bp_get_group_invite_user_last_active', $invites_template->invite->user->last_active );
3490      }
3491  
3492  function bp_group_invite_user_remove_invite_url() {
3493      echo bp_get_group_invite_user_remove_invite_url();
3494  }
3495  	function bp_get_group_invite_user_remove_invite_url() {
3496          global $invites_template;
3497  
3498          $user_id = intval( $invites_template->invite->user->id );
3499  
3500          if ( bp_is_current_action( 'create' ) ) {
3501              $uninvite_url = bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/group-invites/?user_id=' . $user_id;
3502          } else {
3503              $uninvite_url = bp_get_group_permalink( groups_get_current_group() ) . 'send-invites/remove/' . $user_id;
3504          }
3505  
3506          return wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' );
3507      }
3508  
3509  /**
3510   * Output pagination links for group invitations.
3511   *
3512   * @since BuddyPress (2.0.0)
3513   */
3514  function bp_group_invite_pagination_links() {
3515      echo bp_get_group_invite_pagination_links();
3516  }
3517      /**
3518       * Get pagination links for group invitations.
3519       *
3520       * @since BuddyPress (2.0.0)
3521       *
3522       * @return string
3523       */
3524  	function bp_get_group_invite_pagination_links() {
3525          global $invites_template;
3526          return apply_filters( 'bp_get_group_invite_pagination_links', $invites_template->pag_links );
3527      }
3528  
3529  /**
3530   * Output pagination count text for group invitations.
3531   *
3532   * @since BuddyPress (2.0.0)
3533   */
3534  function bp_group_invite_pagination_count() {
3535      echo bp_get_group_invite_pagination_count();
3536  }
3537      /**
3538       * Get pagination count text for group invitations.
3539       *
3540       * @since BuddyPress (2.0.0)
3541       *
3542       * @return string
3543       */
3544  	function bp_get_group_invite_pagination_count() {
3545          global $invites_template;
3546  
3547          $start_num = intval( ( $invites_template->pag_page - 1 ) * $invites_template->pag_num ) + 1;
3548          $from_num  = bp_core_number_format( $start_num );
3549          $to_num    = bp_core_number_format( ( $start_num + ( $invites_template->pag_num - 1 ) > $invites_template->total_invite_count ) ? $invites_template->total_invite_count : $start_num + ( $invites_template->pag_num - 1 ) );
3550          $total     = bp_core_number_format( $invites_template->total_invite_count );
3551  
3552          return apply_filters( 'bp_get_groups_pagination_count', sprintf( _n( 'Viewing invitation %1$s to %2$s (of %3$s invitation)', 'Viewing invitation %1$s to %2$s (of %3$s invitations)', $total, 'buddypress' ), $from_num, $to_num, $total ), $from_num, $to_num, $total );
3553      }
3554  
3555  /***
3556   * Groups RSS Feed Template Tags
3557   */
3558  
3559  /**
3560   * Hook group activity feed to <head>
3561   *
3562   * @since BuddyPress (1.5)
3563   */
3564  function bp_groups_activity_feed() {
3565      if ( !bp_is_active( 'groups' ) || !bp_is_active( 'activity' ) || !bp_is_group() )
3566          return; ?>
3567  
3568      <link rel="alternate" type="application/rss+xml" title="<?php bloginfo( 'name' ) ?> | <?php bp_current_group_name() ?> | <?php _e( 'Group Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_group_activity_feed_link() ?>" />
3569  
3570  <?php
3571  }
3572  add_action( 'bp_head', 'bp_groups_activity_feed' );
3573  
3574  function bp_group_activity_feed_link() {
3575      echo bp_get_group_activity_feed_link();
3576  }
3577  	function bp_get_group_activity_feed_link() {
3578          global $bp;
3579  
3580          return apply_filters( 'bp_get_group_activity_feed_link', bp_get_group_permalink( $bp->groups->current_group ) . 'feed/' );
3581      }
3582  
3583  /**
3584   * Echoes the output of bp_get_current_group_id()
3585   *
3586   * @package BuddyPress
3587   * @since BuddyPress (1.5)
3588   */
3589  function bp_current_group_id() {
3590      echo bp_get_current_group_id();
3591  }
3592      /**
3593       * Returns the ID of the current group
3594       *
3595       * @package BuddyPress
3596       * @since BuddyPress (1.5)
3597       * @uses apply_filters() Filter bp_get_current_group_id to modify this output
3598       *
3599       * @return int $current_group_id The id of the current group, if there is one
3600       */
3601  	function bp_get_current_group_id() {
3602          $current_group = groups_get_current_group();
3603  
3604          $current_group_id = isset( $current_group->id ) ? (int) $current_group->id : 0;
3605  
3606          return apply_filters( 'bp_get_current_group_id', $current_group_id, $current_group );
3607      }
3608  
3609  /**
3610   * Echoes the output of bp_get_current_group_slug()
3611   *
3612   * @package BuddyPress
3613   * @since BuddyPress (1.5)
3614   */
3615  function bp_current_group_slug() {
3616      echo bp_get_current_group_slug();
3617  }
3618      /**
3619       * Returns the slug of the current group
3620       *
3621       * @package BuddyPress
3622       * @since BuddyPress (1.5)
3623       * @uses apply_filters() Filter bp_get_current_group_slug to modify this output
3624       *
3625       * @return string $current_group_slug The slug of the current group, if there is one
3626       */
3627  	function bp_get_current_group_slug() {
3628          $current_group = groups_get_current_group();
3629  
3630          $current_group_slug = isset( $current_group->slug ) ? $current_group->slug : '';
3631  
3632          return apply_filters( 'bp_get_current_group_slug', $current_group_slug, $current_group );
3633      }
3634  
3635  /**
3636   * Echoes the output of bp_get_current_group_name()
3637   *
3638   * @package BuddyPress
3639   */
3640  function bp_current_group_name() {
3641      echo bp_get_current_group_name();
3642  }
3643      /**
3644       * Returns the name of the current group
3645       *
3646       * @package BuddyPress
3647       * @since BuddyPress (1.5)
3648       * @uses apply_filters() Filter bp_get_current_group_name to modify this output
3649       *
3650       * @return string The name of the current group, if there is one
3651       */
3652  	function bp_get_current_group_name() {
3653          global $bp;
3654  
3655          $name = apply_filters( 'bp_get_group_name', $bp->groups->current_group->name );
3656          return apply_filters( 'bp_get_current_group_name', $name );
3657      }
3658  
3659  function bp_groups_action_link( $action = '', $query_args = '', $nonce = false ) {
3660      echo bp_get_groups_action_link( $action, $query_args, $nonce );
3661  }
3662  	function bp_get_groups_action_link( $action = '', $query_args = '', $nonce = false ) {
3663          global $bp;
3664  
3665          // Must be a group
3666          if ( empty( $bp->groups->current_group->id ) )
3667              return;
3668  
3669          // Append $action to $url if provided
3670          if ( !empty( $action ) )
3671              $url = bp_get_group_permalink( groups_get_current_group() ) . $action;
3672          else
3673              $url = bp_get_group_permalink( groups_get_current_group() );
3674  
3675          // Add a slash at the end of our user url
3676          $url = trailingslashit( $url );
3677  
3678          // Add possible query arg
3679          if ( !empty( $query_args ) && is_array( $query_args ) )
3680              $url = add_query_arg( $query_args, $url );
3681  
3682          // To nonce, or not to nonce...
3683          if ( true === $nonce )
3684              $url = wp_nonce_url( $url );
3685          elseif ( is_string( $nonce ) )
3686              $url = wp_nonce_url( $url, $nonce );
3687  
3688          // Return the url, if there is one
3689          if ( !empty( $url ) )
3690              return $url;
3691      }
3692  
3693  /** Stats **********************************************************************/
3694  
3695  /**
3696   * Display the number of groups in user's profile.
3697   *
3698   * @since BuddyPress (2.0.0)
3699   *
3700   * @param array $args before|after|user_id
3701   * @uses bp_groups_get_profile_stats() to get the stats
3702   */
3703  function bp_groups_profile_stats( $args = '' ) {
3704      echo bp_groups_get_profile_stats( $args );
3705  }
3706  add_action( 'bp_members_admin_user_stats', 'bp_groups_profile_stats', 8, 1 );
3707  
3708  /**
3709   * Return the number of groups in user's profile.
3710   *
3711   * @since BuddyPress (2.0.0)
3712   *
3713   * @param array $args before|after|user_id
3714   * @return string HTML for stats output.
3715   */
3716  function bp_groups_get_profile_stats( $args = '' ) {
3717  
3718      // Parse the args
3719      $r = bp_parse_args( $args, array(
3720          'before'  => '<li class="bp-groups-profile-stats">',
3721          'after'   => '</li>',
3722          'user_id' => bp_displayed_user_id(),
3723          'groups'  => 0,
3724          'output'  => ''
3725      ), 'groups_get_profile_stats' );
3726  
3727      // Allow completely overloaded output
3728      if ( empty( $r['output'] ) ) {
3729  
3730          // Only proceed if a user ID was passed
3731          if ( ! empty( $r['user_id'] ) ) {
3732  
3733              // Get the user groups
3734              if ( empty( $r['groups'] ) ) {
3735                  $r['groups'] = absint( bp_get_total_group_count_for_user( $r['user_id'] ) );
3736              }
3737  
3738              // If groups exist, show some formatted output
3739              $r['output'] = $r['before'] . sprintf( _n( '%s group', '%s groups', $r['groups'], 'buddypress' ), '<strong>' . $r['groups'] . '</strong>' ) . $r['after'];
3740          }
3741      }
3742  
3743      // Filter and return
3744      return apply_filters( 'bp_groups_get_profile_stats', $r['output'], $r );
3745  }


Generated: Sun May 4 03:58:45 2014 Hosted by follow the white rabbit.