function wpmudev_chat_friends_dashboard_widget_proc()
        {
            global $bp, $wpmudev_chat, $current_user;
            $friends_list_ids = array();
            if (!empty($bp) && function_exists('bp_get_friend_ids')) {
                $friends_ids = bp_get_friend_ids($bp->loggedin_user->id);
                //echo "friends_ids=[". $friends_ids ."]<br />";
                if (!empty($friends_ids)) {
                    $friends_list_ids = explode(',', $friends_ids);
                }
                //echo "friends_list_ids<pre>"; print_r($friends_list_ids); echo "</pre>";
            } else {
                if (!is_admin() && !function_exists('is_plugin_active')) {
                    include_once ABSPATH . 'wp-admin/includes/plugin.php';
                }
                if (!is_plugin_active('friends/friends.php')) {
                    if (is_multisite() && !is_plugin_active_for_network('friends/friends.php')) {
                        ?>
<p class="error"><?php 
                        $this->plugin_error_message;
                        ?>
</p><?php 
                        return;
                    }
                }
                if (!function_exists('friends_get_list')) {
                    return;
                }
                $friends_list_ids = friends_get_list($current_user->ID);
            }
            //echo "friends_list_ids<pre>"; print_r($friends_list_ids); echo "</pre>";
            if (!is_array($friends_list_ids) || !count($friends_list_ids)) {
                return;
            }
            $chat_output = '';
            $friends_status = wpmudev_chat_get_friends_status($current_user->ID, $friends_list_ids);
            //echo "friends_status<pre>"; print_r($friends_status); echo "</pre>";
            if ($friends_status && is_array($friends_status) && count($friends_status)) {
                //echo "friends_status<pre>"; print_r($friends_status); echo "</pre>";
                foreach ($friends_status as $friend) {
                    if (isset($friend->chat_status) && $friend->chat_status == "available") {
                        $friend_status_data = wpmudev_chat_get_chat_status_data($current_user->ID, $friend);
                        //echo "friend_status_data<pre>"; print_r($friend_status_data); echo "</pre>";
                        $chat_output .= '<li><a class="' . $friend_status_data['href_class'] . '" title="' . $friend_status_data['href_title'] . '" href="#" rel="' . md5($friend->ID) . '"><span class="wpmudev-chat-ab-icon wpmudev-chat-ab-icon-' . $friend->chat_status . '"></span><span class="wpmudev-chat-ab-label">' . $friend->display_name . '</span>' . '</a></li>';
                    }
                }
                if (!empty($chat_output)) {
                    $height_style = ' style="max-height: ' . $this->instance['box_height'] . '; overflow:auto;" ';
                    echo '<ul id="wpmudev-chat-friends-dashboard-widget" ' . $height_style . ' class="wpmudev-chat-friends-widget">' . $chat_output . '</ul>';
                }
            } else {
                ?>
<p><?php 
                _e("No Friends online.", $wpmudev_chat->translation_domain);
                ?>
</p><?php 
            }
        }
function wpmudev_chat_wpadminbar_menu_friends($_parent_menu_id = '', $user_id = 0)
{
    global $wp_admin_bar, $wpmudev_chat, $bp;
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    if (!$user_id) {
        return;
    }
    if (!empty($bp) && function_exists('bp_get_friend_ids')) {
        //echo "here in BP land!<br />";
        $friends_ids = bp_get_friend_ids($bp->loggedin_user->id);
        //echo "friends_ids=[". $friends_ids ."]<br />";
        if (!empty($friends_ids)) {
            $friends_list_ids = explode(',', $friends_ids);
        }
        //echo "friend_ids<pre>"; print_r($friend_ids); echo "</pre>";
        //die();
    } else {
        if (!is_admin() && !function_exists('is_plugin_active')) {
            include_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        if (!is_plugin_active('friends/friends.php')) {
            if (is_multisite() && !is_plugin_active_for_network('friends/friends.php')) {
                return;
            }
        }
        if (!function_exists('friends_get_list')) {
            return;
        }
        $friends_list_ids = friends_get_list($user_id);
    }
    //	echo "friends_list_ids<pre>"; print_r($friends_list_ids); echo "</pre>";
    if (empty($friends_list_ids)) {
        return;
    }
    $friends_status = wpmudev_chat_get_friends_status($user_id, $friends_list_ids);
    //echo "friends_status<pre>"; print_r($friends_status); echo "</pre>";
    if ($friends_status && is_array($friends_status) && count($friends_status)) {
        $wp_admin_bar->add_menu(array('parent' => $_parent_menu_id, 'id' => 'wpmudev-chat-user-friends', 'title' => __('Friends Online', $wpmudev_chat->translation_domain), 'href' => false));
        //echo "friends_status<pre>"; print_r($friends_status); echo "</pre>";
        foreach ($friends_status as $friend) {
            if (isset($friend->chat_status) && $friend->chat_status == "available") {
                $friend_status_data = wpmudev_chat_get_chat_status_data($user_id, $friend);
                //echo "friend_status_data<pre>"; print_r($friend_status_data); echo "</pre>";
                $wp_admin_bar->add_menu(array('parent' => 'wpmudev-chat-user-friends', 'id' => md5($friend->ID), 'title' => '<a class="ab-item ' . $friend_status_data['href_class'] . '" title="' . $friend_status_data['href_title'] . '" href="#" rel="' . md5($friend->ID) . '"><span class="wpmudev-chat-ab-icon wpmudev-chat-ab-icon-' . $friend->chat_status . '"></span>' . '<span class="wpmudev-chat-ab-label">' . $friend->display_name . '</span>' . '</a>'));
            }
        }
    } else {
        $wp_admin_bar->add_menu(array('parent' => $_parent_menu_id, 'id' => 'wpmudev-chat-user-friends', 'title' => __('Friends Online', $wpmudev_chat->translation_domain), 'href' => false));
        $wp_admin_bar->add_menu(array('parent' => 'wpmudev-chat-user-friends', 'title' => __('None', $wpmudev_chat->translation_domain), 'id' => 'none'));
    }
}
function wpmudev_chat_wpadminbar_menu_friends($_parent_menu_id = '', $user_id = 0)
{
    global $wp_admin_bar, $wpmudev_chat, $bp;
    if (!$user_id) {
        $user_id = get_current_user_id();
    }
    if (!$user_id) {
        return;
    }
    if (!empty($bp) && function_exists('bp_get_friend_ids')) {
        $friends_ids = bp_get_friend_ids($bp->loggedin_user->id);
        if (!empty($friends_ids)) {
            $friends_list_ids = explode(',', $friends_ids);
        }
    } else {
        if (!is_admin() && !function_exists('is_plugin_active')) {
            include_once ABSPATH . 'wp-admin/includes/plugin.php';
        }
        if (!is_plugin_active('friends/friends.php')) {
            if (is_multisite() && !is_plugin_active_for_network('friends/friends.php')) {
                return;
            }
        }
        if (!function_exists('friends_get_list')) {
            return;
        }
        $friends_list_ids = friends_get_list($user_id);
    }
    if (empty($friends_list_ids)) {
        return;
    }
    $friends_status = wpmudev_chat_get_friends_status($user_id, $friends_list_ids);
    if ($friends_status && is_array($friends_status) && count($friends_status)) {
        $wp_admin_bar->add_menu(array('parent' => $_parent_menu_id, 'id' => 'wpmudev-chat-user-friends', 'title' => __('Friends Online', $wpmudev_chat->translation_domain), 'href' => false));
        $has_friends = false;
        foreach ($friends_status as $friend) {
            if (isset($friend->chat_status) && $friend->chat_status == "available") {
                $friend_status_data = wpmudev_chat_get_chat_status_data($user_id, $friend);
                $menu_title = '<a class="ab-item ' . $friend_status_data['href_class'] . '" title="' . $friend_status_data['href_title'] . '" href="#" rel="' . md5($friend->ID) . '">';
                $friend->avatar = get_avatar($friend->ID, 25, get_option('avatar_default'), $friend->display_name);
                if (!empty($friend->avatar)) {
                    $menu_title .= '<span class="wpmudev-chat-friend-avatar">' . $friend->avatar . '</span>';
                }
                $menu_title .= '<span style="margin-left: 5px;" class="wpmudev-chat-ab-label">' . $friend->display_name . '</span></a>';
                $wp_admin_bar->add_menu(array('parent' => 'wpmudev-chat-user-friends', 'id' => md5($friend->ID), 'title' => $menu_title));
                $has_friends = true;
            }
        }
        // If we don't have any actual available friends then show a stub
        if ($has_friends == false) {
            $wp_admin_bar->add_menu(array('parent' => 'wpmudev-chat-user-friends', 'title' => __('None', $wpmudev_chat->translation_domain), 'id' => 'none'));
        }
    } else {
        $wp_admin_bar->add_menu(array('parent' => $_parent_menu_id, 'id' => 'wpmudev-chat-user-friends', 'title' => __('Friends Online', $wpmudev_chat->translation_domain), 'href' => false));
        $wp_admin_bar->add_menu(array('parent' => 'wpmudev-chat-user-friends', 'title' => __('None', $wpmudev_chat->translation_domain), 'id' => 'none'));
    }
}