3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/personal.php');
24 define('MESSAGES_PER_PAGE', 20);
26 class MailboxAction extends PersonalAction {
28 function handle($args) {
30 parent::handle($args);
32 $nickname = common_canonical_nickname($this->arg('nickname'));
33 $user = User::staticGet('nickname', $nickname);
36 $this->client_error(_('No such user.'), 404);
40 $cur = common_current_user();
42 if (!$cur || $cur->id != $user->id) {
43 $this->client_error(_('Only the user can read their own mailboxes.'), 403);
47 $profile = $user->getProfile();
50 $this->server_error(_('User has no profile.'));
54 $page = $this->trimmed('page');
60 $this->show_page($user, $page);
63 function get_title($user, $page) {
67 function get_instructions() {
73 $cur = common_current_user();
75 common_message_form(NULL, $cur, NULL);
80 function show_page($user, $page) {
82 common_show_header($this->get_title($user, $page),
84 array($this, 'show_top'));
86 $this->show_box($user, $page);
91 function show_box($user, $page) {
93 $message = $this->get_messages($user, $page);
98 common_element_start('ul', array('id' => 'messages'));
100 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
103 if ($cnt > MESSAGES_PER_PAGE) {
107 $this->show_message($message);
110 common_element_end('ul');
112 common_pagination($page > 1, $cnt > MESSAGES_PER_PAGE,
113 $page, $this->trimmed('action'),
114 array('nickname' => $user->nickname));
121 # returns the profile we want to show with the message
123 function get_message_profile($message) {
127 function show_message($message) {
129 common_element_start('li', array('class' => 'message_single',
130 'id' => 'message-' . $message->id));
132 $profile = $this->get_message_profile($message);
134 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
135 common_element_start('a', array('href' => $profile->profileurl));
136 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
137 'class' => 'avatar stream',
138 'width' => AVATAR_STREAM_SIZE,
139 'height' => AVATAR_STREAM_SIZE,
141 ($profile->fullname) ? $profile->fullname :
142 $profile->nickname));
143 common_element_end('a');
144 common_element('a', array('href' => $profile->profileurl,
145 'class' => 'nickname'),
147 # FIXME: URL, image, video, audio
148 common_element_start('p', array('class' => 'content'));
149 common_raw($message->rendered);
150 common_element_end('p');
152 $messageurl = common_local_url('showmessage', array('message' => $message->id));
154 # XXX: we need to figure this out better. Is this right?
155 if (strcmp($message->uri, $messageurl) != 0 && preg_match('/^http/', $message->uri)) {
156 $messageurl = $message->uri;
158 common_element_start('p', 'time');
159 common_element('a', array('class' => 'permalink',
160 'href' => $messageurl,
161 'title' => common_exact_date($message->created)),
162 common_date_string($message->created));
163 if ($message->source) {
164 common_text(_(' from '));
165 $this->source_link($message->source);
168 common_element_end('p');
170 common_element_end('li');