示例#1
0
文件: main.php 项目: nian2go/fatfree
 function geo()
 {
     $this->set('title', 'Geo');
     $this->expect(is_null($this->get('ERROR')), 'No errors expected at this point', 'ERROR variable is set: ' . $this->get('ERROR.text'));
     $this->expect(Geo::$countries, 'Geo plugin returns ' . count(Geo::$countries) . ' countries', 'Geo plugin failed to retrieve countries');
     $tz = Geo::timezones();
     $this->expect(count($tz), 'Geo plugin returns an array of ' . count($tz) . ' timezones', 'Geo plugin failed to retrieve timezones');
     while (TRUE) {
         $loc = array_rand($tz);
         if (is_int(strpos($loc, '/')) && is_bool(strpos($loc, 'Etc'))) {
             break;
         }
     }
     $this->expect($tz[$loc], $loc . ' timezone returns UTC' . ($tz[$loc]['offset'] ? '+' : '') . $tz[$loc]['offset'] . ' offset', 'UTC offset not available');
     $this->set('QUIET', TRUE);
     $weather = Geo::weather($tz[$loc]['latitude'], $tz[$loc]['longitude']);
     $this->set('QUIET', FALSE);
     $this->expect($weather, 'GeoNames weather report: Temperature at ' . $weather['stationName'] . ' is ' . $weather['temperature'] . ' degrees', 'Weather report for above location is not available');
     $this->clear('ERROR');
     $this->set('QUIET', TRUE);
     $location = Geo::location();
     $this->set('QUIET', FALSE);
     $this->expect($location, 'Detected GeoLocation is ' . $location['city'] . ', ' . $location['countryName'], 'GeoLocation is not available');
     $this->clear('ERROR');
     echo $this->render('basic/results.htm');
 }