public function testParseGeocoderCircle() { global $egMultiMaps_AllowGeocoderTests; if (!$egMultiMaps_AllowGeocoderTests) { return; } $this->assertRegExp('{"circles":\\[{"radius":\\[[0-9\\.]+\\],"pos":\\[{"lat":[0-9\\.]+,"lon":[0-9\\.]+}\\]}\\],"bounds":{"ne":{"lat":[0-9\\.]+,"lon":[0-9\\.]+},"sw":{"lat":[0-9\\.]+,"lon":[0-9\\.]+}}}', \FormatJson::encode($this->object->getMapData(array('circle=Moscow', 'service=yandex')))); }
$geo = '15'; //$query = isset($_REQUEST['query'])?$_REQUEST['query']:null; $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 0; $host = isset($_REQUEST['host']) ? $_REQUEST['host'] : null; //$geo = isset($_REQUEST['geo']) ?$_REQUEST['geo']:null; $cat = isset($_REQUEST['cat']) ? $_REQUEST['cat'] : null; $theme = isset($_REQUEST['theme']) ? $_REQUEST['theme'] : null; // small protection for example script // only 2 seconds if ($query && microtime(true) - $_SESSION['ttl'] > 2) { // Your data http://xmlsearch.yandex.ru/xmlsearch?user=AntonShevchuk&key=03.28303679:b340c90e875df328e6e120986c837284 //http://xmlsearch.yandex.ru/xmlsearch?user=programmatore&key=03.29915828:0e54bb50b2061a2a18038bb37ff306cb $user = '******'; $key = '03.29915828:0e54bb50b2061a2a18038bb37ff306cb'; // Create new instance of Yandex class $Yandex = new Yandex($user, $key); // Set Query $Yandex->query($query)->host($host)->page($page)->limit(10)->geo($geo)->cat($cat)->theme($theme)->sortby(Yandex::SORT_RLV)->groupby(Yandex::GROUP_DEFAULT)->set('max-title-length', 160)->set('max-passage-length', 200)->request(); // Debug request $request = $Yandex->getRequest()->asXml(); } // current URL $server = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $server = substr($server, 0, strpos($server, '?')); $url = $server . '?query=' . urlencode($query) . '&host=' . urlencode($host) . '&geo=' . urlencode($geo) . '&cat=' . urlencode($cat) . '&theme=' . urlencode($theme); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
/** * преобразовать для вывода */ public function getResultsForShow() { $error = $this->Yandex->error; $error = is_null($error) || empty($error) ? false : $error; $resultForShow = []; $totalHuman = ''; if (false === $error) { $totalHuman = $this->Yandex->totalHuman(); $totalHuman = Yandex::getHighlight($totalHuman); $res = $this->Yandex->results(); foreach ($res as $result) { $result_i = []; $url = isset($result->url) && !is_null($result->url) ? Yandex::getHighlight($result->url) : ''; $result_i['url'] = $url; $headline = isset($result->headline) && !is_null($result->headline) ? Yandex::getHighlight($result->headline) : ''; $result_i['headline'] = $headline; $domain = isset($result->domain) && !is_null($result->domain) ? Yandex::getHighlight($result->domain) : ''; $result_i['domain'] = $domain; $title = isset($result->title) && !is_null($result->title) ? Yandex::getHighlight($result->title) : ''; $result_i['title'] = $title; $result_i['passages'] = []; if (isset($result->passages) && !is_null($result->passages)) { if ($result->passages) { foreach ($result->passages as $passage) { $pass = Yandex::getHighlight($passage); $result_i['passages'][] = $pass; } } } $resultForShow[] = $result_i; } } return ['successful' => !$error, 'totalHuman' => $totalHuman, 'pageStart' => $this->Yandex->getLimit() * $this->Yandex->getPage() + 1, 'results' => $resultForShow, 'error' => $error, 'message' => $error]; }