/**
 * Handle the display of the Groups directory index.
 *
 * @since 1.0.0
 */
function groups_directory_groups_setup()
{
    if (bp_is_groups_directory()) {
        // Set group type if available.
        if (bp_is_current_action(bp_get_groups_group_type_base()) && bp_action_variable()) {
            $matched_types = bp_groups_get_group_types(array('has_directory' => true, 'directory_slug' => bp_action_variable()));
            // Redirect back to group directory if no match.
            if (empty($matched_types)) {
                bp_core_redirect(bp_get_groups_directory_permalink());
            }
            // Set our global variable.
            buddypress()->groups->current_directory_type = reset($matched_types);
        }
        bp_update_is_directory(true, 'groups');
        /**
         * Fires before the loading of the Groups directory index.
         *
         * @since 1.1.0
         */
        do_action('groups_directory_groups_setup');
        /**
         * Filters the template to load for the Groups directory index.
         *
         * @since 1.0.0
         *
         * @param string $value Path to the groups directory index template to load.
         */
        bp_core_load_template(apply_filters('groups_template_directory_groups', 'groups/index'));
    }
}
/**
 * Return group type directory permalink.
 *
 * @since 2.7.0
 *
 * @param string $group_type Optional. Group type. Defaults to current group type.
 * @return string Group type directory URL on success, an empty string on failure.
 */
function bp_get_group_type_directory_permalink($group_type = '')
{
    if ($group_type) {
        $_group_type = $group_type;
    } else {
        // Fall back on the current group type.
        $_group_type = bp_get_current_group_directory_type();
    }
    $type = bp_groups_get_group_type_object($_group_type);
    // Bail when member type is not found or has no directory.
    if (!$type || !$type->has_directory) {
        return '';
    }
    /**
     * Filters the group type directory permalink.
     *
     * @since 2.7.0
     *
     * @param string $value       Group type directory permalink.
     * @param object $type        Group type object.
     * @param string $member_type Group type name, as passed to the function.
     */
    return apply_filters('bp_get_group_type_directory_permalink', trailingslashit(bp_get_groups_directory_permalink() . bp_get_groups_group_type_base() . '/' . $type->directory_slug), $type, $group_type);
}
/**
 * Is the current page the groups directory?
 *
 * @since 2.0.0
 *
 * @return True if the current page is the groups directory.
 */
function bp_is_groups_directory()
{
    if (bp_is_groups_component() && !bp_is_group() && (!bp_current_action() || bp_action_variable() && bp_is_current_action(bp_get_groups_group_type_base()))) {
        return true;
    }
    return false;
}