]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/stream.php
fix error storing uris of remote notices
[quix0rs-gnu-social.git] / lib / stream.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class StreamAction extends Action {
23
24         function is_readonly() {
25                 return true;
26         }
27
28         function handle($args) {
29                 parent::handle($args);
30                 common_set_returnto($this->self_url());
31         }
32
33         function views_menu() {
34
35                 $user = NULL;
36                 $action = $this->trimmed('action');
37                 $nickname = $this->trimmed('nickname');
38
39                 if ($nickname) {
40                         $user = User::staticGet('nickname', $nickname);
41                         $user_profile = $user->getProfile();
42                 } else {
43                         $user_profile = false;
44                 }
45
46                 common_element_start('ul', array('id' => 'nav_views'));
47
48                 common_menu_item(common_local_url('all', array('nickname' =>
49                                                                                                            $nickname)),
50                                                  _('Personal'),
51                                                  sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
52                                                  $action == 'all');
53                 common_menu_item(common_local_url('replies', array('nickname' =>
54                                                                                                                           $nickname)),
55                                                  _('Replies'),
56                                                  sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
57                                                  $action == 'replies');
58                 common_menu_item(common_local_url('showstream', array('nickname' =>
59                                                                                                                           $nickname)),
60                                                  _('Profile'),
61                                                  ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
62                                                  $action == 'showstream');
63                 common_element_end('ul');
64         }
65
66         function show_notice($notice) {
67                 global $config;
68                 $profile = $notice->getProfile();
69                 $user = common_current_user();
70
71                 # XXX: RDFa
72                 common_element_start('li', array('class' => 'notice_single',
73                                                                                   'id' => 'notice-' . $notice->id));
74                 $avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
75                 common_element_start('a', array('href' => $profile->profileurl));
76                 common_element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
77                                                                         'class' => 'avatar stream',
78                                                                         'width' => AVATAR_STREAM_SIZE,
79                                                                         'height' => AVATAR_STREAM_SIZE,
80                                                                         'alt' =>
81                                                                         ($profile->fullname) ? $profile->fullname :
82                                                                         $profile->nickname));
83                 common_element_end('a');
84                 common_element('a', array('href' => $profile->profileurl,
85                                                                   'class' => 'nickname'),
86                                            $profile->nickname);
87                 # FIXME: URL, image, video, audio
88                 common_element_start('p', array('class' => 'content'));
89                 if ($notice->rendered) {
90                         common_raw($notice->rendered);
91                 } else {
92                         # XXX: may be some uncooked notices in the DB,
93                         # we cook them right now. This should probably disappear in future
94                         # versions (>> 0.4.x)
95                         common_raw(common_render_content($notice->content, $notice));
96                 }
97                 common_element_end('p');
98                 $noticeurl = common_local_url('shownotice', array('notice' => $notice->id));
99                 # XXX: we need to figure this out better. Is this right?
100                 if (strcmp($notice->uri, $noticeurl) != 0 && preg_match('/^http/', $notice->uri)) {
101                         $noticeurl = $notice->uri;
102                 }
103                 common_element_start('p', 'time');
104                 common_element('a', array('class' => 'permalink',
105                                                                   'href' => $noticeurl,
106                                                                   'title' => common_exact_date($notice->created)),
107                                            common_date_string($notice->created));
108                 if ($notice->source) {
109                         common_text(_(' from '));
110                         $this->source_link($notice->source);
111                 }
112                 if ($notice->reply_to) {
113                         $replyurl = common_local_url('shownotice', array('notice' => $notice->reply_to));
114                         common_text(' (');
115                         common_element('a', array('class' => 'inreplyto',
116                                                                           'href' => $replyurl),
117                                                    _('in reply to...'));
118                         common_text(')');
119                 }
120                 common_element_start('a',
121                                                          array('href' => common_local_url('newnotice',
122                                                                                                                           array('replyto' => $profile->nickname)),
123                                                                    'onclick' => 'doreply("'.$profile->nickname.'"); return false',
124                                                                    'title' => _('reply'),
125                                                                    'class' => 'replybutton'));
126                 common_raw('&rarr;');
127                 common_element_end('a');
128                 if ($user && $notice->profile_id == $user->id) {
129                         $deleteurl = common_local_url('deletenotice', array('notice' => $notice->id));
130                         common_element_start('a', array('class' => 'deletenotice',
131                                                                                         'href' => $deleteurl,
132                                                                                         'title' => _('delete')));
133                         common_raw('&times;');
134                         common_element_end('a');
135                 }
136                 common_element_end('p');
137                 common_element_end('li');
138         }
139         
140         function source_link($source) {
141                 $source_name = _($source);
142                 switch ($source) {
143                  case 'web':
144                  case 'xmpp':
145                  case 'mail':
146                  case 'omb':
147                  case 'api':
148                         common_element('span', 'noticesource', $source_name);
149                         break;
150                  default:
151                         $ns = Notice_source::staticGet($source);
152                         if ($ns) {
153                                 common_element('a', array('href' => $ns->url),
154                                                            $ns->name);
155                         } else {
156                                 common_element('span', 'noticesource', $source_name);
157                         }
158                         break;
159                 }
160                 return;
161         }
162 }