public function addFollower($follower_id) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $account = new account($this->db, $this->id); $account->setLastActive(); unset($account); if ($this->is_friend_exists($follower_id)) { return $result; } if ($this->is_follower_exists($follower_id)) { $stmt = $this->db->prepare("DELETE FROM profile_followers WHERE follower = (:follower) AND follow_to = (:follow_to)"); $stmt->bindParam(":follower", $follower_id, PDO::PARAM_INT); $stmt->bindParam(":follow_to", $this->id, PDO::PARAM_INT); $stmt->execute(); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "follow" => false, "followersCount" => 0); $notify = new notify($this->db); $notify->removeNotify($this->id, $follower_id, NOTIFY_TYPE_FOLLOWER, 0); unset($notify); } else { $create_at = time(); $stmt = $this->db->prepare("INSERT INTO profile_followers (follower, follow_to, create_at) value (:follower, :follow_to, :create_at)"); $stmt->bindParam(":follower", $follower_id, PDO::PARAM_INT); $stmt->bindParam(":follow_to", $this->id, PDO::PARAM_INT); $stmt->bindParam(":create_at", $create_at, PDO::PARAM_INT); $stmt->execute(); $blacklist = new blacklist($this->db); $blacklist->setRequestFrom($this->id); if (!$blacklist->isExists($follower_id)) { $account = new account($this->db, $this->id); if ($account->getAllowFollowersGCM() == ENABLE_FOLLOWERS_GCM) { $gcm = new gcm($this->db, $this->id); $gcm->setData(GCM_NOTIFY_FOLLOWER, "You have new follower", 0); $gcm->send(); } unset($account); $notify = new notify($this->db); $notify->createNotify($this->id, $follower_id, NOTIFY_TYPE_FOLLOWER, 0); unset($notify); } unset($blacklist); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "follow" => true, "followersCount" => 0); } return $result; }
public function accept($friendId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $my_profile = new profile($this->db, $this->profileId); if ($my_profile->is_follower_exists($friendId)) { $currentTime = time(); $stmt = $this->db->prepare("INSERT INTO friends (friend, friendTo, createAt) value (:friend, :friendTo, :createAt)"); $stmt->bindParam(":friend", $friendId, PDO::PARAM_INT); $stmt->bindParam(":friendTo", $this->profileId, PDO::PARAM_INT); $stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT); if ($stmt->execute()) { $result = array("error" => false, "error_code" => ERROR_SUCCESS, "itemId" => $this->db->lastInsertId()); $stmt2 = $this->db->prepare("INSERT INTO friends (friend, friendTo, createAt) value (:friend, :friendTo, :createAt)"); $stmt2->bindParam(":friend", $this->profileId, PDO::PARAM_INT); $stmt2->bindParam(":friendTo", $friendId, PDO::PARAM_INT); $stmt2->bindParam(":createAt", $currentTime, PDO::PARAM_INT); $stmt2->execute(); $stmt3 = $this->db->prepare("DELETE FROM profile_followers WHERE follower = (:follower) AND follow_to = (:follow_to)"); $stmt3->bindParam(":follower", $friendId, PDO::PARAM_INT); $stmt3->bindParam(":follow_to", $this->profileId, PDO::PARAM_INT); $stmt3->execute(); $stmt4 = $this->db->prepare("DELETE FROM profile_followers WHERE follower = (:follower) AND follow_to = (:follow_to)"); $stmt4->bindParam(":follower", $this->profileId, PDO::PARAM_INT); $stmt4->bindParam(":follow_to", $friendId, PDO::PARAM_INT); $stmt4->execute(); $stmt5 = $this->db->prepare("DELETE FROM notifications WHERE notifyToId = (:notifyToId) AND notifyFromId = (:notifyFromId) AND notifyType = 1"); $stmt5->bindParam(":notifyToId", $this->profileId, PDO::PARAM_INT); $stmt5->bindParam(":notifyFromId", $friendId, PDO::PARAM_INT); $stmt5->execute(); $stmt5 = $this->db->prepare("DELETE FROM notifications WHERE notifyToId = (:notifyToId) AND notifyFromId = (:notifyFromId) AND notifyType = 1"); $stmt5->bindParam(":notifyToId", $friendId, PDO::PARAM_INT); $stmt5->bindParam(":notifyFromId", $this->profileId, PDO::PARAM_INT); $stmt5->execute(); $account = new account($this->db, $this->profileId); $account->updateCounters(); unset($account); $account = new account($this->db, $friendId); $account->updateCounters(); if ($account->getAllowFollowersGCM() == ENABLE_FOLLOWERS_GCM) { $gcm = new gcm($this->db, $friendId); $gcm->setData(GCM_FRIEND_REQUEST_ACCEPTED, "Friend Request accepted", 0); $gcm->send(); } unset($account); } } unset($my_profile); return $result; }
<?php /*! * ifsoft.co.uk engine v1.0 * * http://ifsoft.com.ua, http://ifsoft.co.uk * qascript@ifsoft.co.uk * * Copyright 2012-2015 Demyanchuk Dmitry (https://vk.com/dmitry.demyanchuk) */ include_once $_SERVER['DOCUMENT_ROOT'] . "/core/init.inc.php"; include_once $_SERVER['DOCUMENT_ROOT'] . "/config/api.inc.php"; if (!empty($_POST)) { $accountId = isset($_POST['accountId']) ? $_POST['accountId'] : 0; $accessToken = isset($_POST['accessToken']) ? $_POST['accessToken'] : ''; $allowFollowersGCM = isset($_POST['allowFollowersGCM']) ? $_POST['allowFollowersGCM'] : 0; $allowFollowersGCM = helper::clearInt($allowFollowersGCM); $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $auth = new auth($dbo); if (!$auth->authorize($accountId, $accessToken)) { api::printError(ERROR_ACCESS_TOKEN, "Error authorization."); } $result = array("error" => false, "error_code" => ERROR_SUCCESS); $account = new account($dbo, $accountId); $account->setAllowFollowersGCM($allowFollowersGCM); $result['allowFollowersGCM'] = $account->getAllowFollowersGCM(); echo json_encode($result); exit; }