/**
 * 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'));
    }
}
/**
 * Restrict access to a group regarding its 'member type'
 *
 * If a user is not logged in, he is redirected to the login form
 * If a user ! member type, he is redirected to the groups directory
 * If a user is a super admin, he can access
 *
 * @param  bool $user_has_access
 * @param  array &$no_access_args the redirect args
 * @return bool False if member type doesn't match, true otherwise
 */
function cfbgr_enqueue_current_user_has_access($user_has_access, &$no_access_args)
{
    // If the user does not already have access bail
    if (empty($user_has_access)) {
        return $user_has_access;
    }
    // Get the member type of the group
    $restriction = groups_get_groupmeta(bp_get_current_group_id(), 'cf-buddypress-group-restrictions');
    // Don't touch to regular groups and leave Admins access
    if (empty($restriction) || bp_current_user_can('bp_moderate')) {
        return $user_has_access;
    }
    $current_group = groups_get_current_group();
    if (!is_user_logged_in()) {
        $user_has_access = false;
        $no_access_args = array('message' => __('You must log in to access the page you requested.', 'buddypress-group-restrictions'), 'root' => bp_get_group_permalink($current_group) . 'home/', 'redirect' => false);
        return $user_has_access;
        // Current user does not match the restriction
    } elseif ($restriction !== bp_get_member_type(bp_loggedin_user_id())) {
        $user_has_access = false;
        // Get infos about the member type
        $member_type_object = bp_get_member_type_object($restriction);
        $singular_name = '';
        if (!empty($member_type_object->labels['singular_name'])) {
            $singular_name = $member_type_object->labels['singular_name'];
        }
        // You need to redirect to a BuddyPress page to have
        $no_access_args = array('mode' => 3, 'message' => sprintf(__('Sorry the group you tried to enter is only viewable for %s members', 'buddypress-group-restrictions'), esc_html($singular_name)), 'root' => bp_get_groups_directory_permalink(), 'redirect' => false);
        return $user_has_access;
    }
    // By default, leave BuddyPress deal with access
    return $user_has_access;
}
function bpg_init()
{
    require_once dirname(__FILE__) . '/includes/functions.php';
    if (defined('BP_VERSION') && defined('WPGLOBUS_VERSION')) {
        $apply_filters = false;
        //TOFIX
        // Always on frontend
        if (!is_admin() || $apply_filters) {
            $optionLanguages = wpgl_get_option_language();
            $defaultLanguage = wpgl_get_default_language($optionLanguages);
            $currentLanguage = wpgl_get_current_language($optionLanguages);
            if ($currentLanguage != $defaultLanguage) {
                apply_filters('bp_get_groups_directory_permalink', trailingslashit(bp_get_groups_directory_permalink() . $currentLanguage . '/'));
                apply_filters('bp_get_activity_directory_permalink', trailingslashit(bp_get_activity_directory_permalink() . $currentLanguage . '/'));
                apply_filters('bp_get_blogs_directory_permalink', trailingslashit(bp_get_blogs_directory_permalink() . $currentLanguage . '/'));
                apply_filters('bp_get_forum_directory_permalink', trailingslashit(bp_get_forum_directory_permalink() . $currentLanguage . '/'));
                apply_filters('bp_get_members_directory_permalink', trailingslashit(bp_get_members_directory_permalink() . $currentLanguage . '/'));
            }
        }
    } else {
        if (is_admin()) {
            add_action('admin_notices', 'bpgl_admin_notice_required_plugins');
        }
    }
}
/**
 * Invites a friend to join a group via a POST request.
 *
 * @since BuddyPress (1.2)
 * @todo Audit return types
 */
function bp_legacy_theme_ajax_invite_user()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    check_ajax_referer('groups_invite_uninvite_user');
    if (!$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id']) {
        return;
    }
    if (!bp_groups_user_can_send_invites($_POST['group_id'])) {
        return;
    }
    if (!friends_check_friendship(bp_loggedin_user_id(), $_POST['friend_id'])) {
        return;
    }
    $group_id = (int) $_POST['group_id'];
    $friend_id = (int) $_POST['friend_id'];
    if ('invite' == $_POST['friend_action']) {
        $group = groups_get_group($group_id);
        // Users who have previously requested membership do not need
        // another invitation created for them
        if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) {
            $user_status = 'is_pending';
            // Create the user invitation
        } elseif (groups_invite_user(array('user_id' => $friend_id, 'group_id' => $group_id))) {
            $user_status = 'is_invited';
            // Miscellaneous failure
        } else {
            return;
        }
        $user = new BP_Core_User($friend_id);
        $uninvite_url = bp_is_current_action('create') ? bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $friend_id : bp_get_group_permalink($group) . 'send-invites/remove/' . $friend_id;
        echo '<li id="uid-' . esc_attr($user->id) . '">';
        echo $user->avatar_thumb;
        echo '<h4>' . $user->user_link . '</h4>';
        echo '<span class="activity">' . esc_attr($user->last_active) . '</span>';
        echo '<div class="action">
				<a class="button remove" href="' . wp_nonce_url($uninvite_url, 'groups_invite_uninvite_user') . '" id="uid-' . esc_attr($user->id) . '">' . __('Remove Invite', 'buddypress') . '</a>
			  </div>';
        if ('is_pending' == $user_status) {
            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>';
        }
        echo '</li>';
        exit;
    } elseif ('uninvite' == $_POST['friend_action']) {
        // Users who have previously requested membership should not
        // have their requests deleted on the "uninvite" action
        if (BP_Groups_Member::check_for_membership_request($friend_id, $group_id)) {
            return;
        }
        // Remove the unsent invitation
        if (!groups_uninvite_user($friend_id, $group_id)) {
            return;
        }
        exit;
    } else {
        return;
    }
}
 /**
  * Set up the component entries in the WordPress Admin Bar.
  *
  * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
  *      parameter array.
  *
  * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a description.
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     // Menus for logged in user.
     if (is_user_logged_in()) {
         // Setup the logged in user variables.
         $groups_link = trailingslashit(bp_loggedin_user_domain() . bp_get_groups_slug());
         // Pending group invites.
         $count = groups_get_invite_count_for_user();
         $title = _x('Groups', 'My Account Groups', 'buddypress');
         $pending = _x('No Pending Invites', 'My Account Groups sub nav', 'buddypress');
         if (!empty($count['total'])) {
             $title = sprintf(_x('Groups <span class="count">%s</span>', 'My Account Groups nav', 'buddypress'), bp_core_number_format($count));
             $pending = sprintf(_x('Pending Invites <span class="count">%s</span>', 'My Account Groups sub nav', 'buddypress'), bp_core_number_format($count));
         }
         // Add the "My Account" sub menus.
         $wp_admin_nav[] = array('parent' => buddypress()->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => $groups_link);
         // My Groups.
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-memberships', 'title' => _x('Memberships', 'My Account Groups sub nav', 'buddypress'), 'href' => $groups_link);
         // Invitations.
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-invites', 'title' => $pending, 'href' => trailingslashit($groups_link . 'invites'));
         // Create a Group.
         if (bp_user_can_create_groups()) {
             $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => _x('Create a Group', 'My Account Groups sub nav', 'buddypress'), 'href' => trailingslashit(bp_get_groups_directory_permalink() . 'create'));
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
    /**
     * Extends our frontend output method.
     *
     * @param array $args     Array of arguments for the widget.
     * @param array $instance Widget instance data.
     */
    public function widget($args, $instance)
    {
        /**
         * Filters the user ID to use with the widget instance.
         *
         * @since 1.5.0
         *
         * @param string $value Empty user ID.
         */
        $user_id = apply_filters('bp_group_widget_user_id', '0');
        extract($args);
        if (empty($instance['group_default'])) {
            $instance['group_default'] = 'popular';
        }
        if (empty($instance['title'])) {
            $instance['title'] = __('Groups', 'buddypress');
        }
        /**
         * Filters the title of the Groups widget.
         *
         * @since 1.8.0
         * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
         *
         * @param string $title    The widget title.
         * @param array  $instance The settings for the particular instance of the widget.
         * @param string $id_base  Root ID for all widgets of this type.
         */
        $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
        /**
         * Filters the separator of the group widget links.
         *
         * @since 2.4.0
         *
         * @param string $separator Separator string. Default '|'.
         */
        $separator = apply_filters('bp_groups_widget_separator', '|');
        echo $before_widget;
        $title = !empty($instance['link_title']) ? '<a href="' . bp_get_groups_directory_permalink() . '">' . $title . '</a>' : $title;
        echo $before_title . $title . $after_title;
        $max_groups = !empty($instance['max_groups']) ? (int) $instance['max_groups'] : 5;
        $group_args = array('user_id' => $user_id, 'type' => $instance['group_default'], 'per_page' => $max_groups, 'max' => $max_groups);
        ?>

		<?php 
        if (bp_has_groups($group_args)) {
            ?>
			<div class="item-options" id="groups-list-options">
				<a href="<?php 
            bp_groups_directory_permalink();
            ?>
" id="newest-groups"<?php 
            if ($instance['group_default'] == 'newest') {
                ?>
 class="selected"<?php 
            }
            ?>
><?php 
            _e("Newest", 'buddypress');
            ?>
</a>
				<span class="bp-separator" role="separator"><?php 
            echo esc_html($separator);
            ?>
</span>
				<a href="<?php 
            bp_groups_directory_permalink();
            ?>
" id="recently-active-groups"<?php 
            if ($instance['group_default'] == 'active') {
                ?>
 class="selected"<?php 
            }
            ?>
><?php 
            _e("Active", 'buddypress');
            ?>
</a>
				<span class="bp-separator" role="separator"><?php 
            echo esc_html($separator);
            ?>
</span>
				<a href="<?php 
            bp_groups_directory_permalink();
            ?>
" id="popular-groups" <?php 
            if ($instance['group_default'] == 'popular') {
                ?>
 class="selected"<?php 
            }
            ?>
><?php 
            _e("Popular", 'buddypress');
            ?>
</a>
			</div>

			<ul id="groups-list" class="item-list">
				<?php 
            while (bp_groups()) {
                bp_the_group();
                ?>
					<li <?php 
                bp_group_class();
                ?>
>
						<div class="item-avatar">
							<a href="<?php 
                bp_group_permalink();
                ?>
" title="<?php 
                bp_group_name();
                ?>
"><?php 
                bp_group_avatar_thumb();
                ?>
</a>
						</div>

						<div class="item">
							<div class="item-title"><a href="<?php 
                bp_group_permalink();
                ?>
" title="<?php 
                bp_group_name();
                ?>
"><?php 
                bp_group_name();
                ?>
</a></div>
							<div class="item-meta">
								<span class="activity">
								<?php 
                if ('newest' == $instance['group_default']) {
                    printf(__('created %s', 'buddypress'), bp_get_group_date_created());
                } elseif ('active' == $instance['group_default']) {
                    printf(__('active %s', 'buddypress'), bp_get_group_last_active());
                } elseif ('popular' == $instance['group_default']) {
                    bp_group_member_count();
                }
                ?>
								</span>
							</div>
						</div>
					</li>

				<?php 
            }
            ?>
			</ul>
			<?php 
            wp_nonce_field('groups_widget_groups_list', '_wpnonce-groups');
            ?>
			<input type="hidden" name="groups_widget_max" id="groups_widget_max" value="<?php 
            echo esc_attr($max_groups);
            ?>
" />

		<?php 
        } else {
            ?>

			<div class="widget-error">
				<?php 
            _e('There are no groups to display.', 'buddypress');
            ?>
			</div>

		<?php 
        }
        ?>

		<?php 
        echo $after_widget;
        ?>
	<?php 
    }
 function x_buddypress_navbar_menu($items, $args)
 {
     if (X_BUDDYPRESS_IS_ACTIVE && x_get_option('x_buddypress_header_menu_enable', '') == '1') {
         $top_level_link = is_user_logged_in() ? bp_loggedin_user_domain() : bp_get_activity_directory_permalink();
         $submenu_items = '';
         if (bp_is_active('activity')) {
             $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activity_directory_permalink() . '" class="cf"><i class="x-icon-thumbs-up" data-x-icon="&#xf164;"></i> <span>' . x_get_option('x_buddypress_activity_title', __('Activity', '__x__')) . '</span></a></li>';
         }
         if (bp_is_active('groups')) {
             $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_groups_directory_permalink() . '" class="cf"><i class="x-icon-sitemap" data-x-icon="&#xf0e8;"></i> <span>' . x_get_option('x_buddypress_groups_title', __('Groups', '__x__')) . '</span></a></li>';
         }
         if (is_multisite() && bp_is_active('blogs')) {
             $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_blogs_directory_permalink() . '" class="cf"><i class="x-icon-file" data-x-icon="&#xf15b;"></i> <span>' . x_get_option('x_buddypress_blogs_title', __('Blogs', '__x__')) . '</span></a></li>';
         }
         $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_members_directory_permalink() . '" class="cf"><i class="x-icon-male" data-x-icon="&#xf183;"></i> <span>' . x_get_option('x_buddypress_members_title', __('Members', '__x__')) . '</span></a></li>';
         if (!is_user_logged_in()) {
             if (bp_get_signup_allowed()) {
                 $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_signup_page() . '" class="cf"><i class="x-icon-pencil" data-x-icon="&#xf040;"></i> <span>' . x_get_option('x_buddypress_register_title', __('Create an Account', '__x__')) . '</span></a></li>';
                 $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_get_activation_page() . '" class="cf"><i class="x-icon-key" data-x-icon="&#xf084;"></i> <span>' . x_get_option('x_buddypress_activate_title', __('Activate Your Account', '__x__')) . '</span></a></li>';
             }
             $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon="&#xf090;"></i> <span>' . __('Log in', '__x__') . '</span></a></li>';
         } else {
             $submenu_items .= '<li class="menu-item menu-item-buddypress-navigation"><a href="' . bp_loggedin_user_domain() . '" class="cf"><i class="x-icon-cog" data-x-icon="&#xf013;"></i> <span>' . __('Profile', '__x__') . '</span></a></li>';
         }
         if ($args->theme_location == 'primary') {
             $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-buddypress">' . '<a href="' . $top_level_link . '" class="x-btn-navbar-buddypress">' . '<span><i class="x-icon-user" data-x-icon="&#xf007;"></i><span class="x-hidden-desktop"> ' . __('Social', '__x__') . '</span></span>' . '</a>' . '<ul class="sub-menu">' . $submenu_items . '</ul>' . '</li>';
         }
     }
     return $items;
 }
function kleo_search_form_func($atts, $content = null)
{
    $form_style = $type = $placeholder = $context = $el_class = '';
    extract(shortcode_atts(array('form_style' => 'default', 'type' => 'both', 'context' => '', 'placeholder' => '', 'el_class' => ''), $atts));
    global $kleo_config;
    $class = '';
    if ($el_class != '') {
        $class = ' ' . $el_class;
    }
    $class .= ' search-style-' . $form_style;
    //Defaults
    $action = home_url('/');
    $hidden = '';
    $input_name = 's';
    $ajax_results = 'yes';
    $search_page = 'yes';
    if ($type == 'ajax') {
        $search_page = 'no';
    } elseif ($type == 'form_submit') {
        $ajax_results = 'no';
    }
    if (function_exists('bp_is_active') && $context == 'members') {
        //Buddypress members form link
        $action = bp_get_members_directory_permalink();
    } elseif (function_exists('bp_is_active') && bp_is_active('groups') && $context == 'groups') {
        //Buddypress group directory link
        $action = bp_get_groups_directory_permalink();
    } elseif (class_exists('bbPress') && $context == 'forum') {
        $action = bbp_get_search_url();
        $input_name = 'bbp_search';
    } elseif ($context == 'product') {
        $hidden .= '<input type="hidden" name="post_type" value="product">';
    }
    $output = '<div class="kleo-search-wrap kleo-search-form' . $class . '">';
    $output .= '<form role="search" method="get" id="searchform" ' . ($search_page == 'no' ? ' onsubmit="return false;"' : '') . ' action="' . $action . '" data-context="' . $context . '">
		<div class="input-group">
			<input name="' . $input_name . '" id="' . $input_name . '" autocomplete="off" type="text" class="ajax_s form-control input-lg" value="" placeholder="' . $placeholder . '">';
    if ($search_page == 'yes') {
        $output .= '<span class="input-group-btn">' . '<input type="submit" value="' . __("Search") . '" id="searchsubmit" class="button">' . '</span>';
    }
    $output .= '</div>' . $hidden . '</form>';
    if ($ajax_results == 'yes') {
        $output .= '<span class="kleo-ajax-search-loading"><span class="kleo-loading-icon"></span></span><div class="kleo_ajax_results"></div>';
    }
    $output .= '</div>';
    return $output;
}
/**
 * Display the Groups admin index screen.
 *
 * This screen contains a list of all BuddyPress groups.
 *
 * @since 1.7.0
 *
 * @global BP_Groups_List_Table $bp_groups_list_table Group screen list table.
 * @global string $plugin_page Currently viewed plugin page.
 */
function bp_groups_admin_index()
{
    global $bp_groups_list_table, $plugin_page;
    $messages = array();
    // If the user has just made a change to a group, build status messages
    if (!empty($_REQUEST['deleted'])) {
        $deleted = !empty($_REQUEST['deleted']) ? (int) $_REQUEST['deleted'] : 0;
        if ($deleted > 0) {
            $messages[] = sprintf(_n('%s group has been permanently deleted.', '%s groups have been permanently deleted.', $deleted, 'buddypress'), number_format_i18n($deleted));
        }
    }
    // Prepare the group items for display
    $bp_groups_list_table->prepare_items();
    /**
     * Fires before the display of messages for the edit form.
     *
     * Useful for plugins to modify the messages before display.
     *
     * @since 1.7.0
     *
     * @param array $messages Array of messages to be displayed.
     */
    do_action('bp_groups_admin_index', $messages);
    ?>

	<div class="wrap">
		<?php 
    screen_icon('buddypress-groups');
    ?>
		<h2>
			<?php 
    _e('Groups', 'buddypress');
    ?>

			<?php 
    if (is_user_logged_in() && bp_user_can_create_groups()) {
        ?>
				<a class="add-new-h2" href="<?php 
        echo trailingslashit(bp_get_groups_directory_permalink() . 'create');
        ?>
"><?php 
        _e('Add New', 'buddypress');
        ?>
</a>
			<?php 
    }
    ?>

			<?php 
    if (!empty($_REQUEST['s'])) {
        ?>
				<span class="subtitle"><?php 
        printf(__('Search results for &#8220;%s&#8221;', 'buddypress'), wp_html_excerpt(esc_html(stripslashes($_REQUEST['s'])), 50));
        ?>
</span>
			<?php 
    }
    ?>
		</h2>

		<?php 
    // If the user has just made a change to an group, display the status messages
    ?>
		<?php 
    if (!empty($messages)) {
        ?>
			<div id="moderated" class="<?php 
        echo !empty($_REQUEST['error']) ? 'error' : 'updated';
        ?>
"><p><?php 
        echo implode("<br/>\n", $messages);
        ?>
</p></div>
		<?php 
    }
    ?>

		<?php 
    // Display each group on its own row
    ?>
		<?php 
    $bp_groups_list_table->views();
    ?>

		<form id="bp-groups-form" action="" method="get">
			<?php 
    $bp_groups_list_table->search_box(__('Search all Groups', 'buddypress'), 'bp-groups');
    ?>
			<input type="hidden" name="page" value="<?php 
    echo esc_attr($plugin_page);
    ?>
" />
			<?php 
    $bp_groups_list_table->display();
    ?>
		</form>

	</div>

<?php 
}
/**
 * Catch requests for a random group page (example.com/groups/?random-group) and redirect.
 */
function groups_action_redirect_to_random_group()
{
    if (bp_is_groups_component() && isset($_GET['random-group'])) {
        $group = BP_Groups_Group::get_random(1, 1);
        bp_core_redirect(trailingslashit(bp_get_groups_directory_permalink() . $group['groups'][0]->slug));
    }
}
 /**
  * Set up the Toolbar
  *
  * @global BuddyPress $bp The one true BuddyPress instance
  */
 public function setup_admin_bar($wp_admin_nav = array())
 {
     global $bp;
     // Prevent debug notices
     $wp_admin_nav = array();
     // Menus for logged in user
     if (is_user_logged_in()) {
         // Setup the logged in user variables
         $user_domain = bp_loggedin_user_domain();
         $groups_link = trailingslashit($user_domain . $this->slug);
         // Pending group invites
         $count = groups_get_invites_for_user(bp_loggedin_user_id());
         $title = __('Groups', 'buddypress');
         $pending = __('No Pending Invites', 'buddypress');
         if (!empty($count['total'])) {
             $title = sprintf(__('Groups <span class="count">%s</span>', 'buddypress'), $count['total']);
             $pending = sprintf(__('Pending Invites <span class="count">%s</span>', 'buddypress'), $count['total']);
         }
         // Add the "My Account" sub menus
         $wp_admin_nav[] = array('parent' => $bp->my_account_menu_id, 'id' => 'my-account-' . $this->id, 'title' => $title, 'href' => trailingslashit($groups_link));
         // My Groups
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-memberships', 'title' => __('Memberships', 'buddypress'), 'href' => trailingslashit($groups_link));
         // Invitations
         $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-invites', 'title' => $pending, 'href' => trailingslashit($groups_link . 'invites'));
         // Create a Group
         if (bp_user_can_create_groups()) {
             $wp_admin_nav[] = array('parent' => 'my-account-' . $this->id, 'id' => 'my-account-' . $this->id . '-create', 'title' => __('Create a Group', 'buddypress'), 'href' => trailingslashit(bp_get_groups_directory_permalink() . 'create'));
         }
     }
     parent::setup_admin_bar($wp_admin_nav);
 }
Example #12
0
          </div>

          <?php 
        wp_nonce_field('bp_forums_new_topic');
        ?>

        </form><!-- #forum-topic-form -->

      <?php 
    } elseif (bp_is_active('groups')) {
        ?>

        <div id="message" class="info">

          <p><?php 
        printf(__("You are not a member of any groups so you don't have any group forums you can post in. To start posting, first find a group that matches the topic subject you'd like to start. If this group does not exist, why not <a href='%s'>create a new group</a>? Once you have joined or created the group you can post your topic in that group's forum.", 'buddypress'), trailingslashit(bp_get_groups_directory_permalink() . 'create'));
        ?>
</p>

        </div>

      <?php 
    }
    ?>

    <?php 
}
?>
  </div><!-- #new-topic-post -->

  <?php 
Example #13
0
 function x_breadcrumbs()
 {
     if (x_get_option('x_breadcrumb_display')) {
         global $post;
         $is_ltr = !is_rtl();
         $stack = x_get_stack();
         $delimiter = x_get_breadcrumb_delimiter();
         $home_text = x_get_breadcrumb_home_text();
         $home_link = home_url();
         $current_before = x_get_breadcrumb_current_before();
         $current_after = x_get_breadcrumb_current_after();
         $page_title = get_the_title();
         $blog_title = get_the_title(get_option('page_for_posts', true));
         if (!is_404()) {
             $post_parent = $post->post_parent;
         } else {
             $post_parent = '';
         }
         if (X_WOOCOMMERCE_IS_ACTIVE) {
             $shop_url = x_get_shop_link();
             $shop_title = x_get_option('x_' . $stack . '_shop_title');
             $shop_link = '<a href="' . $shop_url . '">' . $shop_title . '</a>';
         }
         echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
         if (is_home()) {
             echo $current_before . $blog_title . $current_after;
         } elseif (is_category()) {
             $the_cat = get_category(get_query_var('cat'), false);
             if ($the_cat->parent != 0) {
                 echo get_category_parents($the_cat->parent, TRUE, $delimiter);
             }
             echo $current_before . single_cat_title('', false) . $current_after;
         } elseif (x_is_product_category()) {
             if ($is_ltr) {
                 echo $shop_link . $delimiter . $current_before . single_cat_title('', false) . $current_after;
             } else {
                 echo $current_before . single_cat_title('', false) . $current_after . $delimiter . $shop_link;
             }
         } elseif (x_is_product_tag()) {
             if ($is_ltr) {
                 echo $shop_link . $delimiter . $current_before . single_tag_title('', false) . $current_after;
             } else {
                 echo $current_before . single_tag_title('', false) . $current_after . $delimiter . $shop_link;
             }
         } elseif (is_search()) {
             echo $current_before . __('Search Results for ', '__x__') . '&#8220;' . get_search_query() . '&#8221;' . $current_after;
         } elseif (is_singular('post')) {
             if (get_option('page_for_posts') == is_front_page()) {
                 echo $current_before . $page_title . $current_after;
             } else {
                 if ($is_ltr) {
                     echo '<a href="' . get_permalink(get_option('page_for_posts')) . '">' . $blog_title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
                 } else {
                     echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . get_permalink(get_option('page_for_posts')) . '">' . $blog_title . '</a>';
                 }
             }
         } elseif (x_is_portfolio()) {
             echo $current_before . get_the_title() . $current_after;
         } elseif (x_is_portfolio_item()) {
             $link = x_get_parent_portfolio_link();
             $title = x_get_parent_portfolio_title();
             if ($is_ltr) {
                 echo '<a href="' . $link . '">' . $title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
             } else {
                 echo $current_before . $page_title . $current_after . $delimiter . '<a href="' . $link . '">' . $title . '</a>';
             }
         } elseif (x_is_product()) {
             if ($is_ltr) {
                 echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
             } else {
                 echo $current_before . $page_title . $current_after . $delimiter . $shop_link;
             }
         } elseif (x_is_buddypress()) {
             if (bp_is_group()) {
                 echo '<a href="' . bp_get_groups_directory_permalink() . '">' . x_get_option('x_buddypress_groups_title') . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
             } elseif (bp_is_user()) {
                 echo '<a href="' . bp_get_members_directory_permalink() . '">' . x_get_option('x_buddypress_members_title') . '</a>' . $delimiter . $current_before . x_buddypress_get_the_title() . $current_after;
             } else {
                 echo $current_before . x_buddypress_get_the_title() . $current_after;
             }
         } elseif (x_is_bbpress()) {
             remove_filter('bbp_no_breadcrumb', '__return_true');
             if (bbp_is_forum_archive()) {
                 echo $current_before . bbp_get_forum_archive_title() . $current_after;
             } else {
                 echo bbp_get_breadcrumb();
             }
             add_filter('bbp_no_breadcrumb', '__return_true');
         } elseif (is_page() && !$post_parent) {
             echo $current_before . $page_title . $current_after;
         } elseif (is_page() && $post_parent) {
             $parent_id = $post_parent;
             $breadcrumbs = array();
             if (is_rtl()) {
                 echo $current_before . $page_title . $current_after . $delimiter;
             }
             while ($parent_id) {
                 $page = get_page($parent_id);
                 $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
                 $parent_id = $page->post_parent;
             }
             if ($is_ltr) {
                 $breadcrumbs = array_reverse($breadcrumbs);
             }
             for ($i = 0; $i < count($breadcrumbs); $i++) {
                 echo $breadcrumbs[$i];
                 if ($i != count($breadcrumbs) - 1) {
                     echo $delimiter;
                 }
             }
             if ($is_ltr) {
                 echo $delimiter . $current_before . $page_title . $current_after;
             }
         } elseif (is_tag()) {
             echo $current_before . single_tag_title('', false) . $current_after;
         } elseif (is_author()) {
             global $author;
             $userdata = get_userdata($author);
             echo $current_before . __('Posts by ', '__x__') . '&#8220;' . $userdata->display_name . $current_after . '&#8221;';
         } elseif (is_404()) {
             echo $current_before . __('404 (Page Not Found)', '__x__') . $current_after;
         } elseif (is_archive()) {
             if (x_is_shop()) {
                 echo $current_before . $shop_title . $current_after;
             } else {
                 echo $current_before . __('Archives ', '__x__') . $current_after;
             }
         }
         echo '</div>';
     }
 }
Example #14
0
 /**
  * Builds a link to the Group's ideas archive page
  *
  * @package WP Idea Stream
  * @subpackage buddypress/groups
  *
  * @since  2.0.0
  *
  * @param  BP_Groups_Group  $group    a group object
  * @param  bool             $fallback whether to use a fallback url
  * @uses   groups_get_current_group() to test if a current group is set
  * @uses   bp_get_groups_directory_permalink() to get the Groups directory permalink
  * @uses   bp_get_group_permalink() to build the link to group's home
  * @uses   WP_Idea_Stream_Group::group_get_option() to check for the group setting
  * @uses   wp_idea_stream_root_slug() to get IdeaStream root slug
  * @return string           permalink to the group's main idea page
  */
 public function group_ideas_archive_url($group = null, $fallback = false)
 {
     // Try to get current
     if (empty($group)) {
         $group = groups_get_current_group();
     }
     if (empty($group->slug)) {
         $group_url = false;
         // return the groups directory if slug is not set and
         // fallback is requested
         if (!empty($fallback)) {
             $group_url = bp_get_groups_directory_permalink();
         }
         return $group_url;
     }
     $group_url = bp_get_group_permalink($group);
     // return the group home url if IdeaStream is not active for this group
     if (!self::group_get_option($group->id, '_group_ideastream_activate', false)) {
         return $group_url;
     }
     // Return the group's IdeaStream Archive url.
     return trailingslashit($group_url . wp_idea_stream_root_slug());
 }
Example #15
0
 /**
  * Get the page context
  * @version 2.0
  */
 function get_context()
 {
     // Setup placeholders
     $title = SITENAME;
     $desc = get_bloginfo('description');
     $classes = get_body_class();
     $crumbs = array();
     // Get some data
     $id = $this->queried_object_id;
     $object = $this->queried_object;
     $sep = " &bull; ";
     /*--------------------------------------------
     			DEFAULT CONTEXT
     		---------------------------------------------*/
     $classes[] = 0 == get_current_user_id() ? 'logged-out' : 'logged-in';
     $crumbs[] = '<a href="' . SITEURL . '" title="' . SITENAME . '" rel="home" class="trail-home">Home</a>';
     // Homepage
     if (is_home()) {
         $title = SITENAME . $sep . 'Home';
         $classes[] = 'home';
         $classes[] = 'sidebar';
         $classes[] = 'archive';
         /*--------------------------------------------
         			BUDDYPRESS CONTEXT
         		---------------------------------------------*/
     } elseif (class_exists('BuddyPress') && is_buddypress()) {
         // BuddyPress Defaults
         $title = "BuddyPress Page";
         $desc = "This is a BuddyPress page.";
         $classes[] = 'buddypress';
         // User Profiles
         if (bp_is_user()) {
             $title = bp_get_displayed_user_fullname() . $sep . "User Profile";
             $desc = SITENAME . " user profile for member " . bp_get_displayed_user_fullname();
             // Your own profile
             if (bp_is_my_profile()) {
                 $crumbs[] = 'Your Profile';
             } else {
                 $crumbs[] = '<a href="' . bp_get_members_directory_permalink() . '" title="Members Directory">Members</a>';
                 $crumbs[] = '<a href="' . bp_displayed_user_domain() . '" title="' . bp_get_displayed_user_fullname() . '">' . bp_get_displayed_user_fullname() . '</a>';
             }
             // Display the profile component if it isnt the profile home
             if (!bp_is_user_profile()) {
                 $crumbs[] = ucfirst(bp_current_component());
             }
             // Display the current action if it is not the default public profile
             if (!in_array(bp_current_action(), array('public', 'just-me', 'my-friends'))) {
                 $crumbs[] = ucfirst(bp_current_action());
             }
             // Single Group
         } elseif (bp_is_group() || bp_is_group_create()) {
             // Group Creation
             if (bp_is_group_create()) {
                 $title = 'Submit New Group';
                 $desc = 'Submit a new user group for listing on the ' . SITENAME . ' community groups directory.';
                 $crumbs[] = '<a href="' . SITEURL . '/' . bp_get_groups_root_slug() . '" title="Groups Directory">Groups</a>';
                 $crumbs[] = 'Create Group';
             } elseif (bp_is_group()) {
                 // Default entries
                 $title = bp_get_group_name();
                 $desc = SITENAME . ' guild profile for ' . bp_get_group_name();
                 $classes = array_diff($classes, array('page', 'page-template-default'));
                 $crumbs[] = '<a href="' . bp_get_groups_directory_permalink() . '" title="Groups Directory">Groups</a>';
                 // Group Profile Home
                 if (bp_is_group_home()) {
                     $title = $title . $sep . 'Profile';
                     $crumbs[] = bp_get_group_name();
                     // Advanced Component
                 } else {
                     // Link back to group profile
                     $crumbs[] = '<a href="' . bp_get_group_permalink() . '" title="Return to Group Profile">' . bp_get_group_name() . '</a>';
                     // Members
                     if (bp_is_group_members()) {
                         $title = $title . $sep . 'Members';
                         $crumbs[] = 'Members';
                         // Activity
                     } elseif (bp_is_group_activity()) {
                         $title = $title . $sep . 'Activity';
                         $crumbs[] = 'Activity';
                         // Invites
                     } elseif (bp_is_group_invites()) {
                         $title = $title . $sep . 'Invitations';
                         $crumbs[] = 'Invitations';
                         // Admin
                     } elseif (bp_is_group_admin_page()) {
                         $title = $title . $sep . 'Admin';
                         $crumbs[] = 'Admin';
                         // Forum
                     } else {
                         // Forum Root
                         if (NULL == bp_action_variable()) {
                             $title = $title . $sep . 'Forum';
                             $crumbs[] = 'Forum';
                             // Sub-Component
                         } else {
                             $crumbs[] = '<a href="' . bp_get_group_permalink() . 'forum/" title="Group Forum">Forum</a>';
                             // Retrieve topic information from the database
                             global $bp;
                             global $wpdb;
                             // Single Topic
                             if (bp_is_action_variable('topic', 0)) {
                                 // Get the topic
                                 $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s", $bp->action_variables[1]));
                                 $title = $topic->title;
                                 $crumbs[] = $topic->title;
                                 // Replies
                             } elseif (bp_is_action_variable('reply', 0)) {
                                 // Get the reply parent topic
                                 $topic = $wpdb->get_row($wpdb->prepare("SELECT post_title AS title, post_name AS url\n\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\t\t\t\t\t\tWHERE ID = ( \n\t\t\t\t\t\t\t\t\t\t\tSELECT post_parent\n\t\t\t\t\t\t\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\t\t\t\t\t\t\tWHERE post_name = %s \n\t\t\t\t\t\t\t\t\t\t)", $bp->action_variables[1]));
                                 $title = $topic->title;
                                 $crumbs[] = $topic->title;
                             }
                             // Topic and Reply Edits
                             if (bp_is_action_variable('edit', 2)) {
                                 $crumbs[] = 'Edit';
                             }
                         }
                     }
                 }
             }
             // Directories
         } elseif (bp_is_directory()) {
             // Sitewide Activity
             if (bp_is_activity_component()) {
                 $title = SITENAME . ' Sitewide Activity Feed';
                 $desc = 'A listing of all recent activity happening throughout the ' . SITENAME . ' community.';
                 $crumbs[] = 'Sitewide Activity';
                 // Members Directory
             } elseif (bp_is_members_component()) {
                 $title = SITENAME . ' Members Directory';
                 $desc = 'A listing of all registered members in the ' . SITENAME . ' community.';
                 $crumbs[] = 'Members Directory';
                 // Groups Directory
             } elseif (bp_is_groups_component()) {
                 $title = SITENAME . ' Guilds Directory';
                 $desc = 'A directory listing of guilds active within in the ' . SITENAME . ' community.';
                 $crumbs[] = 'Guilds Directory';
             }
             // Registration
         } elseif (bp_is_register_page()) {
             $title = SITENAME . ' User Registration';
             $desc = "Register to join the " . SITENAME . " community.";
             $crumbs[] = "User Registration";
             // Activation
         } elseif (bp_is_activation_page()) {
             $title = SITENAME . ' Account Activation';
             $desc = "Activate a pending " . SITENAME . " user account.";
             $crumbs[] = "Account Activation";
         }
         /*--------------------------------------------
         			BBPRESS CONTEXT
         		---------------------------------------------*/
     } elseif (class_exists('bbPress') && is_bbpress()) {
         // bbPress Defaults
         $classes[] = 'bbpress';
         $classes[] = 'forums';
         $crumbs[] = bbp_is_forum_archive() ? "Forums" : '<a href="' . get_post_type_archive_link('forum') . '">Forums</a>';
         // Main Forum Archive
         if (bbp_is_forum_archive()) {
             $title = SITENAME . " Forums";
             $desc = "Get involved in the community on the " . SITENAME . " forums.";
             // Recent Topics
         } elseif (bbp_is_topic_archive()) {
             $title = "Recent Topics in the " . SITENAME . " Forums";
             $desc = "Browse a list of the most recent topics in the " . SITENAME . " Forums.";
             $crumbs[] = "Recent Topics";
             // Single Forum
         } elseif (bbp_is_single_forum()) {
             $title = $object->post_title;
             $desc = $object->post_content;
             // Loop through parent forums
             $parent_id = bbp_get_forum_parent_id($id);
             if (0 != $parent_id) {
                 $crumbs = array_merge($crumbs, $this->parent_crumbs($parent_id));
             }
             $crumbs[] = $object->post_title;
             // Single Topic
         } elseif (bbp_is_single_topic()) {
             $title = $object->post_title;
             $desc = bbp_get_topic_excerpt($id);
             $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_topic_forum_id($id)));
             $crumbs[] = $object->post_title;
             // Edit Topic
         } elseif (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) {
             $title = 'Edit Topic' . $sep . $object->post_title;
             $desc = bbp_get_topic_excerpt($id);
             $crumbs = array_merge($crumbs, $this->parent_crumbs($id));
             // Tag the specific task
             if (bbp_is_topic_split()) {
                 $crumbs[] = 'Split Topic';
             } elseif (bbp_is_topic_merge()) {
                 $crumbs[] = 'Merge Topic';
             } elseif (bbp_is_topic_edit()) {
                 $crumbs[] = 'Edit Topic';
             }
             // Edit Reply
         } elseif (bbp_is_reply_edit()) {
             $title = 'Edit Reply' . $sep . bbp_get_reply_topic_title($id);
             $desc = bbp_get_reply_excerpt($id);
             $crumbs = array_merge($crumbs, $this->parent_crumbs(bbp_get_reply_topic_id($id)));
             $crumbs[] = 'Edit Reply';
         }
         /*--------------------------------------------
         			WORDPRESS CONTEXT
         		---------------------------------------------*/
     } else {
         // Singular Posts and Pages
         if (is_singular()) {
             $title = $object->post_title;
             $desc = get_post_meta($id, 'description', true);
             // If no description is found, use an excerpt
             if (empty($desc)) {
                 $desc = get_post_field('post_excerpt', $id);
             }
             // Check for custom template
             $template = get_post_meta($id, "_wp_{$object->post_type}_template", true);
             if ('' != $template) {
                 $template = str_replace(array("{$object->post_type}-template-", "{$object->post_type}-"), '', basename($template, '.php'));
                 $classes[] = "{$template}-template";
             }
             // Generate breadcrumbs by post type
             switch ($object->post_type) {
                 // Single Posts
                 case 'post':
                     // Is the post in a category?
                     $categories = get_the_category();
                     if ($categories) {
                         // Start with the first category
                         $term = $categories[0];
                         // If the category has a parent, add it to the trail.
                         if (0 != $term->parent) {
                             $crumbs = array_merge($crumbs, $this->parent_crumbs($term->parent, 'category'));
                         }
                         // Add the category archive link to the trail.
                         $crumbs[] = '<a href="' . get_term_link($term) . '" title="' . esc_attr($term->name) . '">' . $term->name . '</a>';
                     }
                     // Does the post have an ancestor?
                     if ($object->post_parent) {
                         $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent));
                     }
                     // Editing a comment on this post
                     if (is_comment_edit()) {
                         $crumbs[] = '<a href="' . get_permalink() . '" title="Return to article">' . get_the_title() . '</a>';
                         $crumbs[] = 'Edit Comment';
                         // Reading the post
                     } else {
                         $crumbs[] = get_the_title();
                     }
                     break;
                     // Pages
                 // Pages
                 case 'page':
                     // Does the page have an ancestor?
                     if ($object->post_parent) {
                         $crumbs = array_merge($crumbs, $this->parent_crumbs($object->post_parent));
                     }
                     // Otherwise, viewing the page
                     $crumbs[] = get_the_title();
                     break;
                     // Events
                 // Events
                 case 'event':
                     // Get the calendar the event belongs to
                     $calendar = get_the_terms($object->ID, 'calendar');
                     $calendar = array_shift($calendar);
                     $desc = 'Upcoming event on the ' . $calendar->name . ' calendar.';
                     $crumbs[] = '<a href="' . SITEURL . '/calendar/' . $calendar->slug . '" title="' . $calendar->name . ' Calendar">' . $calendar->name . ' Calendar</a>';
                     $crumbs[] = get_the_title();
                     break;
             }
             // Archives
         } elseif (is_archive()) {
             // Category Archives
             if (is_category()) {
                 $crumbs[] = 'Category';
                 // If the category has a parent, add it to the trail.
                 if ($object->parent != 0) {
                     $crumbs = array_merge($crumbs, $this->trail_parents($object->parent));
                 }
                 // Finish up with the term name
                 $crumbs[] = $object->name;
                 // Author Archive
             } elseif (is_author()) {
                 $title = 'Author Archive' . $sep . $object->display_name;
                 $desc = 'An archive of articles written by ' . $object->display_name;
                 $crumbs[] = 'Author';
                 $crumbs[] = $object->display_name;
                 // Advanced Search Page
             } elseif (is_search()) {
                 $title = SITENAME . " Advanced Search";
                 $desc = "Search for a variety of content types throughout " . SITENAME;
                 $crumbs[] = 'Advanced Search';
                 $classes[] = 'page';
                 // Calendar
             } elseif (is_calendar()) {
                 $title = $object->name . " Calendar";
                 $desc = "Upcoming events on the " . $object->name . " calendar.";
                 $crumbs[] = $object->name . " Calendar";
             }
             // 404
         } elseif (is_404()) {
             $title = "Error" . $sep . "Page Not Found";
             $desc = "Sorry, but this page does not exist, or is not accessible at this time.";
             $classes[] = 'page';
             $crumbs[] = '404 Page Not Found';
         }
     }
     /*--------------------------------------------
     			RETURN DATA
     		---------------------------------------------*/
     $this->title = html_entity_decode($title);
     $this->description = html_entity_decode($desc);
     $this->classes = $classes;
     $this->crumbs = $crumbs;
 }
/**
 * @since 1.1.0
 *
 * @return string
 */
function bp_get_group_invite_user_remove_invite_url()
{
    global $invites_template;
    $user_id = intval($invites_template->invite->user->id);
    if (bp_is_current_action('create')) {
        $uninvite_url = bp_get_groups_directory_permalink() . 'create/step/group-invites/?user_id=' . $user_id;
    } else {
        $uninvite_url = bp_get_group_permalink(groups_get_current_group()) . 'send-invites/remove/' . $user_id;
    }
    return wp_nonce_url($uninvite_url, 'groups_invite_uninvite_user');
}
/**
 * Output group directory permalink
 *
 * @package BuddyPress
 * @subpackage Groups Template
 * @since BuddyPress (1.5)
 * @uses bp_get_groups_directory_permalink()
 */
function bp_groups_directory_permalink()
{
    echo bp_get_groups_directory_permalink();
}
Example #18
0
function my_group_creation_handler()
{
    // Create a cookie that will tell varnish not to cache the group directory for this user for the next x minutes, so the user can see the group they just created.
    error_log("group url:" . bp_get_groups_directory_permalink());
    $mygroupdir = trim(preg_replace("/([^\\/]+\$)/", "", preg_replace("/^https?:\\/\\/[^\\/]+(\\/*.+\\/).*/", " \$1 ", bp_get_groups_directory_permalink())));
    error_log("group uri:" . $mygroupdir);
    setrawcookie('disable_my_page_cache', $mygroupdir, time() + 65, $mygroupdir);
}
Example #19
0
 function kleo_ajax_search()
 {
     //if "s" input is missing exit
     if (empty($_REQUEST['s']) && empty($_REQUEST['bbp_search'])) {
         die;
     }
     if (!empty($_REQUEST['bbp_search'])) {
         $search_string = $_REQUEST['bbp_search'];
     } else {
         $search_string = $_REQUEST['s'];
     }
     $output = "";
     $context = "any";
     $defaults = array('numberposts' => 4, 'posts_per_page' => 20, 'post_type' => 'any', 'post_status' => 'publish', 'post_password' => '', 'suppress_filters' => false, 's' => $_REQUEST['s']);
     if (isset($_REQUEST['context']) && $_REQUEST['context'] != '') {
         $context = explode(",", $_REQUEST['context']);
         $defaults['post_type'] = $context;
     }
     $defaults = apply_filters('kleo_ajax_query_args', $defaults);
     $the_query = new WP_Query($defaults);
     $posts = $the_query->get_posts();
     $members = array();
     $members['total'] = 0;
     $groups = array();
     $groups['total'] = 0;
     $forums = FALSE;
     if (function_exists('bp_is_active') && ($context == "any" || in_array("members", $context))) {
         $members = bp_core_get_users(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false));
     }
     if (function_exists('bp_is_active') && bp_is_active("groups") && ($context == "any" || in_array("groups", $context))) {
         $groups = groups_get_groups(array('search_terms' => $search_string, 'per_page' => $defaults['numberposts'], 'populate_extras' => false));
     }
     if (class_exists('bbPress') && ($context == "any" || in_array("forum", $context))) {
         $forums = kleo_bbp_get_replies($search_string);
     }
     //if there are no posts, groups nor members
     if (empty($posts) && $members['total'] == 0 && $groups['total'] == 0 && !$forums) {
         $output = "<div class='kleo_ajax_entry ajax_not_found'>";
         $output .= "<div class='ajax_search_content'>";
         $output .= "<i class='icon icon-exclamation-sign'></i> ";
         $output .= __("Sorry, we haven't found anything based on your criteria.", 'kleo_framework');
         $output .= "<br>";
         $output .= __("Please try searching by different terms.", 'kleo_framework');
         $output .= "</div>";
         $output .= "</div>";
         echo $output;
         die;
     }
     //if there are members
     if ($members['total'] != 0) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-members">';
         $output .= '<h4><span>' . __("Members", 'kleo_framework') . '</span></h4>';
         foreach ((array) $members['users'] as $member) {
             $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $member->ID, 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">';
             if ($update = bp_get_user_meta($member->ID, 'bp_latest_update', true)) {
                 $latest_activity = char_trim(trim(strip_tags(bp_create_excerpt($update['content'], 50, "..."))));
             } else {
                 $latest_activity = '';
             }
             $output .= "<div class ='kleo_ajax_entry'>";
             $output .= "<div class='ajax_search_image'>{$image}</div>";
             $output .= "<div class='ajax_search_content'>";
             $output .= "<a href='" . bp_core_get_user_domain($member->ID) . "' class='search_title'>";
             $output .= $member->display_name;
             $output .= "</a>";
             $output .= "<span class='search_excerpt'>";
             $output .= $latest_activity;
             $output .= "</span>";
             $output .= "</div>";
             $output .= "</div>";
         }
         $output .= "<a class='ajax_view_all' href='" . bp_get_members_directory_permalink() . "?s=" . $search_string . "'>" . __('View member results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     //if there are groups
     if ($groups['total'] != 0) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-groups">';
         $output .= '<h4><span>' . __("Groups", 'kleo_framework') . '</span></h4>';
         foreach ((array) $groups['groups'] as $group) {
             $image = '<img src="' . bp_core_fetch_avatar(array('item_id' => $group->id, 'object' => 'group', 'width' => 25, 'height' => 25, 'html' => false)) . '" class="kleo-rounded" alt="">';
             $output .= "<div class ='kleo_ajax_entry'>";
             $output .= "<div class='ajax_search_image'>{$image}</div>";
             $output .= "<div class='ajax_search_content'>";
             $output .= "<a href='" . bp_get_group_permalink($group) . "' class='search_title'>";
             $output .= $group->name;
             $output .= "</a>";
             $output .= "</div>";
             $output .= "</div>";
         }
         $output .= "<a class='ajax_view_all' href='" . bp_get_groups_directory_permalink() . "?s=" . $search_string . "'>" . __('View group results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     //if there are posts
     if (!empty($posts)) {
         $post_types = array();
         $post_type_obj = array();
         foreach ($posts as $post) {
             $post_types[$post->post_type][] = $post;
             if (empty($post_type_obj[$post->post_type])) {
                 $post_type_obj[$post->post_type] = get_post_type_object($post->post_type);
             }
         }
         foreach ($post_types as $ptype => $post_type) {
             $output .= '<div class="kleo-ajax-part kleo-ajax-type-' . esc_attr($post_type_obj[$ptype]->name) . '">';
             if (isset($post_type_obj[$ptype]->labels->name)) {
                 $output .= "<h4><span>" . $post_type_obj[$ptype]->labels->name . "</span></h4>";
             } else {
                 $output .= "<hr>";
             }
             $count = 0;
             foreach ($post_type as $post) {
                 $count++;
                 if ($count > 4) {
                     continue;
                 }
                 $format = get_post_format($post->ID);
                 if ($img_url = kleo_get_post_thumbnail_url($post->ID)) {
                     $image = aq_resize($img_url, 44, 44, true, true, true);
                     if (!$image) {
                         $image = $img_url;
                     }
                     $image = '<img src="' . $image . '" class="kleo-rounded">';
                 } else {
                     if ($format == 'video') {
                         $image = "<i class='icon icon-video'></i>";
                     } elseif ($format == 'image' || $format == 'gallery') {
                         $image = "<i class='icon icon-picture'></i>";
                     } else {
                         $image = "<i class='icon icon-link'></i>";
                     }
                 }
                 $excerpt = "";
                 if (!empty($post->post_content)) {
                     $excerpt = char_trim(trim(strip_tags(strip_shortcodes($post->post_content))), 40, "...");
                 }
                 $link = apply_filters('kleo_custom_url', get_permalink($post->ID));
                 $classes = "format-" . $format;
                 $output .= "<div class ='kleo_ajax_entry {$classes}'>";
                 $output .= "<div class='ajax_search_image'>{$image}</div>";
                 $output .= "<div class='ajax_search_content'>";
                 $output .= "<a href='{$link}' class='search_title'>";
                 $output .= get_the_title($post->ID);
                 $output .= "</a>";
                 $output .= "<span class='search_excerpt'>";
                 $output .= $excerpt;
                 $output .= "</span>";
                 $output .= "</div>";
                 $output .= "</div>";
             }
             $output .= '</div>';
         }
         $output .= "<a class='ajax_view_all' href='" . home_url('/') . '?s=' . $search_string . "'>" . __('View all results', 'kleo_framework') . "</a>";
     }
     /* Forums topics search */
     if (!empty($forums)) {
         $output .= '<div class="kleo-ajax-part kleo-ajax-type-forums">';
         $output .= '<h4><span>' . __("Forums", 'kleo_framework') . '</span></h4>';
         $i = 0;
         foreach ($forums as $fk => $forum) {
             $i++;
             if ($i <= 4) {
                 $image = "<i class='icon icon-chat-1'></i>";
                 $output .= "<div class ='kleo_ajax_entry'>";
                 $output .= "<div class='ajax_search_image'>{$image}</div>";
                 $output .= "<div class='ajax_search_content'>";
                 $output .= "<a href='" . $forum['url'] . "' class='search_title'>";
                 $output .= $forum['name'];
                 $output .= "</a>";
                 //$output .= "<span class='search_excerpt'>";
                 //$output .= $latest_activity;
                 //$output .= "</span>";
                 $output .= "</div>";
                 $output .= "</div>";
             }
         }
         $output .= "<a class='ajax_view_all' href='" . bbp_get_search_url() . "?bbp_search=" . $search_string . "'>" . __('View forum results', 'kleo_framework') . "</a>";
         $output .= "</div>";
     }
     echo $output;
     die;
 }
/**
 * Return the permalink to a given forum.
 *
 * @since 1.0.0
 *
 * @param int $forum_id Optional. Defaults to the current forum, if
 *                      there is one.
 * @return string|bool False on failure, a URL on success.
 */
function bp_get_forum_permalink($forum_id = 0)
{
    if (bp_is_groups_component()) {
        $permalink = trailingslashit(bp_get_groups_directory_permalink() . bp_current_item() . '/forum');
    } else {
        if (empty($forum_id)) {
            global $topic_template;
            if (isset($topic_template->forum_id)) {
                $forum_id = $topic_template->forum_id;
            }
        }
        if ($forum = bp_forums_get_forum($forum_id)) {
            $permalink = trailingslashit(bp_get_root_domain() . '/' . bp_get_forums_root_slug() . '/forum/' . $forum->forum_slug);
        } else {
            return false;
        }
    }
    /**
     * Filters the permalink to a given forum.
     *
     * @since 1.0.0
     *
     * @param string $value Peramlink to the given forum.
     */
    return apply_filters('bp_get_forum_permalink', trailingslashit($permalink));
}