3 * Laconica, the distributed open-source microblogging tool
5 * widget for displaying a list of notices
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.
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.
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/>.
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/
30 if (!defined('LACONICA')) {
35 * widget for displaying a list of notices
37 * There are a number of actions that display a list of notices, in
38 * reverse chronological order. This widget abstracts out most of the
39 * code for UI for notice lists. It's overridden to hide some
40 * data for e.g. the profile page.
44 * @author Evan Prodromou <evan@controlyourself.ca>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://laconi.ca/
50 * @see ProfileNoticeList
55 /** the current stream of notices being displayed. */
62 * @param Notice $notice stream of notices from DB_DataObject
65 function __construct($notice)
67 $this->notice = $notice;
71 * show the list of notices
73 * "Uses up" the stream by looping through it. So, probably can't
74 * be called twice on the same list.
76 * @return int count of notices listed.
81 common_element_start('ul', array('id' => 'notices'));
85 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
88 if ($cnt > NOTICES_PER_PAGE) {
92 $item = $this->newListItem($this->notice);
96 common_element_end('ul');
102 * returns a new list item for the current notice
104 * Recipe (factory?) method; overridden by sub-classes to give
105 * a different list item class.
107 * @param Notice $notice the current notice
109 * @return NoticeListItem a list item for displaying the notice
112 function newListItem($notice)
114 return new NoticeListItem($notice);
119 * widget for displaying a single notice
121 * This widget has the core smarts for showing a single notice: what to display,
122 * where, and under which circumstances. Its key method is show(); this is a recipe
123 * that calls all the other show*() methods to build up a single notice. The
124 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
125 * author info (since that's implicit by the data in the page).
129 * @author Evan Prodromou <evan@controlyourself.ca>
130 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
131 * @link http://laconi.ca/
133 * @see ProfileNoticeListItem
138 /** The notice this item will show. */
142 /** The profile of the author of the notice, extracted once for convenience. */
149 * Also initializes the profile attribute.
151 * @param Notice $notice The notice we'll display
154 function __construct($notice)
156 $this->notice = $notice;
157 $this->profile = $notice->getProfile();
161 * recipe function for displaying a single notice.
163 * This uses all the other methods to correctly display a notice. Override
164 * it or one of the others to fine-tune the output.
172 $this->showFaveForm();
174 $this->showContent();
175 $this->startTimeSection();
176 $this->showNoticeLink();
177 $this->showNoticeSource();
178 $this->showReplyTo();
179 $this->showReplyLink();
180 $this->showDeleteLink();
181 $this->endTimeSection();
186 * start a single notice.
194 // TODO: add notice_type class e.g., notice_video, notice_image
195 common_element_start('li', array('class' => 'hentry notice',
196 'id' => 'notice-' . $this->notice->id));
200 * show the "favorite" form
205 function showFaveForm()
207 $user = common_current_user();
209 if ($user->hasFave($this->notice)) {
210 common_disfavor_form($this->notice);
212 common_favor_form($this->notice);
218 * show the author of a notice
220 * By default, this shows the avatar and (linked) nickname of the author.
225 function showAuthor()
227 common_element_start('span', 'vcard author');
228 common_element_start('a', array('href' => $this->profile->profileurl),
231 $this->showNickname();
232 common_element_end('a');
233 common_element_end('span');
237 * show the avatar of the notice's author
239 * This will use the default avatar if no avatar is assigned for the author.
240 * It makes a link to the author's profile.
245 function showAvatar()
247 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
249 common_element('img', array('src' => ($avatar) ?
250 common_avatar_display_url($avatar) :
251 common_default_avatar(AVATAR_STREAM_SIZE),
252 'class' => 'avatar photo',
253 'width' => AVATAR_STREAM_SIZE,
254 'height' => AVATAR_STREAM_SIZE,
256 ($this->profile->fullname) ?
257 $this->profile->fullname :
258 $this->profile->nickname));
262 * show the nickname of the author
264 * Links to the author's profile page
269 function showNickname()
271 common_element('span', array('class' => 'nickname fn'),
272 $this->profile->nickname);
276 * show the content of the notice
278 * Shows the content of the notice. This is pre-rendered for efficiency
279 * at save time. Some very old notices might not be pre-rendered, so
280 * they're rendered on the spot.
285 function showContent()
287 // FIXME: URL, image, video, audio
288 common_element_start('p', array('class' => 'content entry-title'));
289 if ($this->notice->rendered) {
290 common_raw($this->notice->rendered);
292 // XXX: may be some uncooked notices in the DB,
293 // we cook them right now. This should probably disappear in future
294 // versions (>> 0.4.x)
295 common_raw(common_render_content($this->notice->content, $this->notice));
297 common_element_end('p');
301 * show the "time" section of a notice
303 * This is the greyed-out section that appears beneath the content, including
304 * links to delete or reply to the notice. Probably should be called something
310 function startTimeSection()
312 common_element_start('p', 'time');
316 * show the link to the main page for the notice
318 * Displays a link to the page for a notice, with "relative" time. Tries to
319 * get remote notice URLs correct, but doesn't always succeed.
324 function showNoticeLink()
326 $noticeurl = common_local_url('shownotice',
327 array('notice' => $this->notice->id));
328 // XXX: we need to figure this out better. Is this right?
329 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
330 preg_match('/^http/', $this->notice->uri)) {
331 $noticeurl = $this->notice->uri;
333 common_element_start('a', array('class' => 'permalink',
335 'href' => $noticeurl));
336 $dt = common_date_iso8601($this->notice->created);
337 common_element('abbr', array('class' => 'published',
339 common_date_string($this->notice->created));
340 common_element_end('a');
344 * Show the source of the notice
346 * Either the name (and link) of the API client that posted the notice,
347 * or one of other other channels.
352 function showNoticeSource()
354 if ($this->notice->source) {
355 common_element('span', null, _(' from '));
356 $source_name = _($this->notice->source);
357 switch ($this->notice->source) {
363 common_element('span', 'noticesource', $source_name);
366 $ns = Notice_source::staticGet($this->notice->source);
368 common_element('a', array('href' => $ns->url),
371 common_element('span', 'noticesource', $source_name);
379 * show link to notice this notice is a reply to
381 * If this notice is a reply, show a link to the notice it is replying to. The
382 * heavy lifting for figuring out replies happens at save time.
387 function showReplyTo()
389 if ($this->notice->reply_to) {
390 $replyurl = common_local_url('shownotice',
391 array('notice' => $this->notice->reply_to));
392 $this->elementStart('dl', 'response');
393 $this->element('dt', null, _('To'));
394 $this->elementStart('dd');
395 $this->element('a', array('class' => 'inreplyto',
396 'href' => $replyurl),
397 'rel' => 'in-reply-to',
399 $this->elementEnd('dd');
400 $this->elementEnd('dl');
405 * show a link to reply to the current notice
407 * Should either do the reply in the current notice form (if available), or
408 * link out to the notice-posting form. A little flakey, doesn't always work.
413 function showReplyLink()
415 $reply_url = common_local_url('newnotice',
416 array('replyto' => $this->profile->nickname));
419 'return doreply("'.$this->profile->nickname.'",'.$this->notice->id.');';
421 common_element_start('a',
422 array('href' => $reply_url,
423 'onclick' => $reply_js,
424 'title' => _('reply'),
425 'class' => 'replybutton'));
426 common_raw(' →');
427 common_element_end('a');
431 * if the user is the author, let them delete the notice
436 function showDeleteLink()
438 $user = common_current_user();
439 if ($user && $this->notice->profile_id == $user->id) {
440 $deleteurl = common_local_url('deletenotice',
441 array('notice' => $this->notice->id));
442 common_element_start('a', array('class' => 'deletenotice',
443 'href' => $deleteurl,
444 'title' => _('delete')));
445 common_raw(' ×');
446 common_element_end('a');
451 * end the time section
456 function endTimeSection()
458 common_element_end('p');
464 * Close the last elements in the notice list item
471 common_element_end('li');