]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - _darcs/pristine/actions/block.php
move opening brace of class declaration to next line
[quix0rs-gnu-social.git] / _darcs / pristine / actions / block.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class BlockAction extends Action
23 {
24
25     var $profile = null;
26
27     function prepare($args)
28     {
29
30         parent::prepare($args);
31
32         if (!common_logged_in()) {
33             $this->client_error(_('Not logged in.'));
34             return false;
35         }
36
37         $token = $this->trimmed('token');
38
39         if (!$token || $token != common_session_token()) {
40             $this->client_error(_('There was a problem with your session token. Try again, please.'));
41             return;
42         }
43
44         $id = $this->trimmed('blockto');
45
46         if (!$id) {
47             $this->client_error(_('No profile specified.'));
48             return false;
49         }
50
51         $this->profile = Profile::staticGet('id', $id);
52
53         if (!$this->profile) {
54             $this->client_error(_('No profile with that ID.'));
55             return false;
56         }
57
58         return true;
59     }
60
61     function handle($args)
62     {
63         parent::handle($args);
64         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
65             if ($this->arg('block')) {
66                 $this->are_you_sure_form();
67             } else if ($this->arg('no')) {
68                 $cur = common_current_user();
69                 common_redirect(common_local_url('subscribers',
70                                                  array('nickname' => $cur->nickname)));
71             } else if ($this->arg('yes')) {
72                 $this->block_profile();
73             }
74         }
75     }
76
77     function are_you_sure_form()
78     {
79
80         $id = $this->profile->id;
81
82         common_show_header(_('Block user'));
83
84         common_element('p', null,
85                        _('Are you sure you want to block this user? '.
86                          'Afterwards, they will be unsubscribed from you, '.
87                          'unable to subscribe to you in the future, and '.
88                          'you will not be notified of any @-replies from them.'));
89
90         common_element_start('form', array('id' => 'block-' . $id,
91                                            'method' => 'post',
92                                            'class' => 'block',
93                                            'action' => common_local_url('block')));
94
95         common_hidden('token', common_session_token());
96
97         common_element('input', array('id' => 'blockto-' . $id,
98                                       'name' => 'blockto',
99                                       'type' => 'hidden',
100                                       'value' => $id));
101
102         foreach ($this->args as $k => $v) {
103             if (substr($k, 0, 9) == 'returnto-') {
104                 common_hidden($k, $v);
105             }
106         }
107
108         common_submit('no', _('No'));
109         common_submit('yes', _('Yes'));
110
111         common_element_end('form');
112
113         common_show_footer();
114     }
115
116     function block_profile()
117     {
118
119         $cur = common_current_user();
120
121         if ($cur->hasBlocked($this->profile)) {
122             $this->client_error(_('You have already blocked this user.'));
123             return;
124         }
125
126         $result = $cur->block($this->profile);
127
128         if (!$result) {
129             $this->server_error(_('Failed to save block information.'));
130             return;
131         }
132
133         # Now, gotta figure where we go back to
134
135         foreach ($this->args as $k => $v) {
136             if ($k == 'returnto-action') {
137                 $action = $v;
138             } else if (substr($k, 0, 9) == 'returnto-') {
139                 $args[substr($k, 9)] = $v;
140             }
141         }
142
143         if ($action) {
144             common_redirect(common_local_url($action, $args));
145         } else {
146             common_redirect(common_local_url('subscriptions',
147                                              array('nickname' => $cur->nickname)));
148         }
149     }
150 }