/**
  * Like Post
  *
  * @param int $userID
  * @param int $postID
  * @param $action
  * @param bool $checkToken
  * @return bool|int|null|string
  */
 public static function likePost($userID, $postID, $action, $checkToken = true)
 {
     global $db;
     $post = BuckysPost::getPostById($postID);
     if ($checkToken && !buckys_check_form_token('request')) {
         buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
         return false;
     }
     if (!$post || $post['poster'] == $userID) {
         buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
         return false;
     }
     if ($post['visibility'] == 0 && !BuckysFriend::isFriend($userID, $post['poster'])) {
         buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
         return false;
     }
     if (!BuckysUsersDailyActivity::checkUserDailyLimit($userID, 'likes')) {
         buckys_add_message(sprintf(MSG_DAILY_LIKES_LIMIT_EXCEED_ERROR, USER_DAILY_LIMIT_LIKES), MSG_TYPE_ERROR);
         return false;
     }
     //Check already like it or not
     $query = $db->prepare("SELECT likeID FROM " . TABLE_POSTS_LIKES . " WHERE userID=%s AND postID=%s", $userID, $postID);
     $likeId = $db->getVar($query);
     if ($action == 'likePost') {
         if ($likeId) {
             buckys_add_message(MSG_ALREADY_LIKED_POST, MSG_TYPE_ERROR);
             return false;
         }
         BuckysUsersDailyActivity::addLikes($userID);
         //Like This post
         $rs = $db->insertFromArray(TABLE_POSTS_LIKES, ['userID' => $userID, 'postID' => $postID]);
         //Update likes on the posts table
         $query = $db->prepare('UPDATE ' . TABLE_POSTS . ' SET `likes`=`likes` + 1 WHERE postID=%d', $postID);
         $db->query($query);
         //Add Activity
         $activityId = BuckysActivity::addActivity($userID, $postID, 'post', 'like', $rs);
         //Add Notification
         BuckysActivity::addNotification($post['poster'], $activityId, BuckysActivity::NOTIFICATION_TYPE_LIKE_POST);
         //Increase Hits
         BuckysHit::addHit($postID, $userID);
         //Update User Stats
         BuckysUser::updateStats($post['poster'], 'likes', 1);
         return $rs;
     } else {
         if ($action == 'unlikePost') {
             if (!$likeId) {
                 buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
                 return false;
             }
             BuckysUsersDailyActivity::addLikes($userID);
             $query = $db->prepare("DELETE FROM " . TABLE_POSTS_LIKES . " WHERE userID=%s AND postID=%s", $userID, $postID);
             $db->query($query);
             //Update likes on the posts table
             $query = $db->prepare('UPDATE ' . TABLE_POSTS . ' SET `likes`=`likes` - 1 WHERE postID=%d', $postID);
             $db->query($query);
             //Increase Hits
             BuckysHit::removeHit($postID, $userID);
             //Update User Stats
             BuckysUser::updateStats($post['poster'], 'likes', -1);
             return true;
         }
     }
 }
         render_result_xml($resultXML);
     } else {
         buckys_redirect($return, MSG_FRIEND_REQUEST_ALREADY_SENT, MSG_TYPE_ERROR);
     }
     exit;
 }
 if (BuckysFriend::isSentFriendRequest($friendID, $userID)) {
     if ($isAjax) {
         $resultXML = ['status' => 'error', 'message' => MSG_FRIEND_REQUEST_ALREADY_RECEIVED];
         render_result_xml($resultXML);
     } else {
         buckys_redirect($return, MSG_FRIEND_REQUEST_ALREADY_RECEIVED, MSG_TYPE_ERROR);
     }
     exit;
 }
 if (!BuckysUsersDailyActivity::checkUserDailyLimit($userID, "friendRequests")) {
     if ($isAjax) {
         $resultXML = ['status' => 'error', 'message' => sprintf(MSG_DAILY_FRIEND_REQUESTS_LIMIT_EXCEED_ERROR, USER_DAILY_LIMIT_FRIEND_REQUESTS)];
         render_result_xml($resultXML);
     } else {
         buckys_redirect($return, sprintf(MSG_DAILY_FRIEND_REQUESTS_LIMIT_EXCEED_ERROR, USER_DAILY_LIMIT_FRIEND_REQUESTS), MSG_TYPE_ERROR);
     }
     exit;
 }
 if (BuckysFriend::sendFriendRequest($userID, $friendID)) {
     if ($isAjax) {
         $resultXML = ['status' => 'success', 'message' => MSG_FRIEND_REQUEST_SENT, 'html' => 'Delete Friend Request', 'action' => 'send-friend-request', 'link' => '/myfriends.php?action=delete&friendID=' . $friendID . buckys_get_token_param()];
         render_result_xml($resultXML);
     } else {
         buckys_redirect($return, MSG_FRIEND_REQUEST_SENT);
     }
 if (!$postID) {
     echo MSG_INVALID_REQUEST;
     exit;
 }
 //Check the post id is correct
 if (!BuckysPost::checkPostID($postID)) {
     echo MSG_POST_NOT_EXIST;
     exit;
 }
 $post = BuckysPost::getPostById($postID);
 if ($post['visibility'] == 0 && $userID != $post['poster'] && !BuckysFriend::isFriend($userID, $post['poster'])) {
     //Only Friends can leave comments to private post
     echo MSG_INVALID_REQUEST;
     exit;
 }
 if (!BuckysUsersDailyActivity::checkUserDailyLimit($userID, "comments")) {
     echo sprintf(MSG_DAILY_COMMENTS_LIMIT_EXCEED_ERROR, USER_DAILY_LIMIT_COMMENTS);
     exit;
 }
 //If error, show it
 if (!($commentID = BuckysComment::saveComments($userID, $postID, $comment, $image))) {
     echo $db->getLastError();
     exit;
 } else {
     //Show Results
     header('Content-type: application/xml');
     $newComment = BuckysComment::getComment($commentID);
     $newCount = BuckysComment::getPostCommentsCount($postID);
     render_result_xml(['newcomment' => render_single_comment($newComment, $userID, true), 'count' => $newCount > 1 ? $newCount . " comments" : $newCount . " comment"]);
     exit;
 }