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