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; }
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; }
*/ include_once $_SERVER['DOCUMENT_ROOT'] . "/core/init.inc.php"; if (!admin::isSession()) { header("Location: /admin/login.php"); } if (!empty($_POST)) { $authToken = isset($_POST['authenticity_token']) ? $_POST['authenticity_token'] : ''; $message = isset($_POST['message']) ? $_POST['message'] : ''; $type = isset($_POST['type']) ? $_POST['type'] : 1; $message = helper::clearText($message); $message = helper::escapeText($message); $type = helper::clearInt($type); if ($authToken === helper::getAuthenticityToken() && !APP_DEMO) { if (strlen($message) != 0) { $gcm = new gcm($dbo, 0); $gcm->setData($type, $message, 0); $gcm->forAll(); $gcm->send(); } } header("Location: /admin/gcm.php"); } $stats = new stats($dbo); $page_id = "gcm"; $error = false; $error_message = ''; helper::newAuthenticityToken(); $css_files = array("admin.css"); $page_title = "Google Cloud Messages"; include_once $_SERVER['DOCUMENT_ROOT'] . "/common/header.inc.php"; ?>
public function create($toUserId, $chatId, $message = "", $imgUrl = "") { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); if (strlen($imgUrl) == 0 && strlen($message) == 0) { return $result; } if ($chatId == 0) { $chatId = $this->getChatId($this->getRequestFrom(), $toUserId); if ($chatId == 0) { $chatId = $this->createChat($this->getRequestFrom(), $toUserId); } } $currentTime = time(); $ip_addr = helper::ip_addr(); $u_agent = helper::u_agent(); $stmt = $this->db->prepare("INSERT INTO messages (chatId, fromUserId, toUserId, message, imgUrl, createAt, ip_addr, u_agent) value (:chatId, :fromUserId, :toUserId, :message, :imgUrl, :createAt, :ip_addr, :u_agent)"); $stmt->bindParam(":chatId", $chatId, PDO::PARAM_INT); $stmt->bindParam(":fromUserId", $this->requestFrom, PDO::PARAM_INT); $stmt->bindParam(":toUserId", $toUserId, PDO::PARAM_INT); $stmt->bindParam(":message", $message, PDO::PARAM_STR); $stmt->bindParam(":imgUrl", $imgUrl, PDO::PARAM_STR); $stmt->bindParam(":createAt", $currentTime, PDO::PARAM_INT); $stmt->bindParam(":ip_addr", $ip_addr, PDO::PARAM_STR); $stmt->bindParam(":u_agent", $u_agent, PDO::PARAM_STR); if ($stmt->execute()) { $msgId = $this->db->lastInsertId(); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "chatId" => $chatId, "msgId" => $msgId, "message" => $this->info($msgId)); $gcm = new gcm($this->db, $toUserId); $gcm->setData(GCM_NOTIFY_MESSAGE, "You have new message", $chatId); $gcm->send(); } 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; }