Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x

This commit is contained in:
Zach Copley 2009-12-04 22:43:34 +00:00
commit 1fd7e5e379
5 changed files with 104 additions and 58 deletions

View File

@ -574,3 +574,24 @@ EndShortenUrl: After a URL has been shortened
- $shortenerName: name of the requested shortener - $shortenerName: name of the requested shortener
- $shortenedUrl: short version of the url - $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

View File

@ -350,6 +350,7 @@ class HTMLOutputter extends XMLOutputter
*/ */
function script($src, $type='text/javascript') function script($src, $type='text/javascript')
{ {
if(Event::handle('StartScriptElement', array($this,&$src,&$type))) {
$url = parse_url($src); $url = parse_url($src);
if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment)) 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, $this->element('script', array('type' => $type,
'src' => $src), 'src' => $src),
' '); ' ');
Event::handle('EndScriptElement', array($this,$src,$type));
}
} }
/** /**
@ -390,6 +393,7 @@ class HTMLOutputter extends XMLOutputter
*/ */
function cssLink($src,$theme=null,$media=null) function cssLink($src,$theme=null,$media=null)
{ {
if(Event::handle('StartCssLinkElement', array($this,&$src,&$theme,&$media))) {
$url = parse_url($src); $url = parse_url($src);
if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment)) if( empty($url->scheme) && empty($url->host) && empty($url->query) && empty($url->fragment))
{ {
@ -403,6 +407,8 @@ class HTMLOutputter extends XMLOutputter
'type' => 'text/css', 'type' => 'text/css',
'href' => $src, 'href' => $src,
'media' => $media)); 'media' => $media));
Event::handle('EndCssLinkElement', array($this,$src,$theme,$media));
}
} }
/** /**

View File

@ -76,4 +76,14 @@ class Plugin
{ {
return true; return true;
} }
protected function log($level, $msg)
{
common_log($level, get_class($this) . ': '.$msg);
}
protected function debug($msg)
{
$this->log(LOG_DEBUG, $msg);
}
} }

View File

@ -51,6 +51,11 @@ class GeonamesPlugin extends Plugin
{ {
const LOCATION_NS = 1; 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 * 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 // 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, 'q' => $name,
'lang' => $language, 'lang' => $language,
'type' => 'json')); 'type' => 'json')));
$result = $client->get('http://ws.geonames.org/search?'.$str);
if ($result->isOk()) { if ($result->isOk()) {
$rj = json_decode($result->getBody()); $rj = json_decode($result->getBody());
@ -135,10 +139,9 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start(); $client = HTTPClient::start();
$str = http_build_query(array('geonameId' => $id, $result = $client->get($this->wsUrl('hierarchyJSON',
'lang' => $language)); array('geonameId' => $id,
'lang' => $language)));
$result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str);
if ($result->isOk()) { if ($result->isOk()) {
@ -195,6 +198,9 @@ class GeonamesPlugin extends Plugin
function onLocationFromLatLon($lat, $lon, $language, &$location) function onLocationFromLatLon($lat, $lon, $language, &$location)
{ {
$lat = rtrim($lat, "0");
$lon = rtrim($lon, "0");
$loc = $this->getCache(array('lat' => $lat, $loc = $this->getCache(array('lat' => $lat,
'lon' => $lon)); 'lon' => $lon));
@ -205,12 +211,11 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start(); $client = HTTPClient::start();
$str = http_build_query(array('lat' => $lat,
'lng' => $lon,
'lang' => $language));
$result = $result =
$client->get('http://ws.geonames.org/findNearbyPlaceNameJSON?'.$str); $client->get($this->wsUrl('findNearbyPlaceNameJSON',
array('lat' => $lat,
'lng' => $lon,
'lang' => $language)));
if ($result->isOk()) { if ($result->isOk()) {
@ -286,10 +291,9 @@ class GeonamesPlugin extends Plugin
$client = HTTPClient::start(); $client = HTTPClient::start();
$str = http_build_query(array('geonameId' => $location->location_id, $result = $client->get($this->wsUrl('hierarchyJSON',
'lang' => $language)); array('geonameId' => $location->location_id,
'lang' => $language)));
$result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str);
if ($result->isOk()) { if ($result->isOk()) {
@ -376,33 +380,30 @@ class GeonamesPlugin extends Plugin
{ {
$c = common_memcache(); $c = common_memcache();
if (!$c) { if (empty($c)) {
return null; return null;
} }
return $c->get($this->cacheKey($attrs)); $key = $this->cacheKey($attrs);
$value = $c->get($key);
return $value;
} }
function setCache($attrs, $loc) function setCache($attrs, $loc)
{ {
$c = common_memcache(); $c = common_memcache();
if (!$c) { if (empty($c)) {
return null; return null;
} }
$c->set($this->cacheKey($attrs), $loc); $key = $this->cacheKey($attrs);
}
function clearCache($attrs) $result = $c->set($key, $loc, 0, time() + $this->expiry);
{
$c = common_memcache();
if (!$c) { return $result;
return null;
}
$c->delete($this->cacheKey($attrs));
} }
function cacheKey($attrs) function cacheKey($attrs)
@ -411,4 +412,19 @@ class GeonamesPlugin extends Plugin
implode(',', array_keys($attrs)) . ':'. implode(',', array_keys($attrs)) . ':'.
common_keyize(implode(',', array_values($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;
}
} }

View File

@ -293,13 +293,6 @@ class RealtimePlugin extends Plugin
return $tags; return $tags;
} }
// Push this up to Plugin
function log($level, $msg)
{
common_log($level, get_class($this) . ': '.$msg);
}
function _getScripts() function _getScripts()
{ {
return array('plugins/Realtime/realtimeupdate.js', return array('plugins/Realtime/realtimeupdate.js',