/**
 *    OpenSource-SocialNetwork
 *
 * @package   (Informatikon.com).ossn
 * @author    OSSN Core Team <*****@*****.**>
 * @copyright 2014 iNFORMATIKON TECHNOLOGIES
 * @license   General Public Licence http://opensource-socialnetwork.com/licence
 * @link      http://www.opensource-socialnetwork.com/licence
 */
//declear empty variables;
$friends_c = '';
//init classes
$notification = new OssnNotifications();
$messages = new OssnMessages();
$count_notif = $notification->countNotification(ossn_loggedin_user()->guid);
$count_messages = $messages->countUNREAD(ossn_loggedin_user()->guid);
$friends = ossn_loggedin_user()->getFriendRequests();
if (count($friends) > 0 && !empty($friends)) {
    $friends_c = count($friends);
}
?>
<li id="ossn-notif-friends">
    <a onClick="Ossn.NotificationFriendsShow(this);" class="ossn-notifications-friends" href="javascript::;">
                       <span>
                      <?php 
if ($friends_c > 0) {
    ?>
                          <div class="ossn-icon ossn-icons-topbar-friends-new ossn-icons-topbar"></div>
                          <span class="ossn-notification-container"><?php 
    echo $friends_c;
    ?>
/**
 * Notification Page
 *
 * @return mixed data;
 * @access public
 */
function ossn_notification_page($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        ossn_error_page();
    }
    header('Content-Type: application/json');
    switch ($page) {
        case 'notification':
            $get = new OssnNotifications();
            $notifications['notifications'] = $get->get(ossn_loggedin_user()->guid, true);
            $notifications['seeall'] = ossn_site_url("notifications/all");
            if (!empty($notifications['notifications'])) {
                $data = ossn_view('components/OssnNotifications/pages/notification/notification', $notifications);
                echo json_encode(array('type' => 1, 'data' => $data));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">Nothing to show</div>'));
            }
            break;
        case 'friends':
            $friends['friends'] = ossn_loggedin_user()->getFriendRequests();
            $friends_count = count($friends['friends']);
            if ($friends_count > 0 && !empty($friends['friends'])) {
                $data = ossn_view('components/OssnNotifications/pages/notification/friends', $friends);
                echo json_encode(array('type' => 1, 'data' => $data));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">Nothing to show</div>'));
            }
            break;
        case 'messages':
            $OssnMessages = new OssnMessages();
            $params['recent'] = $OssnMessages->recentChat(ossn_loggedin_user()->guid);
            $data = ossn_view('components/OssnMessages/templates/message-with-notifi', $params);
            if (!empty($params['recent'])) {
                echo json_encode(array('type' => 1, 'data' => $data));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">Nothing to show</div>'));
            }
            break;
        case 'read':
            if (!empty($pages[1])) {
                $notification = new OssnNotifications();
                $guid = $notification->getbyGUID($pages[1]);
                if ($guid->owner_guid == ossn_loggedin_user()->guid) {
                    $notification->setViewed($pages[1]);
                    $url = urldecode(input('notification'));
                    header("Location: {$url}");
                } else {
                    redirect();
                }
            } else {
                redirect();
            }
            break;
        case 'count':
            if (!ossn_isLoggedIn()) {
                ossn_error_page();
            }
            $notification = new OssnNotifications();
            $messages = new OssnMessages();
            $count_notif = $notification->countNotification(ossn_loggedin_user()->guid);
            $count_messages = $messages->countUNREAD(ossn_loggedin_user()->guid);
            if (!$count_notif) {
                $count_notif = 0;
            }
            $friends = ossn_loggedin_user()->getFriendRequests();
            $friends_c = 0;
            if (count($friends) > 0 && !empty($friends)) {
                $friends_c = count($friends);
            }
            echo json_encode(array('notifications' => $count_notif, 'messages' => $count_messages, 'friends' => $friends_c));
            break;
        default:
            ossn_error_page();
            break;
    }
}
Esempio n. 3
0
/**
 * Notification Page
 *
 * @return mixed data;
 * @access public
 */
function ossn_notification_page($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        ossn_error_page();
    }
    header('Content-Type: application/json');
    switch ($page) {
        case 'notification':
            $get = new OssnNotifications();
            //removed true as second arg of get() as second arg is introduced in v2.0
            $notifications['notifications'] = $get->get(ossn_loggedin_user()->guid);
            $notifications['seeall'] = ossn_site_url("notifications/all");
            $clearall = ossn_plugin_view('output/url', array('action' => true, 'href' => ossn_site_url('action/notification/mark/allread'), 'class' => 'ossn-notification-mark-read', 'text' => ossn_print('ossn:notifications:mark:as:read')));
            if (!empty($notifications['notifications'])) {
                $data = ossn_plugin_view('notifications/pages/notification/notification', $notifications);
                echo json_encode(array('type' => 1, 'data' => $data, 'extra' => $clearall));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">' . ossn_print('ossn:notification:no:notification') . '</div>'));
            }
            break;
        case 'friends':
            $friends['friends'] = ossn_loggedin_user()->getFriendRequests();
            $friends_count = count($friends['friends']);
            if ($friends_count > 0 && !empty($friends['friends'])) {
                $data = ossn_plugin_view('notifications/pages/notification/friends', $friends);
                echo json_encode(array('type' => 1, 'data' => $data));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">' . ossn_print('ossn:notification:no:notification') . '</div>'));
            }
            break;
        case 'messages':
            $OssnMessages = new OssnMessages();
            $params['recent'] = $OssnMessages->recentChat(ossn_loggedin_user()->guid);
            $data = ossn_plugin_view('messages/templates/message-with-notifi', $params);
            if (!empty($params['recent'])) {
                echo json_encode(array('type' => 1, 'data' => $data));
            } else {
                echo json_encode(array('type' => 0, 'data' => '<div class="ossn-no-notification">' . ossn_print('ossn:notification:no:notification') . '</div>'));
            }
            break;
        case 'read':
            if (!empty($pages[1])) {
                $notification = new OssnNotifications();
                $guid = $notification->getbyGUID($pages[1]);
                if ($guid->owner_guid == ossn_loggedin_user()->guid) {
                    $notification->setViewed($pages[1]);
                    $url = urldecode(input('notification'));
                    header("Location: {$url}");
                } else {
                    redirect();
                }
            } else {
                redirect();
            }
            break;
        case 'count':
            if (!ossn_isLoggedIn()) {
                ossn_error_page();
            }
            $notification = new OssnNotifications();
            $messages = new OssnMessages();
            $count_notif = $notification->countNotification(ossn_loggedin_user()->guid);
            $count_messages = $messages->countUNREAD(ossn_loggedin_user()->guid);
            if (!$count_notif) {
                $count_notif = 0;
            }
            $friends = ossn_loggedin_user()->getFriendRequests();
            $friends_c = 0;
            if (count($friends) > 0 && !empty($friends)) {
                $friends_c = count($friends);
            }
            echo json_encode(array('notifications' => $count_notif, 'messages' => $count_messages, 'friends' => $friends_c));
            break;
        default:
            ossn_error_page();
            break;
    }
}