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