Exemplo n.º 1
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'];
         }
     }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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'];
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Get the regions in the locations database.
  * If $country is not specified, it will return all regions for all countries
  * @since Version 3.0
  * @param string $country An optional two letter country code we want to search for
  * @return array
  */
 public function getRegions($country = false)
 {
     $timer = Debug::GetTimer();
     $return = false;
     $mckey = $country ? "railpage:locations.regions.country=" . $country : "railpage:locations.regions";
     if ($return = $this->Memcached->fetch($mckey)) {
         return $return;
     }
     $return = array();
     if ($country) {
         foreach ($this->db->fetchAll("SELECT DISTINCT region FROM location WHERE country = ? AND active = 1 ORDER BY region ASC", $country) as $row) {
             $woe = Place::getWOEData($country);
             if (isset($woe['places']['place'][0])) {
                 $return[$country]['woe'] = $woe['places']['place'][0];
             }
             $datarow = array("region" => $row['region'], "url" => $this->makeRegionPermalink($country, $row['region']), "count" => $this->db->fetchOne("SELECT COUNT(id) FROM location WHERE country = ? AND region = ?", array($country, $row['region'])));
             $woe = Place::getWOEData($row['region'] . "," . $country);
             if (isset($woe['places']['place'][0])) {
                 $datarow['woe'] = $woe['places']['place'][0];
             }
             $return[$country]['children'][] = $datarow;
         }
         $this->Memcached->save($mckey, $return, strtotime("+1 day"));
         Debug::LogEvent(__METHOD__ . "(" . $country . ")", $timer);
         return $return;
     }
     $query = "SELECT DISTINCT l.region, l.country, g.country_name, g.region_name \n                FROM location AS l \n                LEFT JOIN geoplace AS g ON l.geoplace = g.id \n                WHERE l.active = 1 \n                GROUP BY l.country \n                ORDER BY l.region DESC";
     foreach ($this->db->fetchAll($query) as $row) {
         if (empty($row['country'])) {
             continue;
         }
         $return[$row['country']]['woe'] = array("country" => $row['country_name']);
         if (empty($return[$row['country']]['woe']['country'])) {
             $woe = Place::getWOEData(strtoupper($row['region']));
             $return[$row['country']]['woe'] = array("country" => $woe['places']['place'][0]['country']);
         }
         $return[$row['country']]['children'][] = $row['region'];
     }
     // Cache it
     $this->Memcached->save($mckey, $return, strtotime("+1 day"));
     Debug::LogEvent(__METHOD__ . "(" . $country . ")", $timer);
     return $return;
 }
Exemplo n.º 5
0
 /**
  * Get the WoE for this place
  * @since Version 3.9.1
  *
  * @param string $country
  * @param string $region
  *
  * @return array
  */
 private function fetchWoE($country, $region)
 {
     if ($region === false && !preg_match("@[a-zA-Z]+@", $country)) {
         // Assume a WOE ID
         $woe = Place::getWOEData($country);
     } else {
         $woe = Place::getWOEData($region . ", " . strtoupper($country));
     }
     if (isset($woe['places']['place'][0]['name'])) {
         $this->slug = $region;
         $this->Country = new Country($country);
         return $woe['places']['place'][0];
     }
     if (isset($woe['place'])) {
         $this->slug = $this->makeRegionSlug($woe['place']['name']);
         return $woe['place'];
     }
     return $woe;
 }