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
- $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,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));
}
/**

View File

@ -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);
}
}

View File

@ -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);
}
$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;
}
}

View File

@ -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',