Ejemplo n.º 1
0
if (isset($_POST['action']) && $_POST['action'] == 'submit-post') {
    //Save Post
    BuckysPost::savePost($userID, $_POST);
    if (isset($_POST['pageID']) && is_numeric($_POST['pageID'])) {
        buckys_redirect('/page.php?pid=' . $_POST['pageID']);
    } else {
        buckys_redirect('/account.php');
    }
} else {
    if (isset($_GET['action']) && $_GET['action'] == 'delete-post') {
        //Delete Post
        if ($userID != $_GET['userID'] || !BuckysPost::deletePost($userID, $_GET['postID'])) {
            echo 'Invalid Request';
        } else {
            echo 'success';
        }
        exit;
    } else {
        if (isset($_GET['action']) && ($_GET['action'] == 'unlikePost' || $_GET['action'] == 'likePost')) {
            $post = BuckysPost::getPostById($_GET['postID']);
            if ($post['post_status'] != 1) {
                render_result_xml(array('status' => 'error', 'message' => MSG_INVALID_REQUEST));
                exit;
            }
            $r = BuckysPost::likePost($userID, $_GET['postID'], $_GET['action']);
            $likes = BuckysPost::getPostLikesCount($_GET['postID']);
            render_result_xml(array('status' => $r ? 'success' : 'error', 'message' => buckys_get_messages(), 'likes' => $likes . " like" . ($likes >= 2 ? "s" : ""), 'postID' => $_GET['postID']));
            exit;
        }
    }
}
Ejemplo n.º 2
0
 public function likePostAction()
 {
     $data = $_POST;
     $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null;
     $postID = isset($data['postID']) ? $data['postID'] : null;
     $actionType = isset($data['actionType']) ? $data['actionType'] : 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 (!$postID || !$actionType) {
         return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)];
     }
     $post = BuckysPost::getPostById($postID);
     if (!$post || $post['post_status'] != 1) {
         return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)];
         exit;
     }
     $r = BuckysPost::likePost($userID, $postID, $actionType, false);
     $message = buckys_get_pure_messages();
     if (!$r) {
         return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result($message)];
         exit;
     } else {
         $likes = BuckysPost::getPostLikesCount($postID);
         return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => 'SUCCESS', 'MESSAGE' => $message, 'LIKES' => $likes, 'isLiked' => $actionType == 'likePost' ? 'yes' : 'no']];
     }
 }