3 * StatusNet, the distributed open-source microblogging tool
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
37 * These are stored in the DB as part of notice and profile records,
38 * but since they're about the same in both, we have a separate class
43 * @author Evan Prodromou <evan@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
60 * Constructor that makes a Location from a string name
62 * @param string $name Human-readable name (any kind)
63 * @param string $language Language, default = common_language()
65 * @return Location Location with that name (or null if not found)
68 static function fromName($name, $language=null)
70 if (is_null($language)) {
71 $language = common_language();
76 // Let a third-party handle it
78 Event::handle('LocationFromName', array($name, $language, &$location));
84 * Constructor that makes a Location from an ID
86 * @param integer $id Identifier ID
87 * @param integer $ns Namespace of the identifier
88 * @param string $language Language to return name in (default is common)
90 * @return Location The location with this ID (or null if none)
93 static function fromId($id, $ns, $language=null)
95 if (is_null($language)) {
96 $language = common_language();
101 // Let a third-party handle it
103 Event::handle('LocationFromId', array($id, $ns, $language, &$location));
109 * Constructor that finds the nearest location to a lat/lon pair
111 * @param float $lat Latitude
112 * @param float $lon Longitude
113 * @param string $language Language for results, default = current
115 * @return Location the location found, or null if none found
118 static function fromLatLon($lat, $lon, $language=null)
120 if (is_null($language)) {
121 $language = common_language();
126 // Let a third-party handle it
128 if (Event::handle('LocationFromLatLon',
129 array($lat, $lon, $language, &$location))) {
130 // Default is just the lat/lon pair
132 $location = new Location();
134 $location->lat = $lat;
135 $location->lon = $lon;
142 * Get the name for this location in the given language
144 * @param string $language language to use, default = current
146 * @return string location name or null if not found
149 function getName($language=null)
151 if (is_null($language)) {
152 $language = common_language();
155 if (array_key_exists($language, $this->names)) {
156 return $this->names[$language];
159 Event::handle('LocationNameLanguage', array($this, $language, &$name));
161 $this->names[$language] = $name;
168 * Get an URL suitable for this location
170 * @return string URL for this location or NULL
177 if (is_string($this->_url)) {
183 Event::handle('LocationUrl', array($this, &$url));
191 * Get an URL for this location, suitable for embedding in RDF
193 * @return string URL for this location or NULL
200 if (is_string($this->_rdfurl)) {
201 return $this->_rdfurl;
206 Event::handle('LocationRdfUrl', array($this, &$url));
208 $this->_rdfurl = $url;