[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-legacy/ -> buddypress-functions.php (source)

   1  <?php
   2  /**
   3   * Functions of BuddyPress's Legacy theme.
   4   *
   5   * @since 1.7.0
   6   *
   7   * @package BuddyPress
   8   * @subpackage BP_Theme_Compat
   9   * @version 3.1.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /** Theme Setup ***************************************************************/
  16  
  17  if ( !class_exists( 'BP_Legacy' ) ) :
  18  
  19  /**
  20   * Loads BuddyPress Legacy Theme functionality.
  21   *
  22   * This is not a real theme by WordPress standards, and is instead used as the
  23   * fallback for any WordPress theme that does not have BuddyPress templates in it.
  24   *
  25   * To make your custom theme BuddyPress compatible and customize the templates, you
  26   * can copy these files into your theme without needing to merge anything
  27   * together; BuddyPress should safely handle the rest.
  28   *
  29   * See @link BP_Theme_Compat() for more.
  30   *
  31   * @since 1.7.0
  32   *
  33   * @package BuddyPress
  34   * @subpackage BP_Theme_Compat
  35   */
  36  class BP_Legacy extends BP_Theme_Compat {
  37  
  38      /** Functions *************************************************************/
  39  
  40      /**
  41       * The main BuddyPress (Legacy) Loader.
  42       *
  43       * @since 1.7.0
  44       *
  45       */
  46  	public function __construct() {
  47          parent::start();
  48      }
  49  
  50      /**
  51       * Component global variables.
  52       *
  53       * You'll want to customize the values in here, so they match whatever your
  54       * needs are.
  55       *
  56       * @since 1.7.0
  57       */
  58  	protected function setup_globals() {
  59          $bp            = buddypress();
  60          $this->id      = 'legacy';
  61          $this->name    = __( 'BuddyPress Legacy', 'buddypress' );
  62          $this->version = bp_get_version();
  63          $this->dir     = trailingslashit( $bp->themes_dir . '/bp-legacy' );
  64          $this->url     = trailingslashit( $bp->themes_url . '/bp-legacy' );
  65      }
  66  
  67      /**
  68       * Setup the theme hooks.
  69       *
  70       * @since 1.7.0
  71       *
  72       */
  73  	protected function setup_actions() {
  74  
  75          // Template Output.
  76          add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'secondary_avatars' ), 10, 2 );
  77  
  78          // Filter BuddyPress template hierarchy and look for page templates.
  79          add_filter( 'bp_get_buddypress_template', array( $this, 'theme_compat_page_templates' ), 10, 1 );
  80  
  81          /** Scripts ***********************************************************/
  82  
  83          add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_styles'   ) ); // Enqueue theme CSS
  84          add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts'  ) ); // Enqueue theme JS
  85          add_filter( 'bp_enqueue_scripts', array( $this, 'localize_scripts' ) ); // Enqueue theme script localization
  86  
  87          /** Body no-js Class **************************************************/
  88  
  89          add_filter( 'body_class', array( $this, 'add_nojs_body_class' ), 20, 1 );
  90  
  91          /** Buttons ***********************************************************/
  92  
  93          if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
  94              // Register buttons for the relevant component templates
  95              // Friends button.
  96              if ( bp_is_active( 'friends' ) )
  97                  add_action( 'bp_member_header_actions',    'bp_add_friend_button',           5 );
  98  
  99              // Activity button.
 100              if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() )
 101                  add_action( 'bp_member_header_actions',    'bp_send_public_message_button',  20 );
 102  
 103              // Messages button.
 104              if ( bp_is_active( 'messages' ) )
 105                  add_action( 'bp_member_header_actions',    'bp_send_private_message_button', 20 );
 106  
 107              // Group buttons.
 108              if ( bp_is_active( 'groups' ) ) {
 109                  add_action( 'bp_group_header_actions',          'bp_group_join_button',               5           );
 110                  add_action( 'bp_directory_groups_actions',      'bp_group_join_button'                            );
 111                  add_action( 'bp_groups_directory_group_filter', 'bp_legacy_theme_group_create_nav', 999           );
 112                  add_action( 'bp_after_group_admin_content',     'bp_legacy_groups_admin_screen_hidden_input'      );
 113                  add_action( 'bp_before_group_admin_form',       'bp_legacy_theme_group_manage_members_add_search' );
 114              }
 115  
 116              // Blog button.
 117              if ( bp_is_active( 'blogs' ) ) {
 118                  add_action( 'bp_directory_blogs_actions',    'bp_blogs_visit_blog_button'           );
 119                  add_action( 'bp_blogs_directory_blog_types', 'bp_legacy_theme_blog_create_nav', 999 );
 120              }
 121          }
 122  
 123          /** Notices ***********************************************************/
 124  
 125          // Only hook the 'sitewide_notices' overlay if the Sitewide
 126          // Notices widget is not in use (to avoid duplicate content).
 127          if ( bp_is_active( 'messages' ) && ! is_active_widget( false, false, 'bp_messages_sitewide_notices_widget', true ) ) {
 128              add_action( 'wp_footer', array( $this, 'sitewide_notices' ), 9999 );
 129          }
 130  
 131          /** Ajax **************************************************************/
 132  
 133          $actions = array(
 134  
 135              // Directory filters.
 136              'blogs_filter'    => 'bp_legacy_theme_object_template_loader',
 137              'forums_filter'   => 'bp_legacy_theme_object_template_loader',
 138              'groups_filter'   => 'bp_legacy_theme_object_template_loader',
 139              'members_filter'  => 'bp_legacy_theme_object_template_loader',
 140              'messages_filter' => 'bp_legacy_theme_messages_template_loader',
 141              'invite_filter'   => 'bp_legacy_theme_invite_template_loader',
 142              'requests_filter' => 'bp_legacy_theme_requests_template_loader',
 143  
 144              // Friends.
 145              'accept_friendship' => 'bp_legacy_theme_ajax_accept_friendship',
 146              'addremove_friend'  => 'bp_legacy_theme_ajax_addremove_friend',
 147              'reject_friendship' => 'bp_legacy_theme_ajax_reject_friendship',
 148  
 149              // Activity.
 150              'activity_get_older_updates'  => 'bp_legacy_theme_activity_template_loader',
 151              'activity_mark_fav'           => 'bp_legacy_theme_mark_activity_favorite',
 152              'activity_mark_unfav'         => 'bp_legacy_theme_unmark_activity_favorite',
 153              'activity_widget_filter'      => 'bp_legacy_theme_activity_template_loader',
 154              'delete_activity'             => 'bp_legacy_theme_delete_activity',
 155              'delete_activity_comment'     => 'bp_legacy_theme_delete_activity_comment',
 156              'get_single_activity_content' => 'bp_legacy_theme_get_single_activity_content',
 157              'new_activity_comment'        => 'bp_legacy_theme_new_activity_comment',
 158              'post_update'                 => 'bp_legacy_theme_post_update',
 159              'bp_spam_activity'            => 'bp_legacy_theme_spam_activity',
 160              'bp_spam_activity_comment'    => 'bp_legacy_theme_spam_activity',
 161  
 162              // Groups.
 163              'groups_invite_user' => 'bp_legacy_theme_ajax_invite_user',
 164              'joinleave_group'    => 'bp_legacy_theme_ajax_joinleave_group',
 165  
 166              // Messages.
 167              'messages_autocomplete_results' => 'bp_legacy_theme_ajax_messages_autocomplete_results',
 168              'messages_close_notice'         => 'bp_legacy_theme_ajax_close_notice',
 169              'messages_delete'               => 'bp_legacy_theme_ajax_messages_delete',
 170              'messages_markread'             => 'bp_legacy_theme_ajax_message_markread',
 171              'messages_markunread'           => 'bp_legacy_theme_ajax_message_markunread',
 172              'messages_send_reply'           => 'bp_legacy_theme_ajax_messages_send_reply',
 173          );
 174  
 175          // Conditional actions.
 176          if ( bp_is_active( 'messages', 'star' ) ) {
 177              $actions['messages_star'] = 'bp_legacy_theme_ajax_messages_star_handler';
 178          }
 179  
 180          /**
 181           * Register all of these AJAX handlers.
 182           *
 183           * The "wp_ajax_" action is used for logged in users, and "wp_ajax_nopriv_"
 184           * executes for users that aren't logged in. This is for backpat with BP <1.6.
 185           */
 186          foreach( $actions as $name => $function ) {
 187              add_action( 'wp_ajax_'        . $name, $function );
 188              add_action( 'wp_ajax_nopriv_' . $name, $function );
 189          }
 190  
 191          add_filter( 'bp_ajax_querystring', 'bp_legacy_theme_ajax_querystring', 10, 2 );
 192  
 193          /** Override **********************************************************/
 194  
 195          /**
 196           * Fires after all of the BuddyPress theme compat actions have been added.
 197           *
 198           * @since 1.7.0
 199           *
 200           * @param BP_Legacy $this Current BP_Legacy instance.
 201           */
 202          do_action_ref_array( 'bp_theme_compat_actions', array( &$this ) );
 203      }
 204  
 205      /**
 206       * Load the theme CSS
 207       *
 208       * @since 1.7.0
 209       * @since 2.3.0 Support custom CSS file named after the current theme or parent theme.
 210       *
 211       */
 212  	public function enqueue_styles() {
 213          $min = bp_core_get_minified_asset_suffix();
 214  
 215          // Locate the BP stylesheet.
 216          $ltr = $this->locate_asset_in_stack( "buddypress{$min}.css",     'css' );
 217  
 218          // LTR.
 219          if ( ! is_rtl() && isset( $ltr['location'], $ltr['handle'] ) ) {
 220              wp_enqueue_style( $ltr['handle'], $ltr['location'], array(), $this->version, 'screen' );
 221  
 222              if ( $min ) {
 223                  wp_style_add_data( $ltr['handle'], 'suffix', $min );
 224              }
 225          }
 226  
 227          // RTL.
 228          if ( is_rtl() ) {
 229              $rtl = $this->locate_asset_in_stack( "buddypress-rtl{$min}.css", 'css' );
 230  
 231              if ( isset( $rtl['location'], $rtl['handle'] ) ) {
 232                  $rtl['handle'] = str_replace( '-css', '-css-rtl', $rtl['handle'] );  // Backwards compatibility.
 233                  wp_enqueue_style( $rtl['handle'], $rtl['location'], array(), $this->version, 'screen' );
 234  
 235                  if ( $min ) {
 236                      wp_style_add_data( $rtl['handle'], 'suffix', $min );
 237                  }
 238              }
 239          }
 240  
 241          // Compatibility stylesheets for specific themes.
 242          $theme = $this->locate_asset_in_stack( get_template() . "{$min}.css", 'css' );
 243          if ( ! is_rtl() && isset( $theme['location'] ) ) {
 244              // Use a unique handle.
 245              $theme['handle'] = 'bp-' . get_template();
 246              wp_enqueue_style( $theme['handle'], $theme['location'], array(), $this->version, 'screen' );
 247  
 248              if ( $min ) {
 249                  wp_style_add_data( $theme['handle'], 'suffix', $min );
 250              }
 251          }
 252  
 253          // Compatibility stylesheet for specific themes, RTL-version.
 254          if ( is_rtl() ) {
 255              $theme_rtl = $this->locate_asset_in_stack( get_template() . "-rtl{$min}.css", 'css' );
 256  
 257              if ( isset( $theme_rtl['location'] ) ) {
 258                  $theme_rtl['handle'] = $theme['handle'] . '-rtl';
 259                  wp_enqueue_style( $theme_rtl['handle'], $theme_rtl['location'], array(), $this->version, 'screen' );
 260  
 261                  if ( $min ) {
 262                      wp_style_add_data( $theme_rtl['handle'], 'suffix', $min );
 263                  }
 264              }
 265          }
 266      }
 267  
 268      /**
 269       * Enqueue the required JavaScript files
 270       *
 271       * @since 1.7.0
 272       */
 273  	public function enqueue_scripts() {
 274          $min = bp_core_get_minified_asset_suffix();
 275  
 276          // Locate the BP JS file.
 277          $asset = $this->locate_asset_in_stack( "buddypress{$min}.js", 'js' );
 278  
 279          // Enqueue the global JS, if found - AJAX will not work
 280          // without it.
 281          if ( isset( $asset['location'], $asset['handle'] ) ) {
 282              wp_enqueue_script( $asset['handle'], $asset['location'], bp_core_get_js_dependencies(), $this->version );
 283          }
 284  
 285          /**
 286           * Filters whether directory filter settings ('scope', etc) should be stored in a persistent cookie.
 287           *
 288           * @since 4.0.0
 289           *
 290           * @param bool $store_filter_settings Whether to store settings. Defaults to true for logged-in users.
 291           */
 292          $store_filter_settings = apply_filters( 'bp_legacy_store_filter_settings', is_user_logged_in() );
 293  
 294          /**
 295           * Filters core JavaScript strings for internationalization before AJAX usage.
 296           *
 297           * @since 2.0.0
 298           *
 299           * @param array $value Array of key/value pairs for AJAX usage.
 300           */
 301          $params = apply_filters( 'bp_core_get_js_strings', array(
 302              // Strings for display.
 303              'accepted'            => __( 'Accepted', 'buddypress' ),
 304              'close'               => __( 'Close', 'buddypress' ),
 305              'comments'            => __( 'comments', 'buddypress' ),
 306              'leave_group_confirm' => __( 'Are you sure you want to leave this group?', 'buddypress' ),
 307              'mark_as_fav'          => __( 'Favorite', 'buddypress' ),
 308              'my_favs'             => __( 'My Favorites', 'buddypress' ),
 309              'rejected'            => __( 'Rejected', 'buddypress' ),
 310              'remove_fav'          => __( 'Remove Favorite', 'buddypress' ),
 311              'show_all'            => __( 'Show all', 'buddypress' ),
 312              'show_all_comments'   => __( 'Show all comments for this thread', 'buddypress' ),
 313              'show_x_comments'     => __( 'Show all comments (%d)', 'buddypress' ),
 314              'unsaved_changes'     => __( 'Your profile has unsaved changes. If you leave the page, the changes will be lost.', 'buddypress' ),
 315              'view'                => __( 'View', 'buddypress' ),
 316  
 317              // Settings.
 318              'store_filter_settings' => $store_filter_settings,
 319          ) );
 320          wp_localize_script( $asset['handle'], 'BP_DTheme', $params );
 321  
 322          // Maybe enqueue comment reply JS.
 323          if ( is_singular() && bp_is_blog_page() && get_option( 'thread_comments' ) ) {
 324              wp_enqueue_script( 'comment-reply' );
 325          }
 326  
 327          // Maybe enqueue password verify JS (register page or user settings page).
 328          if ( bp_is_register_page() || ( function_exists( 'bp_is_user_settings_general' ) && bp_is_user_settings_general() ) ) {
 329  
 330              // Locate the Register Page JS file.
 331              $asset = $this->locate_asset_in_stack( "password-verify{$min}.js", 'js', 'bp-legacy-password-verify' );
 332  
 333              $dependencies = array_merge( bp_core_get_js_dependencies(), array(
 334                  'password-strength-meter',
 335              ) );
 336  
 337              // Enqueue script.
 338              wp_enqueue_script( $asset['handle'] . '-password-verify', $asset['location'], $dependencies, $this->version);
 339          }
 340  
 341          // Star private messages.
 342          if ( bp_is_active( 'messages', 'star' ) && bp_is_user_messages() ) {
 343              wp_localize_script( $asset['handle'], 'BP_PM_Star', array(
 344                  'strings' => array(
 345                      'text_unstar'  => __( 'Unstar', 'buddypress' ),
 346                      'text_star'    => __( 'Star', 'buddypress' ),
 347                      'title_unstar' => __( 'Starred', 'buddypress' ),
 348                      'title_star'   => __( 'Not starred', 'buddypress' ),
 349                      'title_unstar_thread' => __( 'Remove all starred messages in this thread', 'buddypress' ),
 350                      'title_star_thread'   => __( 'Star the first message in this thread', 'buddypress' ),
 351                  ),
 352                  'is_single_thread' => (int) bp_is_messages_conversation(),
 353                  'star_counter'     => 0,
 354                  'unstar_counter'   => 0
 355              ) );
 356          }
 357      }
 358  
 359      /**
 360       * Get the URL and handle of a web-accessible CSS or JS asset
 361       *
 362       * We provide two levels of customizability with respect to where CSS
 363       * and JS files can be stored: (1) the child theme/parent theme/theme
 364       * compat hierarchy, and (2) the "template stack" of /buddypress/css/,
 365       * /community/css/, and /css/. In this way, CSS and JS assets can be
 366       * overloaded, and default versions provided, in exactly the same way
 367       * as corresponding PHP templates.
 368       *
 369       * We are duplicating some of the logic that is currently found in
 370       * bp_locate_template() and the _template_stack() functions. Those
 371       * functions were built with PHP templates in mind, and will require
 372       * refactoring in order to provide "stack" functionality for assets
 373       * that must be accessible both using file_exists() (the file path)
 374       * and at a public URI.
 375       *
 376       * This method is marked private, with the understanding that the
 377       * implementation is subject to change or removal in an upcoming
 378       * release, in favor of a unified _template_stack() system. Plugin
 379       * and theme authors should not attempt to use what follows.
 380       *
 381       * @since 1.8.0
 382       * @param string $file A filename like buddypress.css.
 383       * @param string $type Optional. Either "js" or "css" (the default).
 384       * @param string $script_handle Optional. If set, used as the script name in `wp_enqueue_script`.
 385       * @return array An array of data for the wp_enqueue_* function:
 386       *   'handle' (eg 'bp-child-css') and a 'location' (the URI of the
 387       *   asset)
 388       */
 389  	private function locate_asset_in_stack( $file, $type = 'css', $script_handle = '' ) {
 390          $locations = array();
 391  
 392          // Ensure the assets can be located when running from /src/.
 393          if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && BP_SOURCE_SUBDIRECTORY === 'src' ) {
 394              $file = str_replace( '.min', '', $file );
 395          }
 396  
 397          // No need to check child if template == stylesheet.
 398          if ( is_child_theme() ) {
 399              $locations[] = array(
 400                  'type' => 'bp-child',
 401                  'dir'  => get_stylesheet_directory(),
 402                  'uri'  => get_stylesheet_directory_uri(),
 403                  'file' => $file,
 404              );
 405  
 406              $locations[] = array(
 407                  'type' => 'bp-child',
 408                  'dir'  => get_stylesheet_directory(),
 409                  'uri'  => get_stylesheet_directory_uri(),
 410                  'file' => str_replace( '.min', '', $file ),
 411              );
 412          }
 413  
 414          $locations[] = array(
 415              'type' => 'bp-parent',
 416              'dir'  => get_template_directory(),
 417              'uri'  => get_template_directory_uri(),
 418              'file' => str_replace( '.min', '', $file ),
 419          );
 420  
 421          $locations[] = array(
 422              'type' => 'bp-legacy',
 423              'dir'  => bp_get_theme_compat_dir(),
 424              'uri'  => bp_get_theme_compat_url(),
 425              'file' => $file,
 426          );
 427  
 428          // Subdirectories within the top-level $locations directories.
 429          $subdirs = array(
 430              'buddypress/' . $type,
 431              'community/' . $type,
 432              $type,
 433          );
 434  
 435          $retval = array();
 436  
 437          foreach ( $locations as $location ) {
 438              foreach ( $subdirs as $subdir ) {
 439                  if ( file_exists( trailingslashit( $location['dir'] ) . trailingslashit( $subdir ) . $location['file'] ) ) {
 440                      $retval['location'] = trailingslashit( $location['uri'] ) . trailingslashit( $subdir ) . $location['file'];
 441                      $retval['handle']   = ( $script_handle ) ? $script_handle : "{$location['type']}-{$type}";
 442  
 443                      break 2;
 444                  }
 445              }
 446          }
 447  
 448          return $retval;
 449      }
 450  
 451      /**
 452       * Adds the no-js class to the body tag.
 453       *
 454       * This function ensures that the <body> element will have the 'no-js' class by default. If you're
 455       * using JavaScript for some visual functionality in your theme, and you want to provide noscript
 456       * support, apply those styles to body.no-js.
 457       *
 458       * The no-js class is removed by the JavaScript created in buddypress.js.
 459       *
 460       * @since 1.7.0
 461       *
 462       * @param array $classes Array of classes to append to body tag.
 463       * @return array $classes
 464       */
 465  	public function add_nojs_body_class( $classes ) {
 466          if ( ! in_array( 'no-js', $classes ) )
 467              $classes[] = 'no-js';
 468  
 469          return array_unique( $classes );
 470      }
 471  
 472      /**
 473       * Load localizations for topic script.
 474       *
 475       * These localizations require information that may not be loaded even by init.
 476       *
 477       * @since 1.7.0
 478       */
 479  	public function localize_scripts() {
 480      }
 481  
 482      /**
 483       * Outputs sitewide notices markup in the footer.
 484       *
 485       * @since 1.7.0
 486       *
 487       * @see https://buddypress.trac.wordpress.org/ticket/4802
 488       */
 489  	public function sitewide_notices() {
 490          // Do not show notices if user is not logged in.
 491          if ( ! is_user_logged_in() )
 492              return;
 493  
 494          // Add a class to determine if the admin bar is on or not.
 495          $class = did_action( 'admin_bar_menu' ) ? 'admin-bar-on' : 'admin-bar-off';
 496  
 497          echo '<div id="sitewide-notice" class="' . $class . '">';
 498          bp_message_get_notices();
 499          echo '</div>';
 500      }
 501  
 502      /**
 503       * Add secondary avatar image to this activity stream's record, if supported.
 504       *
 505       * @since 1.7.0
 506       *
 507       * @param string               $action   The text of this activity.
 508       * @param BP_Activity_Activity $activity Activity object.
 509       * @return string
 510       */
 511  	function secondary_avatars( $action, $activity ) {
 512          switch ( $activity->component ) {
 513              case 'groups' :
 514              case 'friends' :
 515                  // Only insert avatar if one exists.
 516                  if ( $secondary_avatar = bp_get_activity_secondary_avatar() ) {
 517                      $reverse_content = strrev( $action );
 518                      $position        = strpos( $reverse_content, 'a<' );
 519                      $action          = substr_replace( $action, $secondary_avatar, -$position - 2, 0 );
 520                  }
 521                  break;
 522          }
 523  
 524          return $action;
 525      }
 526  
 527      /**
 528       * Filter the default theme compatibility root template hierarchy, and prepend
 529       * a page template to the front if it's set.
 530       *
 531       * @see https://buddypress.trac.wordpress.org/ticket/6065
 532       *
 533       * @since 2.2.0
 534       *
 535       * @param  array $templates Array of templates.
 536       *                         to use the defined page template for component's directory and its single items
 537       * @return array
 538       */
 539  	public function theme_compat_page_templates( $templates = array() ) {
 540  
 541          /**
 542           * Filters whether or not we are looking at a directory to determine if to return early.
 543           *
 544           * @since 2.2.0
 545           *
 546           * @param bool $value Whether or not we are viewing a directory.
 547           */
 548          if ( true === (bool) apply_filters( 'bp_legacy_theme_compat_page_templates_directory_only', ! bp_is_directory() ) ) {
 549              return $templates;
 550          }
 551  
 552          // No page ID yet.
 553          $page_id = 0;
 554  
 555          // Get the WordPress Page ID for the current view.
 556          foreach ( (array) buddypress()->pages as $component => $bp_page ) {
 557  
 558              // Handles the majority of components.
 559              if ( bp_is_current_component( $component ) ) {
 560                  $page_id = (int) $bp_page->id;
 561              }
 562  
 563              // Stop if not on a user page.
 564              if ( ! bp_is_user() && ! empty( $page_id ) ) {
 565                  break;
 566              }
 567  
 568              // The Members component requires an explicit check due to overlapping components.
 569              if ( bp_is_user() && ( 'members' === $component ) ) {
 570                  $page_id = (int) $bp_page->id;
 571                  break;
 572              }
 573          }
 574  
 575          // Bail if no directory page set.
 576          if ( 0 === $page_id ) {
 577              return $templates;
 578          }
 579  
 580          // Check for page template.
 581          $page_template = get_page_template_slug( $page_id );
 582  
 583          // Add it to the beginning of the templates array so it takes precedence
 584          // over the default hierarchy.
 585          if ( ! empty( $page_template ) ) {
 586  
 587              /**
 588               * Check for existence of template before adding it to template
 589               * stack to avoid accidentally including an unintended file.
 590               *
 591               * @see: https://buddypress.trac.wordpress.org/ticket/6190
 592               */
 593              if ( '' !== locate_template( $page_template ) ) {
 594                  array_unshift( $templates, $page_template );
 595              }
 596          }
 597  
 598          return $templates;
 599      }
 600  }
 601  new BP_Legacy();
 602  endif;
 603  
 604  /**
 605   * Add the Create a Group button to the Groups directory title.
 606   *
 607   * The bp-legacy puts the Create a Group button into the page title, to mimic
 608   * the behavior of bp-default.
 609   *
 610   * @since 2.0.0
 611   * @todo Deprecate
 612   *
 613   * @param string $title Groups directory title.
 614   * @return string
 615   */
 616  function bp_legacy_theme_group_create_button( $title ) {
 617      return $title . ' ' . bp_get_group_create_button();
 618  }
 619  
 620  /**
 621   * Add the Create a Group nav to the Groups directory navigation.
 622   *
 623   * The bp-legacy puts the Create a Group nav at the last position of
 624   * the Groups directory navigation.
 625   *
 626   * @since 2.2.0
 627   *
 628   */
 629  function bp_legacy_theme_group_create_nav() {
 630      bp_group_create_nav_item();
 631  }
 632  
 633  /**
 634   * Renders the group ID hidden input on group admin screens.
 635   *
 636   * @since 2.7.0
 637   *
 638   * @return string|null html
 639   */
 640  function bp_legacy_groups_admin_screen_hidden_input() {
 641      ?>
 642       <input type="hidden" name="group-id" id="group-id" value="<?php bp_group_id(); ?>" />
 643      <?php
 644  }
 645  
 646  /**
 647   * Add the Create a Site button to the Sites directory title.
 648   *
 649   * The bp-legacy puts the Create a Site button into the page title, to mimic
 650   * the behavior of bp-default.
 651   *
 652   * @since 2.0.0
 653   * @todo Deprecate
 654   *
 655   * @param string $title Sites directory title.
 656   * @return string
 657   */
 658  function bp_legacy_theme_blog_create_button( $title ) {
 659      return $title . ' ' . bp_get_blog_create_button();
 660  }
 661  
 662  /**
 663   * Add the Create a Site nav to the Sites directory navigation.
 664   *
 665   * The bp-legacy puts the Create a Site nav at the last position of
 666   * the Sites directory navigation.
 667   *
 668   * @since 2.2.0
 669   *
 670   */
 671  function bp_legacy_theme_blog_create_nav() {
 672      bp_blog_create_nav_item();
 673  }
 674  
 675  /**
 676   * This function looks scarier than it actually is. :)
 677   * Each object loop (activity/members/groups/blogs/forums) contains default
 678   * parameters to show specific information based on the page we are currently
 679   * looking at.
 680   *
 681   * The following function will take into account any cookies set in the JS and
 682   * allow us to override the parameters sent. That way we can change the results
 683   * returned without reloading the page.
 684   *
 685   * By using cookies we can also make sure that user settings are retained
 686   * across page loads.
 687   *
 688   * @since 1.2.0
 689   *
 690   * @param string $query_string Query string for the current request.
 691   * @param string $object       Object for cookie.
 692   * @return string Query string for the component loops.
 693   */
 694  function bp_legacy_theme_ajax_querystring( $query_string, $object ) {
 695      if ( empty( $object ) )
 696          return '';
 697  
 698      // Set up the cookies passed on this AJAX request. Store a local var to avoid conflicts.
 699      if ( ! empty( $_POST['cookie'] ) ) {
 700          $_BP_COOKIE = wp_parse_args( str_replace( '; ', '&', urldecode( $_POST['cookie'] ) ) );
 701      } else {
 702          $_BP_COOKIE = &$_COOKIE;
 703      }
 704  
 705      $qs = array();
 706  
 707      /**
 708       * Check if any cookie values are set. If there are then override the
 709       * default params passed to the template loop.
 710       */
 711  
 712      // Activity stream filtering on action.
 713      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-filter'] ) && '-1' != $_BP_COOKIE['bp-' . $object . '-filter'] ) {
 714          $qs[] = 'type=' . urlencode( $_BP_COOKIE['bp-' . $object . '-filter'] );
 715  
 716          if ( bp_is_active( 'activity' ) ) {
 717              $actions = bp_activity_get_actions_for_context();
 718  
 719              // Handle multiple actions (eg. 'friendship_accepted,friendship_created')
 720              $action_filter = explode( ',', $_BP_COOKIE['bp-' . $object . '-filter'] );
 721  
 722              // See if action filter matches registered actions. If so, add it to qs.
 723              if ( ! array_diff( $action_filter, wp_list_pluck( $actions, 'key' ) ) ) {
 724                  $qs[] = 'action=' . join( ',', $action_filter );
 725              }
 726          }
 727      }
 728  
 729      if ( ! empty( $_BP_COOKIE['bp-' . $object . '-scope'] ) ) {
 730          if ( 'personal' == $_BP_COOKIE['bp-' . $object . '-scope'] ) {
 731              $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
 732              $qs[] = 'user_id=' . $user_id;
 733          }
 734  
 735          // Activity stream scope only on activity directory.
 736          if ( 'all' != $_BP_COOKIE['bp-' . $object . '-scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() )
 737              $qs[] = 'scope=' . urlencode( $_BP_COOKIE['bp-' . $object . '-scope'] );
 738      }
 739  
 740      // If page and search_terms have been passed via the AJAX post request, use those.
 741      if ( ! empty( $_POST['page'] ) && '-1' != $_POST['page'] )
 742          $qs[] = 'page=' . absint( $_POST['page'] );
 743  
 744      // Excludes activity just posted and avoids duplicate ids.
 745      if ( ! empty( $_POST['exclude_just_posted'] ) ) {
 746          $just_posted = wp_parse_id_list( $_POST['exclude_just_posted'] );
 747          $qs[] = 'exclude=' . implode( ',', $just_posted );
 748      }
 749  
 750      // To get newest activities.
 751      if ( ! empty( $_POST['offset'] ) ) {
 752          $qs[] = 'offset=' . intval( $_POST['offset'] );
 753      }
 754  
 755      $object_search_text = bp_get_search_default_text( $object );
 756      if ( ! empty( $_POST['search_terms'] ) && is_string( $_POST['search_terms'] ) && $object_search_text != $_POST['search_terms'] && 'false' != $_POST['search_terms'] && 'undefined' != $_POST['search_terms'] )
 757          $qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
 758  
 759      // Now pass the querystring to override default values.
 760      $query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
 761  
 762      $object_filter = '';
 763      if ( isset( $_BP_COOKIE['bp-' . $object . '-filter'] ) )
 764          $object_filter = $_BP_COOKIE['bp-' . $object . '-filter'];
 765  
 766      $object_scope = '';
 767      if ( isset( $_BP_COOKIE['bp-' . $object . '-scope'] ) )
 768          $object_scope = $_BP_COOKIE['bp-' . $object . '-scope'];
 769  
 770      $object_page = '';
 771      if ( isset( $_BP_COOKIE['bp-' . $object . '-page'] ) )
 772          $object_page = $_BP_COOKIE['bp-' . $object . '-page'];
 773  
 774      $object_search_terms = '';
 775      if ( isset( $_BP_COOKIE['bp-' . $object . '-search-terms'] ) )
 776          $object_search_terms = $_BP_COOKIE['bp-' . $object . '-search-terms'];
 777  
 778      $object_extras = '';
 779      if ( isset( $_BP_COOKIE['bp-' . $object . '-extras'] ) )
 780          $object_extras = $_BP_COOKIE['bp-' . $object . '-extras'];
 781  
 782      /**
 783       * Filters the AJAX query string for the component loops.
 784       *
 785       * @since 1.7.0
 786       *
 787       * @param string $query_string        The query string we are working with.
 788       * @param string $object              The type of page we are on.
 789       * @param string $object_filter       The current object filter.
 790       * @param string $object_scope        The current object scope.
 791       * @param string $object_page         The current object page.
 792       * @param string $object_search_terms The current object search terms.
 793       * @param string $object_extras       The current object extras.
 794       */
 795      return apply_filters( 'bp_legacy_theme_ajax_querystring', $query_string, $object, $object_filter, $object_scope, $object_page, $object_search_terms, $object_extras );
 796  }
 797  
 798  /**
 799   * Load the template loop for the current object.
 800   *
 801   * @since 1.2.0
 802   *
 803   * @return string|null Prints template loop for the specified object
 804   */
 805  function bp_legacy_theme_object_template_loader() {
 806      if ( ! bp_is_post_request() ) {
 807          return;
 808      }
 809  
 810      // Bail if no object passed.
 811      if ( empty( $_POST['object'] ) ) {
 812          return;
 813      }
 814  
 815      // Sanitize the object.
 816      $object = sanitize_title( $_POST['object'] );
 817  
 818      // Bail if object is not an active component to prevent arbitrary file inclusion.
 819      if ( ! bp_is_active( $object ) ) {
 820          return;
 821      }
 822  
 823      /**
 824       * AJAX requests happen too early to be seen by bp_update_is_directory()
 825       * so we do it manually here to ensure templates load with the correct
 826       * context. Without this check, templates will load the 'single' version
 827       * of themselves rather than the directory version.
 828       */
 829      if ( ! bp_current_action() )
 830          bp_update_is_directory( true, bp_current_component() );
 831  
 832      // The template part can be overridden by the calling JS function.
 833      if ( ! empty( $_POST['template'] ) && 'groups/single/members' === $_POST['template'] ) {
 834          $template_part = 'groups/single/members.php';
 835      } else {
 836          $template_part = $object . '/' . $object . '-loop.php';
 837      }
 838  
 839      $template_path = bp_locate_template( array( $template_part ), false );
 840  
 841      $template_path = apply_filters( 'bp_legacy_object_template_path', $template_path );
 842  
 843      load_template( $template_path );
 844      exit();
 845  }
 846  
 847  /**
 848   * Load messages template loop when searched on the private message page
 849   *
 850   * @since 1.6.0
 851   *
 852   * @return string|null Prints template loop for the Messages component.
 853   */
 854  function bp_legacy_theme_messages_template_loader() {
 855      bp_get_template_part( 'members/single/messages/messages-loop' );
 856      exit();
 857  }
 858  
 859  /**
 860   * Load group invitations loop to handle pagination requests sent via AJAX.
 861   *
 862   * @since 2.0.0
 863   */
 864  function bp_legacy_theme_invite_template_loader() {
 865      bp_get_template_part( 'groups/single/invites-loop' );
 866      exit();
 867  }
 868  
 869  /**
 870   * Load group membership requests loop to handle pagination requests sent via AJAX.
 871   *
 872   * @since 2.0.0
 873   */
 874  function bp_legacy_theme_requests_template_loader() {
 875      bp_get_template_part( 'groups/single/requests-loop' );
 876      exit();
 877  }
 878  
 879  /**
 880   * Load the activity loop template when activity is requested via AJAX.
 881   *
 882   * @since 1.2.0
 883   *
 884   * @return string|null JSON object containing 'contents' (output of the template loop
 885   *                     for the Activity component) and 'feed_url' (URL to the relevant RSS feed).
 886   */
 887  function bp_legacy_theme_activity_template_loader() {
 888      if ( ! bp_is_post_request() ) {
 889          return;
 890      }
 891  
 892      $scope = '';
 893      if ( ! empty( $_POST['scope'] ) )
 894          $scope = $_POST['scope'];
 895  
 896      // We need to calculate and return the feed URL for each scope.
 897      switch ( $scope ) {
 898          case 'friends':
 899              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/friends/feed/';
 900              break;
 901          case 'groups':
 902              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/';
 903              break;
 904          case 'favorites':
 905              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/feed/';
 906              break;
 907          case 'mentions':
 908              $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/';
 909  
 910              if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) {
 911                  bp_activity_clear_new_mentions( bp_loggedin_user_id() );
 912              }
 913  
 914              break;
 915          default:
 916              $feed_url = home_url( bp_get_activity_root_slug() . '/feed/' );
 917              break;
 918      }
 919  
 920      // Buffer the loop in the template to a var for JS to spit out.
 921      ob_start();
 922      bp_get_template_part( 'activity/activity-loop' );
 923      $result['contents'] = ob_get_contents();
 924  
 925      /**
 926       * Filters the feed URL for when activity is requested via AJAX.
 927       *
 928       * @since 1.7.0
 929       *
 930       * @param string $feed_url URL for the feed to be used.
 931       * @param string $scope    Scope for the activity request.
 932       */
 933      $result['feed_url'] = apply_filters( 'bp_legacy_theme_activity_feed_url', $feed_url, $scope );
 934      ob_end_clean();
 935  
 936      exit( json_encode( $result ) );
 937  }
 938  
 939  /**
 940   * Processes Activity updates received via a POST request.
 941   *
 942   * @since 1.2.0
 943   *
 944   * @return string|null HTML
 945   */
 946  function bp_legacy_theme_post_update() {
 947      $bp = buddypress();
 948  
 949      if ( ! bp_is_post_request() ) {
 950          return;
 951      }
 952  
 953      // Check the nonce.
 954      check_admin_referer( 'post_update', '_wpnonce_post_update' );
 955  
 956      if ( ! is_user_logged_in() )
 957          exit( '-1' );
 958  
 959      if ( empty( $_POST['content'] ) )
 960          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'Please enter some content to post.', 'buddypress' ) . '</p></div>' );
 961  
 962      $activity_id = 0;
 963      $item_id     = 0;
 964      $object      = '';
 965  
 966  
 967      // Try to get the item id from posted variables.
 968      if ( ! empty( $_POST['item_id'] ) ) {
 969          $item_id = (int) $_POST['item_id'];
 970      }
 971  
 972      // Try to get the object from posted variables.
 973      if ( ! empty( $_POST['object'] ) ) {
 974          $object  = sanitize_key( $_POST['object'] );
 975  
 976      // If the object is not set and we're in a group, set the item id and the object
 977      } elseif ( bp_is_group() ) {
 978          $item_id = bp_get_current_group_id();
 979          $object = 'groups';
 980      }
 981  
 982      if ( ! $object && bp_is_active( 'activity' ) ) {
 983          $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) );
 984  
 985      } elseif ( 'groups' === $object ) {
 986          if ( $item_id && bp_is_active( 'groups' ) )
 987              $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) );
 988  
 989      } else {
 990  
 991          /** This filter is documented in bp-activity/actions/post.php */
 992          $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] );
 993      }
 994  
 995      if ( false === $activity_id ) {
 996          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' );
 997      } elseif ( is_wp_error( $activity_id ) && $activity_id->get_error_code() ) {
 998          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' );
 999      }
1000  
1001      $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0;
1002      if ( $last_recorded ) {
1003          $activity_args = array( 'since' => $last_recorded );
1004          $bp->activity->last_recorded = $last_recorded;
1005          add_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
1006      } else {
1007          $activity_args = array( 'include' => $activity_id );
1008      }
1009  
1010      if ( bp_has_activities ( $activity_args ) ) {
1011          while ( bp_activities() ) {
1012              bp_the_activity();
1013              bp_get_template_part( 'activity/entry' );
1014          }
1015      }
1016  
1017      if ( ! empty( $last_recorded ) ) {
1018          remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10 );
1019      }
1020  
1021      exit;
1022  }
1023  
1024  /**
1025   * Posts new Activity comments received via a POST request.
1026   *
1027   * @since 1.2.0
1028   *
1029   * @global BP_Activity_Template $activities_template
1030   *
1031   * @return string|null HTML
1032   */
1033  function bp_legacy_theme_new_activity_comment() {
1034      global $activities_template;
1035  
1036      $bp = buddypress();
1037  
1038      if ( ! bp_is_post_request() ) {
1039          return;
1040      }
1041  
1042      // Check the nonce.
1043      check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
1044  
1045      if ( ! is_user_logged_in() ) {
1046          exit( '-1' );
1047      }
1048  
1049      $feedback = __( 'There was an error posting your reply. Please try again.', 'buddypress' );
1050  
1051      if ( empty( $_POST['content'] ) ) {
1052          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html__( 'Please do not leave the comment area blank.', 'buddypress' ) . '</p></div>' );
1053      }
1054  
1055      if ( empty( $_POST['form_id'] ) || empty( $_POST['comment_id'] ) || ! is_numeric( $_POST['form_id'] ) || ! is_numeric( $_POST['comment_id'] ) ) {
1056          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1057      }
1058  
1059      $activity_id   = (int) $_POST['form_id'];
1060      $activity_item = new BP_Activity_Activity( $activity_id );
1061      if ( ! bp_activity_user_can_read( $activity_item ) ) {
1062          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $feedback ) . '</p></div>' );
1063      }
1064  
1065      $comment_id = bp_activity_new_comment( array(
1066          'activity_id' => $activity_id,
1067          'content'     => $_POST['content'],
1068          'parent_id'   => $_POST['comment_id'],
1069          'error_type'  => 'wp_error'
1070      ) );
1071  
1072      if ( is_wp_error( $comment_id ) ) {
1073          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . esc_html( $comment_id->get_error_message() ) . '</p></div>' );
1074      }
1075  
1076      // Load the new activity item into the $activities_template global.
1077      bp_has_activities( 'display_comments=stream&hide_spam=false&show_hidden=true&include=' . $comment_id );
1078  
1079      // Swap the current comment with the activity item we just loaded.
1080      if ( isset( $activities_template->activities[0] ) ) {
1081          $activities_template->activity = new stdClass();
1082          $activities_template->activity->id              = $activities_template->activities[0]->item_id;
1083          $activities_template->activity->current_comment = $activities_template->activities[0];
1084  
1085          // Because the whole tree has not been loaded, we manually
1086          // determine depth.
1087          $depth = 1;
1088          $parent_id = (int) $activities_template->activities[0]->secondary_item_id;
1089          while ( $parent_id !== (int) $activities_template->activities[0]->item_id ) {
1090              $depth++;
1091              $p_obj = new BP_Activity_Activity( $parent_id );
1092              $parent_id = (int) $p_obj->secondary_item_id;
1093          }
1094          $activities_template->activity->current_comment->depth = $depth;
1095      }
1096  
1097      // Get activity comment template part.
1098      bp_get_template_part( 'activity/comment' );
1099  
1100      unset( $activities_template );
1101      exit;
1102  }
1103  
1104  /**
1105   * Deletes an Activity item received via a POST request.
1106   *
1107   * @since 1.2.0
1108   *
1109   * @return mixed String on error, void on success.
1110   */
1111  function bp_legacy_theme_delete_activity() {
1112      if ( ! bp_is_post_request() ) {
1113          return;
1114      }
1115  
1116      // Check the nonce.
1117      check_admin_referer( 'bp_activity_delete_link' );
1118  
1119      if ( ! is_user_logged_in() )
1120          exit( '-1' );
1121  
1122      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1123          exit( '-1' );
1124  
1125      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1126  
1127      // Check access.
1128      if ( ! bp_activity_user_can_delete( $activity ) )
1129          exit( '-1' );
1130  
1131      /** This action is documented in bp-activity/bp-activity-actions.php */
1132      do_action( 'bp_activity_before_action_delete_activity', $activity->id, $activity->user_id );
1133  
1134      if ( ! bp_activity_delete( array( 'id' => $activity->id, 'user_id' => $activity->user_id ) ) )
1135          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1136  
1137      /** This action is documented in bp-activity/bp-activity-actions.php */
1138      do_action( 'bp_activity_action_delete_activity', $activity->id, $activity->user_id );
1139      exit;
1140  }
1141  
1142  /**
1143   * Deletes an Activity comment received via a POST request.
1144   *
1145   * @since 1.2.0
1146   *
1147   * @return mixed String on error, void on success.
1148   */
1149  function bp_legacy_theme_delete_activity_comment() {
1150      if ( ! bp_is_post_request() ) {
1151          return;
1152      }
1153  
1154      // Check the nonce.
1155      check_admin_referer( 'bp_activity_delete_link' );
1156  
1157      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) ) {
1158          exit( '-1' );
1159      }
1160  
1161      if ( ! is_user_logged_in() ) {
1162          exit( '-1' );
1163      }
1164  
1165      $comment = new BP_Activity_Activity( $_POST['id'] );
1166  
1167      // Check access.
1168      if ( ! bp_current_user_can( 'bp_moderate' ) && $comment->user_id != bp_loggedin_user_id() )
1169          exit( '-1' );
1170  
1171      /** This action is documented in bp-activity/bp-activity-actions.php */
1172      do_action( 'bp_activity_before_action_delete_activity', $_POST['id'], $comment->user_id );
1173  
1174      if ( ! bp_activity_delete_comment( $comment->item_id, $comment->id ) )
1175          exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem when deleting. Please try again.', 'buddypress' ) . '</p></div>' );
1176  
1177      /** This action is documented in bp-activity/bp-activity-actions.php */
1178      do_action( 'bp_activity_action_delete_activity', $_POST['id'], $comment->user_id );
1179      exit;
1180  }
1181  
1182  /**
1183   * AJAX spam an activity item or comment.
1184   *
1185   * @since 1.6.0
1186   *
1187   * @return mixed String on error, void on success.
1188   */
1189  function bp_legacy_theme_spam_activity() {
1190      $bp = buddypress();
1191  
1192      if ( ! bp_is_post_request() ) {
1193          return;
1194      }
1195  
1196      // Check that user is logged in, Activity Streams are enabled, and Akismet is present.
1197      if ( ! is_user_logged_in() || ! bp_is_active( 'activity' ) || empty( $bp->activity->akismet ) )
1198          exit( '-1' );
1199  
1200      // Check an item ID was passed.
1201      if ( empty( $_POST['id'] ) || ! is_numeric( $_POST['id'] ) )
1202          exit( '-1' );
1203  
1204      // Is the current user allowed to spam items?
1205      if ( ! bp_activity_user_can_mark_spam() )
1206          exit( '-1' );
1207  
1208      // Load up the activity item.
1209      $activity = new BP_Activity_Activity( (int) $_POST['id'] );
1210      if ( empty( $activity->component ) )
1211          exit( '-1' );
1212  
1213      // Check nonce.
1214      check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
1215  
1216      /** This action is documented in bp-activity/bp-activity-actions.php */
1217      do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
1218  
1219      // Mark as spam.
1220      bp_activity_mark_as_spam( $activity );
1221      $activity->save();
1222  
1223      /** This action is documented in bp-activity/bp-activity-actions.php */
1224      do_action( 'bp_activity_action_spam_activity', $activity->id, $activity->user_id );
1225      exit;
1226  }
1227  
1228  /**
1229   * Mark an activity as a favourite via a POST request.
1230   *
1231   * @since 1.2.0
1232   *
1233   * @return string|null HTML
1234   */
1235  function bp_legacy_theme_mark_activity_favorite() {
1236      // Bail if not a POST action.
1237      if ( ! bp_is_post_request() ) {
1238          return;
1239      }
1240  
1241      if ( ! isset( $_POST['nonce'] ) ) {
1242          return;
1243      }
1244  
1245      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1246      $nonce = wp_unslash( $_POST['nonce'] );
1247      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1248          return;
1249      }
1250  
1251      $activity_id   = (int) $_POST['id'];
1252      $activity_item = new BP_Activity_Activity( $activity_id );
1253      if ( ! bp_activity_user_can_read( $activity_item, bp_loggedin_user_id() ) ) {
1254          return;
1255      }
1256  
1257      if ( bp_activity_add_user_favorite( $_POST['id'] ) )
1258          _e( 'Remove Favorite', 'buddypress' );
1259      else
1260          _e( 'Favorite', 'buddypress' );
1261  
1262      exit;
1263  }
1264  
1265  /**
1266   * Un-favourite an activity via a POST request.
1267   *
1268   * @since 1.2.0
1269   *
1270   * @return string|null HTML
1271   */
1272  function bp_legacy_theme_unmark_activity_favorite() {
1273      if ( ! bp_is_post_request() ) {
1274          return;
1275      }
1276  
1277      if ( ! isset( $_POST['nonce'] ) ) {
1278          return;
1279      }
1280  
1281      // Either the 'mark' or 'unmark' nonce is accepted, for backward compatibility.
1282      $nonce = wp_unslash( $_POST['nonce'] );
1283      if ( ! wp_verify_nonce( $nonce, 'mark_favorite' ) && ! wp_verify_nonce( $nonce, 'unmark_favorite' ) ) {
1284          return;
1285      }
1286  
1287      if ( bp_activity_remove_user_favorite( $_POST['id'] ) )
1288          _e( 'Favorite', 'buddypress' );
1289      else
1290          _e( 'Remove Favorite', 'buddypress' );
1291  
1292      exit;
1293  }
1294  
1295  /**
1296   * Fetches an activity's full, non-excerpted content via a POST request.
1297   * Used for the 'Read More' link on long activity items.
1298   *
1299   * @since 1.5.0
1300   *
1301   * @return string|null HTML
1302   */
1303  function bp_legacy_theme_get_single_activity_content() {
1304      if ( ! bp_is_post_request() ) {
1305          return;
1306      }
1307  
1308      $activity_array = bp_activity_get_specific( array(
1309          'activity_ids'     => $_POST['activity_id'],
1310          'display_comments' => 'stream'
1311      ) );
1312  
1313      $activity = ! empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
1314  
1315      if ( empty( $activity ) )
1316          exit; // @todo: error?
1317  
1318      /**
1319       * Fires before the return of an activity's full, non-excerpted content via a POST request.
1320       *
1321       * @since 1.7.0
1322       *
1323       * @param string $activity Activity content. Passed by reference.
1324       */
1325      do_action_ref_array( 'bp_legacy_theme_get_single_activity_content', array( &$activity ) );
1326  
1327      // Activity content retrieved through AJAX should run through normal filters, but not be truncated.
1328      remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
1329  
1330      /** This filter is documented in bp-activity/bp-activity-template.php */
1331      $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) );
1332  
1333      exit( $content );
1334  }
1335  
1336  /**
1337   * Invites a friend to join a group via a POST request.
1338   *
1339   * @since 1.2.0
1340   *
1341   * @todo Audit return types
1342   */
1343  function bp_legacy_theme_ajax_invite_user() {
1344      if ( ! bp_is_post_request() ) {
1345          return;
1346      }
1347  
1348      check_ajax_referer( 'groups_invite_uninvite_user' );
1349  
1350      if ( ! $_POST['friend_id'] || ! $_POST['friend_action'] || ! $_POST['group_id'] )
1351          return;
1352  
1353      if ( ! bp_groups_user_can_send_invites( $_POST['group_id'] ) )
1354          return;
1355  
1356      $group_id = (int) $_POST['group_id'];
1357      $friend_id = (int) $_POST['friend_id'];
1358  
1359      if ( 'invite' == $_POST['friend_action'] ) {
1360          if ( ! friends_check_friendship( bp_loggedin_user_id(), $_POST['friend_id'] ) ) {
1361              return;
1362          }
1363  
1364          $group = groups_get_group( $group_id );
1365  
1366          // Users who have previously requested membership do not need
1367          // another invitation created for them.
1368          if ( groups_check_for_membership_request( $friend_id, $group_id ) ) {
1369              $user_status = 'is_pending';
1370  
1371          // Create the user invitation.
1372          } elseif ( groups_invite_user( array( 'user_id' => $friend_id, 'group_id' => $group_id ) ) ) {
1373              $user_status = 'is_invited';
1374  
1375          // Miscellaneous failure.
1376          } else {
1377              return;
1378          }
1379  
1380          $user = new BP_Core_User( $friend_id );
1381  
1382          $uninvite_url = bp_is_current_action( 'create' )
1383              ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id
1384              : bp_get_group_permalink( $group )    . 'send-invites/remove/' . $friend_id;
1385  
1386          echo '<li id="uid-' . esc_attr( $user->id ) . '">';
1387          echo $user->avatar_thumb;
1388          echo '<h4>' . $user->user_link . '</h4>';
1389          echo '<span class="activity">' . esc_attr( $user->last_active ) . '</span>';
1390          echo '<div class="action">
1391                  <a class="button remove" href="' . wp_nonce_url( $uninvite_url, 'groups_invite_uninvite_user' ) . '" id="uid-' . esc_attr( $user->id ) . '">' . __( 'Remove Invite', 'buddypress' ) . '</a>
1392                </div>';
1393  
1394          if ( 'is_pending' == $user_status ) {
1395              echo '<p class="description">' . sprintf( __( '%s has previously requested to join this group. Sending an invitation will automatically add the member to the group.', 'buddypress' ), $user->user_link ) . '</p>';
1396          }
1397  
1398          echo '</li>';
1399          exit;
1400  
1401      } elseif ( 'uninvite' == $_POST['friend_action'] ) {
1402          // Users who have previously requested membership should not
1403          // have their requests deleted on the "uninvite" action.
1404          if ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
1405              return;
1406          }
1407  
1408          // Remove the unsent invitation.
1409          if ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
1410              return;
1411          }
1412  
1413          exit;
1414  
1415      } else {
1416          return;
1417      }
1418  }
1419  
1420  /**
1421   * Friend/un-friend a user via a POST request.
1422   *
1423   * @since 1.2.0
1424   *
1425   * @return string|null HTML
1426   */
1427  function bp_legacy_theme_ajax_addremove_friend() {
1428      if ( ! bp_is_post_request() ) {
1429          return;
1430      }
1431  
1432      // Cast fid as an integer.
1433      $friend_id = (int) $_POST['fid'];
1434  
1435      $user = get_user_by( 'id', $friend_id );
1436      if ( ! $user ) {
1437          die( __( 'No member found by that ID.', 'buddypress' ) );
1438      }
1439  
1440      // Trying to cancel friendship.
1441      if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1442          check_ajax_referer( 'friends_remove_friend' );
1443  
1444          if ( ! friends_remove_friend( bp_loggedin_user_id(), $friend_id ) ) {
1445              echo __( 'Friendship could not be canceled.', 'buddypress' );
1446          } else {
1447              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
1448          }
1449  
1450      // Trying to request friendship.
1451      } elseif ( 'not_friends' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1452          check_ajax_referer( 'friends_add_friend' );
1453  
1454          if ( ! friends_add_friend( bp_loggedin_user_id(), $friend_id ) ) {
1455              echo __(' Friendship could not be requested.', 'buddypress' );
1456          } else {
1457              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="remove friendship-button pending_friend requested" rel="remove" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $friend_id . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
1458          }
1459  
1460      // Trying to cancel pending request.
1461      } elseif ( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $friend_id ) ) {
1462          check_ajax_referer( 'friends_withdraw_friendship' );
1463  
1464          if ( friends_withdraw_friendship( bp_loggedin_user_id(), $friend_id ) ) {
1465              echo '<a id="friend-' . esc_attr( $friend_id ) . '" class="friendship-button not_friends add" rel="add" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
1466          } else {
1467              echo __("Friendship request could not be cancelled.", 'buddypress');
1468          }
1469  
1470      // Request already pending.
1471      } else {
1472          echo __( 'Request Pending', 'buddypress' );
1473      }
1474  
1475      exit;
1476  }
1477  
1478  /**
1479   * Accept a user friendship request via a POST request.
1480   *
1481   * @since 1.2.0
1482   *
1483   * @return mixed String on error, void on success.
1484   */
1485  function bp_legacy_theme_ajax_accept_friendship() {
1486      if ( ! bp_is_post_request() ) {
1487          return;
1488      }
1489  
1490      check_admin_referer( 'friends_accept_friendship' );
1491  
1492      if ( ! friends_accept_friendship( (int) $_POST['id'] ) )
1493          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem accepting that request. Please try again.', 'buddypress' ) . '</p></div>';
1494  
1495      exit;
1496  }
1497  
1498  /**
1499   * Reject a user friendship request via a POST request.
1500   *
1501   * @since 1.2.0
1502   *
1503   * @return mixed String on error, void on success.
1504   */
1505  function bp_legacy_theme_ajax_reject_friendship() {
1506      if ( ! bp_is_post_request() ) {
1507          return;
1508      }
1509  
1510      check_admin_referer( 'friends_reject_friendship' );
1511  
1512      if ( ! friends_reject_friendship( (int) $_POST['id'] ) )
1513          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem rejecting that request. Please try again.', 'buddypress' ) . '</p></div>';
1514  
1515      exit;
1516  }
1517  
1518  /**
1519   * Join or leave a group when clicking the "join/leave" button via a POST request.
1520   *
1521   * @since 1.2.0
1522   *
1523   * @return string|null HTML
1524   */
1525  function bp_legacy_theme_ajax_joinleave_group() {
1526      if ( ! bp_is_post_request() ) {
1527          return;
1528      }
1529  
1530      // Cast gid as integer.
1531      $group_id = (int) $_POST['gid'];
1532  
1533      if ( groups_is_user_banned( bp_loggedin_user_id(), $group_id ) )
1534          return;
1535  
1536      if ( ! $group = groups_get_group( $group_id ) )
1537          return;
1538  
1539      // Client doesn't distinguish between different request types, so we infer from user status.
1540      if ( groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
1541          $request_type = 'leave_group';
1542      } elseif ( groups_check_user_has_invite( bp_loggedin_user_id(), $group->id ) ) {
1543          $request_type = 'accept_invite';
1544      } elseif ( 'private' === $group->status ) {
1545          $request_type = 'request_membership';
1546      } else {
1547          $request_type = 'join_group';
1548      }
1549  
1550      switch ( $request_type ) {
1551          case 'join_group' :
1552              if ( ! bp_current_user_can( 'groups_join_group', array( 'group_id' => $group->id ) ) ) {
1553                  esc_html_e( 'Error joining group', 'buddypress' );
1554              }
1555  
1556              check_ajax_referer( 'groups_join_group' );
1557  
1558              if ( ! groups_join_group( $group->id ) ) {
1559                  _e( 'Error joining group', 'buddypress' );
1560              } else {
1561                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
1562              }
1563          break;
1564  
1565          case 'accept_invite' :
1566              if ( ! bp_current_user_can( 'groups_request_membership', array( 'group_id' => $group->id ) ) ) {
1567                  esc_html_e( 'Error accepting invitation', 'buddypress' );
1568              }
1569  
1570              check_ajax_referer( 'groups_accept_invite' );
1571  
1572              if ( ! groups_accept_invite( bp_loggedin_user_id(), $group->id ) ) {
1573                  _e( 'Error requesting membership', 'buddypress' );
1574              } else {
1575                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button leave-group" rel="leave" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ) . '">' . __( 'Leave Group', 'buddypress' ) . '</a>';
1576              }
1577          break;
1578  
1579          case 'request_membership' :
1580              check_ajax_referer( 'groups_request_membership' );
1581  
1582              if ( ! groups_send_membership_request( bp_loggedin_user_id(), $group->id ) ) {
1583                  _e( 'Error requesting membership', 'buddypress' );
1584              } else {
1585                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button disabled pending membership-requested" rel="membership-requested" href="' . bp_get_group_permalink( $group ) . '">' . __( 'Request Sent', 'buddypress' ) . '</a>';
1586              }
1587          break;
1588  
1589          case 'leave_group' :
1590              check_ajax_referer( 'groups_leave_group' );
1591  
1592              if ( ! groups_leave_group( $group->id ) ) {
1593                  _e( 'Error leaving group', 'buddypress' );
1594              } elseif ( 'public' === $group->status ) {
1595                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button join-group" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ) . '">' . __( 'Join Group', 'buddypress' ) . '</a>';
1596              } else {
1597                  echo '<a id="group-' . esc_attr( $group->id ) . '" class="group-button request-membership" rel="join" href="' . wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ) . '">' . __( 'Request Membership', 'buddypress' ) . '</a>';
1598              }
1599          break;
1600      }
1601  
1602      exit;
1603  }
1604  
1605  /**
1606   * Close and keep closed site wide notices from an admin in the sidebar, via a POST request.
1607   *
1608   * @since 1.2.0
1609   *
1610   * @return mixed String on error, void on success.
1611   */
1612  function bp_legacy_theme_ajax_close_notice() {
1613      if ( ! bp_is_post_request() ) {
1614          return;
1615      }
1616  
1617      $nonce_check = isset( $_POST['nonce'] ) && wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'bp_messages_close_notice' );
1618  
1619      if ( ! $nonce_check || ! isset( $_POST['notice_id'] ) ) {
1620          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem closing the notice.', 'buddypress' ) . '</p></div>';
1621  
1622      } else {
1623          $user_id    = get_current_user_id();
1624          $notice_ids = bp_get_user_meta( $user_id, 'closed_notices', true );
1625          if ( ! is_array( $notice_ids ) ) {
1626              $notice_ids = array();
1627          }
1628  
1629          $notice_ids[] = (int) $_POST['notice_id'];
1630  
1631          bp_update_user_meta( $user_id, 'closed_notices', $notice_ids );
1632      }
1633  
1634      exit;
1635  }
1636  
1637  /**
1638   * Send a private message reply to a thread via a POST request.
1639   *
1640   * @since 1.2.0
1641   *
1642   * @return string|null HTML
1643   */
1644  function bp_legacy_theme_ajax_messages_send_reply() {
1645      if ( ! bp_is_post_request() ) {
1646          return;
1647      }
1648  
1649      check_ajax_referer( 'messages_send_message' );
1650  
1651      $thread_id = (int) $_POST['thread_id'];
1652  
1653      // Cannot respond to a thread you're not already a recipient on.
1654      if ( ! bp_current_user_can( 'bp_moderate' ) && ( ! messages_is_valid_thread( $thread_id ) || ! messages_check_thread_access( $thread_id ) ) ) {
1655          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1656          die;
1657      }
1658  
1659      $result = messages_new_message( array( 'thread_id' => $thread_id, 'content' => $_REQUEST['content'] ) );
1660  
1661      if ( !empty( $result ) ) {
1662  
1663          // Pretend we're in the message loop.
1664          global $thread_template;
1665  
1666          bp_thread_has_messages( array( 'thread_id' => $thread_id ) );
1667  
1668          // Set the current message to the 2nd last.
1669          $thread_template->message = end( $thread_template->thread->messages );
1670          $thread_template->message = prev( $thread_template->thread->messages );
1671  
1672          // Set current message to current key.
1673          $thread_template->current_message = key( $thread_template->thread->messages );
1674  
1675          // Now manually iterate message like we're in the loop.
1676          bp_thread_the_message();
1677  
1678          // Manually call oEmbed
1679          // this is needed because we're not at the beginning of the loop.
1680          bp_messages_embed();
1681  
1682          // Add new-message css class.
1683          add_filter( 'bp_get_the_thread_message_css_class', function( $retval ) {
1684              $retval[] = 'new-message';
1685              return $retval;
1686          } );
1687  
1688          // Output single message template part.
1689          bp_get_template_part( 'members/single/messages/message' );
1690  
1691          // Clean up the loop.
1692          bp_thread_messages();
1693  
1694      } else {
1695          echo "-1<div id='message' class='error'><p>" . __( 'There was a problem sending that reply. Please try again.', 'buddypress' ) . '</p></div>';
1696      }
1697  
1698      exit;
1699  }
1700  
1701  /**
1702   * Mark a private message as unread in your inbox via a POST request.
1703   *
1704   * No longer used.
1705   *
1706   * @since 1.2.0
1707   * @deprecated 2.2.0
1708   *
1709   * @return mixed String on error, void on success.
1710   */
1711  function bp_legacy_theme_ajax_message_markunread() {
1712      die( '-1' );
1713  }
1714  
1715  /**
1716   * Mark a private message as read in your inbox via a POST request.
1717   *
1718   * No longer used.
1719   *
1720   * @since 1.2.0
1721   * @deprecated 2.2.0
1722   *
1723   * @return mixed String on error, void on success.
1724   */
1725  function bp_legacy_theme_ajax_message_markread() {
1726      die( '-1' );
1727  }
1728  
1729  /**
1730   * Delete a private message(s) in your inbox via a POST request.
1731   *
1732   * No longer used.
1733   *
1734   * @since 1.2.0
1735   * @deprecated 2.2.0
1736   *
1737   * @return string|null HTML
1738   */
1739  function bp_legacy_theme_ajax_messages_delete() {
1740      die( '-1' );
1741  }
1742  
1743  /**
1744   * AJAX handler for autocomplete.
1745   *
1746   * Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
1747   *
1748   * @since 1.2.0
1749   */
1750  function bp_legacy_theme_ajax_messages_autocomplete_results() {
1751  
1752      /**
1753       * Filters the max results default value for ajax messages autocomplete results.
1754       *
1755       * @since 1.5.0
1756       *
1757       * @param int $value Max results for autocomplete. Default 10.
1758       */
1759      $limit = isset( $_GET['limit'] ) ? absint( $_GET['limit'] )          : (int) apply_filters( 'bp_autocomplete_max_results', 10 );
1760      $term  = isset( $_GET['q'] )     ? sanitize_text_field( $_GET['q'] ) : '';
1761  
1762      // Include everyone in the autocomplete, or just friends?
1763      if ( bp_is_current_component( bp_get_messages_slug() ) ) {
1764          $only_friends = ( buddypress()->messages->autocomplete_all === false );
1765      } else {
1766          $only_friends = true;
1767      }
1768  
1769      $suggestions = bp_core_get_suggestions( array(
1770          'limit'        => $limit,
1771          'only_friends' => $only_friends,
1772          'term'         => $term,
1773          'type'         => 'members',
1774      ) );
1775  
1776      if ( $suggestions && ! is_wp_error( $suggestions ) ) {
1777          foreach ( $suggestions as $user ) {
1778  
1779              // Note that the final line break acts as a delimiter for the
1780              // autocomplete JavaScript and thus should not be removed.
1781              printf( '<span id="%s" href="#"></span><img src="%s" style="width: 15px"> &nbsp; %s (%s)' . "\n",
1782                  esc_attr( 'link-' . $user->ID ),
1783                  esc_url( $user->image ),
1784                  esc_html( $user->name ),
1785                  esc_html( $user->ID )
1786              );
1787          }
1788      }
1789  
1790      exit;
1791  }
1792  
1793  /**
1794   * AJAX callback to set a message's star status.
1795   *
1796   * @since 2.3.0
1797   */
1798  function bp_legacy_theme_ajax_messages_star_handler() {
1799      if ( false === bp_is_active( 'messages', 'star' ) || empty( $_POST['message_id'] ) ) {
1800          return;
1801      }
1802  
1803      // Check nonce.
1804      check_ajax_referer( 'bp-messages-star-' . (int) $_POST['message_id'], 'nonce' );
1805  
1806      // Check capability.
1807      if ( ! is_user_logged_in() || ! bp_core_can_edit_settings() ) {
1808          return;
1809      }
1810  
1811      if ( true === bp_messages_star_set_action( array(
1812          'action'     => $_POST['star_status'],
1813          'message_id' => (int) $_POST['message_id'],
1814          'bulk'       => ! empty( $_POST['bulk'] ) ? true : false
1815       ) ) ) {
1816          echo '1';
1817          die();
1818      }
1819  
1820      echo '-1';
1821      die();
1822  }
1823  
1824  /**
1825   * BP Legacy's callback for the cover image feature.
1826   *
1827   * @since  2.4.0
1828   *
1829   * @param  array $params the current component's feature parameters.
1830   * @return null|string An array to inform about the css handle to attach the css rules to
1831   */
1832  function bp_legacy_theme_cover_image( $params = array() ) {
1833      if ( empty( $params ) ) {
1834          return;
1835      }
1836  
1837      // Avatar height - padding - 1/2 avatar height.
1838      $avatar_offset = $params['height'] - 5 - round( (int) bp_core_avatar_full_height() / 2 );
1839  
1840      // Header content offset + spacing.
1841      $top_offset  = bp_core_avatar_full_height() - 10;
1842      $left_offset = bp_core_avatar_full_width() + 20;
1843  
1844      $cover_image = ( !empty( $params['cover_image'] ) ) ? 'background-image: url(' . $params['cover_image'] . ');' : '';
1845  
1846      $hide_avatar_style = '';
1847  
1848      // Adjust the cover image header, in case avatars are completely disabled.
1849      if ( ! buddypress()->avatar->show_avatars ) {
1850          $hide_avatar_style = '
1851              #buddypress #item-header-cover-image #item-header-avatar {
1852                  display:  none;
1853              }
1854          ';
1855  
1856          if ( bp_is_user() ) {
1857              $hide_avatar_style = '
1858                  #buddypress #item-header-cover-image #item-header-avatar a {
1859                      display: block;
1860                      height: ' . $top_offset . 'px;
1861                      margin: 0 15px 19px 0;
1862                  }
1863  
1864                  #buddypress div#item-header #item-header-cover-image #item-header-content {
1865                      margin-left: auto;
1866                  }
1867              ';
1868          }
1869      }
1870  
1871      return '
1872          /* Cover image */
1873          #buddypress #header-cover-image {
1874              height: ' . $params["height"] . 'px;
1875              ' . $cover_image . '
1876          }
1877  
1878          #buddypress #create-group-form #header-cover-image {
1879              margin: 1em 0;
1880              position: relative;
1881          }
1882  
1883          .bp-user #buddypress #item-header {
1884              padding-top: 0;
1885          }
1886  
1887          #buddypress #item-header-cover-image #item-header-avatar {
1888              margin-top: '. $avatar_offset .'px;
1889              float: left;
1890              overflow: visible;
1891              width: auto;
1892          }
1893  
1894          #buddypress div#item-header #item-header-cover-image #item-header-content {
1895              clear: both;
1896              float: left;
1897              margin-left: ' . $left_offset . 'px;
1898              margin-top: -' . $top_offset . 'px;
1899              width: auto;
1900          }
1901  
1902          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1903          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1904              clear: none;
1905              margin-top: ' . $params["height"] . 'px;
1906              margin-left: 0;
1907              max-width: 50%;
1908          }
1909  
1910          body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1911              max-width: 20%;
1912              padding-top: 20px;
1913          }
1914  
1915          ' . $hide_avatar_style . '
1916  
1917          #buddypress div#item-header-cover-image .user-nicename a,
1918          #buddypress div#item-header-cover-image .user-nicename {
1919              font-size: 200%;
1920              color: #fff;
1921              margin: 0 0 0.6em;
1922              text-rendering: optimizelegibility;
1923              text-shadow: 0 0 3px rgba( 0, 0, 0, 0.8 );
1924          }
1925  
1926          #buddypress #item-header-cover-image #item-header-avatar img.avatar {
1927              background: rgba( 255, 255, 255, 0.8 );
1928              border: solid 2px #fff;
1929          }
1930  
1931          #buddypress #item-header-cover-image #item-header-avatar a {
1932              border: 0;
1933              text-decoration: none;
1934          }
1935  
1936          #buddypress #item-header-cover-image #item-buttons {
1937              margin: 0 0 10px;
1938              padding: 0 0 5px;
1939          }
1940  
1941          #buddypress #item-header-cover-image #item-buttons:after {
1942              clear: both;
1943              content: "";
1944              display: table;
1945          }
1946  
1947          @media screen and (max-width: 782px) {
1948              #buddypress #item-header-cover-image #item-header-avatar,
1949              .bp-user #buddypress #item-header #item-header-cover-image #item-header-avatar,
1950              #buddypress div#item-header #item-header-cover-image #item-header-content {
1951                  width: 100%;
1952                  text-align: center;
1953              }
1954  
1955              #buddypress #item-header-cover-image #item-header-avatar a {
1956                  display: inline-block;
1957              }
1958  
1959              #buddypress #item-header-cover-image #item-header-avatar img {
1960                  margin: 0;
1961              }
1962  
1963              #buddypress div#item-header #item-header-cover-image #item-header-content,
1964              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1965              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1966                  margin: 0;
1967              }
1968  
1969              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-header-content,
1970              body.single-item.groups #buddypress div#item-header #item-header-cover-image #item-actions {
1971                  max-width: 100%;
1972              }
1973  
1974              #buddypress div#item-header-cover-image h2 a,
1975              #buddypress div#item-header-cover-image h2 {
1976                  color: inherit;
1977                  text-shadow: none;
1978                  margin: 25px 0 0;
1979                  font-size: 200%;
1980              }
1981  
1982              #buddypress #item-header-cover-image #item-buttons div {
1983                  float: none;
1984                  display: inline-block;
1985              }
1986  
1987              #buddypress #item-header-cover-image #item-buttons:before {
1988                  content: "";
1989              }
1990  
1991              #buddypress #item-header-cover-image #item-buttons {
1992                  margin: 5px 0;
1993              }
1994          }
1995      ';
1996  }
1997  
1998  /**
1999   * Add a search box to a single group's manage members screen.
2000   *
2001   * @since 2.7.0
2002   *
2003   * @return string|null HTML for the search form.
2004   */
2005  function bp_legacy_theme_group_manage_members_add_search() {
2006      if ( bp_is_action_variable( 'manage-members' ) ) :
2007          ?>
2008          <div id="members-dir-search" class="dir-search no-ajax" role="search">
2009              <?php bp_directory_members_search_form(); ?>
2010          </div>
2011          <?php
2012      endif;
2013  }


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1