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;
 }
Esempio n. 2
0
 public function send($giftId, $giftTo, $message, $giftAnonymous = 0)
 {
     $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
     if ($giftId == 0) {
         return $result;
     }
     $giftInfo = $this->db_info($giftId);
     if ($giftInfo['error'] === true) {
         return $result;
     }
     $currentTime = time();
     $stmt = $this->db->prepare("INSERT INTO gifts (giftId, giftTo, giftFrom, giftAnonymous, message, imgUrl, createAt) value (:giftId, :giftTo, :giftFrom, :giftAnonymous, :message, :imgUrl, :createAt)");
     $stmt->bindParam(":giftId", $giftId, PDO::PARAM_INT);
     $stmt->bindParam(":giftTo", $giftTo, PDO::PARAM_INT);
     $stmt->bindParam(":giftFrom", $this->requestFrom, PDO::PARAM_INT);
     $stmt->bindParam(":giftAnonymous", $giftAnonymous, PDO::PARAM_INT);
     $stmt->bindParam(":message", $message, PDO::PARAM_STR);
     $stmt->bindParam(":imgUrl", $giftInfo['imgUrl'], PDO::PARAM_STR);
     $stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT);
     if ($stmt->execute()) {
         $giftId = $this->db->lastInsertId();
         $result = array("error" => false, "error_code" => ERROR_SUCCESS, "giftId" => $this->db->lastInsertId(), "gift" => $this->info($this->db->lastInsertId()));
         $account = new account($this->db, $giftTo);
         $account->updateCounters();
         unset($account);
         if ($this->requestFrom != $giftTo) {
             $blacklist = new blacklist($this->db);
             $blacklist->setRequestFrom($giftTo);
             if (!$blacklist->isExists($this->requestFrom)) {
                 $account = new account($this->db, $giftTo);
                 if ($account->getAllowGiftsGCM() == ENABLE_GIFTS_GCM) {
                     $gcm = new gcm($this->db, $giftTo);
                     $gcm->setData(GCM_NOTIFY_GIFT, "You have new gift", 0);
                     $gcm->send();
                 }
                 unset($account);
                 $notify = new notify($this->db);
                 $notify->createNotify($giftTo, $this->requestFrom, NOTIFY_TYPE_GIFT, $giftId);
                 unset($notify);
             }
             unset($blacklist);
         }
     }
     return $result;
 }
/*!
 * ifsoft.co.uk engine v1.0
 *
 * http://ifsoft.com.ua, http://ifsoft.co.uk
 * qascript@ifsoft.co.uk
 *
 * Copyright 2012-2016 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'] : '';
    $profileId = isset($_POST['profileId']) ? $_POST['profileId'] : 0;
    $profileId = helper::clearInt($profileId);
    $result = array("error" => true, "error_code" => ERROR_UNKNOWN);
    $auth = new auth($dbo);
    if (!$auth->authorize($accountId, $accessToken)) {
        api::printError(ERROR_ACCESS_TOKEN, "Error authorization.");
    }
    $blacklist = new blacklist($dbo);
    $blacklist->setRequestFrom($profileId);
    if (!$blacklist->isExists($accountId)) {
        $profile = new profile($dbo, $profileId);
        $profile->setRequestFrom($accountId);
        $result = $profile->addFollower($accountId);
    }
    echo json_encode($result);
    exit;
}