]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/mailbox.php
comma to dot
[quix0rs-gnu-social.git] / lib / mailbox.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 require_once(INSTALLDIR.'/lib/personal.php');
23
24 define('MESSAGES_PER_PAGE', 20);
25
26 class MailboxAction extends PersonalAction {
27         
28         function handle($args) {
29
30                 parent::handle($args);
31
32                 $nickname = common_canonical_nickname($this->arg('nickname'));
33                 $user = User::staticGet('nickname', $nickname);
34
35                 if (!$user) {
36                         $this->client_error(_('No such user.'), 404);
37                         return;
38                 }
39
40                 $cur = common_current_user();
41                 
42                 if (!$cur || $cur->id != $user->id) {
43                         $this->client_error(_('Only the user can read their own mailboxes.'), 403);
44                         return;
45                 }
46                 
47                 $profile = $user->getProfile();
48
49                 if (!$profile) {
50                         $this->server_error(_('User has no profile.'));
51                         return;
52                 }
53
54                 $page = $this->trimmed('page');
55                 
56                 if (!$page) {
57                         $page = 1;
58                 }
59                 
60                 $this->show_page($user, $page);
61         }
62
63         function get_title($user, $page) {
64                 return '';
65         }
66
67         function get_instructions() {
68                 return '';
69         }
70
71         function show_top() {
72                 
73                 $inst = $this->get_instructions();
74                 $output = common_markup_to_html($inst);
75                 common_element_start('div', 'instructions');
76                 common_raw($output);
77                 common_element_end('div');
78                 
79                 $this->views_menu();
80         }
81         
82         function show_page($user, $page) {
83
84                 common_show_header($this->get_title($user, $page),
85                                                    NULL, NULL,
86                                                    array($this, 'show_top'));
87                 
88                 $this->show_box($user, $page);
89                 
90                 common_show_footer();
91         }
92         
93         function show_box($user, $page) {
94                 
95                 $message = $this->get_messages($user, $page);
96                 
97                 if ($message) {
98                         
99                         $cnt = 0;
100                         common_element_start('ul', array('id' => 'messages'));
101                 
102                         while ($message->fetch() && $cnt <= MESSAGES_PER_PAGE) {
103                                 $cnt++;
104                                 
105                                 if ($cnt > MESSAGES_PER_PAGE) {
106                                         break;
107                                 }
108                                 
109                                 $this->show_message($message);
110                         }
111
112                         common_element_end('ul');
113                         
114                         common_pagination($page > 1, $cnt > MESSAGES_PER_PAGE,
115                                                           $page, $this->trimmed('action'),
116                                                           array('nickname' => $user->nickname));
117                         
118                         $message->free();
119                         unset($message);
120                 }
121         }
122
123         # returns the profile we want to show with the message
124         
125         function get_message_profile($message) {
126                 return NULL;
127         }
128         
129         function show_message($message) {
130
131                 common_element_start('li', array('class' => 'message_single',
132                                                                                   'id' => 'message-' . $message->id));
133
134                 $profile = $this->get_message_profile($message);
135                 
136                 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
137                 common_element_start('a', array('href' => $profile->profileurl));
138                 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
139                                                                         'class' => 'avatar stream',
140                                                                         'width' => AVATAR_STREAM_SIZE,
141                                                                         'height' => AVATAR_STREAM_SIZE,
142                                                                         'alt' =>
143                                                                         ($profile->fullname) ? $profile->fullname :
144                                                                         $profile->nickname));
145                 common_element_end('a');
146                 common_element('a', array('href' => $profile->profileurl,
147                                                                   'class' => 'nickname'),
148                                            $profile->nickname);
149                 # FIXME: URL, image, video, audio
150                 common_element_start('p', array('class' => 'content'));
151                 common_raw($message->rendered);
152                 common_element_end('p');
153                 
154                 $messageurl = common_local_url('showmessage', array('message' => $message->id));
155                 
156                 # XXX: we need to figure this out better. Is this right?
157                 if (strcmp($message->uri, $messageurl) != 0 && preg_match('/^http/', $message->uri)) {
158                         $messageurl = $message->uri;
159                 }
160                 common_element_start('p', 'time');
161                 common_element('a', array('class' => 'permalink',
162                                                                   'href' => $messageurl,
163                                                                   'title' => common_exact_date($message->created)),
164                                            common_date_string($message->created));
165                 if ($message->source) {
166                         common_text(_(' from '));
167                         $this->source_link($message->source);
168                 }
169                 
170                 common_element_end('p');
171                 
172                 common_element_end('li');
173         }
174 }