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
53 class NoticeList extends Widget
55 /** the current stream of notices being displayed. */
62 * @param Notice $notice stream of notices from DB_DataObject
65 function __construct($notice, $out=null)
67 parent::__construct($out);
68 $this->notice = $notice;
72 * show the list of notices
74 * "Uses up" the stream by looping through it. So, probably can't
75 * be called twice on the same list.
77 * @return int count of notices listed.
82 $this->out->elementStart('div', array('id' =>'notices_primary'));
83 $this->out->element('h2', null, _('Notices'));
84 $this->out->elementStart('ul', array('class' => 'notices'));
88 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
91 if ($cnt > NOTICES_PER_PAGE) {
95 $item = $this->newListItem($this->notice);
99 $this->out->elementEnd('ul');
100 $this->out->elementEnd('div');
106 * returns a new list item for the current notice
108 * Recipe (factory?) method; overridden by sub-classes to give
109 * a different list item class.
111 * @param Notice $notice the current notice
113 * @return NoticeListItem a list item for displaying the notice
116 function newListItem($notice)
118 return new NoticeListItem($notice, $this->out);
123 * widget for displaying a single notice
125 * This widget has the core smarts for showing a single notice: what to display,
126 * where, and under which circumstances. Its key method is show(); this is a recipe
127 * that calls all the other show*() methods to build up a single notice. The
128 * ProfileNoticeListItem subclass, for example, overrides showAuthor() to skip
129 * author info (since that's implicit by the data in the page).
133 * @author Evan Prodromou <evan@controlyourself.ca>
134 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
135 * @link http://laconi.ca/
137 * @see ProfileNoticeListItem
140 class NoticeListItem extends Widget
142 /** The notice this item will show. */
146 /** The profile of the author of the notice, extracted once for convenience. */
153 * Also initializes the profile attribute.
155 * @param Notice $notice The notice we'll display
158 function __construct($notice, $out=null)
160 parent::__construct($out);
161 $this->notice = $notice;
162 $this->profile = $notice->getProfile();
166 * recipe function for displaying a single notice.
168 * This uses all the other methods to correctly display a notice. Override
169 * it or one of the others to fine-tune the output.
178 $this->showNoticeInfo();
179 $this->showNoticeOptions();
183 function showNotice()
185 $this->out->elementStart('div', 'entry-title');
187 $this->showContent();
188 $this->out->elementEnd('div');
191 function showNoticeInfo()
193 $this->out->elementStart('div', 'entry-content');
194 $this->showNoticeLink();
195 $this->showNoticeSource();
196 $this->showReplyTo();
197 $this->out->elementEnd('div');
200 function showNoticeOptions()
202 $this->out->elementStart('div', 'notice-options');
203 $this->showFaveForm();
204 $this->showReplyLink();
205 $this->showDeleteLink();
206 $this->out->elementEnd('div');
211 * start a single notice.
219 // TODO: add notice_type class e.g., notice_video, notice_image
220 $this->out->elementStart('li', array('class' => 'hentry notice',
221 'id' => 'notice-' . $this->notice->id));
225 * show the "favorite" form
230 function showFaveForm()
232 $user = common_current_user();
234 if ($user->hasFave($this->notice)) {
235 $disfavor = new DisfavorForm($this->out, $this->notice);
238 $favor = new FavorForm($this->out, $this->notice);
245 * show the author of a notice
247 * By default, this shows the avatar and (linked) nickname of the author.
252 function showAuthor()
254 $this->out->elementStart('span', 'vcard author');
255 $this->out->elementStart('a', array('href' => $this->profile->profileurl,
258 $this->showNickname();
259 $this->out->elementEnd('a');
260 $this->out->elementEnd('span');
264 * show the avatar of the notice's author
266 * This will use the default avatar if no avatar is assigned for the author.
267 * It makes a link to the author's profile.
272 function showAvatar()
274 $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
276 $this->out->element('img', array('src' => ($avatar) ?
277 common_avatar_display_url($avatar) :
278 common_default_avatar(AVATAR_STREAM_SIZE),
279 'class' => 'avatar photo',
280 'width' => AVATAR_STREAM_SIZE,
281 'height' => AVATAR_STREAM_SIZE,
283 ($this->profile->fullname) ?
284 $this->profile->fullname :
285 $this->profile->nickname));
289 * show the nickname of the author
291 * Links to the author's profile page
296 function showNickname()
298 $this->out->element('span', array('class' => 'nickname fn'),
299 $this->profile->nickname);
303 * show the content of the notice
305 * Shows the content of the notice. This is pre-rendered for efficiency
306 * at save time. Some very old notices might not be pre-rendered, so
307 * they're rendered on the spot.
312 function showContent()
314 // FIXME: URL, image, video, audio
315 $this->out->elementStart('p', array('class' => 'entry-content'));
316 if ($this->notice->rendered) {
317 $this->out->raw($this->notice->rendered);
319 // XXX: may be some uncooked notices in the DB,
320 // we cook them right now. This should probably disappear in future
321 // versions (>> 0.4.x)
322 $this->out->raw(common_render_content($this->notice->content, $this->notice));
324 $this->out->elementEnd('p');
328 * show the link to the main page for the notice
330 * Displays a link to the page for a notice, with "relative" time. Tries to
331 * get remote notice URLs correct, but doesn't always succeed.
336 function showNoticeLink()
338 $noticeurl = common_local_url('shownotice',
339 array('notice' => $this->notice->id));
340 // XXX: we need to figure this out better. Is this right?
341 if (strcmp($this->notice->uri, $noticeurl) != 0 &&
342 preg_match('/^http/', $this->notice->uri)) {
343 $noticeurl = $this->notice->uri;
345 $this->out->elementStart('dl', 'timestamp');
346 $this->out->element('dt', _('Published'));
347 $this->out->elementStart('dd', null);
348 $this->out->elementStart('a', array('rel' => 'bookmark',
349 'href' => $noticeurl));
350 $dt = common_date_iso8601($this->notice->created);
351 $this->out->element('abbr', array('class' => 'published',
353 common_date_string($this->notice->created));
354 $this->out->elementEnd('a');
355 $this->out->elementEnd('dd');
356 $this->out->elementEnd('dl');
360 * Show the source of the notice
362 * Either the name (and link) of the API client that posted the notice,
363 * or one of other other channels.
368 function showNoticeSource()
370 if ($this->notice->source) {
371 $this->out->elementStart('dl', 'device');
372 $this->out->element('dt', null, _('From'));
373 $source_name = _($this->notice->source);
374 switch ($this->notice->source) {
380 $this->out->element('dd', 'noticesource', $source_name);
383 $ns = Notice_source::staticGet($this->notice->source);
385 $this->out->elementStart('dd', null);
386 $this->out->element('a', array('href' => $ns->url,
387 'rel' => 'external'),
389 $this->out->elementEnd('dd');
391 $this->out->element('dd', 'noticesource', $source_name);
395 $this->out->elementEnd('dl');
400 * show link to notice this notice is a reply to
402 * If this notice is a reply, show a link to the notice it is replying to. The
403 * heavy lifting for figuring out replies happens at save time.
408 function showReplyTo()
410 if ($this->notice->reply_to) {
411 $replyurl = common_local_url('shownotice',
412 array('notice' => $this->notice->reply_to));
413 $this->out->elementStart('dl', 'response');
414 $this->out->element('dt', null, _('To'));
415 $this->out->elementStart('dd');
416 $this->out->element('a', array('href' => $replyurl,
417 'rel' => 'in-reply-to'),
419 $this->out->elementEnd('dd');
420 $this->out->elementEnd('dl');
425 * show a link to reply to the current notice
427 * Should either do the reply in the current notice form (if available), or
428 * link out to the notice-posting form. A little flakey, doesn't always work.
433 function showReplyLink()
435 $reply_url = common_local_url('newnotice',
436 array('replyto' => $this->profile->nickname));
439 'return doreply("'.$this->profile->nickname.'",'.$this->notice->id.');';
441 $this->out->elementStart('a',
442 array('href' => $reply_url,
443 'onclick' => $reply_js,
444 'title' => _('reply'),
445 'class' => 'replybutton'));
446 $this->out->raw(' →');
447 $this->out->elementEnd('a');
451 * if the user is the author, let them delete the notice
456 function showDeleteLink()
458 $user = common_current_user();
459 if ($user && $this->notice->profile_id == $user->id) {
460 $deleteurl = common_local_url('deletenotice',
461 array('notice' => $this->notice->id));
462 $this->out->elementStart('a', array('class' => 'deletenotice',
463 'href' => $deleteurl,
464 'title' => _('delete')));
465 $this->out->raw(' ×');
466 $this->out->elementEnd('a');
473 * Close the last elements in the notice list item
480 $this->out->elementEnd('li');