]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TagSub/actions/tagsubs.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / TagSub / actions / tagsubs.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of a user's subscriptions
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  Social
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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * A list of the user's subscriptions
35  *
36  * @category Social
37  * @package  StatusNet
38  * @author   Evan Prodromou <evan@status.net>
39  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
40  * @link     http://status.net/
41  */
42 class TagSubsAction extends GalleryAction
43 {
44     function title()
45     {
46         if ($this->page == 1) {
47             // TRANS: Header for subscriptions overview for a user (first page).
48             // TRANS: %s is a user nickname.
49             return sprintf(_m('%s\'s tag subscriptions'), $this->getTarget()->getNickname());
50         } else {
51             // TRANS: Header for subscriptions overview for a user (not first page).
52             // TRANS: %1$s is a user nickname, %2$d is the page number.
53             return sprintf(_m('%1$s\'s tag subscriptions, page %2$d'),
54                            $this->getTarget()->getNickname(),
55                            $this->page);
56         }
57     }
58
59     function showPageNotice()
60     {
61         if ($this->scoped instanceof Profile && $this->scoped->sameAs($this->getTarget())) {
62             $this->element('p', null,
63                            // TRANS: Page notice for page with an overview of all tag subscriptions
64                            // TRANS: of the logged in user's own profile.
65                            _m('You have subscribed to receive all notices on this site containing the following tags:'));
66         } else {
67             $this->element('p', null,
68                            // TRANS: Page notice for page with an overview of all subscriptions of a user other
69                            // TRANS: than the logged in user. %s is the user nickname.
70                            sprintf(_m('%s has subscribed to receive all notices on this site containing the following tags:'),
71                                    $this->getTarget()->getNickname()));
72         }
73     }
74
75     function showContent()
76     {
77         if (Event::handle('StartShowTagSubscriptionsContent', array($this))) {
78             parent::showContent();
79
80             $offset = ($this->page-1) * PROFILES_PER_PAGE;
81             $limit =  PROFILES_PER_PAGE + 1;
82
83             $cnt = 0;
84
85             $tagsub = new TagSub();
86             $tagsub->profile_id = $this->getTarget()->getID();
87             $tagsub->limit($limit, $offset);
88             $tagsub->find();
89
90             if ($tagsub->N) {
91                 $list = new TagSubscriptionsList($tagsub, $this->getTarget(), $this);
92                 $cnt = $list->show();
93                 if (0 == $cnt) {
94                     $this->showEmptyListMessage();
95                 }
96             } else {
97                 $this->showEmptyListMessage();
98             }
99
100             $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
101                               $this->page, 'tagsubs',
102                               array('nickname' => $this->getTarget()->getNickname()));
103
104
105             Event::handle('EndShowTagSubscriptionsContent', array($this));
106         }
107     }
108
109     function showEmptyListMessage()
110     {
111         if (common_logged_in()) {
112             if ($this->scoped->sameAs($this->getTarget())) {
113                 // TRANS: Tag subscription list text when the logged in user has no tag subscriptions.
114                 $message = _m('You are not listening to any hash tags right now. You can push the "Subscribe" button ' .
115                               'on any hashtag page to automatically receive any public messages on this site that use that ' .
116                               'tag, even if you are not subscribed to the poster.');
117             } else {
118                 // TRANS: Tag subscription list text when looking at the subscriptions for a of a user other
119                 // TRANS: than the logged in user that has no tag subscriptions. %s is the user nickname.
120                 $message = sprintf(_m('%s is not following any tags.'), $this->getTarget()->getNickname());
121             }
122         }
123         else {
124             // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
125             // TRANS: as an anonymous user. %s is the user nickname.
126             $message = sprintf(_m('%s is not following any tags.'), $this->getTarget()->getNickname());
127         }
128
129         $this->elementStart('div', 'guide');
130         $this->raw(common_markup_to_html($message));
131         $this->elementEnd('div');
132     }
133 }
134
135 // XXX SubscriptionsList and SubscriptionList are dangerously close
136
137 class TagSubscriptionsList extends SubscriptionList
138 {
139     function newListItem($tagsub)
140     {
141         return new TagSubscriptionsListItem($tagsub, $this->owner, $this->action);
142     }
143 }
144
145 class TagSubscriptionsListItem extends SubscriptionListItem
146 {
147     function startItem()
148     {
149         $this->out->elementStart('li', array('class' => 'tagsub'));
150     }
151
152     function showProfile()
153     {
154         $tagsub = $this->profile;
155         $tag = $tagsub->tag;
156
157         // Relevant portion!
158         $cur = common_current_user();
159         if (!empty($cur) && $cur->id == $this->owner->id) {
160             $this->showOwnerControls();
161         }
162
163         $url = common_local_url('tag', array('tag' => $tag));
164         // TRANS: %1$s is a URL to a tag, %2$s is a tag,
165         // TRANS: %3$s a date string.
166         $linkline = sprintf(_m('#<a href="%1$s">%2$s</a> since %3$s'),
167                             htmlspecialchars($url),
168                             htmlspecialchars($tag),
169                             common_date_string($tagsub->created));
170
171         $this->out->elementStart('div', 'tagsub-item');
172         $this->out->raw($linkline);
173         $this->out->element('div', array('style' => 'clear: both'));
174         $this->out->elementEnd('div');
175     }
176
177     function showActions()
178     {
179     }
180
181     function showOwnerControls()
182     {
183         $this->out->elementStart('div', 'entity_actions');
184
185         $tagsub = $this->profile; // ?
186         $form = new TagUnsubForm($this->out, $tagsub->tag);
187         $form->show();
188
189         $this->out->elementEnd('div');
190         return;
191     }
192 }