ADD Aviasales
This commit is contained in:
parent
a1ae282446
commit
fdb0a0bdb5
21
app.php
21
app.php
|
|
@ -34,6 +34,8 @@ class App
|
||||||
public static $user = null;
|
public static $user = null;
|
||||||
public static $request = array();
|
public static $request = array();
|
||||||
public static $defaultTitle = 'Лучшие выходные — это выходные в путешествии! – wikipoints.ru';
|
public static $defaultTitle = 'Лучшие выходные — это выходные в путешествии! – wikipoints.ru';
|
||||||
|
public static $userIp = null;
|
||||||
|
public static $userGeo = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Разбивает урл на контроллер, метод и выбирает параметры.
|
* Разбивает урл на контроллер, метод и выбирает параметры.
|
||||||
|
|
@ -75,6 +77,7 @@ class App
|
||||||
self::parseUrl();
|
self::parseUrl();
|
||||||
|
|
||||||
self::userInit();
|
self::userInit();
|
||||||
|
self::ipAndGeoInit();
|
||||||
|
|
||||||
$controller = self::$controller;
|
$controller = self::$controller;
|
||||||
$action = self::$action;
|
$action = self::$action;
|
||||||
|
|
@ -129,6 +132,24 @@ class App
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function ipAndGeoInit()
|
||||||
|
{
|
||||||
|
App::$userIp = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
|
$loc = Storage::get(App::$userIp);
|
||||||
|
if(!$loc) {
|
||||||
|
$loc = IpInfo::geo(App::$userIp);
|
||||||
|
Storage::model()->set(App::$userIp, $loc, 604800); // ttl = week
|
||||||
|
} else {
|
||||||
|
App::log('reuseIp', App::$userIp);
|
||||||
|
}
|
||||||
|
|
||||||
|
App::$userGeo = array(
|
||||||
|
'lat' => $loc['lat'],
|
||||||
|
'lng' => $loc['lng'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function userLogin($user)
|
public static function userLogin($user)
|
||||||
{
|
{
|
||||||
$_SESSION['user_id'] = $user->id;
|
$_SESSION['user_id'] = $user->id;
|
||||||
|
|
|
||||||
|
|
@ -60,17 +60,8 @@ class IndexController extends Controller
|
||||||
self::addVar('userLat', $_COOKIE['userLat']);
|
self::addVar('userLat', $_COOKIE['userLat']);
|
||||||
self::addVar('userLng', $_COOKIE['userLng']);
|
self::addVar('userLng', $_COOKIE['userLng']);
|
||||||
} else {
|
} else {
|
||||||
$ip = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $_SERVER['REMOTE_ADDR'];
|
self::addVar('userLat', App::$userGeo['lat']);
|
||||||
// $ip = '91.204.150.217';
|
self::addVar('userLng', App::$userGeo['lng']);
|
||||||
$loc = Storage::get($ip);
|
|
||||||
if(!$loc) {
|
|
||||||
$loc = IpInfo::geo($ip);
|
|
||||||
Storage::model()->set($ip, $loc, 604800); // ttl = week
|
|
||||||
} else {
|
|
||||||
App::log('reuseIp', $ip);
|
|
||||||
}
|
|
||||||
self::addVar('userLat', $loc['lat']);
|
|
||||||
self::addVar('userLng', $loc['lng']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$og = array();
|
$og = array();
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,8 @@ class PointController extends Controller
|
||||||
'photoLinks' => $photoLinksRes,
|
'photoLinks' => $photoLinksRes,
|
||||||
'articles' => $articles,
|
'articles' => $articles,
|
||||||
'extraParams' => $point->getExtraParams(),
|
'extraParams' => $point->getExtraParams(),
|
||||||
|
'usersAirport' => Airports::getNearest(App::$userGeo['lat'], App::$userGeo['lng']),
|
||||||
|
'pointsAirport' => Airports::getNearest($point->lat, $point->lng),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Airports extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
function __construct($fromArray = array())
|
||||||
|
{
|
||||||
|
$this->_tableName_ = 'airports';
|
||||||
|
parent::__construct($fromArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
static function model()
|
||||||
|
{
|
||||||
|
return new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getNearest($lat, $lng)
|
||||||
|
{
|
||||||
|
$degrees = 3;
|
||||||
|
|
||||||
|
$lat = floatval($lat);
|
||||||
|
$lng = floatval($lng);
|
||||||
|
|
||||||
|
$delta = (1+abs(SIN($lat/100)*SIN($lat/100)*5))*$degrees;
|
||||||
|
|
||||||
|
$query = '
|
||||||
|
SELECT *,
|
||||||
|
(POW(`lat`-:lat,2)+POW(`lng`-:lng,2)) AS `dist`
|
||||||
|
FROM `airports`
|
||||||
|
WHERE
|
||||||
|
`lat` BETWEEN :minLat AND :maxLat
|
||||||
|
AND
|
||||||
|
`lng` BETWEEN :minLng AND :maxLng
|
||||||
|
ORDER BY `dist`
|
||||||
|
LIMIT 1;';
|
||||||
|
|
||||||
|
$res = App::DB()->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
|
||||||
|
$res->execute(array(':lat' => $lat, ':lng' => $lng, ':minLat' => $lat - $degrees, ':minLng' => $lng - $delta, ':maxLat' => $lat + $degrees, ':maxLng' => $lng + $delta));
|
||||||
|
|
||||||
|
if ($res && $row = $res->fetch(PDO::FETCH_ASSOC)) {
|
||||||
|
return new Airports($row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
|
||||||
|
return self::model()->getAll(array('where'=>'`lat`>0 AND `lng`>0', 'order','limit'=>1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -119,6 +119,91 @@ $index = 0;
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<br/>
|
||||||
|
<?php if ($pointsAirport && $usersAirport && $pointsAirport->id != $usersAirport->id): ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12 text-center">
|
||||||
|
<script charset="utf-8" type="text/javascript">
|
||||||
|
window.TP_FORM_SETTINGS = window.TP_FORM_SETTINGS || {};
|
||||||
|
window.TP_FORM_SETTINGS["394e02eacac3a5c9b000360787c2d5d2"] = {
|
||||||
|
"handle": "394e02eacac3a5c9b000360787c2d5d2",
|
||||||
|
"widget_name": "Поисковая форма — точка",
|
||||||
|
"border_radius": "2",
|
||||||
|
"additional_marker": null,
|
||||||
|
"width": null,
|
||||||
|
"show_logo": true,
|
||||||
|
"show_hotels": false,
|
||||||
|
"form_type": "avia",
|
||||||
|
"locale": "ru",
|
||||||
|
"currency": "rub",
|
||||||
|
"sizes": "default",
|
||||||
|
"search_target": "_blank",
|
||||||
|
"active_tab": "avia",
|
||||||
|
"search_host": "hydra.aviasales.ru",
|
||||||
|
"hotels_host": "hotellook.ru/search",
|
||||||
|
"hotel": "",
|
||||||
|
"hotel_alt": "",
|
||||||
|
"avia_alt": "",
|
||||||
|
"retargeting": true,
|
||||||
|
"trip_class": "economy",
|
||||||
|
"depart_date": null,
|
||||||
|
"return_date": null,
|
||||||
|
"check_in_date": null,
|
||||||
|
"check_out_date": null,
|
||||||
|
"id": 70240,
|
||||||
|
"marker": 52337,
|
||||||
|
"origin": {
|
||||||
|
"name": "<?= $usersAirport->cityRu?>",
|
||||||
|
"iata": "<?= $usersAirport->iata?>"
|
||||||
|
},
|
||||||
|
"destination": {
|
||||||
|
"name": "<?= '';//$pointsAirport->cityRu?>",
|
||||||
|
"iata": "<?= $pointsAirport->iata?>"
|
||||||
|
},
|
||||||
|
"color_scheme": {
|
||||||
|
"name": "white_orange",
|
||||||
|
"icons": "icons_orange",
|
||||||
|
"background": "#ffffff",
|
||||||
|
"color": "#000000",
|
||||||
|
"border_color": "#cccccc",
|
||||||
|
"button": "#feb20e",
|
||||||
|
"button_text_color": "#ffffff",
|
||||||
|
"input_border": "#cccccc"
|
||||||
|
},
|
||||||
|
"hotels_type": "hotellook_host",
|
||||||
|
"best_offer": {
|
||||||
|
"locale": "ru",
|
||||||
|
"currency": "rub",
|
||||||
|
"marker": 52337,
|
||||||
|
"search_host": "hydra.aviasales.ru",
|
||||||
|
"offers_switch": true,
|
||||||
|
"api_url": "//www.travelpayouts.com/minimal_prices/offers.json",
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"one_way": true,
|
||||||
|
"origin": {
|
||||||
|
"name": "<?= $usersAirport->cityRu?>",
|
||||||
|
"iata": "<?= $usersAirport->iata?>"
|
||||||
|
},
|
||||||
|
"destination": {
|
||||||
|
"name": "<?= $pointsAirport->cityRu?>",
|
||||||
|
"iata": "<?= $pointsAirport->iata?>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hotel_logo_host": "hotellook.ru",
|
||||||
|
"search_logo_host": "www.aviasales.ru",
|
||||||
|
"hotel_marker_format": "marker=",
|
||||||
|
"hotelscombined_marker": null,
|
||||||
|
"responsive": true,
|
||||||
|
"height": 194
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script charset="utf-8" src="//www.travelpayouts.com/widgets/394e02eacac3a5c9b000360787c2d5d2.js?v=727" async></script>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12" style="text-align: center;">
|
<div class="col-md-12" style="text-align: center;">
|
||||||
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
||||||
|
|
@ -133,6 +218,7 @@ $index = 0;
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue