3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
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.
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.
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/>.
20 if (!defined('LACONICA')) { exit(1); }
26 function __construct($notice) {
27 $this->notice = $notice;
32 common_element_start('ul', array('id' => 'notices'));
36 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
39 if ($cnt > NOTICES_PER_PAGE) {
43 $item = $this->new_list_item($this->notice);
47 common_element_end('ul');
52 function new_list_item($notice) {
53 return new NoticeListItem($notice);
57 class NoticeListItem {
62 function __construct($notice) {
63 $this->notice = $notice;
64 $this->profile = $notice->getProfile();
69 $this->show_fave_form();
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();
82 function show_start() {
84 common_element_start('li', array('class' => 'notice_single hentry',
85 'id' => 'notice-' . $this->notice->id));
88 function show_fave_form() {
89 $user = common_current_user();
91 if ($user->hasFave($this->notice)) {
92 common_disfavor_form($this->notice);
94 common_favor_form($this->notice);
99 function show_author() {
100 common_element_start('span', 'vcard author');
101 $this->show_avatar();
102 $this->show_nickname();
103 common_element_end('span');
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,
114 ($this->profile->fullname) ? $this->profile->fullname :
115 $this->profile->nickname));
116 common_element_end('a');
119 function show_nickname() {
120 common_element('a', array('href' => $this->profile->profileurl,
121 'class' => 'nickname fn url'),
122 $this->profile->nickname);
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);
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));
136 common_element_end('p');
139 function show_start_time_section() {
140 common_element_start('p', 'time');
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;
149 common_element_start('a', array('class' => 'permalink',
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');
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) {
168 common_element('span', 'noticesource', $source_name);
171 $ns = Notice_source::staticGet($this->notice->source);
173 common_element('a', array('href' => $ns->url),
176 common_element('span', 'noticesource', $source_name);
183 function show_reply_to() {
184 if ($this->notice->reply_to) {
185 $replyurl = common_local_url('shownotice', array('notice' => $this->notice->reply_to));
187 common_element('a', array('class' => 'inreplyto',
188 'href' => $replyurl),
189 _('in reply to...'));
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(' →');
202 common_element_end('a');
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(' ×');
213 common_element_end('a');
217 function show_end_time_section() {
218 common_element_end('p');
221 function show_end() {
222 common_element_end('li');