]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/removepeopletag.php
aa8ae2b6ad469091efddb67d9494788cc8a421f5
[quix0rs-gnu-social.git] / actions / removepeopletag.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008-2010, StatusNet, Inc.
5  *
6  * Subscription action.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * PHP version 5
22  *
23  * @category  Action
24  * @package   StatusNet
25  * @author    Shashi Gowda <connect2shashi@gmail.com>
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/lib/togglepeopletag.php';
35
36 /**
37  * Subscription action
38  *
39  * Subscribing to a profile. Does not work for OMB 0.1 remote subscriptions,
40  * but may work for other remote subscription protocols, like OStatus.
41  *
42  * Takes parameters:
43  *
44  *    - subscribeto: a profile ID
45  *    - token: session token to prevent CSRF attacks
46  *    - ajax: boolean; whether to return Ajax or full-browser results
47  *
48  * Only works if the current user is logged in.
49  *
50  * @category  Action
51  * @package   StatusNet
52  * @author    Shashi Gowda <connect2shashi@gmail.com>
53  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
54  * @link      http://status.net/
55  */
56
57 class RemovepeopletagAction extends Action
58 {
59     var $user;
60     var $tagged;
61     var $peopletag;
62
63     /**
64      * Check pre-requisites and instantiate attributes
65      *
66      * @param Array $args array of arguments (URL, GET, POST)
67      *
68      * @return boolean success flag
69      */
70
71     function prepare($args)
72     {
73         parent::prepare($args);
74
75         // CSRF protection
76
77         $token = $this->trimmed('token');
78
79         if (!$token || $token != common_session_token()) {
80             $this->clientError(_('There was a problem with your session token.'.
81                                  ' Try again, please.'));
82             return false;
83         }
84
85         // Only for logged-in users
86
87         $this->user = common_current_user();
88
89         if (empty($this->user)) {
90             $this->clientError(_('Not logged in.'));
91             return false;
92         }
93
94         // Profile to subscribe to
95
96         $tagged_id = $this->arg('tagged');
97
98         $this->tagged = Profile::staticGet('id', $tagged_id);
99
100         if (empty($this->tagged)) {
101             $this->clientError(_('No such profile.'));
102             return false;
103         }
104
105         $id = $this->arg('peopletag_id');
106         $this->peopletag = Profile_list::staticGet('id', $id);
107
108         if (empty($this->peopletag)) {
109             $this->clientError(_('No such peopletag.'));
110             return false;
111         }
112
113         // OMB 0.1 doesn't have a mechanism for local-server-
114         // originated tag.
115
116         $omb01 = Remote_profile::staticGet('id', $tagged_id);
117
118         if (!empty($omb01)) {
119             $this->clientError(_('You cannot tag or untag an OMB 0.1'.
120                                  ' remote profile with this action.'));
121             return false;
122         }
123
124         return true;
125     }
126
127     /**
128      * Handle request
129      *
130      * Does the subscription and returns results.
131      *
132      * @param Array $args unused.
133      *
134      * @return void
135      */
136
137     function handle($args)
138     {
139         // Throws exception on error
140
141         $ptag = Profile_tag::unTag($this->user->id, $this->tagged->id,
142                                 $this->peopletag->tag);
143
144         if (!$ptag) {
145             $user = User::staticGet('id', $this->tagged->id);
146             if ($user) {
147                 $this->clientError(
148                         sprintf(_('There was an unexpected error while tagging %s'),
149                         $user->nickname));
150             } else {
151                 $this->clientError(sprintf(_('There was a problem tagging %s.' .
152                                       'The remote server is probably not responding correctly, ' .
153                                       'please try retrying later.'), $this->profile->profileurl));
154             }
155             return false;
156         }
157         if ($this->boolean('ajax')) {
158             $this->startHTML('text/xml;charset=utf-8');
159             $this->elementStart('head');
160             $this->element('title', null, _('Untagged'));
161             $this->elementEnd('head');
162             $this->elementStart('body');
163             $unsubscribe = new TagButton($this, $this->tagged, $this->peopletag);
164             $unsubscribe->show();
165             $this->elementEnd('body');
166             $this->elementEnd('html');
167         } else {
168             $url = common_local_url('subscriptions',
169                                     array('nickname' => $this->user->nickname));
170             common_redirect($url, 303);
171         }
172     }
173 }