예제 #1
0
 function search($name)
 {
     $url = 'http://' . $this->host . '/search?name=' . urlencode($name) . '&lang=pl&maxrows=3' . ($this->username !== NULL ? '&username='******'');
     try {
         $download = new DownloadHelper($url);
         $data = $download->exec();
         if (!$data) {
             $download->cacheFor(600);
             return FALSE;
         }
         libxml_use_internal_errors();
         $data = simplexml_load_string($data);
         libxml_clear_errors();
         if (!$data) {
             $download->cacheFor(600);
             return FALSE;
         }
         // Trzymaj w cache przez około 116 dni
         $download->cacheFor(10000000);
         if ((int) $data->totalResultsCount == 0 || $data->geoname->getName() != 'geoname' || $data->geoname[0]->getName() != 'geoname' || $data->geoname[0]->name->getName() != 'name' || $data->geoname[0]->countryName->getName() != 'countryName' || $data->geoname[0]->lat->getName() != 'lat' || $data->geoname[0]->lng->getName() != 'lng') {
             return NULL;
         }
         $data = (array) $data->geoname[0];
         foreach ($data as &$value) {
             $value = trim($value);
         }
         unset($value);
         if (isset($data['countryName']) && $data['countryName'] == 'Rzeczpospolita Polska') {
             $data['countryName'] = 'Polska';
         }
         return $data;
     } catch (Exception $e) {
         return FALSE;
     }
 }
예제 #2
0
파일: handler.php 프로젝트: Alambos/bot
 function cache($url)
 {
     $down = new DownloadHelper($url);
     $dane = $down->exec();
     libxml_use_internal_errors(TRUE);
     $dom = new DOMDocument();
     if (!$dom->loadHTML($dane)) {
         libxml_use_internal_errors(FALSE);
         $down->cacheFor(1800);
         return FALSE;
     }
     $down->cacheUntil(strtotime('tomorrow midnight'));
     return $dom;
 }
예제 #3
0
파일: api_yrno.php 프로젝트: Alambos/bot
function yrno_weather($lat, $lon)
{
    $down = new DownloadHelper('http://api.yr.no/weatherapi/locationforecastlts/1.1/?lat=' . urlencode($lat) . ';lon=' . urlencode($lon));
    $down->setopt(CURLOPT_USERAGENT, 'BotGG/' . main::VERSION_NUM . ' WeatherModule/1.0 (http://bot.jacekk.net/weather.html)');
    try {
        $data = $down->exec();
        $data = new api_yrno_parse($data);
        $data->parseForecast();
    } catch (Exception $e) {
        $down->cacheFor(600);
        return FALSE;
    }
    $down->cacheFor(7200);
    return $data;
}