$prefered_offset = ($prefered_page - 1) * $prefered_page_size; switch ($prefered_type) { case 'from': $friend_value = 'AND friend_value > 0'; $prefered_total = $db->get_var("SELECT count(*) FROM friends WHERE friend_type='manual' AND friend_from={$prefered_id} {$friend_value}"); $dbusers = $db->get_results("SELECT friend_to as who, unix_timestamp(friend_date) as date FROM friends, users WHERE friend_type='manual' AND friend_from={$prefered_id} and user_id = friend_to {$friend_value} order by user_login asc LIMIT {$prefered_offset},{$prefered_page_size}"); break; case 'to': $prefered_total = $db->get_var("SELECT count(*) FROM friends WHERE friend_type='manual' AND friend_to={$prefered_id} AND friend_from != 0 and friend_value > 0"); $dbusers = $db->get_results("SELECT friend_from as who, unix_timestamp(friend_date) as date FROM friends, users WHERE friend_type='manual' AND friend_to={$prefered_id} and user_id = friend_from and friend_value > 0 order by user_login asc LIMIT {$prefered_offset},{$prefered_page_size}"); break; case 'new': if ($prefered_id != $current_user->user_id) { return; } $new_friends = User::get_new_friends($prefered_id); $prefered_total = count($new_friends); if ($prefered_total > 0) { $friends = implode(',', $new_friends); $dbusers = $db->get_results("SELECT friend_from as who, unix_timestamp(friend_date) as date FROM friends, users WHERE friend_type='manual' AND friend_to={$prefered_id} and friend_from in ({$friends}) and user_id = friend_from order by friend_date desc LIMIT {$prefered_offset},{$prefered_page_size}"); } break; case 'ignored': if ($prefered_id != $current_user->user_id) { return; } $friend_value = 'AND friend_value < 0'; $prefered_total = $db->get_var("SELECT count(*) FROM friends WHERE friend_type='manual' AND friend_from={$prefered_id} {$friend_value}"); $dbusers = $db->get_results("SELECT friend_to as who, unix_timestamp(friend_date) as date FROM friends, users WHERE friend_type='manual' AND friend_from={$prefered_id} and user_id = friend_to {$friend_value} order by user_login asc LIMIT {$prefered_offset},{$prefered_page_size}"); break; }
include '../config.php'; $db->connect_timeout = 3; if (!$current_user->user_id) { die; } if (!empty($_GET['redirect'])) { do_redirect($_GET['redirect']); exit(0); } header('Content-Type: application/json; charset=utf-8'); http_cache(5); $notifications = new stdClass(); $notifications->posts = (int) Post::get_unread_conversations($current_user->user_id); $notifications->comments = (int) Comment::get_unread_conversations($current_user->user_id); $notifications->privates = (int) PrivateMessage::get_unread($current_user->user_id); $notifications->friends = count(User::get_new_friends($current_user->user_id)); $notifications->total = $notifications->posts + $notifications->privates + $notifications->friends + $notifications->comments; echo json_encode($notifications); function do_redirect($type) { global $globals, $current_user; $url = '/'; // If everything fails, it will be redirected to the home switch ($type) { case 'privates': $url = post_get_base_url('_priv'); break; case 'posts': $url = post_get_base_url($current_user->user_login) . '/_conversation'; break; case 'comments':