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
52 class ThreadedNoticeList extends NoticeList
55 * show the list of notices
57 * "Uses up" the stream by looping through it. So, probably can't
58 * be called twice on the same list.
60 * @return int count of notices listed.
65 $this->out->elementStart('div', array('id' =>'notices_primary'));
66 $this->out->element('h2', null, _('Notices'));
67 $this->out->elementStart('ol', array('class' => 'notices xoxo'));
70 $conversations = array();
71 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
72 $convo = $this->notice->conversation;
73 if (!empty($conversations[$convo])) {
74 // Seen this convo already -- skip!
77 $conversations[$convo] = true;
79 // Get the convo's root notice
80 // @fixme stream goes in wrong direction, this needs sane caching
81 //$notice = Notice::conversationStream($convo, 0, 1);
83 $notice = new Notice();
84 $notice->conversation = $this->notice->conversation;
85 $notice->orderBy('CREATED');
91 if ($cnt > NOTICES_PER_PAGE) {
96 $item = $this->newListItem($notice);
98 } catch (Exception $e) {
99 // we log exceptions and continue
100 common_log(LOG_ERR, $e->getMessage());
105 $this->out->elementEnd('ol');
106 $this->out->elementEnd('div');
112 * returns a new list item for the current notice
114 * Recipe (factory?) method; overridden by sub-classes to give
115 * a different list item class.
117 * @param Notice $notice the current notice
119 * @return NoticeListItem a list item for displaying the notice
122 function newListItem($notice)
124 return new ThreadedNoticeListItem($notice, $this->out);
129 * widget for displaying a single notice
131 * This widget has the core smarts for showing a single notice: what to display,
132 * where, and under which circumstances. Its key method is show(); this is a recipe
133 * that calls all the other show*() methods to build up a single notice. The
134 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
135 * author info (since that's implicit by the data in the page).
139 * @author Evan Prodromou <evan@status.net>
140 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
141 * @link http://status.net/
143 * @see ProfileNoticeListItem
146 class ThreadedNoticeListItem extends NoticeListItem
151 * Close the last elements in the notice list item
158 $notice = Notice::conversationStream($this->notice->conversation);
160 while ($notice->fetch()) {
161 if ($notice->id == $this->notice->id) {
165 $notices[] = clone($notice); // *grumble* inefficient as hell
169 $this->out->elementStart('ul', 'notices threaded-notices xoxo');
170 foreach (array_reverse($notices) as $notice) {
171 $item = new ThreadedNoticeListSubItem($notice, $this->out);
174 if (common_current_user()) {
175 $item = new ThreadedNoticeListReplyItem($this->notice, $this->out);
178 $this->out->elementEnd('ul');
185 class ThreadedNoticeListSubItem extends NoticeListItem
188 function avatarSize()
190 return AVATAR_STREAM_SIZE; // @fixme would like something in between
193 function showNoticeLocation()
198 function showNoticeSource()
205 * Show a mini inline posting form for replies.
207 class ThreadedNoticeListReplyItem extends NoticeListItem
211 * recipe function for displaying a single notice.
213 * This uses all the other methods to correctly display a notice. Override
214 * it or one of the others to fine-tune the output.
222 $this->showMiniForm();
227 * start a single notice.
234 if (Event::handle('StartOpenNoticeListItemElement', array($this))) {
235 $id = (empty($this->repeat)) ? $this->notice->id : $this->repeat->id;
236 $this->out->elementStart('li', array('class' => 'notice-reply',
237 'id' => 'notice-reply-' . $id));
241 function showMiniForm()
243 $replyToId = $this->notice->id;
244 $id = 'replyto-notice-' + $replyToId;
245 $url = common_local_url('newnotice');
247 // @fixme replace this with an ajax-friendly form pair?
248 $this->out->elementStart('form',
250 'class' => 'replyform',
253 $this->out->hidden('token', common_session_token());
254 $this->out->hidden("$id-inreplyto", $replyToId, "inreplyto");
255 $this->out->element('textarea', array('name' => 'status_textarea'));
256 $this->out->elementStart('div', array('class' => 'controls'));
257 $this->out->submit("$id-submit", _m('Send reply'));
258 $this->out->elementEnd('div');
259 $this->out->elementEnd('form');