]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/subscribepeopletag.php
Merge branch 'people_tags_rebase' into 1.0.x
[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
46 class SubscribepeopletagAction extends Action
47 {
48     var $peopletag = null;
49     var $tagger = null;
50
51     /**
52      * Prepare to run
53      */
54
55     function prepare($args)
56     {
57         parent::prepare($args);
58
59         if (!common_logged_in()) {
60             $this->clientError(_('You must be logged in to unsubscribe to a peopletag.'));
61             return false;
62         }
63         // Only allow POST requests
64
65         if ($_SERVER['REQUEST_METHOD'] != 'POST') {
66             $this->clientError(_('This action only accepts POST requests.'));
67             return false;
68         }
69
70         // CSRF protection
71
72         $token = $this->trimmed('token');
73
74         if (!$token || $token != common_session_token()) {
75             $this->clientError(_('There was a problem with your session token.'.
76                                  ' Try again, please.'));
77             return false;
78         }
79
80         $tagger_arg = $this->trimmed('tagger');
81         $tag_arg = $this->trimmed('tag');
82
83         $id = intval($this->arg('id'));
84         if ($id) {
85             $this->peopletag = Profile_list::staticGet('id', $id);
86         } else {
87             $this->clientError(_('No ID given.'), 404);
88             return false;
89         }
90
91         if (!$this->peopletag || $this->peopletag->private) {
92             $this->clientError(_('No such peopletag.'), 404);
93             return false;
94         }
95
96         $this->tagger = Profile::staticGet('id', $this->peopletag->tagger);
97
98         return true;
99     }
100
101     /**
102      * Handle the request
103      *
104      * On POST, add the current user to the group
105      *
106      * @param array $args unused
107      *
108      * @return void
109      */
110
111     function handle($args)
112     {
113         parent::handle($args);
114
115         $cur = common_current_user();
116
117         try {
118             Profile_tag_subscription::add($this->peopletag, $cur);
119         } catch (Exception $e) {
120             $this->serverError(sprintf(_('Could not subscribe user %1$s to peopletag %2$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             $this->element('title', null, sprintf(_('%1$s subscribed to peopletag %2$s by %3$s'),
128                                                   $cur->nickname,
129                                                   $this->peopletag->tag,
130                                                   $this->tagger->nickname));
131             $this->elementEnd('head');
132             $this->elementStart('body');
133             $lf = new UnsubscribePeopletagForm($this, $this->peopletag);
134             $lf->show();
135             $this->elementEnd('body');
136             $this->elementEnd('html');
137         } else {
138             common_redirect(common_local_url('peopletagsubscribers',
139                                 array('tagger' => $this->tagger->nickname,
140                                       'tag' =>$this->peopletag->tag)),
141                             303);
142         }
143     }
144 }