Example #1
0
function dln_get_notifications()
{
    if (!is_user_logged_in()) {
        return false;
    }
    $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
    if (!$notifications) {
        return null;
    }
    // Assign notification type
    foreach ($notifications as $i => $nof) {
        if (isset($nof->id)) {
            $componen_actions = bp_notifications_get_notification($nof->id);
            switch ($componen_actions->component_name) {
                case 'messages':
                    $notifications[$i]->icon = 'ico-mail-send bgcolor-info';
                    break;
                case 'friends':
                    $notifications[$i]->icon = 'ico-user-plus bgcolor-success';
                    break;
                default:
                    $notifications[$i]->icon = 'ico-notification';
                    break;
            }
        }
    }
    return $notifications;
}
/**
 * Create the Notifications menu for the BuddyBar.
 *
 * @since BuddyPress (1.9.0)
 */
function bp_notifications_buddybar_menu()
{
    if (!is_user_logged_in()) {
        return false;
    }
    echo '<li id="bp-adminbar-notifications-menu"><a href="' . esc_url(bp_loggedin_user_domain()) . '">';
    _e('Notifications', 'buddypress');
    if ($notification_count = bp_notifications_get_unread_notification_count(bp_loggedin_user_id())) {
        ?>
		<span><?php 
        echo bp_core_number_format($notification_count);
        ?>
</span>
	<?php 
    }
    echo '</a>';
    echo '<ul>';
    if ($notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id())) {
        $counter = 0;
        for ($i = 0, $count = count($notifications); $i < $count; ++$i) {
            $alt = 0 == $counter % 2 ? ' class="alt"' : '';
            ?>

			<li<?php 
            echo $alt;
            ?>
><?php 
            echo $notifications[$i];
            ?>
</li>

			<?php 
            $counter++;
        }
    } else {
        ?>

		<li><a href="<?php 
        echo esc_url(bp_loggedin_user_domain());
        ?>
"><?php 
        _e('No new notifications.', 'buddypress');
        ?>
</a></li>

	<?php 
    }
    echo '</ul>';
    echo '</li>';
}
/**
 * Build the "Notifications" dropdown.
 *
 * @since BuddyPress (1.9.0)
 *
 * @return bool
 */
function bp_notifications_toolbar_menu()
{
    global $wp_admin_bar;
    if (!is_user_logged_in()) {
        return false;
    }
    $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
    $count = !empty($notifications) ? count($notifications) : 0;
    $alert_class = (int) $count > 0 ? 'pending-count alert' : 'count no-alert';
    $menu_title = '<span id="ab-pending-notifications" class="' . $alert_class . '">' . number_format_i18n($count) . '</span>';
    $menu_link = trailingslashit(bp_loggedin_user_domain() . bp_get_notifications_slug());
    // Add the top-level Notifications button
    $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'bp-notifications', 'title' => $menu_title, 'href' => $menu_link));
    if (!empty($notifications)) {
        foreach ((array) $notifications as $notification) {
            $wp_admin_bar->add_menu(array('parent' => 'bp-notifications', 'id' => 'notification-' . $notification->id, 'title' => $notification->content, 'href' => $notification->href));
        }
    } else {
        $wp_admin_bar->add_menu(array('parent' => 'bp-notifications', 'id' => 'no-notifications', 'title' => __('No new notifications', 'buddypress'), 'href' => $menu_link));
    }
    return;
}
Example #4
0
/** 
 * Include buddypress in menu.
 * @return $items
 */
function mmm_nav_buddypress($items, $args)
{
    global $mega_main_menu;
    $args = (object) $args;
    if (isset($args->theme_location)) {
        $args->theme_location = str_replace(' ', '-', $args->theme_location);
        $mega_menu_locations = is_array($mega_main_menu->get_option('mega_menu_locations')) ? $mega_main_menu->get_option('mega_menu_locations') : array();
        if (in_array($args->theme_location, $mega_menu_locations) && is_array($mega_main_menu->get_option($args->theme_location . '_included_components')) && in_array('buddypress', $mega_main_menu->get_option($args->theme_location . '_included_components'))) {
            if (class_exists('BuddyPress')) {
                global $bp;
                $bp_avatar = bp_core_fetch_avatar(array('item_id' => $bp->loggedin_user->id, 'html' => false));
                if (strpos($bp_avatar, 'gravatar') !== false) {
                    $bp_avatar = $bp->avatar->thumb->default;
                }
                $buddypress_item = '';
                $drop_side = $mega_main_menu->get_option('language_direction', 'ltr') == 'ltr' ? 'drop_to_left' : 'drop_to_right';
                if (is_user_logged_in()) {
                    $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
                    $count = !empty($notifications) ? count($notifications) : 0;
                    $menu_link = trailingslashit(bp_loggedin_user_domain() . bp_get_notifications_slug());
                    $notification_class = (int) $count > 0 ? 'notification-yes' : 'notification-none';
                    $buddypress_item .= mm_common::ntab(1) . '<li class="menu-item nav_buddypress default_dropdown ' . $drop_side . ' submenu_default_width">';
                    $buddypress_item .= mm_common::ntab(2) . '<a href="' . $menu_link . '" tabindex="0" class="item_link ">';
                    $buddypress_item .= mm_common::ntab(3) . '<i class="ci-icon-buddypress-user"><style>.ci-icon-buddypress-user:before{ background-image: url("' . $bp_avatar . '"); }</style><span class="mega_notifications ' . $notification_class . '">' . $count . '</span></i>';
                    $buddypress_item .= mm_common::ntab(3) . '';
                    $buddypress_item .= mm_common::ntab(2) . '</a><!--  class="item_link" -->';
                    $buddypress_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';
                    foreach ($bp->bp_nav as $key => $component) {
                        switch ($component['slug']) {
                            case 'activity':
                                $icon = 'health';
                                break;
                            case 'profile':
                                $icon = 'user';
                                break;
                            case 'notifications':
                                $icon = 'notification-2';
                                break;
                            case 'messages':
                                $icon = 'envelop-opened';
                                break;
                            case 'friends':
                                $icon = 'users';
                                break;
                            case 'groups':
                                $icon = 'tree-5';
                                break;
                            default:
                                $icon = 'cog';
                                break;
                        }
                        $buddypress_item .= mm_common::ntab(3) . '<li class="menu-item">';
                        $buddypress_item .= mm_common::ntab(4) . '<a href="' . $component['link'] . '" tabindex="0" class="item_link with_icon">';
                        $buddypress_item .= mm_common::ntab(5) . '<i class="im-icon-' . $icon . '"></i>';
                        $buddypress_item .= mm_common::ntab(5) . '<span class="link_content">';
                        $buddypress_item .= mm_common::ntab(6) . '<span class="link_text">' . $component['name'] . '</span>';
                        $buddypress_item .= mm_common::ntab(5) . '</span>';
                        $buddypress_item .= mm_common::ntab(4) . '</a><!-- class="item_link" -->';
                        if (is_array($bp->bp_options_nav[$component['slug']])) {
                            $buddypress_item .= mm_common::ntab(4) . '<ul class="mega_dropdown">';
                            foreach ($bp->bp_options_nav[$component['slug']] as $key => $sub_component) {
                                $buddypress_item .= mm_common::ntab(5) . '<li class="menu-item">';
                                $buddypress_item .= mm_common::ntab(6) . '<a href="' . $sub_component['link'] . '" tabindex="0" class="item_link">';
                                $buddypress_item .= mm_common::ntab(7) . '<span class="link_content">';
                                $buddypress_item .= mm_common::ntab(8) . '<span class="link_text">' . $sub_component['name'] . '</span>';
                                $buddypress_item .= mm_common::ntab(7) . '</span>';
                                $buddypress_item .= mm_common::ntab(6) . '</a><!-- class="item_link" -->';
                                $buddypress_item .= mm_common::ntab(5) . '</li>';
                            }
                            $buddypress_item .= mm_common::ntab(4) . '</ul><!-- class="mega_dropdown" -->';
                        }
                        $buddypress_item .= mm_common::ntab(3) . '</li>';
                    }
                    $buddypress_item .= mm_common::ntab(3) . '<li class="menu-item">';
                    $buddypress_item .= mm_common::ntab(4) . '<a href="' . wp_logout_url() . '" title="' . __('Log Out') . '" tabindex="0" class="item_link with_icon">';
                    $buddypress_item .= mm_common::ntab(5) . '<i class="im-icon-switch"></i>';
                    $buddypress_item .= mm_common::ntab(5) . '<span class="link_content">';
                    $buddypress_item .= mm_common::ntab(6) . '<span class="link_text">';
                    $buddypress_item .= mm_common::ntab(7) . __('Log Out');
                    $buddypress_item .= mm_common::ntab(6) . '</span>';
                    $buddypress_item .= mm_common::ntab(5) . '</span>';
                    $buddypress_item .= mm_common::ntab(4) . '</a>';
                    $buddypress_item .= mm_common::ntab(3) . '</li>';
                    $buddypress_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
                    $buddypress_item .= mm_common::ntab(1) . '</li><!-- class="nav_buddypress" -->' . mm_common::ntab(0);
                } else {
                    $buddypress_item .= mm_common::ntab(1) . '<li class="nav_buddypress not_logged default_dropdown ' . $drop_side . ' submenu_default_width">';
                    $buddypress_item .= mm_common::ntab(2) . '<span class="item_link">';
                    $buddypress_item .= mm_common::ntab(3) . '<i class="im-icon-user"></i>';
                    $buddypress_item .= mm_common::ntab(2) . '</span><!--  class="item_link" -->';
                    $buddypress_item .= mm_common::ntab(2) . '<ul class="mega_dropdown">';
                    $buddypress_item .= mm_common::ntab(3) . wp_login_form(array('echo' => false));
                    $buddypress_item .= mm_common::ntab(2) . '</ul><!-- class="mega_dropdown" -->';
                    $buddypress_item .= mm_common::ntab(1) . '</li><!-- class="nav_buddypress" -->' . mm_common::ntab(0);
                }
                $items = $items . $buddypress_item;
            }
        }
    }
    return $items;
}
/**
 * Get notifications for a specific user
 *
 * @deprecated Deprecated since BuddyPress 1.9.0. Use
 *  bp_notifications_get_notifications_for_user() instead.
 *
 * @since BuddyPress (1.0)
 * @global BuddyPress $bp
 * @param int $user_id
 * @param string $format
 * @return boolean Object or array on success, false on fail
 */
function bp_core_get_notifications_for_user($user_id, $format = 'string')
{
    // Bail if notifications is not active
    if (!bp_is_active('notifications')) {
        return false;
    }
    // Trigger the deprecated function notice
    _deprecated_function(__FUNCTION__, '1.9', 'bp_notifications_get_notifications_for_user()');
    $renderable = bp_notifications_get_notifications_for_user($user_id, $format);
    return apply_filters('bp_core_get_notifications_for_user', $renderable, $user_id, $format);
}
Example #6
0
function vbp_current_user_notification_count()
{
    if (function_exists('bp_notifications_get_notifications_for_user')) {
        $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
    }
    $count = !empty($notifications) ? count($notifications) : 0;
    return $count;
}
Example #7
0
/**
 * Roll our custom Bootstrap Notifications
 *
 * @since 1.0
 */
function wff_bp_notifications_menu()
{
    if (!is_user_logged_in()) {
        return false;
    }
    echo '<li class="dropdown menu-groups notification-nav" id="bp-adminbar-notifications-menu"><a data-toggle="dropdown" class="dropdown-toggle has-submenu" href="' . esc_url(bp_loggedin_user_domain()) . '"><i class="fa fa-bell"></i>';
    _e('', 'buddypress');
    if ($notification_count = bp_notifications_get_unread_notification_count(bp_loggedin_user_id())) {
        ?>
		<span id="notification-counter"><?php 
        echo bp_core_number_format($notification_count);
        ?>
</span>
		<?php 
    }
    echo '</a>';
    echo '<ul class="dropdown-menu">';
    if ($notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id())) {
        $counter = 0;
        for ($i = 0, $count = count($notifications); $i < $count; ++$i) {
            $alt = 0 == $counter % 2 ? ' class="alt"' : '';
            ?>

			<li<?php 
            echo $alt;
            ?>
><?php 
            echo $notifications[$i];
            ?>
</li>

			<?php 
            $counter++;
        }
    } else {
        ?>

		<li>
			<a href="<?php 
        echo esc_url(bp_loggedin_user_domain());
        ?>
">
				<?php 
        _e('No new notifications.', 'buddypress');
        ?>
			</a>
		</li>

		<?php 
    }
    echo '</ul>';
    echo '</li>';
}
Example #8
0
/**
 * Display Notifications Menu in the Header of the theme
 *
 * @since v1.0
 */
function bpmagic_notifications_menu()
{
    if (class_exists('ClearBpNotifications')) {
        ClearBpNotifications::add_notifications_menu();
        return;
    }
    echo '<li class="top-nav-main-item top-nav-item-first top-notification-menu"><a href="' . bp_loggedin_user_domain() . '">' . __('Notifications', 'bp-magic');
    if (function_exists('bp_notifications_get_notifications_for_user')) {
        $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id());
    } else {
        $notifications = bp_core_get_notifications_for_user(bp_loggedin_user_id());
        //this method is depricated in 1.9
    }
    if ($notifications) {
        ?>
		<span><?php 
        echo count($notifications);
        ?>
</span>
		<?php 
    }
    echo '</a>';
    echo '<ul>';
    if ($notifications) {
        $counter = 0;
        for ($i = 0, $count = count($notifications); $i < $count; ++$i) {
            $alt = 0 == $counter % 2 ? ' class="alt"' : '';
            ?>

			<li<?php 
            echo $alt;
            ?>
><?php 
            echo $notifications[$i];
            ?>
</li>

			<?php 
            $counter++;
        }
    } else {
        ?>

		<li><a href="<?php 
        echo bp_loggedin_user_domain();
        ?>
"><?php 
        _e('No new notifications.', 'bp-magic');
        ?>
</a></li>

		<?php 
    }
    echo '</ul>';
    echo '</li>';
}
 function simpleportal_current_user_notification_count()
 {
     $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
     $count = !empty($notifications) ? count($notifications) : 0;
     echo $count;
 }
 /**
  * @group  notification_callback
  * @ticket BP7141
  */
 public function test_notification_callback_parameter_integrity()
 {
     $u = $this->factory->user->create();
     $n = $this->factory->notification->create(array('component_name' => 'activity', 'component_action' => 'new_at_mention', 'item_id' => 99, 'user_id' => $u));
     // Override activity notification callback so we can test integrity.
     buddypress()->activity->notification_callback = array($this, 'dummy_notification_callback');
     // Fetch notifications with string format.
     bp_notifications_get_notifications_for_user($u, 'string');
     // Assert!
     // @todo When we cast all numeric strings as integers, this needs to be changed.
     $expected = array('action' => 'new_at_mention', 'item_id' => '99', 'secondary_item_id' => '0', 'total_items' => 1, 'id' => (string) $n, 'format' => 'string');
     $this->assertEquals($expected, $this->n_args);
     // Fetch notifications with object format this time.
     bp_notifications_get_notifications_for_user($u, 'object');
     // Assert!
     $expected['format'] = 'array';
     $this->assertEquals($expected, $this->n_args);
     // Reset!
     buddypress()->activity->notification_callback = 'bp_activity_format_notifications';
     unset($this->n_args);
 }
Example #11
0
/**
 * Sending a heartbeat for notification updates
 * 
 * @since Boss 1.0.0 
 *
 */
function buddyboss_notification_count_heartbeat($response, $data, $screen_id)
{
    if (function_exists("bp_friend_get_total_requests_count")) {
        $friend_request_count = bp_friend_get_total_requests_count();
    }
    if (function_exists("bp_notifications_get_all_notifications_for_user")) {
        $notifications = bp_notifications_get_all_notifications_for_user(get_current_user_id());
    }
    $notification_count = count($notifications);
    if (function_exists("bp_notifications_get_all_notifications_for_user")) {
        $notifications = bp_notifications_get_notifications_for_user(get_current_user_id());
        foreach ((array) $notifications as $notification) {
            $notification_content .= $notification;
        }
        if (empty($notification_content)) {
            $notification_content = '<a href="' . bp_loggedin_user_domain() . '' . BP_NOTIFICATIONS_SLUG . '/">' . __("No new notifications", "buddypress") . '</a>';
        }
    }
    if (function_exists("messages_get_unread_count")) {
        $unread_message_count = messages_get_unread_count();
    }
    $response['bb_notification_count'] = array('friend_request' => @intval($friend_request_count), 'notification' => @intval($notification_count), 'notification_content' => @$notification_content, 'unread_message' => @intval($unread_message_count));
    return $response;
}
Example #12
0
function kleo_bp_notifications_refresh()
{
    $response = array();
    if (!isset($_GET['current'])) {
        $response['status'] = 'failure';
        echo json_encode($response);
        exit;
    }
    $old_count = (int) $_GET['current'];
    $notifications = bp_notifications_get_notifications_for_user(bp_loggedin_user_id(), 'object');
    $count = !empty($notifications) ? count($notifications) : 0;
    if ($count == $old_count) {
        $response['status'] = 'no_change';
        echo json_encode($response);
        exit;
    }
    $output = '';
    if (!empty($notifications)) {
        foreach ((array) $notifications as $notification) {
            $output .= '<li class="kleo-submenu-item" id="kleo-notification-' . $notification->id . '">';
            $output .= '<a href="' . $notification->href . '">' . $notification->content . '</a>';
            $output .= '</li>';
        }
    } else {
        $output .= '<li class="kleo-submenu-item">' . __('No new notifications', 'kleo_framework') . '</li>';
    }
    $response['data'] = $output;
    $response['count'] = $count;
    $response['status'] = 'success';
    echo json_encode($response);
    exit;
}