]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/messagelistitem.php
Start tracking alpha release numbers
[quix0rs-gnu-social.git] / lib / messagelistitem.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * A single list item for showing in a message list
7  *
8  * PHP version 5
9  *
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.
14  *
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.
19  *
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/>.
22  *
23  * @category  Widget
24  * @package   StatusNet
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/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * A single item in a message list
39  *
40  * @category  Widget
41  * @package   StatusNet
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/
46  */
47 abstract class MessageListItem extends Widget
48 {
49     var $message;
50
51     /**
52      * Constructor
53      *
54      * @param HTMLOutputter $out     Output context
55      * @param Message       $message Message to show
56      */
57     function __construct($out, $message)
58     {
59         parent::__construct($out);
60         $this->message = $message;
61     }
62
63     /**
64      * Show the widget
65      *
66      * @return void
67      */
68     function show()
69     {
70         $this->out->elementStart('li', array('class' => 'hentry notice',
71                                              'id' => 'message-' . $this->message->id));
72
73         $profile = $this->getMessageProfile();
74
75         $this->out->elementStart('div', 'entry-title');
76         $this->out->elementStart('span', 'vcard author');
77         $this->out->elementStart('a', array('href' => $profile->profileurl,
78                                             'class' => 'url'));
79         $avatarUrl = $profile->avatarUrl(AVATAR_STREAM_SIZE);
80         $this->out->element('img', array('src' => $avatarUrl,
81                                          'class' => 'photo avatar',
82                                          'width' => AVATAR_STREAM_SIZE,
83                                          'height' => AVATAR_STREAM_SIZE,
84                                          'alt' =>
85                                          ($profile->fullname) ? $profile->fullname :
86                                          $profile->nickname));
87         $this->out->element('span', array('class' => 'nickname fn'),
88                             $profile->nickname);
89         $this->out->elementEnd('a');
90         $this->out->elementEnd('span');
91
92         // FIXME: URL, image, video, audio
93         $this->out->elementStart('p', array('class' => 'entry-content'));
94         $this->out->raw($this->message->rendered);
95         $this->out->elementEnd('p');
96         $this->out->elementEnd('div');
97
98         $messageurl = common_local_url('showmessage',
99                                        array('message' => $this->message->id));
100
101         // XXX: we need to figure this out better. Is this right?
102         if (strcmp($this->message->uri, $messageurl) != 0 &&
103             preg_match('/^http/', $this->message->uri)) {
104             $messageurl = $this->message->uri;
105         }
106
107         $this->out->elementStart('div', 'entry-content');
108         $this->out->elementStart('a', array('rel' => 'bookmark',
109                                             'class' => 'timestamp',
110                                             'href' => $messageurl));
111         $dt = common_date_iso8601($this->message->created);
112         $this->out->element('time', array('class' => 'dt-published',
113                                           'datetime' => common_date_iso8601($this->message->created),
114                                           // TRANS: Timestamp title (tooltip text) for NoticeListItem
115                                           'title' => common_exact_date($this->message->created)),
116                             common_date_string($this->message->created));
117         $this->out->elementEnd('a');
118
119         if ($this->message->source) {
120             $this->out->elementStart('span', 'source');
121             // FIXME: bad i18n. Device should be a parameter (from %s).
122             // TRANS: Followed by notice source (usually the client used to send the notice).
123             $this->out->text(_('from'));
124             $this->showSource($this->message->source);
125             $this->out->elementEnd('span');
126         }
127         $this->out->elementEnd('div');
128
129         $this->out->elementEnd('li');
130     }
131
132     /**
133      * Dummy method. Serves no other purpose than to make strings available used
134      * in self::showSource() through xgettext.
135      *
136      * @return void
137      */
138     function messageListItemDummyMessages()
139     {
140         // A dummy array with messages. These will get extracted by xgettext and
141         // are used in self::showSource().
142         $dummy_messages = array(
143             // TRANS: A possible notice source (web interface).
144             _m('SOURCE','web'),
145             // TRANS: A possible notice source (XMPP).
146             _m('SOURCE','xmpp'),
147             // TRANS: A possible notice source (e-mail).
148             _m('SOURCE','mail'),
149             // TRANS: A possible notice source (OpenMicroBlogging).
150             _m('SOURCE','omb'),
151             // TRANS: A possible notice source (Application Programming Interface).
152             _m('SOURCE','api'),
153         );
154     }
155
156     /**
157      * Show the source of the message
158      *
159      * Returns either the name (and link) of the API client that posted the notice,
160      * or one of other other channels.
161      *
162      * @param string $source the source of the message
163      *
164      * @return void
165      */
166     function showSource($source)
167     {
168         $source_name = _m('SOURCE',$source);
169         switch ($source) {
170         case 'web':
171         case 'xmpp':
172         case 'mail':
173         case 'omb':
174         case 'api':
175             $this->out->element('span', 'device', $source_name);
176             break;
177         default:
178             $ns = Notice_source::getKV($source);
179             if ($ns) {
180                 $this->out->elementStart('span', 'device');
181                 $this->out->element('a', array('href' => $ns->url,
182                                                'rel' => 'external'),
183                                     $ns->name);
184                 $this->out->elementEnd('span');
185             } else {
186                 $this->out->element('span', 'device', $source_name);
187             }
188             break;
189         }
190         return;
191     }
192
193     /**
194      * Return the profile to show in the message item
195      *
196      * Overridden in sub-classes to show sender, receiver, or whatever
197      *
198      * @return Profile profile to show avatar and name of
199      */
200     abstract function getMessageProfile();
201 }