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
54 function prepare($args)
56 parent::prepare($args);
58 $nickname = common_canonical_nickname($this->arg('nickname'));
59 $this->user = User::staticGet('nickname', $nickname);
60 $this->page = $this->trimmed('page');
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();
116 $this->elementStart('ul', array('id' => 'messages'));
118 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
121 if ($cnt > MESSAGES_PER_PAGE) {
125 $this->showMessage($message);
128 $this->elementEnd('ul');
130 $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE,
131 $this->page, $this->trimmed('action'),
132 array('nickname' => $this->user->nickname));
139 function getMessages()
145 * returns the profile we want to show with the message
147 * For inboxes, we show the sender; for outboxes, the recipient.
149 * @param Message $message The message to get the profile for
151 * @return Profile The profile that matches the message
154 function getMessageProfile($message)
160 * show a single message in the list format
162 * XXX: This needs to be extracted out into a MessageList similar
165 * @param Message $message the message to show
170 function showMessage($message)
172 $this->elementStart('li', array('class' => 'message_single',
173 'id' => 'message-' . $message->id));
175 $profile = $this->getMessageProfile($message);
177 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
178 $this->elementStart('a', array('href' => $profile->profileurl));
179 $this->element('img', array('src' => ($avatar) ?
180 common_avatar_display_url($avatar) :
181 common_default_avatar(AVATAR_STREAM_SIZE),
182 'class' => 'avatar stream',
183 'width' => AVATAR_STREAM_SIZE,
184 'height' => AVATAR_STREAM_SIZE,
186 ($profile->fullname) ? $profile->fullname :
187 $profile->nickname));
188 $this->elementEnd('a');
189 $this->element('a', array('href' => $profile->profileurl,
190 'class' => 'nickname'),
192 // FIXME: URL, image, video, audio
193 $this->elementStart('p', array('class' => 'content'));
194 $this->raw($message->rendered);
195 $this->elementEnd('p');
197 $messageurl = common_local_url('showmessage',
198 array('message' => $message->id));
200 // XXX: we need to figure this out better. Is this right?
201 if (strcmp($message->uri, $messageurl) != 0 &&
202 preg_match('/^http/', $message->uri)) {
203 $messageurl = $message->uri;
205 $this->elementStart('p', 'time');
206 $this->element('a', array('class' => 'permalink',
207 'href' => $messageurl,
208 'title' => common_exact_date($message->created)),
209 common_date_string($message->created));
210 if ($message->source) {
211 $this->text(_(' from '));
212 $this->showSource($message->source);
215 $this->elementEnd('p');
217 $this->elementEnd('li');
221 * Show the page notice
223 * Shows instructions for the page
228 function showPageNotice()
230 $instr = $this->getInstructions();
231 $output = common_markup_to_html($instr);
233 $this->elementStart('div', 'instructions');
235 $this->elementEnd('div');
239 * Show the source of the message
241 * Returns either the name (and link) of the API client that posted the notice,
242 * or one of other other channels.
244 * @param string $source the source of the message
249 function showSource($source)
251 $source_name = _($source);
258 $this->element('span', 'noticesource', $source_name);
261 $ns = Notice_source::staticGet($source);
263 $this->element('a', array('href' => $ns->url),
266 $this->element('span', 'noticesource', $source_name);