-
-
Save vgrish/222949d8ac0f8e20fa23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function download($src, $timeout = 3) { | |
if (function_exists('curl_init')) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $src); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | |
$safeMode = @ini_get('safe_mode'); | |
$openBasedir = @ini_get('open_basedir'); | |
if (empty($safeMode) && empty($openBasedir)) { | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
} | |
$file = curl_exec($ch); | |
$info = curl_getinfo($ch); | |
if ($info['http_code'] != 200) { | |
$modx->log(1, 'Could not download data from: '.$src); | |
$file = ''; | |
} | |
curl_close($ch); | |
} else { | |
$file = @file_get_contents($src); | |
} | |
return $file; | |
} | |
/*Массив с параметрами для получения значения ем параметра*/ | |
$where = array( | |
'contentid' => $id | |
, 'tmplvarid' => 11 | |
); | |
if (!$tv = $modx->getObject('modTemplateVarResource', $where)) { | |
return ''; | |
} | |
/*Записываем в переменную значение из TV */ | |
$result = $tv->get('value'); | |
/*Переворачиваем координаты*/ | |
$revers_coords = explode ("," , $result); | |
/*URL с запросом на yandex*/ | |
$city="https://geocode-maps.yandex.ru/1.x/?geocode=".$revers_coords[1].",".$revers_coords[0]."&city&results=1"; | |
$city_xml = download($city); | |
preg_match('/<LocalityName>(.*?)<\/LocalityName>/',$city_xml,$city_point); // вырезаем нужные нам координаты для метро | |
$resource -> setTVValue('city', $city_point[1] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment