コード例 #1
0
 /**
  * Save Comment
  *
  * @param Int    $userID
  * @param Int    $postID
  * @param String $comment
  * @return int|null|string
  */
 public static function saveComments($userID, $postID, $comment, $image = null)
 {
     global $db;
     $now = date("Y-m-d H:i:s");
     if ($image != null) {
         if (file_exists(DIR_FS_PHOTO_TMP . $image)) {
             list($width, $height, $type, $attr) = getimagesize(DIR_FS_PHOTO_TMP . $image);
             if ($width > MAX_COMMENT_IMAGE_WIDTH) {
                 $height = $height * (MAX_COMMENT_IMAGE_WIDTH / $width);
                 $width = MAX_COMMENT_IMAGE_WIDTH;
             }
             if ($height > MAX_COMMENT_IMAGE_HEIGHT) {
                 $width = $width * (MAX_COMMENT_IMAGE_HEIGHT / $height);
                 $height = MAX_COMMENT_IMAGE_HEIGHT;
             }
             BuckysPost::moveFileFromTmpToUserFolder($userID, $image, $width, $height, 0, 0);
         } else {
             $image = null;
         }
     }
     $newId = $db->insertFromArray(TABLE_COMMENTS, ['postID' => $postID, 'commenter' => $userID, 'content' => $comment, 'image' => $image, 'posted_date' => $now]);
     if (buckys_not_null($newId)) {
         $postData = BuckysPost::getPostById($postID);
         BuckysUsersDailyActivity::addComment($userID);
         //Update comments on the posts table
         $query = $db->prepare('UPDATE ' . TABLE_POSTS . ' SET `comments`=`comments` + 1 WHERE postID=%d', $postID);
         $db->query($query);
         //Add Activity
         $activityID = BuckysActivity::addActivity($userID, $postID, 'post', 'comment', $newId);
         //Add Notification
         if ($postData['poster'] != $userID) {
             BuckysActivity::addNotification($postData['poster'], $activityID, BuckysActivity::NOTIFICATION_TYPE_COMMENT_TO_POST);
         }
         //Get Already Commented users which commentToComment is 1
         $query = $db->prepare("SELECT DISTINCT(pc.commenter), IFNULL(un.notifyCommentToMyComment, 1) AS notifyCommentToMyComment FROM " . TABLE_POSTS_COMMENTS . " AS pc LEFT JOIN " . TABLE_USERS_NOTIFY_SETTINGS . " AS un ON pc.commenter = un.userID WHERE pc.postID=%d AND pc.commenter != %d AND IFNULL(un.notifyCommentToMyComment, 1) > 0", $postID, $userID);
         $rows = $db->getResultsArray($query);
         foreach ($rows as $row) {
             BuckysActivity::addNotification($row['commenter'], $activityID, BuckysActivity::NOTIFICATION_TYPE_COMMENT_TO_COMMENT);
         }
         //Increase Hits
         BuckysHit::addHit($postID, $userID);
         //Update User Stats
         BuckysUser::updateStats($postData['poster'], 'comments', 1);
     }
     return $newId;
 }
コード例 #2
0
 /**
  * Decline
  *
  * @param Int   $userID
  * @param Array $ids
  * @return bool
  */
 public static function sendFriendRequest($userID, $id)
 {
     global $db;
     $query = $db->prepare("INSERT INTO " . TABLE_FRIENDS . "(userID, userFriendID, `status`)VALUES(%d, %d, '0')", $userID, $id);
     $db->query($query);
     BuckysUsersDailyActivity::addFrendRequest($userID);
     return true;
 }
コード例 #3
0
 /**
  * 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;
         }
     }
 }
コード例 #4
0
         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);
     }
コード例 #5
0
 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;
 }