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')) {
34 define('MESSAGES_PER_PAGE', 20);
37 * common superclass for direct messages inbox and outbox
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
48 class MailboxAction extends CurrentUserDesignAction
52 function prepare($args)
54 parent::prepare($args);
56 $nickname = common_canonical_nickname($this->arg('nickname'));
57 $this->user = User::staticGet('nickname', $nickname);
58 $this->page = $this->trimmed('page');
64 common_set_returnto($this->selfUrl());
70 * output page based on arguments
72 * @param array $args HTTP arguments (from $_REQUEST)
77 function handle($args)
79 parent::handle($args);
82 $this->clientError(_('No such user.'), 404);
86 $cur = common_current_user();
88 if (!$cur || $cur->id != $this->user->id) {
89 $this->clientError(_('Only the user can read their own mailboxes.'),
97 function showLocalNav()
99 $nav = new PersonalGroupNav($this);
103 function showNoticeForm()
105 $message_form = new MessageForm($this);
106 $message_form->show();
109 function showContent()
111 $message = $this->getMessages();
115 $this->elementStart('div', array('id' =>'notices_primary'));
116 $this->element('h2', null, _('Notices'));
117 $this->elementStart('ul', 'notices');
119 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
122 if ($cnt > MESSAGES_PER_PAGE) {
126 $this->showMessage($message);
129 $this->elementEnd('ul');
131 $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE,
132 $this->page, $this->trimmed('action'),
133 array('nickname' => $this->user->nickname));
134 $this->elementEnd('div');
139 $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.'));
143 function getMessages()
149 * returns the profile we want to show with the message
151 * For inboxes, we show the sender; for outboxes, the recipient.
153 * @param Message $message The message to get the profile for
155 * @return Profile The profile that matches the message
158 function getMessageProfile($message)
164 * show a single message in the list format
166 * XXX: This needs to be extracted out into a MessageList similar
169 * @param Message $message the message to show
174 function showMessage($message)
176 $this->elementStart('li', array('class' => 'hentry notice',
177 'id' => 'message-' . $message->id));
179 $profile = $this->getMessageProfile($message);
181 $this->elementStart('div', 'entry-title');
182 $this->elementStart('span', 'vcard author');
183 $this->elementStart('a', array('href' => $profile->profileurl,
185 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
186 $this->element('img', array('src' => ($avatar) ?
187 $avatar->displayUrl() :
188 Avatar::defaultImage(AVATAR_STREAM_SIZE),
189 'class' => 'photo avatar',
190 'width' => AVATAR_STREAM_SIZE,
191 'height' => AVATAR_STREAM_SIZE,
193 ($profile->fullname) ? $profile->fullname :
194 $profile->nickname));
195 $this->element('span', array('class' => 'nickname fn'),
197 $this->elementEnd('a');
198 $this->elementEnd('span');
200 // FIXME: URL, image, video, audio
201 $this->elementStart('p', array('class' => 'entry-content'));
202 $this->raw($message->rendered);
203 $this->elementEnd('p');
204 $this->elementEnd('div');
206 $messageurl = common_local_url('showmessage',
207 array('message' => $message->id));
209 // XXX: we need to figure this out better. Is this right?
210 if (strcmp($message->uri, $messageurl) != 0 &&
211 preg_match('/^http/', $message->uri)) {
212 $messageurl = $message->uri;
215 $this->elementStart('div', 'entry-content');
216 $this->elementStart('a', array('rel' => 'bookmark',
217 'class' => 'timestamp',
218 'href' => $messageurl));
219 $dt = common_date_iso8601($message->created);
220 $this->element('abbr', array('class' => 'published',
222 common_date_string($message->created));
223 $this->elementEnd('a');
225 if ($message->source) {
226 $this->elementStart('span', 'source');
227 // FIXME: bad i18n. Device should be a parameter (from %s).
228 $this->text(_('from'));
229 $this->element('span', 'device', $this->showSource($message->source));
230 $this->elementEnd('span');
232 $this->elementEnd('div');
234 $this->elementEnd('li');
238 * Show the page notice
240 * Shows instructions for the page
245 function showPageNotice()
247 $instr = $this->getInstructions();
248 $output = common_markup_to_html($instr);
250 $this->elementStart('div', 'instructions');
252 $this->elementEnd('div');
256 * Show the source of the message
258 * Returns either the name (and link) of the API client that posted the notice,
259 * or one of other other channels.
261 * @param string $source the source of the message
266 function showSource($source)
268 $source_name = _($source);
275 $this->element('span', 'device', $source_name);
278 $ns = Notice_source::staticGet($source);
280 $this->elementStart('span', 'device');
281 $this->element('a', array('href' => $ns->url,
282 'rel' => 'external'),
284 $this->elementEnd('span');
286 $this->element('span', 'device', $source_name);
294 * Mailbox actions are read only
296 * @param array $args other arguments
301 function isReadOnly($args)