X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Flocation.php;h=54e0d07acf61575fff990cf2d9f56c8123fabcc6;hb=57163e6fd69d560b462a1b9eaee054126e029703;hp=048554f0f7042fa5dc8cdbb4558bf7686c6da48c;hpb=61ccf450de29a0433cd35415c6f2a3c7bbcbb91b;p=quix0rs-gnu-social.git diff --git a/lib/location.php b/lib/location.php index 048554f0f7..54e0d07acf 100644 --- a/lib/location.php +++ b/lib/location.php @@ -47,13 +47,32 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { class Location { - public $lat; - public $lon; - public $location_id; - public $location_ns; + public $lat; + public $lon; + public $location_id; + public $location_ns; + private $_url; + private $_rdfurl; var $names = array(); + /** + * Constructor that makes a Location from Notice::locationOptions(...) + * + * @param array $options an array for example provided by Notice::locationOptions(...) + * + * @return Location Location with the given options (lat, lon, id, name) + */ + static function fromOptions(array $options) { + $location = new Location(); + foreach (['lat', 'lon', 'location_id', 'location_ns'] as $opt) { + if (isset($options[$opt])) { + $location->$opt = $options[$opt]; + } + } + return $location; + } + /** * Constructor that makes a Location from a string name * @@ -90,6 +109,10 @@ class Location static function fromId($id, $ns, $language=null) { + if (is_null($language)) { + $language = common_language(); + } + $location = null; // Let a third-party handle it @@ -157,4 +180,50 @@ class Location } } } + + /** + * Get an URL suitable for this location + * + * @return string URL for this location or NULL + */ + + function getURL() + { + // Keep one cached + + if (is_string($this->_url)) { + return $this->_url; + } + + $url = null; + + Event::handle('LocationUrl', array($this, &$url)); + + $this->_url = $url; + + return $url; + } + + /** + * Get an URL for this location, suitable for embedding in RDF + * + * @return string URL for this location or NULL + */ + + function getRdfURL() + { + // Keep one cached + + if (is_string($this->_rdfurl)) { + return $this->_rdfurl; + } + + $url = null; + + Event::handle('LocationRdfUrl', array($this, &$url)); + + $this->_rdfurl = $url; + + return $url; + } }