]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/mailbox.php
Fixed bad query causing facebook_update to fail
[quix0rs-gnu-social.git] / lib / mailbox.php
1 <?php
2 /**
3  * Laconica, 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   Laconica
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/
28  */
29
30 if (!defined('LACONICA')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR.'/lib/personal.php';
35
36 define('MESSAGES_PER_PAGE', 20);
37
38 /**
39  * common superclass for direct messages inbox and outbox
40  *
41  * @category Message
42  * @package  Laconica
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/
46  * @see      InboxAction
47  * @see      OutboxAction
48  */
49
50 class MailboxAction extends PersonalAction
51 {
52     var $page = null;
53
54     function prepare($args) 
55     {
56         parent::prepare($args);
57
58         $nickname   = common_canonical_nickname($this->arg('nickname'));
59         $this->user = User::staticGet('nickname', $nickname);
60         $this->page = $this->trimmed('page');
61
62         if (!$this->page) {
63             $this->page = 1;
64         }
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     }
139
140     function getMessages()
141     {
142         return null;
143     }
144
145     /**
146      * returns the profile we want to show with the message
147      *
148      * For inboxes, we show the sender; for outboxes, the recipient.
149      *
150      * @param Message $message The message to get the profile for
151      *
152      * @return Profile The profile that matches the message
153      */
154
155     function getMessageProfile($message)
156     {
157         return null;
158     }
159
160     /**
161      * show a single message in the list format
162      *
163      * XXX: This needs to be extracted out into a MessageList similar
164      * to NoticeList.
165      *
166      * @param Message $message the message to show
167      *
168      * @return void
169      */
170
171     function showMessage($message)
172     {
173         $this->elementStart('li', array('class' => 'hentry notice',
174                                          'id' => 'message-' . $message->id));
175
176         $profile = $this->getMessageProfile($message);
177
178         $this->elementStart('div', 'entry-title');
179         $this->elementStart('span', 'vcard author');
180         $this->elementStart('a', array('href' => $profile->profileurl,
181                                        'class' => 'url'));
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,
189                                     'alt' =>
190                                     ($profile->fullname) ? $profile->fullname :
191                                     $profile->nickname));
192         $this->element('span', array('class' => 'nickname fn'),
193                             $profile->nickname);
194         $this->elementEnd('a');
195         $this->elementEnd('span');
196
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');
202
203         $messageurl = common_local_url('showmessage',
204                                        array('message' => $message->id));
205
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;
210         }
211
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',
220                                      'title' => $dt),
221                                common_date_string($message->created));
222         $this->elementEnd('a');
223         $this->elementEnd('dd');
224         $this->elementEnd('dl');
225
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');
233         }
234         $this->elementEnd('div');
235
236         $this->elementEnd('li');
237     }
238
239     /**
240      * Show the page notice
241      *
242      * Shows instructions for the page
243      *
244      * @return void
245      */
246
247     function showPageNotice()
248     {
249         $instr  = $this->getInstructions();
250         $output = common_markup_to_html($instr);
251
252         $this->elementStart('div', 'instructions');
253         $this->raw($output);
254         $this->elementEnd('div');
255     }
256
257     /**
258      * Show the source of the message
259      *
260      * Returns either the name (and link) of the API client that posted the notice,
261      * or one of other other channels.
262      *
263      * @param string $source the source of the message 
264      *
265      * @return void
266      */
267
268     function showSource($source) 
269     {
270         $source_name = _($source);
271         switch ($source) {
272         case 'web':
273         case 'xmpp':
274         case 'mail':
275         case 'omb':
276         case 'api':
277             $this->element('dd', null, $source_name);
278             break;
279         default:
280             $ns = Notice_source::staticGet($source);
281             if ($ns) {
282                 $this->elementStart('dd', null);
283                 $this->element('a', array('href' => $ns->url,
284                                           'rel' => 'external'),
285                                $ns->name);
286                 $this->elementEnd('dd');
287             } else {
288                 $this->element('dd', null, $source_name);
289             }
290             break;
291         }
292         return;
293     }
294
295 }