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 user's notices
37 * @category Mapstraction
39 * @author Evan Prodromou <evan@status.net>
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41 * @link http://status.net/
44 class UsermapAction extends OwnerDesignAction
50 public $plugin = null;
52 function prepare($args)
54 parent::prepare($args);
56 $nickname_arg = $this->arg('nickname');
57 $nickname = common_canonical_nickname($nickname_arg);
59 // Permanent redirect on non-canonical nickname
61 if ($nickname_arg != $nickname) {
62 $args = array('nickname' => $nickname);
63 if ($this->arg('page') && $this->arg('page') != 1) {
64 $args['page'] = $this->arg['page'];
66 common_redirect(common_local_url($this->trimmed('action'), $args), 301);
70 $this->user = User::staticGet('nickname', $nickname);
73 $this->clientError(_('No such user.'), 404);
77 $this->profile = $this->user->getProfile();
79 if (!$this->profile) {
80 $this->serverError(_('User has no profile.'));
84 $page = $this->trimmed('page');
86 if (!empty($page) && Validate::number($page)) {
87 $this->page = $page+0;
92 $this->notices = $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
99 if (!empty($this->profile->fullname)) {
100 $base = $this->profile->fullname . ' (' . $this->user->nickname . ') ';
102 $base = $this->user->nickname;
105 if ($this->page == 1) {
108 return sprintf(_("%s map, page %d"),
114 function handle($args)
116 parent::handle($args);
120 function showContent()
122 $this->element('div', array('id' => 'map_canvas',
123 'class' => 'gray smallmap',
124 'style' => "width: 100%; height: 400px"));
128 * Hook for adding extra JavaScript
130 * @param Action $action Action object for the page
132 * @return boolean event handler return
135 function showScripts()
137 parent::showScripts();
138 $notice = empty($this->tag)
139 ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
140 : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
142 $jsonArray = array();
144 while ($notice->fetch()) {
145 if (!empty($notice->lat) && !empty($notice->lon)) {
146 $jsonNotice = $this->noticeAsJson($notice);
147 $jsonArray[] = $jsonNotice;
151 $this->elementStart('script', array('type' => 'text/javascript'));
152 $this->raw('/*<![CDATA[*/'); // XHTML compat for Safari
153 $this->raw('var _notices = ' . json_encode($jsonArray).'; ');
154 $this->raw('showMapstraction($("#map_canvas"),_notices);');
155 $this->raw('/*]]>*/'); // XHTML compat for Safari
156 $this->elementEnd('script');
161 function noticeAsJson($notice)
163 // FIXME: this code should be abstracted to a neutral third
164 // party, like Notice::asJson(). I'm not sure of the ethics
165 // of refactoring from within a plugin, so I'm just abusing
166 // the ApiAction method. Don't do this unless you're me!
168 require_once(INSTALLDIR.'/lib/api.php');
170 $act = new ApiAction('/dev/null');
172 $arr = $act->twitterStatusArray($notice, true);
173 $arr['url'] = $notice->bestUrl();
174 $arr['html'] = $notice->rendered;
175 $arr['source'] = $arr['source'];
177 if (!empty($notice->reply_to)) {
178 $reply_to = Notice::staticGet('id', $notice->reply_to);
179 if (!empty($reply_to)) {
180 $arr['in_reply_to_status_url'] = $reply_to->bestUrl();
185 $profile = $notice->getProfile();
186 $arr['user']['profile_url'] = $profile->profileurl;