3 * StatusNet, the distributed open-source microblogging tool
5 * Show a map of user's notices
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * @category Mapstraction
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2009 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
35 * Show a map of notices
37 * @category Mapstraction
39 * @author Evan Prodromou <evan@status.net>
40 * @author Craig Andrews <candrews@integralblue.com>
41 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42 * @link http://status.net/
45 class MapAction extends OwnerDesignAction
51 function prepare($args)
53 parent::prepare($args);
55 $nickname_arg = $this->arg('nickname');
56 $nickname = common_canonical_nickname($nickname_arg);
58 // Permanent redirect on non-canonical nickname
60 if ($nickname_arg != $nickname) {
61 $args = array('nickname' => $nickname);
62 if ($this->arg('page') && $this->arg('page') != 1) {
63 $args['page'] = $this->arg['page'];
65 common_redirect(common_local_url($this->trimmed('action'), $args), 301);
69 $this->user = User::staticGet('nickname', $nickname);
72 $this->clientError(_m('No such user.'), 404);
76 $this->profile = $this->user->getProfile();
78 if (!$this->profile) {
79 $this->serverError(_m('User has no profile.'));
83 $page = $this->trimmed('page');
85 if (!empty($page) && Validate::number($page)) {
86 $this->page = $page+0;
91 $this->notices = empty($this->tag)
92 ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
93 : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
98 function handle($args)
100 parent::handle($args);
104 function showContent()
106 $this->element('div', array('id' => 'map_canvas',
107 'class' => 'gray smallmap',
108 'style' => "width: 100%; height: 400px"));
112 * Hook for adding extra JavaScript
114 * @param Action $action Action object for the page
116 * @return boolean event handler return
119 function showScripts()
121 parent::showScripts();
122 $jsonArray = array();
124 while ($this->notice->fetch()) {
125 if (!empty($this->notice->lat) && !empty($this->notice->lon)) {
126 $jsonNotice = $this->noticeAsJson($this->notice);
127 $jsonArray[] = $jsonNotice;
131 $this->inlineScript('$(document).ready(function() { '.
132 ' var _notices = ' . json_encode($jsonArray).'; ' .
133 'showMapstraction($("#map_canvas"), _notices); });');
138 function noticeAsJson($notice)
140 // FIXME: this code should be abstracted to a neutral third
141 // party, like Notice::asJson(). I'm not sure of the ethics
142 // of refactoring from within a plugin, so I'm just abusing
143 // the ApiAction method. Don't do this unless you're me!
145 require_once(INSTALLDIR.'/lib/api.php');
147 $act = new ApiAction('/dev/null');
149 $arr = $act->twitterStatusArray($notice, true);
150 $arr['url'] = $notice->bestUrl();
151 $arr['html'] = $notice->rendered;
152 $arr['source'] = $arr['source'];
154 if (!empty($notice->reply_to)) {
155 $reply_to = Notice::staticGet('id', $notice->reply_to);
156 if (!empty($reply_to)) {
157 $arr['in_reply_to_status_url'] = $reply_to->bestUrl();
162 $profile = $notice->getProfile();
163 $arr['user']['profile_url'] = $profile->profileurl;