summaryrefslogtreecommitdiff
path: root/plugins/Mapstraction
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Mapstraction')
-rw-r--r--plugins/Mapstraction/MapstractionPlugin.php82
-rw-r--r--plugins/Mapstraction/allmap.php72
-rw-r--r--plugins/Mapstraction/locale/Mapstraction.po48
-rw-r--r--plugins/Mapstraction/map.php167
-rw-r--r--plugins/Mapstraction/usermap.js87
-rw-r--r--plugins/Mapstraction/usermap.php70
6 files changed, 298 insertions, 228 deletions
diff --git a/plugins/Mapstraction/MapstractionPlugin.php b/plugins/Mapstraction/MapstractionPlugin.php
index c0c2c5b8e..93679e56c 100644
--- a/plugins/Mapstraction/MapstractionPlugin.php
+++ b/plugins/Mapstraction/MapstractionPlugin.php
@@ -90,6 +90,7 @@ class MapstractionPlugin extends Plugin
{
case 'AllmapAction':
case 'UsermapAction':
+ case 'MapAction':
include_once INSTALLDIR.'/plugins/Mapstraction/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
default:
@@ -110,9 +111,9 @@ class MapstractionPlugin extends Plugin
function onEndShowScripts($action)
{
$actionName = $action->trimmed('action');
- // These are the ones that have maps on 'em
+
if (!in_array($actionName,
- array('showstream', 'all', 'allmap', 'usermap'))) {
+ array('showstream', 'all', 'usermap', 'allmap'))) {
return true;
}
@@ -147,43 +148,20 @@ class MapstractionPlugin extends Plugin
$action->script(common_path('plugins/Mapstraction/usermap.js'));
- $action->elementStart('script', array('type' => 'text/javascript'));
- $action->raw(sprintf('var _provider = "%s";', $this->provider));
- $action->elementEnd('script');
+ $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
- switch ($actionName) {
- case 'usermap':
- case 'showstream':
- $notice = empty($action->tag)
- ? $action->user->getNotices(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
- : $action->user->getTaggedNotices($action->tag, ($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
- break;
- case 'all':
- case 'allmap':
- $cur = common_current_user();
- if (!empty($cur) && $cur->id == $action->user->id) {
- $notice = $action->user->noticeInbox(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- } else {
- $notice = $action->user->noticesWithFriends(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
- }
- break;
- }
-
- $jsonArray = array();
+ // usermap and allmap handle this themselves
- while ($notice->fetch()) {
- if (!empty($notice->lat) && !empty($notice->lon)) {
- $jsonNotice = $this->noticeAsJson($notice);
- $jsonArray[] = $jsonNotice;
- }
+ if (in_array($actionName,
+ array('showstream', 'all'))) {
+ $action->inlineScript('$(document).ready(function() { '.
+ ' var user = null; '.
+ (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
+ ' var notices = scrapeNotices(user); ' .
+ ' showMapstraction($("#map_canvas"), notices); '.
+ '});');
}
- $action->elementStart('script', array('type' => 'text/javascript'));
- $action->raw('/*<![CDATA[*/'); // XHTML compat for Safari
- $action->raw('var _notices = ' . json_encode($jsonArray));
- $action->raw('/*]]>*/'); // XHTML compat for Safari
- $action->elementEnd('script');
-
return true;
}
@@ -199,7 +177,7 @@ class MapstractionPlugin extends Plugin
$action->elementStart('div', array('id' => 'entity_map',
'class' => 'section'));
- $action->element('h2', null, _('Map'));
+ $action->element('h2', null, _m('Map'));
$action->element('div', array('id' => 'map_canvas',
'class' => 'gray smallmap',
@@ -210,38 +188,8 @@ class MapstractionPlugin extends Plugin
array('nickname' => $action->trimmed('nickname')));
$action->element('a', array('href' => $mapUrl),
- _("Full size"));
+ _m("Full size"));
$action->elementEnd('div');
}
-
- function noticeAsJson($notice)
- {
- // FIXME: this code should be abstracted to a neutral third
- // party, like Notice::asJson(). I'm not sure of the ethics
- // of refactoring from within a plugin, so I'm just abusing
- // the ApiAction method. Don't do this unless you're me!
-
- require_once(INSTALLDIR.'/lib/api.php');
-
- $act = new ApiAction('/dev/null');
-
- $arr = $act->twitterStatusArray($notice, true);
- $arr['url'] = $notice->bestUrl();
- $arr['html'] = $notice->rendered;
- $arr['source'] = $arr['source'];
-
- if (!empty($notice->reply_to)) {
- $reply_to = Notice::staticGet('id', $notice->reply_to);
- if (!empty($reply_to)) {
- $arr['in_reply_to_status_url'] = $reply_to->bestUrl();
- }
- $reply_to = null;
- }
-
- $profile = $notice->getProfile();
- $arr['user']['profile_url'] = $profile->profileurl;
-
- return $arr;
- }
}
diff --git a/plugins/Mapstraction/allmap.php b/plugins/Mapstraction/allmap.php
index 6a48b141f..e73aa76e8 100644
--- a/plugins/Mapstraction/allmap.php
+++ b/plugins/Mapstraction/allmap.php
@@ -37,59 +37,26 @@ if (!defined('STATUSNET')) {
* @category Mapstraction
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
+ * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-class AllmapAction extends OwnerDesignAction
+class AllmapAction extends MapAction
{
- var $profile = null;
- var $page = null;
- var $notices = null;
-
- public $plugin = null;
-
function prepare($args)
{
- parent::prepare($args);
-
- $nickname_arg = $this->arg('nickname');
- $nickname = common_canonical_nickname($nickname_arg);
-
- // Permanent redirect on non-canonical nickname
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- if ($this->arg('page') && $this->arg('page') != 1) {
- $args['page'] = $this->arg['page'];
+ if(parent::prepare($args)) {
+ $cur = common_current_user();
+ if (!empty($cur) && $cur->id == $this->user->id) {
+ $this->notice = $this->user->noticeInbox(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
+ } else {
+ $this->notice = $this->user->noticesWithFriends(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
}
- common_redirect(common_local_url($this->trimmed('action'), $args), 301);
- return false;
- }
-
- $this->user = User::staticGet('nickname', $nickname);
-
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
- }
-
- $this->profile = $this->user->getProfile();
-
- if (!$this->profile) {
- $this->serverError(_('User has no profile.'));
+ return true;
+ }else{
return false;
}
-
- $page = $this->trimmed('page');
-
- if (!empty($page) && Validate::number($page)) {
- $this->page = $page+0;
- } else {
- $this->page = 1;
- }
-
- return true;
}
function title()
@@ -101,25 +68,12 @@ class AllmapAction extends OwnerDesignAction
}
if ($this->page == 1) {
- return sprintf(_("%s friends map"),
+ return sprintf(_m("%s friends map"),
$base);
} else {
- return sprintf(_("%s friends map, page %d"),
+ return sprintf(_m("%s friends map, page %d"),
$base,
$this->page);
}
}
-
- function handle($args)
- {
- parent::handle($args);
- $this->showPage();
- }
-
- function showContent()
- {
- $this->element('div', array('id' => 'map_canvas',
- 'class' => 'gray smallmap',
- 'style' => "width: 100%; height: 400px"));
- }
-} \ No newline at end of file
+}
diff --git a/plugins/Mapstraction/locale/Mapstraction.po b/plugins/Mapstraction/locale/Mapstraction.po
new file mode 100644
index 000000000..c1c50bf50
--- /dev/null
+++ b/plugins/Mapstraction/locale/Mapstraction.po
@@ -0,0 +1,48 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2009-12-07 20:38-0800\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: allmap.php:71
+#, php-format
+msgid "%s friends map"
+msgstr ""
+
+#: allmap.php:74
+#, php-format
+msgid "%s friends map, page %d"
+msgstr ""
+
+#: map.php:72
+msgid "No such user."
+msgstr ""
+
+#: map.php:79
+msgid "User has no profile."
+msgstr ""
+
+#: usermap.php:71
+#, php-format
+msgid "%s map, page %d"
+msgstr ""
+
+#: MapstractionPlugin.php:180
+msgid "Map"
+msgstr ""
+
+#: MapstractionPlugin.php:191
+msgid "Full size"
+msgstr ""
diff --git a/plugins/Mapstraction/map.php b/plugins/Mapstraction/map.php
new file mode 100644
index 000000000..a33dfc736
--- /dev/null
+++ b/plugins/Mapstraction/map.php
@@ -0,0 +1,167 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Show a map of user's notices
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category Mapstraction
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+/**
+ * Show a map of notices
+ *
+ * @category Mapstraction
+ * @package StatusNet
+ * @author Evan Prodromou <evan@status.net>
+ * @author Craig Andrews <candrews@integralblue.com>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class MapAction extends OwnerDesignAction
+{
+ var $profile = null;
+ var $page = null;
+ var $notices = null;
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ $nickname_arg = $this->arg('nickname');
+ $nickname = common_canonical_nickname($nickname_arg);
+
+ // Permanent redirect on non-canonical nickname
+
+ if ($nickname_arg != $nickname) {
+ $args = array('nickname' => $nickname);
+ if ($this->arg('page') && $this->arg('page') != 1) {
+ $args['page'] = $this->arg['page'];
+ }
+ common_redirect(common_local_url($this->trimmed('action'), $args), 301);
+ return false;
+ }
+
+ $this->user = User::staticGet('nickname', $nickname);
+
+ if (!$this->user) {
+ $this->clientError(_m('No such user.'), 404);
+ return false;
+ }
+
+ $this->profile = $this->user->getProfile();
+
+ if (!$this->profile) {
+ $this->serverError(_m('User has no profile.'));
+ return false;
+ }
+
+ $page = $this->trimmed('page');
+
+ if (!empty($page) && Validate::number($page)) {
+ $this->page = $page+0;
+ } else {
+ $this->page = 1;
+ }
+
+ $this->notices = empty($this->tag)
+ ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
+ : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
+
+ return true;
+ }
+
+ function handle($args)
+ {
+ parent::handle($args);
+ $this->showPage();
+ }
+
+ function showContent()
+ {
+ $this->element('div', array('id' => 'map_canvas',
+ 'class' => 'gray smallmap',
+ 'style' => "width: 100%; height: 400px"));
+ }
+
+ /**
+ * Hook for adding extra JavaScript
+ *
+ * @param Action $action Action object for the page
+ *
+ * @return boolean event handler return
+ */
+
+ function showScripts()
+ {
+ parent::showScripts();
+ $jsonArray = array();
+
+ while ($this->notice->fetch()) {
+ if (!empty($this->notice->lat) && !empty($this->notice->lon)) {
+ $jsonNotice = $this->noticeAsJson($this->notice);
+ $jsonArray[] = $jsonNotice;
+ }
+ }
+
+ $this->inlineScript('$(document).ready(function() { '.
+ ' var _notices = ' . json_encode($jsonArray).'; ' .
+ 'showMapstraction($("#map_canvas"), _notices); });');
+
+ return true;
+ }
+
+ function noticeAsJson($notice)
+ {
+ // FIXME: this code should be abstracted to a neutral third
+ // party, like Notice::asJson(). I'm not sure of the ethics
+ // of refactoring from within a plugin, so I'm just abusing
+ // the ApiAction method. Don't do this unless you're me!
+
+ require_once(INSTALLDIR.'/lib/api.php');
+
+ $act = new ApiAction('/dev/null');
+
+ $arr = $act->twitterStatusArray($notice, true);
+ $arr['url'] = $notice->bestUrl();
+ $arr['html'] = $notice->rendered;
+ $arr['source'] = $arr['source'];
+
+ if (!empty($notice->reply_to)) {
+ $reply_to = Notice::staticGet('id', $notice->reply_to);
+ if (!empty($reply_to)) {
+ $arr['in_reply_to_status_url'] = $reply_to->bestUrl();
+ }
+ $reply_to = null;
+ }
+
+ $profile = $notice->getProfile();
+ $arr['user']['profile_url'] = $profile->profileurl;
+
+ return $arr;
+ }
+}
diff --git a/plugins/Mapstraction/usermap.js b/plugins/Mapstraction/usermap.js
index e667dd579..4b7a6c26b 100644
--- a/plugins/Mapstraction/usermap.js
+++ b/plugins/Mapstraction/usermap.js
@@ -1,40 +1,32 @@
-$(document).ready(function() {
+function scrapeNotices(user)
+{
var notices = [];
$(".notice").each(function(){
- var notice = getNoticeFromElement($(this));
- if(notice['geo'])
- notices.push(notice);
+ var notice = getNoticeFromElement($(this));
+ if (user) {
+ notice['user'] = user;
+ } else {
+ notice['user'] = getUserFromElement($(this));
+ }
+ if(notice['geo'])
+ notices.push(notice);
});
- if($("#map_canvas").length && notices.length>0)
- {
- showMapstraction($("#map_canvas"), notices);
- }
- $('.geo').click(function(){
- var noticeElement = $(this).closest(".notice");
- notice = getNoticeFromElement(noticeElement);
-
- $.fn.jOverlay.options = {
- color : '#000',
- opacity : '0.6',
- zIndex : 99,
- center : false,
- bgClickToClose : true,
- autoHide : true,
- css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
- };
- 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 });
- $('#jOverlayContent').show();
- $('#jOverlayContent button').click($.closeOverlay);
-
- showMapstraction($("#map_canvas_popup"), notice);
-
- return false;
- });
-});
+ return notices;
+}
+
+function scrapeUser()
+{
+ var avatarURL = $(".entity_profile .entity_depiction img.avatar").attr('src');
+ var profileURL = $(".entity_profile .entity_nickname .url").attr('href');
+ var nickname = $(".entity_profile .entity_nickname .nickname").text();
+
+ return {
+ 'profile_image_url': avatarURL,
+ 'profile_url': profileURL,
+ 'screen_name': nickname
+ };
+}
function getMicroformatValue(element)
{
@@ -48,23 +40,34 @@ function getMicroformatValue(element)
function getNoticeFromElement(noticeElement)
{
var notice = {};
- if(noticeElement.find(".geo").length){
+
+ if(noticeElement.find(".geo").length) {
var latlon = noticeElement.find(".geo").attr('title').split(";");
notice['geo']={'coordinates': [
parseFloat(latlon[0]),
parseFloat(latlon[1])] };
}
- notice['user']={
- 'profile_image_url': noticeElement.find("img.avatar").attr('src'),
- 'profile_url': noticeElement.find(".author a.url").attr('href'),
- 'screen_name': noticeElement.find(".author .nickname").text()
- };
- notice['html']=noticeElement.find(".entry-content").html();
- notice['url']=noticeElement.find("a.timestamp").attr('href');
- notice['created_at']=noticeElement.find("abbr.published").text();
+
+ notice['html'] = noticeElement.find(".entry-content").html();
+ notice['url'] = noticeElement.find("a.timestamp").attr('href');
+ notice['created_at'] = noticeElement.find("abbr.published").text();
+
return notice;
}
+function getUserFromElement(noticeElement)
+{
+ var avatarURL = noticeElement.find("img.avatar").attr('src');
+ var profileURL = noticeElement.find(".author a.url").attr('href');
+ var nickname = noticeElement.find(".author .nickname").text();
+
+ return {
+ 'profile_image_url': avatarURL,
+ 'profile_url': profileURL,
+ 'screen_name': nickname
+ };
+}
+
function showMapstraction(element, notices) {
if(element instanceof jQuery) element = element[0];
if(! $.isArray(notices)) notices = [notices];
diff --git a/plugins/Mapstraction/usermap.php b/plugins/Mapstraction/usermap.php
index fbf1469c3..ff47b6ada 100644
--- a/plugins/Mapstraction/usermap.php
+++ b/plugins/Mapstraction/usermap.php
@@ -37,61 +37,24 @@ if (!defined('STATUSNET')) {
* @category Mapstraction
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
+ * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
-class UsermapAction extends OwnerDesignAction
+class UsermapAction extends MapAction
{
- var $profile = null;
- var $page = null;
- var $notices = null;
-
- public $plugin = null;
function prepare($args)
{
- parent::prepare($args);
-
- $nickname_arg = $this->arg('nickname');
- $nickname = common_canonical_nickname($nickname_arg);
-
- // Permanent redirect on non-canonical nickname
-
- if ($nickname_arg != $nickname) {
- $args = array('nickname' => $nickname);
- if ($this->arg('page') && $this->arg('page') != 1) {
- $args['page'] = $this->arg['page'];
- }
- common_redirect(common_local_url($this->trimmed('action'), $args), 301);
+ if(parent::prepare($args)) {
+ $this->notice = empty($this->tag)
+ ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
+ : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
+ return true;
+ }else{
return false;
}
-
- $this->user = User::staticGet('nickname', $nickname);
-
- if (!$this->user) {
- $this->clientError(_('No such user.'), 404);
- return false;
- }
-
- $this->profile = $this->user->getProfile();
-
- if (!$this->profile) {
- $this->serverError(_('User has no profile.'));
- return false;
- }
-
- $page = $this->trimmed('page');
-
- if (!empty($page) && Validate::number($page)) {
- $this->page = $page+0;
- } else {
- $this->page = 1;
- }
-
- $this->notices = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
-
- return true;
}
function title()
@@ -105,22 +68,9 @@ class UsermapAction extends OwnerDesignAction
if ($this->page == 1) {
return $base;
} else {
- return sprintf(_("%s map, page %d"),
+ return sprintf(_m("%s map, page %d"),
$base,
$this->page);
}
}
-
- function handle($args)
- {
- parent::handle($args);
- $this->showPage();
- }
-
- function showContent()
- {
- $this->element('div', array('id' => 'map_canvas',
- 'class' => 'gray smallmap',
- 'style' => "width: 100%; height: 400px"));
- }
-} \ No newline at end of file
+}