'',
'scope' => 'all',
'page' => 1,
'search_terms' => '',
'extras' => '',
);
if ( ! empty( $_POST ) ) {
$post_query = bp_parse_args(
$_POST,
$post_query,
'nouveau_ajax_querystring'
);
// Make sure to transport the scope, filter etc.. in HeartBeat Requests
if ( ! empty( $post_query['data']['bp_heartbeat'] ) ) {
$bp_heartbeat = $post_query['data']['bp_heartbeat'];
// Remove heartbeat specific vars
$post_query = array_diff_key(
bp_parse_args(
$bp_heartbeat,
$post_query,
'nouveau_ajax_querystring_heartbeat'
),
array(
'data' => false,
'interval' => false,
'_nonce' => false,
'action' => false,
'screen_id' => false,
'has_focus' => false,
)
);
}
}
// Init the query string
$qs = array();
// Activity stream filtering on action.
if ( ! empty( $post_query['filter'] ) && '-1' !== $post_query['filter'] ) {
if ( 'notifications' === $object ) {
$qs[] = 'component_action=' . $post_query['filter'];
} else {
$qs[] = 'type=' . $post_query['filter'];
$qs[] = 'action=' . $post_query['filter'];
}
}
// Sort the notifications if needed
if ( ! empty( $post_query['extras'] ) && 'notifications' === $object ) {
$qs[] = 'sort_order=' . $post_query['extras'];
}
if ( 'personal' === $post_query['scope'] ) {
$user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
$qs[] = 'user_id=' . $user_id;
}
// Activity stream scope only on activity directory.
if ( 'all' !== $post_query['scope'] && ! bp_displayed_user_id() && ! bp_is_single_item() ) {
$qs[] = 'scope=' . $post_query['scope'];
}
// If page have been passed via the AJAX post request, use those.
if ( '-1' != $post_query['page'] ) {
$qs[] = 'page=' . absint( $post_query['page'] );
}
// Excludes activity just posted and avoids duplicate ids.
if ( ! empty( $post_query['exclude_just_posted'] ) ) {
$just_posted = wp_parse_id_list( $post_query['exclude_just_posted'] );
$qs[] = 'exclude=' . implode( ',', $just_posted );
}
// To get newest activities.
if ( ! empty( $post_query['offset'] ) ) {
$qs[] = 'offset=' . intval( $post_query['offset'] );
}
$object_search_text = bp_get_search_default_text( $object );
if ( ! empty( $post_query['search_terms'] ) && $object_search_text != $post_query['search_terms'] && 'false' != $post_query['search_terms'] && 'undefined' != $post_query['search_terms'] ) {
$qs[] = 'search_terms=' . urlencode( $_POST['search_terms'] );
}
// Specific to messages
if ( 'messages' === $object ) {
if ( ! empty( $post_query['box'] ) ) {
$qs[] = 'box=' . $post_query['box'];
}
}
// Single activity.
if ( bp_is_single_activity() ) {
$qs = array(
'display_comments=threaded',
'show_hidden=true',
'include=' . bp_current_action(),
);
}
// Now pass the querystring to override default values.
$query_string = empty( $qs ) ? '' : join( '&', (array) $qs );
// List the variables for the filter
list( $filter, $scope, $page, $search_terms, $extras ) = array_values( $post_query );
/**
* Filters the AJAX query string for the component loops.
*
* @since 3.0.0
*
* @param string $query_string The query string we are working with.
* @param string $object The type of page we are on.
* @param string $filter The current object filter.
* @param string $scope The current object scope.
* @param string $page The current object page.
* @param string $search_terms The current object search terms.
* @param string $extras The current object extras.
*/
return apply_filters( 'bp_nouveau_ajax_querystring', $query_string, $object, $filter, $scope, $page, $search_terms, $extras );
}
/**
* @since 3.0.0
*
* @return string
*/
function bp_nouveau_ajax_button( $output = '', $button = null, $before = '', $after = '', $r = array() ) {
if ( empty( $button->component ) ) {
return $output;
}
// Custom data attribute.
$r['button_attr']['data-bp-btn-action'] = $button->id;
$reset_ids = array(
'member_friendship' => true,
'group_membership' => true,
);
if ( ! empty( $reset_ids[ $button->id ] ) ) {
$parse_class = array_map( 'sanitize_html_class', explode( ' ', $r['button_attr']['class'] ) );
if ( false === $parse_class ) {
return $output;
}
$find_id = array_intersect( $parse_class, array(
'pending_friend',
'is_friend',
'not_friends',
'leave-group',
'join-group',
'accept-invite',
'membership-requested',
'request-membership',
) );
if ( 1 !== count( $find_id ) ) {
return $output;
}
$data_attribute = reset( $find_id );
if ( 'pending_friend' === $data_attribute ) {
$data_attribute = str_replace( '_friend', '', $data_attribute );
} elseif ( 'group_membership' === $button->id ) {
$data_attribute = str_replace( '-', '_', $data_attribute );
}
$r['button_attr']['data-bp-btn-action'] = $data_attribute;
}
// Re-render the button with our custom data attribute.
$output = new BP_Core_HTML_Element( array(
'element' => $r['button_element'],
'attr' => $r['button_attr'],
'inner_html' => ! empty( $r['link_text'] ) ? $r['link_text'] : ''
) );
$output = $output->contents();
// Add span bp-screen-reader-text class
return $before . $output . $after;
}
/**
* Output HTML content into a wrapper.
*
* @since 3.0.0
*
* @param array $args {
* Optional arguments.
*
* @type string $container String HTML container type that should wrap
* the items as a group: 'div', 'ul', or 'p'. Required.
* @type string $container_id The group wrapping container element ID
* @type string $container_classes The group wrapping container elements class
* @type string $output The HTML to output. Required.
* }
*/
function bp_nouveau_wrapper( $args = array() ) {
/**
* Classes need to be determined & set by component to a certain degree
*
* Check the component to find a default container_class to add
*/
$current_component_class = bp_current_component() . '-meta';
if ( bp_is_group_activity() ) {
$generic_class = ' activity-meta ';
} else {
$generic_class = '';
}
$r = bp_parse_args(
$args,
array(
'container' => 'div',
'container_id' => '',
'container_classes' => array( $generic_class, $current_component_class ),
'output' => '',
),
'nouveau_wrapper'
);
$valid_containers = array(
'div' => true,
'ul' => true,
'ol' => true,
'span' => true,
'p' => true,
);
// Actually merge some classes defaults and $args
// @todo This is temp, we need certain classes but maybe improve this approach.
$default_classes = array( 'action' );
$r['container_classes'] = array_merge( $r['container_classes'], $default_classes );
if ( empty( $r['container'] ) || ! isset( $valid_containers[ $r['container'] ] ) || empty( $r['output'] ) ) {
return;
}
$container = $r['container'];
$container_id = '';
$container_classes = '';
$output = $r['output'];
if ( ! empty( $r['container_id'] ) ) {
$container_id = ' id="' . esc_attr( $r['container_id'] ) . '"';
}
if ( ! empty( $r['container_classes'] ) && is_array( $r['container_classes'] ) ) {
$container_classes = ' class="' . join( ' ', array_map( 'sanitize_html_class', $r['container_classes'] ) ) . '"';
}
// Print the wrapper and its content.
printf( '<%1$s%2$s%3$s>%4$s%1$s>', $container, $container_id, $container_classes, $output );
}
/**
* Register the 2 sidebars for the Group & User default front page
*
* @since 3.0.0
*/
function bp_nouveau_register_sidebars() {
$default_fronts = bp_nouveau_get_appearance_settings();
$default_user_front = 0;
$default_group_front = 0;
$is_active_groups = bp_is_active( 'groups' );
if ( isset( $default_fronts['user_front_page'] ) ) {
$default_user_front = $default_fronts['user_front_page'];
}
if ( $is_active_groups ) {
if ( isset( $default_fronts['group_front_page'] ) ) {
$default_group_front = $default_fronts['group_front_page'];
}
}
// Setting the front template happens too early, so we need this!
if ( is_customize_preview() ) {
$default_user_front = bp_nouveau_get_temporary_setting( 'user_front_page', $default_user_front );
if ( $is_active_groups ) {
$default_group_front = bp_nouveau_get_temporary_setting( 'group_front_page', $default_group_front );
}
}
$sidebars = array();
if ( $default_user_front ) {
$sidebars[] = array(
'name' => __( 'BuddyPress Member\'s Home', 'buddypress' ),
'id' => 'sidebar-buddypress-members',
'description' => __( 'Add widgets here to appear in the front page of each member of your community.', 'buddypress' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
);
}
if ( $default_group_front ) {
$sidebars[] = array(
'name' => __( 'BuddyPress Group\'s Home', 'buddypress' ),
'id' => 'sidebar-buddypress-groups',
'description' => __( 'Add widgets here to appear in the front page of each group of your community.', 'buddypress' ),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
);
}
if ( empty( $sidebars ) ) {
return;
}
// Register the sidebars if needed.
foreach ( $sidebars as $sidebar ) {
register_sidebar( $sidebar );
}
}
/**
* @since 3.0.0
*
* @return bool
*/
function bp_nouveau_is_object_nav_in_sidebar() {
return is_active_widget( false, false, 'bp_nouveau_sidebar_object_nav_widget', true );
}
/**
* @since 3.0.0
*
* @return bool
*/
function bp_nouveau_current_user_can( $capability = '' ) {
/**
* Filters whether or not the current user can perform an action for BuddyPress Nouveau.
*
* @since 3.0.0
*
* @param bool $value Whether or not the user is logged in.
* @param string $capability Current capability being checked.
* @param int $value Current logged in user ID.
*/
return apply_filters( 'bp_nouveau_current_user_can', is_user_logged_in(), $capability, bp_loggedin_user_id() );
}
/**
* Parse an html output to a list of component's directory nav item.
*
* @since 3.0.0
*
* @param string $hook The hook to fire.
* @param string $component The component nav belongs to.
* @param int $position The position of the nav item.
*
* @return array A list of component's dir nav items
*/
function bp_nouveau_parse_hooked_dir_nav( $hook = '', $component = '', $position = 99 ) {
$extra_nav_items = array();
if ( empty( $hook ) || empty( $component ) || ! has_action( $hook ) ) {
return $extra_nav_items;
}
// Get the hook output.
ob_start();
/**
* Fires at the start of the output for `bp_nouveau_parse_hooked_dir_nav()`.
*
* This hook is variable and depends on the hook parameter passed in.
*
* @since 3.0.0
*/
do_action( $hook );
$output = ob_get_clean();
if ( empty( $output ) ) {
return $extra_nav_items;
}
preg_match_all( "/