summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--EVENTS.txt21
-rw-r--r--lib/htmloutputter.php42
-rw-r--r--lib/plugin.php10
-rw-r--r--plugins/GeonamesPlugin.php80
-rw-r--r--plugins/Realtime/RealtimePlugin.php9
5 files changed, 104 insertions, 58 deletions
diff --git a/EVENTS.txt b/EVENTS.txt
index 34a222e8f..f4ec62033 100644
--- a/EVENTS.txt
+++ b/EVENTS.txt
@@ -574,3 +574,24 @@ EndShortenUrl: After a URL has been shortened
- $shortenerName: name of the requested shortener
- $shortenedUrl: short version of the url
+StartCssLinkElement: Before a <link rel="stylesheet"..> element is written
+- $action
+- &$src
+- &$theme
+- &$media
+
+EndCssLinkElement: After a <link rel="stylesheet"..> element is written
+- $action
+- $src
+- $theme
+- $media
+
+StartScriptElement: Before a <script...> element is written
+- $action
+- &$src
+- &$type
+
+EndScriptElement: After a <script...> element is written
+- $action
+- $src
+- $type
diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php
index 3fabc4037..a0066594f 100644
--- a/lib/htmloutputter.php
+++ b/lib/htmloutputter.php
@@ -350,14 +350,17 @@ class HTMLOutputter extends XMLOutputter
*/
function script($src, $type='text/javascript')
{
- $url = parse_url($src);
- if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
- {
- $src = common_path($src) . '?version=' . STATUSNET_VERSION;
+ if(Event::handle('StartScriptElement', array($this,&$src,&$type))) {
+ $url = parse_url($src);
+ if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
+ {
+ $src = common_path($src) . '?version=' . STATUSNET_VERSION;
+ }
+ $this->element('script', array('type' => $type,
+ 'src' => $src),
+ ' ');
+ Event::handle('EndScriptElement', array($this,$src,$type));
}
- $this->element('script', array('type' => $type,
- 'src' => $src),
- ' ');
}
/**
@@ -390,19 +393,22 @@ class HTMLOutputter extends XMLOutputter
*/
function cssLink($src,$theme=null,$media=null)
{
- $url = parse_url($src);
- if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
- {
- if(file_exists(Theme::file($src,$theme))){
- $src = Theme::path($src, $theme) . '?version=' . STATUSNET_VERSION;
- }else{
- $src = common_path($src);
+ if(Event::handle('StartCssLinkElement', array($this,&$src,&$theme,&$media))) {
+ $url = parse_url($src);
+ if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
+ {
+ if(file_exists(Theme::file($src,$theme))){
+ $src = Theme::path($src, $theme) . '?version=' . STATUSNET_VERSION;
+ }else{
+ $src = common_path($src);
+ }
}
+ $this->element('link', array('rel' => 'stylesheet',
+ 'type' => 'text/css',
+ 'href' => $src,
+ 'media' => $media));
+ Event::handle('EndCssLinkElement', array($this,$src,$theme,$media));
}
- $this->element('link', array('rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => $src,
- 'media' => $media));
}
/**
diff --git a/lib/plugin.php b/lib/plugin.php
index 87d7be5a7..2c77c3e12 100644
--- a/lib/plugin.php
+++ b/lib/plugin.php
@@ -76,4 +76,14 @@ class Plugin
{
return true;
}
+
+ protected function log($level, $msg)
+ {
+ common_log($level, get_class($this) . ': '.$msg);
+ }
+
+ protected function debug($msg)
+ {
+ $this->log(LOG_DEBUG, $msg);
+ }
}
diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php
index 340a6f0bf..a750f1242 100644
--- a/plugins/GeonamesPlugin.php
+++ b/plugins/GeonamesPlugin.php
@@ -51,6 +51,11 @@ class GeonamesPlugin extends Plugin
{
const LOCATION_NS = 1;
+ public $host = 'ws.geonames.org';
+ public $username = null;
+ public $token = null;
+ public $expiry = 7776000; // 90-day expiry
+
/**
* convert a name into a Location object
*
@@ -75,12 +80,11 @@ class GeonamesPlugin extends Plugin
// XXX: break down a name by commas, narrow by each
- $str = http_build_query(array('maxRows' => 1,
- 'q' => $name,
- 'lang' => $language,
- 'type' => 'json'));
-
- $result = $client->get('http://ws.geonames.org/search?'.$str);
+ $result = $client->get($this->wsUrl('search',
+ array('maxRows' => 1,
+ 'q' => $name,
+ 'lang' => $language,
+ 'type' => 'json')));
if ($result->isOk()) {
$rj = json_decode($result->getBody());
@@ -135,10 +139,9 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start();
- $str = http_build_query(array('geonameId' => $id,
- 'lang' => $language));
-
- $result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str);
+ $result = $client->get($this->wsUrl('hierarchyJSON',
+ array('geonameId' => $id,
+ 'lang' => $language)));
if ($result->isOk()) {
@@ -195,6 +198,9 @@ class GeonamesPlugin extends Plugin
function onLocationFromLatLon($lat, $lon, $language, &$location)
{
+ $lat = rtrim($lat, "0");
+ $lon = rtrim($lon, "0");
+
$loc = $this->getCache(array('lat' => $lat,
'lon' => $lon));
@@ -205,12 +211,11 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start();
- $str = http_build_query(array('lat' => $lat,
- 'lng' => $lon,
- 'lang' => $language));
-
$result =
- $client->get('http://ws.geonames.org/findNearbyPlaceNameJSON?'.$str);
+ $client->get($this->wsUrl('findNearbyPlaceNameJSON',
+ array('lat' => $lat,
+ 'lng' => $lon,
+ 'lang' => $language)));
if ($result->isOk()) {
@@ -286,10 +291,9 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start();
- $str = http_build_query(array('geonameId' => $location->location_id,
- 'lang' => $language));
-
- $result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str);
+ $result = $client->get($this->wsUrl('hierarchyJSON',
+ array('geonameId' => $location->location_id,
+ 'lang' => $language)));
if ($result->isOk()) {
@@ -376,33 +380,30 @@ class GeonamesPlugin extends Plugin
{
$c = common_memcache();
- if (!$c) {
+ if (empty($c)) {
return null;
}
- return $c->get($this->cacheKey($attrs));
+ $key = $this->cacheKey($attrs);
+
+ $value = $c->get($key);
+
+ return $value;
}
function setCache($attrs, $loc)
{
$c = common_memcache();
- if (!$c) {
+ if (empty($c)) {
return null;
}
- $c->set($this->cacheKey($attrs), $loc);
- }
-
- function clearCache($attrs)
- {
- $c = common_memcache();
+ $key = $this->cacheKey($attrs);
- if (!$c) {
- return null;
- }
+ $result = $c->set($key, $loc, 0, time() + $this->expiry);
- $c->delete($this->cacheKey($attrs));
+ return $result;
}
function cacheKey($attrs)
@@ -411,4 +412,19 @@ class GeonamesPlugin extends Plugin
implode(',', array_keys($attrs)) . ':'.
common_keyize(implode(',', array_values($attrs))));
}
+
+ function wsUrl($method, $params)
+ {
+ if (!empty($this->username)) {
+ $params['username'] = $this->username;
+ }
+
+ if (!empty($this->token)) {
+ $params['token'] = $this->token;
+ }
+
+ $str = http_build_query($params);
+
+ return 'http://'.$this->host.'/'.$method.'?'.$str;
+ }
}
diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php
index cbfa6bae0..030df405b 100644
--- a/plugins/Realtime/RealtimePlugin.php
+++ b/plugins/Realtime/RealtimePlugin.php
@@ -120,7 +120,7 @@ class RealtimePlugin extends Plugin
function onEndShowStatusNetStyles($action)
{
- $action->cssLink(common_path('plugins/Realtime/realtimeupdate.css'),
+ $action->cssLink(common_path('plugins/Realtime/realtimeupdate.css'),
null, 'screen, projection, tv');
return true;
}
@@ -293,13 +293,6 @@ class RealtimePlugin extends Plugin
return $tags;
}
- // Push this up to Plugin
-
- function log($level, $msg)
- {
- common_log($level, get_class($this) . ': '.$msg);
- }
-
function _getScripts()
{
return array('plugins/Realtime/realtimeupdate.js',