]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/oauthappssettings.php
e9b6280feb81ad65e1f0c1374b1d22de2c641b37
[quix0rs-gnu-social.git] / actions / oauthappssettings.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List the OAuth applications that a user has registered with this instance
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  Settings
23  * @package   StatusNet
24  * @author    Zach Copley <zach@status.net>
25  * @copyright 2008-2009 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('GNUSOCIAL')) { exit(1); }
31
32 /**
33  * Show a user's registered OAuth applications
34  *
35  * @category Settings
36  * @package  StatusNet
37  * @author   Zach Copley <zach@status.net>
38  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
39  * @link     http://status.net/
40  *
41  * @see      SettingsAction
42  */
43
44 class OauthappssettingsAction extends SettingsAction
45 {
46     var $page = 0;
47
48     function prepare($args)
49     {
50         parent::prepare($args);
51         $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
52
53         if (!common_logged_in()) {
54             // TRANS: Message displayed to an anonymous user trying to view OAuth application list.
55             $this->clientError(_('You must be logged in to list your applications.'));
56         }
57
58         return true;
59     }
60
61     /**
62      * Title of the page
63      *
64      * @return string Title of the page
65      */
66
67     function title()
68     {
69         // TRANS: Page title for OAuth applications
70         return _('OAuth applications');
71     }
72
73     /**
74      * Instructions for use
75      *
76      * @return instructions for use
77      */
78
79     function getInstructions()
80     {
81         // TRANS: Page instructions for OAuth applications
82         return _('Applications you have registered');
83     }
84
85     /**
86      * Content area of the page
87      *
88      * @return void
89      */
90
91     function showContent()
92     {
93         $user = common_current_user();
94
95         $offset = ($this->page - 1) * APPS_PER_PAGE;
96         $limit  =  APPS_PER_PAGE + 1;
97
98         $application = new Oauth_application();
99         $application->owner = $user->id;
100         $application->whereAdd("name != 'anonymous'");
101         $application->limit($offset, $limit);
102         $application->orderBy('created DESC');
103         $application->find();
104
105         $cnt = 0;
106
107         if ($application) {
108             $al = new ApplicationList($application, $user, $this);
109             $cnt = $al->show();
110             if (0 == $cnt) {
111                 $this->showEmptyListMessage();
112             }
113         }
114
115         $this->elementStart('p', array('id' => 'application_register'));
116         $this->element('a',
117             array('href' => common_local_url('newapplication'),
118                   'class' => 'more'
119             ),
120             // TRANS: Link description to add a new OAuth application.
121             'Register a new application');
122         $this->elementEnd('p');
123
124         $this->pagination(
125             $this->page > 1,
126             $cnt > APPS_PER_PAGE,
127             $this->page,
128             'oauthappssettings'
129         );
130     }
131
132     function showEmptyListMessage()
133     {
134         // TRANS: Empty list message on page with OAuth applications.
135         $message = sprintf(_('You have not registered any applications yet.'));
136
137         $this->elementStart('div', 'guide');
138         $this->raw(common_markup_to_html($message));
139         $this->elementEnd('div');
140     }
141
142     /**
143      * Handle posts to this form
144      *
145      * Based on the button that was pressed, muxes out to other functions
146      * to do the actual task requested.
147      *
148      * All sub-functions reload the form with a message -- success or failure.
149      *
150      * @return void
151      */
152
153     function handlePost()
154     {
155         // CSRF protection
156
157         $token = $this->trimmed('token');
158         if (!$token || $token != common_session_token()) {
159             $this->showForm(_('There was a problem with your session token. '.
160                               'Try again, please.'));
161             return;
162         }
163     }
164 }