]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/oauthappssettings.php
Don't show 'anonymous' app in OAuth application list.
[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->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             'Register a new application');
124         $this->elementEnd('p');
125
126         $this->pagination(
127             $this->page > 1,
128             $cnt > APPS_PER_PAGE,
129             $this->page,
130             'oauthappssettings'
131         );
132     }
133
134     function showEmptyListMessage()
135     {
136         $message = sprintf(_('You have not registered any applications yet.'));
137
138         $this->elementStart('div', 'guide');
139         $this->raw(common_markup_to_html($message));
140         $this->elementEnd('div');
141     }
142
143     /**
144      * Handle posts to this form
145      *
146      * Based on the button that was pressed, muxes out to other functions
147      * to do the actual task requested.
148      *
149      * All sub-functions reload the form with a message -- success or failure.
150      *
151      * @return void
152      */
153
154     function handlePost()
155     {
156         // CSRF protection
157
158         $token = $this->trimmed('token');
159         if (!$token || $token != common_session_token()) {
160             $this->showForm(_('There was a problem with your session token. '.
161                               'Try again, please.'));
162             return;
163         }
164
165     }
166
167 }