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();
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');
140 function getMessages()
146 * returns the profile we want to show with the message
148 * For inboxes, we show the sender; for outboxes, the recipient.
150 * @param Message $message The message to get the profile for
152 * @return Profile The profile that matches the message
155 function getMessageProfile($message)
161 * show a single message in the list format
163 * XXX: This needs to be extracted out into a MessageList similar
166 * @param Message $message the message to show
171 function showMessage($message)
173 $this->elementStart('li', array('class' => 'hentry notice',
174 'id' => 'message-' . $message->id));
176 $profile = $this->getMessageProfile($message);
178 $this->elementStart('div', 'entry-title');
179 $this->elementStart('span', 'vcard author');
180 $this->elementStart('a', array('href' => $profile->profileurl,
182 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
183 $this->element('img', array('src' => ($avatar) ?
184 common_avatar_display_url($avatar) :
185 common_default_avatar(AVATAR_STREAM_SIZE),
186 'class' => 'photo avatar',
187 'width' => AVATAR_STREAM_SIZE,
188 'height' => AVATAR_STREAM_SIZE,
190 ($profile->fullname) ? $profile->fullname :
191 $profile->nickname));
192 $this->element('span', array('class' => 'nickname fn'),
194 $this->elementEnd('a');
195 $this->elementEnd('span');
197 // FIXME: URL, image, video, audio
198 $this->elementStart('p', array('class' => 'entry-content'));
199 $this->raw($message->rendered);
200 $this->elementEnd('p');
201 $this->elementEnd('div');
203 $messageurl = common_local_url('showmessage',
204 array('message' => $message->id));
206 // XXX: we need to figure this out better. Is this right?
207 if (strcmp($message->uri, $messageurl) != 0 &&
208 preg_match('/^http/', $message->uri)) {
209 $messageurl = $message->uri;
212 $this->elementStart('div', 'entry-content');
213 $this->elementStart('dl', 'timestamp');
214 $this->element('dt', null, _('Published'));
215 $this->elementStart('dd', null);
216 $dt = common_date_iso8601($message->created);
217 $this->elementStart('a', array('rel' => 'bookmark',
218 'href' => $messageurl));
219 $this->element('abbr', array('class' => 'published',
221 common_date_string($message->created));
222 $this->elementEnd('a');
223 $this->elementEnd('dd');
224 $this->elementEnd('dl');
226 if ($message->source) {
227 $this->elementStart('dl', 'device');
228 $this->elementStart('dt');
229 $this->text(_('From'));
230 $this->elementEnd('dt');
231 $this->showSource($message->source);
232 $this->elementEnd('dl');
234 $this->elementEnd('div');
236 $this->elementEnd('li');
240 * Show the page notice
242 * Shows instructions for the page
247 function showPageNotice()
249 $instr = $this->getInstructions();
250 $output = common_markup_to_html($instr);
252 $this->elementStart('div', 'instructions');
254 $this->elementEnd('div');
258 * Show the source of the message
260 * Returns either the name (and link) of the API client that posted the notice,
261 * or one of other other channels.
263 * @param string $source the source of the message
268 function showSource($source)
270 $source_name = _($source);
277 $this->element('dd', null, $source_name);
280 $ns = Notice_source::staticGet($source);
282 $this->elementStart('dd', null);
283 $this->element('a', array('href' => $ns->url,
284 'rel' => 'external'),
286 $this->elementEnd('dd');
288 $this->element('dd', null, $source_name);