3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * A single list item for showing in a message list
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('STATUSNET')) {
32 // This check helps protect against security problems;
33 // your code file can't be executed directly from the web.
38 * A single item in a message list
42 * @author Evan Prodromou <evan@status.net>
43 * @copyright 2011 StatusNet, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 abstract class MessageListItem extends Widget
54 * @param HTMLOutputter $out Output context
55 * @param Message $message Message to show
57 function __construct($out, $message)
59 parent::__construct($out);
60 $this->message = $message;
70 $this->out->elementStart('li', array('class' => 'h-entry notice',
71 'id' => 'message-' . $this->message->id));
73 $profile = $this->getMessageProfile();
75 $this->out->elementStart('a', array('href' => $profile->profileurl,
76 'class' => 'p-author'));
77 $avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
78 $this->out->element('img', array('src' => $avatarUrl,
79 'class' => 'avatar u-photo',
80 'width' => AVATAR_STREAM_SIZE,
81 'height' => AVATAR_STREAM_SIZE,
82 'alt' => $profile->getBestName()));
83 $this->out->element('span', array('class' => 'nickname fn'), $profile->getNickname());
84 $this->out->elementEnd('a');
86 // FIXME: URL, image, video, audio
87 $this->out->elementStart('div', array('class' => 'e-content'));
88 $this->out->raw($this->message->rendered);
89 $this->out->elementEnd('div');
91 $messageurl = common_local_url('showmessage',
92 array('message' => $this->message->id));
94 // XXX: we need to figure this out better. Is this right?
95 if (strcmp($this->message->uri, $messageurl) != 0 &&
96 preg_match('/^http/', $this->message->uri)) {
97 $messageurl = $this->message->uri;
100 $this->out->elementStart('div', 'entry-metadata');
101 $this->out->elementStart('a', array('rel' => 'bookmark',
102 'class' => 'timestamp',
103 'href' => $messageurl));
104 $dt = common_date_iso8601($this->message->created);
105 $this->out->element('time', array('class' => 'dt-published',
106 'datetime' => common_date_iso8601($this->message->created),
107 // TRANS: Timestamp title (tooltip text) for NoticeListItem
108 'title' => common_exact_date($this->message->created)),
109 common_date_string($this->message->created));
110 $this->out->elementEnd('a');
112 if ($this->message->source) {
113 $this->out->elementStart('span', 'source');
114 // FIXME: bad i18n. Device should be a parameter (from %s).
115 // TRANS: Followed by notice source (usually the client used to send the notice).
116 $this->out->text(_('from'));
117 $this->showSource($this->message->source);
118 $this->out->elementEnd('span');
120 $this->out->elementEnd('div');
122 $this->out->elementEnd('li');
126 * Dummy method. Serves no other purpose than to make strings available used
127 * in self::showSource() through xgettext.
131 function messageListItemDummyMessages()
133 // A dummy array with messages. These will get extracted by xgettext and
134 // are used in self::showSource().
135 $dummy_messages = array(
136 // TRANS: A possible notice source (web interface).
138 // TRANS: A possible notice source (XMPP).
140 // TRANS: A possible notice source (e-mail).
142 // TRANS: A possible notice source (OpenMicroBlogging).
144 // TRANS: A possible notice source (Application Programming Interface).
150 * Show the source of the message
152 * Returns either the name (and link) of the API client that posted the notice,
153 * or one of other other channels.
155 * @param string $source the source of the message
159 function showSource($source)
161 $source_name = _m('SOURCE',$source);
168 $this->out->element('span', 'device', $source_name);
171 $ns = Notice_source::getKV($source);
173 $this->out->elementStart('span', 'device');
174 $this->out->element('a', array('href' => $ns->url,
175 'rel' => 'external'),
177 $this->out->elementEnd('span');
179 $this->out->element('span', 'device', $source_name);
187 * Return the profile to show in the message item
189 * Overridden in sub-classes to show sender, receiver, or whatever
191 * @return Profile profile to show avatar and name of
193 abstract function getMessageProfile();