Ejemplo n.º 1
0
 /**
  * Constructor method.
  *
  * @see BP_Groups_Group::get() for an in-depth description of arguments.
  *
  * @param array $args {
  *     Array of arguments. Accepts all arguments accepted by
  *     {@link BP_Groups_Group::get()}. In cases where the default
  *     values of the params differ, they have been discussed below.
  *     @type int $per_page Default: 20.
  *     @type int $page Default: 1.
  * }
  */
 function __construct($args = array())
 {
     // Backward compatibility with old method of passing arguments.
     if (!is_array($args) || func_num_args() > 1) {
         _deprecated_argument(__METHOD__, '1.7', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__));
         $old_args_keys = array(0 => 'user_id', 1 => 'type', 2 => 'page', 3 => 'per_page', 4 => 'max', 5 => 'slug', 6 => 'search_terms', 7 => 'populate_extras', 8 => 'include', 9 => 'exclude', 10 => 'show_hidden', 11 => 'page_arg');
         $func_args = func_get_args();
         $args = bp_core_parse_args_array($old_args_keys, $func_args);
     }
     $defaults = array('page' => 1, 'per_page' => 20, 'page_arg' => 'grpage', 'max' => false, 'type' => 'active', 'order' => 'DESC', 'orderby' => 'date_created', 'show_hidden' => false, 'user_id' => 0, 'slug' => false, 'include' => false, 'exclude' => false, 'search_terms' => '', 'meta_query' => false, 'populate_extras' => true, 'update_meta_cache' => true);
     $r = wp_parse_args($args, $defaults);
     extract($r);
     $this->pag_arg = sanitize_key($r['page_arg']);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']);
     $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']);
     if (bp_current_user_can('bp_moderate') || is_user_logged_in() && $user_id == bp_loggedin_user_id()) {
         $show_hidden = true;
     }
     if ('invites' == $type) {
         $this->groups = groups_get_invites_for_user($user_id, $this->pag_num, $this->pag_page, $exclude);
     } elseif ('single-group' == $type) {
         $this->single_group = true;
         if (groups_get_current_group()) {
             $group = groups_get_current_group();
         } else {
             $group = groups_get_group(array('group_id' => BP_Groups_Group::get_id_from_slug($r['slug']), 'populate_extras' => $r['populate_extras']));
         }
         // Backwards compatibility - the 'group_id' variable is not part of the
         // BP_Groups_Group object, but we add it here for devs doing checks against it
         //
         // @see https://buddypress.trac.wordpress.org/changeset/3540
         //
         // this is subject to removal in a future release; devs should check against
         // $group->id instead.
         $group->group_id = $group->id;
         $this->groups = array($group);
     } else {
         $this->groups = groups_get_groups(array('type' => $type, 'order' => $order, 'orderby' => $orderby, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'include' => $include, 'exclude' => $exclude, 'populate_extras' => $populate_extras, 'update_meta_cache' => $update_meta_cache, 'show_hidden' => $show_hidden));
     }
     if ('invites' == $type) {
         $this->total_group_count = (int) $this->groups['total'];
         $this->group_count = (int) $this->groups['total'];
         $this->groups = $this->groups['groups'];
     } elseif ('single-group' == $type) {
         if (empty($group->id)) {
             $this->total_group_count = 0;
             $this->group_count = 0;
         } else {
             $this->total_group_count = 1;
             $this->group_count = 1;
         }
     } else {
         if (empty($max) || $max >= (int) $this->groups['total']) {
             $this->total_group_count = (int) $this->groups['total'];
         } else {
             $this->total_group_count = (int) $max;
         }
         $this->groups = $this->groups['groups'];
         if (!empty($max)) {
             if ($max >= count($this->groups)) {
                 $this->group_count = count($this->groups);
             } else {
                 $this->group_count = (int) $max;
             }
         } else {
             $this->group_count = count($this->groups);
         }
     }
     // Build pagination links.
     if ((int) $this->total_group_count && (int) $this->pag_num) {
         $pag_args = array($this->pag_arg => '%#%');
         if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) {
             $base = remove_query_arg('s', wp_get_referer());
         } else {
             $base = '';
         }
         $add_args = array('num' => $this->pag_num, 'sortby' => $this->sort_by, 'order' => $this->order);
         if (!empty($search_terms)) {
             $query_arg = bp_core_get_component_search_query_arg('groups');
             $add_args[$query_arg] = urlencode($search_terms);
         }
         $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_group_count / (int) $this->pag_num), 'current' => $this->pag_page, 'prev_text' => _x('←', 'Group pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Group pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args));
     }
 }
/**
 * @since 1.0.0
 */
function bp_directory_groups_search_form()
{
    $query_arg = bp_core_get_component_search_query_arg('groups');
    if (!empty($_REQUEST[$query_arg])) {
        $search_value = stripslashes($_REQUEST[$query_arg]);
    } else {
        $search_value = bp_get_search_default_text('groups');
    }
    $search_form_html = '<form action="" method="get" id="search-groups-form">
		<label for="groups_search"><input type="text" name="' . esc_attr($query_arg) . '" id="groups_search" placeholder="' . esc_attr($search_value) . '" /></label>
		<input type="submit" id="groups_search_submit" name="groups_search_submit" value="' . __('Search', 'buddypress') . '" />
	</form>';
    /**
     * Filters the HTML markup for the groups search form.
     *
     * @since 1.9.0
     *
     * @param string $search_form_html HTML markup for the search form.
     */
    echo apply_filters('bp_directory_groups_search_form', $search_form_html);
}
/**
 * Filter an Extended Profile field value, and attempt to make clickable links
 * to members search results out of them.
 *
 * - Not run on datebox field types.
 * - Not run on values without commas with less than 5 words.
 * - URL's are made clickable.
 * - To disable: remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
 *
 * @since 1.1.0
 *
 * @param string $field_value Profile field data value.
 * @param string $field_type  Profile field type.
 * @return string
 */
function xprofile_filter_link_profile_data($field_value, $field_type = 'textbox')
{
    if ('datebox' === $field_type) {
        return $field_value;
    }
    if (!strpos($field_value, ',') && count(explode(' ', $field_value)) > 5) {
        return $field_value;
    }
    $values = explode(',', $field_value);
    if (!empty($values)) {
        foreach ((array) $values as $value) {
            $value = trim($value);
            // If the value is a URL, skip it and just make it clickable.
            if (preg_match('@(https?://([-\\w\\.]+)+(:\\d+)?(/([\\w/_\\.]*(\\?\\S+)?)?)?)@', $value)) {
                $new_values[] = make_clickable($value);
                // Is not clickable.
            } else {
                // More than 5 spaces.
                if (count(explode(' ', $value)) > 5) {
                    $new_values[] = $value;
                    // Less than 5 spaces.
                } else {
                    $query_arg = bp_core_get_component_search_query_arg('members');
                    $search_url = add_query_arg(array($query_arg => urlencode($value)), bp_get_members_directory_permalink());
                    $new_values[] = '<a href="' . esc_url($search_url) . '" rel="nofollow">' . $value . '</a>';
                }
            }
        }
        $values = implode(', ', $new_values);
    }
    return $values;
}
Ejemplo n.º 4
0
 /**
  * Constructor method.
  *
  * @see BP_User_Query for an in-depth description of parameters.
  *
  * @param string       $type                Sort order.
  * @param int          $page_number         Page of results.
  * @param int          $per_page            Number of results per page.
  * @param int          $max                 Max number of results to return.
  * @param int          $user_id             Limit to friends of a user.
  * @param string       $search_terms        Limit to users matching search terms.
  * @param array        $include             Limit results by these user IDs.
  * @param bool         $populate_extras     Fetch optional extras.
  * @param array        $exclude             Exclude these IDs from results.
  * @param array        $meta_key            Limit to users with a meta_key.
  * @param array        $meta_value          Limit to users with a meta_value (with meta_key).
  * @param string       $page_arg            Optional. The string used as a query parameter in pagination links.
  *                                          Default: 'upage'.
  * @param array|string $member_type         Array or comma-separated string of member types to limit results to.
  * @param array|string $member_type__in     Array or comma-separated string of member types to limit results to.
  * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude
  *                                          from results.
  */
 function __construct($type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '')
 {
     $this->pag_arg = sanitize_key($page_arg);
     $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page_number);
     $this->pag_num = bp_sanitize_pagination_arg('num', $per_page);
     $this->type = $type;
     if (!empty($_REQUEST['letter'])) {
         $this->members = BP_Core_User::get_users_by_letter($_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude);
     } else {
         $this->members = bp_core_get_users(array('type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in));
     }
     if (!$max || $max >= (int) $this->members['total']) {
         $this->total_member_count = (int) $this->members['total'];
     } else {
         $this->total_member_count = (int) $max;
     }
     $this->members = $this->members['users'];
     if ($max) {
         if ($max >= count($this->members)) {
             $this->member_count = count($this->members);
         } else {
             $this->member_count = (int) $max;
         }
     } else {
         $this->member_count = count($this->members);
     }
     if ((int) $this->total_member_count && (int) $this->pag_num) {
         $pag_args = array($this->pag_arg => '%#%');
         if (defined('DOING_AJAX') && true === (bool) DOING_AJAX) {
             $base = remove_query_arg('s', wp_get_referer());
         } else {
             $base = '';
         }
         /**
          * Defaults to an empty array to make sure paginate_links()
          * won't add the $page_arg to the links which would break
          * pagination in case JavaScript is disabled.
          */
         $add_args = array();
         if (!empty($search_terms)) {
             $query_arg = bp_core_get_component_search_query_arg('members');
             $add_args[$query_arg] = urlencode($search_terms);
         }
         $this->pag_links = paginate_links(array('base' => add_query_arg($pag_args, $base), 'format' => '', 'total' => ceil((int) $this->total_member_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('&larr;', 'Member pagination previous text', 'buddypress'), 'next_text' => _x('&rarr;', 'Member pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => $add_args));
     }
 }
/**
 * Get the placeholder text for the search box for a given component.
 *
 * @since 2.7.0
 *
 * @param string $component Component name. Defaults to current component.
 * @return string Placeholder text for the search field.
 */
function bp_get_search_placeholder($component = '')
{
    $query_arg = bp_core_get_component_search_query_arg($component);
    if ($query_arg && !empty($_REQUEST[$query_arg])) {
        $placeholder = wp_unslash($_REQUEST[$query_arg]);
    } else {
        $placeholder = bp_get_search_default_text($component);
    }
    return $placeholder;
}
/**
 * Initialize the activity loop.
 *
 * Based on the $args passed, bp_has_activities() populates the
 * $activities_template global, enabling the use of BuddyPress templates and
 * template functions to display a list of activity items.
 *
 * @since 1.0.0
 * @since 2.4.0 Introduced the `$fields` parameter.
 *
 * @global object $activities_template {@link BP_Activity_Template}
 * @uses groups_is_user_member()
 * @uses bp_current_action()
 * @uses bp_is_current_action()
 * @uses bp_get_activity_slug()
 * @uses bp_action_variable()
 * @uses wp_parse_args()
 * @uses bp_is_active()
 * @uses friends_get_friend_user_ids()
 * @uses groups_get_user_groups()
 * @uses bp_activity_get_user_favorites()
 * @uses apply_filters() To call the 'bp_has_activities' hook.
 *
 * @param array|string $args {
 *     Arguments for limiting the contents of the activity loop. Most arguments
 *     are in the same format as {@link BP_Activity_Activity::get()}. However,
 *     because the format of the arguments accepted here differs in a number of
 *     ways, and because bp_has_activities() determines some default arguments in
 *     a dynamic fashion, we list all accepted arguments here as well.
 *
 *     Arguments can be passed as an associative array, or as a URL querystring
 *     (eg, 'user_id=4&display_comments=threaded').
 *
 *     @type int               $page             Which page of results to fetch. Using page=1 without per_page will result
 *                                               in no pagination. Default: 1.
 *     @type int|bool          $per_page         Number of results per page. Default: 20.
 *     @type string            $page_arg         String used as a query parameter in pagination links. Default: 'acpage'.
 *     @type int|bool          $max              Maximum number of results to return. Default: false (unlimited).
 *     @type string            $fields           Activity fields to retrieve. 'all' to fetch entire activity objects,
 *                                               'ids' to get only the activity IDs. Default 'all'.
 *     @type string|bool       $count_total      If true, an additional DB query is run to count the total activity items
 *                                               for the query. Default: false.
 *     @type string            $sort             'ASC' or 'DESC'. Default: 'DESC'.
 *     @type array|bool        $exclude          Array of activity IDs to exclude. Default: false.
 *     @type array|bool        $in               Array of IDs to limit query by (IN). 'in' is intended to be used in
 *                                               conjunction with other filter parameters. Default: false.
 *     @type array|bool        $include          Array of exact activity IDs to query. Providing an 'include' array will
 *                                               override all other filters passed in the argument array. When viewing the
 *                                               permalink page for a single activity item, this value defaults to the ID of
 *                                               that item. Otherwise the default is false.
 *     @type array             $meta_query       Limit by activitymeta by passing an array of meta_query conditions. See
 *                                               {@link WP_Meta_Query::queries} for a description of the syntax.
 *     @type array             $date_query       Limit by date by passing an array of date_query conditions. See first
 *                                               parameter of {@link WP_Date_Query::__construct()} for syntax.
 *     @type array             $filter_query     Advanced activity filtering.  See {@link BP_Activity_Query::__construct()}.
 *     @type string            $search_terms     Limit results by a search term. Default: false.
 *     @type string            $scope            Use a BuddyPress pre-built filter.
 *                                                 - 'just-me' retrieves items belonging only to a user; this is equivalent
 *                                                   to passing a 'user_id' argument.
 *                                                 - 'friends' retrieves items belonging to the friends of a user.
 *                                                 - 'groups' retrieves items belonging to groups to which a user belongs to.
 *                                                 - 'favorites' retrieves a user's favorited activity items.
 *                                                 - 'mentions' retrieves items where a user has received an @-mention.
 *                                               The default value of 'scope' is set to one of the above if that value
 *                                               appears in the appropriate place in the URL; eg, 'scope' will be 'groups'
 *                                               when visiting http://example.com/members/joe/activity/groups/. Otherwise
 *                                               defaults to false.
 *     @type int|array|bool    $user_id          The ID(s) of user(s) whose activity should be fetched. Pass a single ID or
 *                                               an array of IDs. When viewing a user profile page (but not that user's
 *                                               activity subpages, ie My Friends, My Groups, etc), 'user_id' defaults to
 *                                               the ID of the displayed user. Otherwise the default is false.
 *     @type string|array|bool $object           Filters by the `component` column in the database, which is generally the
 *                                               component ID in the case of BuddyPress components, or the plugin slug in
 *                                               the case of plugins. For example, 'groups' will limit results to those that
 *                                               are associated with the BP Groups component. Accepts a single component
 *                                               string, or an array of multiple components. Defaults to 'groups' when
 *                                               viewing the page of a single group, the My Groups activity filter, or the
 *                                               Activity > Groups filter of a user profile. Otherwise defaults to false.
 *     @type string|array|bool $action           Filters by the `type` column in the database, which is a string
 *                                               categorizing the activity item (eg, 'new_blog_post', 'created_group').
 *                                               Accepts a comma-delimited string or an array of types. Default: false.
 *     @type int|array|bool    $primary_id       Filters by the `item_id` column in the database. The meaning of
 *                                               'primary_id' differs between components/types; for example, in the case of
 *                                               'created_group', 'primary_id' is the ID of the group. Accepts a single ID,
 *                                               or an array of multiple IDs. When viewing a single group, defaults to the
 *                                               current group ID. When viewing a user's Groups stream page, defaults to the
 *                                               IDs of the user's groups. Otherwise defaults to false.
 *     @type int|array|bool    $secondary_id     Filters by the `secondary_item_id` column in the database. The meaning of
 *                                               'secondary_id' differs between components/types. Accepts a single ID, or an
 *                                               array of multiple IDs. Defaults to false.
 *     @type int               $offset           Return only activity items with an ID greater than or equal to this one.
 *                                               Note that providing an offset will disable pagination. Default: false.
 *     @type string|bool       $display_comments How to handle activity comments. Possible values:
 *                                                 - 'threaded' - comments appear in a threaded tree, under their parent
 *                                                   items.
 *                                                 - 'stream' - the activity stream is presented in a flat manner, with
 *                                                   comments sorted in chronological order alongside other activity items.
 *                                                 - false - don't fetch activity comments at all.
 *                                               Default: 'threaded'.
 *     @type bool              $show_hidden      Whether to show items marked hide_sitewide. Defaults to false, except in
 *                                               the following cases:
 *                                                 - User is viewing his own activity stream.
 *                                                 - User is viewing the activity stream of a non-public group of which he
 *                                                   is a member.
 *     @type string|bool       $spam             Spam status. 'ham_only', 'spam_only', or false to show all activity
 *                                               regardless of spam status. Default: 'ham_only'.
 *     @type bool              $populate_extras  Whether to pre-fetch the activity metadata for the queried items.
 *                                               Default: true.
 * }
 * @return bool Returns true when activities are found, otherwise false.
 */
function bp_has_activities($args = '')
{
    global $activities_template;
    // Get BuddyPress.
    $bp = buddypress();
    /*
     * Smart Defaults.
     */
    // User filtering.
    $user_id = bp_displayed_user_id() ? bp_displayed_user_id() : false;
    // Group filtering.
    if (bp_is_group()) {
        $object = $bp->groups->id;
        $primary_id = bp_get_current_group_id();
        $show_hidden = (bool) (groups_is_user_member(bp_loggedin_user_id(), $primary_id) || bp_current_user_can('bp_moderate'));
    } else {
        $object = false;
        $primary_id = false;
        $show_hidden = false;
    }
    // The default scope should recognize custom slugs.
    $scope = array_key_exists(bp_current_action(), (array) $bp->loaded_components) ? $bp->loaded_components[bp_current_action()] : bp_current_action();
    // Support for permalinks on single item pages: /groups/my-group/activity/124/.
    $include = bp_is_current_action(bp_get_activity_slug()) ? bp_action_variable(0) : false;
    $search_terms_default = false;
    $search_query_arg = bp_core_get_component_search_query_arg('activity');
    if (!empty($_REQUEST[$search_query_arg])) {
        $search_terms_default = stripslashes($_REQUEST[$search_query_arg]);
    }
    /*
     * Parse Args.
     */
    // Note: any params used for filtering can be a single value, or multiple
    // values comma separated.
    $r = bp_parse_args($args, array('display_comments' => 'threaded', 'include' => $include, 'exclude' => false, 'in' => false, 'sort' => 'DESC', 'page' => 1, 'per_page' => 20, 'page_arg' => 'acpage', 'max' => false, 'fields' => 'all', 'count_total' => false, 'show_hidden' => $show_hidden, 'spam' => 'ham_only', 'scope' => $scope, 'user_id' => $user_id, 'object' => $object, 'action' => false, 'primary_id' => $primary_id, 'secondary_id' => false, 'offset' => false, 'since' => false, 'meta_query' => false, 'date_query' => false, 'filter_query' => false, 'search_terms' => $search_terms_default, 'update_meta_cache' => true), 'has_activities');
    /*
     * Smart Overrides.
     */
    // Translate various values for 'display_comments'
    // This allows disabling comments via ?display_comments=0
    // or =none or =false. Final true is a strict type check. See #5029.
    if (in_array($r['display_comments'], array(0, '0', 'none', 'false'), true)) {
        $r['display_comments'] = false;
    }
    // Ignore pagination if an offset is passed.
    if (!empty($r['offset'])) {
        $r['page'] = 0;
    }
    // Search terms.
    if (!empty($_REQUEST['s']) && empty($r['search_terms'])) {
        $r['search_terms'] = $_REQUEST['s'];
    }
    // Do not exceed the maximum per page.
    if (!empty($r['max']) && (int) $r['per_page'] > (int) $r['max']) {
        $r['per_page'] = $r['max'];
    }
    /**
     * Filters whether BuddyPress should enable afilter support.
     *
     * Support for basic filters in earlier BP versions is disabled by default.
     * To enable, put add_filter( 'bp_activity_enable_afilter_support', '__return_true' );
     * into bp-custom.php or your theme's functions.php.
     *
     * @since 1.6.0
     *
     * @param bool $value True if BuddyPress should enable afilter support.
     */
    if (isset($_GET['afilter']) && apply_filters('bp_activity_enable_afilter_support', false)) {
        $r['filter'] = array('object' => $_GET['afilter']);
    } elseif (!empty($r['user_id']) || !empty($r['object']) || !empty($r['action']) || !empty($r['primary_id']) || !empty($r['secondary_id']) || !empty($r['offset']) || !empty($r['since'])) {
        $r['filter'] = array('user_id' => $r['user_id'], 'object' => $r['object'], 'action' => $r['action'], 'primary_id' => $r['primary_id'], 'secondary_id' => $r['secondary_id'], 'offset' => $r['offset'], 'since' => $r['since']);
    } else {
        $r['filter'] = false;
    }
    // If specific activity items have been requested, override the $hide_spam
    // argument. This prevents backpat errors with AJAX.
    if (!empty($r['include']) && 'ham_only' === $r['spam']) {
        $r['spam'] = 'all';
    }
    /*
     * Query
     */
    $activities_template = new BP_Activity_Template($r);
    /**
     * Filters whether or not there are activity items to display.
     *
     * @since 1.1.0
     *
     * @param bool   $value               Whether or not there are activity items to display.
     * @param string $activities_template Current activities template being used.
     * @param array  $r                   Array of arguments passed into the BP_Activity_Template class.
     */
    return apply_filters('bp_has_activities', $activities_template->has_activities(), $activities_template, $r);
}
echo esc_attr(bp_current_component());
?>
-dir-search" class="dir-search" role="search">
	<form action="" method="get" id="search-<?php 
echo esc_attr(bp_current_component());
?>
-form">
		<label for="<?php 
bp_search_input_name();
?>
" class="bp-screen-reader-text"><?php 
bp_search_placeholder();
?>
</label>
		<input type="text" name="<?php 
echo esc_attr(bp_core_get_component_search_query_arg());
?>
" id="<?php 
bp_search_input_name();
?>
" placeholder="<?php 
bp_search_placeholder();
?>
" />

		<input type="submit" id="<?php 
echo esc_attr(bp_get_search_input_name());
?>
_submit" name="<?php 
bp_search_input_name();
?>