summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-11-24 18:47:56 +0000
committerZach Copley <zach@status.net>2009-11-24 18:47:56 +0000
commit2eae258319d5621065f9491ba4d81814c0f2b1fd (patch)
tree71305b1bee0e9b557f078f0c11ecbad3b9ee2059 /plugins
parent4bace8f1a5df797aead91ce802d4538e1dfed9ec (diff)
parent2da531d7d65044f3093eafd72b73a08e1cf67fd5 (diff)
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'plugins')
-rw-r--r--plugins/GeonamesPlugin.php87
-rw-r--r--plugins/Mapstraction/MapstractionPlugin.php4
-rw-r--r--plugins/Mapstraction/usermap.js21
-rw-r--r--plugins/Realtime/RealtimePlugin.php9
-rw-r--r--plugins/Realtime/realtimeupdate.css29
-rw-r--r--plugins/Realtime/realtimeupdate.js20
6 files changed, 133 insertions, 37 deletions
diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php
index 59232c1c5..340a6f0bf 100644
--- a/plugins/GeonamesPlugin.php
+++ b/plugins/GeonamesPlugin.php
@@ -63,6 +63,14 @@ class GeonamesPlugin extends Plugin
function onLocationFromName($name, $language, &$location)
{
+ $loc = $this->getCache(array('name' => $name,
+ 'language' => $language));
+
+ if (!empty($loc)) {
+ $location = $loc;
+ return false;
+ }
+
$client = HTTPClient::start();
// XXX: break down a name by commas, narrow by each
@@ -87,6 +95,10 @@ class GeonamesPlugin extends Plugin
$location->location_id = $n->geonameId;
$location->location_ns = self::LOCATION_NS;
+ $this->setCache(array('name' => $name,
+ 'language' => $language),
+ $location);
+
// handled, don't continue processing!
return false;
}
@@ -114,6 +126,13 @@ class GeonamesPlugin extends Plugin
return true;
}
+ $loc = $this->getCache(array('id' => $id));
+
+ if (!empty($loc)) {
+ $location = $loc;
+ return false;
+ }
+
$client = HTTPClient::start();
$str = http_build_query(array('geonameId' => $id,
@@ -148,6 +167,9 @@ class GeonamesPlugin extends Plugin
$location->lat = $last->lat;
$location->lon = $last->lng;
$location->names[$language] = implode(', ', array_reverse($parts));
+
+ $this->setCache(array('id' => $last->geonameId),
+ $location);
}
}
@@ -173,6 +195,14 @@ class GeonamesPlugin extends Plugin
function onLocationFromLatLon($lat, $lon, $language, &$location)
{
+ $loc = $this->getCache(array('lat' => $lat,
+ 'lon' => $lon));
+
+ if (!empty($loc)) {
+ $location = $loc;
+ return false;
+ }
+
$client = HTTPClient::start();
$str = http_build_query(array('lat' => $lat,
@@ -211,6 +241,10 @@ class GeonamesPlugin extends Plugin
$location->names[$language] = implode(', ', $parts);
+ $this->setCache(array('lat' => $lat,
+ 'lon' => $lon),
+ $location);
+
// Success! We handled it, so no further processing
return false;
@@ -242,9 +276,17 @@ class GeonamesPlugin extends Plugin
return true;
}
+ $n = $this->getCache(array('id' => $location->location_id,
+ 'language' => $language));
+
+ if (!empty($n)) {
+ $name = $n;
+ return false;
+ }
+
$client = HTTPClient::start();
- $str = http_build_query(array('geonameId' => $id,
+ $str = http_build_query(array('geonameId' => $location->location_id,
'lang' => $language));
$result = $client->get('http://ws.geonames.org/hierarchyJSON?'.$str);
@@ -271,6 +313,9 @@ class GeonamesPlugin extends Plugin
if (count($parts)) {
$name = implode(', ', array_reverse($parts));
+ $this->setCache(array('id' => $location->location_id,
+ 'language' => $language),
+ $name);
return false;
}
}
@@ -326,4 +371,44 @@ class GeonamesPlugin extends Plugin
// it's been filled, so don't process further.
return false;
}
+
+ function getCache($attrs)
+ {
+ $c = common_memcache();
+
+ if (!$c) {
+ return null;
+ }
+
+ return $c->get($this->cacheKey($attrs));
+ }
+
+ function setCache($attrs, $loc)
+ {
+ $c = common_memcache();
+
+ if (!$c) {
+ return null;
+ }
+
+ $c->set($this->cacheKey($attrs), $loc);
+ }
+
+ function clearCache($attrs)
+ {
+ $c = common_memcache();
+
+ if (!$c) {
+ return null;
+ }
+
+ $c->delete($this->cacheKey($attrs));
+ }
+
+ function cacheKey($attrs)
+ {
+ return common_cache_key('geonames:'.
+ implode(',', array_keys($attrs)) . ':'.
+ common_keyize(implode(',', array_values($attrs))));
+ }
}
diff --git a/plugins/Mapstraction/MapstractionPlugin.php b/plugins/Mapstraction/MapstractionPlugin.php
index a0dbf5204..37306a23c 100644
--- a/plugins/Mapstraction/MapstractionPlugin.php
+++ b/plugins/Mapstraction/MapstractionPlugin.php
@@ -58,12 +58,12 @@ class MapstractionPlugin extends Plugin
*
* The way to register new actions from a plugin.
*
- * @param Router &$m reference to router
+ * @param Router $m reference to router
*
* @return boolean event handler return
*/
- function onRouterInitialized(&$m)
+ function onRouterInitialized($m)
{
$m->connect(':nickname/all/map',
array('action' => 'allmap'),
diff --git a/plugins/Mapstraction/usermap.js b/plugins/Mapstraction/usermap.js
index 7fb73fa88..e667dd579 100644
--- a/plugins/Mapstraction/usermap.js
+++ b/plugins/Mapstraction/usermap.js
@@ -1,17 +1,17 @@
$(document).ready(function() {
- notices = [];
+ var notices = [];
$(".notice").each(function(){
- notice = getNoticeFromElement($(this));
+ var notice = getNoticeFromElement($(this));
if(notice['geo'])
notices.push(notice);
});
- if($("#map_canvas") && notices.length>0)
+ if($("#map_canvas").length && notices.length>0)
{
showMapstraction($("#map_canvas"), notices);
}
- $('a.geo').click(function(){
- noticeElement = $(this).closest(".notice");
+ $('.geo').click(function(){
+ var noticeElement = $(this).closest(".notice");
notice = getNoticeFromElement(noticeElement);
$.fn.jOverlay.options = {
@@ -23,7 +23,7 @@ $(document).ready(function() {
autoHide : true,
css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
};
- html="<div id='map_canvas_popup' class='gray smallmap' style='width: 542px; height: 500px' />";
+ var html="<div id='map_canvas_popup' class='gray smallmap' style='width: 542px; height: 500px' />";
html+="<button class='close'>&#215;</button>";
html+=$("<div/>").append($(this).clone()).html();
$().jOverlay({ "html": html });
@@ -47,11 +47,12 @@ function getMicroformatValue(element)
function getNoticeFromElement(noticeElement)
{
- notice = {};
- if(noticeElement.find(".latitude").length){
+ var notice = {};
+ if(noticeElement.find(".geo").length){
+ var latlon = noticeElement.find(".geo").attr('title').split(";");
notice['geo']={'coordinates': [
- parseFloat(getMicroformatValue(noticeElement.find(".latitude"))),
- parseFloat(getMicroformatValue(noticeElement.find(".longitude")))] };
+ parseFloat(latlon[0]),
+ parseFloat(latlon[1])] };
}
notice['user']={
'profile_image_url': noticeElement.find("img.avatar").attr('src'),
diff --git a/plugins/Realtime/RealtimePlugin.php b/plugins/Realtime/RealtimePlugin.php
index c5fb6de03..cbfa6bae0 100644
--- a/plugins/Realtime/RealtimePlugin.php
+++ b/plugins/Realtime/RealtimePlugin.php
@@ -139,8 +139,8 @@ class RealtimePlugin extends Plugin
// Add to the public timeline
- if ($notice->is_local ||
- ($notice->is_local == 0 && !common_config('public', 'localonly'))) {
+ if ($notice->is_local == Notice::LOCAL_PUBLIC ||
+ ($notice->is_local == Notice::REMOTE_OMB && !common_config('public', 'localonly'))) {
$paths[] = array('public');
}
@@ -220,8 +220,9 @@ class RealtimePlugin extends Plugin
$action->elementStart('body',
(common_current_user()) ? array('id' => $action->trimmed('action'),
- 'class' => 'user_in')
- : array('id' => $action->trimmed('action')));
+ 'class' => 'user_in realtime-popup')
+ : array('id' => $action->trimmed('action'),
+ 'class'=> 'realtime-popup'));
// XXX hack to deal with JS that tries to get the
// root url from page output
diff --git a/plugins/Realtime/realtimeupdate.css b/plugins/Realtime/realtimeupdate.css
index 0ab5dd32b..a5728b83d 100644
--- a/plugins/Realtime/realtimeupdate.css
+++ b/plugins/Realtime/realtimeupdate.css
@@ -1,3 +1,32 @@
+.realtime-popup address {
+display:none;
+}
+
+.realtime-popup #content {
+width:93.5%;
+}
+
+.realtime-popup #form_notice {
+margin:18px 0 18px 1.795%;
+width:93%;
+max-width:451px;
+}
+
+.realtime-popup #form_notice label[for=notice_data-text],
+.realtime-popup h1 {
+display:none;
+}
+
+.realtime-popup #form_notice label[for=notice_data-attach],
+.realtime-popup #form_notice #notice_data-attach {
+top:0;
+}
+
+.realtime-popup #form_notice #notice_data-attach {
+left:auto;
+right:0;
+}
+
#notices_primary {
position:relative;
}
diff --git a/plugins/Realtime/realtimeupdate.js b/plugins/Realtime/realtimeupdate.js
index a2c4da113..b3c41456e 100644
--- a/plugins/Realtime/realtimeupdate.js
+++ b/plugins/Realtime/realtimeupdate.js
@@ -276,26 +276,6 @@ RealtimeUpdate = {
initPopupWindow: function()
{
- $('address').hide();
- $('#content').css({'width':'93.5%'});
-
- $('#form_notice').css({
- 'margin':'18px 0 18px 1.795%',
- 'width':'93%',
- 'max-width':'451px'
- });
-
- $('#form_notice label[for=notice_data-text], h1').css({'display': 'none'});
-
- $('.notices li:first-child').css({'border-top-color':'transparent'});
-
- $('#form_notice label[for="notice_data-attach"], #form_notice #notice_data-attach').css({'top':'0'});
-
- $('#form_notice #notice_data-attach').css({
- 'left':'auto',
- 'right':'0'
- });
-
$('.notices .entry-title a, .notices .entry-content a').bind('click', function() {
window.open(this.href, '');