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');
66 common_set_returnto($this->selfUrl());
72 * output page based on arguments
74 * @param array $args HTTP arguments (from $_REQUEST)
79 function handle($args)
81 parent::handle($args);
84 $this->clientError(_('No such user.'), 404);
88 $cur = common_current_user();
90 if (!$cur || $cur->id != $this->user->id) {
91 $this->clientError(_('Only the user can read their own mailboxes.'),
99 function showLocalNav()
101 $nav = new PersonalGroupNav($this);
105 function showNoticeForm()
107 $message_form = new MessageForm($this);
108 $message_form->show();
111 function showContent()
113 $message = $this->getMessages();
117 $this->elementStart('div', array('id' =>'notices_primary'));
118 $this->element('h2', null, _('Notices'));
119 $this->elementStart('ul', 'notices');
121 while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
124 if ($cnt > MESSAGES_PER_PAGE) {
128 $this->showMessage($message);
131 $this->elementEnd('ul');
133 $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE,
134 $this->page, $this->trimmed('action'),
135 array('nickname' => $this->user->nickname));
136 $this->elementEnd('div');
142 function getMessages()
148 * returns the profile we want to show with the message
150 * For inboxes, we show the sender; for outboxes, the recipient.
152 * @param Message $message The message to get the profile for
154 * @return Profile The profile that matches the message
157 function getMessageProfile($message)
163 * show a single message in the list format
165 * XXX: This needs to be extracted out into a MessageList similar
168 * @param Message $message the message to show
173 function showMessage($message)
175 $this->elementStart('li', array('class' => 'hentry notice',
176 'id' => 'message-' . $message->id));
178 $profile = $this->getMessageProfile($message);
180 $this->elementStart('div', 'entry-title');
181 $this->elementStart('span', 'vcard author');
182 $this->elementStart('a', array('href' => $profile->profileurl,
184 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
185 $this->element('img', array('src' => ($avatar) ?
186 $avatar->displayUrl() :
187 Avatar::defaultImage(AVATAR_STREAM_SIZE),
188 'class' => 'photo avatar',
189 'width' => AVATAR_STREAM_SIZE,
190 'height' => AVATAR_STREAM_SIZE,
192 ($profile->fullname) ? $profile->fullname :
193 $profile->nickname));
194 $this->element('span', array('class' => 'nickname fn'),
196 $this->elementEnd('a');
197 $this->elementEnd('span');
199 // FIXME: URL, image, video, audio
200 $this->elementStart('p', array('class' => 'entry-content'));
201 $this->raw($message->rendered);
202 $this->elementEnd('p');
203 $this->elementEnd('div');
205 $messageurl = common_local_url('showmessage',
206 array('message' => $message->id));
208 // XXX: we need to figure this out better. Is this right?
209 if (strcmp($message->uri, $messageurl) != 0 &&
210 preg_match('/^http/', $message->uri)) {
211 $messageurl = $message->uri;
214 $this->elementStart('div', 'entry-content');
215 $this->elementStart('dl', 'timestamp');
216 $this->element('dt', null, _('Published'));
217 $this->elementStart('dd', null);
218 $dt = common_date_iso8601($message->created);
219 $this->elementStart('a', array('rel' => 'bookmark',
220 'href' => $messageurl));
221 $this->element('abbr', array('class' => 'published',
223 common_date_string($message->created));
224 $this->elementEnd('a');
225 $this->elementEnd('dd');
226 $this->elementEnd('dl');
228 if ($message->source) {
229 $this->elementStart('dl', 'device');
230 $this->elementStart('dt');
231 $this->text(_('From'));
232 $this->elementEnd('dt');
233 $this->showSource($message->source);
234 $this->elementEnd('dl');
236 $this->elementEnd('div');
238 $this->elementEnd('li');
242 * Show the page notice
244 * Shows instructions for the page
249 function showPageNotice()
251 $instr = $this->getInstructions();
252 $output = common_markup_to_html($instr);
254 $this->elementStart('div', 'instructions');
256 $this->elementEnd('div');
260 * Show the source of the message
262 * Returns either the name (and link) of the API client that posted the notice,
263 * or one of other other channels.
265 * @param string $source the source of the message
270 function showSource($source)
272 $source_name = _($source);
279 $this->element('dd', null, $source_name);
282 $ns = Notice_source::staticGet($source);
284 $this->elementStart('dd', null);
285 $this->element('a', array('href' => $ns->url,
286 'rel' => 'external'),
288 $this->elementEnd('dd');
290 $this->element('dd', null, $source_name);