/** * 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 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); } }
/** * 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; }
/** * 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); } }
/** * 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; } } }