3 * Laconica, 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@controlyourself.ca>
25 * @copyright 2008 Control Yourself, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://laconi.ca/
30 if (!defined('LACONICA')) {
34 require_once INSTALLDIR.'/lib/personal.php';
36 define('MESSAGES_PER_PAGE', 20);
39 * common superclass for direct messages inbox and outbox
43 * @author Evan Prodromou <evan@controlyourself.ca>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://laconi.ca/
50 class MailboxAction extends PersonalAction
53 * output page based on arguments
55 * @param array $args HTTP arguments (from $_REQUEST)
60 function handle($args)
62 parent::handle($args);
64 $nickname = common_canonical_nickname($this->arg('nickname'));
66 $user = User::staticGet('nickname', $nickname);
69 $this->client_error(_('No such user.'), 404);
73 $cur = common_current_user();
75 if (!$cur || $cur->id != $user->id) {
76 $this->client_error(_('Only the user can read their own mailboxes.'),
81 $profile = $user->getProfile();
84 $this->server_error(_('User has no profile.'));
88 $page = $this->trimmed('page');
94 $this->showPage($user, $page);
98 * returns the title of the page
100 * @param User $user current user
101 * @param int $page current page
103 * @return string localised title of the page
106 function getTitle($user, $page)
112 * instructions for using this page
114 * @return string localised instructions for using the page
117 function getInstructions()
123 * do structured output for the "instructions" are of the page
130 $cur = common_current_user();
132 common_message_form(null, $cur, null);
138 * show a full page of output
140 * @param User $user The current user
141 * @param int $page The page the user is on
146 function showPage($user, $page)
148 common_show_header($this->getTitle($user, $page),
150 array($this, 'showTop'));
152 $this->showBox($user, $page);
154 common_show_footer();
158 * retrieve the messages appropriate for this mailbox
160 * Does a query for the right messages
162 * @param User $user The current user
163 * @param int $page The page the user is on
165 * @return Message data object with stream for messages
168 function getMessages($user, $page)
174 * show the messages for a mailbox in list format
176 * Includes the pagination links (before, after).
178 * @param User $user The current user
179 * @param int $page The page the user is on
184 function showBox($user, $page)
186 $message = $this->getMessages($user, $page);
191 common_element_start('ul', array('id' => 'messages'));
193 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
196 if ($cnt > MESSAGES_PER_PAGE) {
200 $this->showMessage($message);
203 common_element_end('ul');
205 common_pagination($page > 1, $cnt > MESSAGES_PER_PAGE,
206 $page, $this->trimmed('action'),
207 array('nickname' => $user->nickname));
215 * returns the profile we want to show with the message
217 * For inboxes, we show the sender; for outboxes, the recipient.
219 * @param Message $message The message to get the profile for
221 * @return Profile The profile that matches the message
224 function getMessageProfile($message)
230 * show a single message in the list format
232 * @param Message $message the message to show
237 function showMessage($message)
239 common_element_start('li', array('class' => 'message_single',
240 'id' => 'message-' . $message->id));
242 $profile = $this->getMessageProfile($message);
244 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
245 common_element_start('a', array('href' => $profile->profileurl));
246 common_element('img', array('src' => ($avatar) ?
247 common_avatar_display_url($avatar) :
248 common_default_avatar(AVATAR_STREAM_SIZE),
249 'class' => 'avatar stream',
250 'width' => AVATAR_STREAM_SIZE,
251 'height' => AVATAR_STREAM_SIZE,
253 ($profile->fullname) ? $profile->fullname :
254 $profile->nickname));
255 common_element_end('a');
256 common_element('a', array('href' => $profile->profileurl,
257 'class' => 'nickname'),
259 // FIXME: URL, image, video, audio
260 common_element_start('p', array('class' => 'content'));
261 common_raw($message->rendered);
262 common_element_end('p');
264 $messageurl = common_local_url('showmessage',
265 array('message' => $message->id));
267 // XXX: we need to figure this out better. Is this right?
268 if (strcmp($message->uri, $messageurl) != 0 &&
269 preg_match('/^http/', $message->uri)) {
270 $messageurl = $message->uri;
272 common_element_start('p', 'time');
273 common_element('a', array('class' => 'permalink',
274 'href' => $messageurl,
275 'title' => common_exact_date($message->created)),
276 common_date_string($message->created));
277 if ($message->source) {
278 common_text(_(' from '));
279 $this->source_link($message->source);
282 common_element_end('p');
284 common_element_end('li');