]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribepeopletag.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / subscribepeopletag.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Subscribe to a peopletag
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  Peopletag
23  * @package   StatusNet
24  * @author    Shashi Gowda <connect2shashi@gmail.com>
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET') && !defined('LACONICA')) {
30     exit(1);
31 }
32
33 /**
34  * Subscribe to a peopletag
35  *
36  * This is the action for subscribing to a peopletag. It works more or less like the join action
37  * for groups.
38  *
39  * @category Peopletag
40  * @package  StatusNet
41  * @author   Shashi Gowda <connect2shashi@gmail.com>
42  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43  * @link     http://status.net/
44  */
45 class SubscribepeopletagAction extends Action
46 {
47     var $peopletag = null;
48     var $tagger = null;
49
50     /**
51      * Prepare to run
52      */
53     function prepare(array $args=array())
54     {
55         parent::prepare($args);
56
57         if (!common_logged_in()) {
58             // TRANS: Client error displayed when trying to perform an action while not logged in.
59             $this->clientError(_('You must be logged in to unsubscribe from a list.'));
60         }
61         // Only allow POST requests
62
63         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
64             // TRANS: Client error displayed when trying to use another method than POST.
65             $this->clientError(_('This action only accepts POST requests.'));
66         }
67
68         // CSRF protection
69
70         $token = $this->trimmed('token');
71
72         if (!$token || $token != common_session_token()) {
73             // TRANS: Client error displayed when the session token does not match or is not given.
74             $this->clientError(_('There was a problem with your session token.'.
75                                  ' Try again, please.'));
76         }
77
78         $tagger_arg = $this->trimmed('tagger');
79         $tag_arg = $this->trimmed('tag');
80
81         $id = intval($this->arg('id'));
82         if ($id) {
83             $this->peopletag = Profile_list::getKV('id', $id);
84         } else {
85             // TRANS: Client error displayed when trying to perform an action without providing an ID.
86             $this->clientError(_('No ID given.'), 404);
87         }
88
89         if (!$this->peopletag || $this->peopletag->private) {
90             // TRANS: Client error displayed trying to reference a non-existing list.
91             $this->clientError(_('No such list.'), 404);
92         }
93
94         $this->tagger = Profile::getKV('id', $this->peopletag->tagger);
95
96         return true;
97     }
98
99     /**
100      * Handle the request
101      *
102      * On POST, add the current user to the group
103      *
104      * @param array $args unused
105      *
106      * @return void
107      */
108
109     function handle(array $args=array())
110     {
111         parent::handle($args);
112
113         $cur = common_current_user();
114
115         try {
116             Profile_tag_subscription::add($this->peopletag, $cur);
117         } catch (Exception $e) {
118             // TRANS: Server error displayed subscribing to a list fails.
119             // TRANS: %1$s is a user nickname, %2$s is a list, %3$s is the error message (no period).
120             $this->serverError(sprintf(_('Could not subscribe user %1$s to list %2$s: %3$s'),
121                                        $cur->nickname, $this->peopletag->tag), $e->getMessage());
122         }
123
124         if ($this->boolean('ajax')) {
125             $this->startHTML('text/xml;charset=utf-8');
126             $this->elementStart('head');
127             // TRANS: Title of form to subscribe to a list.
128             // TRANS: %1%s is a user nickname, %2$s is a list, %3$s is a tagger nickname.
129             $this->element('title', null, sprintf(_('%1$s subscribed to list %2$s by %3$s'),
130                                                   $cur->nickname,
131                                                   $this->peopletag->tag,
132                                                   $this->tagger->nickname));
133             $this->elementEnd('head');
134             $this->elementStart('body');
135             $lf = new UnsubscribePeopletagForm($this, $this->peopletag);
136             $lf->show();
137             $this->elementEnd('body');
138             $this->endHTML();
139         } else {
140             common_redirect(common_local_url('peopletagsubscribers',
141                                 array('tagger' => $this->tagger->nickname,
142                                       'tag' =>$this->peopletag->tag)),
143                             303);
144         }
145     }
146 }