]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/location.php
Added type-hint for constructor of NoticeTreeItem class
[quix0rs-gnu-social.git] / lib / location.php
index bbfc15a36d3929e817df561a05a59683593961b3..54e0d07acf61575fff990cf2d9f56c8123fabcc6 100644 (file)
@@ -52,9 +52,27 @@ class Location
     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
      *
@@ -185,4 +203,27 @@ class Location
 
         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;
+    }
 }