public function getAll($notifyId = 0) { if ($notifyId == 0) { $notifyId = $this->getMaxId(); $notifyId++; } $notifications = array("error" => false, "error_code" => ERROR_SUCCESS, "notifyId" => $notifyId, "notifications" => array()); $stmt = $this->db->prepare("SELECT * FROM notifications WHERE notifyToId = (:notifyToId) AND id < (:notifyId) ORDER BY id DESC LIMIT 20"); $stmt->bindParam(':notifyToId', $this->requestFrom, PDO::PARAM_INT); $stmt->bindParam(':notifyId', $notifyId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch()) { $time = new language($this->db, $this->language); if ($row['notifyFromId'] == 0) { $profileInfo = array("id" => 0, "state" => 0, "username" => "", "fullname" => "", "lowPhotoUrl" => "/img/profile_default_photo.png"); } else { $profile = new profile($this->db, $row['notifyFromId']); $profileInfo = $profile->get(); unset($profile); } $data = array("id" => $row['id'], "type" => $row['notifyType'], "itemId" => $row['itemId'], "fromUserId" => $profileInfo['id'], "fromUserState" => $profileInfo['state'], "fromUserUsername" => $profileInfo['username'], "fromUserFullname" => $profileInfo['fullname'], "fromUserPhotoUrl" => $profileInfo['lowPhotoUrl'], "createAt" => $row['createAt'], "timeAgo" => $time->timeAgo($row['createAt'])); array_push($notifications['notifications'], $data); $notifications['notifyId'] = $row['id']; unset($data); } } } return $notifications; }
public function getPeopleNearby($itemId, $lat, $lng, $distance = 30) { if ($itemId == 0) { $itemId = $this->getMaxId(); $itemId++; } $result = array("error" => false, "error_code" => ERROR_SUCCESS, "itemId" => $itemId, "items" => array()); $tableName = "users"; $origLat = $lat; $origLon = $lng; $dist = $distance; // This is the maximum distance (in miles) away from $origLat, $origLon in which to search $sql = "SELECT id, lat, lng, 3956 * 2 *\r\n ASIN(SQRT( POWER(SIN(({$origLat} - lat)*pi()/180/2),2)\r\n +COS({$origLat}*pi()/180 )*COS(lat*pi()/180)\r\n *POWER(SIN(({$origLon}-lng)*pi()/180/2),2)))\r\n as distance FROM {$tableName} WHERE\r\n lng between ({$origLon}-{$dist}/cos(radians({$origLat}))*69)\r\n and ({$origLon}+{$dist}/cos(radians({$origLat}))*69)\r\n and lat between ({$origLat}-({$dist}/69))\r\n and ({$origLat}+({$dist}/69))\r\n and (id < {$itemId})\r\n and (id <> {$this->requestFrom})\r\n and (state = 0)\r\n having distance < {$dist} ORDER BY id DESC limit 20"; $stmt = $this->db->prepare($sql); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch()) { $profile = new profile($this->db, $row['id']); $profile->setRequestFrom($this->requestFrom); $profileInfo = $profile->get(); $profileInfo['distance'] = round($this->getDistance($lat, $lng, $profileInfo['lat'], $profileInfo['lng']), 1); unset($profile); array_push($result['items'], $profileInfo); $result['itemId'] = $row['id']; unset($profile); } } } return $result; }
public function query($queryText = '', $userId = 0, $gender = -1, $online = -1, $ageFrom = 13, $ageTo = 110) { $originQuery = $queryText; if ($userId == 0) { $userId = $this->lastIndex(); $userId++; } $endSql = " ORDER BY regtime DESC LIMIT 20"; $genderSql = ""; if ($gender != -1) { $genderSql = " AND sex = {$gender}"; } $onlineSql = ""; if ($online != -1) { $current_time = time() - 15 * 60; $onlineSql = " AND last_authorize > {$current_time}"; } $current_year = date("Y"); $fromYear = $current_year - $ageFrom; $toYear = $current_year - $ageTo; $dateSql = " AND bYear < {$fromYear} AND bYear > {$toYear}"; $users = array("error" => false, "error_code" => ERROR_SUCCESS, "itemCount" => $this->getCount($originQuery, $gender, $online, $ageFrom, $ageTo), "userId" => $userId, "query" => $originQuery, "users" => array()); $queryText = "%" . $queryText . "%"; $sql = "SELECT id, regtime FROM users WHERE state = 0 AND (login LIKE '{$queryText}' OR fullname LIKE '{$queryText}' OR email LIKE '{$queryText}' OR country LIKE '{$queryText}') AND id < {$userId}" . $genderSql . $onlineSql . $dateSql . $endSql; $stmt = $this->db->prepare($sql); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch()) { $profile = new profile($this->db, $row['id']); $profile->setRequestFrom($this->requestFrom); array_push($users['users'], $profile->get()); $users['userId'] = $row['id']; unset($profile); } } } return $users; }
public function info($giftId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $stmt = $this->db->prepare("SELECT * FROM gifts WHERE id = (:giftId) LIMIT 1"); $stmt->bindParam(":giftId", $giftId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { $row = $stmt->fetch(); $time = new language($this->db, $this->language); $profile = new profile($this->db, $row['giftFrom']); $profileInfo = $profile->get(); unset($profile); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "id" => $row['id'], "giftId" => $row['giftId'], "giftTo" => $row['giftTo'], "giftFrom" => $row['giftFrom'], "giftFromUserVip" => $profileInfo['vip'], "giftFromUserVerify" => $profileInfo['verify'], "giftFromUserUsername" => $profileInfo['username'], "giftFromUserFullname" => $profileInfo['fullname'], "giftFromUserPhoto" => $profileInfo['lowPhotoUrl'], "giftAnonymous" => $row['giftAnonymous'], "message" => htmlspecialchars_decode(stripslashes($row['message'])), "imgUrl" => $row['imgUrl'], "createAt" => $row['createAt'], "date" => date("Y-m-d H:i:s", $row['createAt']), "timeAgo" => $time->timeAgo($row['createAt']), "removeAt" => $row['removeAt']); } } return $result; }
public function getILiked($itemId = 0) { if ($itemId == 0) { $itemId = $this->getMaxIdLikes(); $itemId++; } $result = array("error" => false, "error_code" => ERROR_SUCCESS, "itemId" => $itemId, "items" => array()); $stmt = $this->db->prepare("SELECT * FROM profile_likes WHERE fromUserId = (:fromUserId) AND id < (:itemId) AND removeAt = 0 ORDER BY id DESC LIMIT 20"); $stmt->bindParam(':fromUserId', $this->id, PDO::PARAM_INT); $stmt->bindParam(':itemId', $itemId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { while ($row = $stmt->fetch()) { $profile = new profile($this->db, $row['toUserId']); $profile->setRequestFrom($this->requestFrom); $profileInfo = $profile->get(); unset($profile); array_push($result['items'], $profileInfo); $result['itemId'] = $row['id']; unset($profile); } } } return $result; }
* 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."); } $profile = new profile($dbo, $profileId); $profile->setRequestFrom($accountId); $account = new account($dbo, $accountId); $accountInfo = $account->get(); if ($profileId == $accountId) { $account->setLastActive(); } else { if ($accountInfo['ghost'] == 0) { $guests = new guests($dbo, $profileId); $guests->setRequestFrom($accountId); $guests->add($accountId); } } $result = $profile->get(); echo json_encode($result); exit; }
$messageText = helper::clearText($messageText); $messageText = preg_replace("/[\r\n]+/", "<br>", $messageText); //replace all new lines to one new line $messageText = preg_replace('/\\s+/', ' ', $messageText); //replace all white spaces to one space $messageText = helper::escapeText($messageText); $messageImg = helper::clearText($messageImg); $messageImg = helper::escapeText($messageImg); $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $auth = new auth($dbo); if (!$auth->authorize($accountId, $accessToken)) { api::printError(ERROR_ACCESS_TOKEN, "Error authorization."); } $profile = new profile($dbo, $profileId); $profile->setRequestFrom($accountId); $profileInfo = $profile->get(); if ($profileInfo['state'] != ACCOUNT_STATE_ENABLED) { echo json_encode($result); exit; } if ($profileInfo['allowMessages'] == 0 && $profileInfo['follower'] === false) { echo json_encode($result); exit; } $blacklist = new blacklist($dbo); $blacklist->setRequestFrom($profileId); if (!$blacklist->isExists($accountId)) { $messages = new messages($dbo); $messages->setRequestFrom($accountId); $result = $messages->create($profileId, $chatId, $messageText, $messageImg); }
public function info($itemId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $stmt = $this->db->prepare("SELECT * FROM friends WHERE id = (:itemId) LIMIT 1"); $stmt->bindParam(":itemId", $itemId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { $row = $stmt->fetch(); $time = new language($this->db, $this->language); $profile = new profile($this->db, $row['friend']); $profileInfo = $profile->get(); unset($profile); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "id" => $row['id'], "friendUserId" => $row['friend'], "friendUserVip" => $profileInfo['vip'], "friendUserVerify" => $profileInfo['verify'], "friendUserUsername" => $profileInfo['username'], "friendUserFullname" => $profileInfo['fullname'], "friendUserPhoto" => $profileInfo['lowPhotoUrl'], "friendUserOnline" => $profileInfo['online'], "friendLocation" => $profileInfo['location'], "friendTo" => $row['friendTo'], "friend" => $row['friend'], "createAt" => $row['createAt'], "date" => date("Y-m-d H:i:s", $row['createAt']), "timeAgo" => $time->timeAgo($row['createAt']), "removeAt" => $row['removeAt']); } } return $result; }
private function itemInfo($itemId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $stmt = $this->db->prepare("SELECT * FROM profile_blacklist WHERE id = (:itemId) LIMIT 1"); $stmt->bindParam(":itemId", $itemId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { $row = $stmt->fetch(); $time = new language($this->db, $this->language); $profile = new profile($this->db, $row['blockedUserId']); $blockedUserId = $profile->get(); unset($profile); $lowPhotoUrl = "/img/profile_default_photo.png"; if (strlen($blockedUserId['lowPhotoUrl']) != 0) { $lowPhotoUrl = $blockedUserId['lowPhotoUrl']; } $result = array("error" => false, "error_code" => ERROR_SUCCESS, "id" => $row['id'], "blockedUserId" => $row['blockedUserId'], "blockedUserState" => $blockedUserId['state'], "blockedUserVerify" => $blockedUserId['verify'], "blockedUserUsername" => $blockedUserId['username'], "blockedUserFullname" => $blockedUserId['fullname'], "blockedUserPhotoUrl" => $lowPhotoUrl, "reason" => htmlspecialchars_decode(stripslashes($row['reason'])), "createAt" => $row['createAt'], "removeAt" => $row['removeAt'], "timeAgo" => $time->timeAgo($row['createAt'])); } } return $result; }
public function info($photoId) { $result = array("error" => true, "error_code" => ERROR_UNKNOWN); $stmt = $this->db->prepare("SELECT * FROM photos WHERE id = (:photoId) LIMIT 1"); $stmt->bindParam(":photoId", $photoId, PDO::PARAM_INT); if ($stmt->execute()) { if ($stmt->rowCount() > 0) { $row = $stmt->fetch(); $time = new language($this->db, $this->language); $profile = new profile($this->db, $row['fromUserId']); $profileInfo = $profile->get(); unset($profile); $result = array("error" => false, "error_code" => ERROR_SUCCESS, "id" => $row['id'], "accessMode" => $row['accessMode'], "fromUserId" => $row['fromUserId'], "fromUserVerify" => $profileInfo['verify'], "fromUserUsername" => $profileInfo['username'], "fromUserFullname" => $profileInfo['fullname'], "fromUserPhoto" => $profileInfo['lowPhotoUrl'], "comment" => htmlspecialchars_decode(stripslashes($row['comment'])), "area" => htmlspecialchars_decode(stripslashes($row['area'])), "country" => htmlspecialchars_decode(stripslashes($row['country'])), "city" => htmlspecialchars_decode(stripslashes($row['city'])), "lat" => $row['lat'], "lng" => $row['lng'], "imgUrl" => $row['imgUrl'], "previewImgUrl" => $row['previewImgUrl'], "originImgUrl" => $row['originImgUrl'], "rating" => $row['rating'], "commentsCount" => $row['commentsCount'], "likesCount" => $row['likesCount'], "createAt" => $row['createAt'], "date" => date("Y-m-d H:i:s", $row['createAt']), "timeAgo" => $time->timeAgo($row['createAt']), "removeAt" => $row['removeAt']); } } return $result; }