Exemple #1
0
<?php

require dirname(__FILE__) . '/includes/bootstrap.php';
//Getting Current User ID
if (!($userID = buckys_is_logged_in())) {
    buckys_redirect('/index.php', MSG_NOT_LOGGED_IN_USER, MSG_TYPE_ERROR);
}
$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : '';
if (!in_array($type, array('all', 'pending', 'requested'))) {
    $type = 'all';
}
if (isset($_REQUEST['action'])) {
    $return = isset($_REQUEST['return']) ? base64_decode($_REQUEST['return']) : '/myfriends.php?type=' . $type;
    if ($_REQUEST['action'] == 'unfriend') {
        if (BuckysFriend::unfriend($userID, $_REQUEST['friendID'])) {
            buckys_redirect($return, MSG_FRIEND_REMOVED);
        } else {
            buckys_redirect($return, $db->getLastError(), MSG_TYPE_ERROR);
        }
    } else {
        if ($_REQUEST['action'] == 'decline') {
            if (BuckysFriend::decline($userID, $_REQUEST['friendID'])) {
                buckys_redirect($return, MSG_FRIEND_REQUEST_DECLINED);
            } else {
                buckys_redirect($return, $db->getLastError(), MSG_TYPE_ERROR);
            }
        } else {
            if ($_REQUEST['action'] == 'accept') {
                if (BuckysFriend::accept($userID, $_REQUEST['friendID'])) {
                    buckys_redirect('/myfriends.php?type=requested', MSG_FRIEND_REQUEST_APPROVED);
                } else {
 $isAjax = isset($_REQUEST['buckys_ajax']) ? true : false;
 if ($isAjax) {
     header('Content-type: application/xml');
 }
 $friendID = buckys_escape_query_integer($_REQUEST['friendID']);
 if (!buckys_check_form_token('request')) {
     if ($isAjax) {
         $resultXML = ['status' => 'error', 'message' => MSG_INVALID_REQUEST];
         render_result_xml($resultXML);
     } else {
         buckys_redirect($return, MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
     }
     exit;
 }
 if ($_REQUEST['action'] == 'unfriend') {
     if (BuckysFriend::unfriend($userID, $friendID)) {
         if ($isAjax) {
             $resultXML = ['status' => 'success', 'message' => MSG_FRIEND_REMOVED, 'html' => 'Send Friend Request', 'action' => 'unfriend', 'link' => '/myfriends.php?action=request&friendID=' . $friendID . buckys_get_token_param()];
             render_result_xml($resultXML);
         } else {
             buckys_redirect($return, MSG_FRIEND_REMOVED);
         }
     } else {
         if ($isAjax) {
             $resultXML = ['status' => 'error', 'message' => $db->getLastError()];
             render_result_xml($resultXML);
         } else {
             buckys_redirect($return, $db->getLastError(), MSG_TYPE_ERROR);
         }
     }
 } else {
 public function unfriendAction()
 {
     $data = $_POST;
     $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null;
     $friendID = isset($data['friendID']) ? $data['friendID'] : null;
     if (!$token) {
         return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')];
     }
     if (!($userID = BuckysUsersToken::checkTokenValidity($token, "api"))) {
         return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')];
     }
     if (!isset($friendID) || !BuckysUser::checkUserID($friendID)) {
         return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)];
     }
     if (BuckysFriend::unfriend($userID, $friendID)) {
         return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => "SUCCESS", "MESSAGE" => MSG_FRIEND_REQUEST_REMOVED]];
     } else {
         ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(buckys_get_pure_messages())];
     }
 }