summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--classes/Notice.php17
-rw-r--r--classes/Profile.php25
-rw-r--r--lib/location.php36
-rw-r--r--lib/noticelist.php39
-rw-r--r--plugins/GeonamesPlugin.php24
5 files changed, 137 insertions, 4 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index fdf5cd4c8..c08a66790 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -1412,4 +1412,21 @@ class Notice extends Memcached_DataObject
$contentlimit = self::maxContent();
return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit));
}
+
+ function getLocation()
+ {
+ $location = null;
+
+ if (!empty($this->location_id) && !empty($this->location_ns)) {
+ $location = Location::fromId($this->location_id, $this->location_ns);
+ }
+
+ if (is_null($location)) { // no ID, or Location::fromId() failed
+ if (!empty($this->lat) && !empty($this->lon)) {
+ $location = Location::fromLatLon($this->lat, $this->lon);
+ }
+ }
+
+ return $location;
+ }
}
diff --git a/classes/Profile.php b/classes/Profile.php
index 53d07fb2f..7c1e9db33 100644
--- a/classes/Profile.php
+++ b/classes/Profile.php
@@ -562,4 +562,29 @@ class Profile extends Memcached_DataObject
$block->blocked = $this->id;
$block->delete();
}
+
+ // XXX: identical to Notice::getLocation.
+
+ function getLocation()
+ {
+ $location = null;
+
+ if (!empty($this->location_id) && !empty($this->location_ns)) {
+ $location = Location::fromId($this->location_id, $this->location_ns);
+ }
+
+ if (is_null($location)) { // no ID, or Location::fromId() failed
+ if (!empty($this->lat) && !empty($this->lon)) {
+ $location = Location::fromLatLon($this->lat, $this->lon);
+ }
+ }
+
+ if (is_null($location)) { // still haven't found it!
+ if (!empty($this->location)) {
+ $location = Location::fromName($this->location);
+ }
+ }
+
+ return $location;
+ }
}
diff --git a/lib/location.php b/lib/location.php
index 048554f0f..bbfc15a36 100644
--- a/lib/location.php
+++ b/lib/location.php
@@ -47,10 +47,11 @@ 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;
var $names = array();
@@ -90,6 +91,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 +162,27 @@ 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;
+ }
}
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 6c296f82a..8b3015cc3 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -199,6 +199,7 @@ class NoticeListItem extends Widget
{
$this->out->elementStart('div', 'entry-content');
$this->showNoticeLink();
+ $this->showNoticeLocation();
$this->showNoticeSource();
$this->showContext();
$this->out->elementEnd('div');
@@ -370,6 +371,44 @@ class NoticeListItem extends Widget
}
/**
+ * show the notice location
+ *
+ * shows the notice location in the correct language.
+ *
+ * If an URL is available, makes a link. Otherwise, just a span.
+ *
+ * @return void
+ */
+
+ function showNoticeLocation()
+ {
+ $id = $this->notice->id;
+
+ $location = $this->notice->getLocation();
+
+ if (empty($location)) {
+ return;
+ }
+
+ $name = $location->getName();
+
+ if (empty($name)) {
+ // XXX: Could be a translation issue. Fall back to... something?
+ return;
+ }
+
+ $url = $location->getUrl();
+
+ if (empty($url)) {
+ $this->out->element('span', array('class' => 'location'), $name);
+ } else {
+ $this->out->element('a', array('class' => 'location',
+ 'href' => $url),
+ $name);
+ }
+ }
+
+ /**
* Show the source of the notice
*
* Either the name (and link) of the API client that posted the notice,
diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php
index 745cd4126..80ef44cc9 100644
--- a/plugins/GeonamesPlugin.php
+++ b/plugins/GeonamesPlugin.php
@@ -278,4 +278,28 @@ class GeonamesPlugin extends Plugin
return true;
}
+
+ /**
+ * Human-readable name for a location
+ *
+ * Given a location, we try to retrieve a geonames.org URL.
+ *
+ * @param Location $location Location to get the url for
+ * @param string &$url Place to put the url
+ *
+ * @return boolean whether to continue
+ */
+
+ function onLocationUrl($location, &$url)
+ {
+ if ($location->location_ns != self::NAMESPACE) {
+ // It's not one of our IDs... keep processing
+ return true;
+ }
+
+ $url = 'http://www.geonames.org/' . $location->location_id;
+
+ // it's been filled, so don't process further.
+ return false;
+ }
}