3 * StatusNet, 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 Brion Vibber <brion@status.net>
25 * @copyright 2011 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET') && !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@status.net>
45 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46 * @link http://status.net/
49 * @see ProfileNoticeList
51 class ThreadedNoticeList extends NoticeList
54 * show the list of notices
56 * "Uses up" the stream by looping through it. So, probably can't
57 * be called twice on the same list.
59 * @return int count of notices listed.
63 $this->out->elementStart('div', array('id' =>'notices_primary'));
64 // TRANS: Header for Notices section.
65 $this->out->element('h2', null, _m('HEADER','Notices'));
66 $this->out->elementStart('ol', array('class' => 'notices threaded-notices xoxo'));
69 $conversations = array();
70 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
73 if ($cnt > NOTICES_PER_PAGE) {
77 // Collapse repeats into their originals...
78 $notice = $this->notice;
79 if ($notice->repeat_of) {
80 $orig = Notice::staticGet('id', $notice->repeat_of);
85 $convo = $notice->conversation;
86 if (!empty($conversations[$convo])) {
87 // Seen this convo already -- skip!
90 $conversations[$convo] = true;
92 // Get the convo's root notice
93 $root = $notice->conversationRoot();
99 $item = $this->newListItem($notice);
101 } catch (Exception $e) {
102 // we log exceptions and continue
103 common_log(LOG_ERR, $e->getMessage());
108 $this->out->elementEnd('ol');
109 $this->out->elementEnd('div');
115 * returns a new list item for the current notice
117 * Recipe (factory?) method; overridden by sub-classes to give
118 * a different list item class.
120 * @param Notice $notice the current notice
122 * @return NoticeListItem a list item for displaying the notice
124 function newListItem($notice)
126 return new ThreadedNoticeListItem($notice, $this->out);
131 * widget for displaying a single notice
133 * This widget has the core smarts for showing a single notice: what to display,
134 * where, and under which circumstances. Its key method is show(); this is a recipe
135 * that calls all the other show*() methods to build up a single notice. The
136 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
137 * author info (since that's implicit by the data in the page).
141 * @author Evan Prodromou <evan@status.net>
142 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
143 * @link http://status.net/
145 * @see ProfileNoticeListItem
147 class ThreadedNoticeListItem extends NoticeListItem
149 function initialItems()
154 function showContext()
162 * Close the last elements in the notice list item
168 $max = $this->initialItems();
169 if (!$this->repeat) {
170 $notice = Notice::conversationStream($this->notice->conversation, 0, $max + 2);
174 while ($notice->fetch()) {
175 if ($notice->id == $this->notice->id) {
182 $moreCutoff = clone($notice);
185 $notices[] = clone($notice); // *grumble* inefficient as hell
188 $this->out->elementStart('ul', 'notices threaded-replies xoxo');
190 $item = new ThreadedNoticeListFavesItem($this->notice, $this->out);
191 $hasFaves = $item->show();
193 $item = new ThreadedNoticeListRepeatsItem($this->notice, $this->out);
194 $hasRepeats = $item->show();
198 $item = new ThreadedNoticeListMoreItem($moreCutoff, $this->out);
201 foreach (array_reverse($notices) as $notice) {
202 $item = new ThreadedNoticeListSubItem($notice, $this->out);
206 if ($notices || $hasFaves || $hasRepeats) {
207 // @fixme do a proper can-post check that's consistent
209 if (common_current_user()) {
210 $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
214 $this->out->elementEnd('ul');
221 // @todo FIXME: needs documentation.
222 class ThreadedNoticeListSubItem extends NoticeListItem
224 function avatarSize()
226 return AVATAR_STREAM_SIZE; // @fixme would like something in between
229 function showNoticeLocation()
234 function showNoticeSource()
239 function showContext()
246 $item = new ThreadedNoticeListInlineFavesItem($this->notice, $this->out);
247 $hasFaves = $item->show();
253 * Placeholder for loading more replies...
255 class ThreadedNoticeListMoreItem extends NoticeListItem
258 * recipe function for displaying a single notice.
260 * This uses all the other methods to correctly display a notice. Override
261 * it or one of the others to fine-tune the output.
268 $this->showMiniForm();
273 * start a single notice.
279 $this->out->elementStart('li', array('class' => 'notice-reply-comments'));
282 function showMiniForm()
284 $id = $this->notice->conversation;
285 $url = common_local_url('conversationreplies', array('id' => $id));
287 $notice = new Notice();
288 $notice->conversation = $id;
289 $n = $notice->count() - 1;
290 // TRANS: Link to show replies for a notice.
291 // TRANS: %d is the number of replies to a notice and used for plural.
292 $msg = sprintf(_m('Show reply', 'Show all %d replies', $n), $n);
294 $this->out->element('a', array('href' => $url), $msg);
299 * Placeholder for reply form...
300 * Same as get added at runtime via SN.U.NoticeInlineReplyPlaceholder
302 class ThreadedNoticeListReplyItem extends NoticeListItem
305 * recipe function for displaying a single notice.
307 * This uses all the other methods to correctly display a notice. Override
308 * it or one of the others to fine-tune the output.
315 $this->showMiniForm();
320 * start a single notice.
326 $this->out->elementStart('li', array('class' => 'notice-reply-placeholder'));
329 function showMiniForm()
331 $this->out->element('input', array('class' => 'placeholder',
332 // TRANS: Field label for reply mini form.
333 'value' => _('Write a reply...')));
338 * Placeholder for showing faves...
340 abstract class NoticeListActorsItem extends NoticeListItem
343 * @return array of profile IDs
345 abstract function getProfiles();
347 abstract function getListMessage($count, $you);
353 $cur = common_current_user();
354 foreach ($this->getProfiles() as $id) {
355 if ($cur && $cur->id == $id) {
357 // TRANS: Reference to the logged in user in favourite list.
358 array_unshift($links, _m('FAVELIST', 'You'));
360 $profile = Profile::staticGet('id', $id);
362 $links[] = sprintf('<a href="%s" title="%s">%s</a>',
363 htmlspecialchars($profile->profileurl),
364 htmlspecialchars($profile->getBestName()),
365 htmlspecialchars($profile->nickname));
371 $count = count($links);
372 $msg = $this->getListMessage($count, $you);
373 $out = sprintf($msg, $this->magicList($links));
376 $this->out->raw($out);
384 function magicList($items)
386 if (count($items) == 0) {
388 } else if (count($items) == 1) {
391 $first = array_slice($items, 0, -1);
392 $last = array_slice($items, -1, 1);
393 // TRANS: Separator in list of user names like "You, Bob, Mary".
394 $sepataror = _(', ');
395 // TRANS: For building a list such as "You, bob, mary and 5 others have favored this notice".
396 // TRANS: %1$s is a list of users, separated by a separator (default: ", "), %2$s is the last user in the list.
397 return sprintf(_m('FAVELIST', '%1$s and %2$s'), implode($separator, $first), implode($separator, $last));
403 * Placeholder for showing faves...
405 class ThreadedNoticeListFavesItem extends NoticeListActorsItem
407 function getProfiles()
409 $fave = Fave::byNotice($this->notice->id);
411 while ($fave->fetch()) {
412 $profiles[] = $fave->user_id;
417 function getListMessage($count, $you)
419 if ($count == 1 && $you) {
420 // darn first person being different from third person!
421 // TRANS: List message for notice favoured by logged in user.
422 return _m('FAVELIST', 'You have favored this notice.');
424 // TRANS: List message for favoured notices.
425 // TRANS: %d is the number of users that have favoured a notice.
428 'One person has favored this notice.',
429 '%d people have favored this notice.',
437 $this->out->elementStart('li', array('class' => 'notice-data notice-faves'));
442 $this->out->elementEnd('li');
447 // @todo FIXME: needs documentation.
448 class ThreadedNoticeListInlineFavesItem extends ThreadedNoticeListFavesItem
452 $this->out->elementStart('div', array('class' => 'entry-content notice-faves'));
457 $this->out->elementEnd('div');
462 * Placeholder for showing faves...
464 class ThreadedNoticeListRepeatsItem extends NoticeListActorsItem
466 function getProfiles()
468 $rep = $this->notice->repeatStream();
471 while ($rep->fetch()) {
472 $profiles[] = $rep->profile_id;
477 function getListMessage($count, $you)
479 if ($count == 1 && $you) {
480 // darn first person being different from third person!
481 // TRANS: List message for notice repeated by logged in user.
482 return _m('REPEATLIST', 'You have repeated this notice.');
484 // TRANS: List message for repeated notices.
485 // TRANS: %d is the number of users that have repeated a notice.
488 'One person has repeated this notice.',
489 '%d people have repeated this notice.',
497 $this->out->elementStart('li', array('class' => 'notice-data notice-repeats'));
502 $this->out->elementEnd('li');