Beispiel #1
0
 /**
  * Constructor
  * @param string $country
  * @param string $region
  */
 public function __construct($country, $region = false)
 {
     parent::__construct();
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Start the debug timer
      */
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     if ($region == false && !preg_match("@[a-zA-Z]+@", $country)) {
         // Assume a WOE ID
         $woe = Place::getWOEData($country);
     } else {
         $woe = Place::getWOEData($region . ", " . strtoupper($country));
     }
     /**
      * End the debug timer
      */
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : fetched WOE data from Yahoo in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     if (isset($woe['places']['place'][0]['name'])) {
         $row = $woe['places']['place'][0];
         $this->slug = $region;
         $this->Country = new Country($country);
     } elseif (isset($woe['place'])) {
         $row = $woe['place'];
         $this->slug = $this->makeRegionSlug($row['name']);
     }
     if (isset($row)) {
         if (empty($this->Country->name) && !preg_match("@[a-zA-Z]+@", $country) && isset($row['country'])) {
             $this->Country = new Country($row['country']);
         }
         $this->name = $row['name'];
         $this->url = $this->Country->url . "/" . $this->slug;
         $this->centre = new stdClass();
         $this->centre->lat = $row['centroid']['latitude'];
         $this->centre->lon = $row['centroid']['longitude'];
         $this->boundingBox = new stdClass();
         $this->boundingBox->northEast = new stdClass();
         $this->boundingBox->northEast->lat = $row['boundingBox']['northEast']['latitude'];
         $this->boundingBox->northEast->lon = $row['boundingBox']['northEast']['longitude'];
         $this->boundingBox->southWest = new stdClass();
         $this->boundingBox->southWest->lat = $row['boundingBox']['southWest']['latitude'];
         $this->boundingBox->southWest->lon = $row['boundingBox']['southWest']['longitude'];
         if (isset($row['timezone'])) {
             $this->timezone = $row['timezone'];
         }
     }
 }
Beispiel #2
0
 /**
  * Constructor
  *
  * @param string|null $country
  * @param string|bool $region
  */
 public function __construct($country = null, $region = false)
 {
     Debug::RecordInstance();
     $timer = Debug::GetTimer();
     if (is_null($country)) {
         throw new InvalidArgumentException("No country was specified");
     }
     parent::__construct();
     $this->load($country, $region);
     Debug::LogEvent(__METHOD__, $timer);
 }
Beispiel #3
0
 /**
  * Constructor
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $query = "SELECT * FROM location_datetypes WHERE id = ?";
         if ($row = $this->db->fetchRow($query, $id)) {
             $this->id = $id;
             $this->name = $row['name'];
         }
     }
 }
Beispiel #4
0
 /**
  * Constructor
  * @param string $code
  */
 public function __construct($code)
 {
     parent::__construct();
     $this->code = $code;
     $this->url = "/locations/" . strtolower($this->code);
     /**
      * Record this in the debug log
      */
     if (function_exists("debug_recordInstance")) {
         debug_recordInstance(__CLASS__);
     }
     /**
      * Start the debug timer
      */
     if (RP_DEBUG) {
         global $site_debug;
         $debug_timer_start = microtime(true);
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     $woe = Place::getWOEData(strtoupper($code));
     /**
      * End the debug timer
      */
     if (RP_DEBUG) {
         $site_debug[] = __CLASS__ . "::" . __FUNCTION__ . "() : fetched WOE data from Yahoo in " . round(microtime(true) - $debug_timer_start, 5) . "s";
     }
     if (isset($woe['places']['place'][0]['name'])) {
         $woe = $woe['places']['place'][0];
         $this->name = $woe['name'];
         if (isset($woe['country attrs'])) {
             $this->code = $woe['country attrs']['code'];
             $this->url = "/locations/" . strtolower($this->code);
         }
         $this->centre = new stdClass();
         $this->centre->lat = $woe['centroid']['latitude'];
         $this->centre->lon = $woe['centroid']['longitude'];
         $this->boundingBox = new stdClass();
         $this->boundingBox->northEast = new stdClass();
         $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude'];
         $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude'];
         $this->boundingBox->southWest = new stdClass();
         $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude'];
         $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude'];
         if (isset($woe['timezone'])) {
             $this->timezone = $woe['timezone'];
         }
     }
 }
Beispiel #5
0
 /**
  * Constructor
  * @since Version 3.8.7
  * @param int $id
  */
 public function __construct($id = false)
 {
     parent::__construct();
     if (filter_var($id, FILTER_VALIDATE_INT)) {
         $query = "SELECT * FROM location_date WHERE id = ?";
         if ($row = $this->db->fetchRow($query, $id)) {
             $this->id = $id;
             $this->Date = new DateTime($row['date']);
             $this->text = $row['text'];
             $this->meta = json_decode($row['meta']);
             $this->Type = new DateType($row['type_id']);
             $this->Location = new Location($row['location_id']);
         }
     }
 }
Beispiel #6
0
 /**
  * Constructor
  *
  * @param string $code
  */
 public function __construct($code)
 {
     parent::__construct();
     $this->code = $code;
     $this->url = new Url("/locations/" . strtolower($this->code));
     $countries = ISO_3166::get_countries();
     if (strlen($this->code) == 2) {
         $this->name = $countries[$code]['name'];
     } else {
         foreach ($countries as $cc => $data) {
             if (strtolower($data['name']) == strtolower($this->code)) {
                 $this->code = $cc;
                 $this->url = new Url("/locations/" . strtolower($this->code));
                 $this->name = $data['name'];
             }
         }
     }
     Debug::RecordInstance();
     $timer = Debug::GetTimer();
     if (!$this->loadFromCache() || empty($this->name)) {
         $woe = Place::getWOEData(strtoupper($code));
         if (isset($woe['places']['place'][0]['name'])) {
             $woe = $woe['places']['place'][0];
             $data = ["point" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['centroid']['latitude'], $woe['centroid']['longitude'])), "bb_southwest" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['southWest']['latitude'], $woe['boundingBox']['southWest']['longitude'])), "bb_northeast" => new Zend_Db_Expr(sprintf("GeomFromText('POINT(%s %s)')", $woe['boundingBox']['northEast']['latitude'], $woe['boundingBox']['northEast']['longitude'])), "country_code" => $woe['country attrs']['code'], "country_name" => $woe['name'], "timezone" => isset($woe['timezone']) ? $woe['timezone'] : ""];
             $this->db->insert("geoplace", $data);
             $this->name = $woe['name'];
             $this->centre = new stdClass();
             $this->centre->lat = $woe['centroid']['latitude'];
             $this->centre->lon = $woe['centroid']['longitude'];
             $this->boundingBox = new stdClass();
             $this->boundingBox->northEast = new stdClass();
             $this->boundingBox->northEast->lat = $woe['boundingBox']['northEast']['latitude'];
             $this->boundingBox->northEast->lon = $woe['boundingBox']['northEast']['longitude'];
             $this->boundingBox->southWest = new stdClass();
             $this->boundingBox->southWest->lat = $woe['boundingBox']['southWest']['latitude'];
             $this->boundingBox->southWest->lon = $woe['boundingBox']['southWest']['longitude'];
         }
     }
     /**
      * Fetch the WOE (Where On Earth) data from Yahoo
      */
     Debug::LogEvent(__METHOD__, $timer);
 }
Beispiel #7
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.7.5
  * @param int $location_id
  */
 public function __construct($location_id = false)
 {
     parent::__construct();
     if ($id = filter_var($location_id, FILTER_VALIDATE_INT)) {
         $this->id = $id;
         $this->load();
     } elseif (is_string($location_id) && ($id = filter_var($location_id, FILTER_SANITIZE_STRING))) {
         $this->id = $this->db->fetchOne("SELECT id FROM location WHERE slug = ?", $id);
         if (filter_var($this->id, FILTER_VALIDATE_INT)) {
             $this->load();
         }
     }
 }
 public function test_locations()
 {
     $Locations = new Locations();
     $Locations->getCountries();
     $Locations->getRegions();
     $Locations->getLocations();
     $Locations->getPending();
     $Locations->getDateTypes();
     $Locations->getRandomLocation();
     $Locations->getOpenCorrections();
 }
Beispiel #9
0
 /**
  * Get locations adjacent to this place
  * @return array
  */
 public function getLocations()
 {
     $Locations = new Locations();
     return $Locations->nearby($this->lat, $this->lon, $this->radius);
 }
Beispiel #10
0
 /**
  * Constructor
  * @since Version 3.0.1
  * @version 3.7.5
  * @param object $db
  * @param int $location_id
  */
 public function __construct()
 {
     parent::__construct();
     foreach (func_get_args() as $arg) {
         if (filter_var($arg, FILTER_VALIDATE_INT)) {
             $this->id = $arg;
             $this->load();
         }
     }
 }