3 * StatusNet, the distributed open-source microblogging tool
5 * common superclass for direct messages inbox and outbox
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/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2008 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') && !defined('LACONICA')) {
35 * common superclass for direct messages inbox and outbox
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/
46 class MailboxAction extends CurrentUserDesignAction
50 function prepare($args)
52 parent::prepare($args);
54 $nickname = common_canonical_nickname($this->arg('nickname'));
55 $this->user = User::staticGet('nickname', $nickname);
56 $this->page = $this->trimmed('page');
62 common_set_returnto($this->selfUrl());
68 * output page based on arguments
70 * @param array $args HTTP arguments (from $_REQUEST)
75 function handle($args)
77 parent::handle($args);
80 $this->clientError(_('No such user.'), 404);
84 $cur = common_current_user();
86 if (!$cur || $cur->id != $this->user->id) {
87 $this->clientError(_('Only the user can read their own mailboxes.'),
95 function showLocalNav()
97 $nav = new PersonalGroupNav($this);
101 function showNoticeForm()
103 $message_form = new MessageForm($this);
104 $message_form->show();
107 function showContent()
109 $message = $this->getMessages();
113 $this->elementStart('div', array('id' =>'notices_primary'));
114 $this->element('h2', null, _('Notices'));
115 $this->elementStart('ul', 'notices');
117 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
120 if ($cnt > MESSAGES_PER_PAGE) {
124 $this->showMessage($message);
127 $this->elementEnd('ul');
129 $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE,
130 $this->page, $this->trimmed('action'),
131 array('nickname' => $this->user->nickname));
132 $this->elementEnd('div');
137 $this->element('p', 'guide', _('You have no private messages. You can send private message to engage other users in conversation. People can send you messages for your eyes only.'));
141 function getMessages()
147 * returns the profile we want to show with the message
149 * For inboxes, we show the sender; for outboxes, the recipient.
151 * @param Message $message The message to get the profile for
153 * @return Profile The profile that matches the message
156 function getMessageProfile($message)
162 * show a single message in the list format
164 * XXX: This needs to be extracted out into a MessageList similar
167 * @param Message $message the message to show
172 function showMessage($message)
174 $this->elementStart('li', array('class' => 'hentry notice',
175 'id' => 'message-' . $message->id));
177 $profile = $this->getMessageProfile($message);
179 $this->elementStart('div', 'entry-title');
180 $this->elementStart('span', 'vcard author');
181 $this->elementStart('a', array('href' => $profile->profileurl,
183 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
184 $this->element('img', array('src' => ($avatar) ?
185 $avatar->displayUrl() :
186 Avatar::defaultImage(AVATAR_STREAM_SIZE),
187 'class' => 'photo avatar',
188 'width' => AVATAR_STREAM_SIZE,
189 'height' => AVATAR_STREAM_SIZE,
191 ($profile->fullname) ? $profile->fullname :
192 $profile->nickname));
193 $this->element('span', array('class' => 'nickname fn'),
195 $this->elementEnd('a');
196 $this->elementEnd('span');
198 // FIXME: URL, image, video, audio
199 $this->elementStart('p', array('class' => 'entry-content'));
200 $this->raw($message->rendered);
201 $this->elementEnd('p');
202 $this->elementEnd('div');
204 $messageurl = common_local_url('showmessage',
205 array('message' => $message->id));
207 // XXX: we need to figure this out better. Is this right?
208 if (strcmp($message->uri, $messageurl) != 0 &&
209 preg_match('/^http/', $message->uri)) {
210 $messageurl = $message->uri;
213 $this->elementStart('div', 'entry-content');
214 $this->elementStart('a', array('rel' => 'bookmark',
215 'class' => 'timestamp',
216 'href' => $messageurl));
217 $dt = common_date_iso8601($message->created);
218 $this->element('abbr', array('class' => 'published',
220 common_date_string($message->created));
221 $this->elementEnd('a');
223 if ($message->source) {
224 $this->elementStart('span', 'source');
225 // FIXME: bad i18n. Device should be a parameter (from %s).
226 $this->text(_('from'));
227 $this->element('span', 'device', $this->showSource($message->source));
228 $this->elementEnd('span');
230 $this->elementEnd('div');
232 $this->elementEnd('li');
236 * Show the page notice
238 * Shows instructions for the page
243 function showPageNotice()
245 $instr = $this->getInstructions();
246 $output = common_markup_to_html($instr);
248 $this->elementStart('div', 'instructions');
250 $this->elementEnd('div');
254 * Show the source of the message
256 * Returns either the name (and link) of the API client that posted the notice,
257 * or one of other other channels.
259 * @param string $source the source of the message
264 function showSource($source)
266 $source_name = _($source);
273 $this->element('span', 'device', $source_name);
276 $ns = Notice_source::staticGet($source);
278 $this->elementStart('span', 'device');
279 $this->element('a', array('href' => $ns->url,
280 'rel' => 'external'),
282 $this->elementEnd('span');
284 $this->element('span', 'device', $source_name);
292 * Mailbox actions are read only
294 * @param array $args other arguments
299 function isReadOnly($args)