]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Favorite/actions/showfavorites.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / plugins / Favorite / actions / showfavorites.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of replies
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  * @copyright 2008-2011 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * List of replies
34  *
35  * @category Personal
36  * @package  StatusNet
37  * @author   Evan Prodromou <evan@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  */
41 class ShowfavoritesAction extends ShowstreamAction
42 {
43     function title()
44     {
45         if ($this->page == 1) {
46             // TRANS: Title for first page of favourite notices of a user.
47             // TRANS: %s is the user for whom the favourite notices are displayed.
48             return sprintf(_('%s\'s favorite notices'), $this->getTarget()->getNickname());
49         } else {
50             // TRANS: Title for all but the first page of favourite notices of a user.
51             // TRANS: %1$s is the user for whom the favourite notices are displayed, %2$d is the page number.
52             return sprintf(_('%1$s\'s favorite notices, page %2$d'),
53                            $this->getTarget()->getNickname(),
54                            $this->page);
55         }
56     }
57
58     public function getStream()
59     {
60         $own = $this->scoped instanceof Profile ? $this->scoped->sameAs($this->getTarget()) : false;
61         return new FaveNoticeStream($this->getTarget()->getID(), $own);
62     }
63
64     function getFeeds()
65     {
66         return array(new Feed(Feed::JSON,
67                               common_local_url('ApiTimelineFavorites',
68                                                array(
69                                                     'id' => $this->user->nickname,
70                                                     'format' => 'as')),
71                               // TRANS: Feed link text. %s is a username.
72                               sprintf(_('Feed for favorites of %s (Activity Streams JSON)'),
73                                       $this->user->nickname)),
74                      new Feed(Feed::RSS1,
75                               common_local_url('favoritesrss',
76                                                array('nickname' => $this->user->nickname)),
77                               // TRANS: Feed link text. %s is a username.
78                               sprintf(_('Feed for favorites of %s (RSS 1.0)'),
79                                       $this->user->nickname)),
80                      new Feed(Feed::RSS2,
81                               common_local_url('ApiTimelineFavorites',
82                                                array(
83                                                     'id' => $this->user->nickname,
84                                                     'format' => 'rss')),
85                               // TRANS: Feed link text. %s is a username.
86                               sprintf(_('Feed for favorites of %s (RSS 2.0)'),
87                                       $this->user->nickname)),
88                      new Feed(Feed::ATOM,
89                               common_local_url('ApiTimelineFavorites',
90                                                array(
91                                                     'id' => $this->user->nickname,
92                                                     'format' => 'atom')),
93                               // TRANS: Feed link text. %s is a username.
94                               sprintf(_('Feed for favorites of %s (Atom)'),
95                                       $this->user->nickname)));
96     }
97
98     function showEmptyListMessage()
99     {
100         if (common_logged_in()) {
101             $current_user = common_current_user();
102             if ($this->user->id === $current_user->id) {
103                 // TRANS: Text displayed instead of favourite notices for the current logged in user that has no favourites.
104                 $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.');
105             } else {
106                 // TRANS: Text displayed instead of favourite notices for a user that has no favourites while logged in.
107                 // TRANS: %s is a username.
108                 $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname);
109             }
110         }
111         else {
112                 // TRANS: Text displayed instead of favourite notices for a user that has no favourites while not logged in.
113                 // TRANS: %s is a username, %%%%action.register%%%% is a link to the user registration page.
114                 // TRANS: (link text)[link] is a Mark Down link.
115             $message = sprintf(_('%s hasn\'t added any favorite notices yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname);
116         }
117
118         $this->elementStart('div', 'guide');
119         $this->raw(common_markup_to_html($message));
120         $this->elementEnd('div');
121     }
122
123     /**
124      * Show the content
125      *
126      * A list of notices that this user has marked as a favorite
127      *
128      * @return void
129      */
130     function showNotices()
131     {
132         $nl = new FavoritesNoticeList($this->notice, $this);
133
134         $cnt = $nl->show();
135         if (0 == $cnt) {
136             $this->showEmptyListMessage();
137         }
138
139         $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE,
140                           $this->page, 'showfavorites',
141                           array('nickname' => $this->getTarget()->getNickname()));
142     }
143
144     function showPageNotice() {
145         // TRANS: Page notice for show favourites page.
146         $this->element('p', 'instructions', _('This is a way to share what you like.'));
147     }
148 }
149
150 class FavoritesNoticeList extends NoticeList
151 {
152     function newListItem(Notice $notice)
153     {
154         return new FavoritesNoticeListItem($notice, $this->out);
155     }
156 }
157
158 // All handled by superclass
159 class FavoritesNoticeListItem extends DoFollowListItem
160 {
161 }