3 * StatusNet, the distributed open-source microblogging tool
5 * Widget to show a list of OAuth applications
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.
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.
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/>.
22 * @category Application
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2008-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/
30 if (!defined('STATUSNET') && !defined('LACONICA')) {
34 require_once INSTALLDIR . '/lib/widget.php';
36 define('APPS_PER_PAGE', 20);
39 * Widget to show a list of OAuth applications
41 * @category Application
43 * @author Zach Copley <zach@status.net>
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
45 * @link http://status.net/
47 class ApplicationList extends Widget
49 /** Current application, application query */
50 var $application = null;
52 /** Owner of this list */
55 /** Action object using us. */
58 function __construct($application, $owner=null, $action=null)
60 parent::__construct($action);
62 $this->application = $application;
63 $this->owner = $owner;
64 $this->action = $action;
69 $this->out->elementStart('ul', 'applications');
73 while ($this->application->fetch()) {
75 if($cnt > APPS_PER_PAGE) {
78 $this->showapplication();
81 $this->out->elementEnd('ul');
86 function showApplication()
88 $user = common_current_user();
90 $this->out->elementStart(
93 'class' => 'application',
94 'id' => 'oauthclient-' . $this->application->id
98 $this->out->elementStart('span', 'vcard author');
100 $this->out->elementStart(
103 'href' => common_local_url(
105 array('id' => $this->application->id)),
110 if (!empty($this->application->icon)) {
114 'src' => $this->application->icon,
115 'class' => 'photo avatar'
120 $this->out->element('span', 'fn', $this->application->name);
121 $this->out->elementEnd('a');
122 $this->out->elementEnd('span');
124 $this->out->raw(' by ');
129 'href' => $this->application->homepage,
132 $this->application->organization
135 $this->out->element('p', 'note', $this->application->description);
136 $this->out->elementEnd('li');
140 /* Override this in subclasses. */
141 function showOwnerControls()
148 * Widget to show a list of connected OAuth clients
150 * @category Application
152 * @author Zach Copley <zach@status.net>
153 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
154 * @link http://status.net/
156 class ConnectedAppsList extends Widget
158 /** Current connected application query */
159 var $connection = null;
161 /** Owner of this list */
164 /** Action object using us. */
167 function __construct($connection, $owner=null, $action=null)
169 parent::__construct($action);
171 common_debug("ConnectedAppsList constructor");
173 $this->connection = $connection;
174 $this->owner = $owner;
175 $this->action = $action;
178 /* Override this in subclasses. */
179 function showOwnerControls()
186 $this->out->elementStart('ul', 'applications');
190 while ($this->connection->fetch()) {
192 if($cnt > APPS_PER_PAGE) {
195 $this->showConnection();
198 $this->out->elementEnd('ul');
203 function showConnection()
205 $app = Oauth_application::getKV('id', $this->connection->application_id);
207 $this->out->elementStart(
210 'class' => 'application',
211 'id' => 'oauthclient-' . $app->id
215 $this->out->elementStart('span', 'vcard author');
217 $this->out->elementStart(
220 'href' => $app->source_url,
225 if (!empty($app->icon)) {
230 'class' => 'photo avatar'
234 if ($app->name != 'anonymous') {
235 $this->out->element('span', 'fn', $app->name);
237 $this->out->elementEnd('a');
239 if ($app->name == 'anonymous') {
240 // TRANS: Name for an anonymous application in application list.
241 $this->out->element('span', 'fn', _('Unknown application'));
244 $this->out->elementEnd('span');
246 if ($app->name != 'anonymous') {
247 // @todo FIXME: i18n trouble.
248 // TRANS: Message has a leading space and a trailing space. Used in application list.
249 // TRANS: Before this message the application name is put, behind it the organisation that manages it.
250 $this->out->raw(_(' by '));
255 'href' => $app->homepage,
262 // TRANS: Application access type
263 $readWriteText = _('read-write');
264 // TRANS: Application access type
265 $readOnlyText = _('read-only');
267 $access = ($this->connection->access_type & Oauth_application::$writeAccess)
268 ? $readWriteText : $readOnlyText;
269 $modifiedDate = common_date_string($this->connection->modified);
270 // TRANS: Used in application list. %1$s is a modified date, %2$s is access type ("read-write" or "read-only")
271 $txt = sprintf(_('Approved %1$s - "%2$s" access.'), $modifiedDate, $access);
273 // @todo FIXME: i18n trouble.
274 $this->out->raw(" - $txt");
275 if (!empty($app->description)) {
277 'p', array('class' => 'application_description'),
283 'class' => 'access_token'),
284 // TRANS: Access token in the application list.
285 // TRANS: %s are the first 7 characters of the access token.
286 sprintf(_('Access token starting with: %s'), substr($this->connection->token, 0, 7))
289 $this->out->elementStart(
292 'id' => 'form_revoke_app',
293 'class' => 'form_revoke_app',
295 'action' => common_local_url('oauthconnectionssettings')
298 $this->out->elementStart('fieldset');
299 $this->out->hidden('oauth_token', $this->connection->token);
300 $this->out->hidden('token', common_session_token());
301 // TRANS: Button label in application list to revoke access to user data.
302 $this->out->submit('revoke', _m('BUTTON','Revoke'));
303 $this->out->elementEnd('fieldset');
304 $this->out->elementEnd('form');
306 $this->out->elementEnd('li');