Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
<?php

/*!
 * 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'] : '';
    $itemId = isset($_POST['itemId']) ? $_POST['itemId'] : 0;
    $itemId = helper::clearInt($itemId);
    $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, $accountId);
    $profile->setRequestFrom($accountId);
    $result = $profile->getILiked($itemId);
    echo json_encode($result);
    exit;
}
Ejemplo n.º 4
0
 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;
 }