showstream.php 11.9 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
4
 *
5 6 7 8 9
 * User profile page
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
10 11 12
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
13
 *
14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
18
 *
19 20
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 22
 *
 * @category  Personal
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @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('GNUSOCIAL')) { exit(1); }
Evan Prodromou's avatar
Evan Prodromou committed
32

33 34 35 36 37 38 39 40 41 42
/**
 * User profile page
 *
 * When I created this page, "show stream" seemed like the best name for it.
 * Now, it seems like a really bad name.
 *
 * It shows a stream of the user's posts, plus lots of profile info, links
 * to subscriptions and stuff, etc.
 *
 * @category Personal
43
 * @package  StatusNet
44
 * @author   Evan Prodromou <evan@status.net>
45
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
46
 * @link     http://status.net/
47
 */
48
class ShowstreamAction extends NoticestreamAction
49
{
50
    public function getStream()
51 52
    {
        if (empty($this->tag)) {
53
            $stream = new ProfileNoticeStream($this->target, $this->scoped);
54
        } else {
55
            $stream = new TaggedProfileNoticeStream($this->target, $this->tag, $this->scoped);
56 57
        }

58
        return $stream;
59 60
    }

61
    function title()
62
    {
63
        $base = $this->target->getFancyName();
64
        if (!empty($this->tag)) {
65
            if ($this->page == 1) {
66
                // TRANS: Page title showing tagged notices in one user's timeline.
67
                // TRANS: %1$s is the username, %2$s is the hash tag.
68
                return sprintf(_('Notices by %1$s tagged %2$s'), $base, $this->tag);
69
            } else {
70
                // TRANS: Page title showing tagged notices in one user's timeline.
71
                // TRANS: %1$s is the username, %2$s is the hash tag, %3$d is the page number.
72
                return sprintf(_('Notices by %1$s tagged %2$s, page %3$d'), $base, $this->tag, $this->page);
73
            }
74
        } else {
75
            if ($this->page == 1) {
76
                return sprintf(_('Notices by %s'), $base);
77
            } else {
78
                // TRANS: Extended page title showing tagged notices in one user's timeline.
79
                // TRANS: %1$s is the username, %2$d is the page number.
80
                return sprintf(_('Notices by %1$s, page %2$d'),
81 82 83
                               $base,
                               $this->page);
            }
84 85
        }
    }
86

87
    protected function showContent()
88
    {
89 90
        $this->showNotices();
    }
91

92 93
    function showProfileBlock()
    {
94
        $block = new AccountProfileBlock($this, $this->target);
95 96 97
        $block->show();
    }

98 99 100
    function showPageNoticeBlock()
    {
        return;
101 102
    }

103
    function getFeeds()
104
    {
105 106
        if (!empty($this->tag)) {
            return array(new Feed(Feed::RSS1,
107
                                  common_local_url('userrss',
108
                                                   array('nickname' => $this->target->getNickname(),
109
                                                         'tag' => $this->tag)),
110 111
                                  // TRANS: Title for link to notice feed.
                                  // TRANS: %1$s is a user nickname, %2$s is a hashtag.
112
                                  sprintf(_('Notice feed for %1$s tagged %2$s (RSS 1.0)'),
113
                                          $this->target->getNickname(), $this->tag)));
114 115
        }

116 117 118
        return array(new Feed(Feed::JSON,
                              common_local_url('ApiTimelineUser',
                                               array(
119
                                                    'id' => $this->target->getID(),
120 121 122 123
                                                    'format' => 'as')),
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
                              sprintf(_('Notice feed for %s (Activity Streams JSON)'),
124
                                      $this->target->getNickname())),
125
                     new Feed(Feed::RSS1,
126
                              common_local_url('userrss',
127
                                               array('nickname' => $this->target->getNickname())),
128 129
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
130
                              sprintf(_('Notice feed for %s (RSS 1.0)'),
131
                                      $this->target->getNickname())),
132
                     new Feed(Feed::RSS2,
133 134
                              common_local_url('ApiTimelineUser',
                                               array(
135
                                                    'id' => $this->target->getID(),
136
                                                    'format' => 'rss')),
137 138
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
139
                              sprintf(_('Notice feed for %s (RSS 2.0)'),
140
                                      $this->target->getNickname())),
141
                     new Feed(Feed::ATOM,
142 143
                              common_local_url('ApiTimelineUser',
                                               array(
144
                                                    'id' => $this->target->getID(),
145
                                                    'format' => 'atom')),
146 147
                              // TRANS: Title for link to notice feed.
                              // TRANS: %s is a user nickname.
148
                              sprintf(_('Notice feed for %s (Atom)'),
149
                                      $this->target->getNickname())),
150 151
                     new Feed(Feed::FOAF,
                              common_local_url('foaf', array('nickname' =>
152
                                                             $this->target->getNickname())),
153 154
                              // TRANS: Title for link to notice feed. FOAF stands for Friend of a Friend.
                              // TRANS: More information at http://www.foaf-project.org. %s is a user nickname.
155
                              sprintf(_('FOAF for %s'), $this->target->getNickname())));
156 157 158 159
    }

    function extraHead()
    {
160
        if ($this->target->bio) {
161
            $this->element('meta', array('name' => 'description',
162
                                         'content' => $this->target->getDescription()));
163 164
        }

165
        // See https://wiki.mozilla.org/Microsummaries
166

167
        $this->element('link', array('rel' => 'microsummary',
168
                                     'href' => common_local_url('microsummary',
169
                                                                array('nickname' => $this->target->getNickname()))));
170 171

        $rsd = common_local_url('rsd',
172
                                array('nickname' => $this->target->getNickname()));
173 174 175 176 177

        // RSD, http://tales.phrasewise.com/rfc/rsd
        $this->element('link', array('rel' => 'EditURI',
                                     'type' => 'application/rsd+xml',
                                     'href' => $rsd));
Evan Prodromou's avatar
Evan Prodromou committed
178 179 180

        if ($this->page != 1) {
            $this->element('link', array('rel' => 'canonical',
181
                                         'href' => $this->target->getUrl()));
Evan Prodromou's avatar
Evan Prodromou committed
182
        }
183 184
    }

185 186
    function showEmptyListMessage()
    {
187
        // TRANS: First sentence of empty list message for a timeline. $1%s is a user nickname.
188
        $message = sprintf(_('This is the timeline for %1$s, but %1$s hasn\'t posted anything yet.'), $this->target->getNickname()) . ' ';
189

190 191
        if ($this->scoped instanceof Profile) {
            if ($this->target->getID() === $this->scoped->getID()) {
192
                // TRANS: Second sentence of empty list message for a stream for the user themselves.
193 194
                $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)');
            } else {
195
                // TRANS: Second sentence of empty  list message for a non-self timeline. %1$s is a user nickname, %2$s is a part of a URL.
196
                // TRANS: This message contains a Markdown link. Keep "](" together.
197
                $message .= sprintf(_('You can try to nudge %1$s or [post something to them](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->target->getNickname(), '@' . $this->target->getNickname());
198 199 200
            }
        }
        else {
201 202
            // TRANS: Second sentence of empty message for anonymous users. %s is a user nickname.
            // TRANS: This message contains a Markdown link. Keep "](" together.
203
            $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to them.'), $this->target->getNickname());
204 205 206 207 208 209 210
        }

        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }

211
    function showNotices()
212
    {
213
        $pnl = new NoticeList($this->notice, $this);
214
        $cnt = $pnl->show();
215
        if (0 == $cnt) {
216
            $this->showEmptyListMessage();
217
        }
218

219
        $args = array('nickname' => $this->target->getNickname());
220 221 222 223
        if (!empty($this->tag))
        {
            $args['tag'] = $this->tag;
        }
224
        $this->pagination($this->page>1, $cnt>NOTICES_PER_PAGE, $this->page,
225
                          'showstream', $args);
226 227
    }

228 229
    function showAnonymousMessage()
    {
230
        if (!(common_config('site','closed') || common_config('site','inviteonly'))) {
231
            // TRANS: Announcement for anonymous users showing a timeline if site registrations are open.
232
            // TRANS: This message contains a Markdown link. Keep "](" together.
233
            $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
234 235
                           'based on the Free Software [StatusNet](http://status.net/) tool. ' .
                           '[Join now](%%%%action.register%%%%) to follow **%s**\'s notices and many more! ([Read more](%%%%doc.help%%%%))'),
236
                         $this->target->getNickname(), $this->target->getNickname());
237
        } else {
238
            // TRANS: Announcement for anonymous users showing a timeline if site registrations are closed or invite only.
239
            // TRANS: This message contains a Markdown link. Keep "](" together.
240
            $m = sprintf(_('**%s** has an account on %%%%site.name%%%%, a [micro-blogging](http://en.wikipedia.org/wiki/Micro-blogging) service ' .
241
                           'based on the Free Software [StatusNet](http://status.net/) tool.'),
242
                         $this->target->getNickname(), $this->target->getNickname());
243
        }
sarven's avatar
sarven committed
244
        $this->elementStart('div', array('id' => 'anon_notice'));
245
        $this->raw(common_markup_to_html($m));
246
        $this->elementEnd('div');
247 248
    }

249 250 251
    function showSections()
    {
        parent::showSections();
252
        if (!common_config('performance', 'high')) {
253
            $cloud = new PersonalTagCloudSection($this->target, $this);
254 255
            $cloud->show();
        }
256
    }
257 258 259 260 261

    function noticeFormOptions()
    {
        $options = parent::noticeFormOptions();

262
        if (!$this->scoped instanceof Profile || !$this->scoped->sameAs($this->target)) {
263
            $options['to_profile'] =  $this->target;
264 265 266 267
        }

        return $options;
    }
268
}