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');
141 $this->element('p', 'guide', _('You have no private messages. You can send private message to engage other users in conversation. People can send you messages for your eyes only.'));
145 function getMessages()
151 * returns the profile we want to show with the message
153 * For inboxes, we show the sender; for outboxes, the recipient.
155 * @param Message $message The message to get the profile for
157 * @return Profile The profile that matches the message
160 function getMessageProfile($message)
166 * show a single message in the list format
168 * XXX: This needs to be extracted out into a MessageList similar
171 * @param Message $message the message to show
176 function showMessage($message)
178 $this->elementStart('li', array('class' => 'hentry notice',
179 'id' => 'message-' . $message->id));
181 $profile = $this->getMessageProfile($message);
183 $this->elementStart('div', 'entry-title');
184 $this->elementStart('span', 'vcard author');
185 $this->elementStart('a', array('href' => $profile->profileurl,
187 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
188 $this->element('img', array('src' => ($avatar) ?
189 $avatar->displayUrl() :
190 Avatar::defaultImage(AVATAR_STREAM_SIZE),
191 'class' => 'photo avatar',
192 'width' => AVATAR_STREAM_SIZE,
193 'height' => AVATAR_STREAM_SIZE,
195 ($profile->fullname) ? $profile->fullname :
196 $profile->nickname));
197 $this->element('span', array('class' => 'nickname fn'),
199 $this->elementEnd('a');
200 $this->elementEnd('span');
202 // FIXME: URL, image, video, audio
203 $this->elementStart('p', array('class' => 'entry-content'));
204 $this->raw($message->rendered);
205 $this->elementEnd('p');
206 $this->elementEnd('div');
208 $messageurl = common_local_url('showmessage',
209 array('message' => $message->id));
211 // XXX: we need to figure this out better. Is this right?
212 if (strcmp($message->uri, $messageurl) != 0 &&
213 preg_match('/^http/', $message->uri)) {
214 $messageurl = $message->uri;
217 $this->elementStart('div', 'entry-content');
218 $this->elementStart('dl', 'timestamp');
219 $this->element('dt', null, _('Published'));
220 $this->elementStart('dd', null);
221 $dt = common_date_iso8601($message->created);
222 $this->elementStart('a', array('rel' => 'bookmark',
223 'href' => $messageurl));
224 $this->element('abbr', array('class' => 'published',
226 common_date_string($message->created));
227 $this->elementEnd('a');
228 $this->elementEnd('dd');
229 $this->elementEnd('dl');
231 if ($message->source) {
232 $this->elementStart('dl', 'device');
233 $this->elementStart('dt');
234 $this->text(_('From'));
235 $this->elementEnd('dt');
236 $this->showSource($message->source);
237 $this->elementEnd('dl');
239 $this->elementEnd('div');
241 $this->elementEnd('li');
245 * Show the page notice
247 * Shows instructions for the page
252 function showPageNotice()
254 $instr = $this->getInstructions();
255 $output = common_markup_to_html($instr);
257 $this->elementStart('div', 'instructions');
259 $this->elementEnd('div');
263 * Show the source of the message
265 * Returns either the name (and link) of the API client that posted the notice,
266 * or one of other other channels.
268 * @param string $source the source of the message
273 function showSource($source)
275 $source_name = _($source);
282 $this->element('dd', null, $source_name);
285 $ns = Notice_source::staticGet($source);
287 $this->elementStart('dd', null);
288 $this->element('a', array('href' => $ns->url,
289 'rel' => 'external'),
291 $this->elementEnd('dd');
293 $this->element('dd', null, $source_name);