]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/messagelistitem.php
Extended profile - fix some issues saving and displaying dates
[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
69     function show()
70     {
71         $this->out->elementStart('li', array('class' => 'hentry notice',
72                                              'id' => 'message-' . $this->message->id));
73
74         $profile = $this->getMessageProfile();
75
76         $this->out->elementStart('div', 'entry-title');
77         $this->out->elementStart('span', 'vcard author');
78         $this->out->elementStart('a', array('href' => $profile->profileurl,
79                                             'class' => 'url'));
80         $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
81         $this->out->element('img', array('src' => ($avatar) ?
82                                          $avatar->displayUrl() :
83                                          Avatar::defaultImage(AVATAR_STREAM_SIZE),
84                                          'class' => 'photo avatar',
85                                          'width' => AVATAR_STREAM_SIZE,
86                                          'height' => AVATAR_STREAM_SIZE,
87                                          'alt' =>
88                                          ($profile->fullname) ? $profile->fullname :
89                                          $profile->nickname));
90         $this->out->element('span', array('class' => 'nickname fn'),
91                             $profile->nickname);
92         $this->out->elementEnd('a');
93         $this->out->elementEnd('span');
94
95         // FIXME: URL, image, video, audio
96         $this->out->elementStart('p', array('class' => 'entry-content'));
97         $this->out->raw($this->message->rendered);
98         $this->out->elementEnd('p');
99         $this->out->elementEnd('div');
100
101         $messageurl = common_local_url('showmessage',
102                                        array('message' => $this->message->id));
103
104         // XXX: we need to figure this out better. Is this right?
105         if (strcmp($this->message->uri, $messageurl) != 0 &&
106             preg_match('/^http/', $this->message->uri)) {
107             $messageurl = $this->message->uri;
108         }
109
110         $this->out->elementStart('div', 'entry-content');
111         $this->out->elementStart('a', array('rel' => 'bookmark',
112                                             'class' => 'timestamp',
113                                             'href' => $messageurl));
114         $dt = common_date_iso8601($this->message->created);
115         $this->out->element('abbr', array('class' => 'published',
116                                           'title' => $dt),
117                             common_date_string($this->message->created));
118         $this->out->elementEnd('a');
119
120         if ($this->message->source) {
121             $this->out->elementStart('span', 'source');
122             // FIXME: bad i18n. Device should be a parameter (from %s).
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     /**
134      * Show the source of the message
135      *
136      * Returns either the name (and link) of the API client that posted the notice,
137      * or one of other other channels.
138      *
139      * @param string $source the source of the message
140      *
141      * @return void
142      */
143     function showSource($source)
144     {
145         $source_name = _($source);
146         switch ($source) {
147         case 'web':
148         case 'xmpp':
149         case 'mail':
150         case 'omb':
151         case 'api':
152             $this->out->element('span', 'device', $source_name);
153             break;
154         default:
155             $ns = Notice_source::staticGet($source);
156             if ($ns) {
157                 $this->out->elementStart('span', 'device');
158                 $this->out->element('a', array('href' => $ns->url,
159                                                'rel' => 'external'),
160                                     $ns->name);
161                 $this->out->elementEnd('span');
162             } else {
163                 $this->out->element('span', 'device', $source_name);
164             }
165             break;
166         }
167         return;
168     }
169
170     /**
171      * Return the profile to show in the message item
172      *
173      * Overridden in sub-classes to show sender, receiver, or whatever
174      *
175      * @return Profile profile to show avatar and name of
176      */
177     abstract function getMessageProfile();
178 }