]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/deleteapplication.php
Update translator documentation.
[quix0rs-gnu-social.git] / actions / deleteapplication.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Action class to delete an OAuth application
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  Action
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2010 StatusNet, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27  * @link      http://status.net/
28  */
29
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
31     exit(1);
32 }
33
34 /**
35  * Delete an OAuth appliction
36  *
37  * @category Action
38  * @package  StatusNet
39  * @author   Zach Copley <zach@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43 class DeleteapplicationAction extends Action
44 {
45     var $app = null;
46
47     /**
48      * Take arguments for running
49      *
50      * @param array $args $_REQUEST args
51      *
52      * @return boolean success flag
53      */
54     function prepare($args)
55     {
56         if (!parent::prepare($args)) {
57             return false;
58         }
59
60         if (!common_logged_in()) {
61             // TRANS: Client error displayed trying to delete an application while not logged in.
62             $this->clientError(_('You must be logged in to delete an application.'));
63             return false;
64         }
65
66         $id        = (int)$this->arg('id');
67         $this->app = Oauth_application::staticGet('id', $id);
68
69         if (empty($this->app)) {
70             // TRANS: Client error displayed trying to delete an application that does not exist.
71             $this->clientError(_('Application not found.'));
72             return false;
73         }
74
75         $cur = common_current_user();
76
77         if ($cur->id != $this->app->owner) {
78             // TRANS: Client error displayed trying to delete an application the current user does not own.
79             $this->clientError(_('You are not the owner of this application.'), 401);
80             return false;
81         }
82
83         return true;
84     }
85
86     /**
87      * Handle request
88      *
89      * Shows a page with list of favorite notices
90      *
91      * @param array $args $_REQUEST args; handled in prepare()
92      *
93      * @return void
94      */
95     function handle($args)
96     {
97         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
98
99             // CSRF protection
100             $token = $this->trimmed('token');
101             if (!$token || $token != common_session_token()) {
102                 $this->clientError(_('There was a problem with your session token.'));
103                 return;
104             }
105
106             if ($this->arg('no')) {
107                 common_redirect(common_local_url('showapplication',
108                                                  array('id' => $this->app->id)), 303);
109             } elseif ($this->arg('yes')) {
110                 $this->handlePost();
111                 common_redirect(common_local_url('oauthappssettings'), 303);
112             } else {
113                 $this->showPage();
114             }
115         }
116     }
117
118     function showContent() {
119         $this->areYouSureForm();
120     }
121
122     function title() {
123         // TRANS: Title for delete application page.
124         return _('Delete application');
125     }
126
127     function showNoticeForm() {
128         // nop
129     }
130
131     /**
132      * Confirm with user.
133      *
134      * Shows a confirmation form.
135      *
136      * @return void
137      */
138     function areYouSureForm()
139     {
140         $id = $this->app->id;
141         $this->elementStart('form', array('id' => 'deleteapplication-' . $id,
142                                           'method' => 'post',
143                                           'class' => 'form_settings form_entity_block',
144                                           'action' => common_local_url('deleteapplication',
145                                                                        array('id' => $this->app->id))));
146         $this->elementStart('fieldset');
147         $this->hidden('token', common_session_token());
148         // TRANS: Fieldset legend on delete application page.
149         $this->element('legend', _('Delete application'));
150         $this->element('p', null,
151                        // TRANS: Confirmation text on delete application page.
152                        _('Are you sure you want to delete this application? '.
153                          'This will clear all data about the application from the '.
154                          'database, including all existing user connections.'));
155         $this->submit('form_action-no',
156                       // TRANS: Button label on the delete application form.
157                       _m('BUTTON','No'),
158                       'submit form_action-primary',
159                       'no',
160                       // TRANS: Submit button title for 'No' when deleting an application.
161                       _('Do not delete this application'));
162         $this->submit('form_action-yes',
163                       // TRANS: Button label on the delete application form.
164                       _m('BUTTON','Yes'),
165                       'submit form_action-secondary',
166                       // TRANS: Submit button title for 'Yes' when deleting an application.
167                       'yes', _('Delete this application'));
168         $this->elementEnd('fieldset');
169         $this->elementEnd('form');
170     }
171
172     /**
173      * Actually delete the app
174      *
175      * @return void
176      */
177     function handlePost()
178     {
179         $this->app->delete();
180     }
181 }