]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/mailbox.php
move MESSAGES_PER_PAGE to common.php
[quix0rs-gnu-social.git] / lib / mailbox.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * common superclass for direct messages inbox and outbox
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Message
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @copyright 2008 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * common superclass for direct messages inbox and outbox
36  *
37  * @category Message
38  * @package  StatusNet
39  * @author   Evan Prodromou <evan@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
41  * @link     http://status.net/
42  * @see      InboxAction
43  * @see      OutboxAction
44  */
45
46 class MailboxAction extends CurrentUserDesignAction
47 {
48     var $page = null;
49
50     function prepare($args)
51     {
52         parent::prepare($args);
53
54         $nickname   = common_canonical_nickname($this->arg('nickname'));
55         $this->user = User::staticGet('nickname', $nickname);
56         $this->page = $this->trimmed('page');
57
58         if (!$this->page) {
59             $this->page = 1;
60         }
61
62         common_set_returnto($this->selfUrl());
63
64         return true;
65     }
66
67     /**
68      * output page based on arguments
69      *
70      * @param array $args HTTP arguments (from $_REQUEST)
71      *
72      * @return void
73      */
74
75     function handle($args)
76     {
77         parent::handle($args);
78
79         if (!$this->user) {
80             $this->clientError(_('No such user.'), 404);
81             return;
82         }
83
84         $cur = common_current_user();
85
86         if (!$cur || $cur->id != $this->user->id) {
87             $this->clientError(_('Only the user can read their own mailboxes.'),
88                 403);
89             return;
90         }
91
92         $this->showPage();
93     }
94
95     function showLocalNav()
96     {
97         $nav = new PersonalGroupNav($this);
98         $nav->show();
99     }
100
101     function showNoticeForm()
102     {
103         $message_form = new MessageForm($this);
104         $message_form->show();
105     }
106
107     function showContent()
108     {
109         $message = $this->getMessages();
110
111         if ($message) {
112             $cnt = 0;
113             $this->elementStart('div', array('id' =>'notices_primary'));
114             $this->element('h2', null, _('Notices'));
115             $this->elementStart('ul', 'notices');
116
117             while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
118                 $cnt++;
119
120                 if ($cnt > MESSAGES_PER_PAGE) {
121                     break;
122                 }
123
124                 $this->showMessage($message);
125             }
126
127             $this->elementEnd('ul');
128
129             $this->pagination($this->page > 1, $cnt > MESSAGES_PER_PAGE,
130                               $this->page, $this->trimmed('action'),
131                               array('nickname' => $this->user->nickname));
132             $this->elementEnd('div');
133             $message->free();
134             unset($message);
135         }
136         else {
137             $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.'));
138         }
139     }
140
141     function getMessages()
142     {
143         return null;
144     }
145
146     /**
147      * returns the profile we want to show with the message
148      *
149      * For inboxes, we show the sender; for outboxes, the recipient.
150      *
151      * @param Message $message The message to get the profile for
152      *
153      * @return Profile The profile that matches the message
154      */
155
156     function getMessageProfile($message)
157     {
158         return null;
159     }
160
161     /**
162      * show a single message in the list format
163      *
164      * XXX: This needs to be extracted out into a MessageList similar
165      * to NoticeList.
166      *
167      * @param Message $message the message to show
168      *
169      * @return void
170      */
171
172     function showMessage($message)
173     {
174         $this->elementStart('li', array('class' => 'hentry notice',
175                                          'id' => 'message-' . $message->id));
176
177         $profile = $this->getMessageProfile($message);
178
179         $this->elementStart('div', 'entry-title');
180         $this->elementStart('span', 'vcard author');
181         $this->elementStart('a', array('href' => $profile->profileurl,
182                                        'class' => 'url'));
183         $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
184         $this->element('img', array('src' => ($avatar) ?
185                                     $avatar->displayUrl() :
186                                     Avatar::defaultImage(AVATAR_STREAM_SIZE),
187                                     'class' => 'photo avatar',
188                                     'width' => AVATAR_STREAM_SIZE,
189                                     'height' => AVATAR_STREAM_SIZE,
190                                     'alt' =>
191                                     ($profile->fullname) ? $profile->fullname :
192                                     $profile->nickname));
193         $this->element('span', array('class' => 'nickname fn'),
194                             $profile->nickname);
195         $this->elementEnd('a');
196         $this->elementEnd('span');
197
198         // FIXME: URL, image, video, audio
199         $this->elementStart('p', array('class' => 'entry-content'));
200         $this->raw($message->rendered);
201         $this->elementEnd('p');
202         $this->elementEnd('div');
203
204         $messageurl = common_local_url('showmessage',
205                                        array('message' => $message->id));
206
207         // XXX: we need to figure this out better. Is this right?
208         if (strcmp($message->uri, $messageurl) != 0 &&
209             preg_match('/^http/', $message->uri)) {
210             $messageurl = $message->uri;
211         }
212
213         $this->elementStart('div', 'entry-content');
214         $this->elementStart('a', array('rel' => 'bookmark',
215                                        'class' => 'timestamp',
216                                        'href' => $messageurl));
217         $dt = common_date_iso8601($message->created);
218         $this->element('abbr', array('class' => 'published',
219                                      'title' => $dt),
220                                common_date_string($message->created));
221         $this->elementEnd('a');
222
223         if ($message->source) {
224             $this->elementStart('span', 'source');
225             // FIXME: bad i18n. Device should be a parameter (from %s).
226             $this->text(_('from'));
227             $this->element('span', 'device', $this->showSource($message->source));
228             $this->elementEnd('span');
229         }
230         $this->elementEnd('div');
231
232         $this->elementEnd('li');
233     }
234
235     /**
236      * Show the page notice
237      *
238      * Shows instructions for the page
239      *
240      * @return void
241      */
242
243     function showPageNotice()
244     {
245         $instr  = $this->getInstructions();
246         $output = common_markup_to_html($instr);
247
248         $this->elementStart('div', 'instructions');
249         $this->raw($output);
250         $this->elementEnd('div');
251     }
252
253     /**
254      * Show the source of the message
255      *
256      * Returns either the name (and link) of the API client that posted the notice,
257      * or one of other other channels.
258      *
259      * @param string $source the source of the message
260      *
261      * @return void
262      */
263
264     function showSource($source)
265     {
266         $source_name = _($source);
267         switch ($source) {
268         case 'web':
269         case 'xmpp':
270         case 'mail':
271         case 'omb':
272         case 'api':
273             $this->element('span', 'device', $source_name);
274             break;
275         default:
276             $ns = Notice_source::staticGet($source);
277             if ($ns) {
278                 $this->elementStart('span', 'device');
279                 $this->element('a', array('href' => $ns->url,
280                                                'rel' => 'external'),
281                                     $ns->name);
282                 $this->elementEnd('span');
283             } else {
284                 $this->element('span', 'device', $source_name);
285             }
286             break;
287         }
288         return;
289     }
290
291     /**
292      * Mailbox actions are read only
293      *
294      * @param array $args other arguments
295      *
296      * @return boolean
297      */
298
299     function isReadOnly($args)
300     {
301          return true;
302     }
303
304 }