]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/lib/noticelist.php
add standard directories
[quix0rs-gnu-social.git] / _darcs / pristine / lib / noticelist.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 class NoticeList {
23
24     var $notice = NULL;
25
26     function __construct($notice) {
27         $this->notice = $notice;
28     }
29
30     function show() {
31
32                 common_element_start('ul', array('id' => 'notices'));
33
34                 $cnt = 0;
35
36                 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
37                         $cnt++;
38
39                         if ($cnt > NOTICES_PER_PAGE) {
40                                 break;
41                         }
42
43             $item = $this->new_list_item($this->notice);
44             $item->show();
45                 }
46
47                 common_element_end('ul');
48
49         return $cnt;
50         }
51
52     function new_list_item($notice) {
53         return new NoticeListItem($notice);
54     }
55 }
56
57 class NoticeListItem {
58
59     var $notice = NULL;
60     var $profile = NULL;
61
62     function __construct($notice) {
63         $this->notice = $notice;
64                 $this->profile = $notice->getProfile();
65     }
66
67         function show() {
68         $this->show_start();
69         $this->show_fave_form();
70         $this->show_author();
71         $this->show_content();
72         $this->show_start_time_section();
73         $this->show_notice_link();
74         $this->show_notice_source();
75         $this->show_reply_to();
76         $this->show_reply_link();
77         $this->show_delete_link();
78         $this->show_end_time_section();
79         $this->show_end();
80         }
81
82     function show_start() {
83                 # XXX: RDFa
84                 common_element_start('li', array('class' => 'notice_single hentry',
85                                                                                   'id' => 'notice-' . $this->notice->id));
86     }
87
88     function show_fave_form() {
89         $user = common_current_user();
90                 if ($user) {
91                         if ($user->hasFave($this->notice)) {
92                                 common_disfavor_form($this->notice);
93                         } else {
94                                 common_favor_form($this->notice);
95                         }
96                 }
97     }
98
99     function show_author() {
100                 common_element_start('span', 'vcard author');
101         $this->show_avatar();
102         $this->show_nickname();
103                 common_element_end('span');
104     }
105
106     function show_avatar() {
107                 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
108                 common_element_start('a', array('href' => $this->profile->profileurl));
109                 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
110                                                                         'class' => 'avatar stream photo',
111                                                                         'width' => AVATAR_STREAM_SIZE,
112                                                                         'height' => AVATAR_STREAM_SIZE,
113                                                                         'alt' =>
114                                                                         ($this->profile->fullname) ? $this->profile->fullname :
115                                                                         $this->profile->nickname));
116                 common_element_end('a');
117     }
118
119     function show_nickname() {
120                 common_element('a', array('href' => $this->profile->profileurl,
121                                                                   'class' => 'nickname fn url'),
122                                            $this->profile->nickname);
123     }
124
125     function show_content() {
126                 # FIXME: URL, image, video, audio
127                 common_element_start('p', array('class' => 'content entry-title'));
128                 if ($this->notice->rendered) {
129                         common_raw($this->notice->rendered);
130                 } else {
131                         # XXX: may be some uncooked notices in the DB,
132                         # we cook them right now. This should probably disappear in future
133                         # versions (>> 0.4.x)
134                         common_raw(common_render_content($this->notice->content, $this->notice));
135                 }
136                 common_element_end('p');
137     }
138
139     function show_start_time_section() {
140                 common_element_start('p', 'time');
141     }
142
143     function show_notice_link() {
144                 $noticeurl = common_local_url('shownotice', array('notice' => $this->notice->id));
145                 # XXX: we need to figure this out better. Is this right?
146                 if (strcmp($this->notice->uri, $noticeurl) != 0 && preg_match('/^http/', $this->notice->uri)) {
147                         $noticeurl = $this->notice->uri;
148                 }
149                 common_element_start('a', array('class' => 'permalink',
150                                                                   'rel' => 'bookmark',
151                                                                   'href' => $noticeurl));
152                 common_element('abbr', array('class' => 'published',
153                                                                          'title' => common_date_iso8601($this->notice->created)),
154                                                 common_date_string($this->notice->created));
155                 common_element_end('a');
156     }
157
158     function show_notice_source() {
159                 if ($this->notice->source) {
160                         common_element('span', null, _(' from '));
161             $source_name = _($this->notice->source);
162             switch ($this->notice->source) {
163              case 'web':
164              case 'xmpp':
165              case 'mail':
166              case 'omb':
167              case 'api':
168                 common_element('span', 'noticesource', $source_name);
169                 break;
170              default:
171                 $ns = Notice_source::staticGet($this->notice->source);
172                 if ($ns) {
173                     common_element('a', array('href' => $ns->url),
174                                    $ns->name);
175                 } else {
176                     common_element('span', 'noticesource', $source_name);
177                 }
178                 break;
179             }
180                 }
181     }
182
183     function show_reply_to() {
184                 if ($this->notice->reply_to) {
185                         $replyurl = common_local_url('shownotice', array('notice' => $this->notice->reply_to));
186                         common_text(' (');
187                         common_element('a', array('class' => 'inreplyto',
188                                                                           'href' => $replyurl),
189                                                    _('in reply to...'));
190                         common_text(')');
191                 }
192     }
193
194     function show_reply_link() {
195                 common_element_start('a',
196                                                          array('href' => common_local_url('newnotice',
197                                                                                                                           array('replyto' => $this->profile->nickname)),
198                                                                    'onclick' => 'return doreply("'.$this->profile->nickname.'", '.$this->notice->id.');',
199                                                                    'title' => _('reply'),
200                                                                    'class' => 'replybutton'));
201                 common_raw(' &#8594;');
202                 common_element_end('a');
203     }
204
205     function show_delete_link() {
206         $user = common_current_user();
207                 if ($user && $this->notice->profile_id == $user->id) {
208                         $deleteurl = common_local_url('deletenotice', array('notice' => $this->notice->id));
209                         common_element_start('a', array('class' => 'deletenotice',
210                                                                                         'href' => $deleteurl,
211                                                                                         'title' => _('delete')));
212                         common_raw(' &#215;');
213                         common_element_end('a');
214                 }
215     }
216
217     function show_end_time_section() {
218                 common_element_end('p');
219     }
220
221     function show_end() {
222                 common_element_end('li');
223     }
224 }