]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/showstream.php
Alternate pretty-title tweaks for #2668
[quix0rs-gnu-social.git] / actions / showstream.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * User profile page
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Personal
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 require_once INSTALLDIR.'/lib/personalgroupnav.php';
36 require_once INSTALLDIR.'/lib/userprofile.php';
37 require_once INSTALLDIR.'/lib/noticelist.php';
38 require_once INSTALLDIR.'/lib/profileminilist.php';
39 require_once INSTALLDIR.'/lib/groupminilist.php';
40 require_once INSTALLDIR.'/lib/feedlist.php';
41
42 /**
43  * User profile page
44  *
45  * When I created this page, "show stream" seemed like the best name for it.
46  * Now, it seems like a really bad name.
47  *
48  * It shows a stream of the user's posts, plus lots of profile info, links
49  * to subscriptions and stuff, etc.
50  *
51  * @category Personal
52  * @package  StatusNet
53  * @author   Evan Prodromou <evan@status.net>
54  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
55  * @link     http://status.net/
56  */
57 class ShowstreamAction extends ProfileAction
58 {
59     function isReadOnly($args)
60     {
61         return true;
62     }
63
64     function title()
65     {
66         $base = $this->profile->getFancyName();
67         if (!empty($this->tag)) {
68             // TRANS: Page title showing tagged notices in one user's stream. Param 1 is the username, 2 is the hash tag.
69             $base = sprintf(_('%1$s tagged %2$s'), $base, $this->tag);
70         }
71
72         if ($this->page == 1) {
73             return $base;
74         } else {
75             // TRANS: Extended page title showing tagged notices in one user's stream. Param 1 is the main title clause; 2 is the page number.
76             return sprintf(_('%1$s, page %2$d'),
77                            $base,
78                            $this->page);
79         }
80     }
81
82     function handle($args)
83     {
84         // Looks like we're good; start output
85
86         // For YADIS discovery, we also have a <meta> tag
87
88         header('X-XRDS-Location: '. common_local_url('xrds', array('nickname' =>
89                                                                    $this->user->nickname)));
90
91         $this->showPage();
92     }
93
94     function showContent()
95     {
96         $this->showProfile();
97         $this->showNotices();
98     }
99
100     function showLocalNav()
101     {
102         $nav = new PersonalGroupNav($this);
103         $nav->show();
104     }
105
106     function showPageNoticeBlock()
107     {
108         return;
109     }
110
111     function getFeeds()
112     {
113         if (!empty($this->tag)) {
114             return array(new Feed(Feed::RSS1,
115                                   common_local_url('userrss',
116                                                    array('nickname' => $this->user->nickname,
117                                                          'tag' => $this->tag)),
118                                   sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
119                                           $this->user->nickname, $this->tag)));
120         }
121
122         return array(new Feed(Feed::RSS1,
123                               common_local_url('userrss',
124                                                array('nickname' => $this->user->nickname)),
125                               sprintf(_('Notice feed for %s (RSS 1.0)'),
126                                       $this->user->nickname)),
127                      new Feed(Feed::RSS2,
128                               common_local_url('ApiTimelineUser',
129                                                array(
130                                                     'id' => $this->user->id,
131                                                     'format' => 'rss')),
132                               sprintf(_('Notice feed for %s (RSS 2.0)'),
133                                       $this->user->nickname)),
134                      new Feed(Feed::ATOM,
135                               common_local_url('ApiTimelineUser',
136                                                array(
137                                                     'id' => $this->user->id,
138                                                     'format' => 'atom')),
139                               sprintf(_('Notice feed for %s (Atom)'),
140                                       $this->user->nickname)),
141                      new Feed(Feed::FOAF,
142                               common_local_url('foaf', array('nickname' =>
143                                                              $this->user->nickname)),
144                               sprintf(_('FOAF for %s'), $this->user->nickname)));
145     }
146
147     function extraHead()
148     {
149         // for remote subscriptions etc.
150         $this->element('meta', array('http-equiv' => 'X-XRDS-Location',
151                                      'content' => common_local_url('xrds', array('nickname' =>
152                                                                                  $this->user->nickname))));
153
154         if ($this->profile->bio) {
155             $this->element('meta', array('name' => 'description',
156                                          'content' => $this->profile->bio));
157         }
158
159         if ($this->user->emailmicroid && $this->user->email && $this->profile->profileurl) {
160             $id = new Microid('mailto:'.$this->user->email,
161                               $this->selfUrl());
162             $this->element('meta', array('name' => 'microid',
163                                          'content' => $id->toString()));
164         }
165         if ($this->user->jabbermicroid && $this->user->jabber && $this->profile->profileurl) {
166             $id = new Microid('xmpp:'.$this->user->jabber,
167                               $this->selfUrl());
168             $this->element('meta', array('name' => 'microid',
169                                          'content' => $id->toString()));
170         }
171
172         // See https://wiki.mozilla.org/Microsummaries
173
174         $this->element('link', array('rel' => 'microsummary',
175                                      'href' => common_local_url('microsummary',
176                                                                 array('nickname' => $this->profile->nickname))));
177
178         $rsd = common_local_url('rsd',
179                                 array('nickname' => $this->profile->nickname));
180
181         // RSD, http://tales.phrasewise.com/rfc/rsd
182         $this->element('link', array('rel' => 'EditURI',
183                                      'type' => 'application/rsd+xml',
184                                      'href' => $rsd));
185     }
186
187     function showProfile()
188     {
189         $profile = new UserProfile($this, $this->user, $this->profile);
190         $profile->show();
191     }
192
193     function showEmptyListMessage()
194     {
195         $message = sprintf(_('This is the timeline for %1$s but %2$s hasn\'t posted anything yet.'), $this->user->nickname, $this->user->nickname) . ' ';
196
197         if (common_logged_in()) {
198             $current_user = common_current_user();
199             if ($this->user->id === $current_user->id) {
200                 $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
201             } else {
202                 $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->user->nickname, '@' . $this->user->nickname);
203             }
204         }
205         else {
206             $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->user->nickname);
207         }
208
209         $this->elementStart('div', 'guide');
210         $this->raw(common_markup_to_html($message));
211         $this->elementEnd('div');
212     }
213
214     function showNotices()
215     {
216         $notice = empty($this->tag)
217           ? $this->user->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1)
218             : $this->user->getTaggedNotices($this->tag, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1, 0, 0, null);
219
220         $pnl = null;
221         if (Event::handle('ShowStreamNoticeList', array($notice, $this, &$pnl))) {
222             $pnl = new ProfileNoticeList($notice, $this);
223         }
224         $cnt = $pnl->show();
225         if (0 == $cnt) {
226             $this->showEmptyListMessage();
227         }
228
229         $args = array('nickname' => $this->user->nickname);
230         if (!empty($this->tag))
231         {
232             $args['tag'] = $this->tag;
233         }
234         $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
235                           'showstream', $args);
236     }
237
238     function showAnonymousMessage()
239     {
240         if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
241             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
242                            'based on the Free Software [StatusNet](http://status.net/) tool. ' .
243                            '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
244                          $this->user->nickname, $this->user->nickname);
245         } else {
246             $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
247                            'based on the Free Software [StatusNet](http://status.net/) tool. '),
248                          $this->user->nickname, $this->user->nickname);
249         }
250         $this->elementStart('div', array('id' => 'anon_notice'));
251         $this->raw(common_markup_to_html($m));
252         $this->elementEnd('div');
253     }
254
255     function showSections()
256     {
257         parent::showSections();
258         $cloud = new PersonalTagCloudSection($this, $this->user);
259         $cloud->show();
260     }
261 }
262
263 // We don't show the author for a profile, since we already know who it is!
264
265 class ProfileNoticeList extends NoticeList
266 {
267     function newListItem($notice)
268     {
269         return new ProfileNoticeListItem($notice, $this->out);
270     }
271 }
272
273 class ProfileNoticeListItem extends DoFollowListItem
274 {
275     function showAuthor()
276     {
277         return;
278     }
279
280     /**
281      * show a link to the author of repeat
282      *
283      * @return void
284      */
285
286     function showRepeat()
287     {
288         if (!empty($this->repeat)) {
289
290             // FIXME: this code is almost identical to default; need to refactor
291
292             $attrs = array('href' => $this->profile->profileurl,
293                            'class' => 'url');
294
295             if (!empty($this->profile->fullname)) {
296                 $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')';
297             }
298
299             $this->out->elementStart('span', 'repeat');
300
301             $text_link = XMLStringer::estring('a', $attrs, $this->profile->nickname);
302
303             $this->out->raw(sprintf(_('Repeat of %s'), $text_link));
304
305             $this->out->elementEnd('span');
306         }
307     }
308 }