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


Generated: Sat Apr 19 03:58:43 2014 Hosted by follow the white rabbit.