]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/oauthappssettings.php
Merge branch 'master' into 0.9.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 require_once INSTALLDIR . '/lib/settingsaction.php';
35 require_once INSTALLDIR . '/lib/applicationlist.php';
36
37 /**
38  * Show a user's registered OAuth applications
39  *
40  * @category Settings
41  * @package  StatusNet
42  * @author   Zach Copley <zach@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
44  * @link     http://status.net/
45  *
46  * @see      SettingsAction
47  */
48
49 class OauthappssettingsAction extends SettingsAction
50 {
51     var $page = 0;
52
53     function prepare($args)
54     {
55         parent::prepare($args);
56         $this->page = ($this->arg('page')) ? ($this->arg('page') + 0) : 1;
57
58         if (!common_logged_in()) {
59             $this->clientError(_('You must be logged in to list your applications.'));
60             return false;
61         }
62
63         return true;
64     }
65
66     /**
67      * Title of the page
68      *
69      * @return string Title of the page
70      */
71
72     function title()
73     {
74         return _('OAuth applications');
75     }
76
77     /**
78      * Instructions for use
79      *
80      * @return instructions for use
81      */
82
83     function getInstructions()
84     {
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->limit($offset, $limit);
104         $application->orderBy('created DESC');
105         $application->find();
106
107         $cnt = 0;
108
109         if ($application) {
110             $al = new ApplicationList($application, $user, $this);
111             $cnt = $al->show();
112             if (0 == $cnt) {
113                 $this->showEmptyListMessage();
114             }
115         }
116
117         $this->elementStart('p', array('id' => 'application_register'));
118         $this->element('a',
119             array('href' => common_local_url('newapplication'),
120                   'class' => 'more'
121             ),
122             'Register a new application');
123         $this->elementEnd('p');
124
125         $this->pagination(
126             $this->page > 1,
127             $cnt > APPS_PER_PAGE,
128             $this->page,
129             'oauthappssettings'
130         );
131     }
132
133     function showEmptyListMessage()
134     {
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     }
165
166 }