forked from GNUsocial/gnu-social
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
This commit is contained in:
commit
1fd7e5e379
21
EVENTS.txt
21
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
|
||||
|
@ -350,6 +350,7 @@ class HTMLOutputter extends XMLOutputter
|
||||
*/
|
||||
function script($src, $type='text/javascript')
|
||||
{
|
||||
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))
|
||||
{
|
||||
@ -358,6 +359,8 @@ class HTMLOutputter extends XMLOutputter
|
||||
$this->element('script', array('type' => $type,
|
||||
'src' => $src),
|
||||
' ');
|
||||
Event::handle('EndScriptElement', array($this,$src,$type));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -390,6 +393,7 @@ class HTMLOutputter extends XMLOutputter
|
||||
*/
|
||||
function cssLink($src,$theme=null,$media=null)
|
||||
{
|
||||
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))
|
||||
{
|
||||
@ -403,6 +407,8 @@ class HTMLOutputter extends XMLOutputter
|
||||
'type' => 'text/css',
|
||||
'href' => $src,
|
||||
'media' => $media));
|
||||
Event::handle('EndCssLinkElement', array($this,$src,$theme,$media));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
$result = $client->get($this->wsUrl('search',
|
||||
array('maxRows' => 1,
|
||||
'q' => $name,
|
||||
'lang' => $language,
|
||||
'type' => 'json'));
|
||||
|
||||
$result = $client->get('http://ws.geonames.org/search?'.$str);
|
||||
'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);
|
||||
}
|
||||
$key = $this->cacheKey($attrs);
|
||||
|
||||
function clearCache($attrs)
|
||||
{
|
||||
$c = common_memcache();
|
||||
$result = $c->set($key, $loc, 0, time() + $this->expiry);
|
||||
|
||||
if (!$c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user