]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/unblock.php
define LACONICA and accept LACONICA for backwards compatibility
[quix0rs-gnu-social.git] / actions / unblock.php
1 <?php
2 /**
3  * Unblock a user action class.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008, 2009, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Unblock a user action class.
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Robin Millette <millette@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45 class UnblockAction extends Action
46 {
47     var $profile = null;
48
49     /**
50      * Take arguments for running
51      *
52      * @param array $args $_REQUEST args
53      *
54      * @return boolean success flag
55      */
56     function prepare($args)
57     {
58         parent::prepare($args);
59         if (!common_logged_in()) {
60             $this->clientError(_('Not logged in.'));
61             return false;
62         }
63         $token = $this->trimmed('token');
64         if (!$token || $token != common_session_token()) {
65             $this->clientError(_('There was a problem with your session token. Try again, please.'));
66             return;
67         }
68         $id = $this->trimmed('unblockto');
69         if (!$id) {
70             $this->clientError(_('No profile specified.'));
71             return false;
72         }
73         $this->profile = Profile::staticGet('id', $id);
74         if (!$this->profile) {
75             $this->clientError(_('No profile with that ID.'));
76             return false;
77         }
78         return true;
79     }
80
81     /**
82      * Handle request
83      *
84      * Shows a page with list of favorite notices
85      *
86      * @param array $args $_REQUEST args; handled in prepare()
87      *
88      * @return void
89      */
90     function handle($args)
91     {
92         parent::handle($args);
93         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
94             $this->unblockProfile();
95         }
96     }
97
98     /**
99      * Unblock a user.
100      *
101      * @return void
102      */
103     function unblockProfile()
104     {
105         $cur    = common_current_user();
106         $result = $cur->unblock($this->profile);
107         if (!$result) {
108             $this->serverError(_('Error removing the block.'));
109             return;
110         }
111         foreach ($this->args as $k => $v) {
112             if ($k == 'returnto-action') {
113                 $action = $v;
114             } else if (substr($k, 0, 9) == 'returnto-') {
115                 $args[substr($k, 9)] = $v;
116             }
117         }
118         if ($action) {
119             common_redirect(common_local_url($action, $args), 303);
120         } else {
121             common_redirect(common_local_url('subscribers',
122                                              array('nickname' => $cur->nickname)),
123                             303);
124         }
125     }
126 }
127