/** * It will create Notification on Activities table * * @param integer $userID * @param integer $senderID (the man who creates this alert) * @param string $actionType : one of action types (const defined for this class) * @param integer $actionID : related trade offer, feedback ID */ function createNotification($userID, $senderID, $actionType, $actionID) { //Check if this user will get this notification. (it will be set by Notification setting page) $tradeUserIns = new BuckysTradeUser(); $userData = $tradeUserIns->getUserByID($userID); $flagEnabled = 0; // user checked that he didn't want to have this notification switch ($actionType) { case BuckysActivity::ACTION_TYPE_OFFER_ACCEPTED: $notificationType = BuckysActivity::NOTIFICATION_TYPE_OFFER_ACCEPTED; $flagEnabled = $userData['optOfferAccepted']; break; case BuckysActivity::ACTION_TYPE_OFFER_RECEIVED: $notificationType = BuckysActivity::NOTIFICATION_TYPE_OFFER_RECEIVED; $flagEnabled = $userData['optOfferReceived']; break; case BuckysActivity::ACTION_TYPE_OFFER_DECLINED: $notificationType = BuckysActivity::NOTIFICATION_TYPE_OFFER_DECLINED; $flagEnabled = $userData['optOfferDeclined']; break; case BuckysActivity::ACTION_TYPE_FEEDBACK: $notificationType = BuckysActivity::NOTIFICATION_TYPE_OFFER_FEEDBACK; $flagEnabled = $userData['optFeedbackReceived']; break; } if ($flagEnabled == 1) { //Create Notification. $activityIns = new BuckysActivity(); $activityId = $activityIns->addActivity($userID, $senderID, $this->objectType, $actionType, $actionID); $activityIns->addNotification($userID, $activityId, $notificationType); } }
/** * Add notification for the users whose 'My post approved' set 1. * * @param Int $ownerID * @param Int $topicID * @param Int $replyID */ public function addNotificationsForPendingPost($ownerID, $topicID, $replyID = null) { global $db, $BUCKYS_GLOBALS; $forumSettings = BuckysUser::getUserForumSettings($ownerID); $activity = new BuckysActivity(); if ($forumSettings['notifyRepliedToMyTopic']) { if ($replyID == null) { $activity->addActivity($ownerID, $topicID, 'forum', BuckysForumNotification::ACTION_TYPE_TOPIC_APPROVED, 0); } else { $activity->addActivity($ownerID, $topicID, 'forum', BuckysForumNotification::ACTION_TYPE_REPLY_APPROVED, $replyID); } } return true; }
/** * It will create Notification on Activities table * * @param integer $userID * @param integer $senderID (the man who creates this alert) * @param string $actionType : one of action types (const defined for this class) * @param integer $actionID : related shop order ID */ function createNotification($userID, $senderID, $actionType, $actionID) { //Check if this user will get this notification. (it will be set by Notification setting page) $userIns = new BuckysTradeUser(); $userData = $userIns->getUserByID($userID); $flagEnabled = 0; // user checked that he didn't want to have this notification switch ($actionType) { case BuckysActivity::ACTION_TYPE_PRODUCT_SOLD: $flagEnabled = $userData['optProductSoldOnShop']; break; } if ($flagEnabled == 1) { //Create Notification. $activityIns = new BuckysActivity(); $activityId = $activityIns->addActivity($userID, $senderID, $this->objectType, $actionType, $actionID); $activityIns->addNotification($userID, $activityId, BuckysActivity::NOTIFICATION_TYPE_PRODUCT_SOLD); } }
public function markReadNotificationAction() { $data = $_POST; $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : 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 (BuckysActivity::markReadNotifications($userID, $data['postID'])) { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => 'SUCCESS']]; } else { return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('There was an error to mark read.')]; } }
/** * 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; }
require dirname(__FILE__) . '/includes/bootstrap.php'; if (!($userID = buckys_is_logged_in())) { buckys_redirect('/index.php', MSG_NOT_LOGGED_IN_USER, MSG_TYPE_ERROR); } //Getting Activity Stream $stream = BuckysPost::getUserPostsStream($userID); //Get Activities $activities = BuckysActivity::getActivities($userID); if (!$activities) { $activities = []; } //Get Notifications $notifications = BuckysActivity::getNotifications($userID); //Mark the notifications to read BuckysActivity::markReadNotifications($userID); if (!$notifications) { $notifications = []; } buckys_enqueue_stylesheet('account.css'); buckys_enqueue_stylesheet('stream.css'); buckys_enqueue_stylesheet('posting.css'); buckys_enqueue_stylesheet('uploadify.css'); buckys_enqueue_stylesheet('jquery.Jcrop.css'); buckys_enqueue_javascript('uploadify/jquery.uploadify.js'); buckys_enqueue_javascript('jquery.Jcrop.js'); buckys_enqueue_javascript('jquery.color.js'); buckys_enqueue_javascript('posts.js'); buckys_enqueue_javascript('add_post.js'); buckys_enqueue_javascript('account.js'); //Set Content
/** * 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; } } }
<div class="clear"></div> <a href="#" class="view-more">view more</a> <?php } ?> </div> <div class="clear"></div> <br/> <h2 class="activityHeader" style="background-color: #2980B9;">Friend Activity</h2> <div id="activities" data-count="15"> <?php foreach ($activities as $row) { echo BuckysActivity::getActivityHTML($row, $userID); } ?> <?php if (count($activities) == 15) { ?> <div class="clear"></div> <a href="#" class="view-more">view more</a> <?php } ?> </div> </section> </section> </section>
<?php require dirname(__FILE__) . '/includes/bootstrap.php'; if (!($userID = buckys_is_logged_in())) { exit; } if ($_POST['action'] == 'activity-notification') { $acount = isset($_POST['acount']) ? intval($_POST['acount']) : 15; $rows = BuckysActivity::getActivities($userID, $acount); $activities = ''; foreach ($rows as $row) { $activities .= BuckysActivity::getActivityHTML($row, $userID); } if (count($rows) == $acount) { $activities .= "<div class='clear'></div><a href='#' class='view-more'>view more</a>"; } $ncount = isset($_POST['ncount']) ? intval($_POST['ncount']) : 15; $rows = BuckysActivity::getNotifications($userID, $ncount); $notifications = ''; foreach ($rows as $row) { $notifications .= BuckysActivity::getActivityHTML($row, $userID); } if (count($rows) == $ncount) { $notifications .= "<div class='clear'></div><a href='#' class='view-more'>view more</a>"; } render_result_xml(['notifications' => $notifications, 'activities' => $activities]); exit; }
function render_footer_link_content($type, $data, $outFlag = true) { $userID = buckys_is_logged_in(); ob_start(); switch ($type) { case 'my': foreach ($data as $row) { echo BuckysActivity::getActivityHTML($row, $userID); } echo '<a class="view-detail-links" href="/account.php">View All Notifications</a>'; break; case 'friend': $count = 0; foreach ($data as $row) { $count++; if ($count > 5) { break; } ?> <div class="activityComment"> <a href="/profile.php?user=<?php echo $row['userID']; ?> "><img src="<?php echo BuckysUser::getProfileIcon($row); ?> " class="dropDownNotificationImages"/></a> <a href="/profile.php?user=<?php echo $row['userID']; ?> "><?php echo $row['fullName']; ?> </a> sent you new friend request <a href="/myfriends.php?action=decline&friendID=<?php echo $row['userID']; echo buckys_get_token_param(); ?> &return=<?php echo base64_encode("/profile.php?user="******" class="redButton">Decline</a> <a href="/myfriends.php?action=accept&friendID=<?php echo $row['userID']; echo buckys_get_token_param(); ?> &return=<?php echo base64_encode("/profile.php?user="******" class="redButton">Approve</a> <br clear="all"/> </div> <?php } ?> <a class="view-detail-links" href="/myfriends.php?type=requested"> View All Requests </a> <?php break; case 'forum': foreach ($data as $idx => $row) { ?> <?php if ($row['activityType'] == 'topic_approved' || $row['activityType'] == 'reply_approved') { ?> <div class="activityComment"> <span> <a href="/profile.php?user=<?php echo $row['userID']; ?> "><img src="<?php echo BuckysUser::getProfileIcon($TNB_GLOBALS['user']['userID']); ?> " class="dropDownNotificationImages"/></a> <!-- <span class="redBold"><?php echo $TNB_GLOBALS['user']['firstName'] . " " . $TNB_GLOBALS['user']['lastName']; ?> </span> <br />--> <?php if ($row['activityType'] == 'topic_approved') { ?> Your topic <a href="/forum/topic.php?id=<?php echo $row['activityType'] == 'topic_approved' ? $row['objectID'] : $row['actionID']; ?> "><?php echo buckys_truncate_string($row['topicTitle'], 30); ?> </a> has been approved <?php } else { ?> Your reply to <a href="/forum/topic.php?id=<?php echo $row['activityType'] == 'reply_approved' ? $row['objectID'] : $row['actionID']; ?> "><?php echo buckys_truncate_string($row['topicTitle'], 30); ?> </a> has been approved <?php } ?> <span class="createdDate"><?php echo buckys_format_date($row['createdDate']); ?> </span> <br clear="all"/> </span> </div> <?php } else { ?> <div class="activityComment"> <span> <a href="/profile.php?user=<?php echo $row['replierID']; ?> "><img src="<?php echo BuckysUser::getProfileIcon(['userID' => $row['replierID'], 'thumbnail' => $row['rThumbnail']]); ?> " class="dropDownNotificationImages"/></a> <a href="/profile.php?user=<?php echo $row['replierID']; ?> "><?php echo $row['rName']; ?> </a> replied to <?php echo $row['activityType'] == "replied_to_topic" ? "your" : "the"; ?> topic <a href="/forum/topic.php?id=<?php echo $row['objectID']; ?> &page=9999"><?php echo buckys_truncate_string($row['topicTitle'], 30); ?> </a> <span class="createdDate"><?php echo buckys_format_date($row['createdDate']); ?> </span> <br clear="all"/> </span> </div> <?php } ?> <?php } ?> <a class="view-detail-links" href="/forum"> Go to Forum </a> <?php break; case 'mail': foreach ($data as $idx => $row) { ?> <a class="singleNotificationListItem" href="/messages_read.php?message=<?php echo $row['messageID']; ?> "> <span> <img src="<?php echo BuckysUser::getProfileIcon($row['sender']); ?> " class="dropDownNotificationImages"/> <span class="redBold" style="font-weight:normal;"><?php echo $row['senderName']; ?> </span> <span style="font-size:11px; color:#888; float:right;"><?php echo buckys_format_date($row['created_date']); ?> </span> <br/> <?php echo substr($row['body'], 0, 120); if (strlen($row['body']) > 120) { echo "..."; } ?> </span> </a> <?php if ($idx > 4) { break; } } ?> <a class="view-detail-links" href="/messages_inbox.php">Go to Inbox</a> <?php break; case 'trade': foreach ($data as $idx => $row) { $htmlBodyContent = ''; if ($row['activityType'] == BuckysTradeNotification::ACTION_TYPE_OFFER_ACCEPTED) { $actionUrl = '/trade/traded.php'; $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">%s</span>', $row['senderName']); $htmlBodyContent .= sprintf('<span> accepted your </span>'); $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">offer</span>'); } else { if ($row['activityType'] == BuckysTradeNotification::ACTION_TYPE_OFFER_DECLINED) { $actionUrl = '/trade/offer_declined.php'; $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">%s</span>', $row['senderName']); $htmlBodyContent .= sprintf('<span> declined your </span>'); $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">offer</span>'); } else { if ($row['activityType'] == BuckysTradeNotification::ACTION_TYPE_OFFER_RECEIVED) { $actionUrl = '/trade/offer_received.php'; $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">%s</span>', $row['senderName']); $htmlBodyContent .= sprintf('<span> made you an </span>'); $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">offer</span>'); } else { if ($row['activityType'] == BuckysTradeNotification::ACTION_TYPE_FEEDBACK) { $actionUrl = '/feedback.php?user='******'<span class="redBold" style="font-weight:normal;">%s</span>', $row['senderName']); $htmlBodyContent .= sprintf('<span> left you </span>'); $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">feedback</span>'); $row['feedback'] = strip_tags($row['feedback']); if (strlen($row['feedback']) > 120) { $row['feedback'] = substr($row['feedback'], 0, 120) . '...'; } $htmlBodyContent .= sprintf('<span> "%s"</span>', $row['feedback']); } else { $actionUrl = '#'; //not sure if we can be here. } } } } ?> <a class="singleNotificationListItem" href="<?php echo $actionUrl; ?> "> <img src="<?php echo BuckysUser::getProfileIcon($row['senderID']); ?> " class="dropDownNotificationImages"/> <?php echo $htmlBodyContent; ?> </a> <?php } ?> <a class="view-detail-links" href="/trade/available.php">My Trading Account</a> <?php break; case 'shop': foreach ($data as $idx => $row) { $htmlBodyContent = ''; if ($row['activityType'] == BuckysShopNotification::ACTION_TYPE_PRODUCT_SOLD) { $actionUrl = '/shop/sold.php'; $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">%s</span>', $row['senderName']); $htmlBodyContent .= sprintf('<span> purchased your </span>'); $htmlBodyContent .= sprintf('<span class="redBold" style="font-weight:normal;">product</span>'); } else { $actionUrl = '#'; //not sure if we can be here. } ?> <a class="singleNotificationListItem" href="<?php echo $actionUrl; ?> "> <img src="<?php echo BuckysUser::getProfileIcon($row['senderID']); ?> " class="dropDownNotificationImages"/> <?php echo $htmlBodyContent; ?> </a> <?php } ?> <a class="view-detail-links" href="/shop/available.php">My Shop Account</a> <?php break; } $output = ob_get_contents(); ob_end_clean(); if ($outFlag == true) { echo $output; return true; } else { return $output; } }
<li class="right"> <a href="/logout.php" class="p_menu">Log Out</a> </li> <!-- notifications Icons --> <li class="rightIcons"> <?php $newMsgFlag = 1; $notifications = BuckysActivity::getNumberOfNotifications($userID, $newMsgFlag); if ($notifications == 0) { $newMsgFlag = 0; $notifications = BuckysActivity::getNumberOfNotifications($userID, $newMsgFlag); } if ($notifications > 0) { $notificationsList = BuckysActivity::getNotifications($userID, $notificationLimit, $newMsgFlag); ?> <span class="notificationLinks <?php if ($newMsgFlag == 0) { echo 'inactive-notify'; } ?> " id="my-notifications-icon"> <span class="notification-count"><?php if ($newMsgFlag != 0) { echo '+' . $notifications; } else { echo 0; } ?> </span>
<?php require dirname(__FILE__) . '/includes/bootstrap.php'; if (!($userID = buckys_is_logged_in())) { echo MSG_INVALID_REQUEST; exit; } $notificationLimit = 5; //This module will make the notifications as read. $result = ['success' => 1, 'content' => '']; $type = isset($_REQUEST['type']) ? strtolower($_REQUEST['type']) : null; if (isset($_POST['action']) && $_POST['action'] == 'read') { switch ($type) { case 'my': BuckysActivity::markReadNotifications($userID); $notiData = BuckysActivity::getNotifications($userID, $notificationLimit, 0); $result['content'] = render_footer_link_content($type, $notiData, false); break; case 'forum': BuckysForumNotification::makeNotificationsToRead($userID); $notiData = BuckysForumNotification::getNewNotifications($userID, 0, $notificationLimit); $result['content'] = render_footer_link_content($type, $notiData, false); break; case 'trade': $tradeNotiIns = new BuckysTradeNotification(); $tradeNotiIns->markAsRead($userID); $notiData = $tradeNotiIns->getReceivedMessages($userID, null, 0, $notificationLimit); $result['content'] = render_footer_link_content($type, $notiData, false); break; case 'shop': $shopNotiIns = new BuckysShopNotification();
/** * 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; } } }