/** * Save Comment * * @param Int $userID * @param Int $postID * @param String $comment */ public function saveComments($userID, $postID, $comment) { global $db; $now = date("Y-m-d H:i:s"); $newId = $db->insertFromArray(TABLE_COMMENTS, array('postID' => $postID, 'commenter' => $userID, 'content' => $comment, 'posted_date' => $now)); if (buckys_not_null($newId)) { //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 BuckysActivity::addActivity($userID, $postID, 'post', 'comment', $newId); //Increase Hits BuckysHit::addHit($postID, $userID); } return $newId; }
/** * 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; }
/** * 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; } } }
/** * Like Post * * * @param int $userID * @param int $postID */ public function likePost($userID, $postID, $action) { global $db; $post = BuckysPost::getPostById($postID); 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; } //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; } //Like This post $rs = $db->insertFromArray(TABLE_POSTS_LIKES, array('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 BuckysActivity::addActivity($userID, $postID, 'post', 'like', $rs); //Increase Hits BuckysHit::addHit($postID, $userID); return $rs; } else { if ($action == 'unlikePost') { if (!$likeId) { buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR); return false; } $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); return true; } } }